From: fomichev Date: Thu, 3 Jul 2025 10:57:33 +0000 (+0300) Subject: Скачивание по кнопке Auto X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=ea4a9de7cd90ebea77fe0b035869a1dc1c7216ec;p=erp24_rep%2Fyii-erp24%2F.git Скачивание по кнопке Auto --- diff --git a/erp24/commands/CronController.php b/erp24/commands/CronController.php index 480b3789..3d1b9f41 100644 --- a/erp24/commands/CronController.php +++ b/erp24/commands/CronController.php @@ -1692,7 +1692,7 @@ class CronController extends Controller 'store_id' => $store->id, 'is_archive' => false, 'capacity_type' => 1, - 'details' => json_encode($details, JSON_UNESCAPED_UNICODE), + 'details' => json_encode($details, JSON_UNESCAPED_UNICODE), // TODO двойное кодирование 'calculate' => $quantity, 'modify' => ceil($total), 'total' => ceil($total) diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 5e9eb967..4a8c90f9 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -1424,17 +1424,34 @@ class AutoPlannogrammaController extends BaseController $this->layout = false; Yii::$app->response->format = Response::FORMAT_RAW; + $mappingTypes = [ + 'offline' => 'Офлайн', + 'online' => 'Онлайн', + 'write_offs' => 'Списания', + 'marketplace' => 'Маркетплейс' + ]; while (ob_get_level() > 0) { ob_end_clean(); } - $filters = $request->get(); + $filters = []; + $request->get(); + $filters['year'] = (int)$request->get('year'); + $filters['week'] = (int)$request->get('week'); + $filters['city'] = $request->get('city', null); + $filters['region'] = $request->get('region', null); + $filters['district'] = $request->get('district', null); + $filters['capacity_type'] = is_numeric($request->get('capacity_type')) ? (int)$request->get('capacity_type') : null; + $filters['store_type'] = is_numeric($request->get('store_type')) ? (int)$request->get('store_type') : null; + $filters['territorial_manager'] = is_numeric($request->get('territorial_manager')) ? (int)$request->get('territorial_manager') : null; + $filters['bush_chef_florist'] = is_numeric($request->get('bush_chef_florist')) ? (int)$request->get('bush_chef_florist') : null; $query = Autoplannogramma::find() ->alias('a') ->leftJoin('products_1c_nomenclature p1n', 'p1n.id = a.product_id') ->leftJoin('city_store_params cp', 'cp.store_id = a.store_id') + ->leftJoin('city_store c', 'c.id = a.store_id') // ->where(['p1n.category' => $category]) // ->andWhere(['p1n.subcategory' => $subcategory]) ->andFilterWhere(['=', 'a.year', $filters['year']]) @@ -1461,37 +1478,68 @@ class AutoPlannogrammaController extends BaseController $query->andWhere(['in', 'a.store_id', $bushChefFloristStoreIds ?: [-1]]); } - $models = $query + $autoplannogrammData = $query ->select([ 'a.id AS plan_id', 'p1n.id AS product_id', + 'a.product_id', 'p1n.name AS product_name', + 'p1n.category AS category', + 'p1n.subcategory AS subcategory', + 'p1n.species AS species', 'a.store_id', + 'c.name AS store_name', 'a.modify', + 'a.capacity_type', 'a.details', - 'a.month' + 'a.month', + 'a.year', + 'a.week' ]) ->asArray() ->all(); + $detailsData = []; + foreach ($autoplannogrammData as $product) { + $data = $product['details']; + while (is_string($data)) { + $decoded = json_decode($data, true); + if (json_last_error() !== JSON_ERROR_NONE) { + break; + } + $data = $decoded; + } + $detailsArray = $data; + foreach ($detailsArray as $type => $typeArr) { + if (!isset($typeArr['groups']) ) { + continue; + } + $groups = $typeArr['groups']; + $groups[$type] = $typeArr['quantity']; + foreach ($groups as $group => $quantity) { + if (in_array($group, array_keys($mappingTypes))) { + $groupName = $mappingTypes[$group]; + } else { + $groupName = $group; + } + $detailsData[] = [ + 'product_name' => $product['product_name'], + 'category' => $product['category'], + 'subcategory' => $product['subcategory'], + 'species' => $product['species'], + 'month' => $product['month'], + 'year' => $product['year'], + 'week' => $product['week'] . '/' . $product['year'] . '/' . $product['month'], + 'type_pm' => $product['capacity_type'] == 1 ? 'max' : 'min', + 'shop' => $product['store_id'] . ' ' . $product['store_name'], + 'group_name' => $groupName, + 'quantity' => $quantity, + 'value_type' => $type, + ]; + } - foreach ($weeklySalesForecast as $fc ) { - $rows[] = [ - 'week' => $fc['week'], - 'type_pm' => 'max', - 'shop' => $fc['store_id'], - 'category' => $fc['category'], - 'subcategory' => $fc['subcategory'], - 'species' => $fc['species'], - 'product_name' => $fc['product_id'], - 'quantity' => $fc['forecast_week_pieces'], - 'value_type' => 'offline', - 'group_name' => 'Оффлайн', - ]; + } } - - - $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setTitle('Отчёт'); @@ -1509,7 +1557,7 @@ class AutoPlannogrammaController extends BaseController $rowNum = 2; - foreach ($rows as $row) { + foreach ($detailsData as $row) { $sheet->setCellValue('A' . $rowNum, $row['week']); $sheet->setCellValue('B' . $rowNum, $row['type_pm']); $sheet->setCellValue('C' . $rowNum, $row['shop']); diff --git a/erp24/views/auto-plannogramma/index.php b/erp24/views/auto-plannogramma/index.php index 9ee91af0..950f0727 100644 --- a/erp24/views/auto-plannogramma/index.php +++ b/erp24/views/auto-plannogramma/index.php @@ -187,7 +187,11 @@ $this->registerJsFile('/js/autoplannogramma/autoplannogramma.js', ['position' => 'label-kshf']) ?>
- 'btn btn-success ms-1 btn-auto', 'target' => '_blank']) ?> + 'btn btn-success ms-1 btn-auto', + 'id' => 'export-excel-btn', + 'target' => '_blank' + ]) ?> 'btn btn-success ms-1 btn-corrected']) ?>
diff --git a/erp24/web/js/autoplannogramma/autoplannogramma.js b/erp24/web/js/autoplannogramma/autoplannogramma.js index e337b58d..553d40f4 100644 --- a/erp24/web/js/autoplannogramma/autoplannogramma.js +++ b/erp24/web/js/autoplannogramma/autoplannogramma.js @@ -5,6 +5,31 @@ document.addEventListener("DOMContentLoaded", () => { row.style.display = "none"; } }); + $('#export-excel-btn').on('click', function (e) { + e.preventDefault(); + + const baseUrl = '/auto-plannogramma/export-excel'; + const params = { + year: $('#year').val(), + week: $('#week').val(), + city: $('#city').val(), + region: $('#region').val(), + store_type: $('#store-type').val(), + capacity_type: $('#capacity-type').val() || null, + bush_chef_florist: $('#bush_chef_florist').val(), + territorial_manager: $('#territorial-manager').val(), + polnogramma_type: $('#polnogramma-type').val() + }; + + const query = Object.entries(params) + .filter(([_, v]) => v !== null && v !== '') + .map(([k, v]) => k + '=' + encodeURIComponent(v)) + .join('&'); + + const url = baseUrl + (query ? '?' + query : ''); + + window.open(url, '_blank'); + }); document.querySelectorAll(".category").forEach(category => { category.addEventListener("click", function () {