$modelsShiftRemain->shift_transfer_id = $shiftTransfer->id;
if ($modelsShiftRemain->validate()) {
$modelsShiftRemain->save();
+ } else {
+ var_dump($modelsShiftRemain->getErrors()); die;
}
}
return $this->redirect(['/shift-transfer/view', 'id' => $shiftTransfer->id]);
'admins'));
}
- public function actionGetProductsByGroupLabel() {
- Yii::$app->response->format = Response::FORMAT_JSON;
-
- $productsClass = ProductsClass::find()->select('category_id')
- ->where(['tip' => Yii::$app->request->post('groupLabel')])->column();
-
- return ArrayHelper::map(Products1c::find()->select(['id', 'name'])
- ->where(['parent_id' => $productsClass])->all(), 'id', 'name');
- }
-
public function actionGetProductPriceSelfCostAndRemains() {
Yii::$app->response->format = Response::FORMAT_JSON;
$productGuid = Yii::$app->request->post('productGuid');
$storeGuid = Yii::$app->request->post('storeGuid');
+ $product = Products1c::find()->where(['id' => $productGuid])->one();
+ $productClass = ProductsClass::find()->where(['category_id' => $product->parent_id])->one();
+
$price = Prices::find()->select(['price'])->where(['product_id' => $productGuid])->one();
$storeEIT = ExportImportTable::find()->select(['entity_id'])->where(['entity' => 'city_store', 'export_val' => $storeGuid, 'export_id' => 1])->one();
$balance = Balances::find()->select(['quantity'])->where(['store_id' => $storeGuid, 'product_id' => $productGuid])->one();
- return ['price' => $price->price ?? 0, 'selfCost' => $selfCost->price ?? 0, 'quantity' => $balance->quantity ?? 0];
+ return ['groupLabel' => $productClass->tip ?? 'other_items', 'price' => $price->price ?? 0, 'selfCost' => $selfCost->price ?? 0, 'quantity' => $balance->quantity ?? 0];
}
public function actionView($id) {
<?php
echo $form->field($filterModel, 'activeFilter')->dropDownList(
['' => 'Все', 1 => 'Активная', 0 => 'Не активная',],
- ['class' => 'form-control'])->label('Активность');
+ ['class' => 'form-control', 'onchange' => 'this.form.submit();'])->label('Активность');
?>
</div>
width: 40px;
}
');
+
?>
<div class="shiftTransferCreate m-5">
<h1><?= $isCreate ? 'Создание' : 'Обновление' ?> передачи смены</h1>
<?php $form = ActiveForm::begin([
+ 'enableClientScript' => false,
'action' => ['/shift-transfer/update', 'id' => Yii::$app->request->get('id')],
+ 'options' => [
+ 'onsubmit' => 'if (!checkInputs()) { event.preventDefault(); }'
+ ],
]) ?>
<?= $form->field($shiftTransfer, 'id')->hiddenInput()->label(false) ?>
'max' => 100,
'columns' => [
[
- 'name' => 'group_label',
- 'title' => 'Название группы',
- 'type' => BaseColumn::TYPE_DROPDOWN,
- 'items' => ProductsClass::getHints(),
+ 'name' => 'product_guid',
+ 'title' => 'Продукт',
+ 'type' => Select2::class,
+ 'options' => [
+ 'data' => ArrayHelper::map(Products1c::find()->select(['id', 'name'])
+ ->where(['tip' => 'products'])->all(), 'id', 'name'),
+ ],
'value' => function($data) {
- return $data['group_label'] ?? '';
+ return $data['product_guid'] ?? '';
},
'headerOptions' => [
'style' => 'width: 70px;',
]
],
[
- 'name' => 'product_guid',
- 'title' => 'Ð\9fÑ\80одÑ\83кÑ\82',
+ 'name' => 'group_label',
+ 'title' => 'Ð\9dазвание гÑ\80Ñ\83ппÑ\8b',
'type' => BaseColumn::TYPE_DROPDOWN,
- 'items' => function($data) {
- $productsClass = ProductsClass::find()->select('category_id')
- ->where(['tip' => $data['group_label'] ?? null])->column();
-
- return ArrayHelper::map(Products1c::find()->select(['id', 'name'])
- ->where(['parent_id' => $productsClass])->all(), 'id', 'name');
- },
+ 'items' => ProductsClass::getHints(),
+ 'options' => ['readonly' => true],
'value' => function($data) {
- return $data['product_guid'] ?? '';
+ return ProductsClass::getHints()[$data['group_label'] ?? 'other_items'];
},
'headerOptions' => [
'style' => 'width: 70px;',
'name' => 'remains_count',
'title' => 'Фактические остатки кол-во, шт',
'type' => BaseColumn::TYPE_TEXT_INPUT,
- 'options' => ['type' => 'number', 'step' => 0.01, 'min' => 0],
+ 'options' => ['type' => 'number', 'step' => 1, 'min' => 0],
'value' => function($data) {
return $data['remains_count'] ?? '';
},
]),
// 'showFooter' => true,
'columns' => [
- [
- 'attribute' => 'group_label',
- 'label' => 'Название группы',
-// 'footer' => 'Итого:',
- 'pageSummary' => 'Итого:',
- 'value' => function($data) {
- return ProductsClass::getHints()[$data['group_label']] ?? '';
- },
- ],
[
'attribute' => 'product_guid',
'label' => 'Продукт',
+ 'pageSummary' => 'Итого:',
'value' => function($data) {
- $productsClass = ProductsClass::find()->select('category_id')
- ->where(['tip' => $data['group_label'] ?? null])->column();
-
$products = ArrayHelper::map(Products1c::find()->select(['id', 'name'])
- ->where(['parent_id' => $productsClass])->all(), 'id', 'name');
+ ->where(['id' => $data['product_guid']])->all(), 'id', 'name');
return $products[$data['product_guid']] ?? '';
},
],
+ [
+ 'attribute' => 'group_label',
+ 'label' => 'Название группы',
+ 'value' => function($data) {
+ return ProductsClass::getHints()[$data['group_label']] ?? '';
+ },
+ ],
[
'attribute' => 'retail_price',
'label' => 'Розничная цена, руб',
/* jshint esversion: 6 */
+/* jshint strict: false */
const param24 = $('meta[name=csrf-param]').attr('content');
const token24 = $('meta[name=csrf-token]').attr('content');
+function checkInputRow(currentIndex, row, errorContainer) {
+ const groupLabel = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-group_label');
+ const productGuid = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-product_guid');
+ const productName = $(row).find('#select2-shifttransfer-shiftremains-' + currentIndex + '-product_guid-container').text();
+ const retailPrice = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-retail_price');
+ const selfCost = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-self_cost');
+ const remains1c = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-remains_1c');
+ const remains_summ = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-remains_summ');
+ const remains_count = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-remains_count');
+ const fact_and_1c_diff = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-fact_and_1c_diff');
+ function checkField(field, currentIndex, productName, msg, errorContainer) {
+ if (field.val() === '') { errorContainer.push(msg + ' Продукт: ' + productName + ' Строка: ' + (currentIndex + 1)); return false; }
+ return true;
+ }
+
+ return checkField(groupLabel, currentIndex, productName, 'Пустое название группы.', errorContainer) &&
+ checkField(productGuid, currentIndex, productName, 'Не выбран продукт.', errorContainer) &&
+ checkField(retailPrice, currentIndex, productName, 'Не назначена розничная цена.', errorContainer) &&
+ checkField(selfCost, currentIndex, productName, 'Отсутствует себестоимость.', errorContainer) &&
+ checkField(remains1c, currentIndex, productName, 'Отсутствует информация об остатках в 1с.', errorContainer) &&
+ checkField(remains_summ, currentIndex, productName, 'Не подсчитана сумма остатков.', errorContainer) &&
+ checkField(remains_count, currentIndex, productName, 'Не подсчитано количество остатков.', errorContainer) &&
+ checkField(fact_and_1c_diff, currentIndex, productName, 'Не подсчитано разность количество остатков в 1с и в ERP.', errorContainer);
+}
+
+function checkInputs() {
+ const rows = $('.multiple-input-list__item');
+ let noError = true;
+ const errorContainer = [];
+ for (let currentIndex = 0; currentIndex < rows.length; currentIndex++) {
+ noError = checkInputRow(currentIndex, rows[currentIndex], errorContainer) && noError;
+ }
+ if (errorContainer.length > 0) {
+ alert(errorContainer.join('\n'));
+ }
+ return noError;
+}
+
function setMultipleInputHandlers(currentIndex, row) {
const store = $('#shifttransfer-store_guid');
const groupLabel = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-group_label');
remains_summ.val(remains_count.val() * retailPrice.val())
}
- groupLabel.on('change', (e) => {
- $.ajax({
- type: 'POST',
- url: '/shift-transfer/get-products-by-group-label',
- data: { groupLabel: e.target.value, [param24]: token24 },
- dataType: 'json',
- success: (data) => {
- productGuid.empty();
- $.each(data, (guid, name) => {
- const option = document.createElement('option');
- option.text = name;
- option.value = guid;
- productGuid.append(option);
- })
- }
- });
- });
-
productGuid.on('change', (e) => {
$.ajax({
type: 'POST',
data: { productGuid: e.target.value, storeGuid: store.val(), [param24]: token24 },
dataType: 'json',
success: (data) => {
+ if (data.groupLabel) { groupLabel.val(data.groupLabel); }
if (data.price) { retailPrice.val(data.price); }
if (data.selfCost) { selfCost.val(data.selfCost); }
if (data.quantity) { remains1c.val(data.quantity); }