diff --git a/README.md b/README.md
index c44c790cac..13382ea244 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-Firefly III (v3.4.0.2)
+Firefly III (v3.4.0.3)
===========
[](https://travis-ci.org/JC5/firefly-iii)
@@ -68,13 +68,19 @@ Some stuff has been removed:
## Screenshots
-
+
-
+
-
+
-
+
+
+
+
+
+
+
## Current state
I have the basics up and running. Test coverage is currently coming, slowly.
diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php
index 55026e0620..9efbd64e74 100644
--- a/app/Helpers/Report/ReportHelper.php
+++ b/app/Helpers/Report/ReportHelper.php
@@ -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'))
diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php
index f2d65060c5..6f49c9669a 100644
--- a/app/Models/TransactionJournal.php
+++ b/app/Models/TransactionJournal.php
@@ -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;
}
diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php
index 0c85491199..fd52a224f7 100644
--- a/app/Providers/EventServiceProvider.php
+++ b/app/Providers/EventServiceProvider.php
@@ -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) {
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index c026a037d0..7c3f3e94ff 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -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;
diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php
index 41fabfceec..0c3419f7b9 100644
--- a/app/Repositories/Bill/BillRepository.php
+++ b/app/Repositories/Bill/BillRepository.php
@@ -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 */
diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php
index 82ceed96cf..42133ba6fb 100644
--- a/app/Repositories/Budget/BudgetRepository.php
+++ b/app/Repositories/Budget/BudgetRepository.php
@@ -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)
diff --git a/app/Support/Amount.php b/app/Support/Amount.php
index 54669530d2..b1146b4496 100644
--- a/app/Support/Amount.php
+++ b/app/Support/Amount.php
@@ -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;
diff --git a/composer.lock b/composer.lock
index 739325247b..2bc395932a 100644
--- a/composer.lock
+++ b/composer.lock
@@ -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",
diff --git a/public/js/reports.js b/public/js/reports.js
index c8b46cfcbb..0b6dcacad4 100644
--- a/public/js/reports.js
+++ b/public/js/reports.js
@@ -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();
diff --git a/resources/twig/bills/index.twig b/resources/twig/bills/index.twig
index 96b0ba7949..e2b6531245 100644
--- a/resources/twig/bills/index.twig
+++ b/resources/twig/bills/index.twig
@@ -25,3 +25,10 @@
{% endblock %}
+{% block styles %}
+
+{% endblock %}
+
+{% block scripts %}
+
+{% endblock %}
diff --git a/resources/twig/list/bills.twig b/resources/twig/list/bills.twig
index 2432efaf88..91338ec6ad 100644
--- a/resources/twig/list/bills.twig
+++ b/resources/twig/list/bills.twig
@@ -1,6 +1,7 @@
-
+
+
- | |
+ |
Name |
Matches on |
Matching amount |
@@ -9,8 +10,9 @@
Is active |
Will be automatched |
Repeats every |
- |
-
+ |
+
+
{% for entry in bills %}
|
@@ -22,46 +24,52 @@
|
{{ entry.name }}
|
-
+ |
{% for match in entry.match|split(',') %}
{{ match }}
{% endfor %}
|
-
+ |
{{ entry.amount_min|formatAmount }}
|
-
+ |
{{ entry.amount_max|formatAmount }}
|
-
{% if entry.lastFoundMatch %}
+ |
{{entry.lastFoundMatch.format('j F Y')}}
+ |
{% else %}
+
Unknown
+ |
{% endif %}
-
-
+
{% if entry.nextExpectedMatch%}
+ |
{{entry.nextExpectedMatch.format('j F Y')}}
+ |
{% else %}
+
Unknown
+ |
{% endif %}
-
-
+
+ |
{% if entry.active %}
{% else %}
{% endif %}
|
-
+ |
{% if entry.automatch %}
{% else %}
{% endif %}
|
-
+ |
{{ entry.repeat_freq }}
{% if entry.skip > 0 %}
skips over {{entry.skip}}
@@ -75,4 +83,5 @@
|
{% endfor %}
+
diff --git a/tests/repositories/AccountRepositoryTest.php b/tests/repositories/AccountRepositoryTest.php
index d635463355..5f57fd4a03 100644
--- a/tests/repositories/AccountRepositoryTest.php
+++ b/tests/repositories/AccountRepositoryTest.php
@@ -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);
+
+
}
}
diff --git a/tests/repositories/BillRepositoryTest.php b/tests/repositories/BillRepositoryTest.php
new file mode 100644
index 0000000000..803c509d46
--- /dev/null
+++ b/tests/repositories/BillRepositoryTest.php
@@ -0,0 +1,464 @@
+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);
+ }
+}