id)->first(); if(!empty($doc)){ $wo = WorkOrder::where('docket_id',$request->id)->first(); if(!empty($wo)){ if($wo->status == "Completed"){ $form = Form::with('PackageDetail','Subscriber')->where('_id',$wo->_id)->first(); if(!empty($form->Subscriber) && !empty($form->PackageDetail)){ $product = Product::where('formT',$form->type_application)->where('speed',$form->PackageDetail->name)->first(); if(!empty($product)){ return $this->sendResponse($form, '/v3/main/docket-pdf/'.$request->id); }else{ return $this->sendError('Product not exist!', ''); } }else{ return $this->sendError('Package or subscriber not exist!', ''); } } }else{ return $this->sendError('Work Order not exist!', ''); } }else{ return $this->sendError('Docket not exist!', ''); } } /** * Get Docket data * * @return json */ public function getCustomerDocket($startdate,$enddate,$company_id) { if($company_id == 'null'){ if($startdate == '-' && $enddate == '-'){ $docket= Docket::with(['WorkOrder' =>function($q){ $q->with(['Form' => function($w) { $w->with('Subscriber','PackageDetail'); }])->with('Company'); }])->with(['Staff' => function($e) { $e->with('StaffDetail'); }])->orderBy('created_at', 'desc')->get(); }else if($startdate != '-'){ $dateS = Carbon::createFromFormat('Y-m-d', $startdate); $start = $dateS->copy()->startOfDay(); if($enddate != '-'){ $dateE = Carbon::createFromFormat('Y-m-d', $enddate); $end = $dateE->copy()->endOfDay(); }else{ $end = $dateS->copy()->endOfDay(); } $docket = Docket::with(['WorkOrder' =>function($q){ $q->with(['Form' => function($w) { $w->with('Subscriber','PackageDetail'); }])->with('Company'); }])->with(['Staff' => function($e) { $e->with('StaffDetail'); }])->orderBy('created_at', 'desc')->whereBetween('created_at', array($start, $end))->get(); } }else{ if($startdate == '-' && $enddate == '-'){ $docket= Docket::with(['WorkOrder' => function($q) use($company_id){ $q->where('contractor_id', $company_id)->with(['Form' => function($w) { $w->with('Subscriber','PackageDetail'); }])->with('Company'); }])->with(['Staff' => function($e) { $e->with('StaffDetail'); }])->orderBy('created_at', 'desc')->get(); }else if($startdate != '-'){ $dateS = Carbon::createFromFormat('Y-m-d', $startdate); $start = $dateS->copy()->startOfDay(); if($enddate != '-'){ $dateE = Carbon::createFromFormat('Y-m-d', $enddate); $end = $dateE->copy()->endOfDay(); }else{ $end = $dateS->copy()->endOfDay(); } $docket = Docket::with(['WorkOrder' => function($q) use($company_id){ $q->where('contractor_id', $company_id)->with(['Form' => function($w) { $w->with('Subscriber','PackageDetail'); }])->with('Company'); }])->with(['Staff' => function($e) { $e->with('StaffDetail'); }])->orderBy('created_at', 'desc')->whereBetween('created_at', array($start, $end))->get(); } } return $docket; } public function displayDocketData($startdate,$enddate,$company_id){ $i = 0; $company = ''; $installer = ''; $phone = ''; $curr = Carbon::now()->getTimestamp(); $nested_data = array(); $docket = $this->getCustomerDocket($startdate, $enddate, $company_id); if(!empty($docket)){ foreach($docket as $d){ if(!empty($d->WorkOrder) && !empty($d->WorkOrder->Form) && !empty($d->Staff) && !empty($d->WorkOrder->Company)){ $reg_time = $d->created_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "New/"; } $phone = $d->Staff->StaffDetail->phone; $installer = $d->Staff->StaffDetail->name; $company = $d->WorkOrder->Company->name; if($d->WorkOrder->Form->type_application == 'R'){ $building = $d->WorkOrder->Form->Subscriber->building_name; }else if($d->WorkOrder->Form->type_application == 'B'){ $building = $d->WorkOrder->Form->Subscriber->company_name; } $i++; array_push($nested_data, array( 'index' => $n1.$i, 'docket_id' => $d->docket_id, 'work_order_id' => $d->work_order_id, 'nature_work' => $d->nature_work, 'contractor_id' => $company, 'installer_name' => $installer, 'customer_id' => $building, 'installer_num' => $phone, 'end_job' => date('d/m/Y H:i', strtotime($d->end_job)), 'serial_number' => $d->router_serial_number, 'rating' => round((($d->Rating1 + $d->Rating2 + $d->Rating3)/15) * 100)."%/".$d->WorkOrder->contractor_id, 'action' => $d->docket_id.'/'.$d->work_order_id )); } } } return \DataTables::of($nested_data)->make(true); } }