]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-243 Действия по замене (II этап)
authormarina <m.zozirova@gmail.com>
Tue, 3 Dec 2024 07:27:05 +0000 (10:27 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 3 Dec 2024 07:27:05 +0000 (10:27 +0300)
erp24/controllers/StoreBalanceController.php [new file with mode: 0644]
erp24/records/StoreBalance.php
erp24/views/shift-transfer/_replacement.php
erp24/views/store-balance/index.php [new file with mode: 0644]
erp24/views/store-balance/view.php [new file with mode: 0644]

diff --git a/erp24/controllers/StoreBalanceController.php b/erp24/controllers/StoreBalanceController.php
new file mode 100644 (file)
index 0000000..3047305
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+
+namespace app\controllers;
+
+use Yii;
+use yii\data\ActiveDataProvider;
+use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+use yii_app\records\StoreBalance;
+
+/**
+ * StoreBalanceController реализует действия для модели StoreBalance.
+ */
+class StoreBalanceController extends Controller
+{
+    /**
+     * Displays a list of all StoreBalance records.
+     *
+     * @return mixed
+     */
+    public function actionIndex()
+    {
+        $dataProvider = new ActiveDataProvider([
+            'query' => 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.');
+    }
+}
index 178b85be8399736422054790a9cf5f95d8aa9112..83a9a532ad12a9437e95d81f6850b30f424e48c3 100644 (file)
@@ -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' => 'Тип записи',
         ];
     }
 }
index 018bd9b2bb8d54596f161d894f52db243ccb86dc..cafe8a430e7c8393804a2724d2a517ce250a7ee8 100644 (file)
@@ -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'
+            ]) . '&nbsp;&nbsp;' . 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 (file)
index 0000000..55b5f05
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+use yii\helpers\Html;
+use yii\grid\GridView;
+
+/* @var $this yii\web\View */
+/* @var $dataProvider yii\data\ActiveDataProvider */
+
+$this->title = 'Store Balances';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="store-balance-index">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= GridView::widget([
+        'dataProvider' => $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}', // только кнопка просмотра
+            ],
+        ],
+    ]); ?>
+</div>
diff --git a/erp24/views/store-balance/view.php b/erp24/views/store-balance/view.php
new file mode 100644 (file)
index 0000000..d593eeb
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+
+use yii\helpers\Html;
+
+/* @var $this yii\web\View */
+/* @var $model app\models\StoreBalance */
+
+$this->title = 'Детали баланса магазина: ' . $model->id;
+$this->params['breadcrumbs'][] = ['label' => 'Баланс магазинов', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="store-balance-view">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Вернуться к списку', ['index'], ['class' => 'btn btn-primary']) ?>
+    </p>
+
+    <table class="table table-striped">
+        <tr>
+            <th>ID</th>
+            <td><?= Html::encode($model->id) ?></td>
+        </tr>
+        <tr>
+            <th>Магазин</th>
+            <td><?= Html::encode($model->store_id) ?></td>
+        </tr>
+        <tr>
+            <th>Смена</th>
+            <td><?= Html::encode($model->shift_id) ?></td>
+        </tr>
+        <tr>
+            <th>Дата</th>
+            <td><?= Html::encode($model->date) ?></td>
+        </tr>
+        <tr>
+            <th>Сумма</th>
+            <td><?= Html::encode($model->amount) ?></td>
+        </tr>
+        <tr>
+            <th>Статус</th>
+            <td><?= Html::encode($model->status_id) ?></td>
+        </tr>
+        <tr>
+            <th>Комментарий</th>
+            <td><?= Html::encode($model->comment) ?></td>
+        </tr>
+        <tr>
+            <th>JSON</th>
+            <td><?= Html::encode($model->json) ?></td>
+        </tr>
+        <tr>
+            <th>Заменить товары</th>
+            <td><?= Html::encode($model->replace_articule) ?></td>
+        </tr>
+        <tr>
+            <th>Комментарий контролера</th>
+            <td><?= Html::encode($model->comment_controler) ?></td>
+        </tr>
+        <tr>
+            <th>ID контролера</th>
+            <td><?= Html::encode($model->controler_id) ?></td>
+        </tr>
+        <tr>
+            <th>Тип</th>
+            <td><?= Html::encode($model->type_id) ?></td>
+        </tr>
+    </table>
+</div>