public static function rollbackTransaction($orderId)
 {
     $doctrine = self::$servicelocator->get('doctrine');
     $transactionModel = new transactionModel($doctrine);
     $transactionModel->delete(array('orderId' => $orderId));
     return true;
 }
示例#2
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()) {
             $Auth_service = new AuthenticationService();
             $auth = $Auth_service->getIdentity();
             if ($auth->userId) {
                 $tableId = $param->fromPost('table_id');
                 $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->setCustomerId(0);
                 $cat->setNewDate(date('Y-m-d H:i:s', time()));
                 $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;
                 } else {
                     $url = "http://" . $_SERVER['HTTP_HOST'] . '/frontend/order/add';
                     header("Location:" . $url);
                     exit;
                 }
             } else {
                 $url = "http://" . $_SERVER['HTTP_HOST'] . '/frontend/login';
                 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);
             $cat->setCustomerId(0);
             $cat->setNewDate(date('Y-m-d H:i:s', time()));
             $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));
             $transactionModel->deleteAll(array('orderId' => $id));
             // insert order detail
             foreach ($dataDetail as $k => $val) {
                 if ($val['menuid'] != -1) {
                     self::insertOrderDetail($val, $id);
                 }
             }
             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';
                 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);
     }
 }
 public function sortCostTransaction($menuStoreId)
 {
     $doctrine = self::$servicelocator->get('doctrine');
     $transactionModel = new transactionModel($doctrine);
     $transaction = $transactionModel->findBy(array('action' => 'N', 'menuStoreId' => $menuStoreId));
     $array = array();
     foreach ($transaction as $item) {
         $cost = $item->getCost();
         $quantity = $item->getQuantity();
         $supplier = $item->getSupplier();
         $unit = $item->getUnit();
         $info = array('supplier_id' => $supplier, 'cost' => $cost, 'quantity' => $quantity, 'rating' => self::exChangeCost($cost, $quantity), 'unit' => $unit);
         $array[] = $info;
     }
     return $array;
 }