Skip to content

Commit

Permalink
JE-400: Fixed possible null value issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tuj committed Dec 14, 2023
1 parent 5c5beb7 commit 0e4888e
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Controller/InvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Repository\AccountRepository;
use App\Repository\InvoiceRepository;
use App\Service\BillingService;
use Doctrine\ORM\EntityManagerInterface;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Csv;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down Expand Up @@ -302,28 +303,36 @@ public function export(Request $request, Invoice $invoice, InvoiceRepository $in
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
#[Route('/export-selection', name: 'app_invoices_export_selection', methods: ['GET'])]
public function exportSelection(Request $request, InvoiceRepository $invoiceRepository, BillingService $billingService): Response
public function exportSelection(Request $request, InvoiceRepository $invoiceRepository, BillingService $billingService, EntityManagerInterface $entityManager): Response
{
$ids = explode(",", $request->query->get('ids'));
$queryIds = $request->query->get('ids');

$ids = [];

if (is_string($queryIds)) {
$ids = explode(',', $queryIds);
}

foreach ($ids as $id) {
$invoice = $invoiceRepository->find($id);

if ($invoice != null) {
if (null != $invoice) {
if (!$invoice->isRecorded()) {
throw new HttpException(400, 'Invoice cannot be exported before it is on record.');
}

if (null !== $invoice->getProjectBilling()) {
throw new HttpException(400, 'Invoice is a part of a project billing, cannot be exported.');
}
}

// Mark invoice as exported.
$invoice->setExportedDate(new \DateTime());
$invoiceRepository->save($invoice, false);
// Mark invoice as exported.
$invoice->setExportedDate(new \DateTime());
$invoiceRepository->save($invoice);
}
}

$entityManager->flush();

$spreadsheet = $billingService->exportInvoicesToSpreadsheet($ids);

/** @var Csv $writer */
Expand Down

0 comments on commit 0e4888e

Please sign in to comment.