Exemplo n.º 1
0
 public function printPreview()
 {
     $tableId = parent::readCookie('cti');
     $takeawayNo = parent::readCookie('ctn');
     $deliveryNo = parent::readCookie('cdn');
     Log::debug('Current tableId :-' . $tableId);
     Log::debug('Current takeawayNo :- ' . $takeawayNo);
     Log::debug('Current delivery number :- ' . $takeawayNo);
     if (!$tableId and !$takeawayNo and !$deliveryNo) {
         $this->redirect('login');
     }
     $billController = new BillController();
     $billInfo = $billController->getBill($tableId, $takeawayNo, $deliveryNo);
     if (is_null($billInfo)) {
         Log::error('Bill has not generated for this table');
         $this->set([MESSAGE => DTO\ErrorDto::prepareMessage(124), COLOR => ERROR_COLOR]);
         return;
     }
     Log::debug('Bill has generated for this table');
     $billDetailsController = new BillDetailsController();
     $billDeatilsInfo = $billDetailsController->getOrderId($billInfo->billNo);
     $orders = array();
     foreach ($billDeatilsInfo as $info) {
         array_push($orders, $info->orderId);
     }
     $orderDetailsController = new OrderDetailsController();
     $billOrderDetails = $orderDetailsController->getbillOrderDetails($orders);
     $billPrintInfo = array();
     $indexCounter = 0;
     $menuTitleList = array();
     foreach ($billOrderDetails as $menu) {
         if (!key_exists($menu->menuTitle, $menuTitleList)) {
             $menuTitleList[$menu->menuTitle] = $menu;
         } else {
             foreach ($menuTitleList as $key => $value) {
                 if ($value->menuId == $menu->menuId and $value->subMenuId == $menu->subMenuId) {
                     $value->qty += $menu->qty;
                     $value->orderPrice += $menu->orderPrice;
                 }
             }
         }
     }
     foreach ($menuTitleList as $key => $value) {
         $billPrintDto = new DownloadDTO\BillPrintDwnldDto($indexCounter + 1, $value->menuId, $value->menuTitle, $value->qty, $value->orderPrice / $menu->qty, $value->orderPrice);
         $billPrintInfo[$indexCounter++] = $billPrintDto;
     }
     $restId = parent::readCookie('cri');
     $restaurantController = new RestaurantController();
     $restaurantInfo = $restaurantController->getAdminRestaurants(array($restId));
     $userController = new UserController();
     $userInfo = $userController->getUserName($billInfo->userId);
     $rtableController = new RTablesController();
     $tableNo = $rtableController->getBillTableNo($tableId);
     if (isset($billInfo) and isset($restaurantInfo) and isset($billPrintInfo)) {
         $this->set(['table' => $tableNo, 'bill' => $billInfo, 'restaurants' => $restaurantInfo, 'printInfo' => $billPrintInfo, 'user' => $userInfo->userName]);
     } else {
         $this->set([MESSAGE => DTO\ErrorDto::prepareMessage(124), COLOR => ERROR_COLOR]);
     }
 }
Exemplo n.º 2
0
 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');
     }
 }