Some last-minute fixes.

This commit is contained in:
James Cole 2018-07-03 17:48:26 +02:00
parent 53addcf99a
commit 18b06ff283
7 changed files with 50 additions and 12 deletions

View File

@ -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.
*/

View File

@ -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)

View File

@ -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
{

View File

@ -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
{

View File

@ -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();

View File

@ -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';

View File

@ -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.',