payments import/export
This commit is contained in:
parent
04173eae78
commit
9b42e2d127
@ -9,7 +9,7 @@ class Payments extends Export
|
|||||||
{
|
{
|
||||||
public function collection()
|
public function collection()
|
||||||
{
|
{
|
||||||
$model = Model::type('expense')->usingSearchString(request('search'));
|
$model = Model::with(['account', 'bill', 'category', 'contact'])->type('expense')->usingSearchString(request('search'));
|
||||||
|
|
||||||
if (!empty($this->ids)) {
|
if (!empty($this->ids)) {
|
||||||
$model->whereIn('id', (array) $this->ids);
|
$model->whereIn('id', (array) $this->ids);
|
||||||
@ -18,6 +18,16 @@ class Payments extends Export
|
|||||||
return $model->get();
|
return $model->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function map($model): array
|
||||||
|
{
|
||||||
|
$model->account_name = $model->account->name;
|
||||||
|
$model->bill_number = $model->bill ? $model->bill->bill_number : 0;
|
||||||
|
$model->contact_email = $model->contact->email;
|
||||||
|
$model->category_name = $model->category->name;
|
||||||
|
|
||||||
|
return parent::map($model);
|
||||||
|
}
|
||||||
|
|
||||||
public function fields(): array
|
public function fields(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -25,10 +35,10 @@ class Payments extends Export
|
|||||||
'amount',
|
'amount',
|
||||||
'currency_code',
|
'currency_code',
|
||||||
'currency_rate',
|
'currency_rate',
|
||||||
'account_id',
|
'account_name',
|
||||||
'document_id',
|
'bill_number',
|
||||||
'contact_id',
|
'contact_email',
|
||||||
'category_id',
|
'category_name',
|
||||||
'description',
|
'description',
|
||||||
'payment_method',
|
'payment_method',
|
||||||
'reference',
|
'reference',
|
||||||
|
@ -5,6 +5,7 @@ namespace App\Imports\Purchases;
|
|||||||
use App\Abstracts\Import;
|
use App\Abstracts\Import;
|
||||||
use App\Models\Banking\Transaction as Model;
|
use App\Models\Banking\Transaction as Model;
|
||||||
use App\Http\Requests\Banking\Transaction as Request;
|
use App\Http\Requests\Banking\Transaction as Request;
|
||||||
|
use App\Models\Purchase\Bill;
|
||||||
|
|
||||||
class Payments extends Import
|
class Payments extends Import
|
||||||
{
|
{
|
||||||
@ -19,6 +20,34 @@ class Payments extends Import
|
|||||||
|
|
||||||
$row['type'] = 'expense';
|
$row['type'] = 'expense';
|
||||||
|
|
||||||
|
if (empty($row['account_id']) && !empty($row['account_name'])) {
|
||||||
|
$row['account_id'] = $this->getAccountIdFromName($row);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($row['account_id']) && !empty($row['account_number'])) {
|
||||||
|
$row['account_id'] = $this->getAccountIdFromNumber($row);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($row['account_id']) && !empty($row['currency_code'])) {
|
||||||
|
$row['account_id'] = $this->getAccountIdFromCurrency($row);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($row['contact_id']) && !empty($row['contact_name'])) {
|
||||||
|
$row['contact_id'] = $this->getContactIdFromName($row, 'vendor');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($row['contact_id']) && !empty($row['contact_email'])) {
|
||||||
|
$row['contact_id'] = $this->getContactIdFromEmail($row, 'vendor');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($row['category_id']) && !empty($row['category_name'])) {
|
||||||
|
$row['category_id'] = $this->getCategoryIdFromName($row, 'expense');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($row['bill_number'])) {
|
||||||
|
$row['document_id'] = Bill::number($row['bill_number'])->pluck('id')->first();
|
||||||
|
}
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user