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