Skip to content

Commit

Permalink
used jobs to import transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Sep 6, 2021
1 parent c08a8cf commit 442b238
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions app/Imports/Banking/Transfers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
namespace App\Imports\Banking;

use App\Abstracts\Import;
use App\Models\Banking\Transaction;
use App\Jobs\Banking\CreateTransaction;
use App\Models\Banking\Transfer as Model;
use App\Models\Setting\Category;
use App\Traits\Currencies;
use App\Traits\Jobs;
use App\Utilities\Date;

class Transfers extends Import
{
use Currencies;
use Currencies, Jobs;

public function model(array $row)
{
Expand Down Expand Up @@ -48,8 +49,8 @@ public function rules(): array

private function getExpenseTransactionId($row)
{
$expense_transaction = Transaction::create([
'company_id' => company_id(),
$expense_transaction = $this->dispatch(new CreateTransaction([
'company_id' => $row['company_id'],
'type' => 'expense',
'account_id' => $row['from_account_id'],
'paid_at' => $row['transferred_at'],
Expand All @@ -61,14 +62,16 @@ private function getExpenseTransactionId($row)
'category_id' => Category::transfer(), // Transfer Category ID
'payment_method' => $row['payment_method'],
'reference' => $row['reference'],
]);
'created_by' => $row['created_by'],
]));

return $expense_transaction->id;
}

private function getIncomeTransactionId($row)
{
$amount = $row['amount'];

// Convert amount if not same currency
if ($row['from_currency_code'] !== $row['to_currency_code']) {
$amount = $this->convertBetween(
Expand All @@ -80,8 +83,8 @@ private function getIncomeTransactionId($row)
);
}

$income_transaction = Transaction::create([
'company_id' => company_id(),
$income_transaction = $this->dispatch(new CreateTransaction([
'company_id' => $row['company_id'],
'type' => 'income',
'account_id' => $row['to_account_id'],
'paid_at' => $row['transferred_at'],
Expand All @@ -93,7 +96,8 @@ private function getIncomeTransactionId($row)
'category_id' => Category::transfer(), // Transfer Category ID
'payment_method' => $row['payment_method'],
'reference' => $row['reference'],
]);
'created_by' => $row['created_by'],
]));

return $income_transaction->id;
}
Expand Down

0 comments on commit 442b238

Please sign in to comment.