akaunting/app/Imports/Sales/Revenues.php

59 lines
1.6 KiB
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
2020-01-20 10:46:30 +03:00
namespace App\Imports\Sales;
2019-11-16 10:21:14 +03:00
2020-01-20 01:26:35 +03:00
use App\Abstracts\Import;
2019-11-16 10:21:14 +03:00
use App\Http\Requests\Banking\Transaction as Request;
2020-01-20 23:50:19 +03:00
use App\Models\Banking\Transaction as Model;
use App\Models\Sale\Invoice;
2019-11-16 10:21:14 +03:00
2020-01-20 01:26:35 +03:00
class Revenues extends Import
2019-11-16 10:21:14 +03:00
{
public function model(array $row)
{
return new Model($row);
}
public function map($row): array
{
2020-01-20 11:12:14 +03:00
$row = parent::map($row);
2019-11-16 10:21:14 +03:00
2020-01-20 11:12:14 +03:00
$row['type'] = 'income';
2019-11-16 10:21:14 +03:00
2020-01-20 23:50:19 +03:00
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, 'customer');
}
if (empty($row['contact_id']) && !empty($row['contact_email'])) {
$row['contact_id'] = $this->getContactIdFromEmail($row, 'customer');
}
if (empty($row['category_id']) && !empty($row['category_name'])) {
$row['category_id'] = $this->getCategoryIdFromName($row, 'income');
}
if (!empty($row['invoice_number'])) {
$row['document_id'] = Invoice::number($row['invoice_number'])->pluck('id')->first();
}
2019-11-16 10:21:14 +03:00
return $row;
}
public function rules(): array
{
return (new Request())->rules();
}
2020-01-20 01:26:35 +03:00
}