return $this->render('index', compact('shiftTransfers', 'storeNameById', 'admins'));
}
+ public function buildLoadDataShiftRemains($groups, $storeGuid) {
+ $productsClass = ProductsClass::find()->select(['category_id'])->where(['tip' => $groups])->column();
+ $products = ArrayHelper::map(Products1c::find()->select(['id', 'name'])
+ ->where(['parent_id' => $productsClass])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name');
+ $balance = ArrayHelper::map(Balances::find()->select(['quantity', 'product_id'])
+ ->where(['store_id' => $storeGuid])->all(), 'product_id', 'quantity');
+ $productGuids = [];
+ foreach ($products as $key => $name) {
+ if (isset($balance[$key])) {
+ $productGuids[$key] = $name . ' (' . $balance[$key] . ' шт.)';
+ }
+ else {
+ $productGuids[$key] = $name;
+ }
+ }
+ $price = ArrayHelper::map(Prices::find()->select(['product_id', 'price'])->where(['product_id' => array_keys($products)])->all(), 'product_id', 'price');
+ $storeEIT = ExportImportTable::find()->select(['entity_id'])->where(['entity' => 'city_store', 'export_val' => $storeGuid, 'export_id' => 1])->one();
+ $selfCost = ArrayHelper::map(SelfCostProduct::find()->select(['product_guid', 'price'])->where(['product_guid' =>
+ array_keys($products), 'store_id' => $storeEIT->entity_id])->all(), 'product_guid', 'price');
+
+ $loadDataShiftRemains = [];
+ foreach ($productGuids as $key => $name) {
+ $loadDataShiftRemains[]= [
+ 'product_guid' => $key, 'retail_price' => $price[$key] ?? '',
+ 'self_cost' => $selfCost[$key] ?? '',
+ 'remains_summ' => isset($price[$key]) && isset($balance[$key]) ? $price[$key] * $balance[$key]: '',
+ 'remains_count' => $balance[$key] ?? '',
+ 'fact_and_1c_diff' => 0, 'remains_1c' => $balance[$key] ?? ''
+ ];
+ }
+ return compact('loadDataShiftRemains', 'productGuids');
+ }
+
public function actionCreate()
{
$shiftTransfer = new ShiftTransfer;
$shiftTransfer->date_start = $shiftTransfer->date;
$shiftTransfer->status_id = ShiftTransfer::STATUS_ID_INPUT_FACT_REMAINS;
$shiftTransfer->end_shift_admin_id = Yii::$app->user->id;
+ $shiftTransfer->groups2 = [ProductsClass::HINT_OTHER_ITEMS];
$isCreate = true;
$storeNameById = TaskService::getEntitiesByAlias('store');
$storeGuids = AdminStores::find()->select(['store_guid'])->where(['admin_id' => Yii::$app->user->id])->column();
+ $firstId = null;
foreach ($storeNameById as $id => $name) {
if (!in_array($id, $storeGuids)) {
unset($storeNameById[$id]);
+ continue;
+ }
+ if (!$firstId) {
+ $firstId = $id;
}
}
- return $this->render('update', compact('shiftTransfer', 'isCreate', 'storeNameById'));
+ $data = self::buildLoadDataShiftRemains($shiftTransfer->groups2, $firstId);
+ $loadDataShiftRemains = $data['loadDataShiftRemains'];
+ $productGuids = $data['productGuids'];
+
+ $shiftTransfer->shiftRemainsCopy = $loadDataShiftRemains ?? $shiftTransfer->shiftRemains;
+
+ return $this->render('update', compact('shiftTransfer', 'isCreate', 'storeNameById', 'productGuids'));
}
public function actionUpdate($id = null)
$loadDataShiftRemains = null;
if ($shiftTransfer->load(Yii::$app->request->post())) {
$postShiftTransfer = Yii::$app->request->post('ShiftTransfer');
- $loadDataShiftRemains = ArrayHelper::getValue($postShiftTransfer, 'shiftRemainsCopy');
-
- if ($shiftTransfer->id || ($shiftTransfer->validate() && $shiftTransfer->save())) {
- ShiftRemains::deleteAll(['shift_transfer_id' => $shiftTransfer->id]);
- $modelsShiftRemains = MultipleModel::createMultipleModel(ShiftRemains::class,
- 'ShiftTransfer', 'shiftRemainsCopy');
- if (!empty($loadDataShiftRemains)) {
- MultipleModel::loadMultipleFromArray($modelsShiftRemains, $loadDataShiftRemains, '', []);
- }
+ $action = Yii::$app->request->post('action');
+ if ($action == 'applyGroups') {
+ $data = self::buildLoadDataShiftRemains(array_merge(empty($postShiftTransfer['groups1']) ? [] : $postShiftTransfer['groups1'],
+ empty($postShiftTransfer['groups2']) ? [] : $postShiftTransfer['groups2']), $postShiftTransfer['store_guid']);
+ $loadDataShiftRemains = $data['loadDataShiftRemains'];
+ $productGuids = $data['productGuids'];
+ } else {
+ $loadDataShiftRemains = ArrayHelper::getValue($postShiftTransfer, 'shiftRemainsCopy');
+
+ if ($shiftTransfer->id || ($shiftTransfer->validate() && $shiftTransfer->save())) {
+ ShiftRemains::deleteAll(['shift_transfer_id' => $shiftTransfer->id]);
+ $modelsShiftRemains = MultipleModel::createMultipleModel(ShiftRemains::class,
+ 'ShiftTransfer', 'shiftRemainsCopy');
+ if (!empty($loadDataShiftRemains)) {
+ MultipleModel::loadMultipleFromArray($modelsShiftRemains, $loadDataShiftRemains, '', []);
+ }
- foreach ($modelsShiftRemains as $modelsShiftRemain) {
- $modelsShiftRemain->shift_transfer_id = $shiftTransfer->id;
- if ($modelsShiftRemain->validate()) {
- $modelsShiftRemain->save();
- } else {
- var_dump($modelsShiftRemain->getErrors());
- die;
+ foreach ($modelsShiftRemains as $modelsShiftRemain) {
+ $modelsShiftRemain->shift_transfer_id = $shiftTransfer->id;
+ if ($modelsShiftRemain->validate()) {
+ $modelsShiftRemain->save();
+ } else {
+ var_dump($modelsShiftRemain->getErrors());
+ die;
+ }
}
- }
- if ($shiftTransfer->validate()) {
- $shiftTransfer->goods_transfer_summ = array_sum(ArrayHelper::getColumn($shiftTransfer->shiftRemains, 'remains_summ'));
- $shiftTransfer->goods_transfer_count = array_sum(ArrayHelper::getColumn($shiftTransfer->shiftRemains, 'remains_count'));
- $shiftTransfer->discrepancy_pieces = array_sum(ArrayHelper::getColumn($shiftTransfer->shiftRemains, 'fact_and_1c_diff'));
- $shiftTransfer->discrepancy_rubles = array_sum(ArrayHelper::getColumn($shiftTransfer->shiftRemains, 'remains_1c'));
- $shiftTransfer->status_id = ShiftTransfer::STATUS_ID_TRANSFER_ACTIONS;
- $shiftTransfer->save();
+ if ($shiftTransfer->validate()) {
+ $shiftTransfer->goods_transfer_summ = array_sum(ArrayHelper::getColumn($shiftTransfer->shiftRemains, 'remains_summ'));
+ $shiftTransfer->goods_transfer_count = array_sum(ArrayHelper::getColumn($shiftTransfer->shiftRemains, 'remains_count'));
+ $shiftTransfer->discrepancy_pieces = array_sum(ArrayHelper::getColumn($shiftTransfer->shiftRemains, 'fact_and_1c_diff'));
+ $shiftTransfer->discrepancy_rubles = array_sum(ArrayHelper::getColumn($shiftTransfer->shiftRemains, 'remains_1c'));
+ $shiftTransfer->status_id = ShiftTransfer::STATUS_ID_TRANSFER_ACTIONS;
+ $shiftTransfer->setProductGroups();
+ $shiftTransfer->save();
- Yii::$app->session->setFlash('info', 'Документ передачи смены успешно сохранён. Сейчас документ находится в статусе Действия по замене.<br>' .
- 'Для продолжения оформления документа в таблице возможных замен добавьте замену недостающего товара.');
+ Yii::$app->session->setFlash('info', 'Документ передачи смены успешно сохранён. Сейчас документ находится в статусе Действия по замене.<br>' .
+ 'Для продолжения оформления документа в таблице возможных замен добавьте замену недостающего товара.');
- return $this->redirect(['/shift-transfer/view', 'id' => $shiftTransfer->id]);
- }
+ return $this->redirect(['/shift-transfer/view', 'id' => $shiftTransfer->id]);
+ }
+ }
}
}
$shiftTransfer->shiftRemainsCopy = $loadDataShiftRemains ?? $shiftTransfer->shiftRemains;
- return $this->render('update', compact('shiftTransfer', 'isCreate', 'storeNameById'));
+ return $this->render('update', compact('shiftTransfer', 'isCreate', 'storeNameById', 'productGuids'));
}
--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m241205_080132_alter_table_shift_transfer_product_groups
+ */
+class m241205_080132_alter_table_shift_transfer_product_groups extends Migration
+{
+ const TABLE_NAME = 'erp24.shift_transfer';
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $this->addColumn(self::TABLE_NAME, 'product_groups', $this->text()->null()->comment('Список alias выбранных чекбоксов, через запятую'));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropColumn(self::TABLE_NAME, 'product_groups');
+ }
+}
* @property float|null $discrepancy_rubles Расхождение факта, руб.
* @property string|null $comment Комментарий принимающей стороны
* @property string|null $report в формате HTML или TXT или JSON внешний вид всех данных при приеме
+ * @property string|null $product_groups Список alias выбранных чекбоксов, через запятую
*/
class ShiftTransfer extends \yii\db\ActiveRecord
{
public $shiftRemainsCopy;
+ public $groups1;
+ public $groups2;
const STATUS_ID_INPUT_FACT_REMAINS = 1;
const STATUS_ID_TRANSFER_ACTIONS = 2;
[['status_id', 'date', 'date_start', 'store_guid', 'end_shift_admin_id'], 'required'],
[['status_id', 'end_shift_admin_id', 'start_shift_admin_id'], 'default', 'value' => null],
[['status_id', 'end_shift_admin_id', 'start_shift_admin_id'], 'integer'],
- [['date_start', 'date_end'], 'safe'],
+ [['date_start', 'date_end', 'groups1', 'groups2'], 'safe'],
[['goods_transfer_summ', 'goods_transfer_count', 'discrepancy_pieces', 'discrepancy_rubles'], 'number'],
- [['comment', 'report'], 'string'],
+ [['comment', 'report', 'product_groups'], 'string'],
[['date', 'store_guid'], 'string', 'max' => 36],
];
}
'discrepancy_rubles' => 'Расхождение факта, руб.',
'comment' => 'Комментарий',
'report' => 'Отчёт',
+ 'product_groups' => 'Продуктовые группы',
+ 'groups1' => 'Другая группа',
+ 'groups2' => 'Основная группа'
];
}
{
return $this->hasMany(EqualizationRemains::class, ['shift_id' => 'id']);
}
+
+ public function setGroups() {
+ function cb($a) { return $a != 'other_items'; }
+ function cb2($a) { return $a == 'other_items'; }
+ $this->groups1 = array_filter(explode(',', $this->product_groups ?? ''), 'cb');
+ $this->groups2 = array_filter(explode(',', $this->product_groups ?? ''), 'cb2');
+ }
+
+ public function setProductGroups() {
+ $this->product_groups = implode(',', array_merge(empty($this->groups1) ? [] : $this->groups1, empty($this->groups2) ? [] : $this->groups2));
+ }
}
/* @var $isCreate bool */
/* @var $shiftTransfer ShiftTransfer */
/* @var $storeNameById array */
+/* @var $productGuids array */
$this->registerJsFile('/js/shift-transfer/update.js', ['position' => \yii\web\View::POS_END]);
<div class="row">
<div class="col-6">
- <?= $form->field($shiftTransfer, 'store_guid')->dropDownList($storeNameById, ['onchange' => 'updateProductsWithBalanceAll();']) ?>
+ <?= $form->field($shiftTransfer, 'store_guid')->dropDownList($storeNameById, ['onchange'
+ => 'const inp = document.createElement("input"); inp.setAttribute("type", "hidden"); inp.setAttribute("name", "action");' .
+ ' inp.setAttribute("value", "applyGroups"); this.form.append(inp); this.form.submit();']) ?>
</div>
</div>
</div>
</div>
+ <div class="row">
+ <details>
+ <summary>Другие</summary>
+ <div class="col-9">
+ <?php $hints1 = ProductsClass::getHints(); unset($hints1['other_items']); ?>
+ <?= $form->field($shiftTransfer, 'groups1')->checkboxList($hints1, ['checked' => 1]) ?>
+ </div>
+ </details>
+ <div class="col-9">
+ <?php $hints2 = [ProductsClass::HINT_OTHER_ITEMS => 'Номенклатура 1%'] ?>
+ <?= $form->field($shiftTransfer, 'groups2')->checkboxList($hints2, ['checked' => 1]) ?>
+ </div>
+ <div class="col-2 mt-5">
+ <?= Html::submitButton('Применить', ['class' => 'btn btn-success', 'name' => 'action', 'value' => 'applyGroups']) ?>
+ </div>
+ </div>
+
<div class="row">
<div class="col-12">
<?= $form->field($shiftTransfer, 'shiftRemainsCopy')->widget(MultipleInput::class, [
'title' => 'Продукт',
'type' => Select2::class,
'options' => [
- 'data' => ArrayHelper::map(Products1c::find()->select(['id', 'name'])
- ->where(['tip' => 'products'])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'),
+ 'data' => $productGuids,
+// ArrayHelper::map(Products1c::find()->select(['id', 'name'])
+// ->where(['tip' => 'products'])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'),
],
'value' => function($data) {
return $data['product_guid'] ?? '';
'style' => 'width: 70px;',
]
],
- [
+ /*[
'name' => 'group_label',
'title' => 'Название группы',
'type' => Select2::class,
'headerOptions' => [
'style' => 'width: 70px;',
]
- ],
+ ], */
[
- 'name' => 'retail_price',
- 'title' => 'РозниÑ\87наÑ\8f Ñ\86ена, Ñ\80Ñ\83б',
+ 'name' => 'remains_count',
+ 'title' => 'ФакÑ\82иÑ\87еÑ\81кие оÑ\81Ñ\82аÑ\82ки кол-во, Ñ\88Ñ\82',
'type' => BaseColumn::TYPE_TEXT_INPUT,
- 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true],
+ 'options' => ['type' => 'number', 'step' => 1/*, 'min' => 0*/],
'value' => function($data) {
- return $data['retail_price'] ?? '';
+ return $data['remains_count'] ?? '';
},
'headerOptions' => [
'style' => 'width: 70px;',
]
],
[
- 'name' => 'self_cost',
- 'title' => 'СебеÑ\81Ñ\82оимоÑ\81Ñ\82Ñ\8c, Ñ\80Ñ\83б',
+ 'name' => 'fact_and_1c_diff',
+ 'title' => 'РазниÑ\86а Ñ\84акÑ\82 и по пÑ\80огÑ\80амме 1Ñ\81, Ñ\88Ñ\82',
'type' => BaseColumn::TYPE_TEXT_INPUT,
'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true],
'value' => function($data) {
- return $data['self_cost'] ?? '';
+ return $data['fact_and_1c_diff'] ?? '';
},
'headerOptions' => [
'style' => 'width: 70px;',
]
],
[
- 'name' => 'remains_summ',
- 'title' => 'СÑ\83мма оÑ\81Ñ\82аÑ\82ков (недоÑ\81Ñ\82аÑ\87а или излиÑ\88ек), Ñ\80Ñ\83б',
+ 'name' => 'remains_1c',
+ 'title' => 'Ð\9eÑ\81Ñ\82аÑ\82ки по 1Ñ\81, Ñ\88Ñ\82',
'type' => BaseColumn::TYPE_TEXT_INPUT,
'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true],
'value' => function($data) {
- return $data['remains_summ'] ?? '';
+ return $data['remains_1c'] ?? '';
},
'headerOptions' => [
'style' => 'width: 70px;',
]
],
[
- 'name' => 'remains_count',
- 'title' => 'ФакÑ\82иÑ\87еÑ\81кие оÑ\81Ñ\82аÑ\82ки кол-во, Ñ\88Ñ\82',
+ 'name' => 'retail_price',
+ 'title' => 'РозниÑ\87наÑ\8f Ñ\86ена, Ñ\80Ñ\83б',
'type' => BaseColumn::TYPE_TEXT_INPUT,
- 'options' => ['type' => 'number', 'step' => 1, 'min' => 0],
+ 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true],
'value' => function($data) {
- return $data['remains_count'] ?? '';
+ return $data['retail_price'] ?? '';
},
'headerOptions' => [
'style' => 'width: 70px;',
]
],
[
- 'name' => 'fact_and_1c_diff',
- 'title' => 'РазниÑ\86а Ñ\84акÑ\82 и по пÑ\80огÑ\80амме 1Ñ\81, Ñ\88Ñ\82',
+ 'name' => 'self_cost',
+ 'title' => 'СебеÑ\81Ñ\82оимоÑ\81Ñ\82Ñ\8c, Ñ\80Ñ\83б',
'type' => BaseColumn::TYPE_TEXT_INPUT,
'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true],
'value' => function($data) {
- return $data['fact_and_1c_diff'] ?? '';
+ return $data['self_cost'] ?? '';
},
'headerOptions' => [
'style' => 'width: 70px;',
]
],
[
- 'name' => 'remains_1c',
- 'title' => 'Ð\9eÑ\81Ñ\82аÑ\82ки по 1Ñ\81, Ñ\88Ñ\82',
+ 'name' => 'remains_summ',
+ 'title' => 'СÑ\83мма оÑ\81Ñ\82аÑ\82ков (недоÑ\81Ñ\82аÑ\87а или излиÑ\88ек), Ñ\80Ñ\83б',
'type' => BaseColumn::TYPE_TEXT_INPUT,
'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true],
'value' => function($data) {
- return $data['remains_1c'] ?? '';
+ return $data['remains_summ'] ?? '';
},
'headerOptions' => [
'style' => 'width: 70px;',
const param24 = $('meta[name=csrf-param]').attr('content');
const token24 = $('meta[name=csrf-token]').attr('content');
-function updateProductsWithBalance(currentIndex, row) {
- const store = $('#shifttransfer-store_guid');
- const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid');
- productGuid.empty();
- $.ajax({
- type: 'POST',
- url: '/shift-transfer/get-products-with-remains',
- data: { storeGuid: store.val(), [param24]: token24 },
- dataType: 'json',
- success: (data) => {
- console.log(data);
- $.each(data, (key, el) => {
- console.log(key, el)
- const opt = document.createElement('option');
- opt.text = el;
- opt.value = key;
- productGuid.append(opt);
- })
- }
- });
-}
+// function updateProductsWithBalance(currentIndex, row) {
+// const store = $('#shifttransfer-store_guid');
+// const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid');
+// productGuid.empty();
+// $.ajax({
+// type: 'POST',
+// url: '/shift-transfer/get-products-with-remains',
+// data: { storeGuid: store.val(), [param24]: token24 },
+// dataType: 'json',
+// success: (data) => {
+// console.log(data);
+// $.each(data, (key, el) => {
+// console.log(key, el)
+// const opt = document.createElement('option');
+// opt.text = el;
+// opt.value = key;
+// productGuid.append(opt);
+// })
+// }
+// });
+// }
-function updateProductsWithBalanceAll() {
- const rows = $('.multiple-input-list__item');
- for (let currentIndex = 0; currentIndex < rows.length; currentIndex++) {
- updateProductsWithBalance(currentIndex + 1, rows[currentIndex]);
- }
-}
+// function updateProductsWithBalanceAll() {
+// const rows = $('.multiple-input-list__item');
+// for (let currentIndex = 0; currentIndex < rows.length; currentIndex++) {
+// updateProductsWithBalance(currentIndex + 1, rows[currentIndex]);
+// }
+// }
function checkInputRow(currentIndex, row, errorContainer) {
const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid');
const productName = $(row).find('#select2-shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid-container').text();
- const groupLabel = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-group_label');
+ //const groupLabel = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-group_label');
const retailPrice = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-retail_price');
const selfCost = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-self_cost');
const remains1c = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-remains_1c');
}
return checkField(productGuid, currentIndex, productName, 'Не выбран продукт.', errorContainer) &&
- checkField(groupLabel, currentIndex, productName, 'Пустое название группы.', errorContainer) &&
+ // checkField(groupLabel, currentIndex, productName, 'Пустое название группы.', errorContainer) &&
checkField(retailPrice, currentIndex, productName, 'Не назначена розничная цена.', errorContainer) &&
checkField(selfCost, currentIndex, productName, 'Отсутствует себестоимость.', errorContainer) &&
checkField(remains1c, currentIndex, productName, 'Отсутствует информация об остатках в 1с.', errorContainer) &&
let noError = true;
const errorContainer = [];
for (let currentIndex = 0; currentIndex < rows.length; currentIndex++) {
- noError = checkInputRow(currentIndex + 1, rows[currentIndex], errorContainer) && noError;
+ noError = checkInputRow(currentIndex, rows[currentIndex], errorContainer) && noError;
}
if (errorContainer.length > 0) {
alert(errorContainer.join('\n'));
}
function setMultipleInputHandlers(currentIndex, row) {
- updateProductsWithBalance(currentIndex, row);
+ // updateProductsWithBalance(currentIndex, row);
const store = $('#shifttransfer-store_guid');
- const groupLabel = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-group_label');
+ // const groupLabel = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-group_label');
const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid');
const retailPrice = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-retail_price');
const selfCost = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-self_cost');
data: { productGuid: e.target.value, storeGuid: store.val(), [param24]: token24 },
dataType: 'json',
success: (data) => {
- if (data.groupLabel) { groupLabel.val(data.groupLabel); groupLabel.select2('destroy'); groupLabel.select2(); }
+ // if (data.groupLabel) { groupLabel.val(data.groupLabel); groupLabel.select2('destroy'); groupLabel.select2(); }
if (data.price) { retailPrice.val(data.price); }
if (data.selfCost) { selfCost.val(data.selfCost); }
if (data.quantity) { remains1c.val(data.quantity); }