]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Правки пересчета
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 1 Jul 2025 09:33:16 +0000 (12:33 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 1 Jul 2025 09:33:16 +0000 (12:33 +0300)
erp24/controllers/CategoryPlanController.php
erp24/views/category-plan/new.php
erp24/web/js/category-plan/index.js

index ef87bdc5615054f597c5528dee7f9a0e8ff7e971..0a5f3648ee7dfee16224ea609b56d1270eb7397d 100644 (file)
@@ -460,7 +460,7 @@ class CategoryPlanController extends Controller {
         $stores = ArrayHelper::map(CityStore::find()->andWhere(['visible' => '1'])->all(), 'id', 'name');
         $salesWriteOffsPlan = SalesWriteOffsPlan::find()->where(['year' => $model->year, 'month' => $model->month, 'store_id' => $model->store_id])->one();
         /////////////////////////// CHAT GPT STUFF ///////////////////////////////////
-        //var_dump(Yii::$app->request->get()); die();
+
         if (
             $model->year
             && $model->month
@@ -483,7 +483,7 @@ class CategoryPlanController extends Controller {
                         ? "Удалено {$count} записей."
                         : 'Ничего не удалено.'
                 );
-
+                Yii::$app->cache->set('needRecalc', time(), 3600);
 
                 $params = [
                     'DynamicModel' => $model->attributes,
@@ -500,47 +500,6 @@ class CategoryPlanController extends Controller {
 
             }
 
-            if (Yii::$app->request->get('rebuild') === '1'
-            ) {
-                /*Yii::$app->queue->push(new RebuildAutoplannogramJob([
-                    'year'    => (int)$model->year,
-                    'month'   => (int)$model->month,
-                    'storeId' => (int)$model->store_id,
-                ]));*/
-                $yii = escapeshellarg(Yii::getAlias('@app/yii'));
-                $year  = (int)$model->year;
-                $month = (int)$model->month;
-                $store = (int)$model->store_id;
-
-
-                $cmd = "php {$yii}  cron/autoplannogramma-recalculate "
-                    . " --year={$year} --month={$month} --storeId={$store} "
-                    . "> /dev/null 2>&1 &";
-
-                exec($cmd, $output, $exitCode);
-
-                if ($exitCode === 0) {
-                    Yii::$app->session->setFlash('success','Задача запущена в фоне.');
-                    Yii::info('Задача запущена в фоне.');
-                } else {
-                    Yii::$app->session->setFlash('error','Не удалось запустить задачу.');
-                    Yii::error('Не удалось запустить задачу.');
-                }
-
-                $params = [
-                    'DynamicModel' => $model->attributes,
-                ];
-
-                $params['DynamicModel'] = array_filter($params['DynamicModel'], function($v) {
-                    return $v !== null && $v !== '';
-                });
-
-                return $this->redirect(array_merge(
-                    ['new'],
-                    $params
-                ));
-            }
-
             $currentDate = new \DateTime(date($model->year . '-' . $model->month . '-01'));
 
             $startDate = (clone $currentDate)->modify('-4 months')->modify('first day of this month');
@@ -575,10 +534,6 @@ class CategoryPlanController extends Controller {
                 ->asArray()
                 ->all();
 
-
-
-
-
             $mnths = [];
             foreach ($salesMatrixOffline as $saleMatrixOffline) {
                 $mnths[$saleMatrixOffline['month']] = 1;
@@ -699,6 +654,8 @@ class CategoryPlanController extends Controller {
                     if ($categoryPlanNew->getErrors()) {
                         throw new Exception(Json::encode($categoryPlanNew->getErrors()));
                     }
+
+                    $recalcFlag = Yii::$app->cache->get('needRecalc');
                 }
             }
 
index 434ed740bf231e13a3ac1aec15bbaeb5b0e6a7bd..b566f1e04052a81fba7f4706f61628461843e3bd 100644 (file)
@@ -159,8 +159,19 @@ input[readonly] {
                 <div class="col-1"></div>
                 <div class="col-11">
                     <?= Html::submitButton('Применить', ['class' => 'btn btn-secondary'])?>
-                    <?php if ($model->month && $model->year && $model->store_id) { ?>
-                    <?= Html::submitButton('Вернуть автоплан', [
+
+                </div>
+            </div>
+        </div>
+    </div>
+    <?php ActiveForm::end() ?>
+
+    <?php if (isset($model->store_id)): ?>
+        <div class="row">
+            <div class="col-4">
+                <h1><?= $stores[$model->store_id]?></h1>
+                <?php if ($model->month && $model->year && $model->store_id) { ?>
+                    <?= Html::button('Вернуть автоплан', [
                         'class' => 'btn btn-danger ms-2',
                         'name'  => 'delete',
                         'id' => 'delete',
@@ -172,7 +183,7 @@ input[readonly] {
                     ])
                     ?>
 
-                    <?= Html::submitButton('Пересчитать автопланограмму', [
+                    <?= Html::button('Пересчитать автопланограмму', [
                         'class' => 'btn btn-success ms-2',
                         'disabled' => true,
                         'id' => 'rebuild',
@@ -184,19 +195,9 @@ input[readonly] {
                         ],
                     ])
                     ?>
-                    <?php } ?>
-                    <div id="changes-count"></div>
-                    <div id="changes" style="display:none;"></div>
-                </div>
-            </div>
-        </div>
-    </div>
-    <?php ActiveForm::end() ?>
-
-    <?php if (isset($model->store_id)): ?>
-        <div class="row">
-            <div class="col-4">
-                <h1><?= $stores[$model->store_id]?></h1>
+                <?php } ?>
+                <div id="changes-count"></div>
+                <div id="changes" style="display:none;"></div>
             </div>
         </div>
         <?php if (isset($salesWriteOffsPlan)): ?>
index 5c58bb1e3e5cdd05fcfcbf388ba1c9ae52424fa5..c7aef7f7d3e160346e2c8c36a1b3ea3671a7a934 100644 (file)
@@ -38,9 +38,9 @@ function editProcent(zis) {
     const type = tr.querySelector('th[data-type]').textContent.trim();
 
     const map = {
-        p1: { dataKey: 'offline', inputName: 'offline' },
-        p2: { dataKey: 'online', inputName: 'internet_shop' },
-        p3: { dataKey: 'writeoffs', inputName: 'write_offs' },
+        p1: { dataKey: 'offline', inputName: 'offline', desc: "Оффлайн" },
+        p2: { dataKey: 'online', inputName: 'internet_shop', desc: "Онлайн" },
+        p3: { dataKey: 'writeoffs', inputName: 'write_offs', desc: "Списания" },
     }[zis.name];
 
     if (!map) return;
@@ -92,7 +92,7 @@ function editProcent(zis) {
                 changes[store_id][type] = {};
             }
 
-            changes[store_id][type][map.inputName] = currentVal;
+            changes[store_id][type][map.inputName] = map.desc;
 
             localStorage.setItem('planChanges', JSON.stringify(changes, null, 2));
             updateChangesLog(store_id);
@@ -113,16 +113,16 @@ function updateChangesLog(store_id) {
     if (!changes[store_id]) {
         changes[store_id] = {};
     }
-
+    console.log(changes);
     const count = Object.keys(changes[store_id]).length;
     let listItems = '';
     Object.entries(changes[store_id]).forEach(([category, values]) => {
         if (values.offline !== undefined)
-            listItems += `<li>${category} offline</li>`;
+            listItems += `<li>${category} - ${values.offline}</li>`;
         if (values.internet_shop !== undefined)
-            listItems += `<li>${category} internet_shop</li>`;
+            listItems += `<li>${category} - ${values.internet_shop}</li>`;
         if (values.write_offs !== undefined)
-            listItems += `<li>${category} write_offs</li>`;
+            listItems += `<li>${category} - ${values.write_offs}</li>`;
     });
 
     changesBox.html(`<ul>${listItems}</ul>`).hide();
@@ -153,8 +153,32 @@ $(document).ready(() => {
             '"Пересчитать автопланограмму"</div>');
     }
 
-    $('#delete').on('click', function () {
+    $('#delete').on('click', function (event) {
+        event.preventDefault();
         localStorage.removeItem('planChanges');
+
+
+        const year = $('#dynamicmodel-year').val();
+        const month = $('#dynamicmodel-month').val();
+        const store_id = $('#selected-store').val();
+
+        const params = {
+            'DynamicModel[year]': year,
+            'DynamicModel[month]': month,
+            'DynamicModel[store_id]': store_id,
+            'delete': 1
+        };
+
+        $.ajax({
+            url: '/category-plan/new',
+            method: 'GET',
+            data: params,
+            success: function (response) {
+            },
+            error: function () {
+                alert('Ошибка при удалении автоплана.');
+            }
+        });
     });
 
     $('#rebuild').on('click', function (event) {