More support for #142

This commit is contained in:
James Cole 2016-05-15 09:00:49 +02:00
parent 446ab62d38
commit 626404407e
9 changed files with 697 additions and 443 deletions

View File

@ -38,6 +38,7 @@ class ReportController extends Controller
/** /**
* @param Request $request * @param Request $request
* *
* @return \Illuminate\Http\JsonResponse
* @throws FireflyException * @throws FireflyException
*/ */
public function info(Request $request) public function info(Request $request)

View File

@ -436,7 +436,6 @@ class TransactionController extends Controller
->orderBy('amount', 'ASC')->first( ->orderBy('amount', 'ASC')->first(
['transactions.*', DB::raw('SUM(`transactions`.`amount`) as `sum`')] ['transactions.*', DB::raw('SUM(`transactions`.`amount`) as `sum`')]
); );
$final->description = '';
$transactions->push($final); $transactions->push($final);
break; break;
case TransactionType::WITHDRAWAL: case TransactionType::WITHDRAWAL:
@ -453,7 +452,6 @@ class TransactionController extends Controller
->orderBy('amount', 'ASC')->first( ->orderBy('amount', 'ASC')->first(
['transactions.*', DB::raw('SUM(`transactions`.`amount`) as `sum`')] ['transactions.*', DB::raw('SUM(`transactions`.`amount`) as `sum`')]
); );
$final->description = '';
$transactions->push($final); $transactions->push($final);
break; break;
default: default:

View File

@ -61,36 +61,32 @@ class TestData
*/ */
private function createAccounts() private function createAccounts()
{ {
if (isset($this->data['accounts']) && is_array($this->data['accounts'])) { $insert = [];
$insert = []; foreach ($this->data['accounts'] as $account) {
foreach ($this->data['accounts'] as $account) { $insert[] = [
$insert[] = [ 'created_at' => DB::raw('NOW()'),
'created_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'user_id' => $account['user_id'],
'user_id' => $account['user_id'], 'account_type_id' => $account['account_type_id'],
'account_type_id' => $account['account_type_id'], 'name' => Crypt::encrypt($account['name']),
'name' => Crypt::encrypt($account['name']), 'active' => 1,
'active' => 1, 'encrypted' => 1,
'encrypted' => 1, 'virtual_balance' => 0,
'virtual_balance' => 0, 'iban' => isset($account['iban']) ? Crypt::encrypt($account['iban']) : null,
'iban' => isset($account['iban']) ? Crypt::encrypt($account['iban']) : null, ];
];
}
DB::table('accounts')->insert($insert);
} }
if (isset($this->data['account-meta']) && is_array($this->data['account-meta'])) { DB::table('accounts')->insert($insert);
$insert = []; $insert = [];
foreach ($this->data['account-meta'] as $meta) { foreach ($this->data['account-meta'] as $meta) {
$insert[] = [ $insert[] = [
'created_at' => DB::raw('NOW()'), 'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'account_id' => $meta['account_id'], 'account_id' => $meta['account_id'],
'name' => $meta['name'], 'name' => $meta['name'],
'data' => $meta['data'], 'data' => $meta['data'],
]; ];
}
DB::table('account_meta')->insert($insert);
} }
DB::table('account_meta')->insert($insert);
} }
/** /**
@ -98,31 +94,29 @@ class TestData
*/ */
private function createAttachments() private function createAttachments()
{ {
if (isset($this->data['attachments']) && is_array($this->data['attachments'])) { $insert = [];
$insert = []; $disk = Storage::disk('upload');
$disk = Storage::disk('upload'); foreach ($this->data['attachments'] as $attachment) {
foreach ($this->data['attachments'] as $attachment) { $data = Crypt::encrypt($attachment['content']);
$data = Crypt::encrypt($attachment['content']); $attachmentId = DB::table('attachments')->insertGetId(
$attachmentId = DB::table('attachments')->insertGetId( [
[ 'created_at' => DB::raw('NOW()'),
'created_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'attachable_id' => $attachment['attachable_id'],
'attachable_id' => $attachment['attachable_id'], 'attachable_type' => $attachment['attachable_type'],
'attachable_type' => $attachment['attachable_type'], 'user_id' => $attachment['user_id'],
'user_id' => $attachment['user_id'], 'md5' => md5($attachment['content']),
'md5' => md5($attachment['content']), 'filename' => $attachment['filename'],
'filename' => $attachment['filename'], 'title' => $attachment['title'],
'title' => $attachment['title'], 'description' => $attachment['description'],
'description' => $attachment['description'], 'notes' => $attachment['notes'],
'notes' => $attachment['notes'], 'mime' => $attachment['mime'],
'mime' => $attachment['mime'], 'size' => strlen($attachment['content']),
'size' => strlen($attachment['content']), 'uploaded' => 1,
'uploaded' => 1, ]
] );
);
$disk->put('at-' . $attachmentId . '.data', $data); $disk->put('at-' . $attachmentId . '.data', $data);
}
} }
} }
@ -131,28 +125,26 @@ class TestData
*/ */
private function createBills() private function createBills()
{ {
if (isset($this->data['bills']) && is_array($this->data['bills'])) { $insert = [];
$insert = []; foreach ($this->data['bills'] as $bill) {
foreach ($this->data['bills'] as $bill) { $insert[] = [
$insert[] = [ 'created_at' => DB::raw('NOW()'),
'created_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'user_id' => $bill['user_id'],
'user_id' => $bill['user_id'], 'name' => Crypt::encrypt($bill['name']),
'name' => Crypt::encrypt($bill['name']), 'match' => Crypt::encrypt($bill['match']),
'match' => Crypt::encrypt($bill['match']), 'amount_min' => $bill['amount_min'],
'amount_min' => $bill['amount_min'], 'amount_max' => $bill['amount_max'],
'amount_max' => $bill['amount_max'], 'date' => $bill['date'],
'date' => $bill['date'], 'active' => $bill['active'],
'active' => $bill['active'], 'automatch' => $bill['automatch'],
'automatch' => $bill['automatch'], 'repeat_freq' => $bill['repeat_freq'],
'repeat_freq' => $bill['repeat_freq'], 'skip' => $bill['skip'],
'skip' => $bill['skip'], 'name_encrypted' => 1,
'name_encrypted' => 1, 'match_encrypted' => 1,
'match_encrypted' => 1, ];
];
}
DB::table('bills')->insert($insert);
} }
DB::table('bills')->insert($insert);
} }
/** /**
@ -160,32 +152,56 @@ class TestData
*/ */
private function createBudgets() private function createBudgets()
{ {
if (isset($this->data['budgets']) && is_array($this->data['budgets'])) { $insert = [];
$insert = []; foreach ($this->data['budgets'] as $budget) {
foreach ($this->data['budgets'] as $budget) { $insert[] = [
$insert[] = [ 'created_at' => DB::raw('NOW()'),
'created_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'user_id' => $budget['user_id'],
'user_id' => $budget['user_id'], 'name' => Crypt::encrypt($budget['name']),
'name' => Crypt::encrypt($budget['name']), 'encrypted' => 1,
'encrypted' => 1, ];
];
}
DB::table('budgets')->insert($insert);
} }
DB::table('budgets')->insert($insert);
if (isset($this->data['budget-limits']) && is_array($this->data['budget-limits'])) { foreach ($this->data['budget-limits'] as $limit) {
foreach ($this->data['budget-limits'] as $limit) { $amount = rand($limit['amount_min'], $limit['amount_max']);
$limitId = DB::table('budget_limits')->insertGetId(
[
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'budget_id' => $limit['budget_id'],
'startdate' => $limit['startdate'],
'amount' => $amount,
'repeats' => 0,
'repeat_freq' => $limit['repeat_freq'],
]
);
DB::table('limit_repetitions')->insert(
[
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'budget_limit_id' => $limitId,
'startdate' => $limit['startdate'],
'enddate' => Navigation::endOfPeriod(new Carbon($limit['startdate']), $limit['repeat_freq'])->format('Y-m-d'),
'amount' => $amount,
]
);
}
$current = clone $this->start;
while ($current <= $this->end) {
foreach ($this->data['monthly-limits'] as $limit) {
$amount = rand($limit['amount_min'], $limit['amount_max']); $amount = rand($limit['amount_min'], $limit['amount_max']);
$limitId = DB::table('budget_limits')->insertGetId( $limitId = DB::table('budget_limits')->insertGetId(
[ [
'created_at' => DB::raw('NOW()'), 'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'budget_id' => $limit['budget_id'], 'budget_id' => $limit['budget_id'],
'startdate' => $limit['startdate'], 'startdate' => $current->format('Y-m-d'),
'amount' => $amount, 'amount' => $amount,
'repeats' => 0, 'repeats' => 0,
'repeat_freq' => $limit['repeat_freq'], 'repeat_freq' => 'monthly',
] ]
); );
@ -194,46 +210,16 @@ class TestData
'created_at' => DB::raw('NOW()'), 'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'budget_limit_id' => $limitId, 'budget_limit_id' => $limitId,
'startdate' => $limit['startdate'], 'startdate' => $current->format('Y-m-d'),
'enddate' => Navigation::endOfPeriod(new Carbon($limit['startdate']), $limit['repeat_freq'])->format('Y-m-d'), 'enddate' => Navigation::endOfPeriod($current, 'monthly')->format('Y-m-d'),
'amount' => $amount, 'amount' => $amount,
] ]
); );
} }
$current->addMonth();
} }
if (isset($this->data['monthly-limits']) && is_array($this->data['monthly-limits'])) {
$current = clone $this->start;
while ($current <= $this->end) {
foreach ($this->data['monthly-limits'] as $limit) {
$amount = rand($limit['amount_min'], $limit['amount_max']);
$limitId = DB::table('budget_limits')->insertGetId(
[
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'budget_id' => $limit['budget_id'],
'startdate' => $current->format('Y-m-d'),
'amount' => $amount,
'repeats' => 0,
'repeat_freq' => 'monthly',
]
);
DB::table('limit_repetitions')->insert(
[
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'budget_limit_id' => $limitId,
'startdate' => $current->format('Y-m-d'),
'enddate' => Navigation::endOfPeriod($current, 'monthly')->format('Y-m-d'),
'amount' => $amount,
]
);
}
$current->addMonth();
}
}
} }
/** /**
@ -241,19 +227,17 @@ class TestData
*/ */
private function createCategories() private function createCategories()
{ {
if (isset($this->data['categories']) && is_array($this->data['categories'])) { $insert = [];
$insert = []; foreach ($this->data['categories'] as $category) {
foreach ($this->data['categories'] as $category) { $insert[] = [
$insert[] = [ 'created_at' => DB::raw('NOW()'),
'created_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'user_id' => $category['user_id'],
'user_id' => $category['user_id'], 'name' => Crypt::encrypt($category['name']),
'name' => Crypt::encrypt($category['name']), 'encrypted' => 1,
'encrypted' => 1, ];
];
}
DB::table('categories')->insert($insert);
} }
DB::table('categories')->insert($insert);
} }
/** /**
@ -268,167 +252,160 @@ class TestData
$month = $current->format('F'); $month = $current->format('F');
// run all monthly withdrawals: // run all monthly withdrawals:
if (isset($this->data['monthly-withdrawals']) && is_array($this->data['monthly-withdrawals'])) { foreach ($this->data['monthly-withdrawals'] as $withdrawal) {
foreach ($this->data['monthly-withdrawals'] as $withdrawal) { $description = str_replace(':month', $month, $withdrawal['description']);
$description = str_replace(':month', $month, $withdrawal['description']); $journalId = DB::table('transaction_journals')->insertGetId(
$journalId = DB::table('transaction_journals')->insertGetId( [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'user_id' => $withdrawal['user_id'],
'transaction_type_id' => 1,
'bill_id' => $withdrawal['bill_id'] ?? null,
'transaction_currency_id' => 1,
'description' => Crypt::encrypt($description),
'completed' => 1,
'date' => $date . $withdrawal['day-of-month'],
'interest_date' => $withdrawal['interest_date'] ?? null,
'book_date' => $withdrawal['book_date'] ?? null,
'process_date' => $withdrawal['process_date'] ?? null,
'encrypted' => 1,
'order' => 0,
'tag_count' => 0,
]
);
$amount = (rand($withdrawal['min_amount'] * 100, $withdrawal['max_amount'] * 100)) / 100;
$transactions[] = [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'transaction_journal_id' => $journalId,
'account_id' => $withdrawal['source_id'],
'amount' => $amount * -1,
];
$transactions[] = [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'transaction_journal_id' => $journalId,
'account_id' => $withdrawal['destination_id'],
'amount' => $amount,
];
// link to budget if set.
if (isset($withdrawal['budget_id'])) {
DB::table('budget_transaction_journal')->insert(
[ [
'created_at' => DB::raw('NOW()'), 'budget_id' => $withdrawal['budget_id'],
'updated_at' => DB::raw('NOW()'), 'transaction_journal_id' => $journalId,
'user_id' => $withdrawal['user_id'],
'transaction_type_id' => 1,
'bill_id' => $withdrawal['bill_id'] ?? null,
'transaction_currency_id' => 1,
'description' => Crypt::encrypt($description),
'completed' => 1,
'date' => $date . $withdrawal['day-of-month'],
'interest_date' => $withdrawal['interest_date'] ?? null,
'book_date' => $withdrawal['book_date'] ?? null,
'process_date' => $withdrawal['process_date'] ?? null,
'encrypted' => 1,
'order' => 0,
'tag_count' => 0,
] ]
); );
$amount = (rand($withdrawal['min_amount'] * 100, $withdrawal['max_amount'] * 100)) / 100; }
$transactions[] = [ // link to category if set.
'created_at' => DB::raw('NOW()'), if (isset($withdrawal['category_id'])) {
'updated_at' => DB::raw('NOW()'), DB::table('category_transaction_journal')->insert(
'transaction_journal_id' => $journalId, [
'account_id' => $withdrawal['source_id'], 'category_id' => $withdrawal['category_id'],
'amount' => $amount * -1, 'transaction_journal_id' => $journalId,
];
$transactions[] = [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'transaction_journal_id' => $journalId,
'account_id' => $withdrawal['destination_id'],
'amount' => $amount,
];
// link to budget if set. ]
if (isset($withdrawal['budget_id'])) { );
DB::table('budget_transaction_journal')->insert(
[
'budget_id' => $withdrawal['budget_id'],
'transaction_journal_id' => $journalId,
]
);
}
// link to category if set.
if (isset($withdrawal['category_id'])) {
DB::table('category_transaction_journal')->insert(
[
'category_id' => $withdrawal['category_id'],
'transaction_journal_id' => $journalId,
]
);
}
} }
} }
// run all monthly deposits: // run all monthly deposits:
if (isset($this->data['monthly-deposits']) && is_array($this->data['monthly-deposits'])) { foreach ($this->data['monthly-deposits'] as $deposit) {
foreach ($this->data['monthly-deposits'] as $deposit) { $description = str_replace(':month', $month, $deposit['description']);
$description = str_replace(':month', $month, $deposit['description']); $journalId = DB::table('transaction_journals')->insertGetId(
$journalId = DB::table('transaction_journals')->insertGetId( [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'user_id' => $deposit['user_id'],
'transaction_type_id' => 2,
'bill_id' => $deposit['bill_id'] ?? null,
'transaction_currency_id' => 1,
'description' => Crypt::encrypt($description),
'completed' => 1,
'date' => $date . $deposit['day-of-month'],
'interest_date' => $deposit['interest_date'] ?? null,
'book_date' => $deposit['book_date'] ?? null,
'process_date' => $deposit['process_date'] ?? null,
'encrypted' => 1,
'order' => 0,
'tag_count' => 0,
]
);
$amount = (rand($deposit['min_amount'] * 100, $deposit['max_amount'] * 100)) / 100;
$transactions[] = [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'transaction_journal_id' => $journalId,
'account_id' => $deposit['source_id'],
'amount' => $amount * -1,
];
$transactions[] = [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'transaction_journal_id' => $journalId,
'account_id' => $deposit['destination_id'],
'amount' => $amount,
];
// link to category if set.
if (isset($deposit['category_id'])) {
DB::table('category_transaction_journal')->insert(
[ [
'created_at' => DB::raw('NOW()'), 'category_id' => $deposit['category_id'],
'updated_at' => DB::raw('NOW()'), 'transaction_journal_id' => $journalId,
'user_id' => $deposit['user_id'],
'transaction_type_id' => 2,
'bill_id' => $deposit['bill_id'] ?? null,
'transaction_currency_id' => 1,
'description' => Crypt::encrypt($description),
'completed' => 1,
'date' => $date . $deposit['day-of-month'],
'interest_date' => $deposit['interest_date'] ?? null,
'book_date' => $deposit['book_date'] ?? null,
'process_date' => $deposit['process_date'] ?? null,
'encrypted' => 1,
'order' => 0,
'tag_count' => 0,
] ]
); );
$amount = (rand($deposit['min_amount'] * 100, $deposit['max_amount'] * 100)) / 100;
$transactions[] = [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'transaction_journal_id' => $journalId,
'account_id' => $deposit['source_id'],
'amount' => $amount * -1,
];
$transactions[] = [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'transaction_journal_id' => $journalId,
'account_id' => $deposit['destination_id'],
'amount' => $amount,
];
// link to category if set.
if (isset($deposit['category_id'])) {
DB::table('category_transaction_journal')->insert(
[
'category_id' => $deposit['category_id'],
'transaction_journal_id' => $journalId,
]
);
}
} }
} }
// run all monthly transfers: // run all monthly transfers:
if (isset($this->data['monthly-transfers']) && is_array($this->data['monthly-transfers'])) { foreach ($this->data['monthly-transfers'] as $transfer) {
foreach ($this->data['monthly-transfers'] as $transfer) { $description = str_replace(':month', $month, $transfer['description']);
$description = str_replace(':month', $month, $transfer['description']); $journalId = DB::table('transaction_journals')->insertGetId(
$journalId = DB::table('transaction_journals')->insertGetId( [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'user_id' => $transfer['user_id'],
'transaction_type_id' => 3,
'bill_id' => $transfer['bill_id'] ?? null,
'transaction_currency_id' => 1,
'description' => Crypt::encrypt($description),
'completed' => 1,
'date' => $date . $transfer['day-of-month'],
'interest_date' => $transfer['interest_date'] ?? null,
'book_date' => $transfer['book_date'] ?? null,
'process_date' => $transfer['process_date'] ?? null,
'encrypted' => 1,
'order' => 0,
'tag_count' => 0,
]
);
$amount = (rand($transfer['min_amount'] * 100, $transfer['max_amount'] * 100)) / 100;
$transactions[] = [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'transaction_journal_id' => $journalId,
'account_id' => $transfer['source_id'],
'amount' => $amount * -1,
];
$transactions[] = [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'transaction_journal_id' => $journalId,
'account_id' => $transfer['destination_id'],
'amount' => $amount,
];
// link to category if set.
if (isset($transfer['category_id'])) {
DB::table('category_transaction_journal')->insert(
[ [
'created_at' => DB::raw('NOW()'), 'category_id' => $transfer['category_id'],
'updated_at' => DB::raw('NOW()'), 'transaction_journal_id' => $journalId,
'user_id' => $transfer['user_id'],
'transaction_type_id' => 3,
'bill_id' => $transfer['bill_id'] ?? null,
'transaction_currency_id' => 1,
'description' => Crypt::encrypt($description),
'completed' => 1,
'date' => $date . $transfer['day-of-month'],
'interest_date' => $transfer['interest_date'] ?? null,
'book_date' => $transfer['book_date'] ?? null,
'process_date' => $transfer['process_date'] ?? null,
'encrypted' => 1,
'order' => 0,
'tag_count' => 0,
] ]
); );
$amount = (rand($transfer['min_amount'] * 100, $transfer['max_amount'] * 100)) / 100;
$transactions[] = [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'transaction_journal_id' => $journalId,
'account_id' => $transfer['source_id'],
'amount' => $amount * -1,
];
$transactions[] = [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'transaction_journal_id' => $journalId,
'account_id' => $transfer['destination_id'],
'amount' => $amount,
];
// link to category if set.
if (isset($transfer['category_id'])) {
DB::table('category_transaction_journal')->insert(
[
'category_id' => $transfer['category_id'],
'transaction_journal_id' => $journalId,
]
);
}
} }
} }
@ -441,32 +418,77 @@ class TestData
/** /**
* *
*/ */
private function createPiggyBanks() private function createMultiWithdrawals()
{ {
if (isset($this->data['piggy-banks']) && is_array($this->data['piggy-banks'])) { foreach ($this->data['multi-withdrawals'] as $withdrawal) {
foreach ($this->data['piggy-banks'] as $piggyBank) { $journalId = DB::table('transaction_journals')->insertGetId(
$piggyId = DB::table('piggy_banks')->insertGetId( [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'user_id' => $withdrawal['user_id'],
'transaction_type_id' => 1,
'transaction_currency_id' => 1,
'description' => Crypt::encrypt($withdrawal['description']),
'completed' => 1,
'date' => $withdrawal['date'],
'interest_date' => $withdrawal['interest_date'] ?? null,
'book_date' => $withdrawal['book_date'] ?? null,
'process_date' => $withdrawal['process_date'] ?? null,
'encrypted' => 1,
'order' => 0,
'tag_count' => 0,
]
);
foreach ($withdrawal['destination_ids'] as $index => $destination) {
$description = $withdrawal['description'] . ' (#' . ($index + 1) . ')';
$amount = $withdrawal['amounts'][$index];
$first = DB::table('transactions')->insertGetId(
[ [
'created_at' => DB::raw('NOW()'), 'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'account_id' => $piggyBank['account_id'], 'account_id' => $withdrawal['source_id'],
'name' => Crypt::encrypt($piggyBank['name']), 'transaction_journal_id' => $journalId,
'targetamount' => $piggyBank['targetamount'], 'description' => $description,
'startdate' => $piggyBank['startdate'], 'amount' => $amount * -1,
'reminder_skip' => 0,
'remind_me' => 0,
'order' => $piggyBank['order'],
'encrypted' => 1,
] ]
); );
if (isset($piggyBank['currentamount'])) { $second = DB::table('transactions')->insertGetId(
DB::table('piggy_bank_repetitions')->insert( [
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'account_id' => $destination,
'transaction_journal_id' => $journalId,
'description' => $description,
'amount' => $amount,
]
);
// link first and second to budget and category, if present.
if (isset($withdrawal['budget_ids'][$index])) {
DB::table('budget_transaction')->insert(
[ [
'created_at' => DB::raw('NOW()'), 'budget_id' => $withdrawal['budget_ids'][$index],
'updated_at' => DB::raw('NOW()'), 'transaction_id' => $first,
'piggy_bank_id' => $piggyId, ]
'startdate' => $piggyBank['startdate'], );
'currentamount' => $piggyBank['currentamount'], DB::table('budget_transaction')->insert(
[
'budget_id' => $withdrawal['budget_ids'][$index],
'transaction_id' => $second,
]
);
}
if (isset($withdrawal['category_ids'][$index])) {
DB::table('category_transaction')->insert(
[
'category_id' => $withdrawal['category_ids'][$index],
'transaction_id' => $first,
]
);
DB::table('category_transaction')->insert(
[
'category_id' => $withdrawal['category_ids'][$index],
'transaction_id' => $second,
] ]
); );
} }
@ -474,76 +496,103 @@ class TestData
} }
} }
/**
*
*/
private function createPiggyBanks()
{
foreach ($this->data['piggy-banks'] as $piggyBank) {
$piggyId = DB::table('piggy_banks')->insertGetId(
[
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'account_id' => $piggyBank['account_id'],
'name' => Crypt::encrypt($piggyBank['name']),
'targetamount' => $piggyBank['targetamount'],
'startdate' => $piggyBank['startdate'],
'reminder_skip' => 0,
'remind_me' => 0,
'order' => $piggyBank['order'],
'encrypted' => 1,
]
);
if (isset($piggyBank['currentamount'])) {
DB::table('piggy_bank_repetitions')->insert(
[
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
'piggy_bank_id' => $piggyId,
'startdate' => $piggyBank['startdate'],
'currentamount' => $piggyBank['currentamount'],
]
);
}
}
}
/** /**
* *
*/ */
private function createRules() private function createRules()
{ {
if (isset($this->data['rule-groups']) && is_array($this->data['rule-groups'])) { $insert = [];
$insert = []; foreach ($this->data['rule-groups'] as $group) {
foreach ($this->data['rule-groups'] as $group) { $insert[] = [
$insert[] = [ 'created_at' => DB::raw('NOW()'),
'created_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'user_id' => $group['user_id'],
'user_id' => $group['user_id'], 'order' => $group['order'],
'order' => $group['order'], 'title' => $group['title'],
'title' => $group['title'], 'description' => $group['description'],
'description' => $group['description'], 'active' => 1,
'active' => 1, ];
];
}
DB::table('rule_groups')->insert($insert);
} }
if (isset($this->data['rules']) && is_array($this->data['rules'])) { DB::table('rule_groups')->insert($insert);
$insert = []; $insert = [];
foreach ($this->data['rules'] as $rule) { foreach ($this->data['rules'] as $rule) {
$insert[] = [ $insert[] = [
'created_at' => DB::raw('NOW()'), 'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'user_id' => $rule['user_id'], 'user_id' => $rule['user_id'],
'rule_group_id' => $rule['rule_group_id'], 'rule_group_id' => $rule['rule_group_id'],
'order' => $rule['order'], 'order' => $rule['order'],
'active' => $rule['active'], 'active' => $rule['active'],
'stop_processing' => $rule['stop_processing'], 'stop_processing' => $rule['stop_processing'],
'title' => $rule['title'], 'title' => $rule['title'],
'description' => $rule['description'], 'description' => $rule['description'],
]; ];
}
DB::table('rules')->insert($insert);
} }
DB::table('rules')->insert($insert);
if (isset($this->data['rule-triggers']) && is_array($this->data['rule-triggers'])) { $insert = [];
$insert = []; foreach ($this->data['rule-triggers'] as $trigger) {
foreach ($this->data['rule-triggers'] as $trigger) { $insert[] = [
$insert[] = [ 'created_at' => DB::raw('NOW()'),
'created_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'rule_id' => $trigger['rule_id'],
'rule_id' => $trigger['rule_id'], 'order' => $trigger['order'],
'order' => $trigger['order'], 'active' => $trigger['active'],
'active' => $trigger['active'], 'stop_processing' => $trigger['stop_processing'],
'stop_processing' => $trigger['stop_processing'], 'trigger_type' => $trigger['trigger_type'],
'trigger_type' => $trigger['trigger_type'], 'trigger_value' => $trigger['trigger_value'],
'trigger_value' => $trigger['trigger_value'], ];
];
}
DB::table('rule_triggers')->insert($insert);
} }
if (isset($this->data['rule-actions']) && is_array($this->data['rule-actions'])) { DB::table('rule_triggers')->insert($insert);
$insert = [];
foreach ($this->data['rule-actions'] as $action) { $insert = [];
$insert[] = [ foreach ($this->data['rule-actions'] as $action) {
'created_at' => DB::raw('NOW()'), $insert[] = [
'updated_at' => DB::raw('NOW()'), 'created_at' => DB::raw('NOW()'),
'rule_id' => $action['rule_id'], 'updated_at' => DB::raw('NOW()'),
'order' => $action['order'], 'rule_id' => $action['rule_id'],
'active' => $action['active'], 'order' => $action['order'],
'stop_processing' => $action['stop_processing'], 'active' => $action['active'],
'action_type' => $action['action_type'], 'stop_processing' => $action['stop_processing'],
'action_value' => $action['action_value'], 'action_type' => $action['action_type'],
]; 'action_value' => $action['action_value'],
} ];
DB::table('rule_actions')->insert($insert);
} }
DB::table('rule_actions')->insert($insert);
} }
/** /**
@ -551,22 +600,20 @@ class TestData
*/ */
private function createTags() private function createTags()
{ {
if (isset($this->data['tags']) && is_array($this->data['tags'])) { $insert = [];
$insert = []; foreach ($this->data['tags'] as $tag) {
foreach ($this->data['tags'] as $tag) { $insert[]
$insert[] = [
= [ 'created_at' => DB::raw('NOW()'),
'created_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'user_id' => $tag['user_id'],
'user_id' => $tag['user_id'], 'tag' => Crypt::encrypt($tag['tag']),
'tag' => Crypt::encrypt($tag['tag']), 'tagMode' => $tag['tagMode'],
'tagMode' => $tag['tagMode'], 'date' => $tag['date'] ?? null,
'date' => $tag['date'] ?? null, ];
];
}
DB::table('tags')->insert($insert);
} }
DB::table('tags')->insert($insert);
} }
/** /**
@ -574,31 +621,27 @@ class TestData
*/ */
private function createUsers() private function createUsers()
{ {
if (isset($this->data['users']) && is_array($this->data['users'])) { $insert = [];
$insert = []; foreach ($this->data['users'] as $user) {
foreach ($this->data['users'] as $user) { $insert[]
$insert[] = [
= [ 'created_at' => DB::raw('NOW()'),
'created_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'), 'email' => $user['email'],
'email' => $user['email'], 'password' => bcrypt($user['password']),
'password' => bcrypt($user['password']), ];
];
}
DB::table('users')->insert($insert);
} }
if (isset($this->data['roles']) && is_array($this->data['roles'])) { DB::table('users')->insert($insert);
$insert = []; $insert = [];
foreach ($this->data['roles'] as $role) { foreach ($this->data['roles'] as $role) {
$insert[] $insert[]
= [ = [
'user_id' => $role['user_id'], 'user_id' => $role['user_id'],
'role_id' => $role['role'], 'role_id' => $role['role'],
]; ];
}
DB::table('role_user')->insert($insert);
} }
DB::table('role_user')->insert($insert);
} }
/** /**
@ -616,6 +659,7 @@ class TestData
$this->createTags(); $this->createTags();
$this->createJournals(); $this->createJournals();
$this->createAttachments(); $this->createAttachments();
$this->createMultiWithdrawals();
} }
} }

View File

@ -6,6 +6,7 @@ namespace FireflyIII\Support\Twig;
use Amount; use Amount;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Twig_Extension; use Twig_Extension;
@ -19,6 +20,7 @@ use Twig_SimpleFunction;
*/ */
class Journal extends Twig_Extension class Journal extends Twig_Extension
{ {
/** /**
* @return Twig_SimpleFunction * @return Twig_SimpleFunction
*/ */
@ -95,6 +97,10 @@ class Journal extends Twig_Extension
$this->getSourceAccount(), $this->getSourceAccount(),
$this->getDestinationAccount(), $this->getDestinationAccount(),
$this->formatPerspective(), $this->formatPerspective(),
$this->journalBudgets(),
$this->journalCategories(),
$this->transactionBudgets(),
$this->transactionCategories(),
]; ];
return $functions; return $functions;
@ -147,6 +153,143 @@ class Journal extends Twig_Extension
); );
} }
/**
* @return Twig_SimpleFunction
*/
public function journalBudgets(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'journalBudgets', function (TransactionJournal $journal): string {
$cache = new CacheProperties;
$cache->addProperty($journal->id);
$cache->addProperty('transaction-journal');
$cache->addProperty('budget-string');
if ($cache->has()) {
//return $cache->get();
}
$budgets = [];
// get all budgets:
foreach ($journal->budgets as $budget) {
$budgets[] = '<a href="' . route('budgets.show', [$budget->id]) . '" title="' . e($budget->name) . '">' . e($budget->name) . '</a>';
}
// and more!
foreach ($journal->transactions as $transaction) {
foreach ($transaction->budgets as $budget) {
$budgets[] = '<a href="' . route('budgets.show', [$budget->id]) . '" title="' . e($budget->name) . '">' . e($budget->name) . '</a>';
}
}
$string = join(', ', array_unique($budgets));
$cache->store($string);
return $string;
}
);
}
/**
* @return Twig_SimpleFunction
*/
public function journalCategories(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'journalCategories', function (TransactionJournal $journal): string {
$cache = new CacheProperties;
$cache->addProperty($journal->id);
$cache->addProperty('transaction-journal');
$cache->addProperty('category-string');
if ($cache->has()) {
return $cache->get();
}
$categories = [];
// get all budgets:
foreach ($journal->categories as $category) {
$categories[] = '<a href="' . route('categories.show', [$category->id]) . '" title="' . e($category->name) . '">' . e($category->name) . '</a>';
}
// and more!
foreach ($journal->transactions as $transaction) {
foreach ($transaction->categories as $category) {
$categories[] = '<a href="' . route('categories.show', [$category->id]) . '" title="' . e($category->name) . '">' . e($category->name)
. '</a>';
}
}
$string = join(', ', array_unique($categories));
$cache->store($string);
return $string;
}
);
}
/**
* @return Twig_SimpleFunction
*/
public function transactionBudgets(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'transactionBudgets', function (Transaction $transaction): string {
$cache = new CacheProperties;
$cache->addProperty($transaction->id);
$cache->addProperty('transaction');
$cache->addProperty('budget-string');
if ($cache->has()) {
// return $cache->get();
}
$budgets = [];
// get all budgets:
foreach ($transaction->budgets as $budget) {
$budgets[] = '<a href="' . route('budgets.show', [$budget->id]) . '" title="' . e($budget->name) . '">' . e($budget->name) . '</a>';
}
$string = join(', ', array_unique($budgets));
$cache->store($string);
return $string;
}
);
}
/**
* @return Twig_SimpleFunction
*/
public function transactionCategories(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'transactionCategories', function (Transaction $transaction): string {
$cache = new CacheProperties;
$cache->addProperty($transaction->id);
$cache->addProperty('transaction');
$cache->addProperty('category-string');
if ($cache->has()) {
// return $cache->get();
}
$categories = [];
// get all budgets:
foreach ($transaction->categories as $category) {
$categories[] = '<a href="' . route('categories.show', [$category->id]) . '" title="' . e($category->name) . '">' . e($category->name) . '</a>';
}
$string = join(', ', array_unique($categories));
$cache->store($string);
return $string;
}
);
}
/** /**
* @return Twig_SimpleFilter * @return Twig_SimpleFilter
*/ */

View File

@ -76,18 +76,14 @@
<!-- Do NOT hide the budget? --> <!-- Do NOT hide the budget? -->
{% if not hideBudgets %} {% if not hideBudgets %}
<td class="hidden-xs"> <td class="hidden-xs">
{% if journal.budgets[0] %} {{ journalBudgets(journal)|raw }}
<a href="{{ route('budgets.show',journal.budgets[0].id) }}">{{ journal.budgets[0].name }}</a>
{% endif %}
</td> </td>
{% endif %} {% endif %}
<!-- Do NOT hide the category? --> <!-- Do NOT hide the category? -->
{% if not hideCategories %} {% if not hideCategories %}
<td class="hidden-xs"> <td class="hidden-xs">
{% if journal.categories[0] %} {{ journalCategories(journal)|raw }}
<a href="{{ route('categories.show',journal.categories[0].id) }}">{{ journal.categories[0].name }}</a>
{% endif %}
</td> </td>
{% endif %} {% endif %}

View File

@ -62,15 +62,14 @@
<!-- Do NOT hide the budget? --> <!-- Do NOT hide the budget? -->
{% if not hideBudget %} {% if not hideBudget %}
<td class="hidden-xs"> <td class="hidden-xs">
{% if journal.budgets[0] %} {{ journalBudgets(journal)|raw }}
<a href="{{ route('budgets.show',journal.budgets[0].id) }}">{{ journal.budgets[0].name }}</a>
{% endif %}
</td> </td>
{% endif %} {% endif %}
<!-- Do NOT hide the category? --> <!-- Do NOT hide the category? -->
{% if not hideCategory %} {% if not hideCategory %}
<td class="hidden-xs"> <td class="hidden-xs">
{{ journalCategories(journal)|raw }}
{% if journal.categories[0] %} {% if journal.categories[0] %}
<a href="{{ route('categories.show',journal.categories[0].id) }}">{{ journal.categories[0].name }}</a> <a href="{{ route('categories.show',journal.categories[0].id) }}">{{ journal.categories[0].name }}</a>
{% endif %} {% endif %}

View File

@ -62,17 +62,12 @@
{% endif %} {% endif %}
</td> </td>
<td class="hide-budget">
{% if journal.budgets[0] %} {{ journalBudgets(journal)|raw }}
<td class="hide-budget"><a href="{{ route('budgets.show',journal.budgets[0].id) }}">{{ journal.budgets[0].name }}</a></td> </td>
{% else %} <td class="hide-category">
<td class="hide-budget"><em>{{ 'no_budget'|_ }}</em></td> {{ journalCategories(journal)|raw }}
{% endif %} </td>
{% if journal.categories[0] %}
<td class="hide-category"><a href="{{ route('categories.show',journal.categories[0].id) }}">{{ journal.categories[0].name }}</a></td>
{% else %}
<td class="hide-category"><em>{{ 'no_category'|_ }}</em></td>
{% endif %}
{% if journal.bill_id %} {% if journal.bill_id %}
<td class="hide-bill"><i class="fa fa-fw fa-rotate-right" title="{{ trans('list.bill') }}"></i>&nbsp;<a <td class="hide-bill"><i class="fa fa-fw fa-rotate-right" title="{{ trans('list.bill') }}"></i>&nbsp;<a
href="{{ route('bills.show',journal.bill_id) }}">{{ journal.bill.name }}</a></td> href="{{ route('bills.show',journal.bill_id) }}">{{ journal.bill.name }}</a></td>

View File

@ -172,7 +172,7 @@
</tr> </tr>
<tr> <tr>
<td>{{ 'amount'|_ }}</td> <td>{{ 'amount'|_ }}</td>
<td>{{ t.before|formatAmount}}</td> <td>{{ t.before|formatAmount }}</td>
</tr> </tr>
<tr> <tr>
<td>{{ 'newBalance'|_ }}</td> <td>{{ 'newBalance'|_ }}</td>
@ -184,22 +184,18 @@
<td>{{ t.description }}</td> <td>{{ t.description }}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if t.categories[0] %} <tr>
<tr> <td>{{ 'category'|_ }}</td>
<td>{{ 'category'|_ }}</td> <td>
<td> {{ transactionCategories(t)|raw }}
<a href="{{ route('categories.show',t.categories[0].id) }}">{{ t.categories[0].name }}</a> </td>
</td> </tr>
</tr> <tr>
{% endif %} <td>{{ 'budget'|_ }}</td>
{% if t.budgets[0] %} <td>
<tr> {{ transactionBudgets(t)|raw }}
<td>{{ 'budget'|_ }}</td> </td>
<td> </tr>
<a href="{{ route('budgets.show',t.budgets[0].id) }}">{{ t.budgets[0].name }}</a>
</td>
</tr>
{% endif %}
</table> </table>
</div> </div>
{% endfor %} {% endfor %}
@ -249,7 +245,7 @@
</div> </div>
</div> </div>
<!-- more than two start--> <!-- more than two transactions-->
{% if transactions.count > 2 %} {% if transactions.count > 2 %}
<div class="row"> <div class="row">
<div class="col-lg-12 col-md-12 col-sm-12"> <div class="col-lg-12 col-md-12 col-sm-12">
@ -270,20 +266,24 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for t in transactions %} {% for index, t in transactions %}
<tr> <tr>
<td>{{ t.description }}</td> <td>
{% if (index+1) != transactions|length %}
{{ t.description }}
{% endif %}
</td>
<td><a href="{{ route('accounts.show',t.account.id) }}">{{ t.account.name }}</a> ({{ t.account.accounttype.type|_ }})</td> <td><a href="{{ route('accounts.show',t.account.id) }}">{{ t.account.name }}</a> ({{ t.account.accounttype.type|_ }})</td>
<td>{{ t.sum|formatAmount }}</td> <td>{{ t.sum|formatAmount }}</td>
<td>{{ t.before|formatAmount }} &rarr; {{ (t.sum+t.before)|formatAmount }}</td> <td>{{ t.before|formatAmount }} &rarr; {{ (t.sum+t.before)|formatAmount }}</td>
<td> <td>
{% if t.budgets[0] %} {% if (index+1) != transactions|length %}
<a href="{{ route('budgets.show',t.budgets[0].id) }}">{{ t.budgets[0].name }}</a> {{ transactionBudgets(t)|raw }}
{% endif %} {% endif %}
</td> </td>
<td> <td>
{% if t.categories[0] %} {% if (index+1) != transactions|length %}
<a href="{{ route('categories.show',t.categories[0].id) }}">{{ t.categories[0].name }}</a> {{ transactionCategories(t)|raw }}
{% endif %} {% endif %}
</td> </td>

View File

@ -293,6 +293,18 @@
{ {
"name": "Going out", "name": "Going out",
"user_id": 1 "user_id": 1
},
{
"name": "Multi budget A",
"user_id": 1
},
{
"name": "Multi budget B",
"user_id": 1
},
{
"name": "Multi budget C",
"user_id": 1
} }
], ],
"budget-limits": [ "budget-limits": [
@ -385,6 +397,18 @@
{ {
"name": "Going out", "name": "Going out",
"user_id": 1 "user_id": 1
},
{
"name": "Multi category A",
"user_id": 1
},
{
"name": "Multi category B",
"user_id": 1
},
{
"name": "Multi category C",
"user_id": 1
} }
], ],
"piggy-banks": [ "piggy-banks": [
@ -840,5 +864,59 @@
"mime": "text\/plain", "mime": "text\/plain",
"uploaded": 1 "uploaded": 1
} }
] ],
"multi-withdrawals": [
{
"user_id": 1,
"date": "2016-03-12",
"description": "Even multi-withdrawal (50, 50)",
"destination_ids": [
18,
19
],
"source_id": 1,
"amounts": [
50,
50
],
"category_ids": [
7,
8,
9
],
"budget_ids": [
7,
8,
9
]
},
{
"user_id": 1,
"date": "2016-05-12",
"description": "Uneven multi-withdrawal (15,34,51)",
"destination_ids": [
18,
19,
20
],
"source_id": 1,
"amounts": [
14,
35,
51
],
"category_ids": [
7,
8,
9
],
"budget_ids": [
7,
8,
9
]
}
],
"multi-deposits": [],
"multi-transfers": []
} }