]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-370] fix bugs origin/feature_smirnov_erp-370_region_in_price
authorAlexander Smirnov <fredeom@mail.ru>
Fri, 28 Mar 2025 15:04:20 +0000 (18:04 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Fri, 28 Mar 2025 15:04:20 +0000 (18:04 +0300)
erp24/commands/PriceController.php

index 8c0cc0f8b3cb7665bd23810962918f6fc3f893d9..0296a6efc6523367392298fe9ed0c5c59ddceae3 100644 (file)
@@ -4,30 +4,34 @@ namespace yii_app\commands;
 
 use Yii;
 use yii\console\Controller;
+use yii\db\Expression;
 use yii_app\records\PricesDynamic;
 
 class PriceController extends Controller {
     public function actionFixActiveNullRegion() {
         $pricesDynamics = PricesDynamic::find()->where(['or', ['region_id' => null], ['region_id' => 52]])
-            ->andWhere(['active' => 1])->orderBy(['date_from' => SORT_ASC])->all();
+            ->andWhere(['active' => 1])
+            //->andWhere(['product_id' => ['5466448f-946a-11e2-bf3d-1c6f659fb563', 'c552f4d8-0a1e-11e5-bd74-1c6f659fb563', '8476f3e1-a9ee-11e4-bedc-1c6f659fb563']])
+            ->orderBy(['date_from' => SORT_ASC])
+            ->all();
         $p = [];
         foreach ($pricesDynamics as $pricesDynamic) {
             /** @var $pricesDynamic PricesDynamic */
             $p[$pricesDynamic->region_id ?? 0][$pricesDynamic->product_id][] = [
                 'id' => $pricesDynamic->id,
-                'date_to' => $pricesDynamic->date_to,
+                'date_from' => $pricesDynamic->date_from,
             ];
         }
-        foreach ($p[0] as $productId => $priceDynamicDatas) {
-            if ($p[52][$productId]) {
+        foreach ($p[0] ?? [] as $productId => $priceDynamicDatas) {
+            if (isset($p[52][$productId])) {
                 $cnt = count($priceDynamicDatas);
-                for ($ind = 0; $ind < $cnt - 1; $cnt++) {
+                for ($ind = 0; $ind < $cnt; $ind++) {
                     if ($ind < $cnt - 1) {
-                        PricesDynamic::updateAll(['active' => 0, 'region_id' => 52, 'date_to' => $priceDynamicDatas[$ind+1]['date_to']],
+                        PricesDynamic::updateAll(['active' => 0, 'region_id' => 52, 'date_to' => $priceDynamicDatas[$ind+1]['date_from']],
                             ['id' => $priceDynamicDatas[$ind]['id']]);
                         echo '1';
                     } else {
-                        PricesDynamic::updateAll(['active' => 0, 'region_id' => 52, 'date_to' => $p[52][$productId][count($p[52][$productId]) - 1]['date_to']],
+                        PricesDynamic::updateAll(['active' => 0, 'region_id' => 52, 'date_to' => $p[52][$productId][count($p[52][$productId]) - 1]['date_from']],
                             ['id' => $priceDynamicDatas[$ind]['id']]);
                         echo '2';
                     }