mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code clean up.
This commit is contained in:
parent
4164ebcc69
commit
bd818b2dea
@ -70,9 +70,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
|
|||||||
Log::debug('Build new report.');
|
Log::debug('Build new report.');
|
||||||
// build a balance header:
|
// build a balance header:
|
||||||
$header = new BalanceHeader;
|
$header = new BalanceHeader;
|
||||||
$budgets = $this->budgetRepository->getBudgets();
|
|
||||||
$limitRepetitions = $this->budgetRepository->getAllBudgetLimitRepetitions($start, $end);
|
$limitRepetitions = $this->budgetRepository->getAllBudgetLimitRepetitions($start, $end);
|
||||||
$spentData = $this->budgetRepository->journalsInPeriod($budgets, $accounts, $start, $end);
|
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$header->addAccount($account);
|
$header->addAccount($account);
|
||||||
Log::debug('Add account #' . $account->id . ' to header.');
|
Log::debug('Add account #' . $account->id . ' to header.');
|
||||||
|
@ -54,7 +54,6 @@ class BudgetReportHelper implements BudgetReportHelperInterface
|
|||||||
// spent for budget in time range:
|
// spent for budget in time range:
|
||||||
$spent = $repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end);
|
$spent = $repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end);
|
||||||
|
|
||||||
// $spent = array_sum($totalSpent);
|
|
||||||
if ($spent > 0) {
|
if ($spent > 0) {
|
||||||
$budgetLine = new BudgetLine;
|
$budgetLine = new BudgetLine;
|
||||||
$budgetLine->setBudget($budget);
|
$budgetLine->setBudget($budget);
|
||||||
|
@ -180,8 +180,8 @@ class BudgetController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Do some cleanup:
|
* Do some cleanup:
|
||||||
|
* TODO reimplement the deletion of budget_limits and limit_repetitions with amount 0
|
||||||
*/
|
*/
|
||||||
// $repository->cleanupBudgets();
|
|
||||||
|
|
||||||
// loop the budgets:
|
// loop the budgets:
|
||||||
/** @var Budget $budget */
|
/** @var Budget $budget */
|
||||||
|
@ -9,7 +9,6 @@ use FireflyIII\Http\Controllers\Controller;
|
|||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\Models\LimitRepetition;
|
use FireflyIII\Models\LimitRepetition;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@ -110,7 +109,7 @@ class BudgetController extends Controller
|
|||||||
$cache->addProperty($repetition->id);
|
$cache->addProperty($repetition->id);
|
||||||
|
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get());
|
return Response::json($cache->get());
|
||||||
}
|
}
|
||||||
|
|
||||||
$entries = new Collection;
|
$entries = new Collection;
|
||||||
@ -135,11 +134,9 @@ class BudgetController extends Controller
|
|||||||
*
|
*
|
||||||
* @param BudgetRepositoryInterface $repository
|
* @param BudgetRepositoryInterface $repository
|
||||||
*
|
*
|
||||||
* @param ARI $accountRepository
|
|
||||||
*
|
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function frontpage(BudgetRepositoryInterface $repository, ARI $accountRepository)
|
public function frontpage(BudgetRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
$start = session('start', Carbon::now()->startOfMonth());
|
$start = session('start', Carbon::now()->startOfMonth());
|
||||||
$end = session('end', Carbon::now()->endOfMonth());
|
$end = session('end', Carbon::now()->endOfMonth());
|
||||||
|
@ -151,10 +151,6 @@ class HomeController extends Controller
|
|||||||
{
|
{
|
||||||
// these routes are not relevant for the help pages:
|
// these routes are not relevant for the help pages:
|
||||||
$ignore = [
|
$ignore = [
|
||||||
// 'logout', 'register', 'bills.rescan', 'attachments.download', 'attachments.preview',
|
|
||||||
// 'budgets.income', 'csv.download-config', 'currency.default', 'export.status', 'export.download',
|
|
||||||
// 'json.', 'help.', 'piggy-banks.addMoney', 'piggy-banks.removeMoney', 'rules.rule.up', 'rules.rule.down',
|
|
||||||
// 'rules.rule-group.up', 'rules.rule-group.down', 'debugbar',
|
|
||||||
];
|
];
|
||||||
$routes = Route::getRoutes();
|
$routes = Route::getRoutes();
|
||||||
/** @var \Illuminate\Routing\Route $route */
|
/** @var \Illuminate\Routing\Route $route */
|
||||||
|
@ -113,13 +113,11 @@ class TagController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Tag $tag
|
* @param Tag $tag
|
||||||
*
|
|
||||||
* @param TagRepositoryInterface $repository
|
|
||||||
*
|
*
|
||||||
* @return \Illuminate\View\View
|
* @return \Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function edit(Tag $tag, TagRepositoryInterface $repository)
|
public function edit(Tag $tag)
|
||||||
{
|
{
|
||||||
$subTitle = trans('firefly.edit_tag', ['tag' => $tag->tag]);
|
$subTitle = trans('firefly.edit_tag', ['tag' => $tag->tag]);
|
||||||
$subTitleIcon = 'fa-tag';
|
$subTitleIcon = 'fa-tag';
|
||||||
|
@ -82,7 +82,6 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function earnedInPeriod(Collection $accounts, Carbon $start, Carbon $end): string
|
public function earnedInPeriod(Collection $accounts, Carbon $start, Carbon $end): string
|
||||||
{
|
{
|
||||||
Log::debug('earnedinperiod');
|
|
||||||
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
|
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
|
||||||
$sum = bcmul($this->sumInPeriod($accounts, $types, $start, $end), '-1');
|
$sum = bcmul($this->sumInPeriod($accounts, $types, $start, $end), '-1');
|
||||||
|
|
||||||
@ -438,7 +437,6 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function spentInPeriod(Collection $accounts, Carbon $start, Carbon $end): string
|
public function spentInPeriod(Collection $accounts, Carbon $start, Carbon $end): string
|
||||||
{
|
{
|
||||||
Log::debug('spentinperiod');
|
|
||||||
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
||||||
$sum = $this->sumInPeriod($accounts, $types, $start, $end);
|
$sum = $this->sumInPeriod($accounts, $types, $start, $end);
|
||||||
|
|
||||||
@ -757,7 +755,6 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
$second = strval($query->sum('t.amount'));
|
$second = strval($query->sum('t.amount'));
|
||||||
$sum = bcadd($first, $second);
|
$sum = bcadd($first, $second);
|
||||||
|
|
||||||
Log::debug('SumInPeriodData ', ['accounts' => $accountIds, 'first' => $first, 'second' => $second, 'sum' => $sum]);
|
|
||||||
|
|
||||||
return $sum;
|
return $sum;
|
||||||
}
|
}
|
||||||
|
@ -205,8 +205,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
// get them:
|
// get them:
|
||||||
$journals = $journalQuery->get(TransactionJournal::queryFields());
|
$journals = $journalQuery->get(TransactionJournal::queryFields());
|
||||||
|
|
||||||
//Log::debug('journalsInPeriod journal count is ' . $journals->count());
|
|
||||||
|
|
||||||
// then get transactions themselves.
|
// then get transactions themselves.
|
||||||
$transactionQuery = $this->user->transactionjournals()
|
$transactionQuery = $this->user->transactionjournals()
|
||||||
->expanded()
|
->expanded()
|
||||||
|
@ -198,9 +198,6 @@ class CategoryRepository implements CategoryRepositoryInterface
|
|||||||
);
|
);
|
||||||
// create paginator
|
// create paginator
|
||||||
$offset = ($page - 1) * $pageSize;
|
$offset = ($page - 1) * $pageSize;
|
||||||
Log::debug('Page is ' . $page);
|
|
||||||
Log::debug('Offset is ' . $offset);
|
|
||||||
Log::debug('pagesize is ' . $pageSize);
|
|
||||||
$subSet = $complete->slice($offset, $pageSize)->all();
|
$subSet = $complete->slice($offset, $pageSize)->all();
|
||||||
$paginator = new LengthAwarePaginator($subSet, $complete->count(), $pageSize, $page);
|
$paginator = new LengthAwarePaginator($subSet, $complete->count(), $pageSize, $page);
|
||||||
|
|
||||||
@ -343,7 +340,6 @@ class CategoryRepository implements CategoryRepositoryInterface
|
|||||||
|
|
||||||
/** @var TransactionJournal $first */
|
/** @var TransactionJournal $first */
|
||||||
$lastJournalQuery = $category->transactionjournals()->orderBy('date', 'DESC');
|
$lastJournalQuery = $category->transactionjournals()->orderBy('date', 'DESC');
|
||||||
Log::debug('lastUseDate ' . $category->name . ' (' . $category->id . ')');
|
|
||||||
|
|
||||||
if ($accounts->count() > 0) {
|
if ($accounts->count() > 0) {
|
||||||
// filter journals:
|
// filter journals:
|
||||||
@ -356,7 +352,6 @@ class CategoryRepository implements CategoryRepositoryInterface
|
|||||||
|
|
||||||
if ($lastJournal) {
|
if ($lastJournal) {
|
||||||
$last = $lastJournal->date;
|
$last = $lastJournal->date;
|
||||||
Log::debug('last is now ' . $last);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check transactions:
|
// check transactions:
|
||||||
@ -371,8 +366,6 @@ class CategoryRepository implements CategoryRepositoryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$lastTransaction = $lastTransactionQuery->first(['transaction_journals.*']);
|
$lastTransaction = $lastTransactionQuery->first(['transaction_journals.*']);
|
||||||
if (!is_null($lastTransaction)) {
|
|
||||||
}
|
|
||||||
if (!is_null($lastTransaction) && ((!is_null($last) && $lastTransaction->date < $last) || is_null($last))) {
|
if (!is_null($lastTransaction) && ((!is_null($last) && $lastTransaction->date < $last) || is_null($last))) {
|
||||||
$last = new Carbon($lastTransaction->date);
|
$last = new Carbon($lastTransaction->date);
|
||||||
}
|
}
|
||||||
|
@ -122,11 +122,9 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
$entry = $this->user->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
|
$entry = $this->user->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
|
||||||
|
|
||||||
if (is_null($entry)) {
|
if (is_null($entry)) {
|
||||||
Log::debug('Could not find first transaction journal.');
|
|
||||||
|
|
||||||
return new TransactionJournal;
|
return new TransactionJournal;
|
||||||
}
|
}
|
||||||
Log::debug('Found first journal: ', ['date' => $entry->date->format('Y-m-d')]);
|
|
||||||
|
|
||||||
return $entry;
|
return $entry;
|
||||||
}
|
}
|
||||||
@ -145,8 +143,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
if (count($types) > 0) {
|
if (count($types) > 0) {
|
||||||
$query->transactionTypes($types);
|
$query->transactionTypes($types);
|
||||||
}
|
}
|
||||||
$count = $this->user->transactionJournals()->transactionTypes($types)->count();
|
$count = $this->user->transactionJournals()->transactionTypes($types)->count();
|
||||||
Log::debug('getJournals() count: ' . $count);
|
|
||||||
$set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::queryFields());
|
$set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::queryFields());
|
||||||
$journals = new LengthAwarePaginator($set, $count, $pageSize, $page);
|
$journals = new LengthAwarePaginator($set, $count, $pageSize, $page);
|
||||||
|
|
||||||
@ -205,7 +202,6 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
*/
|
||||||
public function getTransactions(TransactionJournal $journal): Collection
|
public function getTransactions(TransactionJournal $journal): Collection
|
||||||
{
|
{
|
||||||
@ -231,8 +227,8 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
|
|
||||||
/** @var Collection $transactions */
|
/** @var Collection $transactions */
|
||||||
$transactions = $journal->transactions()
|
$transactions = $journal->transactions()
|
||||||
->groupBy('transactions.id')
|
->groupBy('transactions.id')
|
||||||
->orderBy('transactions.id')->get(
|
->orderBy('transactions.id')->get(
|
||||||
['transactions.*', DB::raw('SUM(`transactions`.`amount`) as `sum`')]
|
['transactions.*', DB::raw('SUM(`transactions`.`amount`) as `sum`')]
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@ -253,10 +249,6 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
);
|
);
|
||||||
$transactions->push($final);
|
$transactions->push($final);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
|
|
||||||
throw new FireflyException('Cannot handle ' . $journal->transactionType->type);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
// foreach do balance thing
|
// foreach do balance thing
|
||||||
$transactions->each(
|
$transactions->each(
|
||||||
@ -469,27 +461,22 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
{
|
{
|
||||||
$sourceAccount = null;
|
$sourceAccount = null;
|
||||||
$destinationAccount = null;
|
$destinationAccount = null;
|
||||||
Log::debug('Now in storeAccounts()');
|
|
||||||
switch ($type->type) {
|
switch ($type->type) {
|
||||||
case TransactionType::WITHDRAWAL:
|
case TransactionType::WITHDRAWAL:
|
||||||
Log::debug('Now in storeAccounts()::withdrawal');
|
|
||||||
list($sourceAccount, $destinationAccount) = $this->storeWithdrawalAccounts($data);
|
list($sourceAccount, $destinationAccount) = $this->storeWithdrawalAccounts($data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TransactionType::DEPOSIT:
|
case TransactionType::DEPOSIT:
|
||||||
Log::debug('Now in storeAccounts()::deposit');
|
|
||||||
list($sourceAccount, $destinationAccount) = $this->storeDepositAccounts($data);
|
list($sourceAccount, $destinationAccount) = $this->storeDepositAccounts($data);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case TransactionType::TRANSFER:
|
case TransactionType::TRANSFER:
|
||||||
Log::debug('Now in storeAccounts()::transfer');
|
|
||||||
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first();
|
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first();
|
||||||
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first();
|
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new FireflyException('Did not recognise transaction type.');
|
throw new FireflyException('Did not recognise transaction type.');
|
||||||
}
|
}
|
||||||
Log::debug('Now in storeAccounts(), continued.');
|
|
||||||
|
|
||||||
if (is_null($destinationAccount)) {
|
if (is_null($destinationAccount)) {
|
||||||
Log::error('"destination"-account is null, so we cannot continue!', ['data' => $data]);
|
Log::error('"destination"-account is null, so we cannot continue!', ['data' => $data]);
|
||||||
@ -540,10 +527,8 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
private function storeWithdrawalAccounts(array $data): array
|
private function storeWithdrawalAccounts(array $data): array
|
||||||
{
|
{
|
||||||
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first(['accounts.*']);
|
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first(['accounts.*']);
|
||||||
Log::debug('Now in storeWithdrawalAccounts() with ', ['name' => $data['destination_account_name'], 'len' => strlen($data['destination_account_name'])]);
|
|
||||||
|
|
||||||
if (strlen($data['destination_account_name']) > 0) {
|
if (strlen($data['destination_account_name']) > 0) {
|
||||||
Log::debug('Now in storeWithdrawalAccounts()');
|
|
||||||
$destinationType = AccountType::where('type', 'Expense account')->first();
|
$destinationType = AccountType::where('type', 'Expense account')->first();
|
||||||
$destinationAccount = Account::firstOrCreateEncrypted(
|
$destinationAccount = Account::firstOrCreateEncrypted(
|
||||||
[
|
[
|
||||||
@ -553,7 +538,6 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
'active' => 1,
|
'active' => 1,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
Log::debug('Errors: ', ['err' => $destinationAccount->getErrors()->toArray(), 'id' => $destinationAccount->id]);
|
|
||||||
|
|
||||||
return [$sourceAccount, $destinationAccount];
|
return [$sourceAccount, $destinationAccount];
|
||||||
}
|
}
|
||||||
|
@ -72,8 +72,6 @@ class TransactionMatcher
|
|||||||
// - the maximum number of transactions to search in have been searched
|
// - the maximum number of transactions to search in have been searched
|
||||||
do {
|
do {
|
||||||
// Fetch a batch of transactions from the database
|
// Fetch a batch of transactions from the database
|
||||||
//$offset = $page > 0 ? ($page - 1) * $pagesize : 0;
|
|
||||||
//$set = $this->repository->getCollectionOfTypes($this->transactionTypes, $offset, $pagesize);
|
|
||||||
$paginator = $this->repository->getJournals($this->transactionTypes, $page, $pagesize);
|
$paginator = $this->repository->getJournals($this->transactionTypes, $page, $pagesize);
|
||||||
$set = $paginator->getCollection();
|
$set = $paginator->getCollection();
|
||||||
|
|
||||||
|
@ -343,7 +343,6 @@ class ExpandedForm
|
|||||||
$label = $this->label($name, $options);
|
$label = $this->label($name, $options);
|
||||||
$options = $this->expandOptionArray($name, $label, $options);
|
$options = $this->expandOptionArray($name, $label, $options);
|
||||||
$classes = $this->getHolderClasses($name);
|
$classes = $this->getHolderClasses($name);
|
||||||
//$value = $this->fillFieldValue($name, $value);
|
|
||||||
$html = view('form.static', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.static', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
|
@ -1,282 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* SplitDataSeeder.php
|
|
||||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
||||||
*
|
|
||||||
* This software may be modified and distributed under the terms
|
|
||||||
* of the MIT license. See the LICENSE file for details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types = 1);
|
|
||||||
/**
|
|
||||||
* SplitDataSeeder.php
|
|
||||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
||||||
*
|
|
||||||
* This software may be modified and distributed under the terms
|
|
||||||
* of the MIT license. See the LICENSE file for details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use FireflyIII\Models\Transaction;
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
|
||||||
use FireflyIII\Support\Migration\TestData;
|
|
||||||
use FireflyIII\User;
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class SplitDataSeeder
|
|
||||||
*/
|
|
||||||
class SplitDataSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* TestDataSeeder constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
$skipWithdrawal = false;
|
|
||||||
$skipDeposit = false;
|
|
||||||
$skipTransfer = true;
|
|
||||||
// start by creating all users:
|
|
||||||
// method will return the first user.
|
|
||||||
$user = TestData::createUsers();
|
|
||||||
|
|
||||||
// create all kinds of static data:
|
|
||||||
$assets = [['name' => 'Checking Account', 'iban' => 'NL11XOLA6707795988', 'meta' => ['accountRole' => 'defaultAsset']],
|
|
||||||
['name' => 'Alternate Checking Account', 'iban' => 'NL40UKBK3619908726', 'meta' => ['accountRole' => 'defaultAsset']],
|
|
||||||
['name' => 'Savings Account', 'iban' => 'NL96DZCO4665940223', 'meta' => ['accountRole' => 'savingAsset']],
|
|
||||||
['name' => 'Shared Checking Account', 'iban' => 'NL81RCQZ7160379858', 'meta' => ['accountRole' => 'sharedAsset']]];
|
|
||||||
|
|
||||||
// some asset accounts
|
|
||||||
TestData::createAssetAccounts($user, $assets);
|
|
||||||
|
|
||||||
// budgets, categories and others:
|
|
||||||
TestData::createBudgets($user);
|
|
||||||
TestData::createCategories($user);
|
|
||||||
TestData::createExpenseAccounts($user);
|
|
||||||
TestData::createRevenueAccounts($user);
|
|
||||||
TestData::createPiggybanks($user, 'Savings Account');
|
|
||||||
TestData::createBills($user);
|
|
||||||
// some bills
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Create splitted expense of 66,-
|
|
||||||
*/
|
|
||||||
$today = new Carbon('2012-03-14');
|
|
||||||
|
|
||||||
if (!$skipWithdrawal) {
|
|
||||||
$this->generateWithdrawals($user);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create splitted income of 99,-
|
|
||||||
$today->addDay();
|
|
||||||
|
|
||||||
if (!$skipDeposit) {
|
|
||||||
$this->generateDeposits($user);
|
|
||||||
}
|
|
||||||
// create a splitted transfer of 57,- (19)
|
|
||||||
// $today->addDay();
|
|
||||||
|
|
||||||
if (!$skipTransfer) {
|
|
||||||
$this->generateTransfers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param User $user
|
|
||||||
*/
|
|
||||||
private function generateDeposits(User $user)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* DEPOSIT ONE
|
|
||||||
*/
|
|
||||||
$sources = ['Work SixtyFive', 'Work EightyFour'];
|
|
||||||
$categories = ['Salary', 'Reimbursements'];
|
|
||||||
$amounts = [50, 50];
|
|
||||||
$destination = TestData::findAccount($user, 'Alternate Checking Account');
|
|
||||||
$date = new Carbon('2012-03-12');
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
['user_id' => $user->id, 'transaction_type_id' => 2, 'transaction_currency_id' => 1, 'description' => 'Split Even Income (journal (50/50))',
|
|
||||||
'completed' => 1, 'date' => $date->format('Y-m-d'),]
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($sources as $index => $source) {
|
|
||||||
$cat = $categories[$index];
|
|
||||||
$source = TestData::findAccount($user, $source);
|
|
||||||
$one = Transaction::create(
|
|
||||||
['account_id' => $source->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index] * -1,
|
|
||||||
'description' => 'Split Even Income #' . $index,]
|
|
||||||
);
|
|
||||||
$two = Transaction::create(
|
|
||||||
['account_id' => $destination->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index],
|
|
||||||
'description' => 'Split Even Income #' . $index,]
|
|
||||||
);
|
|
||||||
|
|
||||||
$one->categories()->save(TestData::findCategory($user, $cat));
|
|
||||||
$two->categories()->save(TestData::findCategory($user, $cat));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* DEPOSIT TWO.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
$sources = ['Work SixtyFive', 'Work EightyFour', 'Work Fiftyone'];
|
|
||||||
$categories = ['Salary', 'Bills', 'Reimbursements'];
|
|
||||||
$amounts = [15, 34, 51];
|
|
||||||
$destination = TestData::findAccount($user, 'Checking Account');
|
|
||||||
$date = new Carbon;
|
|
||||||
$date->subDays(3);
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
['user_id' => $user->id, 'transaction_type_id' => 2, 'transaction_currency_id' => 1,
|
|
||||||
'description' => 'Split Uneven Income (journal (15/34/51=100))', 'completed' => 1, 'date' => $date->format('Y-m-d'),]
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($sources as $index => $source) {
|
|
||||||
$cat = $categories[$index];
|
|
||||||
$source = TestData::findAccount($user, $source);
|
|
||||||
$one = Transaction::create(
|
|
||||||
['account_id' => $source->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index] * -1,
|
|
||||||
'description' => 'Split Uneven Income #' . $index,]
|
|
||||||
);
|
|
||||||
$two = Transaction::create(
|
|
||||||
['account_id' => $destination->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index],
|
|
||||||
'description' => 'Split Uneven Income #' . $index,]
|
|
||||||
);
|
|
||||||
|
|
||||||
$one->categories()->save(TestData::findCategory($user, $cat));
|
|
||||||
$two->categories()->save(TestData::findCategory($user, $cat));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function generateTransfers()
|
|
||||||
{
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 3, // transfer
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => 'Split Transfer (journal)',
|
|
||||||
'completed' => 1,
|
|
||||||
'date' => $today->format('Y-m-d'),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$source = TestData::findAccount($user, 'Alternate Checking Account');
|
|
||||||
$destinations = ['Checking Account', 'Savings Account', 'Shared Checking Account'];
|
|
||||||
$budgets = ['Groceries', 'Groceries', 'Car'];
|
|
||||||
$categories = ['Bills', 'Bills', 'Car'];
|
|
||||||
foreach ($destinations as $index => $dest) {
|
|
||||||
$bud = $budgets[$index];
|
|
||||||
$cat = $categories[$index];
|
|
||||||
$destination = TestData::findAccount($user, $dest);
|
|
||||||
|
|
||||||
$one = Transaction::create(
|
|
||||||
[
|
|
||||||
'account_id' => $source->id,
|
|
||||||
'transaction_journal_id' => $journal->id,
|
|
||||||
'amount' => '-19',
|
|
||||||
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$two = Transaction::create(
|
|
||||||
[
|
|
||||||
'account_id' => $destination->id,
|
|
||||||
'transaction_journal_id' => $journal->id,
|
|
||||||
'amount' => '19',
|
|
||||||
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$one->budgets()->save(TestData::findBudget($user, $bud));
|
|
||||||
$two->budgets()->save(TestData::findBudget($user, $bud));
|
|
||||||
|
|
||||||
$one->categories()->save(TestData::findCategory($user, $cat));
|
|
||||||
$two->categories()->save(TestData::findCategory($user, $cat));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param User $user
|
|
||||||
*/
|
|
||||||
private function generateWithdrawals(User $user)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* TRANSACTION ONE
|
|
||||||
*/
|
|
||||||
$destinations = ['SixtyFive', 'EightyFour'];
|
|
||||||
$budgets = ['Groceries', 'Car'];
|
|
||||||
$categories = ['Bills', 'Bills'];
|
|
||||||
$amounts = [50, 50];
|
|
||||||
$source = TestData::findAccount($user, 'Alternate Checking Account');
|
|
||||||
$date = new Carbon('2012-03-15');
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
['user_id' => $user->id, 'transaction_type_id' => 1, 'transaction_currency_id' => 1, 'description' => 'Split Even Expense (journal (50/50))',
|
|
||||||
'completed' => 1, 'date' => $date->format('Y-m-d'),]
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($destinations as $index => $dest) {
|
|
||||||
$bud = $budgets[$index];
|
|
||||||
$cat = $categories[$index];
|
|
||||||
$destination = TestData::findAccount($user, $dest);
|
|
||||||
$one = Transaction::create(
|
|
||||||
['account_id' => $source->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index] * -1,
|
|
||||||
'description' => 'Split Even Expense #' . $index,]
|
|
||||||
);
|
|
||||||
$two = Transaction::create(
|
|
||||||
['account_id' => $destination->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index],
|
|
||||||
'description' => 'Split Even Expense #' . $index,]
|
|
||||||
);
|
|
||||||
|
|
||||||
$one->budgets()->save(TestData::findBudget($user, $bud));
|
|
||||||
$two->budgets()->save(TestData::findBudget($user, $bud));
|
|
||||||
$one->categories()->save(TestData::findCategory($user, $cat));
|
|
||||||
$two->categories()->save(TestData::findCategory($user, $cat));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* TRANSACTION TWO.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
$destinations = ['SixtyFive', 'EightyFour', 'Fiftyone'];
|
|
||||||
$budgets = ['Groceries', 'Groceries', 'Car'];
|
|
||||||
$categories = ['Bills', 'Bills', 'Car'];
|
|
||||||
$amounts = [15, 34, 51];
|
|
||||||
$source = TestData::findAccount($user, 'Checking Account');
|
|
||||||
$date = new Carbon;
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
['user_id' => $user->id, 'transaction_type_id' => 1, 'transaction_currency_id' => 1,
|
|
||||||
'description' => 'Split Uneven Expense (journal (15/34/51=100))', 'completed' => 1, 'date' => $date->format('Y-m-d'),]
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($destinations as $index => $dest) {
|
|
||||||
$bud = $budgets[$index];
|
|
||||||
$cat = $categories[$index];
|
|
||||||
$destination = TestData::findAccount($user, $dest);
|
|
||||||
$one = Transaction::create(
|
|
||||||
['account_id' => $source->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index] * -1,
|
|
||||||
'description' => 'Split Uneven Expense #' . $index,]
|
|
||||||
);
|
|
||||||
$two = Transaction::create(
|
|
||||||
['account_id' => $destination->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index],
|
|
||||||
'description' => 'Split Uneven Expense #' . $index,]
|
|
||||||
);
|
|
||||||
|
|
||||||
$one->budgets()->save(TestData::findBudget($user, $bud));
|
|
||||||
$two->budgets()->save(TestData::findBudget($user, $bud));
|
|
||||||
$one->categories()->save(TestData::findCategory($user, $cat));
|
|
||||||
$two->categories()->save(TestData::findCategory($user, $cat));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user