Jump to content

About listener files


Jbaltazar67

Recommended Posts

I need to clear my head about the listener file .
After creating the expenses do I have to create them again in the admin panel of Phpvms?
I have tested without adding them but for example no hard landing charged to the driver, if someone could
If someone could put me on the right track before transmitting to the web master of our VA thank you very much

Link to comment
Share on other sites

  • ProAvia changed the title to About listener files

Nope, if the listener is coded properly it will work. No need to add it to expenses or somewhere else.

 

They are being checked when a pirep's finances are calculated (when it gets accepted and/or when you click recalculate finances button).

 

What I can think of now is;

 

1. Either the code of the custom expense you developed is wrong (thus being skipped by the core)

2. Or it is fine but the conditions you defined in it is not met, so it is not being applied

 

Hope this info helps

Link to comment
Share on other sites

Thanks DiposableHero ,

But nothing works for the moment, not easy when you are a beginner ,
what I did and I don't see any error, I publish here an example of what I want to put in place :

 

class ExpenseListener extends Listener
{    
    public function handle(Expenses $event)
    {
        $expenses = [];
        $amount = 5000;
        if (abs($event->pirep->landing_rate) < 500) {
          return $expenses;
        }
        
        $expenses[] = new Expense([
            'type'              => ExpenseType::FLIGHT,
            'amount'            => 5000,
            'transaction_group' => 'Hard Landing',
            'name'    => 'Hard Landing Fee For Pirep='.$event->pirep->id,
            'multiplier'        => false,
            'charge_to_user'    => true,
        ]);

        return $expenses;
    }
}

 

Thank you

Link to comment
Share on other sites

What is the filename ?

 

I think I explained it somewhere before, the filename and the class name should match and this is important ;) Also you should not be using the same class name twice or more, it may cause problems (like it being skipped or worse, erroring out all process and stopping)

 

Filename : HardLanding.php

Class Definition : class HardLanding extends Listener

 

class HardLanding extends Listener
{
    public function handle(Expenses $event)
    {
        $expenses = [];
        $amount = 5000;

        if (abs($event->pirep->landing_rate) < 500) { 
            return $expenses; 
        }
    
        $expenses[] = new Expense([
            'type'              => ExpenseType::FLIGHT,
            'amount'            => $amount,
            'transaction_group' => 'Hard Landing',
            'name'              => 'Hard Landing Fee For Pirep='.$event->pirep->id,
            'multiplier'        => false,
            'charge_to_user'    => true
        ]);

        return $expenses;
    }
}

 

Rest looks ok though.

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...