mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand code for reports.
This commit is contained in:
parent
0a2cbaa047
commit
d7b0106e7d
@ -200,50 +200,17 @@ class ReportController extends BaseController
|
||||
// );
|
||||
|
||||
/*
|
||||
* Filter withdrawals without a counter-transfer (into this account)
|
||||
* TODO Filter withdrawals without a counter-transfer (into this account)
|
||||
*/
|
||||
$withdrawals = $withdrawals->filter(
|
||||
function (TransactionJournal $journal) {
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
if (floatval($transaction->amount) < 0) {
|
||||
$account = $transaction->account;
|
||||
// find counter transfer:
|
||||
$counters = $account->transactions()->where('amount', floatval($transaction->amount) * -1)
|
||||
->where('account_id', '=', $transaction->account_id)
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.description', 'LIKE', '%' . e($journal->description) . '%')
|
||||
->get(['transactions.*']);
|
||||
if ($counters->count() == 0) {
|
||||
return $journal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/*
|
||||
* Filter deposits without a counter-transfer (away from this account)
|
||||
* TODO Filter deposits without a counter-transfer (away from this account)
|
||||
*/
|
||||
$deposits = $deposits->filter(
|
||||
function (TransactionJournal $journal) {
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
|
||||
if (floatval($transaction->amount) > 0) {
|
||||
$account = $transaction->account;
|
||||
// find counter transfer:
|
||||
$counters = $account->transactions()->where('amount', floatval($transaction->amount) * -1)
|
||||
->where('account_id', '=', $transaction->account_id)
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.description', 'LIKE', '%' . e($journal->description) . '%')
|
||||
->get(['transactions.*']);
|
||||
if ($counters->count() == 0) {
|
||||
return $journal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
$journals = $withdrawals->merge($deposits);
|
||||
|
||||
return View::make('reports.unbalanced', compact('start', 'end', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon', 'withdrawals', 'deposits'));
|
||||
|
||||
return View::make('reports.unbalanced', compact('start', 'end', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon', 'journals'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,7 @@ class DatabaseSeeder extends Seeder
|
||||
$this->call('TransactionCurrencySeeder');
|
||||
$this->call('TransactionTypeSeeder');
|
||||
$this->call('DefaultUserSeeder');
|
||||
$this->call('TestContentSeeder');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,10 +8,15 @@ class DefaultUserSeeder extends Seeder
|
||||
public function run()
|
||||
{
|
||||
DB::table('users')->delete();
|
||||
if (App::environment() == 'homestead') {
|
||||
|
||||
User::create(
|
||||
['email' => 'thegrumpydictator@gmail.com', 'password' => 'sander', 'reset' => null, 'remember_token' => null, 'migrated' => 0]
|
||||
);
|
||||
User::create(
|
||||
['email' => 'thegrumpydictator@gmail.com', 'password' => 'james', 'reset' => null, 'remember_token' => null, 'migrated' => 0]
|
||||
);
|
||||
User::create(
|
||||
['email' => 'acceptance@example.com', 'password' => 'acceptance', 'reset' => null, 'remember_token' => null, 'migrated' => 0]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
176
app/database/seeds/TestContentSeeder.php
Normal file
176
app/database/seeds/TestContentSeeder.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class TestContentSeeder extends Seeder
|
||||
{
|
||||
|
||||
public function run()
|
||||
{
|
||||
if (App::environment() == 'homestead') {
|
||||
|
||||
$assetType = AccountType::whereType('Asset account')->first();
|
||||
$expenseType = AccountType::whereType('Expense account')->first();
|
||||
$revenueType = AccountType::whereType('Revenue account')->first();
|
||||
$ibType = AccountType::whereType('Initial balance account')->first();
|
||||
|
||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||
|
||||
$obType = TransactionType::whereType('Opening balance')->first();
|
||||
$withdrawal = TransactionType::whereType('Withdrawal')->first();
|
||||
$transfer = TransactionType::whereType('Transfer')->first();
|
||||
$deposit = TransactionType::whereType('Deposit')->first();
|
||||
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
|
||||
if ($user) {
|
||||
// create two asset accounts.
|
||||
$checking = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Checking account', 'active' => 1]);
|
||||
$savings = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Savings account', 'active' => 1]);
|
||||
|
||||
// create two budgets:
|
||||
$groceriesBudget = Budget::create(['user_id' => $user->id, 'name' => 'Groceries']);
|
||||
$billsBudget = Budget::create(['user_id' => $user->id, 'name' => 'Bills']);
|
||||
|
||||
// create two categories:
|
||||
$dailyGroceries = Category::create(['user_id' => $user->id, 'name' => 'Daily groceries']);
|
||||
$lunch = Category::create(['user_id' => $user->id, 'name' => 'Lunch']);
|
||||
$house = Category::create(['user_id' => $user->id, 'name' => 'House']);
|
||||
|
||||
// create some expense accounts.
|
||||
$ah = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Albert Heijn', 'active' => 1]);
|
||||
$plus = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'PLUS', 'active' => 1]);
|
||||
$vitens = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Vitens', 'active' => 1]);
|
||||
$greenchoice = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Greenchoice', 'active' => 1]);
|
||||
$portaal = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Portaal', 'active' => 1]);
|
||||
$store = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Buy More', 'active' => 1]);
|
||||
|
||||
// create three revenue accounts.
|
||||
$employer = Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Employer', 'active' => 1]);
|
||||
$taxes = Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'IRS', 'active' => 1]);
|
||||
$job = Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Job', 'active' => 1]);
|
||||
|
||||
// put money in the two accounts (initial balance)
|
||||
$ibChecking = Account::create(
|
||||
['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Checking account initial balance', 'active' => 0]
|
||||
);
|
||||
$ibSavings = Account::create(
|
||||
['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Savings account initial balance', 'active' => 0]
|
||||
);
|
||||
|
||||
$this->createTransaction($ibChecking, $checking, 4000, $obType, 'Initial Balance for Checking account', '2014-01-01');
|
||||
$this->createTransaction($ibSavings, $savings, 10000, $obType, 'Initial Balance for Savings account', '2014-01-01');
|
||||
|
||||
|
||||
// create some expenses and incomes and what-not (for every month):
|
||||
$start = new Carbon('2014-01-01');
|
||||
$end = Carbon::now()->startOfMonth()->subDay();
|
||||
while ($start <= $end) {
|
||||
$this->createTransaction(
|
||||
$checking, $portaal, 500, $withdrawal, 'Rent for ' . $start->format('F Y'), $start->format('Y-m-') . '01', $billsBudget, $house
|
||||
);
|
||||
$this->createTransaction(
|
||||
$checking, $vitens, 12, $withdrawal, 'Water for ' . $start->format('F Y'), $start->format('Y-m-') . '02', $billsBudget, $house
|
||||
);
|
||||
$this->createTransaction(
|
||||
$checking, $greenchoice, 110, $withdrawal, 'Power for ' . $start->format('F Y'), $start->format('Y-m-') . '02', $billsBudget, $house
|
||||
);
|
||||
|
||||
// spend on groceries
|
||||
$groceriesStart = clone $start;
|
||||
for ($i = 0; $i < 13; $i++) {
|
||||
$amt = rand(100, 300) / 10;
|
||||
$lunchAmount = rand(30, 60) / 10;
|
||||
$this->createTransaction(
|
||||
$checking, $plus, $lunchAmount, $withdrawal, 'Lunch', $groceriesStart->format('Y-m-d'), $groceriesBudget, $lunch
|
||||
);
|
||||
$groceriesStart->addDay();
|
||||
if (intval($groceriesStart->format('d')) % 2 == 0) {
|
||||
$this->createTransaction(
|
||||
$checking, $ah, $amt, $withdrawal, 'Groceries', $groceriesStart->format('Y-m-d'), $groceriesBudget, $dailyGroceries
|
||||
);
|
||||
}
|
||||
$groceriesStart->addDay();
|
||||
}
|
||||
|
||||
// get income:
|
||||
$this->createTransaction($employer, $checking, rand(1400, 1600), $deposit, 'Salary', $start->format('Y-m-') . '23');
|
||||
|
||||
// pay taxes:
|
||||
$this->createTransaction($checking, $taxes, rand(50, 70), $withdrawal, 'Taxes in ' . $start->format('F Y'), $start->format('Y-m-') . '27');
|
||||
|
||||
// some other stuff.
|
||||
|
||||
|
||||
$start->addMonth();
|
||||
|
||||
}
|
||||
|
||||
// create some big expenses, move some money around.
|
||||
$this->createTransaction($savings, $checking, 1259, $transfer, 'Money for new PC', $end->format('Y-m') . '-11');
|
||||
$this->createTransaction($checking, $store, 1259, $withdrawal, 'New PC', $end->format('Y-m') . '-12');
|
||||
|
||||
// create two budgets
|
||||
|
||||
// create two categories
|
||||
|
||||
// create
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $from
|
||||
* @param Account $to
|
||||
* @param $amount
|
||||
* @param TransactionType $type
|
||||
* @param $description
|
||||
* @param $date
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function createTransaction(
|
||||
Account $from, Account $to, $amount, TransactionType $type, $description, $date, Budget $budget = null, Category $category = null
|
||||
) {
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = TransactionJournal::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'transaction_type_id' => $type->id,
|
||||
'transaction_currency_id' => $euro->id,
|
||||
'description' => $description,
|
||||
'completed' => 1,
|
||||
'date' => $date
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $from->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => $amount * -1
|
||||
]
|
||||
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $to->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => $amount
|
||||
]
|
||||
|
||||
);
|
||||
if (!is_null($budget)) {
|
||||
$journal->budgets()->save($budget);
|
||||
}
|
||||
if (!is_null($category)) {
|
||||
$journal->categories()->save($category);
|
||||
}
|
||||
|
||||
return $journal;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace FireflyIII\Shared\Mail;
|
||||
use Swift_RfcComplianceException;
|
||||
|
||||
/**
|
||||
* Class Registration
|
||||
@ -24,11 +25,13 @@ class Registration implements RegistrationInterface
|
||||
|
||||
|
||||
$data = ['password' => $password];
|
||||
\Mail::send(
|
||||
['emails.user.register-html', 'emails.user.register-text'], $data, function ($message) use ($email) {
|
||||
$message->to($email, $email)->subject('Welcome to Firefly!');
|
||||
}
|
||||
);
|
||||
try {
|
||||
\Mail::send(
|
||||
['emails.user.register-html', 'emails.user.register-text'], $data, function ($message) use ($email) {
|
||||
$message->to($email, $email)->subject('Welcome to Firefly!');
|
||||
}
|
||||
);
|
||||
} catch(Swift_RfcComplianceException $e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,14 +1,14 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $start) }}
|
||||
@if(count($withdrawals) == 0 && count($deposits) == 0)
|
||||
@if(count($journals) == 0)
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-4 col-sm-6">
|
||||
<p class="text-success">Everything accounted for.</p>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@if(count($withdrawals) > 0)
|
||||
@if(count($journals) > 0)
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-4 col-sm-6">
|
||||
<h3>Withdrawals</h3>
|
||||
@ -16,47 +16,37 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@foreach($withdrawals as $journal)
|
||||
@foreach($journals as $journal)
|
||||
<div class="col-lg-4 col-md-4 col-sm-6">
|
||||
<div class="panel panel-danger">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
@if($journal->transactiontype->type == 'Withdrawal')
|
||||
<span class="glyphicon glyphicon-arrow-left" title="Withdrawal"></span>
|
||||
@endif
|
||||
@if($journal->transactiontype->type == 'Deposit')
|
||||
<span class="glyphicon glyphicon-arrow-right" title="Deposit"></span>
|
||||
@endif
|
||||
@if($journal->transactiontype->type == 'Transfer')
|
||||
<span class="glyphicon glyphicon-resize-full" title="Transfer"></span>
|
||||
@endif
|
||||
@if($journal->transactiontype->type == 'Opening balance')
|
||||
<span class="glyphicon glyphicon-ban-circle" title="Opening balance"></span>
|
||||
@endif
|
||||
<a href="{{route('transactions.show',$journal->id)}}">{{{$journal->description}}}</a>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>Spent {{mf($journal->getAmount())}}</p>
|
||||
<p class="text-danger">No counter transaction!</p>
|
||||
<p>
|
||||
<a href="#" class="btn btn-default">Add counter transaction</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
@if(count($deposits) > 0)
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-4 col-sm-6">
|
||||
<h3>Deposits</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
@foreach($deposits as $journal)
|
||||
<div class="col-lg-4 col-md-4 col-sm-6">
|
||||
<div class="panel panel-danger">
|
||||
<div class="panel-heading">
|
||||
<a href="{{route('transactions.show',$journal->id)}}">{{{$journal->description}}}</a>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>Received {{mf($journal->getAmount())}}</p>
|
||||
<p class="text-danger">No counter transaction!</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
|
||||
|
||||
@stop
|
||||
@section('scripts')
|
||||
|
||||
@stop
|
Loading…
Reference in New Issue
Block a user