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.

DocketController.php 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace App\Http\Controllers\CustomerService;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use LynX39\LaraPdfMerger\Facades\PdfMerger;
  7. use Carbon\Carbon;
  8. use Validator;
  9. use PDF;
  10. use App\Staff;
  11. use App\Model\StaffDetail;
  12. use App\Model\Form;
  13. use App\Model\Subscriber;
  14. use App\Model\WorkOrder;
  15. use App\Model\PackageDetail;
  16. use App\Model\Company;
  17. use App\Model\Coverage;
  18. use App\Model\Product;
  19. use App\Model\Docket;
  20. class DocketController extends Controller
  21. {
  22. function random_code($limit) {
  23. return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
  24. }
  25. function createWorkID($limit){
  26. $allowedNumbers = range(0, 9);
  27. shuffle($allowedNumbers);
  28. $digits = array_rand($allowedNumbers, $limit);
  29. $number = '';
  30. foreach($digits as $d){
  31. $number .= $allowedNumbers[$d];
  32. }
  33. $unique_id = $number;
  34. return $unique_id;
  35. }
  36. public function viewDocket()
  37. {
  38. $id = Auth::guard('cs')->id();
  39. $user = Staff::with('StaffDetail')->find($id);
  40. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->get());
  41. $sp = count(WorkOrder::where('status','Success Non Prelaid')->get());
  42. $rs = count(WorkOrder::where('status','Reschedule')->get());
  43. $ss = count(WorkOrder::where('status','Suspend')->get());
  44. $cm = count(WorkOrder::where('status','Completed')->get());
  45. return view('customer-service.view_docket',compact('user','pp','sp','rs','ss','cm'));
  46. }
  47. public function getCustomerDocket($year,$month,$day)
  48. {
  49. if($year == 'null' && $month == 'null' && $day == 'null'){
  50. $docket= Docket::with('WorkOrder')->orderBy('created_at', 'desc')->get();
  51. }else if($year != 'null' && $month == 'null' && $day == 'null'){
  52. $timestamp = $year."-01-01 00:00:00.000Z";
  53. $masa = strtotime($timestamp);
  54. $go = Carbon::createFromTimestamp($masa);
  55. $go2 = Carbon::createFromTimestamp($masa);
  56. $end_year = $go2->endOfYear();
  57. $docket = Docket::with('WorkOrder')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  58. }else if($year != 'null' && $month != 'null' && $day == 'null'){
  59. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  60. $masa = strtotime($timestamp);
  61. $go = Carbon::createFromTimestamp($masa);
  62. $go2 = Carbon::createFromTimestamp($masa);
  63. $end_year = $go2->endOfMonth();
  64. $docket = Docket::with('WorkOrder')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  65. }
  66. $i = 0; $n1 = ''; $building = '';
  67. $curr = Carbon::now()->getTimestamp();
  68. $tempD = array();
  69. $nested_data = array();
  70. if(!empty($docket)){
  71. foreach($docket as $d){
  72. $i++;
  73. if(!empty($d->WorkOrder->_id)){
  74. $form = Form::with('Subscriber','PackageDetail')->where('_id',$d->WorkOrder->_id)->first();
  75. $company = Company::where('_id', $d->WorkOrder->contractor_id)->first();
  76. $installer = Staff::with('StaffDetail')->withTrashed()->where('_id', $d->installer_id)->first();
  77. if($form->type_application == 'R'){
  78. $building = $form->Subscriber->building_name;
  79. }else if($form->type_application == 'B'){
  80. $building = $form->Subscriber->company_name;
  81. }
  82. $reg_time = $d->created_at;
  83. $expiry_date = $reg_time->addDays(3);
  84. $expiry_date = $expiry_date->getTimestamp();
  85. if($curr < $expiry_date) {
  86. $n1 = "New/";
  87. }
  88. array_push($tempD, array(
  89. 'index' => $n1.$i,
  90. 'docket_id' => $d->docket_id,
  91. 'work_order_id' => $d->work_order_id,
  92. 'nature_work' => $d->nature_work,
  93. 'contractor_id' => $company->name,
  94. 'installer_name' => $installer->StaffDetail->name,
  95. 'customer_id' => $building,
  96. 'installer_id' => $installer->StaffDetail->phone,
  97. 'end_job' => date('d/m/Y H:i', strtotime($d->end_job)),
  98. 'rating' => round((($d->Rating1 + $d->Rating2 + $d->Rating3)/15) * 100)."%",
  99. 'action' => $d->docket_id.'/'.$d->work_order_id
  100. ));
  101. }
  102. }
  103. }
  104. foreach($tempD as $t){
  105. array_push($nested_data, array(
  106. 'index' => $t['index'],
  107. 'docket_id' => $t['docket_id'],
  108. 'work_order_id' => $t['work_order_id'],
  109. 'nature_work' => $t['nature_work'],
  110. 'contractor_id' => $t['contractor_id'],
  111. 'installer_name' => $t['installer_name'],
  112. 'customer_id' => $t['customer_id'],
  113. 'installer_id' => $t['installer_id'],
  114. 'end_job' => $t['end_job'],
  115. 'rating' =>$t['rating'],
  116. 'action' =>$t['action'],
  117. ));
  118. }
  119. return \DataTables::of($nested_data)->make(true);
  120. }
  121. public function generateDocketPDF($do)
  122. {
  123. $id = Auth::guard('cs')->id();
  124. $user = Staff::with('StaffDetail')->find($id);
  125. $docket = Docket::with('WorkOrder')->where('docket_id',$do)->first();
  126. if(!empty($docket)){
  127. $form = Form::with('Subscriber','PackageDetail')->where('_id',$docket->WorkOrder->_id)->first();
  128. $address = '';
  129. if($form->type_application == 'R'){
  130. if($form->Subscriber->street != ''){
  131. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  132. }else {
  133. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  134. }
  135. }else if($form->type_application == 'B'){
  136. if($form->Subscriber->unit_no != ''){
  137. $address = $form->Subscriber->unit_no. ', '.$form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  138. }else {
  139. $address = $form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  140. }
  141. }
  142. $product = Product::where('formT',$form->type_application)->where('speed',$form->PackageDetail->name)->first();
  143. $installer = Staff::with('StaffDetail')->where('_id',$docket->installer_id)->withTrashed()->first();
  144. if(empty($product)){
  145. $product = 'RMbps';
  146. }else {
  147. $product = $product->package_name;
  148. }
  149. $dateTime = Carbon::parse($docket->WorkOrder->dateTimeStart)->toDateTimeString();
  150. $edateTime = Carbon::parse($docket->end_job)->toDateTimeString();
  151. $pdf = PDF::loadView('pdf.docket-pdf',compact('docket','form','address','product','installer','dateTime','edateTime'));
  152. $pdf->setPaper('A4', 'potrait');
  153. return $pdf->stream();
  154. }
  155. }
  156. }