work_order = $work_order; $this->staff = $staff; $this->customer = $customer; $this->company = $company; } /** * Build the message. * * @return $this */ public function build() { $wo = WorkOrder::where('wo',$this->work_order->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 $this->from('no-reply@allo.my','no-reply@allo.my')->subject('You Have New Work Order')->view('email.assign_wo') ->attachData($pdf->output(), $wo->wo.'.pdf', ['mime' => 'application/pdf',]); } }