diff --git a/app/Events/Payment/PaymentWasUpdated.php b/app/Events/Payment/PaymentWasUpdated.php new file mode 100644 index 000000000000..054e0a9f461b --- /dev/null +++ b/app/Events/Payment/PaymentWasUpdated.php @@ -0,0 +1,45 @@ +payment = $payment; + $this->company = $company; + $this->event_vars = $event_vars; + } +} diff --git a/app/Listeners/Activity/PaymentArchivedActivity.php b/app/Listeners/Activity/PaymentArchivedActivity.php new file mode 100644 index 000000000000..816e257efc3f --- /dev/null +++ b/app/Listeners/Activity/PaymentArchivedActivity.php @@ -0,0 +1,70 @@ +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); + + } +} diff --git a/app/Listeners/Activity/PaymentUpdatedActivity.php b/app/Listeners/Activity/PaymentUpdatedActivity.php new file mode 100644 index 000000000000..5185b562147c --- /dev/null +++ b/app/Listeners/Activity/PaymentUpdatedActivity.php @@ -0,0 +1,70 @@ +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); + // } + } +} diff --git a/app/Listeners/Invoice/InvoiceArchivedActivity.php b/app/Listeners/Invoice/InvoiceArchivedActivity.php new file mode 100644 index 000000000000..c38db35b7589 --- /dev/null +++ b/app/Listeners/Invoice/InvoiceArchivedActivity.php @@ -0,0 +1,57 @@ +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); + } +} diff --git a/app/Models/Activity.php b/app/Models/Activity.php index d31e92194d92..7e08f34ce7a7 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -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; diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index ff955841ca74..9ba87ca4dc78 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -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 => [