Some code cleanup [skip ci]

This commit is contained in:
James Cole 2015-05-27 07:27:05 +02:00
parent 58014f0592
commit 2ace7c3ca0
7 changed files with 67 additions and 40 deletions

View File

@ -1,6 +1,8 @@
<?php namespace FireflyIII\Http\Controllers\Auth;
use App;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
@ -87,22 +89,27 @@ class AuthController extends Controller
$this->auth->login($this->registrar->create($data));
// get the email address
$email = $this->auth->user()->email;
if ($this->auth->user() instanceof User) {
$email = $this->auth->user()->email;
// send email.
Mail::send(
'emails.registered', [], function(Message $message) use ($email) {
$message->to($email, $email)->subject('Welcome to Firefly III!');
// send email.
Mail::send(
'emails.registered', [], function (Message $message) use ($email) {
$message->to($email, $email)->subject('Welcome to Firefly III!');
}
);
// set flash message
Session::flash('success', 'You have registered successfully!');
Session::flash('gaEventCategory', 'user');
Session::flash('gaEventAction', 'new-registration');
return redirect($this->redirectPath());
}
);
App::abort(500, 'Not a user!');
// set flash message
Session::flash('success', 'You have registered successfully!');
Session::flash('gaEventCategory', 'user');
Session::flash('gaEventAction', 'new-registration');
return redirect($this->redirectPath());
return false;
}
}

View File

@ -118,7 +118,7 @@ class TransactionController extends Controller
*/
public function edit(AccountRepositoryInterface $repository, TransactionJournal $journal)
{
$what = strtolower($journal->transactiontype->type);
$what = strtolower($journal->transactionType->type);
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
$budgets[0] = trans('form.noBudget');
@ -153,7 +153,7 @@ class TransactionController extends Controller
$preFilled['piggy_bank_id'] = $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id;
}
$preFilled['amount'] = $journal->actualAmount;
$preFilled['amount'] = $journal->actual_amount;
$preFilled['account_id'] = $journal->assetAccount->id;
$preFilled['expense_account'] = $transactions[0]->account->name;
$preFilled['revenue_account'] = $transactions[1]->account->name;
@ -254,7 +254,7 @@ class TransactionController extends Controller
$t->after = $t->before + $t->amount;
}
);
$subTitle = trans('firefly.' . $journal->transactiontype->type) . ' "' . e($journal->description) . '"';
$subTitle = trans('firefly.' . $journal->transactionType->type) . ' "' . e($journal->description) . '"';
return view('transactions.show', compact('journal', 'subTitle'));
}

View File

@ -7,6 +7,7 @@ use Carbon\Carbon;
use Closure;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Reminder;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
use View;
@ -48,30 +49,33 @@ class Reminders
{
if ($this->auth->check() && !$request->isXmlHttpRequest()) {
// do reminders stuff.
$piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get();
/** @var \FireflyIII\Helpers\Reminders\ReminderHelperInterface $helper */
$helper = App::make('FireflyIII\Helpers\Reminders\ReminderHelperInterface');
$reminders = [];
if ($this->auth->user() instanceof User) {
$piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get();
/** @var \FireflyIII\Helpers\Reminders\ReminderHelperInterface $helper */
$helper = App::make('FireflyIII\Helpers\Reminders\ReminderHelperInterface');
/** @var PiggyBank $piggyBank */
foreach ($piggyBanks as $piggyBank) {
$helper->createReminders($piggyBank, new Carbon);
}
// delete invalid reminders
// this is a construction SQLITE cannot handle :(
if (env('DB_CONNECTION') != 'sqlite') {
Reminder::whereUserId($this->auth->user()->id)
->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id')
->whereNull('piggy_banks.id')
->delete();
}
// get and list active reminders:
$reminders = $this->auth->user()->reminders()->today()->get();
$reminders->each(
function(Reminder $reminder) use ($helper) {
$reminder->description = $helper->getReminderText($reminder);
/** @var PiggyBank $piggyBank */
foreach ($piggyBanks as $piggyBank) {
$helper->createReminders($piggyBank, new Carbon);
}
);
// delete invalid reminders
// this is a construction SQLITE cannot handle :(
if (env('DB_CONNECTION') != 'sqlite') {
Reminder::whereUserId($this->auth->user()->id)
->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id')
->whereNull('piggy_banks.id')
->delete();
}
// get and list active reminders:
$reminders = $this->auth->user()->reminders()->today()->get();
$reminders->each(
function (Reminder $reminder) use ($helper) {
$reminder->description = $helper->getReminderText($reminder);
}
);
}
View::share('reminders', $reminders);
}

View File

@ -40,6 +40,11 @@ use Watson\Validating\ValidatingTrait;
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereVirtualBalanceEncrypted($value)
* @method static \FireflyIII\Models\Account accountTypeIn($types)
* @method static \FireflyIII\Models\Account hasMetaValue($name, $value)
*
* @property boolean joinedAccountTypes
* @property mixed startBalance
* @property mixed endBalance
* @property mixed lastActivityDate
*/
class Account extends Model
{

View File

@ -44,6 +44,9 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereSkip($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereNameEncrypted($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereMatchEncrypted($value)
*
* @property mixed nextExpectedMatch
* @property mixed lastFoundMatch
*/
class Bill extends Model
{

View File

@ -24,6 +24,9 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereName($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereUserId($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereEncrypted($value)
*
* @property mixed spent
* @property mixed lastActivity
*/
class Category extends Model
{

View File

@ -61,6 +61,11 @@ use Watson\Validating\ValidatingTrait;
* @method static \FireflyIII\Models\TransactionJournal transactionTypes($types)
* @method static \FireflyIII\Models\TransactionJournal withRelevantData()
* @property-read mixed $expense_account
* @property string account_encrypted
* @property bool joinedTransactions
* @property bool joinedTransactionTypes
* @property mixed account_id
* @property mixed name
*/
class TransactionJournal extends Model
{
@ -152,7 +157,7 @@ class TransactionJournal extends Model
// loop other deposits, remove from our amount.
$others = $advancePayment->transactionJournals()->transactionTypes(['Deposit'])->get();
foreach ($others as $other) {
$amount = bcsub($amount, $other->actualAmount);
$amount = bcsub($amount, $other->actual_amount);
}
return $amount;
@ -173,7 +178,7 @@ class TransactionJournal extends Model
if ($this->transactionType->type == 'Withdrawal') {
$transfer = $balancingAct->transactionJournals()->transactionTypes(['Transfer'])->first();
if ($transfer) {
$amount = bcsub($amount, $transfer->actualAmount);
$amount = bcsub($amount, $transfer->actual_amount);
return $amount;
}