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.7KB

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