use yii\db\Expression;
use yii\db\Query;
use yii\helpers\ArrayHelper;
+use yii_app\records\Autoplannogramma;
use yii_app\records\CityStore;
use yii_app\records\CityStoreParams;
+use yii_app\records\StoreDynamic;
use yii_app\services\AutoPlannogrammaService;
class AutoPlannogrammaController extends BaseController
]);
}
- public function actionGetProducts(string $category, string $subcategory): array
+ public function actionGetProducts(string $category, string $subcategory, array $filters): array
{
+ Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+ $models = Autoplannogramma::find()
+ ->joinWith('products p')
+ ->where(['category' => $category])
+ ->andWhere(['subcategory' => $subcategory])
+ ->andFilterWhere($filters)
+ ->select(['p.id', 'p.name', 'store_id', 'quantity'])
+ ->asArray()
+ ->all();
- Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+ $result = [];
- return [
- [
- 'name' => 'Роза Эквадор 60',
- 'guid' => '74876785y85',
- 'values' => [
- ['count' => 42,
- 'store_id' => 1,
- ],
- [
- 'count' => 13,
- 'store_id' => 2,
- ],
- ]
- ],
- [
- 'name' => 'Роза Эквадор 50',
- 'guid' => '74876e785y85',
- 'values' => [
- ['count' => 2,
- 'store_id' => 1,
- ],
- [
- 'count' => 1,
- 'store_id' => 2,
- ],
- ]
- ],
- ];
+ foreach ($models as $model) {
+ $guid = $model['id'];
+ $name = $model['name'];
+ $storeId = $model['store_id'];
+ $quantity = $model['quantity'];
+
+ if (!isset($result[$guid])) {
+ $result[$guid] = [
+ 'name' => $name,
+ 'guid' => $guid,
+ 'values' => [],
+ ];
+ }
+
+ $result[$guid]['values'][] = [
+ 'count' => (int) $quantity,
+ 'store_id' => (int) $storeId,
+ ];
+ }
+
+ return array_values($result);
}
public function actionGetVisibleStores()
{
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+ $f = Yii::$app->request->get();
- $filters = Yii::$app->request->get();
-
- $query = CityStoreParams::find()
+ $q = CityStoreParams::find()
->alias('p')
->joinWith(['store s'])
->select('p.store_id')
->where(['s.visible' => CityStore::IS_VISIBLE]);
- $fields = [
- 'city' => 'p.address_city',
- 'store_type' => 'p.store_type',
- 'territorialManager' => 's.territorial_manager_id',
- 'region' => 'p.address_region',
- 'district' => 'p.address_district',
- 'bushChefFlorist' => 's.bush_chef_florist_id',
- ];
+ foreach ([
+ 'city' => 'p.address_city',
+ 'storeType' => 'p.store_type',
+ 'region' => 'p.address_region',
+ 'district' => 'p.address_district'
+ ] as $param => $col) {
+ if (!empty($f[$param])) $q->andWhere([$col => $f[$param]]);
+ }
- foreach ($fields as $param => $column) {
- if (!empty($filters[$param])) {
- $query->andWhere([$column => $filters[$param]]);
+ foreach ([
+ 'territorialManager' => 3,
+ 'bushChefFlorist' => 2
+ ] as $param => $cat) {
+ if (!empty($f[$param])) {
+ $ids = StoreDynamic::find()
+ ->select('store_id')
+ ->where(['category' => $cat, 'active' => 1, 'value_int' => $f[$param]])
+ ->column();
+ $q->andWhere(['p.store_id' => $ids ?: [-1]]);
}
}
- return ['store_ids' => $query->column()];
+ return ['store_ids' => $q->column()];
}
-
-
public function action1()
{
$request = Yii::$app->request;
namespace yii_app\records;
+use Product;
use Yii;
/**
'updated_by' => 'Автор обновления',
];
}
+
+ public function getProducts() {
+ return $this->hasOne(Products1cNomenclature::className(), ['id' => 'product_id']);
+ }
}
<thead>
<tr class="head">
<th scope="col" style="text-align: left !important;">
- <?= Html::label("год: 2025 неделя: 05") ?><br>
- <?= Html::label("январь - февраль") ?><br>
- <?= Html::label("Тип п-ма:") ?><br>
- <?= Html::label("Город:") ?><br>
- <?= Html::label("Регион:") ?><br>
- <?= Html::label("Район:") ?><br>
- <?= Html::label("Тип магазина:") ?><br>
- <?= Html::label("Тер. Уп.:") ?><br>
- <?= Html::label("КШФ:") ?><br>
+ <?= Html::label("год: 2025 неделя: 05", null, ['class' => 'label-year-week']) ?><br>
+ <?= Html::label("январь - февраль", null, ['class' => 'label-month-range']) ?><br>
+ <?= Html::label("Тип п-ма:", null, ['class' => 'label-capacity-type']) ?><br>
+ <?= Html::label("Город:", null, ['class' => 'label-city']) ?><br>
+ <?= Html::label("Регион:", null, ['class' => 'label-region']) ?><br>
+ <?= Html::label("Район:", null, ['class' => 'label-district']) ?><br>
+ <?= Html::label("Тип магазина:", null, ['class' => 'label-store-type']) ?><br>
+ <?= Html::label("Тер. Уп.:", null, ['class' => 'label-tu']) ?><br>
+ <?= Html::label("КШФ:", null, ['class' => 'label-kshf']) ?><br>
+
<div class="buttons d-flex justify-content-end">
- <?= Html::a('Auto', '#', ['class' => 'btn btn-success ms-1']) ?>
- <?= Html::a('Corrected', '#', ['class' => 'btn btn-success ms-1']) ?>
+ <?= Html::a('Auto', '#', ['class' => 'btn btn-success ms-1 btn-auto']) ?>
+ <?= Html::a('Corrected', '#', ['class' => 'btn btn-success ms-1 btn-corrected']) ?>
</div>
</th>
<?php foreach ($stores as $storeId => $storeName): ?>
<th scope="col" class="fixed-column" data-store-id="<?= $storeId ?>">
<?= Html::label($storeName, null, [
- 'style' => 'writing-mode: sideways-lr; text-align: center; white-space: nowrap;
+ 'style' => 'text-align: center; white-space: nowrap;
font-weight: bold; transform-origin: left bottom; padding-right: 7%;'
]) ?>
</th>
$row.find('td[data-store-id]').each(function () {
const td = $(this);
const storeId = td.data('store-id');
- const val = valuesMap[storeId] ?? { count: '', guid: '' };
+ const val = valuesMap[storeId] ?? {count: '', guid: ''};
const newTd = $(`
<td data-store-id="${storeId}">
});
});
-$('#autoplannogramma').on('change, input', '.input', function () {
+$('#autoplannogramma').on('input', '.input', function () {
const $input = $(this);
const newValue = $input.val();
-console.log(3)
const $td = $input.closest('td');
const $svg = $td.find('svg');
};
}
-// Применение фильтра магазинов
+function getFilterData() {
+ return {
+ year: $('#year').val(),
+ week: $('#week').val(),
+ city: $('#city').val(),
+ store_type: $('#store-type').val(),
+ territorial_manager: $('#territorial-manager').val(),
+ capacity_type: $('#polnogramma-type').val(),
+ region: $('#region').val(),
+ district: $('#district').val(),
+ bush_chef_florist: $('#bush_chef_florist').val(),
+ };
+}
+
function applyStoreFilter() {
- $.get('/auto-plannogramma/get-visible-stores', getFilterData(), function (response) {
+ const data = getFilterData();
+
+ $.get('/auto-plannogramma/get-visible-stores', data, function (response) {
const allowedStoreIds = (response.store_ids || []).map(String);
$('td[data-store-id], th[data-store-id]').each(function () {
const storeId = String($(this).data('store-id'));
$(this).toggle(allowedStoreIds.includes(storeId));
});
+
+ // Обновляем значения рядом с лейблами, выводим текст, а не id
+ $('.label-year-week').text(`год: ${data.year || '—'} неделя: ${data.week || '—'}`);
+ $('.label-month-range').text(getMonthRangeByWeek(data.week));
+
+ $('.label-capacity-type').text('Тип п-ма: ' + getSelectedText('#polnogramma-type'));
+ $('.label-city').text('Город: ' + getSelectedText('#city'));
+ $('.label-region').text('Регион: ' + getSelectedText('#region'));
+ $('.label-district').text('Район: ' + getSelectedText('#district'));
+ $('.label-store-type').text('Тип магазина: ' + getSelectedText('#store-type'));
+ $('.label-tu').text('Тер. Уп.: ' + getSelectedText('#territorial-manager'));
+ $('.label-kshf').text('КШФ: ' + getSelectedText('#bush_chef_florist'));
+
}).fail(function (xhr) {
console.error('Ошибка при фильтрации магазинов:', xhr.responseText);
});
}
-// Сброс фильтров и отображение всех ячеек
+function getSelectedText(selector) {
+ const select = $(selector);
+ const val = select.val();
+ const text = select.find(`option[value="${val}"]`).text();
+ return text;
+}
+
function resetStoreFilter() {
- // Сброс значений фильтров
- $('#year, #city, #store-type, #territorial-manger, #polnogramma-type, #week, #region, #bush_chef_florist, #district').val('');
- // Показ всех ячеек
+ // Сброс обычных инпутов
+ $('#year, #week').val('');
+
+ // Сброс всех Select2
+ $('#city, #store-type, #territorial-manager, #polnogramma-type, #region, #bush_chef_florist, #district')
+ .val(null)
+ .trigger('change');
+
+ // Показ всех ячеек магазинов
$('td[data-store-id], th[data-store-id]').show();
+
+ // Очистка лейблов
+ $('.label-year-week').text('');
+ $('.label-month-range').text('');
+ $('.label-city, .label-store-type, .label-tu, .label-capacity-type, .label-region, .label-district, .label-kshf')
+ .text('—');
}
-// Ð\9eбÑ\80абоÑ\82Ñ\87ики событий
-$('.btn-apply').on('click', applyStoreFilter);
-$('.btn-reset').on('click', resetStoreFilter);
+// Ð\9fÑ\80ивÑ\8fзка событий
+$(document).on('click', '.btn-apply', applyStoreFilter);
+$(document).on('click', '.btn-reset', resetStoreFilter);
+// Дополнительная функция: получить диапазон месяцев по номеру недели (примерная логика)
+function getMonthRangeByWeek(week) {
+ if (!week) return '—';
+ const w = parseInt(week, 10);
+ if (w <= 4) return 'январь';
+ if (w <= 8) return 'январь - февраль';
+ if (w <= 13) return 'февраль - март';
+ // ... можно доработать
+ return '—';
+}