From 1f2b5e79f3fab5d400229a321b91e83efc4e3c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Fri, 10 Sep 2021 01:20:20 +0300 Subject: [PATCH] fixed document source --- app/Jobs/Document/CreateDocumentHistory.php | 14 ++++++++++++-- app/Jobs/Document/CreateDocumentItem.php | 4 ++-- app/Jobs/Document/CreateDocumentItemsAndTotals.php | 3 +++ .../Document/CreateDocumentCreatedHistory.php | 2 +- app/Models/Document/DocumentTotal.php | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/Jobs/Document/CreateDocumentHistory.php b/app/Jobs/Document/CreateDocumentHistory.php index f07e8c117..4b3773550 100644 --- a/app/Jobs/Document/CreateDocumentHistory.php +++ b/app/Jobs/Document/CreateDocumentHistory.php @@ -17,11 +17,12 @@ class CreateDocumentHistory extends Job implements HasOwner, HasSource, ShouldCr protected $description; - public function __construct(Document $document, $notify = 0, $description = null) + public function __construct(Document $document, $notify = 0, $description = null, $request = null) { $this->document = $document; $this->notify = $notify; $this->description = $description; + $this->request = $request; parent::__construct($document, $notify, $description); } @@ -37,10 +38,19 @@ class CreateDocumentHistory extends Job implements HasOwner, HasSource, ShouldCr 'status' => $this->document->status, 'notify' => $this->notify, 'description' => $description, - 'created_from' => source_name(), + 'created_from' => $this->getCustomSourceName(), 'created_by' => user_id(), ]); return $document_history; } + + public function getCustomSourceName(): string + { + if (empty($this->request) || empty($this->request['created_from'])) { + return $this->getSourceName(); + } + + return $this->request['created_from']; + } } diff --git a/app/Jobs/Document/CreateDocumentItem.php b/app/Jobs/Document/CreateDocumentItem.php index 8eaa69b61..529245aaa 100644 --- a/app/Jobs/Document/CreateDocumentItem.php +++ b/app/Jobs/Document/CreateDocumentItem.php @@ -184,8 +184,8 @@ class CreateDocumentItem extends Job implements HasOwner, HasSource, ShouldCreat $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(); + $this->request['created_from'] = $this->request['created_from']; + $this->request['created_by'] = $this->request['created_by']; $document_item = DocumentItem::create($this->request); diff --git a/app/Jobs/Document/CreateDocumentItemsAndTotals.php b/app/Jobs/Document/CreateDocumentItemsAndTotals.php index 45f928621..3307bfe97 100644 --- a/app/Jobs/Document/CreateDocumentItemsAndTotals.php +++ b/app/Jobs/Document/CreateDocumentItemsAndTotals.php @@ -193,6 +193,9 @@ class CreateDocumentItemsAndTotals extends Job implements HasOwner, HasSource, S $item['item_id'] = $new_item->id; } + $item['created_from'] = $this->request['created_from']; + $item['created_by'] = $this->request['created_by']; + $document_item = $this->dispatch(new CreateDocumentItem($this->document, $item)); $item_amount = (double) $item['price'] * (double) $item['quantity']; diff --git a/app/Listeners/Document/CreateDocumentCreatedHistory.php b/app/Listeners/Document/CreateDocumentCreatedHistory.php index ca6a95a7f..e3c3ff650 100644 --- a/app/Listeners/Document/CreateDocumentCreatedHistory.php +++ b/app/Listeners/Document/CreateDocumentCreatedHistory.php @@ -20,6 +20,6 @@ class CreateDocumentCreatedHistory { $message = trans('messages.success.added', ['type' => $event->document->document_number]); - $this->dispatch(new CreateDocumentHistory($event->document, 0, $message)); + $this->dispatch(new CreateDocumentHistory($event->document, 0, $message, $event->request)); } } diff --git a/app/Models/Document/DocumentTotal.php b/app/Models/Document/DocumentTotal.php index 7304e83c2..e6b0795ea 100644 --- a/app/Models/Document/DocumentTotal.php +++ b/app/Models/Document/DocumentTotal.php @@ -16,7 +16,7 @@ class DocumentTotal extends Model protected $appends = ['title']; - protected $fillable = ['company_id', 'type', 'document_id', 'code', 'name', 'amount', 'sort_order']; + protected $fillable = ['company_id', 'type', 'document_id', 'code', 'name', 'amount', 'sort_order', 'created_from', 'created_by']; /** * The attributes that should be cast.