private function generateBill($operationData, $userInfo) { $generateBillUploadrequest = UploadDTO\BillUploadDto::Deserialize($operationData); if (!$generateBillUploadrequest) { Log::error('Generate Bill details not serialized correctly'); return false; } $orderController = new OrderController(); $customerOrders = $orderController->getCustomerOrders($generateBillUploadrequest->custId, $userInfo->restaurantId); if (is_null($customerOrders)) { return; } $billNetAmount = 0; $billDetailsList[] = NULL; $billDetailsCounter = 0; foreach ($customerOrders as $order) { $billDetailsUploadDto = new UploadDTO\BillDetailsUploadDto(NULL, $order->orderId, $order->orderNo, $order->orderAmt); $billNetAmount += $order->orderAmt; Log::debug('Bill Net Amount calculated for orderAmt :' . $order->orderAmt); $billDetailsList[$billDetailsCounter++] = $billDetailsUploadDto; } $totalBillTaxAmt = 0; $taxController = new TaxController(); $billTaxList = $taxController->getTax($billNetAmount); if (!is_null($billTaxList)) { foreach ($billTaxList as $billTax) { $totalBillTaxAmt += $billTax->taxAmt; } } $billController = new BillController(); $totalPayBillAmt = $billNetAmount + $totalBillTaxAmt; $maxBillNo = $billController->getMaxBillNo($userInfo->restaurantId); if ($totalPayBillAmt) { $billEntryDto = new UploadDTO\BillEntryDto($maxBillNo, $billNetAmount, $totalBillTaxAmt, $totalPayBillAmt, $userInfo->userId, $userInfo->restaurantId, $generateBillUploadrequest->custId, $this->isZero($generateBillUploadrequest->tableId), $this->isZero($generateBillUploadrequest->takeawayNo), $this->isZero($generateBillUploadrequest->deliveryNo)); $salesReportDto = new DTO\DownloadDTO\SalesHistoryReportDto($userInfo->restaurantId, date('m'), date('Y'), $billNetAmount, $totalBillTaxAmt, $totalPayBillAmt); $generateBillResult = $billController->addBillEntry($billEntryDto); Log::debug('your Bill generated for Bill No : ' . $generateBillResult); if (!$generateBillResult) { Log::error('Bill generation failed'); return 0; } } else { Log::error('Bill amount not valid so Bill is not generated for given request'); $this->response->body(DTO\ErrorDto::prepareError(107)); return; } foreach ($billDetailsList as $billDetails) { $billDetails->billNo = $generateBillResult; } $billDetailsController = new BillDetailsController(); $addBillDetailsResult = $billDetailsController->addBillDetails($billDetailsList, $userInfo->userId, $userInfo->restaurantId); if (!$addBillDetailsResult) { Log::error('Bill details generation failed'); $this->response->body(DTO\ErrorDto::prepareError(107)); return 0; } if (!is_null($billTaxList)) { foreach ($billTaxList as $billTax) { $billTax->billNo = $generateBillResult; } } $billTaxTransactionsController = new BillTaxTransactionsController(); $addBillTaxTransactionsResult = $billTaxTransactionsController->addBillTaxTransactions($billTaxList); if (!$addBillTaxTransactionsResult) { Log::error('Bill Tax Tansactions generation failed'); return; } $salesHistoryController = new SalesHistoryController(); $reportResult = $salesHistoryController->makeSalesReportEntry($salesReportDto); if (!$reportResult) { Log::error('Sales History report data not saved properly'); $this->response->body(DTO\ErrorDto::prepareError(107)); return 0; } $this->response->body(DTO\ErrorDto::prepareSuccessMessage('Bill has been generated', $generateBillResult)); foreach ($customerOrders as $billedOrder) { $changeOrderStatusResult = $orderController->changeOrderStatus($billedOrder->orderId, BILLED_ORDER_STATUS, $userInfo->restaurantId); } if (!$changeOrderStatusResult) { Log::error('Changing Billed Order status failed'); } }