]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-259 Доработка второго шага передачи смен
authormarina <m.zozirova@gmail.com>
Thu, 5 Dec 2024 14:08:56 +0000 (17:08 +0300)
committermarina <m.zozirova@gmail.com>
Thu, 5 Dec 2024 14:08:56 +0000 (17:08 +0300)
erp24/controllers/ShiftTransferController.php
erp24/records/EqualizationRemains.php
erp24/views/shift-transfer/_replacement.php

index 36362a9cee11847554476346b247f547cff6a255..cb8ed07ff3efc385fa93160e20f1142078deadaf 100644 (file)
@@ -102,6 +102,9 @@ class ShiftTransferController extends Controller
                     }
                 }
 
+
+                EqualizationRemains::setData($shiftTransfer);
+
                 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'));
index 90cd3c3251bac6407b6dae1ef6c1d220db7f5e6a..2bf72474b32c6f1cb80ae51412bc9ef59cbe32dd 100644 (file)
@@ -95,7 +95,8 @@ class EqualizationRemains extends \yii\db\ActiveRecord
         ];
     }
 
-    public static function updateData($equalizationRemains, int $shift_id) {
+    public static function updateData($equalizationRemains, int $shift_id)
+    {
         self::deleteAll(['shift_id' => $shift_id]);
 
         if (!is_array($equalizationRemains) || empty($equalizationRemains)) {
@@ -118,12 +119,59 @@ class EqualizationRemains extends \yii\db\ActiveRecord
                 'balance_self_cost' => $er['balance_self_cost'],
             ]);
 
-            if ($equalizationRemain->validate())
+            if ($equalizationRemain->validate()) {
                 $equalizationRemain->save();
-            else {var_dump($equalizationRemain->errors);die();}
+            } else {
+                var_dump($equalizationRemain->errors);
+                die();
+            }
         }
     }
 
+    public static function setData($shiftTransfer)
+    {
+        $plus = ShiftRemains::find()
+            ->andWhere(['shift_transfer_id' => $shiftTransfer->id])
+            ->andWhere(['!=', 'fact_and_1c_diff', 0])
+            ->andWhere(['>', 'fact_and_1c_diff', 0]);
+
+        $minus = ShiftRemains::find()
+            ->andWhere(['shift_transfer_id' => $shiftTransfer->id])
+            ->andWhere(['!=', 'fact_and_1c_diff', 0])
+            ->andWhere(['<', 'fact_and_1c_diff', 0])
+            ->all();
+
+        foreach ($minus as $m) {
+            $replacement = Product1cReplacement::find()
+                ->andWhere(['guid' => $m->product_guid])
+                ->select('guid_replacement')
+                ->scalar();
+            $p = $plus->andWhere(['product_guid' => $replacement])->one();
+
+            $model = new EqualizationRemains();
+            $model->setAttributes([
+                'shift_id' => $shiftTransfer->id,
+                'product_id' => $m->product_guid,
+                'product_count' => $m->fact_and_1c_diff,
+                'product_price' => $m->retail_price,
+                'product_self_cost' => $m->self_cost,
+                'product_replacement_id' => $p->product_guid,
+                'product_replacement_count' => $m->fact_and_1c_diff,
+                'product_replacement_price' => $p->retail_price,
+                'product_replacement_self_cost' => $p->self_cost,
+                'balance' => $m->fact_and_1c_diff * ($p->retail_price - $m->retail_price),
+                'balance_self_cost' => $m->fact_and_1c_diff * ($p->self_cost - $m->self_cost)
+            ]);
+            if ($model->validate()) {
+                $model->save();
+            } elseif ($model->getErrors()) {
+                var_dump($model->errors);
+                die();
+            }
+        }
+
+    }
+
     /**
      * @return \yii\db\ActiveQuery
      */
index 03a5111710c83915ea4f466b08b2aa39c725c2ed..77382a2dad5ff7e7687f5a325bfba8bae48ac19b 100644 (file)
@@ -20,126 +20,126 @@ $this->registerJsFile('/js/shift-transfer/replacement.js', ['position' => \yii\w
 $form = \yii\widgets\ActiveForm::begin();
 if (in_array($shiftTransfer->status_id, [ShiftTransfer::STATUS_ID_TRANSFER_ACTIONS, ShiftTransfer::STATUS_ID_INPUT_FACT_REMAINS])
     && Yii::$app->user->id === $shiftTransfer->end_shift_admin_id) {
-    echo $form->field($shiftTransfer, 'equalizationRemains')->widget(MultipleInput::class, [
-        'min' => 0,
-        'max' => 100,
-        'columns' => [
-            [
-                'name' => 'product_id',
-                'title' => 'Заменяемый товар',
-                'type' => Select2::class,
-                'options' => [
-                    'data' => array_merge(
-                        ['text' => 'Выберите товар'],
-                        $products
-                    ),
-                    'pluginOptions' => [
-                        'allowClear' => true,
-                    ],
-                    'pluginEvents' => [
-                        'change' => new \yii\web\JsExpression('function() { setProductData.call(this); }'),
-                    ],
-                ],
-                'value' => function ($model) {
-                    return $model->product->id ?? '';
-                },
-            ],
-            [
-                'name' => 'product_price',
-                'type' => BaseColumn::TYPE_TEXT_INPUT,
-                'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,],
-                'title' => 'Цена товара',
-                'value' => function ($data) {
-                    return $data['product_price'] ?? '';
-                },
-            ],
-            [
-                'name' => 'product_self_cost',
-                'type' => BaseColumn::TYPE_TEXT_INPUT,
-                'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,],
-                'title' => 'Себестоимость товара',
-                'value' => function ($data) {
-                    return $data['product_self_cost'] ?? '';
-                },
-            ],
-            [
-                'name' => 'product_replacement_id',
-                'title' => 'Замещающий товар',
-                'type' => Select2::class,
-                'options' => [
-                    'data' => [],
-                    'options' => [
-                        'placeholder' => 'Выберите товар',
-                        'class' => 'form-control',
-                    ],
-                    'pluginOptions' => [
-                        'allowClear' => true,
-                    ],
-                    'pluginEvents' => [
-                        'select2:select' => new \yii\web\JsExpression('function() {
-                        setReplacementPriceData.call(this);
-                    }'),
-                    ],
-                ],
-                'value' => function ($model) {
-                    return $model->productReplacement->name ?? '';
-                },
-            ],
-            [
-                'name' => 'product_replacement_price',
-                'type' => BaseColumn::TYPE_TEXT_INPUT,
-                'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,],
-                'title' => 'Цена замещающего товара',
-                'value' => function ($data) {
-                    return $data['product_replacement_price'] ?? '';
-                },
-            ],
-            [
-                'name' => 'product_replacement_self_cost',
-                'type' => BaseColumn::TYPE_TEXT_INPUT,
-                'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,],
-                'title' => 'Себестоимость замещаемого товара',
-                'value' => function ($data) {
-                    return $data['product_replacement_self_cost'] ?? '';
-                },
-            ],
-            [
-                'name' => 'product_replacement_count',
-                'type' => BaseColumn::TYPE_TEXT_INPUT,
-                'options' => ['type' => 'number', 'step' => 1,],
-                'title' => 'Количество',
-                'value' => function ($data) {
-                    return $data['product_replacement_count'] ?? '';
-                }
-            ],
-            [
-                'name' => 'balance',
-                'title' => 'Баланс',
-                'type' => BaseColumn::TYPE_TEXT_INPUT,
-                'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,],
-                'value' => function ($data) {
-                    return $data['balance'] ?? '';
-                },
-            ],
-            [
-                'name' => 'balance_self_cost',
-                'title' => 'Разница в сумме (Себестоиомость)',
-                'type' => BaseColumn::TYPE_TEXT_INPUT,
-                'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,],
-                'value' => function ($data) {
-                    return $data['balance_self_cost'] ?? '';
-                },
-            ],
-        ],
-        'addButtonPosition' => MultipleInput::POS_FOOTER,
-        'addButtonOptions' => [
-            'class' => 'btn btn-success visible',
-        ],
-        'removeButtonOptions' => [
-            'class' => 'btn btn-danger visible',
-        ],
-        'iconSource' => 'fa',
-    ])->label('Таблица возможных замен');
+//    echo $form->field($shiftTransfer, 'equalizationRemains')->widget(MultipleInput::class, [
+//        'min' => 0,
+//        'max' => 100,
+//        'columns' => [
+//            [
+//                'name' => 'product_id',
+//                'title' => 'Заменяемый товар',
+//                'type' => Select2::class,
+//                'options' => [
+//                    'data' => array_merge(
+//                        ['text' => 'Выберите товар'],
+//                        $products
+//                    ),
+//                    'pluginOptions' => [
+//                        'allowClear' => true,
+//                    ],
+//                    'pluginEvents' => [
+//                        'change' => new \yii\web\JsExpression('function() { setProductData.call(this); }'),
+//                    ],
+//                ],
+//                'value' => function ($model) {
+//                    return $model->product->id ?? '';
+//                },
+//            ],
+//            [
+//                'name' => 'product_price',
+//                'type' => BaseColumn::TYPE_TEXT_INPUT,
+//                'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,],
+//                'title' => 'Цена товара',
+//                'value' => function ($data) {
+//                    return $data['product_price'] ?? '';
+//                },
+//            ],
+//            [
+//                'name' => 'product_self_cost',
+//                'type' => BaseColumn::TYPE_TEXT_INPUT,
+//                'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,],
+//                'title' => 'Себестоимость товара',
+//                'value' => function ($data) {
+//                    return $data['product_self_cost'] ?? '';
+//                },
+//            ],
+//            [
+//                'name' => 'product_replacement_id',
+//                'title' => 'Замещающий товар',
+//                'type' => Select2::class,
+//                'options' => [
+//                    'data' => [],
+//                    'options' => [
+//                        'placeholder' => 'Выберите товар',
+//                        'class' => 'form-control',
+//                    ],
+//                    'pluginOptions' => [
+//                        'allowClear' => true,
+//                    ],
+//                    'pluginEvents' => [
+//                        'select2:select' => new \yii\web\JsExpression('function() {
+//                        setReplacementPriceData.call(this);
+//                    }'),
+//                    ],
+//                ],
+//                'value' => function ($model) {
+//                    return $model->productReplacement->name ?? '';
+//                },
+//            ],
+//            [
+//                'name' => 'product_replacement_price',
+//                'type' => BaseColumn::TYPE_TEXT_INPUT,
+//                'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,],
+//                'title' => 'Цена замещающего товара',
+//                'value' => function ($data) {
+//                    return $data['product_replacement_price'] ?? '';
+//                },
+//            ],
+//            [
+//                'name' => 'product_replacement_self_cost',
+//                'type' => BaseColumn::TYPE_TEXT_INPUT,
+//                'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,],
+//                'title' => 'Себестоимость замещаемого товара',
+//                'value' => function ($data) {
+//                    return $data['product_replacement_self_cost'] ?? '';
+//                },
+//            ],
+//            [
+//                'name' => 'product_replacement_count',
+//                'type' => BaseColumn::TYPE_TEXT_INPUT,
+//                'options' => ['type' => 'number', 'step' => 1,],
+//                'title' => 'Количество',
+//                'value' => function ($data) {
+//                    return $data['product_replacement_count'] ?? '';
+//                }
+//            ],
+//            [
+//                'name' => 'balance',
+//                'title' => 'Баланс',
+//                'type' => BaseColumn::TYPE_TEXT_INPUT,
+//                'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,],
+//                'value' => function ($data) {
+//                    return $data['balance'] ?? '';
+//                },
+//            ],
+//            [
+//                'name' => 'balance_self_cost',
+//                'title' => 'Разница в сумме (Себестоиомость)',
+//                'type' => BaseColumn::TYPE_TEXT_INPUT,
+//                'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,],
+//                'value' => function ($data) {
+//                    return $data['balance_self_cost'] ?? '';
+//                },
+//            ],
+//        ],
+//        'addButtonPosition' => MultipleInput::POS_FOOTER,
+//        'addButtonOptions' => [
+//            'class' => 'btn btn-success visible',
+//        ],
+//        'removeButtonOptions' => [
+//            'class' => 'btn btn-danger visible',
+//        ],
+//        'iconSource' => 'fa',
+//    ])->label('Таблица возможных замен');
 
     echo $btn = Html::submitButton('Сохранить', [
         'class' => 'btn btn-primary float-right',