· 5 years ago · Nov 19, 2020, 06:54 PM
1<?php
2
3namespace App\Http\Controllers\Mobile;
4use App\Events\CamOrder;
5use App\Order;
6use App\Events\OrderEvent;
7use App\Service;
8use App\Zone;
9use App\CityCode;
10use App\ServiceCategory;
11use App\Product;
12use App\ServiceRequestHireDriver;
13use App\Events\LiveDashboard;
14use App\ServiceRequestPickFromStore;
15use App\User;
16use App\AppPreference;
17use Carbon\Carbon;
18use Illuminate\Support\Facades\Validator;
19use Illuminate\Support\Facades\Auth;
20use Illuminate\Http\Request;
21use App\Http\Controllers\Controller;
22use App\FirebaseToken;
23use DB;
24use Helper;
25
26class OrdersController extends Controller
27{
28 // Orders Placed Via Uploading the List to CB Via APP
29 public function camOrders(Request $request){
30 $rules = array(
31 'cam_image' => 'required',
32 'service_id' => 'required',
33 'category_id' => 'required',
34 'current_location' => 'required',
35 );
36
37 $error = Validator::make($request->all(), $rules);
38
39 if($error->fails())
40 {
41 return response()->json([
42 'status'=>'Error',
43 'status_code'=>400,
44 'message' => $error->errors()->all()
45 ]);
46 }else{
47 $validations = true;
48 }
49
50
51
52
53 if(Auth::user()->block_pod == 1){
54 return response()->json([
55 'status'=>'Error',
56 'status_code'=>409,
57 'message' => 'Please place the order from general items list.'
58 ]);
59 }
60
61
62
63 $order = new Order();
64 // dd(Auth::user()->id);
65 // Cam IMAGE Processing and Upload
66 // $unique = uniqid();
67
68 if(Zone::where('pincode',Auth::user()->pincode)->count() > 0){
69 $zone = Zone::where('pincode',Auth::user()->pincode)->first();
70 $order->territory_id = $zone->id;
71 $order->state = $zone->state;
72 $order->pincode = $zone->pincode;
73 }
74
75 if(Auth::user()->address != NULL){
76 if(CityCode::where('name',Auth::user()->address)->count() > 0){
77 $u1 = CityCode::where('name',Auth::user()->address)->first()->code;
78 if($u1 == NULL){
79 $u1 = substr((Auth::user()->address),0,1) .''. substr((Auth::user()->address),1,2);
80 }else{
81 if(Auth::user()->city_not_selected != NULL){
82 $u1 = AppPreference::where('id',65)->first()->value;
83 }else{
84 $u1 = substr(($u1),0,1) .''. substr(($u1),1,2);
85 }
86 }
87 }else{
88 $u1 = substr((Auth::user()->address),0,1) .''. substr((Auth::user()->address),1,2);
89 }
90 }else{
91 $u1 = substr((Auth::user()->address),0,1) .''. substr((Auth::user()->address),1,2);
92 }
93
94 $u2 = chr(rand(65,90));
95 $u3 = rand(0,9);
96 $u4 = rand(0,9);
97 $u5 = substr((Carbon::now()->timestamp),-3);
98 $u6 = substr((Auth::user()->mobile),-2);
99 $unique = $u1.''.$u2.''.$u3.''.$u4.''.$u5.''.$u6;
100 $file = $request->file('cam_image');
101
102 if($file){
103 $fileName = 'uploads/cam-order/'.$unique.'-'.$file->getClientOriginalName();
104 $filePath = public_path('uploads/cam-order/');
105 $destinationPath = public_path('uploads/cam-order');
106 if(!file_exists($filePath.'/'.$file->getClientOriginalName())){
107 $userProfile = $file->move($destinationPath,$fileName);
108 }
109 }else{
110 return response()->json([
111 'status'=>'Error',
112 'status_code'=>409,
113 'message'=>'The Cam Image Field is Required.'
114 ]);
115 }
116
117
118
119 $order->uid = $unique;
120 $order->user_id = Auth::user()->id;
121 $order->service_id = 4;
122 $order->category_id = 16;
123 $order->from_lat_lng = $request->current_location;
124 $order->to_lat_lng = $request->current_location;
125 $order->cam_image = $unique.'-'.$file->getClientOriginalName();
126 $order->status = 701;
127 $order->payment_status = 'pending';
128 $order->actual_schedule_timestamp = Carbon::now();
129 $order->call_cam_request = 2;
130 $response = $order->save();
131
132 // $order_details = Order::where('uid',$order->uid)->first();
133 // event(new CamOrder($order_details));
134
135 if($response){
136 return response()->json([
137 'status'=>'Success',
138 'status_code'=>200,
139 'message'=>'Cam Order Placed Successfully.',
140 'order_id'=>$unique
141 ]);
142 }
143 }
144
145
146
147 public function placeCamOrders(Request $request)
148 {
149 $order_details = Order::where('uid',$request->order_id)->first();
150 $order_details->payment_mode = $request->payment_mode;
151 $order_details->payment_status = $request->payment_status;
152 $order_details->transaction_id = $request->transaction_id;
153 $order_details->pick_phone = User::where('id',$order_details->user_id)->first()->mobile;
154 $order_details->save();
155
156 $order_details = Order::where('uid',$request->order_id)->first();
157 event(new LiveDashboard('LiveDashboard'));
158 event(new CamOrder($order_details));
159
160 $user=User::where('id',Auth::user()->id)->first();
161
162 $message = 'Hi '.$user->name.', Cam Order Request Placed Successfully, Our Representative Will Address Your Request Shortly. Thank you. ChotaBeta';
163
164 Helper::sendSms($user->mobile,$message);
165
166
167
168 if($user->test_account != 1){
169 $admins = AppPreference::where('id',17)->first()->value;
170
171 $admins = explode(',',$admins);
172
173 foreach ($admins as $admin) {
174 $message = 'Hi! User Name: '.$user->name.'('.$user->mobile.') Placed a Cam Order, Order Id: '.$request->order_id;
175
176 Helper::sendSms($admin,$message);
177 }
178 }
179 return response()->json([
180 'status'=>'Success',
181 'status_code'=>200,
182 'message'=>'Cam Order Placed Successfully.',
183 'order_id'=>$request->order_id
184 ]);
185 }
186
187
188 //Order Place
189 public function acceptOrder(Request $request){
190 $rules = array(
191 'order_id' => 'required',
192 );
193
194 $error = Validator::make($request->all(), $rules);
195
196 if($error->fails())
197 {
198 return response()->json([
199 'status'=>'Error',
200 'status_code'=>400,
201 'message' => $error->errors()->all()
202 ]);
203 }else{
204 $validations = true;
205 }
206
207
208 if(isset($request->del_boy_id)){
209 $user = User::where('id',$request->del_boy_id)->first();
210 }else{
211 $user = User::where('id',Auth::user()->id)->first();
212 }
213 // if(Order::where('delivery_person_id',Auth::user()->id)->whereDate('created_at',Carbon::today())->where('status','!=',703)->count() > 0){
214 // return response()->json([
215 // 'status' => 'Error',
216 // 'status_code' => 400,
217 // 'message' => 'You have Accepted Another Order Please Complete it First',
218 // ]);
219 // }
220
221 if(User::where('id',$user->id)->count() > 0){
222
223 if(Order::where('id',$request->order_id)->where('delivery_person_id',NULL)->count()>0 or Order::where('id',$request->order_id)->where('delivery_person_id',$user->id)->count()>0){
224 // if()
225 $order_uid = Order::where('id',$request->order_id)->first()->uid;
226
227 if(Order::where('uid',$order_uid)->count() == 1){
228 $order = Order::where('id',$request->order_id)->first();
229 $order_status = $order->status;
230 $order->status='715';
231
232 if($order->accepted_at == NULL){
233 $order->accepted_at= Carbon::now();
234 }
235
236 if($order->total_distance == NULL){
237
238 $order->location_track = $order->status.';'.$request->current_location;
239 $order->total_distance = 0;
240 }
241
242 $order->delivery_person_id = $user->id;
243 $user_id=$order->user_id;
244 $user_curnt=User::where('id',$user->id)->first();
245 $user_curnt->current_location=$request->current_location;
246
247 if($order_status == 701){
248 if(FirebaseToken::where('user_id',$user_id)->count() > 0){
249 if(User::where('id',$user_id)->first()->device == 'IOS'){
250 $notif_key = env('FIRE_BASE_APP_KEY_IOS');
251 }else{
252 $notif_key = env('FIRE_BASE_APP_KEY_USER');
253 }
254 $user_current_app_version = User::where('id',$user_id)->first()->current_app_version;
255 if(($user_current_app_version != NULL) and ($user_current_app_version != '0.2.9')){
256 $notif_key = env('FIRE_BASE_APP_KEY_USER2');
257 }
258 $user_token = FirebaseToken::where('user_id',$user_id)->first()->token;
259 $fcmUrl = env('FIRE_BASE_APP_SEND_URL', '');
260 $notification = [
261 'title' => 'Order Accepted',
262 'body' => 'Your Order was Accepted by the Delivery Person',
263 'icon' =>'myIcon',
264 'sound' => 'mySound'
265 ];
266 $extraNotificationData = ["message" => $notification,"moredata" =>'--'];
267 $fcmNotification = [
268 //multple token array
269 // 'registration_ids' => $tokens,
270 //single token
271 'to' => $user_token,
272 'notification' => $notification,
273 'data' => $extraNotificationData
274 ];
275 // dd($notification);
276 $headers = [
277 'Authorization: key=' . $notif_key,
278 'Content-Type: application/json'
279 ];
280 $ch = curl_init();
281 curl_setopt($ch, CURLOPT_URL,$fcmUrl);
282 curl_setopt($ch, CURLOPT_POST, true);
283 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
284 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
285 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
286 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
287 $result = curl_exec($ch);
288 curl_close($ch);
289 $resultArr = json_decode($result, true);
290 }
291
292 $message = 'Hi '.User::where('id',$order->user_id)->first()->name.', Your Order: '.$order_uid.' is Accepted By '.$user->name .' Mobile('.$user->mobile.')';
293
294 Helper::sendSms(User::where('id',$order->user_id)->first()->mobile,$message);
295 // $admins = AppPreference::where('id',17)->first()->value;
296 //
297 // $admins = explode(',',$admins);
298 //
299 // foreach ($admins as $admin) {
300 // $message = 'Order ID: '.$order_uid. 'was accepted by: '.$user->name.' Order TimeStamp: '.Carbon::parse($order->created_at)->format('d-m-y h:i A') .' Accepted TimeStamp: '.Carbon::now()->format('d-m-y h:i A');
301 //
302 // Helper::sendSms($admin,$message);
303 // }
304 }
305
306 $user_curnt->save();
307
308 if($order->service_id == 1){
309 $order_type = 1;
310 }elseif($order->service_id == 3){
311 $order_type = 3;
312 }else{
313 $order_type = 2;
314 }
315
316
317 $message = [
318 'order_id' =>$order->id,
319 'uid' =>$order->uid,
320 'change_status'=> 3, //For Broadcast modified or cancelled
321 'order_type' => $order_type,
322 'status' => $order->status,
323 'total_bill' => $order->amount,
324 'pay_pick_up' => 0,
325 'collect_from_customer' => 0,
326 'scheduled_time' => $order->created_at,
327 'stores'=>$order->preferred_stores,
328 "delivery_name"=> User::where('id',$order->user_id)->first()->name,
329 "delivery_phone"=> User::where('id',$order->user_id)->first()->mobile,
330 'from_address' => $order->from_location,
331 'from_location' => $order->from_lat_lng,
332 'time_stamp' => $order->pick_name.', '.$order->pick_phone.','.$order->to_location.','.Carbon::parse($order->created_at)->format('D h:i a').': '.Service::where('id',$order->service_id)->first()->name,
333 'weight_of_items' => $order->weight.'Kgs',
334 'to_address' => $order->to_lat_lng,
335 'to_location' => $order->to_location,
336 'user_name' => User::where('id',$order->user_id)->first()->name,
337 'mobile' => User::where('id',$order->user_id)->first()->mobile,
338 'claimed_status' => 0,
339 'claimed_counter' => 1,
340 'items_list' => [array(
341 'id'=>0,
342 'name'=>"0",
343 'weight'=>0,
344 'weight_desc'=>'Kgs',
345 'qty'=>0,
346 'cost'=>0
347 )],
348 'roud_trip' => 'No',
349 'car_logo' => 'No',
350 'car_type' => 'Manual',
351 'car_model' => 'Sedan',
352 ];
353 event(new LiveDashboard('LiveDashboard'));
354 event(new OrderEvent($message));
355
356
357
358
359 $order->save();
360 return response()->json([
361 'status' => 'Success',
362 'status_code' => 200,
363 'message' => 'You have Successfully Accepted the Order',
364 ]);
365 }
366 else{
367 $order_uid = Order::where('id',$request->order_id)->first()->uid;
368
369 $order = Order::where('uid',$order_uid)->count();
370 if($order == 2){
371 for($i=1; $i<=2; $i++){
372 if(Order::where('uid',$order_uid)->where('delivery_person_id',NULL)->count() == 0){
373 break;
374 }else{
375 $order = Order::where('uid',$order_uid)->where('delivery_person_id',NULL)->first();
376 $order->delivery_person_id = $user->id;
377 $order->location_track = $order->status.';'.$request->current_location;
378 $order->total_distance = 0;
379 $order->save();
380 }
381 // dd($i);
382 }
383 }
384
385 $order = Order::where('uid',$order_uid)->first();
386 $order_status = $order->status;
387 $user_id=$order->user_id;
388 $user_curnt=User::where('id',$user->id)->first();
389 $user_curnt->current_location=$request->current_location;
390
391 if($order_status == 701){
392 if(FirebaseToken::where('user_id',$user_id)->count() > 0){
393 if(User::where('id',$user_id)->first()->device == 'IOS'){
394 $notif_key = env('FIRE_BASE_APP_KEY_IOS');
395 }else{
396 $notif_key = env('FIRE_BASE_APP_KEY_USER');
397 }
398 $user_current_app_version = User::where('id',$user_id)->first()->current_app_version;
399 if(($user_current_app_version != NULL) and ($user_current_app_version != '0.2.9')){
400 $notif_key = env('FIRE_BASE_APP_KEY_USER2');
401 }
402 $user_token = FirebaseToken::where('user_id',$user_id)->first()->token;
403 $fcmUrl = env('FIRE_BASE_APP_SEND_URL', '');
404 $notification = [
405 'title' => 'Order Accepted',
406 'body' => 'Your Order was Accepted by the Delivery Person',
407 'icon' =>'myIcon',
408 'sound' => 'mySound'
409 ];
410 $extraNotificationData = ["message" => $notification,"moredata" =>'--'];
411 $fcmNotification = [
412 //multple token array
413 // 'registration_ids' => $tokens,
414 //single token
415 'to' => $user_token,
416 'notification' => $notification,
417 'data' => $extraNotificationData
418 ];
419 // dd($notification);
420 $headers = [
421 'Authorization: key=' . $notif_key,
422 'Content-Type: application/json'
423 ];
424 $ch = curl_init();
425 curl_setopt($ch, CURLOPT_URL,$fcmUrl);
426 curl_setopt($ch, CURLOPT_POST, true);
427 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
428 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
429 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
430 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
431 $result = curl_exec($ch);
432 curl_close($ch);
433 $resultArr = json_decode($result, true);
434 }
435
436
437 $message = 'Hi '.User::where('id',$order->user_id)->first()->name.', Your Order: '.$order_uid.' is Accepted By '.$user->name;
438
439 Helper::sendSms(User::where('id',$order->user_id)->first()->mobile,$message);
440 $admins = AppPreference::where('id',17)->first()->value;
441
442 $admins = explode(',',$admins);
443
444 foreach ($admins as $admin) {
445 $message = 'Order ID: '.$order_uid. 'was accepted by: '.$user->name.' Order TimeStamp: '.Carbon::parse($order->created_at)->format('d-m-y h:i A') .' Accepted TimeStamp: '.Carbon::now()->format('d-m-y h:i A');
446
447 Helper::sendSms($admin,$message);
448 }
449 }
450 $user_curnt->save();
451
452
453 if($order->service_id == 1){
454 $order_type = 1;
455 }elseif($order->service_id == 3){
456 $order_type = 3;
457 }else{
458 $order_type = 2;
459 }
460 $message = [
461 'order_id' =>$order->id,
462 'uid' =>$order->uid,
463 'change_status'=> 3, //For Broadcast modified or cancelled
464 'order_type' => $order_type,
465 'status' => $order->status,
466 'total_bill' => $order->amount,
467 'pay_pick_up' => 0,
468 'collect_from_customer' => 0,
469 'scheduled_time' => $order->created_at,
470 'stores'=>$order->preferred_stores,
471 "delivery_name"=> User::where('id',$order->user_id)->first()->name,
472 "delivery_phone"=> User::where('id',$order->user_id)->first()->mobile,
473 'from_address' => $order->from_location,
474 'from_location' => $order->from_lat_lng,
475 'time_stamp' => $order->pick_name.', '.$order->pick_phone.','.$order->to_location.','.Carbon::parse($order->created_at)->format('D h:i a').': '.Service::where('id',$order->service_id)->first()->name,
476 'weight_of_items' => $order->weight.'Kgs',
477 'to_address' => $order->to_lat_lng,
478 'to_location' => $order->to_location,
479 'user_name' => User::where('id',$order->user_id)->first()->name,
480 'mobile' => User::where('id',$order->user_id)->first()->mobile,
481 'claimed_status' => 0,
482 'claimed_counter' => 1,
483 'items_list' =>[array(
484 'id'=>0,
485 'name'=>"0",
486 'weight'=>0,
487 'weight_desc'=>'Kgs',
488 'qty'=>0,
489 'cost'=>0
490 )],
491 'roud_trip' => 'No',
492 'car_logo' => 'No',
493 'car_type' => 'Manual',
494 'car_model' => 'Sedan',
495 ];
496
497 $data_broadcast = array(
498 'notification_sound' => 2
499 );
500 $data_broadcast = json_encode($data_broadcast);
501
502 event(new LiveDashboard($data_broadcast));
503 event(new OrderEvent($message));
504
505
506 $order->save();
507 return response()->json([
508 'status' => 'Success',
509 'status_code' => 200,
510 'message' => 'You have Successfully Accepted the Order',
511 ]);
512 }
513
514 }
515 else{
516 $order_iod = Order::where('id',$request->order_id)->first();
517 $user_id = $order_iod->user_id;
518 $user = User::where('id',$user_id)->first()->name;
519 return response()->json([
520 'status' => 'Error',
521 'status_code' => 409,
522 'message' => 'Already Order was Assigned.',
523 ]);
524 }
525 }
526 else{ return response()->json([
527 'status' => 'Error',
528 'status_code' => 409,
529 'message' => 'No Driver Found',
530 ]);
531 }
532 }
533
534 public function orderStatus(Request $request){
535 if(Order::where('id',$request->order_id)->count() > 0){
536 $order_status = Order::where('id',$request->order_id)->first();
537 $order_status->status = $request->status;
538
539 Helper::totalOrderDistance($request->status,$request->current_location,$request->order_id);
540 // dd('here');
541 if($order_status->service_id != 3 and $order_status->service_id != 1){
542 if($order_status->status == "716"){
543 $order = "ChotaBeta is on the way to pick the order";
544 }
545 elseif($order_status->status == "717"){
546 $order = "ChotaBeta is arrived to pick the order";
547 }
548 elseif($order_status->status == "718"){
549 if($order_status->store1_paid == NULL){
550 return response()->json([
551 'status'=>'Error',
552 'status_code'=>409,
553 'message'=>'You did Not Enter Store Pay, Go Back and Enter'
554 ]);
555 }
556 $order = "ChotaBeta have picked the order";
557 }
558 elseif($order_status->status == "702"){
559 $order = "ChotaBeta is on the way to drop the order";
560 }
561 elseif($order_status->status == "719"){
562 $order = "ChotaBeta have arrived to drop the order";
563 $fare = Helper::totalPaidDriver($order_status->id);
564 $data = $fare->getData();
565 $status_track = explode(',',$order_status->status_track);
566 if(!(in_array($order_status->status,$status_track))){
567 $order_status->amount = (int)($data->payable_amount);
568 // dd($data);
569 }
570 }
571 elseif($order_status->status == "703"){
572 // dd('here1');
573 if($order_status->payment_mode != 'COD' and ($order_status->payment_status == 'pending' or $order_status->payment_status == 'Pending')){
574 if($request->received_cash == FALSE or $request->received_cash == "FALSE"){
575 return response()->json([
576 'status'=>'Error',
577 'status_code'=>204,
578 'message'=>'Payment is Pending.'
579 ]);
580 }else{
581 $order_status->received_as_cash = $request->received_as_cash;
582 }
583 }
584 if($order_status->payment_mode == 'Online'){
585 $fare = Helper::totalPaidDriver($order_status->id);
586 $data = $fare->getData();
587 if($data->amount != 0 or $data->amount != NULL){
588 $order_status->cod = $data->amount;
589 }
590 }
591
592 $order = "ChotaBeta have Delivered the order";
593 $order_status->payment_status = 'paid';
594 $subject = 'ChotaBeta Order Invoice';
595 $order_id = $request->order_id;
596
597 $order_status->delivered_at = Carbon::now();
598
599 Helper::sendInvoiceMail($subject,$order_id);
600 }
601 else{
602 $order = "No Status Found";
603 }
604 }
605 else if($order_status->service_id == 1){
606 if($order_status->status == "716"){
607 // $order = "ChotaBeta is on the way to pick the order";
608 $order = NULL;
609 }
610 elseif($order_status->status == "717"){
611 $order = "ChotaBeta is arrived to pick the order";
612 }
613 elseif($order_status->status == "718"){
614 $order = "ChotaBeta have picked the order";
615 }
616 elseif($order_status->status == "702"){
617 $order = "ChotaBeta is on the way to drop the order";
618 }
619 elseif($order_status->status == "719"){
620 $order = "ChotaBeta have arrived to drop the order";
621 $fare = Helper::totalPaidDriver($order_status->id);
622 $data = $fare->getData();
623
624 $order_status->amount = (int)($data->payable_amount);
625 }
626 elseif($order_status->status == "703"){
627 // dd('here2');
628 if($order_status->payment_mode != 'COD' and ($order_status->payment_status == 'pending' or $order_status->payment_status == 'Pending')){
629 if($request->received_cash == FALSE or $request->received_cash == "FALSE"){
630 return response()->json([
631 'status'=>'Error',
632 'status_code'=>204,
633 'message'=>'Payment is Pending.'
634 ]);
635 }else{
636 $order_status->received_as_cash = $request->received_as_cash;
637 }
638 }
639 // dd('sdfs');
640
641 if($order_status->payment_mode == 'Online'){
642 $fare = Helper::totalPaidDriver($order_status->id);
643 $data = $fare->getData();
644 if($data->amount != 0 or $data->amount != NULL){
645 $order_status->cod = $data->amount;
646 }
647 }
648
649
650 $order = "ChotaBeta have Delivered the order";
651 $order_status->payment_status = 'paid';
652 $subject = 'ChotaBeta Order Invoice';
653 $order_id = $request->order_id;
654 Helper::sendInvoiceMail($subject,$order_id);
655 }
656 else{
657 $order = "No Status Found";
658 }
659 }
660 else{
661 if($order_status->status == "716"){
662 $order = "ChotaBeta is on the way";
663 }
664 elseif($order_status->status == "717"){
665 $order = "ChotaBeta Arrived at Pick Location";
666 }
667 elseif($order_status->status == "718"){
668 $order = "ChotaBeta Started the Trip";
669 }
670 elseif($order_status->status == "702"){
671 $order = "ChotaBeta: Your trip is on going";
672 }
673 elseif($order_status->status == "719"){
674 $order = "ChotaBeta Arrived at Drop Location";
675 $fare = Helper::totalPaidDriver($order_status->id);
676 $data = $fare->getData();
677 $order_status->amount = (int)($data->payable_amount);
678
679 // $order_status->amount = (int)($data->amount);
680 }
681 elseif($order_status->status == "703"){
682 // dd('here3');
683 if($order_status->payment_mode != 'COD' and ($order_status->payment_status == 'pending' or $order_status->payment_status == 'Pending')){
684 if($request->received_cash == FALSE or $request->received_cash == "FALSE"){
685 return response()->json([
686 'status'=>'Error',
687 'status_code'=>204,
688 'message'=>'Payment is Pending.'
689 ]);
690 }else{
691 $order_status->received_as_cash = $request->received_as_cash;
692 }
693 }
694
695 if($order_status->payment_mode == 'Online'){
696 $fare = Helper::totalPaidDriver($order_status->id);
697 $data = $fare->getData();
698 if($data->amount != 0 or $data->amount != NULL){
699 $order_status->cod = $data->amount;
700 }
701 }
702
703
704 $order = "ChotaBeta Dropped at the Drop Location, Trip Completed";
705 $order_status->payment_status = 'paid';
706 $subject = 'ChotaBeta Order Invoice';
707 $order_id = $request->order_id;
708 Helper::sendInvoiceMail($subject,$order_id);
709 }
710 else{
711 $order = "No Status Found";
712 }
713 }
714 $user_id = $order_status->user_id;
715 // dd($order);
716 $user_curnt=User::where('id',Auth::user()->id)->first();
717 $user_curnt->current_location=$request->current_location;
718
719 $status_track = explode(',',$order_status->status_track);
720
721 if(!(in_array($order_status->status,$status_track))){
722 if($order_status->status_track == NULL){
723 $order_status->status_track = $order_status->status;
724 }else{
725 $order_status->status_track .= ','.$order_status->status;
726 }
727
728 if($order != NULL){
729 if(FirebaseToken::where('user_id',$user_id)->count() > 0){
730 if(User::where('id',$user_id)->first()->device == 'IOS'){
731 $notif_key = env('FIRE_BASE_APP_KEY_IOS');
732 }else{
733 $notif_key = env('FIRE_BASE_APP_KEY_USER');
734 }
735 $user_current_app_version = User::where('id',$user_id)->first()->current_app_version;
736 if(($user_current_app_version != NULL) and ($user_current_app_version != '0.2.9')){
737 $notif_key = env('FIRE_BASE_APP_KEY_USER2');
738 }
739 $user_token = FirebaseToken::where('user_id',$user_id)->first()->token;
740 $fcmUrl = env('FIRE_BASE_APP_SEND_URL', '');
741 $notification = [
742 'title' => 'Order Update',
743 'body' => $order,
744 'icon' =>'myIcon',
745 'sound' => 'mySound'
746 ];
747 // dd($notification);
748 $extraNotificationData = ["message" => $notification,"moredata" =>'--'];
749 $fcmNotification = [
750 //multple token array
751 // 'registration_ids' => $tokens,
752 //single token
753 'to' => $user_token,
754 'notification' => $notification,
755 'data' => $extraNotificationData
756 ];
757 // dd($notification);
758 $headers = [
759 'Authorization: key=' . $notif_key,
760 'Content-Type: application/json'
761 ];
762 $ch = curl_init();
763 curl_setopt($ch, CURLOPT_URL,$fcmUrl);
764 curl_setopt($ch, CURLOPT_POST, true);
765 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
766 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
767 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
768 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
769 $result = curl_exec($ch);
770 curl_close($ch);
771 $resultArr = json_decode($result, true);
772 // dd($result);
773 // dd($resultArr);
774 // if($resultArr['success'] != 0 ){
775 // return 'TRUE';
776 // }else{
777 // return 'FALSE';
778 // }
779 }
780 }
781
782 }
783
784 $order_status->save();
785 $user_curnt->save();
786 event(new LiveDashboard('LiveDashboard'));
787 return response()->json([
788 'status' => 'Success',
789 'status_Code' =>200,
790 'message' => 'Your Order Status Has Changed',
791 // 'user_token'=>$user_token,
792 // 'resultArr'=>$resultArr
793 ]);
794 }
795 else{
796 return response()->json([
797 'status' => 'Error',
798 'status_Code' =>409,
799 'message' => 'No order Found',
800 ]);
801 }
802 }
803
804 //Pick proof
805 public function pickProof(Request $request){
806 if(Order::where('id',$request->order_id)->count() > 0){
807 $pick=Order::where('id',$request->order_id)->first();
808
809 $unique = uniqid();
810 $file = $request->file('pick_proof');
811 $order_image = NULL;
812 if($file){
813 // return "Hi ";
814 $fileName = 'uploads/pick_proof/'.$unique.'-'.$file->getClientOriginalName();
815 $filePath = public_path('uploads/pick_proof/');
816 $destinationPath = public_path('uploads/pick_proof');
817 if(!file_exists($filePath.'/'.$file->getClientOriginalName())){
818 $userProfile = $file->move($destinationPath,$fileName);
819 }
820 $order_image = $unique.'-'.$file->getClientOriginalName();
821 }
822 // else{
823 // return "No IMage Found";
824 // }
825 // $o_image = $pick->order_image;
826 $o_image = DB::table('orders')->where('id',$request->order_id)->first()->order_image;
827 // dd($o_image);
828 if($order_image != NULL){
829 if(getType($o_image) == 'array'){
830 $o_image = $o_image[0];
831 }
832 $pick->order_image = ($o_image.' '.$order_image);
833 }
834 // dd($pick->order_image);
835
836 $pick->save();
837 return response()->json([
838 'status' => 'Success',
839 'status_code' => 200,
840 'message' => 'Pick Image was successfully inserted'
841 ]);
842 }
843 else{
844 return response()->json([
845 'status' => 'Error',
846 'status_Code' =>409,
847 'message' => 'No order Found',
848 ]);
849 }
850 }
851
852 //Drop Proof
853 public function dropProof(Request $request){
854 if(Order::where('id',$request->order_id)->count() > 0){
855 $pick=Order::where('id',$request->order_id)->first();
856
857 $unique = uniqid();
858 $file = $request->file('drop_proof');
859 // dd($file);
860 $drop_image = NULL;
861 if($file){
862 $fileName = 'uploads/pick_proof/'.$unique.'-'.$file->getClientOriginalName();
863 $filePath = public_path('uploads/pick_proof/');
864 $destinationPath = public_path('uploads/pick_proof');
865 if(!file_exists($filePath.'/'.$file->getClientOriginalName())){
866 $userProfile = $file->move($destinationPath,$fileName);
867 }
868 $drop_image = $unique.'-'.$file->getClientOriginalName();
869 }
870 // dd($drop_image);
871 $pick->drop_image = $drop_image;
872 $o_image = DB::table('orders')->where('id',$request->order_id)->first()->drop_image;
873 // dd($o_image);
874 if($drop_image != NULL){
875 if(getType($o_image) == 'array'){
876 $o_image = $o_image[0];
877 }
878 $pick->drop_image = ($o_image.' '.$drop_image);
879 }
880 $pick->save();
881 return response()->json([
882 'status' => 'Success',
883 'status_code' => 200,
884 'message' => 'Drop Image was successfully inserted'
885 ]);
886 }
887 else{
888 return response()->json([
889 'status' => 'Error',
890 'status_Code' =>409,
891 'message' => 'No order Found',
892 ]);
893 }
894 }
895
896
897 public function claimOrder(Request $request)
898 {
899
900 $rules = array(
901 'order_id' => 'required',
902 'claimed_status' => 'required'
903 );
904
905 $error = Validator::make($request->all(), $rules);
906
907 if($error->fails())
908 {
909 return response()->json([
910 'status'=>'Error',
911 'status_code'=>400,
912 'message' => $error->errors()->all()
913 ]);
914 }else{
915 $validations = true;
916 }
917
918 $order_id = $request->order_id;
919 $claimed_status = $request->claimed_status;
920
921 if(Order::where('id',$order_id)->count() == 0){
922 return response()->json([
923 'status'=>'Error',
924 'status_code'=>204,
925 'message'=>'Invalid Order ID.'
926 ]);
927 }
928
929 $order = Order::where('id',$order_id)->first();
930 $order->claimed = $claimed_status;
931 if($claimed_status == 1){
932 $order->claimed_counter += 1;
933 $order->delivery_person_id = Auth::user()->id;
934 }else{
935 $order->delivery_person_id = NULL;
936 }
937
938 if($order->service_id == 1){
939 $order_type = 1;
940 }elseif($order->service_id == 3){
941 $order_type = 3;
942 }else{
943 $order_type = 2;
944 }
945
946 $item = array();
947 $items = ServiceRequestPickFromStore::where('order_id',$order->uid)->get();
948 if($items!= NULL){
949 foreach($items as $i){
950 $b = Product::where('id',$i->product_id)->withTrashed()->first();
951 $a = array(
952 'id'=>$i->product_id,
953 'name'=>$i->product_name,
954 'weight'=>$b->weight_cal * $i->qty,
955 'weight_desc'=>'Kgs',
956 'qty'=>$i->qty,
957 'cost'=>$b->mrp * $i->qty
958 );
959 array_push($item,$a);
960 }
961
962 if($order->custom_item != NULL){
963 $ci = json_decode($order->custom_item);
964 if($ci !='[NA]' and $ci != NULL){
965 foreach ($ci as $cia) {
966 array_push($item,$cia);
967 }
968 }
969 }
970 }
971
972 $message = [
973 'order_id' =>$order->id,
974 'uid' =>$order->uid,
975 'change_status'=> 3, //For Broadcast modified or cancelled
976 'order_type' => $order_type,
977 'status' => $order->status,
978 'total_bill' => $order->amount,
979 'pay_pick_up' => 0,
980 'collect_from_customer' => 0,
981 'scheduled_time' => $order->created_at,
982 'stores'=>$order->preferred_stores,
983 "delivery_name"=> User::where('id',$order->user_id)->first()->name,
984 "delivery_phone"=> User::where('id',$order->user_id)->first()->mobile,
985 'from_address' => $order->from_location,
986 'from_location' => $order->from_lat_lng,
987 'time_stamp' => $order->pick_name.', '.$order->pick_phone.','.$order->to_location.','.Carbon::parse($order->created_at)->format('D h:i a').': '.Service::where('id',$order->service_id)->first()->name,
988 'weight_of_items' => $order->weight.'Kgs',
989 'to_address' => $order->to_lat_lng,
990 'to_location' => $order->to_location,
991 'user_name' => User::where('id',$order->user_id)->first()->name,
992 'mobile' => User::where('id',$order->user_id)->first()->mobile,
993 'claimed_status' => 0,
994 'claimed_counter' => $order->claimed_counter,
995 'transaction_id'=>$order->transaction_id,
996 'pick_name'=>$order->pick_name,
997 'pick_phone'=>$order->pick_phone,
998 'drop_name'=>$order->drop_name,
999 'drop_phone'=>$order->drop_phone,
1000 'user_instructions'=>$order->user_instructions,
1001 'items_list' => $item,
1002 'roud_trip' => $order->trip_type,
1003 'car_logo' => 'No',
1004 'car_type' => $order->car_type,
1005 'car_model' => $order->car_model,
1006 ];
1007
1008 if($order->status == 701){
1009 event(new OrderEvent($message));
1010 $resp = $order->save();
1011 }else{
1012 $resp = false;
1013 }
1014
1015 if($resp){
1016 return response()->json([
1017 'status'=>'Success',
1018 'status_code'=>200,
1019 'message'=>'Order Modified Successfully.'
1020 ]);
1021 }
1022 }
1023
1024
1025
1026 public function orderQueue(Request $request)
1027 {
1028 // dd(Auth::user()->id);
1029 if(Order::where('delivery_person_id',Auth::user()->id)->whereNotIn('status',['703','707','722','705'])->count() > 0){
1030 $order_queue = Order::select('*','user_id as user_name','user_id as mobile','uid as roud_trip','uid as car_model','uid as car_logo','uid as car_type','uid as time_stamp_one')->where('delivery_person_id',Auth::user()->id)->whereNotIn('status',['703','707','722','705'])->limit(25)->get();
1031
1032
1033 $orders = array();
1034 foreach ($order_queue as $order){
1035 // // Item Name
1036 if($order->category_id != 30){
1037 $items_name = ServiceCategory::where('id',$order->category_id)->first()->name;
1038 }else{
1039 $items_name = $order->other_item_name;
1040 }
1041
1042
1043
1044 if($order->service_id == 1){
1045 $car_type = NULL;
1046 $car_model = NULL;
1047 $round_trip = NULL;
1048 $car_type = NULL;
1049 $order_type = 1;
1050 $item = [array(
1051 'name'=>$items_name,
1052 'weight'=>$order->weight,
1053 'weight_desc'=>$order->weight.' Kgs',
1054 'info'=>NULL,
1055 'qty'=>1,
1056 'cost'=>$order->amount,
1057 'item_image'=>'https://www.stackroger.com/public/landingpage/images/services/logoopt.png'
1058 )];
1059 }elseif($order->service_id == 3){
1060 $drive = ServiceRequestHireDriver::where('order_id',$order->uid)->first();
1061 $round_trip = $order->trip_type;
1062 $car_type = $drive->car_type;
1063 $car_model = $drive->car_model;
1064 $order_type = 3;
1065 $item = [array(
1066 'name'=>'kkk',
1067 'weight'=>$order->weight,
1068 'weight_desc'=>'Kgs',
1069 'qty'=>1,
1070 'cost'=>$order->amount
1071 )];
1072 }elseif($order->service_id == 11){
1073 $drive = ServiceRequestHireDriver::where('order_id',$order->uid)->first();
1074 $round_trip = $order->trip_type;
1075 $car_type = $drive->car_type;
1076 $car_model = $drive->car_model;
1077 $order_type = 4;
1078 $item = [array(
1079 'name'=>'kkk',
1080 'weight'=>$order->weight,
1081 'weight_desc'=>'Kgs',
1082 'qty'=>1,
1083 'cost'=>$order->amount
1084 )];
1085 }
1086 else{
1087 $car_type = NULL;
1088 $car_model = NULL;
1089 $round_trip = NULL;
1090 $car_type = NULL;
1091 $order_type = 2;
1092 $item = array();
1093 $items = ServiceRequestPickFromStore::where('order_id',$order->uid)->get();
1094 foreach($items as $i){
1095 $b = Product::where('id',$i->product_id)->withTrashed()->first();
1096 $a = array(
1097 'id'=>$i->product_id,
1098 'name'=>ucwords($b->brand).' '.$i->product_name,
1099 'weight'=>$b->weight_cal * $i->qty,
1100 'weight_desc'=>$b->weight.' '.$b->weight_type,
1101 'qty'=>$i->qty,
1102 'info'=>$b->info,
1103 // 'cost'=>$b->mrp * $i->qty,
1104 'cost'=>$i->price * $i->qty,
1105 'item_image'=>url('/public/uploads/items/'.$b->product_id.'.jpg')
1106 );
1107 array_push($item,$a);
1108 }
1109
1110 if($order->custom_item != NULL){
1111 $ci = json_decode($order->custom_item);
1112 if($ci !='[NA]' and $ci != NULL){
1113 foreach ($ci as $cia) {
1114 $cim = array('id'=>0,'cost'=>0,'item_image'=> 'https://www.stackroger.com/public/uploads/category/Others.png');
1115 $cia->id = 0;
1116 $cia->cost = 0;
1117 $cia->item_image = 'https://www.stackroger.com/public/uploads/category/Others.png';
1118 $cia = (array)$cia;
1119 array_push($item,$cia);
1120 }
1121 }
1122 }
1123
1124 }
1125 // if(User::where('id',$order->delivery_person_id)->count() > 0){
1126 // $deliver_name = User::where('id',$order->delivery_person_id)->first()->name;
1127 // $delivery_phone = User::where('id',$order->delivery_person_id)->first()->mobile;
1128 // }else{
1129 // $deliver_name = 'User Was Deleted';
1130 // $delivery_phone = 'User Was Deleted';
1131 // }
1132 if(User::where('id',$order->user_id)->count() > 0){
1133 $user_name = User::where('id',$order->user_id)->first()->name;
1134 $user_mobile = User::where('id',$order->user_id)->first()->mobile;
1135 }else{
1136 $user_name = "name";
1137 $user_mobile = "mobile";
1138 }
1139 $message = [
1140 'order_id' =>$order->id,
1141 'uid' =>$order->uid,
1142 'change_status'=>1,
1143 'order_type' => $order_type,
1144 'status' => $order->status,
1145 'total_bill' => $order->amount,
1146 'pay_pick_up' => 0,
1147 'collect_from_customer' => 0,
1148 'scheduled_time' => ($order_type==3)?(Carbon::parse($order->schedule)->format('Y-m-d')).' '.(Carbon::parse($order->schedule_time)->format('h:i a')):$order->created_at,
1149 'stores'=>$order->preferred_stores,
1150 "delivery_name"=> $order->drop_name,
1151 "delivery_phone"=> $order->drop_phone,
1152 'from_address' => $order->from_location,
1153 'from_location' => $order->from_lat_lng,
1154 'time_stamp' =>$order->pick_name.', '.$order->pick_phone.','.$order->to_location.','.(($order_type==3)?(Carbon::parse($order->schedule)->format('Y-m-d')).' '.(Carbon::parse($order->schedule_time)->format('h:i a')):$order->created_at).': '.Service::where('id',$order->service_id)->first()->name,
1155 'weight_of_items' => $order->weight.'Kgs',
1156 'to_address' => $order->to_location,
1157 'to_location' => $order->to_lat_lng,
1158 'user_name' => $user_name,
1159 'mobile' => $user_mobile,
1160 'claimed_status' => 0,
1161 'claimed_counter' => $order->claimed_counter,
1162 'transaction_id'=>$order->transaction_id,
1163 'pick_name'=>$order->pick_name,
1164 'pick_phone'=>$order->pick_phone,
1165 'drop_name'=>$order->drop_name,
1166 'drop_phone'=>$order->drop_phone,
1167 'user_instructions'=>$order->user_instructions,
1168 'items_list' =>$item,
1169 'roud_trip' => $round_trip,
1170 'car_logo' => 'No',
1171 'car_type' => $car_type,
1172 'car_model' => $car_model,
1173 ];
1174 array_push($orders,$message);
1175 }
1176 return response()->json([
1177 'status'=>'Success',
1178 'status_code'=>200,
1179 'message'=>'Today\'s Order Queue.',
1180 'orders'=>$orders
1181 ]);
1182
1183 // return $order_queue;
1184 // $orders = array();
1185 // foreach ($order_queue as $order){
1186 // if($order->service_id == 1){
1187 // $order_type = 1;
1188 // $item = [array(
1189 // 'name'=>'kkk',
1190 // 'weight'=>$order->weight,
1191 // 'weight_desc'=>'Kgs',
1192 // 'qty'=>1,
1193 // 'cost'=>$order->amount
1194 // )];
1195 // }elseif($order->service_id == 3){
1196 // $order_type = 3;
1197 // $item = [array(
1198 // 'name'=>'kkk',
1199 // 'weight'=>$order->weight,
1200 // 'weight_desc'=>'Kgs',
1201 // 'qty'=>1,
1202 // 'cost'=>$order->amount
1203 // )];
1204 // }else{
1205 // $order_type = 2;
1206 // $item = array();
1207 // $items = ServiceRequestPickFromStore::where('order_id',$order->uid)->get();
1208 // foreach($items as $i){
1209 // $b = Product::where('id',$i->product_id)->first();
1210 // $a = array(
1211 // 'id'=>$i->product_id,
1212 // 'name'=>$i->product_name,
1213 // 'weight'=>$b->weight_cal * $i->qty,
1214 // 'weight_desc'=>'Kgs',
1215 // 'qty'=>$i->qty,
1216 // 'cost'=>$b->mrp
1217 // );
1218 // array_push($item,$a);
1219 // }
1220 // }
1221 // $message = [
1222 // 'order_id' =>$order->id,
1223 // 'uid' =>$order->uid,
1224 // 'order_type' => $order->service_id,
1225 // 'status' => $order->status,
1226 // 'total_bill' => $order->amount,
1227 // 'pay_pick_up' => 0,
1228 // 'collect_from_customer' => 0,
1229 // 'scheduled_time' => $order->created_at,
1230 // 'stores'=>$order->preferred_stores,
1231 // "delivery_name"=> User::where('id',$order->user_id)->first()->name,
1232 // "delivery_phone"=> User::where('id',$order->user_id)->first()->mobile,
1233 // 'from_address' => $order->from_location,
1234 // 'from_location' => $order->from_lat_lng,
1235 // 'time_stamp' => Carbon::parse($order->created_at)->format('D h:i a').': '.Service::where('id',$order->service_id)->first()->name,
1236 // 'weight_of_items' => $order->weight.'Kgs',
1237 // 'to_address' => $order->to_lat_lng,
1238 // 'to_location' => $order->to_location,
1239 // 'user_name' => User::where('id',$order->user_id)->first()->name,
1240 // 'mobile' => User::where('id',$order->user_id)->first()->mobile,
1241 // 'claimed_status' => 0,
1242 // 'claimed_counter' => 1,
1243 // 'items_list' =>$item,
1244 // 'roud_trip' => 'No',
1245 // 'car_logo' => 'No',
1246 // 'car_type' => 'Manual',
1247 // 'car_model' => 'Sedan',
1248 // ];
1249 // array_push($orders,$message);
1250 // }
1251
1252 return response()->json([
1253 'status'=>'Success',
1254 'status_code'=>200,
1255 'message'=>'Your Orders Queue Today.',
1256 'order_queue'=>$order_queue
1257 ]);
1258 }else{
1259 return response()->json([
1260 'status'=>'Error',
1261 'status_code'=>204,
1262 'message'=>'No Order Queue for You Today.'
1263 ]);
1264 }
1265 }
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281 public function getContact(Request $request)
1282 {
1283 // Get Delivery Boy or Driver Details API for User app
1284 if(Order::where('uid',$request->order_id)->count() > 0){
1285 $order = Order::where('uid',$request->order_id)->first()->delivery_person_id;
1286 if($order != NULL){
1287 $user = User::where('id',$order)->first();
1288
1289 $order_details = Order::where('uid',$request->order_id)->first();
1290 if($order_details->service_id == 1){
1291 $order_track = array(
1292 701=>'Order Placed',
1293 715=>'ChotaBeta Assigned',
1294 716=>'ChotaBeta is On The Way to Pick Up Order',
1295 718=>'ChotaBeta Picked up the Order',
1296 702=>'ChotaBeta is On the Way to Deliver the Order',
1297 719=>'ChotaBeta is Arrived at Delivery Location',
1298 703=>'ChotaBeta Delivered The Order',
1299 );
1300 $order_current = array();
1301 $order_next = array();
1302
1303 $position = array_search($order_details->status, array_keys($order_track));
1304
1305 // If a position is found, splice the array.
1306 if ($position !== false) {
1307 $order_next = array_splice($order_track, ($position + 1));
1308 }
1309
1310 $order_current = array_diff($order_track, $order_next);
1311 }else if($order_details->service_id != 1 or $order_details->service_id != 3){
1312 $order_track = array(
1313 701=>'Order Placed',
1314 715=>'ChotaBeta Assigned and Will Pick Up Your Order',
1315 718=>'ChotaBeta Picked up the Order',
1316 719=>'ChotaBeta is Arrived at Delivery Location',
1317 703=>'ChotaBeta Delivered The Order',
1318 );
1319 $order_current = array();
1320 $order_next = array();
1321
1322 $position = array_search($order_details->status, array_keys($order_track));
1323
1324 // If a position is found, splice the array.
1325 if ($position !== false) {
1326 $order_next = array_splice($order_track, ($position + 1));
1327 }
1328
1329 $order_current = array_diff($order_track, $order_next);
1330 }else{
1331 $order_track = array(
1332 701=>'Order Placed',
1333 715=>'ChotaBeta Assigned and Will Pick Up Your Order',
1334 718=>'ChotaBeta Picked up the Order',
1335 719=>'ChotaBeta is Arrived at Delivery Location',
1336 703=>'ChotaBeta Delivered The Order',
1337 );
1338 $order_current = array();
1339 $order_next = array();
1340
1341 $position = array_search($order_details->status, array_keys($order_track));
1342
1343 // If a position is found, splice the array.
1344 if ($position !== false) {
1345 $order_next = array_splice($order_track, ($position + 1));
1346 }
1347
1348 $order_current = array_diff($order_track, $order_next);
1349 }
1350
1351 return response()->json([
1352 'status'=>'Success',
1353 'status_code'=>200,
1354 'message'=>'Delivery Person Details',
1355 'delivery_or_driver_name'=>$user->name,
1356 'delivery_or_driver_contact_number'=>$user->mobile,
1357 'order_current_track'=>$order_current,
1358 'order_next_track'=>$order_next,
1359 ]);
1360 }else{
1361 return response()->json([
1362 'status'=>'Error',
1363 'status_code'=>204,
1364 'message'=>'Delivery Person Not Yet Assigned'
1365 ]);
1366 }
1367 }else{
1368 return response()->json([
1369 'status'=>'Error',
1370 'status_code'=>204,
1371 'message'=>'Invlaid Order ID'
1372 ]);
1373 }
1374 }
1375
1376
1377
1378
1379
1380
1381
1382
1383 // My orders, My Order Details and Cancellation reason predefined texts
1384 public function myOrders()
1385 {
1386 if(User::where('id',Auth::user()->id)->count() > 0){
1387 // dd('k');
1388 $open_orders = Order::select('id','uid','category_id as cat_image','service_id as service_name','category_id as category_name','updated_at as delivered_at','payment_mode','payment_status','amount','status','id as rating_status','transaction_id','delivery_person_id','user_instructions','custom_item','id as cancellation_requested','uid as order_details_particulars')->where('user_id',Auth::user()->id)->where('service_id','!=',3)->whereNotIn('status',[703,707,722])->where('cam_image',NULL)->orderBy('created_at','ASC')->get();
1389
1390
1391
1392 $delivered_orders = Order::select('id','uid','category_id as cat_image','service_id as service_name','category_id as category_name','updated_at as delivered_at','payment_mode','payment_status','amount','status','id as rating_status','transaction_id','delivery_person_id','user_instructions','custom_item','id as cancellation_requested','uid as order_details_particulars')->where('user_id',Auth::user()->id)->where('service_id','!=',3)->whereIn('status',[703,707])->where('cam_image',NULL)->orderBy('created_at','DESC')->get();
1393
1394 $cancellation_reason_predefined_texts = AppPreference::where('id',37)->first()->value;
1395 $cancellation_reason_predefined_texts = explode(';',$cancellation_reason_predefined_texts);
1396
1397
1398 $invoice_link_status = AppPreference::where('id',83)->first()->value;
1399
1400 return response()->json([
1401 'status' => 'Success',
1402 'status_code' => 200,
1403 'message' => 'orders',
1404 'cancellation_reason_predefined_texts' => $cancellation_reason_predefined_texts,
1405 'open_orders' => $open_orders,
1406 'delivered_orders' =>$delivered_orders,
1407 'invoice_link_status' =>$invoice_link_status,
1408 'invoice_link' =>url('/api/get-my-invoice/?order_id='),
1409 ]);
1410 }
1411 else{
1412 return response()->json([
1413 'status' => 'Error',
1414 'status_code' => 209,
1415 'message' => 'Please Login',
1416 ]);
1417 }
1418 }
1419
1420
1421 // My Drives, My Drive Details and Cancellation reason predefined texts
1422 public function myDrives()
1423 {
1424 if(Order::where('service_id',3)->where('user_id',Auth::user()->id)->count() > 0){
1425
1426 $my_active_drives = Order::select('id','user_id','uid as order_id','id as d_schedule_date','id as d_schedule_time','id as d_from_location','id as d_to_location','uid as d_estimated_fare','status','payment_mode','payment_status','amount','car_type as vehicle_type','car_model as vehicle_model','trip_type','id as rating_status','transaction_id','delivery_person_id','user_instructions','id as cancellation_requested','uid as order_details_particulars')->where('service_id',3)->where('user_id',Auth::user()->id)->whereNotIn('status',[703,707,705,722])->get();
1427
1428
1429 $my_past_drives = Order::select('id','user_id','uid as order_id','id as d_schedule_date','id as d_schedule_time','id as d_from_location','id as d_to_location','uid as d_estimated_fare','status','payment_mode','payment_status','amount','car_type as vehicle_type','car_model as vehicle_model','trip_type','id as rating_status','transaction_id','delivery_person_id','user_instructions','id as cancellation_requested','uid as order_details_particulars')->where('service_id',3)->where('user_id',Auth::user()->id)->whereIn('status',[703,707])->get();
1430
1431
1432 $cancellation_reason_predefined_texts = AppPreference::where('id',37)->first()->value;
1433 $cancellation_reason_predefined_texts = explode(';',$cancellation_reason_predefined_texts);
1434
1435 $invoice_link_status = AppPreference::where('id',83)->first()->value;
1436
1437 return response()->json([
1438 'status'=>'Success',
1439 'status_code'=>200,
1440 'message'=>'User My Drives.',
1441 'cancellation_reason_predefined_texts' => $cancellation_reason_predefined_texts,
1442 'active_drives'=>$my_active_drives,
1443 'past_drives'=>$my_past_drives,
1444 'invoice_link_status' =>$invoice_link_status,
1445 'invoice_link' =>url('/api/get-my-invoice/?order_id='),
1446 ]);
1447 }else{
1448 return response()->json([
1449 'status'=>'Error',
1450 'status_code'=>204,
1451 'message'=>'Orders Not Found.'
1452 ]);
1453 }
1454 }
1455}
1456