mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Large update to fix split journals.
This commit is contained in:
parent
a74cef439b
commit
6a553f77f3
@ -49,7 +49,7 @@ class SingleController extends Controller
|
|||||||
|
|
||||||
/** @var BudgetRepositoryInterface */
|
/** @var BudgetRepositoryInterface */
|
||||||
private $budgets;
|
private $budgets;
|
||||||
|
|
||||||
/** @var PiggyBankRepositoryInterface */
|
/** @var PiggyBankRepositoryInterface */
|
||||||
private $piggyBanks;
|
private $piggyBanks;
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ class SingleController extends Controller
|
|||||||
{
|
{
|
||||||
$what = strtolower($what);
|
$what = strtolower($what);
|
||||||
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
|
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
|
||||||
$assetAccounts = ExpandedForm::makeSelectList($this->accounts->getActiveAccountsByType(['Default account', 'Asset account']));
|
$assetAccounts = ExpandedForm::makeSelectList($this->accounts->getActiveAccountsByType([AccountType::DEFAULT, AccountType::ASSET]));
|
||||||
$budgets = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
$budgets = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
||||||
$piggyBanks = $this->piggyBanks->getPiggyBanksWithAmount();
|
$piggyBanks = $this->piggyBanks->getPiggyBanksWithAmount();
|
||||||
$piggies = ExpandedForm::makeSelectListWithEmpty($piggyBanks);
|
$piggies = ExpandedForm::makeSelectListWithEmpty($piggyBanks);
|
||||||
@ -166,10 +166,10 @@ class SingleController extends Controller
|
|||||||
{
|
{
|
||||||
$count = $journal->transactions()->count();
|
$count = $journal->transactions()->count();
|
||||||
if ($count > 2) {
|
if ($count > 2) {
|
||||||
return redirect(route('journal.edit-split', [$journal->id]));
|
return redirect(route('transactions.edit-split', [$journal->id]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$assetAccounts = ExpandedForm::makeSelectList($this->accounts->getAccountsByType(['Default account', 'Asset account']));
|
$assetAccounts = ExpandedForm::makeSelectList($this->accounts->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]));
|
||||||
$budgetList = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
$budgetList = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
||||||
$piggyBankList = ExpandedForm::makeSelectListWithEmpty($this->piggyBanks->getPiggyBanks());
|
$piggyBankList = ExpandedForm::makeSelectListWithEmpty($this->piggyBanks->getPiggyBanks());
|
||||||
|
|
||||||
|
@ -15,19 +15,17 @@ namespace FireflyIII\Http\Controllers\Transaction;
|
|||||||
|
|
||||||
|
|
||||||
use ExpandedForm;
|
use ExpandedForm;
|
||||||
use FireflyIII\Crud\Split\JournalInterface;
|
|
||||||
use FireflyIII\Events\TransactionJournalUpdated;
|
use FireflyIII\Events\TransactionJournalUpdated;
|
||||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Http\Requests\SplitJournalFormRequest;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Account;
|
|
||||||
use FireflyIII\Models\Transaction;
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Log;
|
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Session;
|
use Session;
|
||||||
use Steam;
|
use Steam;
|
||||||
@ -42,6 +40,22 @@ use View;
|
|||||||
*/
|
*/
|
||||||
class SplitController extends Controller
|
class SplitController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var AccountRepositoryInterface */
|
||||||
|
private $accounts;
|
||||||
|
/** @var AttachmentHelperInterface */
|
||||||
|
private $attachments;
|
||||||
|
/** @var BudgetRepositoryInterface */
|
||||||
|
private $budgets;
|
||||||
|
/** @var CurrencyRepositoryInterface */
|
||||||
|
private $currencies;
|
||||||
|
|
||||||
|
/** @var JournalTaskerInterface */
|
||||||
|
private $tasker;
|
||||||
|
//
|
||||||
|
// /** @var PiggyBankRepositoryInterface */
|
||||||
|
// private $piggyBanks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -50,47 +64,19 @@ class SplitController extends Controller
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
View::share('mainTitleIcon', 'fa-share-alt');
|
View::share('mainTitleIcon', 'fa-share-alt');
|
||||||
View::share('title', trans('firefly.split-transactions'));
|
View::share('title', trans('firefly.split-transactions'));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// some useful repositories:
|
||||||
* @param TransactionJournal $journal
|
$this->middleware(
|
||||||
*
|
function ($request, $next) {
|
||||||
* @return View
|
$this->accounts = app(AccountRepositoryInterface::class);
|
||||||
*/
|
$this->budgets = app(BudgetRepositoryInterface::class);
|
||||||
public function create(TransactionJournal $journal)
|
$this->tasker = app(JournalTaskerInterface::class);
|
||||||
{
|
// $this->piggyBanks = app(PiggyBankRepositoryInterface::class);
|
||||||
$currencyRepository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
|
$this->attachments = app(AttachmentHelperInterface::class);
|
||||||
$budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
$this->currencies = app(CurrencyRepositoryInterface::class);
|
||||||
$piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
|
|
||||||
|
|
||||||
/** @var AccountRepositoryInterface $accountRepository */
|
return $next($request);
|
||||||
$accountRepository = app(AccountRepositoryInterface::class);
|
}
|
||||||
|
|
||||||
$assetAccounts = ExpandedForm::makeSelectList($accountRepository->getAccountsByType(['Default account', 'Asset account']));
|
|
||||||
$sessionData = session('journal-data', []);
|
|
||||||
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
|
|
||||||
$currencies = ExpandedForm::makeSelectList($currencyRepository->get());
|
|
||||||
$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
|
|
||||||
$piggyBanks = ExpandedForm::makeSelectListWithEmpty($piggyRepository->getPiggyBanksWithAmount());
|
|
||||||
$subTitle = trans('form.add_new_' . $sessionData['what']);
|
|
||||||
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
|
||||||
$subTitleIcon = 'fa-plus';
|
|
||||||
$preFilled = [
|
|
||||||
'what' => $sessionData['what'] ?? 'withdrawal',
|
|
||||||
'journal_amount' => $sessionData['amount'] ?? 0,
|
|
||||||
'journal_source_account_id' => $sessionData['source_account_id'] ?? 0,
|
|
||||||
'journal_source_account_name' => $sessionData['source_account_name'] ?? '',
|
|
||||||
'description' => [$journal->description],
|
|
||||||
'destination_account_name' => [$sessionData['destination_account_name']],
|
|
||||||
'destination_account_id' => [$sessionData['destination_account_id']],
|
|
||||||
'amount' => [$sessionData['amount']],
|
|
||||||
'budget_id' => [$sessionData['budget_id']],
|
|
||||||
'category' => [$sessionData['category']],
|
|
||||||
];
|
|
||||||
|
|
||||||
return view(
|
|
||||||
'split.journals.create',
|
|
||||||
compact('journal', 'piggyBanks', 'subTitle', 'optionalFields', 'subTitleIcon', 'preFilled', 'assetAccounts', 'currencies', 'budgets', 'uploadSize')
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,17 +88,11 @@ class SplitController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function edit(Request $request, TransactionJournal $journal)
|
public function edit(Request $request, TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
$currencyRepository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
|
|
||||||
$budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
|
||||||
|
|
||||||
/** @var AccountRepositoryInterface $accountRepository */
|
|
||||||
$accountRepository = app(AccountRepositoryInterface::class);
|
|
||||||
|
|
||||||
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
|
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
|
||||||
$currencies = ExpandedForm::makeSelectList($currencyRepository->get());
|
$currencies = ExpandedForm::makeSelectList($this->currencies->get());
|
||||||
$assetAccounts = ExpandedForm::makeSelectList($accountRepository->getAccountsByType(['Default account', 'Asset account']));
|
$assetAccounts = ExpandedForm::makeSelectList($this->accounts->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]));
|
||||||
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||||
$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
|
$budgets = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
||||||
$preFilled = $this->arrayFromJournal($request, $journal);
|
$preFilled = $this->arrayFromJournal($request, $journal);
|
||||||
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
|
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
|
||||||
$subTitleIcon = 'fa-pencil';
|
$subTitleIcon = 'fa-pencil';
|
||||||
@ -127,7 +107,7 @@ class SplitController extends Controller
|
|||||||
Session::forget('transactions.edit-split.fromUpdate');
|
Session::forget('transactions.edit-split.fromUpdate');
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'split.journals.edit',
|
'transactions.edit-split',
|
||||||
compact(
|
compact(
|
||||||
'subTitleIcon', 'currencies', 'optionalFields',
|
'subTitleIcon', 'currencies', 'optionalFields',
|
||||||
'preFilled', 'subTitle', 'amount', 'sourceAccounts', 'uploadSize', 'destinationAccounts', 'assetAccounts',
|
'preFilled', 'subTitle', 'amount', 'sourceAccounts', 'uploadSize', 'destinationAccounts', 'assetAccounts',
|
||||||
@ -136,63 +116,32 @@ class SplitController extends Controller
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param JournalInterface $repository
|
|
||||||
* @param SplitJournalFormRequest $request
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
||||||
*/
|
|
||||||
public function store(JournalInterface $repository, SplitJournalFormRequest $request, TransactionJournal $journal)
|
|
||||||
{
|
|
||||||
$data = $request->getSplitData();
|
|
||||||
foreach ($data['transactions'] as $transaction) {
|
|
||||||
$repository->storeTransaction($journal, $transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
$repository->markAsComplete($journal);
|
|
||||||
|
|
||||||
Session::flash('success', strval(trans('firefly.stored_journal', ['description' => e($journal->description)])));
|
|
||||||
Preferences::mark();
|
|
||||||
|
|
||||||
if (intval($request->get('create_another')) === 1) {
|
|
||||||
// set value so create routine will not overwrite URL:
|
|
||||||
Session::put('transactions.create.fromStore', true);
|
|
||||||
|
|
||||||
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
// redirect to previous URL.
|
|
||||||
return redirect(session('transactions.create.url'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param Request $request
|
||||||
* @param SplitJournalFormRequest $request
|
* @param JournalRepositoryInterface $repository
|
||||||
* @param JournalInterface $repository
|
* @param TransactionJournal $journal
|
||||||
* @param AttachmentHelperInterface $att
|
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
*/
|
*/
|
||||||
public function update(TransactionJournal $journal, SplitJournalFormRequest $request, JournalInterface $repository, AttachmentHelperInterface $att)
|
public function update(Request $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = $request->getSplitData();
|
$data = $this->arrayFromInput($request, $journal);
|
||||||
$journal = $repository->updateJournal($journal, $data);
|
$journal = $repository->updateSplitJournal($journal, $data);
|
||||||
|
|
||||||
// save attachments:
|
// save attachments:
|
||||||
$att->saveAttachmentsForModel($journal);
|
$this->attachments->saveAttachmentsForModel($journal);
|
||||||
|
|
||||||
event(new TransactionJournalUpdated($journal));
|
event(new TransactionJournalUpdated($journal));
|
||||||
// update, get events by date and sort DESC
|
// update, get events by date and sort DESC
|
||||||
|
|
||||||
// flash messages
|
// flash messages
|
||||||
if (count($att->getMessages()->get('attachments')) > 0) {
|
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||||
Session::flash('info', $att->getMessages()->get('attachments'));
|
Session::flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$type = strtolower(TransactionJournal::transactionTypeStr($journal));
|
||||||
$type = strtolower($journal->transaction_type_type ?? TransactionJournal::transactionTypeStr($journal));
|
|
||||||
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($data['journal_description'])])));
|
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($data['journal_description'])])));
|
||||||
Preferences::mark();
|
Preferences::mark();
|
||||||
|
|
||||||
@ -200,7 +149,7 @@ class SplitController extends Controller
|
|||||||
// set value so edit routine will not overwrite URL:
|
// set value so edit routine will not overwrite URL:
|
||||||
Session::put('transactions.edit-split.fromUpdate', true);
|
Session::put('transactions.edit-split.fromUpdate', true);
|
||||||
|
|
||||||
return redirect(route('split.journal.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);
|
return redirect(route('transactions.edit-split', [$journal->id]))->withInput(['return_to_edit' => 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// redirect to previous URL.
|
// redirect to previous URL.
|
||||||
@ -208,6 +157,40 @@ class SplitController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function arrayFromInput(Request $request, TransactionJournal $journal): array
|
||||||
|
{
|
||||||
|
$array = [
|
||||||
|
'journal_description' => $request->get('journal_description'),
|
||||||
|
'journal_source_account_id' => $request->get('journal_source_account_id'),
|
||||||
|
'journal_source_account_name' => $request->get('journal_source_account_name'),
|
||||||
|
'journal_destination_account_id' => $request->get('journal_destination_account_id'),
|
||||||
|
'transaction_currency_id' => $request->get('transaction_currency_id'),
|
||||||
|
'what' => $request->get('what'),
|
||||||
|
'date' => $request->get('date'),
|
||||||
|
// all custom fields:
|
||||||
|
'interest_date' => $request->get('interest_date'),
|
||||||
|
'book_date' => $request->get('book_date'),
|
||||||
|
'process_date' => $request->get('process_date'),
|
||||||
|
'due_date' => $request->get('due_date'),
|
||||||
|
'payment_date' => $request->get('payment_date'),
|
||||||
|
'invoice_date' => $request->get('invoice_date'),
|
||||||
|
'internal_reference' => $request->get('internal_reference'),
|
||||||
|
'notes' => $request->get('notes'),
|
||||||
|
'tags' => explode(',', $request->get('tags')),
|
||||||
|
|
||||||
|
// transactions.
|
||||||
|
'transactions' => $this->getTransactionDataFromRequest($request),
|
||||||
|
];
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
@ -222,149 +205,80 @@ class SplitController extends Controller
|
|||||||
'journal_description' => $request->old('journal_description', $journal->description),
|
'journal_description' => $request->old('journal_description', $journal->description),
|
||||||
'journal_amount' => TransactionJournal::amountPositive($journal),
|
'journal_amount' => TransactionJournal::amountPositive($journal),
|
||||||
'sourceAccounts' => $sourceAccounts,
|
'sourceAccounts' => $sourceAccounts,
|
||||||
'journal_source_account_id' => $sourceAccounts->first()->id,
|
'journal_source_account_id' => $request->old('journal_source_account_id', $sourceAccounts->first()->id),
|
||||||
'journal_source_account_name' => $sourceAccounts->first()->name,
|
'journal_source_account_name' => $request->old('journal_source_account_name', $sourceAccounts->first()->name),
|
||||||
'journal_destination_account_id' => $destinationAccounts->first()->id,
|
'journal_destination_account_id' => $request->old('journal_destination_account_id', $destinationAccounts->first()->id),
|
||||||
'transaction_currency_id' => $request->old('transaction_currency_id', $journal->transaction_currency_id),
|
'transaction_currency_id' => $request->old('transaction_currency_id', $journal->transaction_currency_id),
|
||||||
'destinationAccounts' => $destinationAccounts,
|
'destinationAccounts' => $destinationAccounts,
|
||||||
'what' => strtolower(TransactionJournal::transactionTypeStr($journal)),
|
'what' => strtolower(TransactionJournal::transactionTypeStr($journal)),
|
||||||
'date' => $request->old('date', $journal->date),
|
'date' => $request->old('date', $journal->date),
|
||||||
'interest_date' => $request->old('interest_date', $journal->interest_date),
|
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
|
||||||
'book_date' => $request->old('book_date', $journal->book_date),
|
|
||||||
'process_date' => $request->old('process_date', $journal->process_date),
|
// all custom fields:
|
||||||
'description' => [],
|
'interest_date' => $request->old('interest_date', $journal->getMeta('interest_date')),
|
||||||
'source_account_id' => [],
|
'book_date' => $request->old('book_date', $journal->getMeta('book_date')),
|
||||||
'source_account_name' => [],
|
'process_date' => $request->old('process_date', $journal->getMeta('process_date')),
|
||||||
'destination_account_id' => [],
|
'due_date' => $request->old('due_date', $journal->getMeta('due_date')),
|
||||||
'destination_account_name' => [],
|
'payment_date' => $request->old('payment_date', $journal->getMeta('payment_date')),
|
||||||
'amount' => [],
|
'invoice_date' => $request->old('invoice_date', $journal->getMeta('invoice_date')),
|
||||||
'budget_id' => [],
|
'internal_reference' => $request->old('internal_reference', $journal->getMeta('internal_reference')),
|
||||||
'category' => [],
|
'notes' => $request->old('notes', $journal->getMeta('notes')),
|
||||||
|
|
||||||
|
// transactions.
|
||||||
|
'transactions' => $this->getTransactionDataFromJournal($journal),
|
||||||
];
|
];
|
||||||
|
|
||||||
// number of transactions present in old input:
|
|
||||||
$previousCount = count($request->old('description'));
|
|
||||||
|
|
||||||
if ($previousCount === 0) {
|
|
||||||
// build from scratch
|
|
||||||
$transactions = $this->transactionsFromJournal($request, $journal);
|
|
||||||
$array['description'] = $transactions['description'];
|
|
||||||
$array['source_account_id'] = $transactions['source_account_id'];
|
|
||||||
$array['source_account_name'] = $transactions['source_account_name'];
|
|
||||||
$array['destination_account_id'] = $transactions['destination_account_id'];
|
|
||||||
$array['destination_account_name'] = $transactions['destination_account_name'];
|
|
||||||
$array['amount'] = $transactions['amount'];
|
|
||||||
$array['budget_id'] = $transactions['budget_id'];
|
|
||||||
$array['category'] = $transactions['category'];
|
|
||||||
|
|
||||||
return $array;
|
|
||||||
}
|
|
||||||
|
|
||||||
$index = 0;
|
|
||||||
while ($index < $previousCount) {
|
|
||||||
$description = $request->old('description')[$index] ?? '';
|
|
||||||
$destinationId = $request->old('destination_account_id')[$index] ?? 0;
|
|
||||||
$destinationName = $request->old('destination_account_name')[$index] ?? '';
|
|
||||||
$sourceId = $request->old('source_account_id')[$index] ?? 0;
|
|
||||||
$sourceName = $request->old('source_account_name')[$index] ?? '';
|
|
||||||
$amount = $request->old('amount')[$index] ?? '';
|
|
||||||
$budgetId = $request->old('budget_id')[$index] ?? 0;
|
|
||||||
$categoryName = $request->old('category')[$index] ?? '';
|
|
||||||
|
|
||||||
|
|
||||||
// any transfer not from the source:
|
|
||||||
$array['description'][] = $description;
|
|
||||||
$array['source_account_id'][] = $sourceId;
|
|
||||||
$array['source_account_name'][] = $sourceName;
|
|
||||||
$array['destination_account_id'][] = $destinationId;
|
|
||||||
$array['destination_account_name'][] = $destinationName;
|
|
||||||
$array['amount'][] = $amount;
|
|
||||||
$array['budget_id'][] = intval($budgetId);
|
|
||||||
$array['category'][] = $categoryName;
|
|
||||||
$index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function transactionsFromJournal(Request $request, TransactionJournal $journal): array
|
private function getTransactionDataFromJournal(TransactionJournal $journal): array
|
||||||
{
|
{
|
||||||
/** @var Collection $transactions */
|
$transactions = $this->tasker->getTransactionsOverview($journal);
|
||||||
$transactions = $journal->transactions()->get();
|
$return = [];
|
||||||
|
/** @var array $transaction */
|
||||||
/*
|
foreach ($transactions as $transaction) {
|
||||||
* Splitted journals always have ONE source OR ONE destination.
|
$return[] = [
|
||||||
* Withdrawals have ONE source (asset account)
|
'description' => $transaction['description'],
|
||||||
* Deposits have ONE destination (asset account)
|
'source_account_id' => $transaction['source_account_id'],
|
||||||
* Transfers have ONE of both (asset account)
|
'source_account_name' => $transaction['source_account_name'],
|
||||||
*/
|
'destination_account_id' => $transaction['destination_account_id'],
|
||||||
/** @var Account $singular */
|
'destination_account_name' => $transaction['destination_account_name'],
|
||||||
$singular = TransactionJournal::sourceAccountList($journal)->first();
|
'amount' => round($transaction['destination_amount'], 2),
|
||||||
if ($journal->transactionType->type == TransactionType::DEPOSIT) {
|
'budget_id' => $transaction['budget_id'],
|
||||||
/** @var Account $singular */
|
'category' => $transaction['category'],
|
||||||
$singular = TransactionJournal::destinationAccountList($journal)->first();
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
return $return;
|
||||||
* Loop all transactions. Collect info ONLY from the transaction that is NOT related to
|
}
|
||||||
* the singular account.
|
|
||||||
*/
|
|
||||||
$index = 0;
|
|
||||||
$return = [
|
|
||||||
'description' => [],
|
|
||||||
'source_account_id' => [],
|
|
||||||
'source_account_name' => [],
|
|
||||||
'destination_account_id' => [],
|
|
||||||
'destination_account_name' => [],
|
|
||||||
'amount' => [],
|
|
||||||
'budget_id' => [],
|
|
||||||
'category' => [],
|
|
||||||
];
|
|
||||||
|
|
||||||
Log::debug('now at transactionsFromJournal');
|
/**
|
||||||
|
* @param Request $request
|
||||||
/**
|
*
|
||||||
* @var int $current
|
* @return array
|
||||||
* @var Transaction $transaction
|
*/
|
||||||
*/
|
private function getTransactionDataFromRequest(Request $request): array
|
||||||
foreach ($transactions as $current => $transaction) {
|
{
|
||||||
$budget = $transaction->budgets()->first();
|
$return = [];
|
||||||
$category = $transaction->categories()->first();
|
$transactions = $request->get('transactions');
|
||||||
$budgetId = 0;
|
foreach ($transactions as $transaction) {
|
||||||
$categoryName = '';
|
$return[] = [
|
||||||
if (!is_null($budget)) {
|
'description' => $transaction['description'],
|
||||||
$budgetId = $budget->id;
|
'source_account_id' => $transaction['source_account_id'] ?? 0,
|
||||||
}
|
'source_account_name' => $transaction['source_account_name'] ?? '',
|
||||||
|
'destination_account_id' => $transaction['destination_account_id'] ?? 0,
|
||||||
if (!is_null($category)) {
|
'destination_account_name' => $transaction['destination_account_name'] ?? '',
|
||||||
$categoryName = $category->name;
|
'amount' => round($transaction['amount'] ?? 0, 2),
|
||||||
}
|
'budget_id' => intval($transaction['budget_id']),
|
||||||
|
'category' => $transaction['category'] ?? '',
|
||||||
$budgetId = $request->old('budget_id')[$index] ?? $budgetId;
|
'user' => auth()->user()->id, // needed for accounts.
|
||||||
$categoryName = $request->old('category')[$index] ?? $categoryName;
|
'piggy_bank_id' => $transaction['piggy_bank_id'] ?? 0,
|
||||||
$amount = $request->old('amount')[$index] ?? $transaction->amount;
|
];
|
||||||
$description = $request->old('description')[$index] ?? $transaction->description;
|
|
||||||
$destinationName = $request->old('destination_account_name')[$index] ?? $transaction->account->name;
|
|
||||||
$sourceName = $request->old('source_account_name')[$index] ?? $transaction->account->name;
|
|
||||||
$amount = bccomp($amount, '0') === -1 ? bcmul($amount, '-1') : $amount;
|
|
||||||
|
|
||||||
if ($transaction->account_id !== $singular->id) {
|
|
||||||
$return['description'][] = $description;
|
|
||||||
$return['destination_account_id'][] = $transaction->account_id;
|
|
||||||
$return['destination_account_name'][] = $destinationName;
|
|
||||||
$return['source_account_name'][] = $sourceName;
|
|
||||||
$return['amount'][] = $amount;
|
|
||||||
$return['budget_id'][] = intval($budgetId);
|
|
||||||
$return['category'][] = $categoryName;
|
|
||||||
// only add one when "valid" transaction
|
|
||||||
$index++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
@ -55,7 +55,7 @@ class Transaction extends Model
|
|||||||
{
|
{
|
||||||
|
|
||||||
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
||||||
protected $fillable = ['account_id', 'transaction_journal_id', 'description', 'amount'];
|
protected $fillable = ['account_id', 'transaction_journal_id', 'description', 'amount','identifier'];
|
||||||
protected $hidden = ['encrypted'];
|
protected $hidden = ['encrypted'];
|
||||||
protected $rules
|
protected $rules
|
||||||
= [
|
= [
|
||||||
|
@ -14,6 +14,7 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Repositories\Journal;
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
use DB;
|
use DB;
|
||||||
|
use FireflyIII\Events\TransactionStored;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
@ -25,6 +26,7 @@ use FireflyIII\Models\TransactionJournal;
|
|||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -251,6 +253,92 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
return $journal;
|
return $journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as above but for transaction journal with multiple transactions.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return TransactionJournal
|
||||||
|
*/
|
||||||
|
public function updateSplitJournal(TransactionJournal $journal, array $data): TransactionJournal
|
||||||
|
{
|
||||||
|
// update actual journal:
|
||||||
|
$journal->transaction_currency_id = $data['transaction_currency_id'];
|
||||||
|
$journal->description = $data['journal_description'];
|
||||||
|
$journal->date = $data['date'];
|
||||||
|
|
||||||
|
// unlink all categories:
|
||||||
|
$journal->categories()->detach();
|
||||||
|
$journal->budgets()->detach();
|
||||||
|
|
||||||
|
// update meta fields:
|
||||||
|
$result = $journal->save();
|
||||||
|
if ($result) {
|
||||||
|
foreach ($data as $key => $value) {
|
||||||
|
if (in_array($key, $this->validMetaFields)) {
|
||||||
|
$journal->setMeta($key, $value);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Log::debug(sprintf('Could not store meta field "%s" with value "%s" for journal #%d', json_encode($key), json_encode($value), $journal->id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $journal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// update tags:
|
||||||
|
if (isset($data['tags']) && is_array($data['tags'])) {
|
||||||
|
$this->updateTags($journal, $data['tags']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete original transactions, and recreate them.
|
||||||
|
$journal->transactions()->delete();
|
||||||
|
|
||||||
|
// store each transaction.
|
||||||
|
$identifier = 0;
|
||||||
|
foreach ($data['transactions'] as $transaction) {
|
||||||
|
Log::debug(sprintf('Split journal update split transaction %d', $identifier));
|
||||||
|
$transaction = $this->appendTransactionData($transaction, $data);
|
||||||
|
$this->storeSplitTransaction($journal, $transaction, $identifier);
|
||||||
|
$identifier++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$journal->save();
|
||||||
|
|
||||||
|
return $journal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When the user edits a split journal, each line is missing crucial data:
|
||||||
|
*
|
||||||
|
* - Withdrawal lines are missing the source account ID
|
||||||
|
* - Deposit lines are missing the destination account ID
|
||||||
|
* - Transfers are missing both.
|
||||||
|
*
|
||||||
|
* We need to append the array.
|
||||||
|
*
|
||||||
|
* @param array $transaction
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function appendTransactionData(array $transaction, array $data): array
|
||||||
|
{
|
||||||
|
switch ($data['what']) {
|
||||||
|
case strtolower(TransactionType::TRANSFER):
|
||||||
|
case strtolower(TransactionType::WITHDRAWAL):
|
||||||
|
$transaction['source_account_id'] = intval($data['journal_source_account_id']);
|
||||||
|
break;
|
||||||
|
case strtolower(TransactionType::TRANSFER):
|
||||||
|
case strtolower(TransactionType::DEPOSIT):
|
||||||
|
$transaction['destination_account_id'] = intval($data['journal_destination_account_id']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transaction;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* * Remember: a balancingAct takes at most one expense and one transfer.
|
* * Remember: a balancingAct takes at most one expense and one transfer.
|
||||||
@ -291,6 +379,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
'source' => null,
|
'source' => null,
|
||||||
'destination' => null,
|
'destination' => null,
|
||||||
];
|
];
|
||||||
|
Log::debug(sprintf('Going to store accounts for type %s', $type->type));
|
||||||
switch ($type->type) {
|
switch ($type->type) {
|
||||||
case TransactionType::WITHDRAWAL:
|
case TransactionType::WITHDRAWAL:
|
||||||
$accounts = $this->storeWithdrawalAccounts($data);
|
$accounts = $this->storeWithdrawalAccounts($data);
|
||||||
@ -310,13 +399,13 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($accounts['source'])) {
|
if (is_null($accounts['source'])) {
|
||||||
Log::error('"destination"-account is null, so we cannot continue!', ['data' => $data]);
|
Log::error('"source"-account is null, so we cannot continue!', ['data' => $data]);
|
||||||
throw new FireflyException('"destination"-account is null, so we cannot continue!');
|
throw new FireflyException('"source"-account is null, so we cannot continue!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($accounts['destination'])) {
|
if (is_null($accounts['destination'])) {
|
||||||
Log::error('"source"-account is null, so we cannot continue!', ['data' => $data]);
|
Log::error('"destination"-account is null, so we cannot continue!', ['data' => $data]);
|
||||||
throw new FireflyException('"source"-account is null, so we cannot continue!');
|
throw new FireflyException('"destination"-account is null, so we cannot continue!');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,6 +426,19 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Transaction $transaction
|
||||||
|
* @param int $budgetId
|
||||||
|
*/
|
||||||
|
private function storeBudgetWithTransaction(Transaction $transaction, int $budgetId)
|
||||||
|
{
|
||||||
|
if (intval($budgetId) > 0 && $transaction->transactionJournal->transactionType->type !== TransactionType::TRANSFER) {
|
||||||
|
/** @var \FireflyIII\Models\Budget $budget */
|
||||||
|
$budget = Budget::find($budgetId);
|
||||||
|
$transaction->budgets()->save($budget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
* @param string $category
|
* @param string $category
|
||||||
@ -349,6 +451,18 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Transaction $transaction
|
||||||
|
* @param string $category
|
||||||
|
*/
|
||||||
|
private function storeCategoryWithTransaction(Transaction $transaction, string $category)
|
||||||
|
{
|
||||||
|
if (strlen($category) > 0) {
|
||||||
|
$category = Category::firstOrCreateEncrypted(['name' => $category, 'user_id' => $transaction->transactionJournal->user_id]);
|
||||||
|
$transaction->categories()->save($category);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
@ -380,7 +494,61 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
* @param array $transaction
|
||||||
|
* @param int $identifier
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
private function storeSplitTransaction(TransactionJournal $journal, array $transaction, int $identifier): Collection
|
||||||
|
{
|
||||||
|
// store source and destination accounts (depends on type)
|
||||||
|
$accounts = $this->storeAccounts($journal->transactionType, $transaction);
|
||||||
|
|
||||||
|
// store transaction one way:
|
||||||
|
$one = $this->storeTransaction(
|
||||||
|
[
|
||||||
|
'journal' => $journal,
|
||||||
|
'account' => $accounts['source'],
|
||||||
|
'amount' => bcmul(strval($transaction['amount']), '-1'),
|
||||||
|
'description' => $transaction['description'],
|
||||||
|
'category' => null,
|
||||||
|
'budget' => null,
|
||||||
|
'identifier' => $identifier,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$this->storeCategoryWithTransaction($one, $transaction['category']);
|
||||||
|
$this->storeBudgetWithTransaction($one, $transaction['budget_id']);
|
||||||
|
|
||||||
|
// and the other way:
|
||||||
|
$two = $this->storeTransaction(
|
||||||
|
[
|
||||||
|
'journal' => $journal,
|
||||||
|
'account' => $accounts['destination'],
|
||||||
|
'amount' => strval($transaction['amount']),
|
||||||
|
'description' => $transaction['description'],
|
||||||
|
'category' => null,
|
||||||
|
'budget' => null,
|
||||||
|
'identifier' => $identifier,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$this->storeCategoryWithTransaction($two, $transaction['category']);
|
||||||
|
$this->storeBudgetWithTransaction($two, $transaction['budget_id']);
|
||||||
|
|
||||||
|
if ($transaction['piggy_bank_id'] > 0) {
|
||||||
|
$transaction['date'] = $journal->date->format('Y-m-d');
|
||||||
|
event(new TransactionStored($transaction));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Collection([$one, $two]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return Transaction
|
||||||
|
*/
|
||||||
private function storeTransaction(array $data): Transaction
|
private function storeTransaction(array $data): Transaction
|
||||||
{
|
{
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
@ -393,6 +561,9 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
'identifier' => $data['identifier'],
|
'identifier' => $data['identifier'],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Log::debug(sprintf('Transaction stored with ID: %s', $transaction->id));
|
||||||
|
|
||||||
if (!is_null($data['category'])) {
|
if (!is_null($data['category'])) {
|
||||||
$transaction->categories()->save($data['category']);
|
$transaction->categories()->save($data['category']);
|
||||||
}
|
}
|
||||||
@ -415,7 +586,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
$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.*']);
|
||||||
|
|
||||||
if (strlen($data['destination_account_name']) > 0) {
|
if (strlen($data['destination_account_name']) > 0) {
|
||||||
$destinationType = AccountType::where('type', 'Expense account')->first();
|
$destinationType = AccountType::where('type', AccountType::EXPENSE)->first();
|
||||||
$destinationAccount = Account::firstOrCreateEncrypted(
|
$destinationAccount = Account::firstOrCreateEncrypted(
|
||||||
[
|
[
|
||||||
'user_id' => $data['user'],
|
'user_id' => $data['user'],
|
||||||
|
@ -73,4 +73,12 @@ interface JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function update(TransactionJournal $journal, array $data): TransactionJournal;
|
public function update(TransactionJournal $journal, array $data): TransactionJournal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return TransactionJournal
|
||||||
|
*/
|
||||||
|
public function updateSplitJournal(TransactionJournal $journal, array $data): TransactionJournal;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -175,12 +175,15 @@ class JournalTasker implements JournalTaskerInterface
|
|||||||
$join
|
$join
|
||||||
->on('transactions.transaction_journal_id', '=', 'destination.transaction_journal_id')
|
->on('transactions.transaction_journal_id', '=', 'destination.transaction_journal_id')
|
||||||
->where('transactions.amount', '=', DB::raw('destination.amount * -1'))
|
->where('transactions.amount', '=', DB::raw('destination.amount * -1'))
|
||||||
->where('transactions.identifier', '=', DB::raw('destination.identifier'));
|
->where('transactions.identifier', '=', DB::raw('destination.identifier'))
|
||||||
|
->whereNull('destination.deleted_at');
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
->with(['budgets', 'categories'])
|
||||||
->leftJoin('accounts as source_accounts', 'transactions.account_id', '=', 'source_accounts.id')
|
->leftJoin('accounts as source_accounts', 'transactions.account_id', '=', 'source_accounts.id')
|
||||||
->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id')
|
->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id')
|
||||||
->where('transactions.amount', '<', 0)
|
->where('transactions.amount', '<', 0)
|
||||||
|
->whereNull('transactions.deleted_at')
|
||||||
->get(
|
->get(
|
||||||
[
|
[
|
||||||
'transactions.id',
|
'transactions.id',
|
||||||
@ -202,6 +205,8 @@ class JournalTasker implements JournalTaskerInterface
|
|||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
$sourceBalance = $this->getBalance($entry->id);
|
$sourceBalance = $this->getBalance($entry->id);
|
||||||
$destinationBalance = $this->getBalance($entry->destination_id);
|
$destinationBalance = $this->getBalance($entry->destination_id);
|
||||||
|
$budget = $entry->budgets->first();
|
||||||
|
$category = $entry->categories->first();
|
||||||
$transaction = [
|
$transaction = [
|
||||||
'source_id' => $entry->id,
|
'source_id' => $entry->id,
|
||||||
'source_amount' => $entry->amount,
|
'source_amount' => $entry->amount,
|
||||||
@ -218,8 +223,11 @@ class JournalTasker implements JournalTaskerInterface
|
|||||||
intval($entry->destination_account_encrypted) === 1 ? Crypt::decrypt($entry->destination_account_name) : $entry->destination_account_name,
|
intval($entry->destination_account_encrypted) === 1 ? Crypt::decrypt($entry->destination_account_name) : $entry->destination_account_name,
|
||||||
'destination_account_before' => $destinationBalance,
|
'destination_account_before' => $destinationBalance,
|
||||||
'destination_account_after' => bcadd($destinationBalance, bcmul($entry->amount, '-1')),
|
'destination_account_after' => bcadd($destinationBalance, bcmul($entry->amount, '-1')),
|
||||||
|
'budget_id' => is_null($budget) ? 0 : $budget->id,
|
||||||
|
'category' => is_null($category) ? '' : $category->name,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
$transactions[] = $transaction;
|
$transactions[] = $transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,40 +245,6 @@ class JournalTasker implements JournalTaskerInterface
|
|||||||
*/
|
*/
|
||||||
private function getBalance(int $transactionId): string
|
private function getBalance(int $transactionId): string
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
select
|
|
||||||
|
|
||||||
-- transactions.*, transaction_journals.date, transaction_journals.order, transaction_journals.id, transactions.identifier
|
|
||||||
sum(transactions.amount)
|
|
||||||
|
|
||||||
from transactions
|
|
||||||
|
|
||||||
|
|
||||||
and (
|
|
||||||
-- first things first: remove all transaction journals that are newer by selecting only those that are earlier:
|
|
||||||
or
|
|
||||||
-- date is 03 but sorted lower: (fucntion 1)
|
|
||||||
(
|
|
||||||
transaction_journals.date = "2016-09-20"
|
|
||||||
and transaction_journals.order > 2)
|
|
||||||
or
|
|
||||||
-- date is 03 and sort is the same but id is higher (func 2)
|
|
||||||
(transaction_journals.date = "2016-09-20"
|
|
||||||
and transaction_journals.order = 2
|
|
||||||
and transaction_journals.id < 6966
|
|
||||||
)
|
|
||||||
-- date is 03 and sort is the same, and id is the same but identifier is 1 and not 0.(func 3)
|
|
||||||
or
|
|
||||||
(transaction_journals.date = "2016-09-20"
|
|
||||||
and transaction_journals.order = 2
|
|
||||||
and transaction_journals.id = 6966
|
|
||||||
and transactions.identifier > 1
|
|
||||||
)
|
|
||||||
) -- 14048
|
|
||||||
and transactions.id != 14048 -- just in case
|
|
||||||
|
|
||||||
order by transaction_journals.date DESC, transaction_journals.order ASC, transaction_journals.id DESC, transactions.identifier ASC
|
|
||||||
*/
|
|
||||||
// find the transaction first:
|
// find the transaction first:
|
||||||
$transaction = Transaction::find($transactionId);
|
$transaction = Transaction::find($transactionId);
|
||||||
$date = $transaction->transactionJournal->date->format('Y-m-d');
|
$date = $transaction->transactionJournal->date->format('Y-m-d');
|
||||||
|
@ -18,40 +18,58 @@ $(function () {
|
|||||||
$.getJSON('json/expense-accounts').done(function (data) {
|
$.getJSON('json/expense-accounts').done(function (data) {
|
||||||
destAccounts = data;
|
destAccounts = data;
|
||||||
console.log('destAccounts length is now ' + destAccounts.length);
|
console.log('destAccounts length is now ' + destAccounts.length);
|
||||||
|
$('input[name$="destination_account_name]"]').typeahead({source: destAccounts});
|
||||||
});
|
});
|
||||||
|
|
||||||
$.getJSON('json/revenue-accounts').done(function (data) {
|
$.getJSON('json/revenue-accounts').done(function (data) {
|
||||||
srcAccounts = data;
|
srcAccounts = data;
|
||||||
console.log('srcAccounts length is now ' + srcAccounts.length);
|
console.log('srcAccounts length is now ' + srcAccounts.length);
|
||||||
|
$('input[name$="source_account_name]"]').typeahead({source: srcAccounts});
|
||||||
});
|
});
|
||||||
|
|
||||||
$.getJSON('json/categories').done(function (data) {
|
$.getJSON('json/categories').done(function (data) {
|
||||||
categories = data;
|
categories = data;
|
||||||
console.log('categories length is now ' + categories.length);
|
console.log('categories length is now ' + categories.length);
|
||||||
|
$('input[name$="category]"]').typeahead({source: categories});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('input[name="amount[]"]').on('input', calculateSum)
|
$('input[name$="][amount]"]').on('input', calculateSum);
|
||||||
|
|
||||||
|
// add auto complete:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function cloneRow() {
|
function cloneRow() {
|
||||||
"use strict";
|
"use strict";
|
||||||
var source = $('.initial-row').clone();
|
var source = $('.initial-row').clone();
|
||||||
var count = $('.split-table tbody tr').length + 1;
|
var count = $('.split-table tbody tr').length + 1;
|
||||||
|
var index = count - 1;
|
||||||
source.removeClass('initial-row');
|
source.removeClass('initial-row');
|
||||||
source.find('.count').text('#' + count);
|
source.find('.count').text('#' + count);
|
||||||
source.find('input[name="amount[]"]').val("").on('input', calculateSum);
|
|
||||||
|
// get each input, change the name?
|
||||||
|
$.each(source.find('input, select'), function (i, v) {
|
||||||
|
var obj = $(v);
|
||||||
|
var name = obj.attr('name').replace('[0]', '[' + index + ']');
|
||||||
|
obj.attr('name', name);
|
||||||
|
});
|
||||||
|
|
||||||
|
source.find('input[name$="][amount]"]').val("").on('input', calculateSum);
|
||||||
if (destAccounts.length > 0) {
|
if (destAccounts.length > 0) {
|
||||||
console.log('Will be able to extend dest-accounts.');
|
console.log('Will be able to extend dest-accounts.');
|
||||||
source.find('input[name="destination_account_name[]"]').typeahead({source: destAccounts});
|
source.find('input[name$="destination_account_name]"]').typeahead({source: destAccounts});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (destAccounts.length > 0) {
|
if (destAccounts.length > 0) {
|
||||||
console.log('Will be able to extend src-accounts.');
|
console.log('Will be able to extend src-accounts.');
|
||||||
source.find('input[name="source_account_name[]"]').typeahead({source: srcAccounts});
|
source.find('input[name$="source_account_name]"]').typeahead({source: srcAccounts});
|
||||||
}
|
}
|
||||||
if(categories.length > 0) {
|
if (categories.length > 0) {
|
||||||
console.log('Will be able to extend categories.');
|
console.log('Will be able to extend categories.');
|
||||||
source.find('input[name="category[]"]').typeahead({source: categories});
|
source.find('input[name$="category]"]').typeahead({source: categories});
|
||||||
}
|
}
|
||||||
|
|
||||||
$('.split-table tbody').append(source);
|
$('.split-table tbody').append(source);
|
||||||
@ -64,7 +82,7 @@ function cloneRow() {
|
|||||||
function calculateSum() {
|
function calculateSum() {
|
||||||
"use strict";
|
"use strict";
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
var set = $('input[name="amount[]"]');
|
var set = $('input[name$="][amount]"]');
|
||||||
for (var i = 0; i < set.length; i++) {
|
for (var i = 0; i < set.length; i++) {
|
||||||
var current = $(set[i]);
|
var current = $(set[i]);
|
||||||
sum += (current.val() == "" ? 0 : parseFloat(current.val()));
|
sum += (current.val() == "" ? 0 : parseFloat(current.val()));
|
||||||
|
@ -1,270 +0,0 @@
|
|||||||
{% extends "./layout/default.twig" %}
|
|
||||||
|
|
||||||
{% block breadcrumbs %}
|
|
||||||
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, preFilled.what) }}
|
|
||||||
{% endblock %}
|
|
||||||
{% block content %}
|
|
||||||
<form method="POST" action="{{ route('split.journal.store',journal.id) }}" accept-charset="UTF-8" class="form-horizontal" id="update"
|
|
||||||
enctype="multipart/form-data">
|
|
||||||
|
|
||||||
<input name="_token" type="hidden" value="{{ csrf_token() }}">
|
|
||||||
<input type="hidden" name="id" value="{{ journal.id }}"/>
|
|
||||||
<input type="hidden" name="what" value="{{ preFilled.what }}"/>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
A splitted withdrawal has a single source with multiple destinations.
|
|
||||||
Amount X is withdrawn from one account and submitted to multiple accounts.
|
|
||||||
Groceries can be split in several categories this way.
|
|
||||||
|
|
||||||
A splitted deposit has a singe destination and multiple sources.
|
|
||||||
Amount X is deposited from multiple sources.
|
|
||||||
Salary can be split in several types this way (base salary, reimbursements, bonus)
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
{% if errors.all()|length > 0 %}
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
|
||||||
<div class="box box-danger">
|
|
||||||
<div class="box-header with-border">
|
|
||||||
<h3 class="box-title">{{ 'errors'|_ }}</h3>
|
|
||||||
</div>
|
|
||||||
<div class="box-body">
|
|
||||||
<ul>
|
|
||||||
{% for key, err in errors.all() %}
|
|
||||||
<li class="text-danger">{{ err }}</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-6 col-md-6 col-sm-6">
|
|
||||||
<div class="box">
|
|
||||||
<div class="box-header with-border">
|
|
||||||
<h3 class="box-title">{{ 'transaction_data'|_ }}</h3>
|
|
||||||
</div>
|
|
||||||
<div class="box-body">
|
|
||||||
{{ ExpandedForm.text('journal_description', journal.description) }}
|
|
||||||
{{ ExpandedForm.select('journal_currency_id', currencies, journal.transaction_currency_id) }}
|
|
||||||
{{ ExpandedForm.staticText('journal_amount', preFilled.journal_amount|formatAmount ) }}
|
|
||||||
<input type="hidden" name="journal_amount" value="{{ preFilled.journal_amount }}"/>
|
|
||||||
|
|
||||||
<!-- show source if withdrawal or transfer -->
|
|
||||||
{% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %}
|
|
||||||
{{ ExpandedForm.select('journal_source_account_id', assetAccounts, preFilled.journal_source_account_id) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<!-- show destination account id, if deposit (is asset): -->
|
|
||||||
{% if preFilled.what == 'deposit' %}
|
|
||||||
{{ ExpandedForm.select('journal_destination_account_id', assetAccounts, preFilled.journal_destination_account_id) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<!-- show static destination if transfer -->
|
|
||||||
{% if preFilled.what == 'transfer' %}
|
|
||||||
{{ ExpandedForm.select('journal_destination_account_id', assetAccounts, preFilled.journal_destination_account_id) }}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-6 col-md-6 col-sm-6">
|
|
||||||
<div class="box">
|
|
||||||
<div class="box-header with-border">
|
|
||||||
<h3 class="box-title">{{ 'transaction_meta_data'|_ }}</h3>
|
|
||||||
</div>
|
|
||||||
<div class="box-body">
|
|
||||||
{{ ExpandedForm.date('date', journal.date) }}
|
|
||||||
|
|
||||||
{% if optionalFields.interest_date or journal.interest_date %}
|
|
||||||
<!-- INTEREST DATE -->
|
|
||||||
{{ ExpandedForm.date('interest_date', journal.interest_date) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if optionalFields.book_date or journal.book_date %}
|
|
||||||
<!-- BOOK DATE -->
|
|
||||||
{{ ExpandedForm.date('book_date', journal.book_date) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if optionalFields.process_date or journal.process_date %}
|
|
||||||
<!-- PROCESSING DATE -->
|
|
||||||
{{ ExpandedForm.date('process_date', journal.process_date) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if optionalFields.due_date or journal.due_date %}
|
|
||||||
<!-- DUE DATE -->
|
|
||||||
{{ ExpandedForm.date('due_date', journal.due_date) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if optionalFields.payment_date or journal.payment_date %}
|
|
||||||
<!-- PAYMENT DATE -->
|
|
||||||
{{ ExpandedForm.date('payment_date', journal.payment_date) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if optionalFields.internal_reference or journal.internal_reference %}
|
|
||||||
<!-- REFERENCE -->
|
|
||||||
{{ ExpandedForm.text('internal_reference', journal.internal_reference) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if optionalFields.notes or journal.notes %}
|
|
||||||
<!-- NOTES -->
|
|
||||||
{{ ExpandedForm.textarea('notes', journal.notes) }}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
|
||||||
<div class="box">
|
|
||||||
<div class="box-header with-border">
|
|
||||||
<h3 class="box-title">{{ 'splits'|_ }}</h3>
|
|
||||||
</div>
|
|
||||||
<div class="box-body">
|
|
||||||
<table class="table table-bordered table-condensed table-striped split-table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>{{ trans('list.split_number') }}</th>
|
|
||||||
<th>{{ trans('list.description') }}</th>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- withdrawal and deposit have a destination. -->
|
|
||||||
{% if preFilled.what == 'withdrawal' %}
|
|
||||||
<th>{{ trans('list.destination') }}</th>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if preFilled.what == 'deposit' %}
|
|
||||||
<th>{{ trans('list.source') }}</th>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
|
|
||||||
<th>{{ trans('list.amount') }}</th>
|
|
||||||
|
|
||||||
<!-- only withdrawal has budget -->
|
|
||||||
{% if preFilled.what == 'withdrawal' %}
|
|
||||||
<th>{{ trans('list.budget') }}</th>
|
|
||||||
{% endif %}
|
|
||||||
<th>{{ trans('list.category') }}</th>
|
|
||||||
|
|
||||||
{% if preFilled.what == 'transfer' %}
|
|
||||||
<th>{{ trans('list.piggy_bank') }}</th>
|
|
||||||
{% endif %}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for index, descr in preFilled.description %}
|
|
||||||
<tr class="{% if loop.index == 1 %}initial-row{% else %}not-initial-row{% endif %}">
|
|
||||||
<td class="count">#{{ loop.index }}</td>
|
|
||||||
<td>
|
|
||||||
<input type="text" name="description[]" value="{{ descr }}" class="form-control"/>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<!-- withdrawal has several destination names. -->
|
|
||||||
{% if preFilled.what == 'withdrawal' %}
|
|
||||||
<td>
|
|
||||||
<input type="text" name="destination_account_name[]" value="{{ preFilled.destination_account_name[index] }}"
|
|
||||||
class="form-control"/>
|
|
||||||
</td>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<!-- deposit has several source names -->
|
|
||||||
{% if preFilled.what == 'deposit' %}
|
|
||||||
<td>
|
|
||||||
<input type="text" name="source_account_name[]" value="{{ preFilled.source_account_name[index] }}"
|
|
||||||
class="form-control"/>
|
|
||||||
</td>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
|
|
||||||
<td style="width:10%;">
|
|
||||||
<input type="number" name="amount[]" value="{{ preFilled.amount[index] }}"
|
|
||||||
class="form-control" autocomplete="off" step="any" min="0.01">
|
|
||||||
</td>
|
|
||||||
{% if preFilled.what == 'withdrawal' %}
|
|
||||||
<td>
|
|
||||||
<select class="form-control" name="budget_id[]">
|
|
||||||
{% for key, budget in budgets %}
|
|
||||||
<option label="{{ budget }}" value="{{ key }}"
|
|
||||||
{% if preFilled.budget_id[index] == key %}
|
|
||||||
selected="selected"
|
|
||||||
{% endif %}
|
|
||||||
>{{ budget }}</option>
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
{% endif %}
|
|
||||||
<td>
|
|
||||||
<input type="text" name="category[]" value="{{ preFilled.category[index] }}" class="form-control"/>
|
|
||||||
</td>
|
|
||||||
{% if preFilled.what == 'transfer' %}
|
|
||||||
<td>
|
|
||||||
<!-- RELATE THIS TRANSFER TO A PIGGY BANK -->
|
|
||||||
{{ Form.select('piggy_bank_id[]',piggyBanks, preFilled.piggy_bank_id[index], {class: 'form-control'}) }}
|
|
||||||
</td>
|
|
||||||
{% endif %}
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<p>
|
|
||||||
<br/>
|
|
||||||
<a href="#" class="btn btn-default btn-do-split"><i class="fa fa-plus-circle"></i> {{ 'add_another_split'|_ }}</a>
|
|
||||||
</p>
|
|
||||||
<!--<p class="pull-right">
|
|
||||||
<button type="submit" id="transaction-btn" class="btn btn-success pull-right">
|
|
||||||
{{ ('update_splitted_'~preFilled.what)|_ }}
|
|
||||||
</button>
|
|
||||||
</p>
|
|
||||||
-->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
|
|
||||||
{% if optionalFields.attachments %}
|
|
||||||
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
|
||||||
<div class="box">
|
|
||||||
<div class="box-header with-border">
|
|
||||||
<h3 class="box-title">{{ 'optionalFields'|_ }}</h3>
|
|
||||||
</div>
|
|
||||||
<div class="box-body">
|
|
||||||
<!-- ATTACHMENTS -->
|
|
||||||
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
|
|
||||||
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
|
||||||
<!-- panel for options -->
|
|
||||||
<div class="box">
|
|
||||||
<div class="box-header with-border">
|
|
||||||
<h3 class="box-title">{{ 'options'|_ }}</h3>
|
|
||||||
</div>
|
|
||||||
<div class="box-body">
|
|
||||||
{{ ExpandedForm.optionsList('create','split-transaction') }}
|
|
||||||
</div>
|
|
||||||
<div class="box-footer">
|
|
||||||
<button type="submit" class="pull-right btn btn-success">{{ ('store_' ~ preFilled.what)|_ }}</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
{% block scripts %}
|
|
||||||
<script type="text/javascript">
|
|
||||||
var originalSum = {{ preFilled.journal_amount }};
|
|
||||||
var what = "{{ preFilled.what }}";
|
|
||||||
</script>
|
|
||||||
<script type="text/javascript" src="js/lib/bootstrap3-typeahead.min.js"></script>
|
|
||||||
<script type="text/javascript" src="js/ff/transactions/create-edit.js"></script>
|
|
||||||
<script type="text/javascript" src="js/ff/split/journal/from-store.js"></script>
|
|
||||||
{% endblock %}
|
|
||||||
{% block styles %}
|
|
||||||
{% endblock %}
|
|
@ -96,6 +96,7 @@
|
|||||||
<p class="text-center text-success"><i class="fa fa-info-circle" aria-hidden="true"></i>
|
<p class="text-center text-success"><i class="fa fa-info-circle" aria-hidden="true"></i>
|
||||||
<em>{{ trans('firefly.hidden_fields_preferences', {link: route('preferences')})|raw }}</em></p>
|
<em>{{ trans('firefly.hidden_fields_preferences', {link: route('preferences')})|raw }}</em></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- box for dates -->
|
<!-- box for dates -->
|
||||||
{% if
|
{% if
|
||||||
optionalFields.interest_date or optionalFields.book_date or optionalFields.process_date
|
optionalFields.interest_date or optionalFields.book_date or optionalFields.process_date
|
||||||
@ -136,7 +137,6 @@
|
|||||||
{% if optionalFields.invoice_date %}
|
{% if optionalFields.invoice_date %}
|
||||||
{{ ExpandedForm.date('invoice_date') }}
|
{{ ExpandedForm.date('invoice_date') }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -36,73 +36,148 @@
|
|||||||
<h3 class="box-title">{{ 'transaction_data'|_ }}</h3>
|
<h3 class="box-title">{{ 'transaction_data'|_ }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
{{ ExpandedForm.text('journal_description', journal.description) }}
|
|
||||||
{{ ExpandedForm.select('journal_currency_id', currencies, preFilled.transaction_currency_id) }}
|
|
||||||
{{ ExpandedForm.staticText('journal_amount', preFilled.journal_amount|formatAmount ) }}
|
|
||||||
<input type="hidden" name="journal_amount" value="{{ preFilled.journal_amount }}"/>
|
|
||||||
|
|
||||||
<!-- show source if withdrawal or transfer -->
|
{# DESCRIPTION IS ALWAYS AVAILABLE #}
|
||||||
|
{{ ExpandedForm.text('journal_description', journal.description) }}
|
||||||
|
|
||||||
|
{# CURRENCY IS NEW FOR SPLIT JOURNALS #}
|
||||||
|
{{ ExpandedForm.select('journal_currency_id', currencies, preFilled.transaction_currency_id) }}
|
||||||
|
|
||||||
|
{# show source if withdrawal or transfer #}
|
||||||
{% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %}
|
{% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %}
|
||||||
{{ ExpandedForm.select('journal_source_account_id', assetAccounts, preFilled.journal_source_account_id) }}
|
{{ ExpandedForm.select('journal_source_account_id', assetAccounts, preFilled.journal_source_account_id) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- show destination account id, if deposit (is asset): -->
|
{# show destination account id, if deposit (is asset): #}
|
||||||
{% if preFilled.what == 'deposit' %}
|
{% if preFilled.what == 'deposit' %}
|
||||||
{{ ExpandedForm.select('journal_destination_account_id', assetAccounts, preFilled.journal_destination_account_id) }}
|
{{ ExpandedForm.select('journal_destination_account_id', assetAccounts, preFilled.journal_destination_account_id) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- show static destination if transfer -->
|
{# show static destination if transfer #}
|
||||||
{% if preFilled.what == 'transfer' %}
|
{% if preFilled.what == 'transfer' %}
|
||||||
{{ ExpandedForm.select('journal_destination_account_id', assetAccounts, preFilled.journal_destination_account_id) }}
|
{{ ExpandedForm.select('journal_destination_account_id', assetAccounts, preFilled.journal_destination_account_id) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{# TOTAL AMOUNT IS STATIC TEXT #}
|
||||||
|
{{ ExpandedForm.staticText('journal_amount', preFilled.journal_amount|formatAmount ) }}
|
||||||
|
<input type="hidden" name="journal_amount" value="{{ preFilled.journal_amount }}"/>
|
||||||
|
|
||||||
|
{# DATE #}
|
||||||
|
{{ ExpandedForm.date('date', journal.date) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6 col-md-6 col-sm-6">
|
<div class="col-lg-6 col-md-6 col-sm-6">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'transaction_meta_data'|_ }}</h3>
|
<h3 class="box-title">{{ 'optional_field_meta_data'|_ }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
{{ ExpandedForm.date('date', journal.date) }}
|
{# NO BUDGET #}
|
||||||
|
{# NO CATEGORY #}
|
||||||
|
|
||||||
{% if optionalFields.interest_date or journal.interest_date %}
|
{# ALWAYS TAGS #}
|
||||||
<!-- INTEREST DATE -->
|
{{ ExpandedForm.text('tags', preFilled.tags) }}
|
||||||
{{ ExpandedForm.date('interest_date', journal.interest_date) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if optionalFields.book_date or journal.book_date %}
|
{# NO PIGGY BANK #}
|
||||||
<!-- BOOK DATE -->
|
|
||||||
{{ ExpandedForm.date('book_date', journal.book_date) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if optionalFields.process_date or journal.process_date %}
|
|
||||||
<!-- PROCESSING DATE -->
|
|
||||||
{{ ExpandedForm.date('process_date', journal.process_date) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if optionalFields.due_date or journal.due_date %}
|
|
||||||
<!-- DUE DATE -->
|
|
||||||
{{ ExpandedForm.date('due_date', journal.due_date) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if optionalFields.payment_date or journal.payment_date %}
|
|
||||||
<!-- PAYMENT DATE -->
|
|
||||||
{{ ExpandedForm.date('payment_date', journal.payment_date) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if optionalFields.internal_reference or journal.internal_reference %}
|
|
||||||
<!-- REFERENCE -->
|
|
||||||
{{ ExpandedForm.text('internal_reference', journal.internal_reference) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if optionalFields.notes or journal.notes %}
|
|
||||||
<!-- NOTES -->
|
|
||||||
{{ ExpandedForm.textarea('notes', journal.notes) }}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{# EXPLANATION IF NECESSARY: #}
|
||||||
|
{% if
|
||||||
|
not optionalFields.interest_date or
|
||||||
|
not optionalFields.book_date or
|
||||||
|
not optionalFields.process_date or
|
||||||
|
not optionalFields.due_date or
|
||||||
|
not optionalFields.payment_date or
|
||||||
|
not optionalFields.invoice_date or
|
||||||
|
not optionalFields.internal_reference or
|
||||||
|
not optionalFields.notes or
|
||||||
|
not optionalFields.attachments %}
|
||||||
|
<p class="text-center text-success"><i class="fa fa-info-circle" aria-hidden="true"></i>
|
||||||
|
<em>{{ trans('firefly.hidden_fields_preferences', {link: route('preferences')})|raw }}</em></p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# BOX FOR DATES #}
|
||||||
|
{% if
|
||||||
|
optionalFields.interest_date or optionalFields.book_date or optionalFields.process_date
|
||||||
|
or optionalFields.due_date or optionalFields.payment_date
|
||||||
|
or optionalFields.invoice_date %}
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">{{ 'optional_field_meta_dates'|_ }}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
|
||||||
|
{# INTEREST DATE #}
|
||||||
|
{% if optionalFields.interest_date or journal.interest_date %}
|
||||||
|
{{ ExpandedForm.date('interest_date', journal.interest_date) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# BOOK DATE #}
|
||||||
|
{% if optionalFields.book_date or journal.book_date %}
|
||||||
|
{{ ExpandedForm.date('book_date', journal.book_date) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# PROCESSING DATE #}
|
||||||
|
{% if optionalFields.process_date or journal.process_date %}
|
||||||
|
{{ ExpandedForm.date('process_date', journal.process_date) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# DUE DATE #}
|
||||||
|
{% if optionalFields.due_date or journal.due_date %}
|
||||||
|
{{ ExpandedForm.date('due_date', journal.due_date) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# PAYMENT DATE #}
|
||||||
|
{% if optionalFields.payment_date or journal.payment_date %}
|
||||||
|
{{ ExpandedForm.date('payment_date', journal.payment_date) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# INVOICE DATE #}
|
||||||
|
{% if optionalFields.invoice_date or journal.invoice_date %}
|
||||||
|
{{ ExpandedForm.date('invoice_date', journal.invoice_date) }}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# BOX FOR BUSINESS FIELDS #}
|
||||||
|
{% if optionalFields.internal_reference or optionalFields.notes %}
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">{{ 'optional_field_meta_business'|_ }}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
|
||||||
|
{# INTERNAL REFERENCE #}
|
||||||
|
{% if optionalFields.internal_reference or journal.internal_reference %}
|
||||||
|
{{ ExpandedForm.text('internal_reference', journal.internal_reference) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# NOTES #}
|
||||||
|
{% if optionalFields.notes or journal.notes %}
|
||||||
|
{{ ExpandedForm.textarea('notes', journal.notes) }}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# BOX FOR ATTACHMENTS #}
|
||||||
|
{% if optionalFields.attachments %}
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">{{ 'optional_field_attachments'|_ }}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
{# ATTACHMENTS #}
|
||||||
|
{% if optionalFields.attachments %}
|
||||||
|
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -115,39 +190,47 @@
|
|||||||
<table class="table table-bordered table-condensed table-striped split-table">
|
<table class="table table-bordered table-condensed table-striped split-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th> </th>
|
||||||
<th>{{ trans('list.split_number') }}</th>
|
<th>{{ trans('list.split_number') }}</th>
|
||||||
<th>{{ trans('list.description') }}</th>
|
<th>{{ trans('list.description') }}</th>
|
||||||
|
|
||||||
<!-- withdrawal and deposit have a destination. -->
|
{# withdrawal and deposit have a destination. #}
|
||||||
{% if preFilled.what == 'withdrawal' %}
|
{% if preFilled.what == 'withdrawal' %}
|
||||||
<th>{{ trans('list.destination') }}</th>
|
<th>{{ trans('list.destination') }}</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{# DEPOSIT HAS A SOURCE #}
|
||||||
{% if preFilled.what == 'deposit' %}
|
{% if preFilled.what == 'deposit' %}
|
||||||
<th>{{ trans('list.source') }}</th>
|
<th>{{ trans('list.source') }}</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<th>{{ trans('list.amount') }}</th>
|
<th>{{ trans('list.amount') }}</th>
|
||||||
|
|
||||||
<!-- only withdrawal has budget -->
|
{# only withdrawal has budget #}
|
||||||
{% if preFilled.what == 'withdrawal' %}
|
{% if preFilled.what == 'withdrawal' %}
|
||||||
<th>{{ trans('list.budget') }}</th>
|
<th>{{ trans('list.budget') }}</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<th>{{ trans('list.category') }}</th>
|
<th>{{ trans('list.category') }}</th>
|
||||||
|
|
||||||
|
<!-- piggy bank -->
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for index, descr in preFilled.description %}
|
{% for index, transaction in preFilled.transactions %}
|
||||||
<tr class="{% if loop.index == 1 %}initial-row{% else %}not-initial-row{% endif %}">
|
<tr class="{% if loop.index == 1 %}initial-row{% else %}not-initial-row{% endif %}">
|
||||||
|
<td><a href="#" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></a></td>
|
||||||
<td class="count">#{{ loop.index }}</td>
|
<td class="count">#{{ loop.index }}</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="description[]" value="{{ descr }}" class="form-control"/>
|
<input type="text" name="transactions[{{ loop.index0 }}][description]" value="{{ transaction.description }}"
|
||||||
|
class="form-control"/>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<!-- withdrawal has several destination names. -->
|
<!-- withdrawal has several destination names. -->
|
||||||
{% if preFilled.what == 'withdrawal' %}
|
{% if preFilled.what == 'withdrawal' %}
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="destination_account_name[]" value="{{ preFilled.destination_account_name[index] }}"
|
<input type="text" name="transactions[{{ loop.index0 }}][destination_account_name]"
|
||||||
|
value="{{ transaction.destination_account_name }}"
|
||||||
class="form-control"/>
|
class="form-control"/>
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -155,22 +238,24 @@
|
|||||||
<!-- deposit has several source names -->
|
<!-- deposit has several source names -->
|
||||||
{% if preFilled.what == 'deposit' %}
|
{% if preFilled.what == 'deposit' %}
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="source_account_name[]" value="{{ preFilled.source_account_name[index] }}"
|
<input type="text" name="transactions[{{ loop.index0 }}][source_account_name]"
|
||||||
|
value="{{ transaction.source_account_name }}"
|
||||||
class="form-control"/>
|
class="form-control"/>
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
<td style="width:10%;">
|
<td style="width:10%;">
|
||||||
<input type="number" name="amount[]" value="{{ preFilled.amount[index] }}"
|
<input type="number" name="transactions[{{ loop.index0 }}][amount]" value="{{ transaction.amount }}"
|
||||||
class="form-control" autocomplete="off" step="any" min="0.01">
|
class="form-control" autocomplete="off" step="any" min="0.01">
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
{% if preFilled.what == 'withdrawal' %}
|
{% if preFilled.what == 'withdrawal' %}
|
||||||
<td>
|
<td>
|
||||||
<select class="form-control" name="budget_id[]">
|
<select class="form-control" name="transactions[{{ loop.index0 }}][budget_id]">
|
||||||
{% for key, budget in budgets %}
|
{% for key, budget in budgets %}
|
||||||
<option label="{{ budget }}" value="{{ key }}"
|
<option label="{{ budget }}" value="{{ key }}"
|
||||||
{% if preFilled.budget_id[index] == key %}
|
{% if transaction.budget_id == key %}
|
||||||
selected="selected"
|
selected="selected"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
>{{ budget }}</option>
|
>{{ budget }}</option>
|
||||||
@ -179,7 +264,8 @@
|
|||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="category[]" value="{{ preFilled.category[index] }}" class="form-control"/>
|
<input type="text" name="transactions[{{ loop.index0 }}][category]" value="{{ transaction.category }}"
|
||||||
|
class="form-control" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -189,30 +275,11 @@
|
|||||||
<br/>
|
<br/>
|
||||||
<a href="#" class="btn btn-default btn-do-split"><i class="fa fa-plus-circle"></i> {{ 'add_another_split'|_ }}</a>
|
<a href="#" class="btn btn-default btn-do-split"><i class="fa fa-plus-circle"></i> {{ 'add_another_split'|_ }}</a>
|
||||||
</p>
|
</p>
|
||||||
<!--<p class="pull-right">
|
|
||||||
<button type="submit" id="transaction-btn" class="btn btn-success pull-right">
|
|
||||||
{{ ('update_splitted_'~preFilled.what)|_ }}
|
|
||||||
</button>
|
|
||||||
</p>
|
|
||||||
-->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% if optionalFields.attachments %}
|
|
||||||
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
|
||||||
<div class="box">
|
|
||||||
<div class="box-header with-border">
|
|
||||||
<h3 class="box-title">{{ 'optionalFields'|_ }}</h3>
|
|
||||||
</div>
|
|
||||||
<div class="box-body">
|
|
||||||
<!-- ATTACHMENTS -->
|
|
||||||
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
||||||
<!-- panel for options -->
|
<!-- panel for options -->
|
||||||
<div class="box">
|
<div class="box">
|
||||||
@ -231,14 +298,16 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
{% block styles %}
|
||||||
|
<link href="css/bootstrap-tagsinput.css" type="text/css" rel="stylesheet" media="all">
|
||||||
|
{% endblock %}
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var originalSum = {{ preFilled.journal_amount }};
|
var originalSum = {{ preFilled.journal_amount }};
|
||||||
var what = "{{ preFilled.what }}";
|
var what = "{{ preFilled.what }}";
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="js/lib/bootstrap3-typeahead.min.js"></script>
|
<script type="text/javascript" src="js/lib/bootstrap3-typeahead.min.js"></script>
|
||||||
|
<script type="text/javascript" src="js/lib/bootstrap-tagsinput.min.js"></script>
|
||||||
<script type="text/javascript" src="js/ff/transactions/create-edit.js"></script>
|
<script type="text/javascript" src="js/ff/transactions/create-edit.js"></script>
|
||||||
<script type="text/javascript" src="js/ff/split/journal/from-store.js"></script>
|
<script type="text/javascript" src="js/ff/split/journal/from-store.js"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block styles %}
|
|
||||||
{% endblock %}
|
|
@ -33,15 +33,15 @@
|
|||||||
<h3 class="box-title">{{ 'mandatoryFields'|_ }}</h3>
|
<h3 class="box-title">{{ 'mandatoryFields'|_ }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
<!-- ALWAYS AVAILABLE -->
|
{# ALWAYS AVAILABLE #}
|
||||||
{{ ExpandedForm.text('description',journal.description) }}
|
{{ ExpandedForm.text('description',journal.description) }}
|
||||||
|
|
||||||
<!-- SELECTABLE SOURCE ACCOUNT ONLY FOR WITHDRAWALS AND TRANSFERS -->
|
{# SELECTABLE SOURCE ACCOUNT ONLY FOR WITHDRAWALS AND TRANSFERS #}
|
||||||
{% if what == 'transfer' or what == 'withdrawal' %}
|
{% if what == 'transfer' or what == 'withdrawal' %}
|
||||||
{{ ExpandedForm.select('source_account_id',assetAccounts, data.source_account_id, {label: trans('form.asset_source_account')}) }}
|
{{ ExpandedForm.select('source_account_id',assetAccounts, data.source_account_id, {label: trans('form.asset_source_account')}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- FREE FORMAT SOURCE ACCOUNT ONLY FOR DEPOSITS -->
|
{# FREE FORMAT SOURCE ACCOUNT ONLY FOR DEPOSITS #}
|
||||||
{% if what == 'deposit' %}
|
{% if what == 'deposit' %}
|
||||||
{{ ExpandedForm.text('source_account_name',data.source_account_name, {label: trans('form.revenue_account')}) }}
|
{{ ExpandedForm.text('source_account_name',data.source_account_name, {label: trans('form.revenue_account')}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -99,8 +99,8 @@
|
|||||||
not optionalFields.process_date or
|
not optionalFields.process_date or
|
||||||
not optionalFields.due_date or
|
not optionalFields.due_date or
|
||||||
not optionalFields.payment_date or
|
not optionalFields.payment_date or
|
||||||
not optionalFields.internal_reference or
|
|
||||||
not optionalFields.invoice_date or
|
not optionalFields.invoice_date or
|
||||||
|
not optionalFields.internal_reference or
|
||||||
not optionalFields.notes or
|
not optionalFields.notes or
|
||||||
not optionalFields.attachments %}
|
not optionalFields.attachments %}
|
||||||
<p class="text-center text-success"><i class="fa fa-info-circle" aria-hidden="true"></i>
|
<p class="text-center text-success"><i class="fa fa-info-circle" aria-hidden="true"></i>
|
||||||
|
@ -363,14 +363,6 @@ Route::group(
|
|||||||
*/
|
*/
|
||||||
Route::get('/search', ['uses' => 'SearchController@index', 'as' => 'search']);
|
Route::get('/search', ['uses' => 'SearchController@index', 'as' => 'search']);
|
||||||
|
|
||||||
/**
|
|
||||||
* Split controller
|
|
||||||
*/
|
|
||||||
|
|
||||||
Route::get('/transaction/create-split/{unfinishedJournal}', ['uses' => 'Transaction\SplitController@create', 'as' => 'split.journal.create']);
|
|
||||||
Route::post('/transaction/store-split/{unfinishedJournal}', ['uses' => 'Transaction\SplitController@store', 'as' => 'split.journal.store']);
|
|
||||||
Route::get('/transaction/edit-split/{tj}', ['uses' => 'Transaction\SplitController@edit', 'as' => 'split.journal.edit']);
|
|
||||||
Route::post('/transaction/edit-split/{tj}', ['uses' => 'Transaction\SplitController@update', 'as' => 'split.journal.update']);
|
|
||||||
/**
|
/**
|
||||||
* Tag Controller
|
* Tag Controller
|
||||||
*/
|
*/
|
||||||
@ -411,6 +403,8 @@ Route::group(
|
|||||||
Route::post('/transactions/mass-destroy', ['uses' => 'Transaction\MassController@massDestroy', 'as' => 'transactions.mass-destroy']);
|
Route::post('/transactions/mass-destroy', ['uses' => 'Transaction\MassController@massDestroy', 'as' => 'transactions.mass-destroy']);
|
||||||
|
|
||||||
// split (will be here):
|
// split (will be here):
|
||||||
|
Route::get('/transaction/split/edit/{tj}', ['uses' => 'Transaction\SplitController@edit', 'as' => 'transactions.edit-split']);
|
||||||
|
Route::post('/transaction/split/update/{tj}', ['uses' => 'Transaction\SplitController@update', 'as' => 'split.journal.update']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POPUP Controllers
|
* POPUP Controllers
|
||||||
|
Loading…
Reference in New Issue
Block a user