src/Controller/ProjectManagement/InvoiceViewerController.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Controller\ProjectManagement;
  3. use App\Repository\DepartmentRepository;
  4. use App\Repository\ProjectRepository;
  5. use App\Repository\TimeSpentRepository;
  6. use App\Repository\TaskRepository;
  7. use App\Repository\UserRepository;
  8. use App\Repository\VendorRepository;
  9. use App\Service\CurrencyService;
  10. use App\Entity\Client;
  11. use App\Repository\ClientRepository;
  12. use App\Form\ProjectManagement\ClientType;
  13. use App\Repository\InvoiceRepository;
  14. use App\Repository\PurchaseOrderRepository;
  15. use App\Repository\SalesOrderInvoiceRepository;
  16. use App\Repository\SalesOrderRepository;
  17. use App\Repository\VendorInvoiceRepository;
  18. use App\Repository\XeroContactRepository;
  19. use App\Service\GoogleDriveService;
  20. use App\Service\UserService;
  21. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  22. use Symfony\Component\HttpFoundation\JsonResponse;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\HttpFoundation\Response;
  25. use Symfony\Component\Routing\Annotation\Route;
  26. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  27. use PhpOffice\PhpSpreadsheet\Style\Fill;
  28. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  29. use Symfony\Component\HttpFoundation\RedirectResponse;
  30. use Symfony\Contracts\Translation\TranslatorInterface;
  31. class InvoiceViewerController extends AbstractController
  32. {
  33.     /**
  34.      * @param ClientRepository $clientRepository
  35.      * @param ProjectRepository $projectRepository
  36.      * @param DepartmentRepository $departmentRepository
  37.      * @param TaskRepository $taskRepository
  38.      * @param Request $request
  39.      * @return Response
  40.      */
  41.     #[Route(path'/invoice-viewer'name'invoice_viewer')]
  42.     public function invoiceViewer(ProjectRepository $projectRepositoryClientRepository $clientRepositoryTaskRepository $taskRepositoryDepartmentRepository $departmentRepositoryRequest $requestTranslatorInterface $translator): Response
  43.     {
  44.         $user $this->getUser();
  45.         if (count(array_diff(['ROLE_FINANCE''ROLE_HR''ROLE_MANAGEMENT'], $user->getRoles())) == 0) {
  46.             throw new \Exception($translator->trans('messages.security.forbidden'));
  47.         };
  48.         $page  intval($request->query->get('page'));
  49.         $limit intval($request->query->get('limit'));
  50.         if ($limit === 0) {
  51.             $limit 20;
  52.         }
  53.         $keyword $request->get('keyword');
  54.         $order $request->get('order');
  55.         $orderBy $request->get('orderBy');
  56.         $clientsList $clientRepository->findByPage($page$limit$keyword,$order$orderBy);
  57.         $dataClient $clientRepository->findAll();
  58.         $clients $clientRepository->findByPage(09999"""ASC""");
  59.         $confirmedProjects $projectRepository->findByPage(09999""'ASC'"""""""CONFIRMED"0null0nullnullnullfalse);
  60.         return $this->render('private/invoice-viewer/invoice-viewer.html.twig', [
  61.             'clientList' => $clientsList,
  62.             'dataClient' => $dataClient,
  63.             'clients' => $clients,
  64.             'confirmedProjects' => $confirmedProjects,
  65.         ]);
  66.     }
  67.     /**
  68.      * @param ClientRepository $clientRepository
  69.      * @param ProjectRepository $projectRepository
  70.      * @param DepartmentRepository $departmentRepository
  71.      * @param TaskRepository $taskRepository
  72.      * @param Request $request
  73.      * @return Response
  74.      */
  75.     #[Route(path'/settings/finance'name'settings_finance')]
  76.     public function settingsFinance(ProjectRepository $projectRepositoryClientRepository $clientRepositoryTaskRepository $taskRepositoryDepartmentRepository $departmentRepositoryRequest $requestTranslatorInterface $translator): Response
  77.     {
  78.         $user $this->getUser();
  79.         if (count(array_diff(['ROLE_FINANCE''ROLE_HR''ROLE_MANAGEMENT'], $user->getRoles())) == 0) {
  80.             throw new \Exception($translator->trans('messages.security.forbidden'));
  81.         };
  82.         $page  intval($request->query->get('page'));
  83.         $limit intval($request->query->get('limit'));
  84.         if ($limit === 0) {
  85.             $limit 20;
  86.         }
  87.         $keyword $request->get('keyword');
  88.         $order $request->get('order');
  89.         $orderBy $request->get('orderBy');
  90.         $clientsList $clientRepository->findByPage($page$limit$keyword,$order$orderBy);
  91.         $dataClient $clientRepository->findAll();
  92.         $clients $clientRepository->findByPage(09999"""ASC""");
  93.         $confirmedProjects $projectRepository->findByPage(09999""'ASC'"""""""CONFIRMED"0null0nullnullnullfalse);
  94.         return $this->render('private/invoice-viewer/invoice-viewer-admin.html.twig', [
  95.             'clientList' => $clientsList,
  96.             'dataClient' => $dataClient,
  97.             'clients' => $clients,
  98.             'confirmedProjects' => $confirmedProjects,
  99.         ]);
  100.     }
  101.     /**
  102.      * @param SalesOrderRepository $salesOrderRepository
  103.      * @param Request $request
  104.      * @return Response
  105.      */
  106.     #[Route(path'/invoice-viewer/export/so/{_target}',  defaults: ['_target' => ''], name'export_invoice_so')]
  107.     public function exportSO(string $_targetSalesOrderRepository $salesOrderRepositoryXeroContactRepository $xeroContactRepositoryRequest $requestUserService $userServiceGoogleDriveService $googleDriveService): Response
  108.     {
  109.         $nonlinked $request->get('nonlinked');
  110.         $keyword $request->get('keyword');
  111.         $order $request->get('order');
  112.         $client $request->get('client');
  113.         $status $request->get('status');
  114.         $orderBy $request->get('orderBy');
  115.         $start $request->get('start');
  116.         $end $request->get('end');
  117.         $project $request->get('project');
  118.         $waitForPage $request->query->get('waitForPage');
  119.         $waitForPage === null $result['waitForPage'] = 'false' $result['waitForPage'] = $waitForPage;
  120.         $spreadsheet = new Spreadsheet();
  121.         $sheet $spreadsheet->getActiveSheet();
  122.         $sheet->setCellValue('A1''SO Number');
  123.         $sheet->setCellValue('B1''Xero Client');
  124.         $sheet->setCellValue('C1''Amount');
  125.         $sheet->setCellValue('D1''Allocated');
  126.         $sheet->setCellValue('E1''Amount Left');
  127.         $sheet->setCellValue('F1''Invoice');
  128.         $sheet->setCellValue('G1''INV Amount');
  129.         $sheet->setCellValue('H1''CN Number');
  130.         $sheet->setCellValue('I1''PO Number');
  131.         $sheet->setCellValue('J1''Client');
  132.         $sheet->setCellValue('K1''Project');
  133.         $sheet->setCellValue('L1''SO PIC');
  134.         $sheet->setCellValue('M1''Issue Date');
  135.         $sheet->setCellValue('N1''SO Status');
  136.         $sheet->getDefaultColumnDimension()->setWidth(25);
  137.         $sheet->getStyle("A1:"$sheet->getHighestColumn() ."1")->getFont()->setBold(true);
  138.         $sheet->getStyle("A1:"$sheet->getHighestColumn() ."1")->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
  139.         $sheet->getStyle("A1:"$sheet->getHighestColumn() ."1")->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('00000000');
  140.         $sheet->getStyle("A2:"$sheet->getHighestColumn() ."2")->getFont()->setBold(false);
  141.         $sheet->getStyle("A2:"$sheet->getHighestColumn() ."2")->getAlignment()->setWrapText(true);
  142.         $sheet->getStyle("A2:"$sheet->getHighestColumn() ."2")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP);
  143.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  144.         $salesOrdersList $salesOrderRepository->findByPage(09999$keyword$order$orderBy$project$nonlinked$client$status$start$end);
  145.         $filename =  'Sales-Orders_' $status .'_'date('Y-m-d') . '.xlsx';
  146.         $row $sheet->getHighestRow();
  147.         foreach($salesOrdersList as $salesOrder){
  148.             $initiateRow $row;
  149.             $sheet->setCellValue('A'.$row$salesOrder->getSalesOrderNo());
  150.             $xeroContact $xeroContactRepository->findOneBy(['xeroContactId' => $salesOrder->getXeroContactId()]);
  151.             $sheet->setCellValue('B'.$row$xeroContact $xeroContact->getName() : '-');
  152.             $sheet->setCellValue('C'.$row$salesOrder->getSubTotalUsd());
  153.             $sheet->setCellValue('D'.$row$salesOrder->getProjectSalesOrderTotalAmountUsedUsd());
  154.             $sheet->setCellValue('E'.$row$salesOrder->getSubTotalUsd() - $salesOrder->getProjectSalesOrderTotalAmountUsedUsd());
  155.             $sheet->setCellValue('L'.$row$salesOrder->getCreator());
  156.             $sheet->setCellValue('M'.$row$salesOrder->getQuoteDate() ? $salesOrder->getQuoteDate()->format("d/m/Y") : '-');
  157.             $sheet->setCellValue('N'.$row$salesOrder->getXeroStatus());
  158.             $invoices $salesOrder->getSalesOrderInvoices();
  159.             /*
  160.             $soInvoices = [];
  161.             foreach ($invoices as $soInvoice){
  162.                 $invoice = $soInvoice->getInvoice();
  163.                 array_push($soInvoices, $invoice->getInvoiceNo());
  164.             }
  165.             $sheet->setCellValue('F'.$row,implode(', ', $soInvoices));
  166.             */
  167.             $invoiceRow $row;
  168.             if (count($invoices) > 0){
  169.                 foreach($salesOrder->getSalesOrderInvoices() as $invoice){
  170.                     $sheet->setCellValue('F'.$invoiceRow,$invoice->getInvoice()->getInvoiceNo());
  171.                     $sheet->setCellValue('G'.$invoiceRow,$invoice->getAmountUsd());
  172.                     $creditNote $invoice->getInvoice()->getXeroCreditNoteAllocation();
  173.                     $sheet->setCellValue('H'.$invoiceRow$creditNote $creditNote->getXeroCreditNote()->getCreditNoteNo() : '-');
  174.                     $invoiceRow++;
  175.                 }
  176.             }else{
  177.                 $sheet->setCellValue('F'.$invoiceRow"-");
  178.                 $sheet->setCellValue('G'.$invoiceRow"-");
  179.             }
  180.             $purchases $salesOrder->getSalesOrderPurchaseOrders();
  181.             $purchasesRow $row;
  182.             if(count($purchases) > 0){
  183.                 foreach($purchases as $po){
  184.                     $sheet->setCellValue('I'.$purchasesRow$po->getPurchaseOrder()->getPurchaseOrderNo());
  185.                     $purchasesRow++;
  186.                 }
  187.             }else{
  188.                 $sheet->setCellValue('I'.$purchasesRow"-");
  189.             }
  190.             $projectSORow $row;
  191.             $projectSalesOrders $salesOrder->getProjectSalesOrders();
  192.             
  193.             if(count($projectSalesOrders) > 0){
  194.                 foreach($projectSalesOrders as $pso){
  195.                     $sheet->setCellValue('J'.$projectSORow$pso->getProject()->getClient()->getName());
  196.                     $sheet->setCellValue('K'.$projectSORow$pso->getProject()->getName());
  197.                     $sheet->getCell('K' $projectSORow)->getHyperlink()->setUrl($baseurl '/project-management/project/view/' $pso->getProject()->getId());
  198.                     $sheet->getStyle('K' $projectSORow)->getFont()->setUnderline(true);
  199.                     $projectSORow++;
  200.                 }
  201.             }else{
  202.                 $sheet->setCellValue('J'.$projectSORow"-");
  203.                 $sheet->setCellValue('K'.$projectSORow"-");
  204.             }
  205.             $allRow = [$projectSORow$purchasesRow$invoiceRow];
  206.             $maxRow max($allRow);
  207.             $row $maxRow == $row $row $maxRow;
  208.             /*
  209.             $PurchaseOrders = [];
  210.             foreach ($purchases as $purchase){
  211.                 $po = $purchase->getPurchaseOrder();
  212.                 array_push($PurchaseOrders, $po->getPurchaseOrderNo());
  213.             }
  214.             $sheet->setCellValue('G'.$row, implode(', ', $PurchaseOrders));
  215.             */
  216.             if(count($invoices) > || count($purchases) > || count($projectSalesOrders) > 0){
  217.                 $sheet->mergeCells('A'.$initiateRow.':A'.($row 1));
  218.                 $sheet->mergeCells('B'.$initiateRow.':B'.($row 1));
  219.                 $sheet->mergeCells('C'.$initiateRow.':C'.($row 1));
  220.                 $sheet->mergeCells('D'.$initiateRow.':D'.($row 1));
  221.                 $sheet->mergeCells('E'.$initiateRow.':E'.($row 1));
  222.                 $sheet->mergeCells('K'.$initiateRow.':K'.($row 1));
  223.                 $sheet->mergeCells('L'.$initiateRow.':L'.($row 1));
  224.                 $sheet->mergeCells('M'.$initiateRow.':M'.($row 1));
  225.                 $sheet->mergeCells('N'.$initiateRow.':N'.($row 1));
  226.                 $sheet->getStyle('A'.$initiateRow.':A'.($row 1))->getAlignment()->setVertical('center');
  227.                 $sheet->getStyle('B'.$initiateRow.':B'.($row 1))->getAlignment()->setVertical('center');
  228.                 $sheet->getStyle('C'.$initiateRow.':C'.($row 1))->getAlignment()->setVertical('center');
  229.                 $sheet->getStyle('D'.$initiateRow.':D'.($row 1))->getAlignment()->setVertical('center');
  230.                 $sheet->getStyle('E'.$initiateRow.':E'.($row 1))->getAlignment()->setVertical('center');
  231.                 $sheet->getStyle('K'.$initiateRow.':K'.($row 1))->getAlignment()->setVertical('center');
  232.                 $sheet->getStyle('L'.$initiateRow.':L'.($row 1))->getAlignment()->setVertical('center');
  233.                 $sheet->getStyle('M'.$initiateRow.':M'.($row 1))->getAlignment()->setVertical('center');
  234.                 $sheet->getStyle('N'.$initiateRow.':N'.($row 1))->getAlignment()->setVertical('center');
  235.                 if(count($projectSalesOrders) == 1){
  236.                     $sheet->mergeCells('J'.$initiateRow.':J'.($row 1));
  237.                     $sheet->mergeCells('K'.$initiateRow.':K'.($row 1));
  238.                     $sheet->getStyle('J'.$initiateRow.':J'.($row 1))->getAlignment()->setVertical('center');
  239.                     $sheet->getStyle('K'.$initiateRow.':K'.($row 1))->getAlignment()->setVertical('center');
  240.                 }
  241.             }
  242.             
  243.         }
  244.         $sheet->setAutoFilter('A1:'$sheet->getHighestColumn() . $sheet->getHighestRow());
  245.         // $sheet->getStyle('C2:E' . $sheet->getHighestRow())->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2);
  246.         // $sheet->getStyle('F2:F' . $sheet->getHighestRow())->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2);
  247.         $sheet->getStyle('C2:E' $sheet->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00;(#,##0.00)');
  248.         $sheet->getStyle('F2:F' $sheet->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00;(#,##0.00)');
  249.         $writer = new Xlsx($spreadsheet);
  250.         $writer->save($filename);
  251.         // Set the content-type:
  252.         if($_target == 'google'){
  253.             $gsheetURL $googleDriveService->uploadToGoogleDrive($filename);
  254.             if($gsheetURL){
  255.                 unlink($filename);
  256.                 return new RedirectResponse($gsheetURL302);
  257.             }
  258.         }else{
  259.             $response = new Response();
  260.             $response->headers->set('Content-type''application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  261.             $response->headers->set('Content-Disposition'sprintf('attachment; filename="%s"'$filename));
  262.             $response->setContent(file_get_contents($filename));
  263.             $response->setStatusCode(\Symfony\Component\HttpFoundation\Response::HTTP_OK);
  264.             $response->headers->set('Content-Transfer-Encoding''binary');
  265.             $response->headers->set('Pragma''no-cache');
  266.             $response->headers->set('Expires''0');
  267.             unlink($filename);
  268.             return $response;
  269.             exit;
  270.         }   
  271.     }
  272.     /**
  273.      * @param PurchaseOrderRepository $purchaseOrderRepository
  274.      * @param Request $request
  275.      * @return Response
  276.      */
  277.     #[Route(path'/invoice-viewer/export/po/{_target}'defaults: ['_target' => ''], name'export_invoice_po')]
  278.     public function exportPO(string $_targetPurchaseOrderRepository $purchaseOrderRepositoryXeroContactRepository $xeroContactRepositoryRequest $requestGoogleDriveService $googleDriveService): Response
  279.     {
  280.         $keyword $request->get('keyword');
  281.         $order $request->get('order');
  282.         $client $request->get('client');
  283.         $status $request->get('status');
  284.         $orderBy $request->get('orderBy');
  285.         $start $request->get('start');
  286.         $end $request->get('end');
  287.         $waitForPage $request->query->get('waitForPage');
  288.         $waitForPage === null $result['waitForPage'] = 'false' $result['waitForPage'] = $waitForPage;
  289.         $spreadsheet = new Spreadsheet();
  290.         $sheet $spreadsheet->getActiveSheet();
  291.         $sheet->setCellValue('A1''PO Number');
  292.         $sheet->setCellValue('B1''Amount');
  293.         $sheet->setCellValue('C1''Client');
  294.         $sheet->setCellValue('D1''Project');
  295.         $sheet->setCellValue('E1''Amount Allocated');
  296.         $sheet->setCellValue('F1''Total Allocated');
  297.         $sheet->setCellValue('G1''Amount Left');
  298.         $sheet->setCellValue('H1''PO Date');
  299.         $sheet->setCellValue('I1''Cancel Note');
  300.         $lastCol $sheet->getHighestColumn();
  301.         $sheet->getDefaultColumnDimension()->setWidth(25);
  302.         $sheet->getStyle("A1:".$lastCol."1")->getFont()->setBold(true);
  303.         $sheet->getStyle("A1:".$lastCol."1")->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
  304.         $sheet->getStyle("A1:".$lastCol."1")->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('00000000');
  305.         $sheet->getStyle("A2:".$lastCol."2")->getFont()->setBold(false);
  306.         $sheet->getStyle("A2:".$lastCol."2")->getAlignment()->setWrapText(true);
  307.         $sheet->getStyle("A2:".$lastCol."2")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP);
  308.         $purchaseOrderList $purchaseOrderRepository->findByPage(099999$keyword$order$orderBy$status$client$start$end);
  309.         $filename =  'Purchase-Orders_'date('Y-m-d') . '.xlsx';
  310.         $row $sheet->getHighestRow();
  311.         foreach($purchaseOrderList as $purchaseOrder){
  312.             $sheet->setCellValue('A'.$row'PO-'.$purchaseOrder->getPurchaseOrderNo());
  313.             $sheet->setCellValue('B'.$row$purchaseOrder->getAmountUsd());
  314.             $sheet->setCellValue('C'.$row$purchaseOrder->getClient() ? $purchaseOrder->getClient()->getName() : '-');
  315.             $sheet->setCellValue('F'.$row$purchaseOrder->getTotalAllocatedUsd());
  316.             $sheet->setCellValue('G'.$row$purchaseOrder->getAmountLeftUsd());
  317.             $sheet->setCellValue('H'.$row$purchaseOrder->getDate()->format("d-M-Y"));
  318.             $sheet->setCellValue('I'.$row$purchaseOrder->getCancelNote());
  319.             if ($purchaseOrder->getCancelNote()) {
  320.                 $sheet->getStyle('A'.$row.':I'.$row)->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('FFFF00'); // Yellow color
  321.             }
  322.             $salesOrderPurchaseOrders $purchaseOrder->getSalesOrderPurchaseOrders()->toArray();
  323.             // dd($salesOrderPurchaseOrders);
  324.             $mergeRow $row;
  325.             if(count($salesOrderPurchaseOrders) > 0){
  326.                 foreach($salesOrderPurchaseOrders as $salesOrderPurchaseOrder){
  327.                     $sheet->setCellValue('D'.$mergeRow$salesOrderPurchaseOrder->getProject() ? $salesOrderPurchaseOrder->getProject()->getName() : '-');
  328.                     $sheet->setCellValue('E'.$mergeRow$salesOrderPurchaseOrder->getAmountUsd());
  329.                     $mergeRow count($salesOrderPurchaseOrders) > $mergeRow+$mergeRow;
  330.                 }
  331.                 
  332.                 if(count($salesOrderPurchaseOrders) > && $mergeRow $row){
  333.                     $sheet->mergeCells("A$row:A".($mergeRow 1));
  334.                     $sheet->mergeCells("B$row:B".($mergeRow 1));
  335.                     $sheet->mergeCells("C$row:C".($mergeRow 1));
  336.                     $sheet->mergeCells("F$row:F".($mergeRow 1));
  337.                     $sheet->mergeCells("G$row:G".($mergeRow 1));
  338.                     $sheet->mergeCells("H$row:H".($mergeRow 1));
  339.                     $sheet->mergeCells("I$row:I".($mergeRow 1));
  340.                     $sheet->getStyle("A$row:A".($mergeRow 1))->getAlignment()->setVertical('center');
  341.                     $sheet->getStyle("B$row:B".($mergeRow 1))->getAlignment()->setVertical('center');
  342.                     $sheet->getStyle("C$row:C".($mergeRow 1))->getAlignment()->setVertical('center');
  343.                     $sheet->getStyle("F$row:F".($mergeRow 1))->getAlignment()->setVertical('center');
  344.                     $sheet->getStyle("G$row:G".($mergeRow 1))->getAlignment()->setVertical('center');
  345.                     $sheet->getStyle("H$row:H".($mergeRow 1))->getAlignment()->setVertical('center');
  346.                     $sheet->getStyle("I$row:I".($mergeRow 1))->getAlignment()->setVertical('center');
  347.                 }
  348.             }else{
  349.                 $sheet->setCellValue('D'.$row'-');
  350.                 $sheet->setCellValue('E'.$row'-');
  351.             }
  352.             $row $mergeRow == $row $row+$mergeRow;
  353.         }
  354.         $sheet->setAutoFilter('A1:'.$sheet->getHighestColumn(). $sheet->getHighestRow());
  355.         $sheet->getStyle('B2:B' $sheet->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00;(#,##0.00)');
  356.         $sheet->getStyle('E2:G' $sheet->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00;(#,##0.00)');
  357.         $writer = new Xlsx($spreadsheet);
  358.         $writer->save($filename);
  359.         // Set the content-type:
  360.         if($_target == 'google'){
  361.             $gsheetURL $googleDriveService->uploadToGoogleDrive($filename);
  362.             if($gsheetURL){
  363.                 unlink($filename);
  364.                 return new RedirectResponse($gsheetURL302);
  365.             }
  366.         }else{
  367.             $response = new Response();
  368.             $response->headers->set('Content-type''application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  369.             $response->headers->set('Content-Disposition'sprintf('attachment; filename="%s"'$filename));
  370.             $response->setContent(file_get_contents($filename));
  371.             $response->setStatusCode(\Symfony\Component\HttpFoundation\Response::HTTP_OK);
  372.             $response->headers->set('Content-Transfer-Encoding''binary');
  373.             $response->headers->set('Pragma''no-cache');
  374.             $response->headers->set('Expires''0');
  375.             unlink($filename);
  376.             return $response;
  377.             exit;
  378.         }  
  379.     }
  380.     
  381.     /**
  382.      * @param InvoiceRepository $invoiceRepository
  383.      * @param Request $request
  384.      * @return Response
  385.      */
  386.     #[Route(path'/invoice-viewer/export/client/{_target}'defaults: ['_target' => ''], name'export_invoice_client')]
  387.     public function exportClientInvoice(string $_targetInvoiceRepository $invoiceRepositoryXeroContactRepository $xeroContactRepositoryRequest $requestUserService $userServiceGoogleDriveService $googleDriveService): Response
  388.     {
  389.         $keyword $request->get('keyword');
  390.         $order $request->get('order');
  391.         $client $request->get('client');
  392.         $status $request->get('status');
  393.         $orderBy $request->get('orderBy');
  394.         $start $request->get('start');
  395.         $end $request->get('end');
  396.         $waitForPage $request->query->get('waitForPage');
  397.         $waitForPage === null $result['waitForPage'] = 'false' $result['waitForPage'] = $waitForPage;
  398.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  399.         $spreadsheet = new Spreadsheet();
  400.         $sheet $spreadsheet->getActiveSheet();
  401.         $sheet->setCellValue('A1''Invoice');
  402.         $sheet->setCellValue('B1''Xero Client');
  403.         $sheet->setCellValue('C1''Currency');
  404.         $sheet->setCellValue('D1''Amount');
  405.         $sheet->setCellValue('E1''Amount Left');
  406.         $sheet->setCellValue('F1''Allocated');
  407.         $sheet->setCellValue('G1''SO Number');
  408.         $sheet->setCellValue('H1''PO Number');
  409.         $sheet->setCellValue('I1''CN Number');
  410.         $sheet->setCellValue('J1''Client');
  411.         $sheet->setCellValue('K1''Project');
  412.         $sheet->setCellValue('L1''INV PIC');
  413.         $sheet->setCellValue('M1''Due');
  414.         $sheet->setCellValue('N1''Status');
  415.         $sheet->getDefaultColumnDimension()->setWidth(25);
  416.         $sheet->getStyle("A1:"$sheet->getHighestColumn() ."1")->getFont()->setBold(true);
  417.         $sheet->getStyle("A1:"$sheet->getHighestColumn() ."1")->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
  418.         $sheet->getStyle("A1:"$sheet->getHighestColumn() ."1")->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('00000000');
  419.         $sheet->getStyle("A2:"$sheet->getHighestColumn() ."2")->getFont()->setBold(false);
  420.         $sheet->getStyle("A2:"$sheet->getHighestColumn() ."2")->getAlignment()->setWrapText(true);
  421.         $sheet->getStyle("A2:"$sheet->getHighestColumn() ."2")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP);
  422.         $invoicesList $invoiceRepository->findByPage(099999$keyword$order$orderBy$status$client$start$end);
  423.         // dd($invoicesList);
  424.         $filename =  'Invoices_' .$status.'_'date('Y-m-d') . '.xlsx';
  425.         
  426.         $row $sheet->getHighestRow();
  427.         foreach($invoicesList as $invoice){
  428.             $sheet->setCellValue('A'.$row$invoice->getInvoiceNo());
  429.             $xeroContact $xeroContactRepository->findOneBy(['xeroContactId' => $invoice->getXeroContactId()]);
  430.             //$invoice->xeroContactName = $xeroContact ? $xeroContact->getName() : null;
  431.             
  432.             $sheet->setCellValue('B'.$row,  $xeroContact $xeroContact->getName() : '-');
  433.             $sheet->setCellValue('C'.$row$invoice->getCurrency ()->getIso());
  434.             $sheet->setCellValue('D'.$row$invoice->getSubTotalUsd() ?: '-');
  435.             $creditNote $invoice->getXeroCreditNoteAllocation();
  436.             $sheet->setCellValue('I'.$row$creditNote $creditNote->getXeroCreditNote()->getCreditNoteNo() : '-');
  437.             $sheet->setCellValue('L'.$row$invoice->getCreator());
  438.             $sheet->setCellValue('M'.$row$invoice->getDueDate() ? $invoice->getDueDate()->format('d M Y') : "");
  439.             $sheet->setCellValue('N'.$row$invoice->getXeroStatus() == 'AUTHORISED''NOT PAID' $invoice->getXeroStatus());
  440.             
  441.             $soInvoices $invoice->getSalesOrderInvoices();
  442.             // Amount Left
  443.             $amountLeft '-';
  444.             if(count($soInvoices) > 0){
  445.                 $amountLeft $invoice->getSubTotalUsd() - $invoice->getTotalAmountUsedUsd(); 
  446.             }
  447.             $sheet->setCellValue('E'.$row$amountLeft);
  448.             // Allocated
  449.             $allocatedRow  $row;
  450.             if(count($soInvoices) > 0){
  451.                 foreach($soInvoices as $soInvoice){
  452.                     $sheet->setCellValue('F'.$row$soInvoice->getAmountUsd() ?: '-');
  453.                     $sheet->setCellValue('G'.$row$soInvoice->getSalesOrder()->getSalesOrderNo());
  454.                     $sheet->setCellValue('J'.$row$soInvoice->getProject() ? $soInvoice->getProject()->getClient()->getName() : '-');
  455.                     $sheet->setCellValue('K'.$row$soInvoice->getProject() ? $soInvoice->getProject()->fullName() : '-');
  456.                     $sheet->getCell('K' $row)->getHyperlink()->setUrl($baseurl '/project-management/project/view/' $soInvoice->getProject()->getId());
  457.                     $sheet->getStyle('K' $row)->getFont()->setUnderline(true);
  458.                     // $allocatedRow++;
  459.                     $purchases $soInvoice->getSalesOrder()->getSalesOrderPurchaseOrders();
  460.                     if(count($purchases) > 0){
  461.                         foreach($purchases as $purchase){
  462.                             $sheet->setCellValue('H'.$row$purchase->getPurchaseOrder()->getPurchaseOrderNo());
  463.                             $row++;
  464.                         }
  465.                     }else{
  466.                         $sheet->setCellValue('H'.$row,'-');
  467.                          $row++;
  468.                     }
  469.                     // $row++;
  470.                 }
  471.             }else{
  472.                 $sheet->setCellValue('F'.$row,'-');
  473.                 $sheet->setCellValue('G'.$row,'-');
  474.                 $row++;
  475.             }
  476.             // Client
  477.             // PO Number
  478.             /*
  479.             $salesOrderInvoices = $invoice->getSalesOrderInvoices();
  480.             $salesOrderNums = [];
  481.             $PONums = [];
  482.             foreach ($salesOrderInvoices as $salesOrderInvoice){
  483.                 $salesOrder = $salesOrderInvoice->getSalesOrder();
  484.                 array_push($salesOrderNums, $salesOrder->getSalesOrderNo());
  485.                 
  486.                 $salesOrderPurchaseOrders = null;
  487.                 if($salesOrder){
  488.                     $salesOrderPurchaseOrders = $salesOrder->getSalesOrderPurchaseOrders();
  489.                 }
  490.                 foreach ($salesOrderPurchaseOrders as $salesOrderPurchaseOrder) {
  491.                     $poNum = $salesOrderPurchaseOrder->getPurchaseOrder() ? $salesOrderPurchaseOrder->getPurchaseOrder()->getPurchaseOrderNo() : "";
  492.                     array_push($PONums, $poNum);
  493.                 }
  494.             }
  495.             */
  496.             // $row++;
  497.         }
  498.         $sheet->setAutoFilter('A1:'$sheet->getHighestColumn() . $sheet->getHighestRow());
  499.         // $sheet->getStyle('D2:F' . $sheet->getHighestRow())->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2);
  500.         $sheet->getStyle('D2:F' $sheet->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00;(#,##0.00)');
  501.         $writer = new Xlsx($spreadsheet);
  502.         $writer->save($filename);
  503.         // Set the content-type:
  504.         if($_target == 'google'){
  505.             $gsheetURL $googleDriveService->uploadToGoogleDrive($filename);
  506.             if($gsheetURL){
  507.                 unlink($filename);
  508.                 return new RedirectResponse($gsheetURL302);
  509.             }
  510.         }else{
  511.             $response = new Response();
  512.             $response->headers->set('Content-type''application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  513.             $response->headers->set('Content-Disposition'sprintf('attachment; filename="%s"'$filename));
  514.             $response->setContent(file_get_contents($filename));
  515.             $response->setStatusCode(\Symfony\Component\HttpFoundation\Response::HTTP_OK);
  516.             $response->headers->set('Content-Transfer-Encoding''binary');
  517.             $response->headers->set('Pragma''no-cache');
  518.             $response->headers->set('Expires''0');
  519.             unlink($filename);
  520.             return $response;
  521.             exit;
  522.         }  
  523.     }
  524.     /**
  525.      * @param InvoiceRepository $invoiceRepository
  526.      * @param Request $request
  527.      * @return Response
  528.      */
  529.     #[Route(path'/invoice-viewer/report/client/overdue/{_target}'defaults: ['_target' => ''], name'report_invoice_client_overdue')]
  530.     public function reportInvoiceClientOverdue(string $_targetInvoiceRepository $invoiceRepositoryRequest $requestSalesOrderInvoiceRepository $salesOrderInvoiceRepositoryGoogleDriveService $googleDriveService): Response
  531.     {
  532.         $keyword $request->get('keyword');
  533.         $order $request->get('order');
  534.         $client $request->get('client');
  535.         $status $request->get('status');
  536.         $orderBy $request->get('orderBy');
  537.         $start $request->get('start');
  538.         $end $request->get('end');
  539.         $waitForPage $request->query->get('waitForPage');
  540.         $waitForPage === null $result['waitForPage'] = 'false' $result['waitForPage'] = $waitForPage;
  541.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  542.         if (strpos($start'/') !== false) {
  543.             $startDate str_replace('/''-'$start);
  544.             $startDate date("Y-m-d"strtotime($startDate));
  545.             $startDateRange date("d-M-Y"strtotime($startDate));
  546.         } 
  547.         if (strpos($end'/') !== false) {
  548.             $endDate str_replace('/''-'$end);
  549.             $endDate date("Y-m-d"strtotime($endDate));
  550.             $endDateRange date("d-M-Y"strtotime($endDate));
  551.         } 
  552.         $spreadsheet = new Spreadsheet();
  553.         $sheet $spreadsheet->getActiveSheet()->setTitle('All');
  554.         $sheet->setCellValue('A1''Today\'s Date');
  555.         $sheet->setCellValue('B1'date("d-M-Y"));
  556.         $sheet->setCellValue('A2''From');
  557.         $sheet->setCellValue('B2'$startDateRange);
  558.         $sheet->setCellValue('A3''To');
  559.         $sheet->setCellValue('B3'$endDateRange);
  560.         $sheet->setCellValue('A5''Client');
  561.         $sheet->setCellValue('B5''Project');
  562.         $sheet->setCellValue('C5''Client PIC Name');
  563.         $sheet->setCellValue('D5''Client PIC Email');
  564.         $sheet->setCellValue('E5''PIC Name');
  565.         $sheet->setCellValue('F5''PIC Email');
  566.         $sheet->setCellValue('G5''Invoice');
  567.         $sheet->setCellValue('H5''Amount without GST INV Currency');
  568.         $sheet->setCellValue('I5''Amount with GST INV Currency');
  569.         $sheet->setCellValue('J5''Currency');
  570.         $sheet->setCellValue('K5''Amount without GST USD');
  571.         $sheet->setCellValue('L5''Amount with GST USD');
  572.         $sheet->setCellValue('M5''Invoice Date');
  573.         $sheet->setCellValue('N5''Due Date');
  574.         $sheet->setCellValue('O5''Status');
  575.         $sheet->setCellValue('P5''Overdue');
  576.         $lastCol 'P';
  577.         $sheet->getDefaultColumnDimension()->setWidth(25);
  578.         $sheet->getColumnDimension('A')->setWidth(40);
  579.         $sheet->getColumnDimension('B')->setWidth(40);
  580.         $sheet->getColumnDimension('D')->setWidth(38);
  581.         $sheet->getColumnDimension('E')->setWidth(40);
  582.         $sheet->getColumnDimension('F')->setWidth(40);
  583.         $sheet->getColumnDimension('O')->setWidth(15);
  584.         $sheet->getStyle("A1:B3")->getFont()->setBold(true);
  585.         $sheet->getStyle("A5:".$lastCol."5")->getFont()->setBold(true);
  586.         $sheet->getStyle("A5:".$lastCol."5")->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
  587.         $sheet->getStyle("A5:".$lastCol."5")->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('00000000');
  588.         $sheet->getStyle("A6:".$lastCol."6")->getFont()->setBold(false);
  589.         $sheet->getStyle("A6:".$lastCol."6")->getAlignment()->setWrapText(true);
  590.         $sheet->getStyle("A6:".$lastCol."6")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP);
  591.         $invoicesList $salesOrderInvoiceRepository->findByFilter($keyword$order$orderBy$status$client$startDate$endDate);
  592.         // $invoicesList = $invoiceRepository->findByFilter($keyword, $order, $orderBy, $status, $client, $startDate, $endDate);
  593.        
  594.     
  595.         $filename =  'Overdue_Invoice'.'_'date('Y-m-d') . '.xlsx';
  596.         
  597.         
  598.         $row $sheet->getHighestRow();
  599.         foreach($invoicesList as $soInvoice){
  600.             $clientName $soInvoice->getProject()->getClient()->getName();
  601.             $projectName $soInvoice->getProject()->fullName();
  602.             $clientPic $soInvoice->getProject()->getClientPersonInCharge();
  603.             $projectPic $soInvoice->getProject()->getPersonInCharge();
  604.             $invoice $soInvoice->getInvoice();
  605.             $amountWoGST $soInvoice->getAmount();
  606.             $totalAmountWoGST $invoice->getSubTotal();
  607.             $totalAmountWoGSTUsd $invoice->getSubTotalUsd();
  608.             $totalAmountwGST $invoice->getTotal();
  609.             $totalAmountwGSTUsd $invoice->getTotalUsd();
  610.             $sheet->setCellValue('A'.$row$clientName);
  611.             $sheet->setCellValue('B'.$row$projectName);
  612.             $sheet->setCellValue('C'.$row$clientPic $clientPic->getName() : '-');
  613.             $sheet->setCellValue('D'.$row$clientPic $clientPic->getEmail() : '-');
  614.             $sheet->setCellValue('E'.$row$projectPic $projectPic->getPersonalInfo()->getFullName() : '-');
  615.             $sheet->setCellValue('F'.$row$projectPic $projectPic->getEmail() : '-');
  616.             $sheet->setCellValue('G'.$row$invoice->getInvoiceNo());
  617.             $sheet->setCellValue('H'.$row$amountWoGST);
  618.             $amountRatio $amountWoGST $totalAmountWoGST;
  619.             $amountWoGSTUsd $amountRatio $totalAmountWoGSTUsd;
  620.             $amountwGST $amountRatio $totalAmountwGST;
  621.             $amountwGSTUsd $amountRatio $totalAmountwGSTUsd;
  622.             $sheet->setCellValue('I'.$row$amountwGST);
  623.             $sheet->setCellValue('J'.$row$invoice->getCurrency()->getIso());
  624.             $sheet->setCellValue('K'.$row$amountWoGSTUsd);
  625.             $sheet->setCellValue('L'.$row$amountwGSTUsd);
  626.             $sheet->setCellValue('M'.$row$invoice->getInvoiceDate()->format('d-M-Y'));
  627.             $sheet->setCellValue('N'.$row$invoice->getDueDate()->format('d-M-Y'));
  628.             $sheet->setCellValue('O'.$row$invoice->getCustomXeroStatus());
  629.             $overDueDays date_diff($invoice->getDueDate(), new \DateTime());
  630.             $sheet->setCellValue('P'.$row$overDueDays->invert == $overDueDays->days.' Days' '-');
  631.             $color 'FF0000';
  632.             $fontColor 'FFFFFF';
  633.             if($overDueDays->invert == 0){
  634.                 $sheet->getStyle('P'.$row)->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB($color);
  635.                 $sheet->getStyle('P'.$row)->getFont()->getColor()->setRGB($fontColor);
  636.             }
  637.             $row++;
  638.         }
  639.         $sheet->setAutoFilter('A5:'.$lastCol.$sheet->getHighestRow());
  640.         // $sheet->getStyle('H5:I' . $sheet->getHighestRow())->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2);
  641.         // $sheet->getStyle('K5:L' . $sheet->getHighestRow())->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2);
  642.         $sheet->getStyle('H5:I' $sheet->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00;(#,##0.00)');
  643.         $sheet->getStyle('K5:L' $sheet->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00;(#,##0.00)');
  644.         $overdueSheet = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet'Overdue');
  645.         $spreadsheet->addSheet($overdueSheet1);
  646.         $overdueSheet->getDefaultColumnDimension()->setWidth(30);
  647.         $overdueSheet->setCellValue('A1''Today\'s Date');
  648.         $overdueSheet->setCellValue('B1'date("d-M-Y"));
  649.         $overdueSheet->setCellValue('A2''From');
  650.         $overdueSheet->setCellValue('B2'$startDateRange);
  651.         $overdueSheet->setCellValue('A3''To');
  652.         $overdueSheet->setCellValue('B3'$endDateRange);
  653.         $overdueSheet->setCellValue('A5''Client');
  654.         $overdueSheet->setCellValue('B5''Total Due (INV Currency with GST)');
  655.         $overdueSheet->setCellValue('C5''Total Due (USD Currency with GST)');
  656.         $overdueSheet->setCellValue('D5''Total Overdue (INV Currency with GST)');
  657.         $overdueSheet->setCellValue('E5''Total Overdue (USD Currency with GST)');
  658.         $lastCol2 'E';
  659.         $overdueSheet->getDefaultColumnDimension()->setWidth(25);
  660.         $overdueSheet->getStyle("A1:B3")->getFont()->setBold(true);
  661.         $overdueSheet->getStyle("A5:".$lastCol2."5")->getFont()->setBold(true);
  662.         $overdueSheet->getStyle("A5:".$lastCol2."5")->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
  663.         $overdueSheet->getStyle("A5:".$lastCol2."5")->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('00000000');
  664.         $overdueSheet->getStyle("A6:".$lastCol2."6")->getFont()->setBold(false);
  665.         $overdueSheet->getStyle("A6:".$lastCol2."6")->getAlignment()->setWrapText(true);
  666.         $overdueSheet->getStyle("A6:".$lastCol2."6")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP);
  667.         
  668.         /*
  669.         $overdueList = $salesOrderInvoiceRepository->findByFilterGroupByProject($keyword, $order, $orderBy, $status, $client, $startDate, $endDate);
  670.         $row = $overdueSheet->getHighestRow();
  671.         foreach($overdueList as $soInvoice){
  672.             $overdueSheet->setCellValue('A'.$row, $soInvoice['clientName']);
  673.             $overdueSheet->setCellValue('B'.$row, $soInvoice['totalDue']);
  674.             $overdueSheet->setCellValue('C'.$row, '');
  675.             $overdueSheet->setCellValue('D'.$row, $soInvoice['totalOverdue']);
  676.             $overdueSheet->setCellValue('E'.$row, '');
  677.             $row++;
  678.         }
  679.         $overdueSheet->setAutoFilter('A5:'.$lastCol2.$sheet->getHighestRow());
  680.         $overdueSheet->getStyle('B5:E' . $sheet->getHighestRow())->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2);
  681.         */
  682.         // $overdueList = $salesOrderInvoiceRepository->findByFilterGroupByProject($keyword, $order, $orderBy, $status, $client, $startDate, $endDate);
  683.         $overdueList $invoiceRepository->findByTest($keyword$order$orderBy$status$client$startDate$endDate);
  684.         $newArray = [];
  685.         $previousInvoiceNo = [];
  686.         foreach ($overdueList as $item) {
  687.             $clientName $item['clientName'];
  688.             $invoiceNo $item['invoiceNo'];
  689.             // if ($invoiceNo !== $previousInvoiceNo) {
  690.             if (!in_array($invoiceNo$previousInvoiceNo)) {
  691.                 if (!isset($newArray[$clientName])) {
  692.                     $newArray[$clientName] = $item;
  693.                 } else {
  694.                     $newArray[$clientName]['totalDue'] += (float)$item['totalDue'];
  695.                     $newArray[$clientName]['totalDueUsd'] += (float)$item['totalDueUsd'];
  696.                     $newArray[$clientName]['totalOverdue'] += (float)$item['totalOverdue'];
  697.                     $newArray[$clientName]['totalOverdueUsd'] += (float)$item['totalOverdueUsd'];
  698.                 }
  699.             }
  700.             $previousInvoiceNo[] = $invoiceNo;
  701.         }
  702.         $newArray array_values($newArray);
  703.         $row $overdueSheet->getHighestRow();
  704.         foreach($newArray as $soInvoice){
  705.             $overdueSheet->setCellValue('A'.$row$soInvoice['clientName']);
  706.             $overdueSheet->setCellValue('B'.$row$soInvoice['totalDue']);
  707.             $overdueSheet->setCellValue('C'.$row$soInvoice['totalDueUsd']);
  708.             $overdueSheet->setCellValue('D'.$row$soInvoice['totalOverdue']);
  709.             $overdueSheet->setCellValue('E'.$row$soInvoice['totalOverdueUsd']);
  710.             $row++;
  711.         }
  712.         $overdueSheet->setAutoFilter('A5:'.$lastCol2.$sheet->getHighestRow());
  713.         // $overdueSheet->getStyle('B5:E' . $sheet->getHighestRow())->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2);
  714.         $sheet->getStyle('B5:E' $sheet->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00;(#,##0.00)');
  715.         
  716.         $spreadsheet->setActiveSheetIndex(0);
  717.         $writer = new Xlsx($spreadsheet);
  718.         $writer->save($filename);
  719.         // Set the content-type:
  720.         if($_target == 'google'){
  721.             $gsheetURL $googleDriveService->uploadToGoogleDrive($filename);
  722.             if($gsheetURL){
  723.                 unlink($filename);
  724.                 return new RedirectResponse($gsheetURL302);
  725.             }
  726.         }else{
  727.             $response = new Response();
  728.             $response->headers->set('Content-type''application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  729.             $response->headers->set('Content-Disposition'sprintf('attachment; filename="%s"'$filename));
  730.             $response->setContent(file_get_contents($filename));
  731.             $response->setStatusCode(\Symfony\Component\HttpFoundation\Response::HTTP_OK);
  732.             $response->headers->set('Content-Transfer-Encoding''binary');
  733.             $response->headers->set('Pragma''no-cache');
  734.             $response->headers->set('Expires''0');
  735.             unlink($filename);
  736.             return $response;
  737.             exit;
  738.         } 
  739.     }
  740.     /**
  741.      * @param Request $request
  742.      * @param InvoiceRepository $invoiceRepository
  743.      * @param XeroContactRepository $xeroContactRepository
  744.      * @param VendorInvoiceRepository $vendorInvoiceRepository     
  745.      * @return Response  
  746.      */
  747.     #[Route(path'/invoice-viewer/export/vendor/{_target}'defaults: ['_target' => ''], name'export_invoice_vendor')]
  748.     public function exportVendorInvoice(string $_targetRequest $requestInvoiceRepository $invoiceRepositoryXeroContactRepository $xeroContactRepositoryVendorInvoiceRepository $vendorInvoiceRepositoryGoogleDriveService $googleDriveService): Response
  749.     {
  750.         $keyword $request->get('keyword');
  751.         $order $request->get('order');
  752.         $client $request->get('client');
  753.         $status $request->get('status');
  754.         $orderBy $request->get('orderBy');
  755.         $vendor $request->get('vendor');
  756.         $blotter "IMPORTED";
  757.         $vendorQuotationPlanning $request->get('vendorQuotationPlanning');
  758.         $start $request->get('start');
  759.         $end $request->get('end');
  760.         $waitForPage $request->query->get('waitForPage');
  761.         $waitForPage === null $result['waitForPage'] = 'false' $result['waitForPage'] = $waitForPage;
  762.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  763.         $spreadsheet = new Spreadsheet();
  764.         $sheet $spreadsheet->getActiveSheet()->setTitle('Vendor Invoices');
  765.         $sheet->setCellValue('A1''Invoice');
  766.         $sheet->setCellValue('B1''Vendor Name');
  767.         $sheet->setCellValue('C1''Client');
  768.         $sheet->setCellValue('D1''Project');
  769.         $sheet->setCellValue('E1''Vendor Qoute');
  770.         $sheet->setCellValue('F1''Amount');
  771.         $sheet->setCellValue('G1''Allocated');
  772.         $sheet->setCellValue('H1''Amount Left');
  773.         $sheet->setCellValue('I1''Date');
  774.         $sheet->setCellValue('J1''Due Date');
  775.         $sheet->setCellValue('K1''Client INV');
  776.         $sheet->setCellValue('L1''Client INV Issue Date');
  777.         $sheet->setCellValue('M1''Total Client INV Amount');
  778.         $sheet->setCellValue('N1''Total Billed 3rd Party');
  779.         $sheet->setCellValue('O1''Status');
  780.         $sheet->setCellValue('P1''Financial Year');
  781.         $lastCol $sheet->getHighestColumn();
  782.         $sheet->getDefaultColumnDimension()->setWidth(25);
  783.         $sheet->getStyle("A1:".$lastCol."1")->getFont()->setBold(true);
  784.         $sheet->getStyle("A1:".$lastCol."1")->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
  785.         $sheet->getStyle("A1:".$lastCol."1")->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('00000000');
  786.         $sheet->getStyle("A2:".$lastCol."2")->getFont()->setBold(false);
  787.         $sheet->getStyle("A2:".$lastCol."2")->getAlignment()->setWrapText(true);
  788.         $sheet->getStyle("A2:".$lastCol."2")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP);
  789.         $vendorInvoicesList $vendorInvoiceRepository->findByPage(099999$keyword$order$orderBy$vendorQuotationPlanning$blotter$client$vendor$status$start$end);
  790.         $filename =  'Vendor-Invoices_' .$status.'_'.$client.'_'date('Y-m-d') . '.xlsx';
  791.         
  792.         try {
  793.             $row $sheet->getHighestRow();
  794.             foreach ($vendorInvoicesList as $vendorInvoice) {
  795.                 $vendorQuotationPlanningVendorInvoices $vendorInvoice->getVendorQuotationPlanningVendorInvoices();
  796.                 $vqpviLength count($vendorQuotationPlanningVendorInvoices);
  797.                 $xeroContact $xeroContactRepository->findOneBy(['xeroContactId' => $vendorInvoice->getXeroContactId()]);
  798.                 $parentRow $row;
  799.                 $sheet->setCellValue('A' $row$vendorInvoice->getVendorInvoiceNo() ?: '-');
  800.                 $sheet->setCellValue('F' $row$vendorInvoice->getSubTotalUsd());
  801.                 $sheet->setCellValue('H' $row$vendorInvoice->getAmountLeftUsd());
  802.                 $sheet->setCellValue('I' $row$vendorInvoice->getInvoiceDate()->format("d M Y"));
  803.                 $sheet->setCellValue('J' $row$vendorInvoice->getDueDate()->format("d M Y"));
  804.                 $sheet->setCellValue('P' $row$vendorInvoice->getFinancialYear());
  805.                 $clientInvoices = [];
  806.                 // if(!empty($vendorInvoice->getInvoiceVendorInvoices()->toArray())){
  807.                 //     foreach($vendorInvoice->getInvoiceVendorInvoices()->toArray() as $invVendorI){
  808.                 //         $clientInv = $invVendorI->getInvoice()->getInvoiceNo();
  809.                 //         array_push($clientInvoices, $clientInv);
  810.                 //     }
  811.                 // }
  812.                 // $sheet->setCellValue('K'. $row, $clientInvoices ? implode(';', $clientInvoices) : '-');
  813.                 $sheet->setCellValue('O' $row$vendorInvoice->getXeroStatus() == 'AUTHORISED''NOT PAID' $vendorInvoice->getXeroStatus());
  814.     
  815.                 $vendorName '';
  816.                 $amount '';
  817.                 foreach ($vendorQuotationPlanningVendorInvoices as $vqpi) {
  818.                     $vendorQuotationPlanning $vqpi->getVendorQuotationPlanning();
  819.                     if($vqpi){
  820.                         $vendorName $vqpi->getVendorQuotationPlanning() ? $vqpi->getVendorQuotationPlanning()->getVendor()->getName() : "-";
  821.                     }elseif($vendorInvoice->getXeroContactId() == null){
  822.                         $vendorName $vendorInvoice->getVendor()->getName();
  823.                     }else{
  824.                         $vendorName $xeroContact $xeroContact->getName() : null;
  825.                         $vendorName "[".$vendorName."]";
  826.                     }
  827.                     $sheet->setCellValue('C' $row$vendorQuotationPlanning $vendorQuotationPlanning->getProject()->getClient()->getName() : "-");
  828.                     $sheet->setCellValue('D' $row$vendorQuotationPlanning $vendorQuotationPlanning->getProject()->fullName() : "-");
  829.                     if($vendorQuotationPlanning){
  830.                         $sheet->getCell('D' $row)->getHyperlink()->setUrl($baseurl '/project-management/project/view/' $vendorQuotationPlanning->getProject()->getId());
  831.                     } else {
  832.                         $sheet->getCell('D' $row'-');
  833.                     }
  834.                     
  835.                     $sheet->getStyle('D' $row)->getFont()->setUnderline(true);
  836.                     $amount $vqpi->getAmountUsd();
  837.                     $sheet->setCellValue('G' $row$amount);
  838.                     $sheet->setCellValue('K'$row$vqpi->getInvoice() ? $vqpi->getInvoice()->getInvoiceNo() : '-');
  839.                     $sheet->setCellValue('L'$row$vqpi->getInvoice() && $vqpi->getInvoice()->getInvoiceDate() ? $vqpi->getInvoice()->getInvoiceDate()->format('d M Y') : '-');
  840.                     $sheet->setCellValue('M'$row$vqpi->getInvoice() ? $vqpi->getInvoice()->getSubTotalUsd() : '-');
  841.                     $sheet->setCellValue('N'$row$vqpi->getInvoice() ? $vqpi->getInvoice()->getBilled3rdPartyAmountUsd() : '-');
  842.                     if($vqpi->getVendorQuotationPlanning()){
  843.                         $vqRow $row;
  844.                         $vendorQuotations $vqpi->getVendorQuotationPlanning()->getVendorQuotations() ?? null;
  845.                         if(count($vendorQuotations) > 0){
  846.                             foreach($vendorQuotations as $vendorQoute){
  847.                                 $sheet->setCellValue('E' $row$vendorQoute->getAmountUsd());
  848.                                 $row++;
  849.                             }
  850.                             $allocatedRow $row;
  851.                             $sheet->mergeCells('C'.$vqRow.':C'.($allocatedRow 1));
  852.                             $sheet->mergeCells('D'.$vqRow.':D'.($allocatedRow 1));
  853.                             $sheet->mergeCells('G'.$vqRow.':G'.($allocatedRow 1));
  854.                             $sheet->mergeCells('K'.$vqRow.':K'.($allocatedRow 1));
  855.                             $sheet->mergeCells('L'.$vqRow.':L'.($allocatedRow 1));
  856.                             $sheet->mergeCells('M'.$vqRow.':M'.($allocatedRow 1));
  857.                             $sheet->mergeCells('N'.$vqRow.':N'.($allocatedRow 1));
  858.                             $sheet->getStyle('C'.$vqRow.':C'.($allocatedRow 1))->getAlignment()->setVertical('center');
  859.                             $sheet->getStyle('D'.$vqRow.':D'.($allocatedRow 1))->getAlignment()->setVertical('center');
  860.                             $sheet->getStyle('G'.$vqRow.':G'.($allocatedRow 1))->getAlignment()->setVertical('center');
  861.                             $sheet->getStyle('K'.$vqRow.':K'.($allocatedRow 1))->getAlignment()->setVertical('center');
  862.                             $sheet->getStyle('L'.$vqRow.':L'.($allocatedRow 1))->getAlignment()->setVertical('center');
  863.                             $sheet->getStyle('M'.$vqRow.':M'.($allocatedRow 1))->getAlignment()->setVertical('center');
  864.                             $sheet->getStyle('N'.$vqRow.':N'.($allocatedRow 1))->getAlignment()->setVertical('center');
  865.                         }else{
  866.                             $sheet->setCellValue('E' $row"-");
  867.                             $row++;
  868.                         }
  869.                     } else {
  870.                         $sheet->setCellValue('E' $row"-");
  871.                         $row++;
  872.                     }
  873.                 }
  874.                 $sheet->setCellValue('B' $parentRow$vendorName);
  875.                 if($vqpviLength == 0){
  876.                     $vendorName '';
  877.                     if($vendorInvoice->getXeroContactId()){
  878.                         $vendorName $xeroContact $xeroContact->getName() : null;
  879.                         $vendorName "[".$vendorName."]";
  880.                         $sheet->setCellValue('B' $row$vendorName);
  881.                     }else{
  882.                         $sheet->setCellValue('B' $row$vendorInvoice->getVendor()->getName()); 
  883.                     }
  884.                     $sheet->setCellValue('C' $row'-');
  885.                     $sheet->setCellValue('D' $row'-');
  886.                     $sheet->setCellValue('G' $row'-');
  887.                     $sheet->setCellValue('K' $row'-');
  888.                     $sheet->setCellValue('L' $row'-');
  889.                     $sheet->setCellValue('M' $row'-');
  890.                     $sheet->setCellValue('N' $row'-');
  891.                 }
  892.                 if($vqpviLength 0){
  893.                     $sheet->mergeCells('A'.$parentRow.':A'.($row 1));
  894.                     $sheet->mergeCells('B'.$parentRow.':B'.($row 1));
  895.                     $sheet->mergeCells('F'.$parentRow.':F'.($row 1));
  896.                     $sheet->mergeCells('H'.$parentRow.':H'.($row 1));
  897.                     $sheet->mergeCells('I'.$parentRow.':I'.($row 1));
  898.                     $sheet->mergeCells('J'.$parentRow.':J'.($row 1));
  899.                     // $sheet->mergeCells('K'.$parentRow.':K'.($row - 1));
  900.                     $sheet->mergeCells('O'.$parentRow.':O'.($row 1));
  901.                     $sheet->mergeCells('P'.$parentRow.':P'.($row 1));
  902.                     $sheet->getStyle('A'.$parentRow.':A'.($row 1))->getAlignment()->setVertical('center');
  903.                     $sheet->getStyle('B'.$parentRow.':B'.($row 1))->getAlignment()->setVertical('center');
  904.                     $sheet->getStyle('F'.$parentRow.':F'.($row 1))->getAlignment()->setVertical('center');
  905.                     $sheet->getStyle('H'.$parentRow.':H'.($row 1))->getAlignment()->setVertical('center');
  906.                     $sheet->getStyle('I'.$parentRow.':I'.($row 1))->getAlignment()->setVertical('center');
  907.                     $sheet->getStyle('J'.$parentRow.':J'.($row 1))->getAlignment()->setVertical('center');
  908.                     // $sheet->getStyle('K'.$parentRow.':K'.($row - 1))->getAlignment()->setVertical('center');
  909.                     $sheet->getStyle('O'.$parentRow.':O'.($row 1))->getAlignment()->setVertical('center');
  910.                     $sheet->getStyle('P'.$parentRow.':P'.($row 1))->getAlignment()->setVertical('center');
  911.                 }
  912.                 if($vqpviLength == 0){
  913.                     $row++;
  914.                 }
  915.             }
  916.         } catch (\Exception $e) {
  917.             dd($e->getMessage());
  918.         }
  919.         
  920.         $sheet->setAutoFilter('A1:'$sheet->getHighestColumn() . $sheet->getHighestRow());
  921.         // $sheet->getStyle('E2:H' . $sheet->getHighestRow())->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2);
  922.         $sheet->getStyle('E2:H' $sheet->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00;(#,##0.00)');
  923.         $unallocatedSheet = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet'Amount Left Invoices');
  924.         $spreadsheet->addSheet($unallocatedSheet1);
  925.         $unallocatedSheet->setCellValue('A1''Invoice');
  926.         $unallocatedSheet->setCellValue('B1''Vendor Name');
  927.         $unallocatedSheet->setCellValue('C1''Client');
  928.         $unallocatedSheet->setCellValue('D1''Project');
  929.         $unallocatedSheet->setCellValue('E1''Vendor Qoute');
  930.         $unallocatedSheet->setCellValue('F1''Amount');
  931.         $unallocatedSheet->setCellValue('G1''Allocated');
  932.         $unallocatedSheet->setCellValue('H1''Amount Left');
  933.         $unallocatedSheet->setCellValue('I1''Date');
  934.         $unallocatedSheet->setCellValue('J1''Due Date');
  935.         $unallocatedSheet->setCellValue('K1''Client INV');
  936.         $unallocatedSheet->setCellValue('L1''Client INV Issue Date');
  937.         $unallocatedSheet->setCellValue('M1''Total Client INV Amount');
  938.         $unallocatedSheet->setCellValue('N1''Total Billed 3rd Party');
  939.         $unallocatedSheet->setCellValue('O1''Status');
  940.         $unallocatedSheet->setCellValue('P1''Financial Year');
  941.         $lastColx $unallocatedSheet->getHighestColumn();
  942.         $unallocatedSheet->getDefaultColumnDimension()->setWidth(25);
  943.         $unallocatedSheet->getStyle("A1:".$lastColx."1")->getFont()->setBold(true);
  944.         $unallocatedSheet->getStyle("A1:".$lastColx."1")->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
  945.         $unallocatedSheet->getStyle("A1:".$lastColx."1")->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('00000000');
  946.         $unallocatedSheet->getStyle("A2:".$lastColx."2")->getFont()->setBold(false);
  947.         $unallocatedSheet->getStyle("A2:".$lastColx."2")->getAlignment()->setWrapText(true);
  948.         $unallocatedSheet->getStyle("A2:".$lastColx."2")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP);
  949.         $vendorInvoicesListUnallocated $vendorInvoiceRepository->findByPage(099999$keyword$order$orderBy$vendorQuotationPlanning$blotter$client$vendor'Amount Left'$start$end);
  950.         
  951.         try {
  952.             $row $unallocatedSheet->getHighestRow();
  953.             foreach ($vendorInvoicesListUnallocated as $vendorInvoice) {
  954.                 $vendorQuotationPlanningVendorInvoices $vendorInvoice->getVendorQuotationPlanningVendorInvoices();
  955.                 $vqpviLength count($vendorQuotationPlanningVendorInvoices);
  956.                 $xeroContact $xeroContactRepository->findOneBy(['xeroContactId' => $vendorInvoice->getXeroContactId()]);
  957.                 $parentRow $row;
  958.                 $unallocatedSheet->setCellValue('A' $row$vendorInvoice->getVendorInvoiceNo() ?: '-');
  959.                 $unallocatedSheet->setCellValue('F' $row$vendorInvoice->getSubTotalUsd());
  960.                 $unallocatedSheet->setCellValue('H' $row$vendorInvoice->getAmountLeftUsd());
  961.                 $unallocatedSheet->setCellValue('I' $row$vendorInvoice->getInvoiceDate()->format("d M Y"));
  962.                 $unallocatedSheet->setCellValue('J' $row$vendorInvoice->getDueDate()->format("d M Y"));
  963.                 $unallocatedSheet->setCellValue('P' $row$vendorInvoice->getFinancialYear());
  964.                 $clientInvoices = [];
  965.                 // if(!empty($vendorInvoice->getInvoiceVendorInvoices()->toArray())){
  966.                 //     foreach($vendorInvoice->getInvoiceVendorInvoices()->toArray() as $invVendorI){
  967.                 //         $clientInv = $invVendorI->getInvoice()->getInvoiceNo();
  968.                 //         array_push($clientInvoices, $clientInv);
  969.                 //     }
  970.                 // }
  971.                 // $unallocatedSheet->setCellValue('K'. $row, $clientInvoices ? implode(';', $clientInvoices) : '-');
  972.                 $unallocatedSheet->setCellValue('O' $row$vendorInvoice->getXeroStatus() == 'AUTHORISED''NOT PAID' $vendorInvoice->getXeroStatus());
  973.     
  974.                 $vendorName '';
  975.                 $amount '';
  976.                 foreach ($vendorQuotationPlanningVendorInvoices as $vqpi) {
  977.                     $vendorQuotationPlanning $vqpi->getVendorQuotationPlanning();
  978.                     if($vqpi){
  979.                         $vendorName $vqpi->getVendorQuotationPlanning() ? $vqpi->getVendorQuotationPlanning()->getVendor()->getName() : "-";
  980.                     }elseif($vendorInvoice->getXeroContactId() == null){
  981.                         $vendorName $vendorInvoice->getVendor()->getName();
  982.                     }else{
  983.                         $vendorName $xeroContact $xeroContact->getName() : null;
  984.                         $vendorName "[".$vendorName."]";
  985.                     }
  986.                     $unallocatedSheet->setCellValue('C' $row$vendorQuotationPlanning $vendorQuotationPlanning->getProject()->getClient()->getName() : "-");
  987.                     $unallocatedSheet->setCellValue('D' $row$vendorQuotationPlanning $vendorQuotationPlanning->getProject()->fullName() : "-");
  988.                     if($vendorQuotationPlanning){
  989.                         $unallocatedSheet->getCell('D' $row)->getHyperlink()->setUrl($baseurl '/project-management/project/view/' $vendorQuotationPlanning->getProject()->getId());
  990.                     } else {
  991.                         $unallocatedSheet->getCell('D' $row'-');
  992.                     }
  993.                     
  994.                     $unallocatedSheet->getStyle('D' $row)->getFont()->setUnderline(true);
  995.                     $amount $vqpi->getAmountUsd();
  996.                     $unallocatedSheet->setCellValue('G' $row$amount);
  997.                     $unallocatedSheet->setCellValue('K'$row$vqpi->getInvoice() ? $vqpi->getInvoice()->getInvoiceNo() : '-');
  998.                     $unallocatedSheet->setCellValue('L'$row$vqpi->getInvoice() && $vqpi->getInvoice()->getInvoiceDate() ? $vqpi->getInvoice()->getInvoiceDate()->format('d M Y') : '-');
  999.                     $unallocatedSheet->setCellValue('M'$row$vqpi->getInvoice() ? $vqpi->getInvoice()->getSubTotalUsd() : '-');
  1000.                     $unallocatedSheet->setCellValue('N'$row,$vqpi->getInvoice() ? $vqpi->getInvoice()->getBilled3rdPartyAmountUsd() : '-');
  1001.                     if($vqpi->getVendorQuotationPlanning()){
  1002.                         $vqRow $row;
  1003.                         $vendorQuotations $vqpi->getVendorQuotationPlanning()->getVendorQuotations() ?? null;
  1004.                         if(count($vendorQuotations) > 0){
  1005.                             foreach($vendorQuotations as $vendorQoute){
  1006.                                 $unallocatedSheet->setCellValue('E' $row$vendorQoute->getAmountUsd());
  1007.                                 $row++;
  1008.                             }
  1009.                             $allocatedRow $row;
  1010.                             $unallocatedSheet->mergeCells('C'.$vqRow.':C'.($allocatedRow 1));
  1011.                             $unallocatedSheet->mergeCells('D'.$vqRow.':D'.($allocatedRow 1));
  1012.                             $unallocatedSheet->mergeCells('G'.$vqRow.':G'.($allocatedRow 1));
  1013.                             $unallocatedSheet->mergeCells('K'.$vqRow.':K'.($allocatedRow 1));
  1014.                             $unallocatedSheet->mergeCells('L'.$vqRow.':L'.($allocatedRow 1));
  1015.                             $unallocatedSheet->mergeCells('M'.$vqRow.':M'.($allocatedRow 1));
  1016.                             $unallocatedSheet->mergeCells('N'.$vqRow.':N'.($allocatedRow 1));
  1017.                             $unallocatedSheet->getStyle('C'.$vqRow.':C'.($allocatedRow 1))->getAlignment()->setVertical('center');
  1018.                             $unallocatedSheet->getStyle('D'.$vqRow.':D'.($allocatedRow 1))->getAlignment()->setVertical('center');
  1019.                             $unallocatedSheet->getStyle('G'.$vqRow.':G'.($allocatedRow 1))->getAlignment()->setVertical('center');
  1020.                             $unallocatedSheet->getStyle('K'.$vqRow.':K'.($allocatedRow 1))->getAlignment()->setVertical('center');
  1021.                             $unallocatedSheet->getStyle('L'.$vqRow.':L'.($allocatedRow 1))->getAlignment()->setVertical('center');
  1022.                             $unallocatedSheet->getStyle('M'.$vqRow.':M'.($allocatedRow 1))->getAlignment()->setVertical('center');
  1023.                             $unallocatedSheet->getStyle('N'.$vqRow.':N'.($allocatedRow 1))->getAlignment()->setVertical('center');
  1024.                         }else{
  1025.                             $unallocatedSheet->setCellValue('E' $row"-");
  1026.                             $row++;
  1027.                         }
  1028.                     } else {
  1029.                         $unallocatedSheet->setCellValue('E' $row"-");
  1030.                         $row++;
  1031.                     }
  1032.                 }
  1033.                 $unallocatedSheet->setCellValue('B' $parentRow$vendorName);
  1034.                 if($vqpviLength == 0){
  1035.                     $vendorName '';
  1036.                     if($vendorInvoice->getXeroContactId()){
  1037.                         $vendorName $xeroContact $xeroContact->getName() : null;
  1038.                         $vendorName "[".$vendorName."]";
  1039.                         $unallocatedSheet->setCellValue('B' $row$vendorName);
  1040.                     }else{
  1041.                         $unallocatedSheet->setCellValue('B' $row$vendorInvoice->getVendor()->getName()); 
  1042.                     }
  1043.                     $unallocatedSheet->setCellValue('C' $row'-');
  1044.                     $unallocatedSheet->setCellValue('D' $row'-');
  1045.                     $unallocatedSheet->setCellValue('G' $row'-');
  1046.                     $unallocatedSheet->setCellValue('K' $row'-');
  1047.                     $unallocatedSheet->setCellValue('L' $row'-');
  1048.                     $unallocatedSheet->setCellValue('M' $row'-');
  1049.                     $unallocatedSheet->setCellValue('N' $row'-');
  1050.                 }
  1051.                 if($vqpviLength 0){
  1052.                     $unallocatedSheet->mergeCells('A'.$parentRow.':A'.($row 1));
  1053.                     $unallocatedSheet->mergeCells('B'.$parentRow.':B'.($row 1));
  1054.                     $unallocatedSheet->mergeCells('F'.$parentRow.':F'.($row 1));
  1055.                     $unallocatedSheet->mergeCells('H'.$parentRow.':H'.($row 1));
  1056.                     $unallocatedSheet->mergeCells('I'.$parentRow.':I'.($row 1));
  1057.                     $unallocatedSheet->mergeCells('J'.$parentRow.':J'.($row 1));
  1058.                     // $unallocatedSheet->mergeCells('K'.$parentRow.':K'.($row - 1));
  1059.                     $unallocatedSheet->mergeCells('O'.$parentRow.':O'.($row 1));
  1060.                     $unallocatedSheet->mergeCells('P'.$parentRow.':P'.($row 1));
  1061.                     $unallocatedSheet->getStyle('A'.$parentRow.':A'.($row 1))->getAlignment()->setVertical('center');
  1062.                     $unallocatedSheet->getStyle('B'.$parentRow.':B'.($row 1))->getAlignment()->setVertical('center');
  1063.                     $unallocatedSheet->getStyle('F'.$parentRow.':F'.($row 1))->getAlignment()->setVertical('center');
  1064.                     $unallocatedSheet->getStyle('H'.$parentRow.':H'.($row 1))->getAlignment()->setVertical('center');
  1065.                     $unallocatedSheet->getStyle('I'.$parentRow.':I'.($row 1))->getAlignment()->setVertical('center');
  1066.                     $unallocatedSheet->getStyle('J'.$parentRow.':J'.($row 1))->getAlignment()->setVertical('center');
  1067.                     // $unallocatedSheet->getStyle('K'.$parentRow.':K'.($row - 1))->getAlignment()->setVertical('center');
  1068.                     $unallocatedSheet->getStyle('O'.$parentRow.':O'.($row 1))->getAlignment()->setVertical('center');
  1069.                     $unallocatedSheet->getStyle('P'.$parentRow.':P'.($row 1))->getAlignment()->setVertical('center');
  1070.                 }
  1071.                 if($vqpviLength == 0){
  1072.                     $row++;
  1073.                 }
  1074.             }
  1075.         } catch (\Exception $e) {
  1076.             dd($e->getMessage());
  1077.         }
  1078.         
  1079.         $unallocatedSheet->setAutoFilter('A1:'$unallocatedSheet->getHighestColumn() . $unallocatedSheet->getHighestRow());
  1080.         // $sheet->getStyle('E2:H' . $sheet->getHighestRow())->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2);
  1081.         $unallocatedSheet->getStyle('E2:H' $unallocatedSheet->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00;(#,##0.00)');
  1082.         $writer = new Xlsx($spreadsheet);
  1083.         $writer->save($filename);
  1084.         if($_target == 'google'){
  1085.             $gsheetURL $googleDriveService->uploadToGoogleDrive($filename);
  1086.             if($gsheetURL){
  1087.                 unlink($filename);
  1088.                 return new RedirectResponse($gsheetURL302);
  1089.             }
  1090.         }else{
  1091.             $response = new Response();
  1092.             $response->headers->set('Content-type''application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  1093.             $response->headers->set('Content-Disposition'sprintf('attachment; filename="%s"'$filename));
  1094.             $response->setContent(file_get_contents($filename));
  1095.             $response->setStatusCode(\Symfony\Component\HttpFoundation\Response::HTTP_OK);
  1096.             $response->headers->set('Content-Transfer-Encoding''binary');
  1097.             $response->headers->set('Pragma''no-cache');
  1098.             $response->headers->set('Expires''0');
  1099.             unlink($filename);
  1100.             return $response;
  1101.             exit;
  1102.         }   
  1103.     }
  1104.     
  1105. }