mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 03:24:35 -04:00
Fixes for events
This commit is contained in:
parent
b28ec2ace2
commit
f63323e4e2
@ -11,7 +11,9 @@
|
|||||||
|
|
||||||
namespace App\Repositories;
|
namespace App\Repositories;
|
||||||
|
|
||||||
|
use App\Events\Credit\CreditWasUpdated;
|
||||||
use App\Events\Invoice\InvoiceWasUpdated;
|
use App\Events\Invoice\InvoiceWasUpdated;
|
||||||
|
use App\Events\Quote\QuoteWasUpdated;
|
||||||
use App\Factory\InvoiceInvitationFactory;
|
use App\Factory\InvoiceInvitationFactory;
|
||||||
use App\Factory\QuoteInvitationFactory;
|
use App\Factory\QuoteInvitationFactory;
|
||||||
use App\Jobs\Product\UpdateOrCreateProduct;
|
use App\Jobs\Product\UpdateOrCreateProduct;
|
||||||
@ -192,10 +194,6 @@ class BaseRepository
|
|||||||
*/
|
*/
|
||||||
protected function alternativeSave($data, $model)
|
protected function alternativeSave($data, $model)
|
||||||
{
|
{
|
||||||
$new_entity = false;
|
|
||||||
|
|
||||||
if(!$model->id)
|
|
||||||
$new_entity = true;
|
|
||||||
|
|
||||||
$class = new ReflectionClass($model);
|
$class = new ReflectionClass($model);
|
||||||
|
|
||||||
@ -234,9 +232,6 @@ class BaseRepository
|
|||||||
$model->fill($tmp_data);
|
$model->fill($tmp_data);
|
||||||
$model->save();
|
$model->save();
|
||||||
|
|
||||||
if($new_entity)
|
|
||||||
$this->newEntityEvent($model);
|
|
||||||
|
|
||||||
if (array_key_exists('documents', $data)) {
|
if (array_key_exists('documents', $data)) {
|
||||||
$this->saveDocuments($data['documents'], $model);
|
$this->saveDocuments($data['documents'], $model);
|
||||||
}
|
}
|
||||||
@ -302,6 +297,7 @@ class BaseRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($class->name == Invoice::class) {
|
if ($class->name == Invoice::class) {
|
||||||
|
|
||||||
if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) {
|
if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) {
|
||||||
info("inside ledger updating");
|
info("inside ledger updating");
|
||||||
$model->ledger()->updateInvoiceBalance(($state['finished_amount'] - $state['starting_amount']));
|
$model->ledger()->updateInvoiceBalance(($state['finished_amount'] - $state['starting_amount']));
|
||||||
@ -311,8 +307,6 @@ class BaseRepository
|
|||||||
if(!$model->design_id)
|
if(!$model->design_id)
|
||||||
$model->design_id = $this->decodePrimaryKey($client->getSetting('invoice_design_id'));
|
$model->design_id = $this->decodePrimaryKey($client->getSetting('invoice_design_id'));
|
||||||
|
|
||||||
event(new InvoiceWasUpdated($model, $model->company));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($class->name == Credit::class) {
|
if ($class->name == Credit::class) {
|
||||||
@ -320,6 +314,8 @@ class BaseRepository
|
|||||||
|
|
||||||
if(!$model->design_id)
|
if(!$model->design_id)
|
||||||
$model->design_id = $this->decodePrimaryKey($client->getSetting('credit_design_id'));
|
$model->design_id = $this->decodePrimaryKey($client->getSetting('credit_design_id'));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($class->name == Quote::class) {
|
if ($class->name == Quote::class) {
|
||||||
@ -327,22 +323,14 @@ class BaseRepository
|
|||||||
|
|
||||||
if(!$model->design_id)
|
if(!$model->design_id)
|
||||||
$model->design_id = $this->decodePrimaryKey($client->getSetting('quote_design_id'));
|
$model->design_id = $this->decodePrimaryKey($client->getSetting('quote_design_id'));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$model->save();
|
$model->save();
|
||||||
|
|
||||||
return $model->fresh();
|
return $model->fresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newEntityEvent($model)
|
|
||||||
{
|
|
||||||
|
|
||||||
$className = $this->getEventClass($model, 'Created');
|
|
||||||
|
|
||||||
if (class_exists($className)) {
|
|
||||||
event(new $className($model, $model->company));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user