src/Controller/SalesInvoiceController.php line 69

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\SalesInvoice;
  4. use App\Entity\SalesInvoiceDetails;
  5. use App\Entity\Country;
  6. use App\Entity\Courier;
  7. use App\Entity\ProductType;
  8. use App\Entity\Customer;
  9. use App\Entity\CourierWiseZone;
  10. use App\Entity\ZoneWiseMasterRate;
  11. use App\Entity\CountryWiseMasterRate;
  12. use App\Entity\ZoneWiseSalesRate;
  13. use App\Entity\ZoneWiseCommonSalesRate;
  14. use App\Entity\CountryWiseSalesRate;
  15. use App\Entity\CountryWiseCommonSalesRate;
  16. use App\Entity\SettingsInfo;
  17. use App\Entity\ZoneWiseCovidCharge;
  18. use App\Entity\CountryWiseCovidCharge;
  19. use App\Entity\ReceiveVoucher;
  20. use App\Entity\AdditionalCharge;
  21. use App\Entity\InvoiceAdditionalCharge;
  22. use App\Entity\Shipment;
  23. use App\Form\SalesInvoiceType;
  24. use App\Form\SalesInvoiceDetailsType;
  25. use App\Form\SalesInvoiceEditType;
  26. use App\Form\InvoiceSurchargeType;
  27. use App\Repository\SalesInvoiceRepository;
  28. use App\Repository\SettingsInfoRepository;
  29. use App\Repository\CountryRepository;
  30. use App\Repository\CourierRepository;
  31. use App\Repository\ProductTypeRepository;
  32. use App\Repository\SalesInvoiceDetailsRepository;
  33. use App\Repository\ReceiveVoucherRepository;
  34. use App\Repository\AccountNameRepository;
  35. use App\Repository\ShipmentRepository;
  36. use App\Repository\CustomerRepository;
  37. use App\Repository\CourierWiseZoneRepository;
  38. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  39. use Symfony\Component\HttpFoundation\Request;
  40. use Symfony\Component\HttpFoundation\Response;
  41. use Symfony\Component\Routing\Annotation\Route;
  42. use Symfony\Component\Form\Extension\Core\Type\TextType;
  43. use App\Service\UtilsService;
  44. use Doctrine\ORM\EntityManagerInterface;
  45. use Symfony\Component\HttpFoundation\JsonResponse;
  46. use Doctrine\Common\Collections\ArrayCollection;
  47. use Dompdf\Dompdf;
  48. use Dompdf\Options;
  49. use Symfony\Component\Form\Extension\Core\Type\FileType;
  50. use Symfony\Component\String\Slugger\SluggerInterface;
  51. use Symfony\Component\HttpFoundation\File\Exception\FileException;
  52. use Symfony\Component\Validator\Constraints\File;
  53. use PhpOffice\PhpSpreadsheet\IOFactory;
  54. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  55. use Symfony\Component\Form\Extension\Core\Type\DateType;
  56. use Symfony\Component\HttpFoundation\Session\Session;
  57. use Dompdf\FontMetrics
  58. use DateTime
  59. use Symfony\Component\Security\Http\Attribute\IsGranted;
  60. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  61. #[IsGranted("ROLE_ACCOUNTS")]
  62. class SalesInvoiceController extends AbstractController
  63. {
  64.     #[Route('/{page<[1-9]\d*>}'defaults: ['page' => '1'], name'app_sales_invoice_index'methods: ['GET''POST'])]
  65.     #[IsGranted("ROLE_ACCOUNTS")]
  66.     public function index(Request $requestint $pageSalesInvoiceRepository $salesInvoiceRepository): Response
  67.     {
  68.         $form $this->createFormBuilder(null)
  69.             ->add('customer',TextType::class, [       
  70.                 'attr' => ['class' => 'form-control',
  71.                 'placeholder' => 'Search by Customer',
  72.             ],
  73.                 'label' => false,
  74.                 'required' => false,                
  75.             ])
  76.             ->add('invoiceNo',TextType::class, [       
  77.                 'attr' => ['class' => 'form-control',
  78.                 'placeholder' => 'Search by Invoice No',
  79.             ],
  80.                 'label' => false,
  81.                 'required' => false,                
  82.             ])
  83.             ->add('hawbno',TextType::class, [       
  84.                 'attr' => ['class' => 'form-control',
  85.                 'placeholder' => 'Search by Hawb No'
  86.             ],
  87.                 'label' => false,
  88.                 'required' => false,                
  89.             ])
  90.             ->getForm();
  91.         $form->handleRequest($request);
  92.         $session = new Session();  
  93.         
  94.         if ($form->isSubmitted() && $form->isValid()) {
  95.             // data is an array with "name", "email", and "message" keys
  96.             // $data = $form->getData();            
  97.             // $filter = $data['search'];
  98.             $data $form->getData();                     
  99.             $customer =  $form->get('customer')->getData() !== null $form->get('customer')->getData() : "";
  100.             $invoiceNo =  $form->get('invoiceNo')->getData() !== null $form->get('invoiceNo')->getData() : "";
  101.             $hawbNO $form->get('hawbno')->getData() !== null $form->get('hawbno')->getData() : "";
  102.             $page 1;
  103.                         
  104.             if(isset($customer))
  105.             {               
  106.                 // set and get session attributes
  107.                 $session->set('exp_clt_customer'$customer);
  108.                 
  109.             }
  110.                            
  111.             $sales_invoices $salesInvoiceRepository->findAllSalesInvoice($customer$invoiceNo$hawbNO1$this->getUser()->getUserCompany()->getId(), $page);
  112.             
  113.             return $this->render('sales_invoice/index.html.twig', [
  114.                 'sales_invoices' => $sales_invoices,
  115.                 'form' => $form->createView(),
  116.             ]);
  117.         }
  118.         $customer "";
  119.         if($page 1)
  120.         {            
  121.             $customer $session->get('exp_clt_customer');
  122.         }
  123.         else
  124.         {
  125.             $session->remove('exp_clt_customer');                
  126.         }
  127.         
  128.         $sales_invoices $salesInvoiceRepository->findAllSalesInvoice($customer === null "" $customer""""1$this->getUser()->getUserCompany()->getId(), $page);
  129.         return $this->render('sales_invoice/index.html.twig', [
  130.             'sales_invoices' => $sales_invoices,
  131.             'form' => $form->createView(),
  132.         ]);
  133.     }
  134.     #[Route('/salesinvoice/new'name'app_sales_invoice_new'methods: ['GET''POST'])]
  135.     #[IsGranted("ROLE_ACCOUNTS")]
  136.     public function new(Request $requestSalesInvoiceRepository $salesInvoiceRepositoryUtilsService $utilsServiceEntityManagerInterface $entityManagerSettingsInfoRepository $settingsInfoRepositoryReceiveVoucherRepository $receiveVoucherRepositoryAccountNameRepository $accountNameRepository): Response
  137.     {
  138.         $gloPaymentReceived = -1;
  139.         $salesInvoice = new SalesInvoice();
  140.         $salesInvoice->setInvoiceDate(new \DateTime("now", new \DateTimeZone("Asia/Dhaka")));
  141.       
  142.         $form $this->createForm(SalesInvoiceType::class, $salesInvoice);                     
  143.         $form->handleRequest($request);
  144.         $salesInvoiceDetails = new SalesInvoiceDetails();
  145.         $formDet $this->createForm(SalesInvoiceDetailsType::class, $salesInvoiceDetails);
  146.         $formDet->handleRequest($request);
  147.        
  148.         if ($request->isXMLHttpRequest()) {
  149.             $salesInvoiceObj $request->request->get('salesInvoiceObj');            
  150.             if (!empty($salesInvoiceObj)) {
  151.                
  152.                 $salesInvoiceObj_array json_decode($salesInvoiceObjtrue);
  153.                
  154.                 $hawbNo_array json_decode($request->request->get('hawbNo'));
  155.                 $reference_array json_decode($request->request->get('reference'));
  156.                 $country_array json_decode($request->request->get('country'));
  157.                 $courier_array json_decode($request->request->get('courier'));
  158.                 $productType_array json_decode($request->request->get('productType'));
  159.                 $weight_array json_decode($request->request->get('weight'));
  160.                 $bookingWeight_array json_decode($request->request->get('bookingWeight'));
  161.                 $bookingRate_array json_decode($request->request->get('bookingRate'));
  162.                 $salesRate_array json_decode($request->request->get('salesRate'));
  163.                // $agent_array = json_decode($request->request->get('agent'));
  164.                // var_dump($accountNameId_array); die();
  165.               
  166.                $salesInvoiceDetailsList = new ArrayCollection();
  167.                $gloPaymentReceived $salesInvoiceObj_array['PaymentReceived'];
  168.                $index 0;               
  169.                foreach($hawbNo_array as $key=>$Row
  170.                {
  171.                    $keyValue $key;
  172.                    $keyValue $keyValue 1;
  173.                   
  174.                    $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  175.                    
  176.                    $salesInvoiceDetObj $entityManager->getRepository(SalesInvoiceDetails::class)
  177.                                                        ->findOneBy(['hawbNo' => $hawbNo_array[$index]]);                              
  178.                    if($salesInvoiceDetObj !== null)
  179.                    {
  180.                         return new JsonResponse(array('success' => false'responseText' => 'Duplicate HAWB Number : '$hawbNo_array[$index].' in Row Number '.$keyValue.'.'));
  181.                    }
  182.                    
  183.                    $salesInvoiceDetailsObj->setShipmentDate(new \DateTime($salesInvoiceObj_array['ShipmentDate']));
  184.                    $salesInvoiceDetailsObj->setHawbNo($hawbNo_array[$index]);
  185.                    $salesInvoiceDetailsObj->setReference($reference_array[$index]);
  186.                    $countryObj $entityManager->find(Country::class, $country_array[$index]);                  
  187.                    $salesInvoiceDetailsObj->setCountry($countryObj);
  188.                    $courierObj $entityManager->find(Courier::class, $courier_array[$index]);                
  189.                    $salesInvoiceDetailsObj->setCourier($courierObj);
  190.                    
  191.                    $productTypeObj $entityManager->find(ProductType::class, $productType_array[$index]);                 
  192.                    $salesInvoiceDetailsObj->setProductType($productTypeObj);
  193.                    $customerObj $entityManager->find(Customer::class, $salesInvoiceObj_array['CustomerId']);                 
  194.                    $salesInvoiceDetailsObj->setCustomer($customerObj);
  195.                    $salesInvoiceDetailsObj->setWeight($weight_array[$index]);
  196.                    $salesInvoiceDetailsObj->setBookingWeight($bookingWeight_array[$index]);
  197.                    $salesInvoiceDetailsObj->setRateApplicable($salesInvoiceObj_array['RateApplicable']);
  198.                   // return new JsonResponse(array('success' => false, 'responseText' => $salesInvoiceObj_array['InvoiceApplicable']  ));
  199.                   // $salesInvoiceDetailsObj->setInvoiceStatus($salesInvoiceObj_array['InvoiceApplicable']);
  200.                                    
  201.                    //Zone Assign Start
  202.                 //    if($courier_array[$index] < 0)
  203.                 //    {
  204.                         $courierWiseZoneObj $entityManager->getRepository(CourierWiseZone::class)
  205.                                                             ->findOneBy(['courier' => $courier_array[$index], 'country' => $country_array[$index] ]);                       
  206.                         if($courierWiseZoneObj === null )
  207.                         {
  208.                                 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.'.'));
  209.                         }
  210.                         $salesInvoiceDetailsObj->setZone($courierWiseZoneObj->getZone());
  211.                         //return new JsonResponse(array('success' => false, 'responseText' => $courierWiseZoneObj->getZone() ));
  212.                 //    }
  213.                 //    else
  214.                 //    {
  215.                 //     $courierWiseZoneObj = $this->getDoctrine()
  216.                 //             ->getRepository(CourierWiseZone::class)
  217.                 //             ->find(1);
  218.                 //    }
  219.                    //Zone Assign End
  220.                    //Customer Weight Calculation Start 
  221.                    // Half and Per KG
  222.                    $weight trim($weight_array[$index]);
  223.                    $pointInputWeight $weight floor($weight);
  224.                    $intInputWeight floor($weight);
  225.                    $finalWeight 0;
  226.                    $rateWeight 0;
  227.                    if($weight <  $courierObj->getWeightPerkg())
  228.                    {
  229.                        if($pointInputWeight && $pointInputWeight <= 0.5)
  230.                        {
  231.                            $finalWeight = (float)0.5;
  232.                        }
  233.                        elseif($pointInputWeight 0.5 && $pointInputWeight <=1)
  234.                        {
  235.                            $finalWeight = (float)1;
  236.                        }
  237.                    }
  238.                    else
  239.                    {
  240.                        if($pointInputWeight && $pointInputWeight <=1)
  241.                        {
  242.                            $finalWeight = (float)1;
  243.                        }
  244.                    }
  245.                    $rateWeight $intInputWeight $finalWeight;
  246.                    //Only Per KG
  247.                    $pointInputPerKgWeight $weight floor($weight);
  248.                    $intInputPerKgWeight floor($weight);
  249.                    $finalPerKgWeight 0;
  250.                    $ratePerKgWeight 0;
  251.                    if($pointInputPerKgWeight && $pointInputPerKgWeight <=1)
  252.                    {
  253.                        $finalPerKgWeight = (float)1;
  254.                    }
  255.                    $ratePerKgWeight $intInputPerKgWeight $finalPerKgWeight;
  256.                    //Customer Weight Calculation End
  257.                    //Vendor/Booking weight Calculation Start 
  258.                    // Half and Per KG
  259.                    $bookingWeight trim($bookingWeight_array[$index]);
  260.                    $pointInputBookingWeight $bookingWeight floor($bookingWeight);
  261.                    $intInputBookingWeight floor($bookingWeight);
  262.                    $finalBookingWeight 0;
  263.                    $rateBookingWeight 0;
  264.                    if($bookingWeight <  $courierObj->getWeightPerkg())
  265.                    {
  266.                        if($pointInputBookingWeight && $pointInputBookingWeight <= 0.5)
  267.                        {
  268.                            $finalBookingWeight = (float)0.5;
  269.                        }
  270.                        elseif($pointInputBookingWeight 0.5 && $pointInputBookingWeight <=1)
  271.                        {
  272.                            $finalBookingWeight = (float)1;
  273.                        }
  274.                    }
  275.                    else
  276.                    {
  277.                        if($pointInputBookingWeight && $pointInputBookingWeight <=1)
  278.                        {
  279.                            $finalBookingWeight = (float)1;
  280.                        }
  281.                    }
  282.                    $rateBookingWeight $intInputBookingWeight $finalBookingWeight;
  283.                    //Only Per KG
  284.                    $pointInputPerKgBookingWeight $bookingWeight floor($bookingWeight);
  285.                    $intInputPerKgBookingWeight floor($bookingWeight);
  286.                    $finalPerKgBookingWeight 0;
  287.                    $ratePerKgBookingWeight 0;
  288.                    if($pointInputPerKgBookingWeight && $pointInputPerKgBookingWeight <=1)
  289.                    {
  290.                        $finalPerKgBookingWeight = (float)1;
  291.                    }
  292.                    $ratePerKgBookingWeight $intInputPerKgBookingWeight $finalPerKgBookingWeight;
  293.                    //Weight Calculation End
  294.                    if($salesInvoiceObj_array['RateApplicable'] == 1)  // Predefine Rate
  295.                    {
  296.                         //Master Rate Assign Start       
  297.                         $finalMasterRateCal 0;                 
  298.                         $perKgRateWeight $courierObj->getWeightPerkgRate();
  299.                         if($rateBookingWeight $perKgRateWeight )
  300.                         {
  301.                             $zoneWiseMasterRate $entityManager->getRepository(ZoneWiseMasterRate::class)
  302.                                                     ->findBookingRatebyCourierAndWeight($courierObj->getId(), $courierWiseZoneObj->getZone(), $productTypeObj->getId(), $rateBookingWeight);                       
  303.                             
  304.                             if($zoneWiseMasterRate !== null)      
  305.                             { 
  306.                                 $finalMasterRateCal $zoneWiseMasterRate->getRate();
  307.                             }
  308.                         }
  309.                         else
  310.                         {
  311.                             $zoneWiseMasterRate $entityManager->getRepository(ZoneWiseMasterRate::class)
  312.                                                     ->findBookingRatebyCourierAndWeight($courierObj->getId(), $courierWiseZoneObj->getZone(), $productTypeObj->getId(), $rateBookingWeight);                     
  313.                             if($zoneWiseMasterRate !== null)      
  314.                             { 
  315.                                 $finalMasterRateCal $zoneWiseMasterRate->getRate() * $rateBookingWeight;                                
  316.                             }
  317.                         }
  318.                         if($zoneWiseMasterRate === null)  
  319.                         {
  320.                             if($rateBookingWeight $perKgRateWeight )
  321.                             { 
  322.                                 $countryWiseMasterRate $entityManager->getRepository(CountryWiseMasterRate::class)
  323.                                                             ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getId(), 'weight' => $rateBookingWeight ]);                                          
  324.                                 if($countryWiseMasterRate !== null
  325.                                 { 
  326.                                     $finalMasterRateCal =  $countryWiseMasterRate->getRate();
  327.                                 }                           
  328.                             }
  329.                             else
  330.                             {
  331.                                 $countryWiseMasterRate $entityManager->getRepository(CountryWiseMasterRate::class)
  332.                                                             ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getId(), 'weight' => $perKgRateWeight ]);                           
  333.                                 if($countryWiseMasterRate !== null
  334.                                 { 
  335.                                     $finalMasterRateCal $countryWiseMasterRate->getRate() * $rateBookingWeight;                                    
  336.                                 }
  337.                             }
  338.                         }        
  339.                         if($zoneWiseMasterRate !== null)
  340.                         {
  341.                             $salesInvoiceDetailsObj->setBookingRate($finalMasterRateCal);                            
  342.                         }
  343.                         else if($countryWiseMasterRate !== null)
  344.                         {
  345.                             $salesInvoiceDetailsObj->setBookingRate($finalMasterRateCal);                            
  346.                         }
  347.                         else
  348.                         {                                   
  349.                             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.'.'));
  350.                         }
  351.                         
  352.                         //Master Rate Assign End
  353.                         //Sales Rate Assign Start 
  354.                         // if($customerObj->getRateCurrency() == 2)
  355.                         // {
  356.                         //     $perKgRateWeight = 21;
  357.                         // }
  358.                         $finalRateCal 0;
  359.                         // Own Company Rate for Customer Start
  360.                         $salesCourierId 0;
  361.                         $salesCourierName "";
  362.                         if($this->getUser()->getUserCompany()->getCustomerRate() == // Own Company Wise Customer Rate
  363.                         {
  364.                             if($customerObj->getCustomerType() == )  //Customer
  365.                             {
  366.                                 $salesCourierId $this->getUser()->getUserCompany()->getCompanyCourier()->getId();
  367.                                 $salesCourierName $this->getUser()->getUserCompany()->getCompanyCourier()->getName();
  368.                                 return new JsonResponse(array('success' => false'responseText' => ));
  369.                             }
  370.                             else  //Agent
  371.                             {
  372.                                 $salesCourierId $courierObj->getId();
  373.                                 $salesCourierName $courierObj->getName();
  374.                                 return new JsonResponse(array('success' => false'responseText' => ));
  375.                             }
  376.                         }
  377.                         else   // Separate Courier Wise Customer Rate
  378.                         {
  379.                             $salesCourierId $courierObj->getId();
  380.                             $salesCourierName $courierObj->getName();
  381.                             return new JsonResponse(array('success' => false'responseText' => ));
  382.                         }
  383.                         // Own Company Rate for Customer End
  384.                         if($customerObj->getRateType() == 1)  // Customer wise sales rate     
  385.                         {                         
  386.                             if($rateWeight $perKgRateWeight )
  387.                             {
  388.                                 $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseSalesRate::class)
  389.                                                         ->findSalesRatebyCustomerAndWeight($customerObj->getId(), $salesCourierId$courierWiseZoneObj->getZone(), $productTypeObj->getId(), $rateWeight);                                     
  390.                                 if($zoneWiseSalesRate !== null)     
  391.                                 {                         
  392.                                     $finalRateCal $zoneWiseSalesRate->getRate();
  393.                                 }
  394.                             }
  395.                             else
  396.                             {                                                                       
  397.                                 $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseSalesRate::class)
  398.                                                         ->findSalesRatebyCustomerAndWeight($customerObj->getId(), $salesCourierId$courierWiseZoneObj->getZone(), $productTypeObj->getId(), $rateWeight);                       
  399.                                 
  400.                                 if($zoneWiseSalesRate !== null)     
  401.                                 { 
  402.                                     $finalRateCal $zoneWiseSalesRate->getRate() * $rateWeight;                                      
  403.                                 }
  404.                             }
  405.                             if($zoneWiseSalesRate === null)  
  406.                             {
  407.                                 if($rateWeight $perKgRateWeight )
  408.                                 { 
  409.                                     $countryWiseSalesRate $entityManager->getRepository(CountryWiseSalesRate::class)
  410.                                                             ->findOneBy(['customer' => $customerObj->getId(), 'courier' => $salesCourierId'country' => $countryObj->getId(), 'productType' => $productTypeObj->getId(), 'weight' => $rateWeight ]);                                        
  411.                                     if($countryWiseSalesRate !== null)     
  412.                                     {                         
  413.                                         $finalRateCal $countryWiseSalesRate->getRate();
  414.                                     }
  415.                                 }
  416.                                 else
  417.                                 {
  418.                                     $countryWiseSalesRate $entityManager->getRepository(CountryWiseSalesRate::class)
  419.                                                             ->findOneBy(['customer' => $customerObj->getId(), 'courier' => $salesCourierId'country' => $countryObj->getId(), 'productType' => $productTypeObj->getId(), 'weight' => $perKgRateWeight ]);                           
  420.                                     if($countryWiseSalesRate !== null)     
  421.                                     { 
  422.                                         $finalRateCal $countryWiseSalesRate->getRate() * $rateWeight;                                            
  423.                                     }
  424.                                 }
  425.                             }        
  426.                             if($zoneWiseSalesRate !== null)
  427.                             {
  428.                                 $salesInvoiceDetailsObj->setSalesRate($finalRateCal);
  429.                                 
  430.                             }
  431.                             else if($countryWiseSalesRate !== null)
  432.                             {
  433.                                 $salesInvoiceDetailsObj->setSalesRate($finalRateCal);                                    
  434.                             }
  435.                             else
  436.                             {                                   
  437.                                 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.'.'));
  438.                             }
  439.                         }
  440.                         else  // Common sales rate   
  441.                         {
  442.                                 if($rateWeight $perKgRateWeight )
  443.                                 {
  444.                                     $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseCommonSalesRate::class)
  445.                                                             ->findCommonSalesRatebyCourierAndWeight($salesCourierId$courierWiseZoneObj->getZone(), $productTypeObj->getId(), $rateWeight);                                     
  446.                                 }
  447.                                 else
  448.                                 {
  449.                                     $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseCommonSalesRate::class)
  450.                                                             ->findCommonSalesRatebyCourierAndWeight($salesCourierId$courierWiseZoneObj->getZone(), $productTypeObj->getId(), $perKgRateWeight);                       
  451.                                     if($zoneWiseSalesRate !== null)     
  452.                                     {       
  453.                                         $zoneWiseSalesRate->setRate($zoneWiseSalesRate->getRate() * $rateWeight);
  454.                                     }
  455.                                 }
  456.                                 if($zoneWiseSalesRate === null)  
  457.                                 {
  458.                                     if($rateWeight $perKgRateWeight )
  459.                                     { 
  460.                                         $countryWiseSalesRate $entityManager->getRepository(CountryWiseCommonSalesRate::class)
  461.                                                                 ->findOneBy(['courier' => $salesCourierId'country' => $countryObj->getId(), 'productType' => $productTypeObj->getId(), 'weight' => $rateWeight ]);                           
  462.                                     }
  463.                                     else
  464.                                     {
  465.                                         $countryWiseSalesRate $entityManager->getRepository(CountryWiseCommonSalesRate::class)
  466.                                                                 ->findOneBy(['courier' => $salesCourierId'country' => $countryObj->getId(), 'productType' => $productTypeObj->getId(), 'weight' => $perKgRateWeight ]);                           
  467.                                         if($countryWiseSalesRate !== null)     
  468.                                         {   
  469.                                             $countryWiseSalesRate->setRate($countryWiseSalesRate->getRate() * $rateWeight);
  470.                                         }
  471.                                     }
  472.                                 }        
  473.                                 if($zoneWiseSalesRate !== null)
  474.                                 {
  475.                                     $salesInvoiceDetailsObj->setSalesRate($zoneWiseSalesRate->getRate());
  476.                                 }
  477.                                 else if($countryWiseSalesRate !== null)
  478.                                 {
  479.                                     $salesInvoiceDetailsObj->setSalesRate($countryWiseSalesRate->getRate());
  480.                                 }
  481.                                 else
  482.                                 {                                   
  483.                                     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.'.'));
  484.                                 }
  485.                         }
  486.                         //Sales Rate Assign End
  487.                        
  488.                     }
  489.                     else  // Special Calculated Rate
  490.                     {
  491.                         $salesInvoiceDetailsObj->setBookingRate($bookingRate_array[$index]);
  492.                         $salesInvoiceDetailsObj->setSalesRate($salesRate_array[$index]);                        
  493.                     }
  494.                     // if($salesInvoiceObj_array['RateApplicable'] <= 2)  // Predefine Rate
  495.                     // {
  496.                     //     if($customerObj->getRateCurrency() == 2)
  497.                     //     {
  498.                     //         $salesInvoiceDetailsObj->setCovidCharge(0);
  499.                     //     }
  500.                     //     else
  501.                     //     {
  502.                     //         //Covid Charge Cal Start
  503.                     //         if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 1)  // DHL Covid Charge Cal
  504.                     //         {
  505.                     //             $zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)
  506.                     //                                 ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  507.                     //             if($zoneWiseCovidCharge === null)
  508.                     //             {
  509.                     //                 $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)
  510.                     //                                         ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);                           
  511.                     //             }
  512.                     //             if($zoneWiseCovidCharge !== null)
  513.                     //             {                            
  514.                     //                 $salesInvoiceDetailsObj->setCovidCharge($rateWeight <= 1 ? $zoneWiseCovidCharge->getRate() : $zoneWiseCovidCharge->getRate() * $rateWeight);
  515.                     //                 $salesInvoiceDetailsObj->setVendorCovidCharge($rateBookingWeight <= 1 ? $zoneWiseCovidCharge->getRate() : $zoneWiseCovidCharge->getRate() * $rateBookingWeight);
  516.                     //             }
  517.                     //             else if($countryWiseCovidCharge !== null)
  518.                     //             {                          
  519.                     //                 $salesInvoiceDetailsObj->setCovidCharge($countryWiseCovidCharge->getRate() * $ratePerKgWeight);
  520.                     //             }
  521.                     //             else
  522.                     //             {
  523.                     //                 return new JsonResponse(array('success' => false, 'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  524.                     //             }
  525.                                     
  526.                     //         }
  527.                     //         else if($courierObj->getCovidChargeApplicable() == 1 && $courierObj->getId() == 2) // Fedex Covid Charge Cal
  528.                     //         {
  529.                     //             if($courierWiseZoneObj->getZone()->getId() == 16 || $courierWiseZoneObj->getZone()->getId() == 18) // Zone G & I
  530.                     //             {
  531.                     //                 if($rateWeight <= 1)
  532.                     //                 {
  533.                     //                     $salesInvoiceDetailsObj->setCovidCharge(1);
  534.                     //                     $salesInvoiceDetailsObj->setVendorCovidCharge(1);
  535.                     //                 }
  536.                     //                 else
  537.                     //                 {
  538.                     //                     $zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)
  539.                     //                                         ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  540.                     //                     if($zoneWiseCovidCharge !== null)
  541.                     //                     {                            
  542.                     //                         $salesInvoiceDetailsObj->setCovidCharge($zoneWiseCovidCharge->getRate() * $rateWeight);
  543.                     //                         $salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);
  544.                     //                     }                         
  545.                     //                     else
  546.                     //                     {
  547.                     //                         return new JsonResponse(array('success' => false, 'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  548.                     //                     }
  549.                     //                 }
  550.                     //             }
  551.                     //             else if($courierWiseZoneObj->getZone()->getId() == 17) // Zone H
  552.                     //             {
  553.                     //                 if($rateWeight <= 1)
  554.                     //                 {
  555.                     //                     $salesInvoiceDetailsObj->setCovidCharge(2);
  556.                     //                     $salesInvoiceDetailsObj->setVendorCovidCharge(2);
  557.                     //                 }
  558.                     //                 else
  559.                     //                 {
  560.                     //                     $zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)
  561.                     //                                         ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  562.                     //                     if($zoneWiseCovidCharge !== null)
  563.                     //                     {                            
  564.                     //                         $salesInvoiceDetailsObj->setCovidCharge($zoneWiseCovidCharge->getRate() * $rateWeight);
  565.                     //                         $salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);
  566.                     //                     }                         
  567.                     //                     else
  568.                     //                     {
  569.                     //                         return new JsonResponse(array('success' => false, 'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  570.                     //                     }
  571.                     //                 }
  572.                     //             }
  573.                     //             else
  574.                     //             {
  575.                     //                 if($rateWeight < 5)
  576.                     //                 {
  577.                     //                     $salesInvoiceDetailsObj->setCovidCharge(1);
  578.                     //                     $salesInvoiceDetailsObj->setVendorCovidCharge(1);
  579.                     //                 }
  580.                     //                 else
  581.                     //                 {
  582.                     //                     $zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)
  583.                     //                                         ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  584.                     //                     if($zoneWiseCovidCharge !== null)
  585.                     //                     {                            
  586.                     //                         $salesInvoiceDetailsObj->setCovidCharge($zoneWiseCovidCharge->getRate() * $rateWeight);
  587.                     //                         $salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);
  588.                     //                     }                         
  589.                     //                     else
  590.                     //                     {
  591.                     //                         return new JsonResponse(array('success' => false, 'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  592.                     //                     }
  593.                     //                 }
  594.                     //             }
  595.                             
  596.                     //         }
  597.                     //         //Covid Charge Cal End
  598.                     //     }
  599.                        
  600.                     // }
  601.                     // else
  602.                     // {
  603.                     //     $salesInvoiceDetailsObj->setCovidCharge(0);
  604.                     // }
  605.                     //Covid Charge Cal Start
  606.                     if($courierObj->getCovidChargeApplicable() == && $courierObj->getId() == 1)  // DHL Covid Charge Cal
  607.                     {
  608.                         $zoneWiseCovidCharge $entityManager->getRepository(ZoneWiseCovidCharge::class)
  609.                                             ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  610.                         if($zoneWiseCovidCharge === null)
  611.                         {
  612.                             $countryWiseCovidCharge $entityManager->getRepository(CountryWiseCovidCharge::class)
  613.                                                     ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);                           
  614.                         }
  615.                         // Vendor Covid Charge Start                       
  616.                         if($zoneWiseCovidCharge !== null)
  617.                         {                   
  618.                             $salesInvoiceDetailsObj->setVendorCovidCharge($rateBookingWeight <= $zoneWiseCovidCharge->getRate() : $zoneWiseCovidCharge->getRate() * $rateBookingWeight);
  619.                         }
  620.                         else if($countryWiseCovidCharge !== null)
  621.                         {                          
  622.                             $salesInvoiceDetailsObj->setVendorCovidCharge($countryWiseCovidCharge->getRate() * $ratePerKgWeight);
  623.                         }
  624.                         else
  625.                         {
  626.                             return new JsonResponse(array('success' => false'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  627.                         }
  628.                         // Vendor Covid Charge End   
  629.                         //Customer Covid Charge Start       
  630.                         if($salesInvoiceObj_array['RateApplicable'] <= 2)  // Predefine Rate
  631.                         {
  632.                             if($customerObj->getRateCurrency() == 2)
  633.                             {
  634.                                 $salesInvoiceDetailsObj->setCovidCharge(0);
  635.                             }
  636.                             else
  637.                             {
  638.                                 if($zoneWiseCovidCharge !== null)
  639.                                 {                            
  640.                                     $salesInvoiceDetailsObj->setCovidCharge($rateWeight <= $zoneWiseCovidCharge->getRate() : $zoneWiseCovidCharge->getRate() * $rateWeight);                                    
  641.                                 }
  642.                                 else if($countryWiseCovidCharge !== null)
  643.                                 {                          
  644.                                     $salesInvoiceDetailsObj->setCovidCharge($countryWiseCovidCharge->getRate() * $ratePerKgWeight);
  645.                                 }
  646.                             }
  647.                         }
  648.                         else
  649.                         {
  650.                             $salesInvoiceDetailsObj->setCovidCharge(0);
  651.                         }
  652.                         //Customer Covid Charge End       
  653.                             
  654.                     }
  655.                     else if($courierObj->getCovidChargeApplicable() == && $courierObj->getId() == 2// Fedex Covid Charge Cal
  656.                     {
  657.                         if($courierWiseZoneObj->getZone()->getId() == 16 || $courierWiseZoneObj->getZone()->getId() == 18// Zone G & I
  658.                         {
  659.                             // Vendor Covid Charge Start
  660.                             if($rateWeight <= 1)
  661.                             {                                
  662.                                 $salesInvoiceDetailsObj->setVendorCovidCharge(1);
  663.                             }
  664.                             else
  665.                             {
  666.                                 $zoneWiseCovidCharge $entityManager->getRepository(ZoneWiseCovidCharge::class)
  667.                                                     ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  668.                                 if($zoneWiseCovidCharge !== null)
  669.                                 {                           
  670.                                     $salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);
  671.                                 }                         
  672.                                 else
  673.                                 {
  674.                                     return new JsonResponse(array('success' => false'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  675.                                 }
  676.                             }
  677.                             // Vendor Covid Charge Start
  678.                             // Customer Covid Charge Start
  679.                             if($salesInvoiceObj_array['RateApplicable'] <= 2)  // Predefine Rate
  680.                             {
  681.                                 if($customerObj->getRateCurrency() == 2)
  682.                                 {
  683.                                     $salesInvoiceDetailsObj->setCovidCharge(0);
  684.                                 }
  685.                                 else
  686.                                 {
  687.                                     if($rateWeight <= 1)
  688.                                     {
  689.                                         $salesInvoiceDetailsObj->setCovidCharge(1);
  690.                                         
  691.                                     }
  692.                                     else
  693.                                     {
  694.                                         $zoneWiseCovidCharge $entityManager->getRepository(ZoneWiseCovidCharge::class)
  695.                                                             ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  696.                                         if($zoneWiseCovidCharge !== null)
  697.                                         {                            
  698.                                             $salesInvoiceDetailsObj->setCovidCharge($zoneWiseCovidCharge->getRate() * $rateWeight);
  699.                                             
  700.                                         }                
  701.                                     
  702.                                     }
  703.                                 }
  704.                             }
  705.                             else
  706.                             {
  707.                                 $salesInvoiceDetailsObj->setCovidCharge(0);
  708.                             }
  709.                             // Customer Covid Charge End
  710.                         }
  711.                         else if($courierWiseZoneObj->getZone()->getId() == 17// Zone H
  712.                         {
  713.                             // Vendor Covid Charge Start
  714.                             if($rateWeight <= 1)
  715.                             {                                
  716.                                 $salesInvoiceDetailsObj->setVendorCovidCharge(2);
  717.                             }
  718.                             else
  719.                             {
  720.                                 $zoneWiseCovidCharge $entityManager->getRepository(ZoneWiseCovidCharge::class)
  721.                                                     ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  722.                                 if($zoneWiseCovidCharge !== null)
  723.                                 {                           
  724.                                     $salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);
  725.                                 }                         
  726.                                 else
  727.                                 {
  728.                                     return new JsonResponse(array('success' => false'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  729.                                 }
  730.                             }
  731.                             // Vendor Covid Charge End
  732.                             // Customer Covid Charge Start
  733.                             if($salesInvoiceObj_array['RateApplicable'] <= 2)  // Predefine Rate
  734.                             {
  735.                                 if($customerObj->getRateCurrency() == 2)
  736.                                 {
  737.                                     $salesInvoiceDetailsObj->setCovidCharge(0);
  738.                                 }
  739.                                 else
  740.                                 {
  741.                                     if($rateWeight <= 1)
  742.                                     {
  743.                                         $salesInvoiceDetailsObj->setCovidCharge(2);
  744.                                         $salesInvoiceDetailsObj->setVendorCovidCharge(2);
  745.                                     }
  746.                                     else
  747.                                     {
  748.                                         $zoneWiseCovidCharge $entityManager->getRepository(ZoneWiseCovidCharge::class)
  749.                                                             ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  750.                                         if($zoneWiseCovidCharge !== null)
  751.                                         {                            
  752.                                             $salesInvoiceDetailsObj->setCovidCharge($zoneWiseCovidCharge->getRate() * $rateWeight);
  753.                                             $salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);
  754.                                         }                         
  755.                                        
  756.                                     }
  757.                                 }
  758.                             }
  759.                             else
  760.                             {
  761.                                 $salesInvoiceDetailsObj->setCovidCharge(0);
  762.                             }
  763.                             // Customer Covid Charge End
  764.                         }
  765.                         else
  766.                         {
  767.                             // Vendor Covid Charge Start
  768.                             if($rateWeight 5)
  769.                             {                                
  770.                                 $salesInvoiceDetailsObj->setVendorCovidCharge(1);
  771.                             }
  772.                             else
  773.                             {
  774.                                 $zoneWiseCovidCharge $entityManager->getRepository(ZoneWiseCovidCharge::class)
  775.                                                     ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  776.                                 if($zoneWiseCovidCharge !== null)
  777.                                 {                                 
  778.                                     $salesInvoiceDetailsObj->setVendorCovidCharge($zoneWiseCovidCharge->getRate() * $rateBookingWeight);
  779.                                 }                         
  780.                                 else
  781.                                 {
  782.                                     return new JsonResponse(array('success' => false'responseText' => 'Covid Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  783.                                 }
  784.                             }
  785.                             // Vendor Covid Charge End
  786.                             // Customer Covid Charge Start
  787.                             if($salesInvoiceObj_array['RateApplicable'] <= 2)  // Predefine Rate
  788.                             {
  789.                                 if($customerObj->getRateCurrency() == 2)
  790.                                 {
  791.                                     $salesInvoiceDetailsObj->setCovidCharge(0);
  792.                                 }
  793.                                 else
  794.                                 {
  795.                                     if($rateWeight 5)
  796.                                     {
  797.                                         $salesInvoiceDetailsObj->setCovidCharge(1);
  798.                                         
  799.                                     }
  800.                                     else
  801.                                     {
  802.                                         $zoneWiseCovidCharge $entityManager->getRepository(ZoneWiseCovidCharge::class)
  803.                                                             ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  804.                                         if($zoneWiseCovidCharge !== null)
  805.                                         {                            
  806.                                             $salesInvoiceDetailsObj->setCovidCharge($zoneWiseCovidCharge->getRate() * $rateWeight);                                    
  807.                                         }                         
  808.                                     
  809.                                     }
  810.                                 }
  811.                             }
  812.                             else
  813.                             {
  814.                                 $salesInvoiceDetailsObj->setCovidCharge(0);
  815.                             }
  816.                             // Customer Covid Charge End
  817.                         }
  818.                     
  819.                     }
  820.                     //Covid Charge Cal End
  821.                     $salesInvoiceDetailsList->add($salesInvoiceDetailsObj);                    
  822.                     $index ++;
  823.                 }  
  824.                 //Data Save Process Start  
  825.                 $index 0;
  826.                 $individualSalesInvoiceId 0;
  827.                 foreach($salesInvoiceDetailsList as $row)
  828.                 { 
  829.                      $keyValue $key;
  830.                      $keyValue $keyValue 1;
  831.  
  832.                      $shipmentDate $row->getShipmentDate();
  833.  
  834.                      // Get Settings Currency Start
  835.                      $settingsObj $settingsInfoRepository
  836.                                          ->findByDate($shipmentDate->format('Y-m-d')); 
  837.                      if($settingsObj === null)
  838.                      {                                
  839.                          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.'.'));
  840.                      }                       
  841.                      // Get Settings Currency End
  842.                     $firstDateofMonth date('Y-m-01'strtotime($shipmentDate->format('Y-m-d')));            
  843.                     $lastDateofMonth date('Y-m-t'strtotime($shipmentDate->format('Y-m-d')));
  844.                     $lastDateofMonth = new \DateTime($lastDateofMonth);
  845.                     $halfDateofMonth date('Y-m-d'strtotime($firstDateofMonth' + 14 days'));
  846.                     $halfDateofMonth = new \DateTime($halfDateofMonth);
  847.                     if($row->getCustomer()->getRateCurrency() == 2)
  848.                     {
  849.                         $row->setRateApplicable(3);
  850.                     }
  851.                     
  852.                     if($row->getCustomer()->getInvoicePeriod() == 1)  //Monthly Invoice Save Process
  853.                     {
  854.                         $salesInvoiceObj $salesInvoiceRepository->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $lastDateofMonth$lastDateofMonth1$row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId()  );                    
  855.  
  856.                         $invocieDate $lastDateofMonth;
  857.                         if($salesInvoiceObj === null)
  858.                         {
  859.                             $salesInv = new SalesInvoice();
  860.                             $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  861.                             $salesInv->setCustomer($row->getCustomer());
  862.                             
  863.                             $salesInvocieLastObj $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());
  864.                             $invoiceNO $utilsService->invoiceNoGenerator($salesInvocieLastObj$row->getCustomer(), $invocieDate);
  865.                             $salesInv->setInvoiceNo($invoiceNO); 
  866.                             $salesInv->setInvoiceDate($invocieDate);                                         
  867.                             $salesInv->setVat($settingsObj->getVat());                          
  868.                             $salesInv->setApproval(0);
  869.                             $salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());                           
  870.                             $salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());  
  871.                             $salesInv->setRateApplicable($row->getRateApplicable());
  872.                             $salesInv->setInvoiceType(1);
  873.                             $salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());   
  874.                             $salesInvoiceDetailsObj->setReference($row->getReference());                               
  875.                             $salesInvoiceDetailsObj->setWeight($row->getWeight());       
  876.                             $salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());                             
  877.                             $salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());                       
  878.                             $salesInvoiceDetailsObj->setCountry($row->getCountry());                               
  879.                             $salesInvoiceDetailsObj->setZone($row->getZone());
  880.                             $salesInvoiceDetailsObj->setProductType($row->getProductType());                               
  881.                             $salesInvoiceDetailsObj->setCourier($row->getCourier());                          
  882.                             $salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());                               
  883.                             $salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());
  884.                             if($row->getCustomer()->getRateCurrency() == 2)
  885.                             {
  886.                                $salesInvoiceDetailsObj->setCurrency(1);
  887.                             }
  888.                             else
  889.                             {
  890.                                 $salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );
  891.                             }
  892.                             $salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  893.                             $salesInvoiceDetailsObj->setVatApplicable(0);
  894.                             $salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());
  895.                             
  896.                             if($row->getRateApplicable() <= 2)
  897.                                 $salesInvoiceDetailsObj->setFsc$row->getCustomer()->getFsc() == $row->getCourier()->getFsc() : $row->getCustomer()->getFsc() ); 
  898.                             else
  899.                                 $salesInvoiceDetailsObj->setFsc(0); 
  900.                             $salesInvoiceDetailsObj->setVendorFsc($row->getCourier()->getFsc()); 
  901.                             $salesInvoiceDetailsObj->setCustomer($row->getCustomer());
  902.                             $salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null $row->getCovidCharge());
  903.                             $salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null $row->getVendorCovidCharge());
  904.                             $salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);
  905.     
  906.                             $entityManager->persist($salesInv);
  907.                             $entityManager->flush($salesInv);   
  908.                             
  909.                             $salesInvoiceId $salesInv->getId();
  910.     
  911.                         }
  912.                         else
  913.                         {
  914.                             $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  915.                             $salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());   
  916.                             $salesInvoiceDetailsObj->setReference($row->getReference());                               
  917.                             $salesInvoiceDetailsObj->setWeight($row->getWeight());       
  918.                             $salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());                             
  919.                             $salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());                           
  920.                             $salesInvoiceDetailsObj->setCountry($row->getCountry());                               
  921.                             $salesInvoiceDetailsObj->setZone($row->getZone());
  922.                             $salesInvoiceDetailsObj->setProductType($row->getProductType());                               
  923.                             $salesInvoiceDetailsObj->setCourier($row->getCourier());                          
  924.                             $salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());                               
  925.                             $salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());
  926.                             if($row->getCustomer()->getRateCurrency() == 2)
  927.                             {
  928.                                $salesInvoiceDetailsObj->setCurrency(1);
  929.                             }
  930.                             else
  931.                             {
  932.                                 $salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );
  933.                             }
  934.                             $salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  935.                             $salesInvoiceDetailsObj->setVatApplicable(0);
  936.                             $salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());
  937.                             if($row->getRateApplicable() <= 2)
  938.                                 $salesInvoiceDetailsObj->setFsc$row->getCustomer()->getFsc() == $row->getCourier()->getFsc() : $row->getCustomer()->getFsc() ); 
  939.                             else
  940.                                 $salesInvoiceDetailsObj->setFsc(0); 
  941.                             $salesInvoiceDetailsObj->setVendorFsc($row->getCourier()->getFsc());
  942.                             $salesInvoiceDetailsObj->setCustomer($row->getCustomer());
  943.                             $salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null $row->getCovidCharge());
  944.                             $salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null $row->getVendorCovidCharge());                            
  945.                             $salesInvoiceDetailsObj->setSalesInvoice($salesInvoiceObj);
  946.                                         
  947.                             $entityManager->persist($salesInvoiceDetailsObj);
  948.                             $entityManager->flush($salesInvoiceDetailsObj);
  949.                         }
  950.                     }
  951.                     else if($row->getCustomer()->getInvoicePeriod() == 2//Half Monthly Invoice Save Process
  952.                     {
  953.                         if($shipmentDate <= $halfDateofMonth// First Half month
  954.                         
  955.                             $salesInvoiceObj $salesInvoiceRepository
  956.                                     ->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $halfDateofMonth$halfDateofMonth1$row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );                              
  957.                             
  958.                             $invocieDate $halfDateofMonth;
  959.                         }  
  960.                         else
  961.                         {
  962.                             $salesInvoiceObj $salesInvoiceRepository
  963.                                 ->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $lastDateofMonth$lastDateofMonth1$row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );                              
  964.                             $invocieDate $lastDateofMonth;
  965.                         }
  966.                         ////////////////Common portion
  967.                         if($salesInvoiceObj === null)
  968.                         {
  969.                             $salesInv = new SalesInvoice();
  970.                             $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  971.                             $salesInv->setCustomer($row->getCustomer());
  972.                             
  973.                             $salesInvocieLastObj $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());
  974.                             $invoiceNO $utilsService->invoiceNoGenerator($salesInvocieLastObj$row->getCustomer(), $invocieDate);
  975.                             $salesInv->setInvoiceNo($invoiceNO); 
  976.                             $salesInv->setInvoiceDate($invocieDate);                                         
  977.                             $salesInv->setVat($settingsObj->getVat());                          
  978.                             $salesInv->setApproval(0);
  979.                             $salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());                           
  980.                             $salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());  
  981.                             $salesInv->setRateApplicable($row->getRateApplicable());
  982.                             $salesInv->setInvoiceType(1);
  983.                             $salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());   
  984.                             $salesInvoiceDetailsObj->setReference($row->getReference());                               
  985.                             $salesInvoiceDetailsObj->setWeight($row->getWeight());       
  986.                             $salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());                             
  987.                             $salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());                       
  988.                             $salesInvoiceDetailsObj->setCountry($row->getCountry());                               
  989.                             $salesInvoiceDetailsObj->setZone($row->getZone());
  990.                             $salesInvoiceDetailsObj->setProductType($row->getProductType());                               
  991.                             $salesInvoiceDetailsObj->setCourier($row->getCourier());                          
  992.                             $salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());                               
  993.                             $salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());
  994.                             if($row->getCustomer()->getRateCurrency() == 2)
  995.                             {
  996.                                $salesInvoiceDetailsObj->setCurrency(1);
  997.                             }
  998.                             else
  999.                             {
  1000.                                 $salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );
  1001.                             }
  1002.                             $salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  1003.                             $salesInvoiceDetailsObj->setVatApplicable(0);
  1004.                             $salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());
  1005.                             
  1006.                             if($row->getRateApplicable() <= 2)
  1007.                                 $salesInvoiceDetailsObj->setFsc$row->getCustomer()->getFsc() == $row->getCourier()->getFsc() : $row->getCustomer()->getFsc() ); 
  1008.                             else
  1009.                                 $salesInvoiceDetailsObj->setFsc(0); 
  1010.                             $salesInvoiceDetailsObj->setVendorFsc($row->getCourier()->getFsc());
  1011.                             $salesInvoiceDetailsObj->setCustomer($row->getCustomer());
  1012.                             $salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null $row->getCovidCharge());
  1013.                             $salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null $row->getVendorCovidCharge());
  1014.                             $salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);
  1015.     
  1016.                             $entityManager->persist($salesInv);
  1017.                             $entityManager->flush($salesInv);    
  1018.                             
  1019.                             $salesInvoiceId $salesInv->getId();
  1020.     
  1021.                         }
  1022.                         else
  1023.                         {
  1024.                             $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  1025.                             $salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());   
  1026.                             $salesInvoiceDetailsObj->setReference($row->getReference());                               
  1027.                             $salesInvoiceDetailsObj->setWeight($row->getWeight());       
  1028.                             $salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());                             
  1029.                             $salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());                           
  1030.                             $salesInvoiceDetailsObj->setCountry($row->getCountry());                               
  1031.                             $salesInvoiceDetailsObj->setZone($row->getZone());
  1032.                             $salesInvoiceDetailsObj->setProductType($row->getProductType());                               
  1033.                             $salesInvoiceDetailsObj->setCourier($row->getCourier());                          
  1034.                             $salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());                               
  1035.                             $salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());
  1036.                             if($row->getCustomer()->getRateCurrency() == 2)
  1037.                             {
  1038.                                $salesInvoiceDetailsObj->setCurrency(1);
  1039.                             }
  1040.                             else
  1041.                             {
  1042.                                 $salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );
  1043.                             }
  1044.                             $salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  1045.                             $salesInvoiceDetailsObj->setVatApplicable(0);
  1046.                             $salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable()); 
  1047.                             if($row->getRateApplicable() <= 2)
  1048.                                 $salesInvoiceDetailsObj->setFsc$row->getCustomer()->getFsc() == $row->getCourier()->getFsc() : $row->getCustomer()->getFsc() ); 
  1049.                             else
  1050.                                 $salesInvoiceDetailsObj->setFsc(0); 
  1051.                             $salesInvoiceDetailsObj->setVendorFsc($row->getCourier()->getFsc());
  1052.                             $salesInvoiceDetailsObj->setCustomer($row->getCustomer());
  1053.                             $salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null $row->getCovidCharge()); 
  1054.                             $salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null $row->getVendorCovidCharge());                           
  1055.                             $salesInvoiceDetailsObj->setSalesInvoice($salesInvoiceObj);
  1056.                                         
  1057.                             $entityManager->persist($salesInvoiceDetailsObj);
  1058.                             $entityManager->flush($salesInvoiceDetailsObj);
  1059.                         }
  1060.                         /////////////Common 
  1061.                     }
  1062.                     else // HAWB NO Wise Invoice Save Process
  1063.                     {
  1064.                         $salesInv = new SalesInvoice();
  1065.                         $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  1066.                         $salesInv->setCustomer($row->getCustomer());
  1067.                         
  1068.                         $salesInvocieLastObj $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());
  1069.                         $invoiceNO $utilsService->invoiceNoGenerator($salesInvocieLastObj$row->getCustomer(), $shipmentDate);
  1070.                         $salesInv->setInvoiceNo($invoiceNO); 
  1071.                         $salesInv->setInvoiceDate($shipmentDate);                                        
  1072.                         $salesInv->setVat($settingsObj->getVat());                          
  1073.                         $salesInv->setApproval(0);
  1074.                         $salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());                           
  1075.                         $salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());  
  1076.                         $salesInv->setRateApplicable($row->getRateApplicable());
  1077.                         $salesInv->setInvoiceType(1);
  1078.                         $salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());   
  1079.                         $salesInvoiceDetailsObj->setReference($row->getReference());                               
  1080.                         $salesInvoiceDetailsObj->setWeight($row->getWeight());       
  1081.                         $salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());                             
  1082.                         $salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());                       
  1083.                         $salesInvoiceDetailsObj->setCountry($row->getCountry());                               
  1084.                         $salesInvoiceDetailsObj->setZone($row->getZone());
  1085.                         $salesInvoiceDetailsObj->setProductType($row->getProductType());                               
  1086.                         $salesInvoiceDetailsObj->setCourier($row->getCourier());                          
  1087.                         $salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());                               
  1088.                         $salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());
  1089.                         if($row->getCustomer()->getRateCurrency() == 2)
  1090.                         {
  1091.                             $salesInvoiceDetailsObj->setCurrency(1);
  1092.                         }
  1093.                         else
  1094.                         {
  1095.                             $salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );
  1096.                         }
  1097.                         $salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  1098.                         $salesInvoiceDetailsObj->setVatApplicable(0);
  1099.                         $salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());
  1100.                         if($row->getRateApplicable() <= 2)
  1101.                             $salesInvoiceDetailsObj->setFsc$row->getCustomer()->getFsc() == $row->getCourier()->getFsc() : $row->getCustomer()->getFsc() ); 
  1102.                         else
  1103.                             $salesInvoiceDetailsObj->setFsc(0); 
  1104.                         $salesInvoiceDetailsObj->setVendorFsc($row->getCourier()->getFsc());    
  1105.                         $salesInvoiceDetailsObj->setCustomer($row->getCustomer());
  1106.                         $salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null $row->getCovidCharge());
  1107.                         $salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null $row->getVendorCovidCharge());
  1108.                         $salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);
  1109.                         $entityManager->persist($salesInv);
  1110.                         $entityManager->flush($salesInv); 
  1111.                         
  1112.                         $salesInvoiceId $salesInv->getId();
  1113.                         if($gloPaymentReceived == && $salesInvoiceId 0)
  1114.                         {
  1115.                             
  1116.                             $salesValue $salesInvoiceRepository->getSingalSalesValueCalculation($salesInvoiceId);
  1117.                             
  1118.                             $receiveVoucher = new ReceiveVoucher();
  1119.         
  1120.                             $receiveVoucher->setSalesInvoice($salesInvoiceRepository->find($salesInvoiceId));
  1121.                             $receiveVoucher->setDescription('N/A');
  1122.                             $receiveVoucher->setReceiveDate(new \DateTime('now'));
  1123.                             
  1124.                             //Start Reference no Generate $salesInvoiceObj_array['ShipmentDate']
  1125.                             $receiveVoucherLastObj $receiveVoucherRepository->findLastObjReceiveVoucher();
  1126.                 
  1127.                             $now = new \DateTime('now');           
  1128.                             $year substr($now->format('Y'),2); 
  1129.                             $refNO "";
  1130.                             $serialNo "";
  1131.                             if(null !== $receiveVoucherLastObj)
  1132.                                 $refYear substr($receiveVoucherLastObj->getVoucherno(),-2);
  1133.                             else
  1134.                                 $refYear 20;
  1135.                 
  1136.                             if($receiveVoucherLastObj == null)
  1137.                             {
  1138.                                 $refNO "RV-00001/".$year;
  1139.                             } 
  1140.                             else if($year != $refYear)
  1141.                             {
  1142.                                 $refNO "RV-00001/".$year;
  1143.                             }          
  1144.                             else
  1145.                             {
  1146.                                 $serialNo substr($receiveVoucherLastObj->getVoucherno(),-8,-3);
  1147.                                 $serialNo += 1;
  1148.                                 $serialNo str_pad($serialNo,5,"0",STR_PAD_LEFT);
  1149.                                 $refNO ="RV-".$serialNo."/".$year;
  1150.                             
  1151.                             }
  1152.                             //End Reference no Generate
  1153.                 
  1154.                             $receiveVoucher->setVoucherno($refNO);
  1155.                 
  1156.                             $debitAccountName $accountNameRepository->find(1);
  1157.                             $receiveVoucher->setDebitAccount($debitAccountName);
  1158.                 
  1159.                             $creditAccountName $accountNameRepository->find(3);
  1160.                             $receiveVoucher->setCreditAccount($creditAccountName);
  1161.                             $receiveVoucher->setReceiveAmount($salesValue[0]);
  1162.                 
  1163.                             $receiveVoucherRepository->save($receiveVouchertrue);
  1164.                         }
  1165.                     }
  1166.                     $index ++;
  1167.                 } 
  1168.                                
  1169.                 $this->addFlash('notice''Booking Created successfully!');
  1170.                 
  1171.                 return new JsonResponse(array('success' => true));                
  1172.             }
  1173.         }
  1174.         // if ($form->isSubmitted() && $form->isValid()) {
  1175.         //     $salesInvoiceRepository->save($salesInvoice, true);
  1176.         //     return $this->redirectToRoute('app_sales_invoice_index', [], Response::HTTP_SEE_OTHER);
  1177.         // }
  1178.         return $this->renderForm('sales_invoice/new.html.twig', [
  1179.             'sales_invoice' => $salesInvoice,
  1180.             'form' => $form,
  1181.             'formDet' => $formDet,
  1182.         ]);
  1183.     }
  1184.     #[Route('/salesinvoice/{id}/show'name'app_sales_invoice_show'methods: ['GET'])]
  1185.     public function show(SalesInvoice $salesInvoiceRequest $requestReceiveVoucherRepository $receiveVoucherRepository): Response
  1186.     {
  1187.         $searchForm $this->createFormBuilder(null)            
  1188.             ->add('reference'EntityType::class, [
  1189.                 // looks for choices from this entity
  1190.                 'class' => SalesInvoiceDetails::class,
  1191.                 'query_builder' => function (SalesInvoiceDetailsRepository $er) use ($salesInvoice) {
  1192.                     return $er->createQueryBuilder('v')  
  1193.                         ->where('v.salesInvoice = '.$salesInvoice->getId())                     
  1194.                         ->orderBy('v.reference''ASC')
  1195.                         ->groupBy('v.reference')
  1196.                         ;
  1197.                 },                
  1198.                 // uses the User.username property as the visible option string
  1199.                 'choice_label' => 'reference',
  1200.                 'placeholder' => 'Select a Reference...',
  1201.                 'attr' => [
  1202.                     'class' => 'form-control select-tags',
  1203.                     'style' => 'width:100%;',
  1204.                     ],
  1205.                 'label' => 'Reference Name',            
  1206.                 // used to render a select box, check boxes or radios
  1207.                 // 'multiple' => true,
  1208.                 // 'expanded' => true,
  1209.                 ])       
  1210.             ->getForm();
  1211.         $searchForm->handleRequest($request);
  1212.         $receiveVoucherList $receiveVoucherRepository
  1213.                         ->findBy(array('salesInvoice' => $salesInvoice->getId()));
  1214.         return $this->render('sales_invoice/show.html.twig', [
  1215.             'sales_invoice' => $salesInvoice,
  1216.             'receiveVoucherList' => $receiveVoucherList,
  1217.             'searchForm' => $searchForm->createView(),
  1218.         ]);
  1219.     }
  1220.     
  1221.     #[Route('/salesinvoice/{id}/search-show/'name'app_sales_invoice_search_show'methods: ['GET'])]
  1222.     public function searchShow(SalesInvoiceDetails $salesInvoiceDetailsObjSalesInvoiceDetailsRepository $salesInvoiceDetailsRepository): Response
  1223.     {
  1224.         $salesInvoiceDetails $salesInvoiceDetailsRepository
  1225.                         ->findByReference($salesInvoiceDetailsObj->getSalesInvoice()->getId(), 
  1226.                                           $salesInvoiceDetailsObj->getReference()
  1227.                                     );
  1228.         return $this->render('sales_invoice/search_show.html.twig', [
  1229.             'sales_invoice' => $salesInvoiceDetailsObj->getSalesInvoice(),    
  1230.             'salesInvoiceDetails' => $salesInvoiceDetails,        
  1231.         ]);
  1232.     }
  1233.     #[Route('/salesinvoice/{id}/edit'name'app_sales_invoice_edit'methods: ['GET''POST'])]
  1234.     #[IsGranted("ROLE_ACCOUNTS")]
  1235.     public function edit(Request $requestSalesInvoice $salesInvoiceSalesInvoiceRepository $salesInvoiceRepositoryCountryRepository $countryRepositoryCourierRepository $courierRepositoryProductTypeRepository $productTypeRepositorySalesInvoiceDetailsRepository $salesInvoiceDetailsRepositoryEntityManagerInterface $entityManagerSettingsInfoRepository $settingsInfoRepository): Response
  1236.     {
  1237.         // Start remove item by Edit
  1238.         // Original Order details
  1239.         $originalSalesInvoiceDetails = new ArrayCollection();
  1240.         $originalInvoiceAdditionalCharge = new ArrayCollection();
  1241.         
  1242.         foreach($salesInvoice->getSalesInvoiceDetails() as $invoiceDetail)
  1243.         {
  1244.             $originalSalesInvoiceDetails->add($invoiceDetail);
  1245.             foreach($invoiceDetail->getInvoiceAdditionalCharges() as $invAdditionalCharge)
  1246.             {
  1247.                 $originalInvoiceAdditionalCharge->add($invAdditionalCharge);
  1248.             }
  1249.         }
  1250.      
  1251.         // End remove item by Edit
  1252.         $form $this->createForm(SalesInvoiceEditType::class, $salesInvoice);
  1253.         $form->handleRequest($request);
  1254.         $countryList $countryRepository->findAll();
  1255.         $courierList $courierRepository->findAll();
  1256.         $productTypeList $productTypeRepository->findAll(); 
  1257.         $additionalChargeList $entityManager->getRepository(AdditionalCharge::class)->findAll(); 
  1258.         if ($request->isXMLHttpRequest()) {
  1259.             //return new JsonResponse(array('success' => false, 'responseText' =>  $salesInvoice->getInvoiceno() ));
  1260.             $salesInvoiceObj $request->request->get('salesInvoiceObj');            
  1261.             if (!empty($salesInvoiceObj)) {
  1262.                 $salesInvoiceObj_array json_decode($salesInvoiceObjtrue);
  1263.                 $shipmentDate_array json_decode($request->request->get('shipmentDate'));
  1264.                 $hawbNo_array json_decode($request->request->get('hawbNo'));
  1265.                 $reference_array json_decode($request->request->get('reference'));
  1266.                 $country_array json_decode($request->request->get('country'));
  1267.                 $courier_array json_decode($request->request->get('courier'));
  1268.                 $productType_array json_decode($request->request->get('productType'));
  1269.                 $weight_array json_decode($request->request->get('weight'));
  1270.                 $vendorWeight_array json_decode($request->request->get('vendorWeight'));
  1271.                 $bookingRate_array json_decode($request->request->get('bookingRate'));
  1272.                 $salesRate_array json_decode($request->request->get('salesRate'));
  1273.                 $fsc_array json_decode($request->request->get('fsc'));
  1274.                 $vendorCovidCharge_array json_decode($request->request->get('vendorCovidCharge')); 
  1275.                 $covidCharge_array json_decode($request->request->get('covidCharge')); 
  1276.                 $customerCurrency_array json_decode($request->request->get('customerCurrency'));
  1277.                 $vendorCurrency_array json_decode($request->request->get('vendorCurrency'));             
  1278.                 $invoiceDetailsId_array json_decode($request->request->get('invoiceDetailsId'));
  1279.                 $vatApplicable_array json_decode($request->request->get('vatApplicable'));
  1280.                 $vendorVatApplicable_array json_decode($request->request->get('vendorVatApplicable'));
  1281.                 $vendorFsc_array json_decode($request->request->get('vendorFsc'));
  1282.                 $additionalCharge_array json_decode($request->request->get('additionalCharge'));
  1283.                 $additionalPayableAmount_array json_decode($request->request->get('additionalPayableAmount'));
  1284.                 $additionalReceivableAmount_array json_decode($request->request->get('additionalReceivableAmount'));
  1285.                 $additionalFscApplicable_array json_decode($request->request->get('additionalFscApplicable'));
  1286.                 $additionalVatApplicable_array json_decode($request->request->get('additionalVatApplicable'));
  1287.                 $additionalChargeId_array json_decode($request->request->get('additionalChargeId'));
  1288.                 // var_dump($accountNameId_array); die();
  1289.                 // return new JsonResponse(array('success' => false, 'responseText' =>  $salesInvoiceObj_array['CustomerId'] ));
  1290.                 $customerObj $entityManager->find(Customer::class, $salesInvoiceObj_array['CustomerId']);                                
  1291.                 $salesInvoice->setCustomer($customerObj);
  1292.                 $salesInvoice->setInvoiceNo($salesInvoiceObj_array['Invoiceno']);
  1293.                 $salesInvoice->setInvoiceDate(new \DateTime($salesInvoiceObj_array['Invoicedate']));        
  1294.                 $salesInvoice->setVat($salesInvoiceObj_array['Vat']);   
  1295.                 $salesInvoice->setPreviousDues($salesInvoiceObj_array['Previousdues']);
  1296.                 $salesInvoice->setApproval($salesInvoiceObj_array['Approval']); 
  1297.                 $salesInvoice->setPaymentNote($salesInvoiceObj_array['PaymentNote']);   
  1298.                 $salesInvoice->setRateApplicable($salesInvoiceObj_array['RateApplicable']);        
  1299.                 $salesInvoice->setRemarks($salesInvoiceObj_array['Remarks']);
  1300.                 
  1301.                 if($salesInvoiceObj_array['Submissiondate'] == '')
  1302.                     $salesInvoice->setSubmissionDate(new \DateTime($salesInvoiceObj_array['Invoicedate'])); 
  1303.                 else
  1304.                     $salesInvoice->setSubmissionDate(new \DateTime($salesInvoiceObj_array['Submissiondate'])); 
  1305.                 
  1306.                 $salesInvoice->getSalesInvoiceDetails()->clear();
  1307.                 $index 0;
  1308.                 foreach($hawbNo_array as $key=>$row
  1309.                 {
  1310.                     $keyValue $key;
  1311.                     $keyValue $keyValue 1;
  1312.                     if($invoiceDetailsId_array[$index] !== null)
  1313.                     {
  1314.                         // $salesInvoiceDetailsObj = $salesInvoiceDetailsRepository->find($invoiceDetailsId_array[$index]); 
  1315.                         
  1316.                         // $salesInvoiceDetailsObj->getInvoiceAdditionalCharges()->clear();
  1317.                         // $salesInvoiceDetailsObj->setShipmentDate(new \DateTime($shipmentDate_array[$index]));
  1318.                         // $salesInvoiceDetailsObj->setHawbNo($hawbNo_array[$index]);   
  1319.                         // $salesInvoiceDetailsObj->setReference($reference_array[$index]); 
  1320.                         // $countryObj = $countryRepository->find($country_array[$index]);         
  1321.                         // $salesInvoiceDetailsObj->setCountry($countryObj); 
  1322.                         // $courierObj = $courierRepository->find($courier_array[$index]);  
  1323.                         // $salesInvoiceDetailsObj->setCourier($courierObj); 
  1324.                         // $productTypeObj =$productTypeRepository->find($productType_array[$index]);  
  1325.                         // $salesInvoiceDetailsObj->setProductType($productTypeObj);    
  1326.                         // $salesInvoiceDetailsObj->setWeight($weight_array[$index]);  
  1327.                         // $salesInvoiceDetailsObj->setBookingWeight($vendorWeight_array[$index]);                   
  1328.                         // $salesInvoiceDetailsObj->setBookingRate($bookingRate_array[$index]);                               
  1329.                         // $salesInvoiceDetailsObj->setSalesRate($salesRate_array[$index]);
  1330.                         // $salesInvoiceDetailsObj->setFsc($fsc_array[$index]);
  1331.                         // $salesInvoiceDetailsObj->setVendorCovidCharge($vendorCovidCharge_array[$index]);
  1332.                         // $salesInvoiceDetailsObj->setCovidCharge($covidCharge_array[$index]);
  1333.                         // $salesInvoiceDetailsObj->setCurrency($customerCurrency_array[$index]);
  1334.                         // $salesInvoiceDetailsObj->setVendorCurrency($vendorCurrency_array[$index]);
  1335.                         // $salesInvoiceDetailsObj->setVatApplicable($vatApplicable_array[$index]);
  1336.                         // $salesInvoiceDetailsObj->setVendorVatApplicable($vendorVatApplicable_array[$index]);
  1337.                         // $salesInvoiceDetailsObj->setVendorFsc($vendorFsc_array[$index]);
  1338.                         // $salesInvoice->addSalesInvoiceDetail($salesInvoiceDetailsObj);
  1339.                         ///////////
  1340.                         
  1341.                         //return new JsonResponse(array('success' => false, 'responseText' =>  $invoiceDetailsId_array[$index] ));
  1342.                         $salesInvDetailsObj $salesInvoiceDetailsRepository->find($invoiceDetailsId_array[$index]); 
  1343.         
  1344.                         $countryObj $countryRepository->find($country_array[$index]);         
  1345.                         $salesInvDetailsObj->setCountry($countryObj); 
  1346.                         $courierObj $courierRepository->find($courier_array[$index]);  
  1347.                         $salesInvDetailsObj->setCourier($courierObj); 
  1348.                         
  1349.                         // Rate Type get Start Here getRateType()
  1350.                         if($courierObj->getZoneRateType() !== null)
  1351.                             $zoneWiseMasterRateTypeObj $entityManager->find(ZoneWiseMasterRate::class, $courierObj->getZoneRateType());
  1352.                         else 
  1353.                             $zoneWiseMasterRateTypeObj = new ZoneWiseMasterRate();
  1354.                         // Rate Type get End Here
  1355.                         $productTypeObj =$productTypeRepository->find($productType_array[$index]);  
  1356.                         $salesInvDetailsObj->setProductType($productTypeObj); 
  1357.                         
  1358.                         $shipmentObj $salesInvDetailsObj->getShipment();
  1359.                         
  1360.                         $shipmentDate = new \DateTime($shipmentDate_array[$index]);
  1361.                         
  1362.                        // $salesInvDetailsObj->setRateApplicable(!$salesInvDetailsObj->isExpedite() ? $customerObj->getRateType() : 5);   // Expedite Rate Type 5 
  1363.         
  1364.                         $courierWiseZoneObj $entityManager->getRepository(CourierWiseZone::class)
  1365.                                                             ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);  
  1366.         
  1367.                         if($courierWiseZoneObj === null )
  1368.                         {
  1369.                             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.'.'));
  1370.                                                         
  1371.                         }
  1372.                         $salesInvDetailsObj->setZone($courierWiseZoneObj->getZone());
  1373.         
  1374.                         $salesInvDetailsObj->setShipmentDate(new \DateTime($shipmentDate_array[$index]));  
  1375.                         $salesInvDetailsObj->setHawbNo($hawbNo_array[$index]);                         
  1376.                         $salesInvDetailsObj->setReference($reference_array[$index]);
  1377.                         $salesInvDetailsObj->setWeight($weight_array[$index]);       
  1378.                         $salesInvDetailsObj->setBookingWeight($vendorWeight_array[$index]);    
  1379.                         $salesInvDetailsObj->setVatApplicable($vatApplicable_array[$index]);
  1380.                                                     
  1381.                         //Customer Weight Calculation Start 
  1382.                         // Half and Per KG
  1383.                         $weight $weight_array[$index];
  1384.                         $pointInputWeight $weight floor($weight);
  1385.                         $intInputWeight floor($weight);
  1386.                         $finalWeight 0;
  1387.                         $rateWeight 0;
  1388.                         if($weight <  $courierObj->getWeightPerkg())
  1389.                         {
  1390.                             if($pointInputWeight && $pointInputWeight <= 0.5)
  1391.                             {
  1392.                                 $finalWeight = (float)0.5;
  1393.                             }
  1394.                             elseif($pointInputWeight 0.5 && $pointInputWeight <=1)
  1395.                             {
  1396.                                 $finalWeight = (float)1;
  1397.                             }
  1398.                         }
  1399.                         else
  1400.                         {
  1401.                             if($pointInputWeight && $pointInputWeight <=1)
  1402.                             {
  1403.                                 $finalWeight = (float)1;
  1404.                             }
  1405.                         }
  1406.                         $rateWeight $intInputWeight $finalWeight;
  1407.         
  1408.                         //Only Per KG
  1409.                         $pointInputPerKgWeight $weight floor($weight);
  1410.                         $intInputPerKgWeight floor($weight);
  1411.                         $finalPerKgWeight 0;
  1412.                         $ratePerKgWeight 0;
  1413.                         if($pointInputPerKgWeight && $pointInputPerKgWeight <=1)
  1414.                         {
  1415.                             $finalPerKgWeight = (float)1;
  1416.                         }
  1417.                         $ratePerKgWeight $intInputPerKgWeight $finalPerKgWeight;
  1418.                         //Customer Weight Calculation End
  1419.         
  1420.                         //Vendor/Booking weight Calculation Start 
  1421.                         // Half and Per KG
  1422.                         $bookingWeight trim($vendorWeight_array[$index]);
  1423.                         $pointInputBookingWeight $bookingWeight floor($bookingWeight);
  1424.                         $intInputBookingWeight floor($bookingWeight);
  1425.                         $finalBookingWeight 0;
  1426.                         $rateBookingWeight 0;
  1427.                         if($bookingWeight <  $courierObj->getWeightPerkg())
  1428.                         {
  1429.                             if($pointInputBookingWeight && $pointInputBookingWeight <= 0.5)
  1430.                             {
  1431.                                 $finalBookingWeight = (float)0.5;
  1432.                             }
  1433.                             elseif($pointInputBookingWeight 0.5 && $pointInputBookingWeight <=1)
  1434.                             {
  1435.                                 $finalBookingWeight = (float)1;
  1436.                             }
  1437.                         }
  1438.                         else
  1439.                         {
  1440.                             if($pointInputBookingWeight && $pointInputBookingWeight <=1)
  1441.                             {
  1442.                                 $finalBookingWeight = (float)1;
  1443.                             }
  1444.                         }
  1445.                         $rateBookingWeight $intInputBookingWeight $finalBookingWeight;
  1446.         
  1447.                         //Only Per KG
  1448.                         $pointInputPerKgBookingWeight $bookingWeight floor($bookingWeight);
  1449.                         $intInputPerKgBookingWeight floor($bookingWeight);
  1450.                         $finalPerKgBookingWeight 0;
  1451.                         $ratePerKgBookingWeight 0;
  1452.                         if($pointInputPerKgBookingWeight && $pointInputPerKgBookingWeight <=1)
  1453.                         {
  1454.                             $finalPerKgBookingWeight = (float)1;
  1455.                         }
  1456.                         $ratePerKgBookingWeight $intInputPerKgBookingWeight $finalPerKgBookingWeight;
  1457.                         //Weight Calculation End
  1458.                         //return new JsonResponse(array('success' => false, 'responseText' =>  $salesInvDetailsObj->getRateApplicable() ));
  1459.                         
  1460.                         // Get Settings Currency Start
  1461.                         $settingsObj $settingsInfoRepository->findByDateCurrency(1$salesInvDetailsObj->getShipmentDate()->format('Y-m-d')); 
  1462.                         if($settingsObj === null)
  1463.                         {                                
  1464.                             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.'.'));
  1465.                         }                       
  1466.                         // Get Settings Currency End
  1467.                         
  1468.                         
  1469.                         //Master Rate Assign Start  
  1470.                         if($salesInvDetailsObj->getShipment() === null )
  1471.                         {   
  1472.                             // Accessaccessory Surcharge
  1473.                             $salesInvDetailsObj->setBookingRate($bookingRate_array[$index]);  
  1474.                         }
  1475.                         else if(!$salesInvDetailsObj->getShipment()->isExpedite() && $salesInvDetailsObj->getShipment() !== null)
  1476.                         {     
  1477.                             $finalMasterRateCal 0;                 
  1478.                             $perKgRateWeight $courierObj->getWeightPerkgRate();
  1479.                             if($courierObj->getId() != 3)
  1480.                             {
  1481.                                 if($rateBookingWeight $perKgRateWeight )
  1482.                                 { 
  1483.                                     $countryWiseMasterRate $entityManager->getRepository(CountryWiseMasterRate::class) 
  1484.                                                             ->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateBookingWeight ]);                                          
  1485.     
  1486.                                     if($countryWiseMasterRate !== null
  1487.                                     { 
  1488.                                         $finalMasterRateCal =  $countryWiseMasterRate->getRate();
  1489.                                     }                           
  1490.                                 }
  1491.                                 else
  1492.                                 {
  1493.                                     $countryWiseMasterRate $entityManager->getRepository(CountryWiseMasterRate::class)
  1494.                                                             ->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);                           
  1495.                                     if($countryWiseMasterRate !== null
  1496.                                     { 
  1497.                                         $finalMasterRateCal $countryWiseMasterRate->getRate() * $rateBookingWeight;                                    
  1498.                                     }
  1499.                                 }
  1500.             
  1501.                                 if($countryWiseMasterRate === null)  
  1502.                                 {
  1503.                                     if($rateBookingWeight $perKgRateWeight )
  1504.                                     { 
  1505.                                        $zoneWiseMasterRate $entityManager->getRepository(ZoneWiseMasterRate::class)
  1506.                                                             ->findBookingRatebyCourierAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $zoneWiseMasterRateTypeObj->getRateType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight);                       
  1507.                                                 
  1508.                                         if($zoneWiseMasterRate !== null)      
  1509.                                         { 
  1510.                                             $finalMasterRateCal $zoneWiseMasterRate->getRate();
  1511.                                         }
  1512.                                     }
  1513.                                     else
  1514.                                     {
  1515.                                         
  1516.                                        $zoneWiseMasterRate $entityManager->getRepository(ZoneWiseMasterRate::class)
  1517.                                                             ->findBookingRatebyCourierAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $zoneWiseMasterRateTypeObj->getRateType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $courierObj->getId() == ?  $perKgRateWeight $rateBookingWeight );                     
  1518.                                         if($zoneWiseMasterRate !== null)      
  1519.                                         { 
  1520.                                             $finalMasterRateCal $zoneWiseMasterRate->getRate() * $rateBookingWeight;                                
  1521.                                         }
  1522.                                     }
  1523.                                 }        
  1524.             
  1525.                                 if($countryWiseMasterRate !== null)
  1526.                                 {
  1527.                                     $salesInvDetailsObj->setBookingRate($finalMasterRateCal);                            
  1528.                                 }
  1529.                                 else if($zoneWiseMasterRate !== null)
  1530.                                 {
  1531.                                     $salesInvDetailsObj->setBookingRate($finalMasterRateCal);                            
  1532.                                 }
  1533.                                 else
  1534.                                 { 
  1535.             
  1536.                                     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.'.'));
  1537.                                 }
  1538.                             }
  1539.                             else
  1540.                             {
  1541.                                 if($rateBookingWeight <= 30
  1542.                                 {
  1543.                                     $zoneWiseMasterRate $entityManager->getRepository(ZoneWiseMasterRate::class)
  1544.                                         ->findBookingRatebyCourierAndWeight(
  1545.                                             $shipmentObj->getShipmentType(), 
  1546.                                             $zoneWiseMasterRateTypeObj->getRateType(), 
  1547.                                             $courierObj->getId(), 
  1548.                                             $courierWiseZoneObj->getZone()->getId(), 
  1549.                                             $productTypeObj->getRateid(), 
  1550.                                             $rateBookingWeight
  1551.                                     );   
  1552.                                     
  1553.                                     $finalRate $zoneWiseMasterRate->getRate();
  1554.                                 }
  1555.                                 else if($rateBookingWeight 30 && $rateBookingWeight <= 70)
  1556.                                 {
  1557.                                     $zoneWiseMasterRateFs $entityManager->getRepository(ZoneWiseMasterRate::class)
  1558.                                         ->findBookingRatebyCourierAndWeight(
  1559.                                             $shipmentObj->getShipmentType(), 
  1560.                                             $zoneWiseMasterRateTypeObj->getRateType(), 
  1561.                                             $courierObj->getId(), 
  1562.                                             $courierWiseZoneObj->getZone()->getId(), 
  1563.                                             $productTypeObj->getRateid(), 
  1564.                                             30
  1565.                                     );   
  1566.     
  1567.                                     $zoneWiseMasterRateSs $entityManager->getRepository(ZoneWiseMasterRate::class)
  1568.                                         ->findBookingRatebyCourierAndWeight(
  1569.                                             $shipmentObj->getShipmentType(), 
  1570.                                             $zoneWiseMasterRateTypeObj->getRateType(), 
  1571.                                             $courierObj->getId(), 
  1572.                                             $courierWiseZoneObj->getZone()->getId(), 
  1573.                                             $productTypeObj->getRateid(), 
  1574.                                             31
  1575.                                     ); 
  1576.                                     
  1577.                                     $finalRate $zoneWiseMasterRateFs->getRate() + (($rateBookingWeight 30) * $zoneWiseMasterRateSs->getRate());
  1578.                                 }
  1579.                                 else if($rateBookingWeight 70)
  1580.                                 {
  1581.                                     $zoneWiseMasterRateFs $entityManager->getRepository(ZoneWiseMasterRate::class)
  1582.                                         ->findBookingRatebyCourierAndWeight(
  1583.                                             $shipmentObj->getShipmentType(), 
  1584.                                             $zoneWiseMasterRateTypeObj->getRateType(), 
  1585.                                             $courierObj->getId(), 
  1586.                                             $courierWiseZoneObj->getZone()->getId(), 
  1587.                                             $productTypeObj->getRateid(), 
  1588.                                             30
  1589.                                     );   
  1590.     
  1591.                                     $zoneWiseMasterRateSs $entityManager->getRepository(ZoneWiseMasterRate::class)
  1592.                                         ->findBookingRatebyCourierAndWeight(
  1593.                                             $shipmentObj->getShipmentType(), 
  1594.                                             $zoneWiseMasterRateTypeObj->getRateType(), 
  1595.                                             $courierObj->getId(), 
  1596.                                             $courierWiseZoneObj->getZone()->getId(), 
  1597.                                             $productTypeObj->getRateid(), 
  1598.                                             31
  1599.                                     ); 
  1600.     
  1601.                                     $zoneWiseMasterRateTs $entityManager->getRepository(ZoneWiseMasterRate::class)
  1602.                                         ->findBookingRatebyCourierAndWeight(
  1603.                                             $shipmentObj->getShipmentType(), 
  1604.                                             $zoneWiseMasterRateTypeObj->getRateType(), 
  1605.                                             $courierObj->getId(), 
  1606.                                             $courierWiseZoneObj->getZone()->getId(), 
  1607.                                             $productTypeObj->getRateid(), 
  1608.                                             71
  1609.                                     ); 
  1610.     
  1611.                                     $finalRate $zoneWiseMasterRateFs->getRate() + (40 $zoneWiseMasterRateSs->getRate()) + (($rateBookingWeight 70) * $zoneWiseMasterRateTs->getRate());
  1612.                                 }
  1613.     
  1614.                                 $salesInvDetailsObj->setBookingRate($finalRate);
  1615.     
  1616.                             }
  1617.                         }
  1618.                         else
  1619.                         {
  1620.                             
  1621.                             // Expedite Rate 
  1622.                             // $salesInvDetailsObj->setBookingRate($countryObj->getMasterExpediteRate() * $rateBookingWeight);   
  1623.                             // Expedite Or Cash Master Rate
  1624.                             $countryWiseCashMasterRate $entityManager->getRepository(CountryWiseMasterRate::class) 
  1625.                                                             ->findCashBookingRatebyCourierAndWeight(2$salesInvDetailsObj->getShipmentDate(), $courierObj->getId(), $countryObj->getId(), $productTypeObj->getRateid(), $rateBookingWeight);                                          
  1626.                             if($countryWiseCashMasterRate == null)
  1627.                             {
  1628.                                 $zoneWiseMasterRate $entityManager->getRepository(ZoneWiseMasterRate::class)
  1629.                                                         ->findBookingCashRatebyCourierAndWeight(3$salesInvDetailsObj->getShipmentDate(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight );                     
  1630.                             }
  1631.                             if($countryWiseCashMasterRate !== null)
  1632.                             {
  1633.                                 $salesInvDetailsObj->setBookingRate($countryWiseCashMasterRate->getRate() * $rateBookingWeight); 
  1634.                             }
  1635.                             else if($zoneWiseMasterRate !== null)      
  1636.                             {                          
  1637.                                 $salesInvDetailsObj->setBookingRate(round(($zoneWiseMasterRate->getRate() * $rateBookingWeight) / $settingsObj->getCurrency(),2));                           
  1638.                             }
  1639.                             else
  1640.                             {
  1641.                                 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.'.'));
  1642.                             }
  1643.                           //  return new JsonResponse(array('success' => false, 'responseText' =>  3 ));
  1644.                         }
  1645.                         //Master Rate Assign End
  1646.         
  1647.                         
  1648.                         // Own Company Rate for Customer Start
  1649.                         $salesCourierId 0;
  1650.                         $salesCourierName "";
  1651.                         $salesZoneId 0;
  1652.                         if($this->getUser()->getUserCompany()->getCustomerRate() == // Own Company Wise Customer Rate
  1653.                         {
  1654.                             if($customerObj->getCustomerType() == )  //Customer
  1655.                             {
  1656.                                 $salesCourierId $this->getUser()->getUserCompany()->getCompanyCourier()->getId();
  1657.                                 $salesCourierName $this->getUser()->getUserCompany()->getCompanyCourier()->getName();
  1658.     
  1659.                                 /// Zone 
  1660.                                 $courierWiseZoneObject $entityManager->getRepository(CourierWiseZone::class)
  1661.                                                     ->findOneBy(['courier' => $salesCourierId'country' => $countryObj->getId() ]);                       
  1662.                                 if($courierWiseZoneObject === null )
  1663.                                 {
  1664.                                     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.'.'));
  1665.                                                                             
  1666.                                 }
  1667.     
  1668.                                 $salesZoneId $courierWiseZoneObject->getZone()->getId();
  1669.                                                                 
  1670.                             }
  1671.                             else  //Agent
  1672.                             {
  1673.                                 $salesCourierId $courierObj->getId();
  1674.                                 $salesCourierName $courierObj->getName();
  1675.                                 $salesZoneId $courierWiseZoneObj->getZone()->getId();
  1676.                                 
  1677.                             }
  1678.                         }
  1679.                         else   // Separate Courier Wise Customer Rate
  1680.                         {
  1681.                             $salesCourierId $courierObj->getId();
  1682.                             $salesCourierName $courierObj->getName();
  1683.                             $salesZoneId $courierWiseZoneObj->getZone()->getId();
  1684.                             
  1685.                         }
  1686.                         // Own Company Rate for Customer End
  1687.                         
  1688.                         
  1689.                         // return new JsonResponse(array('success' => false, 'responseText' =>  123 ));
  1690.                         if($salesInvDetailsObj->getRateApplicable() <= &&  $salesInvDetailsObj->getShipment() === null)
  1691.                         {
  1692.                             
  1693.                             // Accessaccessory Surcharge
  1694.                             $salesInvDetailsObj->setSalesRate($salesRate_array[$index]);
  1695.                         }
  1696.                         else if($salesInvDetailsObj->getRateApplicable() <= && !$salesInvDetailsObj->getShipment()->isExpedite()  && $salesInvDetailsObj->getShipment() !== null)  // Predefine Rate
  1697.                         {
  1698.                             
  1699.                             //Sales Rate Assign Start 
  1700.                             // if($customerObj->getRateCurrency() == 2)
  1701.                             // {
  1702.                             //     $perKgRateWeight = 21;
  1703.                             // }
  1704.     
  1705.                             $finalRateCal 0;
  1706.     
  1707.                             if($customerObj->getRateType() == 1)  // Customer wise sales rate     
  1708.                             {
  1709.                                 if($courierObj->getId() != 3)  
  1710.                                 {
  1711.                                     if($rateWeight $perKgRateWeight )
  1712.                                     { 
  1713.                                         $countryWiseSalesRate $entityManager->getRepository(CountryWiseSalesRate::class)
  1714.                                                         ->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $salesCourierId'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateWeight ]);                                        
  1715.                                         if($countryWiseSalesRate !== null)     
  1716.                                         {                         
  1717.                                             $finalRateCal $countryWiseSalesRate->getRate();
  1718.                                         }
  1719.                                     }
  1720.                                     else
  1721.                                     {
  1722.                                         $countryWiseSalesRate $entityManager->getRepository(CountryWiseSalesRate::class)
  1723.                                                         ->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $salesCourierId'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);                           
  1724.                                         if($countryWiseSalesRate !== null)     
  1725.                                         { 
  1726.                                             $finalRateCal $countryWiseSalesRate->getRate() * $rateWeight;                                            
  1727.                                         }
  1728.                                     }
  1729.                                 
  1730.                                     if($countryWiseSalesRate === null)  
  1731.                                     {
  1732.                                         if($rateWeight $perKgRateWeight )
  1733.                                         {
  1734.                                             $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseSalesRate::class)
  1735.                                                                     ->findSalesRatebyCustomerAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $customerObj->getId(), $salesCourierId$salesZoneId$productTypeObj->getRateid(), $rateWeight);                                     
  1736.                                             if($zoneWiseSalesRate !== null)     
  1737.                                             {                         
  1738.                                                 $finalRateCal $zoneWiseSalesRate->getRate();
  1739.                                             }
  1740.                                         }
  1741.                                         else
  1742.                                         {                                                             
  1743.                                             $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseSalesRate::class) 
  1744.                                                                     ->findSalesRatebyCustomerAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $customerObj->getId(), $salesCourierId$salesZoneId$productTypeObj->getRateid(), $courierObj->getId() == ?  $perKgRateWeight $rateWeight );                       
  1745.                                             
  1746.                                             if($zoneWiseSalesRate !== null)     
  1747.                                             { 
  1748.                                                 $finalRateCal $zoneWiseSalesRate->getRate() * $rateWeight;                                      
  1749.                                             }
  1750.                                         }
  1751.                                     }        
  1752.         
  1753.                                     if($countryWiseSalesRate !== null)
  1754.                                     {
  1755.                                         $salesInvDetailsObj->setSalesRate($finalRateCal);
  1756.                                         
  1757.                                     }
  1758.                                     else if($zoneWiseSalesRate !== null)
  1759.                                     {
  1760.                                         $salesInvDetailsObj->setSalesRate($finalRateCal);                                    
  1761.                                     }
  1762.                                     else
  1763.                                     { 
  1764.                                         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.'.'));
  1765.                                     }
  1766.                                 }
  1767.                                 else
  1768.                                 {
  1769.                                     if($rateWeight <= 30)
  1770.                                     {
  1771.                                         $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseSalesRate::class)
  1772.                                             ->findSalesRatebyCustomerAndWeight(
  1773.                                                 $shipmentObj->getShipmentType(), 
  1774.                                                 $customerObj->getId(), 
  1775.                                                 $salesCourierId
  1776.                                                 $salesZoneId
  1777.                                                 $productTypeObj->getRateid(), 
  1778.                                                 $rateWeight
  1779.                                             );   
  1780.     
  1781.                                         $finalSalesRate $zoneWiseSalesRate->getRate();                      
  1782.                                     }
  1783.                                     else if($rateWeight 30 && $rateWeight <= 70)
  1784.                                     {
  1785.                                         $zoneWiseSalesRateFs $entityManager->getRepository(ZoneWiseSalesRate::class)
  1786.                                             ->findSalesRatebyCustomerAndWeight(
  1787.                                                 $shipmentObj->getShipmentType(), 
  1788.                                                 $customerObj->getId(), 
  1789.                                                 $salesCourierId
  1790.                                                 $salesZoneId
  1791.                                                 $productTypeObj->getRateid(), 
  1792.                                                 30
  1793.                                             );   
  1794.                                         
  1795.                                         $zoneWiseSalesRateSs $entityManager->getRepository(ZoneWiseSalesRate::class)
  1796.                                             ->findSalesRatebyCustomerAndWeight(
  1797.                                                 $shipmentObj->getShipmentType(), 
  1798.                                                 $customerObj->getId(), 
  1799.                                                 $salesCourierId
  1800.                                                 $salesZoneId
  1801.                                                 $productTypeObj->getRateid(), 
  1802.                                                 31
  1803.                                             );  
  1804.     
  1805.                                         $finalSalesRate $zoneWiseSalesRateFs->getRate() + (($rateWeight 30) * $zoneWiseSalesRateSs->getRate()); 
  1806.                                     }
  1807.                                     else if($rateWeight 70)
  1808.                                     {
  1809.                                         $zoneWiseSalesRateFs $entityManager->getRepository(ZoneWiseSalesRate::class)
  1810.                                             ->findSalesRatebyCustomerAndWeight(
  1811.                                                 $shipmentObj->getShipmentType(), 
  1812.                                                 $customerObj->getId(), 
  1813.                                                 $salesCourierId
  1814.                                                 $salesZoneId
  1815.                                                 $productTypeObj->getRateid(), 
  1816.                                                 30
  1817.                                             );   
  1818.                                     
  1819.                                         $zoneWiseSalesRateSs $entityManager->getRepository(ZoneWiseSalesRate::class)
  1820.                                             ->findSalesRatebyCustomerAndWeight(
  1821.                                                 $shipmentObj->getShipmentType(), 
  1822.                                                 $customerObj->getId(), 
  1823.                                                 $salesCourierId
  1824.                                                 $salesZoneId
  1825.                                                 $productTypeObj->getRateid(), 
  1826.                                                 31
  1827.                                             );  
  1828.     
  1829.                                         $zoneWiseSalesRateTs $entityManager->getRepository(ZoneWiseSalesRate::class)
  1830.                                             ->findSalesRatebyCustomerAndWeight(
  1831.                                                 $shipmentObj->getShipmentType(), 
  1832.                                                 $customerObj->getId(), 
  1833.                                                 $salesCourierId
  1834.                                                 $salesZoneId
  1835.                                                 $productTypeObj->getRateid(), 
  1836.                                                 71
  1837.                                             ); 
  1838.                                         
  1839.                                         $finalSalesRate $zoneWiseSalesRateFs->getRate() + (40 $zoneWiseSalesRateSs->getRate()) + (($rateWeight 70) * $zoneWiseSalesRateTs->getRate()); 
  1840.                                     }
  1841.                                     
  1842.                                      $salesInvDetailsObj->setSalesRate($finalSalesRate);
  1843.                                 }
  1844.                             }
  1845.                             else  // Common sales rate   
  1846.                             {
  1847.                                 if($rateWeight $perKgRateWeight )
  1848.                                 { 
  1849.                                     $countryWiseSalesRate $entityManager->getRepository(CountryWiseCommonSalesRate::class)
  1850.                                                             ->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'courier' => $salesCourierId'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateWeight ]);                           
  1851.                                 }
  1852.                                 else
  1853.                                 {
  1854.                                     $countryWiseSalesRate $entityManager->getRepository(CountryWiseCommonSalesRate::class)
  1855.                                                             ->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'courier' => $salesCourierId'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);                           
  1856.                                     if($countryWiseSalesRate !== null)     
  1857.                                     {   
  1858.                                         $countryWiseSalesRate->setRate($countryWiseSalesRate->getRate() * $rateWeight);
  1859.                                     }
  1860.                                 }
  1861.                                     
  1862.     
  1863.                                 if($countryWiseSalesRate === null)  
  1864.                                 {
  1865.                                     if($rateWeight $perKgRateWeight )
  1866.                                     {
  1867.                                         $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseCommonSalesRate::class)
  1868.                                                                 ->findCommonSalesRatebyCourierAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $salesCourierId$salesZoneId$productTypeObj->getRateid(), $rateWeight);                                     
  1869.                                     }
  1870.                                     else
  1871.                                     {
  1872.                                         $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseCommonSalesRate::class)
  1873.                                                                 ->findCommonSalesRatebyCourierAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $salesCourierId$salesZoneId$productTypeObj->getRateid(), $courierObj->getId() == ?  $perKgRateWeight $rateWeight );                       
  1874.                                         if($zoneWiseSalesRate !== null)     
  1875.                                         {       
  1876.                                             $zoneWiseSalesRate->setRate($zoneWiseSalesRate->getRate() * $rateWeight);
  1877.                                         }
  1878.                                     }
  1879.                                 }        
  1880.     
  1881.                                 if($countryWiseSalesRate !== null)
  1882.                                 {
  1883.                                     $salesInvDetailsObj->setSalesRate($zoneWiseSalesRate->getRate());
  1884.                                 }
  1885.                                 else if($zoneWiseSalesRate !== null)
  1886.                                 {
  1887.                                     $salesInvDetailsObj->setSalesRate($countryWiseSalesRate->getRate());
  1888.                                 }
  1889.                                 else
  1890.                                 {
  1891.                                     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.'.'));
  1892.                                 }
  1893.                             }
  1894.                             //Sales Rate Assign End
  1895.                             
  1896.                         }
  1897.                         else  // Special Calculated Rate
  1898.                         {
  1899.                             
  1900.                            $salesInvDetailsObj->setSalesRate($salesRate_array[$index]);                  
  1901.                         }
  1902.     
  1903.                         
  1904.                         // Master Weight and Sales Rate Calculation Start                                
  1905.                         if($salesInvDetailsObj->getShipment() !== null && $salesInvDetailsObj->getRateApplicable() <= && !$salesInvDetailsObj->getShipment()->isExpedite())  // Predefine Rate
  1906.                         {
  1907.                             
  1908.                             //Sales Rate Assign Start 
  1909.                             // if($customerObj->getRateCurrency() == 2)
  1910.                             // {
  1911.                             //     $perKgRateWeight = 21;
  1912.                             // }
  1913.     
  1914.                             $finalRateCal 0;
  1915.     
  1916.                             if($customerObj->getRateType() == 1)  // Customer wise sales rate     
  1917.                             {
  1918.                                 if($rateBookingWeight $perKgRateWeight )
  1919.                                 { 
  1920.                                   $countryWiseSalesRate $entityManager->getRepository(CountryWiseSalesRate::class)
  1921.                                                     ->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateBookingWeight ]);                              
  1922.                                     if($countryWiseSalesRate !== null)     
  1923.                                     {                         
  1924.                                         $finalRateCal $countryWiseSalesRate->getRate();
  1925.                                     }
  1926.                                 }
  1927.                                 else
  1928.                                 {
  1929.                                      $countryWiseSalesRate $entityManager->getRepository(CountryWiseSalesRate::class)
  1930.                                                     ->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);
  1931.                                     if($countryWiseSalesRate !== null)     
  1932.                                     { 
  1933.                                         $finalRateCal $countryWiseSalesRate->getRate() * $rateBookingWeight;                                            
  1934.                                     }
  1935.                                 }
  1936.                             
  1937.                                 if($countryWiseSalesRate === null)  
  1938.                                 {
  1939.                                     if($rateBookingWeight $perKgRateWeight )
  1940.                                     {
  1941.                                         $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseSalesRate::class)
  1942.                                                                 ->findSalesRatebyCustomerAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $customerObj->getId(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight);                                     
  1943.                                         // return new JsonResponse(array('success' => false, 'responseText' => $rateBookingWeight .'-'. $zoneWiseSalesRate->getRate() ));                           
  1944.                                         if($zoneWiseSalesRate !== null)     
  1945.                                         {                         
  1946.                                             $finalRateCal $zoneWiseSalesRate->getRate();
  1947.                                         }
  1948.                                     }
  1949.                                     else
  1950.                                     {                                                             
  1951.                                         $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseSalesRate::class) 
  1952.                                                                 ->findSalesRatebyCustomerAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $customerObj->getId(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $courierObj->getId() == ?  $perKgRateWeight $rateWeight );                       
  1953.                                         
  1954.                                         if($zoneWiseSalesRate !== null)     
  1955.                                         { 
  1956.                                             $finalRateCal $zoneWiseSalesRate->getRate() * $rateBookingWeight;                                      
  1957.                                         }
  1958.                                     }
  1959.                                 }        
  1960.     
  1961.                                 if($countryWiseSalesRate !== null)
  1962.                                 {
  1963.                                     $salesInvDetailsObj->setSalesMasterRate($finalRateCal);
  1964.                                     
  1965.                                 }
  1966.                                 else if($zoneWiseSalesRate !== null)
  1967.                                 {
  1968.                                     $salesInvDetailsObj->setSalesMasterRate($finalRateCal);                                    
  1969.                                 }
  1970.                                 else
  1971.                                 {                                   
  1972.                                     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.'.'));
  1973.                                 }
  1974.                             }
  1975.                             else  // Common sales rate   
  1976.                             {
  1977.                                 if($rateBookingWeight $perKgRateWeight )
  1978.                                 { 
  1979.                                     $countryWiseSalesRate $entityManager->getRepository(CountryWiseCommonSalesRate::class)
  1980.                                                             ->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateBookingWeight ]);                           
  1981.                                 }
  1982.                                 else
  1983.                                 {
  1984.                                     $countryWiseSalesRate $entityManager->getRepository(CountryWiseCommonSalesRate::class)
  1985.                                                             ->findOneBy(['type' => $salesInvDetailsObj->getShipment()->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);                           
  1986.                                     if($countryWiseSalesRate !== null)     
  1987.                                     {   
  1988.                                         $countryWiseSalesRate->setRate($countryWiseSalesRate->getRate() * $rateWeight);
  1989.                                     }
  1990.                                 }
  1991.                                     
  1992.     
  1993.                                 if($countryWiseSalesRate === null)  
  1994.                                 {
  1995.                                     if($rateWeight $perKgRateWeight )
  1996.                                     {
  1997.                                         $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseCommonSalesRate::class)
  1998.                                                                 ->findCommonSalesRatebyCourierAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight);                                     
  1999.                                     }
  2000.                                     else
  2001.                                     {
  2002.                                         $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseCommonSalesRate::class)
  2003.                                                                 ->findCommonSalesRatebyCourierAndWeight($salesInvDetailsObj->getShipment()->getShipmentType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $courierObj->getId() == ?  $perKgRateWeight $rateBookingWeight );                       
  2004.                                         if($zoneWiseSalesRate !== null)     
  2005.                                         {       
  2006.                                             $zoneWiseSalesRate->setRate($zoneWiseSalesRate->getRate() * $rateBookingWeight);
  2007.                                         }
  2008.                                     }
  2009.                                 }        
  2010.     
  2011.                                 if($countryWiseSalesRate !== null)
  2012.                                 {
  2013.                                     $salesInvDetailsObj->setSalesMasterRate($zoneWiseSalesRate->getRate());
  2014.                                 }
  2015.                                 else if($zoneWiseSalesRate !== null)
  2016.                                 {
  2017.                                     $salesInvDetailsObj->setSalesMasterRate($countryWiseSalesRate->getRate());
  2018.                                 }
  2019.                                 else
  2020.                                 {                                   
  2021.                                     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.'.'));
  2022.                                 }
  2023.                             }
  2024.                             //Sales Rate Assign End
  2025.                             
  2026.                         }
  2027.                         else if($salesInvDetailsObj->getShipment() === null)
  2028.                         {
  2029.                             
  2030.                             $salesInvDetailsObj->setSalesMasterRate($salesInvDetailsObj->getBookingRate());
  2031.                         }
  2032.                         else  // Special Calculated Rate
  2033.                         {
  2034.                             
  2035.                             // Get Settings Currency Start
  2036.                             $settingsObj $settingsInfoRepository
  2037.                                                 ->findByDateCurrency(1$salesInvDetailsObj->getShipmentDate()->format('Y-m-d')); 
  2038.     
  2039.                             if($settingsObj === null)
  2040.                             {                                
  2041.                                 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.'.'));
  2042.                             }                       
  2043.                             // Get Settings Currency End
  2044.     
  2045.                             $salesInvDetailsObj->setSalesMasterRate(round((float)$salesRate_array[$index] / $settingsObj->getCurrency(),2));                        
  2046.                         }                    
  2047.     
  2048.                         // Master Weight and Sales Rate Calculation End
  2049.     
  2050.                          // SRO Calculation Start
  2051.                         if($salesInvDetailsObj->getShipment() !== null && $courierObj->getSro() == && $salesInvDetailsObj->getRateApplicable() <= && !$salesInvDetailsObj->getShipment()->isExpedite())
  2052.                         {
  2053.                             $salesInvDetailsObj->setSro($courierObj->getSroCharge());
  2054.                         }
  2055.                         else
  2056.                         {
  2057.                             $salesInvDetailsObj->setSro(0);
  2058.                         }
  2059.                         // SRO Calculation End
  2060.                     
  2061.                         //Master Covid Charge Cal Start
  2062.                         if($salesInvDetailsObj->getRateApplicable() <= && $salesInvDetailsObj->getShipment() !== null && !$salesInvDetailsObj->getShipment()->isExpedite())
  2063.                         {
  2064.                             if($courierObj->getCovidChargeApplicable() == && $courierObj->getId() == 1)  // DHL Covid Charge Cal
  2065.                             {
  2066.                                
  2067.                                 // // Demand Charge Start
  2068.                                 // $comparisonDate = new DateTime('2024-09-14');
  2069.                                 // if($salesInvDetailsObj->getShipmentDate() > $comparisonDate)
  2070.                                 // {
  2071.                                 //     $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)
  2072.                                 //                                 ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]); 
  2073.                                     
  2074.                                 //     if($countryWiseCovidCharge !== null)
  2075.                                 //     {                          
  2076.                                 //         $salesInvDetailsObj->setVendorCovidCharge($countryWiseCovidCharge->getRate() * $rateBookingWeight);                                       
  2077.                                 //     }
  2078.                                 //     else
  2079.                                 //     {
  2080.                                 //         return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  2081.                                 //     }   
  2082.                                 // }                          
  2083.                                 // // Demand Charge End
  2084.                                 
  2085.                                 // // Go Green Charge Start
  2086.                                 // $comparisonDate = new DateTime('2024-04-01');
  2087.     
  2088.                                 // if ($salesInvDetailsObj->getShipmentDate() < $comparisonDate) {
  2089.                                 //     if($countryObj->getId() == 11 || $countryObj->getId() == 151)
  2090.                                 //     {
  2091.                                 //         $covidChargeUsd = 3.35;
  2092.                                 //     }
  2093.                                 //     else
  2094.                                 //     {
  2095.                                 //         $covidChargeUsd = 1.15;
  2096.                                 //     }
  2097.                                 // } else {
  2098.                                 //     if($countryObj->getId() == 11 || $countryObj->getId() == 151)
  2099.                                 //     {
  2100.                                 //         $covidChargeUsd = 0.56;
  2101.                                 //     }
  2102.                                 //     else
  2103.                                 //     {
  2104.                                 //         $covidChargeUsd = 0.56;
  2105.                                 //     }
  2106.                                 // }
  2107.     
  2108.                                 // $salesInvDetailsObj->setVendorCovidCharge($covidChargeUsd * $rateBookingWeight);
  2109.                                 // // Go Green Charge End
  2110.                           
  2111.                                   
  2112.                                     
  2113.                             }
  2114.                             else if($courierObj->getCovidChargeApplicable() == && $courierObj->getId() == 2// Fedex Covid Charge Cal
  2115.                             {
  2116.                                 // Demand Charge Start
  2117.                                 $comparisonDate = new DateTime('2024-11-17');
  2118.                                 if($salesInvDetailsObj->getShipmentDate() > $comparisonDate)
  2119.                                 {
  2120.                                     $zoneWiseCovidCharge $entityManager->getRepository(ZoneWiseCovidCharge::class)
  2121.                                                         ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  2122.                                     if($zoneWiseCovidCharge !== null)
  2123.                                     {
  2124.                                         $demandCharge =  $zoneWiseCovidCharge->getRate() * $rateBookingWeight;  
  2125.                                     
  2126.                                         if($demandCharge 1)
  2127.                                             $salesInvDetailsObj->setVendorCovidCharge(1);
  2128.                                         else
  2129.                                             $salesInvDetailsObj->setVendorCovidCharge($demandCharge);
  2130.                                     }                         
  2131.                                     else
  2132.                                     {
  2133.                                         return new JsonResponse(array('success' => false'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  2134.                                     }
  2135.                                 
  2136.                                 }
  2137.                                 else
  2138.                                 {
  2139.                                     if($rateBookingWeight <= 3)
  2140.                                     {
  2141.                                         $salesInvDetailsObj->setVendorCovidCharge(1);
  2142.                                     }
  2143.                                     else
  2144.                                     {
  2145.                                         $salesInvDetailsObj->setVendorCovidCharge($rateBookingWeight 0.30);
  2146.                                     }
  2147.                                 }
  2148.                             }
  2149.                         }
  2150.                         else
  2151.                         {                            
  2152.                             $salesInvDetailsObj->setVendorCovidCharge(0);
  2153.                         }
  2154.                         //Master Covid Charge Cal End
  2155.                         //Sales Covid Charge Cal Start
  2156.                         if($salesInvDetailsObj->getRateApplicable() <= && $salesInvDetailsObj->getShipment() !== null && !$salesInvDetailsObj->getShipment()->isExpedite())
  2157.                         {
  2158.                             if($courierObj->getCovidChargeApplicable() == && $courierObj->getId() == 1)  // DHL Covid Charge Cal
  2159.                             {
  2160.                             
  2161.                                 // // Demand Charge Start
  2162.                                 // $comparisonDate = new DateTime('2024-09-14');
  2163.                                 // if($salesInvDetailsObj->getShipmentDate() > $comparisonDate)
  2164.                                 // {
  2165.                                 //     $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)
  2166.                                 //                                 ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]); 
  2167.                                     
  2168.                                 //     if($countryWiseCovidCharge !== null)
  2169.                                 //     {                
  2170.                                        
  2171.                                 //         $salesInvDetailsObj->setCovidCharge($countryWiseCovidCharge->getRate() * $rateWeight);  
  2172.                                 //     }
  2173.                                 //     else
  2174.                                 //     {
  2175.                                 //         return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  2176.                                 //     }   
  2177.                                 // }                          
  2178.                                 // // Demand Charge End
  2179.                                 
  2180.                                 // // Go Green Charge Start
  2181.                                 // $comparisonDate = new DateTime('2024-04-01');
  2182.     
  2183.                                 // if ($salesInvDetailsObj->getShipmentDate() < $comparisonDate) {
  2184.                                 //     if($countryObj->getId() == 11 || $countryObj->getId() == 151)
  2185.                                 //     {
  2186.                                 //         $covidChargeUsd = 3.35;
  2187.                                 //     }
  2188.                                 //     else
  2189.                                 //     {
  2190.                                 //         $covidChargeUsd = 1.15;
  2191.                                 //     }
  2192.                                 // } else {
  2193.                                 //     if($countryObj->getId() == 11 || $countryObj->getId() == 151)
  2194.                                 //     {
  2195.                                 //         $covidChargeUsd = 0.56;
  2196.                                 //     }
  2197.                                 //     else
  2198.                                 //     {
  2199.                                 //         $covidChargeUsd = 0.56;
  2200.                                 //     }
  2201.                                 // }
  2202.                                 
  2203.                                 // $salesInvDetailsObj->setCovidCharge($covidChargeUsd * $rateWeight);
  2204.                                 // // Go Green Charge End
  2205.                                                                     
  2206.                             }
  2207.                             else if($courierObj->getCovidChargeApplicable() == && $courierObj->getId() == 2// Fedex Covid Charge Cal
  2208.                             {
  2209.                                 // Demand Charge Start
  2210.                                 $comparisonDate = new DateTime('2024-11-17');
  2211.                                 if($salesInvDetailsObj->getShipmentDate() > $comparisonDate)
  2212.                                 {
  2213.                                     $zoneWiseCovidCharge $entityManager->getRepository(ZoneWiseCovidCharge::class)
  2214.                                                         ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  2215.                                     if($zoneWiseCovidCharge !== null)
  2216.                                     {
  2217.                                         $demandCharge =  $zoneWiseCovidCharge->getRate() * $rateWeight;  
  2218.                                     
  2219.                                         if($demandCharge 1)
  2220.                                             $salesInvDetailsObj->setCovidCharge(1);
  2221.                                         else
  2222.                                             $salesInvDetailsObj->setCovidCharge($demandCharge);
  2223.                                     }                         
  2224.                                     else
  2225.                                     {
  2226.                                         return new JsonResponse(array('success' => false'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  2227.                                     }
  2228.                                 
  2229.                                 }
  2230.                                 else
  2231.                                 {
  2232.                                     if($rateWeight <= 3)
  2233.                                     {
  2234.                                         $salesInvDetailsObj->setCovidCharge(1);
  2235.                                     }
  2236.                                     else
  2237.                                     {
  2238.                                         $salesInvDetailsObj->setCovidCharge($rateWeight 0.30);
  2239.                                     }
  2240.                                 }
  2241.                             
  2242.                             }
  2243.                         }
  2244.                         else
  2245.                         {
  2246.                             $salesInvDetailsObj->setCovidCharge(0);                             
  2247.                         }
  2248.                         //Sales Covid Charge Cal End
  2249.                         
  2250.                         if($salesInvDetailsObj->getShipment() !== null && !$salesInvDetailsObj->getShipment()->isExpedite())
  2251.                         {
  2252.                         
  2253.                             $shipmentDate $salesInvDetailsObj->getShipmentDate();
  2254.             
  2255.                             // Get Settings Currency Start
  2256.                             $settingsObj $settingsInfoRepository
  2257.                                             ->findByDateCurrency(1$shipmentDate->format('Y-m-d')); 
  2258.             
  2259.                             if($settingsObj === null)
  2260.                             {                                
  2261.                                 
  2262.                                 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.'.'));
  2263.                             }                       
  2264.                             // Get Settings Currency End
  2265.             
  2266.                             // Get Vendor FSC Start
  2267.                             $vendorFscObj $settingsInfoRepository
  2268.                                             ->findByDate(2$courierObj->getId(), $shipmentDate->format('Y-m-d')); 
  2269.             
  2270.                             if($vendorFscObj === null)
  2271.                             {                               
  2272.                                 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.'.'));
  2273.                             }                       
  2274.                             // Get Vendor FSC End
  2275.             
  2276.                             // Get Customer FSC Start
  2277.                             $fscObj $settingsInfoRepository
  2278.                                             ->findByDate(2$this->getUser()->getUserCompany()->getCustomerRate() == $courierObj->getId() : $salesCourierId$shipmentDate->format('Y-m-d')); 
  2279.             
  2280.                             if($fscObj === null)
  2281.                             {                                
  2282.                                 
  2283.                                 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.'.'));
  2284.                             }                       
  2285.                             // Get Customer FSC End
  2286.             
  2287.             
  2288.                             if($customerObj->getRateCurrency() == 2)
  2289.                             {
  2290.                                 $salesInvDetailsObj->setCurrency(1);
  2291.                             }
  2292.                             else
  2293.                             {
  2294.                                 $salesInvDetailsObj->setCurrency($customerObj->getCurrency() == $settingsObj->getCurrency() : $customerObj->getCurrency() );
  2295.                             }
  2296.             
  2297.                             $salesInvDetailsObj->setVendorCurrency($courierObj->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  2298.             
  2299.                             if($salesInvDetailsObj->getRateApplicable() <= 2)
  2300.                                 $salesInvDetailsObj->setFsc$customerObj->getFsc() == $fscObj->getCurrency() : $customerObj->getFsc() ); 
  2301.                             else
  2302.                                 $salesInvDetailsObj->setFsc(0); 
  2303.             
  2304.                             if($salesInvDetailsObj->getRateApplicable() <= 3)
  2305.                                 $salesInvDetailsObj->setVendorFsc($vendorFscObj->getCurrency()); 
  2306.                             else
  2307.                                 $salesInvDetailsObj->setVendorFsc(0);
  2308.                         }
  2309.                         else
  2310.                         {
  2311.                             $salesInvDetailsObj->setVendorFsc(0);
  2312.                             $salesInvDetailsObj->setFsc(0); 
  2313.                         }
  2314.                             
  2315.                         $salesInvoice->addSalesInvoiceDetail($salesInvDetailsObj);
  2316.         
  2317.         
  2318.                         // // DHL Go Green Plus Fee Start
  2319.                         // if($row->getCourier()->getId() == 1)
  2320.                         // {
  2321.                         //     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  2322.                         //     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 4)); // 4 for Go Green Plus Fee
  2323.                         //     $invoiceAdditionalChargeObj->setCharge($receivableGoGreen);
  2324.                         //     $invoiceAdditionalChargeObj->setFsc(0);
  2325.                         //     $invoiceAdditionalChargeObj->setVat(0);
  2326.                         //     $invoiceAdditionalChargeObj->setPayableCharge($payableGoGreen);
  2327.                         //     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  2328.                         // }
  2329.                         // // DHL Go Green Plus Fee Start
  2330.                         
  2331.                         
  2332.                         
  2333.                                     
  2334.                         //////////
  2335.                     }
  2336.                     else if($additionalChargeId_array[$index] !== null)
  2337.                     {  
  2338.                         $invoiceAdditionalChargeObj $entityManager->find(InvoiceAdditionalCharge::class, $additionalChargeId_array[$index]);  
  2339.                         $additionalChargeObj $entityManager->find(AdditionalCharge::class, $additionalCharge_array[$index]);       
  2340.                         $invoiceAdditionalChargeObj->setAdditionalCharge($additionalChargeObj);
  2341.                         $invoiceAdditionalChargeObj->setCharge($additionalReceivableAmount_array[$index]);
  2342.                         $invoiceAdditionalChargeObj->setPayableCharge($additionalPayableAmount_array[$index]);
  2343.                         $invoiceAdditionalChargeObj->setFsc($additionalFscApplicable_array[$index]);
  2344.                         $invoiceAdditionalChargeObj->setVat($additionalVatApplicable_array[$index]);
  2345.                         
  2346.                         $salesInvDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  2347.                     }
  2348.                     $index++;
  2349.                 } 
  2350.                 
  2351.                  // Start remove item by Edit
  2352.                  foreach($originalSalesInvoiceDetails as $key=>$salesInvDetails)
  2353.                  {                   
  2354.                      //check if the shaft is in the $project->getShaft()
  2355.                      if($salesInvoice->getSalesInvoiceDetails()->contains($salesInvDetails) === false)
  2356.                      {                        
  2357.                          $entityManager->remove($salesInvDetails);                        
  2358.                      }                  
  2359.                  }  
  2360.                  
  2361.                  $formInvoiceAdditionalCharge = new ArrayCollection();
  2362.  
  2363.                  foreach($salesInvoice->getSalesInvoiceDetails() as $formSid)
  2364.                  {
  2365.                      foreach($formSid->getInvoiceAdditionalCharges() as $key=>$formAcd)
  2366.                      {                       
  2367.                          $formInvoiceAdditionalCharge->add($formAcd);
  2368.                      }
  2369.                  }
  2370.                               
  2371.                  foreach($originalInvoiceAdditionalCharge as $key=>$orInvoiceAdditionalCharge)
  2372.                  {                   
  2373.                      if($formInvoiceAdditionalCharge->contains($orInvoiceAdditionalCharge) === false)
  2374.                      { 
  2375.                          $entityManager->remove($orInvoiceAdditionalCharge);                        
  2376.                      }
  2377.                  }
  2378.                  // End remove item by Edit
  2379.                 
  2380.                 $entityManager->flush();             
  2381.                 $this->addFlash('notice''Invoice Updated successfully!');
  2382.                 
  2383.                 return new JsonResponse(array('success' => true'responseText' =>  'Data Saved successfully' ));                
  2384.             }
  2385.         }
  2386.         return $this->renderForm('sales_invoice/edit.html.twig', [
  2387.             'sales_invoice' => $salesInvoice,
  2388.             'form' => $form,
  2389.             'countryList' => $countryList,
  2390.             'courierList' => $courierList,
  2391.             'productTypeList' => $productTypeList,
  2392.             'additionalChargeList' => $additionalChargeList,
  2393.         ]);
  2394.     }
  2395.     #[Route('/salesinvoice/{id}/delete'name'app_sales_invoice_delete'methods: ['POST'])]
  2396.     #[IsGranted("ROLE_ACCOUNTS")]
  2397.     public function delete(Request $requestSalesInvoice $salesInvoiceSalesInvoiceRepository $salesInvoiceRepository): Response
  2398.     {
  2399.         if ($this->isCsrfTokenValid('delete'.$salesInvoice->getId(), $request->request->get('_token'))) {
  2400.             $salesInvoiceRepository->remove($salesInvoicetrue);
  2401.         }
  2402.         return $this->redirectToRoute('app_sales_invoice_index', [], Response::HTTP_SEE_OTHER);
  2403.     }
  2404.     #[Route('/salesinvoice/{id}/invoice/{currencyType}'name'app_sales_invoice_invoice')]  
  2405.     #[IsGranted("ROLE_ACCOUNTS")]
  2406.     public function invoice(int $idint $currencyTypeReceiveVoucherRepository $receiveVoucherRepositoryShipmentRepository $shipmentRepositorySalesInvoiceRepository $salesInvoiceRepositorySalesInvoiceDetailsRepository $salesInvoiceDetailsRepository)
  2407.     {
  2408.         $salesInvoice $salesInvoiceRepository->findBySingleOrderObj($id);
  2409.             
  2410.         // Configure Dompdf according to your needs
  2411.         $pdfOptions = new Options();
  2412.         $pdfOptions->set('defaultFont''Arial');
  2413.             
  2414.         // Instantiate Dompdf with our options
  2415.         $dompdf = new Dompdf($pdfOptions);
  2416.        
  2417.         $userObj $this->getUser();
  2418.         
  2419.         if($salesInvoice->getCustomer()->getLastReceivedAmount() == 1)
  2420.         {
  2421.             $lastReceivedObj $receiveVoucherRepository->findReceiveVoucherByCustomer($salesInvoice->getCustomer()->getId(), $this->getUser()->getUserCompany()->getId());
  2422.         }
  2423.         else
  2424.         {
  2425.             $lastReceivedObj null;
  2426.         }
  2427.         if($salesInvoice->getCustomer()->getPreviousDuesAmount() == 1)
  2428.         {
  2429.             $duesAmount $shipmentRepository->getCustomerPreviousDuesCalculation($this->getUser()->getUserCompany()->getId(), $salesInvoice->getCustomer()->getId(), 
  2430.             $salesInvoice->getSubmissionDate() ? $salesInvoice->getSubmissionDate()->format('Y-m-d') : $salesInvoice->getInvoiceDate()->format('Y-m-d'),
  2431.             $salesInvoice->getId()
  2432.             );
  2433.             $duesAmount $duesAmount[0];
  2434.            
  2435.             
  2436.         }
  2437.         else
  2438.         {
  2439.             $duesAmount 0;
  2440.         }
  2441.        
  2442.         $groupByCourier $salesInvoiceDetailsRepository->findGroupByCourier($id);
  2443.         
  2444.         $totalReceivedAmount $receiveVoucherRepository->findTotalReceivedAmountBySalesInvoiceId($id$salesInvoice->getInvoiceDate());
  2445.         $totalReceivedAmount $totalReceivedAmount !== null $totalReceivedAmount 0;
  2446.          
  2447.         // Retrieve the HTML generated in our twig file 
  2448.         if($salesInvoice->getRateApplicable() <= 3)
  2449.         {
  2450.             $html $this->renderView('sales_invoice/invoice.html.twig', [
  2451.                 'salesInvoice' => $salesInvoice
  2452.                 'userObj' => $userObj,
  2453.                 'lastReceivedObj' => $lastReceivedObj,
  2454.                 'duesAmount' => $duesAmount,
  2455.                 'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'$userObj->getUserCompany()->getLogoPath() ),         
  2456.                 'currencyType' => $currencyType,
  2457.                 'groupByCourier' => $groupByCourier,
  2458.                 'totalReceivedAmount' => $totalReceivedAmount,
  2459.             ]);
  2460.         }
  2461.         else
  2462.         {
  2463.             $html $this->renderView('sales_invoice/invoice.html.twig', [
  2464.                 'salesInvoice' => $salesInvoice
  2465.                 'userObj' => $userObj,
  2466.                 'lastReceivedObj' => $lastReceivedObj,
  2467.                 'duesAmount' => $duesAmount,
  2468.                 'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'$userObj->getUserCompany()->getLogoPath() ),         
  2469.                 'currencyType' => $currencyType,
  2470.                 'groupByCourier' => $groupByCourier
  2471.                 'totalReceivedAmount' => $totalReceivedAmount,
  2472.             ]);
  2473.         }
  2474.        
  2475.          
  2476.         // Load HTML to Dompdf
  2477.         $dompdf->loadHtml($html);
  2478.         
  2479.         // (Optional) Setup the paper size and orientation 'portrait' or 'landscape'
  2480.         $dompdf->setPaper('A4''portrait');
  2481.         // Render the HTML as PDF
  2482.         $dompdf->render();
  2483.         //  Add Watermark in Domdpf
  2484.         // Instantiate canvas instance 
  2485.         $canvas $dompdf->getCanvas();
  2486.             
  2487.         // Get the number of pages in the PDF
  2488.         $pageCount $canvas->get_page_count();
  2489.         // if($salesInvoice->getApproval() == 0)
  2490.         // {
  2491.         //   $callback = function ($pageNumber) use ($pageCount, $pdfOptions, $canvas) {
  2492.         //     // Set text opacity 
  2493.         //     $canvas->set_opacity(0.2, 'Multiply');   
  2494.         //     // Instantiate font metrics class 
  2495.         //     $fontMetrics = new FontMetrics($canvas, $pdfOptions);
  2496.         //     // Get height and width of page 
  2497.         //     $w = $canvas->get_width(); 
  2498.         //     $h = $canvas->get_height(); 
  2499.             
  2500.         //     // Get font family file 
  2501.         //     $font = $fontMetrics->getFont('times'); 
  2502.             
  2503.         //     // Specify watermark text 
  2504.         //     $text = "DRAFT"; 
  2505.             
  2506.         //     // Get height and width of text 
  2507.         //     $txtHeight = $fontMetrics->getFontHeight($font, 75); 
  2508.         //     $textWidth = $fontMetrics->getTextWidth($text, $font, 75); 
  2509.                         
  2510.         //     // Specify horizontal and vertical position 
  2511.         //     $x = (($w-$textWidth)/2); 
  2512.         //     $y = (($h-$txtHeight)/2); 
  2513.             
  2514.         //     // Writes text at the specified x and y coordinates 
  2515.         //     $canvas->text($x, $y, $text, $font, 75, array(0, 0, 0), 0, 'B');       
  2516.         //     };
  2517.         //     // Add the callback function to each page
  2518.         //     for ($i = 0; $i < $pageCount; $i++) {        
  2519.         //         $canvas->page_script($callback);        
  2520.         //     }
  2521.         // }
  2522.         
  2523.         // Page number and total page count Start
  2524.         // Define the callback function to add the page number and total page count
  2525.         $callback2 = function ($pageNumber) use ($pageCount$canvas) {
  2526.             // Set text opacity             
  2527.             $canvas->set_opacity(0.9'Multiply');
  2528.             // Set the text and position for page number and total page count
  2529.             $text 'Page ' $pageNumber ' of ' $pageCount;
  2530.             $x 530// X-coordinate position
  2531.             $y 813// Y-coordinate position
  2532.         
  2533.             // Add the page number and total page count to the current page
  2534.             $canvas->text($x$y$textnull10);
  2535.         };
  2536.        
  2537.         // Add the callback function to each page
  2538.         for ($i 0$i $pageCount$i++) {              
  2539.             $canvas->page_script($callback2);        
  2540.         }
  2541.         // Output the generated PDF to Browser (force download)
  2542.         $dompdf->stream("Invoice_".$salesInvoice->getInvoiceNo().".pdf", [
  2543.             "Attachment" => false
  2544.         ]);
  2545.         exit(0);
  2546.     
  2547.     }
  2548.     #[Route('/salesinvoice/{id}/master-invoice'name'app_sales_invoice_master_invoice')]  
  2549.     #[IsGranted("ROLE_ACCOUNTS")]
  2550.     public function masterInvoice(int $idSalesInvoiceRepository $salesInvoiceRepository,  ReceiveVoucherRepository $receiveVoucherRepository)
  2551.     {
  2552.         $salesInvoice $salesInvoiceRepository->findBySingleOrderObj($id);
  2553.         
  2554.         // Configure Dompdf according to your needs
  2555.         $pdfOptions = new Options();
  2556.         $pdfOptions->set('defaultFont''Arial');
  2557.             
  2558.         // Instantiate Dompdf with our options
  2559.         $dompdf = new Dompdf($pdfOptions);
  2560.        
  2561.         $userObj $this->getUser();
  2562.         
  2563.         if($salesInvoice->getCustomer()->getLastReceivedAmount() == 1)
  2564.         {
  2565.             $lastReceivedObj $receiveVoucherRepository->findReceiveVoucherByCustomer($salesInvoice->getCustomer()->getId(), $this->getUser()->getUserCompany()->getId());
  2566.         }
  2567.         else
  2568.         {
  2569.             $lastReceivedObj null;
  2570.         }
  2571.                    
  2572.         // Retrieve the HTML generated in our twig file 
  2573.         if($salesInvoice->getRateApplicable() <= 2)
  2574.         {
  2575.             $html $this->renderView('sales_invoice/masterInvoice.html.twig', [
  2576.                 'salesInvoice' => $salesInvoice
  2577.                 'userObj' => $userObj,
  2578.                 'lastReceivedObj' => $lastReceivedObj,
  2579.                 'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'$userObj->getUserCompany()->getLogoPath() ),         
  2580.             ]);
  2581.         }
  2582.         else
  2583.         {
  2584.             $html $this->renderView('sales_invoice/calculatedInvoice.html.twig', [
  2585.                 'salesInvoice' => $salesInvoice
  2586.                 'userObj' => $userObj,
  2587.                 'lastReceivedObj' => $lastReceivedObj,
  2588.                 'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'$userObj->getUserCompany()->getLogoPath() ),         
  2589.             ]);
  2590.         }
  2591.        
  2592.          
  2593.         // Load HTML to Dompdf
  2594.         $dompdf->loadHtml($html);
  2595.         
  2596.         // (Optional) Setup the paper size and orientation 'portrait' or 'landscape'
  2597.         $dompdf->setPaper('A4''portrait');
  2598.         // Render the HTML as PDF
  2599.         $dompdf->render();
  2600.         //  Add Watermark in Domdpf
  2601.         // Instantiate canvas instance 
  2602.         $canvas $dompdf->getCanvas();
  2603.             
  2604.         // Get the number of pages in the PDF
  2605.         $pageCount $canvas->get_page_count();
  2606.         if($salesInvoice->getApproval() == 0)
  2607.         {
  2608.             $callback = function ($pageNumber) use ($pageCount$pdfOptions$canvas) {
  2609.                 // Set text opacity 
  2610.                 $canvas->set_opacity(0.2'Multiply');   
  2611.                 // Instantiate font metrics class 
  2612.                 $fontMetrics = new FontMetrics($canvas$pdfOptions);
  2613.                 // Get height and width of page 
  2614.                 $w $canvas->get_width(); 
  2615.                 $h $canvas->get_height(); 
  2616.                 
  2617.                 // Get font family file 
  2618.                 $font $fontMetrics->getFont('times'); 
  2619.                 
  2620.                 // Specify watermark text 
  2621.                 $text "DRAFT"
  2622.                 
  2623.                 // Get height and width of text 
  2624.                 $txtHeight $fontMetrics->getFontHeight($font75); 
  2625.                 $textWidth $fontMetrics->getTextWidth($text$font75); 
  2626.                             
  2627.                 // Specify horizontal and vertical position 
  2628.                 $x = (($w-$textWidth)/2); 
  2629.                 $y = (($h-$txtHeight)/2); 
  2630.                 
  2631.                 // Writes text at the specified x and y coordinates 
  2632.                 $canvas->text($x$y$text$font75, array(000), 0'B');       
  2633.             };
  2634.             // Add the callback function to each page
  2635.             for ($i 0$i $pageCount$i++) {        
  2636.                 $canvas->page_script($callback);        
  2637.             }
  2638.         }
  2639.         
  2640.         // Page number and total page count Start
  2641.         // Define the callback function to add the page number and total page count
  2642.         $callback2 = function ($pageNumber) use ($pageCount$canvas) {
  2643.             // Set text opacity             
  2644.             $canvas->set_opacity(0.9'Multiply');
  2645.             // Set the text and position for page number and total page count
  2646.             $text 'Page ' $pageNumber ' of ' $pageCount;
  2647.             $x 530// X-coordinate position
  2648.             $y 820// Y-coordinate position
  2649.         
  2650.             // Add the page number and total page count to the current page
  2651.             $canvas->text($x$y$textnull10);
  2652.         };
  2653.        
  2654.         // Add the callback function to each page
  2655.         for ($i 0$i $pageCount$i++) {        
  2656.             $canvas->page_script($callback2);        
  2657.         }
  2658.         // Output the generated PDF to Browser (force download)
  2659.         $dompdf->stream("Invoice_".$salesInvoice->getInvoiceNo().".pdf", [
  2660.             "Attachment" => false
  2661.         ]);
  2662.         exit(0);
  2663.     
  2664.     }
  2665.     
  2666.     #[Route('/salesinvoice/{id}/master-weight-sales-rate/{currencyType}'name'app_sales_invoice_masterWeightSalesRate')]  
  2667.     #[IsGranted("ROLE_ACCOUNTS")]
  2668.     public function masterWeightSalesRateinvoice(int $idint $currencyTypeReceiveVoucherRepository $receiveVoucherRepositoryShipmentRepository $shipmentRepositorySalesInvoiceRepository $salesInvoiceRepositorySalesInvoiceDetailsRepository $salesInvoiceDetailsRepository)
  2669.     {
  2670.         $salesInvoice $salesInvoiceRepository->findBySingleOrderObj($id);
  2671.             
  2672.         // Configure Dompdf according to your needs
  2673.         $pdfOptions = new Options();
  2674.         $pdfOptions->set('defaultFont''Arial');
  2675.             
  2676.         // Instantiate Dompdf with our options
  2677.         $dompdf = new Dompdf($pdfOptions);
  2678.        
  2679.         $userObj $this->getUser();
  2680.         
  2681.         if($salesInvoice->getCustomer()->getLastReceivedAmount() == 1)
  2682.         {
  2683.             $lastReceivedObj $receiveVoucherRepository->findReceiveVoucherByCustomer($salesInvoice->getCustomer()->getId(), $this->getUser()->getUserCompany()->getId());
  2684.         }
  2685.         else
  2686.         {
  2687.             $lastReceivedObj null;
  2688.         }
  2689.         if($salesInvoice->getCustomer()->getPreviousDuesAmount() == 1)
  2690.         {
  2691.             $duesAmount $shipmentRepository->getCustomerWiseCreditLimitCalculation($salesInvoice->getCustomer()->getId());
  2692.             $duesAmount $duesAmount[0];
  2693.         }
  2694.         else
  2695.         {
  2696.             $duesAmount 0;
  2697.         }
  2698.         $groupByCourier $salesInvoiceDetailsRepository->findGroupByCourier($id);
  2699.        
  2700.         // Retrieve the HTML generated in our twig file 
  2701.         if($salesInvoice->getRateApplicable() <= 3)
  2702.         {
  2703.             $html $this->renderView('sales_invoice/masterWeightSalesRateinvoice.html.twig', [
  2704.                 'salesInvoice' => $salesInvoice
  2705.                 'userObj' => $userObj,
  2706.                 'lastReceivedObj' => $lastReceivedObj,
  2707.                 'duesAmount' => $duesAmount,
  2708.                 'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'$userObj->getUserCompany()->getLogoPath() ),         
  2709.                 'currencyType' => $currencyType,
  2710.                 'groupByCourier' => $groupByCourier,
  2711.             ]);
  2712.         }
  2713.         else
  2714.         {
  2715.             $html $this->renderView('sales_invoice/masterWeightSalesRateinvoice.html.twig', [
  2716.                 'salesInvoice' => $salesInvoice
  2717.                 'userObj' => $userObj,
  2718.                 'lastReceivedObj' => $lastReceivedObj,
  2719.                 'duesAmount' => $duesAmount,
  2720.                 'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'$userObj->getUserCompany()->getLogoPath() ),         
  2721.             ]);
  2722.         }
  2723.        
  2724.          
  2725.         // Load HTML to Dompdf
  2726.         $dompdf->loadHtml($html);
  2727.         
  2728.         // (Optional) Setup the paper size and orientation 'portrait' or 'landscape'
  2729.         $dompdf->setPaper('A4''portrait');
  2730.         // Render the HTML as PDF
  2731.         $dompdf->render();
  2732.         //  Add Watermark in Domdpf
  2733.         // Instantiate canvas instance 
  2734.         $canvas $dompdf->getCanvas();
  2735.             
  2736.         // Get the number of pages in the PDF
  2737.         $pageCount $canvas->get_page_count();
  2738.         // if($salesInvoice->getApproval() == 0)
  2739.         // {
  2740.         //     $callback = function ($pageNumber) use ($pageCount, $pdfOptions, $canvas) {
  2741.         //         // Set text opacity 
  2742.         //         $canvas->set_opacity(0.2, 'Multiply');   
  2743.         //         // Instantiate font metrics class 
  2744.         //         $fontMetrics = new FontMetrics($canvas, $pdfOptions);
  2745.         //         // Get height and width of page 
  2746.         //         $w = $canvas->get_width(); 
  2747.         //         $h = $canvas->get_height(); 
  2748.                 
  2749.         //         // Get font family file 
  2750.         //         $font = $fontMetrics->getFont('times'); 
  2751.                 
  2752.         //         // Specify watermark text 
  2753.         //         $text = "DRAFT"; 
  2754.                 
  2755.         //         // Get height and width of text 
  2756.         //         $txtHeight = $fontMetrics->getFontHeight($font, 75); 
  2757.         //         $textWidth = $fontMetrics->getTextWidth($text, $font, 75); 
  2758.                             
  2759.         //         // Specify horizontal and vertical position 
  2760.         //         $x = (($w-$textWidth)/2); 
  2761.         //         $y = (($h-$txtHeight)/2); 
  2762.                 
  2763.         //         // Writes text at the specified x and y coordinates 
  2764.         //         $canvas->text($x, $y, $text, $font, 75, array(0, 0, 0), 0, 'B');       
  2765.         //     };
  2766.         //     // Add the callback function to each page
  2767.         //     for ($i = 0; $i < $pageCount; $i++) {        
  2768.         //         $canvas->page_script($callback);        
  2769.         //     }
  2770.         // }
  2771.         
  2772.         // Page number and total page count Start
  2773.         // Define the callback function to add the page number and total page count
  2774.         $callback2 = function ($pageNumber) use ($pageCount$canvas) {
  2775.             // Set text opacity             
  2776.             $canvas->set_opacity(0.9'Multiply');
  2777.             // Set the text and position for page number and total page count
  2778.             $text 'Page ' $pageNumber ' of ' $pageCount;
  2779.             $x 530// X-coordinate position
  2780.             $y 813// Y-coordinate position
  2781.         
  2782.             // Add the page number and total page count to the current page
  2783.             $canvas->text($x$y$textnull10);
  2784.         };
  2785.        
  2786.         // Add the callback function to each page
  2787.         for ($i 0$i $pageCount$i++) {              
  2788.             $canvas->page_script($callback2);        
  2789.         }
  2790.         // Output the generated PDF to Browser (force download)
  2791.         $dompdf->stream("Invoice_".$salesInvoice->getInvoiceNo().".pdf", [
  2792.             "Attachment" => false
  2793.         ]);
  2794.         exit(0);
  2795.     
  2796.     }
  2797.     #[Route('/salesinvoice/datewiseinvoice'name'app_sales_invoice_datewiseinvoice'methods: ['GET''POST'])]
  2798.     public function datewiseinvoice(Request $requestEntityManagerInterface $entityManager): Response
  2799.     {      
  2800.         $invoiceId $request->request->get('modal-salesinvocie-id');
  2801.         $fromDate $request->request->get('modal-from-date');
  2802.         $toDate $request->request->get('modal-to-date');
  2803.         
  2804.         $salesInvoice $entityManager->find(SalesInvoice::class, $invoiceId);
  2805.         $salesInvoice->getSalesInvoiceDetails()->clear();
  2806.         $salesInvoiceDetailsList $entityManager->getRepository(SalesInvoiceDetails::class)->salesInvDetailsListDateWise($invoiceId$fromDate$toDate);
  2807.         
  2808.         foreach($salesInvoiceDetailsList as $salesInvoiceDetails)
  2809.         {
  2810.             $salesInvoice->addSalesInvoiceDetail($salesInvoiceDetails);
  2811.         }
  2812.         // Configure Dompdf according to your needs
  2813.         $pdfOptions = new Options();
  2814.         $pdfOptions->set('defaultFont''Arial');
  2815.             
  2816.         // Instantiate Dompdf with our options
  2817.         $dompdf = new Dompdf($pdfOptions);
  2818.         $userObj $this->getUser();
  2819.         
  2820.         // Retrieve the HTML generated in our twig file 
  2821.         if($salesInvoice->getRateApplicable() <= 2)
  2822.         {
  2823.             $html $this->renderView('sales_invoice/invoice.html.twig', [
  2824.                 'salesInvoice' => $salesInvoice
  2825.                 'userObj' => $userObj,
  2826.                 'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'$userObj->getUserCompany()->getLogoPath() ),         
  2827.             ]);
  2828.         }
  2829.         else
  2830.         {
  2831.             $html $this->renderView('sales_invoice/calculatedInvoice.html.twig', [
  2832.                 'salesInvoice' => $salesInvoice
  2833.                 'userObj' => $userObj,
  2834.                 'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'$userObj->getUserCompany()->getLogoPath() ),         
  2835.             ]);
  2836.         }
  2837.     
  2838.         
  2839.         // Load HTML to Dompdf
  2840.         $dompdf->loadHtml($html);
  2841.         
  2842.         // (Optional) Setup the paper size and orientation 'portrait' or 'landscape'
  2843.         $dompdf->setPaper('A4''portrait');
  2844.         // Render the HTML as PDF
  2845.         $dompdf->render();
  2846.         
  2847.         // Output the generated PDF to Browser (force download)
  2848.         $dompdf->stream("Invoice.pdf", [
  2849.             "Attachment" => false,
  2850.         ]);
  2851.              
  2852.     }
  2853.     #[Route('/salesinvoice/datewisedataupdate'name'app_sales_invoice_datewisedataupdate'methods: ['GET''POST'])]
  2854.     public function datewisedataupdate(Request $requestEntityManagerInterface $entityManager): Response
  2855.     {      
  2856.         $invoiceId $request->request->get('modal-salesinvocie-id');
  2857.         $fromDate $request->request->get('modal-from-date');
  2858.         $toDate $request->request->get('modal-to-date');
  2859.         $courier $request->request->get('modal-courier');
  2860.         $fsc $request->request->get('modal-fsc');
  2861.         $currency $request->request->get('modal-currency');
  2862.         $applicable $request->request->get('modal-applicable');
  2863.        
  2864.         $salesInvoiceDetailsList $entityManager->getRepository(SalesInvoiceDetails::class)
  2865.                                     ->salesInvDetailsListCourierAndDateWise($invoiceId$fromDate$toDate$courier);
  2866.         
  2867.         foreach($salesInvoiceDetailsList as $salesInvoiceDetails)
  2868.         {
  2869.             if($applicable == 1)
  2870.             {
  2871.                 $salesInvoiceDetails->setFsc($fsc);
  2872.                 $salesInvoiceDetails->setCurrency($currency);
  2873.             }
  2874.             else if($applicable == 2)
  2875.             {
  2876.                 $salesInvoiceDetails->setVendorFsc($fsc);
  2877.                 $salesInvoiceDetails->setVendorCurrency($currency);
  2878.             }
  2879.             else
  2880.             {
  2881.                 $salesInvoiceDetails->setFsc($fsc);
  2882.                 $salesInvoiceDetails->setCurrency($currency);
  2883.                 $salesInvoiceDetails->setVendorFsc($fsc);
  2884.                 $salesInvoiceDetails->setVendorCurrency($currency);
  2885.             }
  2886.             $entityManager->persist($salesInvoiceDetails);
  2887.             $entityManager->flush($salesInvoiceDetails); 
  2888.             
  2889.         }
  2890.         return $this->redirectToRoute('app_sales_invoice_show', ['id' => $invoiceId]);              
  2891.     }
  2892.     #[Route('/salesinvoice/principle-invoice-checking'name'app_sales_invoice_principle_invocie_checking'methods: ['GET''POST'])]
  2893.     #[IsGranted("ROLE_ACCOUNTS")]
  2894.     public function principleInvoiceChecking(Request $requestSluggerInterface $sluggerSalesInvoiceDetailsRepository $salesInvoiceDetailsRepository): Response
  2895.     {
  2896.         $form $this->createFormBuilder(null)
  2897.             ->add('file'FileType::class, [
  2898.             'label' => 'Upload Principle Invoice Excel File ',
  2899.             // unmapped means that this field is not associated to any entity property
  2900.             'mapped' => false,
  2901.             'attr' => [
  2902.                 'class' => 'form-control select-tags',
  2903.                 ],
  2904.             // make it optional so you don't have to re-upload the PDF file
  2905.             // every time you edit the Product details
  2906.             //'required' => false,
  2907.             // unmapped fields can't define their validation using annotations
  2908.             // in the associated entity, so you can use the PHP constraint classes
  2909.             'constraints' => [
  2910.                 new File([
  2911.                     'maxSize' => '1024k',
  2912.                     'mimeTypes' => [         
  2913.                         'application/vnd.ms-excel',              
  2914.                         'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',                                              
  2915.                     ],
  2916.                     'mimeTypesMessage' => 'Please upload a valid Excel (.xlsx / .xls) file',
  2917.                 ])
  2918.             ],
  2919.         ])
  2920.         ->add('courier'EntityType::class, [
  2921.             // looks for choices from this entity
  2922.             'class' => Courier::class,
  2923.             'query_builder' => function (CourierRepository $er) {
  2924.                 return $er->createQueryBuilder('v')                       
  2925.                     ->orderBy('v.name''ASC');
  2926.             },                
  2927.             // uses the User.username property as the visible option string
  2928.             'choice_label' => 'name',
  2929.             'placeholder' => 'Select a Courier...',
  2930.             'attr' => [
  2931.                 'class' => 'form-control select-tags',
  2932.                 'style' => 'width:100%;',
  2933.                 ],
  2934.             'label' => 'Courier',
  2935.             // used to render a select box, check boxes or radios
  2936.             // 'multiple' => true,
  2937.             // 'expanded' => true,
  2938.             ])
  2939.         ->add('fromDate'DateType::class, [
  2940.             'attr' => ['class' => 'form-control'],
  2941.             'widget' => 'single_text',
  2942.             'empty_data' => null,                         
  2943.             ])
  2944.         ->add('toDate'DateType::class, [
  2945.             'attr' => ['class' => 'form-control'],
  2946.             'widget' => 'single_text',
  2947.             'empty_data' => null,                            
  2948.             ]) 
  2949.               
  2950.         ->getForm();
  2951.        $form->handleRequest($request);
  2952.         if ($form->isSubmitted() && $form->isValid()) {
  2953.             $data $form->getData();                     
  2954.             $formDate =  $form->get('fromDate')->getData()->format('Y-m-d'); 
  2955.             $toDate =  $form->get('toDate')->getData()->format('Y-m-d');    
  2956.             $courier $form->get('courier')->getData();      
  2957.             
  2958.             /* @var UploadedFile document start */
  2959.             $docFile $form->get('file')->getData();
  2960.             // this condition is needed because the 'brochure' field is not required
  2961.             // so the PDF file must be processed only when a file is uploaded
  2962.             if ($docFile) {
  2963.                 $originalFilename pathinfo($docFile->getClientOriginalName(), PATHINFO_FILENAME);
  2964.                 // this is needed to safely include the file name as part of the URL
  2965.                 $safeFilename $slugger->slug($originalFilename);
  2966.                 $newFilename $safeFilename.'-'.uniqid().'.'.$docFile->guessExtension();
  2967.                 // Move the file to the directory where brochures are stored
  2968.                 try {
  2969.                     $docFile->move(
  2970.                         $this->getParameter('filedocument_directory'),
  2971.                         $newFilename
  2972.                     );
  2973.                 } catch (FileException $e) {
  2974.                     // ... handle exception if something happens during file upload
  2975.                 }
  2976.                 // updates the 'brochureFilename' property to store the PDF file name
  2977.                 // instead of its contents
  2978.                 //$assetregister->setDocpath($newFilename);
  2979.             }
  2980.             /* @var UploadedFile document end */
  2981.            
  2982.             /* Excel file read from upload directory Start */
  2983.             // Here we are able to read from the excel file 
  2984.             $spreadsheet IOFactory::load($this->getParameter('filedocument_directory').'/'.$newFilename);
  2985.    
  2986.             // I added this to be able to remove the first file line 
  2987.             $row $spreadsheet->getActiveSheet()->removeRow(1); 
  2988.             $maxCell $spreadsheet->getActiveSheet()->getHighestRowAndColumn();
  2989.            // dd($maxCell);
  2990.            // dd('A1:' . $maxCell['column'] . $maxCell['row']);
  2991.            // here, the read data is turned into an array
  2992.             $sheetData $spreadsheet->getActiveSheet()->rangeToArray('A1:A' $maxCell['row']);
  2993.            // dump($sheetData);
  2994.           
  2995.             $salesInvoiceDetails $salesInvoiceDetailsRepository->principleInvoiceChecking($formDate$toDate$courier->getId(), $this->getUser()->getUserCompany()->getId()); 
  2996.             //dd($salesInvoiceDetails);
  2997.              
  2998.         //     $salesInvoiceDetailsforFalse = array_filter($salesInvoiceDetails, function($item) {
  2999.         //         return $item['principalBill'] === false;
  3000.         //     }); 
  3001.             
  3002.         //   // dd($salesInvoiceDetailsforFalse);
  3003.             
  3004.         //     $salesInvoiceDetailsforTrue = array_filter($salesInvoiceDetails, function($item) {
  3005.         //         return $item['principalBill'] === true;
  3006.         //     }); 
  3007.             
  3008.         //     dd($salesInvoiceDetailsforTrue);
  3009.             // Flatten the first array
  3010.             $flattenedSheetData array_map(function($item) {
  3011.                 return str_replace(' '''$item[0]);
  3012.             }, $sheetData);
  3013.  
  3014.             // Flatten the second array
  3015.             $flattenedSalesInvoiceDetails array_map(function($item) {
  3016.                 return str_replace(' '''$item["hawbNo"]);
  3017.             }, $salesInvoiceDetails);
  3018.             // Elements in $flattenedSheetData but not in $flattenedSalesInvoiceDetails
  3019.             $missingBillCustomer array_diff($flattenedSheetData$flattenedSalesInvoiceDetails);
  3020.             $extraBillCustomer array_diff($flattenedSalesInvoiceDetails$flattenedSheetData);
  3021.             // dump($flattenedSheetData);
  3022.             // dump($flattenedSalesInvoiceDetails);
  3023.             // dump($missingBillCustomer);
  3024.             // dd($extraBillCustomer);
  3025.           
  3026.            // $this->addFlash('notice', 'Country Created successfully!');
  3027.             return $this->render('sales_invoice/principleInvoiceCheckingResult.html.twig', [
  3028.                 'missing_bill_customer' => $missingBillCustomer,
  3029.                 'sheet_data_count' => count($flattenedSheetData),
  3030.                 'extra_bill_customer' => $extraBillCustomer,        
  3031.                 'sales_invoice_count' =>  count($flattenedSalesInvoiceDetails),    
  3032.                 'courier' => $courier
  3033.             ]);
  3034.             
  3035.         }
  3036.         return $this->renderForm('sales_invoice/principleInvoiceChecking.html.twig', [        
  3037.             'form' => $form,
  3038.         ]);
  3039.     }
  3040.     #[Route('/salesinvoice/shipmenttoinvoice'name'app_sales_invoice_shipmentto_invoice'methods: ['GET''POST'])]
  3041.     #[IsGranted("ROLE_ACCOUNTS")]
  3042.     public function shipmenttoinvoice(Request $requestShipmentRepository $shipmentRepositoryCourierRepository $courierRepositoryCountryRepository $countryRepositoryCustomerRepository $customerRepositoryProductTypeRepository $productTypeRepository)
  3043.     {
  3044.         $form $this->createFormBuilder(null)           
  3045.             ->add('fromDate'DateType::class, [
  3046.                 'attr' => ['class' => 'form-control'],
  3047.                 'widget' => 'single_text',
  3048.                 'empty_data' => null,
  3049.                 'label' => 'From Shipment Date',            
  3050.                 ])      
  3051.             ->add('toDate'DateType::class, [
  3052.                 'attr' => ['class' => 'form-control'],
  3053.                 'widget' => 'single_text',
  3054.                 'empty_data' => null,
  3055.                 'label' => 'To Shipment Date',                
  3056.                 ])
  3057.             ->add('customer',TextType::class, [       
  3058.                 'attr' => ['class' => 'form-control'],
  3059.                 'label' => 'Customer',
  3060.                 'required' => false,
  3061.             ])
  3062.             ->add('hawbno',TextType::class, [       
  3063.                 'attr' => ['class' => 'form-control'],
  3064.                 'label' => 'Hawb No',
  3065.                 'required' => false,
  3066.             ])
  3067.         ->getForm();
  3068.  
  3069.         $form->handleRequest($request); 
  3070.                     
  3071.         if ($form->isSubmitted() && $form->isValid()) {
  3072.             $data $form->getData();                     
  3073.             $formDate =  $form->get('fromDate')->getData()->format('Y-m-d'); 
  3074.             $toDate =  $form->get('toDate')->getData()->format('Y-m-d');    
  3075.             $customer $form->get('customer')->getData();      
  3076.             $hawbNO $form->get('hawbno')->getData();
  3077.             $viewTag 0;
  3078.            
  3079.             $shipmentList $shipmentRepository->findShipmentByDateforInvoice($formDate$toDate$customer$hawbNO$this->getUser()->getUserCompany()->getId());
  3080.            
  3081.             foreach($shipmentList as $row)
  3082.             {
  3083.                 if($row->getCustomer()->getRateType() > || $row->isExpedite() || $row->getPaymentOptions()->getId() == 2)
  3084.                 {
  3085.                     $viewTag 1;
  3086.                     break;
  3087.                 }
  3088.                 
  3089.             }
  3090.             $courierList $courierRepository->findBy(['userCompany' => $this->getUser()->getUserCompany()->getId() ]);
  3091.             $countryList $countryRepository->findAll();
  3092.             $customerList $customerRepository->findBy(['userCompany' => $this->getUser()->getUserCompany()->getId() ]);
  3093.             $productTypeList $productTypeRepository->findBy(['type' => 2]);
  3094.             
  3095.             return $this->render('sales_invoice/shipmenttoinvoice.html.twig', [
  3096.                 'form' => $form->createView(),
  3097.                 'bookingList' => $shipmentList,    
  3098.                 'courierList' => $courierList,
  3099.                 'countryList' => $countryList,
  3100.                 'customerList' => $customerList,
  3101.                 'productTypeList' => $productTypeList,         
  3102.                 'track' => 1,
  3103.                 'viewTag' => $viewTag,
  3104.             ]);
  3105.         }
  3106.         $bookingObj = new SalesInvoiceDetails();
  3107.         
  3108.         return $this->render('sales_invoice/shipmenttoinvoice.html.twig', [
  3109.             'form' => $form->createView(),
  3110.             'bookingList' => $bookingObj,            
  3111.             'track' => 0,
  3112.         ]);
  3113.     }
  3114.  
  3115.     #[Route('/salesinvoice/shipmenttoinvoicepost'name'app_sales_invoice_shipmentto_invoice_post'methods: ['GET''POST'])]
  3116.     #[IsGranted("ROLE_ACCOUNTS")]
  3117.     public function shipmenttoinvoicepost(Request $requestEntityManagerInterface $entityManagerUtilsService $utilsServiceShipmentRepository $shipmentRepositoryCourierRepository $courierRepositoryCountryRepository $countryRepositoryCustomerRepository $customerRepositoryProductTypeRepository $productTypeRepositorySettingsInfoRepository $settingsInfoRepositorySalesInvoiceRepository $salesInvoiceRepository)
  3118.     {
  3119.         if ($request->isXMLHttpRequest()) 
  3120.         {
  3121.             $hawbNo $request->request->get('hawbNo');            
  3122.             if (!empty($hawbNo)) 
  3123.             {
  3124.                 $hawbNo_array json_decode($hawbNotrue);
  3125.                // return new JsonResponse(array('success' => false, 'responseText' =>  $hawbNo_array ));
  3126.                 $hawbNo_array json_decode($request->request->get('hawbNo')); 
  3127.                 $shipmentDate_array json_decode($request->request->get('shipmentDate'));
  3128.                 $reference_array json_decode($request->request->get('reference'));
  3129.                 $country_array json_decode($request->request->get('country'));
  3130.                 $customer_array json_decode($request->request->get('customer'));
  3131.                 $courier_array json_decode($request->request->get('courier'));
  3132.                 $productType_array json_decode($request->request->get('productType'));
  3133.                 $weight_array json_decode($request->request->get('weight'));
  3134.                 $bookingWeight_array json_decode($request->request->get('bookingWeight'));
  3135.                 $shipmentId_array json_decode($request->request->get('shipmentId'));
  3136.                 $vatApplicable_array json_decode($request->request->get('vatApplicable'));
  3137.                 $salesRate_array json_decode($request->request->get('billingWeight'));
  3138.                 $salesInvoiceDetailsList = new ArrayCollection();
  3139.                 
  3140.                 $index 0;               
  3141.                 foreach($hawbNo_array as $key=>$Row
  3142.                 {
  3143.                     $keyValue $key;
  3144.                     $keyValue $keyValue 1;
  3145.                     
  3146.                     $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  3147.                     
  3148.                     $salesInvoiceDetObj $entityManager->getRepository(SalesInvoiceDetails::class)
  3149.                                                         ->findOneBy(['hawbNo' => $hawbNo_array[$index]]);                              
  3150.                     if($salesInvoiceDetObj !== null)
  3151.                     {
  3152.                         return new JsonResponse(array('success' => false'responseText' => 'Duplicate HAWB Number : '$hawbNo_array[$index].' in Row Number '.$keyValue.'.'));
  3153.                     }
  3154.                     
  3155.                     $salesInvoiceDetailsObj->setShipmentDate(new \DateTime($shipmentDate_array[$index]));
  3156.                     $salesInvoiceDetailsObj->setHawbNo($hawbNo_array[$index]);
  3157.                     $salesInvoiceDetailsObj->setReference($reference_array[$index]);
  3158.                     $countryObj $entityManager->find(Country::class, $country_array[$index]);                  
  3159.                     $salesInvoiceDetailsObj->setCountry($countryObj);
  3160.                     $courierObj $entityManager->find(Courier::class, $courier_array[$index]);                
  3161.                     $salesInvoiceDetailsObj->setCourier($courierObj);
  3162.                     
  3163.                     // Rate Type get Start Here getRateType()
  3164.                     if($courierObj->getZoneRateType() !== null)
  3165.                         $zoneWiseMasterRateTypeObj $entityManager->find(ZoneWiseMasterRate::class, $courierObj->getZoneRateType());
  3166.                     else 
  3167.                         $zoneWiseMasterRateTypeObj = new ZoneWiseMasterRate();
  3168.                     // Rate Type get End Here
  3169.                     
  3170.                     $productTypeObj $entityManager->find(ProductType::class, $productType_array[$index]);                 
  3171.                     $salesInvoiceDetailsObj->setProductType($productTypeObj);
  3172.                     $customerObj $entityManager->find(Customer::class, $customer_array[$index]);                 
  3173.                     $salesInvoiceDetailsObj->setCustomer($customerObj);
  3174.                     $salesInvoiceDetailsObj->setWeight($weight_array[$index]);
  3175.                     $salesInvoiceDetailsObj->setBookingWeight($bookingWeight_array[$index]);
  3176.                        
  3177.                     $shipmentObj $entityManager->find(Shipment::class, $shipmentId_array[$index]);    
  3178.                     $salesInvoiceDetailsObj->setShipment($shipmentObj);
  3179.                     $salesInvoiceDetailsObj->setVatApplicable($vatApplicable_array[$index]);
  3180.                     $salesInvoiceDetailsObj->setVendorVatApplicable($vatApplicable_array[$index]);
  3181.                     if($salesInvoiceDetailsObj->getShipment()->isExpedite())
  3182.                     {
  3183.                         $rateApplicableId 5;  // Expedite Rate Type 5 
  3184.                     }
  3185.                     else if ($shipmentObj->getPaymentOptions()->getId() == )
  3186.                     {
  3187.                         $rateApplicableId 3// Manually Tariff Rate($) 3
  3188.                     }
  3189.                     else
  3190.                     {
  3191.                         $rateApplicableId $customerObj->getRateType();  
  3192.                     }
  3193.                     $salesInvoiceDetailsObj->setRateApplicable($rateApplicableId);    
  3194.                     // return new JsonResponse(array('success' => false, 'responseText' => $salesInvoiceObj_array['InvoiceApplicable']  ));
  3195.                     // $salesInvoiceDetailsObj->setInvoiceStatus($salesInvoiceObj_array['InvoiceApplicable']);
  3196.                                     
  3197.                     //Zone Assign Start  $shipmentId_array
  3198.                     //    if($courier_array[$index] < 0)
  3199.                         //    {
  3200.                             $courierWiseZoneObj $entityManager->getRepository(CourierWiseZone::class)
  3201.                                                                 ->findOneBy(['courier' => $courier_array[$index], 'country' => $country_array[$index] ]);                       
  3202.                             if($courierWiseZoneObj === null )
  3203.                             {
  3204.                                     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.'.'));
  3205.                             }
  3206.                             $salesInvoiceDetailsObj->setZone($courierWiseZoneObj->getZone());
  3207.                             //return new JsonResponse(array('success' => false, 'responseText' => $courierWiseZoneObj->getZone() ));
  3208.                     //    }
  3209.                     //    else
  3210.                     //    {
  3211.                     //     $courierWiseZoneObj = $this->getDoctrine()
  3212.                     //             ->getRepository(CourierWiseZone::class)
  3213.                     //             ->find(1);
  3214.                     //    }
  3215.                     //Zone Assign End
  3216.                     //Customer Weight Calculation Start 
  3217.                     // Half and Per KG
  3218.                     $weight trim($weight_array[$index]);
  3219.                     $pointInputWeight $weight floor($weight);
  3220.                     $intInputWeight floor($weight);
  3221.                     $finalWeight 0;
  3222.                     $rateWeight 0;
  3223.                     if($weight <  $courierObj->getWeightPerkg())
  3224.                     {
  3225.                         if($pointInputWeight && $pointInputWeight <= 0.5)
  3226.                         {
  3227.                             $finalWeight = (float)0.5;
  3228.                         }
  3229.                         elseif($pointInputWeight 0.5 && $pointInputWeight <=1)
  3230.                         {
  3231.                             $finalWeight = (float)1;
  3232.                         }
  3233.                     }
  3234.                     else
  3235.                     {
  3236.                         if($pointInputWeight && $pointInputWeight <=1)
  3237.                         {
  3238.                             $finalWeight = (float)1;
  3239.                         }
  3240.                     }
  3241.                     $rateWeight $intInputWeight $finalWeight;
  3242.                     //Only Per KG
  3243.                     $pointInputPerKgWeight $weight floor($weight);
  3244.                     $intInputPerKgWeight floor($weight);
  3245.                     $finalPerKgWeight 0;
  3246.                     $ratePerKgWeight 0;
  3247.                     if($pointInputPerKgWeight && $pointInputPerKgWeight <=1)
  3248.                     {
  3249.                         $finalPerKgWeight = (float)1;
  3250.                     }
  3251.                     $ratePerKgWeight $intInputPerKgWeight $finalPerKgWeight;
  3252.                     //Customer Weight Calculation End
  3253.                     //Vendor/Booking weight Calculation Start 
  3254.                     // Half and Per KG
  3255.                     $bookingWeight trim($bookingWeight_array[$index]);
  3256.                     $pointInputBookingWeight $bookingWeight floor($bookingWeight);
  3257.                     $intInputBookingWeight floor($bookingWeight);
  3258.                     $finalBookingWeight 0;
  3259.                     $rateBookingWeight 0;
  3260.                     if($bookingWeight <  $courierObj->getWeightPerkg())
  3261.                     {
  3262.                         if($pointInputBookingWeight && $pointInputBookingWeight <= 0.5)
  3263.                         {
  3264.                             $finalBookingWeight = (float)0.5;
  3265.                         }
  3266.                         elseif($pointInputBookingWeight 0.5 && $pointInputBookingWeight <=1)
  3267.                         {
  3268.                             $finalBookingWeight = (float)1;
  3269.                         }
  3270.                     }
  3271.                     else
  3272.                     {
  3273.                         if($pointInputBookingWeight && $pointInputBookingWeight <=1)
  3274.                         {
  3275.                             $finalBookingWeight = (float)1;
  3276.                         }
  3277.                     }
  3278.                     $rateBookingWeight $intInputBookingWeight $finalBookingWeight;
  3279.                     //Only Per KG
  3280.                     $pointInputPerKgBookingWeight $bookingWeight floor($bookingWeight);
  3281.                     $intInputPerKgBookingWeight floor($bookingWeight);
  3282.                     $finalPerKgBookingWeight 0;
  3283.                     $ratePerKgBookingWeight 0;
  3284.                     if($pointInputPerKgBookingWeight && $pointInputPerKgBookingWeight <=1)
  3285.                     {
  3286.                         $finalPerKgBookingWeight = (float)1;
  3287.                     }
  3288.                     $ratePerKgBookingWeight $intInputPerKgBookingWeight $finalPerKgBookingWeight;
  3289.                     //Weight Calculation End
  3290.                     
  3291.                     // Get Settings Currency Start
  3292.                     $settingsObj $settingsInfoRepository->findByDateCurrency(1$salesInvoiceDetailsObj->getShipmentDate()->format('Y-m-d')); 
  3293.                     if($settingsObj === null)
  3294.                     {                                
  3295.                         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.'.'));
  3296.                     }                       
  3297.                     // Get Settings Currency End
  3298.                     //Master Rate Assign Start  
  3299.                     if(!$salesInvoiceDetailsObj->getShipment()->isExpedite())
  3300.                     {   
  3301.                         $perKgRateWeight $courierObj->getWeightPerkgRate();
  3302.                         if($courierObj->getId() != 3)
  3303.                         {
  3304.                             $finalMasterRateCal 0;                 
  3305.                             
  3306.     
  3307.                             if($rateBookingWeight $perKgRateWeight )
  3308.                             { 
  3309.                                 $countryWiseMasterRate $entityManager->getRepository(CountryWiseMasterRate::class) 
  3310.                                                             ->findOneBy(['type' => $shipmentObj->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateBookingWeight ]);                                          
  3311.     
  3312.                                 if($countryWiseMasterRate !== null
  3313.                                 { 
  3314.                                     $finalMasterRateCal =  $countryWiseMasterRate->getRate();
  3315.                                 }                           
  3316.                             }
  3317.                             else
  3318.                             {
  3319.                                 $countryWiseMasterRate $entityManager->getRepository(CountryWiseMasterRate::class)
  3320.                                                             ->findOneBy(['type' => $shipmentObj->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);                           
  3321.                                 if($countryWiseMasterRate !== null
  3322.                                 { 
  3323.                                     $finalMasterRateCal $countryWiseMasterRate->getRate() * $rateBookingWeight;                                    
  3324.                                 }
  3325.                             }
  3326.     
  3327.                             if($countryWiseMasterRate === null)  
  3328.                             {
  3329.                                 if($rateBookingWeight $perKgRateWeight )
  3330.                                 { 
  3331.                                     $zoneWiseMasterRate $entityManager->getRepository(ZoneWiseMasterRate::class)
  3332.                                                             ->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(), $zoneWiseMasterRateTypeObj->getRateType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight);                       
  3333.                                     
  3334.                                     if($zoneWiseMasterRate !== null)      
  3335.                                     { 
  3336.                                         $finalMasterRateCal $zoneWiseMasterRate->getRate();
  3337.                                     }
  3338.                                 }
  3339.                                 else
  3340.                                 {
  3341.                                    
  3342.                                     $zoneWiseMasterRate $entityManager->getRepository(ZoneWiseMasterRate::class)
  3343.                                                             ->findBookingRatebyCourierAndWeight($shipmentObj->getShipmentType(), $zoneWiseMasterRateTypeObj->getRateType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $courierObj->getId() == ?  $perKgRateWeight $rateBookingWeight );                     
  3344.                                     if($zoneWiseMasterRate !== null)      
  3345.                                     { 
  3346.                                         $finalMasterRateCal $zoneWiseMasterRate->getRate() * $rateBookingWeight;                                
  3347.                                     }
  3348.                                 }
  3349.                             }        
  3350.     
  3351.                             if($countryWiseMasterRate !== null)
  3352.                             {
  3353.                                 $salesInvoiceDetailsObj->setBookingRate($finalMasterRateCal);                            
  3354.                             }
  3355.                             else if($zoneWiseMasterRate !== null)
  3356.                             {
  3357.                                 $salesInvoiceDetailsObj->setBookingRate($finalMasterRateCal);                            
  3358.                             }
  3359.                             else
  3360.                             {                                   
  3361.                                 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.'.'));
  3362.                             }
  3363.                         }
  3364.                         else
  3365.                         {
  3366.                             if($rateBookingWeight <= 30
  3367.                             {
  3368.                                 $zoneWiseMasterRate $entityManager->getRepository(ZoneWiseMasterRate::class)
  3369.                                     ->findBookingRatebyCourierAndWeight(
  3370.                                         $shipmentObj->getShipmentType(), 
  3371.                                         $zoneWiseMasterRateTypeObj->getRateType(), 
  3372.                                         $courierObj->getId(), 
  3373.                                         $courierWiseZoneObj->getZone()->getId(), 
  3374.                                         $productTypeObj->getRateid(), 
  3375.                                         $rateBookingWeight
  3376.                                 );   
  3377.                                 
  3378.                                 $finalRate $zoneWiseMasterRate->getRate();
  3379.                             }
  3380.                             else if($rateBookingWeight 30 && $rateBookingWeight <= 70)
  3381.                             {
  3382.                                 $zoneWiseMasterRateFs $entityManager->getRepository(ZoneWiseMasterRate::class)
  3383.                                     ->findBookingRatebyCourierAndWeight(
  3384.                                         $shipmentObj->getShipmentType(), 
  3385.                                         $zoneWiseMasterRateTypeObj->getRateType(), 
  3386.                                         $courierObj->getId(), 
  3387.                                         $courierWiseZoneObj->getZone()->getId(), 
  3388.                                         $productTypeObj->getRateid(), 
  3389.                                         30
  3390.                                 );   
  3391.                                 $zoneWiseMasterRateSs $entityManager->getRepository(ZoneWiseMasterRate::class)
  3392.                                     ->findBookingRatebyCourierAndWeight(
  3393.                                         $shipmentObj->getShipmentType(), 
  3394.                                         $zoneWiseMasterRateTypeObj->getRateType(), 
  3395.                                         $courierObj->getId(), 
  3396.                                         $courierWiseZoneObj->getZone()->getId(), 
  3397.                                         $productTypeObj->getRateid(), 
  3398.                                         31
  3399.                                 ); 
  3400.                                 
  3401.                                 $finalRate $zoneWiseMasterRateFs->getRate() + (($rateBookingWeight 30) * $zoneWiseMasterRateSs->getRate());
  3402.                             }
  3403.                             else if($rateBookingWeight 70)
  3404.                             {
  3405.                                 $zoneWiseMasterRateFs $entityManager->getRepository(ZoneWiseMasterRate::class)
  3406.                                     ->findBookingRatebyCourierAndWeight(
  3407.                                         $shipmentObj->getShipmentType(), 
  3408.                                         $zoneWiseMasterRateTypeObj->getRateType(), 
  3409.                                         $courierObj->getId(), 
  3410.                                         $courierWiseZoneObj->getZone()->getId(), 
  3411.                                         $productTypeObj->getRateid(), 
  3412.                                         30
  3413.                                 );   
  3414.                                 $zoneWiseMasterRateSs $entityManager->getRepository(ZoneWiseMasterRate::class)
  3415.                                     ->findBookingRatebyCourierAndWeight(
  3416.                                         $shipmentObj->getShipmentType(), 
  3417.                                         $zoneWiseMasterRateTypeObj->getRateType(), 
  3418.                                         $courierObj->getId(), 
  3419.                                         $courierWiseZoneObj->getZone()->getId(), 
  3420.                                         $productTypeObj->getRateid(), 
  3421.                                         31
  3422.                                 ); 
  3423.                                 $zoneWiseMasterRateTs $entityManager->getRepository(ZoneWiseMasterRate::class)
  3424.                                     ->findBookingRatebyCourierAndWeight(
  3425.                                         $shipmentObj->getShipmentType(), 
  3426.                                         $zoneWiseMasterRateTypeObj->getRateType(), 
  3427.                                         $courierObj->getId(), 
  3428.                                         $courierWiseZoneObj->getZone()->getId(), 
  3429.                                         $productTypeObj->getRateid(), 
  3430.                                         71
  3431.                                 ); 
  3432.                                 $finalRate $zoneWiseMasterRateFs->getRate() + (40 $zoneWiseMasterRateSs->getRate()) + (($rateBookingWeight 70) * $zoneWiseMasterRateTs->getRate());
  3433.                             }
  3434.                             $salesInvoiceDetailsObj->setBookingRate($finalRate);
  3435.                         }
  3436.                     }
  3437.                     else
  3438.                     {
  3439.                         // Expedite Or Cash Master Rate
  3440.                         $countryWiseCashMasterRate $entityManager->getRepository(CountryWiseMasterRate::class) 
  3441.                                                     ->findCashBookingRatebyCourierAndWeight(2$salesInvoiceDetailsObj->getShipmentDate(), $courierObj->getId(), $countryObj->getId(), $productTypeObj->getRateid(), $rateBookingWeight);                                          
  3442.                         if($countryWiseCashMasterRate == null)
  3443.                         {
  3444.                             $zoneWiseMasterRate $entityManager->getRepository(ZoneWiseMasterRate::class)
  3445.                                                     ->findBookingCashRatebyCourierAndWeight(3$salesInvoiceDetailsObj->getShipmentDate(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight );                     
  3446.                         }
  3447.                         
  3448.                         if($countryWiseCashMasterRate !== null)
  3449.                         {
  3450.                             $salesInvoiceDetailsObj->setBookingRate($countryWiseCashMasterRate->getRate() * $rateBookingWeight); 
  3451.                         }
  3452.                         else if($zoneWiseMasterRate !== null)      
  3453.                         {                          
  3454.                             $salesInvoiceDetailsObj->setBookingRate(round(($zoneWiseMasterRate->getRate() * $rateBookingWeight) / $settingsObj->getCurrency(),2));                                                         
  3455.                         }
  3456.                         else
  3457.                         {
  3458.                             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.'.'));
  3459.                         }
  3460.                         
  3461.                         //$salesInvoiceDetailsObj->setBookingRate($countryObj->getMasterExpediteRate() * $rateBookingWeight);   
  3462.                     }
  3463.                     //Master Rate Assign End
  3464.                     // Own Company Rate for Customer Start
  3465.                     $salesCourierId 0;
  3466.                     $salesCourierName "";
  3467.                     $salesZoneId 0;
  3468.                     if($this->getUser()->getUserCompany()->getCustomerRate() == // Own Company Wise Customer Rate
  3469.                     {
  3470.                         if($customerObj->getCustomerType() == )  //Customer
  3471.                         {
  3472.                             $salesCourierId $this->getUser()->getUserCompany()->getCompanyCourier()->getId();
  3473.                             $salesCourierName $this->getUser()->getUserCompany()->getCompanyCourier()->getName();
  3474.                             /// Zone 
  3475.                             $courierWiseZoneObject $entityManager->getRepository(CourierWiseZone::class)
  3476.                                                 ->findOneBy(['courier' => $salesCourierId'country' => $countryObj->getId() ]);                       
  3477.                             if($courierWiseZoneObject === null )
  3478.                             {
  3479.                                     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.'.'));
  3480.                             }
  3481.                             $salesZoneId $courierWiseZoneObject->getZone()->getId();
  3482.                                                             
  3483.                         }
  3484.                         else  //Agent
  3485.                         {
  3486.                             $salesCourierId $courierObj->getId();
  3487.                             $salesCourierName $courierObj->getName();
  3488.                             $salesZoneId $courierWiseZoneObj->getZone()->getId();
  3489.                             
  3490.                         }
  3491.                     }
  3492.                     else   // Separate Courier Wise Customer Rate
  3493.                     {
  3494.                         $salesCourierId $courierObj->getId();
  3495.                         $salesCourierName $courierObj->getName();
  3496.                         $salesZoneId $courierWiseZoneObj->getZone()->getId();
  3497.                         
  3498.                     }
  3499.                     // Own Company Rate for Customer End
  3500.                     if($salesInvoiceDetailsObj->getRateApplicable() <= && !$salesInvoiceDetailsObj->getShipment()->isExpedite())  // Predefine Rate
  3501.                     {
  3502.                         
  3503.                         $finalRateCal 0;
  3504.                         if($customerObj->getRateType() == 1)  // Customer wise sales rate     
  3505.                         {
  3506.                             if($courierObj->getId() != 3)    
  3507.                             {  
  3508.                                 if($rateWeight $perKgRateWeight )
  3509.                                 { 
  3510.                                     $countryWiseSalesRate $entityManager->getRepository(CountryWiseSalesRate::class)
  3511.                                                             ->findOneBy(['type' => $shipmentObj->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $salesCourierId'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateWeight ]);                                        
  3512.                                     if($countryWiseSalesRate !== null)     
  3513.                                     {                         
  3514.                                         $finalRateCal $countryWiseSalesRate->getRate();
  3515.                                     }
  3516.                                 }
  3517.                                 else
  3518.                                 {
  3519.                                     $countryWiseSalesRate $entityManager->getRepository(CountryWiseSalesRate::class)
  3520.                                                             ->findOneBy(['type' => $shipmentObj->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $salesCourierId'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);                           
  3521.                                     if($countryWiseSalesRate !== null)     
  3522.                                     { 
  3523.                                         $finalRateCal $countryWiseSalesRate->getRate() * $rateWeight;                                            
  3524.                                     }
  3525.                                 }
  3526.                               
  3527.                                 if($countryWiseSalesRate === null)  
  3528.                                 {
  3529.                                     if($rateWeight $perKgRateWeight )
  3530.                                     {
  3531.                                         $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseSalesRate::class)
  3532.                                                                 ->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(), $customerObj->getId(), $salesCourierId$salesZoneId$productTypeObj->getRateid(), $rateWeight);                                     
  3533.                                         if($zoneWiseSalesRate !== null)     
  3534.                                         {                         
  3535.                                             $finalRateCal $zoneWiseSalesRate->getRate();
  3536.                                         }
  3537.                                     }
  3538.                                     else
  3539.                                     {                                                             
  3540.                                         $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseSalesRate::class) 
  3541.                                                                 ->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(), $customerObj->getId(), $salesCourierId$salesZoneId$productTypeObj->getRateid(), $courierObj->getId() == ?  $perKgRateWeight $rateWeight );                       
  3542.                                         
  3543.                                         if($zoneWiseSalesRate !== null)     
  3544.                                         { 
  3545.                                             $finalRateCal $zoneWiseSalesRate->getRate() * $rateWeight;                                      
  3546.                                         }
  3547.                                     }
  3548.                                 }        
  3549.     
  3550.                                 if($countryWiseSalesRate !== null)
  3551.                                 {
  3552.                                     $salesInvoiceDetailsObj->setSalesRate($finalRateCal);
  3553.                                     
  3554.                                 }
  3555.                                 else if($zoneWiseSalesRate !== null)
  3556.                                 {
  3557.                                     $salesInvoiceDetailsObj->setSalesRate($finalRateCal);                                    
  3558.                                 }
  3559.                                 else
  3560.                                 {                                   
  3561.                                     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.'.'));
  3562.                                 }
  3563.                             }
  3564.                             else
  3565.                             {
  3566.                                 if($rateWeight <= 30)
  3567.                                 {
  3568.                                     $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseSalesRate::class)
  3569.                                         ->findSalesRatebyCustomerAndWeight(
  3570.                                             $shipmentObj->getShipmentType(), 
  3571.                                             $customerObj->getId(), 
  3572.                                             $salesCourierId
  3573.                                             $salesZoneId
  3574.                                             $productTypeObj->getRateid(), 
  3575.                                             $rateWeight
  3576.                                         );   
  3577.                                     $finalSalesRate $zoneWiseSalesRate->getRate();                      
  3578.                                 }
  3579.                                 else if($rateWeight 30 && $rateWeight <= 70)
  3580.                                 {
  3581.                                     $zoneWiseSalesRateFs $entityManager->getRepository(ZoneWiseSalesRate::class)
  3582.                                         ->findSalesRatebyCustomerAndWeight(
  3583.                                             $shipmentObj->getShipmentType(), 
  3584.                                             $customerObj->getId(), 
  3585.                                             $salesCourierId
  3586.                                             $salesZoneId
  3587.                                             $productTypeObj->getRateid(), 
  3588.                                             30
  3589.                                         );   
  3590.                                     
  3591.                                     $zoneWiseSalesRateSs $entityManager->getRepository(ZoneWiseSalesRate::class)
  3592.                                         ->findSalesRatebyCustomerAndWeight(
  3593.                                             $shipmentObj->getShipmentType(), 
  3594.                                             $customerObj->getId(), 
  3595.                                             $salesCourierId
  3596.                                             $salesZoneId
  3597.                                             $productTypeObj->getRateid(), 
  3598.                                             31
  3599.                                         );  
  3600.                                     $finalSalesRate $zoneWiseSalesRateFs->getRate() + (($rateWeight 30) * $zoneWiseSalesRateSs->getRate()); 
  3601.                                 }
  3602.                                 else if($rateWeight 70)
  3603.                                 {
  3604.                                     $zoneWiseSalesRateFs $entityManager->getRepository(ZoneWiseSalesRate::class)
  3605.                                         ->findSalesRatebyCustomerAndWeight(
  3606.                                             $shipmentObj->getShipmentType(), 
  3607.                                             $customerObj->getId(), 
  3608.                                             $salesCourierId
  3609.                                             $salesZoneId
  3610.                                             $productTypeObj->getRateid(), 
  3611.                                             30
  3612.                                         );   
  3613.                                 
  3614.                                     $zoneWiseSalesRateSs $entityManager->getRepository(ZoneWiseSalesRate::class)
  3615.                                         ->findSalesRatebyCustomerAndWeight(
  3616.                                             $shipmentObj->getShipmentType(), 
  3617.                                             $customerObj->getId(), 
  3618.                                             $salesCourierId
  3619.                                             $salesZoneId
  3620.                                             $productTypeObj->getRateid(), 
  3621.                                             31
  3622.                                         );  
  3623.                                     $zoneWiseSalesRateTs $entityManager->getRepository(ZoneWiseSalesRate::class)
  3624.                                         ->findSalesRatebyCustomerAndWeight(
  3625.                                             $shipmentObj->getShipmentType(), 
  3626.                                             $customerObj->getId(), 
  3627.                                             $salesCourierId
  3628.                                             $salesZoneId
  3629.                                             $productTypeObj->getRateid(), 
  3630.                                             71
  3631.                                         ); 
  3632.                                     
  3633.                                     $finalSalesRate $zoneWiseSalesRateFs->getRate() + (40 $zoneWiseSalesRateSs->getRate()) + (($rateWeight 70) * $zoneWiseSalesRateTs->getRate()); 
  3634.                                 }
  3635.                                 
  3636.                                  $salesInvoiceDetailsObj->setSalesRate($finalSalesRate);
  3637.                             }
  3638.                         }
  3639.                         else  // Common sales rate   
  3640.                         {
  3641.                             if($rateWeight $perKgRateWeight )
  3642.                             { 
  3643.                                 $countryWiseSalesRate $entityManager->getRepository(CountryWiseCommonSalesRate::class)
  3644.                                                         ->findOneBy(['type' => $shipmentObj->getShipmentType(), 'courier' => $salesCourierId'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateWeight ]);                           
  3645.                             }
  3646.                             else
  3647.                             {
  3648.                                 $countryWiseSalesRate $entityManager->getRepository(CountryWiseCommonSalesRate::class)
  3649.                                                         ->findOneBy(['type' => $shipmentObj->getShipmentType(), 'courier' => $salesCourierId'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);                           
  3650.                                 if($countryWiseSalesRate !== null)     
  3651.                                 {   
  3652.                                     $countryWiseSalesRate->setRate($countryWiseSalesRate->getRate() * $rateWeight);
  3653.                                 }
  3654.                             }
  3655.                                 
  3656.                             if($countryWiseSalesRate === null)  
  3657.                             {
  3658.                                 if($rateWeight $perKgRateWeight )
  3659.                                 {
  3660.                                     $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseCommonSalesRate::class)
  3661.                                                             ->findCommonSalesRatebyCourierAndWeight($shipmentObj->getShipmentType(), $salesCourierId$salesZoneId$productTypeObj->getRateid(), $rateWeight);                                     
  3662.                                 }
  3663.                                 else
  3664.                                 {
  3665.                                     $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseCommonSalesRate::class)
  3666.                                                             ->findCommonSalesRatebyCourierAndWeight($shipmentObj->getShipmentType(), $salesCourierId$salesZoneId$productTypeObj->getRateid(), $courierObj->getId() == ?  $perKgRateWeight $rateWeight );                       
  3667.                                     if($zoneWiseSalesRate !== null)     
  3668.                                     {       
  3669.                                         $zoneWiseSalesRate->setRate($zoneWiseSalesRate->getRate() * $rateWeight);
  3670.                                     }
  3671.                                 }
  3672.                             }        
  3673.                             if($countryWiseSalesRate !== null)
  3674.                             {
  3675.                                 $salesInvoiceDetailsObj->setSalesRate($zoneWiseSalesRate->getRate());
  3676.                             }
  3677.                             else if($zoneWiseSalesRate !== null)
  3678.                             {
  3679.                                 $salesInvoiceDetailsObj->setSalesRate($countryWiseSalesRate->getRate());
  3680.                             }
  3681.                             else
  3682.                             {                                   
  3683.                                 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.'.'));
  3684.                             }
  3685.                         }
  3686.                         //Sales Rate Assign End
  3687.                         
  3688.                     }
  3689.                     else  // Special Calculated Rate
  3690.                     {
  3691.                         
  3692.                         $salesInvoiceDetailsObj->setSalesRate(round((float)$salesRate_array[$index] / $settingsObj->getCurrency(),2));                        
  3693.                     }
  3694.                     
  3695.                     
  3696.                     // Master Weight and Sales Rate Calculation Start
  3697.                      
  3698.                     if($salesInvoiceDetailsObj->getRateApplicable() <= && !$salesInvoiceDetailsObj->getShipment()->isExpedite())  // Predefine Rate
  3699.                     {
  3700.                        
  3701.                         $finalRateCal 0;
  3702.                         if($customerObj->getRateType() == 1)  // Customer wise sales rate     
  3703.                         {
  3704.                             if($rateBookingWeight $perKgRateWeight )
  3705.                             { 
  3706.                                 $countryWiseSalesRate $entityManager->getRepository(CountryWiseSalesRate::class)
  3707.                                                         ->findOneBy(['type' => $shipmentObj->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateBookingWeight ]);                              
  3708.                                 if($countryWiseSalesRate !== null)     
  3709.                                 {                         
  3710.                                     $finalRateCal $countryWiseSalesRate->getRate();
  3711.                                 }
  3712.                             }
  3713.                             else
  3714.                             {
  3715.                                 $countryWiseSalesRate $entityManager->getRepository(CountryWiseSalesRate::class)
  3716.                                                         ->findOneBy(['type' => $shipmentObj->getShipmentType(), 'customer' => $customerObj->getId(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);
  3717.                                 if($countryWiseSalesRate !== null)     
  3718.                                 { 
  3719.                                     $finalRateCal $countryWiseSalesRate->getRate() * $rateBookingWeight;                                            
  3720.                                 }
  3721.                             }
  3722.                           
  3723.                             if($countryWiseSalesRate === null)  
  3724.                             {
  3725.                                 if($rateBookingWeight $perKgRateWeight )
  3726.                                 {
  3727.                                     $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseSalesRate::class)
  3728.                                                             ->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(), $customerObj->getId(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight);                                     
  3729.                                     // return new JsonResponse(array('success' => false, 'responseText' => $rateBookingWeight .'-'. $zoneWiseSalesRate->getRate() ));                           
  3730.                                     if($zoneWiseSalesRate !== null)     
  3731.                                     {                         
  3732.                                         $finalRateCal $zoneWiseSalesRate->getRate();
  3733.                                     }
  3734.                                 }
  3735.                                 else
  3736.                                 {   
  3737.                                     // return new JsonResponse(array('success' => false, 'responseText' => $shipmentObj->getShipmentType() .' - '. $customerObj->getId() .' - '.$courierObj->getId() .' - '. $courierWiseZoneObj->getZone()->getId() .' - '. $productTypeObj->getRateid() . ' - ' .$rateBookingWeight ));     
  3738.                                     $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseSalesRate::class) 
  3739.                                                             ->findSalesRatebyCustomerAndWeight($shipmentObj->getShipmentType(), $customerObj->getId(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(),  $rateBookingWeight );                       
  3740.                                     
  3741.                                     if($zoneWiseSalesRate !== null)     
  3742.                                     { 
  3743.                                         $finalRateCal $zoneWiseSalesRate->getRate() * $rateBookingWeight;                                      
  3744.                                     }
  3745.                                 }
  3746.                             }        
  3747.                             if($countryWiseSalesRate !== null)
  3748.                             {
  3749.                                 $salesInvoiceDetailsObj->setSalesMasterRate($finalRateCal);
  3750.                                 
  3751.                             }
  3752.                             else if($zoneWiseSalesRate !== null)
  3753.                             {
  3754.                                 $salesInvoiceDetailsObj->setSalesMasterRate($finalRateCal);                                    
  3755.                             }
  3756.                             else
  3757.                             {                                   
  3758.                                 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.'.'));
  3759.                             }
  3760.                         }
  3761.                         else  // Common sales rate   
  3762.                         {
  3763.                             if($rateBookingWeight $perKgRateWeight )
  3764.                             { 
  3765.                                 $countryWiseSalesRate $entityManager->getRepository(CountryWiseCommonSalesRate::class)
  3766.                                                         ->findOneBy(['type' => $shipmentObj->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $rateBookingWeight ]);                           
  3767.                             }
  3768.                             else
  3769.                             {
  3770.                                 $countryWiseSalesRate $entityManager->getRepository(CountryWiseCommonSalesRate::class)
  3771.                                                         ->findOneBy(['type' => $shipmentObj->getShipmentType(), 'courier' => $courierObj->getId(), 'country' => $countryObj->getId(), 'productType' => $productTypeObj->getRateid(), 'weight' => $perKgRateWeight ]);                           
  3772.                                 if($countryWiseSalesRate !== null)     
  3773.                                 {   
  3774.                                     $countryWiseSalesRate->setRate($countryWiseSalesRate->getRate() * $rateWeight);
  3775.                                 }
  3776.                             }
  3777.                                 
  3778.                             if($countryWiseSalesRate === null)  
  3779.                             {
  3780.                                 if($rateWeight $perKgRateWeight )
  3781.                                 {
  3782.                                     $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseCommonSalesRate::class)
  3783.                                                             ->findCommonSalesRatebyCourierAndWeight($shipmentObj->getShipmentType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $rateBookingWeight);                                     
  3784.                                 }
  3785.                                 else
  3786.                                 {
  3787.                                     $zoneWiseSalesRate $entityManager->getRepository(ZoneWiseCommonSalesRate::class)
  3788.                                                             ->findCommonSalesRatebyCourierAndWeight($shipmentObj->getShipmentType(), $courierObj->getId(), $courierWiseZoneObj->getZone()->getId(), $productTypeObj->getRateid(), $courierObj->getId() == ?  $perKgRateWeight $rateBookingWeight );                       
  3789.                                     if($zoneWiseSalesRate !== null)     
  3790.                                     {       
  3791.                                         $zoneWiseSalesRate->setRate($zoneWiseSalesRate->getRate() * $rateBookingWeight);
  3792.                                     }
  3793.                                 }
  3794.                             }        
  3795.                             if($countryWiseSalesRate !== null)
  3796.                             {
  3797.                                 $salesInvoiceDetailsObj->setSalesMasterRate($zoneWiseSalesRate->getRate());
  3798.                             }
  3799.                             else if($zoneWiseSalesRate !== null)
  3800.                             {
  3801.                                 $salesInvoiceDetailsObj->setSalesMasterRate($countryWiseSalesRate->getRate());
  3802.                             }
  3803.                             else
  3804.                             {                                   
  3805.                                 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.'.'));
  3806.                             }
  3807.                         }
  3808.                         //Sales Rate Assign End
  3809.                         
  3810.                     }
  3811.                     else  // Special Calculated Rate
  3812.                     {
  3813.                         
  3814.                         // Get Settings Currency Start
  3815.                         $settingsObj $settingsInfoRepository
  3816.                                             ->findByDateCurrency(1$salesInvoiceDetailsObj->getShipmentDate()->format('Y-m-d')); 
  3817.                         if($settingsObj === null)
  3818.                         {                                
  3819.                             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.'.'));
  3820.                         }                       
  3821.                         // Get Settings Currency End
  3822.                         $salesInvoiceDetailsObj->setSalesMasterRate(round((float)$salesRate_array[$index] / $settingsObj->getCurrency(),2));                        
  3823.                     }                    
  3824.  
  3825.                     // Master Weight and Sales Rate Calculation End
  3826.                     // SRO Calculation Start
  3827.                     if($courierObj->getSro() == && $salesInvoiceDetailsObj->getRateApplicable() <= 2)
  3828.                     {
  3829.                         $salesInvoiceDetailsObj->setSro($courierObj->getSroCharge());
  3830.                     }
  3831.                     // SRO Calculation End
  3832.                    
  3833.                     //Master Covid Charge Cal Start
  3834.                     if($salesInvoiceDetailsObj->getRateApplicable() <= && !$salesInvoiceDetailsObj->getShipment()->isExpedite())
  3835.                     {
  3836.                         if($courierObj->getCovidChargeApplicable() == && $courierObj->getId() == 1)  // DHL Covid Charge Cal
  3837.                         {
  3838.                             // $zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)
  3839.                             //                     ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  3840.                             // if($zoneWiseCovidCharge === null)
  3841.                             // {
  3842.                             //     $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)
  3843.                             //                             ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);                           
  3844.                             // }
  3845.                             // Demand Charge Start
  3846.                             // $comparisonDate = new DateTime('2024-09-14');
  3847.                             // if($salesInvoiceDetailsObj->getShipmentDate() > $comparisonDate)
  3848.                             // {
  3849.                             //     $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)
  3850.                             //                                 ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]); 
  3851.                                 
  3852.                             //     if($countryWiseCovidCharge !== null)
  3853.                             //     {                          
  3854.                             //         $salesInvoiceDetailsObj->setVendorCovidCharge($countryWiseCovidCharge->getRate() * $rateBookingWeight);
  3855.                             //         //$salesInvoiceDetailsObj->setCovidCharge($countryWiseCovidCharge->getRate() * $rateWeight);  
  3856.                             //     }
  3857.                             //     else
  3858.                             //     {
  3859.                             //         return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  3860.                             //     }   
  3861.                             // }                          
  3862.                             // Demand Charge End
  3863.                             // // Go Green Charge Start
  3864.                             // $comparisonDate = new DateTime('2024-04-01');
  3865.                             // if ($salesInvoiceDetailsObj->getShipmentDate() < $comparisonDate) {
  3866.                             //     if($countryObj->getId() == 11 || $countryObj->getId() == 151)
  3867.                             //     {
  3868.                             //         $covidChargeUsd = 3.35;
  3869.                             //     }
  3870.                             //     else
  3871.                             //     {
  3872.                             //         $covidChargeUsd = 1.15;
  3873.                             //     }
  3874.                             // } else {
  3875.                             //     if($countryObj->getId() == 11 || $countryObj->getId() == 151)
  3876.                             //     {
  3877.                             //         $covidChargeUsd = 0.56;
  3878.                             //     }
  3879.                             //     else
  3880.                             //     {
  3881.                             //         $covidChargeUsd = 0.56;
  3882.                             //     }
  3883.                             // }
  3884.                             // $salesInvoiceDetailsObj->setVendorCovidCharge($covidChargeUsd * $rateBookingWeight);
  3885.                             // // Go Green Charge End
  3886.                           
  3887.                                 
  3888.                         }
  3889.                         else if($courierObj->getCovidChargeApplicable() == && $courierObj->getId() == 2// Fedex Covid Charge Cal
  3890.                         {
  3891.                             // Demand Charge Start
  3892.                             $comparisonDate = new DateTime('2024-11-17');
  3893.                             if($salesInvoiceDetailsObj->getShipmentDate() > $comparisonDate)
  3894.                             {
  3895.                                 $zoneWiseCovidCharge $entityManager->getRepository(ZoneWiseCovidCharge::class)
  3896.                                                     ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  3897.                                 if($zoneWiseCovidCharge !== null)
  3898.                                 {
  3899.                                     $demandCharge =  $zoneWiseCovidCharge->getRate() * $rateBookingWeight;  
  3900.                                 
  3901.                                     if($demandCharge 1)
  3902.                                         $salesInvoiceDetailsObj->setVendorCovidCharge(1);
  3903.                                     else
  3904.                                         $salesInvoiceDetailsObj->setVendorCovidCharge($demandCharge);
  3905.                                 }                         
  3906.                                 else
  3907.                                 {
  3908.                                     return new JsonResponse(array('success' => false'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  3909.                                 }
  3910.                                
  3911.                             }
  3912.                             else
  3913.                             {
  3914.                                 if($rateBookingWeight <= 3)
  3915.                                 {
  3916.                                     $salesInvoiceDetailsObj->setVendorCovidCharge(1);
  3917.                                 }
  3918.                                 else
  3919.                                 {
  3920.                                     $salesInvoiceDetailsObj->setVendorCovidCharge($rateBookingWeight 0.30);
  3921.                                 }
  3922.                             }
  3923.                         }
  3924.                     }
  3925.                     //Master Covid Charge Cal End
  3926.                     //Sales Covid Charge Cal Start
  3927.                     if($salesInvoiceDetailsObj->getRateApplicable() <= && !$salesInvoiceDetailsObj->getShipment()->isExpedite())
  3928.                     {
  3929.                         if($courierObj->getCovidChargeApplicable() == && $courierObj->getId() == 1)  // DHL Covid Charge Cal
  3930.                         {
  3931.                             // $zoneWiseCovidCharge = $entityManager->getRepository(ZoneWiseCovidCharge::class)
  3932.                             //                     ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  3933.                             // if($zoneWiseCovidCharge === null)
  3934.                             // {
  3935.                             //     $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)
  3936.                             //                             ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]);                           
  3937.                             // }
  3938.                             // Demand Charge Start
  3939.                             // $comparisonDate = new DateTime('2024-09-14');
  3940.                             // if($salesInvoiceDetailsObj->getShipmentDate() > $comparisonDate)
  3941.                             // {
  3942.                             //     $countryWiseCovidCharge = $entityManager->getRepository(CountryWiseCovidCharge::class)
  3943.                             //                                 ->findOneBy(['courier' => $courierObj->getId(), 'country' => $countryObj->getId() ]); 
  3944.                                 
  3945.                             //     if($countryWiseCovidCharge !== null)
  3946.                             //     {                          
  3947.                             //       // $salesInvoiceDetailsObj->setVendorCovidCharge($countryWiseCovidCharge->getRate() * $rateBookingWeight);
  3948.                             //         $salesInvoiceDetailsObj->setCovidCharge($countryWiseCovidCharge->getRate() * $rateWeight);  
  3949.                             //     }
  3950.                             //     else
  3951.                             //     {
  3952.                             //         return new JsonResponse(array('success' => false, 'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  3953.                             //     }   
  3954.                             // }                          
  3955.                             // Demand Charge End
  3956.                             // // Go Green Charge Start
  3957.                             // $comparisonDate = new DateTime('2024-04-01');
  3958.                             // if ($salesInvoiceDetailsObj->getShipmentDate() < $comparisonDate) {
  3959.                             //     if($countryObj->getId() == 11 || $countryObj->getId() == 151)
  3960.                             //     {
  3961.                             //         $covidChargeUsd = 3.35;
  3962.                             //     }
  3963.                             //     else
  3964.                             //     {
  3965.                             //         $covidChargeUsd = 1.15;
  3966.                             //     }
  3967.                             // } else {
  3968.                             //     if($countryObj->getId() == 11 || $countryObj->getId() == 151)
  3969.                             //     {
  3970.                             //         $covidChargeUsd = 0.56;
  3971.                             //     }
  3972.                             //     else
  3973.                             //     {
  3974.                             //         $covidChargeUsd = 0.56;
  3975.                             //     }
  3976.                             // }
  3977.                             // $salesInvoiceDetailsObj->setVendorCovidCharge($covidChargeUsd * $rateWeight);
  3978.                             
  3979.                             // // Go Green Charge End
  3980.                         }
  3981.                         else if($courierObj->getCovidChargeApplicable() == && $courierObj->getId() == 2// Fedex Covid Charge Cal
  3982.                         {
  3983.                             // Demand Charge Start
  3984.                             $comparisonDate = new DateTime('2024-11-17');
  3985.                             if($salesInvoiceDetailsObj->getShipmentDate() > $comparisonDate)
  3986.                             {
  3987.                                 $zoneWiseCovidCharge $entityManager->getRepository(ZoneWiseCovidCharge::class)
  3988.                                                     ->findOneBy(['courier' => $courierObj->getId(), 'zone' => $courierWiseZoneObj->getZone() ]); 
  3989.                                 if($zoneWiseCovidCharge !== null)
  3990.                                 {
  3991.                                     $demandCharge =  $zoneWiseCovidCharge->getRate() * $rateWeight;  
  3992.                                 
  3993.                                     if($demandCharge 1)
  3994.                                         $salesInvoiceDetailsObj->setCovidCharge(1);
  3995.                                     else
  3996.                                         $salesInvoiceDetailsObj->setCovidCharge($demandCharge);
  3997.                                 }                         
  3998.                                 else
  3999.                                 {
  4000.                                     return new JsonResponse(array('success' => false'responseText' => 'Demand Charge is not set for Courier : '.$courierObj->getName().', Country : '.$countryObj->getName().' in Row Number '.$keyValue.'.'));
  4001.                                 }
  4002.                             
  4003.                             }
  4004.                             else
  4005.                             {
  4006.                                 if($rateWeight <= 3)
  4007.                                 {
  4008.                                     $salesInvoiceDetailsObj->setCovidCharge(1);
  4009.                                 }
  4010.                                 else
  4011.                                 {
  4012.                                     $salesInvoiceDetailsObj->setCovidCharge($rateWeight 0.30);
  4013.                                 }
  4014.                             }
  4015.                         }
  4016.                     }
  4017.                     //Sales Covid Charge Cal End
  4018.                     $salesInvoiceDetailsList->add($salesInvoiceDetailsObj);                    
  4019.                     $index ++;
  4020.                 }  
  4021.                     //Data Save Process Start  
  4022.                     $index 0;
  4023.                     $individualSalesInvoiceId 0;
  4024.                     foreach($salesInvoiceDetailsList as $row)
  4025.                     { 
  4026.                         $keyValue $key;
  4027.                         $keyValue $keyValue 1;
  4028.     
  4029.                         $shipmentDate $row->getShipmentDate();
  4030.                         
  4031.                         // Demand Charge Start
  4032.                         if($row->getCourier()->getId() == 1)
  4033.                         {
  4034.                             $comparisonDate = new DateTime('2025-10-01');
  4035.                             if($shipmentDate >= $comparisonDate)
  4036.                             {
  4037.                                 $countryWiseCovidCharge $entityManager->getRepository(CountryWiseCovidCharge::class)
  4038.                                                             ->findOneBy(['courier' => $row->getCourier()->getId(), 'country' => $row->getCountry()->getId()]); 
  4039.                                 
  4040.                                 if($countryWiseCovidCharge !== null)
  4041.                                 {
  4042.                                     //Vendor/Booking weight Calculation Start 
  4043.                                     // Half and Per KG
  4044.                                     $bookingWeight $row->getBookingWeight();
  4045.                                     $pointInputBookingWeight $bookingWeight floor($bookingWeight);
  4046.                                     $intInputBookingWeight floor($bookingWeight);
  4047.                                   // return new JsonResponse(array('success' => false, 'responseText' => $bookingWeight ));
  4048.                                     $finalBookingWeight 0;
  4049.                                     $rateBookingWeight 0;
  4050.                                     if($bookingWeight <  $row->getCourier()->getWeightPerkg())
  4051.                                     {
  4052.                                         if($pointInputBookingWeight && $pointInputBookingWeight <= 0.5)
  4053.                                         {
  4054.                                             $finalBookingWeight = (float)0.5;
  4055.                                         }
  4056.                                         elseif($pointInputBookingWeight 0.5 && $pointInputBookingWeight <=1)
  4057.                                         {
  4058.                                             $finalBookingWeight = (float)1;
  4059.                                         }
  4060.                                     }
  4061.                                     else
  4062.                                     {
  4063.                                         if($pointInputBookingWeight && $pointInputBookingWeight <=1)
  4064.                                         {
  4065.                                             $finalBookingWeight = (float)1;
  4066.                                         }
  4067.                                     }
  4068.                                     $rateBookingWeight $intInputBookingWeight $finalBookingWeight;
  4069.                                     //Vendor/Booking weight Calculation End
  4070.                                     
  4071.                                     //Customer Weight Calculation Start 
  4072.                                     // Half and Per KG
  4073.                                     $weight $row->getWeight();
  4074.                                     $pointInputWeight $weight floor($weight);
  4075.                                     $intInputWeight floor($weight);
  4076.                                     $finalWeight 0;
  4077.                                     $rateWeight 0;
  4078.                                     if($weight <  $row->getCourier()->getWeightPerkg())
  4079.                                     {
  4080.                                         if($pointInputWeight && $pointInputWeight <= 0.5)
  4081.                                         {
  4082.                                             $finalWeight = (float)0.5;
  4083.                                         }
  4084.                                         elseif($pointInputWeight 0.5 && $pointInputWeight <=1)
  4085.                                         {
  4086.                                             $finalWeight = (float)1;
  4087.                                         }
  4088.                                     }
  4089.                                     else
  4090.                                     {
  4091.                                         if($pointInputWeight && $pointInputWeight <=1)
  4092.                                         {
  4093.                                             $finalWeight = (float)1;
  4094.                                         }
  4095.                                     }
  4096.                                     $rateWeight $intInputWeight $finalWeight;
  4097.                                     //Customer Weight Calculation End 
  4098.                                     $bookingDemandCharge $countryWiseCovidCharge->getRate() * $rateBookingWeight;
  4099.                                     $salesDemandCharge $countryWiseCovidCharge->getRate() * $rateWeight;  
  4100.                                     
  4101.                                    
  4102.                                 }
  4103.                                 else
  4104.                                 {
  4105.                                     
  4106.                                     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.'.'));
  4107.                                 }   
  4108.                             }  
  4109.                             else
  4110.                             {
  4111.                                 $bookingDemandCharge 0;
  4112.                                 $salesDemandCharge 0;  
  4113.                             }
  4114.                         }                        
  4115.                         // Demand Charge End
  4116.     
  4117.                         // Get Settings Currency Start
  4118.                         $settingsObj $settingsInfoRepository
  4119.                                             ->findByDateCurrency(1$shipmentDate->format('Y-m-d')); 
  4120.                         if($settingsObj === null)
  4121.                         {                                
  4122.                             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.'.'));
  4123.                         }                       
  4124.                         // Get Settings Currency End
  4125.                         // Get Vendor FSC Start
  4126.                         $vendorFscObj $settingsInfoRepository
  4127.                                             ->findByDate(2$row->getCourier()->getId(), $shipmentDate->format('Y-m-d')); 
  4128.                         if($vendorFscObj === null)
  4129.                         {                                
  4130.                             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.'.'));
  4131.                         }                       
  4132.                         // Get Vendor FSC End
  4133.                         // Get Customer FSC Start
  4134.                         $fscObj $settingsInfoRepository
  4135.                                     ->findByDate(2$this->getUser()->getUserCompany()->getCustomerRate() == $row->getCourier()->getId() : $salesCourierId$shipmentDate->format('Y-m-d')); 
  4136.                         if($fscObj === null)
  4137.                         {                                
  4138.                             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.'.'));
  4139.                         }                       
  4140.                         // Get Customer FSC End
  4141.                         $firstDateofMonth date('Y-m-01'strtotime($shipmentDate->format('Y-m-d')));            
  4142.                         $lastDateofMonth date('Y-m-t'strtotime($shipmentDate->format('Y-m-d')));
  4143.                         $lastDateofMonth = new \DateTime($lastDateofMonth);
  4144.                         $halfDateofMonth date('Y-m-d'strtotime($firstDateofMonth' + 14 days'));
  4145.                         $halfDateofMonth = new \DateTime($halfDateofMonth);
  4146.                         if($row->getCustomer()->getRateCurrency() == 2)
  4147.                         {
  4148.                             $row->setRateApplicable(3);
  4149.                         }
  4150.                         
  4151.                         if($row->getCustomer()->getInvoicePeriod() == 1)  //Monthly Invoice Save Process
  4152.                         {
  4153.                             $salesInvoiceObj $salesInvoiceRepository->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $lastDateofMonth$lastDateofMonth$shipmentObj->getShipmentType(), $row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );                    
  4154.     
  4155.                             $invocieDate $lastDateofMonth;
  4156.                             if($salesInvoiceObj === null)
  4157.                             {
  4158.                                 $salesInv = new SalesInvoice();
  4159.                                 $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  4160.                                 $salesInv->setCustomer($row->getCustomer());
  4161.                                 
  4162.                                 $salesInvocieLastObj $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());
  4163.                                 $invoiceNO $utilsService->invoiceNoGenerator($salesInvocieLastObj$row->getCustomer(), $invocieDate$shipmentObj->getShipmentType());
  4164.                                 $salesInv->setInvoiceNo($invoiceNO); 
  4165.                                 $salesInv->setInvoiceDate($invocieDate);                                         
  4166.                                 $salesInv->setVat($settingsObj->getVat());                          
  4167.                                 $salesInv->setApproval(0);
  4168.                                 $salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());                           
  4169.                                 $salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());  
  4170.                                 $salesInv->setRateApplicable($row->getRateApplicable());
  4171.                                 $salesInv->setInvoiceType($shipmentObj->getShipmentType());
  4172.                                 $salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());   
  4173.                                 $salesInvoiceDetailsObj->setReference($row->getReference());                               
  4174.                                 $salesInvoiceDetailsObj->setWeight($row->getWeight());       
  4175.                                 $salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());                             
  4176.                                 $salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());                       
  4177.                                 $salesInvoiceDetailsObj->setCountry($row->getCountry());                               
  4178.                                 $salesInvoiceDetailsObj->setZone($row->getZone());
  4179.                                 $salesInvoiceDetailsObj->setProductType($row->getProductType());                               
  4180.                                 $salesInvoiceDetailsObj->setCourier($row->getCourier());                          
  4181.                                 $salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());                               
  4182.                                 $salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());
  4183.                                 if($row->getCustomer()->getRateCurrency() == 2)
  4184.                                 {
  4185.                                     $salesInvoiceDetailsObj->setCurrency(1);
  4186.                                 }
  4187.                                 else
  4188.                                 {
  4189.                                     $salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );
  4190.                                 }
  4191.                                 $salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  4192.                                 $salesInvoiceDetailsObj->setVatApplicable(0);
  4193.                                 $salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());
  4194.                                 
  4195.                                 if($row->getRateApplicable() <= 2)
  4196.                                     $salesInvoiceDetailsObj->setFsc$row->getCustomer()->getFsc() == $fscObj->getCurrency() : $row->getCustomer()->getFsc() ); 
  4197.                                 else
  4198.                                     $salesInvoiceDetailsObj->setFsc(0); 
  4199.                                 if($row->getRateApplicable() <= 3)
  4200.                                     $salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency()); 
  4201.                                 else
  4202.                                     $salesInvoiceDetailsObj->setVendorFsc(0); 
  4203.                                 
  4204.                                 $salesInvoiceDetailsObj->setCustomer($row->getCustomer());
  4205.                                 $salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null $row->getCovidCharge());
  4206.                                 $salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null $row->getVendorCovidCharge());
  4207.                                 $salesInvoiceDetailsObj->setShipment($row->getShipment());
  4208.                                 $salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());
  4209.                                 $salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());
  4210.                                 $salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());
  4211.                                 $salesInvoiceDetailsObj->setSro($row->getSro());
  4212.                                 // UPS Shipment Processing Fee Start 217
  4213.                                 if($row->getCourier()->getId() == && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2)
  4214.                                 {
  4215.                                     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4216.                                     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee
  4217.                                     $invoiceAdditionalChargeObj->setCharge(2.5);
  4218.                                     $invoiceAdditionalChargeObj->setFsc(0);
  4219.                                     $invoiceAdditionalChargeObj->setVat(0);
  4220.                                     $invoiceAdditionalChargeObj->setPayableCharge(2.5);
  4221.                                     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4222.                                 }
  4223.                                 // UPS Shipment Processing Fee Start
  4224.                                 
  4225.                                 //DHL Demand Charge Start
  4226.                                 if($row->getCourier()->getId() == && $shipmentDate $comparisonDate)
  4227.                                 {
  4228.                                     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4229.                                     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee
  4230.                                     $invoiceAdditionalChargeObj->setCharge($salesDemandCharge);
  4231.                                     $invoiceAdditionalChargeObj->setFsc(1);
  4232.                                     $invoiceAdditionalChargeObj->setVat(0);
  4233.                                     $invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);
  4234.                                     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4235.                                 }
  4236.                                 //DHL Demand Charge End
  4237.                                 $salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);
  4238.         
  4239.                                 $entityManager->persist($salesInv);
  4240.                                 $entityManager->flush($salesInv);   
  4241.                                 
  4242.                                 $salesInvoiceId $salesInv->getId();
  4243.         
  4244.                             }
  4245.                             else
  4246.                             {
  4247.                                 $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  4248.                                 $salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());   
  4249.                                 $salesInvoiceDetailsObj->setReference($row->getReference());                               
  4250.                                 $salesInvoiceDetailsObj->setWeight($row->getWeight());       
  4251.                                 $salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());                             
  4252.                                 $salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());                           
  4253.                                 $salesInvoiceDetailsObj->setCountry($row->getCountry());                               
  4254.                                 $salesInvoiceDetailsObj->setZone($row->getZone());
  4255.                                 $salesInvoiceDetailsObj->setProductType($row->getProductType());                               
  4256.                                 $salesInvoiceDetailsObj->setCourier($row->getCourier());                          
  4257.                                 $salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());                               
  4258.                                 $salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());
  4259.                                 if($row->getCustomer()->getRateCurrency() == 2)
  4260.                                 {
  4261.                                 $salesInvoiceDetailsObj->setCurrency(1);
  4262.                                 }
  4263.                                 else
  4264.                                 {
  4265.                                     $salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );
  4266.                                 }
  4267.                                 $salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  4268.                                 $salesInvoiceDetailsObj->setVatApplicable(0);
  4269.                                 $salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());
  4270.                                 if($row->getRateApplicable() <= 2)
  4271.                                     $salesInvoiceDetailsObj->setFsc$row->getCustomer()->getFsc() == $fscObj->getCurrency() : $row->getCustomer()->getFsc() ); 
  4272.                                 else
  4273.                                     $salesInvoiceDetailsObj->setFsc(0); 
  4274.                                 if($row->getRateApplicable() <= 3)
  4275.                                     $salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency()); 
  4276.                                 else
  4277.                                     $salesInvoiceDetailsObj->setVendorFsc(0); 
  4278.                                 $salesInvoiceDetailsObj->setCustomer($row->getCustomer());
  4279.                                 $salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null $row->getCovidCharge());
  4280.                                 $salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null $row->getVendorCovidCharge());                            
  4281.                                 $salesInvoiceDetailsObj->setSalesInvoice($salesInvoiceObj);
  4282.                                 $salesInvoiceDetailsObj->setShipment($row->getShipment());
  4283.                                 $salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());
  4284.                                 $salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());
  4285.                                 $salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());
  4286.                                 $salesInvoiceDetailsObj->setSro($row->getSro());
  4287.                                 // UPS Shipment Processing Fee Start
  4288.                                 if($row->getCourier()->getId() == && $row->getCountry()->getId() == 217  && $row->getRateApplicable() <= 2)
  4289.                                 {
  4290.                                     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4291.                                     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee
  4292.                                     $invoiceAdditionalChargeObj->setCharge(2.5);
  4293.                                     $invoiceAdditionalChargeObj->setFsc(0);
  4294.                                     $invoiceAdditionalChargeObj->setVat(0);
  4295.                                     $invoiceAdditionalChargeObj->setPayableCharge(2.5);
  4296.                                     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4297.                                 }
  4298.                                 // UPS Shipment Processing Fee Start
  4299.                                 
  4300.                                 //DHL Demand Charge Start
  4301.                                 if($row->getCourier()->getId() == && $shipmentDate $comparisonDate)
  4302.                                 {
  4303.                                     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4304.                                     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee
  4305.                                     $invoiceAdditionalChargeObj->setCharge($salesDemandCharge);
  4306.                                     $invoiceAdditionalChargeObj->setFsc(1);
  4307.                                     $invoiceAdditionalChargeObj->setVat(0);
  4308.                                     $invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);
  4309.                                     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4310.                                 }
  4311.                                 //DHL Demand Charge End
  4312.                                             
  4313.                                 $entityManager->persist($salesInvoiceDetailsObj);
  4314.                                 $entityManager->flush($salesInvoiceDetailsObj);
  4315.                             }
  4316.                         }
  4317.                         else if($row->getCustomer()->getInvoicePeriod() == 2//Half Monthly Invoice Save Process
  4318.                         {
  4319.                             if($shipmentDate <= $halfDateofMonth// First Half month
  4320.                             
  4321.                                 $salesInvoiceObj $salesInvoiceRepository
  4322.                                         ->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $halfDateofMonth$halfDateofMonth$shipmentObj->getShipmentType(), $row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );                              
  4323.                                 
  4324.                                 $invocieDate $halfDateofMonth;
  4325.                             }  
  4326.                             else
  4327.                             {
  4328.                                 $salesInvoiceObj $salesInvoiceRepository
  4329.                                     ->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(), $lastDateofMonth$lastDateofMonth$shipmentObj->getShipmentType(), $row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );                              
  4330.                                 $invocieDate $lastDateofMonth;
  4331.                             }
  4332.                             ////////////////Common portion
  4333.                             if($salesInvoiceObj === null)
  4334.                             {
  4335.                                 $salesInv = new SalesInvoice();
  4336.                                 $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  4337.                                 $salesInv->setCustomer($row->getCustomer());
  4338.                                 
  4339.                                 $salesInvocieLastObj $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());
  4340.                                 $invoiceNO $utilsService->invoiceNoGenerator($salesInvocieLastObj$row->getCustomer(), $invocieDate$shipmentObj->getShipmentType());
  4341.                                 $salesInv->setInvoiceNo($invoiceNO); 
  4342.                                 $salesInv->setInvoiceDate($invocieDate);                                         
  4343.                                 $salesInv->setVat($settingsObj->getVat());                          
  4344.                                 $salesInv->setApproval(0);
  4345.                                 $salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());                           
  4346.                                 $salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());  
  4347.                                 $salesInv->setRateApplicable($row->getRateApplicable());
  4348.                                 $salesInv->setInvoiceType($shipmentObj->getShipmentType());
  4349.                                 $salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());   
  4350.                                 $salesInvoiceDetailsObj->setReference($row->getReference());                               
  4351.                                 $salesInvoiceDetailsObj->setWeight($row->getWeight());       
  4352.                                 $salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());                             
  4353.                                 $salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());                       
  4354.                                 $salesInvoiceDetailsObj->setCountry($row->getCountry());                               
  4355.                                 $salesInvoiceDetailsObj->setZone($row->getZone());
  4356.                                 $salesInvoiceDetailsObj->setProductType($row->getProductType());                               
  4357.                                 $salesInvoiceDetailsObj->setCourier($row->getCourier());                          
  4358.                                 $salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());                               
  4359.                                 $salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());
  4360.                                 if($row->getCustomer()->getRateCurrency() == 2)
  4361.                                 {
  4362.                                 $salesInvoiceDetailsObj->setCurrency(1);
  4363.                                 }
  4364.                                 else
  4365.                                 {
  4366.                                     $salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );
  4367.                                 }
  4368.                                 $salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  4369.                                 $salesInvoiceDetailsObj->setVatApplicable(0);
  4370.                                 $salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());
  4371.                                 
  4372.                                 if($row->getRateApplicable() <= 2)
  4373.                                     $salesInvoiceDetailsObj->setFsc$row->getCustomer()->getFsc() == $fscObj->getCurrency() : $row->getCustomer()->getFsc() ); 
  4374.                                 else
  4375.                                     $salesInvoiceDetailsObj->setFsc(0); 
  4376.                                 if($row->getRateApplicable() <= 3)
  4377.                                     $salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency()); 
  4378.                                 else
  4379.                                     $salesInvoiceDetailsObj->setVendorFsc(0); 
  4380.                                 $salesInvoiceDetailsObj->setCustomer($row->getCustomer());
  4381.                                 $salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null $row->getCovidCharge());
  4382.                                 $salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null $row->getVendorCovidCharge());
  4383.                                 $salesInvoiceDetailsObj->setShipment($row->getShipment());
  4384.                                 $salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());
  4385.                                 $salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());
  4386.                                 $salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());
  4387.                                 $salesInvoiceDetailsObj->setSro($row->getSro());
  4388.                                 // UPS Shipment Processing Fee Start
  4389.                                 if($row->getCourier()->getId() == && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2)
  4390.                                 {
  4391.                                     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4392.                                     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee
  4393.                                     $invoiceAdditionalChargeObj->setCharge(2.5);
  4394.                                     $invoiceAdditionalChargeObj->setFsc(0);
  4395.                                     $invoiceAdditionalChargeObj->setVat(0);
  4396.                                     $invoiceAdditionalChargeObj->setPayableCharge(2.5);
  4397.                                     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4398.                                 }
  4399.                                 // UPS Shipment Processing Fee Start
  4400.                                 
  4401.                                 //DHL Demand Charge Start
  4402.                                 if($row->getCourier()->getId() == && $shipmentDate $comparisonDate)
  4403.                                 {
  4404.                                     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4405.                                     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee
  4406.                                     $invoiceAdditionalChargeObj->setCharge($salesDemandCharge);
  4407.                                     $invoiceAdditionalChargeObj->setFsc(1);
  4408.                                     $invoiceAdditionalChargeObj->setVat(0);
  4409.                                     $invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);
  4410.                                     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4411.                                 }
  4412.                                 //DHL Demand Charge End
  4413.                                 $salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);
  4414.         
  4415.                                 $entityManager->persist($salesInv);
  4416.                                 $entityManager->flush($salesInv);    
  4417.                                 
  4418.                                 $salesInvoiceId $salesInv->getId();
  4419.         
  4420.                             }
  4421.                             else
  4422.                             {
  4423.                                 $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  4424.                                 $salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());   
  4425.                                 $salesInvoiceDetailsObj->setReference($row->getReference());                               
  4426.                                 $salesInvoiceDetailsObj->setWeight($row->getWeight());       
  4427.                                 $salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());                             
  4428.                                 $salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());                           
  4429.                                 $salesInvoiceDetailsObj->setCountry($row->getCountry());                               
  4430.                                 $salesInvoiceDetailsObj->setZone($row->getZone());
  4431.                                 $salesInvoiceDetailsObj->setProductType($row->getProductType());                               
  4432.                                 $salesInvoiceDetailsObj->setCourier($row->getCourier());                          
  4433.                                 $salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());                               
  4434.                                 $salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());
  4435.                                 if($row->getCustomer()->getRateCurrency() == 2)
  4436.                                 {
  4437.                                 $salesInvoiceDetailsObj->setCurrency(1);
  4438.                                 }
  4439.                                 else
  4440.                                 {
  4441.                                     $salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );
  4442.                                 }
  4443.                                 $salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  4444.                                 $salesInvoiceDetailsObj->setVatApplicable(0);
  4445.                                 $salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable()); 
  4446.                                 if($row->getRateApplicable() <= 2)
  4447.                                     $salesInvoiceDetailsObj->setFsc$row->getCustomer()->getFsc() == $fscObj->getCurrency() : $row->getCustomer()->getFsc() ); 
  4448.                                 else
  4449.                                     $salesInvoiceDetailsObj->setFsc(0); 
  4450.                                 if($row->getRateApplicable() <= 3)
  4451.                                     $salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency()); 
  4452.                                 else
  4453.                                     $salesInvoiceDetailsObj->setVendorFsc(0); 
  4454.                                 $salesInvoiceDetailsObj->setCustomer($row->getCustomer());
  4455.                                 $salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null $row->getCovidCharge()); 
  4456.                                 $salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null $row->getVendorCovidCharge());                           
  4457.                                 $salesInvoiceDetailsObj->setSalesInvoice($salesInvoiceObj);
  4458.                                 $salesInvoiceDetailsObj->setShipment($row->getShipment());
  4459.                                 $salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());
  4460.                                 $salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());
  4461.                                 $salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());
  4462.                                 $salesInvoiceDetailsObj->setSro($row->getSro());
  4463.                                 // UPS Shipment Processing Fee Start
  4464.                                 if($row->getCourier()->getId() == && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2)
  4465.                                 {
  4466.                                     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4467.                                     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee
  4468.                                     $invoiceAdditionalChargeObj->setCharge(2.5);
  4469.                                     $invoiceAdditionalChargeObj->setFsc(0);
  4470.                                     $invoiceAdditionalChargeObj->setVat(0);
  4471.                                     $invoiceAdditionalChargeObj->setPayableCharge(2.5);
  4472.                                     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4473.                                 }
  4474.                                 // UPS Shipment Processing Fee Start
  4475.                                 
  4476.                                 //DHL Demand Charge Start
  4477.                                 if($row->getCourier()->getId() == && $shipmentDate $comparisonDate)
  4478.                                 {
  4479.                                     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4480.                                     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee
  4481.                                     $invoiceAdditionalChargeObj->setCharge($salesDemandCharge);
  4482.                                     $invoiceAdditionalChargeObj->setFsc(1);
  4483.                                     $invoiceAdditionalChargeObj->setVat(0);
  4484.                                     $invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);
  4485.                                     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4486.                                 }
  4487.                                 //DHL Demand Charge End
  4488.                                             
  4489.                                 $entityManager->persist($salesInvoiceDetailsObj);
  4490.                                 $entityManager->flush($salesInvoiceDetailsObj);
  4491.                             }
  4492.                             /////////////Common 
  4493.                         }
  4494.                         else if($row->getCustomer()->getInvoicePeriod() == 4//Weekly Invoice Save Process
  4495.                         {
  4496.                             $invoicePeriods = [
  4497.                                 ['start' => 1'end' => 7],
  4498.                                 ['start' => 8'end' => 15],
  4499.                                 ['start' => 16'end' => 22],
  4500.                                 ['start' => 23'end' => $lastDateofMonth],
  4501.                             ];
  4502.                             $invoicePeriod $this->getInvoicePeriod($row->getShipmentDate(), $invoicePeriods);
  4503.                            // return new JsonResponse(array('success' => false, 'responseText' => $invoicePeriod['start']. ' - ' . $invoicePeriod['end'] ));
  4504.                             $fromInvDate = clone $row->getShipmentDate();
  4505.                             $fromInvDate->setDate(
  4506.                                 $fromInvDate->format('Y'),  // Maintain the original year
  4507.                                 $fromInvDate->format('m'),  // Maintain the original month
  4508.                                 $invoicePeriod['start']                      // Set the new day
  4509.                             );
  4510.                             $toInvDate = clone $row->getShipmentDate();
  4511.                             $toInvDate->setDate(
  4512.                                 $toInvDate->format('Y'),  // Maintain the original year
  4513.                                 $toInvDate->format('m'),  // Maintain the original month
  4514.                                 $invoicePeriod['end']                      // Set the new day
  4515.                             );
  4516.                             $salesInvoiceObj $salesInvoiceRepository
  4517.                                         ->findSalesInvoiceObjbyCustomerandDateRange($row->getCustomer()->getId(),  $fromInvDate$toInvDate$shipmentObj->getShipmentType(), $row->getCustomer()->getInvoicePeriod(), $this->getUser()->getUserCompany()->getId() );                              
  4518.                            
  4519.                             if($salesInvoiceObj === null)
  4520.                             {
  4521.                                 $invocieDate $toInvDate;
  4522.                                 $salesInv = new SalesInvoice();
  4523.                                 $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  4524.                                 $salesInv->setCustomer($row->getCustomer());
  4525.                                 
  4526.                                 $salesInvocieLastObj $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());
  4527.                                 $invoiceNO $utilsService->invoiceNoGenerator($salesInvocieLastObj$row->getCustomer(), $invocieDate$shipmentObj->getShipmentType());
  4528.                                 $salesInv->setInvoiceNo($invoiceNO); 
  4529.                                 $salesInv->setInvoiceDate($invocieDate);                                         
  4530.                                 $salesInv->setVat($settingsObj->getVat());                          
  4531.                                 $salesInv->setApproval(0);
  4532.                                 $salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());                           
  4533.                                 $salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());  
  4534.                                 $salesInv->setRateApplicable($row->getRateApplicable());
  4535.                                 $salesInv->setInvoiceType($shipmentObj->getShipmentType());
  4536.                                 $salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());   
  4537.                                 $salesInvoiceDetailsObj->setReference($row->getReference());                               
  4538.                                 $salesInvoiceDetailsObj->setWeight($row->getWeight());       
  4539.                                 $salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());                             
  4540.                                 $salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());                       
  4541.                                 $salesInvoiceDetailsObj->setCountry($row->getCountry());                               
  4542.                                 $salesInvoiceDetailsObj->setZone($row->getZone());
  4543.                                 $salesInvoiceDetailsObj->setProductType($row->getProductType());                               
  4544.                                 $salesInvoiceDetailsObj->setCourier($row->getCourier());                          
  4545.                                 $salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());                               
  4546.                                 $salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());
  4547.                                 if($row->getCustomer()->getRateCurrency() == 2)
  4548.                                 {
  4549.                                 $salesInvoiceDetailsObj->setCurrency(1);
  4550.                                 }
  4551.                                 else
  4552.                                 {
  4553.                                     $salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );
  4554.                                 }
  4555.                                 $salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  4556.                                 $salesInvoiceDetailsObj->setVatApplicable(0);
  4557.                                 $salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());
  4558.                                 
  4559.                                 if($row->getRateApplicable() <= 2)
  4560.                                     $salesInvoiceDetailsObj->setFsc$row->getCustomer()->getFsc() == $fscObj->getCurrency() : $row->getCustomer()->getFsc() ); 
  4561.                                 else
  4562.                                     $salesInvoiceDetailsObj->setFsc(0); 
  4563.                                 if($row->getRateApplicable() <= 3)
  4564.                                     $salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency()); 
  4565.                                 else
  4566.                                     $salesInvoiceDetailsObj->setVendorFsc(0); 
  4567.                                 $salesInvoiceDetailsObj->setCustomer($row->getCustomer());
  4568.                                 $salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null $row->getCovidCharge());
  4569.                                 $salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null $row->getVendorCovidCharge());
  4570.                                 $salesInvoiceDetailsObj->setShipment($row->getShipment());
  4571.                                 $salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());
  4572.                                 $salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());
  4573.                                 $salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());
  4574.                                 $salesInvoiceDetailsObj->setSro($row->getSro());
  4575.                                 // UPS Shipment Processing Fee Start
  4576.                                 if($row->getCourier()->getId() == && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2)
  4577.                                 {
  4578.                                     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4579.                                     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee
  4580.                                     $invoiceAdditionalChargeObj->setCharge(2.5);
  4581.                                     $invoiceAdditionalChargeObj->setFsc(0);
  4582.                                     $invoiceAdditionalChargeObj->setVat(0);
  4583.                                     $invoiceAdditionalChargeObj->setPayableCharge(2.5);
  4584.                                     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4585.                                 }
  4586.                                 // UPS Shipment Processing Fee Start
  4587.                                 
  4588.                                 //DHL Demand Charge Start
  4589.                                 if($row->getCourier()->getId() == && $shipmentDate $comparisonDate)
  4590.                                 {
  4591.                                     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4592.                                     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee
  4593.                                     $invoiceAdditionalChargeObj->setCharge($salesDemandCharge);
  4594.                                     $invoiceAdditionalChargeObj->setFsc(1);
  4595.                                     $invoiceAdditionalChargeObj->setVat(0);
  4596.                                     $invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);
  4597.                                     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4598.                                 }
  4599.                                 //DHL Demand Charge End
  4600.                                 $salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);
  4601.         
  4602.                                 $entityManager->persist($salesInv);
  4603.                                 $entityManager->flush($salesInv);    
  4604.                                 
  4605.                                 $salesInvoiceId $salesInv->getId();
  4606.         
  4607.                             }
  4608.                             else
  4609.                             {
  4610.                                 $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  4611.                                 $salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());   
  4612.                                 $salesInvoiceDetailsObj->setReference($row->getReference());                               
  4613.                                 $salesInvoiceDetailsObj->setWeight($row->getWeight());       
  4614.                                 $salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());                             
  4615.                                 $salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());                           
  4616.                                 $salesInvoiceDetailsObj->setCountry($row->getCountry());                               
  4617.                                 $salesInvoiceDetailsObj->setZone($row->getZone());
  4618.                                 $salesInvoiceDetailsObj->setProductType($row->getProductType());                               
  4619.                                 $salesInvoiceDetailsObj->setCourier($row->getCourier());                          
  4620.                                 $salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());                               
  4621.                                 $salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());
  4622.                                 if($row->getCustomer()->getRateCurrency() == 2)
  4623.                                 {
  4624.                                 $salesInvoiceDetailsObj->setCurrency(1);
  4625.                                 }
  4626.                                 else
  4627.                                 {
  4628.                                     $salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );
  4629.                                 }
  4630.                                 $salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  4631.                                 $salesInvoiceDetailsObj->setVatApplicable(0);
  4632.                                 $salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable()); 
  4633.                                 if($row->getRateApplicable() <= 2)
  4634.                                     $salesInvoiceDetailsObj->setFsc$row->getCustomer()->getFsc() == $fscObj->getCurrency() : $row->getCustomer()->getFsc() ); 
  4635.                                 else
  4636.                                     $salesInvoiceDetailsObj->setFsc(0); 
  4637.                                 if($row->getRateApplicable() <= 3)
  4638.                                     $salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency()); 
  4639.                                 else
  4640.                                     $salesInvoiceDetailsObj->setVendorFsc(0); 
  4641.                                 $salesInvoiceDetailsObj->setCustomer($row->getCustomer());
  4642.                                 $salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null $row->getCovidCharge()); 
  4643.                                 $salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null $row->getVendorCovidCharge());                           
  4644.                                 $salesInvoiceDetailsObj->setSalesInvoice($salesInvoiceObj);
  4645.                                 $salesInvoiceDetailsObj->setShipment($row->getShipment());
  4646.                                 $salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());
  4647.                                 $salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());
  4648.                                 $salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());
  4649.                                 $salesInvoiceDetailsObj->setSro($row->getSro());
  4650.                                 // UPS Shipment Processing Fee Start
  4651.                                 if($row->getCourier()->getId() == && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2)
  4652.                                 {
  4653.                                     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4654.                                     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee
  4655.                                     $invoiceAdditionalChargeObj->setCharge(2.5);
  4656.                                     $invoiceAdditionalChargeObj->setFsc(0);
  4657.                                     $invoiceAdditionalChargeObj->setVat(0);
  4658.                                     $invoiceAdditionalChargeObj->setPayableCharge(2.5);
  4659.                                     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4660.                                 }
  4661.                                 // UPS Shipment Processing Fee Start
  4662.                                 
  4663.                                 //DHL Demand Charge Start
  4664.                                 if($row->getCourier()->getId() == && $shipmentDate $comparisonDate)
  4665.                                 {
  4666.                                     $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4667.                                     $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee
  4668.                                     $invoiceAdditionalChargeObj->setCharge($salesDemandCharge);
  4669.                                     $invoiceAdditionalChargeObj->setFsc(1);
  4670.                                     $invoiceAdditionalChargeObj->setVat(0);
  4671.                                     $invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);
  4672.                                     $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4673.                                 }
  4674.                                 //DHL Demand Charge End
  4675.                                             
  4676.                                 $entityManager->persist($salesInvoiceDetailsObj);
  4677.                                 $entityManager->flush($salesInvoiceDetailsObj);
  4678.                             }
  4679.             
  4680.                         }
  4681.                         else // HAWB NO Wise Invoice Save Process
  4682.                         {
  4683.                             $salesInv = new SalesInvoice();
  4684.                             $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  4685.                             $salesInv->setCustomer($row->getCustomer());
  4686.                             
  4687.                             $salesInvocieLastObj $salesInvoiceRepository->findLastSalesInvoiceObj($row->getCustomer()->getId());
  4688.                             $invoiceNO $utilsService->invoiceNoGenerator($salesInvocieLastObj$row->getCustomer(), $shipmentDate$shipmentObj->getShipmentType());
  4689.                             $salesInv->setInvoiceNo($invoiceNO); 
  4690.                             $salesInv->setInvoiceDate($shipmentDate);                                        
  4691.                             $salesInv->setVat($settingsObj->getVat());                          
  4692.                             $salesInv->setApproval(0);
  4693.                             $salesInv->setPaymentNote($this->getUser()->getUserCompany()->getPaymentNote());                           
  4694.                             $salesInv->setInvoicePeriod($row->getCustomer()->getInvoicePeriod());  
  4695.                             $salesInv->setRateApplicable($row->getRateApplicable());
  4696.                             $salesInv->setInvoiceType($shipmentObj->getShipmentType());
  4697.                             $salesInvoiceDetailsObj->setHawbNo($row->getHawbNo());   
  4698.                             $salesInvoiceDetailsObj->setReference($row->getReference());                               
  4699.                             $salesInvoiceDetailsObj->setWeight($row->getWeight());       
  4700.                             $salesInvoiceDetailsObj->setBookingWeight($row->getBookingWeight());                             
  4701.                             $salesInvoiceDetailsObj->setShipmentDate($row->getShipmentDate());                       
  4702.                             $salesInvoiceDetailsObj->setCountry($row->getCountry());                               
  4703.                             $salesInvoiceDetailsObj->setZone($row->getZone());
  4704.                             $salesInvoiceDetailsObj->setProductType($row->getProductType());                               
  4705.                             $salesInvoiceDetailsObj->setCourier($row->getCourier());                          
  4706.                             $salesInvoiceDetailsObj->setBookingRate($row->getBookingRate());                               
  4707.                             $salesInvoiceDetailsObj->setSalesRate($row->getSalesRate());
  4708.                             if($row->getCustomer()->getRateCurrency() == 2)
  4709.                             {
  4710.                                 $salesInvoiceDetailsObj->setCurrency(1);
  4711.                             }
  4712.                             else
  4713.                             {
  4714.                                 $salesInvoiceDetailsObj->setCurrency($row->getCustomer()->getCurrency() == $settingsObj->getCurrency() : $row->getCustomer()->getCurrency() );
  4715.                             }
  4716.                             $salesInvoiceDetailsObj->setVendorCurrency($row->getCourier()->getId() == ?  $settingsObj->getVendorCurrency() : $settingsObj->getCurrency());
  4717.                             $salesInvoiceDetailsObj->setVatApplicable(0);
  4718.                             $salesInvoiceDetailsObj->setRateApplicable($row->getRateApplicable());
  4719.                             if($row->getRateApplicable() <= 2)
  4720.                                 $salesInvoiceDetailsObj->setFsc$row->getCustomer()->getFsc() == $fscObj->getCurrency() : $row->getCustomer()->getFsc() ); 
  4721.                             else
  4722.                                 $salesInvoiceDetailsObj->setFsc(0); 
  4723.                             if($row->getRateApplicable() <= 3)
  4724.                                 $salesInvoiceDetailsObj->setVendorFsc($vendorFscObj->getCurrency()); 
  4725.                             else
  4726.                                 $salesInvoiceDetailsObj->setVendorFsc(0); 
  4727.    
  4728.                             $salesInvoiceDetailsObj->setCustomer($row->getCustomer());
  4729.                             $salesInvoiceDetailsObj->setCovidCharge($row->getCovidCharge() === null $row->getCovidCharge());
  4730.                             $salesInvoiceDetailsObj->setVendorCovidCharge($row->getVendorCovidCharge() === null $row->getVendorCovidCharge());
  4731.                             $salesInvoiceDetailsObj->setShipment($row->getShipment());
  4732.                             $salesInvoiceDetailsObj->setVatApplicable($row->getVatApplicable());
  4733.                             $salesInvoiceDetailsObj->setVendorVatApplicable($row->getVatApplicable());
  4734.                             $salesInvoiceDetailsObj->setSalesMasterRate($row->getSalesMasterRate());
  4735.                             $salesInvoiceDetailsObj->setSro($row->getSro());
  4736.                             // UPS Shipment Processing Fee Start
  4737.                             if($row->getCourier()->getId() == && $row->getCountry()->getId() == 217 && $row->getRateApplicable() <= 2)
  4738.                             {
  4739.                                 $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4740.                                 $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 3)); // 3 for Shipment Processing Fee
  4741.                                 $invoiceAdditionalChargeObj->setCharge(2.5);
  4742.                                 $invoiceAdditionalChargeObj->setFsc(0);
  4743.                                 $invoiceAdditionalChargeObj->setVat(0);
  4744.                                 $invoiceAdditionalChargeObj->setPayableCharge(2.5);
  4745.                                 $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4746.                             }
  4747.                             // UPS Shipment Processing Fee Start
  4748.                             
  4749.                             //DHL Demand Charge Start
  4750.                             if($row->getCourier()->getId() == && $shipmentDate $comparisonDate)
  4751.                             {
  4752.                                 $invoiceAdditionalChargeObj = new InvoiceAdditionalCharge();
  4753.                                 $invoiceAdditionalChargeObj->setAdditionalCharge($entityManager->find(AdditionalCharge::class, 8)); // 4 for Go Green Plus Fee
  4754.                                 $invoiceAdditionalChargeObj->setCharge($salesDemandCharge);
  4755.                                 $invoiceAdditionalChargeObj->setFsc(1);
  4756.                                 $invoiceAdditionalChargeObj->setVat(0);
  4757.                                 $invoiceAdditionalChargeObj->setPayableCharge($bookingDemandCharge);
  4758.                                 $salesInvoiceDetailsObj->addInvoiceAdditionalCharge($invoiceAdditionalChargeObj);
  4759.                             }
  4760.                             //DHL Demand Charge End
  4761.                             $salesInv->addSalesInvoiceDetail($salesInvoiceDetailsObj);
  4762.                             $entityManager->persist($salesInv);
  4763.                             $entityManager->flush($salesInv); 
  4764.                           
  4765.                         }
  4766.                         $index ++;
  4767.                     } 
  4768.                                 
  4769.                                 
  4770.                 }
  4771.                 
  4772.                 
  4773.             }
  4774.             $this->addFlash('notice''Sales Invoice Created successfully!');
  4775.                     
  4776.             return new JsonResponse(array('success' => true));    
  4777.     }
  4778.     
  4779.     
  4780.     #[Route('/salesinvoice/{id}/accessory-surcharge'name'app_sales_invoice_accessory_surcharge'methods: ['GET''POST'])]
  4781.     public function accessorySurcharge(SalesInvoice $salesInvoiceEntityManagerInterface $entityManagerRequest $requestSettingsInfoRepository $settingsInfoRepositoryCourierWiseZoneRepository $courierWiseZoneRepository): Response
  4782.     {
  4783.         $salesInvoice->getSalesInvoiceDetails()->clear();
  4784.         $form $this->createForm(InvoiceSurchargeType::class, $salesInvoice);
  4785.         $form->handleRequest($request);
  4786.         if ($form->isSubmitted() && $form->isValid()) {
  4787.             // Get Settings Currency Start
  4788.             $settingsObj $settingsInfoRepository
  4789.                         ->findByDateCurrency(1$salesInvoice->getInvoiceDate()->format('Y-m-d')); 
  4790.             if($settingsObj === null)
  4791.             {                                
  4792.                 
  4793.                 $this->addFlash('warning''Currency is not set in Settings for Month : '.$salesInvoice->getInvoiceDate()->format('F').'-'.$salesInvoice->getInvoiceDate()->format('Y'));
  4794.                                                                     
  4795.                 return $this->redirectToRoute('app_sales_invoice_show', ['id' => $salesInvoice->getId()]);     
  4796.             }                       
  4797.             // Get Settings Currency End
  4798.             foreach ($form->get('salesInvoiceDetails') as $formChild) {
  4799.               
  4800.                 $salesInvoiceDetailsObj = new SalesInvoiceDetails();
  4801.              
  4802.                 $salesInvoiceDetailsObj->setSalesInvoice($salesInvoice);
  4803.                 $salesInvoiceDetailsObj->setShipmentDate($formChild->get('shipmentDate')->getData());
  4804.                 $salesInvoiceDetailsObj->setHawbNo($formChild->get('hawbNo')->getData());
  4805.                 $salesInvoiceDetailsObj->setReference($formChild->get('reference')->getData());
  4806.                 $salesInvoiceDetailsObj->setCountry($formChild->get('country')->getData());
  4807.                 $salesInvoiceDetailsObj->setProductType($formChild->get('productType')->getData());
  4808.                 $salesInvoiceDetailsObj->setCourier($formChild->get('courier')->getData());
  4809.                 $courierWiseZoneObj $courierWiseZoneRepository
  4810.                                         ->findOneBy(['courier' => $formChild->get('courier')->getData()->getId(), 'country' => $formChild->get('country')->getData()->getId() ]);  
  4811.                 if($courierWiseZoneObj === null )
  4812.                 {
  4813.                     $this->addFlash('warning''Courier Wise Zone is not set for Courier : '.  $formChild->get('courier')->getData()->getName().', and Country : '.$formChild->get('country')->getData()->getName());
  4814.                     return $this->redirectToRoute('app_sales_invoice_show', ['id' => $salesInvoice->getId()]);     
  4815.                 }
  4816.                 $salesInvoiceDetailsObj->setZone($courierWiseZoneObj->getZone());
  4817.                 $salesInvoiceDetailsObj->setWeight($formChild->get('weight')->getData());
  4818.                 $salesInvoiceDetailsObj->setBookingWeight($formChild->get('weight')->getData());
  4819.                 
  4820.                 $salesInvoiceDetailsObj->setSalesRate($formChild->get('salesRate')->getData());
  4821.                 $salesInvoiceDetailsObj->setBookingRate($formChild->get('salesRate')->getData());
  4822.                 $salesInvoiceDetailsObj->setCurrency($settingsObj->getCurrency());
  4823.                 $salesInvoiceDetailsObj->setVendorCurrency($settingsObj->getVendorCurrency());
  4824.                 $salesInvoiceDetailsObj->setCovidCharge(0);
  4825.                 $salesInvoiceDetailsObj->setFsc(0);
  4826.                 $salesInvoiceDetailsObj->setVendorFsc(0);
  4827.                 $salesInvoiceDetailsObj->setVendorCovidCharge(0);
  4828.                 $salesInvoiceDetailsObj->setSalesMasterRate($formChild->get('salesRate')->getData());
  4829.                                
  4830.                 $entityManager->persist($salesInvoiceDetailsObj);
  4831.                 $entityManager->flush($salesInvoiceDetailsObj); 
  4832.             }
  4833.             $this->addFlash('notice''Accessory Surcharge Created successfully!');
  4834.             return $this->redirectToRoute('app_sales_invoice_show', ['id' => $salesInvoice->getId()]);         
  4835.         }
  4836.         return $this->renderForm('sales_invoice/accessorySurcharge.html.twig', [
  4837.             'salesInvoice' => $salesInvoice,
  4838.             'form' => $form,
  4839.         ]);
  4840.     }
  4841.     
  4842.     #[Route('/salesinvoice/country-wise-invoice'name'app_sales_invoice_country_wise_invoice'methods: ['GET''POST'])]
  4843.     public function countryWiseInvoice(Request $request)
  4844.     {
  4845.         $form $this->createFormBuilder(null)           
  4846.             ->add('fromDate'DateType::class, [
  4847.                 'attr' => ['class' => 'form-control'],
  4848.                 'widget' => 'single_text',
  4849.                 'empty_data' => null,
  4850.                 'label' => 'From Date',            
  4851.                 ])  
  4852.             ->add('toDate'DateType::class, [
  4853.                 'attr' => ['class' => 'form-control'],
  4854.                 'widget' => 'single_text',
  4855.                 'empty_data' => null,
  4856.                 'label' => 'To Date',                
  4857.                 ])   
  4858.             ->add('customer'EntityType::class, [
  4859.                 // looks for choices from this entity
  4860.                 'class' => Customer::class,
  4861.                 'query_builder' => function (CustomerRepository $er) {
  4862.                     return $er->createQueryBuilder('v'
  4863.                         ->where('v.userCompany = '.$this->getUser()->getUserCompany()->getId())                        
  4864.                         ->orderBy('v.name''ASC');
  4865.                 },                
  4866.                 // uses the User.username property as the visible option string
  4867.                 'choice_label' => 'name',
  4868.                 'placeholder' => 'Select a Customer...',
  4869.                 'attr' => [
  4870.                     'class' => 'form-control select-tags',
  4871.                     'style' => 'width:100%;',
  4872.                     ],
  4873.                 'label' => 'Customer',
  4874.                 // used to render a select box, check boxes or radios
  4875.                 // 'multiple' => true,
  4876.                 // 'expanded' => true,
  4877.                 ])
  4878.             ->add('country'EntityType::class, [
  4879.                 // looks for choices from this entity
  4880.                 'class' => Country::class,
  4881.                 'query_builder' => function (CountryRepository $er) {
  4882.                     return $er->createQueryBuilder('v')                                   
  4883.                         ->orderBy('v.name''ASC');
  4884.                 },                
  4885.                 // uses the User.username property as the visible option string
  4886.                 'choice_label' => 'name',
  4887.                 'placeholder' => 'Select a Country...',
  4888.                 'attr' => [
  4889.                     'class' => 'form-control select-tags',
  4890.                     'style' => 'width:100%;',
  4891.                     ],
  4892.                 'label' => 'Country',               
  4893.                 // used to render a select box, check boxes or radios
  4894.                 // 'multiple' => true,
  4895.                 // 'expanded' => true,
  4896.                 ])
  4897.         
  4898.             ->getForm();
  4899.         $form->handleRequest($request); 
  4900.                      
  4901.         if ($form->isSubmitted() && $form->isValid()) {
  4902.             $data $form->getData();                     
  4903.             $fromDate =  $form->get('fromDate')->getData()->format('Y-m-d');  
  4904.             $toDate =  $form->get('toDate')->getData()->format('Y-m-d'); 
  4905.             $customerId $form->get('customer')->getData()->getId();  
  4906.             $countryId $form->get('country')->getData()->getId();     
  4907.                
  4908.             $formInvoice $this->createFormBuilder(null)           
  4909.                     ->add('reference'EntityType::class, [
  4910.                         // looks for choices from this entity
  4911.                         'class' => SalesInvoiceDetails::class,
  4912.                         'query_builder' => function (SalesInvoiceDetailsRepository $er) use ($fromDate$toDate$customerId$countryId) {
  4913.                             return $er->createQueryBuilder('s')
  4914.                                     ->innerJoin('s.salesInvoice''i')   
  4915.                                     ->andWhere('i.invoiceType = 1')
  4916.                                     ->andWhere('s.shipmentDate BETWEEN :fromDate AND :toDate'
  4917.                                     ->andWhere('i.customer = :customerId')      
  4918.                                     ->andWhere('s.country = :countryId')                                                 
  4919.                                     ->setParameter('fromDate'$fromDate)
  4920.                                     ->setParameter('toDate'$toDate)    
  4921.                                     ->setParameter('customerId'$customerId)  
  4922.                                     ->setParameter('countryId'$countryId)            
  4923.                                     ->orderBy('s.shipmentDate''ASC')
  4924.                                     ->groupBy('s.reference');
  4925.                             },     
  4926.                         // uses the User.username property as the visible option string
  4927.                         'choice_label' => 'reference',
  4928.                         'placeholder' => 'Select a Reference No...',
  4929.                         'attr' => [
  4930.                             'class' => 'form-control select-tags',
  4931.                             ],
  4932.                         'label' => 'Reference',
  4933.                         // used to render a select box, check boxes or radios
  4934.                         // 'multiple' => true,
  4935.                         // 'expanded' => true,
  4936.                         ])
  4937.                     // ADD HIDDEN FIELDS                  
  4938.                     ->add('fromDate'HiddenType::class, [
  4939.                         'data' => $fromDate,
  4940.                     ])
  4941.                     ->add('toDate'HiddenType::class, [
  4942.                         'data' => $toDate,
  4943.                     ])
  4944.                     ->add('customer'HiddenType::class, [
  4945.                         'data' => $customerId,
  4946.                     ])       
  4947.                     ->add('country'HiddenType::class, [
  4948.                         'data' => $countryId,                       
  4949.                     ])          
  4950.                     ->getForm();
  4951.  
  4952.             $formInvoice->handleRequest($request); 
  4953.            
  4954.             return $this->render('sales_invoice/country_wise_invoice.html.twig', [
  4955.                 'formInvoice' => $formInvoice->createView(),       
  4956.                 'form' => $form->createView(),    
  4957.                 'track' => 1,
  4958.             ]);
  4959.         }
  4960.        
  4961.         $bookingObj = new SalesInvoiceDetails();
  4962.         
  4963.         return $this->render('sales_invoice/country_wise_invoice.html.twig', [
  4964.             'form' => $form->createView(),
  4965.             'bookingList' => $bookingObj,            
  4966.             'track' => 0,
  4967.         ]);
  4968.     }
  4969.        
  4970.     #[Route('/salesinvoice/country-sales-invoice-preview/'name'app_sales_invoice_country_sales_invoice_preview')]  
  4971.     #[IsGranted("ROLE_ADMIN")]
  4972.     public function countryWiseInvoicePreview(Request $requestReceiveVoucherRepository $receiveVoucherRepositoryShipmentRepository $shipmentRepositorySalesInvoiceRepository $salesInvoiceRepositorySettingsInfoRepository $settingsInfoRepositorySalesInvoiceDetailsRepository $repo)
  4973.     {
  4974.         $currencyType 1;
  4975.         $padPrint 1;
  4976.         // You must rebuild the SAME exact reference form again
  4977.         $formInvoice $this->createFormBuilder(null)
  4978.             ->add('reference'EntityType::class, [
  4979.                 'class' => SalesInvoiceDetails::class,
  4980.                 'choice_label' => 'reference',
  4981.             ])            
  4982.             ->add('fromDate'HiddenType::class)
  4983.             ->add('toDate'HiddenType::class)
  4984.             ->add('customer'HiddenType::class)
  4985.             ->add('country'HiddenType::class)            
  4986.             ->getForm();
  4987.         $formInvoice->handleRequest($request);
  4988.         if ($formInvoice->isSubmitted() && $formInvoice->isValid()) {
  4989.             $reference $formInvoice->get('reference')->getData()->getReference();
  4990.             // HIDDEN FIELD VALUES
  4991.             $fromDate  $formInvoice->get('fromDate')->getData();
  4992.             $toDate    $formInvoice->get('toDate')->getData();
  4993.             $customerId $formInvoice->get('customer')->getData();
  4994.             $countryId $formInvoice->get('country')->getData();
  4995.             $results $repo->createQueryBuilder('s')
  4996.                     ->innerJoin('s.salesInvoice''i')
  4997.                     ->andWhere('i.invoiceType = 1')
  4998.                     ->andWhere('s.shipmentDate BETWEEN :fromDate AND :toDate')
  4999.                     ->andWhere('i.customer = :customerId')      
  5000.                     ->andWhere('s.country = :countryId')  
  5001.                     ->andWhere('s.reference = :reference')                    
  5002.                     ->setParameter('fromDate'$fromDate)
  5003.                     ->setParameter('toDate'$toDate)
  5004.                     ->setParameter('customerId'$customerId)  
  5005.                     ->setParameter('countryId'$countryId)    
  5006.                     ->setParameter('reference'$reference)
  5007.                     ->orderBy('s.shipmentDate''ASC')
  5008.                     ->getQuery()
  5009.                     ->getResult();
  5010.            
  5011.             // Configure Dompdf according to your needs
  5012.             $pdfOptions = new Options();
  5013.             $pdfOptions->set('defaultFont''Arial');
  5014.                 
  5015.             // Instantiate Dompdf with our options
  5016.             $dompdf = new Dompdf($pdfOptions);
  5017.         
  5018.             $userObj $this->getUser();
  5019.                        
  5020.             $lastReceivedObj null;
  5021.                     
  5022.             $duesAmount 0;
  5023.     
  5024.             $groupByCourier null;
  5025.             
  5026.             $totalReceivedAmount =  0;
  5027.             $totalAdjustAmount =  0;          
  5028.             $uptoReceivedInvoiceDate 0;
  5029.         
  5030.             $html $this->renderView('sales_invoice/country_wise_invoice_preview.html.twig', [
  5031.                 'salesInvoice' => $results
  5032.                 'userObj' => $userObj,
  5033.                 'lastReceivedObj' => $lastReceivedObj,
  5034.                 'duesAmount' => $duesAmount $uptoReceivedInvoiceDate,
  5035.                 'userCompanyLogo' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/uploads/usercompanylogo/'$userObj->getUserCompany()->getLogoPath() ),         
  5036.                 'currencyType' => $currencyType,
  5037.                 'groupByCourier' => $groupByCourier,
  5038.                 'padPrint' => $padPrint,
  5039.                 'totalReceivedAmount' => $totalReceivedAmount,
  5040.                 'totalAdjustAmount' => $totalAdjustAmount,
  5041.             ]);
  5042.                     
  5043.             // Load HTML to Dompdf
  5044.             $dompdf->loadHtml($html);
  5045.             
  5046.             // (Optional) Setup the paper size and orientation 'portrait' or 'landscape'
  5047.             $dompdf->setPaper('A4''portrait');
  5048.             // Render the HTML as PDF
  5049.             $dompdf->render();
  5050.             //  Add Watermark in Domdpf
  5051.             // Instantiate canvas instance 
  5052.             $canvas $dompdf->getCanvas();
  5053.                 
  5054.             // Get the number of pages in the PDF
  5055.             $pageCount $canvas->get_page_count();
  5056.             if(== 0)
  5057.             {
  5058.                 $callback = function ($pageNumber) use ($pageCount$pdfOptions$canvas) {
  5059.                     // Set text opacity 
  5060.                     $canvas->set_opacity(0.2'Multiply');   
  5061.                     // Instantiate font metrics class 
  5062.                     $fontMetrics = new FontMetrics($canvas$pdfOptions);
  5063.                     // Get height and width of page 
  5064.                     $w $canvas->get_width(); 
  5065.                     $h $canvas->get_height(); 
  5066.                     
  5067.                     // Get font family file 
  5068.                     $font $fontMetrics->getFont('times'); 
  5069.                     
  5070.                     // Specify watermark text 
  5071.                     $text "DRAFT"
  5072.                     
  5073.                     // Get height and width of text 
  5074.                     $txtHeight $fontMetrics->getFontHeight($font75); 
  5075.                     $textWidth $fontMetrics->getTextWidth($text$font75); 
  5076.                                 
  5077.                     // Specify horizontal and vertical position 
  5078.                     $x = (($w-$textWidth)/2); 
  5079.                     $y = (($h-$txtHeight)/2); 
  5080.                     
  5081.                     // Writes text at the specified x and y coordinates 
  5082.                     $canvas->text($x$y$text$font75, array(000), 0'B');       
  5083.                 };
  5084.                 // Add the callback function to each page
  5085.                 for ($i 0$i $pageCount$i++) {        
  5086.                     $canvas->page_script($callback);        
  5087.                 }
  5088.             }
  5089.             
  5090.             // Page number and total page count Start
  5091.             // Define the callback function to add the page number and total page count
  5092.             $callback2 = function ($pageNumber) use ($pageCount$canvas) {
  5093.                 // Set text opacity             
  5094.                 $canvas->set_opacity(0.9'Multiply');
  5095.                 // Set the text and position for page number and total page count
  5096.                 $text 'Page ' $pageNumber ' of ' $pageCount;
  5097.                 $x 530// X-coordinate position
  5098.                 $y 813// Y-coordinate position
  5099.             
  5100.                 // Add the page number and total page count to the current page
  5101.                 $canvas->text($x$y$textnull10);
  5102.             };
  5103.         
  5104.             // Add the callback function to each page
  5105.             for ($i 0$i $pageCount$i++) {              
  5106.                 $canvas->page_script($callback2);        
  5107.             }
  5108.             // Output the generated PDF to Browser (force download)
  5109.             $dompdf->stream("Invoice.pdf", [
  5110.                 "Attachment" => false
  5111.             ]);
  5112.             exit(0);
  5113.             
  5114.         }
  5115.   
  5116.     
  5117.     }
  5118.     private function imageToBase64($path) {
  5119.         $path $path;
  5120.         $type pathinfo($pathPATHINFO_EXTENSION);
  5121.         $data file_get_contents($path);
  5122.         $base64 'data:image/' $type ';base64,' base64_encode($data);
  5123.         return $base64;
  5124.     }
  5125.     private function getInvoicePeriod(\DateTime $date, array $invoicePeriods): ?array
  5126.     {
  5127.         foreach ($invoicePeriods as $period) {
  5128.             if ($date->format('j') >= $period['start'] && $date->format('j') <= $period['end']) {
  5129.                 return $period;
  5130.             }
  5131.         }
  5132.         return null;
  5133.     }
  5134. }