123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786 |
- <?php
-
- namespace App\Http\Controllers\Contractor;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
-
- use Carbon\Carbon;
- use Validator;
- use PDF;
-
- use App\Staff;
- use App\Model\StaffDetail;
- use App\Model\Form;
- use App\Model\Subscriber;
- use App\Model\WorkOrder;
- use App\Model\PackageDetail;
- use App\Model\Company;
- use App\Model\Coverage;
- use App\Model\Product;
- use App\Model\Docket;
- use App\Model\FormStatus;
-
- class WorkOrderController extends Controller
- {
-
- function random_code($limit) {
- return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
- }
-
- // function createWorkID($limit){
- // $number = WorkOrder::select('id','wo')->orderBy('created_at','DESC')->first();
- // $numberOnly = str_replace('WO-','',$number->wo);
- // $numberOnly++;
- // return $numberOnly;
-
- // $allowedNumbers = range(0, 9);
- // shuffle($allowedNumbers);
- // $digits = array_rand($allowedNumbers, $limit);
- // $number = '';
-
- // foreach($digits as $d){
- // $number .= $allowedNumbers[$d];
- // }
- // $unique_id = $number;
- // return $unique_id;
- // }
-
- public function viewContractorWork()
- {
- $id = Auth::guard('contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $pp = count(WorkOrder::where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $sp = count(WorkOrder::where('status','Success Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $rs = count(WorkOrder::where('status','Reschedule')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $ss = count(WorkOrder::where('status','Suspend')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $cm = count(WorkOrder::where('status','Completed')->where('contractor_id',$user->StaffDetail->company_id)->get());
-
- $pc = count(WorkOrder::where('status','Pending Contractor')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $pi = count(WorkOrder::where('status','Pending Installer')->where('contractor_id',$user->StaffDetail->company_id)->get());
-
- return view('contractor.view_wo', compact('user','pp','sp','rs','ss','cm','pc','pi'));
- }
-
- public function editContractorWork($wo)
- {
- $id = Auth::guard('contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $pp = count(WorkOrder::where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $sp = count(WorkOrder::where('status','Success Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $rs = count(WorkOrder::where('status','Reschedule')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $ss = count(WorkOrder::where('status','Suspend')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $cm = count(WorkOrder::where('status','Completed')->where('contractor_id',$user->StaffDetail->company_id)->get());
-
- $w = WorkOrder::where('wo',$wo)->first();
- $form = Form::with('Subscriber','WorkOrder')->where('_id',$w->_id)->first();
- $coverage = Coverage::groupBy('building_name')->orderBy('building_name')->get();
-
- $installer = Staff::with('StaffDetail')->where('_id',$w->installer_id)->first();
- if(empty($installer)){
- $installer = '';
- }else {
- $installer = $installer->StaffDetail->name;
- }
-
- $company = Company::where('_id',$w->contractor_id)->first();
-
- return view('contractor.edit_wo', compact('user','pp','sp','rs','ss','cm','pc','pi','form','coverage','installer','company'));
- }
-
- public function updateCustomerDetail(Request $request){
- $form = Subscriber::with('Form')->where('subscriber_id',$request->subscriber_id)->first();
-
- $phone = ''; $street = ''; $fax = '';
- if($request->phone2 != null){
- $phone = $request->phone2;
- }
-
- if($form->Form->type_application == 'R'){
-
- if($request->street != null){
- $street = $request->street;
- }
-
- $cov = Coverage::where('building_name',$request->building)->first();
-
- $form->name = $request->name;
- $form->ic = $request->ic;
- $form->email = $request->email;
- $form->phone1 = $request->phone1;
- $form->phone2 = $phone;
- $form->unit_no = $request->unit_no;
- $form->building_name = $cov->building_name;
- $form->street = $street;
- $form->city = $cov->city;
- $form->postcode = $cov->postcode;
- $form->state = $cov->state;
- $form->save();
-
- return redirect()->back()->with('success_msg', 'Success! Update customer '.$request->get('name'));
-
- }else if($form->Form->type_application == 'B'){
-
- if($request->company_fax != null){
- $fax = $request->company_fax;
- }
-
- $form->company_reg = $request->company_reg;
- $form->company_num = $request->company_num;
- $form->company_fax = $fax;
- $form->company_name = $request->company_name;
- $form->unit_no = $request->unit_no;
- $form->street = $request->address;
- $form->city = $request->city;
- $form->postcode = $request->postcode;
- $form->state = $request->state;
-
- $form->name = $request->name;
- $form->ic = $request->ic;
- $form->designation = $request->designation;
- $form->email = $request->email;
- $form->phone1 = $request->phone1;
- $form->phone2 = $phone;
- $form->save();
-
- return redirect()->back()->with('success_msg', 'Success! Update customer '.$request->get('name'));
- }
- }
-
-
- public function viewRescheduleCalendar($wo){
-
- $id = Auth::guard('contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $pp = count(WorkOrder::where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $sp = count(WorkOrder::where('status','Success Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $rs = count(WorkOrder::where('status','Reschedule')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $ss = count(WorkOrder::where('status','Suspend')->where('contractor_id',$user->StaffDetail->company_id)->get());
- $cm = count(WorkOrder::where('status','Completed')->where('contractor_id',$user->StaffDetail->company_id)->get());
-
- $installer = StaffDetail::where('company_id',$user->StaffDetail->company_id)->where('position','Installer')->get();
- $today = Carbon::today();
-
- return view('contractor.reschedule_work_order', compact('user','pp','sp','rs','ss','cm','company','wo','today','installer'));
- }
-
- public function getAllPendingContractor($year,$month,$day){
-
- $id = Auth::guard('contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0; $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if($month == 'null' && $day == 'null'){
- $wo = WorkOrder::with('Form')->where('status','Pending Contractor')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->get();
- }else if($year != 'null' && $month == 'null' && $day == 'null'){
-
- $timestamp = $year."-01-01 00:00:00.000Z";
- $masa = strtotime($timestamp);
- $go = Carbon::createFromTimestamp($masa);
- $go2 = Carbon::createFromTimestamp($masa);
- $end_year = $go2->endOfYear();
-
- $wo = WorkOrder::with('Form')->where('status','Pending Contractor')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
-
- }else if($year != 'null' && $month != 'null' && $day == 'null'){
-
- $timestamp = $year."-".$month."-01 00:00:00.000Z";
- $masa = strtotime($timestamp);
- $go = Carbon::createFromTimestamp($masa);
- $go2 = Carbon::createFromTimestamp($masa);
- $end_year = $go2->endOfMonth();
-
- $wo = WorkOrder::with('Form')->where('status','Pending Contractor')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
- }
-
- if(!empty($wo)){
- foreach ($wo as $key => $w) {
- $i++;
-
- $n1 = '';
- $reg_time = $w->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $installer = '';
- $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->Form->_id)->first();
- $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$w->Form->type_application)->first();
- $company = Company::where('_id',$w->contractor_id)->first();
-
- $building = ''; $unit = '-'; $name = '';
- if($form->type_application == 'R'){
- $building = $form->Subscriber->building_name;
- $unit = $form->Subscriber->unit_no;
- $name = $form->Subscriber->name;
-
- }else if($form->type_application == 'B'){
-
- if($form->Subscriber->unit_no != ''){
- $unit = '-';
- }else {
- $unit = $form->Subscriber->unit_no;
- }
-
- $building = '-';
- $name = $form->Subscriber->company_name;
-
- }
-
- if($w->installer_id != ''){
- $installer = Staff::with('StaffDetail')->where('_id',$w->installer_id)->first();
- $installer = $installer->StaffDetail->name;
- }
-
- if(empty($product)){
- $product = 'R Mbps';
- }else {
- $product = $product->package_name;
- }
-
- array_push($nested_data, array(
- 'formT' => $n1.$i.$w->Form->type_application,
- 'service' => $w->nature_work,
- 'wo' => $w->wo,
- 'name' => $name,
- 'phone' => $form->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'city' => $form->Subscriber->city,
- 'package' => $product,
- 'contractor' => $company->name,
- 'installer' => $installer,
- 'date' => date("d/m/Y", strtotime($w->dateTimeStart)),
- 'time' => date("h:i A", strtotime($w->dateTimeStart)),
- 'status' => $w->status,
- 'action' => $w->wo,
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getAllPendingNonPrelaid($year,$month,$day){
-
- $id = Auth::guard('contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0; $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if($year == 'null' && $month == 'null' && $day == 'null'){
- $wo = WorkOrder::with('Form')->where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->get();
- }else if($year != 'null' && $month == 'null' && $day == 'null'){
-
- $timestamp = $year."-01-01 00:00:00.000Z";
- $masa = strtotime($timestamp);
- $go = Carbon::createFromTimestamp($masa);
- $go2 = Carbon::createFromTimestamp($masa);
- $end_year = $go2->endOfYear();
-
- $wo = WorkOrder::with('Form')->where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
-
- }else if($year != 'null' && $month != 'null' && $day == 'null'){
-
- $timestamp = $year."-".$month."-01 00:00:00.000Z";
- $masa = strtotime($timestamp);
- $go = Carbon::createFromTimestamp($masa);
- $go2 = Carbon::createFromTimestamp($masa);
- $end_year = $go2->endOfMonth();
-
- $wo = WorkOrder::with('Form')->where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
- }
-
- if(!empty($wo)){
- foreach ($wo as $key => $w) {
- $i++;
-
- $n1 = '';
- $reg_time = $w->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $installer = '';
- $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->Form->_id)->first();
- $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$w->Form->type_application)->first();
- $company = Company::where('_id',$w->contractor_id)->first();
-
- if($w->installer_id != ''){
- $installer = Staff::with('StaffDetail')->where('_id',$w->installer_id)->first();
- if(!empty($installer)){
- $installer = $installer->StaffDetail->name;
- }
- }
-
- $building = ''; $unit = '-'; $name = '';
- if($form->type_application == 'R'){
- $building = $form->Subscriber->building_name;
- $unit = $form->Subscriber->unit_no;
- $name = $form->Subscriber->name;
-
- }else if($form->type_application == 'B'){
-
- if($form->Subscriber->unit_no != ''){
- $unit = '-';
- }else {
- $unit = $form->Subscriber->unit_no;
- }
-
- $building = '-';
- $name = $form->Subscriber->company_name;
-
- }
-
- if(empty($product)){
- $product = 'R Mbps';
- }else {
- $product = $product->package_name;
- }
-
- $date = ''; $time = '';
- if($w->dateTimeStart == ''){
- $date = '';
- $time = '';
- }else {
- $date = date("d/m/Y", strtotime($w->dateTimeStart));
- $time = date("h:i A", strtotime($w->dateTimeStart));
- }
-
- array_push($nested_data, array(
- 'formT' => $n1.$i.$w->Form->type_application,
- 'service' => $w->nature_work,
- 'wo' => $w->wo,
- 'name' => $name,
- 'phone' => $form->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'city' => $form->Subscriber->city,
- 'package' => $product,
- 'contractor' => $company->name,
- 'installer' => $installer,
- 'date' => $date,
- 'time' => $time,
- 'status' => $w->status,
- 'action' => $w->wo,
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getAllPendingInstaller($year,$month,$day){
-
- $id = Auth::guard('contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0; $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if($year == 'null' && $month == 'null' && $day == 'null'){
- $wo = WorkOrder::with('Form')->where('status','Pending Installer')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->get();
- }else if($year != 'null' && $month == 'null' && $day == 'null'){
-
- $timestamp = $year."-01-01 00:00:00.000Z";
- $masa = strtotime($timestamp);
- $go = Carbon::createFromTimestamp($masa);
- $go2 = Carbon::createFromTimestamp($masa);
- $end_year = $go2->endOfYear();
-
- $wo = WorkOrder::with('Form')->where('status','Pending Installer')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
-
- }else if($year != 'null' && $month != 'null' && $day == 'null'){
-
- $timestamp = $year."-".$month."-01 00:00:00.000Z";
- $masa = strtotime($timestamp);
- $go = Carbon::createFromTimestamp($masa);
- $go2 = Carbon::createFromTimestamp($masa);
- $end_year = $go2->endOfMonth();
-
- $wo = WorkOrder::with('Form')->where('status','Pending Installer')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
- }
-
- if(!empty($wo)){
- foreach ($wo as $key => $w) {
- $i++;
-
- $n1 = '';
- $reg_time = $w->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $installer = '';
- $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->Form->_id)->first();
- $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$w->Form->type_application)->first();
- $company = Company::where('_id',$w->contractor_id)->first();
-
- if($w->installer_id != ''){
- $installer = Staff::with('StaffDetail')->where('_id',$w->installer_id)->first();
- if(!empty($installer)){
- $installer = $installer->StaffDetail->name;
- }
- }
-
- $building = ''; $unit = '-'; $name = '';
- if($form->type_application == 'R'){
- $building = $form->Subscriber->building_name;
- $unit = $form->Subscriber->unit_no;
- $name = $form->Subscriber->name;
-
- }else if($form->type_application == 'B'){
-
- if($form->Subscriber->unit_no != ''){
- $unit = '-';
- }else {
- $unit = $form->Subscriber->unit_no;
- }
-
- $building = '-';
- $name = $form->Subscriber->company_name;
- }
-
- if(empty($product)){
- $product = 'R Mbps';
- }else {
- $product = $product->package_name;
- }
-
- array_push($nested_data, array(
- 'formT' => $n1.$i.$w->Form->type_application,
- 'service' => $w->nature_work,
- 'wo' => $w->wo,
- 'name' => $name,
- 'phone' => $form->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'city' => $form->Subscriber->city,
- 'package' => $product,
- 'contractor' => $company->name,
- 'installer' => $installer,
- 'date' => date("d/m/Y", strtotime($w->dateTimeStart)),
- 'time' => date("h:i A", strtotime($w->dateTimeStart)),
- 'status' => $w->status,
- 'action' => $w->wo,
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getAllCompleted($year,$month,$day){
-
- $id = Auth::guard('contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $i = 0; $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if($year == 'null' && $month == 'null' && $day == 'null'){
- $doc = Docket::with('WorkOrder')->orderBy('updated_at', 'desc')->get();
- }else if($year != 'null' && $month == 'null' && $day == 'null'){
-
- $timestamp = $year."-01-01 00:00:00.000Z";
- $masa = strtotime($timestamp);
- $go = Carbon::createFromTimestamp($masa);
- $go2 = Carbon::createFromTimestamp($masa);
- $end_year = $go2->endOfYear();
-
- $doc = Docket::with('WorkOrder')->orderBy('updated_at', 'desc')->whereBetween('dateTimeStart', [$go, $end_year])->get();
-
- }else if($year != 'null' && $month != 'null' && $day == 'null'){
-
- $timestamp = $year."-".$month."-01 00:00:00.000Z";
- $masa = strtotime($timestamp);
- $go = Carbon::createFromTimestamp($masa);
- $go2 = Carbon::createFromTimestamp($masa);
- $end_year = $go2->endOfMonth();
-
- $doc = Docket::with('WorkOrder')->orderBy('updated_at', 'desc')->whereBetween('dateTimeStart', [$go, $end_year])->get();
- }
-
- if(!empty($doc)){
- foreach ($doc as $key => $w) {
- $i++;
-
- $n1 = '';
- if(!empty($w->updated_at)) {
- $reg_time = $w->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
- }else {
- $n1 = '';
- }
-
- $installer = '';
- if(!empty($w->WorkOrder->_id)){
- $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->WorkOrder->_id)->first();
- $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$form->type_application)->first();
- $company = Company::where('_id',$w->WorkOrder->contractor_id)->first();
-
- if($w->WorkOrder->installer_id != ''){
- $installer = Staff::with('StaffDetail')->withTrashed()->where('_id',$w->WorkOrder->installer_id)->first();
- $installer = $installer->StaffDetail->name;
- }
-
- if(empty($product)){
- $product = 'R Mbps';
- }else {
- $product = $product->package_name;
- }
-
- $building = ''; $unit = '-'; $name = '';
- if($form->type_application == 'R'){
- $building = $form->Subscriber->building_name;
- $unit = $form->Subscriber->unit_no;
- $name = $form->Subscriber->name;
-
- }else if($form->type_application == 'B'){
-
- if($form->Subscriber->unit_no != ''){
- $unit = '-';
- }else {
- $unit = $form->Subscriber->unit_no;
- }
-
- $building = '-';
- $name = $form->Subscriber->company_name;
- }
-
- if($w->WorkOrder->contractor_id == $user->StaffDetail->company_id){
- array_push($nested_data, array(
- 'formT' => $n1.$i.$form->type_application,
- 'service' => $w->nature_work,
- 'wo' => $w->WorkOrder->wo,
- 'name' => $name,
- 'phone' => $form->Subscriber->phone1,
- 'unit' => $unit,
- 'building' => $building,
- 'city' => $form->Subscriber->city,
- 'package' => $product,
- 'contractor' => $company->name,
- 'installer' => $installer,
- 'date' => date("d/m/Y", strtotime($w->end_job)),
- 'time' => date("h:i A", strtotime($w->end_job)),
- 'status' => $w->WorkOrder->status,
- 'docket' => $w->docket_id,
- 'action' => $w->WorkOrder->wo,
- ));
- }
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function generateWorkOrderPDF($wo){
-
- $id = Auth::guard('contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $wo = WorkOrder::where('wo',$wo)->first();
- $form = Form::with('PackageDetail','Subscriber')->where('_id',$wo->_id)->first();
- $product = Product::where('formT',$form->type_application)->where('speed',$form->PackageDetail->name)->first();
-
- if(empty($form->customer_category)){
- $category = '';
- }else {
- $category = $form->customer_category;
- }
-
- if(empty($product)){
- if($form->PackageDetail->name == "30"){
- $product = '30Mbps';
- }else{
- $product = 'RMbps';
- }
- }else {
- $product = $product->package_name;
- }
-
- $created_by = Staff::with('StaffDetail')->where("_id",$wo->created_by)->first();
- if(empty($created_by)){
- $created_by = '';
- }
-
- $created_at = Carbon::parse($wo->created_at)->toDateTimeString();
-
- $address = '';
- if($form->type_application == 'R'){
- if($form->Subscriber->street != ''){
- $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
- }else {
- $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
- }
-
- }else if($form->type_application == 'B'){
-
- if ($form->Subscriber->unit_no != '') {
- $unit = $form->Subscriber->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($form->Subscriber->building_name == null) {
- $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
- } else {
- $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
- }
-
- }
-
- $pdf = PDF::loadView('pdf.workorder-pdf',compact('wo','form','product','created_at','created_by','address', 'category'));
- $pdf->setPaper('A4', 'potrait');
- return $pdf->stream();
- }
-
- public function updateWorkOrder(Request $request){
-
- $id = Auth::guard('contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $wo = WorkOrder::where('wo',$request->work_order)->first();
- if(!empty($wo)){
- $wo->nature_work = $request->task;
- $wo->pppoe_username = $request->pppoe_username;
- $wo->onu = $request->onu_ont;
- $wo->router = $request->router;
- $wo->n_phone = $request->n_phone;
- $wo->no_phone = $request->no_phone;
- $wo->remarks_custservice = $request->remark;
- $wo->created_by = $user->_id;
- $wo->save();
-
- return redirect('/contractor/work-order/list');
- // return redirect()->back()->with('success_msg', 'Success! Update work order '.$request->get('work_order'));
- }else {
- return redirect()->back()->with('error_msg', 'Cant update work order '.$request->get('work_order'));
- }
- }
-
- public function rescheduleWorkOrder(Request $request){
-
- $wod = WorkOrder::where('wo',$request->wo)->first();
- if(!empty($wod)){
-
- $wod->dateTimeStart = $request->start;
- $wod->dateTimeEnd = $request->end;
- $wod->installer_id = $request->installer;
- $wod->status = $request->type_work;
- $wod->save();
-
- return 'success';
-
- }else{
- return 'false';
- }
- }
-
- public function cancelCreateWorkOrder(Request $request){
- $wod = WorkOrder::where('wo',$request->wo)->first();
- if(!empty($wod)){
- $wod->delete();
- return 'true';
- }else{
- return 'false';
- }
- }
-
- public function updateWorkOrderReschedule(Request $request)
- {
- $data = array();
- $wod = WorkOrder::where('wo',$request->wo)->first();
- $form = Form::where('_id',$wod->_id)->first();
- $installer = Staff::with('StaffDetail')->where('_id',$wod->installer_id)->withTrashed()->first();
- $name = '';
- if (!empty($installer)){
- $name = $installer->StaffDetail->name;
- }
-
- if(!empty($wod)){
-
- if($wod->status == 'Pending Contractor'){
-
- $wod->status = $request->type_work;
- $wod->installer_id = $request->installer;
- $wod->save();
-
- $formH = new FormStatus;
- $formH->form_id = $form->_id;
- $formH->status_id = 6;
- $formH->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
- $formH->status = 'Pending Installer';
- $formH->desc = 'This work order been assigned to particular installer ('.$name.')';
- $form->formstatus()->save($formH);
-
- array_push($data, array(
- 'result' => 'yes',
- ));
-
- }else {
-
- $wod->status = $request->type_work;
- $wod->installer_id = $request->installer;
- $wod->save();
-
- array_push($data, array(
- 'result' => 'yes',
- ));
- }
-
- }else{
- array_push($data, array(
- 'result' => 'no',
- ));
- }
-
- return response()->json($data);
- }
-
- public function updateStatusWorkOrder($wo){
-
- $wod = WorkOrder::where('wo',$wo)->first();
- if(!empty($wod)){
- $wod->status = 'Success Non Prelaid';
- $wod->save();
-
- $form = Form::where('_id',$wod->_id)->first();
- $formH = new FormStatus;
- $formH->form_id = $form->_id;
- $formH->status_id = 7;
- $formH->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
- $formH->status = 'Success Prelaid';
- $formH->desc = 'Prelaid successfully';
- $form->formstatus()->save($formH);
-
- return redirect('/contractor/work-order/list');
- }
- }
- }
|