From: fomichev Date: Mon, 26 May 2025 08:55:33 +0000 (+0300) Subject: Немаркированные товары X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=e1c549d7cc625baabc7804f4a8a415e7c208ad42;p=erp24_rep%2Fyii-erp24%2F.git Немаркированные товары --- diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 0baeb488..6a1c9b7d 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -709,7 +709,9 @@ class AutoPlannogrammaController extends BaseController ); - var_dump( $withoutHistoryResults); die(); + + + $flatData = array_filter($data, function ($row) use ($filters) { foreach ($filters as $key => $value) { if (empty($value)) continue; diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index d39bbf85..e3bf11c6 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -6,9 +6,13 @@ use Yii; use yii\db\Expression; use yii\db\Query; use yii\helpers\ArrayHelper; +use yii_app\records\BouquetComposition; use yii_app\records\CityStore; +use yii_app\records\CityStoreParams; use yii_app\records\PricesDynamic; +use yii_app\records\Products1c; use yii_app\records\Products1cNomenclature; +use yii_app\records\Sales; use yii_app\records\SalesProducts; use yii_app\records\SalesWriteOffsPlan; @@ -679,40 +683,64 @@ class AutoPlannogrammaService /** * @param array|int $storeIds - * @param string $dateFrom формат 'Y-m-d H:i:s' - * @param string $dateTo формат 'Y-m-d H:i:s' + * @param int $month + * @param int $year * @param int $regionId * @return array список строк с полями: * sale_id, sale_date, product_id, product_name, * component_guid, component_name, component_category, * quantity, price, cost */ - public function getUnmarkedProductsComponents(array|int $storeIds, string $dateFrom, string $dateTo, int $regionId = 52, $typeFilter = null): array + public function getUnmarkedProductsComponents(int $storeId, string $month, string $year, int $regionId = null, $typeFilter = null): array { - $salesProducts = SalesProducts::find() - ->alias('sp') - ->innerJoinWith([ - 'sale s', - 'product_1c p1c', - 'product.nomenclature nom', - ]) - ->andWhere(['s.store_id' => $storeIds]) - ->andWhere(['between', 's.date', $dateFrom, $dateTo]) - ->andWhere(['nom.category' => null]); + $date = new \DateTimeImmutable(sprintf('%04d-%02d-01', $year, $month)); + + + $region = CityStoreParams::find() + ->where(['store_id' => $storeId]) + ->one()->address_region; - if ($typeFilter) { - $salesProducts->andWhere(['p1c.type' => $typeFilter]); + if (!$regionId && !$region) { + // определяем регион по городу + $cityId = CityStore::find()->select('city_id')->where(['id' => $storeId])->scalar(); + if ($cityId == 1) { + $region = BouquetComposition::REGION_MSK; + } else { + $region = BouquetComposition::REGION_NN; } - $salesProducts->all(); + } + $monthStart = sprintf('%04d-%02d-01 00:00:00', $year, $month); + $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year); + $monthEnd = sprintf('%04d-%02d-%02d 23:59:59', $year, $month, $daysInMonth); + $salesProducts = Sales::find() + ->alias('s') + ->select(['s.id', 's.date', 'sp.product_id', 'p1c.type', 'p1c.components' , 'p1c.name']) + ->innerJoin( + ['sp' => SalesProducts::tableName()], + 's.id = sp.check_id' + ) + ->innerJoin( + ['p1c' => Products1c::tableName()], + 'p1c.id = sp.product_id' + ) + ->leftJoin( + ['nom' => Products1cNomenclature::tableName()], + 'nom.id = sp.product_id' + ) + ->andWhere(['s.store_id' => $storeId]) + ->andWhere(['between', 's.date', $monthStart, $monthEnd]) + ->andWhere(['not', ['p1c.components' => '']]) + ->andWhere(['nom.category' => null]) + ->asArray() + ->all(); + // var_dump( $salesProducts); die(); $components = []; $rows = []; foreach ($salesProducts as $sp) { /** @var SalesProducts $sp */ - $sale = $sp->check_id; - $product = $sp->product_id; - $js = trim($product->components); + $js = trim($sp['components']); if ($js === '' || $js[0] !== '{') { continue; } @@ -729,30 +757,31 @@ class AutoPlannogrammaService $components[$guid] = true; $rows[] = [ - 'sale_id' => $sale->id, - 'sale_date' => $sale->date, - 'product_id' => $product->id, - 'product_name'=> $product->name, + 'sale_id' => $sp['id'], + 'sale_date' => $sp['date'], + 'product_id' => $sp['product_id'], + 'product_name'=> $sp['name'], 'component_guid' => $guid, 'quantity' => $qty, ]; } } + if (empty($rows)) { return []; } $guids = array_keys($components); $nomenclatures = Products1cNomenclature::find() - ->andWhere(['guid' => $guids]) - ->indexBy('guid') + ->andWhere(['id' => $guids]) + ->indexBy('id') ->all(); $priceDynamics = PricesDynamic::find() - ->andWhere(['region_id' => $regionId]) + ->andWhere(['region_id' => $region]) ->andWhere(['product_id' => array_values( ArrayHelper::getColumn($nomenclatures, 'id') )]) - ->andWhere(['<=', 'date_from', $dateTo]) - ->andWhere(['>=', 'date_to', $dateFrom]) + // ->andWhere(['<=', 'date_from', $monthStart]) + // ->andWhere(['>=', 'date_to', $monthEnd]) ->orderBy(['date_from' => SORT_DESC]) ->all(); diff --git a/erp24/services/StorePlanService.php b/erp24/services/StorePlanService.php index dd26b2cc..9d71f8b5 100755 --- a/erp24/services/StorePlanService.php +++ b/erp24/services/StorePlanService.php @@ -627,7 +627,7 @@ class StorePlanService ->andWhere([ 'or', ['>=', 'date_to', $weekStart->format('Y-m-d')], - ['date_to' => '2100-01-01 03:00:00+03'] + ['date_to' => '2100-01-01 00:00:00+03'] ]) ->all();