mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Invoice Activities (#3608)
* Version bump * reverse and cancelled activities * Invoice reversal/cancellation activities
This commit is contained in:
parent
213df6451f
commit
2103758d36
@ -1 +1 @@
|
||||
0.0.2
|
||||
0.0.3
|
38
app/Events/Invoice/InvoiceWasCancelled.php
Normal file
38
app/Events/Invoice/InvoiceWasCancelled.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?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\Invoice;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class InvoiceWasCancelled.
|
||||
*/
|
||||
class InvoiceWasCancelled
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Invoice
|
||||
*/
|
||||
public $invoice;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function __construct(Invoice $invoice)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
}
|
38
app/Events/Invoice/InvoiceWasReversed.php
Normal file
38
app/Events/Invoice/InvoiceWasReversed.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?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\Invoice;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class InvoiceWasReversed.
|
||||
*/
|
||||
class InvoiceWasReversed
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Invoice
|
||||
*/
|
||||
public $invoice;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function __construct(Invoice $invoice)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
}
|
53
app/Listeners/Invoice/InvoiceCancelledActivity.php
Normal file
53
app/Listeners/Invoice/InvoiceCancelledActivity.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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\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 InvoiceCancelledActivity 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)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
/**
|
53
app/Listeners/Invoice/InvoiceReversedActivity.php
Normal file
53
app/Listeners/Invoice/InvoiceReversedActivity.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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\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 InvoiceReversedActivity 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)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
@ -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',
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 )
|
||||
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user