mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 09:22:33 +00:00
Expanded to credit cards.
This commit is contained in:
@@ -84,6 +84,7 @@ class AccountController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function edit(Account $account, AccountRepositoryInterface $repository)
|
public function edit(Account $account, AccountRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
|
|
||||||
$what = Config::get('firefly.shortNamesByFullName')[$account->accountType->type];
|
$what = Config::get('firefly.shortNamesByFullName')[$account->accountType->type];
|
||||||
$subTitle = 'Edit ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"';
|
$subTitle = 'Edit ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"';
|
||||||
$subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
|
$subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
|
||||||
@@ -101,6 +102,8 @@ class AccountController extends Controller
|
|||||||
|
|
||||||
$preFilled = [
|
$preFilled = [
|
||||||
'accountRole' => $account->getMeta('accountRole'),
|
'accountRole' => $account->getMeta('accountRole'),
|
||||||
|
'ccType' => $account->getMeta('ccType'),
|
||||||
|
'ccMonthlyPaymentDate' => $account->getMeta('ccMonthlyPaymentDate'),
|
||||||
'openingBalanceDate' => $openingBalance ? $openingBalance->date->format('Y-m-d') : null,
|
'openingBalanceDate' => $openingBalance ? $openingBalance->date->format('Y-m-d') : null,
|
||||||
'openingBalance' => $openingBalanceAmount,
|
'openingBalance' => $openingBalanceAmount,
|
||||||
'virtualBalance' => floatval($account->virtual_balance)
|
'virtualBalance' => floatval($account->virtual_balance)
|
||||||
@@ -227,6 +230,8 @@ class AccountController extends Controller
|
|||||||
'openingBalance' => floatval($request->input('openingBalance')),
|
'openingBalance' => floatval($request->input('openingBalance')),
|
||||||
'openingBalanceDate' => new Carbon($request->input('openingBalanceDate')),
|
'openingBalanceDate' => new Carbon($request->input('openingBalanceDate')),
|
||||||
'openingBalanceCurrency' => intval($request->input('balance_currency_id')),
|
'openingBalanceCurrency' => intval($request->input('balance_currency_id')),
|
||||||
|
'ccType' => $request->input('ccType'),
|
||||||
|
'ccMonthlyPaymentDate' => $request->input('ccMonthlyPaymentDate'),
|
||||||
];
|
];
|
||||||
|
|
||||||
$repository->update($account, $accountData);
|
$repository->update($account, $accountData);
|
||||||
|
@@ -355,6 +355,47 @@ class GoogleChartController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find credit card accounts and possibly unpaid credit card bills.
|
||||||
|
*/
|
||||||
|
$creditCards = Auth::user()->accounts()
|
||||||
|
->hasMetaValue('accountRole', 'ccAsset')
|
||||||
|
->hasMetaValue('ccType', 'monthlyFull')
|
||||||
|
->get(
|
||||||
|
[
|
||||||
|
'accounts.*',
|
||||||
|
'ccType.data as ccType',
|
||||||
|
'accountRole.data as accountRole'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
// if the balance is not zero, the monthly payment is still underway.
|
||||||
|
/** @var Account $creditCard */
|
||||||
|
foreach ($creditCards as $creditCard) {
|
||||||
|
$balance = Steam::balance($creditCard, null, true);
|
||||||
|
$date = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate'));
|
||||||
|
if ($balance < 0) {
|
||||||
|
// unpaid!
|
||||||
|
$unpaid['amount'] += $balance * -1;
|
||||||
|
$unpaid['items'][] = $creditCard->name . ' (expected on the ' . $date->format('jS') . ')';
|
||||||
|
}
|
||||||
|
if ($balance == 0) {
|
||||||
|
// find a transfer TO the credit card which should account for
|
||||||
|
// anything paid. If not, the CC is not yet used.
|
||||||
|
$transactions = $creditCard->transactions()
|
||||||
|
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
|
->before($end)->after($start)->get();
|
||||||
|
if ($transactions->count() > 0) {
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($transactions as $transaction) {
|
||||||
|
$journal = $transaction->transactionJournal;
|
||||||
|
if ($journal->transactionType->type == 'Transfer') {
|
||||||
|
$paid['amount'] += floatval($transaction->amount);
|
||||||
|
$paid['items'][] = $creditCard->name . ' (paid on the ' . $journal->date->format('jS') . ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$chart->addRow('Unpaid: ' . join(', ', $unpaid['items']), $unpaid['amount']);
|
$chart->addRow('Unpaid: ' . join(', ', $unpaid['items']), $unpaid['amount']);
|
||||||
$chart->addRow('Paid: ' . join(', ', $paid['items']), $paid['amount']);
|
$chart->addRow('Paid: ' . join(', ', $paid['items']), $paid['amount']);
|
||||||
$chart->generate();
|
$chart->generate();
|
||||||
|
@@ -30,6 +30,7 @@ class AccountFormRequest extends Request
|
|||||||
{
|
{
|
||||||
$accountRoles = join(',', array_keys(Config::get('firefly.accountRoles')));
|
$accountRoles = join(',', array_keys(Config::get('firefly.accountRoles')));
|
||||||
$types = join(',', array_keys(Config::get('firefly.subTitlesByIdentifier')));
|
$types = join(',', array_keys(Config::get('firefly.subTitlesByIdentifier')));
|
||||||
|
$ccPaymentTypes = join(',', array_keys(Config::get('firefly.ccTypes')));
|
||||||
|
|
||||||
$nameRule = 'required|between:1,100|uniqueAccountForUser';
|
$nameRule = 'required|between:1,100|uniqueAccountForUser';
|
||||||
$idRule = '';
|
$idRule = '';
|
||||||
@@ -46,6 +47,8 @@ class AccountFormRequest extends Request
|
|||||||
'openingBalanceDate' => 'date',
|
'openingBalanceDate' => 'date',
|
||||||
'accountRole' => 'in:' . $accountRoles,
|
'accountRole' => 'in:' . $accountRoles,
|
||||||
'active' => 'boolean',
|
'active' => 'boolean',
|
||||||
|
'ccType' => 'in:' . $ccPaymentTypes,
|
||||||
|
'ccMonthlyPaymentDate' => 'date',
|
||||||
'balance_currency_id' => 'exists:transaction_currencies,id',
|
'balance_currency_id' => 'exists:transaction_currencies,id',
|
||||||
'what' => 'in:' . $types
|
'what' => 'in:' . $types
|
||||||
];
|
];
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
<?php namespace FireflyIII\Models;
|
<?php namespace FireflyIII\Models;
|
||||||
|
|
||||||
|
use App;
|
||||||
use Crypt;
|
use Crypt;
|
||||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Watson\Validating\ValidatingTrait;
|
use Watson\Validating\ValidatingTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,7 +17,7 @@ class Account extends Model
|
|||||||
{
|
{
|
||||||
use SoftDeletes, ValidatingTrait;
|
use SoftDeletes, ValidatingTrait;
|
||||||
|
|
||||||
protected $fillable = ['user_id', 'account_type_id', 'name', 'active','virtual_balance'];
|
protected $fillable = ['user_id', 'account_type_id', 'name', 'active', 'virtual_balance'];
|
||||||
protected $rules
|
protected $rules
|
||||||
= [
|
= [
|
||||||
'user_id' => 'required|exists:users,id',
|
'user_id' => 'required|exists:users,id',
|
||||||
@@ -24,6 +26,37 @@ class Account extends Model
|
|||||||
'active' => 'required|boolean'
|
'active' => 'required|boolean'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $fields
|
||||||
|
*
|
||||||
|
* @return Account|null
|
||||||
|
*/
|
||||||
|
public static function firstOrCreateEncrypted(array $fields)
|
||||||
|
{
|
||||||
|
// everything but the name:
|
||||||
|
$query = Account::orderBy('id');
|
||||||
|
foreach ($fields as $name => $value) {
|
||||||
|
if ($name != 'name') {
|
||||||
|
$query->where($name, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$set = $query->get(['accounts.*']);
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach ($set as $account) {
|
||||||
|
if ($account->name == $fields['name']) {
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// create it!
|
||||||
|
$account = Account::create($fields);
|
||||||
|
if (is_null($account->id)) {
|
||||||
|
// could not create account:
|
||||||
|
App::abort(500, 'Could not create new account with data: ' . json_encode($fields));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
*/
|
*/
|
||||||
@@ -65,7 +98,22 @@ class Account extends Model
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getNameAttribute($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (intval($this->encrypted) == 1) {
|
||||||
|
return Crypt::decrypt($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
return $value;
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
@@ -88,6 +136,22 @@ class Account extends Model
|
|||||||
$query->whereIn('account_types.type', $types);
|
$query->whereIn('account_types.type', $types);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param EloquentBuilder $query
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function scopeHasMetaValue(EloquentBuilder $query, $name, $value)
|
||||||
|
{
|
||||||
|
$joinName = str_replace('.', '_', $name);
|
||||||
|
$query->leftJoin(
|
||||||
|
'account_meta as ' . $joinName, function (JoinClause $join) use ($joinName, $name) {
|
||||||
|
$join->on($joinName . '.account_id', '=', 'accounts.id')->where($joinName . '.name', '=', $name);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$query->where($joinName . '.data', json_encode($value));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param $value
|
||||||
*/
|
*/
|
||||||
@@ -96,46 +160,6 @@ class Account extends Model
|
|||||||
$this->attributes['name'] = Crypt::encrypt($value);
|
$this->attributes['name'] = Crypt::encrypt($value);
|
||||||
$this->attributes['encrypted'] = true;
|
$this->attributes['encrypted'] = true;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getNameAttribute($value)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (intval($this->encrypted) == 1) {
|
|
||||||
return Crypt::decrypt($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
return $value;
|
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $fields
|
|
||||||
* @return Account|null
|
|
||||||
*/
|
|
||||||
public static function firstOrCreateEncrypted(array $fields) {
|
|
||||||
// everything but the name:
|
|
||||||
$query = Account::orderBy('id');
|
|
||||||
foreach($fields as $name => $value) {
|
|
||||||
if($name != 'name') {
|
|
||||||
$query->where($name,$value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$set = $query->get(['accounts.*']);
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach($set as $account) {
|
|
||||||
if($account->name == $fields['name']) {
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// create it!
|
|
||||||
return Account::create($fields);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?php namespace FireflyIII\Models;
|
<?php namespace FireflyIII\Models;
|
||||||
|
|
||||||
|
use Crypt;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Crypt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Budget
|
* Class Budget
|
||||||
@@ -32,6 +32,23 @@ class Budget extends Model
|
|||||||
return ['created_at', 'updated_at', 'deleted_at'];
|
return ['created_at', 'updated_at', 'deleted_at'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getNameAttribute($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (intval($this->encrypted) == 1) {
|
||||||
|
return Crypt::decrypt($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
return $value;
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||||
*/
|
*/
|
||||||
@@ -40,6 +57,15 @@ class Budget extends Model
|
|||||||
return $this->hasManyThrough('FireflyIII\Models\LimitRepetition', 'FireflyIII\Models\BudgetLimit', 'budget_id');
|
return $this->hasManyThrough('FireflyIII\Models\LimitRepetition', 'FireflyIII\Models\BudgetLimit', 'budget_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $value
|
||||||
|
*/
|
||||||
|
public function setNameAttribute($value)
|
||||||
|
{
|
||||||
|
$this->attributes['name'] = Crypt::encrypt($value);
|
||||||
|
$this->attributes['encrypted'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||||
*/
|
*/
|
||||||
@@ -56,30 +82,5 @@ class Budget extends Model
|
|||||||
return $this->belongsTo('FireflyIII\User');
|
return $this->belongsTo('FireflyIII\User');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*/
|
|
||||||
public function setNameAttribute($value)
|
|
||||||
{
|
|
||||||
$this->attributes['name'] = Crypt::encrypt($value);
|
|
||||||
$this->attributes['encrypted'] = true;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getNameAttribute($value)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (intval($this->encrypted) == 1) {
|
|
||||||
return Crypt::decrypt($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
return $value;
|
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,8 @@
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Watson\Validating\ValidatingTrait;
|
use Watson\Validating\ValidatingTrait;
|
||||||
|
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||||
|
use Carbon\Carbon;
|
||||||
/**
|
/**
|
||||||
* Class Transaction
|
* Class Transaction
|
||||||
*
|
*
|
||||||
@@ -30,6 +31,28 @@ class Transaction extends Model
|
|||||||
return $this->belongsTo('FireflyIII\Models\Account');
|
return $this->belongsTo('FireflyIII\Models\Account');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param EloquentBuilder $query
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function scopeAfter(EloquentBuilder $query, Carbon $date)
|
||||||
|
{
|
||||||
|
return $query->where('transaction_journals.date', '>=', $date->format('Y-m-d 00:00:00'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param EloquentBuilder $query
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function scopeBefore(EloquentBuilder $query, Carbon $date)
|
||||||
|
{
|
||||||
|
return $query->where('transaction_journals.date', '<=', $date->format('Y-m-d 00:00:00'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
@@ -321,19 +321,23 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
protected function storeMetadata(Account $account, array $data)
|
protected function storeMetadata(Account $account, array $data)
|
||||||
{
|
{
|
||||||
|
$validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType'];
|
||||||
|
foreach ($validFields as $field) {
|
||||||
|
if (isset($data[$field])) {
|
||||||
$metaData = new AccountMeta(
|
$metaData = new AccountMeta(
|
||||||
[
|
[
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
'name' => 'accountRole',
|
'name' => $field,
|
||||||
'data' => $data['accountRole']
|
'data' => $data[$field]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
if (!$metaData->isValid()) {
|
|
||||||
App::abort(500);
|
|
||||||
}
|
|
||||||
$metaData->save();
|
$metaData->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
* @param Account $opposing
|
* @param Account $opposing
|
||||||
@@ -412,31 +416,29 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
protected function updateMetadata(Account $account, array $data)
|
protected function updateMetadata(Account $account, array $data)
|
||||||
{
|
{
|
||||||
$metaEntries = $account->accountMeta()->get();
|
$validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType'];
|
||||||
$updated = false;
|
$updated = false;
|
||||||
|
|
||||||
/** @var AccountMeta $entry */
|
foreach ($validFields as $field) {
|
||||||
foreach ($metaEntries as $entry) {
|
$entry = $account->accountMeta()->where('name', $field)->first();
|
||||||
if ($entry->name == 'accountRole') {
|
|
||||||
$entry->data = $data['accountRole'];
|
// update if new data is present:
|
||||||
$updated = true;
|
if ($entry && isset($data[$field])) {
|
||||||
|
$entry->data = $data[$field];
|
||||||
$entry->save();
|
$entry->save();
|
||||||
}
|
}
|
||||||
}
|
// no entry but data present?
|
||||||
|
if (!$entry && isset($data[$field])) {
|
||||||
if ($updated === false) {
|
|
||||||
$metaData = new AccountMeta(
|
$metaData = new AccountMeta(
|
||||||
[
|
[
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
'name' => 'accountRole',
|
'name' => $field,
|
||||||
'data' => $data['accountRole']
|
'data' => $data[$field]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
if (!$metaData->isValid()) {
|
|
||||||
App::abort(500);
|
|
||||||
}
|
|
||||||
$metaData->save();
|
$metaData->save();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace FireflyIII\Repositories\Journal;
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
|
use App;
|
||||||
use Auth;
|
use Auth;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
@@ -11,6 +12,7 @@ use FireflyIII\Models\Transaction;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class JournalRepository
|
* Class JournalRepository
|
||||||
@@ -20,6 +22,16 @@ use Illuminate\Support\Collection;
|
|||||||
class JournalRepository implements JournalRepositoryInterface
|
class JournalRepository implements JournalRepositoryInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get users first transaction journal
|
||||||
|
*
|
||||||
|
* @return TransactionJournal
|
||||||
|
*/
|
||||||
|
public function first()
|
||||||
|
{
|
||||||
|
return Auth::user()->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Get the account_id, which is the asset account that paid for the transaction.
|
* Get the account_id, which is the asset account that paid for the transaction.
|
||||||
@@ -149,7 +161,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
'amount' => $data['amount'] * -1
|
'amount' => $data['amount'] * -1
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$transaction = Transaction::create( // second transaction.
|
Transaction::create( // second transaction.
|
||||||
[
|
[
|
||||||
'account_id' => $to->id,
|
'account_id' => $to->id,
|
||||||
'transaction_journal_id' => $journal->id,
|
'transaction_journal_id' => $journal->id,
|
||||||
@@ -234,12 +246,14 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
|
|
||||||
if (strlen($data['expense_account']) > 0) {
|
if (strlen($data['expense_account']) > 0) {
|
||||||
$toType = AccountType::where('type', 'Expense account')->first();
|
$toType = AccountType::where('type', 'Expense account')->first();
|
||||||
$to = Account::firstOrCreate(
|
$to = Account::firstOrCreateEncrypted(
|
||||||
['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => $data['expense_account'], 'active' => 1]
|
['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => $data['expense_account'], 'active' => 1]
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$toType = AccountType::where('type', 'Cash account')->first();
|
$toType = AccountType::where('type', 'Cash account')->first();
|
||||||
$to = Account::firstOrCreateEncrypted(['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => 'Cash account', 'active' => 1]);
|
$to = Account::firstOrCreateEncrypted(
|
||||||
|
['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => 'Cash account', 'active' => 1]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -253,7 +267,9 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$toType = AccountType::where('type', 'Cash account')->first();
|
$toType = AccountType::where('type', 'Cash account')->first();
|
||||||
$from = Account::firstOrCreateEncrypted(['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => 'Cash account', 'active' => 1]);
|
$from = Account::firstOrCreateEncrypted(
|
||||||
|
['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => 'Cash account', 'active' => 1]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -262,18 +278,16 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
$to = Account::find($data['account_to_id']);
|
$to = Account::find($data['account_to_id']);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (is_null($to->id)) {
|
||||||
|
Log::error('"to"-account is null, so we cannot continue!');
|
||||||
|
App::abort(500, '"to"-account is null, so we cannot continue!');
|
||||||
|
}
|
||||||
|
if (is_null($from->id)) {
|
||||||
|
Log::error('"from"-account is null, so we cannot continue!');
|
||||||
|
App::abort(500, '"from"-account is null, so we cannot continue!');
|
||||||
|
}
|
||||||
|
|
||||||
return [$from, $to];
|
return [$from, $to];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get users first transaction journal
|
|
||||||
*
|
|
||||||
* @return TransactionJournal
|
|
||||||
*/
|
|
||||||
public function first()
|
|
||||||
{
|
|
||||||
return Auth::user()->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -66,6 +66,8 @@ class ExpandedForm
|
|||||||
'targetamount' => 'Target amount',
|
'targetamount' => 'Target amount',
|
||||||
'accountRole' => 'Account role',
|
'accountRole' => 'Account role',
|
||||||
'openingBalanceDate' => 'Opening balance date',
|
'openingBalanceDate' => 'Opening balance date',
|
||||||
|
'ccType' => 'Credit card payment plan',
|
||||||
|
'ccMonthlyPaymentDate' => 'Credit card monthly payment date',
|
||||||
'piggy_bank_id' => 'Piggy bank'];
|
'piggy_bank_id' => 'Piggy bank'];
|
||||||
|
|
||||||
|
|
||||||
@@ -192,6 +194,24 @@ class ExpandedForm
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
* @param null $value
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function month($name, $value = null, array $options = [])
|
||||||
|
{
|
||||||
|
$label = $this->label($name, $options);
|
||||||
|
$options = $this->expandOptionArray($name, $label, $options);
|
||||||
|
$classes = $this->getHolderClasses($name);
|
||||||
|
$value = $this->fillFieldValue($name, $value);
|
||||||
|
$html = View::make('form.month', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @param null $value
|
* @param null $value
|
||||||
|
@@ -32,6 +32,9 @@ return [
|
|||||||
'6M' => 'half year',
|
'6M' => 'half year',
|
||||||
'custom' => '(custom)'
|
'custom' => '(custom)'
|
||||||
],
|
],
|
||||||
|
'ccTypes' => [
|
||||||
|
'monthlyFull' => 'Full payment every month'
|
||||||
|
],
|
||||||
'range_to_name' => [
|
'range_to_name' => [
|
||||||
'1D' => 'one day',
|
'1D' => 'one day',
|
||||||
'1W' => 'one week',
|
'1W' => 'one week',
|
||||||
|
@@ -10,16 +10,19 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>
|
<p>
|
||||||
Are you sure?
|
Are you sure that you want to delete the {{strtolower($account->accountType->type)}} "{{$account->name}}"?
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@if($account->transactions()->count() > 0)
|
@if($account->transactions()->count() > 0)
|
||||||
<p class="text-info">
|
<p class="text-danger">
|
||||||
Account "{{{$account->name}}}" still has {{$account->transactions()->count()}} transaction(s) associated to it.
|
{{ucfirst($account->accountType->type)}} "{{{$account->name}}}" still has {{$account->transactions()->count()}} transaction(s) associated to it. These will be deleted as well.
|
||||||
These will be deleted as well.
|
</p>
|
||||||
|
@endif
|
||||||
|
@if($account->piggyBanks()->count() > 0)
|
||||||
|
<p class="text-danger">
|
||||||
|
{{ucfirst($account->accountType->type)}} "{{{$account->name}}}" still has {{$account->piggyBanks()->count()}} piggy bank(s) associated to it. These will be deleted as well.
|
||||||
</p>
|
</p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
|
<button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
|
||||||
<a href="{{URL::previous()}}" class="btn-default btn">Cancel</a >
|
<a href="{{URL::previous()}}" class="btn-default btn">Cancel</a >
|
||||||
|
@@ -45,7 +45,8 @@
|
|||||||
<i class="fa fa-credit-card"></i> Credit card options
|
<i class="fa fa-credit-card"></i> Credit card options
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
Will be here.
|
{!! ExpandedForm::select('ccType',Config::get('firefly.ccTypes')) !!}
|
||||||
|
{!! ExpandedForm::date('ccMonthlyPaymentDate',null,['helpText' => 'Select any year and any month, it will be ignored anway. Only the day of the month is relevant.']) !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
@@ -10,9 +10,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>
|
<p>
|
||||||
Are you sure?
|
Are you sure that you want to delete bill "{{{$bill->name}}}"?
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@if($bill->transactionjournals()->count() > 0)
|
||||||
|
<p class="text-info">
|
||||||
|
Bill "{{{$bill->name}}}" still has {{$bill->transactionjournals()->count()}} transactions connected
|
||||||
|
to it. These will <strong>not</strong> be removed but will lose their connection to this bill.
|
||||||
|
</p>
|
||||||
|
@endif
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
|
<button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
|
||||||
<a href="{{URL::previous()}}" class="btn-default btn">Cancel</a >
|
<a href="{{URL::previous()}}" class="btn-default btn">Cancel</a >
|
||||||
|
@@ -10,9 +10,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>
|
<p>
|
||||||
Are you sure?
|
Are you sure that you want to delete budget "{{{$budget->name}}}"?
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@if($budget->transactionjournals()->count() > 0)
|
||||||
|
<p class="text-info">
|
||||||
|
Budget "{{{$budget->name}}}" still has {{$budget->transactionjournals()->count()}} transactions connected
|
||||||
|
to it. These will <strong>not</strong> be removed but will lose their connection to this budget.
|
||||||
|
</p>
|
||||||
|
@endif
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
|
<button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
|
||||||
<a href="{{URL::previous()}}" class="btn-default btn">Cancel</a >
|
<a href="{{URL::previous()}}" class="btn-default btn">Cancel</a >
|
||||||
|
@@ -10,9 +10,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>
|
<p>
|
||||||
Are you sure?
|
Are you sure that you want to delete category "{{$category->name}}"?
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@if($category->transactionjournals()->count() > 0)
|
||||||
|
<p class="text-info">
|
||||||
|
Category "{{{$category->name}}}" still has {{$category->transactionjournals()->count()}} transactions connected
|
||||||
|
to it. These will <strong>not</strong> be removed but will lose their connection to this category.
|
||||||
|
</p>
|
||||||
|
@endif
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
|
<button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
|
||||||
<a href="{{URL::previous()}}" class="btn-default btn">Cancel</a >
|
<a href="{{URL::previous()}}" class="btn-default btn">Cancel</a >
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>
|
<p>
|
||||||
Are you sure?
|
Are you sure that you want to delete currency "{{{$currency->name}}}"?
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
|
<button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
<label for="{{{$options['id']}}}" class="col-sm-4 control-label">{{{$label}}}</label>
|
<label for="{{{$options['id']}}}" class="col-sm-4 control-label">{{{$label}}}</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
{!! Form::input('date', $name, $value, $options) !!}
|
{!! Form::input('date', $name, $value, $options) !!}
|
||||||
|
@include('form.help')
|
||||||
@include('form.feedback')
|
@include('form.feedback')
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
3
resources/views/form/help.blade.php
Normal file
3
resources/views/form/help.blade.php
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
@if(isset($options['helpText']))
|
||||||
|
<p class="help-block">{{$options['helpText']}}</p>
|
||||||
|
@endif
|
8
resources/views/form/month.blade.php
Normal file
8
resources/views/form/month.blade.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<div class="{{{$classes}}}">
|
||||||
|
<label for="{{{$options['id']}}}" class="col-sm-4 control-label">{{{$label}}}</label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
{!! Form::input('month', $name, $value, $options) !!}
|
||||||
|
@include('form.help')
|
||||||
|
@include('form.feedback')
|
||||||
|
</div>
|
||||||
|
</div>
|
@@ -2,9 +2,7 @@
|
|||||||
<label for="{{{$options['id']}}}" class="col-sm-4 control-label">{{{$label}}}</label>
|
<label for="{{{$options['id']}}}" class="col-sm-4 control-label">{{{$label}}}</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
{!! Form::select($name, $list, $selected , $options ) !!}
|
{!! Form::select($name, $list, $selected , $options ) !!}
|
||||||
@if(isset($options['helpText']))
|
@include('form.help')
|
||||||
<p class="help-block">{{$options['helpText']}}</p>
|
|
||||||
@endif
|
|
||||||
@include('form.feedback')
|
@include('form.feedback')
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user