mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 12:42:36 +01:00
Fix for invoice items in subscriptions
This commit is contained in:
parent
a456e484ba
commit
04884e8e40
29
app/Events/InvoiceItemsWereCreated.php
Normal file
29
app/Events/InvoiceItemsWereCreated.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class InvoiceItemsWereCreated.
|
||||
*/
|
||||
class InvoiceItemsWereCreated extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Invoice
|
||||
*/
|
||||
public $invoice;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function __construct(Invoice $invoice)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
}
|
29
app/Events/InvoiceItemsWereUpdated.php
Normal file
29
app/Events/InvoiceItemsWereUpdated.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class InvoiceItemsWereUpdated.
|
||||
*/
|
||||
class InvoiceItemsWereUpdated extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Invoice
|
||||
*/
|
||||
public $invoice;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function __construct(Invoice $invoice)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
}
|
24
app/Events/QuoteItemsWereCreated.php
Normal file
24
app/Events/QuoteItemsWereCreated.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class QuoteItemsWereCreated.
|
||||
*/
|
||||
class QuoteItemsWereCreated extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
public $quote;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $quote
|
||||
*/
|
||||
public function __construct($quote)
|
||||
{
|
||||
$this->quote = $quote;
|
||||
}
|
||||
}
|
24
app/Events/QuoteItemsWereUpdated.php
Normal file
24
app/Events/QuoteItemsWereUpdated.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class QuoteItemsWereUpdated.
|
||||
*/
|
||||
class QuoteItemsWereUpdated extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
public $quote;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $quote
|
||||
*/
|
||||
public function __construct($quote)
|
||||
{
|
||||
$this->quote = $quote;
|
||||
}
|
||||
}
|
@ -5,13 +5,13 @@ namespace App\Listeners;
|
||||
use App\Events\ClientWasCreated;
|
||||
use App\Events\CreditWasCreated;
|
||||
use App\Events\ExpenseWasCreated;
|
||||
use App\Events\InvoiceWasCreated;
|
||||
use App\Events\QuoteItemsWereCreated;
|
||||
use App\Events\QuoteItemsWereUpdated;
|
||||
use App\Events\InvoiceWasDeleted;
|
||||
use App\Events\InvoiceWasUpdated;
|
||||
use App\Events\PaymentWasCreated;
|
||||
use App\Events\QuoteWasCreated;
|
||||
use App\Events\InvoiceItemsWereCreated;
|
||||
use App\Events\InvoiceItemsWereUpdated;
|
||||
use App\Events\QuoteWasDeleted;
|
||||
use App\Events\QuoteWasUpdated;
|
||||
use App\Events\VendorWasCreated;
|
||||
use App\Models\EntityModel;
|
||||
use App\Ninja\Serializers\ArraySerializer;
|
||||
@ -36,15 +36,6 @@ class SubscriptionListener
|
||||
$this->checkSubscriptions(EVENT_CREATE_CLIENT, $event->client, $transformer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QuoteWasCreated $event
|
||||
*/
|
||||
public function createdQuote(QuoteWasCreated $event)
|
||||
{
|
||||
$transformer = new InvoiceTransformer($event->quote->account);
|
||||
$this->checkSubscriptions(EVENT_CREATE_QUOTE, $event->quote, $transformer, ENTITY_CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PaymentWasCreated $event
|
||||
*/
|
||||
@ -54,15 +45,6 @@ class SubscriptionListener
|
||||
$this->checkSubscriptions(EVENT_CREATE_PAYMENT, $event->payment, $transformer, [ENTITY_CLIENT, ENTITY_INVOICE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InvoiceWasCreated $event
|
||||
*/
|
||||
public function createdInvoice(InvoiceWasCreated $event)
|
||||
{
|
||||
$transformer = new InvoiceTransformer($event->invoice->account);
|
||||
$this->checkSubscriptions(EVENT_CREATE_INVOICE, $event->invoice, $transformer, ENTITY_CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CreditWasCreated $event
|
||||
*/
|
||||
@ -84,15 +66,42 @@ class SubscriptionListener
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InvoiceWasCreated $event
|
||||
*/
|
||||
public function createdInvoice(InvoiceItemsWereCreated $event)
|
||||
{
|
||||
$transformer = new InvoiceTransformer($event->invoice->account);
|
||||
$this->checkSubscriptions(EVENT_CREATE_INVOICE, $event->invoice, $transformer, ENTITY_CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InvoiceWasUpdated $event
|
||||
*/
|
||||
public function updatedInvoice(InvoiceWasUpdated $event)
|
||||
public function updatedInvoice(InvoiceItemsWereUpdated $event)
|
||||
{
|
||||
$transformer = new InvoiceTransformer($event->invoice->account);
|
||||
$this->checkSubscriptions(EVENT_UPDATE_INVOICE, $event->invoice, $transformer, ENTITY_CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QuoteWasCreated $event
|
||||
*/
|
||||
public function createdQuote(QuoteItemsWereCreated $event)
|
||||
{
|
||||
$transformer = new InvoiceTransformer($event->quote->account);
|
||||
$this->checkSubscriptions(EVENT_CREATE_QUOTE, $event->quote, $transformer, ENTITY_CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QuoteWasUpdated $event
|
||||
*/
|
||||
public function updatedQuote(QuoteItemsWereUpdated $event)
|
||||
{
|
||||
$transformer = new InvoiceTransformer($event->quote->account);
|
||||
$this->checkSubscriptions(EVENT_UPDATE_QUOTE, $event->quote, $transformer, ENTITY_CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InvoiceWasDeleted $event
|
||||
*/
|
||||
@ -102,15 +111,6 @@ class SubscriptionListener
|
||||
$this->checkSubscriptions(EVENT_DELETE_INVOICE, $event->invoice, $transformer, ENTITY_CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QuoteWasUpdated $event
|
||||
*/
|
||||
public function updatedQuote(QuoteWasUpdated $event)
|
||||
{
|
||||
$transformer = new InvoiceTransformer($event->quote->account);
|
||||
$this->checkSubscriptions(EVENT_UPDATE_QUOTE, $event->quote, $transformer, ENTITY_CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InvoiceWasDeleted $event
|
||||
*/
|
||||
@ -129,12 +129,12 @@ class SubscriptionListener
|
||||
private function checkSubscriptions($eventId, $entity, $transformer, $include = '')
|
||||
{
|
||||
if (! EntityModel::$notifySubscriptions) {
|
||||
return;
|
||||
//return;
|
||||
}
|
||||
|
||||
$subscription = $entity->account->getSubscription($eventId);
|
||||
|
||||
if ($subscription) {
|
||||
if (true || $subscription) {
|
||||
$manager = new Manager();
|
||||
$manager->setSerializer(new ArraySerializer());
|
||||
$manager->parseIncludes($include);
|
||||
@ -146,8 +146,8 @@ class SubscriptionListener
|
||||
if (isset($data['client_id'])) {
|
||||
$data['client_name'] = $entity->client->getDisplayName();
|
||||
}
|
||||
|
||||
Utils::notifyZapier($subscription, $data);
|
||||
\Log::info($data);
|
||||
//Utils::notifyZapier($subscription, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Ninja\Repositories;
|
||||
|
||||
use App\Events\InvoiceWasCreated;
|
||||
use App\Events\InvoiceWasUpdated;
|
||||
use App\Events\QuoteWasCreated;
|
||||
use App\Events\QuoteWasUpdated;
|
||||
use App\Events\QuoteItemsWereCreated;
|
||||
use App\Events\QuoteItemsWereUpdated;
|
||||
use App\Events\InvoiceItemsWereCreated;
|
||||
use App\Events\InvoiceItemsWereUpdated;
|
||||
use App\Jobs\SendInvoiceEmail;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
@ -693,11 +693,13 @@ class InvoiceRepository extends BaseRepository
|
||||
$invoice->invoice_items()->save($invoiceItem);
|
||||
}
|
||||
|
||||
$invoice->load('invoice_items');
|
||||
|
||||
if (Auth::check()) {
|
||||
$invoice = $this->saveInvitations($invoice);
|
||||
}
|
||||
|
||||
//$this->dispachEvents($invoice);
|
||||
$this->dispatchEvents($invoice);
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
@ -740,19 +742,19 @@ class InvoiceRepository extends BaseRepository
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
private function dispachEvents($invoice)
|
||||
private function dispatchEvents($invoice)
|
||||
{
|
||||
if ($invoice->isType(INVOICE_TYPE_QUOTE)) {
|
||||
if ($invoice->wasRecentlyCreated) {
|
||||
event(new QuoteWasCreated($invoice));
|
||||
event(new QuoteItemsWereCreated($invoice));
|
||||
} else {
|
||||
event(new QuoteWasUpdated($invoice));
|
||||
event(new QuoteItemsWereUpdated($invoice));
|
||||
}
|
||||
} else {
|
||||
if ($invoice->wasRecentlyCreated) {
|
||||
event(new InvoiceWasCreated($invoice));
|
||||
event(new InvoiceItemsWereCreated($invoice));
|
||||
} else {
|
||||
event(new InvoiceWasUpdated($invoice));
|
||||
event(new InvoiceItemsWereUpdated($invoice));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1105,7 +1107,6 @@ class InvoiceRepository extends BaseRepository
|
||||
if ($item['invoice_item_type_id'] == INVOICE_ITEM_TYPE_PENDING_GATEWAY_FEE) {
|
||||
unset($data['invoice_items'][$key]);
|
||||
$this->save($data, $invoice);
|
||||
$invoice->load('invoice_items');
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1142,7 +1143,6 @@ class InvoiceRepository extends BaseRepository
|
||||
$data['invoice_items'][] = $item;
|
||||
|
||||
$this->save($data, $invoice);
|
||||
$invoice->load('invoice_items');
|
||||
}
|
||||
|
||||
public function findPhonetically($invoiceNumber)
|
||||
|
@ -32,12 +32,16 @@ class EventServiceProvider extends ServiceProvider
|
||||
// Invoices
|
||||
'App\Events\InvoiceWasCreated' => [
|
||||
'App\Listeners\ActivityListener@createdInvoice',
|
||||
'App\Listeners\SubscriptionListener@createdInvoice',
|
||||
'App\Listeners\InvoiceListener@createdInvoice',
|
||||
],
|
||||
'App\Events\InvoiceWasUpdated' => [
|
||||
'App\Listeners\ActivityListener@updatedInvoice',
|
||||
'App\Listeners\InvoiceListener@updatedInvoice',
|
||||
],
|
||||
'App\Events\InvoiceItemsWereCreated' => [
|
||||
'App\Listeners\SubscriptionListener@createdInvoice',
|
||||
],
|
||||
'App\Events\InvoiceItemsWereUpdated' => [
|
||||
'App\Listeners\SubscriptionListener@updatedInvoice',
|
||||
],
|
||||
'App\Events\InvoiceWasArchived' => [
|
||||
@ -66,10 +70,14 @@ class EventServiceProvider extends ServiceProvider
|
||||
// Quotes
|
||||
'App\Events\QuoteWasCreated' => [
|
||||
'App\Listeners\ActivityListener@createdQuote',
|
||||
'App\Listeners\SubscriptionListener@createdQuote',
|
||||
],
|
||||
'App\Events\QuoteWasUpdated' => [
|
||||
'App\Listeners\ActivityListener@updatedQuote',
|
||||
],
|
||||
'App\Events\QuoteItemsWereCreated' => [
|
||||
'App\Listeners\SubscriptionListener@createdQuote',
|
||||
],
|
||||
'App\Events\QuoteItemsWereUpdated' => [
|
||||
'App\Listeners\SubscriptionListener@updatedQuote',
|
||||
],
|
||||
'App\Events\QuoteWasArchived' => [
|
||||
|
Loading…
Reference in New Issue
Block a user