From: Vladimir Fomichev Date: Wed, 4 Sep 2024 09:49:12 +0000 (+0300) Subject: добавил логику возврата X-Git-Tag: 1.4~8^2~2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=02ff6b9c323571f6dd168fabf691d16f4968c30e;p=erp24_rep%2Fyii-erp24%2F.git добавил логику возврата --- diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index 43a9d6ca..fff4ee00 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -1390,13 +1390,31 @@ class MotivationService $salesRecords = Sales::find() - ->select(['id', 'date']) // Выбираем id и дату чека + ->select(['id', 'date']) ->where(['store_id' => $storeId, 'operation' => 'Продажа']) ->andWhere(['>=', 'date', $startDate]) ->andWhere(['<=', 'date', $endDate]) ->asArray() ->all(); + + $returnedSales = Sales::find() + ->select(['sales_check']) + ->where(['store_id' => $storeId, 'operation' => 'Возврат']) + ->andWhere(['>=', 'date', $startDate]) + ->andWhere(['<=', 'date', $endDate]) + ->andWhere(['is not', 'sales_check', '']) // Проверяем, что поле sales_check не пустое + ->asArray() + ->all(); + + + $returnedSalesIds = array_column($returnedSales, 'sales_check'); + + + $salesRecords = array_filter($salesRecords, function($sale) use ($returnedSalesIds) { + return !in_array($sale['id'], $returnedSalesIds); + }); + // Если нет подходящих чеков, сразу возвращаем 0 if (empty($salesRecords)) { return 0.0;