mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-03 19:16:51 +00:00
Some cleanup, some bug fixes.
This commit is contained in:
@@ -22,6 +22,8 @@ class AccountController extends \BaseController
|
|||||||
{
|
{
|
||||||
$this->_accounts = $accounts;
|
$this->_accounts = $accounts;
|
||||||
$this->_repository = $repository;
|
$this->_repository = $repository;
|
||||||
|
View::share('mainTitleIcon', 'fa-credit-card');
|
||||||
|
View::share('title', 'Accounts');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,9 +31,11 @@ class AccountController extends \BaseController
|
|||||||
*/
|
*/
|
||||||
public function create($what)
|
public function create($what)
|
||||||
{
|
{
|
||||||
return View::make('accounts.create')->with('title', 'Accounts')->with(
|
View::share('subTitleIcon', 'fa-money');
|
||||||
'subTitle', 'Create a new ' . $what . ' account'
|
|
||||||
)->with('what', $what);
|
return View::make('accounts.create')->with('subTitle', 'Create a new ' . $what . ' account')->with(
|
||||||
|
'what', $what
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,11 +43,13 @@ class AccountController extends \BaseController
|
|||||||
*/
|
*/
|
||||||
public function asset()
|
public function asset()
|
||||||
{
|
{
|
||||||
|
View::share('subTitleIcon','fa-money');
|
||||||
|
|
||||||
$accounts = $this->_repository->getOfTypes(['Asset account', 'Default account']);
|
$accounts = $this->_repository->getOfTypes(['Asset account', 'Default account']);
|
||||||
|
|
||||||
return View::make('accounts.asset')->with('title', 'Accounts')->with('subTitle', 'Asset accounts')->with(
|
return View::make('accounts.asset')->with('subTitle', 'Asset accounts')->with(
|
||||||
'accounts', $accounts
|
'accounts', $accounts
|
||||||
)->with('titleIcon','fa-money');
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,9 +57,11 @@ class AccountController extends \BaseController
|
|||||||
*/
|
*/
|
||||||
public function expense()
|
public function expense()
|
||||||
{
|
{
|
||||||
|
View::share('subTitleIcon','fa-shopping-cart');
|
||||||
|
|
||||||
$accounts = $this->_repository->getOfTypes(['Expense account', 'Beneficiary account']);
|
$accounts = $this->_repository->getOfTypes(['Expense account', 'Beneficiary account']);
|
||||||
|
|
||||||
return View::make('accounts.expense')->with('title', 'Accounts')->with('subTitle', 'Expense accounts')->with(
|
return View::make('accounts.expense')->with('subTitle', 'Expense accounts')->with(
|
||||||
'accounts', $accounts
|
'accounts', $accounts
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -63,9 +71,11 @@ class AccountController extends \BaseController
|
|||||||
*/
|
*/
|
||||||
public function revenue()
|
public function revenue()
|
||||||
{
|
{
|
||||||
|
View::share('subTitleIcon','fa-download');
|
||||||
|
|
||||||
$accounts = $this->_repository->getOfTypes(['Revenue account']);
|
$accounts = $this->_repository->getOfTypes(['Revenue account']);
|
||||||
|
|
||||||
return View::make('accounts.revenue')->with('title', 'Accounts')->with('subTitle', 'Revenue accounts')->with(
|
return View::make('accounts.revenue')->with('subTitle', 'Revenue accounts')->with(
|
||||||
'accounts', $accounts
|
'accounts', $accounts
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -119,8 +129,8 @@ class AccountController extends \BaseController
|
|||||||
{
|
{
|
||||||
$openingBalance = $this->_accounts->openingBalanceTransaction($account);
|
$openingBalance = $this->_accounts->openingBalanceTransaction($account);
|
||||||
return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance)
|
return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance)
|
||||||
->with('title','Accounts')
|
->with('title', 'Accounts')
|
||||||
->with('subTitle', 'Edit '.strtolower($account->accountType->type).' "' . $account->name . '"');
|
->with('subTitle', 'Edit ' . strtolower($account->accountType->type) . ' "' . $account->name . '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,7 +138,7 @@ class AccountController extends \BaseController
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return View::make('error')->with('message','This view has been disabled');
|
return View::make('error')->with('message', 'This view has been disabled');
|
||||||
// $accounts = $this->_repository->get();
|
// $accounts = $this->_repository->get();
|
||||||
// $set = [
|
// $set = [
|
||||||
// 'personal' => [],
|
// 'personal' => [],
|
||||||
@@ -159,8 +169,8 @@ class AccountController extends \BaseController
|
|||||||
|
|
||||||
return View::make('accounts.show')->with('account', $account)->with('show', $data)->with(
|
return View::make('accounts.show')->with('account', $account)->with('show', $data)->with(
|
||||||
'subTitle',
|
'subTitle',
|
||||||
'Details for '.strtolower($account->accountType->type).' "' . $account->name . '"'
|
'Details for ' . strtolower($account->accountType->type) . ' "' . $account->name . '"'
|
||||||
)->with('title','Accounts');
|
)->with('title', 'Accounts');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -135,17 +135,33 @@ class Import
|
|||||||
|
|
||||||
// if Firefly tries to import a beneficiary, Firefly will "merge" already existing ones,
|
// if Firefly tries to import a beneficiary, Firefly will "merge" already existing ones,
|
||||||
// so we don't care:
|
// so we don't care:
|
||||||
|
|
||||||
if (isset($payload['data']['account_type']) && $payload['data']['account_type'] == 'Expense account') {
|
if (isset($payload['data']['account_type']) && $payload['data']['account_type'] == 'Expense account') {
|
||||||
// store beneficiary
|
// unset some data to make firstOrCreate work:
|
||||||
$acct = $this->_accounts->createOrFindBeneficiary($payload['data']['name']);
|
$oldPayloadId = $payload['data']['id'];
|
||||||
|
unset($payload['data']['type_id'], $payload['data']['parent_component_id'],
|
||||||
|
$payload['data']['reporting'], $payload['data']['type'], $payload['data']['id'], $payload['data']['account_type']);
|
||||||
|
// set other data to make it work:
|
||||||
|
$expenseAccountType = $this->_accounts->findAccountType('Expense account');
|
||||||
|
$payload['data']['account_type_id'] = $expenseAccountType->id;
|
||||||
|
|
||||||
|
$acct = $this->_accounts->firstOrCreate((array)$payload['data']);
|
||||||
|
if (is_null($acct)) {
|
||||||
|
echo '$acct (1) is null, exit!';
|
||||||
|
var_dump($acct);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
\Log::debug('Imported ' . $payload['class'] . ' "' . $payload['data']['name'] . '".');
|
\Log::debug('Imported ' . $payload['class'] . ' "' . $payload['data']['name'] . '".');
|
||||||
$this->_repository->store($importMap, 'Account', $payload['data']['id'], $acct->id);
|
$this->_repository->store($importMap, 'Account', $oldPayloadId, $acct->id);
|
||||||
$job->delete();
|
$job->delete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// but we cannot merge accounts, so we need to search first:
|
// but Firefly cannot merge other types accounts, so we need to search first:
|
||||||
$acct = $this->_accounts->findByName($payload['data']['name']);
|
$assetAccountType = $this->_accounts->findAccountType('Asset account');
|
||||||
|
|
||||||
|
// we need to find it by name AND type.
|
||||||
|
$acct = $this->_accounts->findByNameAndAccountType($payload['data']['name'], $assetAccountType);
|
||||||
if (is_null($acct)) {
|
if (is_null($acct)) {
|
||||||
// store new one!
|
// store new one!
|
||||||
$acct = $this->_accounts->store((array)$payload['data']);
|
$acct = $this->_accounts->store((array)$payload['data']);
|
||||||
@@ -322,7 +338,7 @@ class Import
|
|||||||
'Updated transactions (#' . $journal->id . '), #' . $transaction->id . '\'s Account.'
|
'Updated transactions (#' . $journal->id . '), #' . $transaction->id . '\'s Account.'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
\Log::error('Found account type: "' . $accountType.'" instead of expected "Import account"');
|
\Log::error('Found account type: "' . $accountType . '" instead of expected "Import account"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,8 +548,14 @@ class Import
|
|||||||
// find or create the account type for the import account.
|
// find or create the account type for the import account.
|
||||||
// find or create the account for the import account.
|
// find or create the account for the import account.
|
||||||
$accountType = $this->_accounts->findAccountType('Import account');
|
$accountType = $this->_accounts->findAccountType('Import account');
|
||||||
$importAccount = $this->_accounts->createOrFind('Import account', $accountType);
|
$importAccount = $this->_accounts->firstOrCreate(
|
||||||
|
[
|
||||||
|
'account_type_id' => $accountType->id,
|
||||||
|
'name' => 'Import account',
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'active' => 1,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
// if amount is more than zero, move from $importAccount
|
// if amount is more than zero, move from $importAccount
|
||||||
$amount = floatval($payload['data']['amount']);
|
$amount = floatval($payload['data']['amount']);
|
||||||
@@ -560,6 +582,7 @@ class Import
|
|||||||
|
|
||||||
|
|
||||||
if (is_null($current)) {
|
if (is_null($current)) {
|
||||||
|
|
||||||
$journal = $this->_journals->createSimpleJournal(
|
$journal = $this->_journals->createSimpleJournal(
|
||||||
$accountFrom, $accountTo,
|
$accountFrom, $accountTo,
|
||||||
$payload['data']['description'], $amount, $date
|
$payload['data']['description'], $amount, $date
|
||||||
|
@@ -47,6 +47,14 @@ interface AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function find($accountId);
|
public function find($accountId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
* @param \AccountType $type
|
||||||
|
*
|
||||||
|
* @return \Account
|
||||||
|
*/
|
||||||
|
public function findByNameAndAccountType($name, \AccountType $type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $type
|
* @param $type
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
@@ -43,6 +43,16 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
|||||||
return $accounts;
|
return $accounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
* @param \AccountType $type
|
||||||
|
*
|
||||||
|
* @return \Account
|
||||||
|
*/
|
||||||
|
public function findByNameAndAccountType($name, \AccountType $type) {
|
||||||
|
return $this->_user->accounts()->where('name',$name)->where('account_type_id',$type->id)->first();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
@@ -155,44 +165,44 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
|||||||
// whatever the result, return the account.
|
// whatever the result, return the account.
|
||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// /**
|
/**
|
||||||
// * @param \Account $account
|
* @param \Account $account
|
||||||
// * @param int $amount
|
* @param int $amount
|
||||||
// * @param Carbon $date
|
* @param Carbon $date
|
||||||
// *
|
*
|
||||||
// * @return bool
|
* @return bool
|
||||||
// * @SuppressWarnings(PHPMD.CamelCaseMethodName)
|
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
|
||||||
// */
|
*/
|
||||||
// protected function _createInitialBalance(\Account $account, $amount = 0, Carbon $date)
|
protected function _createInitialBalance(\Account $account, $amount = 0, Carbon $date)
|
||||||
// {
|
{
|
||||||
// // get account type:
|
// get account type:
|
||||||
// $initialBalanceAT = \AccountType::where('type', 'Initial balance account')->first();
|
$initialBalanceAT = \AccountType::where('type', 'Initial balance account')->first();
|
||||||
//
|
|
||||||
// // create new account:
|
// create new account:
|
||||||
// $initial = new \Account;
|
$initial = new \Account;
|
||||||
// $initial->accountType()->associate($initialBalanceAT);
|
$initial->accountType()->associate($initialBalanceAT);
|
||||||
// $initial->user()->associate($this->_user);
|
$initial->user()->associate($this->_user);
|
||||||
// $initial->name = $account->name . ' initial balance';
|
$initial->name = $account->name . ' initial balance';
|
||||||
// $initial->active = 0;
|
$initial->active = 0;
|
||||||
// if ($initial->validate()) {
|
if ($initial->validate()) {
|
||||||
// $initial->save();
|
$initial->save();
|
||||||
// // create new transaction journal (and transactions):
|
// create new transaction journal (and transactions):
|
||||||
// /** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $transactionJournal */
|
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $transactionJournal */
|
||||||
// $transactionJournal = \App::make(
|
$transactionJournal = \App::make(
|
||||||
// 'Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'
|
'Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'
|
||||||
// );
|
);
|
||||||
// $transactionJournal->overruleUser($this->_user);
|
$transactionJournal->overruleUser($this->_user);
|
||||||
//
|
|
||||||
// $transactionJournal->createSimpleJournal(
|
$transactionJournal->createSimpleJournal(
|
||||||
// $initial, $account, 'Initial Balance for ' . $account->name, $amount, $date
|
$initial, $account, 'Initial Balance for ' . $account->name, $amount, $date
|
||||||
// );
|
);
|
||||||
//
|
|
||||||
// return true;
|
return true;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Account $account
|
* @param \Account $account
|
||||||
|
@@ -411,7 +411,8 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
|||||||
$toTransaction->description = null;
|
$toTransaction->description = null;
|
||||||
$toTransaction->amount = $amountTo;
|
$toTransaction->amount = $amountTo;
|
||||||
if (!$toTransaction->validate()) {
|
if (!$toTransaction->validate()) {
|
||||||
throw new FireflyException('Cannot create valid transaction (to): ' . $toTransaction->errors()->first());
|
|
||||||
|
throw new FireflyException('Cannot create valid transaction (to): ' . $toTransaction->errors()->first().': ' . print_r($toAccount->toArray(),true));
|
||||||
}
|
}
|
||||||
$toTransaction->save();
|
$toTransaction->save();
|
||||||
|
|
||||||
|
@@ -107,6 +107,30 @@ use LaravelBook\Ardent\Builder;
|
|||||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
* 'Category[] $categories
|
* 'Category[] $categories
|
||||||
* @method static \TransactionJournal accountIs($account)
|
* @method static \TransactionJournal accountIs($account)
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Budget[] $budgets
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Category[] $categories
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Budget[] $budgets
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Category[] $categories
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Budget[] $budgets
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Category[] $categories
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Budget[] $budgets
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Category[] $categories
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Budget[] $budgets
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Category[] $categories
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Budget[] $budgets
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Category[] $categories
|
||||||
*/
|
*/
|
||||||
class TransactionJournal extends Ardent
|
class TransactionJournal extends Ardent
|
||||||
{
|
{
|
||||||
|
@@ -32,11 +32,14 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<h1 class="page-header">
|
<h1 class="page-header">
|
||||||
|
@if(isset($mainTitleIcon))
|
||||||
|
<i class="fa {{{$mainTitleIcon}}}"></i>
|
||||||
|
@endif
|
||||||
{{$title or '(no title)'}}
|
{{$title or '(no title)'}}
|
||||||
@if(isset($subTitle))
|
@if(isset($subTitle))
|
||||||
<small>
|
<small>
|
||||||
@if(isset($titleIcon))
|
@if(isset($subTitleIcon))
|
||||||
<i class="fa {{{$titleIcon}}}"></i>
|
<i class="fa {{{$subTitleIcon}}}"></i>
|
||||||
@endif
|
@endif
|
||||||
{{$subTitle}}
|
{{$subTitle}}
|
||||||
</small>
|
</small>
|
||||||
|
Reference in New Issue
Block a user