예제 #1
0
 public function actionStruct()
 {
     $id = $_POST['type_id'];
     $mType = $_POST['mType'];
     $products = new Products();
     $stuff = new Halfstaff();
     $dish = new Dishes();
     $prodList = $products->getUseProdList();
     $stuffList = $stuff->getUseStuffList();
     $dishList = $dish->getUseDishList();
     $dishModel = Menu::model()->with('dish')->findAll('t.type_id = :typeId AND mType = :mType', array(':typeId' => $id, ':mType' => $mType));
     $prodModel = Menu::model()->with('products')->findAll('t.type_id = :typeId AND mType = :mType', array(':typeId' => $id, ':mType' => $mType));
     $stuffModel = Menu::model()->with('halfstuff')->findAll('t.type_id = :typeId AND mType = :mType', array(':typeId' => $id, ':mType' => $mType));
     $listDep = CHtml::listData(Department::model()->findAll(), 'department_id', 'name');
     $this->renderPartial('struct', array('id' => $id, 'mType' => $mType, 'listDep' => $listDep, 'dishModel' => $dishModel, 'prodModel' => $prodModel, 'stuffModel' => $stuffModel, 'prodList' => $prodList, 'stuffList' => $stuffList, 'dishList' => $dishList));
 }
예제 #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $chosenProduct = array();
     $products = new Products();
     $model = new Halfstaff();
     $prodList = $products->getUseProdList();
     $stuffList = $model->getUseStuffList();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Halfstaff'])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $_POST['Halfstaff']['count'] = $this->changeToFloat($_POST['Halfstaff']['count']);
             if ($_POST['Halfstaff']['count'] == '' or $_POST['Halfstaff']['count'] == 0) {
                 $_POST['Halfstaff']['count'] = 1;
             }
             $messageType = 'warning';
             $message = "There are some errors ";
             $model->attributes = $_POST['Halfstaff'];
             //$uploadFile=CUploadedFile::getInstance($model,'filename');
             if ($model->save()) {
                 if ($_POST['product_id'] != null) {
                     $count = 0;
                     $prodMes = "prod>";
                     for ($i = 0; $i < count($_POST['product_id']); $i++) {
                         $ss = $this->changeToFloat($_POST['prod'][$i]);
                         $struct = new HalfstuffStructure();
                         $struct->halfstuff_id = $model->halfstuff_id;
                         $struct->prod_id = $_POST['product_id'][$i];
                         $struct->amount = $ss;
                         $struct->types = 1;
                         if ($struct->save()) {
                             $prodMes .= $struct->prod_id . ":" . $struct->amount . ",";
                         }
                         $count++;
                     }
                 }
                 if ($_POST['stuff_id'] != null) {
                     $count = 0;
                     $stuffMes = "stuff>";
                     for ($i = 0; $i < count($_POST['stuff_id']); $i++) {
                         $ss = $this->changeToFloat($_POST['stuff'][$i]);
                         $struct = new HalfstuffStructure();
                         $struct->halfstuff_id = $model->halfstuff_id;
                         $struct->prod_id = $_POST['stuff_id'][$i];
                         $struct->amount = $ss;
                         $struct->types = 2;
                         if ($struct->save()) {
                             $stuffMes .= $struct->prod_id . ":" . $struct->amount . ",";
                         }
                         $count++;
                     }
                 }
                 $messageType = 'success';
                 $message = "<strong>Well done!</strong> You successfully create data ";
                 $this->logs('create', 'halfstaff', $model->halfstuff_id, $model->name . "->" . $prodMes . "=>" . $stuffMes);
                 $transaction->commit();
                 Yii::app()->user->setFlash($messageType, $message);
                 $this->redirect(array('view', 'id' => $model->halfstuff_id));
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             Yii::app()->user->setFlash('error', "{$e->getMessage()}");
             //$this->refresh();
         }
     }
     $this->render('create', array('model' => $model, 'prodList' => $prodList, 'stuffList' => $stuffList));
 }
예제 #3
0
 public function actionRefreshAdd()
 {
     $prod = new Products();
     $prodList = $prod->getUseProdList();
     $stuff = new Halfstaff();
     $stuffList = $stuff->getUseStuffList();
     $this->renderPartial('refreshAdd', array('stuffList' => $stuffList, 'prodList' => $prodList, 'form' => $_POST['form']));
 }