Jump to content

Charge to pilot to accept a pirep not scheduled


ARV187

Recommended Posts

Hi, I'm trying to charge to pilot to accept a pirep not scheduled.
I tried to follow an example, but I don't know what I must write in condition.
if ($event->pirep-> !scheduled)
Or how charge the Debit of pirep
$amount = pirep expenses/debit;

Thanks!

\app\Listeners\FreeFlight.php

<?php

namespace App\Listeners;

use App\Contracts\Listener;
use App\Events\Expenses;
use App\Events\PirepAccepted;
use App\Models\Enums\ExpenseType;
use App\Models\Expense;

class FreeFlight extends Listener
{
    public function handle(Expenses $event)
    {
        $expenses = [];
        $amount = pirep expenses/debit;

        if ($event->pirep-> !scheduled) { 
            return $expenses; 
        }
    
        $expenses[] = new Expense([
            'type'              => ExpenseType::FLIGHT,
            'amount'            => $amount,
            'transaction_group' => 'Free Flight',
            'name'              => 'Free flight Fee For Pirep='.$event->pirep->id,
            'multiplier'        => false,
            'charge_to_user'    => true
        ]);

        return $expenses;
    }
}

 

Edited by ARV187
Link to comment
Share on other sites

As this is a free flight, there will be no $pirep->flight_id , you can use that as your condition.

 

For the $amount, you need to find some fixed value (maybe you can calculate something with the flight time or the distance flown as per your needs) at least please explain your wish a little bit more... What does "pirep expenses/debit" mean ?

 

Rest looks ok though

Link to comment
Share on other sites

$amount = 300; // or calculate something with the flight time like round($event->pirep->flight_time * 5) this will result 300 for 60 mins

if (filled($event->pirep->flight_id)) {
    // There is a flight id present, so this is a scheduled flight.
    // return empty expense array, do nothing more.
    return $expenses; 
}

 

Or worse :) You can just take the pilot pay back for free flights :P By calculating exactly the same amount a pilot earns with flying that flight, or can be a nice admin, taking half of it back etc.

 

So in theory, that amount should be calculated and must be value.

Edited by DisposableHero
more info and thoughts added
Link to comment
Share on other sites

18 minutes ago, ARV187 said:

A full payback xD, but taking half can be good.

Where you get flight_time and others, database fields?
Or filled? I don't found that in \app\Events\PirepFiled.php

 

Well, to be honest I do not think you can get the full expenses of a pirep at that stage with the event. So forget charging the full debit total to the pilot. Nothing is impossible and you can do that of course but not with that expense listener and not at the moment it works. What you can do is, as I wrote earlier, charging the pilot with the half of his earnings per flight hours (nice admin). This means that they will earn less and this will make them fly scheduled routes more than free flights.

 

Technically you have the pirep model and all its relationships there in the event, no need to look other places or events to find things. It is all object/model oriented. So when you have the $event->pirep in your hands this means that you have the flight (if it is a scheduled one), you have the user and all of its relationships like rank , type ratings, subfleets he/she can fly etc. You need to study what those models provide to you, what are their relationships and what to they provide too for better understanding what is available and when, also this will give you a better picture to think about.

 

$event->pirep->flight_time , $event->pirep->distance , $event->pirep->user->rank->acars_base_pay_rate , $event->pirep->flight->flight_number are some examples for you.

 

To be practical, you can simply assign them to shorter names variables like

 

$pirep = $event->pirep;

$user = $pirep->user;

 

in the beginning of your code, so from that moment on you can use $pirep->flight_time instead of $event->pirep->flight_time or $user->rank directly when needed etc.

 

As far as I remember, the pay rate is calculated like this round($pirep->flight_time * ( $user->rank->acars_base_pay_rate / 60), 2) , you can divide that result by 2 and charge the half of his/her earnings back as a punishment of freely flying :D

 

https://github.com/nabeelio/phpvms/tree/dev/app/Models

 

You can check the models and their relationships from the link above (source code of v7)

 

Hope this helps, good luck

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...