|
|
@@ -66,75 +66,9 @@ class ProcessController extends Controller
|
|
|
$processDailies=ProcessDaily::with(['processDailyParticipants','process'])
|
|
|
->orderBy('date','DESC')->where('process_id',$id)->get();
|
|
|
}
|
|
|
- //$processDailies=$this->countManHour($processDailies);
|
|
|
}
|
|
|
return $processDailies;
|
|
|
}
|
|
|
-
|
|
|
- /*//根据参与人查找打卡记录计算工时信息
|
|
|
- public function countManHour($processDailies){
|
|
|
- foreach ($processDailies as $processDaily){
|
|
|
- $date=$processDaily->date;
|
|
|
- foreach ($processDaily->processDailyParticipants as $processDailyParticipant){
|
|
|
- $processDailyParticipant->started_at=Carbon::parse($processDailyParticipant->started_at)->format('H:i');
|
|
|
- $processDailyParticipant->ended_at=Carbon::parse($processDailyParticipant->ended_at)->format('H:i');
|
|
|
- $processDailyParticipant=$this->countParticipantManHour($processDailyParticipant,$date);
|
|
|
- }
|
|
|
- }
|
|
|
- return $processDailies;
|
|
|
- }*/
|
|
|
-
|
|
|
- /*//计算单参与人工时信息
|
|
|
- public function countParticipantManHour($processDailyParticipant,$date){
|
|
|
- $user_id=$processDailyParticipant->user_id;
|
|
|
- $userDutyCheckStart=UserDutyCheck::select('id','checked_at')->where('user_id',$user_id)
|
|
|
- ->where('checked_at','like',$date.'%')->where('type','登入')->orderBy('id')->first();
|
|
|
- $userDutyCheckEnd=UserDutyCheck::select('id','checked_at')->where('user_id',$user_id)
|
|
|
- ->where('checked_at','like',$date.'%')->where('type','登出')->orderBy('id','desc')->first();
|
|
|
- //跨日情况寻找下一天
|
|
|
- if (!$userDutyCheckEnd){
|
|
|
- $date=date("Y-m-d",strtotime("+1 day",strtotime($date)));
|
|
|
- $userDutyCheckEnd=UserDutyCheck::select('id','checked_at')->where('user_id',$user_id)
|
|
|
- ->where('checked_at','like',$date.'%')->where('type','登出')->orderBy('id','desc')->first();
|
|
|
- }
|
|
|
- if (!$userDutyCheckStart || !$userDutyCheckEnd){
|
|
|
- return $processDailyParticipant;
|
|
|
- }
|
|
|
- $dateStart=Carbon::parse($userDutyCheckStart->checked_at);
|
|
|
- $dateEnd=Carbon::parse($userDutyCheckEnd->checked_at);
|
|
|
- $hour=($dateEnd->diffInSeconds($dateStart))/3600; //打卡工时
|
|
|
- if ($processDailyParticipant->dinner_duration)$hour=$hour-(($processDailyParticipant->dinner_duration)/60); //减晚饭时间
|
|
|
- $hour=$this->isHour($userDutyCheckStart,$hour); //去除休息时间
|
|
|
- $processDailyParticipant->hour=round($hour,2);
|
|
|
- if ($hour&&$processDailyParticipant->hour_count){
|
|
|
- $diff=abs(round($processDailyParticipant->hour_count-$hour,2));
|
|
|
- $processDailyParticipant->diff=$diff;
|
|
|
- }
|
|
|
-
|
|
|
- //计件工 保留
|
|
|
- // if ($processDailyParticipant->unit_count){
|
|
|
- // return $processDailyParticipant;
|
|
|
- //}
|
|
|
- if ($hour&&$hour>8){
|
|
|
- $processDailyParticipant->billingHour=8;
|
|
|
- return $processDailyParticipant;
|
|
|
- }
|
|
|
- if ($hour&&$hour<=8){
|
|
|
- $processDailyParticipant->billingHour=round($hour,2);
|
|
|
- }
|
|
|
- return $processDailyParticipant;
|
|
|
- }*/
|
|
|
-
|
|
|
-/* //打卡工时减休息时间
|
|
|
- private function isHour($userDutyCheckStart,$hour){
|
|
|
-
|
|
|
- $date=$userDutyCheckStart->checked_at;
|
|
|
- $date=Carbon::parse($date)->format('H');
|
|
|
- if ((int)$date<=11){
|
|
|
- $hour=$hour-1;
|
|
|
- }
|
|
|
- return $hour;
|
|
|
- }*/
|
|
|
//生成二次加工单缺失时间记录及本日记录
|
|
|
private function createDeficiencyData($processDailies,$today){
|
|
|
$processDailiesArr=[];
|
|
|
@@ -202,15 +136,15 @@ class ProcessController extends Controller
|
|
|
if(!Gate::allows('二次加工管理-交接完成')){ return ['success'=>false,'data'=>'您无权进行该操作!']; }
|
|
|
$process=Process::with('processDailies')->find($request->id);
|
|
|
if (!$process || $process->status == '交接完成')return ['success'=>false];
|
|
|
- $result=$this->statistic($process);
|
|
|
+ $this->statistic($process);
|
|
|
$process->update(['status'=>'交接完成']);
|
|
|
$process->createOperatorLog('交接完成');
|
|
|
- $processStatistic=$result['data'];
|
|
|
- app('LogService')->log(__METHOD__,"完成二次加工单_".__FUNCTION__,json_encode($process)." || ".json_encode($processStatistic),Auth::user()['id']);
|
|
|
app('ProcessService')->createInstantBill($process);
|
|
|
return ['success'=>true,'data'=>'交接完成'];
|
|
|
}
|
|
|
private function statistic($process, $sign_end = false){
|
|
|
+ $processStatistic=ProcessStatistic::query()->find($process->id);
|
|
|
+ if (!$processStatistic)return ['success'=>true];
|
|
|
if (count($process->processDailies)>0){
|
|
|
$completed_amount=0;
|
|
|
foreach ($process->processDailies as $processDaily){
|
|
|
@@ -235,7 +169,6 @@ class ProcessController extends Controller
|
|
|
$total_cost += ($processDailyParticipant->hour_count)*($processDailyParticipant->hour_price);
|
|
|
}
|
|
|
};
|
|
|
- $processStatistic=ProcessStatistic::query()->find($process->id);
|
|
|
$processStatistic->revenue=$revenue;
|
|
|
$processStatistic->duration_days=$duration_days;
|
|
|
$processStatistic->duration_man_hours=$duration_man_hours;
|
|
|
@@ -369,7 +302,7 @@ class ProcessController extends Controller
|
|
|
}]);
|
|
|
|
|
|
// 重置统计开始时间
|
|
|
- event(new ResetProcessStatisticStartDateEvent($processDailyParticipant->processDaily->process));
|
|
|
+ //event(new ResetProcessStatisticStartDateEvent($processDailyParticipant->processDaily->process));
|
|
|
|
|
|
|
|
|
if ($processDailyParticipant->processDaily && $processDailyParticipant->processDaily->process &&
|
|
|
@@ -378,8 +311,6 @@ class ProcessController extends Controller
|
|
|
}
|
|
|
$result=[];
|
|
|
$processDaily=ProcessDaily::with('process')->select('process_id','date')->find($daily_id);
|
|
|
- //$date=$processDaily->date;
|
|
|
- //$processDailyParticipant=$this->countParticipantManHour($processDailyParticipant,$date);
|
|
|
if ($processDaily->process && $processDaily->process->status=="待加工"){
|
|
|
$process=Process::find($processDaily->process_id);
|
|
|
$process->status="加工中";
|
|
|
@@ -389,7 +320,6 @@ class ProcessController extends Controller
|
|
|
if (!$processStatistic){
|
|
|
Log::warning("二次加工统单不存在2",["user"=>Auth::id(),"param"=>$processDaily->process_id]);
|
|
|
}else {
|
|
|
- //$processStatistic->started_at=date('Y-m-d H:i:s');
|
|
|
$processStatistic->started_at=$processDaily->date.' '.$started_at;
|
|
|
$processStatistic->update();
|
|
|
app('LogService')->log(__METHOD__,"二次加工单加工中".__FUNCTION__,json_encode($process)." || ".json_encode($processStatistic),Auth::user()['id']);
|
|
|
@@ -452,7 +382,7 @@ class ProcessController extends Controller
|
|
|
if (!$processDailyParticipant || !$processDailyParticipant->processDaily
|
|
|
|| !$processDailyParticipant->processDaily->process || !$processDailyParticipant->userLabor) return ['success'=>false,'data'=>"修改失败,该信息不存在"];
|
|
|
if ($processDailyParticipant->userLabor->isOccupiedAt($processDailyParticipant->processDaily->date,$request->started_at)){
|
|
|
- ['success'=>false,'data'=>"该临时工此时间段已存在工作记录"];
|
|
|
+ return ['success'=>false,'data'=>"该临时工此时间段已存在工作记录"];
|
|
|
}
|
|
|
$processDailyParticipant->user_id=$request->input('user_id');
|
|
|
$processDailyParticipant->started_at=$request->input('started_at');
|
|
|
@@ -468,19 +398,8 @@ class ProcessController extends Controller
|
|
|
if ($processDailyParticipant->processDaily->process->status=='交接完成'){
|
|
|
$this->statistic($processDailyParticipant->processDaily->process);
|
|
|
}
|
|
|
- //$processDailyParticipant=$this->countParticipantManHour($processDailyParticipant,$processDailyParticipant->processDaily->date);
|
|
|
return ['success'=>true,'data'=>$processDailyParticipant];
|
|
|
}
|
|
|
- /*//参与人审核
|
|
|
- public function processDailyParticipantAudit($id){
|
|
|
- if(!Gate::allows('人事管理-任务审核')){ return redirect(url('/')); }
|
|
|
- $processDailyParticipant=ProcessDailyParticipant::select('id','status')->find($id);
|
|
|
- if (!$processDailyParticipant) return ['success'=>false];
|
|
|
- $processDailyParticipant->status='已审核';
|
|
|
- $processDailyParticipant->update();
|
|
|
- app('LogService')->log(__METHOD__,"登记工时参与人审核".__FUNCTION__,json_encode($processDailyParticipant),Auth::user()['id']);
|
|
|
- return ['success'=>true,'processDailyParticipant'=>$processDailyParticipant];
|
|
|
- }*/
|
|
|
//获取全部教程
|
|
|
public function getTutorials($id){
|
|
|
$process=Process::with('tutorials')->find($id);
|
|
|
@@ -519,7 +438,7 @@ class ProcessController extends Controller
|
|
|
/**
|
|
|
* Show the form for creating a new resource.
|
|
|
*
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
+ * @return Application|Factory|\Illuminate\Http\Response|View
|
|
|
*/
|
|
|
public function create()
|
|
|
{
|
|
|
@@ -565,6 +484,9 @@ class ProcessController extends Controller
|
|
|
'status'=>'待审核',
|
|
|
]);
|
|
|
$process->save();
|
|
|
+ ProcessStatistic::query()->create([
|
|
|
+ 'process_id'=>$process->id,
|
|
|
+ ]);
|
|
|
$process->createOperatorLog('创建');
|
|
|
$processContents=[];
|
|
|
foreach ($request->input('processContents') as $processContent){
|
|
|
@@ -614,12 +536,6 @@ class ProcessController extends Controller
|
|
|
}
|
|
|
$process->code='P'.date ("Ymd").str_pad($process->id,3,"0",STR_PAD_LEFT);
|
|
|
$process->update();
|
|
|
- $processStatistic=new ProcessStatistic([
|
|
|
- 'process_id'=>$process->id,
|
|
|
- ]);
|
|
|
- $processStatistic->save();
|
|
|
- app('LogService')->log(__METHOD__,"录入二次加工单".__FUNCTION__,json_encode($request->input()),Auth::user()['id']);
|
|
|
- //if ($request->input('tutorials'))$process->tutorials()->sync($request->input('tutorials'));
|
|
|
return ['success'=>true];
|
|
|
}
|
|
|
//修改价格
|
|
|
@@ -701,7 +617,7 @@ class ProcessController extends Controller
|
|
|
* Show the form for editing the specified resource.
|
|
|
*
|
|
|
* @param int $id
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
+ * @return Application|Factory|\Illuminate\Http\Response|View
|
|
|
*/
|
|
|
public function edit($id)
|
|
|
{
|
|
|
@@ -884,8 +800,7 @@ class ProcessController extends Controller
|
|
|
$query->where('type','成品单');
|
|
|
}]);
|
|
|
if (count($process->processesContents) == 0)return ['success'=>false,'data'=>'没有成本单不得验收!'];
|
|
|
- $result=$this->statistic($process, true);
|
|
|
- //if (!$result['success'])return $result;
|
|
|
+ $this->statistic($process, true);
|
|
|
$process->update([
|
|
|
'status'=>'待交接'
|
|
|
]);
|
|
|
@@ -1001,9 +916,7 @@ class ProcessController extends Controller
|
|
|
$query->with("process");
|
|
|
}])->find($id);
|
|
|
if ($pro->delete()) {
|
|
|
-
|
|
|
- event(new ResetProcessStatisticStartDateEvent($pro->processDaily->process));
|
|
|
-
|
|
|
+ //event(new ResetProcessStatisticStartDateEvent($pro->processDaily->process));
|
|
|
return ['success'=>true];
|
|
|
}
|
|
|
return ['success'=>false , 'data'=>'记录不存在!'];
|