Auto-set last used design as account default for non pro

This commit is contained in:
Hillel Coren 2016-01-10 20:17:55 +02:00
parent 36859c8262
commit 5fbe59fa8b
2 changed files with 26 additions and 7 deletions

View File

@ -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;

View File

@ -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',