]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Немаркированные товары
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 26 May 2025 08:55:33 +0000 (11:55 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 26 May 2025 08:55:33 +0000 (11:55 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/services/AutoPlannogrammaService.php
erp24/services/StorePlanService.php

index 0baeb488f7a8b27eaea8c04fd5dd0328b8f6671c..6a1c9b7d8a36bf859e5cd949f4fabcc6e59b3a62 100644 (file)
@@ -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;
index d39bbf85fc21a6605b0543675ab2738fdc6f3223..e3bf11c6fa7d7137593278d50cbd27da794995f8 100644 (file)
@@ -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();
 
index dd26b2cc910917738bfad67e786832522dec81d7..9d71f8b57e6c943ddfad085d50b5d0ce29b8e153 100755 (executable)
@@ -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();