use Exception;
use Yii;
+use yii\db\Query;
use yii\helpers\ArrayHelper;
use yii\web\Response;
use yii\widgets\ActiveForm;
}
$listProductsDict = Products1c::getProducts1cByTypeWithPrice();
+ $listProductsID = array_keys($listProductsDict);
+ $storeIds = CityStore::find()->select('id')->where(['visible' => 1])->column();
+
+ $balanceArr = (new Query())
+ ->select([
+ 'b.product_id',
+ 'store_id' => 'ex.entity_id',
+ 'b.quantity'
+ ])
+ ->from('balances as b')
+ ->leftJoin('export_import_table ex', 'ex.export_val = b.store_id')
+ ->where(['b.product_id' => $listProductsID])
+ ->andWhere(['ex.entity_id' => $storeIds])
+ ->all();
+ $balanceDict = [];
+ foreach ($balanceArr as $row) {
+ $balanceDict[$row['product_id']][$row['store_id']]= $row['quantity'];
+ }
$listCityStoreNames = CityStore::getNames($storeIds);
$listCauseDict = WriteOffsProductsErp::getCauseDict($groupId);
'listCityStoreNames' => $listCityStoreNames,
'listCauseDict' => $listCauseDict,
'listProductsDict' => $listProductsDict,
+ 'balanceDict' => $balanceDict,
'errors' => $errors
]);
}
'listCityStoreNames' => $listCityStoreNames,
'listCauseDict' => $listCauseDict,
'listProductsDict' => $listProductsDict,
+ 'balanceDict' => $balanceDict,
'errors' => $errors
]);
}
'listCityStoreNames' => $listCityStoreNames,
'listCauseDict' => $listCauseDict,
'listProductsDict' => $listProductsDict,
+ 'balanceDict' => $balanceDict,
];
return $this->render('/write_offs_erp/create', $params);
$listProductsDict = Products1c::getProducts1cByTypeWithPrice();
+ $listProductsID = array_keys($listProductsDict);
+ $storeIds = CityStore::find()->select('id')->where(['visible' => 1])->column();
+
+ $balanceArr = (new Query())
+ ->select([
+ 'b.product_id',
+ 'store_id' => 'ex.entity_id',
+ 'b.quantity'
+ ])
+ ->from('balances as b')
+ ->leftJoin('export_import_table ex', 'ex.export_val = b.store_id')
+ ->where(['b.product_id' => $listProductsID])
+ ->andWhere(['ex.entity_id' => $storeIds])
+ ->all();
+ $balanceDict = [];
+ foreach ($balanceArr as $row) {
+ $balanceDict[$row['product_id']][$row['store_id']]= $row['quantity'];
+ }
+
$modelWriteOffsProductsErps = ArrayHelper::getValue($model->getRelatedRecords(), 'writeOffsProductsErps');
$listCityStoreNames = CityStore::getNames($storeIds);
'listCityStoreNames' => $listCityStoreNames,
'listCauseDict' => $listCauseDict,
'listProductsDict' => $listProductsDict,
+ 'balanceDict' => $balanceDict,
'errors' => $errors
]);
}
'listCityStoreNames' => $listCityStoreNames,
'listCauseDict' => $listCauseDict,
'listProductsDict' => $listProductsDict,
+ 'balanceDict' => $balanceDict,
'errors' => $e->getMessage()
]);
}
'listCityStoreNames' => $listCityStoreNames,
'listCauseDict' => $listCauseDict,
'listProductsDict' => $listProductsDict,
+ 'balanceDict' => $balanceDict,
];
return $this->render('/write_offs_erp/update', $params);
use unclead\multipleinput\MultipleInputColumn;
use yii\helpers\Html;
use yii\helpers\Url;
+use yii\web\JsExpression;
use yii\widgets\ActiveForm;
/** @var array $listCityStoreNames */
/** @var array $listCauseDict */
/** @var array $listProductsDict */
+/** @var array $balanceDict */
+/** @var bool $isUpdate */
/** @var yii_app\records\WriteOffsProductsErp $modelsProducts */
/** @var yii_app\forms\MultipleUploadForm $multipleUploadForm */
-
+$this->registerJs(
+ 'window.balanceDict = ' . json_encode($balanceDict, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) . ';',
+ \yii\web\View::POS_HEAD
+);
$this->registerJsFile('/js/validate/validateForm.js', ['position' => \yii\web\View::POS_END]);
$this->registerJsFile('/js/heic2any.min.js', ['position' => \yii\web\View::POS_END]);
$this->registerJsFile('/js/heic_to_jpg_replace.js', ['position' => \yii\web\View::POS_END]);
+$this->registerJsFile('/js/write-offs-erp/_form.js', [
+ 'depends' => [
+ \yii\web\JqueryAsset::class,
+ \kartik\select2\Select2Asset::class,
+ ],
+ 'position' => \yii\web\View::POS_END,
+]);
+
?>
<style>
}
?>
<div style="overflow-x: scroll;">
- <?= $form->field($model, 'modelsProducts')->widget(MultipleInput::className(), [
- 'min' => 0,
- 'max' => 100,
- 'columns' => [
- [
- 'name' => 'id',
- 'type' => BaseColumn::TYPE_HIDDEN_INPUT,
- 'value' => function ($data) {
- return $data['id'] ?? '';
- },
- 'headerOptions' => [
- 'style' => 'width: 70px;',
- ]
- ],
- [
- 'name' => 'num_row',
- 'type' => BaseColumn::TYPE_HIDDEN_INPUT,
- 'value' => function ($data) {
- return $data['num_row'] ?? '';
- },
- 'headerOptions' => [
- 'style' => 'width: 70px;',
- ]
- ],
- [
- 'name' => 'product_id',
- 'type' => Select2::classname(),
- 'enableError' => true,
- 'title' => 'Товар',
- 'options' => [
- 'data' => $listProductsDict
- ],
- 'items' => $listProductsDict,
- ],
- [
- 'name' => 'transfer',
- 'type' => 'checkbox',
- 'title' => 'Перенести',
- 'options' => [
- 'class' => 'transfer-checkbox',
- ],
- ],
- [
- 'name' => 'quantity',
- 'type' => 'textInput',
- 'title' => 'Количество',
- 'options' => [
- 'type' => 'number',
- 'class' => 'form-control',
- 'placeholder' => 'Введите количество',
- 'min' => 0.1,
- 'step' => 0.1,
- ],
- ],
- [
- 'name' => 'cause_id',
- 'type' => 'dropDownList',
- 'title' => 'Причина списания',
- 'items' => $listCauseDict,
- ],
- [
- 'name' => 'add_image',
- 'type' => $checkBoxType,
- 'title' => 'Добавить файлы',
- 'options' => [
- 'data' => [0, 1]
- ],
+ <?php
+ $columns = [
+ [
+ 'name' => 'id',
+ 'type' => BaseColumn::TYPE_HIDDEN_INPUT,
+ 'value' => function ($data) {
+ return $data['id'] ?? '';
+ },
+ 'headerOptions' => [
+ 'style' => 'width: 70px;',
+ ]
+ ],
+ [
+ 'name' => 'num_row',
+ 'type' => BaseColumn::TYPE_HIDDEN_INPUT,
+ 'value' => function ($data) {
+ return $data['num_row'] ?? '';
+ },
+ 'headerOptions' => [
+ 'style' => 'width: 70px;',
+ ]
+ ],
+ [
+ 'name' => 'product_id',
+ 'type' => Select2::class,
+ 'title' => 'Товар',
+ 'enableError' => true,
+ 'options' => [
+ 'data' => $listProductsDict,
+ 'options' => [
+ 'placeholder' => 'Выберите товар',
+ 'class' => 'select-product',
+ ],
+ 'pluginOptions' => [
+ 'allowClear' => true,
+ 'escapeMarkup' => new JsExpression('function (m) { return m; }'),
+
+
+ 'templateResult' => new JsExpression('function (state) {
+ if (!state.id) { return state.text || ""; }
+ var storeId = $("#writeoffserp-store_id").val();
+ var bal = 0;
+ if (window.balanceDict && window.balanceDict[state.id] && window.balanceDict[state.id][storeId] !== undefined) {
+ bal = parseFloat(window.balanceDict[state.id][storeId]) || 0;
+ }
+ return (state.text || "") + " (" + bal + ")";
+ }'),
+ 'templateSelection' => new JsExpression('function (state) {
+ if (!state.id) { return state.text || ""; }
+ var storeId = $("#writeoffserp-store_id").val();
+ var bal = 0;
+ if (window.balanceDict && window.balanceDict[state.id] && window.balanceDict[state.id][storeId] !== undefined) {
+ bal = parseFloat(window.balanceDict[state.id][storeId]) || 0;
+ }
+ return (state.text || "") + " (" + bal + ")";
+ }'),
+
+
+ 'matcher' => new JsExpression('function (params, data) {
+ if (!data.id) return data;
+
+ var storeId = $("#writeoffserp-store_id").val();
+ if (!storeId) return null;
+
+ var qty = 0;
+ if (window.balanceDict && window.balanceDict[data.id] && window.balanceDict[data.id][storeId] !== undefined) {
+ qty = parseFloat(window.balanceDict[data.id][storeId]) || 0;
+ }
+ if (qty <= 0) {
+ return null;
+ }
+
+ // стандартное поведение поиска
+ var term = (params.term || "").toLowerCase();
+ if (!term) return data;
+ return (data.text || "").toLowerCase().indexOf(term) > -1 ? data : null;
+ }'),
+ ],
+ ],
+ 'items' => $listProductsDict,
+ ],
+
+
+ [
+ 'name' => 'quantity',
+ 'type' => 'textInput',
+ 'title' => 'Количество',
+ 'options' => [
+ 'type' => 'number',
+ 'class' => 'form-control',
+ 'placeholder' => 'Введите количество',
+ 'min' => 0.1,
+ 'step' => 0.1,
+ ],
+ ],
+ [
+ 'name' => 'cause_id',
+ 'type' => 'dropDownList',
+ 'title' => 'Причина списания',
+ 'items' => $listCauseDict,
+ ],
+ [
+ 'name' => 'add_image',
+ 'type' => $checkBoxType,
+ 'title' => 'Добавить файлы',
+ 'options' => [
+ 'data' => [0, 1]
+ ],
// 'items' => [0,1],
- ],
- [
- 'name' => 'images_row',
- 'type' => BaseColumn::TYPE_STATIC,
- 'value' => function ($data) {
- if (!empty($data['id'])) {
- $query = WriteOffsProductsErp::find()
- ->andWhere([
- 'write_offs_products_erp.id' => $data['id'],
- 'write_offs_products_erp.active_product' => 1,
- ]);
-
-
- $query->joinWith(['imagesWriteOffsErp']);
-
- $action = $query->createCommand()->getRawSql();
-
- $modelWriteOffsProductsErp = $query->All();
- $productImagesList = [];
- $forWidget = false;
- foreach ($modelWriteOffsProductsErp as $item) {
- $productImagesList = WriteOffsErp::getImagesList($item->imagesWriteOffsErp, $forWidget);
- }
- if (!empty($productImagesList)) {
- if ($forWidget) {
- $dataTable = dosamigos\gallery\Gallery::widget(['items' => $productImagesList]);
- } else {
- $dataTable = implode('', $productImagesList);
- }
- }
- }
- $test = 33;
- return $dataTable ?? '';
- },
- 'headerOptions' => [
+ ],
+ [
+ 'name' => 'images_row',
+ 'type' => BaseColumn::TYPE_STATIC,
+ 'value' => function ($data) {
+ if (!empty($data['id'])) {
+ $query = WriteOffsProductsErp::find()
+ ->andWhere([
+ 'write_offs_products_erp.id' => $data['id'],
+ 'write_offs_products_erp.active_product' => 1,
+ ]);
+
+
+ $query->joinWith(['imagesWriteOffsErp']);
+
+ $action = $query->createCommand()->getRawSql();
+
+ $modelWriteOffsProductsErp = $query->All();
+ $productImagesList = [];
+ $forWidget = false;
+ foreach ($modelWriteOffsProductsErp as $item) {
+ $productImagesList = WriteOffsErp::getImagesList($item->imagesWriteOffsErp, $forWidget);
+ }
+ if (!empty($productImagesList)) {
+ if ($forWidget) {
+ $dataTable = dosamigos\gallery\Gallery::widget(['items' => $productImagesList]);
+ } else {
+ $dataTable = implode('', $productImagesList);
+ }
+ }
+ }
+ $test = 33;
+ return $dataTable ?? '';
+ },
+ 'headerOptions' => [
// 'style' => 'width: 70px;',
- ]
- ],
- [
- 'name' => 'imageFiles',
- 'title' => 'Фотографии: jpg и png',
- 'type' => FileInput::className(),
- 'options' => [
- 'options' => [
- 'multiple' => true,
- 'accept' => 'image/*',
- 'name' => 'image_name',
- 'capture' => '',
- 'class' => 'file'
- ],
- 'pluginOptions' => [
- 'showPreview' => false,
- 'showCaption' => true,
- 'showRemove' => true,
- 'showUpload' => false,
- 'overwriteInitial' => true,
- 'browseIcon' => '+',
- 'cancelIcon' => 'x',
- 'removeIcon' => '-',
- 'buttonLabelClass' => 'hidden',
- 'fileActionSettings' => ['showUpload' => false],
- 'maxFileCount' => 10,
- 'multiple' => true
- ],
- 'model' => $multipleUploadForm,
- ],
- ],
- [
- 'name' => 'videoFiles',
- 'title' => 'Видео: mp4, mov, avi',
- 'type' => FileInput::className(),
- 'options' => function ($data) {
- $videoUrl = null;
- $deleteUrl = '#';
-
- if (is_array($data) && !empty($data['id'])) {
- $videoUrl = Files::find()
- ->select('url')
- ->where([
- 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO,
- 'entity_id' => $data['id']
- ])
- ->scalar();
-
- $deleteUrl = Url::to(['write-offs-erp/delete-video', 'id' => $data['id']]);
- }
-
- return [
- 'options' => [
- 'multiple' => false,
- 'accept' => 'video/*',
- 'name' => 'video_name',
- 'capture' => '',
- 'class' => 'videos'
- ],
- 'pluginOptions' => [
- 'showPreview' => false,
- 'showCaption' => true,
- 'showRemove' => true,
- 'showUpload' => false,
- 'showCancel' => false,
- 'overwriteInitial' => true,
- 'browseIcon' => '+',
- 'removeIcon' => '-',
- 'buttonLabelClass' => 'hidden',
- 'fileActionSettings' => ['showUpload' => false],
- 'multiple' => false,
- 'previewFileType' => 'video',
- 'allowedFileExtensions' => ['mp4', 'mov', 'avi'],
- 'initialPreview' => $videoUrl ? [$videoUrl] : [],
- 'initialPreviewAsData' => true,
- 'initialCaption' => $videoUrl ? basename($videoUrl) : '',
- 'initialPreviewConfig' => $videoUrl ? [[
- 'type' => 'video',
- 'caption' => basename($videoUrl),
- 'url' => $deleteUrl,
- ]] : [],
- ],
- 'pluginEvents' => [
- 'fileclear' => new \yii\web\JsExpression("
+ ]
+ ],
+ [
+ 'name' => 'imageFiles',
+ 'title' => 'Фотографии: jpg и png',
+ 'type' => FileInput::className(),
+ 'options' => [
+ 'options' => [
+ 'multiple' => true,
+ 'accept' => 'image/*',
+ 'name' => 'image_name',
+ 'capture' => '',
+ 'class' => 'file'
+ ],
+ 'pluginOptions' => [
+ 'showPreview' => false,
+ 'showCaption' => true,
+ 'showRemove' => true,
+ 'showUpload' => false,
+ 'overwriteInitial' => true,
+ 'browseIcon' => '+',
+ 'cancelIcon' => 'x',
+ 'removeIcon' => '-',
+ 'buttonLabelClass' => 'hidden',
+ 'fileActionSettings' => ['showUpload' => false],
+ 'maxFileCount' => 10,
+ 'multiple' => true
+ ],
+ 'model' => $multipleUploadForm,
+ ],
+ ],
+ [
+ 'name' => 'videoFiles',
+ 'title' => 'Видео: mp4, mov, avi',
+ 'type' => FileInput::className(),
+ 'options' => function ($data) {
+ $videoUrl = null;
+ $deleteUrl = '#';
+
+ if (is_array($data) && !empty($data['id'])) {
+ $videoUrl = Files::find()
+ ->select('url')
+ ->where([
+ 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO,
+ 'entity_id' => $data['id']
+ ])
+ ->scalar();
+
+ $deleteUrl = Url::to(['write-offs-erp/delete-video', 'id' => $data['id']]);
+ }
+
+ return [
+ 'options' => [
+ 'multiple' => false,
+ 'accept' => 'video/*',
+ 'name' => 'video_name',
+ 'capture' => '',
+ 'class' => 'videos'
+ ],
+ 'pluginOptions' => [
+ 'showPreview' => false,
+ 'showCaption' => true,
+ 'showRemove' => true,
+ 'showUpload' => false,
+ 'showCancel' => false,
+ 'overwriteInitial' => true,
+ 'browseIcon' => '+',
+ 'removeIcon' => '-',
+ 'buttonLabelClass' => 'hidden',
+ 'fileActionSettings' => ['showUpload' => false],
+ 'multiple' => false,
+ 'previewFileType' => 'video',
+ 'allowedFileExtensions' => ['mp4', 'mov', 'avi'],
+ 'initialPreview' => $videoUrl ? [$videoUrl] : [],
+ 'initialPreviewAsData' => true,
+ 'initialCaption' => $videoUrl ? basename($videoUrl) : '',
+ 'initialPreviewConfig' => $videoUrl ? [[
+ 'type' => 'video',
+ 'caption' => basename($videoUrl),
+ 'url' => $deleteUrl,
+ ]] : [],
+ ],
+ 'pluginEvents' => [
+ 'fileclear' => new \yii\web\JsExpression("
function(event) {
var modelId = " . (isset($data['id']) ? (int)$data['id'] : 'null') . ";
if (!modelId) {
});
}
"),
- ],
-
- ];
- }
- ],
- [
- 'name' => 'comment',
- 'type' => 'textInput',
- 'title' => 'Комментарий',
-
- ],
- ],
+ ],
+
+ ];
+ }
+ ],
+ [
+ 'name' => 'comment',
+ 'type' => 'textInput',
+ 'title' => 'Комментарий',
+
+ ],
+ ];
+ $transferColumn = [
+ 'name' => 'transfer',
+ 'type' => 'checkbox',
+ 'title' => 'Перенести',
+ 'options' => [
+ 'class' => 'transfer-checkbox',
+ ]
+ ];
+
+ if ($isUpdate) {
+ $columns = array_merge(
+ array_slice($columns, 0, 3),
+ [$transferColumn],
+ array_slice($columns, 3)
+ );
+ }
+
+ ?>
+ <?= $form->field($model, 'modelsProducts')->widget(MultipleInput::className(), [
+ 'min' => 0,
+ 'max' => 100,
+ 'columns' => $columns,
'addButtonPosition' => MultipleInput::POS_FOOTER, // show add button in the header
])->label(false); ?>
</div>
<?php ActiveForm::end(); ?>
<div class="form-group">
+ <?php $classTransferButton = $isUpdate ? 'btn btn-warning ' : ' btn btn-warning d-none'; ?>
<?= Html::button('Перенести выделенные', [
- 'class' => 'btn btn-warning',
+ 'class' => $classTransferButton,
'id' => 'btn-transfer',
'type' => 'button',
+
'title' => 'Создать новый документ и переместить в него отмеченные позиции',
]) ?>
</div>