mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-22 06:23:12 -06:00
Merge branch 'release/3.4.0.3'
This commit is contained in:
commit
36aad379ff
16
README.md
16
README.md
@ -1,4 +1,4 @@
|
||||
Firefly III (v3.4.0.2)
|
||||
Firefly III (v3.4.0.3)
|
||||
===========
|
||||
|
||||
[![Build Status](https://travis-ci.org/JC5/firefly-iii.svg?branch=develop)](https://travis-ci.org/JC5/firefly-iii)
|
||||
@ -68,13 +68,19 @@ Some stuff has been removed:
|
||||
|
||||
## Screenshots
|
||||
|
||||
![Index](http://i.imgur.com/TkZNIer.png)
|
||||
![Index](https://i.nder.be/c09vfw90)
|
||||
|
||||
![Accounts](http://i.imgur.com/YE8WavP.png)
|
||||
![Accounts](https://i.nder.be/hkn0vhcg)
|
||||
|
||||
![Budgets](http://i.imgur.com/Go0M6Nd.png)
|
||||
![Budgets](https://i.nder.be/h2snx2mw)
|
||||
|
||||
![Reports](http://i.imgur.com/EnEIyQI.png)
|
||||
![Reports 1](https://i.nder.be/c9f8zy5c)
|
||||
|
||||
![Reports 2](https://i.nder.be/ghvs5png)
|
||||
|
||||
![Bills](https://i.nder.be/h58kh00p)
|
||||
|
||||
![Piggy banks](https://i.nder.be/hkud0h53)
|
||||
|
||||
## Current state
|
||||
I have the basics up and running. Test coverage is currently coming, slowly.
|
||||
|
@ -136,7 +136,7 @@ class ReportHelper implements ReportHelperInterface
|
||||
$end = clone $date;
|
||||
$sharedAccounts = [];
|
||||
if ($showSharedReports === false) {
|
||||
$sharedCollection = \Auth::user()->accounts()
|
||||
$sharedCollection = Auth::user()->accounts()
|
||||
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
|
||||
->where('account_meta.name', '=', 'accountRole')
|
||||
->where('account_meta.data', '=', json_encode('sharedAsset'))
|
||||
|
@ -230,7 +230,7 @@ class TransactionJournal extends Model
|
||||
*/
|
||||
public function setDescriptionAttribute($value)
|
||||
{
|
||||
$this->attributes['description'] = \Crypt::encrypt($value);
|
||||
$this->attributes['description'] = Crypt::encrypt($value);
|
||||
$this->attributes['encrypted'] = true;
|
||||
}
|
||||
|
||||
|
@ -117,8 +117,8 @@ class EventServiceProvider extends ServiceProvider
|
||||
try {
|
||||
$repetition->save();
|
||||
} catch (QueryException $e) {
|
||||
\Log::error('Trying to save new LimitRepetition failed!');
|
||||
\Log::error($e->getMessage());
|
||||
Log::error('Trying to save new LimitRepetition failed!');
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
if ($set->count() == 1) {
|
||||
|
@ -510,9 +510,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
'encrypted' => true
|
||||
]
|
||||
);
|
||||
if (!$journal->isValid()) {
|
||||
App::abort(500);
|
||||
}
|
||||
$journal->save();
|
||||
|
||||
|
||||
@ -536,9 +533,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
'amount' => $firstAmount
|
||||
]
|
||||
);
|
||||
if (!$one->isValid()) {
|
||||
App::abort(500);
|
||||
}
|
||||
$one->save();
|
||||
|
||||
// second transaction: to
|
||||
@ -549,9 +543,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
'amount' => $secondAmount
|
||||
]
|
||||
);
|
||||
if (!$two->isValid()) {
|
||||
App::abort(500);
|
||||
}
|
||||
$two->save();
|
||||
|
||||
return $journal;
|
||||
|
@ -4,6 +4,7 @@ namespace FireflyIII\Repositories\Bill;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Bill;
|
||||
@ -119,7 +120,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
*/
|
||||
public function getPossiblyRelatedJournals(Bill $bill)
|
||||
{
|
||||
$set = \DB::table('transactions')->where('amount', '>', 0)->where('amount', '>=', $bill->amount_min)->where('amount', '<=', $bill->amount_max)->get(
|
||||
$set = DB::table('transactions')->where('amount', '>', 0)->where('amount', '>=', $bill->amount_min)->where('amount', '<=', $bill->amount_max)->get(
|
||||
['transaction_journal_id']
|
||||
);
|
||||
$ids = [];
|
||||
@ -261,11 +262,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
/*
|
||||
* Attach expense account to description for more narrow matching.
|
||||
*/
|
||||
if (count($journal->transactions) < 2) {
|
||||
$transactions = $journal->transactions()->get();
|
||||
} else {
|
||||
$transactions = $journal->transactions;
|
||||
}
|
||||
$transactions = $journal->transactions()->get();
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
/** @var Account $account */
|
||||
|
@ -10,6 +10,7 @@ use FireflyIII\Models\LimitRepetition;
|
||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Input;
|
||||
|
||||
/**
|
||||
* Class BudgetRepository
|
||||
@ -162,7 +163,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function getJournals(Budget $budget, LimitRepetition $repetition = null, $take = 50)
|
||||
{
|
||||
$offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $take : 0;
|
||||
$offset = intval(Input::get('page')) > 0 ? intval(Input::get('page')) * $take : 0;
|
||||
|
||||
|
||||
$setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset)
|
||||
|
@ -39,17 +39,10 @@ class Amount
|
||||
if (defined('FFCURRENCYSYMBOL')) {
|
||||
return FFCURRENCYSYMBOL;
|
||||
}
|
||||
if (\Cache::has('FFCURRENCYSYMBOL')) {
|
||||
define('FFCURRENCYSYMBOL', \Cache::get('FFCURRENCYSYMBOL'));
|
||||
|
||||
return FFCURRENCYSYMBOL;
|
||||
}
|
||||
|
||||
$currencyPreference = Prefs::get('currencyPreference', 'EUR');
|
||||
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
|
||||
|
||||
\Cache::forever('FFCURRENCYSYMBOL', $currency->symbol);
|
||||
|
||||
define('FFCURRENCYSYMBOL', $currency->symbol);
|
||||
|
||||
return $currency->symbol;
|
||||
@ -160,7 +153,6 @@ class Amount
|
||||
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
|
||||
if ($currency) {
|
||||
|
||||
Cache::forever('FFCURRENCYCODE', $currency->code);
|
||||
define('FFCURRENCYCODE', $currency->code);
|
||||
|
||||
return $currency->code;
|
||||
|
10
composer.lock
generated
10
composer.lock
generated
@ -943,16 +943,16 @@
|
||||
},
|
||||
{
|
||||
"name": "laravel/framework",
|
||||
"version": "v5.0.28",
|
||||
"version": "v5.0.29",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/framework.git",
|
||||
"reference": "06a09429322cf53e5bd4587db1060f02a291562e"
|
||||
"reference": "aa7046645e094b0134a4125cce6694f4b076ac62"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/06a09429322cf53e5bd4587db1060f02a291562e",
|
||||
"reference": "06a09429322cf53e5bd4587db1060f02a291562e",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/aa7046645e094b0134a4125cce6694f4b076ac62",
|
||||
"reference": "aa7046645e094b0134a4125cce6694f4b076ac62",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1065,7 +1065,7 @@
|
||||
"framework",
|
||||
"laravel"
|
||||
],
|
||||
"time": "2015-04-21 01:44:32"
|
||||
"time": "2015-05-08 12:57:10"
|
||||
},
|
||||
{
|
||||
"name": "league/commonmark",
|
||||
|
@ -1,14 +1,16 @@
|
||||
if (typeof(google) != 'undefined') {
|
||||
google.setOnLoadCallback(drawChart);
|
||||
function drawChart() {
|
||||
googleColumnChart('chart/reports/income-expenses/' + year, 'income-expenses-chart');
|
||||
googleColumnChart('chart/reports/income-expenses-sum/' + year, 'income-expenses-sum-chart')
|
||||
|
||||
googleStackedColumnChart('chart/budgets/spending/' + year, 'budgets');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function drawChart() {
|
||||
googleColumnChart('chart/reports/income-expenses/' + year, 'income-expenses-chart');
|
||||
googleColumnChart('chart/reports/income-expenses-sum/' + year, 'income-expenses-sum-chart')
|
||||
|
||||
googleStackedColumnChart('chart/budgets/spending/' + year, 'budgets');
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$('.openModal').on('click', openModal);
|
||||
includeSharedToggle();
|
||||
|
@ -25,3 +25,10 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block styles %}
|
||||
<link rel="stylesheet" href="css/bootstrap-sortable.css" type="text/css" media="all" />
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script type="text/javascript" src="js/bootstrap-sortable.js"></script>
|
||||
{% endblock %}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<table class="table table-bordered table-striped">
|
||||
<table class="table table-bordered table-striped sortable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th data-defaultsort="disabled"> </th>
|
||||
<th>Name</th>
|
||||
<th>Matches on</th>
|
||||
<th colspan="2">Matching amount</th>
|
||||
@ -9,8 +10,9 @@
|
||||
<th>Is active</th>
|
||||
<th>Will be automatched</th>
|
||||
<th>Repeats every</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
<th data-defaultsort="disabled"> </th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
{% for entry in bills %}
|
||||
<tr>
|
||||
<td>
|
||||
@ -22,46 +24,52 @@
|
||||
<td>
|
||||
<a href="{{route('bills.show',entry.id)}}" title="{{ entry.name }}">{{ entry.name }}</a>
|
||||
</td>
|
||||
<td>
|
||||
<td data-value="{{ entry.match }}">
|
||||
{% for match in entry.match|split(',') %}
|
||||
<span class="label label-info">{{ match }}</span>
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td>
|
||||
<td data-value="{{ entry.amount_min }}">
|
||||
{{ entry.amount_min|formatAmount }}
|
||||
</td>
|
||||
<td>
|
||||
<td data-value="{{ entry.amount_max }}">
|
||||
{{ entry.amount_max|formatAmount }}
|
||||
</td>
|
||||
<td>
|
||||
{% if entry.lastFoundMatch %}
|
||||
<td data-value="{{ entry.lastFoundMatch.format('U') }}">
|
||||
{{entry.lastFoundMatch.format('j F Y')}}
|
||||
</td>
|
||||
{% else %}
|
||||
<td data-value="0">
|
||||
<em>Unknown</em>
|
||||
</td>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
|
||||
{% if entry.nextExpectedMatch%}
|
||||
<td data-value="{{entry.nextExpectedMatch.format('U')}}">
|
||||
{{entry.nextExpectedMatch.format('j F Y')}}
|
||||
</td>
|
||||
{% else %}
|
||||
<td data-value="0">
|
||||
<em>Unknown</em>
|
||||
</td>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<td data-value="{{ entry.active }}">
|
||||
{% if entry.active %}
|
||||
<i class="fa fa-fw fa-check"></i>
|
||||
{% else %}
|
||||
<i class="fa fa-fw fa-ban"></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<td data-value="{{ entry.automatch }}">
|
||||
{% if entry.automatch %}
|
||||
<i class="fa fa-fw fa-check"></i>
|
||||
{% else %}
|
||||
<i class="fa fa-fw fa-ban"></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<td data-value="{{ entry.repeat_freq }}{{ entry.skip }}">
|
||||
{{ entry.repeat_freq }}
|
||||
{% if entry.skip > 0 %}
|
||||
skips over {{entry.skip}}
|
||||
@ -75,4 +83,5 @@
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -641,43 +641,6 @@ class AccountRepositoryTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::store
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::storeAccount
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::storeMetadata
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::storeInitialBalance
|
||||
*/
|
||||
public function testStoreWithNegativeInitialBalance()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||
$this->be($user);
|
||||
|
||||
$data = [
|
||||
'accountType' => 'expense',
|
||||
'user' => $user->id,
|
||||
'name' => 'Test account #' . rand(1, 100),
|
||||
'active' => true,
|
||||
'accountRole' => 'testAccount',
|
||||
'openingBalance' => -100,
|
||||
'virtualBalance' => 0,
|
||||
'openingBalanceCurrency' => $currency->id,
|
||||
'openingBalanceDate' => '2015-01-01',
|
||||
];
|
||||
|
||||
|
||||
$account = $this->object->store($data);
|
||||
|
||||
$this->assertEquals($data['name'], $account->name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::store
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::storeAccount
|
||||
@ -751,6 +714,44 @@ class AccountRepositoryTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::store
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::storeAccount
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::storeMetadata
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::storeInitialBalance
|
||||
*/
|
||||
public function testStoreWithNegativeInitialBalance()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||
$this->be($user);
|
||||
|
||||
$data = [
|
||||
'accountType' => 'expense',
|
||||
'user' => $user->id,
|
||||
'name' => 'Test account #' . rand(1, 100),
|
||||
'active' => true,
|
||||
'accountRole' => 'testAccount',
|
||||
'openingBalance' => -100,
|
||||
'virtualBalance' => 0,
|
||||
'openingBalanceCurrency' => $currency->id,
|
||||
'openingBalanceDate' => '2015-01-01',
|
||||
];
|
||||
|
||||
|
||||
$account = $this->object->store($data);
|
||||
|
||||
$this->assertEquals($data['name'], $account->name);
|
||||
$this->assertEquals(-100, $account->transactions()->first()->amount);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::sumOfEverything
|
||||
*/
|
||||
@ -764,11 +765,152 @@ class AccountRepositoryTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::update
|
||||
* @todo Implement testUpdate().
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::updateMetadata
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::updateInitialBalance
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete('This test has not been implemented yet.');
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||
$this->be($user);
|
||||
|
||||
$data = [
|
||||
'accountType' => 'expense',
|
||||
'user' => $user->id,
|
||||
'name' => 'Test account #' . rand(1, 100),
|
||||
'active' => true,
|
||||
'accountRole' => 'testAccount',
|
||||
'openingBalance' => 100,
|
||||
'virtualBalance' => 0,
|
||||
'openingBalanceCurrency' => $currency->id,
|
||||
'openingBalanceDate' => '2015-01-01',
|
||||
];
|
||||
|
||||
|
||||
$account = $this->object->store($data);
|
||||
|
||||
// now update that same account:
|
||||
$data = [
|
||||
'name' => 'New account name' . rand(0, 100),
|
||||
'active' => 1,
|
||||
'virtualBalance' => 0,
|
||||
'openingBalance' => 50,
|
||||
'openingBalanceCurrency' => $currency->id,
|
||||
'openingBalanceDate' => '2015-02-02',
|
||||
];
|
||||
|
||||
$newAccount = $this->object->update($account, $data);
|
||||
|
||||
$this->assertEquals($data['name'], $newAccount->name);
|
||||
$this->assertEquals(50, $account->transactions()->first()->amount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::update
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::updateMetadata
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::updateInitialBalance
|
||||
*/
|
||||
public function testUpdateDeleteOpeningBalance()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||
$this->be($user);
|
||||
|
||||
$data = [
|
||||
'accountType' => 'expense',
|
||||
'user' => $user->id,
|
||||
'name' => 'Test account #' . rand(1, 100),
|
||||
'active' => true,
|
||||
'accountRole' => 'testAccount',
|
||||
'openingBalance' => 100,
|
||||
'virtualBalance' => 0,
|
||||
'openingBalanceCurrency' => $currency->id,
|
||||
'openingBalanceDate' => '2015-01-01',
|
||||
];
|
||||
|
||||
|
||||
$account = $this->object->store($data);
|
||||
|
||||
// now update that same account:
|
||||
$data = [
|
||||
'name' => 'New account name' . rand(0, 100),
|
||||
'active' => 1,
|
||||
'user' => $user->id,
|
||||
'accountRole' => 'testAccount',
|
||||
'virtualBalance' => 0,
|
||||
'openingBalance' => 0,
|
||||
];
|
||||
|
||||
$newAccount = $this->object->update($account, $data);
|
||||
|
||||
$this->assertEquals($data['name'], $newAccount->name);
|
||||
$this->assertEquals(0, $newAccount->transactions()->whereNull('deleted_at')->count());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::update
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::updateMetadata
|
||||
* @covers FireflyIII\Repositories\Account\AccountRepository::updateInitialBalance
|
||||
*/
|
||||
public function testUpdateNewOpeningBalance()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||
$this->be($user);
|
||||
|
||||
$data = [
|
||||
'accountType' => 'expense',
|
||||
'user' => $user->id,
|
||||
'name' => 'Test account #' . rand(1, 100),
|
||||
'active' => true,
|
||||
'accountRole' => 'testAccount',
|
||||
'openingBalance' => 0,
|
||||
'virtualBalance' => 0,
|
||||
];
|
||||
|
||||
|
||||
$account = $this->object->store($data);
|
||||
|
||||
// now update that same account:
|
||||
$data = [
|
||||
'name' => 'New account name' . rand(0, 100),
|
||||
'active' => 1,
|
||||
'user' => $user->id,
|
||||
'virtualBalance' => 0,
|
||||
'accountRole' => 'testAccount',
|
||||
'ccMonthlyPaymentDate' => '2015-01-01',
|
||||
'openingBalance' => 51,
|
||||
'openingBalanceCurrency' => $currency->id,
|
||||
'openingBalanceDate' => '2015-02-02',
|
||||
];
|
||||
|
||||
$newAccount = $this->object->update($account, $data);
|
||||
|
||||
$this->assertEquals($data['name'], $newAccount->name);
|
||||
$this->assertEquals(51, $account->transactions()->first()->amount);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
464
tests/repositories/BillRepositoryTest.php
Normal file
464
tests/repositories/BillRepositoryTest.php
Normal file
@ -0,0 +1,464 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Bill\BillRepository;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator on 2015-05-08 at 10:43:42.
|
||||
*/
|
||||
class BillRepositoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var BillRepository
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->object = new BillRepository;
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::createFakeBill
|
||||
*/
|
||||
public function testCreateFakeBill()
|
||||
{
|
||||
$description = 'Fake bill ' . rand(10, 100);
|
||||
$date = new Carbon('2013-01-01');
|
||||
$amount = 1200;
|
||||
$bill = $this->object->createFakeBill($description, $date, $amount);
|
||||
|
||||
$this->assertEquals($amount, $bill->amount_max);
|
||||
$this->assertEquals($amount, $bill->amount_min);
|
||||
$this->assertNull($bill->id);
|
||||
$this->assertEquals($description, $bill->name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::destroy
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$id = $bill->id;
|
||||
$this->object->destroy($bill);
|
||||
|
||||
// cannot find bill:
|
||||
$this->assertCount(0, Bill::whereId($id)->whereNotNull('deleted_at')->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::getActiveBills
|
||||
*/
|
||||
public function testGetActiveBills()
|
||||
{
|
||||
$bill1 = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$bill2 = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
|
||||
// update bills
|
||||
$bill1->active = 1;
|
||||
$bill2->active = 0;
|
||||
$bill2->user_id = $bill1->user_id;
|
||||
$bill1->save();
|
||||
$bill2->save();
|
||||
$this->be($bill1->user);
|
||||
|
||||
$set = $this->object->getActiveBills();
|
||||
|
||||
$this->assertCount(1, $set);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::getBills
|
||||
*/
|
||||
public function testGetBills()
|
||||
{
|
||||
$bill1 = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$bill2 = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
|
||||
// update bills
|
||||
$bill1->active = 1;
|
||||
$bill2->active = 0;
|
||||
$bill2->user_id = $bill1->user_id;
|
||||
$bill1->save();
|
||||
$bill2->save();
|
||||
$this->be($bill1->user);
|
||||
|
||||
$set = $this->object->getBills();
|
||||
|
||||
$this->assertCount(2, $set);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::getJournals
|
||||
*/
|
||||
public function testGetJournals()
|
||||
{
|
||||
$bill1 = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
|
||||
// update bills
|
||||
$bill1->active = 1;
|
||||
$bill1->save();
|
||||
$this->be($bill1->user);
|
||||
|
||||
$set = $this->object->getJournals($bill1);
|
||||
|
||||
$this->assertCount(0, $set);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::getJournalsInRange
|
||||
* @todo Implement testGetJournalsInRange().
|
||||
*/
|
||||
public function testGetJournalsInRange()
|
||||
{
|
||||
$bill1 = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
|
||||
// update bills
|
||||
$bill1->active = 1;
|
||||
$bill1->save();
|
||||
$this->be($bill1->user);
|
||||
|
||||
$set = $this->object->getJournalsInRange($bill1, new Carbon, new Carbon);
|
||||
|
||||
$this->assertCount(0, $set);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::getPossiblyRelatedJournals
|
||||
* @todo Implement testGetPossiblyRelatedJournals().
|
||||
*/
|
||||
public function testGetPossiblyRelatedJournals()
|
||||
{
|
||||
$bill1 = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$bill1->amount_min = 100;
|
||||
$bill1->amount_max = 1000;
|
||||
$account->user_id = $bill1->user_id;
|
||||
$bill1->save();
|
||||
$account->save();
|
||||
|
||||
// create some transactions to match our bill:
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal->user_id = $bill1->user_id;
|
||||
$journal->save();
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => rand(101, 999),
|
||||
]
|
||||
);
|
||||
}
|
||||
$this->be($bill1->user);
|
||||
|
||||
$set = $this->object->getPossiblyRelatedJournals($bill1);
|
||||
$this->assertCount(8, $set);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::getRanges
|
||||
*/
|
||||
public function testGetRanges()
|
||||
{
|
||||
$bill1 = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$bill1->date = new Carbon('2012-01-01');
|
||||
$bill1->repeat_freq = 'monthly';
|
||||
$bill1->save();
|
||||
|
||||
$set = $this->object->getRanges($bill1, new Carbon('2012-01-01'), new Carbon('2012-12-31'));
|
||||
|
||||
$this->assertCount(12, $set);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::lastFoundMatch
|
||||
*/
|
||||
public function testLastFoundMatch()
|
||||
{
|
||||
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal->bill_id = $bill->id;
|
||||
$journal->user_id = $bill->user_id;
|
||||
$journal->save();
|
||||
|
||||
$this->be($bill->user);
|
||||
|
||||
$date = $this->object->lastFoundMatch($bill);
|
||||
|
||||
$this->assertEquals($journal->date->format('Y-m-d'), $date->format('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::lastFoundMatch
|
||||
*/
|
||||
public function testLastFoundMatchNull()
|
||||
{
|
||||
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
|
||||
$this->be($bill->user);
|
||||
|
||||
$date = $this->object->lastFoundMatch($bill);
|
||||
|
||||
$this->assertNull($date);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::nextExpectedMatch
|
||||
*/
|
||||
public function testNextExpectedMatch()
|
||||
{
|
||||
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$bill->date = new Carbon('2012-01-07');
|
||||
$bill->repeat_freq = 'monthly';
|
||||
$bill->save();
|
||||
$this->be($bill->user);
|
||||
|
||||
// journal:
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal->date = Carbon::now()->format('Y-m-d');
|
||||
$journal->user_id = $bill->user_id;
|
||||
$journal->bill_id = $bill->id;
|
||||
$journal->save();
|
||||
|
||||
$next = $this->object->nextExpectedMatch($bill);
|
||||
$today = Carbon::now()->endOfMonth()->addDay();
|
||||
$this->assertEquals($today->format('Y-m-d'), $next->format('Y-m-d'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::nextExpectedMatch
|
||||
*/
|
||||
public function testNextExpectedMatchInactive()
|
||||
{
|
||||
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$bill->active = 0;
|
||||
$bill->save();
|
||||
$this->be($bill->user);
|
||||
|
||||
$this->assertNull($this->object->nextExpectedMatch($bill));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::nextExpectedMatch
|
||||
*/
|
||||
public function testNextExpectedMatchNoJournals()
|
||||
{
|
||||
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$bill->date = new Carbon('2012-01-07');
|
||||
$bill->repeat_freq = 'monthly';
|
||||
$bill->save();
|
||||
|
||||
$this->be($bill->user);
|
||||
|
||||
$next = $this->object->nextExpectedMatch($bill);
|
||||
$today = Carbon::now()->startOfMonth();
|
||||
$this->assertEquals($today->format('Y-m-d'), $next->format('Y-m-d'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* One
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::scan
|
||||
*/
|
||||
public function testScanMatch()
|
||||
{
|
||||
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$bill->date = new Carbon('2012-01-07');
|
||||
$bill->repeat_freq = 'monthly';
|
||||
$bill->match = 'jemoeder';
|
||||
$bill->amount_min = 90;
|
||||
$bill->amount_max = 110;
|
||||
$bill->save();
|
||||
$this->be($bill->user);
|
||||
|
||||
// journal:
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal->date = Carbon::now()->format('Y-m-d');
|
||||
$journal->description = 'jemoeder';
|
||||
$journal->user_id = $bill->user_id;
|
||||
$journal->save();
|
||||
|
||||
// two transactions:
|
||||
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100,
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100,
|
||||
]
|
||||
);
|
||||
|
||||
$this->object->scan($bill, $journal);
|
||||
$newJournal = TransactionJournal::find($journal->id);
|
||||
|
||||
$this->assertEquals($bill->id, $newJournal->bill_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::scan
|
||||
*/
|
||||
public function testScanNoMatch()
|
||||
{
|
||||
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$bill->date = new Carbon('2012-01-07');
|
||||
$bill->repeat_freq = 'monthly';
|
||||
$bill->save();
|
||||
$this->be($bill->user);
|
||||
|
||||
// journal:
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal->date = Carbon::now()->format('Y-m-d');
|
||||
$journal->user_id = $bill->user_id;
|
||||
$journal->save();
|
||||
|
||||
// two transactions:
|
||||
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100,
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100,
|
||||
]
|
||||
);
|
||||
|
||||
$this->object->scan($bill, $journal);
|
||||
$newJournal = TransactionJournal::find($journal->id);
|
||||
|
||||
$this->assertNull($newJournal->bill_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::scan
|
||||
*/
|
||||
public function testScanNoMatchButAttached()
|
||||
{
|
||||
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$bill->date = new Carbon('2012-01-07');
|
||||
$bill->match = 'blablabla';
|
||||
$bill->repeat_freq = 'monthly';
|
||||
$bill->save();
|
||||
$this->be($bill->user);
|
||||
|
||||
// journal:
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal->date = Carbon::now()->format('Y-m-d');
|
||||
$journal->user_id = $bill->user_id;
|
||||
$journal->bill_id = $bill->id;
|
||||
$journal->save();
|
||||
|
||||
// two transactions:
|
||||
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100,
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100,
|
||||
]
|
||||
);
|
||||
|
||||
$this->object->scan($bill, $journal);
|
||||
$newJournal = TransactionJournal::find($journal->id);
|
||||
|
||||
$this->assertNull($newJournal->bill_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::store
|
||||
*/
|
||||
public function testStore()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$data = [
|
||||
'name' => 'Something',
|
||||
'match' => 'Something',
|
||||
'amount_min' => 100,
|
||||
'user' => $user->id,
|
||||
'amount_max' => 110,
|
||||
'date' => new Carbon,
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
'automatch' => 1,
|
||||
'active' => 1,
|
||||
|
||||
];
|
||||
$bill = $this->object->store($data);
|
||||
|
||||
$this->assertEquals($data['name'], $bill->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Bill\BillRepository::update
|
||||
* @todo Implement testUpdate().
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||
$data = [
|
||||
'name' => 'new Name',
|
||||
'match' => $bill->match,
|
||||
'amount_min' => 100,
|
||||
'amount_max' => 110,
|
||||
'date' => new Carbon,
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
'automatch' => 1,
|
||||
'active' => 1,
|
||||
|
||||
];
|
||||
$newBill = $this->object->update($bill, $data);
|
||||
|
||||
$this->assertEquals($data['name'], $newBill->name);
|
||||
$this->assertEquals($bill->match, $newBill->match);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user