Esempio n. 1
0
 /**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new PurchaseOrderDetail();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = 'Create';
             $log->object_class = 'PurchaseOrderDetail';
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         if ($model->save()) {
             if ($log) {
                 $log->object_pk = $model->id;
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PurchaseOrderDetail::find();
     if (!empty($params['purchase_order_id'])) {
         $query->where(['purchase_order_id' => $params['purchase_order_id']]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'purchase_order_id' => $this->purchase_order_id, 'purchase_order_id' => $this->purchase_order_id, 'unit_price' => $this->unit_price, 'quantity' => $this->quantity, 'discount_percent' => $this->discount_percent, 'is_offer' => $this->is_offer]);
     $query->andFilterWhere(['like', 'product_name', $this->product_name])->andFilterWhere(['like', 'product_code', $this->product_code])->andFilterWhere(['like', 'color_code', $this->color_code])->andFilterWhere(['like', 'customer_note', $this->customer_note])->andFilterWhere(['like', 'user_note', $this->user_note]);
     return $dataProvider;
 }
 /**
  * Deletes an existing PurchaseOrder model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if ($model = $this->findModel($id)) {
         foreach (PurchaseOrderDetail::findAll(['purchase_order_id' => $model->id]) as $item) {
             $item->delete();
         }
         $model->delete();
         return $this->goBack(Url::previous());
     } else {
         throw new NotFoundHttpException();
     }
 }
Esempio n. 4
0
 /**
  * @return ActiveQuery
  */
 public function getPurchaseOrderDetails()
 {
     return $this->hasMany(PurchaseOrderDetail::className(), ['purchase_order_id' => 'id']);
 }
 /**
  * Finds the PurchaseOrderDetail model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return PurchaseOrderDetail the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PurchaseOrderDetail::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }