| } | } | ||||
| function createWorkID($limit){ | function createWorkID($limit){ | ||||
| $number = WorkOrder::select('id','wo')->orderBy('wo','DESC')->first(); | |||||
| $numberOnly = str_replace('WO-','',$number->wo); | |||||
| $numberOnly++; | |||||
| return $numberOnly; | |||||
| $allowedNumbers = range(0, 9); | $allowedNumbers = range(0, 9); | ||||
| shuffle($allowedNumbers); | shuffle($allowedNumbers); | ||||
| $digits = array_rand($allowedNumbers, $limit); | $digits = array_rand($allowedNumbers, $limit); | ||||
| $q->where('building_name', $building)->get(); | $q->where('building_name', $building)->get(); | ||||
| }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get(); | }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get(); | ||||
| } | } | ||||
| if(!empty($form)){ | if(!empty($form)){ | ||||
| foreach ($form as $key => $f) { | foreach ($form as $key => $f) { | ||||
| if(empty($f->WorkOrder)){ | if(empty($f->WorkOrder)){ | ||||
| }else{ | }else{ | ||||
| $labelD = ""; | $labelD = ""; | ||||
| } | } | ||||
| if(!empty($f->Subscriber)){ | if(!empty($f->Subscriber)){ | ||||
| if($f->Subscriber->street != ''){ | if($f->Subscriber->street != ''){ | ||||
| $street = $f->Subscriber->street; | $street = $f->Subscriber->street; | ||||
| $wo = ''; | $wo = ''; | ||||
| if($f->status_email == 'verified'){ | if($f->status_email == 'verified'){ | ||||
| $work_order = ''; | $work_order = ''; | ||||
| if($f->type_application == 'R'){ | if($f->type_application == 'R'){ | ||||
| do { | do { | ||||
| $work_order = 'WO-'.$this->createWorkID(4); | $work_order = 'WO-'.$this->createWorkID(4); | ||||
| } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder); | } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder); | ||||
| $wo = $work_order.'/'.$f->Subscriber->subscriber_id; | $wo = $work_order.'/'.$f->Subscriber->subscriber_id; | ||||
| } | } | ||||
| }else if($f->type_application == 'B'){ | }else if($f->type_application == 'B'){ | ||||
| do { | do { | ||||
| $work_order = 'WO-'.$this->createWorkID(4); | $work_order = 'WO-'.$this->createWorkID(4); | ||||
| } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder); | } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder); | ||||
| $wo = $work_order.'/'.$f->Subscriber->subscriber_id; | $wo = $work_order.'/'.$f->Subscriber->subscriber_id; | ||||
| $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','B')->first(); | $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','B')->first(); | ||||
| if(!empty($cov)){ | if(!empty($cov)){ | ||||
| }else if($f->PackageDetail->voice_fee == ''){ | }else if($f->PackageDetail->voice_fee == ''){ | ||||
| $nP = '-'; | $nP = '-'; | ||||
| } | } | ||||
| array_push($nested_data, array( | array_push($nested_data, array( | ||||
| 'formT' => $n1.$i.$f->type_application, | 'formT' => $n1.$i.$f->type_application, | ||||
| 'type' => $f->type_service, | 'type' => $f->type_service, |