Пример #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Contracts();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_GET['byorder']) and is_numeric($_GET['byorder'])) {
         $order_id = (int) $_GET['byorder'];
         $model->order_id = $order_id;
         $model->order = Orders::model()->findByPk($order_id);
         $model->name = $model->order->name;
         $model->client_id = $model->order->client_id;
         $model->sum = Yii::app()->db->createCommand()->select('SUM(cost*quantity) as order_sum')->from('{{works}}')->where('{{works}}.order_id = ' . $order_id)->queryScalar();
         $model->num = Yii::app()->db->createCommand()->select('max(num*1) as max')->from('{{contracts}}')->queryScalar();
         $model->num = $model->num + 1;
         if (isset($_POST['Contracts'])) {
             //			CVarDumper::dump($_POST['Contracts'],10,true);die;
             $model->attributes = $_POST['Contracts'];
             if ($model->save()) {
                 $msg = 'Договор #' . $model->id . ' - ' . $model->name . ' для ' . $model->client->name . ' создан';
                 Yii::app()->user->setFlash('success', $msg);
                 Yii::app()->logger->write($msg);
                 if (isset($order_id)) {
                     $this->redirect(array('orders/view', 'id' => $order_id));
                 } else {
                     $this->redirect(array('view', 'id' => $model->id));
                 }
             }
         }
     }
     $model->date = $model->isNewRecord ? date('Y-m-d') : $model->date;
     $this->render('create', array('model' => $model));
 }
Пример #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($specid)
 {
     $model = Contracts::model()->find("PersonSpecialityID = {$specid}");
     if (!empty($model)) {
         $this->redirect(Yii::app()->createUrl("pfd/contracts/update", array("id" => $model->idContract)));
     }
     $model = new Contracts();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $this->layout = '/layouts/column2_1';
     if (isset($_POST['Contracts'])) {
         $model->attributes = $_POST['Contracts'];
         if ($model->save()) {
             $this->redirect(Yii::app()->createUrl('pfd/contracts/view', array('id' => $model->idContract)));
         }
     }
     $this->render('create', array('model' => $model, 'specid' => $specid));
 }