]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-130] Дебаг 008
authorAlexander Smirnov <fredeom@mail.ru>
Mon, 2 Sep 2024 11:15:10 +0000 (14:15 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Mon, 2 Sep 2024 11:15:10 +0000 (14:15 +0300)
erp24/services/MotivationService.php

index b225f9a5f0c3b3827aeec762394d7e1dbe25f4ac..ed1ad50e69dc4b1ceb981de2abfbabfb4e45b563 100644 (file)
@@ -457,9 +457,8 @@ class MotivationService
                 $writeOffs = WriteOffs::find()->select(['items', 'type'])
                     ->where(['between', 'date', $weekStart, $weekEnd])
                     ->andWhere(['store_id' => $exportImportTable->export_val])
-//                    ->indexBy('type')
                     ->asArray()->all();
-//                var_dump($writeOffs);
+
                 $selfCostProduct = SelfCostProduct::find()->select(['price', 'product_guid'])
                     ->where(['between', 'date', $weekStart, $weekEnd])
                     ->andWhere(['store_id' => $store_id])
@@ -467,32 +466,32 @@ class MotivationService
                     ->asArray()->all();
 
                 foreach (MotivationCostsItem::getWriteOffsItems() as $key) {
-                    $data = $writeOffs[$key] ?? null;
-                    $sum = 0;
-                    if (!empty($data)) {
-                        try {
-                            $json = Json::decode($data['items'] ?? '[]');
-
-                            foreach ($json as $itemArr) {
-                                $sum += floatval(($selfCostProduct[$itemArr['product_id']]["price"] ?? 0)) * ($itemArr['quantity'] ?? 0);
-//                                var_dump($selfCostProduct[$itemArr['product_id']]["price"] ?? 0);
-//                                var_dump($itemArr['quantity'] ?? 0);
-                            }
-                        } catch (\Exception $ex) {}
-                    }
-                    $motivationItemType = MotivationCostsItem::writeOffsToMotivationItemMap($key);
-                    $motivationCostsItem = MotivationCostsItem::find()->where(['name' => $motivationItemType])->one();
-                    /** @var $motivationCostsItem MotivationCostsItem */
-                    if ($motivation && $motivationCostsItem) {
-                        var_dump($sum);
-                        self::saveOrUpdateMotivationValue($motivation->id, 'week' . $ind, $motivationCostsItem->code,
-                            MotivationCostsItem::DATA_TYPE_FLOAT, $sum);
+                    foreach($writeOffs as $data) {
+                        if (($data['type'] ?? '') != $key) {
+                            continue;
+                        }
+                        $sum = 0;
+                        if (!empty($data)) {
+                            try {
+                                $json = Json::decode($data['items'] ?? '[]');
+
+                                foreach ($json as $itemArr) {
+                                    $sum += floatval(($selfCostProduct[$itemArr['product_id']]["price"] ?? 0)) * ($itemArr['quantity'] ?? 0);
+                                }
+                            } catch (\Exception $ex) {}
+                        }
+                        $motivationItemType = MotivationCostsItem::writeOffsToMotivationItemMap($key);
+                        $motivationCostsItem = MotivationCostsItem::find()->where(['name' => $motivationItemType])->one();
+                        /** @var $motivationCostsItem MotivationCostsItem */
+                        if ($motivation && $motivationCostsItem) {
+                            self::saveOrUpdateMotivationValue($motivation->id, 'week' . $ind, $motivationCostsItem->code,
+                                MotivationCostsItem::DATA_TYPE_FLOAT, $sum);
+                        }
                     }
                 }
             }
-//            var_dump("-------");
         }
-//        die;
+
         if ($motivation) {
             $motivation->save();
             if ($motivation->getErrors()) {