Exemplo n.º 1
0
 public static function addNewOrder($param, $request, $url = 'admin/child')
 {
     $tables = self::$servicelocator->get('doctrine');
     $table = new orderModel($tables);
     $orderItem = new orderdetailModel($tables);
     $tableModel = new tableModel($tables);
     $transactionModel = new transactionModel($tables);
     $translator = self::translate();
     $id = $param->fromRoute('id');
     $catID = 0;
     $tableManage = $tableModel->findBy(array('isdelete' => 0));
     $save = $param->fromPost('save');
     $status = 'pending';
     $isdelete = 0;
     if ($save == "payment") {
         $status = 'finish';
         $isdelete = 1;
     }
     //insert
     if ($id == '') {
         if ($request->isPost()) {
             //$detailRow = $param->fromPost('countChild');
             $Auth_service = new AuthenticationService();
             $auth = $Auth_service->getIdentity();
             $dataDetail = $param->fromPost('detail');
             $totalRealCost = $param->fromPost('total_real_cost');
             $cat = new Orders();
             $cat->setTotalCost($param->fromPost('total_cost'));
             $cat->setTableId($param->fromPost('table_id'));
             $cat->setCreateDate(time());
             $cat->setCouponId($param->fromPost('coupon_id'));
             $cat->setToTalRealCost($totalRealCost);
             $cat->setUserId($auth->userId);
             $cat->setSurtaxId($param->fromPost('surtax_id'));
             $cat->setIsdelete(0);
             $cat->setStatus($status);
             $cat = $table->insert($cat);
             $catID = $cat->getId();
             if ($param->fromPost('coupon_id') != -1) {
                 $doctrine = self::$servicelocator->get('doctrine');
                 $couponModel = new couponModel($doctrine);
                 $coupon = $couponModel->findOneBy(array('id' => $param->fromPost('coupon_id')));
                 if ($coupon->getReuse() == 0) {
                     if ($save == 'payment') {
                         $coupon->setIsdelete($isdelete);
                         $couponModel->edit($coupon);
                     }
                 }
             }
             foreach ($dataDetail as $k => $val) {
                 if ($val['menuid'] != -1) {
                     self::insertOrderDetail($val, $catID);
                 }
             }
             if ($save == 'payment') {
                 $url = "http://" . $_SERVER['HTTP_HOST'] . '/frontend/order/detail/' . $catID;
                 header("Location:" . $url);
                 exit;
             }
         }
         //insert new user
         //$this->redirect()->toRoute('admin/child',array('controller'=>'category'));
         return array('title' => $translator->translate('Add new order'), 'data' => null, 'url' => $url, 'orderId' => $catID, 'tables' => $tableManage, 'dataObject' => array());
     } else {
         $cats = $table->findOneBy(array('id' => $id));
         $orderDetail = $orderItem->findBy(array('orderId' => $id, 'isdelete' => 0));
         if ($request->isPost()) {
             $idFormPost = $param->fromPost('id');
             $cat = $table->findOneBy(array('id' => $idFormPost));
             $dataDetail = $param->fromPost('detail');
             $Auth_service = new AuthenticationService();
             $auth = $Auth_service->getIdentity();
             $totalRealCost = $param->fromPost('total_real_cost');
             $totalCost = $param->fromPost('total_cost');
             $tableId = $param->fromPost('table_id');
             $cat->setTotalCost($totalCost);
             $cat->setTableId($param->fromPost('table_id'));
             $cat->setCreateDate(time());
             $cat->setCouponId($param->fromPost('coupon_id'));
             $cat->setToTalRealCost($totalRealCost);
             $cat->setUserId($auth->userId);
             $cat->setSurtaxId($param->fromPost('surtax_id'));
             $cat->setIsdelete(0);
             $cat->setStatus($status);
             $table->edit($cat);
             if ($param->fromPost('coupon_id') != -1) {
                 $doctrine = self::$servicelocator->get('doctrine');
                 $couponModel = new couponModel($doctrine);
                 $coupon = $couponModel->findOneBy(array('id' => $param->fromPost('coupon_id')));
                 if ($coupon->getReuse() == 0) {
                     if ($save == 'payment') {
                         $coupon->setIsdelete(1);
                         $couponModel->edit($coupon);
                     }
                 }
             }
             //update order
             // delete order detail
             $orderItem->deleteAll(array('orderId' => $id));
             // insert order detail
             foreach ($dataDetail as $k => $val) {
                 if ($val['menuid'] != -1) {
                     self::insertOrderDetail($val, $idFormPost);
                 }
             }
             if ($save == 'payment') {
                 $url = "http://" . $_SERVER['HTTP_HOST'] . '/frontend/order/detail/' . $id;
                 header("Location:" . $url);
                 exit;
             } else {
                 $url = "http://" . $_SERVER['HTTP_HOST'] . '/frontend/order/add/' . $id . '?tbl=' . $tableId;
                 header("Location:" . $url);
                 exit;
             }
         }
         $cat = $table->convertSingleToArray($cats);
         return array('title' => 'Edit Order', 'data' => $cat, 'url' => $url, 'orderDetails' => $orderDetail, 'orderId' => 0, 'dataObject' => $cats, 'tables' => $tableManage);
     }
 }
Exemplo n.º 2
0
 function splitAction()
 {
     if ($this->getRequest()->isPost()) {
         $post = $this->params()->fromPost();
         $table = $post['table-new'];
         $discount = $post['discount'];
         $oldOrder = $post['oldOrder'];
         unset($post['table-new']);
         unset($post['discount']);
         unset($post['oldOrder']);
         if (!empty($post)) {
             $Auth_service = new AuthenticationService();
             $auth = $Auth_service->getIdentity();
             $status = 'pending';
             $orderEntity = new Orders();
             $orderEntity->setTotalCost(0);
             $orderEntity->setTableId($table);
             $orderEntity->setCreateDate(time());
             $orderEntity->setCouponId($discount);
             $orderEntity->setToTalRealCost(0);
             $orderEntity->setUserId($auth->userId);
             $orderEntity->setSurtaxId(0);
             $orderEntity->setIsdelete(0);
             $orderEntity->setStatus($status);
             $orderLastInsert = $this->modelOrder->insert($orderEntity);
             $lastOrderId = $orderLastInsert->getId();
             $totalPrice = 0;
             $oldPrice = 0;
             $newRealCost = 0;
             foreach ($post as $order) {
                 $orderDetailId = $order['orderDetailId'];
                 $oldQty = $order['oldQty'];
                 $qty = $order['qty'];
                 $totalRealCost = $order['menuCost'] * $order['oldQty'];
                 $qty >= $oldQty ? $qty = $oldQty : ($qty = $qty);
                 $orderDetailModel = $this->modelOrderDetail->findOneBy(array('id' => $orderDetailId));
                 // check quantity split every order
                 $orderDetail = new OrderDetail();
                 if ($qty > 0) {
                     if ($qty >= $oldQty) {
                         // update orderId for order detail
                         $orderDetailModel->setOrderId($lastOrderId);
                         if ($order['newCoupon'] != -1) {
                             $Cost = $orderDetailModel->getQuantity() * $orderDetailModel->getMenuCost();
                             $orderDetailModel->setDiscount($order['newCoupon']);
                             $orderDetailModel->setRealCost(Utility::getPriceUseCoupon($Cost, $order['newCoupon']));
                         }
                         $this->modelOrderDetail->edit($orderDetailModel);
                         $newCost = $orderDetailModel->getRealCost();
                     } else {
                         // insert new order detail
                         $realCost = $qty * Utility::getMenuValue($order['menuId'], $order['costType']);
                         $data['menuid'] = $order['menuId'];
                         $data['quantity'] = $qty;
                         $data['menuCost'] = $order['menuCost'];
                         $data['realcost'] = Utility::getPriceUseCoupon($realCost, $order['newCoupon']);
                         $data['orderDetailType'] = $order['costType'];
                         $data['discount'] = $order['newCoupon'];
                         $newCost = $data['realcost'];
                         Utility::insertOrderDetail($data, $lastOrderId);
                         // update old order-item detail
                         $lastQuantity = $order['oldQty'] - $order['qty'];
                         //                            if ($order['discountType'] != '' && $order['discountType'] == 0) {
                         //                                $newRealCost = ($lastQuantity * $order['menuCost']) - $order['discountValue'];
                         //                            } elseif ($order['discountType'] != '' && $order['discountType'] == 1) {
                         //                                $newRealCost = Utility::roundCost(($lastQuantity * $order['menuCost']) - ((($lastQuantity * $order['menuCost']) * $order['discountValue']) / 100));
                         //                            } else {
                         //                                $newRealCost = ($lastQuantity * $order['menuCost']);
                         //                            }   this code replace by static function Utility::getPriceUseCoupon(price,discountId);
                         $newRealCost = Utility::getPriceUseCoupon($lastQuantity * $order['menuCost'], $order['discountId']);
                         $orderDetailModel->setQuantity($lastQuantity);
                         $orderDetailModel->setRealCost($newRealCost);
                         $this->modelOrderDetail->edit($orderDetailModel);
                     }
                 } else {
                     $newRealCost = $orderDetailModel->getRealCost();
                 }
                 $oldPrice += $newRealCost;
                 $totalPrice += $newCost;
             }
             $oldOrderModel = $this->modelOrder->findOneBy(array('id' => $oldOrder));
             $oldOrderModel->setTotalRealCost($oldPrice);
             $oldOrderModel->setTotalCost($oldPrice);
             $this->modelOrder->edit($oldOrderModel);
             $newTotalPrice = $totalPrice;
             //                $coupon = Utility::getCouponInfo($discount);
             //
             //                if ($coupon->getType() == 0) {
             //
             //                    $realCostAfter = Utility::roundCost($newTotalPrice - $coupon->getValue());
             //
             //                } elseif ($coupon->getType() == 1) {
             //
             //                    $realCostAfter = Utility::roundCost($newTotalPrice - ($newTotalPrice * $coupon->getValue()) / 100);
             //
             //                } else {
             //
             //                    $realCostAfter = $newTotalPrice;
             //
             //                } this code replace by function Utility::getPriceUseCoupon(price,discountId);
             $realCostAfter = Utility::getPriceUseCoupon($newTotalPrice, $discount);
             //update last order
             $lastOrder = $this->modelOrder->findOneBy(array('id' => $lastOrderId));
             $lastOrder->setToTalRealCost($realCostAfter);
             $lastOrder->setTotalCost($newTotalPrice);
             $this->modelOrder->edit($lastOrder);
             // update old order
         }
     }
     $this->flashMessenger()->addSuccessMessage('Split order success!');
     return $this->redirect()->toRoute('frontend/child', array('controller' => 'order', 'action' => 'add'));
 }
Exemplo n.º 3
0
 function splitAction()
 {
     if ($this->getRequest()->isPost()) {
         $post = $this->params()->fromPost();
         $table = $post['table-new'];
         $discount = -1;
         //    $oldDiscount = $post['discount'];
         $oldOrder = $post['oldOrder'];
         unset($post['table-new']);
         unset($post['discount']);
         unset($post['oldOrder']);
         if (!empty($post)) {
             $Auth_service = new AuthenticationService();
             $auth = $Auth_service->getIdentity();
             $status = 'pending';
             $orderEntity = new Orders();
             $orderEntity->setTotalCost(0);
             $orderEntity->setTableId($table);
             $orderEntity->setCreateDate(time());
             $orderEntity->setCouponId(-1);
             $orderEntity->setToTalRealCost(0);
             $orderEntity->setUserId($auth->userId);
             $orderEntity->setSurtaxId(0);
             $orderEntity->setIsdelete(0);
             $orderEntity->setStatus($status);
             $orderEntity->setNewDate(date('Y-m-d H:i:s', time()));
             $orderLastInsert = $this->modelOrder->insert($orderEntity);
             $lastOrderId = $orderLastInsert->getId();
             $totalPrice = 0;
             $oldPrice = 0;
             $newRealCost = 0;
             //                echo '<pre>';
             //                print_r($post);die;
             foreach ($post as $order) {
                 $order['newCoupon'] = -1;
                 $orderDetailId = $order['orderDetailId'];
                 $oldQty = $order['oldQty'];
                 $qty = $order['qty'];
                 $totalRealCost = $order['menuCost'] * $order['oldQty'];
                 $qty >= $oldQty ? $qty = $oldQty : ($qty = $qty);
                 $orderDetailModel = $this->modelOrderDetail->findOneBy(array('id' => $orderDetailId));
                 // check quantity split every order
                 $orderDetail = new OrderDetail();
                 if ($qty > 0) {
                     if ($qty >= $oldQty) {
                         // update orderId for order detail
                         $orderDetailModel->setOrderId($lastOrderId);
                         //  if($order['newCoupon'] != -1){
                         $Cost = $orderDetailModel->getQuantity() * $orderDetailModel->getMenuCost();
                         //                                $orderDetailModel->setDiscount($order['newCoupon']);
                         //                                $orderDetailModel->setRealCost(Utility::getPriceUseCoupon($Cost,$order['newCoupon']));
                         $orderDetailModel->setDiscount(-1);
                         $orderDetailModel->setRealCost($Cost);
                         //    }
                         $this->modelOrderDetail->edit($orderDetailModel);
                         $newCost = $orderDetailModel->getRealCost();
                     } else {
                         // insert new order detail
                         $realCost = $qty * Utility::getMenuValue($order['menuId'], $order['costType']);
                         $data['menuid'] = $order['menuId'];
                         $data['quantity'] = $qty;
                         $data['menuCost'] = $order['menuCost'];
                         //                            $data['realcost'] = Utility::getPriceUseCoupon($realCost,$order['newCoupon']) ;
                         $data['realcost'] = $realCost;
                         $data['orderDetailType'] = $order['costType'];
                         //                            $data['discount'] = $order['newCoupon'];
                         $data['discount'] = -1;
                         $newCost = $data['realcost'];
                         Utility::insertOrderDetail($data, $lastOrderId);
                         // update old order-item detail
                         $lastQuantity = $order['oldQty'] - $order['qty'];
                         $newRealCost = $lastQuantity * $order['menuCost'];
                         $orderDetailModel->setQuantity($newRealCost);
                         $orderDetailModel->setRealCost($newRealCost);
                         $this->modelOrderDetail->edit($orderDetailModel);
                     }
                 } else {
                     //                        $newRealCost = $orderDetailModel->getRealCost();
                 }
             }
             $oldOrderModel = $this->modelOrder->findOneBy(array('id' => $oldOrder));
             $sumCost = $this->modelOrderDetail->createQuerySumOrderDetail($oldOrder);
             $returnCost = $sumCost[0]['realCost'];
             $oldTotalCost = $returnCost;
             //                $oldPrice = Utility::getPriceUseCoupon($oldTotalCost,$oldOrderModel->getCouponId());
             //                $oldPrice = Utility::getPriceUseSurtax($oldPrice,$oldOrderModel->getSurtaxId());
             $oldOrderModel->setTotalRealCost($oldTotalCost);
             $oldOrderModel->setTotalCost($oldTotalCost);
             $this->modelOrder->edit($oldOrderModel);
             $newTotalPrice = $totalPrice;
             $sumCostLast = $this->modelOrderDetail->createQuerySumOrderDetail($lastOrderId);
             $returnCostLast = $sumCostLast[0]['realCost'];
             //                $realCostAfter = Utility::getPriceUseCoupon($returnCostLast,$discount)  ;
             $realCostAfter = $returnCostLast;
             //update last order
             $lastOrder = $this->modelOrder->findOneBy(array('id' => $lastOrderId));
             $lastOrder->setToTalRealCost($realCostAfter);
             $lastOrder->setTotalCost($realCostAfter);
             $this->modelOrder->edit($lastOrder);
             // update old order
         }
     }
     $this->flashMessenger()->addSuccessMessage('Split order success!');
     return $this->redirect()->toRoute('frontend/child', array('controller' => 'order', 'action' => 'add'));
 }