1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Adding more event listeners

This commit is contained in:
David Bomba 2020-07-17 11:28:54 +10:00
parent da88319418
commit 1b79188b35
6 changed files with 263 additions and 7 deletions

View File

@ -0,0 +1,45 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Payment;
use App\Models\Company;
use App\Models\Payment;
use Illuminate\Queue\SerializesModels;
/**
* Class PaymentWasUpdated.
*/
class PaymentWasUpdated
{
use SerializesModels;
/**
* @var Payment
*/
public $payment;
public $company;
public $event_vars;
/**
* Create a new event instance.
*
* @param Payment $payment
*/
public function __construct(Payment $payment, Company $company, array $event_vars)
{
$this->payment = $payment;
$this->company = $company;
$this->event_vars = $event_vars;
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class PaymentArchivedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$payment = $event->payment;
$invoices = $payment->invoices;
$fields = new \stdClass;
$fields->payment_id = $payment->id;
$fields->user_id = $payment->user_id;
$fields->company_id = $payment->company_id;
$fields->activity_type_id = Activity::ARCHIVE_PAYMENT;
// foreach ($invoices as $invoice) { //todo we may need to add additional logic if in the future we apply payments to other entity Types, not just invoices
// $fields->invoice_id = $invoice->id;
// $this->activity_repo->save($fields, $invoice, $event->event_vars);
// }
// if (count($invoices) == 0) {
// $this->activity_repo->save($fields, $payment, $event->event_vars);
// }
$this->activity_repo->save($fields, $payment, $event->event_vars);
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class PaymentUpdatedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$payment = $event->payment;
$invoices = $payment->invoices;
$fields = new \stdClass;
$fields->payment_id = $payment->id;
$fields->user_id = $payment->user_id;
$fields->company_id = $payment->company_id;
$fields->activity_type_id = Activity::UPDATE_PAYMENT;
$this->activity_repo->save($fields, $payment, $event->event_vars);
// foreach ($invoices as $invoice) {
// //todo we may need to add additional logic if in the future we apply payments to other entity Types, not just invoices
// $fields->invoice_id = $invoice->id;
// $this->activity_repo->save($fields, $invoice, $event->event_vars);
// }
// if (count($invoices) == 0) {
// $this->activity_repo->save($fields, $payment, $event->event_vars);
// }
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Invoice;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\ClientContact;
use App\Models\InvoiceInvitation;
use App\Repositories\ActivityRepository;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
class InvoiceArchivedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new \stdClass;
$fields->invoice_id = $event->invoice->id;
$fields->user_id = $event->invoice->user_id;
$fields->company_id = $event->invoice->company_id;
$fields->activity_type_id = Activity::ARCHIVE_INVOICE;
$this->activity_repo->save($fields, $event->invoice, $event->event_vars);
}
}

View File

@ -21,13 +21,13 @@ class Activity extends StaticModel
const CREATE_INVOICE=4; //
const UPDATE_INVOICE=5; //
const EMAIL_INVOICE=6; //
const VIEW_INVOICE=7;
const ARCHIVE_INVOICE=8;
const DELETE_INVOICE=9;
const CREATE_PAYMENT=10;
const UPDATE_PAYMENT=11;
const ARCHIVE_PAYMENT=12;
const DELETE_PAYMENT=13;
const VIEW_INVOICE=7; //
const ARCHIVE_INVOICE=8; //
const DELETE_INVOICE=9; //
const CREATE_PAYMENT=10; //
const UPDATE_PAYMENT=11; //
const ARCHIVE_PAYMENT=12; //
const DELETE_PAYMENT=13; //
const CREATE_CREDIT=14;
const UPDATE_CREDIT=15;
const ARCHIVE_CREDIT=16;

View File

@ -24,6 +24,7 @@ use App\Events\Contact\ContactLoggedIn;
use App\Events\Credit\CreditWasEmailedAndFailed;
use App\Events\Credit\CreditWasMarkedSent;
use App\Events\Design\DesignWasArchived;
use App\Events\Invoice\InvoiceWasArchived;
use App\Events\Invoice\InvoiceWasCancelled;
use App\Events\Invoice\InvoiceWasCreated;
use App\Events\Invoice\InvoiceWasDeleted;
@ -34,9 +35,11 @@ use App\Events\Invoice\InvoiceWasReversed;
use App\Events\Invoice\InvoiceWasUpdated;
use App\Events\Invoice\InvoiceWasViewed;
use App\Events\Misc\InvitationWasViewed;
use App\Events\Payment\PaymentWasArchived;
use App\Events\Payment\PaymentWasCreated;
use App\Events\Payment\PaymentWasDeleted;
use App\Events\Payment\PaymentWasRefunded;
use App\Events\Payment\PaymentWasUpdated;
use App\Events\Payment\PaymentWasVoided;
use App\Events\Quote\QuoteWasApproved;
use App\Events\User\UserLoggedIn;
@ -48,6 +51,7 @@ use App\Listeners\Activity\DeleteClientActivity;
use App\Listeners\Activity\PaymentCreatedActivity;
use App\Listeners\Activity\PaymentDeletedActivity;
use App\Listeners\Activity\PaymentRefundedActivity;
use App\Listeners\Activity\PaymentUpdatedActivity;
use App\Listeners\Activity\PaymentVoidedActivity;
use App\Listeners\Activity\RestoreClientActivity;
use App\Listeners\Contact\UpdateContactLastLogin;
@ -56,6 +60,7 @@ use App\Listeners\Invoice\CreateInvoiceActivity;
use App\Listeners\Invoice\CreateInvoiceHtmlBackup;
use App\Listeners\Invoice\CreateInvoiceInvitation;
use App\Listeners\Invoice\CreateInvoicePdf;
use App\Listeners\Invoice\InvoiceArchivedActivity;
use App\Listeners\Invoice\InvoiceDeletedActivity;
use App\Listeners\Invoice\InvoiceEmailActivity;
use App\Listeners\Invoice\InvoiceEmailFailedActivity;
@ -99,6 +104,12 @@ class EventServiceProvider extends ServiceProvider
PaymentWasDeleted::class => [
PaymentDeletedActivity::class,
],
PaymentWasArchived::class => [
PaymentArchivedActivity::class,
],
PaymentWasUpdated::class => [
PaymentUpdatedActivity::class,
],
PaymentWasRefunded::class => [
PaymentRefundedActivity::class,
],
@ -174,6 +185,9 @@ class EventServiceProvider extends ServiceProvider
InvoiceWasDeleted::class => [
InvoiceDeletedActivity::class,
],
InvoiceWasArchived::class => [
InvoiceArchivedActivity::class,
],
InvoiceWasReversed::class => [
],
InvoiceWasCancelled::class => [