this makes possible adding extra attributes to models

This commit is contained in:
Sevan Nerse
2021-02-26 15:38:45 +03:00
parent 19093668ec
commit 962e626c9e
16 changed files with 139 additions and 43 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Imports\Banking;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Models\Banking\Transaction;
use App\Models\Banking\Transfer as Model;
use App\Models\Setting\Category;
@@ -15,7 +16,11 @@ class Transfers extends Import
public function model(array $row)
{
return new Model($row);
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
}
public function map($row): array
@@ -49,19 +54,19 @@ class Transfers extends Import
private function getExpenseTransactionId($row)
{
$expense_transaction = Transaction::create([
'company_id' => session('company_id'),
'type' => 'expense',
'account_id' => $row['from_account_id'],
'paid_at' => $row['transferred_at'],
'currency_code' => $row['from_currency_code'],
'currency_rate' => $row['from_currency_rate'],
'amount' => $row['amount'],
'contact_id' => 0,
'description' => $row['description'],
'category_id' => Category::transfer(), // Transfer Category ID
'payment_method' => $row['payment_method'],
'reference' => $row['reference'],
]);
'company_id' => session('company_id'),
'type' => 'expense',
'account_id' => $row['from_account_id'],
'paid_at' => $row['transferred_at'],
'currency_code' => $row['from_currency_code'],
'currency_rate' => $row['from_currency_rate'],
'amount' => $row['amount'],
'contact_id' => 0,
'description' => $row['description'],
'category_id' => Category::transfer(), // Transfer Category ID
'payment_method' => $row['payment_method'],
'reference' => $row['reference'],
]);
return $expense_transaction->id;
}
@@ -81,19 +86,19 @@ class Transfers extends Import
}
$income_transaction = Transaction::create([
'company_id' => session('company_id'),
'type' => 'income',
'account_id' => $row['to_account_id'],
'paid_at' => $row['transferred_at'],
'currency_code' => $row['to_currency_code'],
'currency_rate' => $row['to_currency_rate'],
'amount' => $amount,
'contact_id' => 0,
'description' => $row['description'],
'category_id' => Category::transfer(), // Transfer Category ID
'payment_method' => $row['payment_method'],
'reference' => $row['reference'],
]);
'company_id' => session('company_id'),
'type' => 'income',
'account_id' => $row['to_account_id'],
'paid_at' => $row['transferred_at'],
'currency_code' => $row['to_currency_code'],
'currency_rate' => $row['to_currency_rate'],
'amount' => $amount,
'contact_id' => 0,
'description' => $row['description'],
'category_id' => Category::transfer(), // Transfer Category ID
'payment_method' => $row['payment_method'],
'reference' => $row['reference'],
]);
return $income_transaction->id;
}