From: fomichev Date: Mon, 5 May 2025 08:51:08 +0000 (+0300) Subject: Выводл списаний за месяц X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=9cac33fcd51cac157862fd01953022d57e546b97;p=erp24_rep%2Fyii-erp24%2F.git Выводл списаний за месяц --- diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 3dc54ee8..4b95f02a 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -212,92 +212,72 @@ class AutoPlannogrammaController extends BaseController public function actionControlSpecies() { - $model = new DynamicModel([ - 'storeId','monthFrom','monthTo','type', - 'category','subcategory','species' + 'storeId', 'month', 'type', + ]); - $model->addRule(['monthFrom','monthTo','type'], 'required') - ->addRule('storeId', 'integer') - ->addRule(['category','subcategory','species'], 'string'); + $model->addRule(['month', 'type'], 'required') + ->addRule('storeId', 'integer'); $storeList = CityStore::find() ->select(['name','id']) + ->where(['visible' => CityStore::IS_VISIBLE]) ->indexBy('id') ->column(); $monthsList = []; for ($i = 0; $i < 12; $i++) { - $m = (new \DateTime("first day of -{$i} month"))->format('Y-m'); - $monthsList[$m] = (new \DateTime("first day of -{$i} month")) - ->format('F Y'); - } - - - $categoryList = Products1cNomenclature::find() - ->select('category') - ->distinct() - ->indexBy('category') - ->column(); - - $subcategoryList = []; - if ($model->category) { - $subcategoryList = Products1cNomenclature::find() - ->where(['category' => $model->category]) - ->select('subcategory') - ->distinct() - ->indexBy('subcategory') - ->column(); - } - - $speciesList = []; - if ($model->category && $model->subcategory) { - $speciesList = Products1cNomenclature::find() - ->where([ - 'category' => $model->category, - 'subcategory' => $model->subcategory - ]) - ->select('species') - ->distinct() - ->indexBy('species') - ->column(); + // получаем метку вида "03-2025" + $ts = strtotime("first day of -{$i} month"); + $key = date('m-Y', $ts); + $monthsList[$key] = $key; } $result = []; + $totals = []; if ($model->load(Yii::$app->request->post()) && $model->validate()) { - // формируем фильтры $filters = []; - if ($model->storeId) $filters['store_id'] = $model->storeId; - if ($model->category) $filters['category'] = $model->category; - if ($model->subcategory)$filters['subcategory']= $model->subcategory; - if ($model->species) $filters['species'] = $model->species; - //var_dump($model->type); die(); - $dateFrom = $model->monthFrom . '-01'; + if ($model->storeId) { + $filters['store_id'] = $model->storeId; + } + + + list($m, $y) = explode('-', $model->month); + $dateFrom = sprintf('%04d-%02d-01', $y, $m); $dateTo = date('Y-m-t', strtotime($dateFrom)); - $service = new AutoPlannogrammaService(); - $totals = $service->getStoreTotals([1,2,4], '2025-03-01', null, 'writeOffs'); - // var_dump($totals);die(); - $result = $service - ->getMonthSpeciesShareOrWriteOffDate( - '2025-03-01', - '2025-03-31', + + $service = new AutoPlannogrammaService(); + + if ($model->storeId) { + $totals = $service->getStoreTotals( + [$model->storeId], + $dateFrom, null, - null, // productFilter - 'writeOffs' + $model->type, + $dateTo ); + } + + $result = $service->getMonthSpeciesShareOrWriteOffDate( + $dateFrom, + $dateTo, + $filters, + null, + $model->type + ); } return $this->render('control-species', [ 'model' => $model, 'result' => $result, + 'totals' => $totals, 'storeList' => $storeList, 'monthsList' => $monthsList, - 'categoryList' => $categoryList, - 'subcategoryList' => $subcategoryList, - 'speciesList' => $speciesList, + ]); } + /** * Возвращает список подкатегорий для выбранной категории. * @param string $category diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index 4f89144a..79c5de6b 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -417,7 +417,7 @@ class AutoPlannogrammaService $storeIds = array_intersect($storeIds, [(int)$filters['store_id']]); } - $totals = $this->getStoreTotals($storeIds, '2025-03-01', null, 'writeOffs', '2025-03-31'); + $totals = $this->getStoreTotals($storeIds, $dateFrom, null, $type, $dateTo); if (empty($totals)) { return []; } @@ -488,7 +488,7 @@ class AutoPlannogrammaService 'subcategory' => $row['subcategory'], 'species' => $row['species'], 'total_sum' => (float)$row['total_sum'], - 'percent_of_month'=> round((float)$row['total_sum'] / $total, 4), + 'percent_of_month'=> round(((float)$row['total_sum'] / $total) , 4), ]; } diff --git a/erp24/views/auto-plannogramma/control-species.php b/erp24/views/auto-plannogramma/control-species.php index f331340b..7df8a61a 100644 --- a/erp24/views/auto-plannogramma/control-species.php +++ b/erp24/views/auto-plannogramma/control-species.php @@ -8,34 +8,26 @@ use yii_app\records\PricesDynamic; use yii_app\records\Products1c; /* @var $this yii\web\View */ -/* @var $result array|null */ /* @var $model DynamicModel */ /* @var $storeList array */ /* @var $monthsList array */ -/* @var $categoryList array */ -/* @var $subcategoryList array */ -/* @var $speciesList array */ +/* @var $result array */ +/* @var $totals array */ ?> -
-

Проверка данных по видам

+
+

Проверка продаж/списаний по видам

- 'post', - ]); ?> + 'post']); ?> field($model, 'storeId') ->dropDownList($storeList, ['prompt' => 'Выберите магазин']) ->label('Магазин') ?> - field($model, 'monthFrom') - ->dropDownList($monthsList, ['prompt' => 'Начало периода']) - ->label('Дата с') ?> - - field($model, 'monthTo') - ->dropDownList($monthsList, ['prompt' => 'Конец периода']) - ->label('Дата по') ?> + field($model, 'month') + ->dropDownList($monthsList, ['prompt' => 'Выберите месяц']) + ->label('Месяц') ?> field($model, 'type') ->radioList([ @@ -44,17 +36,6 @@ use yii_app\records\Products1c; ]) ->label('Тип данных') ?> - field($model, 'category') - ->dropDownList($categoryList, ['prompt' => 'Выберите категорию']) - ->label('Категория') ?> - - field($model, 'subcategory') - ->dropDownList($subcategoryList, ['prompt' => 'Выберите подкатегорию']) - ->label('Подкатегория') ?> - - field($model, 'species') - ->dropDownList($speciesList, ['prompt' => 'Выберите вид товара']) - ->label('Вид товара') ?>
'btn btn-primary']) ?> @@ -62,12 +43,31 @@ use yii_app\records\Products1c; + +

Итоги по магазину

+ + + + + + + + + $sum): ?> + + + + + + +
МагазинИтого сумма
formatter->asDecimal($sum, 2) ?>
+ + -

Результаты

+

Детализация по видам

- @@ -78,7 +78,6 @@ use yii_app\records\Products1c; - @@ -90,9 +89,5 @@ use yii_app\records\Products1c;
Магазин Категория Подкатегория Вид товара
- registerJsFile('/js/category-plan/show-history-data.js', [ - 'position' => \yii\web\View::POS_END - ]); - ?> +