Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DocketController.php 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. if(empty($form->customer_category)){
  83. $category = '';
  84. }else{
  85. $category = $form->customer_category;
  86. }
  87. $n1 = '';
  88. $reg_time = $d->created_at;
  89. $expiry_date = $reg_time->addDays(3);
  90. $expiry_date = $expiry_date->getTimestamp();
  91. if($curr < $expiry_date) {
  92. $n1 = "New/";
  93. }
  94. array_push($tempD, array(
  95. 'index' => $n1.$i,
  96. 'docket_id' => $d->docket_id,
  97. 'work_order_id' => $d->work_order_id,
  98. 'nature_work' => $d->nature_work,
  99. 'category' => $category,
  100. 'contractor_id' => $company->name,
  101. 'installer_name' => $installer->StaffDetail->name,
  102. 'customer_id' => $building,
  103. 'installer_id' => $installer->StaffDetail->phone,
  104. 'end_job' => date('d/m/Y H:i', strtotime($d->end_job)),
  105. 'rating' => round((($d->Rating1 + $d->Rating2 + $d->Rating3)/15) * 100)."%",
  106. 'action' => $d->docket_id.'/'.$d->work_order_id
  107. ));
  108. }
  109. }
  110. }
  111. foreach($tempD as $t){
  112. array_push($nested_data, array(
  113. 'index' => $t['index'],
  114. 'docket_id' => $t['docket_id'],
  115. 'work_order_id' => $t['work_order_id'],
  116. 'nature_work' => $t['nature_work'],
  117. 'category' => $t['category'],
  118. 'contractor_id' => $t['contractor_id'],
  119. 'installer_name' => $t['installer_name'],
  120. 'customer_id' => $t['customer_id'],
  121. 'installer_id' => $t['installer_id'],
  122. 'end_job' => $t['end_job'],
  123. 'rating' =>$t['rating'],
  124. 'action' =>$t['action'],
  125. ));
  126. }
  127. return \DataTables::of($nested_data)->make(true);
  128. }
  129. public function generateDocketPDF($do)
  130. {
  131. $id = Auth::guard('cs')->id();
  132. $user = Staff::with('StaffDetail')->find($id);
  133. $docket = Docket::with('WorkOrder')->where('docket_id',$do)->first();
  134. if(!empty($docket)){
  135. $form = Form::with('Subscriber','PackageDetail')->where('_id',$docket->WorkOrder->_id)->first();
  136. $address = '';
  137. if($form->type_application == 'R'){
  138. if($form->Subscriber->street != ''){
  139. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  140. }else {
  141. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  142. }
  143. }else if($form->type_application == 'B'){
  144. if($form->Subscriber->unit_no != ''){
  145. $address = $form->Subscriber->unit_no. ', '.$form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  146. }else {
  147. $address = $form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  148. }
  149. }
  150. if (empty($form->customer_category)){
  151. $category = '';
  152. }else {
  153. $category = $form->customer_category;
  154. }
  155. $product = Product::where('formT',$form->type_application)->where('speed',$form->PackageDetail->name)->first();
  156. $installer = Staff::with('StaffDetail')->where('_id',$docket->installer_id)->withTrashed()->first();
  157. if(empty($product)){
  158. $product = 'RMbps';
  159. }else {
  160. $product = $product->package_name;
  161. }
  162. $dateTime = Carbon::parse($docket->WorkOrder->dateTimeStart)->toDateTimeString();
  163. $edateTime = Carbon::parse($docket->end_job)->toDateTimeString();
  164. $pdf = PDF::loadView('pdf.docket-pdf',compact('docket','form','address','product','installer','dateTime','edateTime', 'category'));
  165. $pdf->setPaper('A4', 'potrait');
  166. return $pdf->stream();
  167. }
  168. }
  169. public function resetDocket(Request $request)
  170. {
  171. $docket = Docket::where('docket_id', $request->id)->first();
  172. if (!empty($docket)) {
  173. $docket->condition = '';
  174. $docket->save();
  175. return 'true';
  176. } else {
  177. return 'false';
  178. }
  179. }
  180. }