diff --git a/VERSION.txt b/VERSION.txt index 7bcd0e3612da..6812f8122ef3 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.0.2 \ No newline at end of file +0.0.3 \ No newline at end of file diff --git a/app/Events/Invoice/InvoiceWasCancelled.php b/app/Events/Invoice/InvoiceWasCancelled.php new file mode 100644 index 000000000000..399738515c58 --- /dev/null +++ b/app/Events/Invoice/InvoiceWasCancelled.php @@ -0,0 +1,38 @@ +invoice = $invoice; + } +} diff --git a/app/Events/Invoice/InvoiceWasReversed.php b/app/Events/Invoice/InvoiceWasReversed.php new file mode 100644 index 000000000000..c23510014995 --- /dev/null +++ b/app/Events/Invoice/InvoiceWasReversed.php @@ -0,0 +1,38 @@ +invoice = $invoice; + } +} diff --git a/app/Listeners/Invoice/InvoiceCancelledActivity.php b/app/Listeners/Invoice/InvoiceCancelledActivity.php new file mode 100644 index 000000000000..3836f1c5ba9e --- /dev/null +++ b/app/Listeners/Invoice/InvoiceCancelledActivity.php @@ -0,0 +1,53 @@ +activity_repo = $activity_repo; + } + + /** + * Handle the event. + * + * @param object $event + * @return void + */ + public function handle($event) + { + $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::CANCELLED_INVOICE; + + $this->activity_repo->save($fields, $event->invoice); + } +} diff --git a/app/Listeners/Invoice/DeleteInvoiceActivity.php b/app/Listeners/Invoice/InvoiceDeletedActivity.php similarity index 96% rename from app/Listeners/Invoice/DeleteInvoiceActivity.php rename to app/Listeners/Invoice/InvoiceDeletedActivity.php index e8eff7a3b3e8..ee7ad683df5f 100644 --- a/app/Listeners/Invoice/DeleteInvoiceActivity.php +++ b/app/Listeners/Invoice/InvoiceDeletedActivity.php @@ -20,7 +20,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Support\Facades\Log; -class DeleteInvoiceActivity implements ShouldQueue +class InvoiceDeletedActivity implements ShouldQueue { protected $activity_repo; /** diff --git a/app/Listeners/Invoice/InvoiceReversedActivity.php b/app/Listeners/Invoice/InvoiceReversedActivity.php new file mode 100644 index 000000000000..3bf956058a69 --- /dev/null +++ b/app/Listeners/Invoice/InvoiceReversedActivity.php @@ -0,0 +1,53 @@ +activity_repo = $activity_repo; + } + + /** + * Handle the event. + * + * @param object $event + * @return void + */ + public function handle($event) + { + $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::REVERSED_INVOICE; + + $this->activity_repo->save($fields, $event->invoice); + } +} diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 155d6628d596..b37f25160d9a 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -69,6 +69,8 @@ class Activity extends StaticModel const MARK_SENT_INVOICE=53; const PAID_INVOICE=54; const EMAIL_INVOICE_FAILED=57; + const REVERSED_INVOICE=58; + const CANCELLED_INVOICE=59; protected $casts = [ 'is_system' => 'boolean', diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index df696168013c..b8ec2d7c005b 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -15,11 +15,13 @@ use App\Events\Client\ClientWasCreated; use App\Events\Company\CompanyWasDeleted; use App\Events\Contact\ContactLoggedIn; use App\Events\Credit\CreditWasMarkedSent; +use App\Events\Invoice\InvoiceWasCancelled; use App\Events\Invoice\InvoiceWasCreated; use App\Events\Invoice\InvoiceWasDeleted; use App\Events\Invoice\InvoiceWasEmailed; use App\Events\Invoice\InvoiceWasMarkedSent; use App\Events\Invoice\InvoiceWasPaid; +use App\Events\Invoice\InvoiceWasReversed; use App\Events\Invoice\InvoiceWasUpdated; use App\Events\Misc\InvitationWasViewed; use App\Events\Payment\PaymentWasCreated; @@ -40,7 +42,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\DeleteInvoiceActivity; +use App\Listeners\Invoice\InvoiceDeletedActivity; use App\Listeners\Invoice\InvoiceEmailActivity; use App\Listeners\Invoice\InvoiceEmailFailedActivity; use App\Listeners\Invoice\InvoiceEmailedNotification; @@ -139,7 +141,11 @@ class EventServiceProvider extends ServiceProvider InvoiceEmailFailedActivity::class, ], InvoiceWasDeleted::class => [ - DeleteInvoiceActivity::class, + InvoiceDeletedActivity::class, + ], + InvoiceWasReversed::class => [ + ], + InvoiceWasCancelled::class => [ ], InvitationWasViewed::class => [ InvitationViewedListener::class diff --git a/app/Services/Invoice/HandleCancellation.php b/app/Services/Invoice/HandleCancellation.php index 54be067f9085..1e1d7dab34ae 100644 --- a/app/Services/Invoice/HandleCancellation.php +++ b/app/Services/Invoice/HandleCancellation.php @@ -11,6 +11,7 @@ namespace App\Services\Invoice; +use App\Events\Invoice\InvoiceWasCancelled; use App\Events\Payment\PaymentWasCreated; use App\Factory\CreditFactory; use App\Factory\InvoiceItemFactory; @@ -52,6 +53,8 @@ class HandleCancellation extends AbstractService //adjust client balance $this->invoice->client->service()->updateBalance($adjustment)->save(); + event(new InvoiceWasCancelled($this->invoice)); + return $this->invoice; } diff --git a/app/Services/Invoice/HandleReversal.php b/app/Services/Invoice/HandleReversal.php index facf974fa41f..2fcf75d9e7fc 100644 --- a/app/Services/Invoice/HandleReversal.php +++ b/app/Services/Invoice/HandleReversal.php @@ -11,6 +11,7 @@ namespace App\Services\Invoice; +use App\Events\Invoice\InvoiceWasReversed; use App\Events\Payment\PaymentWasCreated; use App\Factory\CreditFactory; use App\Factory\InvoiceItemFactory; @@ -105,6 +106,8 @@ class HandleReversal extends AbstractService ->updatePaidToDate($total_paid*-1) ->save(); + event(new InvoiceWasReversed($this->invoice)); + return $this->invoice; //create a ledger row for this with the resulting Credit ( also include an explanation in the notes section ) diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index e2762695157a..0fc69762e05a 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -818,6 +818,8 @@ return [ 'activity_55' => ':contact replied ticket :ticket', 'activity_56' => ':user viewed ticket :ticket', 'activity_57' => ':invoice failed to send to :client', + 'activity_58' => ':user reversed invoice :invoice', + 'activity_59' => ':user cancelled invoice :invoice', 'payment' => 'Payment', 'system' => 'System',