added source feature
This commit is contained in:
@@ -6,12 +6,13 @@ use App\Abstracts\Job;
|
||||
use App\Events\Document\DocumentCreated;
|
||||
use App\Events\Document\DocumentCreating;
|
||||
use App\Interfaces\Job\HasOwner;
|
||||
use App\Interfaces\Job\HasSource;
|
||||
use App\Interfaces\Job\ShouldCreate;
|
||||
use App\Jobs\Document\CreateDocumentItemsAndTotals;
|
||||
use App\Models\Document\Document;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateDocument extends Job implements HasOwner, ShouldCreate
|
||||
class CreateDocument extends Job implements HasOwner, HasSource, ShouldCreate
|
||||
{
|
||||
public function handle(): Document
|
||||
{
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
namespace App\Jobs\Document;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\HasOwner;
|
||||
use App\Interfaces\Job\HasSource;
|
||||
use App\Interfaces\Job\ShouldCreate;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentHistory;
|
||||
|
||||
class CreateDocumentHistory extends Job implements ShouldCreate
|
||||
class CreateDocumentHistory extends Job implements HasOwner, HasSource, ShouldCreate
|
||||
{
|
||||
protected $document;
|
||||
|
||||
@@ -35,6 +37,8 @@ class CreateDocumentHistory extends Job implements ShouldCreate
|
||||
'status' => $this->document->status,
|
||||
'notify' => $this->notify,
|
||||
'description' => $description,
|
||||
'created_from' => source_name(),
|
||||
'created_by' => user_id(),
|
||||
]);
|
||||
|
||||
return $document_history;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Jobs\Document;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\HasOwner;
|
||||
use App\Interfaces\Job\HasSource;
|
||||
use App\Interfaces\Job\ShouldCreate;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentItem;
|
||||
@@ -10,7 +12,7 @@ use App\Models\Document\DocumentItemTax;
|
||||
use App\Models\Setting\Tax;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateDocumentItem extends Job implements ShouldCreate
|
||||
class CreateDocumentItem extends Job implements HasOwner, HasSource, ShouldCreate
|
||||
{
|
||||
protected $document;
|
||||
|
||||
@@ -182,6 +184,8 @@ class CreateDocumentItem extends Job implements ShouldCreate
|
||||
$this->request['discount_type'] = !empty($this->request['discount_type']) ? $this->request['discount_type'] : 'percentage';
|
||||
$this->request['discount_rate'] = !empty($this->request['discount']) ? $this->request['discount'] : 0;
|
||||
$this->request['total'] = round($item_amount, $precision);
|
||||
$this->request['created_from'] = source_name();
|
||||
$this->request['created_by'] = user_id();
|
||||
|
||||
$document_item = DocumentItem::create($this->request);
|
||||
|
||||
@@ -197,6 +201,8 @@ class CreateDocumentItem extends Job implements ShouldCreate
|
||||
foreach ($item_taxes as $item_tax) {
|
||||
$item_tax['document_item_id'] = $document_item->id;
|
||||
$item_tax['amount'] = round(abs($item_tax['amount']), $precision);
|
||||
$item_tax['created_from'] = $this->request['created_from'];
|
||||
$item_tax['created_by'] = $this->request['created_by'];
|
||||
|
||||
DocumentItemTax::create($item_tax);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Jobs\Document;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\HasOwner;
|
||||
use App\Interfaces\Job\HasSource;
|
||||
use App\Interfaces\Job\ShouldCreate;
|
||||
use App\Jobs\Common\CreateItem;
|
||||
use App\Models\Document\Document;
|
||||
@@ -10,7 +12,7 @@ use App\Models\Document\DocumentTotal;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
|
||||
class CreateDocumentItemsAndTotals extends Job implements ShouldCreate
|
||||
class CreateDocumentItemsAndTotals extends Job implements HasOwner, HasSource, ShouldCreate
|
||||
{
|
||||
use Currencies, DateTime;
|
||||
|
||||
@@ -40,6 +42,8 @@ class CreateDocumentItemsAndTotals extends Job implements ShouldCreate
|
||||
'name' => 'invoices.sub_total',
|
||||
'amount' => round($sub_total, $precision),
|
||||
'sort_order' => $sort_order,
|
||||
'created_from' => $this->request['created_from'],
|
||||
'created_by' => $this->request['created_by'],
|
||||
]);
|
||||
|
||||
$this->request['amount'] += $sub_total;
|
||||
@@ -56,6 +60,8 @@ class CreateDocumentItemsAndTotals extends Job implements ShouldCreate
|
||||
'name' => 'invoices.item_discount',
|
||||
'amount' => round($discount_amount_total, $precision),
|
||||
'sort_order' => $sort_order,
|
||||
'created_from' => $this->request['created_from'],
|
||||
'created_by' => $this->request['created_by'],
|
||||
]);
|
||||
|
||||
$sort_order++;
|
||||
@@ -68,7 +74,7 @@ class CreateDocumentItemsAndTotals extends Job implements ShouldCreate
|
||||
$discount_total = $this->request['discount'];
|
||||
}
|
||||
|
||||
DocumentTotal::create([
|
||||
DocumentTotal::create([
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
@@ -76,6 +82,8 @@ class CreateDocumentItemsAndTotals extends Job implements ShouldCreate
|
||||
'name' => 'invoices.discount',
|
||||
'amount' => round($discount_total, $precision),
|
||||
'sort_order' => $sort_order,
|
||||
'created_from' => $this->request['created_from'],
|
||||
'created_by' => $this->request['created_by'],
|
||||
]);
|
||||
|
||||
$this->request['amount'] -= $discount_total;
|
||||
@@ -94,6 +102,8 @@ class CreateDocumentItemsAndTotals extends Job implements ShouldCreate
|
||||
'name' => $tax['name'],
|
||||
'amount' => round(abs($tax['amount']), $precision),
|
||||
'sort_order' => $sort_order,
|
||||
'created_from' => $this->request['created_from'],
|
||||
'created_by' => $this->request['created_by'],
|
||||
]);
|
||||
|
||||
$this->request['amount'] += $tax['amount'];
|
||||
@@ -109,6 +119,8 @@ class CreateDocumentItemsAndTotals extends Job implements ShouldCreate
|
||||
$total['type'] = $this->document->type;
|
||||
$total['document_id'] = $this->document->id;
|
||||
$total['sort_order'] = $sort_order;
|
||||
$total['created_from'] = $this->request['created_from'];
|
||||
$total['created_by'] = $this->request['created_by'];
|
||||
|
||||
if (empty($total['code'])) {
|
||||
$total['code'] = 'extra';
|
||||
@@ -140,6 +152,8 @@ class CreateDocumentItemsAndTotals extends Job implements ShouldCreate
|
||||
'name' => 'invoices.total',
|
||||
'amount' => $this->request['amount'],
|
||||
'sort_order' => $sort_order,
|
||||
'created_from' => $this->request['created_from'],
|
||||
'created_by' => $this->request['created_by'],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -167,7 +181,7 @@ class CreateDocumentItemsAndTotals extends Job implements ShouldCreate
|
||||
'description' => $item['description'],
|
||||
'sale_price' => $item['price'],
|
||||
'purchase_price' => $item['price'],
|
||||
'enabled' => '1'
|
||||
'enabled' => '1',
|
||||
];
|
||||
|
||||
if (!empty($item['tax_ids'])) {
|
||||
|
||||
Reference in New Issue
Block a user