You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AssignWorkOrder.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace App\Mail;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Mail\Mailable;
  5. use Illuminate\Queue\SerializesModels;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use App\Model\WorkOrder;
  8. use App\Staff;
  9. use App\Model\StaffDetail;
  10. use App\Model\Product;
  11. use App\Model\Subscriber;
  12. use App\Model\Company;
  13. use App\Model\Form;
  14. use App\Model\PackageDetail;
  15. use Carbon\Carbon;
  16. use PDF;
  17. class AssignWorkOrder extends Mailable
  18. {
  19. use Queueable, SerializesModels;
  20. public $work_order,$staff,$customer,$company;
  21. /**
  22. * Create a new message instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct(WorkOrder $work_order,StaffDetail $staff,Subscriber $customer,Company $company)
  27. {
  28. //
  29. $this->work_order = $work_order;
  30. $this->staff = $staff;
  31. $this->customer = $customer;
  32. $this->company = $company;
  33. }
  34. /**
  35. * Build the message.
  36. *
  37. * @return $this
  38. */
  39. public function build()
  40. {
  41. $wo = WorkOrder::where('wo',$this->work_order->wo)->first();
  42. $form = Form::with('PackageDetail','Subscriber')->where('_id',$wo->_id)->first();
  43. $product = Product::where('formT',$form->type_application)->where('speed',$form->PackageDetail->name)->first();
  44. if(empty($form->customer_category)){
  45. $category = '';
  46. }else {
  47. $category = $form->customer_category;
  48. }
  49. if(empty($product)){
  50. if($form->PackageDetail->name == "30"){
  51. $product = '30Mbps';
  52. }else{
  53. $product = 'RMbps';
  54. }
  55. }else {
  56. $product = $product->package_name;
  57. }
  58. $created_by = Staff::with('StaffDetail')->where("_id",$wo->created_by)->first();
  59. if(empty($created_by)){
  60. $created_by = '';
  61. }
  62. $created_at = Carbon::parse($wo->created_at)->toDateTimeString();
  63. $address = '';
  64. if($form->type_application == 'R'){
  65. if($form->Subscriber->street != ''){
  66. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  67. }else {
  68. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  69. }
  70. }else if($form->type_application == 'B'){
  71. if ($form->Subscriber->unit_no != '') {
  72. $unit = $form->Subscriber->unit_no;
  73. } else {
  74. $unit = ' ';
  75. }
  76. if ($form->Subscriber->building_name == null) {
  77. $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  78. } else {
  79. $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  80. }
  81. }
  82. $pdf = PDF::loadView('pdf.workorder-pdf',compact('wo','form','product','created_at','created_by','address', 'category'));
  83. $pdf->setPaper('A4', 'potrait');
  84. return $this->from('no-reply@allo.my','no-reply@allo.my')->subject('You Have New Work Order')->view('email.assign_wo')
  85. ->attachData($pdf->output(), $wo->wo.'.pdf', ['mime' => 'application/pdf',]);
  86. }
  87. }