Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
More support for #142
James Cole626404407e1f
diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.phpindex 85dc7ef1b6..42516282ab 100644--- a/app/Http/Controllers/Popup/ReportController.php+++ b/app/Http/Controllers/Popup/ReportController.php@@ -38,6 +38,7 @@ class ReportController extends Controller/*** @param Request $request*+ * @return \Illuminate\Http\JsonResponse* @throws FireflyException*/public function info(Request $request)diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.phpindex 5264304cb9..2115d548c1 100644--- a/app/Http/Controllers/TransactionController.php+++ b/app/Http/Controllers/TransactionController.php@@ -436,7 +436,6 @@ class TransactionController extends Controller->orderBy('amount', 'ASC')->first(['transactions.*', DB::raw('SUM(`transactions`.`amount`) as `sum`')]);- $final->description = '';$transactions->push($final);break;case TransactionType::WITHDRAWAL:@@ -453,7 +452,6 @@ class TransactionController extends Controller->orderBy('amount', 'ASC')->first(['transactions.*', DB::raw('SUM(`transactions`.`amount`) as `sum`')]);- $final->description = '';$transactions->push($final);break;default:diff --git a/app/Support/Migration/TestData.php b/app/Support/Migration/TestData.phpindex 2839a07636..775ec20d55 100644--- a/app/Support/Migration/TestData.php+++ b/app/Support/Migration/TestData.php@@ -61,36 +61,32 @@ class TestData*/private function createAccounts(){- if (isset($this->data['accounts']) && is_array($this->data['accounts'])) {- $insert = [];- foreach ($this->data['accounts'] as $account) {- $insert[] = [- 'created_at' => DB::raw('NOW()'),- 'updated_at' => DB::raw('NOW()'),- 'user_id' => $account['user_id'],- 'account_type_id' => $account['account_type_id'],- 'name' => Crypt::encrypt($account['name']),- 'active' => 1,- 'encrypted' => 1,- 'virtual_balance' => 0,- 'iban' => isset($account['iban']) ? Crypt::encrypt($account['iban']) : null,- ];- }- DB::table('accounts')->insert($insert);+ $insert = [];+ foreach ($this->data['accounts'] as $account) {+ $insert[] = [+ 'created_at' => DB::raw('NOW()'),+ 'updated_at' => DB::raw('NOW()'),+ 'user_id' => $account['user_id'],+ 'account_type_id' => $account['account_type_id'],+ 'name' => Crypt::encrypt($account['name']),+ 'active' => 1,+ 'encrypted' => 1,+ 'virtual_balance' => 0,+ 'iban' => isset($account['iban']) ? Crypt::encrypt($account['iban']) : null,+ ];}- if (isset($this->data['account-meta']) && is_array($this->data['account-meta'])) {- $insert = [];- foreach ($this->data['account-meta'] as $meta) {- $insert[] = [- 'created_at' => DB::raw('NOW()'),- 'updated_at' => DB::raw('NOW()'),- 'account_id' => $meta['account_id'],- 'name' => $meta['name'],- 'data' => $meta['data'],- ];- }- DB::table('account_meta')->insert($insert);+ DB::table('accounts')->insert($insert);+ $insert = [];+ foreach ($this->data['account-meta'] as $meta) {+ $insert[] = [+ 'created_at' => DB::raw('NOW()'),+ 'updated_at' => DB::raw('NOW()'),+ 'account_id' => $meta['account_id'],+ 'name' => $meta['name'],+ 'data' => $meta['data'],+ ];}+ DB::table('account_meta')->insert($insert);}/**@@ -98,31 +94,29 @@ class TestData*/private function createAttachments(){- if (isset($this->data['attachments']) && is_array($this->data['attachments'])) {- $insert = [];- $disk = Storage::disk('upload');- foreach ($this->data['attachments'] as $attachment) {- $data = Crypt::encrypt($attachment['content']);- $attachmentId = DB::table('attachments')->insertGetId(- [- 'created_at' => DB::raw('NOW()'),- 'updated_at' => DB::raw('NOW()'),- 'attachable_id' => $attachment['attachable_id'],- 'attachable_type' => $attachment['attachable_type'],- 'user_id' => $attachment['user_id'],- 'md5' => md5($attachment['content']),- 'filename' => $attachment['filename'],- 'title' => $attachment['title'],- 'description' => $attachment['description'],- 'notes' => $attachment['notes'],- 'mime' => $attachment['mime'],- 'size' => strlen($attachment['content']),- 'uploaded' => 1,- ]- );-- $disk->put('at-' . $attachmentId . '.data', $data);- }+ $insert = [];+ $disk = Storage::disk('upload');+ foreach ($this->data['attachments'] as $attachment) {+ $data = Crypt::encrypt($attachment['content']);+ $attachmentId = DB::table('attachments')->insertGetId(+ [+ 'created_at' => DB::raw('NOW()'),+ 'updated_at' => DB::raw('NOW()'),+ 'attachable_id' => $attachment['attachable_id'],+ 'attachable_type' => $attachment['attachable_type'],+ 'user_id' => $attachment['user_id'],+ 'md5' => md5($attachment['content']),+ 'filename' => $attachment['filename'],+ 'title' => $attachment['title'],+ 'description' => $attachment['description'],+ 'notes' => $attachment['notes'],+ 'mime' => $attachment['mime'],+ 'size' => strlen($attachment['content']),+ 'uploaded' => 1,+ ]+ );++ $disk->put('at-' . $attachmentId . '.data', $data);}}@@ -131,28 +125,26 @@ class TestData*/private function createBills(){- if (isset($this->data['bills']) && is_array($this->data['bills'])) {- $insert = [];- foreach ($this->data['bills'] as $bill) {- $insert[] = [- 'created_at' => DB::raw('NOW()'),- 'updated_at' => DB::raw('NOW()'),- 'user_id' => $bill['user_id'],- 'name' => Crypt::encrypt($bill['name']),- 'match' => Crypt::encrypt($bill['match']),- 'amount_min' => $bill['amount_min'],- 'amount_max' => $bill['amount_max'],- 'date' => $bill['date'],- 'active' => $bill['active'],- 'automatch' => $bill['automatch'],- 'repeat_freq' => $bill['repeat_freq'],- 'skip' => $bill['skip'],- 'name_encrypted' => 1,- 'match_encrypted' => 1,- ];- }- DB::table('bills')->insert($insert);+ $insert = [];+ foreach ($this->data['bills'] as $bill) {+ $insert[] = [+ 'created_at' => DB::raw('NOW()'),+ 'updated_at' => DB::raw('NOW()'),+ 'user_id' => $bill['user_id'],+ 'name' => Crypt::encrypt($bill['name']),+ 'match' => Crypt::encrypt($bill['match']),+ 'amount_min' => $bill['amount_min'],+ 'amount_max' => $bill['amount_max'],+ 'date' => $bill['date'],+ 'active' => $bill['active'],+ 'automatch' => $bill['automatch'],+ 'repeat_freq' => $bill['repeat_freq'],+ 'skip' => $bill['skip'],+ 'name_encrypted' => 1,+ 'match_encrypted' => 1,+ ];}+ DB::table('bills')->insert($insert);}/**@@ -160,32 +152,56 @@ class TestData*/private function createBudgets(){- if (isset($this->data['budgets']) && is_array($this->data['budgets'])) {- $insert = [];- foreach ($this->data['budgets'] as $budget) {- $insert[] = [- 'created_at' => DB::raw('NOW()'),- 'updated_at' => DB::raw('NOW()'),- 'user_id' => $budget['user_id'],- 'name' => Crypt::encrypt($budget['name']),- 'encrypted' => 1,- ];- }- DB::table('budgets')->insert($insert);+ $insert = [];+ foreach ($this->data['budgets'] as $budget) {+ $insert[] = [+ 'created_at' => DB::raw('NOW()'),+ 'updated_at' => DB::raw('NOW()'),+ 'user_id' => $budget['user_id'],+ 'name' => Crypt::encrypt($budget['name']),+ 'encrypted' => 1,+ ];}+ 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']);$limitId = DB::table('budget_limits')->insertGetId(['created_at' => DB::raw('NOW()'),'updated_at' => DB::raw('NOW()'),'budget_id' => $limit['budget_id'],- 'startdate' => $limit['startdate'],+ 'startdate' => $current->format('Y-m-d'),'amount' => $amount,'repeats' => 0,- 'repeat_freq' => $limit['repeat_freq'],+ 'repeat_freq' => 'monthly',]);@@ -194,46 +210,16 @@ class TestData'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'),+ 'startdate' => $current->format('Y-m-d'),+ 'enddate' => Navigation::endOfPeriod($current, 'monthly')->format('Y-m-d'),'amount' => $amount,]);}- }- 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();- }+ $current->addMonth();}+}/**@@ -241,19 +227,17 @@ class TestData*/private function createCategories(){- if (isset($this->data['categories']) && is_array($this->data['categories'])) {- $insert = [];- foreach ($this->data['categories'] as $category) {- $insert[] = [- 'created_at' => DB::raw('NOW()'),- 'updated_at' => DB::raw('NOW()'),- 'user_id' => $category['user_id'],- 'name' => Crypt::encrypt($category['name']),- 'encrypted' => 1,- ];- }- DB::table('categories')->insert($insert);+ $insert = [];+ foreach ($this->data['categories'] as $category) {+ $insert[] = [+ 'created_at' => DB::raw('NOW()'),+ 'updated_at' => DB::raw('NOW()'),+ 'user_id' => $category['user_id'],+ 'name' => Crypt::encrypt($category['name']),+ 'encrypted' => 1,+ ];}+ DB::table('categories')->insert($insert);}/**@@ -268,174 +252,248 @@ class TestData$month = $current->format('F');// run all monthly withdrawals:- if (isset($this->data['monthly-withdrawals']) && is_array($this->data['monthly-withdrawals'])) {- foreach ($this->data['monthly-withdrawals'] as $withdrawal) {- $description = str_replace(':month', $month, $withdrawal['description']);- $journalId = DB::table('transaction_journals')->insertGetId(+ foreach ($this->data['monthly-withdrawals'] as $withdrawal) {+ $description = str_replace(':month', $month, $withdrawal['description']);+ $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()'),- '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,+ '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,+]);- $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(- [- '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:- if (isset($this->data['monthly-deposits']) && is_array($this->data['monthly-deposits'])) {- foreach ($this->data['monthly-deposits'] as $deposit) {- $description = str_replace(':month', $month, $deposit['description']);- $journalId = DB::table('transaction_journals')->insertGetId(+ foreach ($this->data['monthly-deposits'] as $deposit) {+ $description = str_replace(':month', $month, $deposit['description']);+ $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()'),- '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,+ 'category_id' => $deposit['category_id'],+ 'transaction_journal_id' => $journalId,+]);- $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:- if (isset($this->data['monthly-transfers']) && is_array($this->data['monthly-transfers'])) {- foreach ($this->data['monthly-transfers'] as $transfer) {- $description = str_replace(':month', $month, $transfer['description']);- $journalId = DB::table('transaction_journals')->insertGetId(+ foreach ($this->data['monthly-transfers'] as $transfer) {+ $description = str_replace(':month', $month, $transfer['description']);+ $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()'),- '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,+ 'category_id' => $transfer['category_id'],+ 'transaction_journal_id' => $journalId,+]);- $amount = (rand($transfer['min_amount'] * 100, $transfer['max_amount'] * 100)) / 100;- $transactions[] = [+ }+ }++ $current->addMonth();+ }++ DB::table('transactions')->insert($transactions);+ }++ /**+ *+ */+ private function createMultiWithdrawals()+ {+ foreach ($this->data['multi-withdrawals'] as $withdrawal) {+ $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,+ '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()'),'updated_at' => DB::raw('NOW()'),+ 'account_id' => $withdrawal['source_id'],'transaction_journal_id' => $journalId,- 'account_id' => $transfer['source_id'],+ 'description' => $description,'amount' => $amount * -1,- ];- $transactions[] = [+ ]+ );+ $second = DB::table('transactions')->insertGetId(+ ['created_at' => DB::raw('NOW()'),'updated_at' => DB::raw('NOW()'),+ 'account_id' => $destination,'transaction_journal_id' => $journalId,- 'account_id' => $transfer['destination_id'],+ 'description' => $description,'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,-- ]- );- }+ ]+ );+ // link first and second to budget and category, if present.+ if (isset($withdrawal['budget_ids'][$index])) {+ DB::table('budget_transaction')->insert(+ [+ 'budget_id' => $withdrawal['budget_ids'][$index],+ 'transaction_id' => $first,+ ]+ );+ DB::table('budget_transaction')->insert(+ [+ 'budget_id' => $withdrawal['budget_ids'][$index],+ 'transaction_id' => $second,+ ]+ );}- }- $current->addMonth();+ 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,+ ]+ );+ }+ }}-- DB::table('transactions')->insert($transactions);}/**@@ -443,33 +501,31 @@ class TestData*/private function createPiggyBanks(){- if (isset($this->data['piggy-banks']) && is_array($this->data['piggy-banks'])) {- foreach ($this->data['piggy-banks'] as $piggyBank) {- $piggyId = DB::table('piggy_banks')->insertGetId(+ 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()'),- 'account_id' => $piggyBank['account_id'],- 'name' => Crypt::encrypt($piggyBank['name']),- 'targetamount' => $piggyBank['targetamount'],+ 'piggy_bank_id' => $piggyId,'startdate' => $piggyBank['startdate'],- 'reminder_skip' => 0,- 'remind_me' => 0,- 'order' => $piggyBank['order'],- 'encrypted' => 1,+ 'currentamount' => $piggyBank['currentamount'],]);- 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'],- ]- );- }}}}@@ -479,71 +535,64 @@ class TestData*/private function createRules(){- if (isset($this->data['rule-groups']) && is_array($this->data['rule-groups'])) {- $insert = [];- foreach ($this->data['rule-groups'] as $group) {- $insert[] = [- 'created_at' => DB::raw('NOW()'),- 'updated_at' => DB::raw('NOW()'),- 'user_id' => $group['user_id'],- 'order' => $group['order'],- 'title' => $group['title'],- 'description' => $group['description'],- 'active' => 1,- ];- }- DB::table('rule_groups')->insert($insert);+ $insert = [];+ foreach ($this->data['rule-groups'] as $group) {+ $insert[] = [+ 'created_at' => DB::raw('NOW()'),+ 'updated_at' => DB::raw('NOW()'),+ 'user_id' => $group['user_id'],+ 'order' => $group['order'],+ 'title' => $group['title'],+ 'description' => $group['description'],+ 'active' => 1,+ ];}- if (isset($this->data['rules']) && is_array($this->data['rules'])) {- $insert = [];- foreach ($this->data['rules'] as $rule) {- $insert[] = [- 'created_at' => DB::raw('NOW()'),- 'updated_at' => DB::raw('NOW()'),- 'user_id' => $rule['user_id'],- 'rule_group_id' => $rule['rule_group_id'],- 'order' => $rule['order'],- 'active' => $rule['active'],- 'stop_processing' => $rule['stop_processing'],- 'title' => $rule['title'],- 'description' => $rule['description'],- ];- }- DB::table('rules')->insert($insert);+ DB::table('rule_groups')->insert($insert);+ $insert = [];+ foreach ($this->data['rules'] as $rule) {+ $insert[] = [+ 'created_at' => DB::raw('NOW()'),+ 'updated_at' => DB::raw('NOW()'),+ 'user_id' => $rule['user_id'],+ 'rule_group_id' => $rule['rule_group_id'],+ 'order' => $rule['order'],+ 'active' => $rule['active'],+ 'stop_processing' => $rule['stop_processing'],+ 'title' => $rule['title'],+ 'description' => $rule['description'],+ ];}-- if (isset($this->data['rule-triggers']) && is_array($this->data['rule-triggers'])) {- $insert = [];- foreach ($this->data['rule-triggers'] as $trigger) {- $insert[] = [- 'created_at' => DB::raw('NOW()'),- 'updated_at' => DB::raw('NOW()'),- 'rule_id' => $trigger['rule_id'],- 'order' => $trigger['order'],- 'active' => $trigger['active'],- 'stop_processing' => $trigger['stop_processing'],- 'trigger_type' => $trigger['trigger_type'],- 'trigger_value' => $trigger['trigger_value'],- ];- }- DB::table('rule_triggers')->insert($insert);+ DB::table('rules')->insert($insert);++ $insert = [];+ foreach ($this->data['rule-triggers'] as $trigger) {+ $insert[] = [+ 'created_at' => DB::raw('NOW()'),+ 'updated_at' => DB::raw('NOW()'),+ 'rule_id' => $trigger['rule_id'],+ 'order' => $trigger['order'],+ 'active' => $trigger['active'],+ 'stop_processing' => $trigger['stop_processing'],+ 'trigger_type' => $trigger['trigger_type'],+ 'trigger_value' => $trigger['trigger_value'],+ ];}- if (isset($this->data['rule-actions']) && is_array($this->data['rule-actions'])) {- $insert = [];- foreach ($this->data['rule-actions'] as $action) {- $insert[] = [- 'created_at' => DB::raw('NOW()'),- 'updated_at' => DB::raw('NOW()'),- 'rule_id' => $action['rule_id'],- 'order' => $action['order'],- 'active' => $action['active'],- 'stop_processing' => $action['stop_processing'],- 'action_type' => $action['action_type'],- 'action_value' => $action['action_value'],- ];- }- DB::table('rule_actions')->insert($insert);+ DB::table('rule_triggers')->insert($insert);++ $insert = [];+ foreach ($this->data['rule-actions'] as $action) {+ $insert[] = [+ 'created_at' => DB::raw('NOW()'),+ 'updated_at' => DB::raw('NOW()'),+ 'rule_id' => $action['rule_id'],+ 'order' => $action['order'],+ 'active' => $action['active'],+ 'stop_processing' => $action['stop_processing'],+ 'action_type' => $action['action_type'],+ 'action_value' => $action['action_value'],+ ];}+ DB::table('rule_actions')->insert($insert);}/**@@ -551,22 +600,20 @@ class TestData*/private function createTags(){- if (isset($this->data['tags']) && is_array($this->data['tags'])) {- $insert = [];- foreach ($this->data['tags'] as $tag) {- $insert[]- = [- 'created_at' => DB::raw('NOW()'),- 'updated_at' => DB::raw('NOW()'),- 'user_id' => $tag['user_id'],- 'tag' => Crypt::encrypt($tag['tag']),- 'tagMode' => $tag['tagMode'],- 'date' => $tag['date'] ?? null,- ];+ $insert = [];+ foreach ($this->data['tags'] as $tag) {+ $insert[]+ = [+ 'created_at' => DB::raw('NOW()'),+ 'updated_at' => DB::raw('NOW()'),+ 'user_id' => $tag['user_id'],+ 'tag' => Crypt::encrypt($tag['tag']),+ 'tagMode' => $tag['tagMode'],+ 'date' => $tag['date'] ?? null,+ ];- }- DB::table('tags')->insert($insert);}+ DB::table('tags')->insert($insert);}/**@@ -574,31 +621,27 @@ class TestData*/private function createUsers(){- if (isset($this->data['users']) && is_array($this->data['users'])) {- $insert = [];- foreach ($this->data['users'] as $user) {- $insert[]- = [- 'created_at' => DB::raw('NOW()'),- 'updated_at' => DB::raw('NOW()'),- 'email' => $user['email'],- 'password' => bcrypt($user['password']),- ];+ $insert = [];+ foreach ($this->data['users'] as $user) {+ $insert[]+ = [+ 'created_at' => DB::raw('NOW()'),+ 'updated_at' => DB::raw('NOW()'),+ 'email' => $user['email'],+ 'password' => bcrypt($user['password']),+ ];- }- DB::table('users')->insert($insert);}- if (isset($this->data['roles']) && is_array($this->data['roles'])) {- $insert = [];- foreach ($this->data['roles'] as $role) {- $insert[]- = [- 'user_id' => $role['user_id'],- 'role_id' => $role['role'],- ];- }- DB::table('role_user')->insert($insert);+ DB::table('users')->insert($insert);+ $insert = [];+ foreach ($this->data['roles'] as $role) {+ $insert[]+ = [+ 'user_id' => $role['user_id'],+ 'role_id' => $role['role'],+ ];}+ DB::table('role_user')->insert($insert);}/**@@ -616,6 +659,7 @@ class TestData$this->createTags();$this->createJournals();$this->createAttachments();+ $this->createMultiWithdrawals();}}diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.phpindex 262c5be668..7b79770044 100644--- a/app/Support/Twig/Journal.php+++ b/app/Support/Twig/Journal.php@@ -6,6 +6,7 @@ namespace FireflyIII\Support\Twig;use Amount;use FireflyIII\Models\Account;+use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;use FireflyIII\Support\CacheProperties;use Twig_Extension;@@ -19,6 +20,7 @@ use Twig_SimpleFunction;*/class Journal extends Twig_Extension{+/*** @return Twig_SimpleFunction*/@@ -95,6 +97,10 @@ class Journal extends Twig_Extension$this->getSourceAccount(),$this->getDestinationAccount(),$this->formatPerspective(),+ $this->journalBudgets(),+ $this->journalCategories(),+ $this->transactionBudgets(),+ $this->transactionCategories(),];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*/diff --git a/resources/views/list/journals.twig b/resources/views/list/journals.twigindex a57becf748..c9d0145995 100644--- a/resources/views/list/journals.twig+++ b/resources/views/list/journals.twig@@ -76,18 +76,14 @@<!-- Do NOT hide the budget? -->{% if not hideBudgets %}<td class="hidden-xs">- {% if journal.budgets[0] %}- <a href="{{ route('budgets.show',journal.budgets[0].id) }}">{{ journal.budgets[0].name }}</a>- {% endif %}+ {{ journalBudgets(journal)|raw }}</td>{% endif %}<!-- Do NOT hide the category? -->{% if not hideCategories %}<td class="hidden-xs">- {% if journal.categories[0] %}- <a href="{{ route('categories.show',journal.categories[0].id) }}">{{ journal.categories[0].name }}</a>- {% endif %}+ {{ journalCategories(journal)|raw }}</td>{% endif %}diff --git a/resources/views/popup/list/journals.twig b/resources/views/popup/list/journals.twigindex a75d9e445e..46b9e87680 100644--- a/resources/views/popup/list/journals.twig+++ b/resources/views/popup/list/journals.twig@@ -62,15 +62,14 @@<!-- Do NOT hide the budget? -->{% if not hideBudget %}<td class="hidden-xs">- {% if journal.budgets[0] %}- <a href="{{ route('budgets.show',journal.budgets[0].id) }}">{{ journal.budgets[0].name }}</a>- {% endif %}+ {{ journalBudgets(journal)|raw }}</td>{% endif %}<!-- Do NOT hide the category? -->{% if not hideCategory %}<td class="hidden-xs">+ {{ journalCategories(journal)|raw }}{% if journal.categories[0] %}<a href="{{ route('categories.show',journal.categories[0].id) }}">{{ journal.categories[0].name }}</a>{% endif %}diff --git a/resources/views/reports/partials/journals-audit.twig b/resources/views/reports/partials/journals-audit.twigindex dd47064971..e476a7c182 100644--- a/resources/views/reports/partials/journals-audit.twig+++ b/resources/views/reports/partials/journals-audit.twig@@ -62,17 +62,12 @@{% endif %}</td>-- {% if journal.budgets[0] %}- <td class="hide-budget"><a href="{{ route('budgets.show',journal.budgets[0].id) }}">{{ journal.budgets[0].name }}</a></td>- {% else %}- <td class="hide-budget"><em>{{ 'no_budget'|_ }}</em></td>- {% endif %}- {% 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 %}+ <td class="hide-budget">+ {{ journalBudgets(journal)|raw }}+ </td>+ <td class="hide-category">+ {{ journalCategories(journal)|raw }}+ </td>{% if journal.bill_id %}<td class="hide-bill"><i class="fa fa-fw fa-rotate-right" title="{{ trans('list.bill') }}"></i> <ahref="{{ route('bills.show',journal.bill_id) }}">{{ journal.bill.name }}</a></td>diff --git a/resources/views/transactions/show.twig b/resources/views/transactions/show.twigindex d514ef243b..35bcbe9c2c 100644--- a/resources/views/transactions/show.twig+++ b/resources/views/transactions/show.twig@@ -172,7 +172,7 @@</tr><tr><td>{{ 'amount'|_ }}</td>- <td>{{ t.before|formatAmount}}</td>+ <td>{{ t.before|formatAmount }}</td></tr><tr><td>{{ 'newBalance'|_ }}</td>@@ -184,22 +184,18 @@<td>{{ t.description }}</td></tr>{% endif %}- {% if t.categories[0] %}- <tr>- <td>{{ 'category'|_ }}</td>- <td>- <a href="{{ route('categories.show',t.categories[0].id) }}">{{ t.categories[0].name }}</a>- </td>- </tr>- {% endif %}- {% if t.budgets[0] %}- <tr>- <td>{{ 'budget'|_ }}</td>- <td>- <a href="{{ route('budgets.show',t.budgets[0].id) }}">{{ t.budgets[0].name }}</a>- </td>- </tr>- {% endif %}+ <tr>+ <td>{{ 'category'|_ }}</td>+ <td>+ {{ transactionCategories(t)|raw }}+ </td>+ </tr>+ <tr>+ <td>{{ 'budget'|_ }}</td>+ <td>+ {{ transactionBudgets(t)|raw }}+ </td>+ </tr></table></div>{% endfor %}@@ -249,7 +245,7 @@</div></div>- <!-- more than two start-->+ <!-- more than two transactions-->{% if transactions.count > 2 %}<div class="row"><div class="col-lg-12 col-md-12 col-sm-12">@@ -270,20 +266,24 @@</tr></thead><tbody>- {% for t in transactions %}+ {% for index, t in transactions %}<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>{{ t.sum|formatAmount }}</td><td>{{ t.before|formatAmount }} → {{ (t.sum+t.before)|formatAmount }}</td><td>- {% if t.budgets[0] %}- <a href="{{ route('budgets.show',t.budgets[0].id) }}">{{ t.budgets[0].name }}</a>+ {% if (index+1) != transactions|length %}+ {{ transactionBudgets(t)|raw }}{% endif %}</td><td>- {% if t.categories[0] %}- <a href="{{ route('categories.show',t.categories[0].id) }}">{{ t.categories[0].name }}</a>+ {% if (index+1) != transactions|length %}+ {{ transactionCategories(t)|raw }}{% endif %}</td>diff --git a/storage/database/seed.local.json b/storage/database/seed.local.jsonindex 7fd523c7ed..68bdbf2164 100644--- a/storage/database/seed.local.json+++ b/storage/database/seed.local.json@@ -293,6 +293,18 @@{"name": "Going out","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": [@@ -385,6 +397,18 @@{"name": "Going out","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": [@@ -840,5 +864,59 @@"mime": "text\/plain","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": []}\ No newline at end of file