From d9b8fa29eac8bda6916d930a79338c374f807d9e Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Wed, 7 Aug 2024 13:14:09 +0300 Subject: [PATCH] =?utf8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80?= =?utf8?q?=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/services/MotivationService.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index 6e2371b3..a259fec8 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -3,6 +3,7 @@ namespace yii_app\services; use PhpOffice\PhpSpreadsheet\IOFactory; +use yii\helpers\Json; use yii_app\records\ExportImportTable; use yii_app\records\Motivation; use yii_app\records\MotivationValue; @@ -334,6 +335,8 @@ class MotivationService $monthEnd = date("Y-m-t 23:59:59", strtotime($year . '-' . $month . '-1')); $motivation = Motivation::find()->where(['store_id' => $store_id, 'year' => $year, 'month' => $month])->one(); + $exportImportTable = ExportImportTable::find()->select(['export_val'])->where(['entity' => 'city_store', 'entity_id' => $store_id, 'export_id' => 1])->one(); + /** @var $exportImportTable ExportImportTable */ foreach (range(1, 5) as $ind) { $weekStart = date("Y-m-d 00:00:00", strtotime("+" . (($ind - 1) * 7) . ' days', strtotime($monthStart))); @@ -341,15 +344,16 @@ class MotivationService if ($weekEnd > $monthEnd) { $weekEnd = $monthEnd; } + if ($weekStart > $monthEnd) { + continue; + } $motivationValueGroup = MotivationValueGroup::find()->where(['alias' => 'week' . $ind])->one(); - $eit = ExportImportTable::find()->select(['export_val'])->where(['entity' => 'city_store', 'entity_id' => $store_id, 'export_id' => 1])->one(); - /** @var $eit ExportImportTable */ - if ($eit) { + if ($exportImportTable) { $writeOffs = WriteOffs::find()->select(['sum(summ) as total', 'type']) ->where(['between', 'date', $weekStart, $weekEnd]) - ->andWhere(['store_id' => $eit->export_val]) + ->andWhere(['store_id' => $exportImportTable->export_val]) ->groupBy(['type']) ->indexBy('type') ->asArray()->all(); @@ -374,12 +378,16 @@ class MotivationService $motivationValue->value_float = $data['total']; $motivationValue->save(); if ($motivationValue->getErrors()) { - var_dump($motivationValue->getErrors()); - die; + throw new \Exception(Json::encode($motivationValue->getErrors())); } } } } } + + $motivation->save(); + if ($motivation->getErrors()) { + throw new \Exception(Json::encode($motivation->getErrors())); + } } } -- 2.39.5