used jobs to import transfers
This commit is contained in:
parent
c08a8cfc4e
commit
442b238854
@ -3,15 +3,16 @@
|
|||||||
namespace App\Imports\Banking;
|
namespace App\Imports\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Import;
|
use App\Abstracts\Import;
|
||||||
use App\Models\Banking\Transaction;
|
use App\Jobs\Banking\CreateTransaction;
|
||||||
use App\Models\Banking\Transfer as Model;
|
use App\Models\Banking\Transfer as Model;
|
||||||
use App\Models\Setting\Category;
|
use App\Models\Setting\Category;
|
||||||
use App\Traits\Currencies;
|
use App\Traits\Currencies;
|
||||||
|
use App\Traits\Jobs;
|
||||||
use App\Utilities\Date;
|
use App\Utilities\Date;
|
||||||
|
|
||||||
class Transfers extends Import
|
class Transfers extends Import
|
||||||
{
|
{
|
||||||
use Currencies;
|
use Currencies, Jobs;
|
||||||
|
|
||||||
public function model(array $row)
|
public function model(array $row)
|
||||||
{
|
{
|
||||||
@ -48,8 +49,8 @@ class Transfers extends Import
|
|||||||
|
|
||||||
private function getExpenseTransactionId($row)
|
private function getExpenseTransactionId($row)
|
||||||
{
|
{
|
||||||
$expense_transaction = Transaction::create([
|
$expense_transaction = $this->dispatch(new CreateTransaction([
|
||||||
'company_id' => company_id(),
|
'company_id' => $row['company_id'],
|
||||||
'type' => 'expense',
|
'type' => 'expense',
|
||||||
'account_id' => $row['from_account_id'],
|
'account_id' => $row['from_account_id'],
|
||||||
'paid_at' => $row['transferred_at'],
|
'paid_at' => $row['transferred_at'],
|
||||||
@ -61,7 +62,8 @@ class Transfers extends Import
|
|||||||
'category_id' => Category::transfer(), // Transfer Category ID
|
'category_id' => Category::transfer(), // Transfer Category ID
|
||||||
'payment_method' => $row['payment_method'],
|
'payment_method' => $row['payment_method'],
|
||||||
'reference' => $row['reference'],
|
'reference' => $row['reference'],
|
||||||
]);
|
'created_by' => $row['created_by'],
|
||||||
|
]));
|
||||||
|
|
||||||
return $expense_transaction->id;
|
return $expense_transaction->id;
|
||||||
}
|
}
|
||||||
@ -69,6 +71,7 @@ class Transfers extends Import
|
|||||||
private function getIncomeTransactionId($row)
|
private function getIncomeTransactionId($row)
|
||||||
{
|
{
|
||||||
$amount = $row['amount'];
|
$amount = $row['amount'];
|
||||||
|
|
||||||
// Convert amount if not same currency
|
// Convert amount if not same currency
|
||||||
if ($row['from_currency_code'] !== $row['to_currency_code']) {
|
if ($row['from_currency_code'] !== $row['to_currency_code']) {
|
||||||
$amount = $this->convertBetween(
|
$amount = $this->convertBetween(
|
||||||
@ -80,8 +83,8 @@ class Transfers extends Import
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$income_transaction = Transaction::create([
|
$income_transaction = $this->dispatch(new CreateTransaction([
|
||||||
'company_id' => company_id(),
|
'company_id' => $row['company_id'],
|
||||||
'type' => 'income',
|
'type' => 'income',
|
||||||
'account_id' => $row['to_account_id'],
|
'account_id' => $row['to_account_id'],
|
||||||
'paid_at' => $row['transferred_at'],
|
'paid_at' => $row['transferred_at'],
|
||||||
@ -93,7 +96,8 @@ class Transfers extends Import
|
|||||||
'category_id' => Category::transfer(), // Transfer Category ID
|
'category_id' => Category::transfer(), // Transfer Category ID
|
||||||
'payment_method' => $row['payment_method'],
|
'payment_method' => $row['payment_method'],
|
||||||
'reference' => $row['reference'],
|
'reference' => $row['reference'],
|
||||||
]);
|
'created_by' => $row['created_by'],
|
||||||
|
]));
|
||||||
|
|
||||||
return $income_transaction->id;
|
return $income_transaction->id;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user