Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TransferModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'branch_id' => $this->branch_id, 'branch_dest_id' => $this->branch_dest_id, 'date' => $this->date, 'status' => $this->status, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'number', $this->number]);
     return $dataProvider;
 }
Beispiel #2
0
 /**
  * Handler for Good Movement created.
  * It used to update stock
  * @param \dee\base\Event $event
  */
 public function goodsMovementApplied($event)
 {
     /* @var $model MGoodsMovement */
     $model = $event->params[0];
     /*
      * 300 = Transfer Release
      * 400 = Transfer Receive
      */
     if (!in_array($model->reff_type, [300, 400])) {
         return;
     }
     $type = $model->type;
     $transfer = MTransfer::findOne($model->reff_id);
     $transferDtls = ArrayHelper::index($transfer->transferDtls, 'product_id');
     // change total qty for reff document
     /* @var $transferDtl \biz\api\models\inventory\TransferDtl */
     foreach ($model->goodsMovementDtls as $detail) {
         $transferDtl = $transferDtls[$detail->product_id];
         if ($type == MGoodsMovement::TYPE_ISSUE) {
             $transferDtl->total_release += $detail->qty;
         } else {
             $transferDtl->total_receive += $detail->qty;
         }
         $transferDtl->save(false);
     }
     $complete = true;
     foreach ($transferDtls as $transferDtl) {
         if ($transferDtl->total_release != $transferDtl->qty) {
             $complete = false;
             break;
         }
     }
     if ($complete) {
         $transfer->status = MTransfer::STATUS_COMPLETE_RELEASE;
         $transfer->save(false);
     } elseif ($transfer->status == MTransfer::STATUS_DRAFT) {
         $transfer->status = MTransfer::STATUS_PARTIAL_RELEASE;
         $transfer->save(false);
     }
 }
Beispiel #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTransfer()
 {
     return $this->hasOne(Transfer::className(), ['id' => 'transfer_id']);
 }