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.

WorkOrderMobile.php 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. namespace App\Http\Controllers\API;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests\RegisterRequest;
  5. use App\Http\Controllers\Api\BaseController;
  6. use Illuminate\Support\Facades\Auth;
  7. Use App\Staff;
  8. Use App\Model\StaffDetail;
  9. use App\Model\Docket;
  10. use App\Model\WorkOrder;
  11. use App\Model\Company;
  12. Use App\Model\Form;
  13. Use App\Model\PackageDetail;
  14. Use App\Model\Subscriber;
  15. use App\Model\Question;
  16. Use Hash;
  17. use Carbon\Carbon;
  18. use Crypt;
  19. use File;
  20. use Mail;
  21. class WorkOrderMobile extends BaseController
  22. {
  23. function random_code($limit) {
  24. return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
  25. }
  26. /**
  27. /* Schedule Function
  28. **/
  29. public function getSchedule(Request $request)
  30. {
  31. $data = array();
  32. $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first();
  33. if(!empty($loginUser)) {
  34. $schedule = WorkOrder::where('installer_id',$loginUser->_id)->where('status','Pending Installer')->get();
  35. foreach($schedule as $b) {
  36. array_push($data,array(
  37. "Title" => $b->nature_work,
  38. "Date"=>date("m/d/Y", strtotime($b->dateTimeStart)),
  39. "Time"=>date("H:i", strtotime($b->dateTimeStart)),
  40. "DateTimeStart"=>$b->dateTimeStart,
  41. "DateTimeEnd"=>$b->dateTimeEnd,
  42. "status" => $b->status,
  43. ));
  44. }
  45. return $this->sendResponse($data, 'Get Schedule Successfully');
  46. }else {
  47. return $this->sendError('Invalid User', 'User Not Exist!');
  48. }
  49. }
  50. public function getWorkOrderDetail(Request $request){
  51. $data = array();
  52. $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first();
  53. if(!empty($loginUser)) {
  54. $wo = WorkOrder::where('installer_id',$loginUser->_id)->where('status','Pending Installer')->get();
  55. if(!empty($wo)){
  56. foreach($wo as $w){
  57. $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->_id)->first();
  58. $company = Company::where('_id',$w->contractor_id)->first();
  59. $address = '';
  60. if($form->type_application == 'R'){
  61. if($form->Subscriber->street != ''){
  62. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  63. }else {
  64. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  65. }
  66. }else if($form->type_application == 'B'){
  67. if($form->Subscriber->unit_no != ''){
  68. $address = $form->Subscriber->unit_no. ', '.$form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  69. }else {
  70. $address = $form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  71. }
  72. }
  73. $pp = ''; $noP = 'N/A'; $nP = '';
  74. if($w->no_phone != ''){
  75. $noP = $w->no_phone;
  76. }
  77. if($w->need_phone != ''){
  78. $nP = $w->need_phone;
  79. }
  80. array_push($data,array(
  81. "id" => $w->wo,
  82. "formT" => $form->type_application,
  83. "contractor_id" => $company->name,
  84. "installer_id" => $loginUser->StaffDetail->name,
  85. "title" => $w->nature_work,
  86. "address"=> $address,
  87. "imageUrl"=>'assets/activation_icon_nRead1.png',
  88. "appoint_date"=>date("m/d/Y", strtotime($w->dateTimeStart)),
  89. "appoint_time"=>date("H:i", strtotime($w->dateTimeStart)),
  90. "cus_name"=> $form->Subscriber->name,
  91. "contact_person" => $form->Subscriber->name,
  92. "contact_no"=> $form->Subscriber->phone1,
  93. "technical" => $form->Subscriber->name,
  94. "status" => $w->status,
  95. 'pppoe' => $w->pppoe_username,
  96. 'package' => $form->PackageDetail->name,
  97. 'onu' => $w->onu,
  98. 'router' => $w->router,
  99. 'no_phone' => $noP,
  100. 'n_phone' => $nP,
  101. "note" => $w->remarks_custservice,
  102. ));
  103. }
  104. return $this->sendResponse($data, 'Get Work Order Successfully');
  105. }else {
  106. return $this->sendResponse('', 'No Data');
  107. }
  108. }else {
  109. return $this->sendError('Invalid User', 'User Not Exist!');
  110. }
  111. }
  112. public function getDocketDetail(Request $request)
  113. {
  114. $data = array(); $installer = '';
  115. $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->where('roles_access','Installer')->first();
  116. if(!empty($loginUser)) {
  117. $docket = Docket::with('WorkOrder')->where('installer_id',$loginUser->_id)->where('docket_id', $request->docket_id)->first();
  118. if(!empty($docket)){
  119. $form = Form::with('PackageDetail','Subscriber')->where("_id",$docket->WorkOrder->_id)->first();
  120. if(!empty($form)){
  121. $company = Company::where('_id',$docket->WorkOrder->contractor_id)->first();
  122. $staff = Staff::with('StaffDetail')->where('_id',$docket->installer_id)->first();
  123. if(!empty($staff)){
  124. $installer = $staff->StaffDetail->name;
  125. }else{
  126. $installer = '';
  127. }
  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. $total =array($docket->Rating1, $docket->Rating2, $docket->Rating3);
  143. $total_rating = array_sum($total);
  144. $data = array(
  145. // "contractor_id" => $company->name,
  146. // "installer_id" => $installer,
  147. // "customer_id" => $customer_id,
  148. // "status" => $status,
  149. "cus_name"=> $form->Subscriber->name,
  150. "address"=> $address,
  151. "contact_no"=> $form->Subscriber->phone1,
  152. "technical" => $company->name,
  153. "installer_name" => $installer,
  154. "title" => $docket->nature_work,
  155. "docket_id" => $docket->docket_id,
  156. "wo_id" => $docket->work_order_id,
  157. "status" => $docket->WorkOrder->status,
  158. "start_datetime"=> $docket->WorkOrder->dateTimeStart,
  159. "end_datetime" => $docket->end_job,
  160. "cable_read" => $docket->cable_read,
  161. "router" => $docket->router_serial_number,
  162. "mac_router" => $docket->mac_router,
  163. "condition" => $docket->condition,
  164. "note" => $docket->Note,
  165. "total_rating" => $total_rating,
  166. );
  167. return $this->sendResponse($data, 'Successfull Get Docket Detail');
  168. }
  169. }
  170. }else {
  171. return $this->sendError('Invalid User', 'User Not Exist!');
  172. }
  173. }
  174. public function getDocket(Request $request)
  175. {
  176. $data = array();
  177. $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->where('roles_access','Installer')->first();
  178. if(!empty($loginUser)) {
  179. $docket = Docket::with('WorkOrder')->where('installer_id',$loginUser->_id)->get();
  180. $company = Company::where('_id',$loginUser->StaffDetail->company_id)->first();
  181. if(!empty($docket)){
  182. foreach($docket as $a) {
  183. $nw = '';
  184. if(!empty($a->WorkOrder->nature_work)){
  185. $nw = $a->WorkOrder->nature_work;
  186. }
  187. array_push($data,array(
  188. "docket_id" => $a->docket_id,
  189. "wo_id" => $a->work_order_id,
  190. "contractor_id" => $company,
  191. "installer_id" => $loginUser->StaffDetail->name,
  192. "title" => $nw,
  193. "imageUrl"=>'assets/activation_icon_nRead1.png',
  194. "end_date"=>date("m/d/Y", strtotime($a->end_job)),
  195. "end_time"=>date("H:i", strtotime($a->end_job)),
  196. "cable_read" => $a->cable_read
  197. ));
  198. }
  199. return $this->sendResponse($data, 'Successfull');
  200. }
  201. }else {
  202. return $this->sendError('Invalid User', 'User Not Exist!');
  203. }
  204. }
  205. public function updateWorkOrder(Request $request){
  206. $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->where('roles_access','Installer')->first();
  207. if(!empty($loginUser)) {
  208. $wo = WorkOrder::where('wo',$request->nid)->first();
  209. if(!empty($wo)){
  210. $wo->remarks_installer = $request->postres.". ".$request->note;
  211. $wo->status = $request->type;
  212. $wo->save();
  213. return $this->sendResponse('Success', 'Work Order '.$request->nid.' been update successfull');
  214. }else{
  215. return $this->sendError('Failed', 'Work Order Not Exist!');
  216. }
  217. }else {
  218. return $this->sendError('Invalid User', 'User Not Exist!');
  219. }
  220. }
  221. public function getQuestions(){
  222. $question = Question::all();
  223. if(!empty($question)) {
  224. return $this->sendResponse($question, 'Get all questions successfull');
  225. }else{
  226. return $this->sendError('', 'No Questions!');
  227. }
  228. }
  229. }