123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- <?php
-
- namespace App\Http\Controllers\API;
-
- use Illuminate\Http\Request;
- use App\Http\Requests\RegisterRequest;
- use App\Http\Controllers\Api\BaseController;
- use Illuminate\Support\Facades\Auth;
-
- Use App\Staff;
- Use App\Model\StaffDetail;
- use App\Model\Docket;
- use App\Model\WorkOrder;
- use App\Model\Company;
- Use App\Model\Form;
- Use App\Model\PackageDetail;
- Use App\Model\Subscriber;
- use App\Model\Question;
-
-
- Use Hash;
- use Carbon\Carbon;
- use Crypt;
- use File;
- use Mail;
-
- class WorkOrderMobile extends BaseController
- {
-
- function random_code($limit) {
- return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
- }
-
- /**
- /* Schedule Function
- **/
- public function getSchedule(Request $request)
- {
- $data = array();
- $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first();
- if(!empty($loginUser)) {
- $schedule = WorkOrder::where('installer_id',$loginUser->_id)->where('status','Pending Installer')->get();
- foreach($schedule as $b) {
-
- array_push($data,array(
- "Title" => $b->nature_work,
- "Date"=>date("m/d/Y", strtotime($b->dateTimeStart)),
- "Time"=>date("H:i", strtotime($b->dateTimeStart)),
- "DateTimeStart"=>$b->dateTimeStart,
- "DateTimeEnd"=>$b->dateTimeEnd,
- "status" => $b->status,
- ));
-
- }
-
- return $this->sendResponse($data, 'Get Schedule Successfully');
- }else {
- return $this->sendError('Invalid User', 'User Not Exist!');
- }
- }
-
- public function getWorkOrderDetail(Request $request){
- $data = array();
-
- $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first();
-
- if(!empty($loginUser)) {
-
- $wo = WorkOrder::where('installer_id',$loginUser->_id)->where('status','Pending Installer')->get();
-
- if(!empty($wo)){
- foreach($wo as $w){
- $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->_id)->first();
- $company = Company::where('_id',$w->contractor_id)->first();
-
- $address = '';
- if($form->type_application == 'R'){
- if($form->Subscriber->street != ''){
- $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
- }else {
- $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
- }
-
- }else if($form->type_application == 'B'){
-
- if ($form->Subscriber->unit_no != '') {
- $unit = $form->Subscriber->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($form->Subscriber->building_name == null) {
- $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
- } else {
- $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
- }
-
- }
-
- $pp = ''; $noP = 'N/A'; $nP = '';
-
- if($w->no_phone != ''){
- $noP = $w->no_phone;
- }
-
- if($w->need_phone != ''){
- $nP = $w->need_phone;
- }
-
- array_push($data,array(
- "id" => $w->wo,
- "formT" => $form->type_application,
- "contractor_id" => $company->name,
- "installer_id" => $loginUser->StaffDetail->name,
- "title" => $w->nature_work,
- "address"=> $address,
- "imageUrl"=>'assets/activation_icon_nRead1.png',
- "appoint_date"=>date("m/d/Y", strtotime($w->dateTimeStart)),
- "appoint_time"=>date("H:i", strtotime($w->dateTimeStart)),
- "cus_name"=> $form->Subscriber->name,
- "contact_person" => $form->Subscriber->name,
- "contact_no"=> $form->Subscriber->phone1,
- "technical" => $form->Subscriber->name,
- "status" => $w->status,
- 'pppoe' => $w->pppoe_username,
- 'package' => $form->PackageDetail->name,
- 'onu' => $w->onu,
- 'router' => $w->router,
- 'no_phone' => $noP,
- 'n_phone' => $nP,
- "note" => $w->remarks_custservice,
- ));
- }
-
- return $this->sendResponse($data, 'Get Work Order Successfully');
-
- }else {
- return $this->sendResponse('', 'No Data');
- }
-
- }else {
- return $this->sendError('Invalid User', 'User Not Exist!');
- }
- }
-
- public function getDocketDetail(Request $request)
- {
-
- $data = array(); $installer = '';
- $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->where('roles_access','Installer')->first();
- if(!empty($loginUser)) {
-
- $docket = Docket::with('WorkOrder')->where('installer_id',$loginUser->_id)->where('docket_id', $request->docket_id)->first();
- if(!empty($docket)){
- $form = Form::with('PackageDetail','Subscriber')->where("_id",$docket->WorkOrder->_id)->first();
- if(!empty($form)){
-
- $company = Company::where('_id',$docket->WorkOrder->contractor_id)->first();
- $staff = Staff::with('StaffDetail')->where('_id',$docket->installer_id)->first();
- if(!empty($staff)){
- $installer = $staff->StaffDetail->name;
- }else{
- $installer = '';
- }
-
- $address = '';
- if($form->type_application == 'R'){
- if($form->Subscriber->street != ''){
- $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
- }else {
- $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
- }
-
- }else if($form->type_application == 'B'){
-
- if ($form->Subscriber->unit_no != '') {
- $unit = $form->Subscriber->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($form->Subscriber->building_name == null) {
- $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
- } else {
- $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
- }
-
- }
-
- $total =array($docket->Rating1, $docket->Rating2, $docket->Rating3);
- $total_rating = array_sum($total);
-
- $data = array(
-
-
- // "contractor_id" => $company->name,
- // "installer_id" => $installer,
- // "customer_id" => $customer_id,
-
- // "status" => $status,
-
-
-
-
- "cus_name"=> $form->Subscriber->name,
- "address"=> $address,
- "contact_no"=> $form->Subscriber->phone1,
- "technical" => $company->name,
- "installer_name" => $installer,
- "title" => $docket->nature_work,
- "docket_id" => $docket->docket_id,
- "wo_id" => $docket->work_order_id,
- "status" => $docket->WorkOrder->status,
- "start_datetime"=> $docket->WorkOrder->dateTimeStart,
- "end_datetime" => $docket->end_job,
- "cable_read" => $docket->cable_read,
- "router" => $docket->router_serial_number,
- "mac_router" => $docket->mac_router,
- "modem_sn" => $docket->modem_sn,
- "type_testing" => $docket->type_testing,
- "condition" => $docket->condition,
- "note" => $docket->Note,
- "total_rating" => $total_rating,
- );
-
- return $this->sendResponse($data, 'Successfull Get Docket Detail');
- }
- }
- }else {
- return $this->sendError('Invalid User', 'User Not Exist!');
- }
- }
-
- public function getDocket(Request $request)
- {
-
- $data = array();
- $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->where('roles_access','Installer')->first();
- if(!empty($loginUser)) {
-
- $docket = Docket::with('WorkOrder')->where('installer_id',$loginUser->_id)->get();
- $company = Company::where('_id',$loginUser->StaffDetail->company_id)->first();
-
- if(!empty($docket)){
- foreach($docket as $a) {
-
- $nw = '';
- if(!empty($a->WorkOrder->nature_work)){
- $nw = $a->WorkOrder->nature_work;
- }
-
- array_push($data,array(
- "docket_id" => $a->docket_id,
- "wo_id" => $a->work_order_id,
- "contractor_id" => $company,
- "installer_id" => $loginUser->StaffDetail->name,
- "title" => $nw,
- "imageUrl"=>'assets/activation_icon_nRead1.png',
- "end_date"=>date("m/d/Y", strtotime($a->end_job)),
- "end_time"=>date("H:i", strtotime($a->end_job)),
- "cable_read" => $a->cable_read
- ));
- }
- return $this->sendResponse($data, 'Successfull');
- }
- }else {
- return $this->sendError('Invalid User', 'User Not Exist!');
- }
- }
-
- public function updateWorkOrder(Request $request){
-
- $loginUser = Staff::with('StaffDetail')->where('api_token', $request->api_token)->where('roles_access','Installer')->first();
- if(!empty($loginUser)) {
-
- $wo = WorkOrder::where('wo',$request->nid)->first();
- if(!empty($wo)){
-
- $wo->remarks_installer = $request->postres.". ".$request->note;
- $wo->status = $request->type;
- $wo->save();
-
- return $this->sendResponse('Success', 'Work Order '.$request->nid.' been update successfull');
-
- }else{
- return $this->sendError('Failed', 'Work Order Not Exist!');
- }
-
- }else {
- return $this->sendError('Invalid User', 'User Not Exist!');
- }
- }
-
- public function getQuestions(){
-
- $question = Question::all();
- if(!empty($question)) {
- return $this->sendResponse($question, 'Get all questions successfull');
- }else{
- return $this->sendError('', 'No Questions!');
- }
- }
- }
|