Skip to content

Firefly III: a personal finances manager

Some last-minute fixes.

James Cole18b06ff2832d
diff --git a/app/Console/Commands/VerifyDatabase.php b/app/Console/Commands/VerifyDatabase.php
index 00920aaf7f..0b3ecc5f4d 100644
--- a/app/Console/Commands/VerifyDatabase.php
+++ b/app/Console/Commands/VerifyDatabase.php
@@ -90,6 +90,7 @@ class VerifyDatabase extends Command
$this->createAccessTokens();
$this->fixDoubleAmounts();
$this->fixBadMeta();
+ $this->removeBills();
}
/**
@@ -255,6 +256,23 @@ class VerifyDatabase extends Command
}
}
+ /**
+ *
+ */
+ private function removeBills(): void
+ {
+ /** @var TransactionType $withdrawal */
+ $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
+ $journals = TransactionJournal::whereNotNull('bill_id')
+ ->where('transaction_type_id', '!=', $withdrawal->id)->get();
+ /** @var TransactionJournal $journal */
+ foreach ($journals as $journal) {
+ $this->line(sprintf('Transaction journal #%d should not be linked to bill #%d.', $journal->id, $journal->bill_id));
+ $journal->bill_id = null;
+ $journal->save();
+ }
+ }
+
/**
* Eeport (and fix) piggy banks. Make sure there are only transfers linked to piggy bank events.
*/
diff --git a/app/Http/Controllers/Import/IndexController.php b/app/Http/Controllers/Import/IndexController.php
index a6fe9d3167..72c422caad 100644
--- a/app/Http/Controllers/Import/IndexController.php
+++ b/app/Http/Controllers/Import/IndexController.php
@@ -161,10 +161,8 @@ class IndexController extends Controller
$config['delimiter'] = $config['delimiter'] ?? ',';
$config['delimiter'] = "\t" === $config['delimiter'] ? 'tab' : $config['delimiter'];
- // this prevents private information from escaping
- $config['column-mapping-config'] = [];
- $result = json_encode($config, JSON_PRETTY_PRINT);
- $name = sprintf('"%s"', addcslashes('import-configuration-' . date('Y-m-d') . '.json', '"\\'));
+ $result = json_encode($config, JSON_PRETTY_PRINT);
+ $name = sprintf('"%s"', addcslashes('import-configuration-' . date('Y-m-d') . '.json', '"\\'));
/** @var LaravelResponse $response */
$response = response($result, 200);
$response->header('Content-disposition', 'attachment; filename=' . $name)
diff --git a/app/Models/RuleAction.php b/app/Models/RuleAction.php
index 7ca38fcc39..6bad677108 100644
--- a/app/Models/RuleAction.php
+++ b/app/Models/RuleAction.php
@@ -36,6 +36,7 @@ use Illuminate\Database\Eloquent\Model;
* @property int $order
* @property bool $active
* @property bool $stop_processing
+ * @property Rule $rule
*/
class RuleAction extends Model
{
diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php
index 30f49cdf85..e6be30af6a 100644
--- a/app/Models/TransactionJournal.php
+++ b/app/Models/TransactionJournal.php
@@ -45,6 +45,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property Collection $categories
* @property bool $completed
* @property string $description
+ * @property string $transaction_type_id
*/
class TransactionJournal extends Model
{
diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php
index 4dc900bb95..f3397e1d6b 100644
--- a/app/Repositories/Journal/JournalRepository.php
+++ b/app/Repositories/Journal/JournalRepository.php
@@ -101,6 +101,11 @@ class JournalRepository implements JournalRepositoryInterface
$transaction->budgets()->detach();
}
}
+ // if journal is not a withdrawal, remove the bill ID.
+ if (TransactionType::WITHDRAWAL !== $type->type) {
+ $journal->bill_id = null;
+ $journal->save();
+ }
Preferences::mark();
diff --git a/app/Support/Import/Routine/File/ImportableConverter.php b/app/Support/Import/Routine/File/ImportableConverter.php
index 16e8f5b1d8..bb851e24e4 100644
--- a/app/Support/Import/Routine/File/ImportableConverter.php
+++ b/app/Support/Import/Routine/File/ImportableConverter.php
@@ -185,8 +185,15 @@ class ImportableConverter
Log::debug(sprintf('"%s" (#%d) is source and "%s" (#%d) is destination.', $source->name, $source->id, $destination->name, $destination->id));
- if (bccomp($amount, '0') === 1) {
- // amount is positive? Then switch:
+
+ if ($source->accountType->type === AccountType::ASSET && $destination->accountType->type === AccountType::ASSET) {
+ Log::debug('Source and destination are asset accounts. This is a transfer.');
+ $transactionType = 'transfer';
+ }
+
+ // amount is positive and its not a transfer? Then switch:
+ if ($transactionType !== 'transfer' && bccomp($amount, '0') === 1) {
+
[$destination, $source] = [$source, $destination];
Log::debug(
sprintf(
@@ -195,6 +202,17 @@ class ImportableConverter
)
);
}
+ // amount is negative and type is transfer? then switch.
+ if ($transactionType === 'transfer' && bccomp($amount, '0') === -1) {
+ // amount is positive? Then switch:
+ [$destination, $source] = [$source, $destination];
+ Log::debug(
+ sprintf(
+ '%s is negative, so "%s" (#%d) is now source and "%s" (#%d) is now destination.',
+ $amount, $source->name, $source->id, $destination->name, $destination->id
+ )
+ );
+ }
// get currency preference from source asset account (preferred)
// or destination asset account
@@ -218,10 +236,7 @@ class ImportableConverter
$currency = $this->defaultCurrency;
}
- if ($source->accountType->type === AccountType::ASSET && $destination->accountType->type === AccountType::ASSET) {
- Log::debug('Source and destination are asset accounts. This is a transfer.');
- $transactionType = 'transfer';
- }
+
if ($source->accountType->type === AccountType::REVENUE) {
Log::debug('Source is a revenue account. This is a deposit.');
$transactionType = 'deposit';
diff --git a/resources/lang/en_US/validation.php b/resources/lang/en_US/validation.php
index 6040f20399..b573da5844 100644
--- a/resources/lang/en_US/validation.php
+++ b/resources/lang/en_US/validation.php
@@ -46,8 +46,8 @@ return [
'belongs_to_user' => 'The value of :attribute is unknown.',
'accepted' => 'The :attribute must be accepted.',
'bic' => 'This is not a valid BIC.',
- 'at_least_one_trigger' => 'Rule must have at least one trigger',
- 'at_least_one_action' => 'Rule must have at least one action',
+ 'at_least_one_trigger' => 'Rule must have at least one trigger.',
+ 'at_least_one_action' => 'Rule must have at least one action.',
'base64' => 'This is not valid base64 encoded data.',
'model_id_invalid' => 'The given ID seems invalid for this model.',
'more' => ':attribute must be larger than zero.',