zhouzhendong 4 роки тому
батько
коміт
8540cff774

+ 5 - 1
app/Console/Kernel.php

@@ -20,7 +20,9 @@ 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 App\Services\LaborApplyService;
 use Illuminate\Console\Scheduling\Schedule;
 use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
 use Illuminate\Foundation\Console\ModelMakeCommand;
@@ -85,7 +87,9 @@ class  Kernel extends ConsoleKernel
         //$schedule->command('check:cacheRack')->everyMinute();
         $schedule->command('AccordingToOwnersManualBack')->everyThirtyMinutes()->between('9:00','16:30');
 
-        $schedule->job(new LaborApplyRecordJob())->dailyAt('19:00');//生成临时工派遣数据
+        $schedule->job(new LaborApplyRecordJob(false))->dailyAt(LaborApplyService::TIME_OUT_HOUR.':00');//生成临时工派遣数据
+
+        $schedule->job(new CalculationArrivedManNumJob(now()->subDays(2)->startOfDay()))->dailyAt('01:01');//生成实际到岗人数数据
     }
 
     /**

+ 8 - 12
app/Http/Controllers/LaborApplyController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 
+use App\Filters\LaborApplyFilters;
 use App\Http\Requests\LaborApply\LaborApplyRequest;
 use App\Jobs\LaborApplyRecordJob;
 use App\LaborApply;
@@ -17,12 +18,15 @@ use Illuminate\Support\Facades\Gate;
 
 class LaborApplyController extends Controller
 {
-    public function index(Request $request, \App\Filters\LaborApplyFilters $filters)
+    public function index(Request $request, LaborApplyFilters $filters)
     {
         $builder = LaborApply::query()
             ->filter($filters)
             ->with(['warehouse', 'userWorkGroup', 'applyUser']);
-        if (!(\auth()->user()->isSuperAdmin() || Gate::allows('宝时人事部'))) {
+        /** @var User $user */
+        $user = auth()->user();
+        $auth_user_is_人事主管 = $user->roles()->where('name', '人事主管')->exists();
+        if (!($user->isSuperAdmin() || $auth_user_is_人事主管)) {
             $builder->where('apply_user_id', \auth()->id());
         }
         $labor_applies = $builder
@@ -44,14 +48,6 @@ class LaborApplyController extends Controller
 
     public function store(LaborApplyRequest $request, LaborApply $laborApply)
     {
-
-        $user_workgroup_applied = LaborApply::query()
-            ->whereDate('created_at', now()->toDateString())
-            ->where('user_workgroup_id', $request->user_workgroup_id)
-            ->exists();
-        if ($user_workgroup_applied) {
-            return redirect()->back()->with('warning', '该仓库小组今日已申请过,请修改申请人数,不要重复申请!');
-        }
         $laborApply->fill($request->all());
         $laborApply->apply_user_id = Auth::id();
         $laborApply->status = '创建';
@@ -101,7 +97,7 @@ class LaborApplyController extends Controller
         $service->setCanCreateStatus(LaborApply::CAN_CREATE_STATUS_TEMPORARY_OPEN);
         $ttl = LaborApplyService::LABOR_APPLY_STATUS_TTL;
         //调用定时任务 开放时间过了自动生成报表
-        LaborApplyRecordJob::dispatch()->delay(now()->addSeconds($ttl));
+        LaborApplyRecordJob::dispatch(true)->delay(now()->addSeconds($ttl));
         return redirect(route('laborApply.create'))->with('success', "临时开放成功,有效时间为:{$ttl}S ");
     }
 
@@ -112,7 +108,7 @@ class LaborApplyController extends Controller
     {
         /** @var LaborApplyService $laborApplyService */
         $laborApplyService = app('LaborApplyService');
-        $response = $laborApplyService->allocationLaborToLaborCompany();
+        $response = $laborApplyService->allocationLaborToLaborCompany(true);
         $route = 'laborCompanyDispatch.index';
         if ($response['success']) {
             return redirect(route('' . $route . ''))->with('success', '重新生成劳务派遣数据成功!');

+ 7 - 5
app/Http/Controllers/LaborCompanyDispatchController.php

@@ -18,19 +18,21 @@ class LaborCompanyDispatchController extends Controller
         //按照分配日期倒序
         $builder = LaborCompanyDispatch::query()
             ->filter($filters)
-            ->with(['laborCompany', 'laborCompanyDispatchDetails']);
+            ->with(['laborCompany.warehouse', 'laborCompanyDispatchDetails']);
 
-        if (!(\auth()->user()->isSuperAdmin() || Gate::allows('宝时人事部'))) {
-            /** @var User $user */
-            $user = auth()->user();
+        /** @var User $user */
+        $user = auth()->user();
+        $auth_user_is_人事主管 = $user->roles()->where('name', '人事主管')->exists();
+        if (!($user->isSuperAdmin() || $auth_user_is_人事主管)) {
             //获取用户的劳务角色 劳务角色名 与 劳务所名称相同
-            $laborCompanyNames = $user->roles()->where('name', 'LIKE', '劳务')->pluck('name');
+            $laborCompanyNames = $user->roles()->where('name', 'LIKE', '%劳务%')->pluck('name');
             //根据劳务所名称相同 查询劳务所Id
             $laborCompanyIds = LaborCompany::query()->whereIn('name', $laborCompanyNames)->pluck('id');
             $builder->whereIn('labor_company_id', $laborCompanyIds);
         }
         $labor_company_dispatches = $builder
             ->orderByDesc('dispatch_date')
+            ->orderByDesc('id')
             ->paginate();
 
         return view('personnel.laborApply.dispatch.index', compact('labor_company_dispatches'));

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

@@ -693,4 +693,11 @@ sql;
         $orderHeaders = $service->getQuery()->where('DOC_Order_Header.WaveNo',$code)->get();
         $orderService->syncOrder($orderHeaders);
     }
+
+    public function test_sddgdfg()
+    {
+        /** @var OwnerStoreOutFeeReportService $service */
+        $service = app('OwnerStoreOutFeeReportService');
+        $service->recordReport(null, [2]);
+    }
 }

+ 5 - 2
app/Jobs/LaborApplyRecordJob.php

@@ -16,15 +16,18 @@ class LaborApplyRecordJob implements ShouldQueue
 
     /** @var $service LaborApplyService */
     private $service;
+    //是否为追加
+    private $isAppend = false;
 
     /**
      * Create a new job instance.
      *
      * @return void
      */
-    public function __construct()
+    public function __construct(bool $isAppend = false)
     {
         $this->service = app('LaborApplyService');
+        $this->isAppend = $isAppend;
     }
 
     /**
@@ -34,7 +37,7 @@ class LaborApplyRecordJob implements ShouldQueue
      */
     public function handle()
     {
-        $response = $this->service->allocationLaborToLaborCompany();
+        $response = $this->service->allocationLaborToLaborCompany($this->isAppend);
         if (!$response['success']) throw new WarningException($response['error_message']);
     }
 }

+ 31 - 9
app/Services/LaborApplyService.php

@@ -17,8 +17,10 @@ use function DeepCopy\deep_copy;
 class LaborApplyService
 {
     //超时时间 默认为19:00
-    const TIME_OUT_HOUR = 19;
+    const TIME_OUT_HOUR = 18;
     const LABOR_APPLY_STATUS = 'LABOR_APPLY_STATUS';
+    //上次次临时工申请分配的时间
+    const  LATELY_LABOR_COMPANY_DISPATCH_CREATED_AT = 'LATELY_LABOR_COMPANY_DISPATCH_CREATED_AT';
     const LABOR_APPLY_STATUS_TTL = 60 * 30;
     //到岗日期是申请日期的前一天 为保证数据正确 计算实际人数的时间为到岗日期的后一天 故时间为2
     const CALCULATION_ARRIVED_MAN_NUM_DEFAULT_SUB_DAYS = 2;
@@ -51,6 +53,14 @@ class LaborApplyService
         Cache::put(self::LABOR_APPLY_STATUS, $status, self::LABOR_APPLY_STATUS_TTL);
     }
 
+    public function allocationAppendLaborToLaborCompany()
+    {
+        $lately_allocation_at = Cache::get(self::LATELY_LABOR_COMPANY_DISPATCH_CREATED_AT);
+        $labor_applies = LaborApply::query()
+            ->where('created_at', '>=', $lately_allocation_at)
+            ->get();
+    }
+
     /**
      * 生产劳务派遣报表
      *
@@ -60,27 +70,37 @@ class LaborApplyService
      * 按照仓库查询对应的劳务所 按照优先级排序
      * 将男女工之和依次分配到 劳务所
      * 如果分配完成后 发现还有剩下的 则将状态设置为2
+     * @param bool $isAppend
+     * @return array
      */
-    public function allocationLaborToLaborCompany(): array
+    public function allocationLaborToLaborCompany(bool $isAppend=false): array
     {
-
         //当前时间小于 1.00 禁止生成数据
         if (now()->lte(now()->startOfDay()->addHours(1))) return ['success' => false, 'error_message' => '当前时间禁止生成临时工派遣数据'];
+        //上次分配时间 默认为前一天的18:00
+        $lately_allocation_at = now()->subDay()->startOfDay()->addHours(self::TIME_OUT_HOUR);
+        //缓存中有上次的同步时间
+        if (Cache::has(self::LATELY_LABOR_COMPANY_DISPATCH_CREATED_AT)) {
+            $lately_allocation_at = Cache::get(self::LATELY_LABOR_COMPANY_DISPATCH_CREATED_AT);
+        }
         //派遣日期 为报表生成日期的后一天
         $dispatch_date = now()->addDay()->startOfDay()->toDateTimeString();
 
-        //接口幂等性,删除旧的数据
-        LaborCompanyDispatch::query()->where('dispatch_date', $dispatch_date)->delete();
-
         //查询全部仓库
         $warehouses = Warehouse::all();
         //给每个仓库计算分配数据 更改申请状态为指派成功
         foreach ($warehouses as $warehouse) {
             //查询当日的的申请,将申请的男女工分别加和
-            $apply_man_nums = DB::table('labor_applies')
+            $builder = DB::table('labor_applies')
                 ->selectRaw("sum(man_num) as man_num ,sum(woman_num) as woman_num")
                 ->whereBetween('created_at', [now()->startOfDay(), now()->endOfDay()])
-                ->where('warehouse_id', $warehouse->id)
+                ->where('warehouse_id', $warehouse->id);
+            //如果是追加模式
+            if ($isAppend) {
+                //只查询最后一次分配后的申请
+                $builder->where('created_at', '>=', $lately_allocation_at);
+            }
+            $apply_man_nums = $builder
                 ->groupBy('warehouse_id')
                 ->first();
             if (empty($apply_man_nums)) continue;
@@ -102,6 +122,8 @@ class LaborApplyService
                     'status' => 2,//指派成功
                 ]);
         }
+        //保存分配时间为当前时间
+        Cache::put(self::LATELY_LABOR_COMPANY_DISPATCH_CREATED_AT, now());
         return ['success' => true, 'message' => '生成临时工派遣数据成功'];
     }
 
@@ -222,7 +244,7 @@ class LaborApplyService
         LaborCompanyDispatch::query()
             ->whereDate('dispatch_date', $check_in_at)
             ->update([
-                'status' => 3//任务完结
+                'status' => 4//任务完结
             ]);
     }
 }

+ 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,//税费
+                ]);
+            }
+        }
+    }
 }

+ 1 - 1
resources/views/finance/settlementBills/storeOutFee/report/index.blade.php

@@ -81,7 +81,7 @@
                     <td class="m-0 p-0">
                         <table class="table table-striped table-sm m-0 p-0">
                             <tr v-for="item in report.data">
-                                <td>/</td>
+                                <td>@{{ item.step }}</td>
                             </tr>
                         </table>
                     </td>

+ 4 - 2
resources/views/personnel/laborApply/dispatch/index.blade.php

@@ -21,7 +21,7 @@
                         </div>
                     </td>
                     <td class="">
-                        @can('劳务所')
+                        @can('人事管理-临时工申请协调-劳务派遣明细')
                             <div class="float-left ml-3" v-if="labor_company_dispatch.status==='人事确认'">
                                 <form :action="getBaseUrl(labor_company_dispatch) + '/laborCompanyReceivingOrder'"
                                       method="post"
@@ -64,6 +64,7 @@
                     </td>
 
                     <td>@{{ labor_company_dispatch.labor_company.name }}</td>
+                    <td>@{{ labor_company_dispatch.labor_company.warehouse.name }}</td>
                     <td>@{{ labor_company_dispatch.status }}</td>
                     <td>@{{ labor_company_dispatch.man_num }}</td>
                     <td>@{{ labor_company_dispatch.woman_num }}</td>
@@ -90,7 +91,7 @@
                             </a>
                         </div>
                     </td>
-                    <td>@{{ labor_company_dispatch.dispatch_date }}</td>
+                    <td>@{{  labor_company_dispatch.dispatch_date.slice(0, 10)  }}</td>
 
                 </tr>
             </table>
@@ -134,6 +135,7 @@
                     {name: 'index', value: '序号', neglect: true},
                     {name: 'do', value: '操作'},
                     {name: 'name', value: '劳务公司'},
+                    {name: 'warehouse', value: '仓库'},
                     {name: 'status', value: '状态 '},
                     {name: 'man_num', value: '男工人数'},
                     {name: 'woman_num', value: '女工人数'},