added parent id field to import and export

This commit is contained in:
Cihan Şentürk 2023-07-20 15:39:23 +03:00 committed by GitHub
parent 7768280ea3
commit 6a07f8ad9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 0 deletions

View File

@ -20,6 +20,7 @@ class Transactions extends Export implements WithColumnFormatting
$model->contact_email = $model->contact->email;
$model->category_name = $model->category->name;
$model->invoice_bill_number = $model->document->document_number ?? 0;
$model->parent_number = Model::isRecurring()->find($model->parent_id)?->number;
return parent::map($model);
}
@ -41,6 +42,7 @@ class Transactions extends Export implements WithColumnFormatting
'payment_method',
'reference',
'reconciled',
'parent_number',
];
}

View File

@ -26,6 +26,7 @@ class Bills extends Export implements WithColumnFormatting
$model->bill_number = $model->document_number;
$model->billed_at = $model->issued_at;
$model->contact_country = $country;
$model->parent_number = Model::billRecurring()->find($model->parent_id)?->document_number ?? null;
return parent::map($model);
}
@ -52,6 +53,7 @@ class Bills extends Export implements WithColumnFormatting
'contact_zip_code',
'contact_city',
'notes',
'parent_number',
];
}

View File

@ -26,6 +26,7 @@ class Invoices extends Export implements WithColumnFormatting
$model->invoice_number = $model->document_number;
$model->invoiced_at = $model->issued_at;
$model->contact_country = $country;
$model->parent_number = Model::invoiceRecurring()->find($model->parent_id)?->document_number;
return parent::map($model);
}
@ -53,6 +54,7 @@ class Invoices extends Export implements WithColumnFormatting
'contact_city',
'notes',
'footer',
'parent_number',
];
}

View File

@ -24,6 +24,7 @@ class Transactions extends Import
$row['category_id'] = $this->getCategoryId($row);
$row['contact_id'] = $this->getContactId($row);
$row['document_id'] = $this->getDocumentId($row);
$row['parent_id'] = $this->getParentId($row);
return $row;
}

View File

@ -35,6 +35,7 @@ class Bills extends Import
$row['currency_code'] = $this->getCurrencyCode($row);
$row['type'] = Model::BILL_TYPE;
$row['contact_country'] = !empty($country) ? $country : null;
$row['parent_id'] = $this->getParentId($row);
return $row;
}

View File

@ -35,6 +35,7 @@ class Invoices extends Import
$row['currency_code'] = $this->getCurrencyCode($row);
$row['type'] = Model::INVOICE_TYPE;
$row['contact_country'] = !empty($country) ? $country : null;
$row['parent_id'] = $this->getParentId($row);
return $row;
}

View File

@ -16,6 +16,7 @@ use App\Jobs\Setting\CreateCurrency;
use App\Jobs\Setting\CreateTax;
use App\Models\Auth\User;
use App\Models\Banking\Account;
use App\Models\Banking\Transaction;
use App\Models\Common\Contact;
use App\Models\Common\Item;
use App\Models\Document\Document;
@ -149,6 +150,21 @@ trait Import
return is_null($id) ? $id : (int) $id;
}
public function getParentId($row)
{
$id = isset($row['parent_id']) ? $row['parent_id'] : null;
if (empty($id) && isset($row['document_number']) && !empty($row['parent_number'])) {
$id = Document::number($row['parent_number'])->pluck('id')->first();
}
if (empty($id) && isset($row['number']) && !empty($row['parent_number'])) {
$id = Transaction::number($row['parent_number'])->pluck('id')->first();
}
return is_null($id) ? $id : (int) $id;
}
public function getItemId($row, $type = null)
{
$id = isset($row['item_id']) ? $row['item_id'] : null;