Merge Invoice and Bill into Document
This commit is contained in:
40
app/Jobs/Document/CancelDocument.php
Normal file
40
app/Jobs/Document/CancelDocument.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Document;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Document\Document;
|
||||
|
||||
class CancelDocument extends Job
|
||||
{
|
||||
protected $document;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $document
|
||||
*/
|
||||
public function __construct($document)
|
||||
{
|
||||
$this->document = $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Document
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
\DB::transaction(function () {
|
||||
$this->deleteRelationships($this->document, [
|
||||
'transactions', 'recurring'
|
||||
]);
|
||||
|
||||
$this->document->status = 'cancelled';
|
||||
$this->document->save();
|
||||
});
|
||||
|
||||
return $this->document;
|
||||
}
|
||||
}
|
||||
62
app/Jobs/Document/CreateDocument.php
Normal file
62
app/Jobs/Document/CreateDocument.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Document;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Document\DocumentCreated;
|
||||
use App\Events\Document\DocumentCreating;
|
||||
use App\Jobs\Document\CreateDocumentItemsAndTotals;
|
||||
use App\Models\Document\Document;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateDocument extends Job
|
||||
{
|
||||
protected $document;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Document
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (empty($this->request['amount'])) {
|
||||
$this->request['amount'] = 0;
|
||||
}
|
||||
|
||||
event(new DocumentCreating($this->request));
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->document = Document::create($this->request->all());
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), Str::plural($this->document->type));
|
||||
|
||||
$this->document->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
$this->dispatch(new CreateDocumentItemsAndTotals($this->document, $this->request));
|
||||
|
||||
$this->document->update($this->request->all());
|
||||
|
||||
$this->document->createRecurring();
|
||||
});
|
||||
|
||||
event(new DocumentCreated($this->document));
|
||||
|
||||
return $this->document;
|
||||
}
|
||||
}
|
||||
50
app/Jobs/Document/CreateDocumentHistory.php
Normal file
50
app/Jobs/Document/CreateDocumentHistory.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Document;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Document\DocumentHistory;
|
||||
|
||||
class CreateDocumentHistory extends Job
|
||||
{
|
||||
protected $document;
|
||||
|
||||
protected $notify;
|
||||
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $document
|
||||
* @param $notify
|
||||
* @param $description
|
||||
*/
|
||||
public function __construct($document, $notify = 0, $description = null)
|
||||
{
|
||||
$this->document = $document;
|
||||
$this->notify = $notify;
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return DocumentHistory
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$description = $this->description ?: trans_choice('general.payments', 1);
|
||||
|
||||
$document_history = DocumentHistory::create([
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
'status' => $this->document->status,
|
||||
'notify' => $this->notify,
|
||||
'description' => $description,
|
||||
]);
|
||||
|
||||
return $document_history;
|
||||
}
|
||||
}
|
||||
199
app/Jobs/Document/CreateDocumentItem.php
Normal file
199
app/Jobs/Document/CreateDocumentItem.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Document;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Document\DocumentItem;
|
||||
use App\Models\Document\DocumentItemTax;
|
||||
use App\Models\Setting\Tax;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateDocumentItem extends Job
|
||||
{
|
||||
protected $document;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $document
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($document, $request)
|
||||
{
|
||||
$this->document = $document;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return DocumentItem
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$item_id = !empty($this->request['item_id']) ? $this->request['item_id'] : 0;
|
||||
$precision = config('money.' . $this->document->currency_code . '.precision');
|
||||
|
||||
$item_amount = (double) $this->request['price'] * (double) $this->request['quantity'];
|
||||
|
||||
$discount = 0;
|
||||
$item_discounted_amount = $item_amount;
|
||||
|
||||
// Apply line discount to amount
|
||||
if (!empty($this->request['discount'])) {
|
||||
$discount += $this->request['discount'];
|
||||
|
||||
$item_discounted_amount = $item_amount -= ($item_amount * ($this->request['discount'] / 100));
|
||||
}
|
||||
|
||||
// Apply global discount to amount
|
||||
if (!empty($this->request['global_discount'])) {
|
||||
$discount += $this->request['global_discount'];
|
||||
|
||||
$item_discounted_amount = $item_amount - ($item_amount * ($this->request['global_discount'] / 100));
|
||||
}
|
||||
|
||||
$tax_amount = 0;
|
||||
$item_taxes = [];
|
||||
$item_tax_total = 0;
|
||||
|
||||
if (!empty($this->request['tax_ids'])) {
|
||||
$inclusives = $compounds = [];
|
||||
|
||||
foreach ((array) $this->request['tax_ids'] as $tax_id) {
|
||||
$tax = Tax::find($tax_id);
|
||||
|
||||
switch ($tax->type) {
|
||||
case 'inclusive':
|
||||
$inclusives[] = $tax;
|
||||
|
||||
break;
|
||||
case 'compound':
|
||||
$compounds[] = $tax;
|
||||
|
||||
break;
|
||||
case 'fixed':
|
||||
$tax_amount = $tax->rate * (double) $this->request['quantity'];
|
||||
|
||||
$item_taxes[] = [
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
'tax_id' => $tax_id,
|
||||
'name' => $tax->name,
|
||||
'amount' => $tax_amount,
|
||||
];
|
||||
|
||||
$item_tax_total += $tax_amount;
|
||||
|
||||
break;
|
||||
case 'withholding':
|
||||
$tax_amount = 0 - $item_discounted_amount * ($tax->rate / 100);
|
||||
|
||||
$item_taxes[] = [
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
'tax_id' => $tax_id,
|
||||
'name' => $tax->name,
|
||||
'amount' => $tax_amount,
|
||||
];
|
||||
|
||||
$item_tax_total += $tax_amount;
|
||||
|
||||
break;
|
||||
default:
|
||||
$tax_amount = $item_discounted_amount * ($tax->rate / 100);
|
||||
|
||||
$item_taxes[] = [
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
'tax_id' => $tax_id,
|
||||
'name' => $tax->name,
|
||||
'amount' => $tax_amount,
|
||||
];
|
||||
|
||||
$item_tax_total += $tax_amount;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($inclusives) {
|
||||
$item_amount = $item_discounted_amount + $item_tax_total;
|
||||
|
||||
$item_base_rate = $item_amount / (1 + collect($inclusives)->sum('rate') / 100);
|
||||
|
||||
foreach ($inclusives as $inclusive) {
|
||||
$tax_amount = $item_base_rate * ($inclusive->rate / 100);
|
||||
|
||||
$item_taxes[] = [
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
'tax_id' => $inclusive->id,
|
||||
'name' => $inclusive->name,
|
||||
'amount' => $tax_amount,
|
||||
];
|
||||
|
||||
$item_tax_total += $tax_amount;
|
||||
}
|
||||
|
||||
$item_amount = ($item_amount - $item_tax_total) / (1 - $discount / 100);
|
||||
}
|
||||
|
||||
if ($compounds) {
|
||||
foreach ($compounds as $compound) {
|
||||
$tax_amount = (($item_discounted_amount + $item_tax_total) / 100) * $compound->rate;
|
||||
|
||||
$item_taxes[] = [
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
'tax_id' => $compound->id,
|
||||
'name' => $compound->name,
|
||||
'amount' => $tax_amount,
|
||||
];
|
||||
|
||||
$item_tax_total += $tax_amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$document_item = DocumentItem::create([
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
'item_id' => $item_id,
|
||||
'name' => Str::limit($this->request['name'], 180, ''),
|
||||
'description' => $this->request['description'],
|
||||
'quantity' => (double) $this->request['quantity'],
|
||||
'price' => round($this->request['price'], $precision),
|
||||
'tax' => round($item_tax_total, $precision),
|
||||
'discount_rate' => !empty($this->request['discount']) ? $this->request['discount'] : 0,
|
||||
'total' => round($item_amount, $precision),
|
||||
]);
|
||||
|
||||
$document_item->item_taxes = false;
|
||||
$document_item->inclusives = false;
|
||||
$document_item->compounds = false;
|
||||
|
||||
if (!empty($item_taxes)) {
|
||||
$document_item->item_taxes = $item_taxes;
|
||||
$document_item->inclusives = $inclusives;
|
||||
$document_item->compounds = $compounds;
|
||||
|
||||
foreach ($item_taxes as $item_tax) {
|
||||
$item_tax['document_item_id'] = $document_item->id;
|
||||
$item_tax['amount'] = round(abs($item_tax['amount']), $precision);
|
||||
|
||||
DocumentItemTax::create($item_tax);
|
||||
}
|
||||
}
|
||||
|
||||
return $document_item;
|
||||
}
|
||||
}
|
||||
203
app/Jobs/Document/CreateDocumentItemsAndTotals.php
Normal file
203
app/Jobs/Document/CreateDocumentItemsAndTotals.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Document;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Document\DocumentTotal;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
|
||||
class CreateDocumentItemsAndTotals extends Job
|
||||
{
|
||||
use Currencies, DateTime;
|
||||
|
||||
protected $document;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($document, $request)
|
||||
{
|
||||
$this->document = $document;
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return voide
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$precision = config('money.' . $this->document->currency_code . '.precision');
|
||||
|
||||
list($sub_total, $discount_amount_total, $taxes) = $this->createItems();
|
||||
|
||||
$sort_order = 1;
|
||||
|
||||
// Add sub total
|
||||
DocumentTotal::create([
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
'code' => 'sub_total',
|
||||
'name' => 'invoices.sub_total',
|
||||
'amount' => round($sub_total, $precision),
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$this->request['amount'] += $sub_total;
|
||||
|
||||
$sort_order++;
|
||||
|
||||
// Add discount
|
||||
if ($discount_amount_total > 0) {
|
||||
DocumentTotal::create([
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
'code' => 'item_discount',
|
||||
'name' => 'invoices.item_discount',
|
||||
'amount' => round($discount_amount_total, $precision),
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$this->request['amount'] -= $discount_amount_total;
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
|
||||
if (!empty($this->request['discount'])) {
|
||||
$discount_total = ($sub_total - $discount_amount_total) * ($this->request['discount'] / 100);
|
||||
|
||||
DocumentTotal::create([
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
'code' => 'discount',
|
||||
'name' => 'invoices.discount',
|
||||
'amount' => round($discount_total, $precision),
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$this->request['amount'] -= $discount_total;
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
|
||||
// Add taxes
|
||||
if (!empty($taxes)) {
|
||||
foreach ($taxes as $tax) {
|
||||
DocumentTotal::create([
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
'code' => 'tax',
|
||||
'name' => $tax['name'],
|
||||
'amount' => round(abs($tax['amount']), $precision),
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$this->request['amount'] += $tax['amount'];
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
}
|
||||
|
||||
// Add extra totals, i.e. shipping fee
|
||||
if (!empty($this->request['totals'])) {
|
||||
foreach ($this->request['totals'] as $total) {
|
||||
$total['company_id'] = $this->document->company_id;
|
||||
$total['type'] = $this->document->type;
|
||||
$total['document_id'] = $this->document->id;
|
||||
$total['sort_order'] = $sort_order;
|
||||
|
||||
if (empty($total['code'])) {
|
||||
$total['code'] = 'extra';
|
||||
}
|
||||
|
||||
$total['amount'] = round(abs($total['amount']), $precision);
|
||||
|
||||
DocumentTotal::create($total);
|
||||
|
||||
if (empty($total['operator']) || ($total['operator'] == 'addition')) {
|
||||
$this->request['amount'] += $total['amount'];
|
||||
} else {
|
||||
// subtraction
|
||||
$this->request['amount'] -= $total['amount'];
|
||||
}
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->request['amount'] = round($this->request['amount'], $precision);
|
||||
|
||||
// Add total
|
||||
DocumentTotal::create([
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
'code' => 'total',
|
||||
'name' => 'invoices.total',
|
||||
'amount' => $this->request['amount'],
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function createItems()
|
||||
{
|
||||
$sub_total = $discount_amount = $discount_amount_total = 0;
|
||||
|
||||
$taxes = [];
|
||||
|
||||
if (empty($this->request['items'])) {
|
||||
return [$sub_total, $discount_amount_total, $taxes];
|
||||
}
|
||||
|
||||
foreach ((array) $this->request['items'] as $item) {
|
||||
$item['global_discount'] = 0;
|
||||
|
||||
if (!empty($this->request['discount'])) {
|
||||
$item['global_discount'] = $this->request['discount'];
|
||||
}
|
||||
|
||||
$document_item = $this->dispatch(new CreateDocumentItem($this->document, $item));
|
||||
|
||||
$item_amount = (double) $item['price'] * (double) $item['quantity'];
|
||||
|
||||
$discount_amount = 0;
|
||||
|
||||
if (!empty($item['discount'])) {
|
||||
$discount_amount = ($item_amount * ($item['discount'] / 100));
|
||||
}
|
||||
|
||||
// Calculate totals
|
||||
$sub_total += $document_item->total + $discount_amount;
|
||||
|
||||
$discount_amount_total += $discount_amount;
|
||||
|
||||
if (!$document_item->item_taxes) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Set taxes
|
||||
foreach ((array) $document_item->item_taxes as $item_tax) {
|
||||
if (array_key_exists($item_tax['tax_id'], $taxes)) {
|
||||
$taxes[$item_tax['tax_id']]['amount'] += $item_tax['amount'];
|
||||
} else {
|
||||
$taxes[$item_tax['tax_id']] = [
|
||||
'name' => $item_tax['name'],
|
||||
'amount' => $item_tax['amount'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [$sub_total, $discount_amount_total, $taxes];
|
||||
}
|
||||
}
|
||||
61
app/Jobs/Document/DeleteDocument.php
Normal file
61
app/Jobs/Document/DeleteDocument.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Document;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Observers\Transaction;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DeleteDocument extends Job
|
||||
{
|
||||
protected $document;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $document
|
||||
*/
|
||||
public function __construct($document)
|
||||
{
|
||||
$this->document = $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return boolean|Exception
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
\DB::transaction(function () {
|
||||
Transaction::mute();
|
||||
|
||||
$this->deleteRelationships($this->document, [
|
||||
'items', 'item_taxes', 'histories', 'transactions', 'recurring', 'totals'
|
||||
]);
|
||||
|
||||
$this->document->delete();
|
||||
|
||||
Transaction::unmute();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if ($this->document->transactions()->isReconciled()->count()) {
|
||||
$type = Str::plural($this->document->type);
|
||||
$message = trans('messages.warning.reconciled_doc', ['type' => trans_choice("general.$type", 1)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
app/Jobs/Document/DuplicateDocument.php
Normal file
40
app/Jobs/Document/DuplicateDocument.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Document;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Document\DocumentCreated;
|
||||
use App\Models\Document\Document;
|
||||
|
||||
class DuplicateDocument extends Job
|
||||
{
|
||||
protected $document;
|
||||
|
||||
protected $clone;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $document
|
||||
*/
|
||||
public function __construct($document)
|
||||
{
|
||||
$this->document = $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Document
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
\DB::transaction(function () {
|
||||
$this->clone = $this->document->duplicate();
|
||||
});
|
||||
|
||||
event(new DocumentCreated($this->clone));
|
||||
|
||||
return $this->clone;
|
||||
}
|
||||
}
|
||||
77
app/Jobs/Document/UpdateDocument.php
Normal file
77
app/Jobs/Document/UpdateDocument.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Document;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Document\PaidAmountCalculated;
|
||||
use App\Events\Document\DocumentUpdated;
|
||||
use App\Events\Document\DocumentUpdating;
|
||||
use App\Jobs\Document\CreateDocumentItemsAndTotals;
|
||||
use App\Models\Document\Document;
|
||||
use App\Traits\Relationships;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UpdateDocument extends Job
|
||||
{
|
||||
use Relationships;
|
||||
|
||||
protected $document;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($document, $request)
|
||||
{
|
||||
$this->document = $document;
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Document
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (empty($this->request['amount'])) {
|
||||
$this->request['amount'] = 0;
|
||||
}
|
||||
|
||||
event(new DocumentUpdating($this->document, $this->request));
|
||||
|
||||
\DB::transaction(function () {
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), Str::plural($this->document->type));
|
||||
|
||||
$this->document->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
$this->deleteRelationships($this->document, ['items', 'item_taxes', 'totals']);
|
||||
|
||||
$this->dispatch(new CreateDocumentItemsAndTotals($this->document, $this->request));
|
||||
|
||||
$this->document->paid_amount = $this->document->paid;
|
||||
event(new PaidAmountCalculated($this->document));
|
||||
|
||||
if ($this->request['amount'] > $this->document->paid_amount && $this->document->paid_amount > 0) {
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
|
||||
unset($this->document->reconciled);
|
||||
unset($this->document->paid_amount);
|
||||
|
||||
$this->document->update($this->request->all());
|
||||
|
||||
$this->document->updateRecurring();
|
||||
});
|
||||
|
||||
event(new DocumentUpdated($this->document, $this->request));
|
||||
|
||||
return $this->document;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user