use Yii;
use yii\helpers\ArrayHelper;
use yii\web\Controller;
+use yii\web\Response;
use yii_app\records\Admin;
+use yii_app\records\Balances;
+use yii_app\records\ExportImportTable;
use yii_app\records\MultipleModel;
+use yii_app\records\Prices;
+use yii_app\records\Products1c;
+use yii_app\records\ProductsClass;
+use yii_app\records\SelfCostProduct;
use yii_app\records\ShiftRemains;
use yii_app\records\ShiftTransfer;
use yii_app\services\TaskService;
'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');
+
+ $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();
+
+ $selfCost = SelfCostProduct::find()->select(['price'])->where(['product_guid' => $productGuid, 'store_id' => $storeEIT->entity_id])->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];
+ }
+
public function actionView($id) {
$shiftTransfer = ShiftTransfer::findOne($id);
return $this->redirect(['/shift-transfer']);
}
-}
\ No newline at end of file
+}
use unclead\multipleinput\components\BaseColumn;
use unclead\multipleinput\MultipleInput;
+use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use dosamigos\datetimepicker\DateTimePicker;
+use yii_app\records\Products1c;
use yii_app\records\ShiftTransfer;
use yii_app\records\ProductsClass;
/* @var $storeNameById array */
/* @var $admins array */
+$this->registerJsFile('/js/shift-transfer/update.js', ['position' => \yii\web\View::POS_END]);
$this->registerCss('
.multiple-input-list__btn.js-input-plus.btn.btn-success {
'min' => 0,
'max' => 100,
'columns' => [
-// [
-// 'name' => 'id',
-// 'type' => BaseColumn::TYPE_HIDDEN_INPUT,
-// 'value' => function($data) {
-// return $data['id'] ?? '';
-// },
-// ],
-// [
-// 'name' => 'shift_transfer_id',
-// 'type' => BaseColumn::TYPE_HIDDEN_INPUT,
-// 'value' => function($data) {
-// return $data['shift_transfer_id'] ?? '';
-// },
-// ],
[
'name' => 'group_label',
'title' => 'Название группы',
],
[
'name' => 'product_guid',
- 'title' => 'GUID продукта',
- 'type' => BaseColumn::TYPE_TEXT_INPUT,
+ 'title' => 'Продукт',
+ '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');
+ },
'value' => function($data) {
return $data['product_guid'] ?? '';
},
],
[
'name' => 'retail_price',
- 'title' => 'Розничная цена',
+ 'title' => 'Розничная цена, руб',
'type' => BaseColumn::TYPE_TEXT_INPUT,
'options' => ['type' => 'number', 'step' => 0.01],
'value' => function($data) {
],
[
'name' => 'self_cost',
- 'title' => 'Себестоимость',
+ 'title' => 'Себестоимость, руб',
'type' => BaseColumn::TYPE_TEXT_INPUT,
'options' => ['type' => 'number', 'step' => 0.01],
'value' => function($data) {
],
[
'name' => 'remains_summ',
- 'title' => 'Сумма остатков (недостача или излишек)',
+ 'title' => 'Сумма остатков (недостача или излишек), руб',
'type' => BaseColumn::TYPE_TEXT_INPUT,
'options' => ['type' => 'number', 'step' => 0.01],
'value' => function($data) {
],
[
'name' => 'remains_count',
- 'title' => 'Фактические остатки кол-во',
+ 'title' => 'Фактические остатки кол-во, шт',
'type' => BaseColumn::TYPE_TEXT_INPUT,
- 'options' => ['type' => 'number', 'step' => 0.01],
+ 'options' => ['type' => 'number', 'step' => 0.01, 'min' => 0],
'value' => function($data) {
return $data['remains_count'] ?? '';
},
],
[
'name' => 'fact_and_1c_diff',
- 'title' => 'Разница факт и по программе 1с',
+ 'title' => 'Разница факт и по программе 1с, шт',
'type' => BaseColumn::TYPE_TEXT_INPUT,
'options' => ['type' => 'number', 'step' => 0.01],
'value' => function($data) {
],
[
'name' => 'remains_1c',
- 'title' => 'Остатки по 1с',
+ 'title' => 'Остатки по 1с, шт',
'type' => BaseColumn::TYPE_TEXT_INPUT,
'options' => ['type' => 'number', 'step' => 0.01],
'value' => function($data) {
use yii\helpers\Html;
use yii\widgets\DetailView;
+use yii\helpers\ArrayHelper;
use yii_app\records\ShiftTransfer;
+use yii_app\records\ProductsClass;
+use yii_app\records\Products1c;
/* @var $shiftTransfer ShiftTransfer */
/* @var $storeNameById array */
'attribute' => 'group_label',
'label' => 'Название группы',
'value' => function($data) {
- return $data['group_label'] ?? '';
+ return ProductsClass::getHints()[$data['group_label']] ?? '';
},
],
[
'attribute' => 'product_guid',
- 'label' => 'GUID продукта',
+ 'label' => 'Продукт',
'value' => function($data) {
- return $data['product_guid'] ?? '';
+ $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');
+
+ return $products[$data['product_guid']] ?? '';
},
],
[
],
[
'attribute' => 'remains_count',
- 'label' => 'Фактические остатки кол-во',
+ 'label' => 'Фактические остатки кол-во, шт',
'value' => function($data) {
return $data['remains_count'] ?? '';
},
],
[
'attribute' => 'fact_and_1c_diff',
- 'label' => 'РазниÑ\86а Ñ\84акÑ\82 и по пÑ\80огÑ\80амме 1Ñ\81, Ñ\80Ñ\83б',
+ 'label' => 'РазниÑ\86а Ñ\84акÑ\82 и по пÑ\80огÑ\80амме 1Ñ\81, Ñ\88Ñ\82',
'value' => function($data) {
return $data['fact_and_1c_diff'] ?? '';
},
],
[
'attribute' => 'remains_1c',
- 'label' => 'Остатки по 1с, руб',
+ 'label' => 'Остатки по 1с, шт',
+ 'value' => function($data) {
+ return $data['remains_1c'] ?? '';
+ },
+ ],
+ ],
+ ]); ?>
+ </div>
+ </div>
+
+ <div class="row">
+ <div class="col-12">
+ <?= \yii\grid\GridView::widget([
+ 'dataProvider' => new \yii\data\ArrayDataProvider([
+ 'allModels' => [
+ [
+ 'remains_summ' => array_sum(array_column($shiftTransfer->shiftRemains, 'remains_summ')),
+ 'remains_count' => array_sum(array_column($shiftTransfer->shiftRemains, 'remains_count')),
+ 'remains_diff' => array_sum(array_column($shiftTransfer->shiftRemains, 'fact_and_1c_diff')),
+ 'remains_1c' => array_sum(array_column($shiftTransfer->shiftRemains, 'remains_1c')),
+ ]
+ ],
+ ]),
+ 'columns' => [
+ [
+ 'label' => '',
+ 'value' => function () {
+ return 'Итого:';
+ }
+ ],
+ [
+ 'attribute' => 'remains_summ',
+ 'label' => 'Сумма остатков (недостача или излишек), руб',
+ 'value' => function($data) {
+ return $data['remains_summ'] ?? '';
+ },
+ ],
+ [
+ 'attribute' => 'remains_count',
+ 'label' => 'Фактические остатки кол-во, шт',
+ 'value' => function($data) {
+ return $data['remains_count'] ?? '';
+ },
+ ],
+ [
+ 'attribute' => 'remains_diff',
+ 'label' => 'Разница факт и по программе 1с, шт',
+ 'value' => function($data) {
+ return $data['remains_diff'] ?? '';
+ },
+ ],
+ [
+ 'attribute' => 'remains_1c',
+ 'label' => 'Остатки по 1с, шт',
'value' => function($data) {
return $data['remains_1c'] ?? '';
},
--- /dev/null
+/* jshint esversion: 6 */
+
+const param24 = $('meta[name=csrf-param]').attr('content');
+const token24 = $('meta[name=csrf-token]').attr('content');
+
+$(document).ready(() => {
+ $('.multiple-input').on('afterAddRow', function(e, row, currentIndex) {
+ var store = $('#shifttransfer-store_guid');
+ var groupLabel = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-group_label');
+ var productGuid = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-product_guid');
+ var retailPrice = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-retail_price');
+ var selfCost = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-self_cost');
+ var remains1c = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-remains_1c');
+ var remains_summ = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-remains_summ');
+ var remains_count = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-remains_count');
+ var fact_and_1c_diff = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-fact_and_1c_diff');
+
+ function onChangeTarget() {
+ fact_and_1c_diff.val(remains_count.val() - remains1c.val());
+ 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) => {
+ var option = document.createElement('option');
+ option.text = name;
+ option.value = guid;
+ productGuid.append(option);
+ })
+ }
+ });
+ });
+ productGuid.on('change', (e) => {
+ $.ajax({
+ type: 'POST',
+ url: '/shift-transfer/get-product-price-self-cost-and-remains',
+ data: { productGuid: e.target.value, storeGuid: store.val(), [param24]: token24 },
+ dataType: 'json',
+ success: (data) => {
+ if (data.price) { retailPrice.val(data.price); }
+ if (data.selfCost) { selfCost.val(data.selfCost); }
+ if (data.quantity) { remains1c.val(data.quantity); }
+ }
+ });
+ });
+ remains_count.on('change', onChangeTarget);
+ });
+});