Ejemplo n.º 1
0
 public function prepareList($page_size = 50)
 {
     $criteria = new CdbCriteria();
     $criteria->with = array('listener');
     if ($this->date_from) {
         $criteria->compare('listener.created', '>=' . date('Y-m-d H:i:s', strtotime($this->date_from . ' ' . $this->time_from)));
     }
     if ($this->date_to) {
         $criteria->compare('listener.created', '<=' . date('Y-m-d H:i:s', strtotime($this->date_to . ' ' . $this->time_to)));
     }
     $criteria->compare('listener.source', $this->source);
     $criteria->order = 'listener.created desc, t.created desc';
     $provider = new CActiveDataProvider(ListenerProcess, array('criteria' => $criteria, 'sort' => array('defaultOrder' => array('listener.created' => true, 'created' => false)), 'pagination' => array('pageSize' => empty($page_size) ? 10000 : $page_size)));
     return $provider;
 }
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     if ($model->approved_date != null) {
         Yii::app()->user->setFlash("error", "<strong>Error!</strong> PO already approved. Can't be edited...");
         //$this->redirect(array('/m2/vPorderInventory',));
         $this->redirect(array('view', "id" => $model->id));
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['vPorder'])) {
         $model->attributes = $_POST['vPorder'];
         if ($model->validate()) {
             if (Yii::app()->request->isAjaxRequest) {
                 $sqlinsert = "INSERT INTO v_porder_detail_temp (parent_id, item_id, description, qty, amount)\n\t\t\t\t\tVALUES (" . $model->id . ", " . $model->item_id . ", '" . $model->description . "', " . $model->qty . ", " . $model->amount . ")";
                 $command = Yii::app()->db->createCommand($sqlinsert);
                 $command->execute();
             } else {
                 $model->save();
                 //Delete Old Detail Data
                 $sqlDelete = "DELETE FROM v_porder_detail WHERE parent_id = ':id'";
                 $command = Yii::app()->db->createCommand($sqlDelete);
                 $command->bindParam(":id", $id, PDO::PARAM_STR);
                 $command->execute();
                 //Insert New Data
                 $sql = "INSERT INTO v_porder_detail (parent_id, item_id, description, qty, amount)\n\t\t\t\t\tSELECT :id, item_id, description, qty, amount FROM v_porder_detail_temp\n\t\t\t\t\tWHERE parent_id = ':id'";
                 $command = Yii::app()->db->createCommand($sql);
                 $command->bindParam(":id", $id, PDO::PARAM_STR);
                 $command->execute();
                 //Delete Temporary Data
                 $sqlD = "DELETE FROM v_porder_detail_temp WHERE parent_id = ':id'";
                 $command = Yii::app()->db->createCommand($sqlD);
                 $command->bindParam(":id", $id, PDO::PARAM_STR);
                 $command->execute();
                 $this->redirect(array('/m2/vPorderInventory'));
             }
         }
     }
     if (!Yii::app()->request->isAjaxRequest) {
         $criteria = new CdbCriteria();
         $criteria->compare('parent_id', $model->id);
         $models = vPorderDetail::model()->findAll($criteria);
         $sqlcount = "select count(*) FROM v_porder_detail_temp WHERE parent_id = '" . $model->id . "'";
         $command = Yii::app()->db->createCommand($sqlcount);
         $_count = $command->queryScalar();
         if ($_count == 0) {
             foreach ($models as $mod) {
                 $sql = "INSERT INTO v_porder_detail_temp (parent_id, item_id, description, qty, amount)\n\t\t\t\t\tVALUES (" . $mod->parent_id . ", " . $mod->item_id . ", '" . $mod->description . "', " . $mod->qty . ", " . $mod->amount . ")";
                 $command = Yii::app()->db->createCommand($sql);
                 $command->execute();
             }
         }
     }
     $sql = "SELECT * FROM v_porder_detail_temp WHERE parent_id = '" . $model->id . "'";
     $command = Yii::app()->db->createCommand($sql);
     $rawData = $command->queryAll();
     $dataProvider = new CArrayDataProvider($rawData, array('pagination' => false));
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('_formDetail', array('model' => $model, 'dataProvider' => $dataProvider));
     } else {
         $this->render('update', array('model' => $model, 'dataProvider' => $dataProvider));
     }
 }