• CBarcode
  • https://pub.dev/packages/flutter_barcode_scanner/versions/1.0.2

    app/http/controllers/api/Drivers/DriverDeliveryChargesController.php

    [php]
    namespace App\Http\Controllers\API\Driver;

    use Illuminate\Http\Request;
    use App\Http\Controllers\Controller;
    use Carbon\Carbon;
    USE DB;
    class DriverDeliveryChargesController extends Controller
    {
    function index(Request $request)
    {

    $manager_id = $request->id;

    $faq = DB::table(‘drivers’)
    ->leftjoin(‘driver_markets’,’driver_markets.user_id’,’=’,’drivers.user_id’)

    ->select(‘drivers.delivery_fee’)
    ->where(‘driver_markets.user_id’,’=’,$manager_id)
    ->get();

    return $this->sendResponse($faq->toArray(), ‘Faqs retrieved successfully’);

    }

    function display_detail(Request $request)
    {

    $manager_id = $request->id;

    $faq = DB::table(‘drivers’)
    ->leftjoin(‘driver_markets’,’driver_markets.user_id’,’=’,’drivers.user_id’)
    ->select(‘drivers.delivery_fee’,’drivers.total_orders’,’drivers.earning’,’drivers.distance_travelled’)
    ->where(‘driver_markets.user_id’,’=’,$manager_id)
    ->get();

    return $this->sendResponse($faq->toArray(), ‘Faqs retrieved successfully’);

    }

    function display_earnings(Request $request)
    {

    $manager_id = $request->id;

    $faq = DB::table(‘driver_earnings’)
    ->select(‘driver_earnings.*’)
    ->where(‘user_id’,’=’,$manager_id)
    ->get();

    return $this->sendResponse($faq->toArray(), ‘Faqs retrieved successfully’);

    }

    function update(Request $request)
    {

    $manager_id = $request->id;
    $earning = $request->earning;
    $total_orders = 1;
    $distance_travelled = $request->distance_travelled;
    $order_id = $request->order_id;
    $created_at = Carbon::now();
    $updated_at = Carbon::now();
    $faq = DB::table(‘drivers’)->where(‘user_id’,’=’,$manager_id)
    ->increment(‘earning’, $earning);
    $faq = DB::table(‘drivers’)->where(‘user_id’,’=’,$manager_id)
    ->increment( ‘total_orders’,$total_orders);
    $faq = DB::table(‘drivers’)->where(‘user_id’,’=’,$manager_id)
    ->increment( ‘distance_travelled’,$distance_travelled);

    $insert2 = $insert = DB::table(‘driver_earnings’)
    ->insert([
    ‘user_id’ => $manager_id,
    ‘delivery_fee’ => $earning,
    ‘distance_travelled’ => $distance_travelled,
    ‘order_id’ => $order_id,
    ‘created_at’=>$created_at,
    ‘updated_at’=>$updated_at
    ]);

    return $this->sendResponse($insert2, ‘Faqs retrieved successfully’);

    }

    }

    [/php]

    /APP/HTTP/Contollers/API/OrderAPIController.php

    [php]

    namespace App\Http\Controllers\API;

    use App\Criteria\Orders\OrdersOfStatusesCriteria;
    use DB;
    use App\Criteria\Orders\OrdersOfUserCriteria;
    use App\Criteria\Orders\OrdersOfUserZipCriteria;
    use App\Events\OrderChangedEvent;
    use App\Http\Controllers\Controller;
    use App\Models\Order;
    use App\Notifications\NewOrder;
    use App\Notifications\StatusChangedOrder;
    use App\Repositories\CartRepository;
    use App\Repositories\NotificationRepository;
    use App\Repositories\OrderRepository;
    use App\Repositories\PaymentRepository;
    use App\Repositories\ProductOrderRepository;
    use App\Repositories\UserRepository;
    use Braintree\Gateway;
    use Flash;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Log;
    use Illuminate\Support\Facades\Notification;
    use InfyOm\Generator\Criteria\LimitOffsetCriteria;
    use Prettus\Repository\Criteria\RequestCriteria;
    use Prettus\Repository\Exceptions\RepositoryException;
    use Prettus\Validator\Exceptions\ValidatorException;
    use Stripe\Token;

    /**
    * Class OrderController
    * @package App\Http\Controllers\API
    */
    class OrderAPIController extends Controller
    {
    /** @var OrderRepository */
    private $orderRepository;
    /** @var ProductOrderRepository */
    private $productOrderRepository;
    /** @var CartRepository */
    private $cartRepository;
    /** @var UserRepository */
    private $userRepository;
    /** @var PaymentRepository */
    private $paymentRepository;
    /** @var NotificationRepository */
    private $notificationRepository;

    /**
    * OrderAPIController constructor.
    * @param OrderRepository $orderRepo
    * @param ProductOrderRepository $productOrderRepository
    * @param CartRepository $cartRepo
    * @param PaymentRepository $paymentRepo
    * @param NotificationRepository $notificationRepo
    * @param UserRepository $userRepository
    */
    public function __construct(OrderRepository $orderRepo, ProductOrderRepository $productOrderRepository, CartRepository $cartRepo, PaymentRepository $paymentRepo, NotificationRepository $notificationRepo, UserRepository $userRepository)
    {
    $this->orderRepository = $orderRepo;
    $this->productOrderRepository = $productOrderRepository;
    $this->cartRepository = $cartRepo;
    $this->userRepository = $userRepository;
    $this->paymentRepository = $paymentRepo;
    $this->notificationRepository = $notificationRepo;
    }

    /**
    * Display a listing of the Order.
    * GET|HEAD /orders
    *
    * @param Request $request
    * @return \Illuminate\Http\JsonResponse
    */
    public function index(Request $request)
    {
    Log::info("Order API ");
    try {
    $this->orderRepository->pushCriteria(new RequestCriteria($request));
    $this->orderRepository->pushCriteria(new LimitOffsetCriteria($request));
    $this->orderRepository->pushCriteria(new OrdersOfStatusesCriteria($request));
    $this->orderRepository->pushCriteria(new OrdersOfUserCriteria(auth()->id()));
    } catch (RepositoryException $e) {
    return $this->sendError($e->getMessage());
    }
    $orders = $this->orderRepository->all();
    Log::info("UserId".auth()->id());

    return $this->sendResponse($orders->toArray(), ‘Orders retrieved successfully’);
    }

    /**
    * Display the specified Order.
    * GET|HEAD /orders/{id}
    *
    * @param int $id
    *
    * @return \Illuminate\Http\JsonResponse
    */
    public function show(Request $request, $id)
    {
    /** @var Order $order */
    if (!empty($this->orderRepository)) {
    try {
    $this->orderRepository->pushCriteria(new RequestCriteria($request));
    $this->orderRepository->pushCriteria(new LimitOffsetCriteria($request));
    } catch (RepositoryException $e) {
    return $this->sendError($e->getMessage());
    }
    $order = $this->orderRepository->findWithoutFail($id);
    }

    if (empty($order)) {
    return $this->sendError(‘Order not found’);
    }

    return $this->sendResponse($order->toArray(), ‘Order retrieved successfully’);

    }

    /**
    * Store a newly created Order in storage.
    *
    * @param Request $request
    *
    * @return \Illuminate\Http\JsonResponse
    */
    public function store(Request $request)
    {
    $payment = $request->only(‘payment’);
    if (isset($payment[‘payment’]) && $payment[‘payment’][‘method’]) {
    if ($payment[‘payment’][‘method’] == "Credit Card (Stripe Gateway)") {
    return $this->stripPayment($request);
    } else {
    return $this->cashPayment($request);

    }
    }
    }

    /**
    * @param Request $request
    * @return \Illuminate\Http\JsonResponse|mixed
    */
    private function stripPayment(Request $request)
    {
    $input = $request->all();
    $amount = 0;
    try {
    $user = $this->userRepository->findWithoutFail($input[‘user_id’]);
    if (empty($user)) {
    return $this->sendError(‘User not found’);
    }
    $stripeToken = Token::create(array(
    "card" => array(
    "number" => $input[‘stripe_number’],
    "exp_month" => $input[‘stripe_exp_month’],
    "exp_year" => $input[‘stripe_exp_year’],
    "cvc" => $input[‘stripe_cvc’],
    "name" => $user->name,
    )
    ));
    if ($stripeToken->created > 0) {
    if (empty($input[‘delivery_address_id’])) {
    $order = $this->orderRepository->create(
    $request->only(‘user_id’, ‘order_status_id’, ‘tax’, ‘hint’)
    );
    } else {
    $order = $this->orderRepository->create(
    $request->only(‘user_id’, ‘order_status_id’, ‘tax’, ‘delivery_address_id’, ‘delivery_fee’, ‘hint’)
    );
    }
    foreach ($input[‘products’] as $productOrder) {
    $productOrder[‘order_id’] = $order->id;
    $amount += $productOrder[‘price’] * $productOrder[‘quantity’];
    $this->productOrderRepository->create($productOrder);
    }
    $amount += $order->delivery_fee;
    $amountWithTax = $amount + ($amount * $order->tax / 100);
    $charge = $user->charge((int)($amountWithTax * 100), [‘source’ => $stripeToken]);
    $payment = $this->paymentRepository->create([
    "user_id" => $input[‘user_id’],
    "description" => trans("lang.payment_order_done"),
    "price" => $amountWithTax,
    "status" => $charge->status, // $charge->status
    "method" => $input[‘payment’][‘method’],
    ]);
    $this->orderRepository->update([‘payment_id’ => $payment->id], $order->id);

    $this->cartRepository->deleteWhere([‘user_id’ => $order->user_id]);

    $checkPincode = DB::table(‘orders’)
    ->join(‘product_orders’,’product_orders.order_id’,’=’,’orders.id’)
    ->join(‘products’,’products.id’,’=’,’product_orders.product_id’)
    ->join(‘markets’,’markets.id’,’=’,’products.market_id’)
    ->where(‘orders.id’,’=’,$order->id)
    ->select(‘markets.zipcode’)
    ->first();
    $zipcode =@$checkPincode->zipcode;

    $updateZipcode = DB::table(‘orders’)
    ->where(‘id’,’=’,$order->id)
    ->UPDATE([‘zipcode’=>$zipcode]);

    Notification::send($order->productOrders[0]->product->market->users, new NewOrder($order));
    }
    } catch (ValidatorException $e) {
    return $this->sendError($e->getMessage());
    }

    return $this->sendResponse($order->toArray(), __(‘lang.saved_successfully’, [‘operator’ => __(‘lang.order’)]));
    }

    /**
    * @param Request $request
    * @return \Illuminate\Http\JsonResponse|mixed
    */
    private function cashPayment(Request $request)
    {
    $input = $request->all();
    $amount = 0;
    try {
    $order = $this->orderRepository->create(
    $request->only(‘user_id’, ‘order_status_id’, ‘tax’, ‘delivery_address_id’, ‘delivery_fee’, ‘hint’)
    );
    Log::info($input[‘products’]);
    foreach ($input[‘products’] as $productOrder) {
    $productOrder[‘order_id’] = $order->id;
    $amount += $productOrder[‘price’] * $productOrder[‘quantity’];
    $this->productOrderRepository->create($productOrder);
    }
    $amount += $order->delivery_fee;
    $amountWithTax = $amount + ($amount * $order->tax / 100);
    $payment = $this->paymentRepository->create([
    "user_id" => $input[‘user_id’],
    "description" => trans("lang.payment_order_waiting"),
    "price" => $amountWithTax,
    "status" => ‘Waiting for Client’,
    "method" => $input[‘payment’][‘method’],
    ]);

    $this->orderRepository->update([‘payment_id’ => $payment->id], $order->id);

    $this->cartRepository->deleteWhere([‘user_id’ => $order->user_id]);

    $checkPincode = DB::table(‘orders’)
    ->join(‘product_orders’,’product_orders.order_id’,’=’,’orders.id’)
    ->join(‘products’,’products.id’,’=’,’product_orders.product_id’)
    ->join(‘markets’,’markets.id’,’=’,’products.market_id’)
    ->where(‘orders.id’,’=’,$order->id)
    ->select(‘markets.zipcode’)
    ->first();
    $zipcode =@$checkPincode->zipcode;

    $updateZipcode = DB::table(‘orders’)
    ->where(‘id’,’=’,$order->id)
    ->UPDATE([‘zipcode’=>$zipcode]);

    Notification::send($order->productOrders[0]->product->market->users, new NewOrder($order));

    } catch (ValidatorException $e) {
    return $this->sendError($e->getMessage());
    }

    return $this->sendResponse($order->toArray(), __(‘lang.saved_successfully’, [‘operator’ => __(‘lang.order’)]));
    }

    /**
    * Update the specified Order in storage.
    *
    * @param int $id
    * @param Request $request
    *
    * @return \Illuminate\Http\JsonResponse
    */
    public function update($id, Request $request)
    {
    $oldOrder = $this->orderRepository->findWithoutFail($id);
    if (empty($oldOrder)) {
    return $this->sendError(‘Order not found’);
    }
    $oldStatus = $oldOrder->payment->status;
    $input = $request->all();

    try {
    $order = $this->orderRepository->update($input, $id);
    if (isset($input[‘order_status_id’]) && $input[‘order_status_id’] == 5 && !empty($order)) {
    $this->paymentRepository->update([‘status’ => ‘Paid’], $order[‘payment_id’]);
    }
    event(new OrderChangedEvent($oldStatus, $order));

    if (setting(‘enable_notifications’, false)) {
    if (isset($input[‘order_status_id’]) && $input[‘order_status_id’] != $oldOrder->order_status_id) {
    Notification::send([$order->user], new StatusChangedOrder($order));
    }
    }

    } catch (ValidatorException $e) {
    return $this->sendError($e->getMessage());
    }

    return $this->sendResponse($order->toArray(), __(‘lang.saved_successfully’, [‘operator’ => __(‘lang.order’)]));
    }

    /**
    * driverprocessorders.
    *
    * @param int $id
    * @param Request $request
    *
    * @return \Illuminate\Http\JsonResponse
    */
    public function orderzip(Request $request){
    Log::info("Info AAyu");
    $user_id=request(‘driver_id’);
    try {
    $this->orderRepository->pushCriteria(new RequestCriteria($request));
    $this->orderRepository->pushCriteria(new LimitOffsetCriteria($request));
    $this->orderRepository->pushCriteria(new OrdersOfStatusesCriteria($request));
    $this->orderRepository->pushCriteria(new OrdersOfUserZipCriteria($user_id));
    } catch (RepositoryException $e) {
    return $this->sendError($e->getMessage());
    }
    $orders = $this->orderRepository->all();

    return $this->sendResponse($orders->toArray(), ‘Orders retrieved successfully’);
    }

    /**
    * Assigndriversof order.
    *
    * @param int $id
    * @param Request $request
    *
    * @return \Illuminate\Http\JsonResponse
    */
    public function assignDriver(Request $request){
    Log::info("Assign Driver");
    $order_id = request(‘order_id’);
    $driver_id = request(‘driver_id’);

    $updateOrder = DB::table(‘orders’)
    ->where(‘id’,$order_id)
    ->whereNull(‘driver_id’)
    ->update([‘driver_id’=>$driver_id,’order_status_id’=>3]);
    return response()->json([‘response’ => ‘success’, ‘message’ =>’Driver Assign Succesfully!’]);
    }

    /**
    * Update orderscanner.
    *
    * @param int $id
    * @param Request $request
    *
    * @return \Illuminate\Http\JsonResponse
    */
    public function orderscanner(Request $request){
    $status = request(‘status’);
    $flag = request(‘flag’);
    $order_id = request(‘order_id’);

    if($flag == 1){
    $barcode = explode(‘.’,$order_id);
    $order_id = $barcode[0];
    $sku_code = $barcode[1];
    Log::info("order Id ".$order_id);
    Log::info("Sku COde ".$sku_code);

    $checkDb=DB::table(‘orders’)
    ->join(‘product_orders’,’product_orders.order_id’,’=’,’orders.id’)
    ->join(‘products’,’products.id’,’=’,’product_orders.product_id’)
    ->where(‘products.sku_code’,’=’,$sku_code)
    ->where(‘orders.id’,’=’,$order_id)
    ->first();
    if($checkDb != null){
    $product_id = DB::table(‘product_orders’)
    ->join(‘products’,’products.id’,’=’,’product_orders.product_id’)
    ->where(‘products.sku_code’,’=’,$sku_code)
    ->where(‘product_orders.order_id’,’=’,$order_id)
    ->UPDATE([‘product_orders.order_status’=>’3’]);
    return response()->json([‘success’ => true, ‘message’ =>’Order Fetch Succesfully!’]);
    }
    return response()->json([‘success’ => false, ‘message’ =>’Order Not Found!’]);

    }else{
    $updateOrder = DB::table(‘orders’)
    ->where(‘id’,$order_id)
    ->UPDATE([‘order_status_id’=>$status]);
    return response()->json([‘success’ => true, ‘message’ =>’Order Updated Succesfully!’]);

    }
    }

    }
    [/php]

    /APP/HTTP/Contollers/API/OrderZipController.php

    [php]

    namespace App\Http\Controllers\API;

    use App\Criteria\Orders\OrdersOfStatusesCriteria;
    use App\Criteria\Orders\OrdersOfUserCriteria;
    use App\Criteria\Orders\OrdersOfUserZipCriteria;
    use App\Events\OrderChangedEvent;
    use App\Http\Controllers\Controller;
    use App\Models\Order;
    use App\Notifications\NewOrder;
    use App\Notifications\StatusChangedOrder;
    use App\Repositories\CartRepository;
    use App\Repositories\NotificationRepository;
    use App\Repositories\OrderRepository;
    use App\Repositories\PaymentRepository;
    use App\Repositories\ProductOrderRepository;
    use App\Repositories\UserRepository;
    use Braintree\Gateway;
    use Flash;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Log;
    use Illuminate\Support\Facades\Notification;
    use InfyOm\Generator\Criteria\LimitOffsetCriteria;
    use Prettus\Repository\Criteria\RequestCriteria;
    use Prettus\Repository\Exceptions\RepositoryException;
    use Prettus\Validator\Exceptions\ValidatorException;
    use Stripe\Token;

    /**
    * Class OrderController
    * @package App\Http\Controllers\API
    */
    class OrderZipController extends Controller
    {
    /** @var OrderRepository */
    private $orderRepository;
    /** @var ProductOrderRepository */
    private $productOrderRepository;
    /** @var CartRepository */
    private $cartRepository;
    /** @var UserRepository */
    private $userRepository;
    /** @var PaymentRepository */
    private $paymentRepository;
    /** @var NotificationRepository */
    private $notificationRepository;

    /**
    * OrderAPIController constructor.
    * @param OrderRepository $orderRepo
    * @param ProductOrderRepository $productOrderRepository
    * @param CartRepository $cartRepo
    * @param PaymentRepository $paymentRepo
    * @param NotificationRepository $notificationRepo
    * @param UserRepository $userRepository
    */
    public function __construct(OrderRepository $orderRepo, ProductOrderRepository $productOrderRepository, CartRepository $cartRepo, PaymentRepository $paymentRepo, NotificationRepository $notificationRepo, UserRepository $userRepository)
    {
    $this->orderRepository = $orderRepo;
    $this->productOrderRepository = $productOrderRepository;
    $this->cartRepository = $cartRepo;
    $this->userRepository = $userRepository;
    $this->paymentRepository = $paymentRepo;
    $this->notificationRepository = $notificationRepo;
    }

    public function orderzip(Request $request){
    Log::info("Info AAyu");
    try {
    $this->orderRepository->pushCriteria(new RequestCriteria($request));
    $this->orderRepository->pushCriteria(new LimitOffsetCriteria($request));
    $this->orderRepository->pushCriteria(new OrdersOfStatusesCriteria($request));
    $this->orderRepository->pushCriteria(new OrdersOfUserZipCriteria(auth()->id()));
    } catch (RepositoryException $e) {
    return $this->sendError($e->getMessage());
    }
    $orders = $this->orderRepository->all();

    return $this->sendResponse($orders->toArray(), ‘Orders retrieved successfully’);
    }

    public function assignDriver(Request $request){
    Log::info("Assign Driver");
    $order_id = request(‘order_id’);
    $driver_id = request(‘driver_id’);

    $updateOrder = DB::table(‘orders’)
    ->where(‘order_id’,$order_id)
    ->whereNull(‘driver_id’)
    ->update([‘driver_id’=>$driver_id]);
    return response()->json([‘response’ => ‘success’, ‘message’ =>’Driver_assign Succesfully!’]);
    }

    // public function orderscanner(Request $request){
    // $status = request(‘status’);
    // $flag = request(‘flag’);
    // $order_id = request(‘order_id’);
    // }

    }

    [/php]