mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Updated the migration routine, started on data tables.
This commit is contained in:
@@ -95,6 +95,17 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
$type = $this->findAccountType('Expense account');
|
||||
$account = $this->_user->accounts()->where('name', $name)->where('account_type_id', $type->id)->first();
|
||||
|
||||
// create if not found:
|
||||
if(strlen($name) > 0) {
|
||||
$set = [
|
||||
'name' => $name,
|
||||
'user_id' => $this->_user->id,
|
||||
'active' => 1,
|
||||
'account_type_id' => $type->id
|
||||
];
|
||||
$account = $this->firstOrCreate($set);
|
||||
}
|
||||
|
||||
// find cash account as fall back:
|
||||
if (is_null($account)) {
|
||||
$cashType = $this->findAccountType('Cash account');
|
||||
@@ -156,7 +167,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
/**
|
||||
* @param $type
|
||||
*
|
||||
* @return mixed
|
||||
* @return \AccountType|null
|
||||
*/
|
||||
public function findAccountType($type)
|
||||
{
|
||||
@@ -498,10 +509,22 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
protected function _createInitialBalance(\Account $account, $amount = 0, Carbon $date)
|
||||
{
|
||||
// get account type:
|
||||
$initialBalanceAT = \AccountType::where('type', 'Initial balance account')->first();
|
||||
/*
|
||||
* The repositories we need:
|
||||
*/
|
||||
/** @var \Firefly\Helper\Controllers\TransactionInterface $transactions */
|
||||
$transactions = \App::make('Firefly\Helper\Controllers\TransactionInterface');
|
||||
$transactions->overruleUser($this->_user);
|
||||
|
||||
// create new account:
|
||||
|
||||
/*
|
||||
* get account type:
|
||||
*/
|
||||
$initialBalanceAT = $this->findAccountType('Initial balance account');
|
||||
|
||||
/*
|
||||
* create new account
|
||||
*/
|
||||
$initial = new \Account;
|
||||
$initial->accountType()->associate($initialBalanceAT);
|
||||
$initial->user()->associate($this->_user);
|
||||
@@ -509,16 +532,20 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
$initial->active = 0;
|
||||
if ($initial->validate()) {
|
||||
$initial->save();
|
||||
// create new transaction journal (and transactions):
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $transactionJournal */
|
||||
$transactionJournal = \App::make(
|
||||
'Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'
|
||||
);
|
||||
$transactionJournal->overruleUser($this->_user);
|
||||
/*
|
||||
* create new transaction journal (and transactions):
|
||||
*/
|
||||
|
||||
$transactionJournal->createSimpleJournal(
|
||||
$initial, $account, 'Initial Balance for ' . $account->name, $amount, $date
|
||||
);
|
||||
$set =[
|
||||
'account_from_id' => $initial->id,
|
||||
'account_to_id' => $account->id,
|
||||
'description' => 'Initial Balance for ' . $account->name,
|
||||
'what' => 'Opening balance',
|
||||
'amount' => $amount,
|
||||
'category' => '',
|
||||
'date' => $date->format('Y-m-d')
|
||||
];
|
||||
$transactions->store($set);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -128,7 +128,7 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
/*
|
||||
* Already have a piggy bank with this name, we skip it.
|
||||
*/
|
||||
$this->_repository->store($importMap, 'Piggybank', $payload['data']['id'], $piggyBank->id);
|
||||
$repository->store($importMap, 'Piggybank', $payload['data']['id'], $piggyBank->id);
|
||||
\Log::debug('Already imported piggy "' . $payload['data']['name'] . '".');
|
||||
}
|
||||
// update map:
|
||||
|
@@ -56,6 +56,10 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->overruleUser($user);
|
||||
|
||||
/** @var \Firefly\Helper\Controllers\TransactionInterface $transactions */
|
||||
$transactions = \App::make('Firefly\Helper\Controllers\TransactionInterface');
|
||||
$transactions->overruleUser($this->_user);
|
||||
|
||||
/*
|
||||
* Prep some variables from the payload:
|
||||
*/
|
||||
@@ -114,9 +118,18 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
/*
|
||||
* Import transfer:
|
||||
*/
|
||||
$set = [
|
||||
'account_from_id' => $accountFrom->id,
|
||||
'account_to_id' => $accountTo->id,
|
||||
'amount' => $amount,
|
||||
'description' => $description,
|
||||
'date' => $date->format('Y-m-d'),
|
||||
'category' => '',
|
||||
'what' => 'transfer',
|
||||
'return_journal' => true
|
||||
];
|
||||
$journal = $transactions->store($set);
|
||||
|
||||
|
||||
$journal = $this->createSimpleJournal($accountFrom, $accountTo, $description, $amount, $date);
|
||||
$repository->store($importMap, 'Transfer', $transferId, $journal->id);
|
||||
\Log::debug('Imported transfer "' . $description . '" (' . $amount . ') (' . $date->format('Y-m-d') . ')');
|
||||
|
||||
@@ -175,7 +188,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
* @param \Account $account
|
||||
* @param $amount
|
||||
*
|
||||
* @return mixed
|
||||
* @return \Transaction|null
|
||||
*/
|
||||
public function saveTransaction(\TransactionJournal $journal, \Account $account, $amount)
|
||||
{
|
||||
@@ -217,11 +230,15 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->overruleUser($user);
|
||||
|
||||
/** @var \Firefly\Helper\Controllers\TransactionInterface $transactions */
|
||||
$transactions = \App::make('Firefly\Helper\Controllers\TransactionInterface');
|
||||
$transactions->overruleUser($this->_user);
|
||||
|
||||
|
||||
/*
|
||||
* Prep some vars coming out of the pay load:
|
||||
*/
|
||||
@@ -249,7 +266,6 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Find or create the "import account" which is used because at this point, Firefly
|
||||
* doesn't know which beneficiary (expense account) should be connected to this transaction.
|
||||
@@ -286,6 +302,16 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
}
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Prep some data for the import routine:
|
||||
*/
|
||||
$set = [
|
||||
'category' => '',
|
||||
'description' => $description,
|
||||
'date' => $date->format('Y-m-d'),
|
||||
'return_journal' => true
|
||||
];
|
||||
|
||||
|
||||
/*
|
||||
* If the amount is less than zero, we move money to the $importAccount. Otherwise,
|
||||
@@ -293,22 +319,27 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
*/
|
||||
if ($amount < 0) {
|
||||
// if amount is less than zero, move to $importAccount
|
||||
$accountFrom = $assetAccount;
|
||||
$accountTo = $importAccount;
|
||||
$accountFrom = $assetAccount;
|
||||
$accountTo = $importAccount;
|
||||
$set['what'] = 'withdrawal';
|
||||
$set['account_id'] = $accountFrom->id;
|
||||
$set['expense_account'] = $importAccount->name;
|
||||
} else {
|
||||
$accountFrom = $importAccount;
|
||||
$accountTo = $assetAccount;
|
||||
$accountFrom = $importAccount;
|
||||
$accountTo = $assetAccount;
|
||||
$set['what'] = 'deposit';
|
||||
$set['account_id'] = $accountTo->id;
|
||||
$set['revenue_account'] = $accountFrom->name;
|
||||
}
|
||||
|
||||
/*
|
||||
* Modify the amount so it will work with or new transaction journal structure.
|
||||
*/
|
||||
$amount = $amount < 0 ? $amount * -1 : $amount;
|
||||
|
||||
$set['amount'] = $amount < 0 ? $amount * -1 : $amount;
|
||||
/*
|
||||
* Import it:
|
||||
*/
|
||||
$journal = $this->createSimpleJournal($accountFrom, $accountTo, $description, $amount, $date);
|
||||
$journal = $transactions->store($set);
|
||||
$repository->store($importMap, 'Transaction', $transactionId, $journal->id);
|
||||
\Log::debug('Imported transaction "' . $description . '" (' . $amount . ') (' . $date->format('Y-m-d') . ')');
|
||||
|
||||
@@ -337,14 +368,6 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
->where('id', $journalId)->first();
|
||||
}
|
||||
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// public function get()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
*
|
||||
|
@@ -74,7 +74,7 @@ interface TransactionJournalRepositoryInterface
|
||||
* @param \TransactionJournal $journal
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
* @return \Transaction|null
|
||||
*/
|
||||
public function update(\TransactionJournal $journal, $data);
|
||||
|
||||
|
Reference in New Issue
Block a user