src/Controller/SalesInvoiceController.php line 69
<?phpnamespace App\Controller;use App\Entity\SalesInvoice;use App\Entity\SalesInvoiceDetails;use App\Entity\Country;use App\Entity\Courier;use App\Entity\ProductType;use App\Entity\Customer;use App\Entity\CourierWiseZone;use App\Entity\ZoneWiseMasterRate;use App\Entity\CountryWiseMasterRate;use App\Entity\ZoneWiseSalesRate;use App\Entity\ZoneWiseCommonSalesRate;use App\Entity\CountryWiseSalesRate;use App\Entity\CountryWiseCommonSalesRate;use App\Entity\SettingsInfo;use App\Entity\ZoneWiseCovidCharge;use App\Entity\CountryWiseCovidCharge;use App\Entity\ReceiveVoucher;use App\Entity\AdditionalCharge;use App\Entity\InvoiceAdditionalCharge;use App\Entity\Shipment;use App\Form\SalesInvoiceType;use App\Form\SalesInvoiceDetailsType;use App\Form\SalesInvoiceEditType;use App\Form\InvoiceSurchargeType;use App\Repository\SalesInvoiceRepository;use App\Repository\SettingsInfoRepository;use App\Repository\CountryRepository;use App\Repository\CourierRepository;use App\Repository\ProductTypeRepository;use App\Repository\SalesInvoiceDetailsRepository;use App\Repository\ReceiveVoucherRepository;use App\Repository\AccountNameRepository;use App\Repository\ShipmentRepository;use App\Repository\CustomerRepository;use App\Repository\CourierWiseZoneRepository;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Form\Extension\Core\Type\TextType;use App\Service\UtilsService;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\HttpFoundation\JsonResponse;use Doctrine\Common\Collections\ArrayCollection;use Dompdf\Dompdf;use Dompdf\Options;use Symfony\Component\Form\Extension\Core\Type\FileType;use Symfony\Component\String\Slugger\SluggerInterface;use Symfony\Component\HttpFoundation\File\Exception\FileException;use Symfony\Component\Validator\Constraints\File;use PhpOffice\PhpSpreadsheet\IOFactory;use Symfony\Bridge\Doctrine\Form\Type\EntityType;use Symfony\Component\Form\Extension\Core\Type\DateType;use Symfony\Component\HttpFoundation\Session\Session;use Dompdf\FontMetrics;use DateTime;use Symfony\Component\Security\Http\Attribute\IsGranted;use Symfony\Component\Form\Extension\Core\Type\HiddenType;#[IsGranted("ROLE_ACCOUNTS")]class SalesInvoiceController extends AbstractController{#[Route('/{page<[1-9]\d*>}', defaults: ['page' => '1'], name: 'app_sales_invoice_index', methods: ['GET', 'POST'])]#[IsGranted("ROLE_ACCOUNTS")]public function index(Request $request, int $page, SalesInvoiceRepository $salesInvoiceRepository): Response{$form = $this->createFormBuilder(null)->add('customer',TextType::class, ['attr' => ['class' => 'form-control','placeholder' => 'Search by Customer',],'label' => false,'required' => false,])->add('invoiceNo',TextType::class, ['attr' => ['class' => 'form-control','placeholder' => 'Search by Invoice No',],'label' => false,'required' => false,])->add('hawbno',TextType::class, ['attr' => ['class' => 'form-control','placeholder' => 'Search by Hawb No'],'label' => false,'required' => false,])->getForm();$form->handleRequest($request);$session = new Session();if ($form->isSubmitted() && $form->isValid()) {// data is an array with "name", "email", and "message" keys// $data = $form->getData();// $filter = $data['search'];$data = $form->getData();$customer = $form->get('customer')->getData() !== null ? $form->get('customer')->getData() : "";$invoiceNo = $form->get('invoiceNo')->getData() !== null ? $form->get('invoiceNo')->getData() : "";$hawbNO = $form->get('hawbno')->getData() !== null ? $form->get('hawbno')->getData() : "";$page = 1;if(isset($customer)){// set and get session attributes$session->set('exp_clt_customer', $customer);}$sales_invoices = $salesInvoiceRepository->findAllSalesInvoice($customer, $invoiceNo, $hawbNO, 1, $this->getUser()->getUserCompany()->getId(), $page);return $this->render('sales_invoice/index.html.twig', ['sales_invoices' => $sales_invoices,'form' => $form->createView(),]);}$customer = "";if($page > 1){$customer = $session->get('exp_clt_customer');}else{$session->remove('exp_clt_customer');}$sales_invoices = $salesInvoiceRepository->findAllSalesInvoice($customer === null ? "" : $customer, "", "", 1, $this->getUser()->getUserCompany()->getId(), $page);return $this->render('sales_invoice/index.html.twig', ['sales_invoices' => $sales_invoices,'form' => $form->createView(),]);}#[Route('/salesinvoice/new', name: 'app_sales_invoice_new', methods: ['GET', 'POST'])]#[IsGranted("ROLE_ACCOUNTS")]public function new(Request $request, SalesInvoiceRepository $salesInvoiceRepository, UtilsService $utilsService, EntityManagerInterface $entityManager, SettingsInfoRepository $settingsInfoRepository, ReceiveVoucherRepository $receiveVoucherRepository, AccountNameRepository $accountNameRepository): Response{$gloPaymentReceived = -1;$salesInvoice = new SalesInvoice();$salesInvoice->setInvoiceDate(new \DateTime("now", new \DateTimeZone("Asia/Dhaka")));$form = $this->createForm(SalesInvoiceType::class, $salesInvoice);$form->handleRequest($request);$salesInvoiceDetails = new SalesInvoiceDetails();$formDet = $this->createForm(SalesInvoiceDetailsType::class, $salesInvoiceDetails);$formDet->handleRequest($request);if ($request->isXMLHttpRequest()) {$salesInvoiceObj = $request->request->get('salesInvoiceObj');if (!empty($salesInvoiceObj)) {$salesInvoiceObj_array = json_decode($salesInvoiceObj, true);$hawbNo_array = json_decode($request->request->get('hawbNo'));$reference_array = json_decode($request->request->get('reference'));$country_array = json_decode($request->request->get('country'));$courier_array = json_decode($request->request->get('courier'));$productType_array = json_decode($request->request->get('productType'));$weight_array = json_decode($request->request->get('weight'));$bookingWeight_array = json_decode($request->request->get('bookingWeight'));$bookingRate_array = json_decode($request->request->get('bookingRate'));$salesRate_array = json_decode($request->request->get('salesRate'));// $agent_array = json_decode($request->request->get('agent'));// var_dump($accountNameId_array); die();$salesInvoiceDetailsList = new ArrayCollection();$gloPaymentReceived = $salesInvoiceObj_array['PaymentReceived'];$index = 0;foreach($hawbNo_array as $key=>$Row){$keyValue = $key;$keyValue = $keyValue + 1;$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInvoiceDetObj = $entityManager->getRepository(SalesInvoiceDetails::class)->findOneBy(['hawbNo' => $hawbNo_array[$index]]);if($salesInvoiceDetObj !== null){return new JsonResponse(array('success' => false, 'responseText' => 'Duplicate HAWB Number : '. $hawbNo_array[$index].' in Row Number '.$keyValue.'.'));}$salesInvoiceDetailsObj->setShipmentDate(new \DateTime($salesInvoiceObj_array['ShipmentDate']));$salesInvoiceDetailsObj->setHawbNo($hawbNo_array[$index]);$salesInvoiceDetailsObj->setReference($reference_array[$index]);$countryObj = $entityManager->find(Country::class, $country_array[$index]);$salesInvoiceDetailsObj->setCountry($countryObj);$courierObj = $entityManager->find(Courier::class, $courier_array[$index]);$salesInvoiceDetailsObj->setCourier($courierObj);$productTypeObj = $entityManager->find(ProductType::class, $productType_array[$index]);$salesInvoiceDetailsObj->setProductType($productTypeObj);$customerObj = $entityManager->find(Customer::class, $salesInvoiceObj_array['CustomerId']);$salesInvoiceDetailsObj->setCustomer($customerObj);$salesInvoiceDetailsObj->setWeight($weight_array[$index]);$salesInvoiceDetailsObj->setBookingWeight($bookingWeight_array[$index]);$salesInvoiceDetailsObj->setRateApplicable($salesInvoiceObj_array['RateApplicable']);// return new JsonResponse(array('success' => false, 'responseText' => $salesInvoiceObj_array['InvoiceApplicable'] ));// $salesInvoiceDetailsObj->setInvoiceStatus($salesInvoiceObj_array['InvoiceApplicable']);//Zone Assign Start// if($courier_array[$index] < 0)// {$courierWiseZoneObj = $entityManager->getRepository(CourierWiseZone::class)->findOneBy(['courier' => $courier_array[$index], 'country' => $country_array[$index] ]);if($courierWiseZoneObj === null ){return new JsonResponse(array('success' => false, 'responseText' => 'Courier Wise Zone is not set for Courier : '. $courierObj->getName().', and Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}$salesInvoiceDetailsObj->setZone($courierWiseZoneObj->getZone());//return new JsonResponse(array('success' => false, 'responseText' => $courierWiseZoneObj->getZone() ));// }// else// {// $courierWiseZoneObj = $this->getDoctrine()// ->getRepository(CourierWiseZone::class)// ->find(1);// }//Zone Assign End//Customer Weight Calculation Start// Half and Per KG$weight = trim($weight_array[$index]);$pointInputWeight = $weight - floor($weight);$intInputWeight = floor($weight);$finalWeight = 0;$rateWeight = 0;if($weight < $courierObj->getWeightPerkg()){if($pointInputWeight > 0 && $pointInputWeight <= 0.5){$finalWeight = (float)0.5;}elseif($pointInputWeight > 0.5 && $pointInputWeight <=1){$finalWeight = (float)1;}}else{if($pointInputWeight > 0 && $pointInputWeight <=1){$finalWeight = (float)1;}}$rateWeight = $intInputWeight + $finalWeight;//Only Per KG$pointInputPerKgWeight = $weight - floor($weight);$intInputPerKgWeight = floor($weight);$finalPerKgWeight = 0;$ratePerKgWeight = 0;if($pointInputPerKgWeight > 0 && $pointInputPerKgWeight <=1){$finalPerKgWeight = (float)1;}$ratePerKgWeight = $intInputPerKgWeight + $finalPerKgWeight;//Customer Weight Calculation End//Vendor/Booking weight Calculation Start// Half and Per KG$bookingWeight = trim($bookingWeight_array[$index]);$pointInputBookingWeight = $bookingWeight - floor($bookingWeight);$intInputBookingWeight = floor($bookingWeight);$finalBookingWeight = 0;$rateBookingWeight = 0;if($bookingWeight < $courierObj->getWeightPerkg()){if($pointInputBookingWeight > 0 && $pointInputBookingWeight <= 0.5){$finalBookingWeight = (float)0.5;}elseif($pointInputBookingWeight > 0.5 && $pointInputBookingWeight <=1){$finalBookingWeight = (float)1;}}else{if($pointInputBookingWeight > 0 && $pointInputBookingWeight <=1){$finalBookingWeight = (float)1;}}$rateBookingWeight = $intInputBookingWeight + $finalBookingWeight;//Only Per KG$pointInputPerKgBookingWeight = $bookingWeight - floor($bookingWeight);$intInputPerKgBookingWeight = floor($bookingWeight);$finalPerKgBookingWeight = 0;$ratePerKgBookingWeight = 0;if($pointInputPerKgBookingWeight > 0 && $pointInputPerKgBookingWeight <=1){$finalPerKgBookingWeight = (float)1;}$ratePerKgBookingWeight = $intInputPerKgBookingWeight + $finalPerKgBookingWeight;//Weight Calculation Endif($salesInvoiceObj_array['RateApplicable'] == 1) // Predefine Rate{//Master Rate Assign Start$finalMasterRateCal = 0;$perKgRateWeight = $courierObj->getWeightPerkgRate();if($rateBookingWeight < $perKgRateWeight ){$zoneWiseMasterRate = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($courierObj->getId(), $courierWiseZoneObj->getZone(), $productTypeObj->getId(), $rateBookingWeight);if($zoneWiseMasterRate !== null){$finalMasterRateCal = $zoneWiseMasterRate->getRate();}}else{$zoneWiseMasterRate = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($courierObj->getId(), $courierWiseZoneObj->getZone(), $productTypeObj->getId(), $rateBookingWeight);if($zoneWiseMasterRate !== null){$finalMasterRateCal = $zoneWiseMasterRate->getRate() * $rateBookingWeight;}}if($zoneWiseMasterRate === null){if($rateBookingWeight < $perKgRateWeight ){$countryWiseMasterRate = $entityManager->getRepository(CountryWiseMasterRate::class)->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getId(), 'weight' => $rateBookingWeight ]);if($countryWiseMasterRate !== null){$finalMasterRateCal = $countryWiseMasterRate->getRate();}}else{$countryWiseMasterRate = $entityManager->getRepository(CountryWiseMasterRate::class)->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getId(), 'weight' => $perKgRateWeight ]);if($countryWiseMasterRate !== null){$finalMasterRateCal = $countryWiseMasterRate->getRate() * $rateBookingWeight;}}}if($zoneWiseMasterRate !== null){$salesInvoiceDetailsObj->setBookingRate($finalMasterRateCal);}else if($countryWiseMasterRate !== null){$salesInvoiceDetailsObj->setBookingRate($finalMasterRateCal);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Master Rate is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}//Master Rate Assign End//Sales Rate Assign Start// if($customerObj->getRateCurrency() == 2)// {// $perKgRateWeight = 21;// }$finalRateCal = 0;// Own Company Rate for Customer Start$salesCourierId = 0;$salesCourierName = "";if($this->getUser()->getUserCompany()->getCustomerRate() == 2 ) // Own Company Wise Customer Rate{if($customerObj->getCustomerType() == 1 ) //Customer{$salesCourierId = $this->getUser()->getUserCompany()->getCompanyCourier()->getId();$salesCourierName = $this->getUser()->getUserCompany()->getCompanyCourier()->getName();return new JsonResponse(array('success' => false, 'responseText' => 1 ));}else //Agent{$salesCourierId = $courierObj->getId();$salesCourierName = $courierObj->getName();return new JsonResponse(array('success' => false, 'responseText' => 2 ));}}else // Separate Courier Wise Customer Rate{$salesCourierId = $courierObj->getId();$salesCourierName = $courierObj->getName();return new JsonResponse(array('success' => false, 'responseText' => 3 ));}// Own Company Rate for Customer Endif($customerObj->getRateType() == 1) // Customer wise sales rate{if($rateWeight < $perKgRateWeight ){$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($customerObj->getId(), $salesCourierId, $courierWiseZoneObj->getZone(), $productTypeObj->getId(), $rateWeight);if($zoneWiseSalesRate !== null){$finalRateCal = $zoneWiseSalesRate->getRate();}}else{$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($customerObj->getId(), $salesCourierId, $courierWiseZoneObj->getZone(), $productTypeObj->getId(), $rateWeight);if($zoneWiseSalesRate !== null){$finalRateCal = $zoneWiseSalesRate->getRate() * $rateWeight;}}if($zoneWiseSalesRate === null){if($rateWeight < $perKgRateWeight ){$countryWiseSalesRate = $entityManager->getRepository(CountryWiseSalesRate::class)->findOneBy(['customer' => $customerObj->getId(), 'courier' => $salesCourierId, 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getId(), 'weight' => $rateWeight ]);if($countryWiseSalesRate !== null){$finalRateCal = $countryWiseSalesRate->getRate();}}else{$countryWiseSalesRate = $entityManager->getRepository(CountryWiseSalesRate::class)->findOneBy(['customer' => $customerObj->getId(), 'courier' => $salesCourierId, 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getId(), 'weight' => $perKgRateWeight ]);if($countryWiseSalesRate !== null){$finalRateCal = $countryWiseSalesRate->getRate() * $rateWeight;}}}if($zoneWiseSalesRate !== null){$salesInvoiceDetailsObj->setSalesRate($finalRateCal);}else if($countryWiseSalesRate !== null){$salesInvoiceDetailsObj->setSalesRate($finalRateCal);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Customer Wise Sales Rate is not set for Customer '.$customerObj->getName().' Courier : '.$salesCourierName.', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}}else // Common sales rate{if($rateWeight < $perKgRateWeight ){$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseCommonSalesRate::class)->findCommonSalesRatebyCourierAndWeight($salesCourierId, $courierWiseZoneObj->getZone(), $productTypeObj->getId(), $rateWeight);}else{$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseCommonSalesRate::class)->findCommonSalesRatebyCourierAndWeight($salesCourierId, $courierWiseZoneObj->getZone(), $productTypeObj->getId(), $perKgRateWeight);if($zoneWiseSalesRate !== null){$zoneWiseSalesRate->setRate($zoneWiseSalesRate->getRate() * $rateWeight);}}if($zoneWiseSalesRate === null){if($rateWeight < $perKgRateWeight ){$countryWiseSalesRate = $entityManager->getRepository(CountryWiseCommonSalesRate::class)->findOneBy(['courier' => $salesCourierId, 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getId(), 'weight' => $rateWeight ]);}else{$countryWiseSalesRate = $entityManager->getRepository(CountryWiseCommonSalesRate::class)->findOneBy(['courier' => $salesCourierId, 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getId(), 'weight' => $perKgRateWeight ]);if($countryWiseSalesRate !== null){$countryWiseSalesRate->setRate($countryWiseSalesRate->getRate() * $rateWeight);}}}if($zoneWiseSalesRate !== null){$salesInvoiceDetailsObj->setSalesRate($zoneWiseSalesRate->getRate());}else if($countryWiseSalesRate !== null){$salesInvoiceDetailsObj->setSalesRate($countryWiseSalesRate->getRate());}else{return new JsonResponse(array('success' => false, 'responseText' => 'Common Sales Rate is not set for Courier : '.$salesCourierName.', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}}//Sales Rate Assign End}else // Special Calculated Rate{$salesInvoiceDetailsObj->setBookingRate($bookingRate_array[$index]);$salesInvoiceDetailsObj->setSalesRate($salesRate_array[$index]);}// if($salesInvoiceObj_array['RateApplicable'] <= 2) // Predefine Rate// {// if($customerObj->getRateCurrency() == 2)// {// $salesInvoiceDetailsObj->setCovidCharge(0);// }// else// {// //Covid Charge Cal Start// if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 1) // DHL Covid Charge Cal// {// $zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);// if($zoneWiseCovidCharge === null)// {// $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);// }// if($zoneWiseCovidCharge !== null)// {// $salesInvoiceDetailsObj->setCovidCharge($rateWeight <= 1 ? $zoneWiseCovidCharge->getRate() : $zoneWiseCovidCharge->getRate() * $rateWeight);// $salesInvoiceDetailsObj->setVendorCovidCharge($rateBookingWeight <= 1 ? $zoneWiseCovidCharge->getRate() : $zoneWiseCovidCharge->getRate() * $rateBookingWeight);// }// else if($countryWiseCovidCharge !== null)// {// $salesInvoiceDetailsObj->setCovidCharge($countryWiseCovidCharge->getRate() * $ratePerKgWeight);// }// else// {// return new JsonResponse(array('success' => false, 'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));// }// }// else if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 2) // Fedex Covid Charge Cal// {// if($courierWiseZoneObj->getZone()->getId() == 16 || $courierWiseZoneObj->getZone()->getId() == 18) // Zone G & I// {// if($rateWeight <= 1)// {// $salesInvoiceDetailsObj->setCovidCharge(1);// $salesInvoiceDetailsObj->setVendorCovidCharge(1);// }// else// {// $zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);// if($zoneWiseCovidCharge !== null)// {// $salesInvoiceDetailsObj->setCovidCharge($zoneWiseCovidCharge->getRate() * $rateWeight);// $salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);// }// else// {// return new JsonResponse(array('success' => false, 'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));// }// }// }// else if($courierWiseZoneObj->getZone()->getId() == 17) // Zone H// {// if($rateWeight <= 1)// {// $salesInvoiceDetailsObj->setCovidCharge(2);// $salesInvoiceDetailsObj->setVendorCovidCharge(2);// }// else// {// $zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);// if($zoneWiseCovidCharge !== null)// {// $salesInvoiceDetailsObj->setCovidCharge($zoneWiseCovidCharge->getRate() * $rateWeight);// $salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);// }// else// {// return new JsonResponse(array('success' => false, 'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));// }// }// }// else// {// if($rateWeight < 5)// {// $salesInvoiceDetailsObj->setCovidCharge(1);// $salesInvoiceDetailsObj->setVendorCovidCharge(1);// }// else// {// $zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);// if($zoneWiseCovidCharge !== null)// {// $salesInvoiceDetailsObj->setCovidCharge($zoneWiseCovidCharge->getRate() * $rateWeight);// $salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);// }// else// {// return new JsonResponse(array('success' => false, 'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));// }// }// }// }// //Covid Charge Cal End// }// }// else// {// $salesInvoiceDetailsObj->setCovidCharge(0);// }//Covid Charge Cal Startif($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 1) // DHL Covid Charge Cal{$zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);if($zoneWiseCovidCharge === null){$countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);}// Vendor Covid Charge Startif($zoneWiseCovidCharge !== null){$salesInvoiceDetailsObj->setVendorCovidCharge($rateBookingWeight <= 1 ? $zoneWiseCovidCharge->getRate() : $zoneWiseCovidCharge->getRate() * $rateBookingWeight);}else if($countryWiseCovidCharge !== null){$salesInvoiceDetailsObj->setVendorCovidCharge($countryWiseCovidCharge->getRate() * $ratePerKgWeight);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}// Vendor Covid Charge End//Customer Covid Charge Startif($salesInvoiceObj_array['RateApplicable'] <= 2) // Predefine Rate{if($customerObj->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCovidCharge(0);}else{if($zoneWiseCovidCharge !== null){$salesInvoiceDetailsObj->setCovidCharge($rateWeight <= 1 ? $zoneWiseCovidCharge->getRate() : $zoneWiseCovidCharge->getRate() * $rateWeight);}else if($countryWiseCovidCharge !== null){$salesInvoiceDetailsObj->setCovidCharge($countryWiseCovidCharge->getRate() * $ratePerKgWeight);}}}else{$salesInvoiceDetailsObj->setCovidCharge(0);}//Customer Covid Charge End}else if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 2) // Fedex Covid Charge Cal{if($courierWiseZoneObj->getZone()->getId() == 16 || $courierWiseZoneObj->getZone()->getId() == 18) // Zone G & I{// Vendor Covid Charge Startif($rateWeight <= 1){$salesInvoiceDetailsObj->setVendorCovidCharge(1);}else{$zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);if($zoneWiseCovidCharge !== null){$salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}}// Vendor Covid Charge Start// Customer Covid Charge Startif($salesInvoiceObj_array['RateApplicable'] <= 2) // Predefine Rate{if($customerObj->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCovidCharge(0);}else{if($rateWeight <= 1){$salesInvoiceDetailsObj->setCovidCharge(1);}else{$zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);if($zoneWiseCovidCharge !== null){$salesInvoiceDetailsObj->setCovidCharge($zoneWiseCovidCharge->getRate() * $rateWeight);}}}}else{$salesInvoiceDetailsObj->setCovidCharge(0);}// Customer Covid Charge End}else if($courierWiseZoneObj->getZone()->getId() == 17) // Zone H{// Vendor Covid Charge Startif($rateWeight <= 1){$salesInvoiceDetailsObj->setVendorCovidCharge(2);}else{$zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);if($zoneWiseCovidCharge !== null){$salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}}// Vendor Covid Charge End// Customer Covid Charge Startif($salesInvoiceObj_array['RateApplicable'] <= 2) // Predefine Rate{if($customerObj->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCovidCharge(0);}else{if($rateWeight <= 1){$salesInvoiceDetailsObj->setCovidCharge(2);$salesInvoiceDetailsObj->setVendorCovidCharge(2);}else{$zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);if($zoneWiseCovidCharge !== null){$salesInvoiceDetailsObj->setCovidCharge($zoneWiseCovidCharge->getRate() * $rateWeight);$salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);}}}}else{$salesInvoiceDetailsObj->setCovidCharge(0);}// Customer Covid Charge End}else{// Vendor Covid Charge Startif($rateWeight < 5){$salesInvoiceDetailsObj->setVendorCovidCharge(1);}else{$zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);if($zoneWiseCovidCharge !== null){$salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}}// Vendor Covid Charge End// Customer Covid Charge Startif($salesInvoiceObj_array['RateApplicable'] <= 2) // Predefine Rate{if($customerObj->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCovidCharge(0);}else{if($rateWeight < 5){$salesInvoiceDetailsObj->setCovidCharge(1);}else{$zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);if($zoneWiseCovidCharge !== null){$salesInvoiceDetailsObj->setCovidCharge($zoneWiseCovidCharge->getRate() * $rateWeight);}}}}else{$salesInvoiceDetailsObj->setCovidCharge(0);}// Customer Covid Charge End}}//Covid Charge Cal End$salesInvoiceDetailsList->add($salesInvoiceDetailsObj);$index ++;}//Data Save Process Start$index = 0;$individualSalesInvoiceId = 0;foreach($salesInvoiceDetailsList as $row){$keyValue = $key;$keyValue = $keyValue + 1;$shipmentDate = $row->getShipmentDate();// Get Settings Currency Start$settingsObj = $settingsInfoRepository->findByDate($shipmentDate->format('Y-m-d'));if($settingsObj === null){return new JsonResponse(array('success' => false, 'responseText' => 'Currency is not set in Settings for Month : '.$shipmentDate->format('F').'-'.$shipmentDate->format('Y').' in Row Number '.$keyValue.'.'));}// Get Settings Currency End$firstDateofMonth = date('Y-m-01', strtotime($shipmentDate->format('Y-m-d')));$lastDateofMonth = date('Y-m-t', strtotime($shipmentDate->format('Y-m-d')));$lastDateofMonth = new \DateTime($lastDateofMonth);$halfDateofMonth = date('Y-m-d', strtotime($firstDateofMonth. ' + 14 days'));$halfDateofMonth = new \DateTime($halfDateofMonth);if($row->getCustomer()->getRateCurrency() == 2){$row->setRateApplicable(3);}if($row->getCustomer()->getInvoicePeriod() == 1) //Monthly Invoice Save Process{$salesInvoiceObj = $salesInvoiceRepository->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $lastDateofMonth, $lastDateofMonth, 1, $row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );$invocieDate = $lastDateofMonth;if($salesInvoiceObj === null){$salesInv = new SalesInvoice();$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInv->setCustomer($row->getCustomer());$salesInvocieLastObj = $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());$invoiceNO = $utilsService->invoiceNoGenerator($salesInvocieLastObj, $row->getCustomer(), $invocieDate);$salesInv->setInvoiceNo($invoiceNO);$salesInv->setInvoiceDate($invocieDate);$salesInv->setVat($settingsObj->getVat());$salesInv->setApproval(0);$salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());$salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());$salesInv->setRateApplicable($row->getRateApplicable());$salesInv->setInvoiceType(1);$salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());$salesInvoiceDetailsObj->setReference($row->getReference());$salesInvoiceDetailsObj->setWeight($row->getWeight());$salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());$salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());$salesInvoiceDetailsObj->setCountry($row->getCountry());$salesInvoiceDetailsObj->setZone($row->getZone());$salesInvoiceDetailsObj->setProductType($row->getProductType());$salesInvoiceDetailsObj->setCourier($row->getCourier());$salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());$salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());if($row->getCustomer()->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCurrency(1);}else{$salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == 0 ? $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );}$salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());$salesInvoiceDetailsObj->setVatApplicable(0);$salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());if($row->getRateApplicable() <= 2)$salesInvoiceDetailsObj->setFsc( $row->getCustomer()->getFsc() == 0 ? $row->getCourier()->getFsc() : $row->getCustomer()->getFsc() );else$salesInvoiceDetailsObj->setFsc(0);$salesInvoiceDetailsObj->setVendorFsc($row->getCourier()->getFsc());$salesInvoiceDetailsObj->setCustomer($row->getCustomer());$salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null ? 0 : $row->getCovidCharge());$salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null ? 0 : $row->getVendorCovidCharge());$salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);$entityManager->persist($salesInv);$entityManager->flush($salesInv);$salesInvoiceId = $salesInv->getId();}else{$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());$salesInvoiceDetailsObj->setReference($row->getReference());$salesInvoiceDetailsObj->setWeight($row->getWeight());$salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());$salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());$salesInvoiceDetailsObj->setCountry($row->getCountry());$salesInvoiceDetailsObj->setZone($row->getZone());$salesInvoiceDetailsObj->setProductType($row->getProductType());$salesInvoiceDetailsObj->setCourier($row->getCourier());$salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());$salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());if($row->getCustomer()->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCurrency(1);}else{$salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == 0 ? $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );}$salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());$salesInvoiceDetailsObj->setVatApplicable(0);$salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());if($row->getRateApplicable() <= 2)$salesInvoiceDetailsObj->setFsc( $row->getCustomer()->getFsc() == 0 ? $row->getCourier()->getFsc() : $row->getCustomer()->getFsc() );else$salesInvoiceDetailsObj->setFsc(0);$salesInvoiceDetailsObj->setVendorFsc($row->getCourier()->getFsc());$salesInvoiceDetailsObj->setCustomer($row->getCustomer());$salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null ? 0 : $row->getCovidCharge());$salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null ? 0 : $row->getVendorCovidCharge());$salesInvoiceDetailsObj->setSalesInvoice($salesInvoiceObj);$entityManager->persist($salesInvoiceDetailsObj);$entityManager->flush($salesInvoiceDetailsObj);}}else if($row->getCustomer()->getInvoicePeriod() == 2) //Half Monthly Invoice Save Process{if($shipmentDate <= $halfDateofMonth) // First Half month{$salesInvoiceObj = $salesInvoiceRepository->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $halfDateofMonth, $halfDateofMonth, 1, $row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );$invocieDate = $halfDateofMonth;}else{$salesInvoiceObj = $salesInvoiceRepository->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $lastDateofMonth, $lastDateofMonth, 1, $row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );$invocieDate = $lastDateofMonth;}////////////////Common portionif($salesInvoiceObj === null){$salesInv = new SalesInvoice();$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInv->setCustomer($row->getCustomer());$salesInvocieLastObj = $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());$invoiceNO = $utilsService->invoiceNoGenerator($salesInvocieLastObj, $row->getCustomer(), $invocieDate);$salesInv->setInvoiceNo($invoiceNO);$salesInv->setInvoiceDate($invocieDate);$salesInv->setVat($settingsObj->getVat());$salesInv->setApproval(0);$salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());$salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());$salesInv->setRateApplicable($row->getRateApplicable());$salesInv->setInvoiceType(1);$salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());$salesInvoiceDetailsObj->setReference($row->getReference());$salesInvoiceDetailsObj->setWeight($row->getWeight());$salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());$salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());$salesInvoiceDetailsObj->setCountry($row->getCountry());$salesInvoiceDetailsObj->setZone($row->getZone());$salesInvoiceDetailsObj->setProductType($row->getProductType());$salesInvoiceDetailsObj->setCourier($row->getCourier());$salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());$salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());if($row->getCustomer()->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCurrency(1);}else{$salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == 0 ? $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );}$salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());$salesInvoiceDetailsObj->setVatApplicable(0);$salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());if($row->getRateApplicable() <= 2)$salesInvoiceDetailsObj->setFsc( $row->getCustomer()->getFsc() == 0 ? $row->getCourier()->getFsc() : $row->getCustomer()->getFsc() );else$salesInvoiceDetailsObj->setFsc(0);$salesInvoiceDetailsObj->setVendorFsc($row->getCourier()->getFsc());$salesInvoiceDetailsObj->setCustomer($row->getCustomer());$salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null ? 0 : $row->getCovidCharge());$salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null ? 0 : $row->getVendorCovidCharge());$salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);$entityManager->persist($salesInv);$entityManager->flush($salesInv);$salesInvoiceId = $salesInv->getId();}else{$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());$salesInvoiceDetailsObj->setReference($row->getReference());$salesInvoiceDetailsObj->setWeight($row->getWeight());$salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());$salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());$salesInvoiceDetailsObj->setCountry($row->getCountry());$salesInvoiceDetailsObj->setZone($row->getZone());$salesInvoiceDetailsObj->setProductType($row->getProductType());$salesInvoiceDetailsObj->setCourier($row->getCourier());$salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());$salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());if($row->getCustomer()->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCurrency(1);}else{$salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == 0 ? $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );}$salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());$salesInvoiceDetailsObj->setVatApplicable(0);$salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());if($row->getRateApplicable() <= 2)$salesInvoiceDetailsObj->setFsc( $row->getCustomer()->getFsc() == 0 ? $row->getCourier()->getFsc() : $row->getCustomer()->getFsc() );else$salesInvoiceDetailsObj->setFsc(0);$salesInvoiceDetailsObj->setVendorFsc($row->getCourier()->getFsc());$salesInvoiceDetailsObj->setCustomer($row->getCustomer());$salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null ? 0 : $row->getCovidCharge());$salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null ? 0 : $row->getVendorCovidCharge());$salesInvoiceDetailsObj->setSalesInvoice($salesInvoiceObj);$entityManager->persist($salesInvoiceDetailsObj);$entityManager->flush($salesInvoiceDetailsObj);}/////////////Common}else // HAWB NO Wise Invoice Save Process{$salesInv = new SalesInvoice();$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInv->setCustomer($row->getCustomer());$salesInvocieLastObj = $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());$invoiceNO = $utilsService->invoiceNoGenerator($salesInvocieLastObj, $row->getCustomer(), $shipmentDate);$salesInv->setInvoiceNo($invoiceNO);$salesInv->setInvoiceDate($shipmentDate);$salesInv->setVat($settingsObj->getVat());$salesInv->setApproval(0);$salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());$salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());$salesInv->setRateApplicable($row->getRateApplicable());$salesInv->setInvoiceType(1);$salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());$salesInvoiceDetailsObj->setReference($row->getReference());$salesInvoiceDetailsObj->setWeight($row->getWeight());$salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());$salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());$salesInvoiceDetailsObj->setCountry($row->getCountry());$salesInvoiceDetailsObj->setZone($row->getZone());$salesInvoiceDetailsObj->setProductType($row->getProductType());$salesInvoiceDetailsObj->setCourier($row->getCourier());$salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());$salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());if($row->getCustomer()->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCurrency(1);}else{$salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == 0 ? $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );}$salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());$salesInvoiceDetailsObj->setVatApplicable(0);$salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());if($row->getRateApplicable() <= 2)$salesInvoiceDetailsObj->setFsc( $row->getCustomer()->getFsc() == 0 ? $row->getCourier()->getFsc() : $row->getCustomer()->getFsc() );else$salesInvoiceDetailsObj->setFsc(0);$salesInvoiceDetailsObj->setVendorFsc($row->getCourier()->getFsc());$salesInvoiceDetailsObj->setCustomer($row->getCustomer());$salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null ? 0 : $row->getCovidCharge());$salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null ? 0 : $row->getVendorCovidCharge());$salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);$entityManager->persist($salesInv);$entityManager->flush($salesInv);$salesInvoiceId = $salesInv->getId();if($gloPaymentReceived == 1 && $salesInvoiceId > 0){$salesValue = $salesInvoiceRepository->getSingalSalesValueCalculation($salesInvoiceId);$receiveVoucher = new ReceiveVoucher();$receiveVoucher->setSalesInvoice($salesInvoiceRepository->find($salesInvoiceId));$receiveVoucher->setDescription('N/A');$receiveVoucher->setReceiveDate(new \DateTime('now'));//Start Reference no Generate $salesInvoiceObj_array['ShipmentDate']$receiveVoucherLastObj = $receiveVoucherRepository->findLastObjReceiveVoucher();$now = new \DateTime('now');$year = substr($now->format('Y'),2);$refNO = "";$serialNo = "";if(null !== $receiveVoucherLastObj)$refYear = substr($receiveVoucherLastObj->getVoucherno(),-2);else$refYear = 20;if($receiveVoucherLastObj == null){$refNO = "RV-00001/".$year;}else if($year != $refYear){$refNO = "RV-00001/".$year;}else{$serialNo = substr($receiveVoucherLastObj->getVoucherno(),-8,-3);$serialNo += 1;$serialNo = str_pad($serialNo,5,"0",STR_PAD_LEFT);$refNO ="RV-".$serialNo."/".$year;}//End Reference no Generate$receiveVoucher->setVoucherno($refNO);$debitAccountName = $accountNameRepository->find(1);$receiveVoucher->setDebitAccount($debitAccountName);$creditAccountName = $accountNameRepository->find(3);$receiveVoucher->setCreditAccount($creditAccountName);$receiveVoucher->setReceiveAmount($salesValue[0]);$receiveVoucherRepository->save($receiveVoucher, true);}}$index ++;}$this->addFlash('notice', 'Booking Created successfully!');return new JsonResponse(array('success' => true));}}// if ($form->isSubmitted() && $form->isValid()) {// $salesInvoiceRepository->save($salesInvoice, true);// return $this->redirectToRoute('app_sales_invoice_index', [], Response::HTTP_SEE_OTHER);// }return $this->renderForm('sales_invoice/new.html.twig', ['sales_invoice' => $salesInvoice,'form' => $form,'formDet' => $formDet,]);}#[Route('/salesinvoice/{id}/show', name: 'app_sales_invoice_show', methods: ['GET'])]public function show(SalesInvoice $salesInvoice, Request $request, ReceiveVoucherRepository $receiveVoucherRepository): Response{$searchForm = $this->createFormBuilder(null)->add('reference', EntityType::class, [// looks for choices from this entity'class' => SalesInvoiceDetails::class,'query_builder' => function (SalesInvoiceDetailsRepository $er) use ($salesInvoice) {return $er->createQueryBuilder('v')->where('v.salesInvoice = '.$salesInvoice->getId())->orderBy('v.reference', 'ASC')->groupBy('v.reference');},// uses the User.username property as the visible option string'choice_label' => 'reference','placeholder' => 'Select a Reference...','attr' => ['class' => 'form-control select-tags','style' => 'width:100%;',],'label' => 'Reference Name',// used to render a select box, check boxes or radios// 'multiple' => true,// 'expanded' => true,])->getForm();$searchForm->handleRequest($request);$receiveVoucherList = $receiveVoucherRepository->findBy(array('salesInvoice' => $salesInvoice->getId()));return $this->render('sales_invoice/show.html.twig', ['sales_invoice' => $salesInvoice,'receiveVoucherList' => $receiveVoucherList,'searchForm' => $searchForm->createView(),]);}#[Route('/salesinvoice/{id}/search-show/', name: 'app_sales_invoice_search_show', methods: ['GET'])]public function searchShow(SalesInvoiceDetails $salesInvoiceDetailsObj, SalesInvoiceDetailsRepository $salesInvoiceDetailsRepository): Response{$salesInvoiceDetails = $salesInvoiceDetailsRepository->findByReference($salesInvoiceDetailsObj->getSalesInvoice()->getId(),$salesInvoiceDetailsObj->getReference());return $this->render('sales_invoice/search_show.html.twig', ['sales_invoice' => $salesInvoiceDetailsObj->getSalesInvoice(),'salesInvoiceDetails' => $salesInvoiceDetails,]);}#[Route('/salesinvoice/{id}/edit', name: 'app_sales_invoice_edit', methods: ['GET', 'POST'])]#[IsGranted("ROLE_ACCOUNTS")]public function edit(Request $request, SalesInvoice $salesInvoice, SalesInvoiceRepository $salesInvoiceRepository, CountryRepository $countryRepository, CourierRepository $courierRepository, ProductTypeRepository $productTypeRepository, SalesInvoiceDetailsRepository $salesInvoiceDetailsRepository, EntityManagerInterface $entityManager, SettingsInfoRepository $settingsInfoRepository): Response{// Start remove item by Edit// Original Order details$originalSalesInvoiceDetails = new ArrayCollection();$originalInvoiceAdditionalCharge = new ArrayCollection();foreach($salesInvoice->getSalesInvoiceDetails() as $invoiceDetail){$originalSalesInvoiceDetails->add($invoiceDetail);foreach($invoiceDetail->getInvoiceAdditionalCharges() as $invAdditionalCharge){$originalInvoiceAdditionalCharge->add($invAdditionalCharge);}}// End remove item by Edit$form = $this->createForm(SalesInvoiceEditType::class, $salesInvoice);$form->handleRequest($request);$countryList = $countryRepository->findAll();$courierList = $courierRepository->findAll();$productTypeList = $productTypeRepository->findAll();$additionalChargeList = $entityManager->getRepository(AdditionalCharge::class)->findAll();if ($request->isXMLHttpRequest()) {//return new JsonResponse(array('success' => false, 'responseText' => $salesInvoice->getInvoiceno() ));$salesInvoiceObj = $request->request->get('salesInvoiceObj');if (!empty($salesInvoiceObj)) {$salesInvoiceObj_array = json_decode($salesInvoiceObj, true);$shipmentDate_array = json_decode($request->request->get('shipmentDate'));$hawbNo_array = json_decode($request->request->get('hawbNo'));$reference_array = json_decode($request->request->get('reference'));$country_array = json_decode($request->request->get('country'));$courier_array = json_decode($request->request->get('courier'));$productType_array = json_decode($request->request->get('productType'));$weight_array = json_decode($request->request->get('weight'));$vendorWeight_array = json_decode($request->request->get('vendorWeight'));$bookingRate_array = json_decode($request->request->get('bookingRate'));$salesRate_array = json_decode($request->request->get('salesRate'));$fsc_array = json_decode($request->request->get('fsc'));$vendorCovidCharge_array = json_decode($request->request->get('vendorCovidCharge'));$covidCharge_array = json_decode($request->request->get('covidCharge'));$customerCurrency_array = json_decode($request->request->get('customerCurrency'));$vendorCurrency_array = json_decode($request->request->get('vendorCurrency'));$invoiceDetailsId_array = json_decode($request->request->get('invoiceDetailsId'));$vatApplicable_array = json_decode($request->request->get('vatApplicable'));$vendorVatApplicable_array = json_decode($request->request->get('vendorVatApplicable'));$vendorFsc_array = json_decode($request->request->get('vendorFsc'));$additionalCharge_array = json_decode($request->request->get('additionalCharge'));$additionalPayableAmount_array = json_decode($request->request->get('additionalPayableAmount'));$additionalReceivableAmount_array = json_decode($request->request->get('additionalReceivableAmount'));$additionalFscApplicable_array = json_decode($request->request->get('additionalFscApplicable'));$additionalVatApplicable_array = json_decode($request->request->get('additionalVatApplicable'));$additionalChargeId_array = json_decode($request->request->get('additionalChargeId'));// var_dump($accountNameId_array); die();// return new JsonResponse(array('success' => false, 'responseText' => $salesInvoiceObj_array['CustomerId'] ));$customerObj = $entityManager->find(Customer::class, $salesInvoiceObj_array['CustomerId']);$salesInvoice->setCustomer($customerObj);$salesInvoice->setInvoiceNo($salesInvoiceObj_array['Invoiceno']);$salesInvoice->setInvoiceDate(new \DateTime($salesInvoiceObj_array['Invoicedate']));$salesInvoice->setVat($salesInvoiceObj_array['Vat']);$salesInvoice->setPreviousDues($salesInvoiceObj_array['Previousdues']);$salesInvoice->setApproval($salesInvoiceObj_array['Approval']);$salesInvoice->setPaymentNote($salesInvoiceObj_array['PaymentNote']);$salesInvoice->setRateApplicable($salesInvoiceObj_array['RateApplicable']);$salesInvoice->setRemarks($salesInvoiceObj_array['Remarks']);if($salesInvoiceObj_array['Submissiondate'] == '')$salesInvoice->setSubmissionDate(new \DateTime($salesInvoiceObj_array['Invoicedate']));else$salesInvoice->setSubmissionDate(new \DateTime($salesInvoiceObj_array['Submissiondate']));$salesInvoice->getSalesInvoiceDetails()->clear();$index = 0;foreach($hawbNo_array as $key=>$row){$keyValue = $key;$keyValue = $keyValue + 1;if($invoiceDetailsId_array[$index] !== null){// $salesInvoiceDetailsObj = $salesInvoiceDetailsRepository->find($invoiceDetailsId_array[$index]);// $salesInvoiceDetailsObj->getInvoiceAdditionalCharges()->clear();// $salesInvoiceDetailsObj->setShipmentDate(new \DateTime($shipmentDate_array[$index]));// $salesInvoiceDetailsObj->setHawbNo($hawbNo_array[$index]);// $salesInvoiceDetailsObj->setReference($reference_array[$index]);// $countryObj = $countryRepository->find($country_array[$index]);// $salesInvoiceDetailsObj->setCountry($countryObj);// $courierObj = $courierRepository->find($courier_array[$index]);// $salesInvoiceDetailsObj->setCourier($courierObj);// $productTypeObj =$productTypeRepository->find($productType_array[$index]);// $salesInvoiceDetailsObj->setProductType($productTypeObj);// $salesInvoiceDetailsObj->setWeight($weight_array[$index]);// $salesInvoiceDetailsObj->setBookingWeight($vendorWeight_array[$index]);// $salesInvoiceDetailsObj->setBookingRate($bookingRate_array[$index]);// $salesInvoiceDetailsObj->setSalesRate($salesRate_array[$index]);// $salesInvoiceDetailsObj->setFsc($fsc_array[$index]);// $salesInvoiceDetailsObj->setVendorCovidCharge($vendorCovidCharge_array[$index]);// $salesInvoiceDetailsObj->setCovidCharge($covidCharge_array[$index]);// $salesInvoiceDetailsObj->setCurrency($customerCurrency_array[$index]);// $salesInvoiceDetailsObj->setVendorCurrency($vendorCurrency_array[$index]);// $salesInvoiceDetailsObj->setVatApplicable($vatApplicable_array[$index]);// $salesInvoiceDetailsObj->setVendorVatApplicable($vendorVatApplicable_array[$index]);// $salesInvoiceDetailsObj->setVendorFsc($vendorFsc_array[$index]);// $salesInvoice->addSalesInvoiceDetail($salesInvoiceDetailsObj);/////////////return new JsonResponse(array('success' => false, 'responseText' => $invoiceDetailsId_array[$index] ));$salesInvDetailsObj = $salesInvoiceDetailsRepository->find($invoiceDetailsId_array[$index]);$countryObj = $countryRepository->find($country_array[$index]);$salesInvDetailsObj->setCountry($countryObj);$courierObj = $courierRepository->find($courier_array[$index]);$salesInvDetailsObj->setCourier($courierObj);// Rate Type get Start Here getRateType()if($courierObj->getZoneRateType() !== null)$zoneWiseMasterRateTypeObj = $entityManager->find(ZoneWiseMasterRate::class, $courierObj->getZoneRateType());else$zoneWiseMasterRateTypeObj = new ZoneWiseMasterRate();// Rate Type get End Here$productTypeObj =$productTypeRepository->find($productType_array[$index]);$salesInvDetailsObj->setProductType($productTypeObj);$shipmentObj = $salesInvDetailsObj->getShipment();$shipmentDate = new \DateTime($shipmentDate_array[$index]);// $salesInvDetailsObj->setRateApplicable(!$salesInvDetailsObj->isExpedite() ? $customerObj->getRateType() : 5); // Expedite Rate Type 5$courierWiseZoneObj = $entityManager->getRepository(CourierWiseZone::class)->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);if($courierWiseZoneObj === null ){return new JsonResponse(array('success' => false, 'responseText' => 'Courier Wise Zone is not set for Courier : '. $courierObj->getName().', and Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}$salesInvDetailsObj->setZone($courierWiseZoneObj->getZone());$salesInvDetailsObj->setShipmentDate(new \DateTime($shipmentDate_array[$index]));$salesInvDetailsObj->setHawbNo($hawbNo_array[$index]);$salesInvDetailsObj->setReference($reference_array[$index]);$salesInvDetailsObj->setWeight($weight_array[$index]);$salesInvDetailsObj->setBookingWeight($vendorWeight_array[$index]);$salesInvDetailsObj->setVatApplicable($vatApplicable_array[$index]);//Customer Weight Calculation Start// Half and Per KG$weight = $weight_array[$index];$pointInputWeight = $weight - floor($weight);$intInputWeight = floor($weight);$finalWeight = 0;$rateWeight = 0;if($weight < $courierObj->getWeightPerkg()){if($pointInputWeight > 0 && $pointInputWeight <= 0.5){$finalWeight = (float)0.5;}elseif($pointInputWeight > 0.5 && $pointInputWeight <=1){$finalWeight = (float)1;}}else{if($pointInputWeight > 0 && $pointInputWeight <=1){$finalWeight = (float)1;}}$rateWeight = $intInputWeight + $finalWeight;//Only Per KG$pointInputPerKgWeight = $weight - floor($weight);$intInputPerKgWeight = floor($weight);$finalPerKgWeight = 0;$ratePerKgWeight = 0;if($pointInputPerKgWeight > 0 && $pointInputPerKgWeight <=1){$finalPerKgWeight = (float)1;}$ratePerKgWeight = $intInputPerKgWeight + $finalPerKgWeight;//Customer Weight Calculation End//Vendor/Booking weight Calculation Start// Half and Per KG$bookingWeight = trim($vendorWeight_array[$index]);$pointInputBookingWeight = $bookingWeight - floor($bookingWeight);$intInputBookingWeight = floor($bookingWeight);$finalBookingWeight = 0;$rateBookingWeight = 0;if($bookingWeight < $courierObj->getWeightPerkg()){if($pointInputBookingWeight > 0 && $pointInputBookingWeight <= 0.5){$finalBookingWeight = (float)0.5;}elseif($pointInputBookingWeight > 0.5 && $pointInputBookingWeight <=1){$finalBookingWeight = (float)1;}}else{if($pointInputBookingWeight > 0 && $pointInputBookingWeight <=1){$finalBookingWeight = (float)1;}}$rateBookingWeight = $intInputBookingWeight + $finalBookingWeight;//Only Per KG$pointInputPerKgBookingWeight = $bookingWeight - floor($bookingWeight);$intInputPerKgBookingWeight = floor($bookingWeight);$finalPerKgBookingWeight = 0;$ratePerKgBookingWeight = 0;if($pointInputPerKgBookingWeight > 0 && $pointInputPerKgBookingWeight <=1){$finalPerKgBookingWeight = (float)1;}$ratePerKgBookingWeight = $intInputPerKgBookingWeight + $finalPerKgBookingWeight;//Weight Calculation End//return new JsonResponse(array('success' => false, 'responseText' => $salesInvDetailsObj->getRateApplicable() ));// Get Settings Currency Start$settingsObj = $settingsInfoRepository->findByDateCurrency(1, $salesInvDetailsObj->getShipmentDate()->format('Y-m-d'));if($settingsObj === null){return new JsonResponse(array('success' => false, 'responseText' => 'Currency is not set in Settings for Month : '.$salesInvDetailsObj->getShipmentDate()->format('F').'-'.$salesInvDetailsObj->getShipmentDate()->format('Y').' in Row Number '.$keyValue.'.'));}// Get Settings Currency End//Master Rate Assign Startif($salesInvDetailsObj->getShipment() === null ){// Accessaccessory Surcharge$salesInvDetailsObj->setBookingRate($bookingRate_array[$index]);}else if(!$salesInvDetailsObj->getShipment()->isExpedite() && $salesInvDetailsObj->getShipment() !== null){$finalMasterRateCal = 0;$perKgRateWeight = $courierObj->getWeightPerkgRate();if($courierObj->getId() != 3){if($rateBookingWeight < $perKgRateWeight ){$countryWiseMasterRate = $entityManager->getRepository(CountryWiseMasterRate::class)->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateBookingWeight ]);if($countryWiseMasterRate !== null){$finalMasterRateCal = $countryWiseMasterRate->getRate();}}else{$countryWiseMasterRate = $entityManager->getRepository(CountryWiseMasterRate::class)->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);if($countryWiseMasterRate !== null){$finalMasterRateCal = $countryWiseMasterRate->getRate() * $rateBookingWeight;}}if($countryWiseMasterRate === null){if($rateBookingWeight < $perKgRateWeight ){$zoneWiseMasterRate = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $zoneWiseMasterRateTypeObj->getRateType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight);if($zoneWiseMasterRate !== null){$finalMasterRateCal = $zoneWiseMasterRate->getRate();}}else{$zoneWiseMasterRate = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $zoneWiseMasterRateTypeObj->getRateType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $courierObj->getId() == 3 ? $perKgRateWeight : $rateBookingWeight );if($zoneWiseMasterRate !== null){$finalMasterRateCal = $zoneWiseMasterRate->getRate() * $rateBookingWeight;}}}if($countryWiseMasterRate !== null){$salesInvDetailsObj->setBookingRate($finalMasterRateCal);}else if($zoneWiseMasterRate !== null){$salesInvDetailsObj->setBookingRate($finalMasterRateCal);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Master Rate is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}}else{if($rateBookingWeight <= 30){$zoneWiseMasterRate = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(),$zoneWiseMasterRateTypeObj->getRateType(),$courierObj->getId(),$courierWiseZoneObj->getZone()->getId(),$productTypeObj->getRateid(),$rateBookingWeight);$finalRate = $zoneWiseMasterRate->getRate();}else if($rateBookingWeight > 30 && $rateBookingWeight <= 70){$zoneWiseMasterRateFs = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(),$zoneWiseMasterRateTypeObj->getRateType(),$courierObj->getId(),$courierWiseZoneObj->getZone()->getId(),$productTypeObj->getRateid(),30);$zoneWiseMasterRateSs = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(),$zoneWiseMasterRateTypeObj->getRateType(),$courierObj->getId(),$courierWiseZoneObj->getZone()->getId(),$productTypeObj->getRateid(),31);$finalRate = $zoneWiseMasterRateFs->getRate() + (($rateBookingWeight - 30) * $zoneWiseMasterRateSs->getRate());}else if($rateBookingWeight > 70){$zoneWiseMasterRateFs = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(),$zoneWiseMasterRateTypeObj->getRateType(),$courierObj->getId(),$courierWiseZoneObj->getZone()->getId(),$productTypeObj->getRateid(),30);$zoneWiseMasterRateSs = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(),$zoneWiseMasterRateTypeObj->getRateType(),$courierObj->getId(),$courierWiseZoneObj->getZone()->getId(),$productTypeObj->getRateid(),31);$zoneWiseMasterRateTs = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(),$zoneWiseMasterRateTypeObj->getRateType(),$courierObj->getId(),$courierWiseZoneObj->getZone()->getId(),$productTypeObj->getRateid(),71);$finalRate = $zoneWiseMasterRateFs->getRate() + (40 * $zoneWiseMasterRateSs->getRate()) + (($rateBookingWeight - 70) * $zoneWiseMasterRateTs->getRate());}$salesInvDetailsObj->setBookingRate($finalRate);}}else{// Expedite Rate// $salesInvDetailsObj->setBookingRate($countryObj->getMasterExpediteRate() * $rateBookingWeight);// Expedite Or Cash Master Rate$countryWiseCashMasterRate = $entityManager->getRepository(CountryWiseMasterRate::class)->findCashBookingRatebyCourierAndWeight(2, $salesInvDetailsObj->getShipmentDate(), $courierObj->getId(), $countryObj->getId(), $productTypeObj->getRateid(), $rateBookingWeight);if($countryWiseCashMasterRate == null){$zoneWiseMasterRate = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingCashRatebyCourierAndWeight(3, $salesInvDetailsObj->getShipmentDate(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight );}if($countryWiseCashMasterRate !== null){$salesInvDetailsObj->setBookingRate($countryWiseCashMasterRate->getRate() * $rateBookingWeight);}else if($zoneWiseMasterRate !== null){$salesInvDetailsObj->setBookingRate(round(($zoneWiseMasterRate->getRate() * $rateBookingWeight) / $settingsObj->getCurrency(),2));}else{return new JsonResponse(array('success' => false, 'responseText' => 'Cash Master Rate is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}// return new JsonResponse(array('success' => false, 'responseText' => 3 ));}//Master Rate Assign End// Own Company Rate for Customer Start$salesCourierId = 0;$salesCourierName = "";$salesZoneId = 0;if($this->getUser()->getUserCompany()->getCustomerRate() == 2 ) // Own Company Wise Customer Rate{if($customerObj->getCustomerType() == 1 ) //Customer{$salesCourierId = $this->getUser()->getUserCompany()->getCompanyCourier()->getId();$salesCourierName = $this->getUser()->getUserCompany()->getCompanyCourier()->getName();/// Zone$courierWiseZoneObject = $entityManager->getRepository(CourierWiseZone::class)->findOneBy(['courier' => $salesCourierId, 'country' => $countryObj->getId() ]);if($courierWiseZoneObject === null ){return new JsonResponse(array('success' => false, 'responseText' => 'Courier Wise Zone is not set for Courier : '. $courierObj->getName().', and Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}$salesZoneId = $courierWiseZoneObject->getZone()->getId();}else //Agent{$salesCourierId = $courierObj->getId();$salesCourierName = $courierObj->getName();$salesZoneId = $courierWiseZoneObj->getZone()->getId();}}else // Separate Courier Wise Customer Rate{$salesCourierId = $courierObj->getId();$salesCourierName = $courierObj->getName();$salesZoneId = $courierWiseZoneObj->getZone()->getId();}// Own Company Rate for Customer End// return new JsonResponse(array('success' => false, 'responseText' => 123 ));if($salesInvDetailsObj->getRateApplicable() <= 2 && $salesInvDetailsObj->getShipment() === null){// Accessaccessory Surcharge$salesInvDetailsObj->setSalesRate($salesRate_array[$index]);}else if($salesInvDetailsObj->getRateApplicable() <= 2 && !$salesInvDetailsObj->getShipment()->isExpedite() && $salesInvDetailsObj->getShipment() !== null) // Predefine Rate{//Sales Rate Assign Start// if($customerObj->getRateCurrency() == 2)// {// $perKgRateWeight = 21;// }$finalRateCal = 0;if($customerObj->getRateType() == 1) // Customer wise sales rate{if($courierObj->getId() != 3){if($rateWeight < $perKgRateWeight ){$countryWiseSalesRate = $entityManager->getRepository(CountryWiseSalesRate::class)->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $salesCourierId, 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateWeight ]);if($countryWiseSalesRate !== null){$finalRateCal = $countryWiseSalesRate->getRate();}}else{$countryWiseSalesRate = $entityManager->getRepository(CountryWiseSalesRate::class)->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $salesCourierId, 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);if($countryWiseSalesRate !== null){$finalRateCal = $countryWiseSalesRate->getRate() * $rateWeight;}}if($countryWiseSalesRate === null){if($rateWeight < $perKgRateWeight ){$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $customerObj->getId(), $salesCourierId, $salesZoneId, $productTypeObj->getRateid(), $rateWeight);if($zoneWiseSalesRate !== null){$finalRateCal = $zoneWiseSalesRate->getRate();}}else{$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $customerObj->getId(), $salesCourierId, $salesZoneId, $productTypeObj->getRateid(), $courierObj->getId() == 3 ? $perKgRateWeight : $rateWeight );if($zoneWiseSalesRate !== null){$finalRateCal = $zoneWiseSalesRate->getRate() * $rateWeight;}}}if($countryWiseSalesRate !== null){$salesInvDetailsObj->setSalesRate($finalRateCal);}else if($zoneWiseSalesRate !== null){$salesInvDetailsObj->setSalesRate($finalRateCal);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Customer Wise Sales Rate is not set for Customer : '.$customerObj->getName().' Courier : '.$salesCourierName.', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}}else{if($rateWeight <= 30){$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(),$customerObj->getId(),$salesCourierId,$salesZoneId,$productTypeObj->getRateid(),$rateWeight);$finalSalesRate = $zoneWiseSalesRate->getRate();}else if($rateWeight > 30 && $rateWeight <= 70){$zoneWiseSalesRateFs = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(),$customerObj->getId(),$salesCourierId,$salesZoneId,$productTypeObj->getRateid(),30);$zoneWiseSalesRateSs = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(),$customerObj->getId(),$salesCourierId,$salesZoneId,$productTypeObj->getRateid(),31);$finalSalesRate = $zoneWiseSalesRateFs->getRate() + (($rateWeight - 30) * $zoneWiseSalesRateSs->getRate());}else if($rateWeight > 70){$zoneWiseSalesRateFs = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(),$customerObj->getId(),$salesCourierId,$salesZoneId,$productTypeObj->getRateid(),30);$zoneWiseSalesRateSs = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(),$customerObj->getId(),$salesCourierId,$salesZoneId,$productTypeObj->getRateid(),31);$zoneWiseSalesRateTs = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(),$customerObj->getId(),$salesCourierId,$salesZoneId,$productTypeObj->getRateid(),71);$finalSalesRate = $zoneWiseSalesRateFs->getRate() + (40 * $zoneWiseSalesRateSs->getRate()) + (($rateWeight - 70) * $zoneWiseSalesRateTs->getRate());}$salesInvDetailsObj->setSalesRate($finalSalesRate);}}else // Common sales rate{if($rateWeight < $perKgRateWeight ){$countryWiseSalesRate = $entityManager->getRepository(CountryWiseCommonSalesRate::class)->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'courier' => $salesCourierId, 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateWeight ]);}else{$countryWiseSalesRate = $entityManager->getRepository(CountryWiseCommonSalesRate::class)->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'courier' => $salesCourierId, 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);if($countryWiseSalesRate !== null){$countryWiseSalesRate->setRate($countryWiseSalesRate->getRate() * $rateWeight);}}if($countryWiseSalesRate === null){if($rateWeight < $perKgRateWeight ){$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseCommonSalesRate::class)->findCommonSalesRatebyCourierAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $salesCourierId, $salesZoneId, $productTypeObj->getRateid(), $rateWeight);}else{$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseCommonSalesRate::class)->findCommonSalesRatebyCourierAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $salesCourierId, $salesZoneId, $productTypeObj->getRateid(), $courierObj->getId() == 3 ? $perKgRateWeight : $rateWeight );if($zoneWiseSalesRate !== null){$zoneWiseSalesRate->setRate($zoneWiseSalesRate->getRate() * $rateWeight);}}}if($countryWiseSalesRate !== null){$salesInvDetailsObj->setSalesRate($zoneWiseSalesRate->getRate());}else if($zoneWiseSalesRate !== null){$salesInvDetailsObj->setSalesRate($countryWiseSalesRate->getRate());}else{return new JsonResponse(array('success' => false, 'responseText' => 'Common Sales Rate is not set for Courier : '.$salesCourierName.', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}}//Sales Rate Assign End}else // Special Calculated Rate{$salesInvDetailsObj->setSalesRate($salesRate_array[$index]);}// Master Weight and Sales Rate Calculation Startif($salesInvDetailsObj->getShipment() !== null && $salesInvDetailsObj->getRateApplicable() <= 2 && !$salesInvDetailsObj->getShipment()->isExpedite()) // Predefine Rate{//Sales Rate Assign Start// if($customerObj->getRateCurrency() == 2)// {// $perKgRateWeight = 21;// }$finalRateCal = 0;if($customerObj->getRateType() == 1) // Customer wise sales rate{if($rateBookingWeight < $perKgRateWeight ){$countryWiseSalesRate = $entityManager->getRepository(CountryWiseSalesRate::class)->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateBookingWeight ]);if($countryWiseSalesRate !== null){$finalRateCal = $countryWiseSalesRate->getRate();}}else{$countryWiseSalesRate = $entityManager->getRepository(CountryWiseSalesRate::class)->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);if($countryWiseSalesRate !== null){$finalRateCal = $countryWiseSalesRate->getRate() * $rateBookingWeight;}}if($countryWiseSalesRate === null){if($rateBookingWeight < $perKgRateWeight ){$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $customerObj->getId(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight);// return new JsonResponse(array('success' => false, 'responseText' => $rateBookingWeight .'-'. $zoneWiseSalesRate->getRate() ));if($zoneWiseSalesRate !== null){$finalRateCal = $zoneWiseSalesRate->getRate();}}else{$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $customerObj->getId(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $courierObj->getId() == 3 ? $perKgRateWeight : $rateWeight );if($zoneWiseSalesRate !== null){$finalRateCal = $zoneWiseSalesRate->getRate() * $rateBookingWeight;}}}if($countryWiseSalesRate !== null){$salesInvDetailsObj->setSalesMasterRate($finalRateCal);}else if($zoneWiseSalesRate !== null){$salesInvDetailsObj->setSalesMasterRate($finalRateCal);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Customer Wise Sales Rate is not set for Customer : '.$customerObj->getName().' Courier : '.$salesCourierName.', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}}else // Common sales rate{if($rateBookingWeight < $perKgRateWeight ){$countryWiseSalesRate = $entityManager->getRepository(CountryWiseCommonSalesRate::class)->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateBookingWeight ]);}else{$countryWiseSalesRate = $entityManager->getRepository(CountryWiseCommonSalesRate::class)->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);if($countryWiseSalesRate !== null){$countryWiseSalesRate->setRate($countryWiseSalesRate->getRate() * $rateWeight);}}if($countryWiseSalesRate === null){if($rateWeight < $perKgRateWeight ){$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseCommonSalesRate::class)->findCommonSalesRatebyCourierAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight);}else{$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseCommonSalesRate::class)->findCommonSalesRatebyCourierAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $courierObj->getId() == 3 ? $perKgRateWeight : $rateBookingWeight );if($zoneWiseSalesRate !== null){$zoneWiseSalesRate->setRate($zoneWiseSalesRate->getRate() * $rateBookingWeight);}}}if($countryWiseSalesRate !== null){$salesInvDetailsObj->setSalesMasterRate($zoneWiseSalesRate->getRate());}else if($zoneWiseSalesRate !== null){$salesInvDetailsObj->setSalesMasterRate($countryWiseSalesRate->getRate());}else{return new JsonResponse(array('success' => false, 'responseText' => 'Common Sales Rate is not set for Courier : '.$salesCourierName.', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}}//Sales Rate Assign End}else if($salesInvDetailsObj->getShipment() === null){$salesInvDetailsObj->setSalesMasterRate($salesInvDetailsObj->getBookingRate());}else // Special Calculated Rate{// Get Settings Currency Start$settingsObj = $settingsInfoRepository->findByDateCurrency(1, $salesInvDetailsObj->getShipmentDate()->format('Y-m-d'));if($settingsObj === null){return new JsonResponse(array('success' => false, 'responseText' => 'Currency is not set in Settings for Month : '.$salesInvoiceDetailsObj->getShipmentDate()->format('F').'-'.$salesInvoiceDetailsObj->getShipmentDate()->format('Y').' in Row Number '.$keyValue.'.'));}// Get Settings Currency End$salesInvDetailsObj->setSalesMasterRate(round((float)$salesRate_array[$index] / $settingsObj->getCurrency(),2));}// Master Weight and Sales Rate Calculation End// SRO Calculation Startif($salesInvDetailsObj->getShipment() !== null && $courierObj->getSro() == 1 && $salesInvDetailsObj->getRateApplicable() <= 2 && !$salesInvDetailsObj->getShipment()->isExpedite()){$salesInvDetailsObj->setSro($courierObj->getSroCharge());}else{$salesInvDetailsObj->setSro(0);}// SRO Calculation End//Master Covid Charge Cal Startif($salesInvDetailsObj->getRateApplicable() <= 3 && $salesInvDetailsObj->getShipment() !== null && !$salesInvDetailsObj->getShipment()->isExpedite()){if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 1) // DHL Covid Charge Cal{// // Demand Charge Start// $comparisonDate = new DateTime('2024-09-14');// if($salesInvDetailsObj->getShipmentDate() > $comparisonDate)// {// $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);// if($countryWiseCovidCharge !== null)// {// $salesInvDetailsObj->setVendorCovidCharge($countryWiseCovidCharge->getRate() * $rateBookingWeight);// }// else// {// return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));// }// }// // Demand Charge End// // Go Green Charge Start// $comparisonDate = new DateTime('2024-04-01');// if ($salesInvDetailsObj->getShipmentDate() < $comparisonDate) {// if($countryObj->getId() == 11 || $countryObj->getId() == 151)// {// $covidChargeUsd = 3.35;// }// else// {// $covidChargeUsd = 1.15;// }// } else {// if($countryObj->getId() == 11 || $countryObj->getId() == 151)// {// $covidChargeUsd = 0.56;// }// else// {// $covidChargeUsd = 0.56;// }// }// $salesInvDetailsObj->setVendorCovidCharge($covidChargeUsd * $rateBookingWeight);// // Go Green Charge End}else if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 2) // Fedex Covid Charge Cal{// Demand Charge Start$comparisonDate = new DateTime('2024-11-17');if($salesInvDetailsObj->getShipmentDate() > $comparisonDate){$zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);if($zoneWiseCovidCharge !== null){$demandCharge = $zoneWiseCovidCharge->getRate() * $rateBookingWeight;if($demandCharge < 1)$salesInvDetailsObj->setVendorCovidCharge(1);else$salesInvDetailsObj->setVendorCovidCharge($demandCharge);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}}else{if($rateBookingWeight <= 3){$salesInvDetailsObj->setVendorCovidCharge(1);}else{$salesInvDetailsObj->setVendorCovidCharge($rateBookingWeight * 0.30);}}}}else{$salesInvDetailsObj->setVendorCovidCharge(0);}//Master Covid Charge Cal End//Sales Covid Charge Cal Startif($salesInvDetailsObj->getRateApplicable() <= 2 && $salesInvDetailsObj->getShipment() !== null && !$salesInvDetailsObj->getShipment()->isExpedite()){if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 1) // DHL Covid Charge Cal{// // Demand Charge Start// $comparisonDate = new DateTime('2024-09-14');// if($salesInvDetailsObj->getShipmentDate() > $comparisonDate)// {// $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);// if($countryWiseCovidCharge !== null)// {// $salesInvDetailsObj->setCovidCharge($countryWiseCovidCharge->getRate() * $rateWeight);// }// else// {// return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));// }// }// // Demand Charge End// // Go Green Charge Start// $comparisonDate = new DateTime('2024-04-01');// if ($salesInvDetailsObj->getShipmentDate() < $comparisonDate) {// if($countryObj->getId() == 11 || $countryObj->getId() == 151)// {// $covidChargeUsd = 3.35;// }// else// {// $covidChargeUsd = 1.15;// }// } else {// if($countryObj->getId() == 11 || $countryObj->getId() == 151)// {// $covidChargeUsd = 0.56;// }// else// {// $covidChargeUsd = 0.56;// }// }// $salesInvDetailsObj->setCovidCharge($covidChargeUsd * $rateWeight);// // Go Green Charge End}else if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 2) // Fedex Covid Charge Cal{// Demand Charge Start$comparisonDate = new DateTime('2024-11-17');if($salesInvDetailsObj->getShipmentDate() > $comparisonDate){$zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);if($zoneWiseCovidCharge !== null){$demandCharge = $zoneWiseCovidCharge->getRate() * $rateWeight;if($demandCharge < 1)$salesInvDetailsObj->setCovidCharge(1);else$salesInvDetailsObj->setCovidCharge($demandCharge);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}}else{if($rateWeight <= 3){$salesInvDetailsObj->setCovidCharge(1);}else{$salesInvDetailsObj->setCovidCharge($rateWeight * 0.30);}}}}else{$salesInvDetailsObj->setCovidCharge(0);}//Sales Covid Charge Cal Endif($salesInvDetailsObj->getShipment() !== null && !$salesInvDetailsObj->getShipment()->isExpedite()){$shipmentDate = $salesInvDetailsObj->getShipmentDate();// Get Settings Currency Start$settingsObj = $settingsInfoRepository->findByDateCurrency(1, $shipmentDate->format('Y-m-d'));if($settingsObj === null){return new JsonResponse(array('success' => false, 'responseText' => 'Currency is not set in Settings for Month : '.$salesInvoiceDetailsObj->getShipmentDate()->format('F').'-'.$salesInvoiceDetailsObj->getShipmentDate()->format('Y').' in Row Number '.$keyValue.'.'));}// Get Settings Currency End// Get Vendor FSC Start$vendorFscObj = $settingsInfoRepository->findByDate(2, $courierObj->getId(), $shipmentDate->format('Y-m-d'));if($vendorFscObj === null){return new JsonResponse(array('success' => false, 'responseText' => 'FSC is not set in FSC Setup for Courier: '.$courierObj->getName().' Month : '.$shipmentDate->format('F').'-'.$shipmentDate->format('Y').' in Row Number '.$keyValue.'.'));}// Get Vendor FSC End// Get Customer FSC Start$fscObj = $settingsInfoRepository->findByDate(2, $this->getUser()->getUserCompany()->getCustomerRate() == 1 ? $courierObj->getId() : $salesCourierId, $shipmentDate->format('Y-m-d'));if($fscObj === null){return new JsonResponse(array('success' => false, 'responseText' => 'FSC is not set in FSC Setup for Month : '.$shipmentDate->format('F').'-'.$shipmentDate->format('Y').' in Row Number '.$keyValue.'.'));}// Get Customer FSC Endif($customerObj->getRateCurrency() == 2){$salesInvDetailsObj->setCurrency(1);}else{$salesInvDetailsObj->setCurrency($customerObj->getCurrency() == 0 ? $settingsObj->getCurrency() : $customerObj->getCurrency() );}$salesInvDetailsObj->setVendorCurrency($courierObj->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());if($salesInvDetailsObj->getRateApplicable() <= 2)$salesInvDetailsObj->setFsc( $customerObj->getFsc() == 0 ? $fscObj->getCurrency() : $customerObj->getFsc() );else$salesInvDetailsObj->setFsc(0);if($salesInvDetailsObj->getRateApplicable() <= 3)$salesInvDetailsObj->setVendorFsc($vendorFscObj->getCurrency());else$salesInvDetailsObj->setVendorFsc(0);}else{$salesInvDetailsObj->setVendorFsc(0);$salesInvDetailsObj->setFsc(0);}$salesInvoice->addSalesInvoiceDetail($salesInvDetailsObj);// // DHL Go Green Plus Fee Start// if($row->getCourier()->getId() == 1)// {// $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();// $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 4)); // 4 for Go Green Plus Fee// $invoiceAdditionalChargeObj->setCharge($receivableGoGreen);// $invoiceAdditionalChargeObj->setFsc(0);// $invoiceAdditionalChargeObj->setVat(0);// $invoiceAdditionalChargeObj->setPayableCharge($payableGoGreen);// $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);// }// // DHL Go Green Plus Fee Start//////////}else if($additionalChargeId_array[$index] !== null){$invoiceAdditionalChargeObj = $entityManager->find(InvoiceAdditionalCharge::class, $additionalChargeId_array[$index]);$additionalChargeObj = $entityManager->find(AdditionalCharge::class, $additionalCharge_array[$index]);$invoiceAdditionalChargeObj->setAdditionalCharge($additionalChargeObj);$invoiceAdditionalChargeObj->setCharge($additionalReceivableAmount_array[$index]);$invoiceAdditionalChargeObj->setPayableCharge($additionalPayableAmount_array[$index]);$invoiceAdditionalChargeObj->setFsc($additionalFscApplicable_array[$index]);$invoiceAdditionalChargeObj->setVat($additionalVatApplicable_array[$index]);$salesInvDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}$index++;}// Start remove item by Editforeach($originalSalesInvoiceDetails as $key=>$salesInvDetails){//check if the shaft is in the $project->getShaft()if($salesInvoice->getSalesInvoiceDetails()->contains($salesInvDetails) === false){$entityManager->remove($salesInvDetails);}}$formInvoiceAdditionalCharge = new ArrayCollection();foreach($salesInvoice->getSalesInvoiceDetails() as $formSid){foreach($formSid->getInvoiceAdditionalCharges() as $key=>$formAcd){$formInvoiceAdditionalCharge->add($formAcd);}}foreach($originalInvoiceAdditionalCharge as $key=>$orInvoiceAdditionalCharge){if($formInvoiceAdditionalCharge->contains($orInvoiceAdditionalCharge) === false){$entityManager->remove($orInvoiceAdditionalCharge);}}// End remove item by Edit$entityManager->flush();$this->addFlash('notice', 'Invoice Updated successfully!');return new JsonResponse(array('success' => true, 'responseText' => 'Data Saved successfully' ));}}return $this->renderForm('sales_invoice/edit.html.twig', ['sales_invoice' => $salesInvoice,'form' => $form,'countryList' => $countryList,'courierList' => $courierList,'productTypeList' => $productTypeList,'additionalChargeList' => $additionalChargeList,]);}#[Route('/salesinvoice/{id}/delete', name: 'app_sales_invoice_delete', methods: ['POST'])]#[IsGranted("ROLE_ACCOUNTS")]public function delete(Request $request, SalesInvoice $salesInvoice, SalesInvoiceRepository $salesInvoiceRepository): Response{if ($this->isCsrfTokenValid('delete'.$salesInvoice->getId(), $request->request->get('_token'))) {$salesInvoiceRepository->remove($salesInvoice, true);}return $this->redirectToRoute('app_sales_invoice_index', [], Response::HTTP_SEE_OTHER);}#[Route('/salesinvoice/{id}/invoice/{currencyType}', name: 'app_sales_invoice_invoice')]#[IsGranted("ROLE_ACCOUNTS")]public function invoice(int $id, int $currencyType, ReceiveVoucherRepository $receiveVoucherRepository, ShipmentRepository $shipmentRepository, SalesInvoiceRepository $salesInvoiceRepository, SalesInvoiceDetailsRepository $salesInvoiceDetailsRepository){$salesInvoice = $salesInvoiceRepository->findBySingleOrderObj($id);// Configure Dompdf according to your needs$pdfOptions = new Options();$pdfOptions->set('defaultFont', 'Arial');// Instantiate Dompdf with our options$dompdf = new Dompdf($pdfOptions);$userObj = $this->getUser();if($salesInvoice->getCustomer()->getLastReceivedAmount() == 1){$lastReceivedObj = $receiveVoucherRepository->findReceiveVoucherByCustomer($salesInvoice->getCustomer()->getId(), $this->getUser()->getUserCompany()->getId());}else{$lastReceivedObj = null;}if($salesInvoice->getCustomer()->getPreviousDuesAmount() == 1){$duesAmount = $shipmentRepository->getCustomerPreviousDuesCalculation($this->getUser()->getUserCompany()->getId(), $salesInvoice->getCustomer()->getId(),$salesInvoice->getSubmissionDate() ? $salesInvoice->getSubmissionDate()->format('Y-m-d') : $salesInvoice->getInvoiceDate()->format('Y-m-d'),$salesInvoice->getId());$duesAmount = $duesAmount[0];}else{$duesAmount = 0;}$groupByCourier = $salesInvoiceDetailsRepository->findGroupByCourier($id);$totalReceivedAmount = $receiveVoucherRepository->findTotalReceivedAmountBySalesInvoiceId($id, $salesInvoice->getInvoiceDate());$totalReceivedAmount = $totalReceivedAmount !== null ? $totalReceivedAmount : 0;// Retrieve the HTML generated in our twig fileif($salesInvoice->getRateApplicable() <= 3){$html = $this->renderView('sales_invoice/invoice.html.twig', ['salesInvoice' => $salesInvoice,'userObj' => $userObj,'lastReceivedObj' => $lastReceivedObj,'duesAmount' => $duesAmount,'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'. $userObj->getUserCompany()->getLogoPath() ),'currencyType' => $currencyType,'groupByCourier' => $groupByCourier,'totalReceivedAmount' => $totalReceivedAmount,]);}else{$html = $this->renderView('sales_invoice/invoice.html.twig', ['salesInvoice' => $salesInvoice,'userObj' => $userObj,'lastReceivedObj' => $lastReceivedObj,'duesAmount' => $duesAmount,'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'. $userObj->getUserCompany()->getLogoPath() ),'currencyType' => $currencyType,'groupByCourier' => $groupByCourier,'totalReceivedAmount' => $totalReceivedAmount,]);}// Load HTML to Dompdf$dompdf->loadHtml($html);// (Optional) Setup the paper size and orientation 'portrait' or 'landscape'$dompdf->setPaper('A4', 'portrait');// Render the HTML as PDF$dompdf->render();// Add Watermark in Domdpf// Instantiate canvas instance$canvas = $dompdf->getCanvas();// Get the number of pages in the PDF$pageCount = $canvas->get_page_count();// if($salesInvoice->getApproval() == 0)// {// $callback = function ($pageNumber) use ($pageCount, $pdfOptions, $canvas) {// // Set text opacity// $canvas->set_opacity(0.2, 'Multiply');// // Instantiate font metrics class// $fontMetrics = new FontMetrics($canvas, $pdfOptions);// // Get height and width of page// $w = $canvas->get_width();// $h = $canvas->get_height();// // Get font family file// $font = $fontMetrics->getFont('times');// // Specify watermark text// $text = "DRAFT";// // Get height and width of text// $txtHeight = $fontMetrics->getFontHeight($font, 75);// $textWidth = $fontMetrics->getTextWidth($text, $font, 75);// // Specify horizontal and vertical position// $x = (($w-$textWidth)/2);// $y = (($h-$txtHeight)/2);// // Writes text at the specified x and y coordinates// $canvas->text($x, $y, $text, $font, 75, array(0, 0, 0), 0, 'B');// };// // Add the callback function to each page// for ($i = 0; $i < $pageCount; $i++) {// $canvas->page_script($callback);// }// }// Page number and total page count Start// Define the callback function to add the page number and total page count$callback2 = function ($pageNumber) use ($pageCount, $canvas) {// Set text opacity$canvas->set_opacity(0.9, 'Multiply');// Set the text and position for page number and total page count$text = 'Page ' . $pageNumber . ' of ' . $pageCount;$x = 530; // X-coordinate position$y = 813; // Y-coordinate position// Add the page number and total page count to the current page$canvas->text($x, $y, $text, null, 10);};// Add the callback function to each pagefor ($i = 0; $i < $pageCount; $i++) {$canvas->page_script($callback2);}// Output the generated PDF to Browser (force download)$dompdf->stream("Invoice_".$salesInvoice->getInvoiceNo().".pdf", ["Attachment" => false]);exit(0);}#[Route('/salesinvoice/{id}/master-invoice', name: 'app_sales_invoice_master_invoice')]#[IsGranted("ROLE_ACCOUNTS")]public function masterInvoice(int $id, SalesInvoiceRepository $salesInvoiceRepository, ReceiveVoucherRepository $receiveVoucherRepository){$salesInvoice = $salesInvoiceRepository->findBySingleOrderObj($id);// Configure Dompdf according to your needs$pdfOptions = new Options();$pdfOptions->set('defaultFont', 'Arial');// Instantiate Dompdf with our options$dompdf = new Dompdf($pdfOptions);$userObj = $this->getUser();if($salesInvoice->getCustomer()->getLastReceivedAmount() == 1){$lastReceivedObj = $receiveVoucherRepository->findReceiveVoucherByCustomer($salesInvoice->getCustomer()->getId(), $this->getUser()->getUserCompany()->getId());}else{$lastReceivedObj = null;}// Retrieve the HTML generated in our twig fileif($salesInvoice->getRateApplicable() <= 2){$html = $this->renderView('sales_invoice/masterInvoice.html.twig', ['salesInvoice' => $salesInvoice,'userObj' => $userObj,'lastReceivedObj' => $lastReceivedObj,'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'. $userObj->getUserCompany()->getLogoPath() ),]);}else{$html = $this->renderView('sales_invoice/calculatedInvoice.html.twig', ['salesInvoice' => $salesInvoice,'userObj' => $userObj,'lastReceivedObj' => $lastReceivedObj,'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'. $userObj->getUserCompany()->getLogoPath() ),]);}// Load HTML to Dompdf$dompdf->loadHtml($html);// (Optional) Setup the paper size and orientation 'portrait' or 'landscape'$dompdf->setPaper('A4', 'portrait');// Render the HTML as PDF$dompdf->render();// Add Watermark in Domdpf// Instantiate canvas instance$canvas = $dompdf->getCanvas();// Get the number of pages in the PDF$pageCount = $canvas->get_page_count();if($salesInvoice->getApproval() == 0){$callback = function ($pageNumber) use ($pageCount, $pdfOptions, $canvas) {// Set text opacity$canvas->set_opacity(0.2, 'Multiply');// Instantiate font metrics class$fontMetrics = new FontMetrics($canvas, $pdfOptions);// Get height and width of page$w = $canvas->get_width();$h = $canvas->get_height();// Get font family file$font = $fontMetrics->getFont('times');// Specify watermark text$text = "DRAFT";// Get height and width of text$txtHeight = $fontMetrics->getFontHeight($font, 75);$textWidth = $fontMetrics->getTextWidth($text, $font, 75);// Specify horizontal and vertical position$x = (($w-$textWidth)/2);$y = (($h-$txtHeight)/2);// Writes text at the specified x and y coordinates$canvas->text($x, $y, $text, $font, 75, array(0, 0, 0), 0, 'B');};// Add the callback function to each pagefor ($i = 0; $i < $pageCount; $i++) {$canvas->page_script($callback);}}// Page number and total page count Start// Define the callback function to add the page number and total page count$callback2 = function ($pageNumber) use ($pageCount, $canvas) {// Set text opacity$canvas->set_opacity(0.9, 'Multiply');// Set the text and position for page number and total page count$text = 'Page ' . $pageNumber . ' of ' . $pageCount;$x = 530; // X-coordinate position$y = 820; // Y-coordinate position// Add the page number and total page count to the current page$canvas->text($x, $y, $text, null, 10);};// Add the callback function to each pagefor ($i = 0; $i < $pageCount; $i++) {$canvas->page_script($callback2);}// Output the generated PDF to Browser (force download)$dompdf->stream("Invoice_".$salesInvoice->getInvoiceNo().".pdf", ["Attachment" => false]);exit(0);}#[Route('/salesinvoice/{id}/master-weight-sales-rate/{currencyType}', name: 'app_sales_invoice_masterWeightSalesRate')]#[IsGranted("ROLE_ACCOUNTS")]public function masterWeightSalesRateinvoice(int $id, int $currencyType, ReceiveVoucherRepository $receiveVoucherRepository, ShipmentRepository $shipmentRepository, SalesInvoiceRepository $salesInvoiceRepository, SalesInvoiceDetailsRepository $salesInvoiceDetailsRepository){$salesInvoice = $salesInvoiceRepository->findBySingleOrderObj($id);// Configure Dompdf according to your needs$pdfOptions = new Options();$pdfOptions->set('defaultFont', 'Arial');// Instantiate Dompdf with our options$dompdf = new Dompdf($pdfOptions);$userObj = $this->getUser();if($salesInvoice->getCustomer()->getLastReceivedAmount() == 1){$lastReceivedObj = $receiveVoucherRepository->findReceiveVoucherByCustomer($salesInvoice->getCustomer()->getId(), $this->getUser()->getUserCompany()->getId());}else{$lastReceivedObj = null;}if($salesInvoice->getCustomer()->getPreviousDuesAmount() == 1){$duesAmount = $shipmentRepository->getCustomerWiseCreditLimitCalculation($salesInvoice->getCustomer()->getId());$duesAmount = $duesAmount[0];}else{$duesAmount = 0;}$groupByCourier = $salesInvoiceDetailsRepository->findGroupByCourier($id);// Retrieve the HTML generated in our twig fileif($salesInvoice->getRateApplicable() <= 3){$html = $this->renderView('sales_invoice/masterWeightSalesRateinvoice.html.twig', ['salesInvoice' => $salesInvoice,'userObj' => $userObj,'lastReceivedObj' => $lastReceivedObj,'duesAmount' => $duesAmount,'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'. $userObj->getUserCompany()->getLogoPath() ),'currencyType' => $currencyType,'groupByCourier' => $groupByCourier,]);}else{$html = $this->renderView('sales_invoice/masterWeightSalesRateinvoice.html.twig', ['salesInvoice' => $salesInvoice,'userObj' => $userObj,'lastReceivedObj' => $lastReceivedObj,'duesAmount' => $duesAmount,'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'. $userObj->getUserCompany()->getLogoPath() ),]);}// Load HTML to Dompdf$dompdf->loadHtml($html);// (Optional) Setup the paper size and orientation 'portrait' or 'landscape'$dompdf->setPaper('A4', 'portrait');// Render the HTML as PDF$dompdf->render();// Add Watermark in Domdpf// Instantiate canvas instance$canvas = $dompdf->getCanvas();// Get the number of pages in the PDF$pageCount = $canvas->get_page_count();// if($salesInvoice->getApproval() == 0)// {// $callback = function ($pageNumber) use ($pageCount, $pdfOptions, $canvas) {// // Set text opacity// $canvas->set_opacity(0.2, 'Multiply');// // Instantiate font metrics class// $fontMetrics = new FontMetrics($canvas, $pdfOptions);// // Get height and width of page// $w = $canvas->get_width();// $h = $canvas->get_height();// // Get font family file// $font = $fontMetrics->getFont('times');// // Specify watermark text// $text = "DRAFT";// // Get height and width of text// $txtHeight = $fontMetrics->getFontHeight($font, 75);// $textWidth = $fontMetrics->getTextWidth($text, $font, 75);// // Specify horizontal and vertical position// $x = (($w-$textWidth)/2);// $y = (($h-$txtHeight)/2);// // Writes text at the specified x and y coordinates// $canvas->text($x, $y, $text, $font, 75, array(0, 0, 0), 0, 'B');// };// // Add the callback function to each page// for ($i = 0; $i < $pageCount; $i++) {// $canvas->page_script($callback);// }// }// Page number and total page count Start// Define the callback function to add the page number and total page count$callback2 = function ($pageNumber) use ($pageCount, $canvas) {// Set text opacity$canvas->set_opacity(0.9, 'Multiply');// Set the text and position for page number and total page count$text = 'Page ' . $pageNumber . ' of ' . $pageCount;$x = 530; // X-coordinate position$y = 813; // Y-coordinate position// Add the page number and total page count to the current page$canvas->text($x, $y, $text, null, 10);};// Add the callback function to each pagefor ($i = 0; $i < $pageCount; $i++) {$canvas->page_script($callback2);}// Output the generated PDF to Browser (force download)$dompdf->stream("Invoice_".$salesInvoice->getInvoiceNo().".pdf", ["Attachment" => false]);exit(0);}#[Route('/salesinvoice/datewiseinvoice', name: 'app_sales_invoice_datewiseinvoice', methods: ['GET', 'POST'])]public function datewiseinvoice(Request $request, EntityManagerInterface $entityManager): Response{$invoiceId = $request->request->get('modal-salesinvocie-id');$fromDate = $request->request->get('modal-from-date');$toDate = $request->request->get('modal-to-date');$salesInvoice = $entityManager->find(SalesInvoice::class, $invoiceId);$salesInvoice->getSalesInvoiceDetails()->clear();$salesInvoiceDetailsList = $entityManager->getRepository(SalesInvoiceDetails::class)->salesInvDetailsListDateWise($invoiceId, $fromDate, $toDate);foreach($salesInvoiceDetailsList as $salesInvoiceDetails){$salesInvoice->addSalesInvoiceDetail($salesInvoiceDetails);}// Configure Dompdf according to your needs$pdfOptions = new Options();$pdfOptions->set('defaultFont', 'Arial');// Instantiate Dompdf with our options$dompdf = new Dompdf($pdfOptions);$userObj = $this->getUser();// Retrieve the HTML generated in our twig fileif($salesInvoice->getRateApplicable() <= 2){$html = $this->renderView('sales_invoice/invoice.html.twig', ['salesInvoice' => $salesInvoice,'userObj' => $userObj,'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'. $userObj->getUserCompany()->getLogoPath() ),]);}else{$html = $this->renderView('sales_invoice/calculatedInvoice.html.twig', ['salesInvoice' => $salesInvoice,'userObj' => $userObj,'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'. $userObj->getUserCompany()->getLogoPath() ),]);}// Load HTML to Dompdf$dompdf->loadHtml($html);// (Optional) Setup the paper size and orientation 'portrait' or 'landscape'$dompdf->setPaper('A4', 'portrait');// Render the HTML as PDF$dompdf->render();// Output the generated PDF to Browser (force download)$dompdf->stream("Invoice.pdf", ["Attachment" => false,]);}#[Route('/salesinvoice/datewisedataupdate', name: 'app_sales_invoice_datewisedataupdate', methods: ['GET', 'POST'])]public function datewisedataupdate(Request $request, EntityManagerInterface $entityManager): Response{$invoiceId = $request->request->get('modal-salesinvocie-id');$fromDate = $request->request->get('modal-from-date');$toDate = $request->request->get('modal-to-date');$courier = $request->request->get('modal-courier');$fsc = $request->request->get('modal-fsc');$currency = $request->request->get('modal-currency');$applicable = $request->request->get('modal-applicable');$salesInvoiceDetailsList = $entityManager->getRepository(SalesInvoiceDetails::class)->salesInvDetailsListCourierAndDateWise($invoiceId, $fromDate, $toDate, $courier);foreach($salesInvoiceDetailsList as $salesInvoiceDetails){if($applicable == 1){$salesInvoiceDetails->setFsc($fsc);$salesInvoiceDetails->setCurrency($currency);}else if($applicable == 2){$salesInvoiceDetails->setVendorFsc($fsc);$salesInvoiceDetails->setVendorCurrency($currency);}else{$salesInvoiceDetails->setFsc($fsc);$salesInvoiceDetails->setCurrency($currency);$salesInvoiceDetails->setVendorFsc($fsc);$salesInvoiceDetails->setVendorCurrency($currency);}$entityManager->persist($salesInvoiceDetails);$entityManager->flush($salesInvoiceDetails);}return $this->redirectToRoute('app_sales_invoice_show', ['id' => $invoiceId]);}#[Route('/salesinvoice/principle-invoice-checking', name: 'app_sales_invoice_principle_invocie_checking', methods: ['GET', 'POST'])]#[IsGranted("ROLE_ACCOUNTS")]public function principleInvoiceChecking(Request $request, SluggerInterface $slugger, SalesInvoiceDetailsRepository $salesInvoiceDetailsRepository): Response{$form = $this->createFormBuilder(null)->add('file', FileType::class, ['label' => 'Upload Principle Invoice Excel File ',// unmapped means that this field is not associated to any entity property'mapped' => false,'attr' => ['class' => 'form-control select-tags',],// make it optional so you don't have to re-upload the PDF file// every time you edit the Product details//'required' => false,// unmapped fields can't define their validation using annotations// in the associated entity, so you can use the PHP constraint classes'constraints' => [new File(['maxSize' => '1024k','mimeTypes' => ['application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',],'mimeTypesMessage' => 'Please upload a valid Excel (.xlsx / .xls) file',])],])->add('courier', EntityType::class, [// looks for choices from this entity'class' => Courier::class,'query_builder' => function (CourierRepository $er) {return $er->createQueryBuilder('v')->orderBy('v.name', 'ASC');},// uses the User.username property as the visible option string'choice_label' => 'name','placeholder' => 'Select a Courier...','attr' => ['class' => 'form-control select-tags','style' => 'width:100%;',],'label' => 'Courier',// used to render a select box, check boxes or radios// 'multiple' => true,// 'expanded' => true,])->add('fromDate', DateType::class, ['attr' => ['class' => 'form-control'],'widget' => 'single_text','empty_data' => null,])->add('toDate', DateType::class, ['attr' => ['class' => 'form-control'],'widget' => 'single_text','empty_data' => null,])->getForm();$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$data = $form->getData();$formDate = $form->get('fromDate')->getData()->format('Y-m-d');$toDate = $form->get('toDate')->getData()->format('Y-m-d');$courier = $form->get('courier')->getData();/* @var UploadedFile document start */$docFile = $form->get('file')->getData();// this condition is needed because the 'brochure' field is not required// so the PDF file must be processed only when a file is uploadedif ($docFile) {$originalFilename = pathinfo($docFile->getClientOriginalName(), PATHINFO_FILENAME);// this is needed to safely include the file name as part of the URL$safeFilename = $slugger->slug($originalFilename);$newFilename = $safeFilename.'-'.uniqid().'.'.$docFile->guessExtension();// Move the file to the directory where brochures are storedtry {$docFile->move($this->getParameter('filedocument_directory'),$newFilename);} catch (FileException $e) {// ... handle exception if something happens during file upload}// updates the 'brochureFilename' property to store the PDF file name// instead of its contents//$assetregister->setDocpath($newFilename);}/* @var UploadedFile document end *//* Excel file read from upload directory Start */// Here we are able to read from the excel file$spreadsheet = IOFactory::load($this->getParameter('filedocument_directory').'/'.$newFilename);// I added this to be able to remove the first file line$row = $spreadsheet->getActiveSheet()->removeRow(1);$maxCell = $spreadsheet->getActiveSheet()->getHighestRowAndColumn();// dd($maxCell);// dd('A1:' . $maxCell['column'] . $maxCell['row']);// here, the read data is turned into an array$sheetData = $spreadsheet->getActiveSheet()->rangeToArray('A1:A' . $maxCell['row']);// dump($sheetData);$salesInvoiceDetails = $salesInvoiceDetailsRepository->principleInvoiceChecking($formDate, $toDate, $courier->getId(), $this->getUser()->getUserCompany()->getId());//dd($salesInvoiceDetails);// $salesInvoiceDetailsforFalse = array_filter($salesInvoiceDetails, function($item) {// return $item['principalBill'] === false;// });// // dd($salesInvoiceDetailsforFalse);// $salesInvoiceDetailsforTrue = array_filter($salesInvoiceDetails, function($item) {// return $item['principalBill'] === true;// });// dd($salesInvoiceDetailsforTrue);// Flatten the first array$flattenedSheetData = array_map(function($item) {return str_replace(' ', '', $item[0]);}, $sheetData);// Flatten the second array$flattenedSalesInvoiceDetails = array_map(function($item) {return str_replace(' ', '', $item["hawbNo"]);}, $salesInvoiceDetails);// Elements in $flattenedSheetData but not in $flattenedSalesInvoiceDetails$missingBillCustomer = array_diff($flattenedSheetData, $flattenedSalesInvoiceDetails);$extraBillCustomer = array_diff($flattenedSalesInvoiceDetails, $flattenedSheetData);// dump($flattenedSheetData);// dump($flattenedSalesInvoiceDetails);// dump($missingBillCustomer);// dd($extraBillCustomer);// $this->addFlash('notice', 'Country Created successfully!');return $this->render('sales_invoice/principleInvoiceCheckingResult.html.twig', ['missing_bill_customer' => $missingBillCustomer,'sheet_data_count' => count($flattenedSheetData),'extra_bill_customer' => $extraBillCustomer,'sales_invoice_count' => count($flattenedSalesInvoiceDetails),'courier' => $courier,]);}return $this->renderForm('sales_invoice/principleInvoiceChecking.html.twig', ['form' => $form,]);}#[Route('/salesinvoice/shipmenttoinvoice', name: 'app_sales_invoice_shipmentto_invoice', methods: ['GET', 'POST'])]#[IsGranted("ROLE_ACCOUNTS")]public function shipmenttoinvoice(Request $request, ShipmentRepository $shipmentRepository, CourierRepository $courierRepository, CountryRepository $countryRepository, CustomerRepository $customerRepository, ProductTypeRepository $productTypeRepository){$form = $this->createFormBuilder(null)->add('fromDate', DateType::class, ['attr' => ['class' => 'form-control'],'widget' => 'single_text','empty_data' => null,'label' => 'From Shipment Date',])->add('toDate', DateType::class, ['attr' => ['class' => 'form-control'],'widget' => 'single_text','empty_data' => null,'label' => 'To Shipment Date',])->add('customer',TextType::class, ['attr' => ['class' => 'form-control'],'label' => 'Customer','required' => false,])->add('hawbno',TextType::class, ['attr' => ['class' => 'form-control'],'label' => 'Hawb No','required' => false,])->getForm();$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$data = $form->getData();$formDate = $form->get('fromDate')->getData()->format('Y-m-d');$toDate = $form->get('toDate')->getData()->format('Y-m-d');$customer = $form->get('customer')->getData();$hawbNO = $form->get('hawbno')->getData();$viewTag = 0;$shipmentList = $shipmentRepository->findShipmentByDateforInvoice($formDate, $toDate, $customer, $hawbNO, $this->getUser()->getUserCompany()->getId());foreach($shipmentList as $row){if($row->getCustomer()->getRateType() > 2 || $row->isExpedite() || $row->getPaymentOptions()->getId() == 2){$viewTag = 1;break;}}$courierList = $courierRepository->findBy(['userCompany' => $this->getUser()->getUserCompany()->getId() ]);$countryList = $countryRepository->findAll();$customerList = $customerRepository->findBy(['userCompany' => $this->getUser()->getUserCompany()->getId() ]);$productTypeList = $productTypeRepository->findBy(['type' => 2]);return $this->render('sales_invoice/shipmenttoinvoice.html.twig', ['form' => $form->createView(),'bookingList' => $shipmentList,'courierList' => $courierList,'countryList' => $countryList,'customerList' => $customerList,'productTypeList' => $productTypeList,'track' => 1,'viewTag' => $viewTag,]);}$bookingObj = new SalesInvoiceDetails();return $this->render('sales_invoice/shipmenttoinvoice.html.twig', ['form' => $form->createView(),'bookingList' => $bookingObj,'track' => 0,]);}#[Route('/salesinvoice/shipmenttoinvoicepost', name: 'app_sales_invoice_shipmentto_invoice_post', methods: ['GET', 'POST'])]#[IsGranted("ROLE_ACCOUNTS")]public function shipmenttoinvoicepost(Request $request, EntityManagerInterface $entityManager, UtilsService $utilsService, ShipmentRepository $shipmentRepository, CourierRepository $courierRepository, CountryRepository $countryRepository, CustomerRepository $customerRepository, ProductTypeRepository $productTypeRepository, SettingsInfoRepository $settingsInfoRepository, SalesInvoiceRepository $salesInvoiceRepository){if ($request->isXMLHttpRequest()){$hawbNo = $request->request->get('hawbNo');if (!empty($hawbNo)){$hawbNo_array = json_decode($hawbNo, true);// return new JsonResponse(array('success' => false, 'responseText' => $hawbNo_array ));$hawbNo_array = json_decode($request->request->get('hawbNo'));$shipmentDate_array = json_decode($request->request->get('shipmentDate'));$reference_array = json_decode($request->request->get('reference'));$country_array = json_decode($request->request->get('country'));$customer_array = json_decode($request->request->get('customer'));$courier_array = json_decode($request->request->get('courier'));$productType_array = json_decode($request->request->get('productType'));$weight_array = json_decode($request->request->get('weight'));$bookingWeight_array = json_decode($request->request->get('bookingWeight'));$shipmentId_array = json_decode($request->request->get('shipmentId'));$vatApplicable_array = json_decode($request->request->get('vatApplicable'));$salesRate_array = json_decode($request->request->get('billingWeight'));$salesInvoiceDetailsList = new ArrayCollection();$index = 0;foreach($hawbNo_array as $key=>$Row){$keyValue = $key;$keyValue = $keyValue + 1;$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInvoiceDetObj = $entityManager->getRepository(SalesInvoiceDetails::class)->findOneBy(['hawbNo' => $hawbNo_array[$index]]);if($salesInvoiceDetObj !== null){return new JsonResponse(array('success' => false, 'responseText' => 'Duplicate HAWB Number : '. $hawbNo_array[$index].' in Row Number '.$keyValue.'.'));}$salesInvoiceDetailsObj->setShipmentDate(new \DateTime($shipmentDate_array[$index]));$salesInvoiceDetailsObj->setHawbNo($hawbNo_array[$index]);$salesInvoiceDetailsObj->setReference($reference_array[$index]);$countryObj = $entityManager->find(Country::class, $country_array[$index]);$salesInvoiceDetailsObj->setCountry($countryObj);$courierObj = $entityManager->find(Courier::class, $courier_array[$index]);$salesInvoiceDetailsObj->setCourier($courierObj);// Rate Type get Start Here getRateType()if($courierObj->getZoneRateType() !== null)$zoneWiseMasterRateTypeObj = $entityManager->find(ZoneWiseMasterRate::class, $courierObj->getZoneRateType());else$zoneWiseMasterRateTypeObj = new ZoneWiseMasterRate();// Rate Type get End Here$productTypeObj = $entityManager->find(ProductType::class, $productType_array[$index]);$salesInvoiceDetailsObj->setProductType($productTypeObj);$customerObj = $entityManager->find(Customer::class, $customer_array[$index]);$salesInvoiceDetailsObj->setCustomer($customerObj);$salesInvoiceDetailsObj->setWeight($weight_array[$index]);$salesInvoiceDetailsObj->setBookingWeight($bookingWeight_array[$index]);$shipmentObj = $entityManager->find(Shipment::class, $shipmentId_array[$index]);$salesInvoiceDetailsObj->setShipment($shipmentObj);$salesInvoiceDetailsObj->setVatApplicable($vatApplicable_array[$index]);$salesInvoiceDetailsObj->setVendorVatApplicable($vatApplicable_array[$index]);if($salesInvoiceDetailsObj->getShipment()->isExpedite()){$rateApplicableId = 5; // Expedite Rate Type 5}else if ($shipmentObj->getPaymentOptions()->getId() == 2 ){$rateApplicableId = 3; // Manually Tariff Rate($) 3}else{$rateApplicableId = $customerObj->getRateType();}$salesInvoiceDetailsObj->setRateApplicable($rateApplicableId);// return new JsonResponse(array('success' => false, 'responseText' => $salesInvoiceObj_array['InvoiceApplicable'] ));// $salesInvoiceDetailsObj->setInvoiceStatus($salesInvoiceObj_array['InvoiceApplicable']);//Zone Assign Start $shipmentId_array// if($courier_array[$index] < 0)// {$courierWiseZoneObj = $entityManager->getRepository(CourierWiseZone::class)->findOneBy(['courier' => $courier_array[$index], 'country' => $country_array[$index] ]);if($courierWiseZoneObj === null ){return new JsonResponse(array('success' => false, 'responseText' => 'Courier Wise Zone is not set for Courier : '. $courierObj->getName().', and Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}$salesInvoiceDetailsObj->setZone($courierWiseZoneObj->getZone());//return new JsonResponse(array('success' => false, 'responseText' => $courierWiseZoneObj->getZone() ));// }// else// {// $courierWiseZoneObj = $this->getDoctrine()// ->getRepository(CourierWiseZone::class)// ->find(1);// }//Zone Assign End//Customer Weight Calculation Start// Half and Per KG$weight = trim($weight_array[$index]);$pointInputWeight = $weight - floor($weight);$intInputWeight = floor($weight);$finalWeight = 0;$rateWeight = 0;if($weight < $courierObj->getWeightPerkg()){if($pointInputWeight > 0 && $pointInputWeight <= 0.5){$finalWeight = (float)0.5;}elseif($pointInputWeight > 0.5 && $pointInputWeight <=1){$finalWeight = (float)1;}}else{if($pointInputWeight > 0 && $pointInputWeight <=1){$finalWeight = (float)1;}}$rateWeight = $intInputWeight + $finalWeight;//Only Per KG$pointInputPerKgWeight = $weight - floor($weight);$intInputPerKgWeight = floor($weight);$finalPerKgWeight = 0;$ratePerKgWeight = 0;if($pointInputPerKgWeight > 0 && $pointInputPerKgWeight <=1){$finalPerKgWeight = (float)1;}$ratePerKgWeight = $intInputPerKgWeight + $finalPerKgWeight;//Customer Weight Calculation End//Vendor/Booking weight Calculation Start// Half and Per KG$bookingWeight = trim($bookingWeight_array[$index]);$pointInputBookingWeight = $bookingWeight - floor($bookingWeight);$intInputBookingWeight = floor($bookingWeight);$finalBookingWeight = 0;$rateBookingWeight = 0;if($bookingWeight < $courierObj->getWeightPerkg()){if($pointInputBookingWeight > 0 && $pointInputBookingWeight <= 0.5){$finalBookingWeight = (float)0.5;}elseif($pointInputBookingWeight > 0.5 && $pointInputBookingWeight <=1){$finalBookingWeight = (float)1;}}else{if($pointInputBookingWeight > 0 && $pointInputBookingWeight <=1){$finalBookingWeight = (float)1;}}$rateBookingWeight = $intInputBookingWeight + $finalBookingWeight;//Only Per KG$pointInputPerKgBookingWeight = $bookingWeight - floor($bookingWeight);$intInputPerKgBookingWeight = floor($bookingWeight);$finalPerKgBookingWeight = 0;$ratePerKgBookingWeight = 0;if($pointInputPerKgBookingWeight > 0 && $pointInputPerKgBookingWeight <=1){$finalPerKgBookingWeight = (float)1;}$ratePerKgBookingWeight = $intInputPerKgBookingWeight + $finalPerKgBookingWeight;//Weight Calculation End// Get Settings Currency Start$settingsObj = $settingsInfoRepository->findByDateCurrency(1, $salesInvoiceDetailsObj->getShipmentDate()->format('Y-m-d'));if($settingsObj === null){return new JsonResponse(array('success' => false, 'responseText' => 'Currency is not set in Settings for Month : '.$salesInvoiceDetailsObj->getShipmentDate()->format('F').'-'.$salesInvoiceDetailsObj->getShipmentDate()->format('Y').' in Row Number '.$keyValue.'.'));}// Get Settings Currency End//Master Rate Assign Startif(!$salesInvoiceDetailsObj->getShipment()->isExpedite()){$perKgRateWeight = $courierObj->getWeightPerkgRate();if($courierObj->getId() != 3){$finalMasterRateCal = 0;if($rateBookingWeight < $perKgRateWeight ){$countryWiseMasterRate = $entityManager->getRepository(CountryWiseMasterRate::class)->findOneBy(['type' => $shipmentObj->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateBookingWeight ]);if($countryWiseMasterRate !== null){$finalMasterRateCal = $countryWiseMasterRate->getRate();}}else{$countryWiseMasterRate = $entityManager->getRepository(CountryWiseMasterRate::class)->findOneBy(['type' => $shipmentObj->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);if($countryWiseMasterRate !== null){$finalMasterRateCal = $countryWiseMasterRate->getRate() * $rateBookingWeight;}}if($countryWiseMasterRate === null){if($rateBookingWeight < $perKgRateWeight ){$zoneWiseMasterRate = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(), $zoneWiseMasterRateTypeObj->getRateType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight);if($zoneWiseMasterRate !== null){$finalMasterRateCal = $zoneWiseMasterRate->getRate();}}else{$zoneWiseMasterRate = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(), $zoneWiseMasterRateTypeObj->getRateType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $courierObj->getId() == 3 ? $perKgRateWeight : $rateBookingWeight );if($zoneWiseMasterRate !== null){$finalMasterRateCal = $zoneWiseMasterRate->getRate() * $rateBookingWeight;}}}if($countryWiseMasterRate !== null){$salesInvoiceDetailsObj->setBookingRate($finalMasterRateCal);}else if($zoneWiseMasterRate !== null){$salesInvoiceDetailsObj->setBookingRate($finalMasterRateCal);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Master Rate is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}}else{if($rateBookingWeight <= 30){$zoneWiseMasterRate = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(),$zoneWiseMasterRateTypeObj->getRateType(),$courierObj->getId(),$courierWiseZoneObj->getZone()->getId(),$productTypeObj->getRateid(),$rateBookingWeight);$finalRate = $zoneWiseMasterRate->getRate();}else if($rateBookingWeight > 30 && $rateBookingWeight <= 70){$zoneWiseMasterRateFs = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(),$zoneWiseMasterRateTypeObj->getRateType(),$courierObj->getId(),$courierWiseZoneObj->getZone()->getId(),$productTypeObj->getRateid(),30);$zoneWiseMasterRateSs = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(),$zoneWiseMasterRateTypeObj->getRateType(),$courierObj->getId(),$courierWiseZoneObj->getZone()->getId(),$productTypeObj->getRateid(),31);$finalRate = $zoneWiseMasterRateFs->getRate() + (($rateBookingWeight - 30) * $zoneWiseMasterRateSs->getRate());}else if($rateBookingWeight > 70){$zoneWiseMasterRateFs = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(),$zoneWiseMasterRateTypeObj->getRateType(),$courierObj->getId(),$courierWiseZoneObj->getZone()->getId(),$productTypeObj->getRateid(),30);$zoneWiseMasterRateSs = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(),$zoneWiseMasterRateTypeObj->getRateType(),$courierObj->getId(),$courierWiseZoneObj->getZone()->getId(),$productTypeObj->getRateid(),31);$zoneWiseMasterRateTs = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(),$zoneWiseMasterRateTypeObj->getRateType(),$courierObj->getId(),$courierWiseZoneObj->getZone()->getId(),$productTypeObj->getRateid(),71);$finalRate = $zoneWiseMasterRateFs->getRate() + (40 * $zoneWiseMasterRateSs->getRate()) + (($rateBookingWeight - 70) * $zoneWiseMasterRateTs->getRate());}$salesInvoiceDetailsObj->setBookingRate($finalRate);}}else{// Expedite Or Cash Master Rate$countryWiseCashMasterRate = $entityManager->getRepository(CountryWiseMasterRate::class)->findCashBookingRatebyCourierAndWeight(2, $salesInvoiceDetailsObj->getShipmentDate(), $courierObj->getId(), $countryObj->getId(), $productTypeObj->getRateid(), $rateBookingWeight);if($countryWiseCashMasterRate == null){$zoneWiseMasterRate = $entityManager->getRepository(ZoneWiseMasterRate::class)->findBookingCashRatebyCourierAndWeight(3, $salesInvoiceDetailsObj->getShipmentDate(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight );}if($countryWiseCashMasterRate !== null){$salesInvoiceDetailsObj->setBookingRate($countryWiseCashMasterRate->getRate() * $rateBookingWeight);}else if($zoneWiseMasterRate !== null){$salesInvoiceDetailsObj->setBookingRate(round(($zoneWiseMasterRate->getRate() * $rateBookingWeight) / $settingsObj->getCurrency(),2));}else{return new JsonResponse(array('success' => false, 'responseText' => 'Cash Master Rate is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}//$salesInvoiceDetailsObj->setBookingRate($countryObj->getMasterExpediteRate() * $rateBookingWeight);}//Master Rate Assign End// Own Company Rate for Customer Start$salesCourierId = 0;$salesCourierName = "";$salesZoneId = 0;if($this->getUser()->getUserCompany()->getCustomerRate() == 2 ) // Own Company Wise Customer Rate{if($customerObj->getCustomerType() == 1 ) //Customer{$salesCourierId = $this->getUser()->getUserCompany()->getCompanyCourier()->getId();$salesCourierName = $this->getUser()->getUserCompany()->getCompanyCourier()->getName();/// Zone$courierWiseZoneObject = $entityManager->getRepository(CourierWiseZone::class)->findOneBy(['courier' => $salesCourierId, 'country' => $countryObj->getId() ]);if($courierWiseZoneObject === null ){return new JsonResponse(array('success' => false, 'responseText' => 'Courier Wise Zone is not set for Courier : '. $courierObj->getName().', and Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}$salesZoneId = $courierWiseZoneObject->getZone()->getId();}else //Agent{$salesCourierId = $courierObj->getId();$salesCourierName = $courierObj->getName();$salesZoneId = $courierWiseZoneObj->getZone()->getId();}}else // Separate Courier Wise Customer Rate{$salesCourierId = $courierObj->getId();$salesCourierName = $courierObj->getName();$salesZoneId = $courierWiseZoneObj->getZone()->getId();}// Own Company Rate for Customer Endif($salesInvoiceDetailsObj->getRateApplicable() <= 2 && !$salesInvoiceDetailsObj->getShipment()->isExpedite()) // Predefine Rate{$finalRateCal = 0;if($customerObj->getRateType() == 1) // Customer wise sales rate{if($courierObj->getId() != 3){if($rateWeight < $perKgRateWeight ){$countryWiseSalesRate = $entityManager->getRepository(CountryWiseSalesRate::class)->findOneBy(['type' => $shipmentObj->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $salesCourierId, 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateWeight ]);if($countryWiseSalesRate !== null){$finalRateCal = $countryWiseSalesRate->getRate();}}else{$countryWiseSalesRate = $entityManager->getRepository(CountryWiseSalesRate::class)->findOneBy(['type' => $shipmentObj->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $salesCourierId, 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);if($countryWiseSalesRate !== null){$finalRateCal = $countryWiseSalesRate->getRate() * $rateWeight;}}if($countryWiseSalesRate === null){if($rateWeight < $perKgRateWeight ){$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(), $customerObj->getId(), $salesCourierId, $salesZoneId, $productTypeObj->getRateid(), $rateWeight);if($zoneWiseSalesRate !== null){$finalRateCal = $zoneWiseSalesRate->getRate();}}else{$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(), $customerObj->getId(), $salesCourierId, $salesZoneId, $productTypeObj->getRateid(), $courierObj->getId() == 3 ? $perKgRateWeight : $rateWeight );if($zoneWiseSalesRate !== null){$finalRateCal = $zoneWiseSalesRate->getRate() * $rateWeight;}}}if($countryWiseSalesRate !== null){$salesInvoiceDetailsObj->setSalesRate($finalRateCal);}else if($zoneWiseSalesRate !== null){$salesInvoiceDetailsObj->setSalesRate($finalRateCal);}else{return new JsonResponse(array('success' => false, 'responseText' => '7Customer Wise Sales Rate is not set for Customer : '.$customerObj->getName().' Courier : '.$salesCourierName.', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}}else{if($rateWeight <= 30){$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(),$customerObj->getId(),$salesCourierId,$salesZoneId,$productTypeObj->getRateid(),$rateWeight);$finalSalesRate = $zoneWiseSalesRate->getRate();}else if($rateWeight > 30 && $rateWeight <= 70){$zoneWiseSalesRateFs = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(),$customerObj->getId(),$salesCourierId,$salesZoneId,$productTypeObj->getRateid(),30);$zoneWiseSalesRateSs = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(),$customerObj->getId(),$salesCourierId,$salesZoneId,$productTypeObj->getRateid(),31);$finalSalesRate = $zoneWiseSalesRateFs->getRate() + (($rateWeight - 30) * $zoneWiseSalesRateSs->getRate());}else if($rateWeight > 70){$zoneWiseSalesRateFs = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(),$customerObj->getId(),$salesCourierId,$salesZoneId,$productTypeObj->getRateid(),30);$zoneWiseSalesRateSs = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(),$customerObj->getId(),$salesCourierId,$salesZoneId,$productTypeObj->getRateid(),31);$zoneWiseSalesRateTs = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(),$customerObj->getId(),$salesCourierId,$salesZoneId,$productTypeObj->getRateid(),71);$finalSalesRate = $zoneWiseSalesRateFs->getRate() + (40 * $zoneWiseSalesRateSs->getRate()) + (($rateWeight - 70) * $zoneWiseSalesRateTs->getRate());}$salesInvoiceDetailsObj->setSalesRate($finalSalesRate);}}else // Common sales rate{if($rateWeight < $perKgRateWeight ){$countryWiseSalesRate = $entityManager->getRepository(CountryWiseCommonSalesRate::class)->findOneBy(['type' => $shipmentObj->getShipmentType(), 'courier' => $salesCourierId, 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateWeight ]);}else{$countryWiseSalesRate = $entityManager->getRepository(CountryWiseCommonSalesRate::class)->findOneBy(['type' => $shipmentObj->getShipmentType(), 'courier' => $salesCourierId, 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);if($countryWiseSalesRate !== null){$countryWiseSalesRate->setRate($countryWiseSalesRate->getRate() * $rateWeight);}}if($countryWiseSalesRate === null){if($rateWeight < $perKgRateWeight ){$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseCommonSalesRate::class)->findCommonSalesRatebyCourierAndWeight($shipmentObj->getShipmentType(), $salesCourierId, $salesZoneId, $productTypeObj->getRateid(), $rateWeight);}else{$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseCommonSalesRate::class)->findCommonSalesRatebyCourierAndWeight($shipmentObj->getShipmentType(), $salesCourierId, $salesZoneId, $productTypeObj->getRateid(), $courierObj->getId() == 3 ? $perKgRateWeight : $rateWeight );if($zoneWiseSalesRate !== null){$zoneWiseSalesRate->setRate($zoneWiseSalesRate->getRate() * $rateWeight);}}}if($countryWiseSalesRate !== null){$salesInvoiceDetailsObj->setSalesRate($zoneWiseSalesRate->getRate());}else if($zoneWiseSalesRate !== null){$salesInvoiceDetailsObj->setSalesRate($countryWiseSalesRate->getRate());}else{return new JsonResponse(array('success' => false, 'responseText' => 'Common Sales Rate is not set for Courier : '.$salesCourierName.', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}}//Sales Rate Assign End}else // Special Calculated Rate{$salesInvoiceDetailsObj->setSalesRate(round((float)$salesRate_array[$index] / $settingsObj->getCurrency(),2));}// Master Weight and Sales Rate Calculation Startif($salesInvoiceDetailsObj->getRateApplicable() <= 2 && !$salesInvoiceDetailsObj->getShipment()->isExpedite()) // Predefine Rate{$finalRateCal = 0;if($customerObj->getRateType() == 1) // Customer wise sales rate{if($rateBookingWeight < $perKgRateWeight ){$countryWiseSalesRate = $entityManager->getRepository(CountryWiseSalesRate::class)->findOneBy(['type' => $shipmentObj->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateBookingWeight ]);if($countryWiseSalesRate !== null){$finalRateCal = $countryWiseSalesRate->getRate();}}else{$countryWiseSalesRate = $entityManager->getRepository(CountryWiseSalesRate::class)->findOneBy(['type' => $shipmentObj->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);if($countryWiseSalesRate !== null){$finalRateCal = $countryWiseSalesRate->getRate() * $rateBookingWeight;}}if($countryWiseSalesRate === null){if($rateBookingWeight < $perKgRateWeight ){$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(), $customerObj->getId(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight);// return new JsonResponse(array('success' => false, 'responseText' => $rateBookingWeight .'-'. $zoneWiseSalesRate->getRate() ));if($zoneWiseSalesRate !== null){$finalRateCal = $zoneWiseSalesRate->getRate();}}else{// return new JsonResponse(array('success' => false, 'responseText' => $shipmentObj->getShipmentType() .' - '. $customerObj->getId() .' - '.$courierObj->getId() .' - '. $courierWiseZoneObj->getZone()->getId() .' - '. $productTypeObj->getRateid() . ' - ' .$rateBookingWeight ));$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseSalesRate::class)->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(), $customerObj->getId(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight );if($zoneWiseSalesRate !== null){$finalRateCal = $zoneWiseSalesRate->getRate() * $rateBookingWeight;}}}if($countryWiseSalesRate !== null){$salesInvoiceDetailsObj->setSalesMasterRate($finalRateCal);}else if($zoneWiseSalesRate !== null){$salesInvoiceDetailsObj->setSalesMasterRate($finalRateCal);}else{return new JsonResponse(array('success' => false, 'responseText' => '8Customer Wise Sales Rate is not set for Customer : '.$customerObj->getName().' Courier : '.$salesCourierName.', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}}else // Common sales rate{if($rateBookingWeight < $perKgRateWeight ){$countryWiseSalesRate = $entityManager->getRepository(CountryWiseCommonSalesRate::class)->findOneBy(['type' => $shipmentObj->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateBookingWeight ]);}else{$countryWiseSalesRate = $entityManager->getRepository(CountryWiseCommonSalesRate::class)->findOneBy(['type' => $shipmentObj->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);if($countryWiseSalesRate !== null){$countryWiseSalesRate->setRate($countryWiseSalesRate->getRate() * $rateWeight);}}if($countryWiseSalesRate === null){if($rateWeight < $perKgRateWeight ){$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseCommonSalesRate::class)->findCommonSalesRatebyCourierAndWeight($shipmentObj->getShipmentType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight);}else{$zoneWiseSalesRate = $entityManager->getRepository(ZoneWiseCommonSalesRate::class)->findCommonSalesRatebyCourierAndWeight($shipmentObj->getShipmentType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $courierObj->getId() == 3 ? $perKgRateWeight : $rateBookingWeight );if($zoneWiseSalesRate !== null){$zoneWiseSalesRate->setRate($zoneWiseSalesRate->getRate() * $rateBookingWeight);}}}if($countryWiseSalesRate !== null){$salesInvoiceDetailsObj->setSalesMasterRate($zoneWiseSalesRate->getRate());}else if($zoneWiseSalesRate !== null){$salesInvoiceDetailsObj->setSalesMasterRate($countryWiseSalesRate->getRate());}else{return new JsonResponse(array('success' => false, 'responseText' => 'Common Sales Rate is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().', Product Type : '.$productTypeObj->getName().', Weight : '.$rateWeight.' in Row Number '.$keyValue.'.'));}}//Sales Rate Assign End}else // Special Calculated Rate{// Get Settings Currency Start$settingsObj = $settingsInfoRepository->findByDateCurrency(1, $salesInvoiceDetailsObj->getShipmentDate()->format('Y-m-d'));if($settingsObj === null){return new JsonResponse(array('success' => false, 'responseText' => 'Currency is not set in Settings for Month : '.$salesInvoiceDetailsObj->getShipmentDate()->format('F').'-'.$salesInvoiceDetailsObj->getShipmentDate()->format('Y').' in Row Number '.$keyValue.'.'));}// Get Settings Currency End$salesInvoiceDetailsObj->setSalesMasterRate(round((float)$salesRate_array[$index] / $settingsObj->getCurrency(),2));}// Master Weight and Sales Rate Calculation End// SRO Calculation Startif($courierObj->getSro() == 1 && $salesInvoiceDetailsObj->getRateApplicable() <= 2){$salesInvoiceDetailsObj->setSro($courierObj->getSroCharge());}// SRO Calculation End//Master Covid Charge Cal Startif($salesInvoiceDetailsObj->getRateApplicable() <= 3 && !$salesInvoiceDetailsObj->getShipment()->isExpedite()){if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 1) // DHL Covid Charge Cal{// $zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);// if($zoneWiseCovidCharge === null)// {// $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);// }// Demand Charge Start// $comparisonDate = new DateTime('2024-09-14');// if($salesInvoiceDetailsObj->getShipmentDate() > $comparisonDate)// {// $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);// if($countryWiseCovidCharge !== null)// {// $salesInvoiceDetailsObj->setVendorCovidCharge($countryWiseCovidCharge->getRate() * $rateBookingWeight);// //$salesInvoiceDetailsObj->setCovidCharge($countryWiseCovidCharge->getRate() * $rateWeight);// }// else// {// return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));// }// }// Demand Charge End// // Go Green Charge Start// $comparisonDate = new DateTime('2024-04-01');// if ($salesInvoiceDetailsObj->getShipmentDate() < $comparisonDate) {// if($countryObj->getId() == 11 || $countryObj->getId() == 151)// {// $covidChargeUsd = 3.35;// }// else// {// $covidChargeUsd = 1.15;// }// } else {// if($countryObj->getId() == 11 || $countryObj->getId() == 151)// {// $covidChargeUsd = 0.56;// }// else// {// $covidChargeUsd = 0.56;// }// }// $salesInvoiceDetailsObj->setVendorCovidCharge($covidChargeUsd * $rateBookingWeight);// // Go Green Charge End}else if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 2) // Fedex Covid Charge Cal{// Demand Charge Start$comparisonDate = new DateTime('2024-11-17');if($salesInvoiceDetailsObj->getShipmentDate() > $comparisonDate){$zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);if($zoneWiseCovidCharge !== null){$demandCharge = $zoneWiseCovidCharge->getRate() * $rateBookingWeight;if($demandCharge < 1)$salesInvoiceDetailsObj->setVendorCovidCharge(1);else$salesInvoiceDetailsObj->setVendorCovidCharge($demandCharge);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}}else{if($rateBookingWeight <= 3){$salesInvoiceDetailsObj->setVendorCovidCharge(1);}else{$salesInvoiceDetailsObj->setVendorCovidCharge($rateBookingWeight * 0.30);}}}}//Master Covid Charge Cal End//Sales Covid Charge Cal Startif($salesInvoiceDetailsObj->getRateApplicable() <= 2 && !$salesInvoiceDetailsObj->getShipment()->isExpedite()){if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 1) // DHL Covid Charge Cal{// $zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);// if($zoneWiseCovidCharge === null)// {// $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);// }// Demand Charge Start// $comparisonDate = new DateTime('2024-09-14');// if($salesInvoiceDetailsObj->getShipmentDate() > $comparisonDate)// {// $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)// ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);// if($countryWiseCovidCharge !== null)// {// // $salesInvoiceDetailsObj->setVendorCovidCharge($countryWiseCovidCharge->getRate() * $rateBookingWeight);// $salesInvoiceDetailsObj->setCovidCharge($countryWiseCovidCharge->getRate() * $rateWeight);// }// else// {// return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));// }// }// Demand Charge End// // Go Green Charge Start// $comparisonDate = new DateTime('2024-04-01');// if ($salesInvoiceDetailsObj->getShipmentDate() < $comparisonDate) {// if($countryObj->getId() == 11 || $countryObj->getId() == 151)// {// $covidChargeUsd = 3.35;// }// else// {// $covidChargeUsd = 1.15;// }// } else {// if($countryObj->getId() == 11 || $countryObj->getId() == 151)// {// $covidChargeUsd = 0.56;// }// else// {// $covidChargeUsd = 0.56;// }// }// $salesInvoiceDetailsObj->setVendorCovidCharge($covidChargeUsd * $rateWeight);// // Go Green Charge End}else if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 2) // Fedex Covid Charge Cal{// Demand Charge Start$comparisonDate = new DateTime('2024-11-17');if($salesInvoiceDetailsObj->getShipmentDate() > $comparisonDate){$zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]);if($zoneWiseCovidCharge !== null){$demandCharge = $zoneWiseCovidCharge->getRate() * $rateWeight;if($demandCharge < 1)$salesInvoiceDetailsObj->setCovidCharge(1);else$salesInvoiceDetailsObj->setCovidCharge($demandCharge);}else{return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));}}else{if($rateWeight <= 3){$salesInvoiceDetailsObj->setCovidCharge(1);}else{$salesInvoiceDetailsObj->setCovidCharge($rateWeight * 0.30);}}}}//Sales Covid Charge Cal End$salesInvoiceDetailsList->add($salesInvoiceDetailsObj);$index ++;}//Data Save Process Start$index = 0;$individualSalesInvoiceId = 0;foreach($salesInvoiceDetailsList as $row){$keyValue = $key;$keyValue = $keyValue + 1;$shipmentDate = $row->getShipmentDate();// Demand Charge Startif($row->getCourier()->getId() == 1){$comparisonDate = new DateTime('2025-10-01');if($shipmentDate >= $comparisonDate){$countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)->findOneBy(['courier' => $row->getCourier()->getId(), 'country' => $row->getCountry()->getId()]);if($countryWiseCovidCharge !== null){//Vendor/Booking weight Calculation Start// Half and Per KG$bookingWeight = $row->getBookingWeight();$pointInputBookingWeight = $bookingWeight - floor($bookingWeight);$intInputBookingWeight = floor($bookingWeight);// return new JsonResponse(array('success' => false, 'responseText' => $bookingWeight ));$finalBookingWeight = 0;$rateBookingWeight = 0;if($bookingWeight < $row->getCourier()->getWeightPerkg()){if($pointInputBookingWeight > 0 && $pointInputBookingWeight <= 0.5){$finalBookingWeight = (float)0.5;}elseif($pointInputBookingWeight > 0.5 && $pointInputBookingWeight <=1){$finalBookingWeight = (float)1;}}else{if($pointInputBookingWeight > 0 && $pointInputBookingWeight <=1){$finalBookingWeight = (float)1;}}$rateBookingWeight = $intInputBookingWeight + $finalBookingWeight;//Vendor/Booking weight Calculation End//Customer Weight Calculation Start// Half and Per KG$weight = $row->getWeight();$pointInputWeight = $weight - floor($weight);$intInputWeight = floor($weight);$finalWeight = 0;$rateWeight = 0;if($weight < $row->getCourier()->getWeightPerkg()){if($pointInputWeight > 0 && $pointInputWeight <= 0.5){$finalWeight = (float)0.5;}elseif($pointInputWeight > 0.5 && $pointInputWeight <=1){$finalWeight = (float)1;}}else{if($pointInputWeight > 0 && $pointInputWeight <=1){$finalWeight = (float)1;}}$rateWeight = $intInputWeight + $finalWeight;//Customer Weight Calculation End$bookingDemandCharge = $countryWiseCovidCharge->getRate() * $rateBookingWeight;$salesDemandCharge = $countryWiseCovidCharge->getRate() * $rateWeight;}else{return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$row->getCourier()->getName().', Country : '.$row->getCountry()->getName().' in Row Number '.$keyValue.'.'));}}else{$bookingDemandCharge = 0;$salesDemandCharge = 0;}}// Demand Charge End// Get Settings Currency Start$settingsObj = $settingsInfoRepository->findByDateCurrency(1, $shipmentDate->format('Y-m-d'));if($settingsObj === null){return new JsonResponse(array('success' => false, 'responseText' => 'Currency is not set in Settings for Month : '.$shipmentDate->format('F').'-'.$shipmentDate->format('Y').' in Row Number '.$keyValue.'.'));}// Get Settings Currency End// Get Vendor FSC Start$vendorFscObj = $settingsInfoRepository->findByDate(2, $row->getCourier()->getId(), $shipmentDate->format('Y-m-d'));if($vendorFscObj === null){return new JsonResponse(array('success' => false, 'responseText' => 'FSC is not set in FSC Setup for Courier: '.$courierObj->getName().' Month : '.$shipmentDate->format('F').'-'.$shipmentDate->format('Y').' in Row Number '.$keyValue.'.'));}// Get Vendor FSC End// Get Customer FSC Start$fscObj = $settingsInfoRepository->findByDate(2, $this->getUser()->getUserCompany()->getCustomerRate() == 1 ? $row->getCourier()->getId() : $salesCourierId, $shipmentDate->format('Y-m-d'));if($fscObj === null){return new JsonResponse(array('success' => false, 'responseText' => 'FSC is not set in FSC Setup for Month : '.$shipmentDate->format('F').'-'.$shipmentDate->format('Y').' in Row Number '.$keyValue.'.'));}// Get Customer FSC End$firstDateofMonth = date('Y-m-01', strtotime($shipmentDate->format('Y-m-d')));$lastDateofMonth = date('Y-m-t', strtotime($shipmentDate->format('Y-m-d')));$lastDateofMonth = new \DateTime($lastDateofMonth);$halfDateofMonth = date('Y-m-d', strtotime($firstDateofMonth. ' + 14 days'));$halfDateofMonth = new \DateTime($halfDateofMonth);if($row->getCustomer()->getRateCurrency() == 2){$row->setRateApplicable(3);}if($row->getCustomer()->getInvoicePeriod() == 1) //Monthly Invoice Save Process{$salesInvoiceObj = $salesInvoiceRepository->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $lastDateofMonth, $lastDateofMonth, $shipmentObj->getShipmentType(), $row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );$invocieDate = $lastDateofMonth;if($salesInvoiceObj === null){$salesInv = new SalesInvoice();$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInv->setCustomer($row->getCustomer());$salesInvocieLastObj = $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());$invoiceNO = $utilsService->invoiceNoGenerator($salesInvocieLastObj, $row->getCustomer(), $invocieDate, $shipmentObj->getShipmentType());$salesInv->setInvoiceNo($invoiceNO);$salesInv->setInvoiceDate($invocieDate);$salesInv->setVat($settingsObj->getVat());$salesInv->setApproval(0);$salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());$salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());$salesInv->setRateApplicable($row->getRateApplicable());$salesInv->setInvoiceType($shipmentObj->getShipmentType());$salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());$salesInvoiceDetailsObj->setReference($row->getReference());$salesInvoiceDetailsObj->setWeight($row->getWeight());$salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());$salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());$salesInvoiceDetailsObj->setCountry($row->getCountry());$salesInvoiceDetailsObj->setZone($row->getZone());$salesInvoiceDetailsObj->setProductType($row->getProductType());$salesInvoiceDetailsObj->setCourier($row->getCourier());$salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());$salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());if($row->getCustomer()->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCurrency(1);}else{$salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == 0 ? $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );}$salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());$salesInvoiceDetailsObj->setVatApplicable(0);$salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());if($row->getRateApplicable() <= 2)$salesInvoiceDetailsObj->setFsc( $row->getCustomer()->getFsc() == 0 ? $fscObj->getCurrency() : $row->getCustomer()->getFsc() );else$salesInvoiceDetailsObj->setFsc(0);if($row->getRateApplicable() <= 3)$salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency());else$salesInvoiceDetailsObj->setVendorFsc(0);$salesInvoiceDetailsObj->setCustomer($row->getCustomer());$salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null ? 0 : $row->getCovidCharge());$salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null ? 0 : $row->getVendorCovidCharge());$salesInvoiceDetailsObj->setShipment($row->getShipment());$salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());$salesInvoiceDetailsObj->setSro($row->getSro());// UPS Shipment Processing Fee Start 217if($row->getCourier()->getId() == 3 && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee$invoiceAdditionalChargeObj->setCharge(2.5);$invoiceAdditionalChargeObj->setFsc(0);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge(2.5);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}// UPS Shipment Processing Fee Start//DHL Demand Charge Startif($row->getCourier()->getId() == 1 && $shipmentDate > $comparisonDate){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee$invoiceAdditionalChargeObj->setCharge($salesDemandCharge);$invoiceAdditionalChargeObj->setFsc(1);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}//DHL Demand Charge End$salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);$entityManager->persist($salesInv);$entityManager->flush($salesInv);$salesInvoiceId = $salesInv->getId();}else{$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());$salesInvoiceDetailsObj->setReference($row->getReference());$salesInvoiceDetailsObj->setWeight($row->getWeight());$salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());$salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());$salesInvoiceDetailsObj->setCountry($row->getCountry());$salesInvoiceDetailsObj->setZone($row->getZone());$salesInvoiceDetailsObj->setProductType($row->getProductType());$salesInvoiceDetailsObj->setCourier($row->getCourier());$salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());$salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());if($row->getCustomer()->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCurrency(1);}else{$salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == 0 ? $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );}$salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());$salesInvoiceDetailsObj->setVatApplicable(0);$salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());if($row->getRateApplicable() <= 2)$salesInvoiceDetailsObj->setFsc( $row->getCustomer()->getFsc() == 0 ? $fscObj->getCurrency() : $row->getCustomer()->getFsc() );else$salesInvoiceDetailsObj->setFsc(0);if($row->getRateApplicable() <= 3)$salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency());else$salesInvoiceDetailsObj->setVendorFsc(0);$salesInvoiceDetailsObj->setCustomer($row->getCustomer());$salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null ? 0 : $row->getCovidCharge());$salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null ? 0 : $row->getVendorCovidCharge());$salesInvoiceDetailsObj->setSalesInvoice($salesInvoiceObj);$salesInvoiceDetailsObj->setShipment($row->getShipment());$salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());$salesInvoiceDetailsObj->setSro($row->getSro());// UPS Shipment Processing Fee Startif($row->getCourier()->getId() == 3 && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee$invoiceAdditionalChargeObj->setCharge(2.5);$invoiceAdditionalChargeObj->setFsc(0);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge(2.5);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}// UPS Shipment Processing Fee Start//DHL Demand Charge Startif($row->getCourier()->getId() == 1 && $shipmentDate > $comparisonDate){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee$invoiceAdditionalChargeObj->setCharge($salesDemandCharge);$invoiceAdditionalChargeObj->setFsc(1);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}//DHL Demand Charge End$entityManager->persist($salesInvoiceDetailsObj);$entityManager->flush($salesInvoiceDetailsObj);}}else if($row->getCustomer()->getInvoicePeriod() == 2) //Half Monthly Invoice Save Process{if($shipmentDate <= $halfDateofMonth) // First Half month{$salesInvoiceObj = $salesInvoiceRepository->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $halfDateofMonth, $halfDateofMonth, $shipmentObj->getShipmentType(), $row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );$invocieDate = $halfDateofMonth;}else{$salesInvoiceObj = $salesInvoiceRepository->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $lastDateofMonth, $lastDateofMonth, $shipmentObj->getShipmentType(), $row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );$invocieDate = $lastDateofMonth;}////////////////Common portionif($salesInvoiceObj === null){$salesInv = new SalesInvoice();$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInv->setCustomer($row->getCustomer());$salesInvocieLastObj = $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());$invoiceNO = $utilsService->invoiceNoGenerator($salesInvocieLastObj, $row->getCustomer(), $invocieDate, $shipmentObj->getShipmentType());$salesInv->setInvoiceNo($invoiceNO);$salesInv->setInvoiceDate($invocieDate);$salesInv->setVat($settingsObj->getVat());$salesInv->setApproval(0);$salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());$salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());$salesInv->setRateApplicable($row->getRateApplicable());$salesInv->setInvoiceType($shipmentObj->getShipmentType());$salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());$salesInvoiceDetailsObj->setReference($row->getReference());$salesInvoiceDetailsObj->setWeight($row->getWeight());$salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());$salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());$salesInvoiceDetailsObj->setCountry($row->getCountry());$salesInvoiceDetailsObj->setZone($row->getZone());$salesInvoiceDetailsObj->setProductType($row->getProductType());$salesInvoiceDetailsObj->setCourier($row->getCourier());$salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());$salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());if($row->getCustomer()->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCurrency(1);}else{$salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == 0 ? $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );}$salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());$salesInvoiceDetailsObj->setVatApplicable(0);$salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());if($row->getRateApplicable() <= 2)$salesInvoiceDetailsObj->setFsc( $row->getCustomer()->getFsc() == 0 ? $fscObj->getCurrency() : $row->getCustomer()->getFsc() );else$salesInvoiceDetailsObj->setFsc(0);if($row->getRateApplicable() <= 3)$salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency());else$salesInvoiceDetailsObj->setVendorFsc(0);$salesInvoiceDetailsObj->setCustomer($row->getCustomer());$salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null ? 0 : $row->getCovidCharge());$salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null ? 0 : $row->getVendorCovidCharge());$salesInvoiceDetailsObj->setShipment($row->getShipment());$salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());$salesInvoiceDetailsObj->setSro($row->getSro());// UPS Shipment Processing Fee Startif($row->getCourier()->getId() == 3 && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee$invoiceAdditionalChargeObj->setCharge(2.5);$invoiceAdditionalChargeObj->setFsc(0);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge(2.5);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}// UPS Shipment Processing Fee Start//DHL Demand Charge Startif($row->getCourier()->getId() == 1 && $shipmentDate > $comparisonDate){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee$invoiceAdditionalChargeObj->setCharge($salesDemandCharge);$invoiceAdditionalChargeObj->setFsc(1);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}//DHL Demand Charge End$salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);$entityManager->persist($salesInv);$entityManager->flush($salesInv);$salesInvoiceId = $salesInv->getId();}else{$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());$salesInvoiceDetailsObj->setReference($row->getReference());$salesInvoiceDetailsObj->setWeight($row->getWeight());$salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());$salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());$salesInvoiceDetailsObj->setCountry($row->getCountry());$salesInvoiceDetailsObj->setZone($row->getZone());$salesInvoiceDetailsObj->setProductType($row->getProductType());$salesInvoiceDetailsObj->setCourier($row->getCourier());$salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());$salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());if($row->getCustomer()->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCurrency(1);}else{$salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == 0 ? $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );}$salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());$salesInvoiceDetailsObj->setVatApplicable(0);$salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());if($row->getRateApplicable() <= 2)$salesInvoiceDetailsObj->setFsc( $row->getCustomer()->getFsc() == 0 ? $fscObj->getCurrency() : $row->getCustomer()->getFsc() );else$salesInvoiceDetailsObj->setFsc(0);if($row->getRateApplicable() <= 3)$salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency());else$salesInvoiceDetailsObj->setVendorFsc(0);$salesInvoiceDetailsObj->setCustomer($row->getCustomer());$salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null ? 0 : $row->getCovidCharge());$salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null ? 0 : $row->getVendorCovidCharge());$salesInvoiceDetailsObj->setSalesInvoice($salesInvoiceObj);$salesInvoiceDetailsObj->setShipment($row->getShipment());$salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());$salesInvoiceDetailsObj->setSro($row->getSro());// UPS Shipment Processing Fee Startif($row->getCourier()->getId() == 3 && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee$invoiceAdditionalChargeObj->setCharge(2.5);$invoiceAdditionalChargeObj->setFsc(0);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge(2.5);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}// UPS Shipment Processing Fee Start//DHL Demand Charge Startif($row->getCourier()->getId() == 1 && $shipmentDate > $comparisonDate){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee$invoiceAdditionalChargeObj->setCharge($salesDemandCharge);$invoiceAdditionalChargeObj->setFsc(1);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}//DHL Demand Charge End$entityManager->persist($salesInvoiceDetailsObj);$entityManager->flush($salesInvoiceDetailsObj);}/////////////Common}else if($row->getCustomer()->getInvoicePeriod() == 4) //Weekly Invoice Save Process{$invoicePeriods = [['start' => 1, 'end' => 7],['start' => 8, 'end' => 15],['start' => 16, 'end' => 22],['start' => 23, 'end' => $lastDateofMonth],];$invoicePeriod = $this->getInvoicePeriod($row->getShipmentDate(), $invoicePeriods);// return new JsonResponse(array('success' => false, 'responseText' => $invoicePeriod['start']. ' - ' . $invoicePeriod['end'] ));$fromInvDate = clone $row->getShipmentDate();$fromInvDate->setDate($fromInvDate->format('Y'), // Maintain the original year$fromInvDate->format('m'), // Maintain the original month$invoicePeriod['start'] // Set the new day);$toInvDate = clone $row->getShipmentDate();$toInvDate->setDate($toInvDate->format('Y'), // Maintain the original year$toInvDate->format('m'), // Maintain the original month$invoicePeriod['end'] // Set the new day);$salesInvoiceObj = $salesInvoiceRepository->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $fromInvDate, $toInvDate, $shipmentObj->getShipmentType(), $row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );if($salesInvoiceObj === null){$invocieDate = $toInvDate;$salesInv = new SalesInvoice();$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInv->setCustomer($row->getCustomer());$salesInvocieLastObj = $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());$invoiceNO = $utilsService->invoiceNoGenerator($salesInvocieLastObj, $row->getCustomer(), $invocieDate, $shipmentObj->getShipmentType());$salesInv->setInvoiceNo($invoiceNO);$salesInv->setInvoiceDate($invocieDate);$salesInv->setVat($settingsObj->getVat());$salesInv->setApproval(0);$salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());$salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());$salesInv->setRateApplicable($row->getRateApplicable());$salesInv->setInvoiceType($shipmentObj->getShipmentType());$salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());$salesInvoiceDetailsObj->setReference($row->getReference());$salesInvoiceDetailsObj->setWeight($row->getWeight());$salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());$salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());$salesInvoiceDetailsObj->setCountry($row->getCountry());$salesInvoiceDetailsObj->setZone($row->getZone());$salesInvoiceDetailsObj->setProductType($row->getProductType());$salesInvoiceDetailsObj->setCourier($row->getCourier());$salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());$salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());if($row->getCustomer()->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCurrency(1);}else{$salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == 0 ? $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );}$salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());$salesInvoiceDetailsObj->setVatApplicable(0);$salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());if($row->getRateApplicable() <= 2)$salesInvoiceDetailsObj->setFsc( $row->getCustomer()->getFsc() == 0 ? $fscObj->getCurrency() : $row->getCustomer()->getFsc() );else$salesInvoiceDetailsObj->setFsc(0);if($row->getRateApplicable() <= 3)$salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency());else$salesInvoiceDetailsObj->setVendorFsc(0);$salesInvoiceDetailsObj->setCustomer($row->getCustomer());$salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null ? 0 : $row->getCovidCharge());$salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null ? 0 : $row->getVendorCovidCharge());$salesInvoiceDetailsObj->setShipment($row->getShipment());$salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());$salesInvoiceDetailsObj->setSro($row->getSro());// UPS Shipment Processing Fee Startif($row->getCourier()->getId() == 3 && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee$invoiceAdditionalChargeObj->setCharge(2.5);$invoiceAdditionalChargeObj->setFsc(0);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge(2.5);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}// UPS Shipment Processing Fee Start//DHL Demand Charge Startif($row->getCourier()->getId() == 1 && $shipmentDate > $comparisonDate){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee$invoiceAdditionalChargeObj->setCharge($salesDemandCharge);$invoiceAdditionalChargeObj->setFsc(1);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}//DHL Demand Charge End$salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);$entityManager->persist($salesInv);$entityManager->flush($salesInv);$salesInvoiceId = $salesInv->getId();}else{$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());$salesInvoiceDetailsObj->setReference($row->getReference());$salesInvoiceDetailsObj->setWeight($row->getWeight());$salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());$salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());$salesInvoiceDetailsObj->setCountry($row->getCountry());$salesInvoiceDetailsObj->setZone($row->getZone());$salesInvoiceDetailsObj->setProductType($row->getProductType());$salesInvoiceDetailsObj->setCourier($row->getCourier());$salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());$salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());if($row->getCustomer()->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCurrency(1);}else{$salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == 0 ? $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );}$salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());$salesInvoiceDetailsObj->setVatApplicable(0);$salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());if($row->getRateApplicable() <= 2)$salesInvoiceDetailsObj->setFsc( $row->getCustomer()->getFsc() == 0 ? $fscObj->getCurrency() : $row->getCustomer()->getFsc() );else$salesInvoiceDetailsObj->setFsc(0);if($row->getRateApplicable() <= 3)$salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency());else$salesInvoiceDetailsObj->setVendorFsc(0);$salesInvoiceDetailsObj->setCustomer($row->getCustomer());$salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null ? 0 : $row->getCovidCharge());$salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null ? 0 : $row->getVendorCovidCharge());$salesInvoiceDetailsObj->setSalesInvoice($salesInvoiceObj);$salesInvoiceDetailsObj->setShipment($row->getShipment());$salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());$salesInvoiceDetailsObj->setSro($row->getSro());// UPS Shipment Processing Fee Startif($row->getCourier()->getId() == 3 && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee$invoiceAdditionalChargeObj->setCharge(2.5);$invoiceAdditionalChargeObj->setFsc(0);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge(2.5);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}// UPS Shipment Processing Fee Start//DHL Demand Charge Startif($row->getCourier()->getId() == 1 && $shipmentDate > $comparisonDate){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee$invoiceAdditionalChargeObj->setCharge($salesDemandCharge);$invoiceAdditionalChargeObj->setFsc(1);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}//DHL Demand Charge End$entityManager->persist($salesInvoiceDetailsObj);$entityManager->flush($salesInvoiceDetailsObj);}}else // HAWB NO Wise Invoice Save Process{$salesInv = new SalesInvoice();$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInv->setCustomer($row->getCustomer());$salesInvocieLastObj = $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());$invoiceNO = $utilsService->invoiceNoGenerator($salesInvocieLastObj, $row->getCustomer(), $shipmentDate, $shipmentObj->getShipmentType());$salesInv->setInvoiceNo($invoiceNO);$salesInv->setInvoiceDate($shipmentDate);$salesInv->setVat($settingsObj->getVat());$salesInv->setApproval(0);$salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());$salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());$salesInv->setRateApplicable($row->getRateApplicable());$salesInv->setInvoiceType($shipmentObj->getShipmentType());$salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());$salesInvoiceDetailsObj->setReference($row->getReference());$salesInvoiceDetailsObj->setWeight($row->getWeight());$salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());$salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());$salesInvoiceDetailsObj->setCountry($row->getCountry());$salesInvoiceDetailsObj->setZone($row->getZone());$salesInvoiceDetailsObj->setProductType($row->getProductType());$salesInvoiceDetailsObj->setCourier($row->getCourier());$salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());$salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());if($row->getCustomer()->getRateCurrency() == 2){$salesInvoiceDetailsObj->setCurrency(1);}else{$salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == 0 ? $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );}$salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == 1 ? $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());$salesInvoiceDetailsObj->setVatApplicable(0);$salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());if($row->getRateApplicable() <= 2)$salesInvoiceDetailsObj->setFsc( $row->getCustomer()->getFsc() == 0 ? $fscObj->getCurrency() : $row->getCustomer()->getFsc() );else$salesInvoiceDetailsObj->setFsc(0);if($row->getRateApplicable() <= 3)$salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency());else$salesInvoiceDetailsObj->setVendorFsc(0);$salesInvoiceDetailsObj->setCustomer($row->getCustomer());$salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null ? 0 : $row->getCovidCharge());$salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null ? 0 : $row->getVendorCovidCharge());$salesInvoiceDetailsObj->setShipment($row->getShipment());$salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());$salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());$salesInvoiceDetailsObj->setSro($row->getSro());// UPS Shipment Processing Fee Startif($row->getCourier()->getId() == 3 && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee$invoiceAdditionalChargeObj->setCharge(2.5);$invoiceAdditionalChargeObj->setFsc(0);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge(2.5);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}// UPS Shipment Processing Fee Start//DHL Demand Charge Startif($row->getCourier()->getId() == 1 && $shipmentDate > $comparisonDate){$invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();$invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee$invoiceAdditionalChargeObj->setCharge($salesDemandCharge);$invoiceAdditionalChargeObj->setFsc(1);$invoiceAdditionalChargeObj->setVat(0);$invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);$salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);}//DHL Demand Charge End$salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);$entityManager->persist($salesInv);$entityManager->flush($salesInv);}$index ++;}}}$this->addFlash('notice', 'Sales Invoice Created successfully!');return new JsonResponse(array('success' => true));}#[Route('/salesinvoice/{id}/accessory-surcharge', name: 'app_sales_invoice_accessory_surcharge', methods: ['GET', 'POST'])]public function accessorySurcharge(SalesInvoice $salesInvoice, EntityManagerInterface $entityManager, Request $request, SettingsInfoRepository $settingsInfoRepository, CourierWiseZoneRepository $courierWiseZoneRepository): Response{$salesInvoice->getSalesInvoiceDetails()->clear();$form = $this->createForm(InvoiceSurchargeType::class, $salesInvoice);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {// Get Settings Currency Start$settingsObj = $settingsInfoRepository->findByDateCurrency(1, $salesInvoice->getInvoiceDate()->format('Y-m-d'));if($settingsObj === null){$this->addFlash('warning', 'Currency is not set in Settings for Month : '.$salesInvoice->getInvoiceDate()->format('F').'-'.$salesInvoice->getInvoiceDate()->format('Y'));return $this->redirectToRoute('app_sales_invoice_show', ['id' => $salesInvoice->getId()]);}// Get Settings Currency Endforeach ($form->get('salesInvoiceDetails') as $formChild) {$salesInvoiceDetailsObj = new SalesInvoiceDetails();$salesInvoiceDetailsObj->setSalesInvoice($salesInvoice);$salesInvoiceDetailsObj->setShipmentDate($formChild->get('shipmentDate')->getData());$salesInvoiceDetailsObj->setHawbNo($formChild->get('hawbNo')->getData());$salesInvoiceDetailsObj->setReference($formChild->get('reference')->getData());$salesInvoiceDetailsObj->setCountry($formChild->get('country')->getData());$salesInvoiceDetailsObj->setProductType($formChild->get('productType')->getData());$salesInvoiceDetailsObj->setCourier($formChild->get('courier')->getData());$courierWiseZoneObj = $courierWiseZoneRepository->findOneBy(['courier' => $formChild->get('courier')->getData()->getId(), 'country' => $formChild->get('country')->getData()->getId() ]);if($courierWiseZoneObj === null ){$this->addFlash('warning', 'Courier Wise Zone is not set for Courier : '. $formChild->get('courier')->getData()->getName().', and Country : '.$formChild->get('country')->getData()->getName());return $this->redirectToRoute('app_sales_invoice_show', ['id' => $salesInvoice->getId()]);}$salesInvoiceDetailsObj->setZone($courierWiseZoneObj->getZone());$salesInvoiceDetailsObj->setWeight($formChild->get('weight')->getData());$salesInvoiceDetailsObj->setBookingWeight($formChild->get('weight')->getData());$salesInvoiceDetailsObj->setSalesRate($formChild->get('salesRate')->getData());$salesInvoiceDetailsObj->setBookingRate($formChild->get('salesRate')->getData());$salesInvoiceDetailsObj->setCurrency($settingsObj->getCurrency());$salesInvoiceDetailsObj->setVendorCurrency($settingsObj->getVendorCurrency());$salesInvoiceDetailsObj->setCovidCharge(0);$salesInvoiceDetailsObj->setFsc(0);$salesInvoiceDetailsObj->setVendorFsc(0);$salesInvoiceDetailsObj->setVendorCovidCharge(0);$salesInvoiceDetailsObj->setSalesMasterRate($formChild->get('salesRate')->getData());$entityManager->persist($salesInvoiceDetailsObj);$entityManager->flush($salesInvoiceDetailsObj);}$this->addFlash('notice', 'Accessory Surcharge Created successfully!');return $this->redirectToRoute('app_sales_invoice_show', ['id' => $salesInvoice->getId()]);}return $this->renderForm('sales_invoice/accessorySurcharge.html.twig', ['salesInvoice' => $salesInvoice,'form' => $form,]);}#[Route('/salesinvoice/country-wise-invoice', name: 'app_sales_invoice_country_wise_invoice', methods: ['GET', 'POST'])]public function countryWiseInvoice(Request $request){$form = $this->createFormBuilder(null)->add('fromDate', DateType::class, ['attr' => ['class' => 'form-control'],'widget' => 'single_text','empty_data' => null,'label' => 'From Date',])->add('toDate', DateType::class, ['attr' => ['class' => 'form-control'],'widget' => 'single_text','empty_data' => null,'label' => 'To Date',])->add('customer', EntityType::class, [// looks for choices from this entity'class' => Customer::class,'query_builder' => function (CustomerRepository $er) {return $er->createQueryBuilder('v')->where('v.userCompany = '.$this->getUser()->getUserCompany()->getId())->orderBy('v.name', 'ASC');},// uses the User.username property as the visible option string'choice_label' => 'name','placeholder' => 'Select a Customer...','attr' => ['class' => 'form-control select-tags','style' => 'width:100%;',],'label' => 'Customer',// used to render a select box, check boxes or radios// 'multiple' => true,// 'expanded' => true,])->add('country', EntityType::class, [// looks for choices from this entity'class' => Country::class,'query_builder' => function (CountryRepository $er) {return $er->createQueryBuilder('v')->orderBy('v.name', 'ASC');},// uses the User.username property as the visible option string'choice_label' => 'name','placeholder' => 'Select a Country...','attr' => ['class' => 'form-control select-tags','style' => 'width:100%;',],'label' => 'Country',// used to render a select box, check boxes or radios// 'multiple' => true,// 'expanded' => true,])->getForm();$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$data = $form->getData();$fromDate = $form->get('fromDate')->getData()->format('Y-m-d');$toDate = $form->get('toDate')->getData()->format('Y-m-d');$customerId = $form->get('customer')->getData()->getId();$countryId = $form->get('country')->getData()->getId();$formInvoice = $this->createFormBuilder(null)->add('reference', EntityType::class, [// looks for choices from this entity'class' => SalesInvoiceDetails::class,'query_builder' => function (SalesInvoiceDetailsRepository $er) use ($fromDate, $toDate, $customerId, $countryId) {return $er->createQueryBuilder('s')->innerJoin('s.salesInvoice', 'i')->andWhere('i.invoiceType = 1')->andWhere('s.shipmentDate BETWEEN :fromDate AND :toDate')->andWhere('i.customer = :customerId')->andWhere('s.country = :countryId')->setParameter('fromDate', $fromDate)->setParameter('toDate', $toDate)->setParameter('customerId', $customerId)->setParameter('countryId', $countryId)->orderBy('s.shipmentDate', 'ASC')->groupBy('s.reference');},// uses the User.username property as the visible option string'choice_label' => 'reference','placeholder' => 'Select a Reference No...','attr' => ['class' => 'form-control select-tags',],'label' => 'Reference',// used to render a select box, check boxes or radios// 'multiple' => true,// 'expanded' => true,])// ADD HIDDEN FIELDS->add('fromDate', HiddenType::class, ['data' => $fromDate,])->add('toDate', HiddenType::class, ['data' => $toDate,])->add('customer', HiddenType::class, ['data' => $customerId,])->add('country', HiddenType::class, ['data' => $countryId,])->getForm();$formInvoice->handleRequest($request);return $this->render('sales_invoice/country_wise_invoice.html.twig', ['formInvoice' => $formInvoice->createView(),'form' => $form->createView(),'track' => 1,]);}$bookingObj = new SalesInvoiceDetails();return $this->render('sales_invoice/country_wise_invoice.html.twig', ['form' => $form->createView(),'bookingList' => $bookingObj,'track' => 0,]);}#[Route('/salesinvoice/country-sales-invoice-preview/', name: 'app_sales_invoice_country_sales_invoice_preview')]#[IsGranted("ROLE_ADMIN")]public function countryWiseInvoicePreview(Request $request, ReceiveVoucherRepository $receiveVoucherRepository, ShipmentRepository $shipmentRepository, SalesInvoiceRepository $salesInvoiceRepository, SettingsInfoRepository $settingsInfoRepository, SalesInvoiceDetailsRepository $repo){$currencyType = 1;$padPrint = 1;// You must rebuild the SAME exact reference form again$formInvoice = $this->createFormBuilder(null)->add('reference', EntityType::class, ['class' => SalesInvoiceDetails::class,'choice_label' => 'reference',])->add('fromDate', HiddenType::class)->add('toDate', HiddenType::class)->add('customer', HiddenType::class)->add('country', HiddenType::class)->getForm();$formInvoice->handleRequest($request);if ($formInvoice->isSubmitted() && $formInvoice->isValid()) {$reference = $formInvoice->get('reference')->getData()->getReference();// HIDDEN FIELD VALUES$fromDate = $formInvoice->get('fromDate')->getData();$toDate = $formInvoice->get('toDate')->getData();$customerId = $formInvoice->get('customer')->getData();$countryId = $formInvoice->get('country')->getData();$results = $repo->createQueryBuilder('s')->innerJoin('s.salesInvoice', 'i')->andWhere('i.invoiceType = 1')->andWhere('s.shipmentDate BETWEEN :fromDate AND :toDate')->andWhere('i.customer = :customerId')->andWhere('s.country = :countryId')->andWhere('s.reference = :reference')->setParameter('fromDate', $fromDate)->setParameter('toDate', $toDate)->setParameter('customerId', $customerId)->setParameter('countryId', $countryId)->setParameter('reference', $reference)->orderBy('s.shipmentDate', 'ASC')->getQuery()->getResult();// Configure Dompdf according to your needs$pdfOptions = new Options();$pdfOptions->set('defaultFont', 'Arial');// Instantiate Dompdf with our options$dompdf = new Dompdf($pdfOptions);$userObj = $this->getUser();$lastReceivedObj = null;$duesAmount = 0;$groupByCourier = null;$totalReceivedAmount = 0;$totalAdjustAmount = 0;$uptoReceivedInvoiceDate = 0;$html = $this->renderView('sales_invoice/country_wise_invoice_preview.html.twig', ['salesInvoice' => $results,'userObj' => $userObj,'lastReceivedObj' => $lastReceivedObj,'duesAmount' => $duesAmount + $uptoReceivedInvoiceDate,'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'. $userObj->getUserCompany()->getLogoPath() ),'currencyType' => $currencyType,'groupByCourier' => $groupByCourier,'padPrint' => $padPrint,'totalReceivedAmount' => $totalReceivedAmount,'totalAdjustAmount' => $totalAdjustAmount,]);// Load HTML to Dompdf$dompdf->loadHtml($html);// (Optional) Setup the paper size and orientation 'portrait' or 'landscape'$dompdf->setPaper('A4', 'portrait');// Render the HTML as PDF$dompdf->render();// Add Watermark in Domdpf// Instantiate canvas instance$canvas = $dompdf->getCanvas();// Get the number of pages in the PDF$pageCount = $canvas->get_page_count();if(1 == 0){$callback = function ($pageNumber) use ($pageCount, $pdfOptions, $canvas) {// Set text opacity$canvas->set_opacity(0.2, 'Multiply');// Instantiate font metrics class$fontMetrics = new FontMetrics($canvas, $pdfOptions);// Get height and width of page$w = $canvas->get_width();$h = $canvas->get_height();// Get font family file$font = $fontMetrics->getFont('times');// Specify watermark text$text = "DRAFT";// Get height and width of text$txtHeight = $fontMetrics->getFontHeight($font, 75);$textWidth = $fontMetrics->getTextWidth($text, $font, 75);// Specify horizontal and vertical position$x = (($w-$textWidth)/2);$y = (($h-$txtHeight)/2);// Writes text at the specified x and y coordinates$canvas->text($x, $y, $text, $font, 75, array(0, 0, 0), 0, 'B');};// Add the callback function to each pagefor ($i = 0; $i < $pageCount; $i++) {$canvas->page_script($callback);}}// Page number and total page count Start// Define the callback function to add the page number and total page count$callback2 = function ($pageNumber) use ($pageCount, $canvas) {// Set text opacity$canvas->set_opacity(0.9, 'Multiply');// Set the text and position for page number and total page count$text = 'Page ' . $pageNumber . ' of ' . $pageCount;$x = 530; // X-coordinate position$y = 813; // Y-coordinate position// Add the page number and total page count to the current page$canvas->text($x, $y, $text, null, 10);};// Add the callback function to each pagefor ($i = 0; $i < $pageCount; $i++) {$canvas->page_script($callback2);}// Output the generated PDF to Browser (force download)$dompdf->stream("Invoice.pdf", ["Attachment" => false]);exit(0);}}private function imageToBase64($path) {$path = $path;$type = pathinfo($path, PATHINFO_EXTENSION);$data = file_get_contents($path);$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);return $base64;}private function getInvoicePeriod(\DateTime $date, array $invoicePeriods): ?array{foreach ($invoicePeriods as $period) {if ($date->format('j') >= $period['start'] && $date->format('j') <= $period['end']) {return $period;}}return null;}}