ARV187 Posted February 16, 2022 Report Posted February 16, 2022 (edited) 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 February 16, 2022 by ARV187 Quote
DisposableHero Posted February 16, 2022 Report Posted February 16, 2022 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 Quote
DisposableHero Posted February 17, 2022 Report Posted February 17, 2022 (edited) $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 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 February 17, 2022 by DisposableHero more info and thoughts added Quote
ARV187 Posted February 17, 2022 Author Report Posted February 17, 2022 I'm thinking in this debit xD 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 Quote
DisposableHero Posted February 17, 2022 Report Posted February 17, 2022 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 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 Quote
ARV187 Posted February 17, 2022 Author Report Posted February 17, 2022 (edited) Thank you, it has been very helpful to start. P.S: Listeners not working. Edited March 5, 2022 by ARV187 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.