Browse Source

生成实际到岗人数数据

ANG YU 4 năm trước cách đây
mục cha
commit
c020408020

+ 3 - 0
app/Console/Kernel.php

@@ -20,6 +20,7 @@ use App\Console\Commands\SyncWMSOrderTask;
 use App\Console\Commands\TestTemp;
 use App\Console\Commands\WasSyncWmsAsnInformation;
 use App\Console\Commands\WASSyncWMSOrderInformation;
+use App\Jobs\CalculationArrivedManNumJob;
 use App\Jobs\LaborApplyRecordJob;
 use Illuminate\Console\Scheduling\Schedule;
 use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@@ -86,6 +87,8 @@ class  Kernel extends ConsoleKernel
         $schedule->command('AccordingToOwnersManualBack')->everyThirtyMinutes()->between('9:00','16:30');
 
         $schedule->job(new LaborApplyRecordJob())->dailyAt('19:00');//生成临时工派遣数据
+
+        $schedule->job(new CalculationArrivedManNumJob(now()->subDays(2)->startOfDay()))->dailyAt('01:01');//生成实际到岗人数数据
     }
 
     /**

+ 7 - 0
app/Http/Controllers/TestController.php

@@ -573,4 +573,11 @@ sql;
     {
         $this->dispatch(new CalculationArrivedManNumJob(\Illuminate\Support\Carbon::parse(now()->toDateString())));
     }
+
+    public function test_sddgdfg()
+    {
+        /** @var OwnerStoreOutFeeReportService $service */
+        $service = app('OwnerStoreOutFeeReportService');
+        $service->recordReport(null, [2]);
+    }
 }

+ 43 - 31
app/Services/OwnerStoreFeeReportService.php

@@ -2,6 +2,7 @@
 
 namespace App\Services;
 
+use App\Interfaces\SettlementBillReportInterface;
 use App\Owner;
 use App\OwnerBillReport;
 use App\OwnerBillReportArchive;
@@ -12,7 +13,7 @@ use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Facades\DB;
 
-class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReportInterface
+class OwnerStoreFeeReportService implements SettlementBillReportInterface
 {
     const TYPE = '入库费-合计';
 
@@ -98,35 +99,9 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
             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,//税费
-                ]);
-            }
-        }
+        //货主的每个计费模型都要有数据,如果当月没有实际数据则需要
+        //写默认值
+        $this->insertDefaultData($counting_month);
     }
 
     public function get(array $kvPairs): array
@@ -207,5 +182,42 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
         $this->confirmBillFeeTotal($counting_month, $owner_id);
     }
 
-
+    /**
+     * 没有数量的计费模型填充0数据
+     * @param string|null $counting_month
+     */
+    private function insertDefaultData(?string $counting_month): void
+    {
+        //查询到全部的货主
+        $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;
+                //构建默认数据
+                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,//税费
+                ]);
+            }
+        }
+    }
 }