From: fomichev Date: Tue, 1 Jul 2025 09:33:16 +0000 (+0300) Subject: Правки пересчета X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=0c210b0df02f6cdc8c16b2d52a26c8e14509543a;p=erp24_rep%2Fyii-erp24%2F.git Правки пересчета --- diff --git a/erp24/controllers/CategoryPlanController.php b/erp24/controllers/CategoryPlanController.php index ef87bdc5..0a5f3648 100644 --- a/erp24/controllers/CategoryPlanController.php +++ b/erp24/controllers/CategoryPlanController.php @@ -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'); } } diff --git a/erp24/views/category-plan/new.php b/erp24/views/category-plan/new.php index 434ed740..b566f1e0 100644 --- a/erp24/views/category-plan/new.php +++ b/erp24/views/category-plan/new.php @@ -159,8 +159,19 @@ input[readonly] {
'btn btn-secondary'])?> - month && $model->year && $model->store_id) { ?> - +
+ + + + + store_id)): ?> +
+
+

store_id]?>

+ month && $model->year && $model->store_id) { ?> + 'btn btn-danger ms-2', 'name' => 'delete', 'id' => 'delete', @@ -172,7 +183,7 @@ input[readonly] { ]) ?> - 'btn btn-success ms-2', 'disabled' => true, 'id' => 'rebuild', @@ -184,19 +195,9 @@ input[readonly] { ], ]) ?> - -
- -
-
- - - - - store_id)): ?> -
-
-

store_id]?>

+ +
+
diff --git a/erp24/web/js/category-plan/index.js b/erp24/web/js/category-plan/index.js index 5c58bb1e..c7aef7f7 100644 --- a/erp24/web/js/category-plan/index.js +++ b/erp24/web/js/category-plan/index.js @@ -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 += `
  • ${category} offline
  • `; + listItems += `
  • ${category} - ${values.offline}
  • `; if (values.internet_shop !== undefined) - listItems += `
  • ${category} internet_shop
  • `; + listItems += `
  • ${category} - ${values.internet_shop}
  • `; if (values.write_offs !== undefined) - listItems += `
  • ${category} write_offs
  • `; + listItems += `
  • ${category} - ${values.write_offs}
  • `; }); changesBox.html(``).hide(); @@ -153,8 +153,32 @@ $(document).ready(() => { '"Пересчитать автопланограмму"'); } - $('#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) {