mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Auto-set last used design as account default for non pro
This commit is contained in:
parent
36859c8262
commit
5fbe59fa8b
@ -1,7 +1,10 @@
|
||||
<?php namespace app\Listeners;
|
||||
|
||||
use Utils;
|
||||
use Auth;
|
||||
use App\Events\InvoiceWasEmailed;
|
||||
use App\Events\InvoiceWasUpdated;
|
||||
use App\Events\InvoiceWasCreated;
|
||||
use App\Events\PaymentWasCreated;
|
||||
use App\Events\PaymentWasDeleted;
|
||||
use App\Events\PaymentWasRestored;
|
||||
@ -9,15 +12,19 @@ use App\Events\InvoiceInvitationWasViewed;
|
||||
|
||||
class InvoiceListener
|
||||
{
|
||||
public function createdPayment(PaymentWasCreated $event)
|
||||
public function createdInvoice(InvoiceWasCreated $event)
|
||||
{
|
||||
$payment = $event->payment;
|
||||
$invoice = $payment->invoice;
|
||||
$adjustment = $payment->amount * -1;
|
||||
$partial = max(0, $invoice->partial - $payment->amount);
|
||||
if (Utils::isPro()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$invoice->updateBalances($adjustment, $partial);
|
||||
$invoice->updatePaidStatus();
|
||||
$invoice = $event->invoice;
|
||||
$account = Auth::user()->account;
|
||||
|
||||
if ($account->invoice_design_id != $invoice->invoice_design_id) {
|
||||
$account->invoice_design_id = $invoice->invoice_design_id;
|
||||
$account->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function updatedInvoice(InvoiceWasUpdated $event)
|
||||
@ -32,6 +39,17 @@ class InvoiceListener
|
||||
$invitation->markViewed();
|
||||
}
|
||||
|
||||
public function createdPayment(PaymentWasCreated $event)
|
||||
{
|
||||
$payment = $event->payment;
|
||||
$invoice = $payment->invoice;
|
||||
$adjustment = $payment->amount * -1;
|
||||
$partial = max(0, $invoice->partial - $payment->amount);
|
||||
|
||||
$invoice->updateBalances($adjustment, $partial);
|
||||
$invoice->updatePaidStatus();
|
||||
}
|
||||
|
||||
public function deletedPayment(PaymentWasDeleted $event)
|
||||
{
|
||||
$payment = $event->payment;
|
||||
|
@ -31,6 +31,7 @@ class EventServiceProvider extends ServiceProvider {
|
||||
'App\Events\InvoiceWasCreated' => [
|
||||
'App\Listeners\ActivityListener@createdInvoice',
|
||||
'App\Listeners\SubscriptionListener@createdInvoice',
|
||||
'App\Listeners\InvoiceListener@createdInvoice',
|
||||
],
|
||||
'App\Events\InvoiceWasUpdated' => [
|
||||
'App\Listeners\ActivityListener@updatedInvoice',
|
||||
|
Loading…
x
Reference in New Issue
Block a user