transactions import/export

This commit is contained in:
denisdulici
2020-01-21 09:10:12 +03:00
parent 9b42e2d127
commit 75f17e5466
11 changed files with 270 additions and 222 deletions

View File

@@ -3,8 +3,8 @@
namespace App\Imports\Banking;
use App\Abstracts\Import;
use App\Models\Banking\Transaction as Model;
use App\Http\Requests\Banking\Transaction as Request;
use App\Models\Banking\Transaction as Model;
class Transactions extends Import
{
@@ -13,6 +13,18 @@ class Transactions extends Import
return new Model($row);
}
public function map($row): array
{
$row = parent::map($row);
$row['account_id'] = $this->getAccountId($row);
$row['category_id'] = $this->getCategoryId($row);
$row['contact_id'] = $this->getContactId($row);
$row['document_id'] = $this->getDocumentId($row);
return $row;
}
public function rules(): array
{
return (new Request())->rules();

View File

@@ -17,13 +17,8 @@ class Items extends Import
{
$row = parent::map($row);
if (empty($row['category_id']) && !empty($row['category_name'])) {
$row['category_id'] = $this->getCategoryIdFromName($row, 'item');
}
if (empty($row['tax_id']) && !empty($row['tax_rate'])) {
$row['tax_id'] = $this->getTaxIdFromRate($row);
}
$row['category_id'] = $this->getCategoryId($row, 'item');
$row['tax_id'] = $this->getTaxId($row);
return $row;
}

View File

@@ -5,7 +5,6 @@ namespace App\Imports\Purchases;
use App\Abstracts\Import;
use App\Models\Banking\Transaction as Model;
use App\Http\Requests\Banking\Transaction as Request;
use App\Models\Purchase\Bill;
class Payments extends Import
{
@@ -19,34 +18,10 @@ class Payments extends Import
$row = parent::map($row);
$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();
}
$row['account_id'] = $this->getAccountId($row);
$row['category_id'] = $this->getCategoryId($row, 'expense');
$row['contact_id'] = $this->getContactId($row, 'vendor');
$row['document_id'] = $this->getDocumentId($row);
return $row;
}

View File

@@ -5,7 +5,6 @@ namespace App\Imports\Sales;
use App\Abstracts\Import;
use App\Http\Requests\Banking\Transaction as Request;
use App\Models\Banking\Transaction as Model;
use App\Models\Sale\Invoice;
class Revenues extends Import
{
@@ -19,34 +18,10 @@ class Revenues extends Import
$row = parent::map($row);
$row['type'] = 'income';
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();
}
$row['account_id'] = $this->getAccountId($row);
$row['category_id'] = $this->getCategoryId($row, 'income');
$row['contact_id'] = $this->getContactId($row, 'customer');
$row['document_id'] = $this->getDocumentId($row);
return $row;
}

View File

@@ -35,13 +35,7 @@ class InvoiceItemTaxes extends Import
$row['invoice_item_id'] = InvoiceItem::where('item_id', $item_id)->pluck('id')->first();
}
if (empty($row['tax_id']) && !empty($row['tax_name'])) {
$row['tax_id'] = Tax::name($row['tax_name'])->pluck('id')->first();
}
if (empty($row['tax_id']) && !empty($row['tax_rate'])) {
$row['tax_id'] = $this->getTaxIdFromRate($row);
}
$row['tax_id'] = $this->getTaxId($row);
if (empty($row['name']) && !empty($row['item_name'])) {
$row['name'] = $row['item_name'];

View File

@@ -5,7 +5,6 @@ namespace App\Imports\Sales\Sheets;
use App\Abstracts\Import;
use App\Http\Requests\Banking\Transaction as Request;
use App\Models\Banking\Transaction as Model;
use App\Models\Sale\Invoice;
class InvoiceTransactions extends Import
{
@@ -19,32 +18,10 @@ class InvoiceTransactions extends Import
$row = parent::map($row);
$row['type'] = 'income';
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');
}
$row['document_id'] = Invoice::number($row['invoice_number'])->pluck('id')->first();
$row['account_id'] = $this->getAccountId($row);
$row['category_id'] = $this->getCategoryId($row, 'income');
$row['contact_id'] = $this->getContactId($row, 'customer');
$row['document_id'] = $this->getDocumentId($row);
return $row;
}

View File

@@ -17,17 +17,8 @@ class Invoices extends Import
{
$row = parent::map($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');
}
$row['category_id'] = $this->getCategoryId($row, 'income');
$row['contact_id'] = $this->getContactId($row, 'customer');
return $row;
}