Jbaltazar67 Posted September 24, 2021 Report Posted September 24, 2021 Hello , We offer cargo contracts to our pilots, they are paid by the KG transported, I am looking for how to create the tariff. Ex: 1kg loaded = 1.00 € if a sympathetic enough person could help me that would be great. Thanks in advance Quote
DisposableHero Posted September 24, 2021 Report Posted September 24, 2021 (edited) 9 hours ago, Jbaltazar67 said: Hello , We offer cargo contracts to our pilots, they are paid by the KG transported, I am looking for how to create the tariff. Ex: 1kg loaded = 1.00 € if a sympathetic enough person could help me that would be great. Thanks in advance It is not possible without writing your own code. Currently phpVMS v7 offers two ways to pay pilots; 1. By flight time 2. By each flight (fixed amount) What you need is a your own code, which basically will have two separate parts/actions; 1. Listen pirep events to get the amount of cargo they carried (pirep->fares and fare->count). Calculate the "pilot pay" for that amount/flight. 2. Send back that amount to phpVMS v7 as "pilot pay" for that pirep. For the first, you do not need to alter core code, you can do that without problems by event listeners. But for the second part, you need to alter core code to get and process your calculated pilot pay (which makes tracking updates hard). Alternatively, you can do the first part but skip the second part by paying the amount directly to pilot account after the calculation. This does not need altering core code, but no one will see the calculated pilot pay in pirep transactions, it may be only visible in admin / finances. Pilots will see increase in their current balance of course, but no details will be there. Or as a third solution, you can do the first part and change the second part a little bit. By sending that pilot pay "pilot bonus" as an "expense" (which is already built in to v7 core code so no need to alter it). While sending in the expense to v7, you need to credit the pilot account at the same time, so everyone will see it clearly when looking through pirep transactions. This probably be the nicest solution without altering the core code; 1a. Listen pirep events to get the amount of cargo they carried (pirep->fares and fare->count). Calculate the "pilot bonus" for that amount/flight. 1b. Send back that amount to phpVMS v7 as an additional "expense" for that pirep, credit pilot with the same amount. (This solution can be done in a single custom expense code) Hope this helps Edited September 24, 2021 by DisposableHero Quote
DisposableHero Posted September 24, 2021 Report Posted September 24, 2021 And of course, for both alternative and third solution there should be some checks and corrections (to handle rejected pirep situations, like taking the same amount back from the pilot if the pirep gets rejected after being accepted once). So the first solution is the safest way to do it 'cause phpVMS v7 will handle all the transactions (and accept/reject/accept cases). Second and third solutions may look nicer but both needs extra attention to detail. Quote
Jbaltazar67 Posted September 26, 2021 Author Report Posted September 26, 2021 Thank you for your answers DisposableHero. For the question of creating my own coding, is something I have never done. I don't even know where to find the files to modify :(. Finally I would like to add another question if you allow me: In the VA we charge the hard landing to the pilot, I found how to charge him, create the expense but it is deducted at each of his flights even if the landing rate is good, should we also create a code for that? PS: I use your modules to transfer phpvms on our server of the VA later so that everything works correctly. Many thanks to you Quote
DisposableHero Posted September 27, 2021 Report Posted September 27, 2021 Sounds like the Hard Landing expense you wrote is not checking the landing rate and charging the pilot always. Which is not good of course I do not know how you coded it or did found an example and used it as it is without modifications. So without seeing the expense you are using I can not help much. For the first question, I kindly do not advise messing up with core code so I will not point you to some core files/filenames You can however, try the second/third alternatives by using the same expense logic you used for the hard landing with some enhancements to achieve what you want Quote
Jbaltazar67 Posted September 27, 2021 Author Report Posted September 27, 2021 23 minutes ago, DisposableHero said: For the first question, I kindly do not advise messing up with core code so I will not point you to some core files/filenames Thank you Sir, it is not my intention to touch what I don't know as a French proverb says (touche pas à ça petit con )😀 encore merci à vous pour cette aide 😀 1 Quote
Jbaltazar67 Posted September 27, 2021 Author Report Posted September 27, 2021 (edited) I modified in PHPvms/App/Liteners the ExpenseListener file like this: /*$expenses[] = Hard Landing([ type' => ExpenseType::Hard Landing, amount' => 501, # €50000 transaction_group' => 'Debit', 'charge_to_user' => false, ]);*/ Edited September 27, 2021 by Jbaltazar67 ADD PNG Quote
DisposableHero Posted September 27, 2021 Report Posted September 27, 2021 There is no such expense type called Hard Landing and the transaction group you defined is wrong, also the Hard Landing([...]); will mean nothing for the code etc etc. The images you added in above message is not visible, even when I click I see a thumbnail of them, nothing readable <?php namespace App\Listeners; use App\Contracts\Listener; use App\Events\Expenses; class HardLanding_ChargePilot extends Listener { public function handle(Expenses $event) { $expenses = []; $amount = 250; // Do your check here, return an empty array if it is ok/below your check limit (no expense needed) if (abs($event->pirep->landing_rate) < 500) { return $expenses; } // You can even increase the punishment here by getting a ratio // So the harder they land, the higher the punishment $amount = round($amount * (abs($event->pirep->landing_rate) / 500)); // Prepare a New Expense here $expenses[] = new Expense([ 'type' => ExpenseType::FLIGHT, // This must be FLIGHT for a pirep related pilot charged expense 'amount' => $amount, // No need to add two more digitis, 150 is 150$ or 150Eur etc. 'transaction_group' => 'Hard Landing', // This is the group name, visible at financial report 'name' => 'Hard Landing Fee For Pirep='.$event->pirep->id, // Name is visible like a memo 'multiplier' => false, // or true (to use Subfleet GH Multiplier) 'charge_to_user' => true, // true to charge pilot, false to charge company ]); // If you wish you can create another expense here like the one above... // And finally return all new expenses you prepared return $expenses; } } As the example above, you need to follow some basic logic and do checks. If you do not follow standards it will either not work at all (errors out and causes problems) or at best it will not be applied by phpvms v7. Anyway, if you want to code your expenses or have modules/widgets etc you need to study phpvms first, to learn how it works, what it needs/expects. Quote
DisposableHero Posted September 27, 2021 Report Posted September 27, 2021 Imagine a scenario, in which pilot lands with -673 feet/minute. ( absolute value is 673 , using abs() makes it easier to handle things logically ) It will pass the first "if" check we put in 'cause we are checking anything above -500 feet/minute. Then it will reach the multiplier part, here our new $amount will be calculated like this $amount = 250 * (673 / 500) , means simply $amount = 250 * 1.346 , result will be rounded so it will be 337 ($ or Eur, your selected currency) The next step will prepare the proper Expense array to pass back, charge_to_user is true, this means that the amount will be taken from pilot's pocket In another flight, another pilot lands with -499 feet/minute, then nothing will happen and no expense will be charged to pilot 'cause it will be captured by the "if" check and it can not proceed further. Now, after the example above and basic explanation here, it is up to you and your imagination + skills 1 Quote
Jbaltazar67 Posted September 28, 2021 Author Report Posted September 28, 2021 Thank you very much Disposablehero for all your explanations and for taking your free time. It's a pity that we are not neighbors, it would be worth a drink or a coffee.😉 Quote
DisposableHero Posted September 28, 2021 Report Posted September 28, 2021 4 hours ago, Jbaltazar67 said: Thank you very much Disposablehero for all your explanations and for taking your free time. It's a pity that we are not neighbors, it would be worth a drink or a coffee.😉 My pleasure and thanks for kind thoughts, considered as if I had that drink 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.