mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-25 14:58:40 +00:00
Fixed the tests.
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
use Auth;
|
use Auth;
|
||||||
use FireflyIII\Http\Requests;
|
use FireflyIII\Http\Requests;
|
||||||
use FireflyIII\Http\Requests\BillFormRequest;
|
use FireflyIII\Http\Requests\BillFormRequest;
|
||||||
|
use FireflyIII\Models\Account;
|
||||||
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
@@ -21,12 +23,59 @@ use View;
|
|||||||
class BillController extends Controller
|
class BillController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
View::share('title', 'Bills');
|
View::share('title', 'Bills');
|
||||||
View::share('mainTitleIcon', 'fa-calendar-o');
|
View::share('mainTitleIcon', 'fa-calendar-o');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Bill $bill
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function add(Bill $bill)
|
||||||
|
{
|
||||||
|
$matches = explode(',', $bill->match);
|
||||||
|
$description = [];
|
||||||
|
$expense = null;
|
||||||
|
|
||||||
|
// get users expense accounts:
|
||||||
|
$type = AccountType::where('type', 'Expense account')->first();
|
||||||
|
$accounts = Auth::user()->accounts()->where('account_type_id', $type->id)->get();
|
||||||
|
|
||||||
|
foreach ($matches as $match) {
|
||||||
|
$match = strtolower($match);
|
||||||
|
// find expense account for each word if not found already:
|
||||||
|
if (is_null($expense)) {
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
$name = strtolower($account->name);
|
||||||
|
if (!(strpos($name, $match) === false)) {
|
||||||
|
$expense = $account;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if (is_null($expense)) {
|
||||||
|
$description[] = $match;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$parameters = [
|
||||||
|
'description' => ucfirst(join(' ', $description)),
|
||||||
|
'expense_account' => is_null($expense) ? '' : $expense->name,
|
||||||
|
'amount' => round(($bill->amount_min + $bill->amount_max), 2),
|
||||||
|
];
|
||||||
|
Session::put('preFilled', $parameters);
|
||||||
|
|
||||||
|
return Redirect::to(route('transactions.create', 'withdrawal'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
|
@@ -167,6 +167,7 @@ Route::group(
|
|||||||
Route::get('/bills/rescan/{bill}', ['uses' => 'BillController@rescan', 'as' => 'bills.rescan']); # rescan for matching.
|
Route::get('/bills/rescan/{bill}', ['uses' => 'BillController@rescan', 'as' => 'bills.rescan']); # rescan for matching.
|
||||||
Route::get('/bills/create', ['uses' => 'BillController@create', 'as' => 'bills.create']);
|
Route::get('/bills/create', ['uses' => 'BillController@create', 'as' => 'bills.create']);
|
||||||
Route::get('/bills/edit/{bill}', ['uses' => 'BillController@edit', 'as' => 'bills.edit']);
|
Route::get('/bills/edit/{bill}', ['uses' => 'BillController@edit', 'as' => 'bills.edit']);
|
||||||
|
Route::get('/bills/add/{bill}', ['uses' => 'BillController@add', 'as' => 'bills.add']);
|
||||||
Route::get('/bills/delete/{bill}', ['uses' => 'BillController@delete', 'as' => 'bills.delete']);
|
Route::get('/bills/delete/{bill}', ['uses' => 'BillController@delete', 'as' => 'bills.delete']);
|
||||||
Route::get('/bills/show/{bill}', ['uses' => 'BillController@show', 'as' => 'bills.show']);
|
Route::get('/bills/show/{bill}', ['uses' => 'BillController@show', 'as' => 'bills.show']);
|
||||||
|
|
||||||
|
@@ -514,6 +514,27 @@ class TestDataSeeder extends Seeder
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
*
|
||||||
|
* @return PiggyBank|null
|
||||||
|
*/
|
||||||
|
protected function findPiggyBank($name)
|
||||||
|
{
|
||||||
|
// account
|
||||||
|
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||||
|
/** @var Budget $budget */
|
||||||
|
foreach (PiggyBank::get() as $piggyBank) {
|
||||||
|
$account = $piggyBank->account()->first();
|
||||||
|
if ($piggyBank->name == $name && $user->id == $account->user_id) {
|
||||||
|
return $piggyBank;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
*
|
*
|
||||||
@@ -638,13 +659,13 @@ class TestDataSeeder extends Seeder
|
|||||||
// piggy bank event
|
// piggy bank event
|
||||||
// add money to this piggy bank
|
// add money to this piggy bank
|
||||||
// create a piggy bank event to match:
|
// create a piggy bank event to match:
|
||||||
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
|
$checking = $this->findAccount('Checking account');
|
||||||
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
|
$savings = $this->findAccount('Savings account');
|
||||||
$transfer = TransactionType::whereType('Transfer')->first();
|
$transfer = TransactionType::whereType('Transfer')->first();
|
||||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||||
$groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
|
$groceries = $this->findBudget('Groceries');
|
||||||
$house = Category::whereName('House')->orderBy('id', 'DESC')->first();
|
$house = $this->findCategory('House');
|
||||||
$piggyBank = PiggyBank::whereName('New camera')->orderBy('id', 'DESC')->first();
|
$piggyBank = $this->findPiggyBank('New camera');
|
||||||
$intoPiggy = $this->createJournal(
|
$intoPiggy = $this->createJournal(
|
||||||
['from' => $checking, 'to' => $savings, 'amount' => 100, 'transactionType' => $transfer, 'description' => 'Money for piggy',
|
['from' => $checking, 'to' => $savings, 'amount' => 100, 'transactionType' => $transfer, 'description' => 'Money for piggy',
|
||||||
'date' => $this->yaeom, 'transactionCurrency' => $euro, 'category' => $house, 'budget' => $groceries]
|
'date' => $this->yaeom, 'transactionCurrency' => $euro, 'category' => $house, 'budget' => $groceries]
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
<th>Is active</th>
|
<th>Is active</th>
|
||||||
<th>Will be automatched</th>
|
<th>Will be automatched</th>
|
||||||
<th>Repeats every</th>
|
<th>Repeats every</th>
|
||||||
|
<th> </th>
|
||||||
</tr>
|
</tr>
|
||||||
@foreach($bills as $entry)
|
@foreach($bills as $entry)
|
||||||
<tr>
|
<tr>
|
||||||
@@ -66,6 +67,11 @@
|
|||||||
skips over {{$entry->skip}}
|
skips over {{$entry->skip}}
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
@if($entry->active)
|
||||||
|
<a href="{{route('bills.add',$entry->id)}}" class="btn btn-success btn-xs"><i class="fa fa-fw fa-plus-circle"></i></a>
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@endforeach
|
@endforeach
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generated by PHPUnit_SkeletonGenerator on 2015-03-08 at 20:05:14.
|
* Generated by PHPUnit_SkeletonGenerator on 2015-03-08 at 20:05:14.
|
||||||
@@ -35,8 +36,11 @@ class AccountControllerTest extends TestCase
|
|||||||
$pref = new Preference;
|
$pref = new Preference;
|
||||||
$pref->data = '1M';
|
$pref->data = '1M';
|
||||||
|
|
||||||
|
// CURRENCY:
|
||||||
|
$currency = new TransactionCurrency;
|
||||||
|
|
||||||
Preferences::shouldReceive('get', 'viewRange')->andReturn($pref);
|
Preferences::shouldReceive('get', 'viewRange')->andReturn($pref);
|
||||||
Amount::shouldReceive('getDefaultCurrency')->andReturn(null);
|
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
|
||||||
|
|
||||||
$response = $this->call('GET', '/accounts/create/asset');
|
$response = $this->call('GET', '/accounts/create/asset');
|
||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
|
Reference in New Issue
Block a user