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.

WorkOrderMobile.php 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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->street. ' , '.$form->Subscriber->building_name. ' , '.$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. $unit = $form->Subscriber->unit_no;
  69. } else {
  70. $unit = ' ';
  71. }
  72. if ($form->Subscriber->building_name == null) {
  73. $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  74. } else {
  75. $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  76. }
  77. }
  78. $pp = ''; $noP = 'N/A'; $nP = '';
  79. if($w->no_phone != ''){
  80. $noP = $w->no_phone;
  81. }
  82. if($w->need_phone != ''){
  83. $nP = $w->need_phone;
  84. }
  85. array_push($data,array(
  86. "id" => $w->wo,
  87. "formT" => $form->type_application,
  88. "contractor_id" => $company->name,
  89. "installer_id" => $loginUser->StaffDetail->name,
  90. "title" => $w->nature_work,
  91. "address"=> $address,
  92. "imageUrl"=>'assets/activation_icon_nRead1.png',
  93. "appoint_date"=>date("m/d/Y", strtotime($w->dateTimeStart)),
  94. "appoint_time"=>date("H:i", strtotime($w->dateTimeStart)),
  95. "cus_name"=> $form->Subscriber->name,
  96. "contact_person" => $form->Subscriber->name,
  97. "contact_no"=> $form->Subscriber->phone1,
  98. "technical" => $form->Subscriber->name,
  99. "status" => $w->status,
  100. 'pppoe' => $w->pppoe_username,
  101. 'package' => $form->PackageDetail->name,
  102. 'onu' => $w->onu,
  103. 'router' => $w->router,
  104. 'no_phone' => $noP,
  105. 'n_phone' => $nP,
  106. "note" => $w->remarks_custservice,
  107. ));
  108. }
  109. return $this->sendResponse($data, 'Get Work Order Successfully');
  110. }else {
  111. return $this->sendResponse('', 'No Data');
  112. }
  113. }else {
  114. return $this->sendError('Invalid User', 'User Not Exist!');
  115. }
  116. }
  117. public function getDocketDetail(Request $request)
  118. {
  119. $data = array(); $installer = '';
  120. $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->where('roles_access','Installer')->first();
  121. if(!empty($loginUser)) {
  122. $docket = Docket::with('WorkOrder')->where('installer_id',$loginUser->_id)->where('docket_id', $request->docket_id)->first();
  123. if(!empty($docket)){
  124. $form = Form::with('PackageDetail','Subscriber')->where("_id",$docket->WorkOrder->_id)->first();
  125. if(!empty($form)){
  126. $company = Company::where('_id',$docket->WorkOrder->contractor_id)->first();
  127. $staff = Staff::with('StaffDetail')->where('_id',$docket->installer_id)->first();
  128. if(!empty($staff)){
  129. $installer = $staff->StaffDetail->name;
  130. }else{
  131. $installer = '';
  132. }
  133. $address = '';
  134. if($form->type_application == 'R'){
  135. if($form->Subscriber->street != ''){
  136. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  137. }else {
  138. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  139. }
  140. }else if($form->type_application == 'B'){
  141. if ($form->Subscriber->unit_no != '') {
  142. $unit = $form->Subscriber->unit_no;
  143. } else {
  144. $unit = ' ';
  145. }
  146. if ($form->Subscriber->building_name == null) {
  147. $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  148. } else {
  149. $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  150. }
  151. }
  152. $total =array($docket->Rating1, $docket->Rating2, $docket->Rating3);
  153. $total_rating = array_sum($total);
  154. $data = array(
  155. // "contractor_id" => $company->name,
  156. // "installer_id" => $installer,
  157. // "customer_id" => $customer_id,
  158. // "status" => $status,
  159. "cus_name"=> $form->Subscriber->name,
  160. "address"=> $address,
  161. "contact_no"=> $form->Subscriber->phone1,
  162. "technical" => $company->name,
  163. "installer_name" => $installer,
  164. "title" => $docket->nature_work,
  165. "docket_id" => $docket->docket_id,
  166. "wo_id" => $docket->work_order_id,
  167. "status" => $docket->WorkOrder->status,
  168. "start_datetime"=> $docket->WorkOrder->dateTimeStart,
  169. "end_datetime" => $docket->end_job,
  170. "cable_read" => $docket->cable_read,
  171. "router" => $docket->router_serial_number,
  172. "mac_router" => $docket->mac_router,
  173. "modem_sn" => $docket->modem_sn,
  174. "type_testing" => $docket->type_testing,
  175. "condition" => $docket->condition,
  176. "note" => $docket->Note,
  177. "total_rating" => $total_rating,
  178. );
  179. return $this->sendResponse($data, 'Successfull Get Docket Detail');
  180. }
  181. }
  182. }else {
  183. return $this->sendError('Invalid User', 'User Not Exist!');
  184. }
  185. }
  186. public function getDocket(Request $request)
  187. {
  188. $data = array();
  189. $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->where('roles_access','Installer')->first();
  190. if(!empty($loginUser)) {
  191. $docket = Docket::with('WorkOrder')->where('installer_id',$loginUser->_id)->get();
  192. $company = Company::where('_id',$loginUser->StaffDetail->company_id)->first();
  193. if(!empty($docket)){
  194. foreach($docket as $a) {
  195. $nw = '';
  196. if(!empty($a->WorkOrder->nature_work)){
  197. $nw = $a->WorkOrder->nature_work;
  198. }
  199. array_push($data,array(
  200. "docket_id" => $a->docket_id,
  201. "wo_id" => $a->work_order_id,
  202. "contractor_id" => $company,
  203. "installer_id" => $loginUser->StaffDetail->name,
  204. "title" => $nw,
  205. "imageUrl"=>'assets/activation_icon_nRead1.png',
  206. "end_date"=>date("m/d/Y", strtotime($a->end_job)),
  207. "end_time"=>date("H:i", strtotime($a->end_job)),
  208. "cable_read" => $a->cable_read
  209. ));
  210. }
  211. return $this->sendResponse($data, 'Successfull');
  212. }
  213. }else {
  214. return $this->sendError('Invalid User', 'User Not Exist!');
  215. }
  216. }
  217. public function updateWorkOrder(Request $request){
  218. $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->where('roles_access','Installer')->first();
  219. if(!empty($loginUser)) {
  220. $wo = WorkOrder::where('wo',$request->nid)->first();
  221. if(!empty($wo)){
  222. $wo->remarks_installer = $request->postres.". ".$request->note;
  223. $wo->status = $request->type;
  224. $wo->save();
  225. return $this->sendResponse('Success', 'Work Order '.$request->nid.' been update successfull');
  226. }else{
  227. return $this->sendError('Failed', 'Work Order Not Exist!');
  228. }
  229. }else {
  230. return $this->sendError('Invalid User', 'User Not Exist!');
  231. }
  232. }
  233. public function getQuestions(){
  234. $question = Question::all();
  235. if(!empty($question)) {
  236. return $this->sendResponse($question, 'Get all questions successfull');
  237. }else{
  238. return $this->sendError('', 'No Questions!');
  239. }
  240. }
  241. }