$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
? "Удалено {$count} записей."
: 'Ничего не удалено.'
);
-
+ Yii::$app->cache->set('needRecalc', time(), 3600);
$params = [
'DynamicModel' => $model->attributes,
}
- 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');
->asArray()
->all();
-
-
-
-
$mnths = [];
foreach ($salesMatrixOffline as $saleMatrixOffline) {
$mnths[$saleMatrixOffline['month']] = 1;
if ($categoryPlanNew->getErrors()) {
throw new Exception(Json::encode($categoryPlanNew->getErrors()));
}
+
+ $recalcFlag = Yii::$app->cache->get('needRecalc');
}
}
<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',
])
?>
- <?= Html::submitButton('Пересчитать автопланограмму', [
+ <?= Html::button('Пересчитать автопланограмму', [
'class' => 'btn btn-success ms-2',
'disabled' => true,
'id' => 'rebuild',
],
])
?>
- <?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)): ?>
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;
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);
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();
'"Пересчитать автопланограмму"</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) {