More code for split and small bug fix in attachment helper.

This commit is contained in:
James Cole
2016-04-30 09:48:39 +02:00
parent 11ea4b6d47
commit 4ec6bcc8c7
10 changed files with 126 additions and 27 deletions

View File

@@ -85,6 +85,7 @@ class Journal implements JournalInterface
'account_id' => $sourceAccount->id,
'transaction_journal_id' => $journal->id,
'amount' => $transaction['amount'] * -1,
'description' => $transaction['description'],
]
);
@@ -94,6 +95,7 @@ class Journal implements JournalInterface
'account_id' => $destinationAccount->id,
'transaction_journal_id' => $journal->id,
'amount' => $transaction['amount'],
'description' => $transaction['description'],
]
);
@@ -133,8 +135,8 @@ class Journal implements JournalInterface
list($sourceAccount, $destinationAccount) = $this->storeDepositAccounts($transaction);
break;
case TransactionType::TRANSFER:
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['account_from_id'])->first();
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['account_to_id'])->first();
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $transaction['source_account_id'])->first();
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $transaction['destination_account_id'])->first();
break;
default:
throw new FireflyException('Cannot handle ' . e($type));
@@ -150,7 +152,7 @@ class Journal implements JournalInterface
*/
private function storeDepositAccounts(array $data): array
{
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['account_destination_id'])->first(['accounts.*']);
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first(['accounts.*']);
if (strlen($data['source_account_name']) > 0) {
$fromType = AccountType::where('type', 'Revenue account')->first();

View File

@@ -251,6 +251,7 @@ class AttachmentHelper implements AttachmentHelperInterface
$this->processFile($entry, $model);
}
}
return true;
}

View File

@@ -18,6 +18,7 @@ use FireflyIII\Http\Requests\SplitJournalFormRequest;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Log;
use Session;
/**
@@ -40,8 +41,9 @@ class SplitController extends Controller
/** @var BudgetRepositoryInterface $budgetRepository */
$budgetRepository = app(BudgetRepositoryInterface::class);
// expect data to be in session or in post?
$journalData = session('temporary_split_data');
$journalData = session('temporary_split_data');
$currencies = ExpandedForm::makeSelectList($currencyRepository->get());
$assetAccounts = ExpandedForm::makeSelectList($accountRepository->getAccounts(['Default account', 'Asset account']));
$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
@@ -49,6 +51,9 @@ class SplitController extends Controller
throw new FireflyException('Could not find transaction data in your session. Please go back and try again.'); // translate me.
}
Log::debug('Journal data', $journalData);
return view('split.journals.from-store', compact('currencies', 'assetAccounts', 'budgets'))->with('data', $journalData);

View File

@@ -39,7 +39,7 @@ class JournalFormRequest extends Request
'description' => $this->get('description'),
'source_account_id' => intval($this->get('source_account_id')),
'source_account_name' => $this->get('source_account_name') ?? '',
'account_destination_id' => intval($this->get('account_destination_id')),
'destination_account_id' => intval($this->get('destination_account_id')),
'destination_account_name' => $this->get('destination_account_name') ?? '',
'amount' => round($this->get('amount'), 2),
'user' => Auth::user()->id,

View File

@@ -35,25 +35,28 @@ class SplitJournalFormRequest extends Request
public function getSplitData(): array
{
$data = [
'description' => $this->get('journal_description'),
'currency_id' => intval($this->get('currency')),
'source_account_id' => intval($this->get('source_account_id')),
'date' => new Carbon($this->get('date')),
'what' => $this->get('what'),
'interest_date' => $this->get('interest_date') ? new Carbon($this->get('interest_date')) : null,
'book_date' => $this->get('book_date') ? new Carbon($this->get('book_date')) : null,
'process_date' => $this->get('process_date') ? new Carbon($this->get('process_date')) : null,
'transactions' => [],
'description' => $this->get('journal_description'),
'currency_id' => intval($this->get('currency')),
'source_account_id' => intval($this->get('source_account_id')),
'source_account_name' => $this->get('source_account_name'),
'date' => new Carbon($this->get('date')),
'what' => $this->get('what'),
'interest_date' => $this->get('interest_date') ? new Carbon($this->get('interest_date')) : null,
'book_date' => $this->get('book_date') ? new Carbon($this->get('book_date')) : null,
'process_date' => $this->get('process_date') ? new Carbon($this->get('process_date')) : null,
'transactions' => [],
];
// description is leading because it is one of the mandatory fields.
foreach ($this->get('description') as $index => $description) {
$transaction = [
'description' => $description,
'amount' => round($this->get('amount')[$index], 2),
'budget_id' => $this->get('budget')[$index] ? $this->get('budget')[$index] : 0,
'budget_id' => $this->get('budget')[$index] ? intval($this->get('budget')[$index]) : 0,
'category' => $this->get('category')[$index] ?? '',
'source_account_id' => intval($this->get('source_account_id')),
'destination_account_name' => $this->get('destination_account_name')[$index] ?? ''
'source_account_name' => $this->get('source_account_name'),
'destination_account_id' => $this->get('destination_account_id')[$index] ? intval($this->get('destination_account_id')[$index]) : 0,
'destination_account_name' => $this->get('destination_account_name')[$index] ?? '',
];
$data['transactions'][] = $transaction;
}
@@ -70,12 +73,14 @@ class SplitJournalFormRequest extends Request
'journal_description' => 'required|between:1,255',
'currency' => 'required|exists:transaction_currencies,id',
'source_account_id' => 'numeric|belongsToUser:accounts,id',
'source_account_name.*' => 'between:1,255',
'what' => 'required|in:withdrawal,deposit,transfer',
'date' => 'required|date',
'interest_date' => 'date',
'book_date' => 'date',
'process_date' => 'date',
'description.*' => 'required|between:1,255',
'destination_account_id.*' => 'numeric|belongsToUser:accounts,id',
'destination_account_name.*' => 'between:1,255',
'amount.*' => 'required|numeric',
'budget.*' => 'belongsToUser:budgets,id',

View File

@@ -431,7 +431,7 @@ class JournalRepository implements JournalRepositoryInterface
*/
protected function storeDepositAccounts(array $data): array
{
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['account_destination_id'])->first(['accounts.*']);
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first(['accounts.*']);
if (strlen($data['source_account_name']) > 0) {
$fromType = AccountType::where('type', 'Revenue account')->first();