]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-225 Не правильно считается Прогноз за месяц
authormarina <m.zozirova@gmail.com>
Wed, 16 Oct 2024 10:16:22 +0000 (13:16 +0300)
committermarina <m.zozirova@gmail.com>
Wed, 16 Oct 2024 10:16:22 +0000 (13:16 +0300)
erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php

index 34c3d4e2aebe02401165cc7aa62c07529e8b9b1a..cd54869ddf31a2b94c29d6f6d94a9c23227f6860 100644 (file)
@@ -186,63 +186,64 @@ try {
                     $motivationValue->save();
                 }
 
-
+                $summa = 0;
                 if ($motivationValue->value_id === MotivationCostsItem::findOne(['code' => 10])->id) {
-                        $summa = [];
-
-                        if ($motivationValue->motivation_group_id <= 5 && $motivationValue->motivation_group_id >= 1) {
-                            $period = Motivation::getWeekRange(null, $motivationValue->motivation_group_id);
-                        } else if ($motivationValue->motivation_group_id == 10) {
-                            $period = array(
-                                'startDate' => "$motivation->year-$motivation->month-01 00:00:00",
-                                'endDate' => "$motivation->year-$motivation->month-" . date('t', strtotime("$motivation->year-$motivation->month-01")) . " 23:59:59"
-                            );
-                        }
 
-                        $stores = ArrayHelper::map(CityStore::find()
-                            ->joinWith('storeGuid')
-                            ->select('city_store.id as id, export_import_table.export_val as store_guid')
-                            ->andWhere('city_store.id is not null')
-                            ->andWhere('export_import_table.export_val is not null')
-                            ->andWhere('export_import_table.export_val <> \'\'')
-                            ->orderBy('id desc')
-                            ->asArray()
-                            ->all(), 'id', 'store_guid');
-
-                        if (!empty(array_key_exists($motivation->store_id,$stores))) {
-                            $writeOffs = WriteOffs::find()
-                                ->andWhere(['type' => 'Расходные материалы (обеспечение продаж)'])
-                                ->andWhere(['>', 'date', $period['startDate']])
-                                ->andWhere(['<=', 'date', $period['endDate']])
-                                ->andWhere(['store_id' => $stores[$motivation->store_id]])
+
+                    if ($motivationValue->motivation_group_id <= 5 && $motivationValue->motivation_group_id >= 1) {
+                        $period = Motivation::getWeekRange(null, $motivationValue->motivation_group_id);
+                    } else if ($motivationValue->motivation_group_id == 10) {
+                        $period = array(
+                            'start_time' => "$motivation->year-$motivation->month-01 00:00:00",
+                            'end_time' => "$motivation->year-$motivation->month-" . date('t', strtotime("$motivation->year-$motivation->month-01")) . " 23:59:59"
+                        );
+                    }
+
+                    $stores = ArrayHelper::map(CityStore::find()
+                        ->joinWith('storeGuid')
+                        ->select('city_store.id as id, export_import_table.export_val as store_guid')
+                        ->andWhere('city_store.id is not null')
+                        ->andWhere('export_import_table.export_val is not null')
+                        ->andWhere('export_import_table.export_val <> \'\'')
+                        ->orderBy('id desc')
+                        ->asArray()
+                        ->all(), 'id', 'store_guid');
+
+                    if (!empty(array_key_exists($motivation->store_id,$stores))) {
+                        $writeOffs = WriteOffs::find()
+                            ->andWhere(['type' => 'Расходные материалы (обеспечение продаж)'])
+                            ->andWhere(['>', 'date', $period['start_time']])
+                            ->andWhere(['<=', 'date', $period['end_time']])
+                            ->andWhere(['store_id' => $stores[$motivation->store_id]])
+                            ->all();
+
+                        foreach ($writeOffs as $writeOff) {
+                            $writeOffProducts = WriteOffsProducts::find()
+                                ->andWhere(['write_offs_id' => $writeOff->id])
                                 ->all();
 
-                            foreach ($writeOffs as $writeOff) {
-                                $writeOffProducts = WriteOffsProducts::find()
-                                    ->andWhere(['write_offs_id' => $writeOff->id])
-                                    ->all();
-
-                                foreach ($writeOffProducts as $offProduct) {
-                                    if (empty(array_search($writeOff->store_id, $stores))) {
-                                        continue;
-                                    }
-
-                                    $price = SelfCostProduct::find()
-                                        ->andWhere(['product_guid' => $offProduct->product_id])
-                                        ->andWhere(['store_id' => array_search($writeOff->store_id, $stores)])
-                                        ->andWhere(['date' => date('Y-m-d', strtotime($writeOff->date))])
-                                        ->one();
-                                    if (empty($price)) {
-                                        $price = $offProduct;
-                                    }
-
-                                    $summa += ($price->price * $offProduct->quantity);
+                            foreach ($writeOffProducts as $offProduct) {
+                                if (empty(array_search($writeOff->store_id, $stores))) {
+                                    continue;
+                                }
+
+                                $price = SelfCostProduct::find()
+                                    ->andWhere(['product_guid' => $offProduct->product_id])
+                                    ->andWhere(['store_id' => array_search($writeOff->store_id, $stores)])
+                                    ->andWhere(['date' => date('Y-m-d', strtotime($writeOff->date))])
+                                    ->one();
+
+                                if (empty($price)) {
+                                    $price = $offProduct;
                                 }
+                                $summa =  $summa + $price->price * $offProduct->quantity;
                             }
+
                         }
+                    }
 
-                        $motivationValue += $summa;
-                        $motivationValue->save();
+                    $motivationValue->value_float += $summa;
+                    $motivationValue->save();
                 }
             }