Code rearrange and optimise.

This commit is contained in:
James Cole
2015-03-29 21:27:51 +02:00
parent 210f84b6ea
commit bea321939e
34 changed files with 155 additions and 155 deletions

View File

@@ -1,7 +1,5 @@
<?php namespace FireflyIII\Events; <?php namespace FireflyIII\Events;
use FireflyIII\Events\Event;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
@@ -10,24 +8,25 @@ use Illuminate\Queue\SerializesModels;
* *
* @package FireflyIII\Events * @package FireflyIII\Events
*/ */
class JournalCreated extends Event { class JournalCreated extends Event
{
use SerializesModels; use SerializesModels;
public $journal; public $journal;
public $piggyBankId; public $piggyBankId;
/** /**
* Create a new event instance. * Create a new event instance.
* *
* @return void * @return void
*/ */
public function __construct(TransactionJournal $journal, $piggyBankId) public function __construct(TransactionJournal $journal, $piggyBankId)
{ {
// //
$this->journal = $journal; $this->journal = $journal;
$this->piggyBankId = $piggyBankId; $this->piggyBankId = $piggyBankId;
} }
} }

View File

@@ -1,25 +1,24 @@
<?php namespace FireflyIII\Events; <?php namespace FireflyIII\Events;
use FireflyIII\Events\Event;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
class JournalSaved extends Event { class JournalSaved extends Event
{
use SerializesModels; use SerializesModels;
public $journal; public $journal;
/** /**
* Create a new event instance. * Create a new event instance.
* *
* @return void * @return void
*/ */
public function __construct(TransactionJournal $journal) public function __construct(TransactionJournal $journal)
{ {
// //
$this->journal = $journal; $this->journal = $journal;
} }
} }

View File

@@ -38,7 +38,7 @@ class ConnectJournalToPiggyBank
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
$journal = $event->journal; $journal = $event->journal;
$piggyBankId = $event->piggyBankId; $piggyBankId = $event->piggyBankId;
if(intval($piggyBankId) < 1) { if (intval($piggyBankId) < 1) {
return; return;
} }
@@ -66,7 +66,8 @@ class ConnectJournalToPiggyBank
// update piggy bank rep for date of transaction journal. // update piggy bank rep for date of transaction journal.
$repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first(); $repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first();
if (is_null($repetition)) { if (is_null($repetition)) {
Log::debug('Found no repetition for piggy bank for date '.$journal->date->format('Y M d')); Log::debug('Found no repetition for piggy bank for date ' . $journal->date->format('Y M d'));
return; return;
} }

View File

@@ -1,8 +1,8 @@
<?php namespace FireflyIII\Handlers\Events; <?php namespace FireflyIII\Handlers\Events;
use App;
use FireflyIII\Events\JournalSaved; use FireflyIII\Events\JournalSaved;
use Log; use Log;
use App;
/** /**
* Class RescanJournal * Class RescanJournal

View File

@@ -35,8 +35,8 @@ class UpdateJournalConnection
// get the event connected to this journal: // get the event connected to this journal:
/** @var PiggyBankEvent $event */ /** @var PiggyBankEvent $event */
$event = PiggyBankEvent::where('transaction_journal_id', $journal->id)->first(); $event = PiggyBankEvent::where('transaction_journal_id', $journal->id)->first();
if(is_null($event)) { if (is_null($event)) {
return; return;
} }
$piggyBank = $event->piggyBank()->first(); $piggyBank = $event->piggyBank()->first();

View File

@@ -2,16 +2,17 @@
namespace FireflyIII\Helpers\Reminders; namespace FireflyIII\Helpers\Reminders;
use FireflyIII\Models\Reminder;
use FireflyIII\Models\PiggyBank;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Reminder;
/** /**
* Interface ReminderHelperInterface * Interface ReminderHelperInterface
* *
* @package FireflyIII\Helpers\Reminders * @package FireflyIII\Helpers\Reminders
*/ */
interface ReminderHelperInterface { interface ReminderHelperInterface
{
/** /**
* Takes a reminder, finds the piggy bank and tells you what to do now. * Takes a reminder, finds the piggy bank and tells you what to do now.
* Aka how much money to put in. * Aka how much money to put in.

View File

@@ -169,7 +169,8 @@ class AccountController extends Controller
$what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type);
$journals = $repository->getJournals($account, $page); $journals = $repository->getJournals($account, $page);
$subTitle = 'Details for ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"'; $subTitle = 'Details for ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"';
$journals->setPath('accounts/show/'.$account->id); $journals->setPath('accounts/show/' . $account->id);
return view('accounts.show', compact('account', 'what', 'subTitleIcon', 'journals', 'subTitle')); return view('accounts.show', compact('account', 'what', 'subTitleIcon', 'journals', 'subTitle'));
} }

View File

@@ -64,7 +64,7 @@ class AuthController extends Controller
); );
} }
$data =$request->all(); $data = $request->all();
$data['password'] = bcrypt($data['password']); $data['password'] = bcrypt($data['password']);
$this->auth->login($this->registrar->create($data)); $this->auth->login($this->registrar->create($data));

View File

@@ -98,8 +98,8 @@ class BudgetController extends Controller
*/ */
public function index(BudgetRepositoryInterface $repository) public function index(BudgetRepositoryInterface $repository)
{ {
$budgets = Auth::user()->budgets()->where('active',1)->get(); $budgets = Auth::user()->budgets()->where('active', 1)->get();
$inactive = Auth::user()->budgets()->where('active',0)->get(); $inactive = Auth::user()->budgets()->where('active', 0)->get();
// loop the budgets: // loop the budgets:
$budgets->each( $budgets->each(
@@ -118,7 +118,7 @@ class BudgetController extends Controller
$budgetMax = Preferences::get('budgetMaximum', 1000); $budgetMax = Preferences::get('budgetMaximum', 1000);
$budgetMaximum = $budgetMax->data; $budgetMaximum = $budgetMax->data;
return view('budgets.index', compact('budgetMaximum','inactive', 'budgets', 'spent', 'spentPCT', 'overspent', 'amount')); return view('budgets.index', compact('budgetMaximum', 'inactive', 'budgets', 'spent', 'spentPCT', 'overspent', 'amount'));
} }
/** /**
@@ -134,9 +134,9 @@ class BudgetController extends Controller
->whereNull('budget_transaction_journal.id') ->whereNull('budget_transaction_journal.id')
->before($end) ->before($end)
->after($start) ->after($start)
->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order','ASC') ->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id','DESC') ->orderBy('transaction_journals.id', 'DESC')
->get(['transaction_journals.*']); ->get(['transaction_journals.*']);
$subTitle = 'Transactions without a budget in ' . $start->format('F Y'); $subTitle = 'Transactions without a budget in ' . $start->format('F Y');
@@ -210,7 +210,7 @@ class BudgetController extends Controller
public function update(Budget $budget, BudgetFormRequest $request, BudgetRepositoryInterface $repository) public function update(Budget $budget, BudgetFormRequest $request, BudgetRepositoryInterface $repository)
{ {
$budgetData = [ $budgetData = [
'name' => $request->input('name'), 'name' => $request->input('name'),
'active' => intval($request->input('active')) == 1 'active' => intval($request->input('active')) == 1
]; ];

View File

@@ -89,10 +89,10 @@ class CategoryController extends Controller
$categories->each( $categories->each(
function (Category $category) { function (Category $category) {
$latest = $category->transactionjournals() $latest = $category->transactionjournals()
->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order','ASC') ->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id','DESC') ->orderBy('transaction_journals.id', 'DESC')
->first(); ->first();
if ($latest) { if ($latest) {
$category->lastActivity = $latest->date; $category->lastActivity = $latest->date;
} }
@@ -115,9 +115,9 @@ class CategoryController extends Controller
->whereNull('category_transaction_journal.id') ->whereNull('category_transaction_journal.id')
->before($end) ->before($end)
->after($start) ->after($start)
->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order','ASC') ->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id','DESC') ->orderBy('transaction_journals.id', 'DESC')
->get(['transaction_journals.*']); ->get(['transaction_journals.*']);
$subTitle = 'Transactions without a category between ' . $start->format('jS F Y') . ' and ' . $end->format('jS F Y'); $subTitle = 'Transactions without a category between ' . $start->format('jS F Y') . ' and ' . $end->format('jS F Y');
@@ -136,14 +136,12 @@ class CategoryController extends Controller
$page = intval(Input::get('page')); $page = intval(Input::get('page'));
$offset = $page > 0 ? $page * 50 : 0; $offset = $page > 0 ? $page * 50 : 0;
$set = $category->transactionJournals()->withRelevantData()->take(50)->offset($offset) $set = $category->transactionJournals()->withRelevantData()->take(50)->offset($offset)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.order','ASC') ->orderBy('transaction_journals.id', 'DESC')
->orderBy('transaction_journals.id','DESC') ->get(
['transaction_journals.*']
->get( );
['transaction_journals.*']
);
$count = $category->transactionJournals()->count(); $count = $category->transactionJournals()->count();
$journals = new LengthAwarePaginator($set, $count, 50, $page); $journals = new LengthAwarePaginator($set, $count, 50, $page);
@@ -166,7 +164,7 @@ class CategoryController extends Controller
$category = $repository->store($categoryData); $category = $repository->store($categoryData);
Session::flash('success', 'New category "' . $category->name . '" stored!'); Session::flash('success', 'New category "' . $category->name . '" stored!');
if (intval(Input::get('create_another')) === 1) { if (intval(Input::get('create_another')) === 1) {
return Redirect::route('categories.create')->withInput(); return Redirect::route('categories.create')->withInput();
} }

View File

@@ -51,7 +51,7 @@ class GoogleChartController extends Controller
$start = Session::get('start', Carbon::now()->startOfMonth()); $start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth());
$current = clone $start; $current = clone $start;
$today = new Carbon; $today = new Carbon;
while ($end >= $current) { while ($end >= $current) {
$certain = $current < $today; $certain = $current < $today;
@@ -237,20 +237,20 @@ class GoogleChartController extends Controller
$start = Session::get('start', Carbon::now()->startOfMonth()); $start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth());
$set = TransactionJournal:: $set = TransactionJournal::
where('transaction_journals.user_id',Auth::user()->id) where('transaction_journals.user_id', Auth::user()->id)
->leftJoin( ->leftJoin(
'transactions', 'transactions',
function (JoinClause $join) { function (JoinClause $join) {
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('amount', '>', 0); $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('amount', '>', 0);
} }
) )
->leftJoin( ->leftJoin(
'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
) )
->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id') ->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id')
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->before($end) ->before($end)
->where('categories.user_id',Auth::user()->id) ->where('categories.user_id', Auth::user()->id)
->after($start) ->after($start)
->where('transaction_types.type', 'Withdrawal') ->where('transaction_types.type', 'Withdrawal')
->groupBy('categories.id') ->groupBy('categories.id')

View File

@@ -89,8 +89,8 @@ class JsonController extends Controller
// paid a bill in this range? // paid a bill in this range?
$count = $bill->transactionjournals()->before($range['end'])->after($range['start'])->count(); $count = $bill->transactionjournals()->before($range['end'])->after($range['start'])->count();
if ($count != 0) { if ($count != 0) {
$journal = $bill->transactionjournals()->with('transactions')->before($range['end'])->after($range['start'])->first(); $journal = $bill->transactionjournals()->with('transactions')->before($range['end'])->after($range['start'])->first();
$currentAmount = 0; $currentAmount = 0;
foreach ($journal->transactions as $t) { foreach ($journal->transactions as $t) {
if (floatval($t->amount) > 0) { if (floatval($t->amount) > 0) {
$currentAmount = floatval($t->amount); $currentAmount = floatval($t->amount);

View File

@@ -98,10 +98,10 @@ class PiggyBanks
// first loop fixes this date. or should fix it. // first loop fixes this date. or should fix it.
$max = new Carbon; $max = new Carbon;
echo '[#'.$piggyBank->id.', from: '.$start->format('Y-m-d.').' to '.$end->format('Y-m-d.').']'; echo '[#' . $piggyBank->id . ', from: ' . $start->format('Y-m-d.') . ' to ' . $end->format('Y-m-d.') . ']';
// create stuff. Or at least, try: // create stuff. Or at least, try:
$repetition = $piggyBank->piggyBankRepetitions()->onDates($start, $end)->first(); $repetition = $piggyBank->piggyBankRepetitions()->onDates($start, $end)->first();
if(!$repetition) { if (!$repetition) {
$repetition = new PiggyBankRepetition; $repetition = new PiggyBankRepetition;
$repetition->piggyBank()->associate($piggyBank); $repetition->piggyBank()->associate($piggyBank);
$repetition->startdate = $start; $repetition->startdate = $start;

View File

@@ -46,7 +46,7 @@ class ReplaceTestVars
$input = $request->all(); $input = $request->all();
$input['_token'] = $request->session()->token(); $input['_token'] = $request->session()->token();
// we need to update _token value to make sure we get the POST / PUT tests passed. // we need to update _token value to make sure we get the POST / PUT tests passed.
Log::debug('Input token replaced ('.$input['_token'].').'); Log::debug('Input token replaced (' . $input['_token'] . ').');
$request->replace($input); $request->replace($input);
} }

View File

@@ -33,7 +33,7 @@ class AccountFormRequest extends Request
$nameRule = 'required|between:1,100|uniqueAccountForUser'; $nameRule = 'required|between:1,100|uniqueAccountForUser';
if (Account::find(Input::get('id'))) { if (Account::find(Input::get('id'))) {
$nameRule = 'required|between:1,100|belongsToUser:accounts|uniqueForUser:'.Input::get('id'); $nameRule = 'required|between:1,100|belongsToUser:accounts|uniqueForUser:' . Input::get('id');
} }
return [ return [

View File

@@ -26,7 +26,7 @@ class ProfileFormRequest extends Request
public function rules() public function rules()
{ {
return [ return [
'current_password' => 'required', 'current_password' => 'required',
'new_password' => 'required|confirmed', 'new_password' => 'required|confirmed',
'new_password_confirmation' => 'required', 'new_password_confirmation' => 'required',
]; ];

View File

@@ -3,13 +3,13 @@ use Carbon\Carbon;
use DaveJamesMiller\Breadcrumbs\Generator; use DaveJamesMiller\Breadcrumbs\Generator;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\Bill; use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category; use FireflyIII\Models\Category;
use FireflyIII\Models\Reminder;
use FireflyIII\Models\LimitRepetition; use FireflyIII\Models\LimitRepetition;
use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Reminder;
use FireflyIII\Models\TransactionJournal;
/* /*
* Back home. * Back home.

View File

@@ -132,7 +132,7 @@ Route::get('/register', ['uses' => 'Auth\AuthController@getRegister', 'as' => 'r
Route::controllers( Route::controllers(
[ [
'auth' => 'Auth\AuthController', 'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController', 'password' => 'Auth\PasswordController',
] ]
); );
@@ -142,7 +142,7 @@ Route::controllers(
* Home Controller * Home Controller
*/ */
Route::group( Route::group(
['middleware' => ['auth', 'range', 'reminders','piggybanks']], function () { ['middleware' => ['auth', 'range', 'reminders', 'piggybanks']], function () {
Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index']); Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index']);
Route::get('/home', ['uses' => 'HomeController@index', 'as' => 'home']); Route::get('/home', ['uses' => 'HomeController@index', 'as' => 'home']);
Route::post('/daterange', ['uses' => 'HomeController@dateRange', 'as' => 'daterange']); Route::post('/daterange', ['uses' => 'HomeController@dateRange', 'as' => 'daterange']);

View File

@@ -1,10 +1,11 @@
<?php namespace FireflyIII\Models; <?php namespace FireflyIII\Models;
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 Watson\Validating\ValidatingTrait; use Watson\Validating\ValidatingTrait;
use Crypt;
/** /**
* Class Account * Class Account
* *

View File

@@ -14,12 +14,12 @@ class AccountMeta extends Model
use ValidatingTrait; use ValidatingTrait;
protected $fillable = ['account_id', 'name', 'data']; protected $fillable = ['account_id', 'name', 'data'];
protected $rules protected $rules
= [ = [
'account_id' => 'required|exists:accounts,id', 'account_id' => 'required|exists:accounts,id',
'name' => 'required|between:1,100', 'name' => 'required|between:1,100',
'data' => 'required' 'data' => 'required'
]; ];
protected $table = 'account_meta'; protected $table = 'account_meta';
/** /**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo * @return \Illuminate\Database\Eloquent\Relations\BelongsTo

View File

@@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Model;
class Bill extends Model class Bill extends Model
{ {
protected $fillable = ['name', 'match', 'amount_min','user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',]; protected $fillable = ['name', 'match', 'amount_min', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',];
/** /**
* @return array * @return array

View File

@@ -12,7 +12,7 @@ class Component extends Model
{ {
use SoftDeletes; use SoftDeletes;
protected $fillable = ['user_id', 'name','class']; protected $fillable = ['user_id', 'name', 'class'];
/** /**
* @return array * @return array

View File

@@ -1,11 +1,10 @@
<?php namespace FireflyIII\Models; <?php namespace FireflyIII\Models;
use Carbon\Carbon; use Carbon\Carbon;
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 App;
use Log; use Log;
/** /**
* Class PiggyBank * Class PiggyBank
* *
@@ -44,7 +43,7 @@ class PiggyBank extends Model
return $rep; return $rep;
} else { } else {
Log::error('Tried to work with a piggy bank with a repeats=1 value! (id is '.$this->id.')'); Log::error('Tried to work with a piggy bank with a repeats=1 value! (id is ' . $this->id . ')');
} }

View File

@@ -28,7 +28,7 @@ class EventServiceProvider extends ServiceProvider
*/ */
protected $listen protected $listen
= [ = [
'FireflyIII\Events\JournalSaved' => [ 'FireflyIII\Events\JournalSaved' => [
'FireflyIII\Handlers\Events\RescanJournal', 'FireflyIII\Handlers\Events\RescanJournal',
'FireflyIII\Handlers\Events\UpdateJournalConnection', 'FireflyIII\Handlers\Events\UpdateJournalConnection',
@@ -60,7 +60,6 @@ class EventServiceProvider extends ServiceProvider
); );
Account::deleted( Account::deleted(
function (Account $account) { function (Account $account) {

View File

@@ -106,9 +106,9 @@ class AccountRepository implements AccountRepositoryInterface
->withRelevantData() ->withRelevantData()
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id) ->where('transactions.account_id', $account->id)
->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order','ASC') ->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id','DESC'); ->orderBy('transaction_journals.id', 'DESC');
$query->before(Session::get('end', Carbon::now()->endOfMonth())); $query->before(Session::get('end', Carbon::now()->endOfMonth()));
$query->after(Session::get('start', Carbon::now()->startOfMonth())); $query->after(Session::get('start', Carbon::now()->startOfMonth()));
@@ -119,7 +119,6 @@ class AccountRepository implements AccountRepositoryInterface
return $paginator; return $paginator;
} }
/** /**

View File

@@ -2,11 +2,12 @@
namespace FireflyIII\Repositories\Account; namespace FireflyIII\Repositories\Account;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\Preference;
use Illuminate\Support\Collection;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Support\Collection;
/** /**
* Interface AccountRepositoryInterface * Interface AccountRepositoryInterface
* *

View File

@@ -11,7 +11,8 @@ use FireflyIII\Models\TransactionJournal;
* *
* @package FireflyIII\Repositories\Bill * @package FireflyIII\Repositories\Bill
*/ */
interface BillRepositoryInterface { interface BillRepositoryInterface
{
/** /**
* @param Bill $bill * @param Bill $bill
@@ -25,7 +26,7 @@ interface BillRepositoryInterface {
* and returns date ranges that fall within the given range; those ranges are the bills expected. When a bill is due on the 14th of the month and * and returns date ranges that fall within the given range; those ranges are the bills expected. When a bill is due on the 14th of the month and
* you give 1st and the 31st of that month as argument, you'll get one response, matching the range of your bill. * you give 1st and the 31st of that month as argument, you'll get one response, matching the range of your bill.
* *
* @param Bill $bill * @param Bill $bill
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* *

View File

@@ -43,9 +43,9 @@ class BudgetRepository implements BudgetRepositoryInterface
$setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset) $setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset)
->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order','ASC') ->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id','DESC'); ->orderBy('transaction_journals.id', 'DESC');
$countQuery = $budget->transactionJournals(); $countQuery = $budget->transactionJournals();
@@ -57,6 +57,7 @@ class BudgetRepository implements BudgetRepositoryInterface
$set = $setQuery->get(['transaction_journals.*']); $set = $setQuery->get(['transaction_journals.*']);
$count = $countQuery->count(); $count = $countQuery->count();
return new LengthAwarePaginator($set, $count, $take, $offset); return new LengthAwarePaginator($set, $count, $take, $offset);
} }
@@ -103,7 +104,7 @@ class BudgetRepository implements BudgetRepositoryInterface
public function update(Budget $budget, array $data) public function update(Budget $budget, array $data)
{ {
// update the account: // update the account:
$budget->name = $data['name']; $budget->name = $data['name'];
$budget->active = $data['active']; $budget->active = $data['active'];
$budget->save(); $budget->save();

View File

@@ -111,7 +111,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
public function setOrder($id, $order) public function setOrder($id, $order)
{ {
$piggyBank = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id) $piggyBank = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id)
->where('piggy_banks.id',$id)->first(['piggy_banks.*']); ->where('piggy_banks.id', $id)->first(['piggy_banks.*']);
if ($piggyBank) { if ($piggyBank) {
$piggyBank->order = $order; $piggyBank->order = $order;
$piggyBank->save(); $piggyBank->save();

View File

@@ -2,10 +2,9 @@
namespace FireflyIII\Repositories\PiggyBank; namespace FireflyIII\Repositories\PiggyBank;
use FireflyIII\Models\Reminder;
use FireflyIII\Models\PiggyBankRepetition;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Models\PiggyBankRepetition;
use FireflyIII\Models\Reminder;
/** /**
* Class PiggyBankPart * Class PiggyBankPart

View File

@@ -344,6 +344,48 @@ class Navigation
throw new FireflyException('Cannot do startOfPeriod for $repeat_freq ' . $repeatFreq); throw new FireflyException('Cannot do startOfPeriod for $repeat_freq ' . $repeatFreq);
} }
/**
* @param Carbon $theDate
* @param $repeatFreq
* @param int $subtract
*
* @return Carbon
* @throws FireflyException
*/
public function subtractPeriod(Carbon $theDate, $repeatFreq, $subtract = 1)
{
$date = clone $theDate;
$functionMap = [
'daily' => 'subDays',
'week' => 'subWeeks',
'weekly' => 'subWeeks',
'month' => 'subMonths',
'monthly' => 'subMonths',
'year' => 'subYears',
'yearly' => 'subYears',
];
$modifierMap = [
'quarter' => 3,
'quarterly' => 3,
'half-year' => 6,
];
if (isset($functionMap[$repeatFreq])) {
$function = $functionMap[$repeatFreq];
$date->$function($subtract);
return $date;
}
if (isset($modifierMap[$repeatFreq])) {
$subtract = $subtract * $modifierMap[$repeatFreq];
$date->subMonths($subtract);
return $date;
}
throw new FireflyException('Cannot do subtractPeriod for $repeat_freq ' . $repeatFreq);
}
/** /**
* @param $range * @param $range
* @param Carbon $start * @param Carbon $start
@@ -414,47 +456,5 @@ class Navigation
throw new FireflyException('updateStartDate cannot handle $range ' . $range); throw new FireflyException('updateStartDate cannot handle $range ' . $range);
} }
/**
* @param Carbon $theDate
* @param $repeatFreq
* @param int $subtract
*
* @return Carbon
* @throws FireflyException
*/
public function subtractPeriod(Carbon $theDate, $repeatFreq, $subtract = 1)
{
$date = clone $theDate;
$functionMap = [
'daily' => 'subDays',
'week' => 'subWeeks',
'weekly' => 'subWeeks',
'month' => 'subMonths',
'monthly' => 'subMonths',
'year' => 'subYears',
'yearly' => 'subYears',
];
$modifierMap = [
'quarter' => 3,
'quarterly' => 3,
'half-year' => 6,
];
if (isset($functionMap[$repeatFreq])) {
$function = $functionMap[$repeatFreq];
$date->$function($subtract);
return $date;
}
if (isset($modifierMap[$repeatFreq])) {
$subtract = $subtract * $modifierMap[$repeatFreq];
$date->subMonths($subtract);
return $date;
}
throw new FireflyException('Cannot do subtractPeriod for $repeat_freq ' . $repeatFreq);
}
} }

View File

@@ -112,8 +112,8 @@ class Search implements SearchInterface
)->get(); )->get();
// encrypted // encrypted
$all = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 1)->get(); $all = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 1)->get();
$set = $all->filter( $set = $all->filter(
function (TransactionJournal $journal) use ($words) { function (TransactionJournal $journal) use ($words) {
foreach ($words as $word) { foreach ($words as $word) {
$haystack = strtolower($journal->description); $haystack = strtolower($journal->description);

View File

@@ -9,7 +9,8 @@ use Illuminate\Support\Collection;
* *
* @package FireflyIII\Support\Search * @package FireflyIII\Support\Search
*/ */
interface SearchInterface { interface SearchInterface
{
/** /**
* @param array $words * @param array $words
* *

View File

@@ -152,7 +152,7 @@ class FireflyValidator extends Validator
*/ */
public function validateUniquePiggyBankForUser($attribute, $value, $parameters) public function validateUniquePiggyBankForUser($attribute, $value, $parameters)
{ {
$query = DB::table($parameters[0])->where('piggy_banks.'.$parameters[1], $value); $query = DB::table($parameters[0])->where('piggy_banks.' . $parameters[1], $value);
$query->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id'); $query->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id');
$query->where('accounts.user_id', Auth::user()->id); $query->where('accounts.user_id', Auth::user()->id);
if (isset($paramers[2])) { if (isset($paramers[2])) {