From: marina Date: Tue, 3 Dec 2024 07:27:05 +0000 (+0300) Subject: ERP-243 Действия по замене (II этап) X-Git-Tag: 1.7~203^2~3 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=95e7776823a15b442de8acd87398fdc91a536d0d;p=erp24_rep%2Fyii-erp24%2F.git ERP-243 Действия по замене (II этап) --- diff --git a/erp24/controllers/StoreBalanceController.php b/erp24/controllers/StoreBalanceController.php new file mode 100644 index 00000000..30473058 --- /dev/null +++ b/erp24/controllers/StoreBalanceController.php @@ -0,0 +1,65 @@ + StoreBalance::find(), + 'pagination' => [ + 'pageSize' => 20, + ], + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a detailed view of a single StoreBalance record. + * + * @param int $id + * @return mixed + * @throws NotFoundHttpException + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Finds the StoreBalance model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param int $id + * @return StoreBalance + * @throws NotFoundHttpException + */ + protected function findModel($id) + { + if (($model = StoreBalance::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/erp24/records/StoreBalance.php b/erp24/records/StoreBalance.php index 178b85be..83a9a532 100644 --- a/erp24/records/StoreBalance.php +++ b/erp24/records/StoreBalance.php @@ -22,6 +22,11 @@ use Yii; */ class StoreBalance extends \yii\db\ActiveRecord { + + public const STATUS_NEW = 0; + + public const REPLACEMENT_ACTIONS = 2; + /** * {@inheritdoc} */ @@ -30,6 +35,52 @@ class StoreBalance extends \yii\db\ActiveRecord return 'store_balance'; } + public static function setData($shiftTransfer) + { + + $equalizationData = EqualizationRemains::find() + ->where(['shift_id' => $shiftTransfer->id]) + ->select([ + 'product_id', + 'product_count', + 'product_price', + 'product_self_cost', + 'product_replacement_id', + 'product_replacement_count', + 'product_replacement_price', + 'product_replacement_self_cost', + 'balance', + 'balance_self_cost' + ]) + ->asArray() + ->all() ?? ''; + + $articule = implode(';', array_map(fn($equalizationRemain) => + $equalizationRemain->product->articule . '=>' . $equalizationRemain->productReplacement->articule, + EqualizationRemains::findAll(['shift_id' => $shiftTransfer->id]))) ?? '' . ';'; + + $model = new self(); + $model->setAttributes([ + 'store_id' => $shiftTransfer->store_guid, + 'shift_id' => $shiftTransfer->id, + 'date' => $shiftTransfer->date, + 'amount' => EqualizationRemains::find() + ->where(['shift_id' => $shiftTransfer->id]) + ->select(['SUM(balance) AS total_balance']) + ->scalar() ?? '', + 'status_id' => self::STATUS_NEW, + 'comment' => $shiftTransfer->comment, + 'json' => json_encode($equalizationData), + 'replace_articule' => $articule, + 'type_id' => self::REPLACEMENT_ACTIONS, + ]); + if ($model->validate()) { + $model->save(); + } else { + var_dump($model->errors); + } + } + /** * {@inheritdoc} */ @@ -53,17 +104,17 @@ class StoreBalance extends \yii\db\ActiveRecord { return [ 'id' => 'ID', - 'store_id' => 'Store ID', - 'shift_id' => 'Shift ID', - 'date' => 'Date', - 'amount' => 'Amount', - 'status_id' => 'Status ID', - 'comment' => 'Comment', - 'json' => 'Json', - 'replace_articule' => 'Replace Articule', - 'comment_controler' => 'Comment Controler', - 'controler_id' => 'Controler ID', - 'type_id' => 'Type ID', + 'store_id' => 'GUID магазина', + 'shift_id' => 'ID смены', + 'date' => 'Дата и время внесения', + 'amount' => 'Сумма остатков', + 'status_id' => 'Статус записи', + 'comment' => 'Комментарий смены', + 'json' => 'Массив с товарами', + 'replace_articule' => 'Заменённые товары', + 'comment_controler' => 'Комментарий контроллера', + 'controler_id' => 'ID сотрудника (контролёр)', + 'type_id' => 'Тип записи', ]; } } diff --git a/erp24/views/shift-transfer/_replacement.php b/erp24/views/shift-transfer/_replacement.php index 018bd9b2..cafe8a43 100644 --- a/erp24/views/shift-transfer/_replacement.php +++ b/erp24/views/shift-transfer/_replacement.php @@ -223,11 +223,16 @@ if (in_array($shiftTransfer->status_id, [ShiftTransfer::STATUS_ID_TRANSFER_ACTIO ]); if (Yii::$app->user->id === $shiftTransfer->start_shift_admin_id && $shiftTransfer->status_id == ShiftTransfer::STATUS_ID_READY_TO_ACCEPT) { - echo $btn = Html::submitButton('Принять', [ - 'class' => 'btn btn-primary float-right', - 'name' => 'action', - 'value' => 'accept' - ]); + echo Html::submitButton('Принять', [ + 'class' => 'btn btn-primary float-right', + 'name' => 'action', + 'value' => 'accept' + ]) . '  ' . Html::submitButton('Отказ', [ + 'class' => 'btn btn-primary float-right', + 'name' => 'action', + 'value' => 'rejection' + ]); + } } diff --git a/erp24/views/store-balance/index.php b/erp24/views/store-balance/index.php new file mode 100644 index 00000000..55b5f054 --- /dev/null +++ b/erp24/views/store-balance/index.php @@ -0,0 +1,35 @@ +title = 'Store Balances'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'store_id', + 'shift_id', + 'date', + 'amount', + 'status_id', + 'type_id', + 'comment_controler', + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{view}', // только кнопка просмотра + ], + ], + ]); ?> +
diff --git a/erp24/views/store-balance/view.php b/erp24/views/store-balance/view.php new file mode 100644 index 00000000..d593eebb --- /dev/null +++ b/erp24/views/store-balance/view.php @@ -0,0 +1,70 @@ +title = 'Детали баланса магазина: ' . $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Баланс магазинов', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ 'btn btn-primary']) ?> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDid) ?>
Магазинstore_id) ?>
Сменаshift_id) ?>
Датаdate) ?>
Суммаamount) ?>
Статусstatus_id) ?>
Комментарийcomment) ?>
JSONjson) ?>
Заменить товарыreplace_articule) ?>
Комментарий контролераcomment_controler) ?>
ID контролераcontroler_id) ?>
Типtype_id) ?>
+