From: Alexander Smirnov Date: Fri, 1 Nov 2024 12:43:57 +0000 (+0300) Subject: [ERP-235] Чек возврата без order_id может быть по доставке, если sales_check по доставке X-Git-Tag: 1.6~24^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=7ef809f793be69d87ffbbedafd7a75657758f25d;p=erp24_rep%2Fyii-erp24%2F.git [ERP-235] Чек возврата без order_id может быть по доставке, если sales_check по доставке --- diff --git a/erp24/records/Sales.php b/erp24/records/Sales.php index 626d7db8..32670e43 100755 --- a/erp24/records/Sales.php +++ b/erp24/records/Sales.php @@ -139,4 +139,9 @@ class Sales extends \yii\db\ActiveRecord public function getUsers() { return $this->hasOne(Users::class, ['phone' => 'phone']); } + + public function getSaleCheck() { + return $this->hasOne(self::class, ['id' => 'sales_check']) + ->from(self::tableName() . ' sc'); + } } \ No newline at end of file diff --git a/erp24/services/DashboardService.php b/erp24/services/DashboardService.php index 03083c5e..f5ba83f0 100755 --- a/erp24/services/DashboardService.php +++ b/erp24/services/DashboardService.php @@ -72,7 +72,7 @@ class DashboardService uasort( $sales, function ($a, $b) { - return ($a['percent'] < $b['percent']); + return (-$a['percent'] + $b['percent']); } ); diff --git a/erp24/services/SalesService.php b/erp24/services/SalesService.php index f6179f28..e33e4296 100755 --- a/erp24/services/SalesService.php +++ b/erp24/services/SalesService.php @@ -95,19 +95,32 @@ class SalesService public function getSalesSum($dateFrom, $dateTo, $salesDelivery = false, $salesTotal = false, $storeId1c = null, $payType = null) : array { $query = Sales::find() + ->alias('s') ->select([ - 'summ' => new \yii\db\Expression("SUM(summ - skidka)"), - 'store_id_1c', - 'operation' + 'summ' => new \yii\db\Expression("SUM(s.summ - s.skidka)"), + 's.store_id_1c', + 's.operation' ]) - ->andWhere(['>=', 'date', DateHelper::getDateTimeStartDay($dateFrom, true)]) - ->andWhere(['<=', 'date', DateHelper::getDateTimeEndDay($dateTo, true)]); + ->joinWith('saleCheck') + ->andWhere(['>=', 's.date', DateHelper::getDateTimeStartDay($dateFrom, true)]) + ->andWhere(['<=', 's.date', DateHelper::getDateTimeEndDay($dateTo, true)]); if (!$salesTotal) { if ($salesDelivery) { - $query->andWhere(['not in', 'order_id', ['', '0']]); + $query->andFilterWhere(['or', + ['not in', 's.order_id', ['', '0']], + ['not in', 'sc.order_id', ['', '0']] + ]); } else { - $query->andWhere(['order_id' => ['', '0']]); + $query->andWhere([ + 'and', + ['s.order_id' => ['', '0']], + [ + 'or', + 'sc.order_id IS NULL', + ['sc.order_id' => ['', '0']] + ] + ]); } } @@ -116,15 +129,15 @@ class SalesService $payType = ['1', '3', '1,3', '3,1' ]; } - $query->andWhere(['pay_arr' => $payType]); + $query->andWhere(['s.pay_arr' => $payType]); } if (!empty($storeId1c)) { - $query->andWhere(['store_id_1c' => $storeId1c]); + $query->andWhere(['s.store_id_1c' => $storeId1c]); } - $query->groupBy(['store_id_1c', 'operation']); + $query->groupBy(['s.store_id_1c', 's.operation']); $action = $query->createCommand()->getRawSql();