mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for bank transaction imports
This commit is contained in:
parent
b3e02c8a70
commit
f40360e1fe
@ -46,11 +46,14 @@ use App\Repositories\PaymentRepository;
|
|||||||
use App\Repositories\ProductRepository;
|
use App\Repositories\ProductRepository;
|
||||||
use App\Repositories\QuoteRepository;
|
use App\Repositories\QuoteRepository;
|
||||||
use App\Repositories\VendorRepository;
|
use App\Repositories\VendorRepository;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||||
|
|
||||||
class Csv extends BaseImport implements ImportInterface
|
class Csv extends BaseImport implements ImportInterface
|
||||||
{
|
{
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
public array $entity_count = [];
|
public array $entity_count = [];
|
||||||
|
|
||||||
public function import(string $entity)
|
public function import(string $entity)
|
||||||
@ -77,24 +80,20 @@ class Csv extends BaseImport implements ImportInterface
|
|||||||
|
|
||||||
$data = $this->getCsvData($entity_type);
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
if (is_array($data)) {
|
if (is_array($data))
|
||||||
|
{
|
||||||
|
|
||||||
$data = $this->preTransformCsv($data, $entity_type);
|
$data = $this->preTransformCsv($data, $entity_type);
|
||||||
|
|
||||||
|
foreach($data as $key => $value)
|
||||||
if(array_key_exists('bank_integration_id', $this->request)){
|
{
|
||||||
|
$data[$key]['bank.bank_integration_id'] = $this->decodePrimaryKey($this->request['bank_integration_id']);
|
||||||
foreach($data as $key => $value)
|
|
||||||
{
|
|
||||||
$data['bank_integration_id'][$key] = $this->request['bank_integration_id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
$this->entity_count['bank_transactions'] = 0;
|
$this->entity_count['bank_transactions'] = 0;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +101,8 @@ class Csv extends BaseImport implements ImportInterface
|
|||||||
$this->repository_name = BankTransactionRepository::class;
|
$this->repository_name = BankTransactionRepository::class;
|
||||||
$this->factory_name = BankTransactionFactory::class;
|
$this->factory_name = BankTransactionFactory::class;
|
||||||
|
|
||||||
|
$this->repository = app()->make($this->repository_name);
|
||||||
|
|
||||||
$this->transformer = new BankTransformer($this->company);
|
$this->transformer = new BankTransformer($this->company);
|
||||||
$bank_transaction_count = $this->ingest($data, $entity_type);
|
$bank_transaction_count = $this->ingest($data, $entity_type);
|
||||||
$this->entity_count['bank_transactions'] = $bank_transaction_count;
|
$this->entity_count['bank_transactions'] = $bank_transaction_count;
|
||||||
|
@ -31,17 +31,17 @@ class BankTransformer extends BaseTransformer
|
|||||||
$now = now();
|
$now = now();
|
||||||
|
|
||||||
$transformed = [
|
$transformed = [
|
||||||
// 'bank_integration_id' => $this->bank_integration->id,
|
'bank_integration_id' => $transaction['bank.bank_integration_id'],
|
||||||
'transaction_id' => $this->getNumber($transaction,'bank.transaction_id'),
|
'transaction_id' => $this->getNumber($transaction,'bank.transaction_id'),
|
||||||
'amount' => abs($this->getFloat($transaction, 'bank.amount')),
|
'amount' => abs($this->getFloat($transaction, 'bank.amount')),
|
||||||
'currency_id' => $this->getCurrencyByCode($transaction, 'bank.currency'),
|
'currency_id' => $this->getCurrencyByCode($transaction, 'bank.currency'),
|
||||||
'account_type' => strlen($this->getString($transaction, 'bank.account_type')) > 1 ? $this->getString($transaction, 'bank.account_type') : 'bank',
|
'account_type' => strlen($this->getString($transaction, 'bank.account_type')) > 1 ? $this->getString($transaction, 'bank.account_type') : 'bank',
|
||||||
'category_id' => $this->getNumber($transaction, 'bank.category_id') > 0 ? $this->getNumber($transaction, 'bank.category_id') : null,
|
'category_id' => $this->getNumber($transaction, 'bank.category_id') > 0 ? $this->getNumber($transaction, 'bank.category_id') : null,
|
||||||
'category_type' => $this->getString($transaction, 'category_type'),
|
'category_type' => $this->getString($transaction, 'bank.category_type'),
|
||||||
'date' => array_key_exists('date', $transaction) ? $this->parseDate($transaction['date'])
|
'date' => array_key_exists('bank.date', $transaction) ? $this->parseDate($transaction['bank.date'])
|
||||||
: now()->format('Y-m-d'),
|
: now()->format('Y-m-d'),
|
||||||
'bank_account_id' => array_key_exists('bank_account_id', $transaction) ? $transaction['bank_account_id'] : 0,
|
'bank_account_id' => array_key_exists('bank.bank_account_id', $transaction) ? $transaction['bank.bank_account_id'] : 0,
|
||||||
'description' => array_key_exists('description', $transaction)? $transaction['description'] : '',
|
'description' => array_key_exists('bank.description', $transaction) ? $transaction['bank.description'] : '',
|
||||||
'base_type' => $this->calculateType($transaction),
|
'base_type' => $this->calculateType($transaction),
|
||||||
'created_at' => $now,
|
'created_at' => $now,
|
||||||
'updated_at' => $now,
|
'updated_at' => $now,
|
||||||
@ -56,22 +56,22 @@ class BankTransformer extends BaseTransformer
|
|||||||
private function calculateType($transaction)
|
private function calculateType($transaction)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(array_key_exists('base_type', $transaction) && $transaction['base_type'] == 'CREDIT')
|
if(array_key_exists('bank.base_type', $transaction) && $transaction['bank.base_type'] == 'CREDIT')
|
||||||
return 'CREDIT';
|
return 'CREDIT';
|
||||||
|
|
||||||
if(array_key_exists('base_type', $transaction) && $transaction['base_type'] == 'DEBIT')
|
if(array_key_exists('bank.base_type', $transaction) && $transaction['bank.base_type'] == 'DEBIT')
|
||||||
return 'DEBIT';
|
return 'DEBIT';
|
||||||
|
|
||||||
if(array_key_exists('category_id',$transaction))
|
if(array_key_exists('bank.category_id', $transaction))
|
||||||
return 'DEBIT';
|
return 'DEBIT';
|
||||||
|
|
||||||
if(array_key_exists('category_type', $transaction) && $transaction['category_type'] == 'Income')
|
if(array_key_exists('bank.category_type', $transaction) && $transaction['bank.category_type'] == 'Income')
|
||||||
return 'CREDIT';
|
return 'CREDIT';
|
||||||
|
|
||||||
if(array_key_exists('category_type', $transaction))
|
if(array_key_exists('bank.category_type', $transaction))
|
||||||
return 'DEBIT';
|
return 'DEBIT';
|
||||||
|
|
||||||
if(array_key_exists('amount', $transaction) && is_numeric($transaction['amount']) && $transaction['amount'] > 0)
|
if(array_key_exists('bank.amount', $transaction) && is_numeric($transaction['bank.amount']) && $transaction['bank.amount'] > 0)
|
||||||
return 'CREDIT';
|
return 'CREDIT';
|
||||||
|
|
||||||
return 'DEBIT';
|
return 'DEBIT';
|
||||||
|
@ -38,9 +38,9 @@ class UserObserver
|
|||||||
*/
|
*/
|
||||||
public function updated(User $user)
|
public function updated(User $user)
|
||||||
{
|
{
|
||||||
if (Ninja::isHosted() && $user->isDirty('phone')) {
|
// if (Ninja::isHosted() && $user->isDirty('phone')) {
|
||||||
VerifyPhone::dispatch($user);
|
// VerifyPhone::dispatch($user);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user