improved document import

This commit is contained in:
Denis Duliçi 2021-02-15 23:11:10 +03:00
parent 96fd43384a
commit 7a10757c8d
2 changed files with 6 additions and 7 deletions

View File

@ -11,7 +11,7 @@ class Transactions extends Export implements WithColumnFormatting
{
public function collection()
{
$model = Model::with('account', 'bill', 'category', 'contact', 'invoice')->usingSearchString(request('search'));
$model = Model::with('account', 'category', 'contact', 'document')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('id', (array) $this->ids);
@ -25,12 +25,7 @@ class Transactions extends Export implements WithColumnFormatting
$model->account_name = $model->account->name;
$model->contact_email = $model->contact->email;
$model->category_name = $model->category->name;
if ($model->type == 'income') {
$model->invoice_bill_number = $model->invoice->document_number ?? 0;
} else {
$model->invoice_bill_number = $model->bill->document_number ?? 0;
}
$model->invoice_bill_number = $model->document->document_number ?? 0;
return parent::map($model);
}

View File

@ -64,6 +64,10 @@ trait Import
{
$id = isset($row['document_id']) ? $row['document_id'] : null;
if (empty($id) && !empty($row['document_number'])) {
$id = Document::number($row['document_number'])->pluck('id')->first();
}
if (empty($id) && !empty($row['invoice_number'])) {
$id = Document::invoice()->number($row['invoice_number'])->pluck('id')->first();
}