فهرست منبع

结算 入库费添加默认值

ANG YU 4 سال پیش
والد
کامیت
fe75400001
1فایلهای تغییر یافته به همراه42 افزوده شده و 10 حذف شده
  1. 42 10
      app/Services/OwnerStoreFeeReportService.php

+ 42 - 10
app/Services/OwnerStoreFeeReportService.php

@@ -2,8 +2,10 @@
 
 namespace App\Services;
 
+use App\Owner;
 use App\OwnerBillReport;
 use App\OwnerBillReportArchive;
+use App\OwnerPriceOperation;
 use App\Traits\ServiceAppAop;
 use App\OwnerStoreFeeReport;
 use Carbon\Carbon;
@@ -31,7 +33,7 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
      * 如果参数$counting_month为2021-01-01 则统计2021-01-01 -- 2021-01-31之间的数据
      * @param null $counting_month 统计月份,默认统计上个月的 2021-05-01
      */
-    public function recordReport($counting_month = null,array $ownerIds = [])
+    public function recordReport($counting_month = null, array $ownerIds = [])
     {
         $this->detailService = app('OwnerStoreFeeDetailService');
         if (is_null($counting_month)) {
@@ -56,18 +58,18 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
             ->whereBetween('owner_fee_operations.worked_at', [$start, $end])
             ->whereNotNull('owner_fee_operation_details.price')
             ->whereNotNull('owner_fee_operation_details.amount')
-            ->whereIn('model_id', \App\OwnerPriceOperation::query()->select('id')->where('operation_type', '入库'));
+            ->whereIn('model_id', OwnerPriceOperation::query()->select('id')->where('operation_type', '入库'));
         if (!empty($ownerIds)) {
             $builder->whereIn('owner_fee_operations.owner_id', $ownerIds);
         }
         $details = $builder->groupBy(
-                    'counting_month',
-                    'owner_id',
-                    'unit_id',
-                    'price',
-                    'model_id'
-                )
-                ->get();
+            'counting_month',
+            'owner_id',
+            'unit_id',
+            'price',
+            'model_id'
+        )
+            ->get();
         $reports = [];
         foreach ($details as $detail) {
             $counting_month = Carbon::parse($detail->counting_month)->startOfMonth()->toDateString();
@@ -76,7 +78,7 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
                 ->where('owner_id', $detail->owner_id)
                 ->where('counting_month', $counting_month)->first();
             $reports[] = [
-                'owner_bill_report_id' => $ownerBillReport->id ?? null,
+                'owner_bill_report_id' => $ownerBillReport->id ?? 1,
                 'owner_id' => $detail->owner_id,
                 'counting_month' => $counting_month,
                 'unit_id' => $detail->unit_id,
@@ -95,6 +97,36 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
         foreach ($reports_chunked as $items) {
             OwnerStoreFeeReport::query()->insertOrIgnore($items);
         }
+
+        //没有数量的计费模型填充0数据
+        //查询到全部的货主
+        $owners = Owner::query()->with('ownerPriceOperations.items')->get();
+        foreach ($owners as $owner) {
+            $owner_id = $owner->id;
+            foreach ($owner->ownerPriceOperations as $ownerPriceOperation) {
+                $ownerPriceOperation_id = $ownerPriceOperation->id;
+                $has_report = OwnerStoreFeeReport::query()
+                    ->where('owner_id', $owner_id)
+                    ->where('model_id', $ownerPriceOperation_id)
+                    ->where('counting_month', $counting_month)
+                    ->exists();
+                if ($has_report) continue;
+
+//                foreach ($ownerPriceOperation->items as $ownerPriceOperationItem) {
+                OwnerStoreFeeReport::query()->insert([
+                    'owner_bill_report_id' => 1,
+                    'owner_id' => $owner_id,
+                    'counting_month' => $counting_month, //统计月份
+                    'unit_id' => 4, //件
+                    'unit_price' => $ownerPriceOperation->items[0]->unit_price ?? 0, //单价
+                    'amount' => 0, //数量
+                    'fee' => 0,//费用
+                    'work_name' => $ownerPriceOperation->name,//作业名称
+                    'model_id' => $ownerPriceOperation_id,//计费模型
+                    'tax_fee' => 0,//税费
+                ]);
+            }
+        }
     }
 
     public function get(array $kvPairs): array