mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 02:26:58 +00:00
Fix audit log entries and fix #7677
This commit is contained in:
@@ -24,16 +24,21 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Handlers\Events;
|
namespace FireflyIII\Handlers\Events;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Events\TriggeredAuditLog;
|
use FireflyIII\Events\TriggeredAuditLog;
|
||||||
use FireflyIII\Repositories\AuditLogEntry\ALERepositoryInterface;
|
use FireflyIII\Repositories\AuditLogEntry\ALERepositoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AuditEventHandler
|
||||||
|
*/
|
||||||
class AuditEventHandler
|
class AuditEventHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param TriggeredAuditLog $event
|
* @param TriggeredAuditLog $event
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function storeAuditEvent(TriggeredAuditLog $event)
|
public function storeAuditEvent(TriggeredAuditLog $event): void
|
||||||
{
|
{
|
||||||
$array = [
|
$array = [
|
||||||
'auditable' => $event->auditable,
|
'auditable' => $event->auditable,
|
||||||
@@ -42,6 +47,24 @@ class AuditEventHandler
|
|||||||
'before' => $event->before,
|
'before' => $event->before,
|
||||||
'after' => $event->after,
|
'after' => $event->after,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($event->before === $event->after) {
|
||||||
|
app('log')->debug('Will not store event log because before and after are the same.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($event->before instanceof Carbon && $event->after instanceof Carbon && $event->before->eq($event->after)) {
|
||||||
|
app('log')->debug('Will not store event log because before and after Carbon values are the same.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($event->before instanceof Carbon && $event->after instanceof Carbon) {
|
||||||
|
$array['before'] = $event->before->toIso8601String();
|
||||||
|
$array['after'] = $event->after->toIso8601String();
|
||||||
|
app('log')->debug(sprintf('Converted "before" to "%s".', $event->before));
|
||||||
|
app('log')->debug(sprintf('Converted "after" to "%s".', $event->after));
|
||||||
|
}
|
||||||
|
|
||||||
/** @var ALERepositoryInterface $repository */
|
/** @var ALERepositoryInterface $repository */
|
||||||
$repository = app(ALERepositoryInterface::class);
|
$repository = app(ALERepositoryInterface::class);
|
||||||
$repository->store($array);
|
$repository->store($array);
|
||||||
|
@@ -66,7 +66,7 @@ class ShowController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionGroup $transactionGroup
|
* @param TransactionGroup $transactionGroup
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
@@ -76,8 +76,8 @@ class ShowController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param TransactionGroup $transactionGroup
|
* @param TransactionGroup $transactionGroup
|
||||||
*
|
*
|
||||||
* @return Factory|View
|
* @return Factory|View
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
@@ -106,11 +106,14 @@ class ShowController extends Controller
|
|||||||
$accounts = $this->getAccounts($groupArray);
|
$accounts = $this->getAccounts($groupArray);
|
||||||
|
|
||||||
foreach ($groupArray['transactions'] as $index => $transaction) {
|
foreach ($groupArray['transactions'] as $index => $transaction) {
|
||||||
$groupArray['transactions'][$index]['tags'] = $this->repository->getTagObjects($groupArray['transactions'][$index]['transaction_journal_id']);
|
$groupArray['transactions'][$index]['tags'] = $this->repository->getTagObjects(
|
||||||
|
$groupArray['transactions'][$index]['transaction_journal_id']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get audit log entries:
|
// get audit log entries:
|
||||||
$logEntries = [];
|
$groupLogEntries = $this->aleRepository->getForObject($transactionGroup);
|
||||||
|
$logEntries = [];
|
||||||
foreach ($transactionGroup->transactionJournals as $journal) {
|
foreach ($transactionGroup->transactionJournals as $journal) {
|
||||||
$logEntries[$journal->id] = $this->aleRepository->getForObject($journal);
|
$logEntries[$journal->id] = $this->aleRepository->getForObject($journal);
|
||||||
}
|
}
|
||||||
@@ -128,6 +131,7 @@ class ShowController extends Controller
|
|||||||
'first',
|
'first',
|
||||||
'type',
|
'type',
|
||||||
'logEntries',
|
'logEntries',
|
||||||
|
'groupLogEntries',
|
||||||
'subTitle',
|
'subTitle',
|
||||||
'splits',
|
'splits',
|
||||||
'groupArray',
|
'groupArray',
|
||||||
@@ -140,7 +144,49 @@ class ShowController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $group
|
* @param array $group
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getAmounts(array $group): array
|
||||||
|
{
|
||||||
|
$amounts = [];
|
||||||
|
foreach ($group['transactions'] as $transaction) {
|
||||||
|
$symbol = $transaction['currency_symbol'];
|
||||||
|
if (!array_key_exists($symbol, $amounts)) {
|
||||||
|
$amounts[$symbol] = [
|
||||||
|
'amount' => '0',
|
||||||
|
'symbol' => $symbol,
|
||||||
|
'decimal_places' => $transaction['currency_decimal_places'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$amounts[$symbol]['amount'] = bcadd($amounts[$symbol]['amount'], $transaction['amount']);
|
||||||
|
if (null !== $transaction['foreign_amount'] && '' !== $transaction['foreign_amount']
|
||||||
|
&& bccomp(
|
||||||
|
'0',
|
||||||
|
$transaction['foreign_amount']
|
||||||
|
) !== 0) {
|
||||||
|
// same for foreign currency:
|
||||||
|
$foreignSymbol = $transaction['foreign_currency_symbol'];
|
||||||
|
if (!array_key_exists($foreignSymbol, $amounts)) {
|
||||||
|
$amounts[$foreignSymbol] = [
|
||||||
|
'amount' => '0',
|
||||||
|
'symbol' => $foreignSymbol,
|
||||||
|
'decimal_places' => $transaction['foreign_currency_decimal_places'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$amounts[$foreignSymbol]['amount'] = bcadd(
|
||||||
|
$amounts[$foreignSymbol]['amount'],
|
||||||
|
$transaction['foreign_amount']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $amounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $group
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@@ -168,39 +214,4 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
return $accounts;
|
return $accounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $group
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getAmounts(array $group): array
|
|
||||||
{
|
|
||||||
$amounts = [];
|
|
||||||
foreach ($group['transactions'] as $transaction) {
|
|
||||||
$symbol = $transaction['currency_symbol'];
|
|
||||||
if (!array_key_exists($symbol, $amounts)) {
|
|
||||||
$amounts[$symbol] = [
|
|
||||||
'amount' => '0',
|
|
||||||
'symbol' => $symbol,
|
|
||||||
'decimal_places' => $transaction['currency_decimal_places'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
$amounts[$symbol]['amount'] = bcadd($amounts[$symbol]['amount'], $transaction['amount']);
|
|
||||||
if (null !== $transaction['foreign_amount'] && '' !== $transaction['foreign_amount'] && bccomp('0', $transaction['foreign_amount']) !== 0) {
|
|
||||||
// same for foreign currency:
|
|
||||||
$foreignSymbol = $transaction['foreign_currency_symbol'];
|
|
||||||
if (!array_key_exists($foreignSymbol, $amounts)) {
|
|
||||||
$amounts[$foreignSymbol] = [
|
|
||||||
'amount' => '0',
|
|
||||||
'symbol' => $foreignSymbol,
|
|
||||||
'decimal_places' => $transaction['foreign_currency_decimal_places'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
$amounts[$foreignSymbol]['amount'] = bcadd($amounts[$foreignSymbol]['amount'], $transaction['foreign_amount']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $amounts;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Services\Internal\Update;
|
namespace FireflyIII\Services\Internal\Update;
|
||||||
|
|
||||||
|
use FireflyIII\Events\TriggeredAuditLog;
|
||||||
use FireflyIII\Exceptions\DuplicateTransactionException;
|
use FireflyIII\Exceptions\DuplicateTransactionException;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Factory\TransactionJournalFactory;
|
use FireflyIII\Factory\TransactionJournalFactory;
|
||||||
@@ -40,8 +41,8 @@ class GroupUpdateService
|
|||||||
/**
|
/**
|
||||||
* Update a transaction group.
|
* Update a transaction group.
|
||||||
*
|
*
|
||||||
* @param TransactionGroup $transactionGroup
|
* @param TransactionGroup $transactionGroup
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return TransactionGroup
|
* @return TransactionGroup
|
||||||
* @throws DuplicateTransactionException
|
* @throws DuplicateTransactionException
|
||||||
@@ -56,8 +57,18 @@ class GroupUpdateService
|
|||||||
// update group name.
|
// update group name.
|
||||||
if (array_key_exists('group_title', $data)) {
|
if (array_key_exists('group_title', $data)) {
|
||||||
Log::debug(sprintf('Update transaction group #%d title.', $transactionGroup->id));
|
Log::debug(sprintf('Update transaction group #%d title.', $transactionGroup->id));
|
||||||
|
$oldTitle = $transactionGroup->title;
|
||||||
$transactionGroup->title = $data['group_title'];
|
$transactionGroup->title = $data['group_title'];
|
||||||
$transactionGroup->save();
|
$transactionGroup->save();
|
||||||
|
event(
|
||||||
|
new TriggeredAuditLog(
|
||||||
|
$transactionGroup->user,
|
||||||
|
$transactionGroup,
|
||||||
|
'update_group_title',
|
||||||
|
$oldTitle,
|
||||||
|
$data['group_title']
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -70,7 +81,9 @@ class GroupUpdateService
|
|||||||
if (1 === count($transactions) && 1 === $transactionGroup->transactionJournals()->count()) {
|
if (1 === count($transactions) && 1 === $transactionGroup->transactionJournals()->count()) {
|
||||||
/** @var TransactionJournal $first */
|
/** @var TransactionJournal $first */
|
||||||
$first = $transactionGroup->transactionJournals()->first();
|
$first = $transactionGroup->transactionJournals()->first();
|
||||||
Log::debug(sprintf('Will now update journal #%d (only journal in group #%d)', $first->id, $transactionGroup->id));
|
Log::debug(
|
||||||
|
sprintf('Will now update journal #%d (only journal in group #%d)', $first->id, $transactionGroup->id)
|
||||||
|
);
|
||||||
$this->updateTransactionJournal($transactionGroup, $first, reset($transactions));
|
$this->updateTransactionJournal($transactionGroup, $first, reset($transactions));
|
||||||
$transactionGroup->refresh();
|
$transactionGroup->refresh();
|
||||||
app('preferences')->mark();
|
app('preferences')->mark();
|
||||||
@@ -88,6 +101,7 @@ class GroupUpdateService
|
|||||||
Log::error('There were no transactions updated or created. Will not delete anything.');
|
Log::error('There were no transactions updated or created. Will not delete anything.');
|
||||||
$transactionGroup->refresh();
|
$transactionGroup->refresh();
|
||||||
app('preferences')->mark();
|
app('preferences')->mark();
|
||||||
|
|
||||||
return $transactionGroup;
|
return $transactionGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,8 +125,8 @@ class GroupUpdateService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionGroup $transactionGroup
|
* @param TransactionGroup $transactionGroup
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return TransactionJournal|null
|
* @return TransactionJournal|null
|
||||||
*
|
*
|
||||||
@@ -135,7 +149,11 @@ class GroupUpdateService
|
|||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
Log::error($e->getTraceAsString());
|
Log::error($e->getTraceAsString());
|
||||||
throw new FireflyException(sprintf('Could not create new transaction journal: %s', $e->getMessage()), 0, $e);
|
throw new FireflyException(
|
||||||
|
sprintf('Could not create new transaction journal: %s', $e->getMessage()),
|
||||||
|
0,
|
||||||
|
$e
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$collection->each(
|
$collection->each(
|
||||||
function (TransactionJournal $journal) use ($transactionGroup) {
|
function (TransactionJournal $journal) use ($transactionGroup) {
|
||||||
@@ -152,12 +170,15 @@ class GroupUpdateService
|
|||||||
/**
|
/**
|
||||||
* Update single journal.
|
* Update single journal.
|
||||||
*
|
*
|
||||||
* @param TransactionGroup $transactionGroup
|
* @param TransactionGroup $transactionGroup
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*/
|
*/
|
||||||
private function updateTransactionJournal(TransactionGroup $transactionGroup, TransactionJournal $journal, array $data): void
|
private function updateTransactionJournal(
|
||||||
{
|
TransactionGroup $transactionGroup,
|
||||||
|
TransactionJournal $journal,
|
||||||
|
array $data
|
||||||
|
): void {
|
||||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||||
if (0 === count($data)) {
|
if (0 === count($data)) {
|
||||||
return;
|
return;
|
||||||
@@ -174,8 +195,8 @@ class GroupUpdateService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionGroup $transactionGroup
|
* @param TransactionGroup $transactionGroup
|
||||||
* @param array $transactions
|
* @param array $transactions
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @throws DuplicateTransactionException
|
* @throws DuplicateTransactionException
|
||||||
@@ -188,7 +209,7 @@ class GroupUpdateService
|
|||||||
// updated or created transaction journals:
|
// updated or created transaction journals:
|
||||||
$updated = [];
|
$updated = [];
|
||||||
/**
|
/**
|
||||||
* @var int $index
|
* @var int $index
|
||||||
* @var array $transaction
|
* @var array $transaction
|
||||||
*/
|
*/
|
||||||
foreach ($transactions as $index => $transaction) {
|
foreach ($transactions as $index => $transaction) {
|
||||||
@@ -203,7 +224,9 @@ class GroupUpdateService
|
|||||||
if (!array_key_exists('type', $transaction)) {
|
if (!array_key_exists('type', $transaction)) {
|
||||||
Log::debug('No transaction type is indicated.');
|
Log::debug('No transaction type is indicated.');
|
||||||
/** @var TransactionJournal|null $randomJournal */
|
/** @var TransactionJournal|null $randomJournal */
|
||||||
$randomJournal = $transactionGroup->transactionJournals()->inRandomOrder()->with(['transactionType'])->first();
|
$randomJournal = $transactionGroup->transactionJournals()->inRandomOrder()->with(
|
||||||
|
['transactionType']
|
||||||
|
)->first();
|
||||||
if (null !== $randomJournal) {
|
if (null !== $randomJournal) {
|
||||||
$transaction['type'] = $randomJournal->transactionType->type;
|
$transaction['type'] = $randomJournal->transactionType->type;
|
||||||
Log::debug(sprintf('Transaction type set to %s.', $transaction['type']));
|
Log::debug(sprintf('Transaction type set to %s.', $transaction['type']));
|
||||||
|
@@ -25,6 +25,7 @@ namespace FireflyIII\Services\Internal\Update;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Carbon\Exceptions\InvalidDateException;
|
use Carbon\Exceptions\InvalidDateException;
|
||||||
|
use FireflyIII\Events\TriggeredAuditLog;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Factory\TagFactory;
|
use FireflyIII\Factory\TagFactory;
|
||||||
use FireflyIII\Factory\TransactionJournalMetaFactory;
|
use FireflyIII\Factory\TransactionJournalMetaFactory;
|
||||||
@@ -97,11 +98,12 @@ class JournalUpdateService
|
|||||||
'external_id',
|
'external_id',
|
||||||
'external_url',
|
'external_url',
|
||||||
];
|
];
|
||||||
$this->metaDate = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date',];
|
$this->metaDate = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date',
|
||||||
|
'invoice_date',];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*/
|
*/
|
||||||
public function setData(array $data): void
|
public function setData(array $data): void
|
||||||
{
|
{
|
||||||
@@ -109,7 +111,7 @@ class JournalUpdateService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionGroup $transactionGroup
|
* @param TransactionGroup $transactionGroup
|
||||||
*/
|
*/
|
||||||
public function setTransactionGroup(TransactionGroup $transactionGroup): void
|
public function setTransactionGroup(TransactionGroup $transactionGroup): void
|
||||||
{
|
{
|
||||||
@@ -126,7 +128,7 @@ class JournalUpdateService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $transactionJournal
|
* @param TransactionJournal $transactionJournal
|
||||||
*/
|
*/
|
||||||
public function setTransactionJournal(TransactionJournal $transactionJournal): void
|
public function setTransactionJournal(TransactionJournal $transactionJournal): void
|
||||||
{
|
{
|
||||||
@@ -181,76 +183,49 @@ class JournalUpdateService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* Get destination transaction.
|
||||||
*/
|
|
||||||
private function removeReconciliation(): bool
|
|
||||||
{
|
|
||||||
if (count($this->data) > 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (1 === count($this->data) && true === array_key_exists('transaction_journal_id', $this->data)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function hasValidAccounts(): bool
|
|
||||||
{
|
|
||||||
return $this->hasValidSourceAccount() && $this->hasValidDestinationAccount();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function hasValidSourceAccount(): bool
|
|
||||||
{
|
|
||||||
Log::debug('Now in hasValidSourceAccount().');
|
|
||||||
$sourceId = $this->data['source_id'] ?? null;
|
|
||||||
$sourceName = $this->data['source_name'] ?? null;
|
|
||||||
|
|
||||||
if (!$this->hasFields(['source_id', 'source_name'])) {
|
|
||||||
$origSourceAccount = $this->getOriginalSourceAccount();
|
|
||||||
$sourceId = $origSourceAccount->id;
|
|
||||||
$sourceName = $origSourceAccount->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make new account validator.
|
|
||||||
$expectedType = $this->getExpectedType();
|
|
||||||
Log::debug(sprintf('Expected type (new or unchanged) is %s', $expectedType));
|
|
||||||
|
|
||||||
// make a new validator.
|
|
||||||
/** @var AccountValidator $validator */
|
|
||||||
$validator = app(AccountValidator::class);
|
|
||||||
$validator->setTransactionType($expectedType);
|
|
||||||
$validator->setUser($this->transactionJournal->user);
|
|
||||||
|
|
||||||
$result = $validator->validateSource(['id' => $sourceId]);
|
|
||||||
Log::debug(sprintf('hasValidSourceAccount(%d, "%s") will return %s', $sourceId, $sourceName, var_export($result, true)));
|
|
||||||
|
|
||||||
// TODO typeoverrule the account validator may have a different opinion on the transaction type.
|
|
||||||
|
|
||||||
// validate submitted info:
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $fields
|
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return Transaction
|
||||||
*/
|
*/
|
||||||
private function hasFields(array $fields): bool
|
private function getDestinationTransaction(): Transaction
|
||||||
{
|
{
|
||||||
foreach ($fields as $field) {
|
if (null === $this->destinationTransaction) {
|
||||||
if (array_key_exists($field, $this->data)) {
|
$this->destinationTransaction = $this->transactionJournal->transactions()->where('amount', '>', 0)->first();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return $this->destinationTransaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the current or expected type of the journal (in case of a change) based on the data in the
|
||||||
|
* array.
|
||||||
|
*
|
||||||
|
* If the array contains key 'type' and the value is correct, this is returned. Otherwise, the original type is
|
||||||
|
* returned.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getExpectedType(): string
|
||||||
|
{
|
||||||
|
Log::debug('Now in getExpectedType()');
|
||||||
|
if ($this->hasFields(['type'])) {
|
||||||
|
return ucfirst('opening-balance' === $this->data['type'] ? 'opening balance' : $this->data['type']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->transactionJournal->transactionType->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Account
|
||||||
|
*/
|
||||||
|
private function getOriginalDestinationAccount(): Account
|
||||||
|
{
|
||||||
|
if (null === $this->destinationAccount) {
|
||||||
|
$destination = $this->getDestinationTransaction();
|
||||||
|
$this->destinationAccount = $destination->account;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->destinationAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -272,7 +247,11 @@ class JournalUpdateService
|
|||||||
private function getSourceTransaction(): Transaction
|
private function getSourceTransaction(): Transaction
|
||||||
{
|
{
|
||||||
if (null === $this->sourceTransaction) {
|
if (null === $this->sourceTransaction) {
|
||||||
$this->sourceTransaction = $this->transactionJournal->transactions()->with(['account'])->where('amount', '<', 0)->first();
|
$this->sourceTransaction = $this->transactionJournal->transactions()->with(['account'])->where(
|
||||||
|
'amount',
|
||||||
|
'<',
|
||||||
|
0
|
||||||
|
)->first();
|
||||||
}
|
}
|
||||||
Log::debug(sprintf('getSourceTransaction: %s', $this->sourceTransaction->amount));
|
Log::debug(sprintf('getSourceTransaction: %s', $this->sourceTransaction->amount));
|
||||||
|
|
||||||
@@ -280,84 +259,39 @@ class JournalUpdateService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the current or expected type of the journal (in case of a change) based on the data in the array.
|
* Does a validation and returns the destination account. This method will break if the dest isn't really valid.
|
||||||
*
|
*
|
||||||
* If the array contains key 'type' and the value is correct, this is returned. Otherwise, the original type is returned.
|
* @return Account
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
private function getExpectedType(): string
|
private function getValidDestinationAccount(): Account
|
||||||
{
|
{
|
||||||
Log::debug('Now in getExpectedType()');
|
Log::debug('Now in getValidDestinationAccount().');
|
||||||
if ($this->hasFields(['type'])) {
|
|
||||||
return ucfirst('opening-balance' === $this->data['type'] ? 'opening balance' : $this->data['type']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->transactionJournal->transactionType->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function hasValidDestinationAccount(): bool
|
|
||||||
{
|
|
||||||
Log::debug('Now in hasValidDestinationAccount().');
|
|
||||||
$destId = $this->data['destination_id'] ?? null;
|
|
||||||
$destName = $this->data['destination_name'] ?? null;
|
|
||||||
|
|
||||||
if (!$this->hasFields(['destination_id', 'destination_name'])) {
|
if (!$this->hasFields(['destination_id', 'destination_name'])) {
|
||||||
Log::debug('No destination info submitted, grab the original data.');
|
return $this->getOriginalDestinationAccount();
|
||||||
$destination = $this->getOriginalDestinationAccount();
|
|
||||||
$destId = $destination->id;
|
|
||||||
$destName = $destination->name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$destInfo = [
|
||||||
|
'id' => (int)($this->data['destination_id'] ?? null),
|
||||||
|
'name' => $this->data['destination_name'] ?? null,
|
||||||
|
'iban' => $this->data['destination_iban'] ?? null,
|
||||||
|
'number' => $this->data['destination_number'] ?? null,
|
||||||
|
'bic' => $this->data['destination_bic'] ?? null,
|
||||||
|
];
|
||||||
|
|
||||||
// make new account validator.
|
// make new account validator.
|
||||||
$expectedType = $this->getExpectedType();
|
$expectedType = $this->getExpectedType();
|
||||||
Log::debug(sprintf('Expected type (new or unchanged) is %s', $expectedType));
|
Log::debug(sprintf('Expected type (new or unchanged) is %s', $expectedType));
|
||||||
|
try {
|
||||||
|
$result = $this->getAccount($expectedType, 'destination', $destInfo);
|
||||||
|
} catch (FireflyException $e) {
|
||||||
|
Log::error(sprintf('getValidDestinationAccount() threw unexpected error: %s', $e->getMessage()));
|
||||||
|
$result = $this->getOriginalDestinationAccount();
|
||||||
|
}
|
||||||
|
|
||||||
// make a new validator.
|
|
||||||
/** @var AccountValidator $validator */
|
|
||||||
$validator = app(AccountValidator::class);
|
|
||||||
$validator->setTransactionType($expectedType);
|
|
||||||
$validator->setUser($this->transactionJournal->user);
|
|
||||||
$validator->source = $this->getValidSourceAccount();
|
|
||||||
$result = $validator->validateDestination(['id' => $destId, 'name' => $destName]);
|
|
||||||
Log::debug(sprintf('hasValidDestinationAccount(%d, "%s") will return %s', $destId, $destName, var_export($result, true)));
|
|
||||||
|
|
||||||
// TODO typeOverrule: the account validator may have another opinion on the transaction type.
|
|
||||||
|
|
||||||
// validate submitted info:
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Account
|
|
||||||
*/
|
|
||||||
private function getOriginalDestinationAccount(): Account
|
|
||||||
{
|
|
||||||
if (null === $this->destinationAccount) {
|
|
||||||
$destination = $this->getDestinationTransaction();
|
|
||||||
$this->destinationAccount = $destination->account;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->destinationAccount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get destination transaction.
|
|
||||||
*
|
|
||||||
* @return Transaction
|
|
||||||
*/
|
|
||||||
private function getDestinationTransaction(): Transaction
|
|
||||||
{
|
|
||||||
if (null === $this->destinationTransaction) {
|
|
||||||
$this->destinationTransaction = $this->transactionJournal->transactions()->where('amount', '>', 0)->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->destinationTransaction;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does a validation and returns the source account. This method will break if the source isn't really valid.
|
* Does a validation and returns the source account. This method will break if the source isn't really valid.
|
||||||
*
|
*
|
||||||
@@ -393,6 +327,123 @@ class JournalUpdateService
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $fields
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function hasFields(array $fields): bool
|
||||||
|
{
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
if (array_key_exists($field, $this->data)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function hasValidAccounts(): bool
|
||||||
|
{
|
||||||
|
return $this->hasValidSourceAccount() && $this->hasValidDestinationAccount();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function hasValidDestinationAccount(): bool
|
||||||
|
{
|
||||||
|
Log::debug('Now in hasValidDestinationAccount().');
|
||||||
|
$destId = $this->data['destination_id'] ?? null;
|
||||||
|
$destName = $this->data['destination_name'] ?? null;
|
||||||
|
|
||||||
|
if (!$this->hasFields(['destination_id', 'destination_name'])) {
|
||||||
|
Log::debug('No destination info submitted, grab the original data.');
|
||||||
|
$destination = $this->getOriginalDestinationAccount();
|
||||||
|
$destId = $destination->id;
|
||||||
|
$destName = $destination->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// make new account validator.
|
||||||
|
$expectedType = $this->getExpectedType();
|
||||||
|
Log::debug(sprintf('Expected type (new or unchanged) is %s', $expectedType));
|
||||||
|
|
||||||
|
// make a new validator.
|
||||||
|
/** @var AccountValidator $validator */
|
||||||
|
$validator = app(AccountValidator::class);
|
||||||
|
$validator->setTransactionType($expectedType);
|
||||||
|
$validator->setUser($this->transactionJournal->user);
|
||||||
|
$validator->source = $this->getValidSourceAccount();
|
||||||
|
$result = $validator->validateDestination(['id' => $destId, 'name' => $destName]);
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'hasValidDestinationAccount(%d, "%s") will return %s',
|
||||||
|
$destId,
|
||||||
|
$destName,
|
||||||
|
var_export($result, true)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO typeOverrule: the account validator may have another opinion on the transaction type.
|
||||||
|
|
||||||
|
// validate submitted info:
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function hasValidSourceAccount(): bool
|
||||||
|
{
|
||||||
|
Log::debug('Now in hasValidSourceAccount().');
|
||||||
|
$sourceId = $this->data['source_id'] ?? null;
|
||||||
|
$sourceName = $this->data['source_name'] ?? null;
|
||||||
|
|
||||||
|
if (!$this->hasFields(['source_id', 'source_name'])) {
|
||||||
|
$origSourceAccount = $this->getOriginalSourceAccount();
|
||||||
|
$sourceId = $origSourceAccount->id;
|
||||||
|
$sourceName = $origSourceAccount->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// make new account validator.
|
||||||
|
$expectedType = $this->getExpectedType();
|
||||||
|
Log::debug(sprintf('Expected type (new or unchanged) is %s', $expectedType));
|
||||||
|
|
||||||
|
// make a new validator.
|
||||||
|
/** @var AccountValidator $validator */
|
||||||
|
$validator = app(AccountValidator::class);
|
||||||
|
$validator->setTransactionType($expectedType);
|
||||||
|
$validator->setUser($this->transactionJournal->user);
|
||||||
|
|
||||||
|
$result = $validator->validateSource(['id' => $sourceId]);
|
||||||
|
Log::debug(
|
||||||
|
sprintf('hasValidSourceAccount(%d, "%s") will return %s', $sourceId, $sourceName, var_export($result, true))
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO typeoverrule the account validator may have a different opinion on the transaction type.
|
||||||
|
|
||||||
|
// validate submitted info:
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function removeReconciliation(): bool
|
||||||
|
{
|
||||||
|
if (count($this->data) > 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (1 === count($this->data) && true === array_key_exists('transaction_journal_id', $this->data)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will update the source and destination accounts of this journal. Assumes they are valid.
|
* Will update the source and destination accounts of this journal. Assumes they are valid.
|
||||||
*/
|
*/
|
||||||
@@ -424,70 +475,34 @@ class JournalUpdateService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does a validation and returns the destination account. This method will break if the dest isn't really valid.
|
|
||||||
*
|
*
|
||||||
* @return Account
|
|
||||||
*/
|
*/
|
||||||
private function getValidDestinationAccount(): Account
|
private function updateAmount(): void
|
||||||
{
|
{
|
||||||
Log::debug('Now in getValidDestinationAccount().');
|
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||||
|
if (!$this->hasFields(['amount'])) {
|
||||||
if (!$this->hasFields(['destination_id', 'destination_name'])) {
|
return;
|
||||||
return $this->getOriginalDestinationAccount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$destInfo = [
|
$value = $this->data['amount'] ?? '';
|
||||||
'id' => (int)($this->data['destination_id'] ?? null),
|
Log::debug(sprintf('Amount is now "%s"', $value));
|
||||||
'name' => $this->data['destination_name'] ?? null,
|
|
||||||
'iban' => $this->data['destination_iban'] ?? null,
|
|
||||||
'number' => $this->data['destination_number'] ?? null,
|
|
||||||
'bic' => $this->data['destination_bic'] ?? null,
|
|
||||||
];
|
|
||||||
|
|
||||||
// make new account validator.
|
|
||||||
$expectedType = $this->getExpectedType();
|
|
||||||
Log::debug(sprintf('Expected type (new or unchanged) is %s', $expectedType));
|
|
||||||
try {
|
try {
|
||||||
$result = $this->getAccount($expectedType, 'destination', $destInfo);
|
$amount = $this->getAmount($value);
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
Log::error(sprintf('getValidDestinationAccount() threw unexpected error: %s', $e->getMessage()));
|
Log::debug(sprintf('getAmount("%s") returns error: %s', $value, $e->getMessage()));
|
||||||
$result = $this->getOriginalDestinationAccount();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates journal transaction type.
|
|
||||||
*/
|
|
||||||
private function updateType(): void
|
|
||||||
{
|
|
||||||
Log::debug('Now in updateType()');
|
|
||||||
if ($this->hasFields(['type'])) {
|
|
||||||
$type = 'opening-balance' === $this->data['type'] ? 'opening balance' : $this->data['type'];
|
|
||||||
Log::debug(
|
|
||||||
sprintf(
|
|
||||||
'Trying to change journal #%d from a %s to a %s.',
|
|
||||||
$this->transactionJournal->id,
|
|
||||||
$this->transactionJournal->transactionType->type,
|
|
||||||
$type
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
/** @var TransactionTypeFactory $typeFactory */
|
|
||||||
$typeFactory = app(TransactionTypeFactory::class);
|
|
||||||
$result = $typeFactory->find($this->data['type']);
|
|
||||||
if (null !== $result) {
|
|
||||||
Log::debug('Changed transaction type!');
|
|
||||||
$this->transactionJournal->transaction_type_id = $result->id;
|
|
||||||
$this->transactionJournal->save();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log::debug('No type field present.');
|
$origSourceTransaction = $this->getSourceTransaction();
|
||||||
|
$origSourceTransaction->amount = app('steam')->negative($amount);
|
||||||
|
$origSourceTransaction->save();
|
||||||
|
$destTransaction = $this->getDestinationTransaction();
|
||||||
|
$destTransaction->amount = app('steam')->positive($amount);
|
||||||
|
$destTransaction->save();
|
||||||
|
// refresh transactions.
|
||||||
|
$this->sourceTransaction->refresh();
|
||||||
|
$this->destinationTransaction->refresh();
|
||||||
|
Log::debug(sprintf('Updated amount to "%s"', $amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -510,45 +525,6 @@ class JournalUpdateService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update journal generic field. Cannot be set to NULL.
|
|
||||||
*
|
|
||||||
* @param string $fieldName
|
|
||||||
*/
|
|
||||||
private function updateField(string $fieldName): void
|
|
||||||
{
|
|
||||||
if (array_key_exists($fieldName, $this->data) && '' !== (string)$this->data[$fieldName]) {
|
|
||||||
$value = $this->data[$fieldName];
|
|
||||||
|
|
||||||
if ('date' === $fieldName) {
|
|
||||||
if ($value instanceof Carbon) {
|
|
||||||
// update timezone.
|
|
||||||
$value->setTimezone(config('app.timezone'));
|
|
||||||
}
|
|
||||||
if (!($value instanceof Carbon)) {
|
|
||||||
$value = new Carbon($value);
|
|
||||||
}
|
|
||||||
// do some parsing.
|
|
||||||
Log::debug(sprintf('Create date value from string "%s".', $value));
|
|
||||||
}
|
|
||||||
$this->transactionJournal->$fieldName = $value;
|
|
||||||
Log::debug(sprintf('Updated %s', $fieldName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function updateCategory(): void
|
|
||||||
{
|
|
||||||
// update category
|
|
||||||
if ($this->hasFields(['category_id', 'category_name'])) {
|
|
||||||
Log::debug('Will update category.');
|
|
||||||
|
|
||||||
$this->storeCategory($this->transactionJournal, new NullArrayObject($this->data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -568,102 +544,13 @@ class JournalUpdateService
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function updateTags(): void
|
private function updateCategory(): void
|
||||||
{
|
{
|
||||||
if ($this->hasFields(['tags'])) {
|
// update category
|
||||||
Log::debug('Will update tags.');
|
if ($this->hasFields(['category_id', 'category_name'])) {
|
||||||
$tags = $this->data['tags'] ?? null;
|
Log::debug('Will update category.');
|
||||||
$this->storeTags($this->transactionJournal, $tags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$this->storeCategory($this->transactionJournal, new NullArrayObject($this->data));
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function updateReconciled(): void
|
|
||||||
{
|
|
||||||
if (array_key_exists('reconciled', $this->data) && is_bool($this->data['reconciled'])) {
|
|
||||||
$this->transactionJournal->transactions()->update(['reconciled' => $this->data['reconciled']]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function updateNotes(): void
|
|
||||||
{
|
|
||||||
// update notes.
|
|
||||||
if ($this->hasFields(['notes'])) {
|
|
||||||
$notes = '' === (string)$this->data['notes'] ? null : $this->data['notes'];
|
|
||||||
$this->storeNotes($this->transactionJournal, $notes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function updateMeta(): void
|
|
||||||
{
|
|
||||||
// update meta fields.
|
|
||||||
// first string
|
|
||||||
if ($this->hasFields($this->metaString)) {
|
|
||||||
Log::debug('Meta string fields are present.');
|
|
||||||
$this->updateMetaFields();
|
|
||||||
}
|
|
||||||
|
|
||||||
// then date fields.
|
|
||||||
if ($this->hasFields($this->metaDate)) {
|
|
||||||
Log::debug('Meta date fields are present.');
|
|
||||||
$this->updateMetaDateFields();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function updateMetaFields(): void
|
|
||||||
{
|
|
||||||
/** @var TransactionJournalMetaFactory $factory */
|
|
||||||
$factory = app(TransactionJournalMetaFactory::class);
|
|
||||||
|
|
||||||
foreach ($this->metaString as $field) {
|
|
||||||
if ($this->hasFields([$field])) {
|
|
||||||
$value = '' === $this->data[$field] ? null : $this->data[$field];
|
|
||||||
Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value));
|
|
||||||
$set = [
|
|
||||||
'journal' => $this->transactionJournal,
|
|
||||||
'name' => $field,
|
|
||||||
'data' => $value,
|
|
||||||
];
|
|
||||||
$factory->updateOrCreate($set);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function updateMetaDateFields(): void
|
|
||||||
{
|
|
||||||
/** @var TransactionJournalMetaFactory $factory */
|
|
||||||
$factory = app(TransactionJournalMetaFactory::class);
|
|
||||||
|
|
||||||
foreach ($this->metaDate as $field) {
|
|
||||||
if ($this->hasFields([$field])) {
|
|
||||||
try {
|
|
||||||
$value = '' === (string)$this->data[$field] ? null : new Carbon($this->data[$field]);
|
|
||||||
} catch (InvalidDateException $e) {
|
|
||||||
Log::debug(sprintf('%s is not a valid date value: %s', $this->data[$field], $e->getMessage()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value));
|
|
||||||
$set = [
|
|
||||||
'journal' => $this->transactionJournal,
|
|
||||||
'name' => $field,
|
|
||||||
'data' => $value,
|
|
||||||
];
|
|
||||||
$factory->updateOrCreate($set);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,34 +587,39 @@ class JournalUpdateService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Update journal generic field. Cannot be set to NULL.
|
||||||
*
|
*
|
||||||
|
* @param string $fieldName
|
||||||
*/
|
*/
|
||||||
private function updateAmount(): void
|
private function updateField(string $fieldName): void
|
||||||
{
|
{
|
||||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
if (array_key_exists($fieldName, $this->data) && '' !== (string)$this->data[$fieldName]) {
|
||||||
if (!$this->hasFields(['amount'])) {
|
$value = $this->data[$fieldName];
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = $this->data['amount'] ?? '';
|
if ('date' === $fieldName) {
|
||||||
Log::debug(sprintf('Amount is now "%s"', $value));
|
if ($value instanceof Carbon) {
|
||||||
try {
|
// update timezone.
|
||||||
$amount = $this->getAmount($value);
|
$value->setTimezone(config('app.timezone'));
|
||||||
} catch (FireflyException $e) {
|
}
|
||||||
Log::debug(sprintf('getAmount("%s") returns error: %s', $value, $e->getMessage()));
|
if (!($value instanceof Carbon)) {
|
||||||
|
$value = new Carbon($value);
|
||||||
|
}
|
||||||
|
// do some parsing.
|
||||||
|
Log::debug(sprintf('Create date value from string "%s".', $value));
|
||||||
|
}
|
||||||
|
event(
|
||||||
|
new TriggeredAuditLog(
|
||||||
|
$this->transactionJournal->user,
|
||||||
|
$this->transactionJournal,
|
||||||
|
sprintf('update_%s', $fieldName),
|
||||||
|
$this->transactionJournal->$fieldName,
|
||||||
|
$value
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return;
|
$this->transactionJournal->$fieldName = $value;
|
||||||
|
Log::debug(sprintf('Updated %s', $fieldName));
|
||||||
}
|
}
|
||||||
$origSourceTransaction = $this->getSourceTransaction();
|
|
||||||
$origSourceTransaction->amount = app('steam')->negative($amount);
|
|
||||||
$origSourceTransaction->save();
|
|
||||||
$destTransaction = $this->getDestinationTransaction();
|
|
||||||
$destTransaction->amount = app('steam')->positive($amount);
|
|
||||||
$destTransaction->save();
|
|
||||||
// refresh transactions.
|
|
||||||
$this->sourceTransaction->refresh();
|
|
||||||
$this->destinationTransaction->refresh();
|
|
||||||
Log::debug(sprintf('Updated amount to "%s"', $amount));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -749,7 +641,8 @@ class JournalUpdateService
|
|||||||
// find currency in data array
|
// find currency in data array
|
||||||
$newForeignId = $this->data['foreign_currency_id'] ?? null;
|
$newForeignId = $this->data['foreign_currency_id'] ?? null;
|
||||||
$newForeignCode = $this->data['foreign_currency_code'] ?? null;
|
$newForeignCode = $this->data['foreign_currency_code'] ?? null;
|
||||||
$foreignCurrency = $this->currencyRepository->findCurrencyNull($newForeignId, $newForeignCode) ?? $foreignCurrency;
|
$foreignCurrency = $this->currencyRepository->findCurrencyNull($newForeignId, $newForeignCode) ??
|
||||||
|
$foreignCurrency;
|
||||||
|
|
||||||
// not the same as normal currency
|
// not the same as normal currency
|
||||||
if (null !== $foreignCurrency && $foreignCurrency->id === $this->transactionJournal->transaction_currency_id) {
|
if (null !== $foreignCurrency && $foreignCurrency->id === $this->transactionJournal->transaction_currency_id) {
|
||||||
@@ -767,7 +660,14 @@ class JournalUpdateService
|
|||||||
$dest->foreign_amount = app('steam')->positive($foreignAmount);
|
$dest->foreign_amount = app('steam')->positive($foreignAmount);
|
||||||
$dest->save();
|
$dest->save();
|
||||||
|
|
||||||
Log::debug(sprintf('Update foreign info to %s (#%d) %s', $foreignCurrency->code, $foreignCurrency->id, $foreignAmount));
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'Update foreign info to %s (#%d) %s',
|
||||||
|
$foreignCurrency->code,
|
||||||
|
$foreignCurrency->id,
|
||||||
|
$foreignAmount
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// refresh transactions.
|
// refresh transactions.
|
||||||
$this->sourceTransaction->refresh();
|
$this->sourceTransaction->refresh();
|
||||||
@@ -791,4 +691,140 @@ class JournalUpdateService
|
|||||||
$this->sourceTransaction->refresh();
|
$this->sourceTransaction->refresh();
|
||||||
$this->destinationTransaction->refresh();
|
$this->destinationTransaction->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function updateMeta(): void
|
||||||
|
{
|
||||||
|
// update meta fields.
|
||||||
|
// first string
|
||||||
|
if ($this->hasFields($this->metaString)) {
|
||||||
|
Log::debug('Meta string fields are present.');
|
||||||
|
$this->updateMetaFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
// then date fields.
|
||||||
|
if ($this->hasFields($this->metaDate)) {
|
||||||
|
Log::debug('Meta date fields are present.');
|
||||||
|
$this->updateMetaDateFields();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function updateMetaDateFields(): void
|
||||||
|
{
|
||||||
|
/** @var TransactionJournalMetaFactory $factory */
|
||||||
|
$factory = app(TransactionJournalMetaFactory::class);
|
||||||
|
|
||||||
|
foreach ($this->metaDate as $field) {
|
||||||
|
if ($this->hasFields([$field])) {
|
||||||
|
try {
|
||||||
|
$value = '' === (string)$this->data[$field] ? null : new Carbon($this->data[$field]);
|
||||||
|
} catch (InvalidDateException $e) {
|
||||||
|
Log::debug(sprintf('%s is not a valid date value: %s', $this->data[$field], $e->getMessage()));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value));
|
||||||
|
$set = [
|
||||||
|
'journal' => $this->transactionJournal,
|
||||||
|
'name' => $field,
|
||||||
|
'data' => $value,
|
||||||
|
];
|
||||||
|
$factory->updateOrCreate($set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function updateMetaFields(): void
|
||||||
|
{
|
||||||
|
/** @var TransactionJournalMetaFactory $factory */
|
||||||
|
$factory = app(TransactionJournalMetaFactory::class);
|
||||||
|
|
||||||
|
foreach ($this->metaString as $field) {
|
||||||
|
if ($this->hasFields([$field])) {
|
||||||
|
$value = '' === $this->data[$field] ? null : $this->data[$field];
|
||||||
|
Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value));
|
||||||
|
$set = [
|
||||||
|
'journal' => $this->transactionJournal,
|
||||||
|
'name' => $field,
|
||||||
|
'data' => $value,
|
||||||
|
];
|
||||||
|
$factory->updateOrCreate($set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function updateNotes(): void
|
||||||
|
{
|
||||||
|
// update notes.
|
||||||
|
if ($this->hasFields(['notes'])) {
|
||||||
|
$notes = '' === (string)$this->data['notes'] ? null : $this->data['notes'];
|
||||||
|
$this->storeNotes($this->transactionJournal, $notes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function updateReconciled(): void
|
||||||
|
{
|
||||||
|
if (array_key_exists('reconciled', $this->data) && is_bool($this->data['reconciled'])) {
|
||||||
|
$this->transactionJournal->transactions()->update(['reconciled' => $this->data['reconciled']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function updateTags(): void
|
||||||
|
{
|
||||||
|
if ($this->hasFields(['tags'])) {
|
||||||
|
Log::debug('Will update tags.');
|
||||||
|
$tags = $this->data['tags'] ?? null;
|
||||||
|
$this->storeTags($this->transactionJournal, $tags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates journal transaction type.
|
||||||
|
*/
|
||||||
|
private function updateType(): void
|
||||||
|
{
|
||||||
|
Log::debug('Now in updateType()');
|
||||||
|
if ($this->hasFields(['type'])) {
|
||||||
|
$type = 'opening-balance' === $this->data['type'] ? 'opening balance' : $this->data['type'];
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'Trying to change journal #%d from a %s to a %s.',
|
||||||
|
$this->transactionJournal->id,
|
||||||
|
$this->transactionJournal->transactionType->type,
|
||||||
|
$type
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
/** @var TransactionTypeFactory $typeFactory */
|
||||||
|
$typeFactory = app(TransactionTypeFactory::class);
|
||||||
|
$result = $typeFactory->find($this->data['type']);
|
||||||
|
if (null !== $result) {
|
||||||
|
Log::debug('Changed transaction type!');
|
||||||
|
$this->transactionJournal->transaction_type_id = $result->id;
|
||||||
|
$this->transactionJournal->save();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Log::debug('No type field present.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -109,7 +109,11 @@ class General extends AbstractExtension
|
|||||||
[, $route, $objectType] = func_get_args();
|
[, $route, $objectType] = func_get_args();
|
||||||
$activeObjectType = $context['objectType'] ?? false;
|
$activeObjectType = $context['objectType'] ?? false;
|
||||||
|
|
||||||
if ($objectType === $activeObjectType && false !== stripos(Route::getCurrentRoute()->getName(), $route)) {
|
if ($objectType === $activeObjectType
|
||||||
|
&& false !== stripos(
|
||||||
|
Route::getCurrentRoute()->getName(),
|
||||||
|
$route
|
||||||
|
)) {
|
||||||
return 'active';
|
return 'active';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +175,7 @@ class General extends AbstractExtension
|
|||||||
return new TwigFunction(
|
return new TwigFunction(
|
||||||
'carbonize',
|
'carbonize',
|
||||||
static function (string $date): Carbon {
|
static function (string $date): Carbon {
|
||||||
return new Carbon($date);
|
return new Carbon($date, config('app.timezone'));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -205,15 +209,15 @@ class General extends AbstractExtension
|
|||||||
static function (int $size): string {
|
static function (int $size): string {
|
||||||
// less than one GB, more than one MB
|
// less than one GB, more than one MB
|
||||||
if ($size < (1024 * 1024 * 2014) && $size >= (1024 * 1024)) {
|
if ($size < (1024 * 1024 * 2014) && $size >= (1024 * 1024)) {
|
||||||
return round($size / (1024 * 1024), 2).' MB';
|
return round($size / (1024 * 1024), 2) . ' MB';
|
||||||
}
|
}
|
||||||
|
|
||||||
// less than one MB
|
// less than one MB
|
||||||
if ($size < (1024 * 1024)) {
|
if ($size < (1024 * 1024)) {
|
||||||
return round($size / 1024, 2).' KB';
|
return round($size / 1024, 2) . ' KB';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $size.' bytes';
|
return $size . ' bytes';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -245,6 +249,7 @@ class General extends AbstractExtension
|
|||||||
'getRootSearchOperator',
|
'getRootSearchOperator',
|
||||||
static function (string $operator): string {
|
static function (string $operator): string {
|
||||||
$result = OperatorQuerySearch::getRootOperator($operator);
|
$result = OperatorQuerySearch::getRootOperator($operator);
|
||||||
|
|
||||||
return str_replace('-', 'not_', $result);
|
return str_replace('-', 'not_', $result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@@ -2595,6 +2595,9 @@ return [
|
|||||||
'ale_action_log_add' => 'Added :amount to piggy bank ":name"',
|
'ale_action_log_add' => 'Added :amount to piggy bank ":name"',
|
||||||
'ale_action_log_remove' => 'Removed :amount from piggy bank ":name"',
|
'ale_action_log_remove' => 'Removed :amount from piggy bank ":name"',
|
||||||
'ale_action_clear_budget' => 'Removed from budget',
|
'ale_action_clear_budget' => 'Removed from budget',
|
||||||
|
'ale_action_update_group_title' => 'Updated transaction group title',
|
||||||
|
'ale_action_update_date' => 'Updated transaction date',
|
||||||
|
'ale_action_update_order' => 'Updated transaction order',
|
||||||
'ale_action_clear_category' => 'Removed from category',
|
'ale_action_clear_category' => 'Removed from category',
|
||||||
'ale_action_clear_notes' => 'Removed notes',
|
'ale_action_clear_notes' => 'Removed notes',
|
||||||
'ale_action_clear_tag' => 'Cleared tag',
|
'ale_action_clear_tag' => 'Cleared tag',
|
||||||
|
@@ -4,13 +4,16 @@
|
|||||||
<th style="width:20%;" scope="row">
|
<th style="width:20%;" scope="row">
|
||||||
{# link to object: #}
|
{# link to object: #}
|
||||||
{% if 'FireflyIII\\Models\\Rule' == logEntry.changer_type %}
|
{% if 'FireflyIII\\Models\\Rule' == logEntry.changer_type %}
|
||||||
<a href="{{ route('rules.edit', [logEntry.changer_id] ) }}">
|
<a href="{{ route('rules.edit', [logEntry.changer_id] ) }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ logEntry.changer_type|replace({"FireflyIII\\Models\\": ""}) }}
|
{% if 'FireflyIII\\User' == logEntry.changer_type %}
|
||||||
#{{ logEntry.changer_id }}
|
<a href="{{ route('profile.index') }}">
|
||||||
|
{% endif %}
|
||||||
|
{{ logEntry.changer_type|replace({"FireflyIII\\Models\\": ""})|replace({"FireflyIII\\": ""}) }}
|
||||||
|
#{{ logEntry.changer_id }}
|
||||||
</a>
|
</a>
|
||||||
</th>
|
</th>
|
||||||
<td style="width:30%;">
|
<td style="width:30%;" title="{{ logEntry.created_at.isoFormat(dateTimeFormat) }}">
|
||||||
{{ trans('firefly.ale_action_'~logEntry.action) }}
|
{{ trans('firefly.ale_action_'~logEntry.action) }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@@ -18,8 +21,11 @@
|
|||||||
{% if 'add_tag' == logEntry.action %}
|
{% if 'add_tag' == logEntry.action %}
|
||||||
<code>{{ logEntry.after }}</code>
|
<code>{{ logEntry.after }}</code>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'clear_budget' == logEntry.action %}
|
|
||||||
|
{% if 'update_group_title' == logEntry.action %}
|
||||||
<code><s>{{ logEntry.before }}</s></code>
|
<code><s>{{ logEntry.before }}</s></code>
|
||||||
|
→
|
||||||
|
<code>{{ logEntry.after }}</code>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'clear_category' == logEntry.action %}
|
{% if 'clear_category' == logEntry.action %}
|
||||||
<code><s>{{ logEntry.before }}</s></code>
|
<code><s>{{ logEntry.before }}</s></code>
|
||||||
@@ -51,6 +57,11 @@
|
|||||||
{% if 'set_destination' == logEntry.action %}
|
{% if 'set_destination' == logEntry.action %}
|
||||||
<code>{{ logEntry.after }}</code>
|
<code>{{ logEntry.after }}</code>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if 'update_date' == logEntry.action %}
|
||||||
|
<code><s>{{ carbonize(logEntry.before).isoFormat(dateTimeFormat) }}</s></code>
|
||||||
|
→
|
||||||
|
<code>{{ carbonize(logEntry.after).isoFormat(dateTimeFormat) }}</code>
|
||||||
|
{% endif %}
|
||||||
{% if 'update_transaction_type' == logEntry.action %}
|
{% if 'update_transaction_type' == logEntry.action %}
|
||||||
{{ trans('firefly.'~logEntry.before) }} → {{ trans('firefly.'~logEntry.after) }}
|
{{ trans('firefly.'~logEntry.before) }} → {{ trans('firefly.'~logEntry.after) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@@ -11,32 +11,42 @@
|
|||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'transaction_journal_information'|_ }}</h3>
|
<h3 class="box-title">{{ 'transaction_journal_information'|_ }}</h3>
|
||||||
<div class="btn-group btn-group-xs pull-right">
|
<div class="btn-group btn-group-xs pull-right">
|
||||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
|
||||||
{{ 'actions'|_}} <span class="caret"></span>
|
aria-haspopup="true" aria-expanded="false">
|
||||||
|
{{ 'actions'|_ }} <span class="caret"></span>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
{# edit + delete #}
|
{# edit + delete #}
|
||||||
<li><a href="{{ route('transactions.edit', [transactionGroup.id]) }}"><span class="fa fa-pencil"></span> {{ 'edit'|_ }}</a></li>
|
<li><a href="{{ route('transactions.edit', [transactionGroup.id]) }}"><span
|
||||||
<li><a href="{{ route('transactions.delete', [transactionGroup.id]) }}"><span class="fa fa-trash"></span> {{ 'delete'|_ }}</a></li>
|
class="fa fa-pencil"></span> {{ 'edit'|_ }}</a></li>
|
||||||
|
<li><a href="{{ route('transactions.delete', [transactionGroup.id]) }}"><span
|
||||||
|
class="fa fa-trash"></span> {{ 'delete'|_ }}</a></li>
|
||||||
<li role="separator" class="divider"></li>
|
<li role="separator" class="divider"></li>
|
||||||
|
|
||||||
{# convert to different type #}
|
{# convert to different type #}
|
||||||
{% if groupArray.transactions[0].type != 'withdrawal' %}
|
{% if groupArray.transactions[0].type != 'withdrawal' %}
|
||||||
<li><a href="{{ route('transactions.convert.index', ['withdrawal', transactionGroup.id]) }}"><span class="fa fa-exchange"></span> {{ 'convert_to_withdrawal'|_ }}</a></li>
|
<li>
|
||||||
|
<a href="{{ route('transactions.convert.index', ['withdrawal', transactionGroup.id]) }}"><span
|
||||||
|
class="fa fa-exchange"></span> {{ 'convert_to_withdrawal'|_ }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if groupArray.transactions[0].type != 'deposit' %}
|
{% if groupArray.transactions[0].type != 'deposit' %}
|
||||||
<li><a href="{{ route('transactions.convert.index', ['deposit', transactionGroup.id]) }}"><span class="fa fa-exchange"></span> {{ 'convert_to_deposit'|_ }}</a></li>
|
<li>
|
||||||
|
<a href="{{ route('transactions.convert.index', ['deposit', transactionGroup.id]) }}"><span
|
||||||
|
class="fa fa-exchange"></span> {{ 'convert_to_deposit'|_ }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if groupArray.transactions[0].type != 'transfer' %}
|
{% if groupArray.transactions[0].type != 'transfer' %}
|
||||||
<li><a href="{{ route('transactions.convert.index', ['transfer', transactionGroup.id]) }}"><span class="fa fa-exchange"></span> {{ 'convert_to_transfer'|_ }}</a></li>
|
<li>
|
||||||
|
<a href="{{ route('transactions.convert.index', ['transfer', transactionGroup.id]) }}"><span
|
||||||
|
class="fa fa-exchange"></span> {{ 'convert_to_transfer'|_ }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# clone #}
|
{# clone #}
|
||||||
{% if groupArray.transactions[0].type != 'opening balance' and groupArray.transactions[0].type != 'reconciliation' %}
|
{% if groupArray.transactions[0].type != 'opening balance' and groupArray.transactions[0].type != 'reconciliation' %}
|
||||||
<li role="separator" class="divider"></li>
|
<li role="separator" class="divider"></li>
|
||||||
<li><a href="#" class="clone-transaction" data-id="{{ transactionGroup.id }}"><span class="fa fa-copy"></span> {{ 'clone'|_ }}</a></li>
|
<li><a href="#" class="clone-transaction" data-id="{{ transactionGroup.id }}"><span
|
||||||
|
class="fa fa-copy"></span> {{ 'clone'|_ }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
@@ -69,6 +79,19 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% if groupLogEntries|length > 0 %}
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">
|
||||||
|
{{ 'audit_log_entries'|_ }}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body no-padding">
|
||||||
|
{% include 'list.ale' with {logEntries: groupLogEntries} %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
<div class="box box-primary">
|
<div class="box box-primary">
|
||||||
@@ -183,38 +206,58 @@
|
|||||||
|
|
||||||
|
|
||||||
<div class="btn-group btn-group-xs pull-right">
|
<div class="btn-group btn-group-xs pull-right">
|
||||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
|
||||||
{{ 'actions'|_}} <span class="caret"></span>
|
aria-haspopup="true" aria-expanded="false">
|
||||||
|
{{ 'actions'|_ }} <span class="caret"></span>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
{# edit + delete #}
|
{# edit + delete #}
|
||||||
<li><a href="{{ route('transactions.edit', [transactionGroup.id]) }}"><span class="fa fa-pencil"></span> {{ 'edit'|_ }}</a></li>
|
<li><a href="{{ route('transactions.edit', [transactionGroup.id]) }}"><span
|
||||||
<li><a href="{{ route('transactions.delete', [transactionGroup.id]) }}"><span class="fa fa-trash"></span> {{ 'delete'|_ }}</a></li>
|
class="fa fa-pencil"></span> {{ 'edit'|_ }}</a></li>
|
||||||
|
<li><a href="{{ route('transactions.delete', [transactionGroup.id]) }}"><span
|
||||||
|
class="fa fa-trash"></span> {{ 'delete'|_ }}</a></li>
|
||||||
<li role="separator" class="divider"></li>
|
<li role="separator" class="divider"></li>
|
||||||
|
|
||||||
{# convert to different type #}
|
{# convert to different type #}
|
||||||
{% if groupArray.transactions[0].type != 'withdrawal' %}
|
{% if groupArray.transactions[0].type != 'withdrawal' %}
|
||||||
<li><a href="{{ route('transactions.convert.index', ['withdrawal', transactionGroup.id]) }}"><span class="fa fa-exchange"></span> {{ 'convert_to_withdrawal'|_ }}</a></li>
|
<li>
|
||||||
|
<a href="{{ route('transactions.convert.index', ['withdrawal', transactionGroup.id]) }}"><span
|
||||||
|
class="fa fa-exchange"></span> {{ 'convert_to_withdrawal'|_ }}</a>
|
||||||
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if groupArray.transactions[0].type != 'deposit' %}
|
{% if groupArray.transactions[0].type != 'deposit' %}
|
||||||
<li><a href="{{ route('transactions.convert.index', ['deposit', transactionGroup.id]) }}"><span class="fa fa-exchange"></span> {{ 'convert_to_deposit'|_ }}</a></li>
|
<li>
|
||||||
|
<a href="{{ route('transactions.convert.index', ['deposit', transactionGroup.id]) }}"><span
|
||||||
|
class="fa fa-exchange"></span> {{ 'convert_to_deposit'|_ }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if groupArray.transactions[0].type != 'transfer' %}
|
{% if groupArray.transactions[0].type != 'transfer' %}
|
||||||
<li><a href="{{ route('transactions.convert.index', ['transfer', transactionGroup.id]) }}"><span class="fa fa-exchange"></span> {{ 'convert_to_transfer'|_ }}</a></li>
|
<li>
|
||||||
|
<a href="{{ route('transactions.convert.index', ['transfer', transactionGroup.id]) }}"><span
|
||||||
|
class="fa fa-exchange"></span> {{ 'convert_to_transfer'|_ }}</a>
|
||||||
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# clone #}
|
{# clone #}
|
||||||
{% if groupArray.transactions[0].type != 'opening balance' and groupArray.transactions[0].type != 'reconciliation' %}
|
{% if groupArray.transactions[0].type != 'opening balance' and groupArray.transactions[0].type != 'reconciliation' %}
|
||||||
<li role="separator" class="divider"></li>
|
<li role="separator" class="divider"></li>
|
||||||
<li><a href="#" data-id="{{ transactionGroup.id }}" class="clone-transaction"><span class="fa fa-copy"></span> {{ 'clone'|_ }}</a></li>
|
<li><a href="#" data-id="{{ transactionGroup.id }}" class="clone-transaction"><span
|
||||||
|
class="fa fa-copy"></span> {{ 'clone'|_ }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<li><a href="#" class="link-modal" data-journal="{{ journal.transaction_journal_id }}"><span class="fa fa-fw fa-link"></span>{{ 'link_transaction'|_ }}</a></li>
|
<li><a href="#" class="link-modal"
|
||||||
|
data-journal="{{ journal.transaction_journal_id }}"><span
|
||||||
|
class="fa fa-fw fa-link"></span>{{ 'link_transaction'|_ }}</a></li>
|
||||||
<li role="separator" class="divider"></li>
|
<li role="separator" class="divider"></li>
|
||||||
<li><a href="{{ route('rules.create-from-journal', [journal.transaction_journal_id]) }}"><span class="fa fa-fw fa-random"></span>{{ 'create_rule_from_transaction'|_ }}</a></li>
|
<li>
|
||||||
<li><a href="{{ route('recurring.create-from-journal', [journal.transaction_journal_id]) }}"><span class="fa fa-fw fa-paint-brush"></span>{{ 'create_recurring_from_transaction'|_ }}</a></li>
|
<a href="{{ route('rules.create-from-journal', [journal.transaction_journal_id]) }}"><span
|
||||||
|
class="fa fa-fw fa-random"></span>{{ 'create_rule_from_transaction'|_ }}
|
||||||
|
</a></li>
|
||||||
|
<li>
|
||||||
|
<a href="{{ route('recurring.create-from-journal', [journal.transaction_journal_id]) }}"><span
|
||||||
|
class="fa fa-fw fa-paint-brush"></span>{{ 'create_recurring_from_transaction'|_ }}
|
||||||
|
</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -222,6 +265,7 @@
|
|||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
|
|
||||||
<!-- type is: "{{ first.transactiontype.type }}" -->
|
<!-- type is: "{{ first.transactiontype.type }}" -->
|
||||||
{% if 'Cash account' == journal.source_type %}
|
{% if 'Cash account' == journal.source_type %}
|
||||||
<span class="text-success">({{ 'cash'|_ }})</span>
|
<span class="text-success">({{ 'cash'|_ }})</span>
|
||||||
@@ -230,8 +274,10 @@
|
|||||||
title="{{ journal.source_iban|default(journal.source_name) }}">{{ journal.source_name }}</a> →
|
title="{{ journal.source_iban|default(journal.source_name) }}">{{ journal.source_name }}</a> →
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if first.transactiontype.type == 'Withdrawal' or first.transactiontype.type == 'Deposit' %}
|
{% if first.transactiontype.type == 'Withdrawal' %}
|
||||||
{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places) }}
|
{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places) }}
|
||||||
|
{% elseif first.transactiontype.type == 'Deposit' %}
|
||||||
|
{{ formatAmountBySymbol(journal.amount, journal.currency_symbol, journal.currency_decimal_places) }}
|
||||||
{% elseif first.transactiontype.type == 'Transfer' or first.transactiontype.type == 'Opening balance' %}
|
{% elseif first.transactiontype.type == 'Transfer' or first.transactiontype.type == 'Opening balance' %}
|
||||||
<span class="text-info money-transfer">
|
<span class="text-info money-transfer">
|
||||||
{{ formatAmountBySymbol(journal.amount, journal.currency_symbol, journal.currency_decimal_places, false) }}
|
{{ formatAmountBySymbol(journal.amount, journal.currency_symbol, journal.currency_decimal_places, false) }}
|
||||||
@@ -265,19 +311,25 @@
|
|||||||
{% if null != journal.category_id %}
|
{% if null != journal.category_id %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width:30%;">{{ 'category'|_ }}</td>
|
<td style="width:30%;">{{ 'category'|_ }}</td>
|
||||||
<td><a href="{{ route('categories.show', [journal.category_id]) }}">{{ journal.category_name }}</a></td>
|
<td>
|
||||||
|
<a href="{{ route('categories.show', [journal.category_id]) }}">{{ journal.category_name }}</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if null != journal.budget_id and first.transactiontype.type == 'Withdrawal' %}
|
{% if null != journal.budget_id and first.transactiontype.type == 'Withdrawal' %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width:40%;">{{ 'budget'|_ }}</td>
|
<td style="width:40%;">{{ 'budget'|_ }}</td>
|
||||||
<td><a href="{{ route('budgets.show', [journal.budget_id]) }}">{{ journal.budget_name }}</a></td>
|
<td>
|
||||||
|
<a href="{{ route('budgets.show', [journal.budget_id]) }}">{{ journal.budget_name }}</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if null != journal.bill_id and first.transactiontype.type == 'Withdrawal' %}
|
{% if null != journal.bill_id and first.transactiontype.type == 'Withdrawal' %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width:40%;">{{ 'bill'|_ }}</td>
|
<td style="width:40%;">{{ 'bill'|_ }}</td>
|
||||||
<td><a href="{{ route('bills.show', [journal.bill_id]) }}">{{ journal.bill_name }}</a></td>
|
<td>
|
||||||
|
<a href="{{ route('bills.show', [journal.bill_id]) }}">{{ journal.bill_name }}</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<!-- other fields -->
|
<!-- other fields -->
|
||||||
@@ -294,7 +346,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{ trans('list.'~metaField) }}</td>
|
<td>{{ trans('list.'~metaField) }}</td>
|
||||||
<td style="width:40%;">
|
<td style="width:40%;">
|
||||||
{% if 'external_url' == metaField %}
|
{% if 'external_url' == metaField %}
|
||||||
{% set url = journalGetMetaField(journal.transaction_journal_id, metaField) %}
|
{% set url = journalGetMetaField(journal.transaction_journal_id, metaField) %}
|
||||||
<a href="{{ url }}" rel="noopener noreferrer nofollow" target="_blank">
|
<a href="{{ url }}" rel="noopener noreferrer nofollow" target="_blank">
|
||||||
{% if url|length > 60 %}
|
{% if url|length > 60 %}
|
||||||
@@ -304,7 +356,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'external_url' != metaField %}
|
{% if 'external_url' != metaField %}
|
||||||
{{ journalGetMetaField(journal.transaction_journal_id, metaField) }}
|
{{ journalGetMetaField(journal.transaction_journal_id, metaField) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
@@ -317,7 +369,7 @@
|
|||||||
<td class="markdown">{{ journal.notes|default('')|markdown }}</td>
|
<td class="markdown">{{ journal.notes|default('')|markdown }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if journalHasMeta(journal.transaction_journal_id, 'recurring_total') and journalHasMeta(journal.transaction_journal_id, 'recurring_count') %}
|
{% if journalHasMeta(journal.transaction_journal_id, 'recurring_total') and journalHasMeta(journal.transaction_journal_id, 'recurring_count') %}
|
||||||
{% set recurringTotal = journalGetMetaField(journal.transaction_journal_id, 'recurring_total') %}
|
{% set recurringTotal = journalGetMetaField(journal.transaction_journal_id, 'recurring_total') %}
|
||||||
{% if 0 == recurringTotal %}
|
{% if 0 == recurringTotal %}
|
||||||
{% set recurringTotal = '∞' %}
|
{% set recurringTotal = '∞' %}
|
||||||
@@ -332,7 +384,8 @@
|
|||||||
<td style="width:40%;">{{ 'tags'|_ }}</td>
|
<td style="width:40%;">{{ 'tags'|_ }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% for tag in journal.tags %}
|
{% for tag in journal.tags %}
|
||||||
<h4 style="display: inline;"><a class="label label-success" href="{{ route('tags.show', tag.id) }}">
|
<h4 style="display: inline;"><a class="label label-success"
|
||||||
|
href="{{ route('tags.show', tag.id) }}">
|
||||||
<span class="fa fa-fw fa-tag"></span>{{ tag.tag }}</a>
|
<span class="fa fa-fw fa-tag"></span>{{ tag.tag }}</a>
|
||||||
</h4>
|
</h4>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -359,17 +412,18 @@
|
|||||||
<div class="btn-group btn-group-xs">
|
<div class="btn-group btn-group-xs">
|
||||||
<a href="#" class="btn btn-default switch-link" data-id="{{ link.id }}"><span
|
<a href="#" class="btn btn-default switch-link" data-id="{{ link.id }}"><span
|
||||||
class="fa fa-fw fa-arrows-h"></span></a>
|
class="fa fa-fw fa-arrows-h"></span></a>
|
||||||
<a href="{{ route('transactions.link.delete', [link.id]) }}" class="btn btn-danger"><span class="fa fa-trash"></span></a>
|
<a href="{{ route('transactions.link.delete', [link.id]) }}"
|
||||||
|
class="btn btn-danger"><span class="fa fa-trash"></span></a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if link.editable %}
|
{% if link.editable %}
|
||||||
{{ link.link }}
|
{{ link.link }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ trans('firefly.'~link.link) }}
|
{{ trans('firefly.'~link.link) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
"<a href="{{ route('transactions.show', link.group) }}"
|
"<a href="{{ route('transactions.show', link.group) }}"
|
||||||
title="{{ link.description }}">{{ link.description }}</a>"
|
title="{{ link.description }}">{{ link.description }}</a>"
|
||||||
|
|
||||||
({{ link.amount|raw }})
|
({{ link.amount|raw }})
|
||||||
{% if '' != link.foreign_amount %}
|
{% if '' != link.foreign_amount %}
|
||||||
@@ -408,7 +462,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td style="width:30%;">{{ event.amount|raw }}</td>
|
<td style="width:30%;">{{ event.amount|raw }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ route('piggy-banks.show', [event.piggy_id]) }}">{{ event.piggy }}</a></td>
|
<a href="{{ route('piggy-banks.show', [event.piggy_id]) }}">{{ event.piggy }}</a>
|
||||||
|
</td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -417,16 +472,16 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if logEntries[journal.transaction_journal_id]|length > 0 %}
|
{% if logEntries[journal.transaction_journal_id]|length > 0 %}
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">
|
<h3 class="box-title">
|
||||||
{{ 'audit_log_entries'|_ }}
|
{{ 'audit_log_entries'|_ }}
|
||||||
</h3>
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body no-padding">
|
||||||
|
{% include 'list.ale' with {logEntries: logEntries[journal.transaction_journal_id]} %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body no-padding">
|
|
||||||
{% include 'list.ale' with {logEntries: logEntries[journal.transaction_journal_id]} %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -444,6 +499,7 @@
|
|||||||
|
|
||||||
$('.switch-link').on('click', switchLink);
|
$('.switch-link').on('click', switchLink);
|
||||||
var switchLinkUrl = '{{ route('transactions.link.switch') }}';
|
var switchLinkUrl = '{{ route('transactions.link.switch') }}';
|
||||||
|
|
||||||
function switchLink(e) {
|
function switchLink(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var obj = $(e.currentTarget);
|
var obj = $(e.currentTarget);
|
||||||
@@ -461,7 +517,9 @@
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="v1/js/lib/typeahead/typeahead.bundle.min.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
|
<script type="text/javascript" src="v1/js/lib/typeahead/typeahead.bundle.min.js?v={{ FF_VERSION }}"
|
||||||
<script type="text/javascript" src="v1/js/ff/transactions/show.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
|
nonce="{{ JS_NONCE }}"></script>
|
||||||
|
<script type="text/javascript" src="v1/js/ff/transactions/show.js?v={{ FF_VERSION }}"
|
||||||
|
nonce="{{ JS_NONCE }}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user