--- /dev/null
+<?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.');
+ }
+}
*/
class StoreBalance extends \yii\db\ActiveRecord
{
+
+ public const STATUS_NEW = 0;
+
+ public const REPLACEMENT_ACTIONS = 2;
+
/**
* {@inheritdoc}
*/
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}
*/
{
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' => 'Тип записи',
];
}
}
]);
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'
+ ]);
+
}
}
--- /dev/null
+<?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>
--- /dev/null
+<?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>