mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Building split transactions and fixing tests.
This commit is contained in:
parent
21a197ba46
commit
eb3d2b1749
@ -53,8 +53,8 @@ class Journal implements JournalInterface
|
|||||||
[
|
[
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
'transaction_type_id' => $transactionType->id,
|
'transaction_type_id' => $transactionType->id,
|
||||||
'transaction_currency_id' => $data['currency_id'],
|
'transaction_currency_id' => $data['journal_currency_id'],
|
||||||
'description' => $data['description'],
|
'description' => $data['journal_description'],
|
||||||
'completed' => 0,
|
'completed' => 0,
|
||||||
'date' => $data['date'],
|
'date' => $data['date'],
|
||||||
'interest_date' => $data['interest_date'],
|
'interest_date' => $data['interest_date'],
|
||||||
|
@ -19,8 +19,10 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Log;
|
use Log;
|
||||||
use Session;
|
use Session;
|
||||||
|
use View;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SplitController
|
* Class SplitController
|
||||||
@ -32,8 +34,31 @@ class SplitController extends Controller
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function journalFromStore()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
parent::__construct();
|
||||||
|
View::share('mainTitleIcon', 'fa-share-alt');
|
||||||
|
View::share('title', trans('firefly.split-transactions'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
public function journalFromStore(Request $request)
|
||||||
|
{
|
||||||
|
if ($request->old('journal_currency_id')) {
|
||||||
|
$preFilled = $this->arrayFromOldData($request->old());
|
||||||
|
} else {
|
||||||
|
$preFilled = $this->arrayFromSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
Session::flash('preFilled', $preFilled);
|
||||||
|
View::share('subTitle', trans('firefly.split-new-transaction'));
|
||||||
|
|
||||||
/** @var CurrencyRepositoryInterface $currencyRepository */
|
/** @var CurrencyRepositoryInterface $currencyRepository */
|
||||||
$currencyRepository = app(CurrencyRepositoryInterface::class);
|
$currencyRepository = app(CurrencyRepositoryInterface::class);
|
||||||
/** @var AccountRepositoryInterface $accountRepository */
|
/** @var AccountRepositoryInterface $accountRepository */
|
||||||
@ -45,20 +70,16 @@ class SplitController extends Controller
|
|||||||
/** @var PiggyBankRepositoryInterface $piggyBankRepository */
|
/** @var PiggyBankRepositoryInterface $piggyBankRepository */
|
||||||
$piggyBankRepository = app(PiggyBankRepositoryInterface::class);
|
$piggyBankRepository = app(PiggyBankRepositoryInterface::class);
|
||||||
|
|
||||||
// expect data to be in session or in post?
|
|
||||||
$journalData = session('temporary_split_data');
|
|
||||||
$currencies = ExpandedForm::makeSelectList($currencyRepository->get());
|
$currencies = ExpandedForm::makeSelectList($currencyRepository->get());
|
||||||
$assetAccounts = ExpandedForm::makeSelectList($accountRepository->getAccounts(['Default account', 'Asset account']));
|
$assetAccounts = ExpandedForm::makeSelectList($accountRepository->getAccounts(['Default account', 'Asset account']));
|
||||||
$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
|
$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
|
||||||
$piggyBanks = ExpandedForm::makeSelectListWithEmpty($piggyBankRepository->getPiggyBanks());
|
$piggyBanks = ExpandedForm::makeSelectListWithEmpty($piggyBankRepository->getPiggyBanks());
|
||||||
if (!is_array($journalData)) {
|
|
||||||
throw new FireflyException('Could not find transaction data in your session. Please go back and try again.'); // translate me.
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::debug('Journal data', $journalData);
|
//Session::flash('warning', 'This feature is very experimental. Beware.');
|
||||||
|
|
||||||
|
|
||||||
return view('split.journals.from-store', compact('currencies', 'piggyBanks', 'assetAccounts', 'budgets'))->with('data', $journalData);
|
return view('split.journals.from-store', compact('currencies', 'piggyBanks', 'assetAccounts', 'budgets'))->with('data', $preFilled);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -77,6 +98,9 @@ class SplitController extends Controller
|
|||||||
$journal = $repository->storeJournal($data);
|
$journal = $repository->storeJournal($data);
|
||||||
// Then, store each transaction individually.
|
// Then, store each transaction individually.
|
||||||
|
|
||||||
|
if (is_null($journal->id)) {
|
||||||
|
throw new FireflyException('Could not store transaction.');
|
||||||
|
}
|
||||||
foreach ($data['transactions'] as $transaction) {
|
foreach ($data['transactions'] as $transaction) {
|
||||||
$transactions = $repository->storeTransaction($journal, $transaction);
|
$transactions = $repository->storeTransaction($journal, $transaction);
|
||||||
}
|
}
|
||||||
@ -92,4 +116,74 @@ class SplitController extends Controller
|
|||||||
return redirect(session('transactions.create.url'));
|
return redirect(session('transactions.create.url'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $old
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function arrayFromOldData(array $old): array
|
||||||
|
{
|
||||||
|
// this array is pretty much equal to what we expect it to be.
|
||||||
|
Log::debug('Prefilled', $old);
|
||||||
|
|
||||||
|
return $old;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
private function arrayFromSession(): array
|
||||||
|
{
|
||||||
|
// expect data to be in session or in post?
|
||||||
|
$data = session('temporary_split_data');
|
||||||
|
|
||||||
|
if (!is_array($data)) {
|
||||||
|
Log::error('Could not find transaction data in your session. Please go back and try again.', ['data' => $data]); // translate me.
|
||||||
|
throw new FireflyException('Could not find transaction data in your session. Please go back and try again.'); // translate me.
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug('Journal data', $data);
|
||||||
|
|
||||||
|
$preFilled = [
|
||||||
|
'what' => $data['what'],
|
||||||
|
'journal_description' => $data['description'],
|
||||||
|
'journal_source_account_id' => $data['source_account_id'],
|
||||||
|
'journal_source_account_name' => $data['source_account_name'],
|
||||||
|
'journal_destination_account_id' => $data['destination_account_id'],
|
||||||
|
'journal_destination_account_name' => $data['destination_account_name'],
|
||||||
|
'journal_amount' => $data['amount'],
|
||||||
|
'journal_currency_id' => $data['amount_currency_id_amount'],
|
||||||
|
'date' => $data['date'],
|
||||||
|
'interest_date' => $data['interest_date'],
|
||||||
|
'book_date' => $data['book_date'],
|
||||||
|
'process_date' => $data['process_date'],
|
||||||
|
|
||||||
|
'description' => [],
|
||||||
|
'destination_account_id' => [],
|
||||||
|
'destination_account_name' => [],
|
||||||
|
'amount' => [],
|
||||||
|
'budget_id' => [],
|
||||||
|
'category' => [],
|
||||||
|
'piggy_bank_id' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
// create the first transaction:
|
||||||
|
$preFilled['description'][] = $data['description'];
|
||||||
|
$preFilled['destination_account_id'][] = $data['destination_account_id'];
|
||||||
|
$preFilled['destination_account_name'][] = $data['destination_account_name'];
|
||||||
|
$preFilled['amount'][] = $data['amount'];
|
||||||
|
$preFilled['budget_id'][] = $data['budget_id'];
|
||||||
|
$preFilled['category'][] = $data['category'];
|
||||||
|
$preFilled['piggy_bank_id'][] = $data['piggy_bank_id'];
|
||||||
|
|
||||||
|
// echo '<pre>';
|
||||||
|
// var_dump($data);
|
||||||
|
// var_dump($preFilled);
|
||||||
|
// exit;
|
||||||
|
Log::debug('Prefilled', $preFilled);
|
||||||
|
|
||||||
|
return $preFilled;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -30,6 +30,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Input;
|
use Input;
|
||||||
|
use Log;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Response;
|
use Response;
|
||||||
use Session;
|
use Session;
|
||||||
@ -437,6 +438,7 @@ class TransactionController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository, AttachmentHelperInterface $att)
|
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository, AttachmentHelperInterface $att)
|
||||||
{
|
{
|
||||||
|
Log::debug('Start of store.');
|
||||||
$doSplit = intval($request->get('split_journal')) === 1;
|
$doSplit = intval($request->get('split_journal')) === 1;
|
||||||
$journalData = $request->getJournalData();
|
$journalData = $request->getJournalData();
|
||||||
if ($doSplit) {
|
if ($doSplit) {
|
||||||
@ -445,6 +447,7 @@ class TransactionController extends Controller
|
|||||||
|
|
||||||
return redirect(route('split.journal.from-store'));
|
return redirect(route('split.journal.from-store'));
|
||||||
}
|
}
|
||||||
|
Log::debug('Not in split.');
|
||||||
|
|
||||||
// if not withdrawal, unset budgetid.
|
// if not withdrawal, unset budgetid.
|
||||||
if ($journalData['what'] != strtolower(TransactionType::WITHDRAWAL)) {
|
if ($journalData['what'] != strtolower(TransactionType::WITHDRAWAL)) {
|
||||||
@ -493,6 +496,8 @@ class TransactionController extends Controller
|
|||||||
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, AttachmentHelperInterface $att, TransactionJournal $journal)
|
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, AttachmentHelperInterface $att, TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
$journalData = $request->getJournalData();
|
$journalData = $request->getJournalData();
|
||||||
|
Log::debug('Will update journal ', $journal->toArray());
|
||||||
|
Log::debug('Update related data ', $journalData);
|
||||||
$repository->update($journal, $journalData);
|
$repository->update($journal, $journalData);
|
||||||
|
|
||||||
// save attachments:
|
// save attachments:
|
||||||
|
@ -35,10 +35,12 @@ class SplitJournalFormRequest extends Request
|
|||||||
public function getSplitData(): array
|
public function getSplitData(): array
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'description' => $this->get('journal_description'),
|
'journal_description' => $this->get('journal_description'),
|
||||||
'currency_id' => intval($this->get('currency')),
|
'journal_currency_id' => intval($this->get('journal_currency_id')),
|
||||||
'source_account_id' => intval($this->get('source_account_id')),
|
'journal_source_account_id' => intval($this->get('journal_source_account_id')),
|
||||||
'source_account_name' => $this->get('source_account_name'),
|
'journal_source_account_name' => $this->get('journal_source_account_name'),
|
||||||
|
'journal_destination_account_id' => intval($this->get('journal_source_destination_id')),
|
||||||
|
'journal_destination_account_name' => $this->get('journal_source_destination_name'),
|
||||||
'date' => new Carbon($this->get('date')),
|
'date' => new Carbon($this->get('date')),
|
||||||
'what' => $this->get('what'),
|
'what' => $this->get('what'),
|
||||||
'interest_date' => $this->get('interest_date') ? new Carbon($this->get('interest_date')) : null,
|
'interest_date' => $this->get('interest_date') ? new Carbon($this->get('interest_date')) : null,
|
||||||
@ -46,15 +48,16 @@ class SplitJournalFormRequest extends Request
|
|||||||
'process_date' => $this->get('process_date') ? new Carbon($this->get('process_date')) : null,
|
'process_date' => $this->get('process_date') ? new Carbon($this->get('process_date')) : null,
|
||||||
'transactions' => [],
|
'transactions' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
// description is leading because it is one of the mandatory fields.
|
// description is leading because it is one of the mandatory fields.
|
||||||
foreach ($this->get('description') as $index => $description) {
|
foreach ($this->get('description') as $index => $description) {
|
||||||
$transaction = [
|
$transaction = [
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'amount' => round($this->get('amount')[$index], 2),
|
'amount' => round($this->get('amount')[$index], 2),
|
||||||
'budget_id' => $this->get('budget')[$index] ? intval($this->get('budget')[$index]) : 0,
|
'budget_id' => $this->get('budget_id')[$index] ? intval($this->get('budget_id')[$index]) : 0,
|
||||||
'category' => $this->get('category')[$index] ?? '',
|
'category' => $this->get('category')[$index] ?? '',
|
||||||
'source_account_id' => intval($this->get('source_account_id')),
|
'source_account_id' => intval($this->get('journal_source_account_id')),
|
||||||
'source_account_name' => $this->get('source_account_name'),
|
'source_account_name' => $this->get('journal_source_account_name'),
|
||||||
'destination_account_id' => isset($this->get('destination_account_id')[$index])
|
'destination_account_id' => isset($this->get('destination_account_id')[$index])
|
||||||
? intval($this->get('destination_account_id')[$index])
|
? intval($this->get('destination_account_id')[$index])
|
||||||
: intval($this->get('destination_account_id')),
|
: intval($this->get('destination_account_id')),
|
||||||
@ -72,21 +75,23 @@ class SplitJournalFormRequest extends Request
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'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',
|
'what' => 'required|in:withdrawal,deposit,transfer',
|
||||||
|
'journal_description' => 'required|between:1,255',
|
||||||
|
'journal_source_account_id' => 'numeric|belongsToUser:accounts,id',
|
||||||
|
'journal_source_account_name.*' => 'between:1,255',
|
||||||
|
'journal_currency_id' => 'required|exists:transaction_currencies,id',
|
||||||
'date' => 'required|date',
|
'date' => 'required|date',
|
||||||
'interest_date' => 'date',
|
'interest_date' => 'date',
|
||||||
'book_date' => 'date',
|
'book_date' => 'date',
|
||||||
'process_date' => 'date',
|
'process_date' => 'date',
|
||||||
|
|
||||||
'description.*' => 'required|between:1,255',
|
'description.*' => 'required|between:1,255',
|
||||||
'destination_account_id.*' => 'numeric|belongsToUser:accounts,id',
|
'destination_account_id.*' => 'numeric|belongsToUser:accounts,id',
|
||||||
'destination_account_name.*' => 'between:1,255',
|
'destination_account_name.*' => 'between:1,255',
|
||||||
'amount.*' => 'required|numeric',
|
'amount.*' => 'required|numeric',
|
||||||
'budget.*' => 'belongsToUser:budgets,id',
|
'budget_id.*' => 'belongsToUser:budgets,id',
|
||||||
'category.*' => 'between:1,255',
|
'category.*' => 'between:1,255',
|
||||||
|
'piggy_bank_id.*' => 'between:1,255',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,7 +3,6 @@
|
|||||||
use Auth;
|
use Auth;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Crypt;
|
use Crypt;
|
||||||
use DB;
|
|
||||||
use FireflyIII\Support\Models\TransactionJournalSupport;
|
use FireflyIII\Support\Models\TransactionJournalSupport;
|
||||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
@ -325,7 +324,6 @@ class TransactionJournal extends TransactionJournalSupport
|
|||||||
*/
|
*/
|
||||||
public function scopeExpanded(EloquentBuilder $query)
|
public function scopeExpanded(EloquentBuilder $query)
|
||||||
{
|
{
|
||||||
$query->distinct();
|
|
||||||
// left join transaction type:
|
// left join transaction type:
|
||||||
if (!self::isJoined($query, 'transaction_types')) {
|
if (!self::isJoined($query, 'transaction_types')) {
|
||||||
$query->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id');
|
$query->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id');
|
||||||
@ -336,39 +334,12 @@ class TransactionJournal extends TransactionJournalSupport
|
|||||||
|
|
||||||
// left join destination (for amount and account info).
|
// left join destination (for amount and account info).
|
||||||
$query->leftJoin(
|
$query->leftJoin(
|
||||||
'transactions as destination', function (JoinClause $join) {
|
'transactions', function (JoinClause $join) {
|
||||||
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
|
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '>', 0);
|
||||||
->where('destination.amount', '>', 0);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// join destination account
|
|
||||||
$query->leftJoin('accounts as destination_account', 'destination_account.id', '=', 'destination.account_id');
|
|
||||||
// join destination account type
|
|
||||||
$query->leftJoin('account_types as destination_acct_type', 'destination_account.account_type_id', '=', 'destination_acct_type.id');
|
|
||||||
|
|
||||||
// left join source (for amount and account info).
|
|
||||||
$query->leftJoin(
|
|
||||||
'transactions as source', function (JoinClause $join) {
|
|
||||||
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
|
|
||||||
->where('source.amount', '<', 0);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
// join destination account
|
|
||||||
$query->leftJoin('accounts as source_account', 'source_account.id', '=', 'source.account_id');
|
|
||||||
// join destination account type
|
|
||||||
$query->leftJoin('account_types as source_acct_type', 'source_account.account_type_id', '=', 'source_acct_type.id')
|
|
||||||
->orderBy('transaction_journals.date', 'DESC')->orderBy('transaction_journals.order', 'ASC')->orderBy('transaction_journals.id', 'DESC');
|
|
||||||
|
|
||||||
// something else:
|
|
||||||
$query->where(DB::raw('`destination`.`amount` * -1'),'=',DB::raw('`source`.`amount`'));
|
|
||||||
|
|
||||||
// group:
|
|
||||||
$query->groupBy('transaction_journals.id');
|
$query->groupBy('transaction_journals.id');
|
||||||
$query->groupBy('source.id');
|
$query->with(['categories', 'budgets', 'attachments', 'bill','transactions']);
|
||||||
|
|
||||||
$query->with(['categories', 'budgets', 'attachments', 'bill']);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,7 @@ use FireflyIII\Models\TransactionType;
|
|||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
@ -232,23 +233,20 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end): Collection
|
public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end): Collection
|
||||||
{
|
{
|
||||||
$set = $this->user
|
$query = $this->user
|
||||||
->transactionjournals()
|
->transactionjournals()
|
||||||
->expanded()
|
->expanded()
|
||||||
->where('source_account.id', $account->id)
|
|
||||||
// ->with(['transactions'])
|
|
||||||
// ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
|
||||||
// ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id)
|
|
||||||
// ->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transaction_journals.transaction_currency_id')
|
|
||||||
// ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
|
||||||
->before($end)
|
->before($end)
|
||||||
->after($start)
|
->after($start);
|
||||||
// ->orderBy('transaction_journals.date', 'DESC')
|
|
||||||
// ->orderBy('transaction_journals.order', 'ASC')
|
// expand query:
|
||||||
// ->orderBy('transaction_journals.id', 'DESC')
|
$query->leftJoin(
|
||||||
->take(10)
|
'transactions as source', function (JoinClause $join) {
|
||||||
// ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']);
|
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id');
|
||||||
->get(TransactionJournal::queryFields());
|
}
|
||||||
|
)->where('source.account_id', $account->id);
|
||||||
|
|
||||||
|
$set = $query->get(TransactionJournal::queryFields());
|
||||||
|
|
||||||
return $set;
|
return $set;
|
||||||
}
|
}
|
||||||
@ -290,13 +288,15 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
$offset = ($page - 1) * $pageSize;
|
$offset = ($page - 1) * $pageSize;
|
||||||
$query = $this->user
|
$query = $this->user
|
||||||
->transactionJournals()
|
->transactionJournals()
|
||||||
->expanded()
|
->expanded();
|
||||||
->where(
|
|
||||||
function (Builder $q) use ($account) {
|
// expand query:
|
||||||
$q->where('source_account.id', $account->id);
|
$query->leftJoin(
|
||||||
$q->orWhere('destination_account.id', $account->id);
|
'transactions as source', function (JoinClause $join) {
|
||||||
|
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id');
|
||||||
}
|
}
|
||||||
);
|
)->where('source.account_id', $account->id);
|
||||||
|
|
||||||
|
|
||||||
$count = $query->count();
|
$count = $query->count();
|
||||||
$set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::queryFields());
|
$set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::queryFields());
|
||||||
|
@ -568,32 +568,9 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
public function getValidRepetitions(Budget $budget, Carbon $start, Carbon $end, LimitRepetition $ignore) : Collection
|
public function getValidRepetitions(Budget $budget, Carbon $start, Carbon $end, LimitRepetition $ignore) : Collection
|
||||||
{
|
{
|
||||||
$query = $budget->limitrepetitions()
|
$query = $budget->limitrepetitions()
|
||||||
->where( // valid when either of these are true:
|
|
||||||
function ($q) use ($start, $end) {
|
|
||||||
$q->where(
|
|
||||||
function ($query) use ($start, $end) {
|
|
||||||
// starts before start time, and the end also after start time.
|
// starts before start time, and the end also after start time.
|
||||||
$query->where('limit_repetitions.startdate', '<=', $start->format('Y-m-d 00:00:00'));
|
->where('limit_repetitions.enddate', '>=', $start->format('Y-m-d 00:00:00'))
|
||||||
$query->where('limit_repetitions.enddate', '>=', $start->format('Y-m-d 00:00:00'));
|
->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00'));
|
||||||
}
|
|
||||||
);
|
|
||||||
$q->orWhere(
|
|
||||||
function ($query) use ($start, $end) {
|
|
||||||
// end after end time, and start is before end time
|
|
||||||
$query->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00'));
|
|
||||||
$query->where('limit_repetitions.enddate', '>=', $end->format('Y-m-d 00:00:00'));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
// start is after start and end is before end
|
|
||||||
$q->orWhere(
|
|
||||||
function ($query) use ($start, $end) {
|
|
||||||
// end after end time, and start is before end time
|
|
||||||
$query->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00'));
|
|
||||||
$query->where('limit_repetitions.enddate', '<=', $end->format('Y-m-d 00:00:00'));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (!is_null($ignore->id)) {
|
if (!is_null($ignore->id)) {
|
||||||
$query->where('limit_repetitions.id', '!=', $ignore->id);
|
$query->where('limit_repetitions.id', '!=', $ignore->id);
|
||||||
}
|
}
|
||||||
@ -683,7 +660,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
->whereIn('transactions.account_id', $ids)
|
->whereIn('transactions.account_id', $ids)
|
||||||
->having('transaction_count', '=', 1)
|
//->having('transaction_count', '=', 1) TODO check if this still works
|
||||||
->transactionTypes([TransactionType::WITHDRAWAL])
|
->transactionTypes([TransactionType::WITHDRAWAL])
|
||||||
->first(
|
->first(
|
||||||
[
|
[
|
||||||
|
@ -10,6 +10,7 @@ use FireflyIII\Models\TransactionJournal;
|
|||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Shared\ComponentRepository;
|
use FireflyIII\Repositories\Shared\ComponentRepository;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,9 +91,16 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
|||||||
->after($start)
|
->after($start)
|
||||||
->groupBy('transaction_journals.date');
|
->groupBy('transaction_journals.date');
|
||||||
|
|
||||||
|
$query->leftJoin(
|
||||||
|
'transactions as destination', function (JoinClause $join) {
|
||||||
|
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('destination.amount', '>', 0);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
if ($accounts->count() > 0) {
|
if ($accounts->count() > 0) {
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
$ids = $accounts->pluck('id')->toArray();
|
||||||
$query->whereIn('destination_account.id', $ids);
|
$query->whereIn('destination.account.id', $ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $query->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`destination`.`amount`) AS `sum`')]);
|
$result = $query->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`destination`.`amount`) AS `sum`')]);
|
||||||
@ -258,13 +266,17 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
|||||||
->before($end)
|
->before($end)
|
||||||
->after($start)
|
->after($start)
|
||||||
->groupBy('transaction_journals.date');
|
->groupBy('transaction_journals.date');
|
||||||
|
$query->leftJoin(
|
||||||
|
'transactions as source', function (JoinClause $join) {
|
||||||
|
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')->where('source.amount', '<', 0);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if ($accounts->count() > 0) {
|
if ($accounts->count() > 0) {
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
$ids = $accounts->pluck('id')->toArray();
|
||||||
$query->whereIn('source_account.id', $ids);
|
$query->whereIn('source.account_id', $ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$result = $query->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`source`.`amount`) AS `sum`')]);
|
$result = $query->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`source`.`amount`) AS `sum`')]);
|
||||||
|
|
||||||
$return = [];
|
$return = [];
|
||||||
|
@ -336,31 +336,36 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
{
|
{
|
||||||
$sourceAccount = null;
|
$sourceAccount = null;
|
||||||
$destinationAccount = null;
|
$destinationAccount = null;
|
||||||
|
Log::debug('Now in storeAccounts()');
|
||||||
switch ($type->type) {
|
switch ($type->type) {
|
||||||
case TransactionType::WITHDRAWAL:
|
case TransactionType::WITHDRAWAL:
|
||||||
|
Log::debug('Now in storeAccounts()::withdrawal');
|
||||||
list($sourceAccount, $destinationAccount) = $this->storeWithdrawalAccounts($data);
|
list($sourceAccount, $destinationAccount) = $this->storeWithdrawalAccounts($data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TransactionType::DEPOSIT:
|
case TransactionType::DEPOSIT:
|
||||||
|
Log::debug('Now in storeAccounts()::deposit');
|
||||||
list($sourceAccount, $destinationAccount) = $this->storeDepositAccounts($data);
|
list($sourceAccount, $destinationAccount) = $this->storeDepositAccounts($data);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case TransactionType::TRANSFER:
|
case TransactionType::TRANSFER:
|
||||||
|
Log::debug('Now in storeAccounts()::transfer');
|
||||||
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first();
|
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first();
|
||||||
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first();
|
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new FireflyException('Did not recognise transaction type.');
|
throw new FireflyException('Did not recognise transaction type.');
|
||||||
}
|
}
|
||||||
|
Log::debug('Now in storeAccounts(), continued.');
|
||||||
|
|
||||||
if (is_null($destinationAccount)) {
|
if (is_null($destinationAccount)) {
|
||||||
Log::error('"to"-account is null, so we cannot continue!', ['data' => $data]);
|
Log::error('"destination"-account is null, so we cannot continue!', ['data' => $data]);
|
||||||
throw new FireflyException('"to"-account is null, so we cannot continue!');
|
throw new FireflyException('"destination"-account is null, so we cannot continue!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($sourceAccount)) {
|
if (is_null($sourceAccount)) {
|
||||||
Log::error('"from"-account is null, so we cannot continue!', ['data' => $data]);
|
Log::error('"source"-account is null, so we cannot continue!', ['data' => $data]);
|
||||||
throw new FireflyException('"from"-account is null, so we cannot continue!');
|
throw new FireflyException('"source"-account is null, so we cannot continue!');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -402,8 +407,10 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
private function storeWithdrawalAccounts(array $data): array
|
private function storeWithdrawalAccounts(array $data): array
|
||||||
{
|
{
|
||||||
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first(['accounts.*']);
|
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first(['accounts.*']);
|
||||||
|
Log::debug('Now in storeWithdrawalAccounts() with ', ['name' => $data['destination_account_name'], 'len' => strlen($data['destination_account_name'])]);
|
||||||
|
|
||||||
if (strlen($data['destination_account_name']) > 0) {
|
if (strlen($data['destination_account_name']) > 0) {
|
||||||
|
Log::debug('Now in storeWithdrawalAccounts()');
|
||||||
$destinationType = AccountType::where('type', 'Expense account')->first();
|
$destinationType = AccountType::where('type', 'Expense account')->first();
|
||||||
$destinationAccount = Account::firstOrCreateEncrypted(
|
$destinationAccount = Account::firstOrCreateEncrypted(
|
||||||
[
|
[
|
||||||
@ -413,6 +420,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
'active' => 1,
|
'active' => 1,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
Log::debug('Errors: ', ['err' => $destinationAccount->getErrors()->toArray(), 'id' => $destinationAccount->id]);
|
||||||
|
|
||||||
return [$sourceAccount, $destinationAccount];
|
return [$sourceAccount, $destinationAccount];
|
||||||
}
|
}
|
||||||
|
@ -367,7 +367,7 @@ class TestData
|
|||||||
public static function createExpenseAccounts(User $user): bool
|
public static function createExpenseAccounts(User $user): bool
|
||||||
{
|
{
|
||||||
$expenses = ['Adobe', 'Google', 'Vitens', 'Albert Heijn', 'PLUS', 'Apple', 'Bakker', 'Belastingdienst', 'bol.com', 'Cafe Central', 'conrad.nl',
|
$expenses = ['Adobe', 'Google', 'Vitens', 'Albert Heijn', 'PLUS', 'Apple', 'Bakker', 'Belastingdienst', 'bol.com', 'Cafe Central', 'conrad.nl',
|
||||||
'Coolblue', 'Shell',
|
'Coolblue', 'Shell', 'SixtyFive', 'EightyFour', 'Fiftyone',
|
||||||
'DUO', 'Etos', 'FEBO', 'Greenchoice', 'Halfords', 'XS4All', 'iCentre', 'Jumper', 'Land lord'];
|
'DUO', 'Etos', 'FEBO', 'Greenchoice', 'Halfords', 'XS4All', 'iCentre', 'Jumper', 'Land lord'];
|
||||||
foreach ($expenses as $name) {
|
foreach ($expenses as $name) {
|
||||||
// create account:
|
// create account:
|
||||||
|
@ -56,8 +56,21 @@ class TransactionJournalSupport extends Model
|
|||||||
return $journal->destination_amount;
|
return $journal->destination_amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// saves on queries:
|
||||||
|
$amount = '0';
|
||||||
|
if (count($journal->transactions) === 0) {
|
||||||
|
$amount = '0';
|
||||||
|
foreach ($journal->transactions as $t) {
|
||||||
|
if ($t->amount > 0) {
|
||||||
|
$amount = bcadd($amount, $t->amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($amount === '0') {
|
||||||
$amount = $journal->transactions()->where('amount', '>', 0)->get()->sum('amount');
|
$amount = $journal->transactions()->where('amount', '>', 0)->get()->sum('amount');
|
||||||
if ($journal->isDeposit()) {
|
}
|
||||||
|
|
||||||
|
if ($journal->isWithdrawal()) {
|
||||||
$amount = $amount * -1;
|
$amount = $amount * -1;
|
||||||
}
|
}
|
||||||
$amount = strval($amount);
|
$amount = strval($amount);
|
||||||
@ -234,19 +247,8 @@ class TransactionJournalSupport extends Model
|
|||||||
'transaction_journals.*',
|
'transaction_journals.*',
|
||||||
'transaction_types.type AS transaction_type_type', // the other field is called "transaction_type_id" so this is pretty consistent.
|
'transaction_types.type AS transaction_type_type', // the other field is called "transaction_type_id" so this is pretty consistent.
|
||||||
'transaction_currencies.code AS transaction_currency_code',
|
'transaction_currencies.code AS transaction_currency_code',
|
||||||
// all for destination:
|
DB::raw('SUM(`transactions`.`amount`) as `amount`'),
|
||||||
//'destination.amount AS destination_amount', // is always positive
|
DB::raw('(COUNT(`transactions`.`id`) * 2) as `count_transactions`'),
|
||||||
DB::raw('SUM(`destination`.`amount`) as `destination_amount`'),
|
|
||||||
'destination_account.id AS destination_account_id',
|
|
||||||
'destination_account.name AS destination_account_name',
|
|
||||||
'destination_acct_type.type AS destination_account_type',
|
|
||||||
// all for source:
|
|
||||||
//'source.amount AS source_amount', // is always negative
|
|
||||||
DB::raw('SUM(`source`.`amount`) as `source_amount`'),
|
|
||||||
'source_account.id AS source_account_id',
|
|
||||||
'source_account.name AS source_account_name',
|
|
||||||
'source_acct_type.type AS source_account_type',
|
|
||||||
DB::raw('COUNT(`destination`.`id`) + COUNT(`source`.`id`) as `count_transactions`'),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,9 @@ class FireflyValidator extends Validator
|
|||||||
{
|
{
|
||||||
$field = $parameters[1] ?? 'id';
|
$field = $parameters[1] ?? 'id';
|
||||||
|
|
||||||
|
if (intval($value) === 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
$count = DB::table($parameters[0])->where('user_id', Auth::user()->id)->where($field, $value)->count();
|
$count = DB::table($parameters[0])->where('user_id', Auth::user()->id)->where($field, $value)->count();
|
||||||
if ($count === 1) {
|
if ($count === 1) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -154,6 +154,7 @@ return [
|
|||||||
/*
|
/*
|
||||||
* More service providers.
|
* More service providers.
|
||||||
*/
|
*/
|
||||||
|
FireflyIII\Providers\CrudServiceProvider::class,
|
||||||
FireflyIII\Providers\AccountServiceProvider::class,
|
FireflyIII\Providers\AccountServiceProvider::class,
|
||||||
FireflyIII\Providers\AttachmentServiceProvider::class,
|
FireflyIII\Providers\AttachmentServiceProvider::class,
|
||||||
FireflyIII\Providers\BillServiceProvider::class,
|
FireflyIII\Providers\BillServiceProvider::class,
|
||||||
|
@ -90,7 +90,7 @@ class SplitDataSeeder extends Seeder
|
|||||||
* Create splitted expense of 66,-
|
* Create splitted expense of 66,-
|
||||||
*/
|
*/
|
||||||
$today = new Carbon;
|
$today = new Carbon;
|
||||||
$today->subDays(6);
|
$today->subDays(2);
|
||||||
|
|
||||||
if (!$skipWithdrawal) {
|
if (!$skipWithdrawal) {
|
||||||
$journal = TransactionJournal::create(
|
$journal = TransactionJournal::create(
|
||||||
@ -98,7 +98,7 @@ class SplitDataSeeder extends Seeder
|
|||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'transaction_type_id' => 1, // withdrawal
|
'transaction_type_id' => 1, // withdrawal
|
||||||
'transaction_currency_id' => 1,
|
'transaction_currency_id' => 1,
|
||||||
'description' => 'Split Expense (journal)',
|
'description' => 'Split Even Expense (journal (50/50))',
|
||||||
'completed' => 1,
|
'completed' => 1,
|
||||||
'date' => $today->format('Y-m-d'),
|
'date' => $today->format('Y-m-d'),
|
||||||
]
|
]
|
||||||
@ -107,10 +107,11 @@ class SplitDataSeeder extends Seeder
|
|||||||
// split in 6 transactions (multiple destinations). 22,- each
|
// split in 6 transactions (multiple destinations). 22,- each
|
||||||
// source is TestData Checking Account.
|
// source is TestData Checking Account.
|
||||||
// also attach some budgets and stuff.
|
// also attach some budgets and stuff.
|
||||||
$destinations = ['Albert Heijn', 'PLUS', 'Apple'];
|
$destinations = ['SixtyFive', 'EightyFour'];
|
||||||
$budgets = ['Groceries', 'Groceries', 'Car'];
|
$budgets = ['Groceries', 'Car'];
|
||||||
$categories = ['Bills', 'Bills', 'Car'];
|
$categories = ['Bills', 'Bills'];
|
||||||
$source = TestData::findAccount($user, 'Checking Account');
|
$amounts = [50, 50];
|
||||||
|
$source = TestData::findAccount($user, 'Alternate Checking Account');
|
||||||
foreach ($destinations as $index => $dest) {
|
foreach ($destinations as $index => $dest) {
|
||||||
$bud = $budgets[$index];
|
$bud = $budgets[$index];
|
||||||
$cat = $categories[$index];
|
$cat = $categories[$index];
|
||||||
@ -120,7 +121,7 @@ class SplitDataSeeder extends Seeder
|
|||||||
[
|
[
|
||||||
'account_id' => $source->id,
|
'account_id' => $source->id,
|
||||||
'transaction_journal_id' => $journal->id,
|
'transaction_journal_id' => $journal->id,
|
||||||
'amount' => '-22',
|
'amount' => $amounts[$index] * -1,
|
||||||
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -129,7 +130,7 @@ class SplitDataSeeder extends Seeder
|
|||||||
[
|
[
|
||||||
'account_id' => $destination->id,
|
'account_id' => $destination->id,
|
||||||
'transaction_journal_id' => $journal->id,
|
'transaction_journal_id' => $journal->id,
|
||||||
'amount' => '22',
|
'amount' => $amounts[$index],
|
||||||
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -141,6 +142,57 @@ class SplitDataSeeder extends Seeder
|
|||||||
$two->categories()->save(TestData::findCategory($user, $cat));
|
$two->categories()->save(TestData::findCategory($user, $cat));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// AND ANOTHER ONE
|
||||||
|
$today->addDay();
|
||||||
|
$journal = TransactionJournal::create(
|
||||||
|
[
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'transaction_type_id' => 1, // withdrawal
|
||||||
|
'transaction_currency_id' => 1,
|
||||||
|
'description' => 'Split Uneven Expense (journal (15/34/51=100))',
|
||||||
|
'completed' => 1,
|
||||||
|
'date' => $today->format('Y-m-d'),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// split in 6 transactions (multiple destinations). 22,- each
|
||||||
|
// source is TestData Checking Account.
|
||||||
|
// also attach some budgets and stuff.
|
||||||
|
$destinations = ['SixtyFive', 'EightyFour', 'Fiftyone'];
|
||||||
|
$budgets = ['Groceries', 'Groceries', 'Car'];
|
||||||
|
$categories = ['Bills', 'Bills', 'Car'];
|
||||||
|
$amounts = [15, 34, 51];
|
||||||
|
$source = TestData::findAccount($user, 'Checking Account');
|
||||||
|
foreach ($destinations as $index => $dest) {
|
||||||
|
$bud = $budgets[$index];
|
||||||
|
$cat = $categories[$index];
|
||||||
|
$destination = TestData::findAccount($user, $dest);
|
||||||
|
|
||||||
|
$one = Transaction::create(
|
||||||
|
[
|
||||||
|
'account_id' => $source->id,
|
||||||
|
'transaction_journal_id' => $journal->id,
|
||||||
|
'amount' => $amounts[$index] * -1,
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$two = Transaction::create(
|
||||||
|
[
|
||||||
|
'account_id' => $destination->id,
|
||||||
|
'transaction_journal_id' => $journal->id,
|
||||||
|
'amount' => $amounts[$index],
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$one->budgets()->save(TestData::findBudget($user, $bud));
|
||||||
|
$two->budgets()->save(TestData::findBudget($user, $bud));
|
||||||
|
|
||||||
|
$one->categories()->save(TestData::findCategory($user, $cat));
|
||||||
|
$two->categories()->save(TestData::findCategory($user, $cat));
|
||||||
|
}
|
||||||
|
|
||||||
// create splitted income of 99,-
|
// create splitted income of 99,-
|
||||||
$today->addDay();
|
$today->addDay();
|
||||||
|
|
||||||
|
31
phpunit.xml
Normal file
31
phpunit.xml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit backupGlobals="false"
|
||||||
|
backupStaticAttributes="false"
|
||||||
|
bootstrap="bootstrap/autoload.php"
|
||||||
|
colors="true"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
processIsolation="false"
|
||||||
|
stopOnFailure="true">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Application Test Suite">
|
||||||
|
<directory>./tests/</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<filter>
|
||||||
|
<whitelist>
|
||||||
|
<directory suffix=".php">app/</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
<php>
|
||||||
|
<env name="APP_ENV" value="testing"/>
|
||||||
|
<env name="CACHE_DRIVER" value="array"/>
|
||||||
|
<env name="SESSION_DRIVER" value="array"/>
|
||||||
|
<env name="QUEUE_DRIVER" value="sync"/>
|
||||||
|
</php>
|
||||||
|
|
||||||
|
<listeners>
|
||||||
|
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
|
||||||
|
</listeners>
|
||||||
|
</phpunit>
|
@ -73,18 +73,18 @@
|
|||||||
<input type="hidden" name="journal_amount" value="{{ data.journal_amount }}"/>
|
<input type="hidden" name="journal_amount" value="{{ data.journal_amount }}"/>
|
||||||
<!-- show static source if withdrawal or transfer -->
|
<!-- show static source if withdrawal or transfer -->
|
||||||
{% if data.what == 'withdrawal' or data.what == 'transfer' %}
|
{% if data.what == 'withdrawal' or data.what == 'transfer' %}
|
||||||
{{ ExpandedForm.staticText('asset_source_account', assetAccounts[data.journal_source_account_id]) }}
|
{{ ExpandedForm.staticText('journal_asset_source_account', assetAccounts[data.journal_source_account_id]) }}
|
||||||
<input type="hidden" name="source_account_id" value="{{ data.journal_source_account_id }}"/>
|
<input type="hidden" name="journal_source_account_id" value="{{ data.journal_source_account_id }}"/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<!-- show static source if deposit: -->
|
<!-- show static source if deposit: -->
|
||||||
{% if data.what == 'deposit' %}
|
{% if data.what == 'deposit' %}
|
||||||
{{ ExpandedForm.staticText('revenue_account', data.journal_source_account_name) }}
|
{{ ExpandedForm.staticText('revenue_account', data.journal_source_account_name) }}
|
||||||
<input type="hidden" name="source_account_name" value="{{ data.journal_source_account_name }}"/>
|
<input type="hidden" name="journal_source_account_name" value="{{ data.journal_source_account_name }}"/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<!-- show static destination if transfer -->
|
<!-- show static destination if transfer -->
|
||||||
{% if data.what == 'transfer' %}
|
{% if data.what == 'transfer' %}
|
||||||
{{ ExpandedForm.staticText('asset_destination_account', assetAccounts[data.journal_destination_account_id]) }}
|
{{ ExpandedForm.staticText('asset_destination_account', assetAccounts[data.journal_destination_account_id]) }}
|
||||||
<input type="hidden" name="destination_account_id" value="{{ data.journal_destination_account_id }}"/>
|
<input type="hidden" name="journal_destination_account_id" value="{{ data.journal_destination_account_id }}"/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -155,11 +155,9 @@ class JsonControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTransactionJournals($range)
|
public function testTransactionJournals($range)
|
||||||
{
|
{
|
||||||
$type = factory(FireflyIII\Models\TransactionType::class)->make();
|
|
||||||
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
|
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
|
||||||
|
$paginator = new \Illuminate\Pagination\LengthAwarePaginator(new Collection, 0, 40);
|
||||||
$repository->shouldReceive('getTransactionType')->with('deposit')->once()->andReturn($type);
|
$repository->shouldReceive('getJournals')->withAnyArgs()->once()->andReturn($paginator);
|
||||||
$repository->shouldReceive('getJournalsOfType')->with($type)->once()->andReturn(new Collection);
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
|
@ -68,7 +68,7 @@ class TransactionControllerTest extends TestCase
|
|||||||
public function testIndex($range)
|
public function testIndex($range)
|
||||||
{
|
{
|
||||||
$journals = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
|
$journals = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
|
||||||
$journals->shouldReceive('getJournalsOfTypes')->once()->andReturn(new LengthAwarePaginator([], 0, 50));
|
$journals->shouldReceive('getJournals')->once()->andReturn(new LengthAwarePaginator([], 0, 50));
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
@ -117,8 +117,8 @@ class TransactionControllerTest extends TestCase
|
|||||||
$args = [
|
$args = [
|
||||||
'what' => 'withdrawal',
|
'what' => 'withdrawal',
|
||||||
'description' => 'Something',
|
'description' => 'Something',
|
||||||
'account_id' => '1',
|
'source_account_id' => '1',
|
||||||
'expense_account' => 'Some expense',
|
'destination_account_name' => 'Some expense',
|
||||||
'amount' => 100,
|
'amount' => 100,
|
||||||
'amount_currency_id_amount' => 1,
|
'amount_currency_id_amount' => 1,
|
||||||
'date' => '2015-01-01',
|
'date' => '2015-01-01',
|
||||||
@ -141,10 +141,10 @@ class TransactionControllerTest extends TestCase
|
|||||||
|
|
||||||
$args = [
|
$args = [
|
||||||
'what' => 'withdrawal',
|
'what' => 'withdrawal',
|
||||||
'id' => 2,
|
'id' => 4,
|
||||||
'description' => 'Something new',
|
'description' => 'Something new',
|
||||||
'account_id' => '1',
|
'source_account_id' => '1',
|
||||||
'expense_account' => 'Some expense',
|
'destination_account_name' => 'Some expense account',
|
||||||
'amount' => 100,
|
'amount' => 100,
|
||||||
'amount_currency_id_amount' => 1,
|
'amount_currency_id_amount' => 1,
|
||||||
'date' => '2015-01-01',
|
'date' => '2015-01-01',
|
||||||
|
Loading…
Reference in New Issue
Block a user