Ejemplo n.º 1
0
 public function restoreMenuRecipeItemQty($orderId)
 {
     $orderDetailsController = new OrderDetailsController();
     $orderMenu = $orderDetailsController->getOrderMenu($orderId);
     foreach ($orderMenu as $menu) {
         $recipeItems = $this->getMenuRecipe($menu->id);
         foreach ($recipeItems as $item) {
             $recipeItemMasterController = new RecipeItemMasterController();
             $itemUnit = $recipeItemMasterController->getItemUnit($item->itemId);
             if ($itemUnit == $item->unitId) {
                 $restoreDto = new RecipeItemRestoreDto($item->itemId, $menu->qty, $item->qty, 1);
             } else {
                 $unitMaterController = new UnitMasterController();
                 $cfactor = $unitMaterController->getCfactor($item->unitId);
                 $restoreDto = new RecipeItemRestoreDto($item->itemId, $menu->qty, $item->qty, $cfactor);
             }
             $recipeItemMasterController->restoreItemQty($restoreDto);
         }
     }
 }
Ejemplo n.º 2
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]);
     }
 }
Ejemplo n.º 3
0
 /**
  * Submits order to database, by getting records from Menu table, calculating 
  * Inserts into Order and Order details table with appropriate qty.
  * @param type $operationData
  * @param type $userInfo
  * @return type 
  */
 private function placeOrder($operationData, $userInfo)
 {
     $orderUploadRequest = UploadDTO\OrderUploadDto::Deserialize($operationData);
     if (!is_array($orderUploadRequest->orderDetails)) {
         Log::error("No menu items are provided or wrong element in JSON");
         return NULL;
     }
     $orderController = new OrderController();
     $orderCheck = $orderController->orderCheck($orderUploadRequest->custId, $userInfo->restaurantId, BILLED_ORDER_STATUS);
     if ($orderCheck) {
         $this->response->body(DTO\ErrorDto::prepareError(105));
         return;
     }
     $menuIdList = null;
     $menuIdLoopCounter = 0;
     $subMenuIdLoopCounter = 0;
     $subMenuList = null;
     foreach ($orderUploadRequest->orderDetails as $menuItemIndex => $menuItemRecord) {
         if ($menuItemRecord->orderQty) {
             if ($menuItemRecord->subMenuId) {
                 $subMenuList[$subMenuIdLoopCounter++] = $menuItemRecord->subMenuId;
             } else {
                 $menuIdList[$menuIdLoopCounter] = $menuItemRecord->menuId;
             }
         }
         if (isset($menuItemRecord->note)) {
             $note = $menuItemRecord->note;
         } else {
             $note = null;
         }
         $orderNote[$menuItemRecord->menuId] = $note;
         $menuIdLoopCounter++;
     }
     if (!count($menuIdList) and !count($subMenuList)) {
         $this->response->body(DTO\ErrorDto::prepareError(117));
         \Cake\Log\Log::error("request with zero menu quantity");
         return;
     }
     $orderTotalAmt = 0;
     $orderLoopCounter = 0;
     $orderDetailList[] = NULL;
     $MenuInfoList = null;
     $menuController = new MenuController();
     if (count($menuIdList)) {
         $MenuInfoList = $menuController->getMenuItemList($userInfo->restaurantId, $menuIdList);
     }
     $SubMenuInfo = null;
     if (count($subMenuList)) {
         $subMenuController = new SubMenuController();
         $SubMenuInfo = $subMenuController->getSubMenu($subMenuList);
     }
     if (is_null($MenuInfoList) and is_null($SubMenuInfo)) {
         $this->response->body(DTO\ErrorDto::prepareError(117));
         \Cake\Log\Log::error("request with zero menu quantity");
         return;
     }
     if ($MenuInfoList) {
         foreach ($MenuInfoList as $menuInfo) {
             $resultArray = $this->search($orderUploadRequest->orderDetails, "menuId", $menuInfo->menuId);
             $menuQty = $resultArray->orderQty;
             $orderTotalAmt += $menuQty * $menuInfo->price;
             $orderDetailEntryDto = new UploadDTO\OrderDetailEntryDto($orderUploadRequest->orderId, $menuQty, $menuQty * $menuInfo->price, $menuInfo->menuId, $menuInfo->subMenuId, $menuInfo->menuTitle, $menuInfo->price, $orderNote[$menuInfo->menuId]);
             $orderDetailList[$orderLoopCounter] = $orderDetailEntryDto;
             $orderLoopCounter++;
         }
     }
     if ($SubMenuInfo) {
         foreach ($SubMenuInfo as $menuInfo) {
             $resultArray = $this->subMenuSearch($orderUploadRequest->orderDetails, "menuId", $menuInfo->menuId, "subMenuId", $menuInfo->subMenuId);
             $menuQty = $resultArray->orderQty;
             $orderTotalAmt += $menuQty * $menuInfo->price;
             $orderDetailEntryDto = new UploadDTO\OrderDetailEntryDto($orderUploadRequest->orderId, $menuQty, $menuQty * $menuInfo->price, $menuInfo->menuId, $menuInfo->subMenuId, $menuInfo->menuTitle . '  ' . $menuInfo->subMenuTitle, $menuInfo->price, $orderNote[$menuInfo->menuId]);
             $orderDetailList[$orderLoopCounter] = $orderDetailEntryDto;
             $orderLoopCounter++;
         }
     }
     $orderStatus = PLACED_ORDER_STATUS;
     $rConfigSettingController = new RConfigSettingsController();
     if ($rConfigSettingController->allow($userInfo->restaurantId, KOT_CONFIG_KEY)) {
         $orderStatus = FULFILLED_ORDER_STATUS;
     }
     $this->transBegin();
     $maxOrderNo = $orderController->getMaxOrderNo($userInfo->restaurantId);
     $orderEntryDto = new UploadDTO\OrderEntryDto($orderUploadRequest->orderId, $maxOrderNo, $orderTotalAmt, $userInfo->restaurantId, $orderUploadRequest->custId, $this->isZero($orderUploadRequest->tableId), $orderStatus, $userInfo->userId, $this->isZero($orderUploadRequest->takeawayNo), $this->isZero($orderUploadRequest->deliveryNo), $orderUploadRequest->orderType);
     $orderHeaderEntrySucceded = $orderController->addOrderEntry($orderEntryDto);
     if ($orderHeaderEntrySucceded == 0) {
         $this->transRollback();
         Log::error('No order entry was inserted into db');
         return;
     }
     $orderDetailController = new OrderDetailsController();
     $orderDetailEntrySucceeded = $orderDetailController->addOrderEntries($orderDetailList, $userInfo);
     if ($orderDetailEntrySucceeded == 0) {
         $this->transRollback();
         Log::error('No order entry was inserted for order details into db');
         return;
     }
     $this->transCommit();
     return $orderHeaderEntrySucceded;
 }