/** * * @param \yii\web\Application $app * @param array $config */ protected function initialize($app, $config) { if ($app instanceof \yii\web\Application) { $app->attachBehaviors([hooks\TransferNoticeHook::className() => hooks\TransferNoticeHook::className()]); AppHelper::registerAccessHandler(models\Transfer::className(), AccessHandler::className()); AppHelper::registerAccessHandler(models\TransferNotice::className(), AccessHandler::className()); } }
/** * * @param Event $event */ public function receiveReceiveEnd($event) { $model = $event->params[0]; $noticeDtls = []; foreach ($model->transferDtls as $detail) { if ($detail->transfer_qty_send != $detail->transfer_qty_receive) { $noticeDtl = new TransferNoticeDtl(); $noticeDtl->id_product = $detail->id_product; $noticeDtl->qty_notice = $detail->transfer_qty_receive - $detail->transfer_qty_send; $noticeDtl->id_uom = $detail->id_uom; $noticeDtls[] = $noticeDtl; } } if (count($noticeDtls)) { $notice = new TransferNotice(); $notice->description = 'Qty kirim tidak sama dengan qty terima'; $notice->notice_date = date('Y-m-d'); $notice->status = TransferNotice::STATUS_CREATE; $notice->id_transfer = $model->id_transfer; if (!$notice->save()) { throw new \Exception(implode("\n", $notice->firstErrors)); } Yii::$app->trigger(Hooks::E_TNCRE_21, new Event([$notice])); foreach ($noticeDtls as $noticeDtl) { $noticeDtl->id_transfer = $notice->id_transfer; if (!$noticeDtl->save()) { throw new \Exception(implode("\n", $noticeDtl->firstErrors)); } Yii::$app->trigger(Hooks::E_TNCRE_22, new Event([$notice, $noticeDtl])); } Yii::$app->trigger(Hooks::E_TNCRE_23, new Event([$notice])); } }
public function search($params) { $query = TransferNoticeModel::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id_transfer' => $this->id_transfer, 'notice_date' => $this->notice_date, 'status' => $this->status, 'update_by' => $this->update_by, 'create_by' => $this->create_by]); $query->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'create_at', $this->create_at])->andFilterWhere(['like', 'update_at', $this->update_at]); return $dataProvider; }
/** * Finds the TransferNotice model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return TransferNotice the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TransferNotice::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getTransferNotice() { return $this->hasOne(TransferNotice::className(), ['id_transfer' => 'id_transfer']); }