Skip to content

Commit

Permalink
fixed document source
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Sep 9, 2021
1 parent 6379c0e commit 1f2b5e7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
14 changes: 12 additions & 2 deletions app/Jobs/Document/CreateDocumentHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -37,10 +38,19 @@ public function handle(): DocumentHistory
'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'];
}
}
4 changes: 2 additions & 2 deletions app/Jobs/Document/CreateDocumentItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ public function handle(): DocumentItem
$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);

Expand Down
3 changes: 3 additions & 0 deletions app/Jobs/Document/CreateDocumentItemsAndTotals.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ protected function createItems(): array
$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'];
Expand Down
2 changes: 1 addition & 1 deletion app/Listeners/Document/CreateDocumentCreatedHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public function handle(Event $event)
{
$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));
}
}
2 changes: 1 addition & 1 deletion app/Models/Document/DocumentTotal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1f2b5e7

Please sign in to comment.