예제 #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);
     }
 }
예제 #2
0
 static function deleteExpireCoupon()
 {
     $doctrine = self::$servicelocator->get('doctrine');
     $couponModel = new couponModel($doctrine);
     $array = $couponModel->delExpireCoupon();
     foreach ($array as $coupon) {
         $coupon->setIsDelete(1);
         $couponModel->edit($coupon);
     }
 }