mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Moved all old code for Laravel 5.
This commit is contained in:
parent
a4b3bf3ef4
commit
d16015d625
@ -1,369 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use DaveJamesMiller\Breadcrumbs\Generator;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
|
||||
/*
|
||||
* Back home.
|
||||
*/
|
||||
Breadcrumbs::register(
|
||||
'home',
|
||||
function (Generator $breadcrumbs) {
|
||||
|
||||
$breadcrumbs->push('Home', route('index'));
|
||||
}
|
||||
);
|
||||
|
||||
// accounts
|
||||
Breadcrumbs::register(
|
||||
'accounts.index', function (Generator $breadcrumbs, $what) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push(ucfirst(e($what)) . ' accounts', route('accounts.index', $what));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'accounts.show', function (Generator $breadcrumbs, \Account $account) {
|
||||
switch ($account->accountType->type) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle account type "' . e($account->accountType->type) . '"');
|
||||
break;
|
||||
case 'Default account':
|
||||
case 'Asset account':
|
||||
$what = 'asset';
|
||||
break;
|
||||
case 'Cash account':
|
||||
$what = 'cash';
|
||||
break;
|
||||
case 'Expense account':
|
||||
case 'Beneficiary account':
|
||||
$what = 'expense';
|
||||
break;
|
||||
case 'Revenue account':
|
||||
$what = 'revenue';
|
||||
break;
|
||||
}
|
||||
$breadcrumbs->parent('accounts.index', $what);
|
||||
$breadcrumbs->push(e($account->name), route('accounts.show', $account->id));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'accounts.delete', function (Generator $breadcrumbs, \Account $account) {
|
||||
$breadcrumbs->parent('accounts.show', $account);
|
||||
$breadcrumbs->push('Delete ' . e($account->name), route('accounts.delete', $account->id));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'accounts.edit', function (Generator $breadcrumbs, \Account $account) {
|
||||
$breadcrumbs->parent('accounts.show', $account);
|
||||
$breadcrumbs->push('Edit ' . e($account->name), route('accounts.edit', $account->id));
|
||||
}
|
||||
);
|
||||
|
||||
// budgets.
|
||||
Breadcrumbs::register(
|
||||
'budgets.index', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push('Budgets', route('budgets.index'));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'budgets.create', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('budgets.index');
|
||||
$breadcrumbs->push('Create new budget', route('budgets.create'));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'budgets.edit', function (Generator $breadcrumbs, Budget $budget) {
|
||||
$breadcrumbs->parent('budgets.show', $budget);
|
||||
$breadcrumbs->push('Edit ' . e($budget->name), route('budgets.edit', $budget->id));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'budgets.delete', function (Generator $breadcrumbs, Budget $budget) {
|
||||
$breadcrumbs->parent('budgets.show', $budget);
|
||||
$breadcrumbs->push('Delete ' . e($budget->name), route('budgets.delete', $budget->id));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'budgets.show', function (Generator $breadcrumbs, Budget $budget, LimitRepetition $repetition = null) {
|
||||
$breadcrumbs->parent('budgets.index');
|
||||
$breadcrumbs->push(e($budget->name), route('budgets.show', $budget->id));
|
||||
if (!is_null($repetition)) {
|
||||
$breadcrumbs->push(
|
||||
DateKit::periodShow($repetition->startdate, $repetition->budgetlimit->repeat_freq), route('budgets.show', $budget->id, $repetition->id)
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// categories
|
||||
Breadcrumbs::register(
|
||||
'categories.index', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push('Categories', route('categories.index'));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'categories.create', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('categories.index');
|
||||
$breadcrumbs->push('Create new category', route('categories.create'));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'categories.edit', function (Generator $breadcrumbs, Category $category) {
|
||||
$breadcrumbs->parent('categories.show', $category);
|
||||
$breadcrumbs->push('Edit ' . e($category->name), route('categories.edit', $category->id));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'categories.delete', function (Generator $breadcrumbs, Category $category) {
|
||||
$breadcrumbs->parent('categories.show', $category);
|
||||
$breadcrumbs->push('Delete ' . e($category->name), route('categories.delete', $category->id));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'categories.show', function (Generator $breadcrumbs, Category $category) {
|
||||
$breadcrumbs->parent('categories.index');
|
||||
$breadcrumbs->push(e($category->name), route('categories.show', $category->id));
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// piggy banks
|
||||
Breadcrumbs::register(
|
||||
'piggyBanks.index', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push('Piggy banks', route('piggyBanks.index'));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'piggyBanks.create', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('piggyBanks.index');
|
||||
$breadcrumbs->push('Create new piggy bank', route('piggyBanks.create'));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'piggyBanks.edit', function (Generator $breadcrumbs, PiggyBank $piggyBank) {
|
||||
$breadcrumbs->parent('piggyBanks.show', $piggyBank);
|
||||
$breadcrumbs->push('Edit ' . e($piggyBank->name), route('piggyBanks.edit', $piggyBank->id));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'piggyBanks.delete', function (Generator $breadcrumbs, PiggyBank $piggyBank) {
|
||||
$breadcrumbs->parent('piggyBanks.show', $piggyBank);
|
||||
$breadcrumbs->push('Delete ' . e($piggyBank->name), route('piggyBanks.delete', $piggyBank->id));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'piggyBanks.show', function (Generator $breadcrumbs, PiggyBank $piggyBank) {
|
||||
$breadcrumbs->parent('piggyBanks.index');
|
||||
$breadcrumbs->push(e($piggyBank->name), route('piggyBanks.show', $piggyBank->id));
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// preferences
|
||||
Breadcrumbs::register(
|
||||
'preferences', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push('Preferences', route('preferences'));
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// profile
|
||||
Breadcrumbs::register(
|
||||
'profile', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push('Profile', route('profile'));
|
||||
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'change-password', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('profile');
|
||||
$breadcrumbs->push('Change your password', route('change-password'));
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// bills
|
||||
Breadcrumbs::register(
|
||||
'bills.index', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push('Bills', route('bills.index'));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'bills.create', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('bills.index');
|
||||
$breadcrumbs->push('Create new bill', route('bills.create'));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'bills.edit', function (Generator $breadcrumbs, Bill $bill) {
|
||||
$breadcrumbs->parent('bills.show', $bill);
|
||||
$breadcrumbs->push('Edit ' . e($bill->name), route('bills.edit', $bill->id));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'bills.delete', function (Generator $breadcrumbs, Bill $bill) {
|
||||
$breadcrumbs->parent('bills.show', $bill);
|
||||
$breadcrumbs->push('Delete ' . e($bill->name), route('bills.delete', $bill->id));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'bills.show', function (Generator $breadcrumbs, Bill $bill) {
|
||||
$breadcrumbs->parent('bills.index');
|
||||
$breadcrumbs->push(e($bill->name), route('bills.show', $bill->id));
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// reminders
|
||||
Breadcrumbs::register(
|
||||
'reminders.show', function (Generator $breadcrumbs, Reminder $reminder) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push('Reminder #' . $reminder->id, route('reminders.show', $reminder->id));
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// repeated expenses
|
||||
Breadcrumbs::register(
|
||||
'repeated.index', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push('Repeated expenses', route('repeated.index'));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'repeated.create', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('repeated.index');
|
||||
$breadcrumbs->push('Create new repeated expense', route('repeated.create'));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'repeated.edit', function (Generator $breadcrumbs, PiggyBank $piggyBank) {
|
||||
$breadcrumbs->parent('repeated.show', $piggyBank);
|
||||
$breadcrumbs->push('Edit ' . e($piggyBank->name), route('repeated.edit', $piggyBank->id));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'repeated.delete', function (Generator $breadcrumbs, PiggyBank $piggyBank) {
|
||||
$breadcrumbs->parent('repeated.show', $piggyBank);
|
||||
$breadcrumbs->push('Delete ' . e($piggyBank->name), route('repeated.delete', $piggyBank->id));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'repeated.show', function (Generator $breadcrumbs, PiggyBank $piggyBank) {
|
||||
$breadcrumbs->parent('repeated.index');
|
||||
$breadcrumbs->push(e($piggyBank->name), route('repeated.show', $piggyBank->id));
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// reports
|
||||
Breadcrumbs::register(
|
||||
'reports.index', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push('Reports', route('reports.index'));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'reports.year', function (Generator $breadcrumbs, Carbon $date) {
|
||||
$breadcrumbs->parent('reports.index');
|
||||
$breadcrumbs->push($date->format('Y'), route('reports.year', $date->format('Y')));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'reports.month', function (Generator $breadcrumbs, Carbon $date) {
|
||||
$breadcrumbs->parent('reports.index');
|
||||
$breadcrumbs->push('Monthly report for ' . $date->format('F Y'), route('reports.month', $date));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'reports.budget', function (Generator $breadcrumbs, Carbon $date) {
|
||||
$breadcrumbs->parent('reports.index');
|
||||
$breadcrumbs->push('Budget report for ' . $date->format('F Y'), route('reports.budget', $date));
|
||||
}
|
||||
);
|
||||
|
||||
// search
|
||||
Breadcrumbs::register(
|
||||
'search', function (Generator $breadcrumbs, $query) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push('Search for "' . e($query) . '"', route('search'));
|
||||
}
|
||||
);
|
||||
|
||||
// transactions
|
||||
Breadcrumbs::register(
|
||||
'transactions.index', function (Generator $breadcrumbs, $what) {
|
||||
$breadcrumbs->parent('home');
|
||||
|
||||
switch ($what) {
|
||||
case 'expenses':
|
||||
case 'withdrawal':
|
||||
$subTitle = 'Expenses';
|
||||
break;
|
||||
case 'revenue':
|
||||
case 'deposit':
|
||||
$subTitle = 'Revenue, income and deposits';
|
||||
break;
|
||||
case 'transfer':
|
||||
case 'transfers':
|
||||
$subTitle = 'Transfers';
|
||||
break;
|
||||
case 'opening balance':
|
||||
$subTitle = 'Opening balances';
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('Cannot handle $what "' . e($what) . '" in bread crumbs');
|
||||
}
|
||||
|
||||
$breadcrumbs->push($subTitle, route('transactions.index', $what));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'transactions.create', function (Generator $breadcrumbs, $what) {
|
||||
$breadcrumbs->parent('transactions.index', $what);
|
||||
$breadcrumbs->push('Create new ' .e($what), route('transactions.create', $what));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'transactions.edit', function (Generator $breadcrumbs, TransactionJournal $journal) {
|
||||
$breadcrumbs->parent('transactions.show', $journal);
|
||||
$breadcrumbs->push('Edit ' . e($journal->description), route('transactions.edit', $journal->id));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'transactions.delete', function (Generator $breadcrumbs, TransactionJournal $journal) {
|
||||
$breadcrumbs->parent('transactions.show', $journal);
|
||||
$breadcrumbs->push('Delete ' . e($journal->description), route('transactions.delete', $journal->id));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'transactions.show', function (Generator $breadcrumbs, TransactionJournal $journal) {
|
||||
|
||||
$breadcrumbs->parent('transactions.index', strtolower($journal->transactionType->type));
|
||||
$breadcrumbs->push(e($journal->description), route('transactions.show', $journal->id));
|
||||
|
||||
}
|
||||
);
|
@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* Class Cleanup
|
||||
*/
|
||||
class Cleanup extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Clean caches, regenerate some stuff.';
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'firefly:cleanup';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$this->info('Start!');
|
||||
Artisan::call('clear-compiled');
|
||||
$this->info('Cleared compiled...');
|
||||
Artisan::call('ide-helper:generate');
|
||||
$this->info('IDE helper, done...');
|
||||
Artisan::call('ide-helper:models');
|
||||
$this->info('IDE models, done...');
|
||||
Artisan::call('optimize');
|
||||
$this->info('Optimized...');
|
||||
Artisan::call('dump-autoload');
|
||||
$this->info('Done!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
// ['example', InputArgument::REQUIRED, 'An example argument.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
// ['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
4
app/config/.gitignore
vendored
4
app/config/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
local/
|
||||
laptop/
|
||||
vagrant/
|
||||
production/
|
@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'debug' => false,
|
||||
'url' => 'http://localhost',
|
||||
'timezone' => 'UTC',
|
||||
'locale' => 'en',
|
||||
'fallback_locale' => 'en',
|
||||
'log_level' => 'notice',
|
||||
'key' => 'D93oqmVsIARg23FC3cbsHuBGk0uXQc3r',
|
||||
'cipher' => MCRYPT_RIJNDAEL_128,
|
||||
'providers' => [
|
||||
|
||||
'Illuminate\Foundation\Providers\ArtisanServiceProvider',
|
||||
'Illuminate\Auth\AuthServiceProvider',
|
||||
'Illuminate\Cache\CacheServiceProvider',
|
||||
'Illuminate\Session\CommandsServiceProvider',
|
||||
'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
|
||||
'Illuminate\Routing\ControllerServiceProvider',
|
||||
'Illuminate\Cookie\CookieServiceProvider',
|
||||
'Illuminate\Database\DatabaseServiceProvider',
|
||||
'Illuminate\Encryption\EncryptionServiceProvider',
|
||||
'Illuminate\Filesystem\FilesystemServiceProvider',
|
||||
'Illuminate\Hashing\HashServiceProvider',
|
||||
'Illuminate\Html\HtmlServiceProvider',
|
||||
'Illuminate\Log\LogServiceProvider',
|
||||
'Illuminate\Mail\MailServiceProvider',
|
||||
'Illuminate\Database\MigrationServiceProvider',
|
||||
'Illuminate\Pagination\PaginationServiceProvider',
|
||||
'Illuminate\Queue\QueueServiceProvider',
|
||||
'Illuminate\Redis\RedisServiceProvider',
|
||||
'Illuminate\Remote\RemoteServiceProvider',
|
||||
'Illuminate\Auth\Reminders\ReminderServiceProvider',
|
||||
'Illuminate\Database\SeedServiceProvider',
|
||||
'Illuminate\Session\SessionServiceProvider',
|
||||
'Illuminate\Translation\TranslationServiceProvider',
|
||||
'Illuminate\Validation\ValidationServiceProvider',
|
||||
'Illuminate\View\ViewServiceProvider',
|
||||
'Illuminate\Workbench\WorkbenchServiceProvider',
|
||||
//'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
|
||||
//'Barryvdh\Debugbar\ServiceProvider',
|
||||
'FireflyIII\FF3ServiceProvider',
|
||||
'DaveJamesMiller\Breadcrumbs\ServiceProvider',
|
||||
'Grumpydictator\Gchart\GchartServiceProvider',
|
||||
],
|
||||
'manifest' => storage_path() . '/meta',
|
||||
'aliases' => [
|
||||
|
||||
'App' => 'Illuminate\Support\Facades\App',
|
||||
'Artisan' => 'Illuminate\Support\Facades\Artisan',
|
||||
'Auth' => 'Illuminate\Support\Facades\Auth',
|
||||
'Blade' => 'Illuminate\Support\Facades\Blade',
|
||||
'Cache' => 'Illuminate\Support\Facades\Cache',
|
||||
'ClassLoader' => 'Illuminate\Support\ClassLoader',
|
||||
'Config' => 'Illuminate\Support\Facades\Config',
|
||||
'Controller' => 'Illuminate\Routing\Controller',
|
||||
'Cookie' => 'Illuminate\Support\Facades\Cookie',
|
||||
'Crypt' => 'Illuminate\Support\Facades\Crypt',
|
||||
'DB' => 'Illuminate\Support\Facades\DB',
|
||||
'Eloquent' => 'Illuminate\Database\Eloquent\Model',
|
||||
'Event' => 'Illuminate\Support\Facades\Event',
|
||||
'File' => 'Illuminate\Support\Facades\File',
|
||||
'Form' => 'Illuminate\Support\Facades\Form',
|
||||
'Hash' => 'Illuminate\Support\Facades\Hash',
|
||||
'HTML' => 'Illuminate\Support\Facades\HTML',
|
||||
'Input' => 'Illuminate\Support\Facades\Input',
|
||||
'Lang' => 'Illuminate\Support\Facades\Lang',
|
||||
'Log' => 'Illuminate\Support\Facades\Log',
|
||||
'Mail' => 'Illuminate\Support\Facades\Mail',
|
||||
'Paginator' => 'Illuminate\Support\Facades\Paginator',
|
||||
'Password' => 'Illuminate\Support\Facades\Password',
|
||||
'Queue' => 'Illuminate\Support\Facades\Queue',
|
||||
'Redirect' => 'Illuminate\Support\Facades\Redirect',
|
||||
'Redis' => 'Illuminate\Support\Facades\Redis',
|
||||
'Request' => 'Illuminate\Support\Facades\Request',
|
||||
'Response' => 'Illuminate\Support\Facades\Response',
|
||||
'Route' => 'Illuminate\Support\Facades\Route',
|
||||
'Schema' => 'Illuminate\Support\Facades\Schema',
|
||||
'Seeder' => 'Illuminate\Database\Seeder',
|
||||
'Session' => 'Illuminate\Support\Facades\Session',
|
||||
'SoftDeletingTrait' => 'Illuminate\Database\Eloquent\SoftDeletingTrait',
|
||||
'SSH' => 'Illuminate\Support\Facades\SSH',
|
||||
'Str' => 'Illuminate\Support\Str',
|
||||
'URL' => 'Illuminate\Support\Facades\URL',
|
||||
'Validator' => 'Illuminate\Support\Facades\Validator',
|
||||
'View' => 'Illuminate\Support\Facades\View',
|
||||
'Breadcrumbs' => 'DaveJamesMiller\Breadcrumbs\Facade'
|
||||
|
||||
],
|
||||
|
||||
];
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'driver' => 'eloquent',
|
||||
'model' => 'User',
|
||||
'table' => 'users',
|
||||
'reminder' => [
|
||||
'email' => 'emails.auth.reminder',
|
||||
'table' => 'password_reminders',
|
||||
'expire' => 60,
|
||||
],
|
||||
'verify_mail' => true,
|
||||
'verify_reset' => true,
|
||||
'allow_register' => true
|
||||
|
||||
];
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'driver' => 'file',
|
||||
'path' => storage_path() . '/cache',
|
||||
'connection' => null,
|
||||
'table' => 'cache',
|
||||
'memcached' => [
|
||||
['host' => '127.0.0.1', 'port' => 11211, 'weight' => 100],
|
||||
],
|
||||
'prefix' => 'laravel',
|
||||
];
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [];
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'fetch' => PDO::FETCH_CLASS,
|
||||
'default' => 'mysql',
|
||||
'connections' => [
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'host' => 'localhost',
|
||||
'database' => 'forge',
|
||||
'username' => 'forge',
|
||||
'password' => '',
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
],
|
||||
],
|
||||
'migrations' => 'migrations',
|
||||
'redis' => [
|
||||
|
||||
'cluster' => false,
|
||||
|
||||
'default' => [
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 6379,
|
||||
'database' => 0,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
@ -1,4 +0,0 @@
|
||||
<?php
|
||||
return [
|
||||
'import' => ''
|
||||
];
|
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'index_periods' => ['1D', '1W', '1M', '3M', '6M', '1Y', 'custom'],
|
||||
'budget_periods' => ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly'],
|
||||
'piggy_bank_periods' => [
|
||||
'week' => 'Week',
|
||||
'month' => 'Month',
|
||||
'quarter' => 'Quarter',
|
||||
'year' => 'Year'
|
||||
],
|
||||
'periods_to_text' => [
|
||||
'weekly' => 'A week',
|
||||
'monthly' => 'A month',
|
||||
'quarterly' => 'A quarter',
|
||||
'half-year' => 'Six months',
|
||||
'yearly' => 'A year',
|
||||
],
|
||||
|
||||
'accountRoles' => [
|
||||
'defaultExpense' => 'Default expense account',
|
||||
'sharedExpense' => 'Shared expense account'
|
||||
],
|
||||
|
||||
'range_to_text' => [
|
||||
'1D' => 'day',
|
||||
'1W' => 'week',
|
||||
'1M' => 'month',
|
||||
'3M' => 'three months',
|
||||
'6M' => 'half year',
|
||||
'custom' => '(custom)'
|
||||
],
|
||||
'range_to_name' => [
|
||||
'1D' => 'one day',
|
||||
'1W' => 'one week',
|
||||
'1M' => 'one month',
|
||||
'3M' => 'three months',
|
||||
'6M' => 'six months',
|
||||
'1Y' => 'one year',
|
||||
],
|
||||
'range_to_repeat_freq' => [
|
||||
'1D' => 'weekly',
|
||||
'1W' => 'weekly',
|
||||
'1M' => 'monthly',
|
||||
'3M' => 'quarterly',
|
||||
'6M' => 'half-year',
|
||||
'custom' => 'monthly'
|
||||
],
|
||||
];
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
return [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Debug Mode
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When your application is in debug mode, detailed error messages with
|
||||
| stack traces will be shown on every error that occurs within your
|
||||
| application. If disabled, a simple generic error page is shown.
|
||||
|
|
||||
*/
|
||||
'debug' => true,
|
||||
'log_level' => 'debug',
|
||||
];
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'driver' => 'file',
|
||||
'path' => storage_path() . '/cache',
|
||||
'connection' => null,
|
||||
'table' => 'cache',
|
||||
'memcached' => [
|
||||
['host' => '127.0.0.1', 'port' => 11211, 'weight' => 100],
|
||||
],
|
||||
'prefix' => 'laravel',
|
||||
];
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'default' => 'mysql',
|
||||
'connections' => [
|
||||
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'host' => 'localhost',
|
||||
'database' => 'homestead',
|
||||
'username' => 'homestead',
|
||||
'password' => 'secret',
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
],
|
||||
'sqlite' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => realpath(__DIR__.'/../../../tests/_data/testing.sqlite'),
|
||||
'prefix' => ''
|
||||
],
|
||||
|
||||
'pgsql' => [
|
||||
'driver' => 'pgsql',
|
||||
'host' => 'localhost',
|
||||
'database' => 'homestead',
|
||||
'username' => 'homestead',
|
||||
'password' => 'secret',
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'schema' => 'public',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'driver' => 'smtp',
|
||||
'host' => 'smtp.gmail.com',
|
||||
'port' => 587,
|
||||
'from' => ['address' => 'empty@example.com', 'name' => 'Firefly III'],
|
||||
'encryption' => 'tls',
|
||||
'username' => 'empty@example.com',
|
||||
'password' => '',
|
||||
'sendmail' => '/usr/sbin/sendmail -bs',
|
||||
'pretend' => false,
|
||||
];
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'driver' => 'smtp',
|
||||
'host' => '',
|
||||
'port' => 587,
|
||||
'from' => ['address' => '', 'name' => 'Firefly III'],
|
||||
'encryption' => 'tls',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'sendmail' => '/usr/sbin/sendmail -bs',
|
||||
'pretend' => false,
|
||||
];
|
@ -1,127 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
return [
|
||||
|
||||
'enabled' => Config::get('app.debug'),
|
||||
|
||||
'storage' => [
|
||||
'enabled' => true,
|
||||
'path' => storage_path() . '/debugbar',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Vendors
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Vendor files are included by default, but can be set to false.
|
||||
| This can also be set to 'js' or 'css', to only include javascript or css vendor files.
|
||||
| Vendor files are for css: font-awesome (including fonts) and highlight.js (css files)
|
||||
| and for js: jquery and and highlight.js
|
||||
| So if you want syntax highlighting, set it to true.
|
||||
| jQuery is set to not conflict with existing jQuery scripts.
|
||||
|
|
||||
*/
|
||||
|
||||
'include_vendors' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Capture Ajax Requests
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The Debugbar can capture Ajax requests and display them. If you don't want this (ie. because of errors),
|
||||
| you can use this option to disable sending the data through the headers.
|
||||
|
|
||||
*/
|
||||
|
||||
'capture_ajax' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Capture Console Commands
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The Debugbar can listen to Artisan commands. You can view them with the browse button in the Debugbar.
|
||||
|
|
||||
*/
|
||||
|
||||
'capture_console' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DataCollectors
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Enable/disable DataCollectors
|
||||
|
|
||||
*/
|
||||
|
||||
'collectors' => [
|
||||
'phpinfo' => true, // Php version
|
||||
'messages' => true, // Messages
|
||||
'time' => true, // Time Datalogger
|
||||
'memory' => true, // Memory usage
|
||||
'exceptions' => true, // Exception displayer
|
||||
'log' => true, // Logs from Monolog (merged in messages if enabled)
|
||||
'db' => true, // Show database (PDO) queries and bindings
|
||||
'views' => true, // Views with their data
|
||||
'route' => true, // Current route information
|
||||
'laravel' => false, // Laravel version and environment
|
||||
'events' => false, // All events fired
|
||||
'default_request' => false, // Regular or special Symfony request logger
|
||||
'symfony_request' => true, // Only one can be enabled..
|
||||
'mail' => true, // Catch mail messages
|
||||
'logs' => false, // Add the latest log messages
|
||||
'files' => false, // Show the included files
|
||||
'config' => false, // Display config settings
|
||||
'auth' => false, // Display Laravel authentication status
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Extra options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Configure some DataCollectors
|
||||
|
|
||||
*/
|
||||
|
||||
'options' => [
|
||||
'auth' => [
|
||||
'show_name' => false, // Also show the users name/email in the debugbar
|
||||
],
|
||||
'db' => [
|
||||
'with_params' => true, // Render SQL with the parameters substituted
|
||||
'timeline' => false, // Add the queries to the timeline
|
||||
],
|
||||
'mail' => [
|
||||
'full_log' => false
|
||||
],
|
||||
'views' => [
|
||||
'data' => false, //Note: Can slow down the application, because the data can be quite large..
|
||||
],
|
||||
'route' => [
|
||||
'label' => true // show complete route on bar
|
||||
],
|
||||
'logs' => [
|
||||
'file' => null
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Inject Debugbar in Response
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Usually, the debugbar is added just before <body>, by listening to the
|
||||
| Response after the App is done. If you disable this, you have to add them
|
||||
| in your template yourself. See http://phpdebugbar.com/docs/rendering.html
|
||||
|
|
||||
*/
|
||||
|
||||
'inject' => true,
|
||||
|
||||
];
|
@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filename
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The default path to the helper file
|
||||
|
|
||||
*/
|
||||
|
||||
'filename' => '_ide_helper.php',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Helper files to include
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Include helper files. By default not included, but can be toggled with the
|
||||
| -- helpers (-H) option. Extra helper files can be included.
|
||||
|
|
||||
*/
|
||||
|
||||
'include_helpers' => false,
|
||||
|
||||
'helper_files' => [
|
||||
base_path() . '/vendor/laravel/framework/src/Illuminate/Support/helpers.php',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Model locations to include
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Define in which directories the ide-helper:models command should look
|
||||
| for models.
|
||||
|
|
||||
*/
|
||||
|
||||
'model_locations' => [
|
||||
'app/models',
|
||||
],
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Extra classes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These implementations are not really extended, but called with magic functions
|
||||
|
|
||||
*/
|
||||
|
||||
'extra' => [
|
||||
'Artisan' => ['Illuminate\Foundation\Artisan'],
|
||||
'Eloquent' => ['Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'],
|
||||
'Session' => ['Illuminate\Session\Store'],
|
||||
],
|
||||
|
||||
'magic' => [
|
||||
'Log' => [
|
||||
'debug' => 'Monolog\Logger::addDebug',
|
||||
'info' => 'Monolog\Logger::addInfo',
|
||||
'notice' => 'Monolog\Logger::addNotice',
|
||||
'warning' => 'Monolog\Logger::addWarning',
|
||||
'error' => 'Monolog\Logger::addError',
|
||||
'critical' => 'Monolog\Logger::addCritical',
|
||||
'alert' => 'Monolog\Logger::addAlert',
|
||||
'emergency' => 'Monolog\Logger::addEmergency',
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
];
|
@ -1,5 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'view' => 'laravel-breadcrumbs::bootstrap3',
|
||||
];
|
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'default' => 'sync',
|
||||
'connections' => [
|
||||
|
||||
'sync' => [
|
||||
'driver' => 'sync',
|
||||
],
|
||||
|
||||
'beanstalkd' => [
|
||||
'driver' => 'beanstalkd',
|
||||
'host' => 'localhost',
|
||||
'queue' => 'default',
|
||||
'ttr' => 60,
|
||||
],
|
||||
|
||||
'sqs' => [
|
||||
'driver' => 'sqs',
|
||||
'key' => 'your-public-key',
|
||||
'secret' => 'your-secret-key',
|
||||
'queue' => 'your-queue-url',
|
||||
'region' => 'us-east-1',
|
||||
],
|
||||
|
||||
'iron' => [
|
||||
'driver' => 'iron',
|
||||
'host' => 'mq-aws-us-east-1.iron.io',
|
||||
'token' => 'your-token',
|
||||
'project' => 'your-project-id',
|
||||
'queue' => 'your-queue-name',
|
||||
'encrypt' => true,
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'queue' => 'default',
|
||||
],
|
||||
|
||||
],
|
||||
'failed' => [
|
||||
'database' => 'mysql', 'table' => 'failed_jobs',
|
||||
],
|
||||
|
||||
];
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'default' => 'production',
|
||||
'connections' => [
|
||||
|
||||
'production' => [
|
||||
'host' => '',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'key' => '',
|
||||
'keyphrase' => '',
|
||||
'root' => '/var/www',
|
||||
],
|
||||
],
|
||||
'groups' => [
|
||||
'web' => ['production']
|
||||
|
||||
],
|
||||
|
||||
];
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'mailgun' => [
|
||||
'domain' => '',
|
||||
'secret' => '',
|
||||
],
|
||||
|
||||
'mandrill' => [
|
||||
'secret' => '',
|
||||
],
|
||||
|
||||
'stripe' => [
|
||||
'model' => 'User',
|
||||
'secret' => '',
|
||||
],
|
||||
|
||||
];
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'driver' => 'file',
|
||||
'lifetime' => 120,
|
||||
'expire_on_close' => false,
|
||||
'files' => storage_path() . '/sessions',
|
||||
'connection' => null,
|
||||
'table' => 'sessions',
|
||||
'lottery' => [2, 100],
|
||||
'cookie' => 'firefly_session',
|
||||
'path' => '/',
|
||||
'domain' => null,
|
||||
'secure' => false,
|
||||
|
||||
];
|
@ -1,2 +0,0 @@
|
||||
<?php
|
||||
return ['log_level' => 'debug',];
|
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'verify_mail' => false,
|
||||
'verify_reset' => true,
|
||||
'allow_register' => true
|
||||
|
||||
];
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
return ['driver' => 'array',];
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
return [
|
||||
'default' => 'sqlite',
|
||||
'connections' => [
|
||||
'sqlite' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => realpath(__DIR__.'/../../../tests/_data/db.sqlite'),
|
||||
'prefix' => ''
|
||||
]
|
||||
|
||||
]
|
||||
];
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'driver' => 'smtp',
|
||||
'host' => '',
|
||||
'port' => 587,
|
||||
'from' => ['address' => '', 'name' => 'Firefly III'],
|
||||
'encryption' => 'tls',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'sendmail' => '/usr/sbin/sendmail -bs',
|
||||
'pretend' => true,
|
||||
];
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
return ['driver' => 'array',];
|
@ -1,2 +0,0 @@
|
||||
<?php
|
||||
return ['log_level' => 'debug',];
|
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'verify_mail' => false,
|
||||
'verify_reset' => true,
|
||||
'allow_register' => true
|
||||
|
||||
];
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
return ['driver' => 'array',];
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
return [
|
||||
'default' => 'sqlite',
|
||||
'connections' => [
|
||||
'sqlite' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
'prefix' => ''
|
||||
]
|
||||
|
||||
]
|
||||
];
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'driver' => 'smtp',
|
||||
'host' => '',
|
||||
'port' => 587,
|
||||
'from' => ['address' => '', 'name' => 'Firefly III'],
|
||||
'encryption' => 'tls',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'sendmail' => '/usr/sbin/sendmail -bs',
|
||||
'pretend' => true,
|
||||
];
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
return ['driver' => 'array',];
|
@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'paths' => [__DIR__ . '/../views'],
|
||||
'pagination' => 'pagination::slider-3',
|
||||
];
|
@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => '',
|
||||
'email' => '',
|
||||
];
|
@ -1,233 +0,0 @@
|
||||
<?php
|
||||
|
||||
use FireflyIII\Database\Account\Account as AccountRepository;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
* Class AccountController
|
||||
*/
|
||||
class AccountController extends BaseController
|
||||
{
|
||||
|
||||
/** @var array */
|
||||
protected $_accountTypesByIdentifier
|
||||
= [
|
||||
'asset' => ['Default account', 'Asset account'],
|
||||
'expense' => ['Expense account', 'Beneficiary account'],
|
||||
'revenue' => ['Revenue account'],
|
||||
];
|
||||
|
||||
/** @var AccountRepository */
|
||||
protected $_repository;
|
||||
|
||||
/** @var array */
|
||||
protected $_shortNamesByFullName
|
||||
= [
|
||||
'Default account' => 'asset',
|
||||
'Asset account' => 'asset',
|
||||
'Expense account' => 'expense',
|
||||
'Beneficiary account' => 'expense',
|
||||
'Revenue account' => 'revenue',
|
||||
'Cash account' => 'cash',
|
||||
];
|
||||
|
||||
/** @var array */
|
||||
protected $_subIconsByIdentifier
|
||||
= [
|
||||
'asset' => 'fa-money',
|
||||
'Asset account' => 'fa-money',
|
||||
'Default account' => 'fa-money',
|
||||
'Cash account' => 'fa-money',
|
||||
'expense' => 'fa-shopping-cart',
|
||||
'Expense account' => 'fa-shopping-cart',
|
||||
'Beneficiary account' => 'fa-shopping-cart',
|
||||
'revenue' => 'fa-download',
|
||||
'Revenue account' => 'fa-download',
|
||||
];
|
||||
/** @var array */
|
||||
protected $_subTitlesByIdentifier
|
||||
= [
|
||||
'asset' => 'Asset accounts',
|
||||
'expense' => 'Expense accounts',
|
||||
'revenue' => 'Revenue accounts',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param AccountRepository $repository
|
||||
*/
|
||||
public function __construct(AccountRepository $repository)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
View::share('mainTitleIcon', 'fa-credit-card');
|
||||
View::share('title', 'Accounts');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $what
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create($what)
|
||||
{
|
||||
$subTitleIcon = $this->_subIconsByIdentifier[$what];
|
||||
$subTitle = 'Create a new ' . e($what) . ' account';
|
||||
|
||||
return View::make('accounts.create', compact('subTitleIcon', 'what', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete(Account $account)
|
||||
{
|
||||
$subTitle = 'Delete ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"';
|
||||
|
||||
return View::make('accounts.delete', compact('account', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Account $account)
|
||||
{
|
||||
|
||||
$type = $account->accountType->type;
|
||||
$typeName = $this->_shortNamesByFullName[$type];
|
||||
$name = $account->name;
|
||||
|
||||
$this->_repository->destroy($account);
|
||||
|
||||
Session::flash('success', 'The ' . e($typeName) . ' account "' . e($name) . '" was deleted.');
|
||||
|
||||
return Redirect::route('accounts.index', $typeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function edit(Account $account)
|
||||
{
|
||||
|
||||
$openingBalance = $this->_repository->openingBalanceTransaction($account);
|
||||
$subTitleIcon = $this->_subIconsByIdentifier[$account->accountType->type];
|
||||
$subTitle = 'Edit ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"';
|
||||
$what = $this->_shortNamesByFullName[$account->accountType->type];
|
||||
|
||||
// pre fill some useful values.
|
||||
$preFilled = [
|
||||
'account_role' => $account->getMeta('accountRole'),
|
||||
'openingBalanceDate' => $openingBalance ? $openingBalance->date->format('Y-m-d') : null,
|
||||
'openingBalance' => $openingBalance ? $openingBalance->getAmount($account) : null
|
||||
];
|
||||
Session::flash('preFilled', $preFilled);
|
||||
|
||||
return View::make('accounts.edit', compact('account', 'what', 'subTitle', 'openingBalance', 'subTitleIcon'));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $what
|
||||
*
|
||||
* @return View
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function index($what = 'default')
|
||||
{
|
||||
$subTitle = $this->_subTitlesByIdentifier[$what];
|
||||
$subTitleIcon = $this->_subIconsByIdentifier[$what];
|
||||
|
||||
$accounts = $this->_repository->getAccountsByType($this->_accountTypesByIdentifier[$what]);
|
||||
|
||||
return View::make('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param string $range
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function show(Account $account, $range = 'session')
|
||||
{
|
||||
$subTitleIcon = $this->_subIconsByIdentifier[$account->accountType->type];
|
||||
$what = $this->_shortNamesByFullName[$account->accountType->type];
|
||||
$journals = $this->_repository->getTransactionJournals($account, 50, $range);
|
||||
$subTitle = 'Details for ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"';
|
||||
|
||||
return View::make('accounts.show', compact('account', 'what', 'range', 'subTitleIcon', 'journals', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
|
||||
// flash messages:
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not store account: ' . $messages['errors']->first());
|
||||
}
|
||||
|
||||
// return to create screen:
|
||||
if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
|
||||
return Redirect::route('accounts.create', e($data['what']))->withInput();
|
||||
}
|
||||
|
||||
// store
|
||||
$this->_repository->store($data);
|
||||
Session::flash('success', 'Account "' . e($data['name']) . '" stored.');
|
||||
if ($data['post_submit_action'] == 'store') {
|
||||
return Redirect::route('accounts.index', e($data['what']));
|
||||
}
|
||||
|
||||
return Redirect::route('accounts.create', e($data['what']))->withInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return $this
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(Account $account)
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
// flash messages:
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not update account: ' . $messages['errors']->first());
|
||||
}
|
||||
|
||||
// return to update screen:
|
||||
if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
|
||||
return Redirect::route('accounts.edit', $account->id)->withInput();
|
||||
}
|
||||
|
||||
// update
|
||||
$this->_repository->update($account, $data);
|
||||
Session::flash('success', 'Account "' . e($data['name']) . '" updated.');
|
||||
|
||||
// go back to list
|
||||
if ($data['post_submit_action'] == 'update') {
|
||||
return Redirect::route('accounts.index', e($data['what']));
|
||||
}
|
||||
|
||||
// go back to update screen.
|
||||
return Redirect::route('accounts.edit', $account->id)->withInput(['post_submit_action' => 'return_to_edit']);
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
/**
|
||||
* Class BaseController
|
||||
*/
|
||||
class BaseController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the layout used by the controller.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setupLayout()
|
||||
{
|
||||
if (!is_null($this->layout)) {
|
||||
$this->layout = View::make($this->layout);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,215 +0,0 @@
|
||||
<?php
|
||||
use FireflyIII\Database\Bill\Bill as Repository;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
*
|
||||
* Class BillController
|
||||
*
|
||||
*/
|
||||
class BillController extends BaseController
|
||||
{
|
||||
|
||||
/** @var Repository */
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param Repository $repository
|
||||
*/
|
||||
public function __construct(Repository $repository)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
|
||||
View::share('title', 'Bills');
|
||||
View::share('mainTitleIcon', 'fa-calendar-o');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
|
||||
return View::make('bills.create')->with('periods', $periods)->with('subTitle', 'Create new');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete(Bill $bill)
|
||||
{
|
||||
return View::make('bills.delete')->with('bill', $bill)->with(
|
||||
'subTitle', 'Delete "' . e($bill->name) . '"'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Bill $bill)
|
||||
{
|
||||
$this->_repository->destroy($bill);
|
||||
Session::flash('success', 'The bill was deleted.');
|
||||
|
||||
return Redirect::route('bills.index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function edit(Bill $bill)
|
||||
{
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
|
||||
return View::make('bills.edit')->with('periods', $periods)->with('bill', $bill)->with(
|
||||
'subTitle', 'Edit "' . e($bill->name) . '"'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$bills = $this->_repository->get();
|
||||
$bills->each(
|
||||
function (Bill $bill) {
|
||||
$bill->nextExpectedMatch = $this->_repository->nextExpectedMatch($bill);
|
||||
$bill->lastFoundMatch = $this->_repository->lastFoundMatch($bill);
|
||||
}
|
||||
);
|
||||
|
||||
return View::make('bills.index', compact('bills'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function rescan(Bill $bill)
|
||||
{
|
||||
if (intval($bill->active) == 0) {
|
||||
Session::flash('warning', 'Inactive bills cannot be scanned.');
|
||||
|
||||
return Redirect::intended('/');
|
||||
}
|
||||
|
||||
$this->_repository->scanEverything($bill);
|
||||
|
||||
Session::flash('success', 'Rescanned everything.');
|
||||
|
||||
return Redirect::intended('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function show(Bill $bill)
|
||||
{
|
||||
$journals = $bill->transactionjournals()->withRelevantData()->orderBy('date', 'DESC')->get();
|
||||
$bill->nextExpectedMatch = $this->_repository->nextExpectedMatch($bill);
|
||||
$hideBill = true;
|
||||
|
||||
|
||||
return View::make('bills.show', compact('journals', 'hideBill', 'bill'))->with(
|
||||
'subTitle', e($bill->name)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$data = Input::except(['_token', 'post_submit_action']);
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
|
||||
|
||||
// always validate:
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
// flash messages:
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not store bill: ' . $messages['errors']->first());
|
||||
|
||||
return Redirect::route('bills.create')->withInput();
|
||||
}
|
||||
|
||||
// return to create screen:
|
||||
if (Input::get('post_submit_action') == 'validate_only') {
|
||||
return Redirect::route('bills.create')->withInput();
|
||||
}
|
||||
|
||||
// store
|
||||
$this->_repository->store($data);
|
||||
Session::flash('success', 'Bill "' . e($data['name']) . '" stored.');
|
||||
if (Input::get('post_submit_action') == 'store') {
|
||||
return Redirect::route('bills.index');
|
||||
}
|
||||
|
||||
return Redirect::route('bills.create')->withInput();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return $this
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(Bill $bill)
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
$data['active'] = intval(Input::get('active'));
|
||||
$data['automatch'] = intval(Input::get('automatch'));
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
|
||||
// always validate:
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
// flash messages:
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not update bill: ' . $messages['errors']->first());
|
||||
|
||||
return Redirect::route('bills.edit', $bill->id)->withInput();
|
||||
}
|
||||
|
||||
// return to update screen:
|
||||
if ($data['post_submit_action'] == 'validate_only') {
|
||||
return Redirect::route('bills.edit', $bill->id)->withInput();
|
||||
}
|
||||
|
||||
// update
|
||||
$this->_repository->update($bill, $data);
|
||||
Session::flash('success', 'Bill "' . e($data['name']) . '" updated.');
|
||||
|
||||
// go back to list
|
||||
if ($data['post_submit_action'] == 'update') {
|
||||
return Redirect::route('bills.index');
|
||||
}
|
||||
|
||||
// go back to update screen.
|
||||
return Redirect::route('bills.edit', $bill->id)->withInput(['post_submit_action' => 'return_to_edit']);
|
||||
|
||||
}
|
||||
}
|
@ -1,254 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\Budget\Budget as BudgetRepository;
|
||||
use FireflyIII\Shared\Preferences\PreferencesInterface as Pref;
|
||||
|
||||
/**
|
||||
* Class BudgetController
|
||||
*
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
*
|
||||
*/
|
||||
class BudgetController extends BaseController
|
||||
{
|
||||
|
||||
/** @var Pref */
|
||||
protected $_preferences;
|
||||
/** @var BudgetRepository */
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param BudgetRepository $repository
|
||||
* @param Pref $preferences
|
||||
*/
|
||||
public function __construct(BudgetRepository $repository, Pref $preferences)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
$this->_preferences = $preferences;
|
||||
View::share('title', 'Budgets');
|
||||
View::share('mainTitleIcon', 'fa-tasks');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function amount(Budget $budget)
|
||||
{
|
||||
$amount = intval(Input::get('amount'));
|
||||
$date = Session::get('start', Carbon::now()->startOfMonth());
|
||||
$limitRepetition = $this->_repository->updateLimitAmount($budget, $date, $amount);
|
||||
|
||||
return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition ? $limitRepetition->id : 0]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return View::make('budgets.create')->with('subTitle', 'Create a new budget');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete(Budget $budget)
|
||||
{
|
||||
$subTitle = 'Delete budget "' . e($budget->name) . '"';
|
||||
|
||||
return View::make('budgets.delete', compact('budget', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Budget $budget)
|
||||
{
|
||||
Session::flash('success', 'Budget "' . e($budget->name) . '" was deleted.');
|
||||
$this->_repository->destroy($budget);
|
||||
|
||||
|
||||
return Redirect::route('budgets.index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function edit(Budget $budget)
|
||||
{
|
||||
$subTitle = 'Edit budget "' . e($budget->name) . '"';
|
||||
|
||||
return View::make('budgets.edit', compact('budget', 'subTitle'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The index of the budget controller contains all budgets and the current relevant limit repetition.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$budgets = $this->_repository->get();
|
||||
|
||||
// loop the budgets:
|
||||
$budgets->each(
|
||||
function (Budget $budget) {
|
||||
$budget->spent = $this->_repository->spentInMonth($budget, \Session::get('start', Carbon::now()->startOfMonth()));
|
||||
$budget->currentRep = $this->_repository->getRepetitionByDate($budget, \Session::get('start', Carbon::now()->startOfMonth()));
|
||||
}
|
||||
);
|
||||
|
||||
$spent = $budgets->sum('spent');
|
||||
$amount = $this->_preferences->get('budgetIncomeTotal' . \Session::get('start', Carbon::now()->startOfMonth())->format('FY'), 1000)->data;
|
||||
$overspent = $spent > $amount;
|
||||
$spentPCT = $overspent ? ceil($amount / $spent * 100) : ceil($spent / $amount * 100);
|
||||
$budgetMax = $this->_preferences->get('budgetMaximum', 1000);
|
||||
$budgetMaximum = $budgetMax->data;
|
||||
|
||||
return View::make('budgets.index', compact('budgetMaximum', 'budgets', 'spent', 'spentPCT', 'overspent', 'amount'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function noBudget()
|
||||
{
|
||||
$start = \Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = \Session::get('end', Carbon::now()->startOfMonth());
|
||||
$list = $this->_repository->journalsNoBudget($start, $end);
|
||||
$subTitle = 'Transactions without a budget in ' . $start->format('F Y');
|
||||
|
||||
return View::make('budgets.noBudget', compact('list', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postUpdateIncome()
|
||||
{
|
||||
$this->_preferences->set('budgetIncomeTotal' . Session::get('start', Carbon::now()->startOfMonth())->format('FY'), intval(Input::get('amount')));
|
||||
|
||||
return Redirect::route('budgets.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param LimitRepetition $repetition
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show(Budget $budget, LimitRepetition $repetition = null)
|
||||
{
|
||||
if (!is_null($repetition) && $repetition->budgetLimit->budget->id != $budget->id) {
|
||||
return View::make('error')->with('message', 'Invalid selection.');
|
||||
}
|
||||
|
||||
$hideBudget = true; // used in transaction list.
|
||||
$journals = $this->_repository->getJournals($budget, $repetition);
|
||||
$limits = $repetition ? [$repetition->budgetLimit] : $budget->budgetLimits()->orderBy('startdate', 'DESC')->get();
|
||||
$subTitle = $repetition ? e($budget->name) . ' in ' . $repetition->startdate->format('F Y') : e($budget->name);
|
||||
|
||||
return View::make('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle', 'hideBudget'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
|
||||
// always validate:
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
// flash messages:
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not validate budget: ' . $messages['errors']->first());
|
||||
return Redirect::route('budgets.create')->withInput();
|
||||
}
|
||||
|
||||
// return to create screen:
|
||||
if ($data['post_submit_action'] == 'validate_only') {
|
||||
return Redirect::route('budgets.create')->withInput();
|
||||
}
|
||||
|
||||
// store
|
||||
$this->_repository->store($data);
|
||||
Session::flash('success', 'Budget "' . e($data['name']) . '" stored.');
|
||||
if ($data['post_submit_action'] == 'store') {
|
||||
return Redirect::route('budgets.index');
|
||||
}
|
||||
|
||||
// create another.
|
||||
return Redirect::route('budgets.create')->withInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Budget $budget)
|
||||
{
|
||||
|
||||
$data = Input::except('_token');
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
|
||||
// always validate:
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
// flash messages:
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not update budget: ' . $messages['errors']->first());
|
||||
return Redirect::route('budgets.edit', $budget->id)->withInput();
|
||||
}
|
||||
|
||||
// return to update screen:
|
||||
if ($data['post_submit_action'] == 'validate_only') {
|
||||
return Redirect::route('budgets.edit', $budget->id)->withInput();
|
||||
}
|
||||
|
||||
// update
|
||||
$this->_repository->update($budget, $data);
|
||||
Session::flash('success', 'Budget "' . e($data['name']) . '" updated.');
|
||||
|
||||
// go back to list
|
||||
if ($data['post_submit_action'] == 'update') {
|
||||
return Redirect::route('budgets.index');
|
||||
}
|
||||
|
||||
return Redirect::route('budgets.edit', $budget->id)->withInput(['post_submit_action' => 'return_to_edit']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function updateIncome()
|
||||
{
|
||||
$budgetAmount = $this->_preferences->get('budgetIncomeTotal' . Session::get('start', Carbon::now()->startOfMonth())->format('FY'), 1000);
|
||||
|
||||
return View::make('budgets.income')->with('amount', $budgetAmount);
|
||||
}
|
||||
}
|
@ -1,189 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\Category\Category as CategoryRepository;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
*
|
||||
* Class CategoryController
|
||||
*/
|
||||
class CategoryController extends BaseController
|
||||
{
|
||||
|
||||
/** @var CategoryRepository */
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param CategoryRepository $repository
|
||||
*/
|
||||
public function __construct(CategoryRepository $repository)
|
||||
{
|
||||
View::share('title', 'Categories');
|
||||
View::share('mainTitleIcon', 'fa-bar-chart');
|
||||
|
||||
$this->_repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return View::make('categories.create')->with('subTitle', 'Create a new category');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function noCategory()
|
||||
{
|
||||
$start = \Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = \Session::get('end', Carbon::now()->startOfMonth());
|
||||
$list = $this->_repository->journalsNoCategory($start, $end);
|
||||
$subTitle = 'Transactions without a category in ' . $start->format('F Y');
|
||||
|
||||
return View::make('categories.noCategory', compact('list', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete(Category $category)
|
||||
{
|
||||
return View::make('categories.delete')->with('category', $category)->with('subTitle', 'Delete category "' . e($category->name) . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Category $category)
|
||||
{
|
||||
Session::flash('success', 'Category "' . e($category->name) . '" was deleted.');
|
||||
$this->_repository->destroy($category);
|
||||
|
||||
|
||||
return Redirect::route('categories.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function edit(Category $category)
|
||||
{
|
||||
return View::make('categories.edit')->with('category', $category)->with('subTitle', 'Edit category "' . e($category->name) . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$categories = $this->_repository->get();
|
||||
|
||||
return View::make('categories.index', compact('categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function show(Category $category)
|
||||
{
|
||||
$hideCategory = true; // used in list.
|
||||
$journals = $this->_repository->getTransactionJournals($category, 50);
|
||||
|
||||
return View::make('categories.show', compact('category', 'journals', 'hideCategory'));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return $this
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
|
||||
// always validate:
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
// flash messages:
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not store category: ' . $messages['errors']->first());
|
||||
return Redirect::route('categories.create')->withInput();
|
||||
}
|
||||
|
||||
// return to create screen:
|
||||
if ($data['post_submit_action'] == 'validate_only') {
|
||||
return Redirect::route('categories.create')->withInput();
|
||||
}
|
||||
|
||||
// store
|
||||
$this->_repository->store($data);
|
||||
Session::flash('success', 'Category "' . e($data['name']) . '" stored.');
|
||||
if ($data['post_submit_action'] == 'store') {
|
||||
return Redirect::route('categories.index');
|
||||
}
|
||||
|
||||
return Redirect::route('categories.create')->withInput();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Category $category
|
||||
*
|
||||
* @return $this
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(Category $category)
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
|
||||
// always validate:
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
// flash messages:
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not update category: ' . $messages['errors']->first());
|
||||
return Redirect::route('categories.edit', $category->id)->withInput();
|
||||
}
|
||||
|
||||
// return to update screen:
|
||||
if ($data['post_submit_action'] == 'validate_only') {
|
||||
return Redirect::route('categories.edit', $category->id)->withInput();
|
||||
}
|
||||
|
||||
// update
|
||||
$this->_repository->update($category, $data);
|
||||
Session::flash('success', 'Category "' . e($data['name']) . '" updated.');
|
||||
|
||||
// go back to list
|
||||
if ($data['post_submit_action'] == 'update') {
|
||||
return Redirect::route('categories.index');
|
||||
}
|
||||
|
||||
// go back to update screen.
|
||||
return Redirect::route('categories.edit', $category->id)->withInput(['post_submit_action' => 'return_to_edit']);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,199 +0,0 @@
|
||||
<?php
|
||||
use FireflyIII\Database\TransactionCurrency\TransactionCurrency as Repository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
*
|
||||
* Class CurrencyController
|
||||
*/
|
||||
class CurrencyController extends BaseController
|
||||
{
|
||||
|
||||
/** @var Repository */
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param Repository $repository
|
||||
*/
|
||||
public function __construct(Repository $repository)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
|
||||
|
||||
View::share('title', 'Currencies');
|
||||
View::share('mainTitleIcon', 'fa-usd');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$subTitleIcon = 'fa-plus';
|
||||
$subTitle = 'Create a new currency';
|
||||
|
||||
return View::make('currency.create', compact('subTitleIcon', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function defaultCurrency(TransactionCurrency $currency)
|
||||
{
|
||||
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
|
||||
$preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
|
||||
|
||||
$currencyPreference = $preferences->get('currencyPreference', 'EUR');
|
||||
$currencyPreference->data = $currency->code;
|
||||
$currencyPreference->save();
|
||||
|
||||
Session::flash('success', $currency->name.' is now the default currency.');
|
||||
Cache::forget('FFCURRENCYSYMBOL');
|
||||
Cache::forget('FFCURRENCYCODE');
|
||||
|
||||
return Redirect::route('currency.index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function delete(TransactionCurrency $currency)
|
||||
{
|
||||
if ($currency->transactionJournals()->count() > 0) {
|
||||
Session::flash('error', 'Cannot delete ' . e($currency->name) . ' because there are still transactions attached to it.');
|
||||
|
||||
return Redirect::route('currency.index');
|
||||
}
|
||||
|
||||
|
||||
return View::make('currency.delete', compact('currency'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(TransactionCurrency $currency)
|
||||
{
|
||||
Session::flash('success', 'Currency "' . e($currency->name) . '" deleted');
|
||||
|
||||
$this->_repository->destroy($currency);
|
||||
|
||||
return Redirect::route('currency.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function edit(TransactionCurrency $currency)
|
||||
{
|
||||
$subTitleIcon = 'fa-pencil';
|
||||
$subTitle = 'Edit currency "' . e($currency->name) . '"';
|
||||
$currency->symbol = htmlentities($currency->symbol);
|
||||
|
||||
return View::make('currency.edit', compact('currency', 'subTitle', 'subTitleIcon'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$currencies = $this->_repository->get();
|
||||
|
||||
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
|
||||
$preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
|
||||
|
||||
$currencyPreference = $preferences->get('currencyPreference', 'EUR');
|
||||
$defaultCurrency = $this->_repository->findByCode($currencyPreference->data);
|
||||
|
||||
|
||||
return View::make('currency.index', compact('currencies', 'defaultCurrency'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
|
||||
// always validate:
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
// flash messages:
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not store currency: ' . $messages['errors']->first());
|
||||
}
|
||||
|
||||
// return to create screen:
|
||||
if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
|
||||
return Redirect::route('currency.create')->withInput();
|
||||
}
|
||||
|
||||
// store
|
||||
$this->_repository->store($data);
|
||||
Session::flash('success', 'Currency "' . e($data['name']) . '" stored.');
|
||||
if ($data['post_submit_action'] == 'store') {
|
||||
return Redirect::route('currency.index');
|
||||
}
|
||||
|
||||
return Redirect::route('currency.create')->withInput();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(TransactionCurrency $currency)
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
|
||||
// always validate:
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
// flash messages:
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not update currency: ' . $messages['errors']->first());
|
||||
return Redirect::route('currency.edit', $currency->id)->withInput();
|
||||
}
|
||||
|
||||
// return to update screen:
|
||||
if ($data['post_submit_action'] == 'validate_only') {
|
||||
return Redirect::route('currency.edit', $currency->id)->withInput();
|
||||
}
|
||||
|
||||
// update
|
||||
$this->_repository->update($currency, $data);
|
||||
Session::flash('success', 'Currency "' . e($data['name']) . '" updated.');
|
||||
|
||||
// go back to list
|
||||
if ($data['post_submit_action'] == 'update') {
|
||||
return Redirect::route('currency.index');
|
||||
}
|
||||
|
||||
return Redirect::route('currency.edit', $currency->id)->withInput(['post_submit_action' => 'return_to_edit']);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,537 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Chart\ChartInterface;
|
||||
use Grumpydictator\Gchart\GChart as GChart;
|
||||
|
||||
/**
|
||||
* Class GoogleChartController
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
*/
|
||||
class GoogleChartController extends BaseController
|
||||
{
|
||||
|
||||
/** @var GChart */
|
||||
protected $_chart;
|
||||
/** @var Carbon */
|
||||
protected $_end;
|
||||
/** @var ChartInterface */
|
||||
protected $_repository;
|
||||
/** @var Carbon */
|
||||
protected $_start;
|
||||
|
||||
/**
|
||||
* @param GChart $chart
|
||||
* @param ChartInterface $repository
|
||||
*/
|
||||
public function __construct(GChart $chart, ChartInterface $repository)
|
||||
{
|
||||
$this->_chart = $chart;
|
||||
$this->_repository = $repository;
|
||||
$this->_start = Session::get('start', Carbon::now()->startOfMonth());
|
||||
$this->_end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param string $view
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function accountBalanceChart(Account $account, $view = 'session')
|
||||
{
|
||||
$this->_chart->addColumn('Day of month', 'date');
|
||||
$this->_chart->addColumn('Balance for ' . $account->name, 'number');
|
||||
$this->_chart->addCertainty(1);
|
||||
|
||||
$start = $this->_start;
|
||||
$end = $this->_end;
|
||||
$count = $account->transactions()->count();
|
||||
|
||||
if ($view == 'all' && $count > 0) {
|
||||
$first = $account->transactions()->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->orderBy(
|
||||
'date', 'ASC'
|
||||
)->first(['transaction_journals.date']);
|
||||
$last = $account->transactions()->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->orderBy(
|
||||
'date', 'DESC'
|
||||
)->first(['transaction_journals.date']);
|
||||
$start = new Carbon($first->date);
|
||||
$end = new Carbon($last->date);
|
||||
}
|
||||
|
||||
$current = clone $start;
|
||||
|
||||
while ($end >= $current) {
|
||||
$this->_chart->addRow(clone $current, Steam::balance($account, $current), false);
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*/
|
||||
public function allAccountsBalanceChart()
|
||||
{
|
||||
$this->_chart->addColumn('Day of the month', 'date');
|
||||
|
||||
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
|
||||
$preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
|
||||
$pref = $preferences->get('frontPageAccounts', []);
|
||||
|
||||
/** @var \FireflyIII\Database\Account\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account\Account');
|
||||
$accounts = count($pref->data) > 0 ? $acct->getByIds($pref->data) : $acct->getAccountsByType(['Default account', 'Asset account']);
|
||||
|
||||
$index = 1;
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$this->_chart->addColumn('Balance for ' . $account->name, 'number');
|
||||
$this->_chart->addCertainty($index);
|
||||
$index++;
|
||||
}
|
||||
$current = clone $this->_start;
|
||||
$current->subDay();
|
||||
$today = Carbon::now();
|
||||
while ($this->_end >= $current) {
|
||||
$row = [clone $current];
|
||||
$certain = $current < $today;
|
||||
foreach ($accounts as $account) {
|
||||
|
||||
$row[] = Steam::balance($account, $current);
|
||||
$row[] = $certain;
|
||||
}
|
||||
$this->_chart->addRowArray($row);
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $year
|
||||
*
|
||||
* @return $this|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function allBudgetsAndSpending($year)
|
||||
{
|
||||
try {
|
||||
new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
return View::make('error')->with('message', 'Invalid year.');
|
||||
}
|
||||
/** @var \FireflyIII\Database\Budget\Budget $budgetRepository */
|
||||
$budgetRepository = App::make('FireflyIII\Database\Budget\Budget');
|
||||
$budgets = $budgetRepository->get();
|
||||
$budgets->sortBy('name');
|
||||
$this->_chart->addColumn('Month', 'date');
|
||||
foreach ($budgets as $budget) {
|
||||
$this->_chart->addColumn($budget->name, 'number');
|
||||
}
|
||||
$start = Carbon::createFromDate(intval($year), 1, 1);
|
||||
$end = clone $start;
|
||||
$end->endOfYear();
|
||||
|
||||
|
||||
while ($start <= $end) {
|
||||
$row = [clone $start];
|
||||
foreach ($budgets as $budget) {
|
||||
$spent = $budgetRepository->spentInMonth($budget, $start);
|
||||
//$repetition = $budgetRepository->repetitionOnStartingOnDate($budget, $start);
|
||||
$row[] = $spent;
|
||||
}
|
||||
$this->_chart->addRowArray($row);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function allBudgetsHomeChart()
|
||||
{
|
||||
$this->_chart->addColumn('Budget', 'string');
|
||||
$this->_chart->addColumn('Budgeted', 'number');
|
||||
$this->_chart->addColumn('Spent', 'number');
|
||||
|
||||
/** @var \FireflyIII\Database\Budget\Budget $bdt */
|
||||
$bdt = App::make('FireflyIII\Database\Budget\Budget');
|
||||
$budgets = $bdt->get();
|
||||
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
|
||||
/** @var \LimitRepetition $repetition */
|
||||
$repetition = $bdt->repetitionOnStartingOnDate($budget, $this->_start);
|
||||
if (is_null($repetition)) { // use the session start and end for our search query
|
||||
$searchStart = $this->_start;
|
||||
$searchEnd = $this->_end;
|
||||
$limit = 0; // the limit is zero:
|
||||
} else {
|
||||
// use the limit's start and end for our search query
|
||||
$searchStart = $repetition->startdate;
|
||||
$searchEnd = $repetition->enddate;
|
||||
$limit = floatval($repetition->amount); // the limit is the repetitions limit:
|
||||
}
|
||||
|
||||
$expenses = floatval($budget->transactionjournals()->before($searchEnd)->after($searchStart)->lessThan(0)->sum('amount')) * -1;
|
||||
if ($expenses > 0) {
|
||||
$this->_chart->addRow($budget->name, $limit, $expenses);
|
||||
}
|
||||
}
|
||||
|
||||
$noBudgetSet = $bdt->expenseNoBudget($this->_start, $this->_end);
|
||||
$sum = $noBudgetSet->sum('amount') * -1;
|
||||
$this->_chart->addRow('No budget', 0, $sum);
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function allCategoriesHomeChart()
|
||||
{
|
||||
$this->_chart->addColumn('Category', 'string');
|
||||
$this->_chart->addColumn('Spent', 'number');
|
||||
|
||||
// query!
|
||||
$set = $this->_repository->getCategorySummary($this->_start, $this->_end);
|
||||
|
||||
foreach ($set as $entry) {
|
||||
$entry->name = strlen($entry->name) == 0 ? '(no category)' : $entry->name;
|
||||
$this->_chart->addRow($entry->name, floatval($entry->sum));
|
||||
}
|
||||
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function billOverview(Bill $bill)
|
||||
{
|
||||
|
||||
$this->_chart->addColumn('Date', 'date');
|
||||
$this->_chart->addColumn('Max amount', 'number');
|
||||
$this->_chart->addColumn('Min amount', 'number');
|
||||
$this->_chart->addColumn('Current entry', 'number');
|
||||
|
||||
// get first transaction or today for start:
|
||||
$first = $bill->transactionjournals()->orderBy('date', 'ASC')->first();
|
||||
if ($first) {
|
||||
$start = $first->date;
|
||||
} else {
|
||||
$start = new Carbon;
|
||||
}
|
||||
$end = new Carbon;
|
||||
while ($start <= $end) {
|
||||
$result = $bill->transactionjournals()->before($end)->after($start)->first();
|
||||
if ($result) {
|
||||
$amount = $result->getAmount();
|
||||
} else {
|
||||
$amount = 0;
|
||||
}
|
||||
unset($result);
|
||||
$this->_chart->addRow(clone $start, $bill->amount_max, $bill->amount_min, $amount);
|
||||
$start = DateKit::addPeriod($start, $bill->repeat_freq, 0);
|
||||
}
|
||||
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \FireflyIII\Exception\FireflyException
|
||||
*/
|
||||
public function billsOverview()
|
||||
{
|
||||
$paid = ['items' => [], 'amount' => 0];
|
||||
$unpaid = ['items' => [], 'amount' => 0];
|
||||
$this->_chart->addColumn('Name', 'string');
|
||||
$this->_chart->addColumn('Amount', 'number');
|
||||
|
||||
$set = $this->_repository->getBillsSummary($this->_start, $this->_end);
|
||||
|
||||
foreach ($set as $entry) {
|
||||
if (intval($entry->journalId) == 0) {
|
||||
$unpaid['items'][] = $entry->name;
|
||||
$unpaid['amount'] += floatval($entry->averageAmount);
|
||||
} else {
|
||||
$description = intval($entry->encrypted) == 1 ? Crypt::decrypt($entry->description) : $entry->description;
|
||||
$paid['items'][] = $description;
|
||||
$paid['amount'] += floatval($entry->actualAmount);
|
||||
}
|
||||
}
|
||||
$this->_chart->addRow('Unpaid: ' . join(', ', $unpaid['items']), $unpaid['amount']);
|
||||
$this->_chart->addRow('Paid: ' . join(', ', $paid['items']), $paid['amount']);
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param LimitRepetition $repetition
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function budgetLimitSpending(\Budget $budget, \LimitRepetition $repetition)
|
||||
{
|
||||
$start = clone $repetition->startdate;
|
||||
$end = $repetition->enddate;
|
||||
|
||||
$this->_chart->addColumn('Day', 'date');
|
||||
$this->_chart->addColumn('Left', 'number');
|
||||
|
||||
|
||||
$amount = $repetition->amount;
|
||||
|
||||
while ($start <= $end) {
|
||||
/*
|
||||
* Sum of expenses on this day:
|
||||
*/
|
||||
$sum = floatval($budget->transactionjournals()->lessThan(0)->transactionTypes(['Withdrawal'])->onDate($start)->sum('amount'));
|
||||
$amount += $sum;
|
||||
$this->_chart->addRow(clone $start, $amount);
|
||||
$start->addDay();
|
||||
}
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @param int $year
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function budgetsAndSpending(Budget $budget, $year = 0)
|
||||
{
|
||||
/** @var \FireflyIII\Database\Budget\Budget $budgetRepository */
|
||||
$budgetRepository = App::make('FireflyIII\Database\Budget\Budget');
|
||||
|
||||
$this->_chart->addColumn('Month', 'date');
|
||||
$this->_chart->addColumn('Budgeted', 'number');
|
||||
$this->_chart->addColumn('Spent', 'number');
|
||||
if ($year == 0) {
|
||||
// grab the first budgetlimit ever:
|
||||
$firstLimit = $budget->budgetlimits()->orderBy('startdate', 'ASC')->first();
|
||||
if ($firstLimit) {
|
||||
$start = new Carbon($firstLimit->startdate);
|
||||
} else {
|
||||
$start = Carbon::now()->startOfYear();
|
||||
}
|
||||
|
||||
// grab the last budget limit ever:
|
||||
$lastLimit = $budget->budgetlimits()->orderBy('startdate', 'DESC')->first();
|
||||
if ($lastLimit) {
|
||||
$end = new Carbon($lastLimit->startdate);
|
||||
} else {
|
||||
$end = Carbon::now()->endOfYear();
|
||||
}
|
||||
} else {
|
||||
$start = Carbon::createFromDate(intval($year), 1, 1);
|
||||
$end = clone $start;
|
||||
$end->endOfYear();
|
||||
}
|
||||
|
||||
while ($start <= $end) {
|
||||
$spent = $budgetRepository->spentInMonth($budget, $start);
|
||||
$repetition = $budgetRepository->repetitionOnStartingOnDate($budget, $start);
|
||||
|
||||
if ($repetition) {
|
||||
$budgeted = floatval($repetition->amount);
|
||||
\Log::debug('Found a repetition on ' . $start->format('Y-m-d') . ' for budget ' . $budget->name . '!');
|
||||
} else {
|
||||
\Log::debug('No repetition on ' . $start->format('Y-m-d') . ' for budget ' . $budget->name);
|
||||
$budgeted = null;
|
||||
}
|
||||
$this->_chart->addRow(clone $start, $budgeted, $spent);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Category $component
|
||||
* @param $year
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function categoriesAndSpending(Category $component, $year)
|
||||
{
|
||||
try {
|
||||
new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
return View::make('error')->with('message', 'Invalid year.');
|
||||
}
|
||||
|
||||
/** @var \FireflyIII\Database\Category\Category $categoryRepository */
|
||||
$categoryRepository = App::make('FireflyIII\Database\Category\Category');
|
||||
|
||||
$this->_chart->addColumn('Month', 'date');
|
||||
$this->_chart->addColumn('Budgeted', 'number');
|
||||
$this->_chart->addColumn('Spent', 'number');
|
||||
|
||||
$start = new Carbon('01-01-' . $year);
|
||||
$end = clone $start;
|
||||
$end->endOfYear();
|
||||
while ($start <= $end) {
|
||||
|
||||
$spent = $categoryRepository->spentInMonth($component, $start);
|
||||
$budgeted = null;
|
||||
|
||||
$this->_chart->addRow(clone $start, $budgeted, $spent);
|
||||
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function piggyBankHistory(\PiggyBank $piggyBank)
|
||||
{
|
||||
$this->_chart->addColumn('Date', 'date');
|
||||
$this->_chart->addColumn('Balance', 'number');
|
||||
|
||||
$set = \DB::table('piggy_bank_events')->where('piggy_bank_id', $piggyBank->id)->groupBy('date')->get(['date', DB::Raw('SUM(`amount`) AS `sum`')]);
|
||||
|
||||
foreach ($set as $entry) {
|
||||
$this->_chart->addRow(new Carbon($entry->date), floatval($entry->sum));
|
||||
}
|
||||
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $year
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function yearInExp($year)
|
||||
{
|
||||
try {
|
||||
$start = new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
return View::make('error')->with('message', 'Invalid year.');
|
||||
}
|
||||
$this->_chart->addColumn('Month', 'date');
|
||||
$this->_chart->addColumn('Income', 'number');
|
||||
$this->_chart->addColumn('Expenses', 'number');
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $repository */
|
||||
$repository = App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
|
||||
|
||||
$end = clone $start;
|
||||
$end->endOfYear();
|
||||
while ($start < $end) {
|
||||
|
||||
// total income:
|
||||
$income = $repository->getSumOfIncomesByMonth($start);
|
||||
$expense = $repository->getSumOfExpensesByMonth($start);
|
||||
|
||||
$this->_chart->addRow(clone $start, $income, $expense);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $year
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function yearInExpSum($year)
|
||||
{
|
||||
try {
|
||||
$start = new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
return View::make('error')->with('message', 'Invalid year.');
|
||||
}
|
||||
$this->_chart->addColumn('Summary', 'string');
|
||||
$this->_chart->addColumn('Income', 'number');
|
||||
$this->_chart->addColumn('Expenses', 'number');
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $repository */
|
||||
$repository = App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
|
||||
|
||||
$end = clone $start;
|
||||
$end->endOfYear();
|
||||
$income = 0;
|
||||
$expense = 0;
|
||||
$count = 0;
|
||||
while ($start < $end) {
|
||||
|
||||
// total income:
|
||||
$income += $repository->getSumOfIncomesByMonth($start);
|
||||
$expense += $repository->getSumOfExpensesByMonth($start);
|
||||
$count++;
|
||||
|
||||
$start->addMonth();
|
||||
}
|
||||
$this->_chart->addRow('Sum', $income, $expense);
|
||||
$count = $count > 0 ? $count : 1;
|
||||
$this->_chart->addRow('Average', ($income / $count), ($expense / $count));
|
||||
|
||||
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
*
|
||||
* Class HelpController
|
||||
*
|
||||
*/
|
||||
class HelpController extends BaseController
|
||||
{
|
||||
/**
|
||||
* @param $route
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show($route)
|
||||
{
|
||||
$content = [
|
||||
'text' => '<p>There is no help for this route!</p>',
|
||||
'title' => 'Help',
|
||||
];
|
||||
|
||||
if (!Route::has($route)) {
|
||||
\Log::error('No such route: ' . $route);
|
||||
|
||||
return Response::json($content);
|
||||
}
|
||||
|
||||
if ($this->_inCache($route)) {
|
||||
$content = [
|
||||
'text' => Cache::get('help.' . $route . '.text'),
|
||||
'title' => Cache::get('help.' . $route . '.title'),
|
||||
];
|
||||
|
||||
return Response::json($content);
|
||||
}
|
||||
$content = $this->_getFromGithub($route);
|
||||
|
||||
|
||||
Cache::put('help.' . $route . '.text', $content['text'], 10080); // a week.
|
||||
Cache::put('help.' . $route . '.title', $content['title'], 10080);
|
||||
|
||||
return Response::json($content);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $route
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _inCache($route)
|
||||
{
|
||||
return Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $route
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _getFromGithub($route)
|
||||
{
|
||||
$uri = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/' . e($route) . '.md';
|
||||
$content = [
|
||||
'text' => '<p>There is no help for this route!</p>',
|
||||
'title' => $route,
|
||||
];
|
||||
try {
|
||||
$content['text'] = file_get_contents($uri);
|
||||
} catch (ErrorException $e) {
|
||||
\Log::error(trim($e->getMessage()));
|
||||
}
|
||||
if (strlen(trim($content['text'])) == 0) {
|
||||
$content['text'] = '<p>There is no help for this route.</p>';
|
||||
}
|
||||
$content['text'] = \Michelf\Markdown::defaultTransform($content['text']);
|
||||
|
||||
return $content;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,101 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class HomeController
|
||||
*
|
||||
*/
|
||||
class HomeController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
Cache::flush();
|
||||
|
||||
return Redirect::route('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// count, maybe Firefly needs some introducing text to show:
|
||||
/** @var \FireflyIII\Database\Account\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account\Account');
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $journalRepository */
|
||||
$journalRepository = App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
|
||||
|
||||
/** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */
|
||||
$preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface');
|
||||
|
||||
$count = $acct->countAccountsByType(['Default account', 'Asset account']);
|
||||
|
||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
|
||||
|
||||
// get the preference for the home accounts to show:
|
||||
$frontPage = $preferences->get('frontPageAccounts', []);
|
||||
if ($frontPage->data == []) {
|
||||
$accounts = $acct->getAccountsByType(['Default account', 'Asset account']);
|
||||
} else {
|
||||
$accounts = $acct->getByIds($frontPage->data);
|
||||
}
|
||||
|
||||
$transactions = [];
|
||||
foreach ($accounts as $account) {
|
||||
$set = $journalRepository->getInDateRangeAccount($account, $start, $end, 10);
|
||||
if (count($set) > 0) {
|
||||
$transactions[] = [$set, $account];
|
||||
}
|
||||
}
|
||||
|
||||
// build the home screen:
|
||||
return View::make('index')->with('count', $count)->with('transactions', $transactions)->with('title', 'Firefly')->with('subTitle', 'What\'s playing?')
|
||||
->with('mainTitleIcon', 'fa-fire');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function rangeJump($range)
|
||||
{
|
||||
|
||||
$valid = ['1D', '1W', '1M', '3M', '6M', '1Y',];
|
||||
|
||||
/** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */
|
||||
$preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface');
|
||||
|
||||
if (in_array($range, $valid)) {
|
||||
$preferences->set('viewRange', $range);
|
||||
Session::forget('range');
|
||||
}
|
||||
return Redirect::to(URL::previous());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function sessionNext()
|
||||
{
|
||||
Navigation::next();
|
||||
return Redirect::to(URL::previous());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function sessionPrev()
|
||||
{
|
||||
Navigation::prev();
|
||||
return Redirect::to(URL::previous());
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class JsonController
|
||||
*
|
||||
*/
|
||||
class JsonController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns a list of categories.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function categories()
|
||||
{
|
||||
/** @var \FireflyIII\Database\Category\Category $categories */
|
||||
$categories = App::make('FireflyIII\Database\Category\Category');
|
||||
$list = $categories->get();
|
||||
$return = [];
|
||||
foreach ($list as $entry) {
|
||||
$return[] = $entry->name;
|
||||
}
|
||||
|
||||
return Response::json($return);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a JSON list of all beneficiaries.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function expenseAccounts()
|
||||
{
|
||||
/** @var \FireflyIII\Database\Account\Account $accounts */
|
||||
$accounts = App::make('FireflyIII\Database\Account\Account');
|
||||
$list = $accounts->getAccountsByType(['Expense account', 'Beneficiary account']);
|
||||
$return = [];
|
||||
foreach ($list as $entry) {
|
||||
$return[] = $entry->name;
|
||||
}
|
||||
|
||||
return Response::json($return);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function revenueAccounts()
|
||||
{
|
||||
/** @var \FireflyIII\Database\Account\Account $accounts */
|
||||
$accounts = App::make('FireflyIII\Database\Account\Account');
|
||||
$list = $accounts->getAccountsByType(['Revenue account']);
|
||||
$return = [];
|
||||
foreach ($list as $entry) {
|
||||
$return[] = $entry->name;
|
||||
}
|
||||
|
||||
return Response::json($return);
|
||||
|
||||
}
|
||||
}
|
@ -1,360 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\PiggyBank\PiggyBank as Repository;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
*
|
||||
*
|
||||
* Class PiggyBankController
|
||||
*
|
||||
*/
|
||||
class PiggyBankController extends BaseController
|
||||
{
|
||||
|
||||
/** @var Repository */
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param Repository $repository
|
||||
*/
|
||||
public function __construct(Repository $repository)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
View::share('title', 'Piggy banks');
|
||||
View::share('mainTitleIcon', 'fa-sort-amount-asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add money to piggy bank
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function add(PiggyBank $piggyBank)
|
||||
{
|
||||
$leftOnAccount = $this->_repository->leftOnAccount($piggyBank->account);
|
||||
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
|
||||
$leftToSave = $piggyBank->targetamount - $savedSoFar;
|
||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||
|
||||
|
||||
\Log::debug('Now going to view for piggy bank #' . $piggyBank->id . ' (' . $piggyBank->name . ')');
|
||||
|
||||
return View::make('piggy_banks.add', compact('piggyBank', 'maxAmount'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Database\Account\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account\Account');
|
||||
|
||||
$periods = Config::get('firefly.piggy_bank_periods');
|
||||
$accounts = FFForm::makeSelectList($acct->getAccountsByType(['Default account', 'Asset account']));
|
||||
$subTitle = 'Create new piggy bank';
|
||||
$subTitleIcon = 'fa-plus';
|
||||
|
||||
return View::make('piggy_banks.create', compact('accounts', 'periods', 'subTitle', 'subTitleIcon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete(PiggyBank $piggyBank)
|
||||
{
|
||||
$subTitle = 'Delete "' . e($piggyBank->name) . '"';
|
||||
|
||||
return View::make('piggy_banks.delete', compact('piggyBank', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(PiggyBank $piggyBank)
|
||||
{
|
||||
|
||||
Session::flash('success', 'Piggy bank "' . e($piggyBank->name) . '" deleted.');
|
||||
$this->_repository->destroy($piggyBank);
|
||||
|
||||
return Redirect::route('piggy_banks.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function edit(PiggyBank $piggyBank)
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Database\Account\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account\Account');
|
||||
|
||||
$periods = Config::get('firefly.piggy_bank_periods');
|
||||
$accounts = FFForm::makeSelectList($acct->getAccountsByType(['Default account', 'Asset account']));
|
||||
$subTitle = 'Edit piggy bank "' . e($piggyBank->name) . '"';
|
||||
$subTitleIcon = 'fa-pencil';
|
||||
|
||||
/*
|
||||
* Flash some data to fill the form.
|
||||
*/
|
||||
if (is_null($piggyBank->targetdate) || $piggyBank->targetdate == '') {
|
||||
$targetDate = null;
|
||||
} else {
|
||||
$targetDate = new Carbon($piggyBank->targetdate);
|
||||
$targetDate = $targetDate->format('Y-m-d');
|
||||
}
|
||||
$preFilled = ['name' => $piggyBank->name,
|
||||
'account_id' => $piggyBank->account_id,
|
||||
'targetamount' => $piggyBank->targetamount,
|
||||
'targetdate' => $targetDate,
|
||||
'reminder' => $piggyBank->reminder,
|
||||
'remind_me' => intval($piggyBank->remind_me) == 1 || !is_null($piggyBank->reminder) ? true : false
|
||||
];
|
||||
Session::flash('preFilled', $preFilled);
|
||||
|
||||
return View::make('piggy_banks.edit', compact('subTitle', 'subTitleIcon', 'piggyBank', 'accounts', 'periods', 'preFilled'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
/** @var Collection $piggyBanks */
|
||||
$piggyBanks = $this->_repository->get();
|
||||
|
||||
$accounts = [];
|
||||
/** @var PiggyBank $piggyBank */
|
||||
foreach ($piggyBanks as $piggyBank) {
|
||||
$piggyBank->savedSoFar = floatval($piggyBank->currentRelevantRep()->currentamount);
|
||||
$piggyBank->percentage = intval($piggyBank->savedSoFar / $piggyBank->targetamount * 100);
|
||||
$piggyBank->leftToSave = $piggyBank->targetamount - $piggyBank->savedSoFar;
|
||||
|
||||
/*
|
||||
* Fill account information:
|
||||
*/
|
||||
$account = $piggyBank->account;
|
||||
if (!isset($accounts[$account->id])) {
|
||||
$accounts[$account->id] = [
|
||||
'name' => $account->name,
|
||||
'balance' => Steam::balance($account),
|
||||
'leftForPiggyBanks' => $this->_repository->leftOnAccount($account),
|
||||
'sumOfSaved' => $piggyBank->savedSoFar,
|
||||
'sumOfTargets' => floatval($piggyBank->targetamount),
|
||||
'leftToSave' => $piggyBank->leftToSave
|
||||
];
|
||||
} else {
|
||||
$accounts[$account->id]['sumOfSaved'] += $piggyBank->savedSoFar;
|
||||
$accounts[$account->id]['sumOfTargets'] += floatval($piggyBank->targetamount);
|
||||
$accounts[$account->id]['leftToSave'] += $piggyBank->leftToSave;
|
||||
}
|
||||
}
|
||||
|
||||
return View::make('piggy_banks.index', compact('piggyBanks', 'accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST add money to piggy bank
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postAdd(PiggyBank $piggyBank)
|
||||
{
|
||||
$amount = round(floatval(Input::get('amount')), 2);
|
||||
|
||||
/** @var \FireflyIII\Database\PiggyBank\PiggyBank $acct */
|
||||
$piggyRepository = App::make('FireflyIII\Database\PiggyBank\PiggyBank');
|
||||
|
||||
$leftOnAccount = $piggyRepository->leftOnAccount($piggyBank->account);
|
||||
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
|
||||
$leftToSave = $piggyBank->targetamount - $savedSoFar;
|
||||
$maxAmount = round(min($leftOnAccount, $leftToSave), 2);
|
||||
|
||||
if ($amount <= $maxAmount) {
|
||||
$repetition = $piggyBank->currentRelevantRep();
|
||||
$repetition->currentamount += $amount;
|
||||
$repetition->save();
|
||||
|
||||
/*
|
||||
* Create event!
|
||||
*/
|
||||
Event::fire('piggy_bank.addMoney', [$piggyBank, $amount]); // new and used.
|
||||
|
||||
Session::flash('success', 'Added ' . Amount::format($amount, false) . ' to "' . e($piggyBank->name) . '".');
|
||||
} else {
|
||||
Session::flash('error', 'Could not add ' . Amount::format($amount, false) . ' to "' . e($piggyBank->name) . '".');
|
||||
}
|
||||
|
||||
return Redirect::route('piggy_banks.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postRemove(PiggyBank $piggyBank)
|
||||
{
|
||||
$amount = floatval(Input::get('amount'));
|
||||
|
||||
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
|
||||
|
||||
if ($amount <= $savedSoFar) {
|
||||
$repetition = $piggyBank->currentRelevantRep();
|
||||
$repetition->currentamount -= $amount;
|
||||
$repetition->save();
|
||||
|
||||
/*
|
||||
* Create event!
|
||||
*/
|
||||
Event::fire('piggy_bank.removeMoney', [$piggyBank, $amount]); // new and used.
|
||||
|
||||
Session::flash('success', 'Removed ' . Amount::format($amount, false) . ' from "' . e($piggyBank->name) . '".');
|
||||
} else {
|
||||
Session::flash('error', 'Could not remove ' . Amount::format($amount, false) . ' from "' . e($piggyBank->name) . '".');
|
||||
}
|
||||
|
||||
return Redirect::route('piggy_banks.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @SuppressWarnings("Unused")
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function remove(PiggyBank $piggyBank)
|
||||
{
|
||||
return View::make('piggy_banks.remove', compact('piggyBank'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function show(PiggyBank $piggyBank)
|
||||
{
|
||||
|
||||
$events = $piggyBank->piggyBankEvents()->orderBy('date', 'DESC')->orderBy('id', 'DESC')->get();
|
||||
|
||||
/*
|
||||
* Number of reminders:
|
||||
*/
|
||||
|
||||
$subTitle = e($piggyBank->name);
|
||||
|
||||
return View::make('piggy_banks.show', compact('piggyBank', 'events', 'subTitle'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$data = Input::all();
|
||||
$data['repeats'] = 0;
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$data['rep_every'] = 0;
|
||||
$data['reminder_skip'] = 0;
|
||||
$data['remind_me'] = intval(Input::get('remind_me'));
|
||||
$data['order'] = 0;
|
||||
|
||||
|
||||
// always validate:
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
// flash messages:
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not store piggy bank: ' . $messages['errors']->first());
|
||||
return Redirect::route('piggy_banks.create')->withInput();
|
||||
}
|
||||
|
||||
|
||||
// return to create screen:
|
||||
if ($data['post_submit_action'] == 'validate_only') {
|
||||
return Redirect::route('piggy_banks.create')->withInput();
|
||||
}
|
||||
|
||||
// store
|
||||
$piggyBank = $this->_repository->store($data);
|
||||
Event::fire('piggy_bank.store', [$piggyBank]); // new and used.
|
||||
Session::flash('success', 'Piggy bank "' . e($data['name']) . '" stored.');
|
||||
if ($data['post_submit_action'] == 'store') {
|
||||
return Redirect::route('piggy_banks.index');
|
||||
}
|
||||
|
||||
return Redirect::route('piggy_banks.create')->withInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @return $this
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(PiggyBank $piggyBank)
|
||||
{
|
||||
|
||||
$data = Input::except('_token');
|
||||
$data['rep_every'] = 0;
|
||||
$data['reminder_skip'] = 0;
|
||||
$data['order'] = 0;
|
||||
$data['remind_me'] = isset($data['remind_me']) ? 1 : 0;
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$data['repeats'] = 0;
|
||||
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not update piggy bank: ' . $messages['errors']->first());
|
||||
return Redirect::route('piggy_banks.edit', $piggyBank->id)->withInput();
|
||||
}
|
||||
|
||||
// return to update screen:
|
||||
if ($data['post_submit_action'] == 'validate_only') {
|
||||
return Redirect::route('piggy_banks.edit', $piggyBank->id)->withInput();
|
||||
}
|
||||
|
||||
// update
|
||||
$this->_repository->update($piggyBank, $data);
|
||||
Session::flash('success', 'Piggy bank "' . e($data['name']) . '" updated.');
|
||||
|
||||
// go back to list
|
||||
if ($data['post_submit_action'] == 'update') {
|
||||
return Redirect::route('piggy_banks.index');
|
||||
}
|
||||
|
||||
// go back to update screen.
|
||||
return Redirect::route('piggy_banks.edit', $piggyBank->id)->withInput(['post_submit_action' => 'return_to_edit']);
|
||||
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class PreferencesController
|
||||
*
|
||||
*
|
||||
*/
|
||||
class PreferencesController extends BaseController
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
View::share('title', 'Preferences');
|
||||
View::share('mainTitleIcon', 'fa-gear');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
/** @var \FireflyIII\Database\Account\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account\Account');
|
||||
|
||||
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
|
||||
$preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
|
||||
|
||||
$accounts = $acct->getAccountsByType(['Default account', 'Asset account']);
|
||||
$viewRange = $preferences->get('viewRange', '1M');
|
||||
$viewRangeValue = $viewRange->data;
|
||||
$frontPage = $preferences->get('frontPageAccounts', []);
|
||||
$budgetMax = $preferences->get('budgetMaximum', 1000);
|
||||
$budgetMaximum = $budgetMax->data;
|
||||
|
||||
return View::make('preferences.index', compact('budgetMaximum'))->with('accounts', $accounts)->with('frontPageAccounts', $frontPage)->with(
|
||||
'viewRange', $viewRangeValue
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postIndex()
|
||||
{
|
||||
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
|
||||
$preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
|
||||
|
||||
// front page accounts
|
||||
$frontPageAccounts = [];
|
||||
foreach (Input::get('frontPageAccounts') as $id) {
|
||||
$frontPageAccounts[] = intval($id);
|
||||
}
|
||||
$preferences->set('frontPageAccounts', $frontPageAccounts);
|
||||
|
||||
// view range:
|
||||
$preferences->set('viewRange', Input::get('viewRange'));
|
||||
// forget session values:
|
||||
Session::forget('start');
|
||||
Session::forget('end');
|
||||
Session::forget('range');
|
||||
|
||||
// budget maximum:
|
||||
$budgetMaximum = intval(Input::get('budgetMaximum'));
|
||||
$preferences->set('budgetMaximum', $budgetMaximum);
|
||||
|
||||
|
||||
Session::flash('success', 'Preferences saved!');
|
||||
|
||||
return Redirect::route('preferences');
|
||||
}
|
||||
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
* Class ProfileController
|
||||
*/
|
||||
class ProfileController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function changePassword()
|
||||
{
|
||||
return View::make('profile.change-password')->with('title', Auth::user()->email)->with('subTitle', 'Change your password')->with(
|
||||
'mainTitleIcon', 'fa-user'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return View::make('profile.index')->with('title', 'Profile')->with('subTitle', Auth::user()->email)->with('mainTitleIcon', 'fa-user');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function postChangePassword()
|
||||
{
|
||||
|
||||
// old, new1, new2
|
||||
if (!Hash::check(Input::get('old'), Auth::user()->password)) {
|
||||
Session::flash('error', 'Invalid current password!');
|
||||
|
||||
return View::make('profile.change-password');
|
||||
}
|
||||
$result = $this->_validatePassword(Input::get('old'), Input::get('new1'), Input::get('new2'));
|
||||
if (!($result === true)) {
|
||||
Session::flash('error', $result);
|
||||
|
||||
return View::make('profile.change-password');
|
||||
}
|
||||
|
||||
// update the user with the new password.
|
||||
/** @var \FireflyIII\Database\User\User $repository */
|
||||
$repository = \App::make('FireflyIII\Database\User\User');
|
||||
$repository->updatePassword(Auth::user(), Input::get('new1'));
|
||||
|
||||
Session::flash('success', 'Password changed!');
|
||||
|
||||
return Redirect::route('profile');
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @param string $old
|
||||
* @param string $new1
|
||||
* @param string $new2
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function _validatePassword($old, $new1, $new2)
|
||||
{
|
||||
if (strlen($new1) == 0 || strlen($new2) == 0) {
|
||||
return 'Do fill in a password!';
|
||||
|
||||
}
|
||||
if ($new1 == $old) {
|
||||
return 'The idea is to change your password.';
|
||||
}
|
||||
|
||||
if ($new1 !== $new2) {
|
||||
return 'New passwords do not match!';
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
<?php
|
||||
use FireflyIII\Helper\Related\RelatedInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
*
|
||||
* Class RelatedController
|
||||
*/
|
||||
class RelatedController extends BaseController
|
||||
{
|
||||
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param RelatedInterface $repository
|
||||
*/
|
||||
public function __construct(RelatedInterface $repository)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function alreadyRelated(TransactionJournal $journal)
|
||||
{
|
||||
$ids = [];
|
||||
/** @var TransactionGroup $group */
|
||||
foreach ($journal->transactiongroups()->get() as $group) {
|
||||
/** @var TransactionJournal $loopJournal */
|
||||
foreach ($group->transactionjournals()->get() as $loopJournal) {
|
||||
if ($loopJournal->id != $journal->id) {
|
||||
$ids[] = $loopJournal->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
$unique = array_unique($ids);
|
||||
if (count($unique) > 0) {
|
||||
|
||||
$set = $this->_repository->getJournalsByIds($unique);
|
||||
$set->each(
|
||||
function (TransactionJournal $journal) {
|
||||
$journal->amount = Amount::format($journal->getAmount());
|
||||
}
|
||||
);
|
||||
|
||||
return Response::json($set->toArray());
|
||||
} else {
|
||||
return Response::json((new Collection)->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $parentJournal
|
||||
* @param TransactionJournal $childJournal
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function relate(TransactionJournal $parentJournal, TransactionJournal $childJournal)
|
||||
{
|
||||
$group = new TransactionGroup;
|
||||
$group->relation = 'balance';
|
||||
$group->user_id = $this->_repository->getUser()->id;
|
||||
$group->save();
|
||||
$group->transactionjournals()->save($parentJournal);
|
||||
$group->transactionjournals()->save($childJournal);
|
||||
|
||||
return Response::json(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function related(TransactionJournal $journal)
|
||||
{
|
||||
$groups = $journal->transactiongroups()->get();
|
||||
$members = new Collection;
|
||||
/** @var TransactionGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
/** @var TransactionJournal $loopJournal */
|
||||
foreach ($group->transactionjournals()->get() as $loopJournal) {
|
||||
if ($loopJournal->id != $journal->id) {
|
||||
$members->push($loopJournal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return View::make('related.relate', compact('journal', 'members'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @param TransactionJournal $parentJournal
|
||||
* @param TransactionJournal $childJournal
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function removeRelation(TransactionJournal $parentJournal, TransactionJournal $childJournal)
|
||||
{
|
||||
$groups = $parentJournal->transactiongroups()->get();
|
||||
/** @var TransactionGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
foreach ($group->transactionjournals()->get() as $loopJournal) {
|
||||
if ($loopJournal->id == $childJournal->id) {
|
||||
// remove from group:
|
||||
$group->transactionjournals()->detach($childJournal);
|
||||
}
|
||||
}
|
||||
if ($group->transactionjournals()->count() == 1) {
|
||||
$group->delete();
|
||||
}
|
||||
}
|
||||
|
||||
return Response::json(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function search(TransactionJournal $journal)
|
||||
{
|
||||
|
||||
$search = e(trim(Input::get('searchValue')));
|
||||
|
||||
$result = $this->_repository->search($search, $journal);
|
||||
$result->each(
|
||||
function (TransactionJournal $j) {
|
||||
$j->amount = Amount::format($j->getAmount());
|
||||
}
|
||||
);
|
||||
|
||||
return Response::json($result->toArray());
|
||||
}
|
||||
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
<?php
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
* Class ReminderController
|
||||
*
|
||||
*/
|
||||
class ReminderController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
View::share('title', 'Reminders');
|
||||
View::share('mainTitleIcon', 'fa-lightbulb-o');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Reminder $reminder
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function act(Reminder $reminder)
|
||||
{
|
||||
|
||||
$class = get_class($reminder->remindersable);
|
||||
|
||||
if ($class == 'PiggyBank') {
|
||||
$amount = Reminders::amountForReminder($reminder);
|
||||
$preFilled = [
|
||||
'amount' => round($amount, 2),
|
||||
'description' => 'Money for ' . $reminder->remindersable->name,
|
||||
'piggy_bank_id' => $reminder->remindersable_id,
|
||||
'account_to_id' => $reminder->remindersable->account_id
|
||||
];
|
||||
Session::flash('preFilled', $preFilled);
|
||||
|
||||
return Redirect::route('transactions.create', 'transfer');
|
||||
}
|
||||
|
||||
return View::make('error')->with('message', 'This reminder has an invalid class connected to it.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Reminder $reminder
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function dismiss(Reminder $reminder)
|
||||
{
|
||||
$reminder->active = 0;
|
||||
$reminder->save();
|
||||
Session::flash('success', 'Reminder dismissed');
|
||||
|
||||
return Redirect::route('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Reminder $reminder
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function notNow(Reminder $reminder)
|
||||
{
|
||||
$reminder->active = 0;
|
||||
$reminder->notnow = 1;
|
||||
$reminder->save();
|
||||
Session::flash('success', 'Reminder dismissed');
|
||||
|
||||
return Redirect::route('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Reminder $reminder
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show(Reminder $reminder)
|
||||
{
|
||||
|
||||
$amount = null;
|
||||
if (get_class($reminder->remindersable) == 'PiggyBank') {
|
||||
|
||||
$amount = Reminders::amountForReminder($reminder);
|
||||
}
|
||||
|
||||
return View::make('reminders.show', compact('reminder', 'amount'));
|
||||
}
|
||||
|
||||
}
|
@ -1,227 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\PiggyBank\RepeatedExpense as Repository;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
*
|
||||
* Class RepeatedExpenseController
|
||||
*/
|
||||
class RepeatedExpenseController extends BaseController
|
||||
{
|
||||
/** @var Repository */
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param Repository $repository
|
||||
*/
|
||||
public function __construct(Repository $repository)
|
||||
{
|
||||
View::share('title', 'Repeated expenses');
|
||||
View::share('mainTitleIcon', 'fa-rotate-left');
|
||||
$this->_repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
/** @var \FireflyIII\Database\Account\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account\Account');
|
||||
$periods = Config::get('firefly.piggy_bank_periods');
|
||||
$accounts = FFForm::makeSelectList($acct->getAccountsByType(['Default account', 'Asset account']));
|
||||
|
||||
return View::make('repeatedExpense.create', compact('accounts', 'periods'))->with('subTitle', 'Create new repeated expense')->with(
|
||||
'subTitleIcon', 'fa-plus'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $repeatedExpense
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete(PiggyBank $repeatedExpense)
|
||||
{
|
||||
$subTitle = 'Delete "' . e($repeatedExpense->name) . '"';
|
||||
|
||||
return View::make('repeatedExpense.delete', compact('repeatedExpense', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $repeatedExpense
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(PiggyBank $repeatedExpense)
|
||||
{
|
||||
|
||||
Session::flash('success', 'Repeated expense "' . e($repeatedExpense->name) . '" deleted.');
|
||||
$this->_repository->destroy($repeatedExpense);
|
||||
|
||||
return Redirect::route('repeated.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $repeatedExpense
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function edit(PiggyBank $repeatedExpense)
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Database\Account\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account\Account');
|
||||
|
||||
$periods = Config::get('firefly.piggy_bank_periods');
|
||||
$accounts = FFForm::makeSelectList($acct->getAccountsByType(['Default account', 'Asset account']));
|
||||
$subTitle = 'Edit repeated expense "' . e($repeatedExpense->name) . '"';
|
||||
$subTitleIcon = 'fa-pencil';
|
||||
|
||||
/*
|
||||
* Flash some data to fill the form.
|
||||
*/
|
||||
$preFilled = ['name' => $repeatedExpense->name,
|
||||
'account_id' => $repeatedExpense->account_id,
|
||||
'targetamount' => $repeatedExpense->targetamount,
|
||||
'targetdate' => $repeatedExpense->targetdate->format('Y-m-d'),
|
||||
'reminder' => $repeatedExpense->reminder,
|
||||
'remind_me' => intval($repeatedExpense->remind_me) == 1 || !is_null($repeatedExpense->reminder) ? true : false
|
||||
];
|
||||
Session::flash('preFilled', $preFilled);
|
||||
|
||||
return View::make('repeatedExpense.edit', compact('subTitle', 'subTitleIcon', 'repeatedExpense', 'accounts', 'periods', 'preFilled'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
$subTitle = 'Overview';
|
||||
|
||||
$expenses = $this->_repository->get();
|
||||
$expenses->each(
|
||||
function (PiggyBank $piggyBank) {
|
||||
$piggyBank->currentRelevantRep();
|
||||
}
|
||||
);
|
||||
|
||||
return View::make('repeatedExpense.index', compact('expenses', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $repeatedExpense
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show(PiggyBank $repeatedExpense)
|
||||
{
|
||||
$subTitle = $repeatedExpense->name;
|
||||
$today = Carbon::now();
|
||||
$repetitions = $repeatedExpense->piggyBankRepetitions()->get();
|
||||
|
||||
$repetitions->each(
|
||||
function (PiggyBankRepetition $repetition) {
|
||||
$repetition->bars = $this->_repository->calculateParts($repetition);
|
||||
}
|
||||
);
|
||||
|
||||
return View::make('repeatedExpense.show', compact('repetitions', 'repeatedExpense', 'today', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$data = Input::all();
|
||||
$data['repeats'] = 1;
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$targetDate = new Carbon($data['targetdate']);
|
||||
$startDate = \DateKit::subtractPeriod($targetDate, $data['rep_length']);
|
||||
$data['startdate'] = $startDate->format('Y-m-d');
|
||||
$data['targetdate'] = $targetDate->format('Y-m-d');
|
||||
$data['reminder_skip'] = 0;
|
||||
$data['remind_me'] = isset($data['remind_me']) ? 1 : 0;
|
||||
$data['order'] = 0;
|
||||
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not store repeated expense: ' . $messages['errors']->first());
|
||||
return Redirect::route('repeated.create')->withInput();
|
||||
}
|
||||
|
||||
|
||||
// return to create screen:
|
||||
if ($data['post_submit_action'] == 'validate_only') {
|
||||
return Redirect::route('repeated.create')->withInput();
|
||||
}
|
||||
|
||||
// store
|
||||
$piggyBank = $this->_repository->store($data);
|
||||
Event::fire('piggy_bank.store', [$piggyBank]); // new and used.
|
||||
Session::flash('success', 'Piggy bank "' . e($data['name']) . '" stored.');
|
||||
if ($data['post_submit_action'] == 'store') {
|
||||
return Redirect::route('repeated.index');
|
||||
}
|
||||
|
||||
return Redirect::route('repeated.create')->withInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @param PiggyBank $repeatedExpense
|
||||
*
|
||||
* @return $this
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(PiggyBank $repeatedExpense)
|
||||
{
|
||||
|
||||
$data = Input::except('_token');
|
||||
$data['rep_every'] = 0;
|
||||
$data['reminder_skip'] = 0;
|
||||
$data['order'] = 0;
|
||||
$data['repeats'] = 1;
|
||||
$data['remind_me'] = isset($data['remind_me']) ? 1 : 0;
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not update repeated expense: ' . $messages['errors']->first());
|
||||
return Redirect::route('repeated.edit', $repeatedExpense->id)->withInput();
|
||||
}
|
||||
|
||||
// return to update screen:
|
||||
if ($data['post_submit_action'] == 'validate_only') {
|
||||
return Redirect::route('repeated.edit', $repeatedExpense->id)->withInput();
|
||||
}
|
||||
|
||||
// update
|
||||
$this->_repository->update($repeatedExpense, $data);
|
||||
Session::flash('success', 'Repeated expense "' . e($data['name']) . '" updated.');
|
||||
|
||||
// go back to list
|
||||
if ($data['post_submit_action'] == 'update') {
|
||||
return Redirect::route('repeated.index');
|
||||
}
|
||||
|
||||
// go back to update screen.
|
||||
return Redirect::route('repeated.edit', $repeatedExpense->id)->withInput(['post_submit_action' => 'return_to_edit']);
|
||||
|
||||
}
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\TransactionJournal\TransactionJournal as TransactionJournalRepository;
|
||||
use FireflyIII\Report\ReportInterface as Report;
|
||||
|
||||
/**
|
||||
*
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
*
|
||||
* Class ReportController
|
||||
*/
|
||||
class ReportController extends BaseController
|
||||
{
|
||||
/** @var \FireflyIII\Database\Budget\Budget */
|
||||
protected $_budgets;
|
||||
/** @var TransactionJournalRepository */
|
||||
protected $_journals;
|
||||
/** @var Report */
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param TransactionJournalRepository $journals
|
||||
* @param Report $repository
|
||||
*/
|
||||
public function __construct(TransactionJournalRepository $journals, Report $repository)
|
||||
{
|
||||
$this->_journals = $journals;
|
||||
$this->_repository = $repository;
|
||||
/** @var \FireflyIII\Database\Budget\Budget _budgets */
|
||||
$this->_budgets = App::make('FireflyIII\Database\Budget\Budget');
|
||||
|
||||
|
||||
View::share('title', 'Reports');
|
||||
View::share('mainTitleIcon', 'fa-line-chart');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $month
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function budget($year = '2014', $month = '1')
|
||||
{
|
||||
try {
|
||||
new Carbon($year . '-' . $month . '-01');
|
||||
} catch (Exception $e) {
|
||||
return View::make('error')->with('message', 'Invalid date');
|
||||
}
|
||||
$date = new Carbon($year . '-' . $month . '-01');
|
||||
$dayEarly = clone $date;
|
||||
$subTitle = 'Budget report for ' . $date->format('F Y');
|
||||
$subTitleIcon = 'fa-calendar';
|
||||
$dayEarly = $dayEarly->subDay();
|
||||
$accounts = $this->_repository->getAccountListBudgetOverview($date);
|
||||
$budgets = $this->_repository->getBudgetsForMonth($date);
|
||||
|
||||
return View::make('reports.budget', compact('subTitle', 'subTitleIcon', 'date', 'accounts', 'budgets', 'dayEarly'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$start = $this->_journals->firstDate();
|
||||
$months = $this->_repository->listOfMonths(clone $start);
|
||||
$years = $this->_repository->listOfYears(clone $start);
|
||||
$title = 'Reports';
|
||||
$mainTitleIcon = 'fa-line-chart';
|
||||
|
||||
return View::make('reports.index', compact('years', 'months', 'title', 'mainTitleIcon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $month
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function month($year = '2014', $month = '1')
|
||||
{
|
||||
try {
|
||||
new Carbon($year . '-' . $month . '-01');
|
||||
} catch (Exception $e) {
|
||||
return View::make('error')->with('message', 'Invalid date.');
|
||||
}
|
||||
$date = new Carbon($year . '-' . $month . '-01');
|
||||
$subTitle = 'Report for ' . $date->format('F Y');
|
||||
$subTitleIcon = 'fa-calendar';
|
||||
$displaySum = true; // to show sums in report.
|
||||
$income = $this->_repository->getIncomeForMonth($date);
|
||||
$expenses = $this->_repository->getExpenseGroupedForMonth($date, 10);
|
||||
$budgets = $this->_repository->getBudgetsForMonth($date);
|
||||
$categories = $this->_repository->getCategoriesForMonth($date, 10);
|
||||
$accounts = $this->_repository->getAccountsForMonth($date);
|
||||
|
||||
return View::make(
|
||||
'reports.month',
|
||||
compact('date', 'accounts', 'categories', 'budgets', 'expenses', 'subTitle', 'displaySum', 'subTitleIcon', 'income')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $year
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function year($year)
|
||||
{
|
||||
try {
|
||||
new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
return View::make('error')->with('message', 'Invalid date.');
|
||||
}
|
||||
$date = new Carbon('01-01-' . $year);
|
||||
$end = clone $date;
|
||||
$end->endOfYear();
|
||||
$title = 'Reports';
|
||||
$subTitle = $year;
|
||||
$subTitleIcon = 'fa-bar-chart';
|
||||
$mainTitleIcon = 'fa-line-chart';
|
||||
|
||||
$balances = $this->_repository->yearBalanceReport($date);
|
||||
$groupedIncomes = $this->_repository->revenueGroupedByAccount($date, $end);
|
||||
$groupedExpenses = $this->_repository->expensesGroupedByAccount($date, $end, 15);
|
||||
|
||||
return View::make(
|
||||
'reports.year',
|
||||
compact('date', 'groupedIncomes', 'groupedExpenses', 'year', 'balances', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class SearchController
|
||||
*/
|
||||
class SearchController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Results always come in the form of an array [results, count, fullCount]
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Search\Search $searcher */
|
||||
$searcher = App::make('FireflyIII\Search\Search');
|
||||
|
||||
$subTitle = null;
|
||||
$rawQuery = null;
|
||||
$result = [];
|
||||
if (!is_null(Input::get('q')) && strlen(Input::get('q')) > 0) {
|
||||
$rawQuery = trim(Input::get('q'));
|
||||
$words = explode(' ', $rawQuery);
|
||||
$subTitle = 'Results for "' . e($rawQuery) . '"';
|
||||
|
||||
$transactions = $searcher->searchTransactions($words);
|
||||
$accounts = $searcher->searchAccounts($words);
|
||||
$categories = $searcher->searchCategories($words);
|
||||
$budgets = $searcher->searchBudgets($words);
|
||||
$tags = $searcher->searchTags($words);
|
||||
$result = ['transactions' => $transactions, 'accounts' => $accounts, 'categories' => $categories, 'budgets' => $budgets, 'tags' => $tags];
|
||||
|
||||
}
|
||||
|
||||
return View::make('search.index')->with('title', 'Search')->with('subTitle', $subTitle)->with(
|
||||
'mainTitleIcon', 'fa-search'
|
||||
)->with('query', $rawQuery)->with('result', $result);
|
||||
}
|
||||
}
|
@ -1,328 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
use FireflyIII\Database\TransactionJournal\TransactionJournal as Repository;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
use FireflyIII\Helper\TransactionJournal\HelperInterface as Helper;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
*
|
||||
* Class TransactionController
|
||||
*
|
||||
*/
|
||||
class TransactionController extends BaseController
|
||||
{
|
||||
|
||||
|
||||
/** @var Helper */
|
||||
protected $_helper;
|
||||
/** @var Repository */
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* Construct a new transaction controller with two of the most often used helpers.
|
||||
*
|
||||
* @param Repository $repository
|
||||
* @param Helper $helper
|
||||
*/
|
||||
public function __construct(Repository $repository, Helper $helper)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
$this->_helper = $helper;
|
||||
View::share('title', 'Transactions');
|
||||
View::share('mainTitleIcon', 'fa-repeat');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows the view helping the user to create a new transaction journal.
|
||||
*
|
||||
* @param string $what
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create($what = 'deposit')
|
||||
{
|
||||
$accounts = FFForm::makeSelectList($this->_helper->getAssetAccounts());
|
||||
$budgets = FFForm::makeSelectList($this->_helper->getBudgets());
|
||||
$budgets[0] = '(no budget)';
|
||||
$piggyBanks = $this->_helper->getPiggyBanks();
|
||||
$repeatedExpenses = $this->_helper->getRepeatedExpenses();
|
||||
$list = $piggyBanks->merge($repeatedExpenses);
|
||||
$piggies = FFForm::makeSelectList($list);
|
||||
$piggies[0] = '(no piggy bank)';
|
||||
$preFilled = Session::has('preFilled') ? Session::get('preFilled') : [];
|
||||
$respondTo = ['account_id', 'account_from_id'];
|
||||
$subTitle = 'Add a new ' . e($what);
|
||||
|
||||
foreach ($respondTo as $r) {
|
||||
if (!is_null(Input::get($r))) {
|
||||
$preFilled[$r] = Input::get($r);
|
||||
}
|
||||
}
|
||||
Session::put('preFilled', $preFilled);
|
||||
|
||||
asort($piggies);
|
||||
|
||||
|
||||
return View::make('transactions.create', compact('accounts', 'budgets', 'what', 'piggies', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the form that allows a user to delete a transaction journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete(TransactionJournal $journal)
|
||||
{
|
||||
$type = strtolower($journal->transactionType->type);
|
||||
$subTitle = 'Delete ' . e($type) . ' "' . e($journal->description) . '"';
|
||||
|
||||
return View::make('transactions.delete', compact('journal', 'subTitle'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $transactionJournal
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(TransactionJournal $transactionJournal)
|
||||
{
|
||||
$type = $transactionJournal->transactionType->type;
|
||||
$return = 'withdrawal';
|
||||
|
||||
Session::flash('success', 'Transaction "' . e($transactionJournal->description) . '" destroyed.');
|
||||
|
||||
$this->_repository->destroy($transactionJournal);
|
||||
|
||||
switch ($type) {
|
||||
case 'Deposit':
|
||||
$return = 'deposit';
|
||||
break;
|
||||
case 'Transfer':
|
||||
$return = 'transfers';
|
||||
break;
|
||||
}
|
||||
|
||||
return Redirect::route('transactions.index', $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the view to edit a transaction.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function edit(TransactionJournal $journal)
|
||||
{
|
||||
$what = strtolower($journal->transactiontype->type);
|
||||
$subTitle = 'Edit ' . e($what) . ' "' . e($journal->description) . '"';
|
||||
$budgets = FFForm::makeSelectList($this->_helper->getBudgets(), true);
|
||||
$accounts = FFForm::makeSelectList($this->_helper->getAssetAccounts());
|
||||
$piggies = FFForm::makeSelectList($this->_helper->getPiggyBanks(), true);
|
||||
$transactions = $journal->transactions()->orderBy('amount', 'DESC')->get();
|
||||
$preFilled = [
|
||||
'date' => $journal->date->format('Y-m-d'),
|
||||
'category' => '',
|
||||
'budget_id' => 0,
|
||||
'piggy_bank_id' => 0
|
||||
];
|
||||
|
||||
$category = $journal->categories()->first();
|
||||
if (!is_null($category)) {
|
||||
$preFilled['category'] = $category->name;
|
||||
}
|
||||
|
||||
$budget = $journal->budgets()->first();
|
||||
if (!is_null($budget)) {
|
||||
$preFilled['budget_id'] = $budget->id;
|
||||
}
|
||||
|
||||
if ($journal->piggyBankEvents()->count() > 0) {
|
||||
$preFilled['piggy_bank_id'] = $journal->piggyBankEvents()->first()->piggy_bank_id;
|
||||
}
|
||||
|
||||
$preFilled['amount'] = $journal->getAmount();
|
||||
$preFilled['account_id'] = $this->_helper->getAssetAccount($what, $transactions);
|
||||
$preFilled['expense_account'] = $transactions[0]->account->name;
|
||||
$preFilled['revenue_account'] = $transactions[1]->account->name;
|
||||
$preFilled['account_from_id'] = $transactions[1]->account->id;
|
||||
$preFilled['account_to_id'] = $transactions[0]->account->id;
|
||||
|
||||
|
||||
return View::make('transactions.edit', compact('journal', 'accounts', 'what', 'budgets', 'piggies', 'subTitle'))->with('data', $preFilled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's 7. More than 5 but alright.
|
||||
*
|
||||
* @param $what
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function index($what)
|
||||
{
|
||||
switch ($what) {
|
||||
case 'expenses':
|
||||
case 'withdrawal':
|
||||
$subTitleIcon = 'fa-long-arrow-left';
|
||||
$subTitle = 'Expenses';
|
||||
$journals = $this->_repository->getWithdrawalsPaginated(50);
|
||||
break;
|
||||
case 'revenue':
|
||||
case 'deposit':
|
||||
$subTitleIcon = 'fa-long-arrow-right';
|
||||
$subTitle = 'Revenue, income and deposits';
|
||||
$journals = $this->_repository->getDepositsPaginated(50);
|
||||
break;
|
||||
case 'transfer':
|
||||
case 'transfers':
|
||||
$subTitleIcon = 'fa-arrows-h';
|
||||
$subTitle = 'Transfers';
|
||||
$journals = $this->_repository->getTransfersPaginated(50);
|
||||
break;
|
||||
}
|
||||
|
||||
return View::make('transactions.index', compact('subTitle', 'what', 'subTitleIcon', 'journals'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function show(TransactionJournal $journal)
|
||||
{
|
||||
$journal->transactions->each(
|
||||
function (\Transaction $t) use ($journal) {
|
||||
$t->before = floatval(
|
||||
$t->account->transactions()->leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||
)->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d'))->where(
|
||||
'transaction_journals.created_at', '<=', $journal->created_at->format('Y-m-d H:i:s')
|
||||
)->where('transaction_journals.id', '!=', $journal->id)->sum('transactions.amount')
|
||||
);
|
||||
$t->after = $t->before + $t->amount;
|
||||
}
|
||||
);
|
||||
$members = new Collection;
|
||||
/** @var TransactionGroup $group */
|
||||
foreach ($journal->transactiongroups()->get() as $group) {
|
||||
/** @var TransactionJournal $loopJournal */
|
||||
foreach ($group->transactionjournals()->get() as $loopJournal) {
|
||||
if ($loopJournal->id != $journal->id) {
|
||||
$members->push($loopJournal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return View::make('transactions.show', compact('journal', 'members'))->with(
|
||||
'subTitle', e($journal->transactionType->type) . ' "' . e($journal->description) . '"'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @param $what
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store($what)
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
$transactionType = $this->_repository->getJournalType($what);
|
||||
$transactionCurrency = $this->_repository->getJournalCurrencyById(intval($data['amount_currency_id']));
|
||||
$data['transaction_type_id'] = $transactionType->id;
|
||||
$data['transaction_currency_id'] = $transactionCurrency->id;
|
||||
$data['completed'] = 0;
|
||||
$data['what'] = $what;
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not store transaction: ' . $messages['errors']->first());
|
||||
|
||||
return Redirect::route('transactions.create', $data['what'])->withInput();
|
||||
}
|
||||
|
||||
if ($data['post_submit_action'] == 'validate_only') {
|
||||
return Redirect::route('transactions.create', $data['what'])->withInput();
|
||||
}
|
||||
|
||||
$journal = $this->_repository->store($data);
|
||||
Event::fire('transactionJournal.store', [$journal, Input::get('piggy_bank_id')]); // new and used.
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
Event::fire('transaction.store', [$transaction]);
|
||||
}
|
||||
|
||||
Session::flash('success', 'Transaction "' . e($data['description']) . '" stored.');
|
||||
if ($data['post_submit_action'] == 'store') {
|
||||
return Redirect::route('transactions.index', $data['what']);
|
||||
}
|
||||
|
||||
return Redirect::route('transactions.create', $data['what'])->withInput();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @return $this
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(TransactionJournal $journal)
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
$data['what'] = strtolower($journal->transactionType->type);
|
||||
$data['transaction_type_id'] = $journal->transaction_type_id;
|
||||
$data['transaction_currency_id'] = intval($data['amount_currency_id']);
|
||||
$data['completed'] = 1;
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('errors', $messages['errors']);
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('error', 'Could not update transaction: ' . $messages['errors']->first());
|
||||
|
||||
return Redirect::route('transactions.edit', $journal->id)->withInput();
|
||||
}
|
||||
if ($data['post_submit_action'] == 'validate_only') {
|
||||
return Redirect::route('transactions.edit', $journal->id)->withInput();
|
||||
}
|
||||
$this->_repository->update($journal, $data);
|
||||
Session::flash('success', 'Transaction "' . e($data['description']) . '" updated.');
|
||||
Event::fire('transactionJournal.update', [$journal]); // new and used.
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions()->get() as $transaction) {
|
||||
Event::fire('transaction.update', [$transaction]);
|
||||
}
|
||||
if ($data['post_submit_action'] == 'update') {
|
||||
return Redirect::route('transactions.index', $data['what']);
|
||||
}
|
||||
|
||||
// go back to update screen.
|
||||
return Redirect::route('transactions.edit', $journal->id)->withInput(['post_submit_action' => 'return_to_edit']);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,176 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class UserController
|
||||
*/
|
||||
class UserController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the login view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
return View::make('user.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout user.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
Auth::logout();
|
||||
Session::flush();
|
||||
|
||||
return Redirect::route('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Login.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function postLogin()
|
||||
{
|
||||
$rememberMe = Input::get('remember_me') == '1';
|
||||
$data = ['email' => Input::get('email'), 'password' => Input::get('password')];
|
||||
$result = Auth::attempt($data, $rememberMe);
|
||||
if ($result) {
|
||||
return Redirect::route('index');
|
||||
}
|
||||
|
||||
Session::flash('error', 'No good!');
|
||||
|
||||
return View::make('user.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* If allowed, register the user.
|
||||
*
|
||||
* Then:
|
||||
*
|
||||
* - Send password OR
|
||||
* - Send reset code.
|
||||
*
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
public function postRegister()
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Database\User\User $repository */
|
||||
$repository = App::make('FireflyIII\Database\User\User');
|
||||
|
||||
/** @var \FireflyIII\Shared\Mail\RegistrationInterface $email */
|
||||
$email = App::make('FireflyIII\Shared\Mail\RegistrationInterface');
|
||||
|
||||
$user = $repository->register(Input::all());
|
||||
|
||||
if ($user) {
|
||||
$result = $email->sendVerificationMail($user);
|
||||
if ($result === false && Config::get('mail.pretend') === false) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$user->delete();
|
||||
|
||||
return View::make('error')->with('message', 'The email message could not be send. See the log files.');
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return View::make('user.verification-pending');
|
||||
}
|
||||
|
||||
|
||||
return View::make('user.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* If need to verify, send new reset code.
|
||||
* Otherwise, send new password.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function postRemindMe()
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Database\User\User $repository */
|
||||
$repository = App::make('FireflyIII\Database\User\User');
|
||||
|
||||
/** @var \FireflyIII\Shared\Mail\RegistrationInterface $email */
|
||||
$email = App::make('FireflyIII\Shared\Mail\RegistrationInterface');
|
||||
|
||||
|
||||
$user = $repository->findByEmail(Input::get('email'));
|
||||
if (!$user) {
|
||||
Session::flash('error', 'No good!');
|
||||
|
||||
return View::make('user.remindMe');
|
||||
}
|
||||
$email->sendResetVerification($user);
|
||||
|
||||
return View::make('user.verification-pending');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If allowed, show the register form.
|
||||
*
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
if ((Config::get('mail.from.address') == '@gmail.com' || Config::get('mail.from.address') == '')
|
||||
&& Config::get('mail.pretend') === false
|
||||
) {
|
||||
return View::make('error')->with('message', 'Configuration error in <code>app/config/' . App::environment() . '/mail.php</code>');
|
||||
}
|
||||
|
||||
return View::make('user.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show form to help user get a new password.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function remindMe()
|
||||
{
|
||||
return View::make('user.remindMe');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a user a password based on his reset code.
|
||||
*
|
||||
* @param $reset
|
||||
*
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
public function reset($reset)
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Database\User\User $repository */
|
||||
$repository = App::make('FireflyIII\Database\User\User');
|
||||
|
||||
/** @var \FireflyIII\Shared\Mail\RegistrationInterface $email */
|
||||
$email = App::make('FireflyIII\Shared\Mail\RegistrationInterface');
|
||||
|
||||
$user = $repository->findByReset($reset);
|
||||
if ($user) {
|
||||
$email->sendPasswordMail($user);
|
||||
|
||||
return View::make('user.registered');
|
||||
}
|
||||
|
||||
return View::make('error')->with('message', 'No reset code found!');
|
||||
}
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateUsersTable
|
||||
*/
|
||||
class CreateUsersTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('users');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'users', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->string('email', 100);
|
||||
$table->string('password', 60);
|
||||
$table->string('reset', 32)->nullable();
|
||||
$table->string('remember_token', 255)->nullable();
|
||||
$table->unique('email');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateAccountTypesTable
|
||||
*
|
||||
*/
|
||||
class CreateAccountTypesTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('account_types');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'account_types', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->string('type', 30);
|
||||
$table->boolean('editable');
|
||||
|
||||
$table->unique('type');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateAccountsTable
|
||||
*
|
||||
*/
|
||||
class CreateAccountsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('accounts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'accounts', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->integer('account_type_id')->unsigned();
|
||||
$table->string('name', 100);
|
||||
$table->boolean('active');
|
||||
|
||||
// connect accounts to users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// connect accounts to account_types
|
||||
$table->foreign('account_type_id')->references('id')->on('account_types')->onDelete('cascade');
|
||||
|
||||
// for a user, the account name must be unique.
|
||||
$table->unique(['user_id', 'account_type_id', 'name']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateComponentsTable
|
||||
*
|
||||
*/
|
||||
class CreateComponentsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('components');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'components', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->string('name', 50);
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('class', 20);
|
||||
|
||||
// connect components to users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// for a user, the component type & name must be unique.
|
||||
$table->unique(['user_id', 'class', 'name']);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreatePiggybanksTable
|
||||
*
|
||||
*/
|
||||
class CreatePiggybanksTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('piggybanks');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'piggybanks', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('account_id')->unsigned();
|
||||
$table->string('name', 100);
|
||||
$table->decimal('targetamount', 10, 2);
|
||||
$table->date('startdate')->nullable();
|
||||
$table->date('targetdate')->nullable();
|
||||
$table->boolean('repeats');
|
||||
$table->enum('rep_length', ['day', 'week', 'quarter', 'month', 'year'])->nullable();
|
||||
$table->smallInteger('rep_every')->unsigned();
|
||||
$table->smallInteger('rep_times')->unsigned()->nullable();
|
||||
$table->enum('reminder', ['day', 'week', 'quarter', 'month', 'year'])->nullable();
|
||||
$table->smallInteger('reminder_skip')->unsigned();
|
||||
$table->boolean('remind_me');
|
||||
$table->integer('order')->unsigned();
|
||||
|
||||
// connect account to piggy bank.
|
||||
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
|
||||
|
||||
// for an account, the name must be unique.
|
||||
$table->unique(['account_id', 'name']);
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateTransactionCurrenciesTable
|
||||
*
|
||||
*/
|
||||
class CreateTransactionCurrenciesTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('transaction_currencies');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'transaction_currencies', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->string('code', 3);
|
||||
|
||||
// code must be unique.
|
||||
$table->unique(['code']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateTransactionTypesTable
|
||||
*
|
||||
*/
|
||||
class CreateTransactionTypesTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('transaction_types');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'transaction_types', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->string('type', 50);
|
||||
|
||||
// type must be unique.
|
||||
$table->unique(['type']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateRecurringTransactionsTable
|
||||
*
|
||||
*/
|
||||
class CreateRecurringTransactionsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('recurring_transactions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'recurring_transactions', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('name', 50);
|
||||
$table->string('match', 255);
|
||||
$table->decimal('amount_min', 10, 2);
|
||||
$table->decimal('amount_max', 10, 2);
|
||||
$table->date('date');
|
||||
$table->boolean('active');
|
||||
|
||||
$table->boolean('automatch');
|
||||
$table->enum('repeat_freq', ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly']);
|
||||
$table->smallInteger('skip')->unsigned();
|
||||
|
||||
// connect user id to users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// for a user, the name must be unique
|
||||
$table->unique(['user_id', 'name']);
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateTransactionJournalsTable
|
||||
*
|
||||
*/
|
||||
class CreateTransactionJournalsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('transaction_journals');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->integer('transaction_type_id')->unsigned();
|
||||
$table->integer('recurring_transaction_id')->unsigned()->nullable();
|
||||
$table->integer('transaction_currency_id')->unsigned();
|
||||
$table->string('description', 255)->nullable();
|
||||
$table->boolean('completed');
|
||||
$table->date('date');
|
||||
|
||||
// connect users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// connect transaction journals to transaction types
|
||||
$table->foreign('transaction_type_id')->references('id')->on('transaction_types')->onDelete('cascade');
|
||||
|
||||
// connect transaction journals to recurring transactions
|
||||
$table->foreign('recurring_transaction_id')->references('id')->on('recurring_transactions')->onDelete('set null');
|
||||
|
||||
// connect transaction journals to transaction currencies
|
||||
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade');
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateTransactionsTable
|
||||
*
|
||||
*/
|
||||
class CreateTransactionsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('transactions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'transactions', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->integer('account_id')->unsigned();
|
||||
$table->integer('piggybank_id')->nullable()->unsigned();
|
||||
$table->integer('transaction_journal_id')->unsigned();
|
||||
$table->string('description', 255)->nullable();
|
||||
$table->decimal('amount', 10, 2);
|
||||
|
||||
// connect account id:
|
||||
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
|
||||
|
||||
// connect piggy banks
|
||||
$table->foreign('piggybank_id')->references('id')->on('piggybanks')->onDelete('set null');
|
||||
|
||||
// connect transactions to transaction journals
|
||||
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateComponentTransactionTable
|
||||
*
|
||||
*/
|
||||
class CreateComponentTransactionTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('component_transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'component_transaction', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('component_id')->unsigned();
|
||||
$table->integer('transaction_id')->unsigned();
|
||||
|
||||
// connect to components
|
||||
$table->foreign('component_id')->references('id')->on('components')->onDelete('cascade');
|
||||
|
||||
// connect to transactions
|
||||
$table->foreign('transaction_id')->references('id')->on('transactions')->onDelete('cascade');
|
||||
|
||||
// combo must be unique:
|
||||
$table->unique(['component_id', 'transaction_id']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateComponentTransactionJournalTable
|
||||
*
|
||||
*/
|
||||
class CreateComponentTransactionJournalTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('component_transaction_journal');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'component_transaction_journal', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('component_id')->unsigned();
|
||||
$table->integer('transaction_journal_id')->unsigned();
|
||||
|
||||
// link components with component_id
|
||||
$table->foreign('component_id')->references('id')->on('components')->onDelete('cascade');
|
||||
|
||||
// link transaction journals with transaction_journal_id
|
||||
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
|
||||
|
||||
// combo must be unique:
|
||||
$table->unique(['component_id', 'transaction_journal_id'], 'cid_tjid_unique');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreatePreferencesTable
|
||||
*
|
||||
*/
|
||||
class CreatePreferencesTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('preferences');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'preferences', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('name');
|
||||
$table->text('data');
|
||||
|
||||
// connect preferences to users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// only one preference per name per user
|
||||
$table->unique(['user_id', 'name']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateSessionTable
|
||||
*
|
||||
*/
|
||||
class CreateSessionTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('sessions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'sessions', function (Blueprint $table) {
|
||||
$table->string('id')->unique();
|
||||
$table->text('payload');
|
||||
$table->integer('last_activity');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)\
|
||||
*
|
||||
*
|
||||
* Class CreateLimitsTable
|
||||
*
|
||||
*/
|
||||
class CreateLimitsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('limits');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'limits', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('component_id')->unsigned();
|
||||
$table->date('startdate');
|
||||
$table->decimal('amount', 10, 2);
|
||||
$table->boolean('repeats');
|
||||
$table->enum('repeat_freq', ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly']);
|
||||
|
||||
$table->unique(['component_id', 'startdate', 'repeat_freq'], 'unique_ci_combi');
|
||||
|
||||
// connect component
|
||||
$table->foreign('component_id')->references('id')->on('components')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateLimitRepeatTable
|
||||
*
|
||||
*/
|
||||
class CreateLimitRepeatTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('limit_repetitions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'limit_repetitions', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('limit_id')->unsigned();
|
||||
$table->date('startdate');
|
||||
$table->date('enddate');
|
||||
$table->decimal('amount', 10, 2);
|
||||
|
||||
$table->unique(['limit_id', 'startdate', 'enddate']);
|
||||
|
||||
// connect limit
|
||||
$table->foreign('limit_id')->references('id')->on('limits')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateComponentRecurringTransactionTable
|
||||
*
|
||||
*/
|
||||
class CreateComponentRecurringTransactionTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('component_recurring_transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'component_recurring_transaction', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('component_id')->unsigned();
|
||||
$table->integer('recurring_transaction_id')->unsigned();
|
||||
$table->boolean('optional');
|
||||
|
||||
// link components with component_id
|
||||
$table->foreign('component_id')->references('id')->on('components')->onDelete('cascade');
|
||||
|
||||
// link transaction journals with transaction_journal_id
|
||||
$table->foreign('recurring_transaction_id')->references('id')->on('recurring_transactions')->onDelete('cascade');
|
||||
|
||||
// component and recurring transaction must be unique.
|
||||
$table->unique(['component_id', 'recurring_transaction_id'], 'cid_rtid_unique');
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreatePiggyInstance
|
||||
*
|
||||
*/
|
||||
class CreatePiggybankRepetitionsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('piggybank_repetitions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'piggybank_repetitions', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('piggybank_id')->unsigned();
|
||||
$table->date('startdate')->nullable();
|
||||
$table->date('targetdate')->nullable();
|
||||
$table->decimal('currentamount', 10, 2);
|
||||
|
||||
$table->unique(['piggybank_id', 'startdate', 'targetdate']);
|
||||
|
||||
// connect instance to piggybank.
|
||||
$table->foreign('piggybank_id')->references('id')->on('piggybanks')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreatePiggybankEventsTable
|
||||
*
|
||||
*/
|
||||
class CreatePiggybankEventsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('piggybank_events');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'piggybank_events', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('piggybank_id')->unsigned();
|
||||
$table->integer('transaction_journal_id')->unsigned()->nullable();
|
||||
|
||||
$table->date('date');
|
||||
$table->decimal('amount', 10, 2);
|
||||
|
||||
// connect instance to piggybank.
|
||||
$table->foreign('piggybank_id')->references('id')->on('piggybanks')->onDelete('cascade');
|
||||
|
||||
// connect to journal:
|
||||
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('set null');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateRemindersTable
|
||||
*
|
||||
*/
|
||||
class CreateRemindersTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('reminders');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'reminders', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->date('startdate');
|
||||
$table->date('enddate')->nullable();
|
||||
$table->boolean('active');
|
||||
$table->boolean('notnow')->default(0);
|
||||
$table->integer('remindersable_id')->unsigned()->nullable();
|
||||
$table->string('remindersable_type')->nullable();
|
||||
|
||||
// connect reminders to users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateAccountMetaTable
|
||||
*
|
||||
*/
|
||||
class CreateAccountMetaTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
Schema::drop('account_meta');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
Schema::create(
|
||||
'account_meta', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('account_id')->unsigned();
|
||||
$table->string('name');
|
||||
$table->text('data');
|
||||
|
||||
$table->unique(['account_id', 'name']);
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateTransactionGroupsTable
|
||||
*
|
||||
*/
|
||||
class CreateTransactionGroupsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('transaction_groups');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'transaction_groups', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->enum('relation', ['balance']);
|
||||
|
||||
// connect reminders to users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* Class CreateTransactionGroupTransactionJournalTable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
class CreateTransactionGroupTransactionJournalTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
Schema::drop('transaction_group_transaction_journal');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
|
||||
Schema::create(
|
||||
'transaction_group_transaction_journal', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('transaction_group_id')->unsigned();
|
||||
$table->integer('transaction_journal_id')->unsigned();
|
||||
|
||||
// link to foreign tables.
|
||||
$table->foreign('transaction_group_id', 'tr_grp_id')->references('id')->on('transaction_groups')->onDelete('cascade');
|
||||
$table->foreign('transaction_journal_id', 'tr_trj_id')->references('id')->on('transaction_journals')->onDelete('cascade');
|
||||
|
||||
// add unique.
|
||||
$table->unique(['transaction_group_id', 'transaction_journal_id'], 'tt_joined');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,497 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName) // method names are mandated by laravel.
|
||||
* @SuppressWarnings("TooManyMethods") // I'm fine with this
|
||||
*
|
||||
* Down:
|
||||
* 1. Create new Components based on Budgets.
|
||||
* 2. Create new Components based on Categories
|
||||
* 3. Recreate component_id in limits
|
||||
* 4. Update all budget_limits entries (component_id).
|
||||
* 5. Add the foreign key to component_id in budget_limits
|
||||
* 6. Drop column 'budget_id' in budget_limits.
|
||||
* 7. Create table journal_components.
|
||||
* 8. create entries for budgets in journal_components.
|
||||
* 9. create entries for categories in journal_components.
|
||||
* 10. drop table budget_journals
|
||||
* 11. drop table category_journals
|
||||
* 12. drop table budgets
|
||||
* 13. drop table categories.
|
||||
* 14. rename budget_limits to limits.
|
||||
* 15. Rename piggy_bank_events to piggybank_events
|
||||
* 16. Rename field 'budget_limit_id' to 'limit_id' in 'limit_repetitions'
|
||||
* 17. Do not recreate component_recurring_transaction
|
||||
* 18. Do not recreate component_transaction
|
||||
* 19. Do not recreate field 'piggybank_id' in 'transactions'
|
||||
* 20. Drop fields from currency table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Up:
|
||||
*
|
||||
* 1. Create new budget table.
|
||||
* 2. Create new category table.
|
||||
* 3. Create journal_budget table.
|
||||
* 4. Create journal_category table.
|
||||
* 5. Move budgets to new budgets table AND move journal_components to budget_components.
|
||||
* 6. Move categories to categories table AND move journal_components to category_components.
|
||||
* 7. Rename limits to budget_limits.
|
||||
* 8. Rename piggybank_events to piggy_bank_events
|
||||
* 9. Rename field 'limit_id' to 'budget_limit_id' in 'limit_repetitions'
|
||||
* 10. Create field budget_id in budget_limits.
|
||||
* 11. Update budget_limits with budgets (instead of components).
|
||||
* 12. drop table journal_components
|
||||
* 13. Drop table component_recurring_transaction
|
||||
* 14. Drop table component_transaction
|
||||
* 15. Drop field 'piggybank_id' from 'transactions'
|
||||
* 16. Drop field 'component_id' from 'budget_limits'
|
||||
* 17. Expand currency table with new fields.
|
||||
*
|
||||
* Class ChangesForV321
|
||||
*/
|
||||
class ChangesForV321 extends Migration
|
||||
{
|
||||
public function down()
|
||||
{
|
||||
|
||||
$this->moveBudgetsBack(); // 1.
|
||||
$this->moveCategoriesBack(); // 2.
|
||||
$this->createComponentId(); // 3.
|
||||
$this->updateComponentInBudgetLimits(); // 4.
|
||||
$this->createComponentIdForeignKey(); // 5.
|
||||
$this->dropBudgetIdColumnInBudgetLimits(); // 6.
|
||||
$createComponents = new CreateComponentTransactionJournalTable; // 7.
|
||||
$createComponents->up();
|
||||
$this->moveBackEntriesForBudgetsInJoinedTable(); // 8.
|
||||
$this->moveBackEntriesForCategoriesInJoinedTable(); // 9.
|
||||
$this->dropBudgetJournalTable(); // 10.
|
||||
$this->dropCategoryJournalTable(); // 11.
|
||||
$this->dropBudgetTable(); // 12.
|
||||
$this->dropCategoryTable(); // 13.
|
||||
$this->renameBudgetLimits(); // 14.
|
||||
$this->renamePiggyBankEvents(); // 15.
|
||||
$this->renameBudgetLimitToBudgetInRepetitions(); // 16.
|
||||
// 17, 18, 19
|
||||
$this->dropFieldsFromCurrencyTable(); // 20.
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function moveBudgetsBack()
|
||||
{
|
||||
Budget::get()->each(
|
||||
function (Budget $budget) {
|
||||
Component::firstOrCreate(
|
||||
[
|
||||
'name' => $budget->name,
|
||||
'user_id' => $budget->user_id,
|
||||
'class' => 'Budget'
|
||||
]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function moveCategoriesBack()
|
||||
{
|
||||
Category::get()->each(
|
||||
function (Category $category) {
|
||||
Component::firstOrCreate(
|
||||
[
|
||||
'name' => $category->name,
|
||||
'user_id' => $category->user_id,
|
||||
'class' => 'Category'
|
||||
]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function createComponentId()
|
||||
{
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->integer('component_id')->unsigned();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function updateComponentInBudgetLimits()
|
||||
{
|
||||
BudgetLimit::get()->each(
|
||||
function (BudgetLimit $bl) {
|
||||
$budgetId = $bl->budget_id;
|
||||
$budget = Budget::find($budgetId);
|
||||
if ($budget) {
|
||||
$component = Component::where('class', 'Budget')->where('user_id', $budget->user_id)->where('name', $budget->name)->first();
|
||||
if ($component) {
|
||||
$bl->component_id = $component->id;
|
||||
$bl->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function createComponentIdForeignKey()
|
||||
{
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->foreign('component_id', 'limits_component_id_foreign')->references('id')->on('components')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function dropBudgetIdColumnInBudgetLimits()
|
||||
{
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->dropForeign('bid_foreign');
|
||||
$table->dropColumn('budget_id'); // also drop foreign key!
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function moveBackEntriesForBudgetsInJoinedTable()
|
||||
{
|
||||
$set = DB::table('budget_transaction_journal')->get();
|
||||
foreach ($set as $entry) {
|
||||
$budget = Budget::find($entry->budget_id);
|
||||
if ($budget) {
|
||||
$component = Component::where('class', 'Budget')->where('name', $budget->name)->where('user_id', $budget->user_id)->first();
|
||||
if ($component) {
|
||||
DB::table('component_transaction_journal')->insert(
|
||||
[
|
||||
'component_id' => $component->id,
|
||||
'transaction_journal_id' => $entry->transaction_journal_id
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function moveBackEntriesForCategoriesInJoinedTable()
|
||||
{
|
||||
$set = DB::table('category_transaction_journal')->get();
|
||||
foreach ($set as $entry) {
|
||||
$category = Category::find($entry->category_id);
|
||||
if ($category) {
|
||||
$component = Component::where('class', 'Category')->where('name', $category->name)->where('user_id', $category->user_id)->first();
|
||||
if ($component) {
|
||||
DB::table('component_transaction_journal')->insert(
|
||||
[
|
||||
'component_id' => $component->id,
|
||||
'transaction_journal_id' => $entry->transaction_journal_id
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function dropBudgetJournalTable()
|
||||
{
|
||||
Schema::dropIfExists('budget_transaction_journal');
|
||||
}
|
||||
|
||||
public function dropCategoryJournalTable()
|
||||
{
|
||||
Schema::dropIfExists('category_transaction_journal');
|
||||
}
|
||||
|
||||
public function dropBudgetTable()
|
||||
{
|
||||
Schema::dropIfExists('budgets');
|
||||
}
|
||||
|
||||
public function dropCategoryTable()
|
||||
{
|
||||
Schema::dropIfExists('categories');
|
||||
}
|
||||
|
||||
public function renameBudgetLimits()
|
||||
{
|
||||
Schema::rename('budget_limits', 'limits');
|
||||
}
|
||||
|
||||
public function renamePiggyBankEvents()
|
||||
{
|
||||
Schema::rename('piggy_bank_events', 'piggybank_events');
|
||||
|
||||
}
|
||||
|
||||
public function renameBudgetLimitToBudgetInRepetitions()
|
||||
{
|
||||
Schema::table(
|
||||
'limit_repetitions', function (Blueprint $table) {
|
||||
$table->renameColumn('budget_limit_id', 'limit_id');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function dropFieldsFromCurrencyTable()
|
||||
{
|
||||
|
||||
Schema::table(
|
||||
'transaction_currencies', function (Blueprint $table) {
|
||||
$table->dropColumn('symbol');
|
||||
$table->dropColumn('name');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$this->createBudgetTable(); // 1.
|
||||
$this->createCategoryTable(); // 2.
|
||||
$this->createBudgetJournalTable(); // 3
|
||||
$this->createCategoryJournalTable(); // 4.
|
||||
$this->moveBudgets(); // 5.
|
||||
$this->moveCategories(); // 6.
|
||||
$this->correctNameForBudgetLimits(); // 7.
|
||||
$this->correctNameForPiggyBankEvents(); // 8.
|
||||
$this->renameBudgetToBudgetLimitInRepetitions(); // 9.
|
||||
$this->addBudgetIdFieldToBudgetLimits(); // 10.
|
||||
$this->moveComponentIdToBudgetId(); // 11.
|
||||
$this->dropComponentJournalTable(); // 12.
|
||||
$this->dropComponentRecurringTransactionTable(); // 13.
|
||||
$this->dropComponentTransactionTable(); // 14.
|
||||
$this->dropPiggyBankIdFromTransactions(); // 15.
|
||||
$this->dropComponentIdFromBudgetLimits(); // 16.
|
||||
$this->expandCurrencyTable(); // 17.
|
||||
|
||||
}
|
||||
|
||||
public function createBudgetTable()
|
||||
{
|
||||
Schema::create(
|
||||
'budgets', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->string('name', 50);
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->unique(['user_id', 'name']);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function createCategoryTable()
|
||||
{
|
||||
Schema::create(
|
||||
'categories', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->string('name', 50);
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->unique(['user_id', 'name']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function createBudgetJournalTable()
|
||||
{
|
||||
Schema::create(
|
||||
'budget_transaction_journal', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('budget_id')->unsigned();
|
||||
$table->integer('transaction_journal_id')->unsigned();
|
||||
$table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade');
|
||||
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
|
||||
$table->unique(['budget_id', 'transaction_journal_id'], 'budid_tjid_unique');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function createCategoryJournalTable()
|
||||
{
|
||||
Schema::create(
|
||||
'category_transaction_journal', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('category_id')->unsigned();
|
||||
$table->integer('transaction_journal_id')->unsigned();
|
||||
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
|
||||
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
|
||||
$table->unique(['category_id', 'transaction_journal_id'], 'catid_tjid_unique');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function moveBudgets()
|
||||
{
|
||||
Component::where('class', 'Budget')->get()->each(
|
||||
function (Component $c) {
|
||||
$entry = [
|
||||
'user_id' => $c->user_id,
|
||||
'name' => $c->name
|
||||
|
||||
];
|
||||
$budget = Budget::firstOrCreate($entry);
|
||||
Log::debug('Migrated budget #' . $budget->id . ': ' . $budget->name);
|
||||
// create entry in budget_transaction_journal
|
||||
$connections = DB::table('component_transaction_journal')->where('component_id', $c->id)->get();
|
||||
foreach ($connections as $connection) {
|
||||
DB::table('budget_transaction_journal')->insert(
|
||||
[
|
||||
'budget_id' => $budget->id,
|
||||
'transaction_journal_id' => $connection->transaction_journal_id
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function moveCategories()
|
||||
{
|
||||
Component::where('class', 'Category')->get()->each(
|
||||
function (Component $c) {
|
||||
$entry = [
|
||||
'user_id' => $c->user_id,
|
||||
'name' => $c->name
|
||||
|
||||
];
|
||||
$category = Category::firstOrCreate($entry);
|
||||
Log::debug('Migrated category #' . $category->id . ': ' . $category->name);
|
||||
// create entry in category_transaction_journal
|
||||
$connections = DB::table('component_transaction_journal')->where('component_id', $c->id)->get();
|
||||
foreach ($connections as $connection) {
|
||||
DB::table('category_transaction_journal')->insert(
|
||||
[
|
||||
'category_id' => $category->id,
|
||||
'transaction_journal_id' => $connection->transaction_journal_id
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function correctNameForBudgetLimits()
|
||||
{
|
||||
Schema::rename('limits', 'budget_limits');
|
||||
}
|
||||
|
||||
public function correctNameForPiggyBankEvents()
|
||||
{
|
||||
Schema::rename('piggybank_events', 'piggy_bank_events');
|
||||
|
||||
}
|
||||
|
||||
public function renameBudgetToBudgetLimitInRepetitions()
|
||||
{
|
||||
Schema::table(
|
||||
'limit_repetitions', function (Blueprint $table) {
|
||||
$table->renameColumn('limit_id', 'budget_limit_id');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function addBudgetIdFieldToBudgetLimits()
|
||||
{
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->integer('budget_id', false, true)->nullable()->after('updated_at');
|
||||
$table->foreign('budget_id', 'bid_foreign')->references('id')->on('budgets')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function moveComponentIdToBudgetId()
|
||||
{
|
||||
\Log::debug('Now in moveComponentIdToBudgetId()');
|
||||
BudgetLimit::get()->each(
|
||||
function (BudgetLimit $bl) {
|
||||
\Log::debug('Now at budgetLimit #' . $bl->id . ' with component_id: ' . $bl->component_id);
|
||||
$component = Component::find($bl->component_id);
|
||||
if ($component) {
|
||||
\Log::debug('Found component with id #' . $component->id . ' and name ' . $component->name);
|
||||
$budget = Budget::whereName($component->name)->whereUserId($component->user_id)->first();
|
||||
if ($budget) {
|
||||
\Log::debug('Found a budget with ID #' . $budget->id . ' and name ' . $budget->name);
|
||||
$bl->budget_id = $budget->id;
|
||||
$bl->save();
|
||||
\Log::debug('Connected budgetLimit #' . $bl->id . ' to budget_id' . $budget->id);
|
||||
} else {
|
||||
\Log::debug('Could not find a matching budget with name ' . $component->name);
|
||||
}
|
||||
} else {
|
||||
\Log::debug('Could not find a component with id ' . $bl->component_id);
|
||||
}
|
||||
}
|
||||
);
|
||||
\Log::debug('Done with moveComponentIdToBudgetId()');
|
||||
|
||||
}
|
||||
|
||||
public function dropComponentJournalTable()
|
||||
{
|
||||
Schema::dropIfExists('component_transaction_journal');
|
||||
}
|
||||
|
||||
public function dropComponentRecurringTransactionTable()
|
||||
{
|
||||
Schema::dropIfExists('component_recurring_transaction');
|
||||
}
|
||||
|
||||
public function dropComponentTransactionTable()
|
||||
{
|
||||
Schema::dropIfExists('component_transaction');
|
||||
}
|
||||
|
||||
public function dropPiggyBankIdFromTransactions()
|
||||
{
|
||||
|
||||
Schema::table(
|
||||
'transactions', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('transactions', 'piggybank_id')) {
|
||||
$table->dropForeign('transactions_piggybank_id_foreign');
|
||||
$table->dropColumn('piggybank_id');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function dropComponentIdFromBudgetLimits()
|
||||
{
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->dropForeign('limits_component_id_foreign');
|
||||
$table->dropColumn('component_id');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function expandCurrencyTable()
|
||||
{
|
||||
Schema::table(
|
||||
'transaction_currencies', function (Blueprint $table) {
|
||||
$table->string('name', 48)->nullable();
|
||||
$table->string('symbol', 8)->nullable();
|
||||
}
|
||||
);
|
||||
\DB::update('UPDATE `transaction_currencies` SET `symbol` = "€", `name` = "Euro" WHERE `code` = "EUR";');
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,172 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
* @SuppressWarnings("MethodLength") // I don't mind this in case of migrations.
|
||||
|
||||
*
|
||||
* Class ChangesForV322
|
||||
*/
|
||||
class ChangesForV322 extends Migration
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// rename tables:
|
||||
Schema::rename('piggy_bank_repetitions', 'piggybank_repetitions');
|
||||
Schema::rename('piggy_banks', 'piggybanks');
|
||||
|
||||
// rename fields
|
||||
Schema::table(
|
||||
'piggy_bank_events', function (Blueprint $table) {
|
||||
$table->renameColumn('piggy_bank_id', 'piggybank_id');
|
||||
}
|
||||
);
|
||||
|
||||
Schema::table(
|
||||
'piggybank_repetitions', function (Blueprint $table) {
|
||||
$table->renameColumn('piggy_bank_id', 'piggybank_id');
|
||||
}
|
||||
);
|
||||
|
||||
// remove soft delete to piggy banks
|
||||
Schema::table(
|
||||
'piggybanks', function (Blueprint $table) {
|
||||
$table->dropSoftDeletes();
|
||||
}
|
||||
);
|
||||
|
||||
// drop keys from bills (foreign bills_uid_for and unique uid_name_unique)
|
||||
Schema::table(
|
||||
'bills', function (Blueprint $table) {
|
||||
$table->dropForeign('bills_uid_for');
|
||||
$table->dropUnique('uid_name_unique');
|
||||
}
|
||||
);
|
||||
// drop foreign key from transaction_journals (bill_id_foreign)
|
||||
Schema::table(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
$table->dropForeign('bill_id_foreign');
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// drop foreign key from budget_limits:
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->dropForeign('bid_foreign');
|
||||
$table->dropUnique('unique_bl_combi');
|
||||
}
|
||||
);
|
||||
|
||||
// rename bills to recurring_transactions
|
||||
Schema::rename('bills', 'recurring_transactions');
|
||||
// recreate foreign key recurring_transactions_user_id_foreign in recurring_transactions
|
||||
// recreate unique recurring_transactions_user_id_name_unique in recurring_transactions
|
||||
Schema::table(
|
||||
'recurring_transactions', function (Blueprint $table) {
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->unique(['user_id', 'name']);
|
||||
}
|
||||
);
|
||||
|
||||
// rename bill_id to recurring_transaction_id
|
||||
// recreate foreign transaction_journals_recurring_transaction_id_foreign in transaction_journals
|
||||
Schema::table(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
$table->renameColumn('bill_id', 'recurring_transaction_id');
|
||||
$table->foreign('recurring_transaction_id')->references('id')->on('recurring_transactions')->onDelete('set null');
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// rename tables:
|
||||
Schema::rename('piggybank_repetitions', 'piggy_bank_repetitions');
|
||||
Schema::rename('piggybanks', 'piggy_banks');
|
||||
|
||||
// recreate it the correct way:
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->unique(['budget_id', 'startdate', 'repeat_freq'], 'unique_bl_combi');
|
||||
}
|
||||
);
|
||||
|
||||
// rename fields
|
||||
Schema::table(
|
||||
'piggy_bank_events', function (Blueprint $table) {
|
||||
$table->renameColumn('piggybank_id', 'piggy_bank_id');
|
||||
}
|
||||
);
|
||||
|
||||
Schema::table(
|
||||
'piggy_bank_repetitions', function (Blueprint $table) {
|
||||
$table->renameColumn('piggybank_id', 'piggy_bank_id');
|
||||
}
|
||||
);
|
||||
|
||||
// add soft delete to piggy banks
|
||||
Schema::table(
|
||||
'piggy_banks', function (Blueprint $table) {
|
||||
$table->softDeletes();
|
||||
}
|
||||
);
|
||||
|
||||
// rename everything related to recurring transactions, aka bills:
|
||||
Schema::table(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
|
||||
|
||||
// drop relation
|
||||
$table->dropForeign('transaction_journals_recurring_transaction_id_foreign');
|
||||
// rename column
|
||||
$table->renameColumn('recurring_transaction_id', 'bill_id');
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
Schema::table(
|
||||
'recurring_transactions', function (Blueprint $table) {
|
||||
$table->dropForeign('recurring_transactions_user_id_foreign');
|
||||
$table->dropUnique('recurring_transactions_user_id_name_unique');
|
||||
}
|
||||
);
|
||||
// rename table:
|
||||
Schema::rename('recurring_transactions', 'bills');
|
||||
|
||||
// recreate foreign relation:
|
||||
Schema::table(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
$table->foreign('bill_id', 'bill_id_foreign')->references('id')->on('bills')->onDelete('set null');
|
||||
}
|
||||
);
|
||||
|
||||
// recreate more foreign relations.
|
||||
Schema::table(
|
||||
'bills', function (Blueprint $table) {
|
||||
// connect user id to users
|
||||
$table->foreign('user_id', 'bills_uid_for')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// for a user, the name must be unique
|
||||
$table->unique(['user_id', 'name'], 'uid_name_unique');
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
* @SuppressWarnings("MethodLength") // I don't mind this in case of migrations.
|
||||
*
|
||||
* Class ChangesForV325
|
||||
*/
|
||||
class ChangesForV325 extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
|
||||
// delete an old index:
|
||||
try {
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->dropUnique('unique_ci_combi');
|
||||
|
||||
}
|
||||
);
|
||||
} catch (PDOException $e) {
|
||||
// don't care.
|
||||
}
|
||||
|
||||
// allow journal descriptions to be encrypted.
|
||||
Schema::table(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
$table->boolean('encrypted')->default(0);
|
||||
|
||||
}
|
||||
);
|
||||
try {
|
||||
DB::update('ALTER TABLE `transaction_journals` MODIFY `description` VARCHAR(1024)');
|
||||
} catch (PDOException $e) {
|
||||
// don't care.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Class AccountTypeSeeder
|
||||
*/
|
||||
class AccountTypeSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
DB::table('account_types')->delete();
|
||||
|
||||
AccountType::create(['type' => 'Default account', 'editable' => true]);
|
||||
AccountType::create(['type' => 'Cash account', 'editable' => false]);
|
||||
AccountType::create(['type' => 'Asset account', 'editable' => true]);
|
||||
AccountType::create(['type' => 'Expense account', 'editable' => true]);
|
||||
AccountType::create(['type' => 'Revenue account', 'editable' => true]);
|
||||
AccountType::create(['type' => 'Initial balance account', 'editable' => false]);
|
||||
AccountType::create(['type' => 'Beneficiary account', 'editable' => true]);
|
||||
AccountType::create(['type' => 'Import account', 'editable' => false]);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class DatabaseSeeder
|
||||
*/
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Eloquent::unguard();
|
||||
|
||||
$this->call('AccountTypeSeeder');
|
||||
$this->call('TransactionCurrencySeeder');
|
||||
$this->call('TransactionTypeSeeder');
|
||||
|
||||
if (App::environment() == 'testing' || App::environment() == 'homestead') {
|
||||
$this->call('TestDataSeeder');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,609 +0,0 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
* @SuppressWarnings("TooManyMethods") // I'm fine with this
|
||||
* @SuppressWarnings("CouplingBetweenObjects") // I'm fine with this
|
||||
* @SuppressWarnings("MethodLength") // I'm fine with this
|
||||
*
|
||||
* Class TestDataSeeder
|
||||
*/
|
||||
class TestDataSeeder extends Seeder
|
||||
{
|
||||
/** @var string */
|
||||
public $eom;
|
||||
/** @var string */
|
||||
public $neom;
|
||||
/** @var string */
|
||||
public $nsom;
|
||||
/** @var string */
|
||||
public $som;
|
||||
/** @var string */
|
||||
public $today;
|
||||
/** @var string */
|
||||
public $yaeom;
|
||||
/** @var string */
|
||||
public $yasom;
|
||||
/** @var Carbon */
|
||||
protected $_endOfMonth;
|
||||
/** @var Carbon */
|
||||
protected $_nextEndOfMonth;
|
||||
/** @var Carbon */
|
||||
protected $_nextStartOfMonth;
|
||||
/** @var Carbon */
|
||||
protected $_startOfMonth;
|
||||
/** @var Carbon */
|
||||
protected $_today;
|
||||
/** @var Carbon */
|
||||
protected $_yearAgoEndOfMonth;
|
||||
/** @var Carbon */
|
||||
protected $_yearAgoStartOfMonth;
|
||||
|
||||
/**
|
||||
* A whole bunch of times and dates.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_startOfMonth = Carbon::now()->startOfMonth();
|
||||
$this->som = $this->_startOfMonth->format('Y-m-d');
|
||||
$this->_endOfMonth = Carbon::now()->endOfMonth();
|
||||
$this->eom = $this->_endOfMonth->format('Y-m-d');
|
||||
$this->_nextStartOfMonth = Carbon::now()->addMonth()->startOfMonth();
|
||||
$this->nsom = $this->_nextStartOfMonth->format('Y-m-d');
|
||||
$this->_nextEndOfMonth = Carbon::now()->addMonth()->endOfMonth();
|
||||
$this->neom = $this->_nextEndOfMonth->format('Y-m-d');
|
||||
$this->_yearAgoStartOfMonth = Carbon::now()->subYear()->startOfMonth();
|
||||
$this->yasom = $this->_yearAgoStartOfMonth->format('Y-m-d');
|
||||
$this->_yearAgoEndOfMonth = Carbon::now()->subYear()->startOfMonth();
|
||||
$this->yaeom = $this->_yearAgoEndOfMonth->format('Y-m-d');
|
||||
$this->_today = Carbon::now();
|
||||
$this->today = $this->_today->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* Dates are always this month, the start of this month or earlier.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->createUsers();
|
||||
$this->createAssetAccounts();
|
||||
$this->createBudgets();
|
||||
$this->createCategories();
|
||||
$this->createPiggyBanks();
|
||||
$this->createReminders();
|
||||
$this->createRecurringTransactions();
|
||||
$this->createBills();
|
||||
$this->createExpenseAccounts();
|
||||
$this->createRevenueAccounts();
|
||||
|
||||
$current = clone $this->_yearAgoStartOfMonth;
|
||||
while ($current <= $this->_startOfMonth) {
|
||||
|
||||
// create expenses for rent, utilities, TV, phone on the 1st of the month.
|
||||
$this->createMonthlyExpenses(clone $current);
|
||||
$this->createGroceries(clone $current);
|
||||
$this->createBigExpense(clone $current);
|
||||
|
||||
echo 'Created test-content for ' . $current->format('F Y') . "\n";
|
||||
$current->addMonth();
|
||||
}
|
||||
$this->createPiggyBankEvent();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createUsers()
|
||||
{
|
||||
User::create(['email' => 'reset@example.com', 'password' => 'functional', 'reset' => 'okokokokokokokokokokokokokokokok', 'remember_token' => null]);
|
||||
User::create(['email' => 'functional@example.com', 'password' => 'functional', 'reset' => null, 'remember_token' => null]);
|
||||
User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => 'james', 'reset' => null, 'remember_token' => null]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createAssetAccounts()
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
$assetType = AccountType::whereType('Asset account')->first();
|
||||
$ibType = AccountType::whereType('Initial balance account')->first();
|
||||
$obType = TransactionType::whereType('Opening balance')->first();
|
||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||
|
||||
|
||||
$acc_a = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Checking account', 'active' => 1]);
|
||||
$acc_b = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Savings account', 'active' => 1]);
|
||||
$acc_c = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Delete me', 'active' => 1]);
|
||||
|
||||
$acc_d = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Checking account initial balance', 'active' => 0]);
|
||||
$acc_e = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Savings account initial balance', 'active' => 0]);
|
||||
$acc_f = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Delete me initial balance', 'active' => 0]);
|
||||
|
||||
$this->createJournal(
|
||||
['from' => $acc_d, 'to' => $acc_a, 'amount' => 4000, 'transactionType' => $obType, 'description' => 'Initial Balance for Checking account',
|
||||
'date' => $this->yasom, 'transactionCurrency' => $euro]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $acc_e, 'to' => $acc_b, 'amount' => 10000, 'transactionType' => $obType, 'description' => 'Initial Balance for Savings account',
|
||||
'date' => $this->yasom, 'transactionCurrency' => $euro]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $acc_f, 'to' => $acc_c, 'amount' => 100, 'transactionType' => $obType, 'description' => 'Initial Balance for Delete me',
|
||||
'date' => $this->yasom, 'transactionCurrency' => $euro]
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function createJournal(array $data)
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
$billID = isset($data['bill']) ? $data['bill']->id : null;
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = TransactionJournal::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'transaction_type_id' => $data['transactionType']->id,
|
||||
'transaction_currency_id' => $data['transactionCurrency']->id,
|
||||
'bill_id' => $billID,
|
||||
'description' => $data['description'],
|
||||
'completed' => 1,
|
||||
'date' => $data['date']
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(['account_id' => $data['from']->id, 'transaction_journal_id' => $journal->id, 'amount' => $data['amount'] * -1]);
|
||||
Transaction::create(['account_id' => $data['to']->id, 'transaction_journal_id' => $journal->id, 'amount' => $data['amount']]);
|
||||
|
||||
if (isset($data['budget'])) {
|
||||
$journal->budgets()->save($data['budget']);
|
||||
}
|
||||
if (isset($data['category'])) {
|
||||
$journal->categories()->save($data['category']);
|
||||
}
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createBudgets()
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
|
||||
$groceries = Budget::create(['user_id' => $user->id, 'name' => 'Groceries']);
|
||||
$bills = Budget::create(['user_id' => $user->id, 'name' => 'Bills']);
|
||||
$deleteMe = Budget::create(['user_id' => $user->id, 'name' => 'Delete me']);
|
||||
Budget::create(['user_id' => $user->id, 'name' => 'Budget without repetition']);
|
||||
$groceriesLimit = BudgetLimit::create(
|
||||
['startdate' => $this->som, 'amount' => 201, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $groceries->id]
|
||||
);
|
||||
$billsLimit = BudgetLimit::create(
|
||||
['startdate' => $this->som, 'amount' => 202, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $bills->id]
|
||||
);
|
||||
$deleteMeLimit = BudgetLimit::create(
|
||||
['startdate' => $this->som, 'amount' => 203, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $deleteMe->id]
|
||||
);
|
||||
|
||||
// and because we have no filters, some repetitions:
|
||||
LimitRepetition::create(['budget_limit_id' => $groceriesLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 201]);
|
||||
LimitRepetition::create(['budget_limit_id' => $billsLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 202]);
|
||||
LimitRepetition::create(['budget_limit_id' => $deleteMeLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 203]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createCategories()
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
Category::create(['user_id' => $user->id, 'name' => 'DailyGroceries']);
|
||||
Category::create(['user_id' => $user->id, 'name' => 'Lunch']);
|
||||
Category::create(['user_id' => $user->id, 'name' => 'House']);
|
||||
Category::create(['user_id' => $user->id, 'name' => 'Delete me']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createPiggyBanks()
|
||||
{
|
||||
// account
|
||||
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
|
||||
|
||||
// some dates
|
||||
$endDate = clone $this->_startOfMonth;
|
||||
$nextYear = clone $this->_startOfMonth;
|
||||
|
||||
$endDate->addMonths(4);
|
||||
$nextYear->addYear()->subDay();
|
||||
|
||||
$next = $nextYear->format('Y-m-d');
|
||||
$end = $endDate->format('Y-m-d');
|
||||
|
||||
// piggy bank
|
||||
$newCamera = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $savings->id,
|
||||
'name' => 'New camera',
|
||||
'targetamount' => 2000,
|
||||
'startdate' => $this->som,
|
||||
'targetdate' => null,
|
||||
'repeats' => 0,
|
||||
'rep_length' => null,
|
||||
'rep_every' => 0,
|
||||
'rep_times' => null,
|
||||
'reminder' => null,
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
'order' => 0,
|
||||
]
|
||||
);
|
||||
// and some events!
|
||||
PiggyBankEvent::create(['piggy_bank_id' => $newCamera->id, 'date' => $this->som, 'amount' => 100]);
|
||||
PiggyBankRepetition::create(['piggy_bank_id' => $newCamera->id, 'startdate' => $this->som, 'targetdate' => null, 'currentamount' => 100]);
|
||||
|
||||
|
||||
$newClothes = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $savings->id,
|
||||
'name' => 'New clothes',
|
||||
'targetamount' => 2000,
|
||||
'startdate' => $this->som,
|
||||
'targetdate' => $end,
|
||||
'repeats' => 0,
|
||||
'rep_length' => null,
|
||||
'rep_every' => 0,
|
||||
'rep_times' => null,
|
||||
'reminder' => null,
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
'order' => 0,
|
||||
]
|
||||
);
|
||||
|
||||
PiggyBankEvent::create(['piggy_bank_id' => $newClothes->id, 'date' => $this->som, 'amount' => 100]);
|
||||
PiggyBankRepetition::create(['piggy_bank_id' => $newClothes->id, 'startdate' => $this->som, 'targetdate' => $end, 'currentamount' => 100]);
|
||||
|
||||
// weekly reminder piggy bank
|
||||
$weekly = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $savings->id,
|
||||
'name' => 'Weekly reminder for clothes',
|
||||
'targetamount' => 2000,
|
||||
'startdate' => $this->som,
|
||||
'targetdate' => $next,
|
||||
'repeats' => 0,
|
||||
'rep_length' => null,
|
||||
'rep_every' => 0,
|
||||
'rep_times' => null,
|
||||
'reminder' => 'week',
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 1,
|
||||
'order' => 0,
|
||||
]
|
||||
);
|
||||
PiggyBankRepetition::create(['piggy_bank_id' => $weekly->id, 'startdate' => $this->som, 'targetdate' => $next, 'currentamount' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createReminders()
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
// for weekly piggy bank (clothes)
|
||||
$nextWeek = clone $this->_startOfMonth;
|
||||
$piggyBank = PiggyBank::whereName('New clothes')->orderBy('id', 'DESC')->first();
|
||||
$nextWeek->addWeek();
|
||||
$week = $nextWeek->format('Y-m-d');
|
||||
|
||||
Reminder::create(
|
||||
['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $week, 'active' => 1, 'notnow' => 0,
|
||||
'remindersable_id' => $piggyBank->id, 'remindersable_type' => 'PiggyBank']
|
||||
);
|
||||
|
||||
// a fake reminder::
|
||||
Reminder::create(
|
||||
['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $week, 'active' => 0, 'notnow' => 0, 'remindersable_id' => 40,
|
||||
'remindersable_type' => 'Transaction']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createRecurringTransactions()
|
||||
{
|
||||
// account
|
||||
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
|
||||
$recurring = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $savings->id,
|
||||
'name' => 'Nieuwe spullen',
|
||||
'targetamount' => 1000,
|
||||
'startdate' => $this->som,
|
||||
'targetdate' => $this->eom,
|
||||
'repeats' => 1,
|
||||
'rep_length' => 'month',
|
||||
'rep_every' => 0,
|
||||
'rep_times' => 0,
|
||||
'reminder' => 'month',
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 1,
|
||||
'order' => 0,
|
||||
]
|
||||
);
|
||||
PiggyBankRepetition::create(['piggy_bank_id' => $recurring->id, 'startdate' => $this->som, 'targetdate' => $this->eom, 'currentamount' => 0]);
|
||||
PiggyBankRepetition::create(
|
||||
['piggy_bank_id' => $recurring->id, 'startdate' => $this->nsom, 'targetdate' => $this->neom, 'currentamount' => 0]
|
||||
);
|
||||
Reminder::create(
|
||||
['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $this->neom, 'active' => 1, 'notnow' => 0,
|
||||
'remindersable_id' => $recurring->id, 'remindersable_type' => 'PiggyBank']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createBills()
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
// bill
|
||||
Bill::create(
|
||||
['user_id' => $user->id, 'name' => 'Rent', 'match' => 'rent,landlord', 'amount_min' => 700, 'amount_max' => 900, 'date' => $this->som,
|
||||
'active' => 1, 'automatch' => 1, 'repeat_freq' => 'monthly', 'skip' => 0,]
|
||||
);
|
||||
|
||||
// bill
|
||||
Bill::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'name' => 'Gas licht',
|
||||
'match' => 'no,match',
|
||||
'amount_min' => 500, 'amount_max' => 700,
|
||||
'date' => $this->som,
|
||||
'active' => 1, 'automatch' => 1,
|
||||
'repeat_freq' => 'monthly', 'skip' => 0,
|
||||
]
|
||||
);
|
||||
|
||||
// bill
|
||||
Bill::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'name' => 'Something something',
|
||||
'match' => 'mumble,mumble',
|
||||
'amount_min' => 500,
|
||||
'amount_max' => 700,
|
||||
'date' => $this->som,
|
||||
'active' => 0,
|
||||
'automatch' => 1,
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createExpenseAccounts()
|
||||
{
|
||||
//// create expenses for rent, utilities, water, TV, phone on the 1st of the month.
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
$expenseType = AccountType::whereType('Expense account')->first();
|
||||
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Land lord', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Utilities company', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Water company', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'TV company', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Phone agency', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Super savers', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Groceries House', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Lunch House', 'active' => 1]);
|
||||
|
||||
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Buy More', 'active' => 1]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createRevenueAccounts()
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
$revenueType = AccountType::whereType('Revenue account')->first();
|
||||
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Employer', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'IRS', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Second job employer', 'active' => 1]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*/
|
||||
public function createMonthlyExpenses(Carbon $date)
|
||||
{
|
||||
// get some objects from the database:
|
||||
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
|
||||
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
|
||||
$landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first();
|
||||
$utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first();
|
||||
$television = Account::whereName('TV company')->orderBy('id', 'DESC')->first();
|
||||
$phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first();
|
||||
$employer = Account::whereName('Employer')->orderBy('id', 'DESC')->first();
|
||||
$bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first();
|
||||
$house = Category::whereName('House')->orderBy('id', 'DESC')->first();
|
||||
$withdrawal = TransactionType::whereType('Withdrawal')->first();
|
||||
$deposit = TransactionType::whereType('Deposit')->first();
|
||||
$transfer = TransactionType::whereType('Transfer')->first();
|
||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||
$rentBill = Bill::where('name', 'Rent')->first();
|
||||
$cur = $date->format('Y-m-d');
|
||||
$formatted = $date->format('F Y');
|
||||
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $landLord, 'amount' => 800, 'transactionType' => $withdrawal, 'description' => 'Rent for ' . $formatted,
|
||||
'date' => $cur, 'transactionCurrency' => $euro, 'budget' => $bills, 'category' => $house, 'bill' => $rentBill]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $utilities, 'amount' => 150, 'transactionType' => $withdrawal, 'description' => 'Utilities for ' . $formatted,
|
||||
'date' => $cur, 'transactionCurrency' => $euro, 'budget' => $bills, 'category' => $house,]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $television, 'amount' => 50, 'transactionType' => $withdrawal, 'description' => 'TV for ' . $formatted,
|
||||
'date' => $cur, 'transactionCurrency' => $euro, 'budget' => $bills, 'category' => $house,]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $phone, 'amount' => 50, 'transactionType' => $withdrawal, 'description' => 'Phone bill for ' . $formatted,
|
||||
'date' => $cur, 'transactionCurrency' => $euro, 'budget' => $bills, 'category' => $house,]
|
||||
);
|
||||
|
||||
// two transactions. One without a budget, one without a category.
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $phone, 'amount' => 10, 'transactionType' => $withdrawal,
|
||||
'description' => 'Extra charges on phone bill for ' . $formatted, 'date' => $cur, 'transactionCurrency' => $euro, 'category' => $house]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $television, 'amount' => 5, 'transactionType' => $withdrawal,
|
||||
'description' => 'Extra charges on TV bill for ' . $formatted, 'date' => $cur, 'transactionCurrency' => $euro, 'budget' => $bills]
|
||||
);
|
||||
|
||||
// income from job:
|
||||
$this->createJournal(
|
||||
['from' => $employer, 'to' => $checking, 'amount' => rand(3500, 4000), 'transactionType' => $deposit, 'description' => 'Salary for ' . $formatted,
|
||||
'date' => $cur, 'transactionCurrency' => $euro]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $savings, 'amount' => 2000, 'transactionType' => $transfer,
|
||||
'description' => 'Salary to savings account in ' . $formatted, 'date' => $cur, 'transactionCurrency' => $euro]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*/
|
||||
public function createGroceries(Carbon $date)
|
||||
{
|
||||
// variables we need:
|
||||
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
|
||||
$shopOne = Account::whereName('Groceries House')->orderBy('id', 'DESC')->first();
|
||||
$shopTwo = Account::whereName('Super savers')->orderBy('id', 'DESC')->first();
|
||||
$lunchHouse = Account::whereName('Lunch House')->orderBy('id', 'DESC')->first();
|
||||
$lunch = Category::whereName('Lunch')->orderBy('id', 'DESC')->first();
|
||||
$daily = Category::whereName('DailyGroceries')->orderBy('id', 'DESC')->first();
|
||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||
$withdrawal = TransactionType::whereType('Withdrawal')->first();
|
||||
$groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
|
||||
|
||||
|
||||
$shops = [$shopOne, $shopTwo];
|
||||
|
||||
// create groceries and lunch (daily, between 5 and 10 euro).
|
||||
$mStart = clone $date;
|
||||
$mEnd = clone $date;
|
||||
$mEnd->endOfMonth();
|
||||
while ($mStart <= $mEnd) {
|
||||
$mFormat = $mStart->format('Y-m-d');
|
||||
$shop = $shops[rand(0, 1)];
|
||||
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $shop, 'amount' => (rand(500, 1000) / 100), 'transactionType' => $withdrawal, 'description' => 'Groceries',
|
||||
'date' => $mFormat, 'transactionCurrency' => $euro, 'category' => $daily, 'budget' => $groceries]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $lunchHouse, 'amount' => (rand(200, 600) / 100), 'transactionType' => $withdrawal, 'description' => 'Lunch',
|
||||
'date' => $mFormat, 'transactionCurrency' => $euro, 'category' => $lunch, 'budget' => $groceries]
|
||||
);
|
||||
|
||||
$mStart->addDay();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $date
|
||||
*/
|
||||
public function createBigExpense($date)
|
||||
{
|
||||
$date->addDays(12);
|
||||
$dollar = TransactionCurrency::whereCode('USD')->first();
|
||||
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
|
||||
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
|
||||
$buyMore = Account::whereName('Buy More')->orderBy('id', 'DESC')->first();
|
||||
$withdrawal = TransactionType::whereType('Withdrawal')->first();
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
|
||||
|
||||
// create some big expenses, move some money around.
|
||||
$amount = rand(500, 2000);
|
||||
|
||||
$one = $this->createJournal(
|
||||
['from' => $savings, 'to' => $checking, 'amount' => $amount, 'transactionType' => $withdrawal,
|
||||
'description' => 'Money for big expense in ' . $date->format('F Y'), 'date' => $date->format('Y-m-d'), 'transactionCurrency' => $dollar]
|
||||
);
|
||||
$two = $this->createJournal(
|
||||
['from' => $checking, 'to' => $buyMore, 'amount' => $amount, 'transactionType' => $withdrawal,
|
||||
'description' => 'Big expense in ' . $date->format('F Y'), 'date' => $date->format('Y-m-d'), 'transactionCurrency' => $dollar]
|
||||
);
|
||||
$group = TransactionGroup::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'relation' => 'balance'
|
||||
]
|
||||
);
|
||||
$group->transactionjournals()->save($one);
|
||||
$group->transactionjournals()->save($two);
|
||||
$group->save();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function createPiggyBankEvent()
|
||||
{
|
||||
// piggy bank event
|
||||
// add money to this piggy bank
|
||||
// create a piggy bank event to match:
|
||||
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
|
||||
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
|
||||
$transfer = TransactionType::whereType('Transfer')->first();
|
||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||
$groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
|
||||
$house = Category::whereName('House')->orderBy('id', 'DESC')->first();
|
||||
$piggyBank = PiggyBank::whereName('New camera')->orderBy('id', 'DESC')->first();
|
||||
$intoPiggy = $this->createJournal(
|
||||
['from' => $checking, 'to' => $savings, 'amount' => 100, 'transactionType' => $transfer, 'description' => 'Money for piggy',
|
||||
'date' => $this->yaeom, 'transactionCurrency' => $euro, 'category' => $house, 'budget' => $groceries]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $piggyBank->id,
|
||||
'transaction_journal_id' => $intoPiggy->id,
|
||||
'date' => $this->yaeom,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Class TransactionCurrencySeeder
|
||||
*/
|
||||
class TransactionCurrencySeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
DB::table('transaction_currencies')->delete();
|
||||
|
||||
TransactionCurrency::create(['code' => 'EUR','name' => 'Euro','symbol' => '€']);
|
||||
TransactionCurrency::create(['code' => 'USD','name' => 'US Dollar','symbol' => '$']);
|
||||
TransactionCurrency::create(['code' => 'HUF','name' => 'Hungarian forint','symbol' => 'Ft']);
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Class TransactionTypeSeeder
|
||||
*/
|
||||
class TransactionTypeSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
||||
DB::table('transaction_types')->delete();
|
||||
|
||||
TransactionType::create(['type' => 'Withdrawal']);
|
||||
TransactionType::create(['type' => 'Deposit']);
|
||||
TransactionType::create(['type' => 'Transfer']);
|
||||
TransactionType::create(['type' => 'Opening balance']);
|
||||
}
|
||||
|
||||
}
|
104
app/filters.php
104
app/filters.php
@ -1,104 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
App::before(
|
||||
function ($request) {
|
||||
|
||||
// put IP in session if not already there.
|
||||
|
||||
$reminders = [];
|
||||
|
||||
if (Auth::check()) {
|
||||
Filter::setSessionDateRange();
|
||||
Reminders::updateReminders();
|
||||
Steam::removeEmptyBudgetLimits();
|
||||
$reminders = Reminders::getReminders();
|
||||
}
|
||||
View::share('reminders', $reminders);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
App::after(
|
||||
function ($request, $response) {
|
||||
//
|
||||
}
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Filters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following filters are used to verify that the user of the current
|
||||
| session is logged into this application. The "basic" filter easily
|
||||
| integrates HTTP Basic authentication for quick, simple checking.
|
||||
|
|
||||
*/
|
||||
|
||||
Route::filter(
|
||||
'auth', function () {
|
||||
if (Auth::guest()) {
|
||||
if (Request::ajax()) {
|
||||
return Response::make('Unauthorized', 401);
|
||||
} else {
|
||||
return Redirect::guest('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Route::filter(
|
||||
'auth.basic', function () {
|
||||
return Auth::basic();
|
||||
}
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Guest Filter
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The "guest" filter is the counterpart of the authentication filters as
|
||||
| it simply checks that the current user is not logged in. A redirect
|
||||
| response will be issued if they are, which you may freely change.
|
||||
|
|
||||
*/
|
||||
|
||||
Route::filter(
|
||||
'guest', function () {
|
||||
if (Auth::check()) {
|
||||
return Redirect::to('/');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| CSRF Protection Filter
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The CSRF filter is responsible for protecting your application against
|
||||
| cross-site request forgery attacks. If this special token in a user
|
||||
| session does not match the one given in this request, we'll bail.
|
||||
|
|
||||
*/
|
||||
|
||||
Route::filter(
|
||||
'csrf', function () {
|
||||
if (Session::token() != Input::get('_token')) {
|
||||
throw new Illuminate\Session\TokenMismatchException;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Route::filter(
|
||||
'allow-register', function () {
|
||||
if (Config::get('auth.allow_register') !== true) {
|
||||
return View::make('error')->with('message', 'Not possible');
|
||||
}
|
||||
}
|
||||
);
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Pagination Language Lines
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following language lines are used by the paginator library to build
|
||||
| the simple pagination links. You are free to change them to anything
|
||||
| you want to customize your views to better match your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'previous' => '« Previous',
|
||||
|
||||
'next' => 'Next »',
|
||||
|
||||
];
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reminder Language Lines
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following language lines are the default lines which match reasons
|
||||
| that are given by the password broker for a password update attempt
|
||||
| has failed, such as for an invalid token or invalid new password.
|
||||
|
|
||||
*/
|
||||
|
||||
"password" => "Passwords must be at least six characters and match the confirmation.",
|
||||
|
||||
"user" => "We can't find a user with that e-mail address.",
|
||||
|
||||
"token" => "This password reset token is invalid.",
|
||||
|
||||
"sent" => "Password reminder sent!",
|
||||
|
||||
];
|
@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Validation Language Lines
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following language lines contain the default error messages used by
|
||||
| the validator class. Some of these rules have multiple versions such
|
||||
| as the size rules. Feel free to tweak each of these messages here.
|
||||
|
|
||||
*/
|
||||
|
||||
"accepted" => "The :attribute must be accepted.",
|
||||
"active_url" => "The :attribute is not a valid URL.",
|
||||
"after" => "The :attribute must be a date after :date.",
|
||||
"alpha" => "The :attribute may only contain letters.",
|
||||
"alpha_dash" => "The :attribute may only contain letters, numbers, and dashes.",
|
||||
"alpha_num" => "The :attribute may only contain letters and numbers.",
|
||||
"array" => "The :attribute must be an array.",
|
||||
"before" => "The :attribute must be a date before :date.",
|
||||
"between" => [
|
||||
"numeric" => "The :attribute must be between :min and :max.",
|
||||
"file" => "The :attribute must be between :min and :max kilobytes.",
|
||||
"string" => "The :attribute must be between :min and :max characters.",
|
||||
"array" => "The :attribute must have between :min and :max items.",
|
||||
],
|
||||
"confirmed" => "The :attribute confirmation does not match.",
|
||||
"date" => "The :attribute is not a valid date.",
|
||||
"date_format" => "The :attribute does not match the format :format.",
|
||||
"different" => "The :attribute and :other must be different.",
|
||||
"digits" => "The :attribute must be :digits digits.",
|
||||
"digits_between" => "The :attribute must be between :min and :max digits.",
|
||||
"email" => "The :attribute must be a valid email address.",
|
||||
"exists" => "The selected :attribute is invalid.",
|
||||
"image" => "The :attribute must be an image.",
|
||||
"in" => "The selected :attribute is invalid.",
|
||||
"integer" => "The :attribute must be an integer.",
|
||||
"ip" => "The :attribute must be a valid IP address.",
|
||||
"max" => [
|
||||
"numeric" => "The :attribute may not be greater than :max.",
|
||||
"file" => "The :attribute may not be greater than :max kilobytes.",
|
||||
"string" => "The :attribute may not be greater than :max characters.",
|
||||
"array" => "The :attribute may not have more than :max items.",
|
||||
],
|
||||
"mimes" => "The :attribute must be a file of type: :values.",
|
||||
"min" => [
|
||||
"numeric" => "The :attribute must be at least :min.",
|
||||
"file" => "The :attribute must be at least :min kilobytes.",
|
||||
"string" => "The :attribute must be at least :min characters.",
|
||||
"array" => "The :attribute must have at least :min items.",
|
||||
],
|
||||
"not_in" => "The selected :attribute is invalid.",
|
||||
"numeric" => "The :attribute must be a number.",
|
||||
"regex" => "The :attribute format is invalid.",
|
||||
"required" => "The :attribute field is required.",
|
||||
"required_if" => "The :attribute field is required when :other is :value.",
|
||||
"required_with" => "The :attribute field is required when :values is present.",
|
||||
"required_with_all" => "The :attribute field is required when :values is present.",
|
||||
"required_without" => "The :attribute field is required when :values is not present.",
|
||||
"required_without_all" => "The :attribute field is required when none of :values are present.",
|
||||
"same" => "The :attribute and :other must match.",
|
||||
"size" => [
|
||||
"numeric" => "The :attribute must be :size.",
|
||||
"file" => "The :attribute must be :size kilobytes.",
|
||||
"string" => "The :attribute must be :size characters.",
|
||||
"array" => "The :attribute must contain :size items.",
|
||||
],
|
||||
"unique" => "The :attribute has already been taken.",
|
||||
"url" => "The :attribute format is invalid.",
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Custom Validation Language Lines
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify custom validation messages for attributes using the
|
||||
| convention "attribute.rule" to name the lines. This makes it quick to
|
||||
| specify a specific custom language line for a given attribute rule.
|
||||
|
|
||||
*/
|
||||
|
||||
'custom' => [
|
||||
'attribute-name' => [
|
||||
'rule-name' => 'custom-message',
|
||||
],
|
||||
],
|
||||
'alphabasic' => 'The :attribute field must consist of basic alphanumeric characters.',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Custom Validation Attributes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following language lines are used to swap attribute place-holders
|
||||
| with something more reader friendly such as E-Mail Address instead
|
||||
| of "email". This simply helps us make messages a little cleaner.
|
||||
|
|
||||
*/
|
||||
|
||||
'attributes' => [],
|
||||
|
||||
];
|
@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Chart;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class Chart
|
||||
*
|
||||
* @package FireflyIII\Chart
|
||||
*/
|
||||
class Chart implements ChartInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getCategorySummary(Carbon $start, Carbon $end)
|
||||
{
|
||||
return \TransactionJournal::leftJoin(
|
||||
'transactions',
|
||||
function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('amount', '>', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
|
||||
)
|
||||
->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id')
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->before($end)
|
||||
->after($start)
|
||||
->where('transaction_types.type', 'Withdrawal')
|
||||
->groupBy('categories.id')
|
||||
->orderBy('sum', 'DESC')
|
||||
->get(['categories.id', 'categories.name', \DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBillsSummary(Carbon $start, Carbon $end)
|
||||
{
|
||||
return \Bill::
|
||||
leftJoin(
|
||||
'transaction_journals', function (JoinClause $join) use ($start, $end) {
|
||||
$join->on('bills.id', '=', 'transaction_journals.bill_id')
|
||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'));
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
->where('active', 1)
|
||||
->groupBy('bills.id')
|
||||
->get(
|
||||
['bills.id', 'bills.name', 'transaction_journals.description',
|
||||
'transaction_journals.encrypted',
|
||||
'transaction_journals.id as journalId',
|
||||
\DB::Raw('SUM(`bills`.`amount_min` + `bills`.`amount_max`) / 2 as `averageAmount`'),
|
||||
'transactions.amount AS actualAmount']
|
||||
);
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Chart;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface ChartInterface
|
||||
*
|
||||
* @package FireflyIII\Chart
|
||||
*/
|
||||
interface ChartInterface
|
||||
{
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getCategorySummary(Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBillsSummary(Carbon $start, Carbon $end);
|
||||
|
||||
}
|
@ -1,179 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Collection;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class PiggyBankPart
|
||||
*
|
||||
* @package FireflyIII\Collection
|
||||
*/
|
||||
class PiggyBankPart
|
||||
{
|
||||
/** @var float */
|
||||
public $amountPerBar;
|
||||
/** @var float */
|
||||
public $cumulativeAmount;
|
||||
/** @var float */
|
||||
public $currentamount;
|
||||
/** @var \Reminder */
|
||||
public $reminder;
|
||||
|
||||
/** @var \PiggyBankRepetition */
|
||||
public $repetition;
|
||||
|
||||
/** @var Carbon */
|
||||
public $startdate;
|
||||
|
||||
/** @var Carbon */
|
||||
public $targetdate;
|
||||
|
||||
/**
|
||||
* @return \Reminder
|
||||
*/
|
||||
public function getReminder()
|
||||
{
|
||||
if (is_null($this->reminder)) {
|
||||
$this->reminder = $this->repetition->piggyBank->reminders()->where('startdate', $this->getStartdate()->format('Y-m-d'))->where(
|
||||
'enddate', $this->getTargetdate()->format('Y-m-d')
|
||||
)->first();
|
||||
}
|
||||
|
||||
return $this->reminder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Reminder $reminder
|
||||
*/
|
||||
public function setReminder($reminder)
|
||||
{
|
||||
$this->reminder = $reminder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getStartdate()
|
||||
{
|
||||
return $this->startdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $startdate
|
||||
*/
|
||||
public function setStartdate($startdate)
|
||||
{
|
||||
$this->startdate = $startdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getTargetdate()
|
||||
{
|
||||
return $this->targetdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $targetdate
|
||||
*/
|
||||
public function setTargetdate($targetdate)
|
||||
{
|
||||
$this->targetdate = $targetdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \PiggyBankRepetition
|
||||
*/
|
||||
public function getRepetition()
|
||||
{
|
||||
return $this->repetition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \PiggyBankRepetition $repetition
|
||||
*/
|
||||
public function setRepetition($repetition)
|
||||
{
|
||||
$this->repetition = $repetition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasReminder()
|
||||
{
|
||||
return !is_null($this->reminder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float|int
|
||||
*/
|
||||
public function percentage()
|
||||
{
|
||||
if ($this->getCurrentamount() < $this->getCumulativeAmount()) {
|
||||
$pct = 0;
|
||||
// calculate halfway point?
|
||||
if ($this->getCumulativeAmount() - $this->getCurrentamount() < $this->getAmountPerBar()) {
|
||||
$left = $this->getCurrentamount() % $this->getAmountPerBar();
|
||||
$pct = round($left / $this->getAmountPerBar() * 100);
|
||||
}
|
||||
|
||||
return $pct;
|
||||
} else {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getCurrentamount()
|
||||
{
|
||||
return $this->currentamount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $currentamount
|
||||
*/
|
||||
public function setCurrentamount($currentamount)
|
||||
{
|
||||
$this->currentamount = $currentamount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getCumulativeAmount()
|
||||
{
|
||||
return $this->cumulativeAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $cumulativeAmount
|
||||
*/
|
||||
public function setCumulativeAmount($cumulativeAmount)
|
||||
{
|
||||
$this->cumulativeAmount = $cumulativeAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getAmountPerBar()
|
||||
{
|
||||
return $this->amountPerBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $amountPerBar
|
||||
*/
|
||||
public function setAmountPerBar($amountPerBar)
|
||||
{
|
||||
$this->amountPerBar = $amountPerBar;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,534 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\CommonDatabaseCallsInterface;
|
||||
use FireflyIII\Database\CUDInterface;
|
||||
use FireflyIII\Database\SwitchUser;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* Class Account
|
||||
*
|
||||
* @package FireflyIII\Database
|
||||
* @implements FireflyIII\Database\Account\AccountInterface
|
||||
*/
|
||||
class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInterface
|
||||
{
|
||||
use SwitchUser;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setUser(\Auth::user());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countAccountsByType(array $types)
|
||||
{
|
||||
return $this->getUser()->accounts()->accountTypeIn($types)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAccountsByType(array $types)
|
||||
{
|
||||
/*
|
||||
* Basic query:
|
||||
*/
|
||||
$query = $this->getUser()->accounts()->accountTypeIn($types)->withMeta()->orderBy('name', 'ASC');;
|
||||
$set = $query->get(['accounts.*', 'account_meta.data as accountRole']);
|
||||
|
||||
$set->each(
|
||||
function (\Account $account) {
|
||||
/*
|
||||
* Get last activity date.
|
||||
*/
|
||||
$account->lastActivityDate = $this->getLastActivity($account);
|
||||
$account->accountRole = \Config::get('firefly.accountRoles.' . json_decode($account->accountRole));
|
||||
}
|
||||
);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
*
|
||||
* @return \TransactionJournal|null
|
||||
*/
|
||||
public function openingBalanceTransaction(\Account $account)
|
||||
{
|
||||
|
||||
$first = \TransactionJournal::withRelevantData()->accountIs($account)
|
||||
->orderBy('transaction_journals.date', 'ASC')
|
||||
->orderBy('created_at', 'ASC')
|
||||
->first(['transaction_journals.*']);
|
||||
$initial = strpos(strtolower($first->description), 'initial');
|
||||
$opening = strpos(strtolower($first->description), 'opening');
|
||||
if ($initial === false && $opening === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $first;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function storeInitialBalance(\Account $account, array $data)
|
||||
{
|
||||
/** @var \FireflyIII\Database\TransactionType\TransactionType $typeRepository */
|
||||
$typeRepository = \App::make('FireflyIII\Database\TransactionType\TransactionType');
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $journals */
|
||||
$journals = \App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
|
||||
|
||||
// some initial variables:
|
||||
$balance = floatval($data['openingBalance']);
|
||||
$date = new Carbon($data['openingBalanceDate']);
|
||||
|
||||
// some dynamic variables:
|
||||
if ($balance < 0) {
|
||||
$opposingType = 'expense';
|
||||
$transactionType = $typeRepository->findByWhat('withdrawal');
|
||||
$toAccount = $this->store(['name' => $account->name . ' Initial Balance Account', 'active' => 1, 'what' => $opposingType]);
|
||||
$fromAccount = $account;
|
||||
} else {
|
||||
$opposingType = 'revenue';
|
||||
$transactionType = $typeRepository->findByWhat('deposit');
|
||||
$fromAccount = $this->store(['name' => $account->name . ' Initial Balance Account', 'active' => 1, 'what' => $opposingType]);
|
||||
$toAccount = $account;
|
||||
}
|
||||
|
||||
// data for transaction journal:
|
||||
$balance = $balance < 0 ? $balance * -1 : $balance;
|
||||
$currency = $journals->getJournalCurrencyById(intval($data['balance_currency_id']));
|
||||
$opening = [
|
||||
'transaction_type_id' => $transactionType->id,
|
||||
'transaction_currency_id' => $currency->id,
|
||||
'amount' => $balance,
|
||||
'what' => 'opening',
|
||||
'from' => $fromAccount,
|
||||
'completed' => 0,
|
||||
'to' => $toAccount,
|
||||
'date' => $date,
|
||||
'description' => 'Opening balance for new account ' . $account->name
|
||||
];
|
||||
|
||||
$validation = $journals->validate($opening);
|
||||
if ($validation['errors']->count() == 0) {
|
||||
$journals->store($opening);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
\Log::error('Initial balance created is not valid (Database/Account)');
|
||||
\Log::error($validation['errors']->all());
|
||||
\App::abort(500);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLastActivity(\Account $account)
|
||||
{
|
||||
$lastActivityKey = 'account.' . $account->id . '.lastActivityDate';
|
||||
if (\Cache::has($lastActivityKey)) {
|
||||
return \Cache::get($lastActivityKey);
|
||||
}
|
||||
|
||||
$transaction = $account->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->orderBy('transaction_journals.date', 'DESC')->first();
|
||||
if ($transaction) {
|
||||
$date = $transaction->transactionJournal->date;
|
||||
} else {
|
||||
$date = 0;
|
||||
}
|
||||
\Cache::forever($lastActivityKey, $date);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot make it shorter because of query.
|
||||
* @param Eloquent $model
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(Eloquent $model)
|
||||
{
|
||||
$journals = \TransactionJournal::whereIn(
|
||||
'id', function (QueryBuilder $query) use ($model) {
|
||||
$query->select('transaction_journal_id')
|
||||
->from('transactions')
|
||||
->whereIn(
|
||||
'account_id', function (QueryBuilder $query) use ($model) {
|
||||
$query
|
||||
->select('accounts.id')
|
||||
->from('accounts')
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->where(
|
||||
function (QueryBuilder $q) use ($model) {
|
||||
$q->where('accounts.id', $model->id);
|
||||
$q->orWhere(
|
||||
function (QueryBuilder $q) use ($model) {
|
||||
$q->where('accounts.name', 'LIKE', '%' . $model->name . '%');
|
||||
$q->where('account_types.type', 'Initial balance account');
|
||||
$q->where('accounts.active', 0);
|
||||
}
|
||||
);
|
||||
}
|
||||
)->where('accounts.user_id', $this->getUser()->id);
|
||||
}
|
||||
)->get();
|
||||
}
|
||||
)->get();
|
||||
$transactions = [];
|
||||
/** @var \TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
/** @var \Transaction $t */
|
||||
foreach ($journal->transactions as $t) {
|
||||
$transactions[] = intval($t->id);
|
||||
}
|
||||
$journal->delete();
|
||||
}
|
||||
if (count($transactions) > 0) {
|
||||
\Transaction::whereIn('id', $transactions)->delete();
|
||||
}
|
||||
\Event::fire('account.destroy', [$model]);
|
||||
|
||||
// get account type:
|
||||
/** @var \FireflyIII\Database\AccountType\AccountType $acctType */
|
||||
$acctType = \App::make('FireflyIII\Database\AccountType\AccountType');
|
||||
|
||||
$accountType = $acctType->findByWhat('initial');
|
||||
|
||||
//$q->where('account_types.type', '');
|
||||
|
||||
\Account::where(
|
||||
function (EloquentBuilder $q) use ($model, $accountType) {
|
||||
$q->where('id', $model->id);
|
||||
$q->orWhere(
|
||||
function (EloquentBuilder $q) use ($model, $accountType) {
|
||||
$q->where('accounts.name', 'LIKE', '%' . $model->name . '%');
|
||||
$q->where('accounts.account_type_id', $accountType->id);
|
||||
$q->where('accounts.active', 0);
|
||||
}
|
||||
);
|
||||
}
|
||||
)->delete();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Eloquent
|
||||
*/
|
||||
public function store(array $data)
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Database\AccountType\AccountType $acctType */
|
||||
$acctType = \App::make('FireflyIII\Database\AccountType\AccountType');
|
||||
|
||||
$accountType = $acctType->findByWhat($data['what']);
|
||||
|
||||
$data['user_id'] = $this->getUser()->id;
|
||||
$data['account_type_id'] = $accountType->id;
|
||||
$data['active'] = isset($data['active']) && intval($data['active']) === 1 ? 1 : 0;
|
||||
|
||||
$data = array_except($data, ['_token', 'what']);
|
||||
$account = new \Account($data);
|
||||
if (!$account->isValid()) {
|
||||
\Log::error('Account created is not valid (Database/Account)');
|
||||
\Log::error($account->getErrors()->all());
|
||||
\App::abort(500);
|
||||
}
|
||||
$account->save();
|
||||
if (isset($data['openingBalance']) && floatval($data['openingBalance']) != 0) {
|
||||
$this->storeInitialBalance($account, $data);
|
||||
}
|
||||
|
||||
switch ($account->accountType->type) {
|
||||
case 'Asset account':
|
||||
case 'Default account':
|
||||
$account->updateMeta('accountRole', $data['account_role']);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Tell transaction journal to store a new one.*/
|
||||
\Event::fire('account.store', [$account]);
|
||||
|
||||
|
||||
return $account;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Eloquent $model
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update(Eloquent $model, array $data)
|
||||
{
|
||||
$model->name = $data['name'];
|
||||
$model->active = isset($data['active']) ? intval($data['active']) : 0;
|
||||
|
||||
switch ($model->accountType->type) {
|
||||
case 'Asset account':
|
||||
case 'Default account':
|
||||
$model->updateMeta('accountRole', $data['account_role']);
|
||||
break;
|
||||
}
|
||||
|
||||
$model->save();
|
||||
|
||||
if (isset($data['openingBalance']) && isset($data['openingBalanceDate']) && strlen($data['openingBalanceDate']) > 0) {
|
||||
$this->updateInitialBalance($model, $data);
|
||||
|
||||
}
|
||||
\Event::fire('account.update', [$model]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a model. Returns an array containing MessageBags
|
||||
* errors/warnings/successes.
|
||||
*
|
||||
* @param array $model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function validate(array $model)
|
||||
{
|
||||
$model['active'] = !isset($model['active']) ? false : $model['active'];
|
||||
$successes = new MessageBag;
|
||||
$account = new \Account($model);
|
||||
$account->isValid('form_input', false);
|
||||
$errors = $account->getErrors();
|
||||
|
||||
if (isset($model['account_role']) && !in_array($model['account_role'], array_keys(\Config::get('firefly.accountRoles')))) {
|
||||
$errors->add('account_role', 'Invalid account role');
|
||||
}
|
||||
/*
|
||||
* Opening balance and opening balance date.
|
||||
*/
|
||||
if (isset($model['what']) && $model['what'] == 'asset') {
|
||||
if (isset($model['openingBalance']) && strlen($model['openingBalance']) > 0 && !is_numeric($model['openingBalance'])) {
|
||||
$errors->add('openingBalance', 'This is not a number.');
|
||||
}
|
||||
if (isset($model['openingBalanceDate']) && strlen($model['openingBalanceDate']) > 0) {
|
||||
try {
|
||||
new Carbon($model['openingBalanceDate']);
|
||||
} catch (\Exception $e) {
|
||||
$errors->add('openingBalanceDate', 'This date is invalid.');
|
||||
}
|
||||
}
|
||||
}
|
||||
$fields = ['name', 'openingBalance', 'openingBalanceDate', 'active', 'account_role'];
|
||||
foreach ($fields as $field) {
|
||||
if (!$errors->has($field)) {
|
||||
$successes->add($field, 'OK');
|
||||
}
|
||||
}
|
||||
|
||||
return ['errors' => $errors, 'successes' => $successes];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Eloquent $model
|
||||
* @param array $data
|
||||
*/
|
||||
public function updateInitialBalance(Eloquent $model, array $data)
|
||||
{
|
||||
/** @noinspection PhpParamsInspection */
|
||||
$openingBalance = $this->openingBalanceTransaction($model);
|
||||
if (is_null($openingBalance)) {
|
||||
$this->storeInitialBalance($model, $data);
|
||||
} else {
|
||||
$openingBalance->date = new Carbon($data['openingBalanceDate']);
|
||||
$openingBalance->save();
|
||||
$amount = floatval($data['openingBalance']);
|
||||
/** @var \Transaction $transaction */
|
||||
foreach ($openingBalance->transactions as $transaction) {
|
||||
if ($transaction->account_id == $model->id) {
|
||||
$transaction->amount = $amount;
|
||||
} else {
|
||||
$transaction->amount = $amount * -1;
|
||||
}
|
||||
$transaction->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object with id $id.
|
||||
*
|
||||
* @param int $objectId
|
||||
*
|
||||
* @return \Eloquent
|
||||
*/
|
||||
public function find($objectId)
|
||||
{
|
||||
return $this->getUser()->accounts()->find($objectId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param $what
|
||||
*
|
||||
* @throws NotImplementedException
|
||||
* @return \AccountType|null
|
||||
*/
|
||||
public function findByWhat($what)
|
||||
{
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all objects.
|
||||
*
|
||||
* @return Collection
|
||||
* @throws NotImplementedException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getByIds(array $ids)
|
||||
{
|
||||
return $this->getUser()->accounts()->whereIn('id', $ids)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return static
|
||||
* @throws \FireflyIII\Exception\FireflyException
|
||||
*/
|
||||
public function firstExpenseAccountOrCreate($name)
|
||||
{
|
||||
/** @var \FireflyIII\Database\AccountType\AccountType $typeRepository */
|
||||
$typeRepository = \App::make('FireflyIII\Database\AccountType\AccountType');
|
||||
|
||||
$accountType = $typeRepository->findByWhat('expense');
|
||||
|
||||
// if name is "", find cash account:
|
||||
if (strlen($name) == 0) {
|
||||
$cashAccountType = $typeRepository->findByWhat('cash');
|
||||
|
||||
// find or create cash account:
|
||||
return \Account::firstOrCreate(
|
||||
['name' => 'Cash account', 'account_type_id' => $cashAccountType->id, 'active' => 0, 'user_id' => $this->getUser()->id,]
|
||||
);
|
||||
}
|
||||
|
||||
$data = ['user_id' => $this->getUser()->id, 'account_type_id' => $accountType->id, 'name' => $name, 'active' => 1];
|
||||
|
||||
return \Account::firstOrCreate($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return static
|
||||
* @throws \FireflyIII\Exception\FireflyException
|
||||
*/
|
||||
public function firstRevenueAccountOrCreate($name)
|
||||
{
|
||||
/** @var \FireflyIII\Database\AccountType\AccountType $typeRepository */
|
||||
$typeRepository = \App::make('FireflyIII\Database\AccountType\AccountType');
|
||||
|
||||
$accountType = $typeRepository->findByWhat('revenue');
|
||||
|
||||
// if name is "", find cash account:
|
||||
if (strlen($name) == 0) {
|
||||
$cashAccountType = $typeRepository->findByWhat('cash');
|
||||
|
||||
// find or create cash account:
|
||||
return \Account::firstOrCreate(
|
||||
['name' => 'Cash account', 'account_type_id' => $cashAccountType->id, 'active' => 0, 'user_id' => $this->getUser()->id,]
|
||||
);
|
||||
}
|
||||
|
||||
$data = ['user_id' => $this->getUser()->id, 'account_type_id' => $accountType->id, 'name' => $name, 'active' => 1];
|
||||
|
||||
return \Account::firstOrCreate($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param int $limit
|
||||
* @param string $range
|
||||
*
|
||||
* @return \Illuminate\Pagination\Paginator
|
||||
*/
|
||||
public function getTransactionJournals(\Account $account, $limit = 50, $range = 'session')
|
||||
{
|
||||
$offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0;
|
||||
$items = [];
|
||||
$query = $this->getUser()
|
||||
->transactionJournals()
|
||||
->withRelevantData()
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->orderBy('date', 'DESC');
|
||||
|
||||
if ($range == 'session') {
|
||||
$query->before(\Session::get('end', Carbon::now()->startOfMonth()));
|
||||
$query->after(\Session::get('start', Carbon::now()->startOfMonth()));
|
||||
}
|
||||
$count = $query->count();
|
||||
$set = $query->take($limit)->offset($offset)->get(['transaction_journals.*']);
|
||||
|
||||
foreach ($set as $entry) {
|
||||
$items[] = $entry;
|
||||
}
|
||||
|
||||
return \Paginator::make($items, $count, $limit);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user