Refactor old methods.

This commit is contained in:
James Cole
2021-04-06 13:30:09 +02:00
parent 5ceef2e9c3
commit 69b1769f22
54 changed files with 191 additions and 478 deletions

View File

@@ -73,7 +73,7 @@ class StoreRequest extends FormRequest
'opening_balance_date' => $this->date('opening_balance_date'),
'cc_type' => $this->string('credit_card_type'),
'cc_monthly_payment_date' => $this->string('monthly_payment_date'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
'interest' => $this->string('interest'),
'interest_period' => $this->string('interest_period'),
];

View File

@@ -62,7 +62,7 @@ class UpdateRequest extends FormRequest
'opening_balance_date' => ['opening_balance_date', 'date'],
'cc_type' => ['credit_card_type', 'string'],
'cc_monthly_payment_date' => ['monthly_payment_date', 'string'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
'interest' => ['interest', 'string'],
'interest_period' => ['interest_period', 'string'],
'order' => ['order', 'integer'],
@@ -73,9 +73,9 @@ class UpdateRequest extends FormRequest
$data = $this->appendLocationData($data, null);
if (array_key_exists('account_type_name', $data) && 'liability' === $data['account_type_name']) {
$data['opening_balance'] = bcmul($this->nullableString('liability_amount'), '-1');
$data['opening_balance'] = bcmul($this->string('liability_amount'), '-1');
$data['opening_balance_date'] = $this->date('liability_start_date');
$data['account_type_name'] = $this->nullableString('liability_type');
$data['account_type_name'] = $this->string('liability_type');
$data['account_type_id'] = null;
}
@@ -97,9 +97,9 @@ class UpdateRequest extends FormRequest
$rules = [
'name' => sprintf('min:1|uniqueAccountForUser:%d', $account->id),
'type' => sprintf('in:%s', $types),
'iban' => ['iban', 'nullable', new UniqueIban($account, $this->nullableString('type'))],
'iban' => ['iban', 'nullable', new UniqueIban($account, $this->string('type'))],
'bic' => 'bic|nullable',
'account_number' => ['between:1,255', 'nullable', new UniqueAccountNumber($account, $this->nullableString('type'))],
'account_number' => ['between:1,255', 'nullable', new UniqueAccountNumber($account, $this->string('type'))],
'opening_balance' => 'numeric|required_with:opening_balance_date|nullable',
'opening_balance_date' => 'date|required_with:opening_balance|nullable',
'virtual_balance' => 'numeric|nullable',

View File

@@ -47,7 +47,7 @@ class StoreRequest extends FormRequest
return [
'filename' => $this->string('filename'),
'title' => $this->string('title'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
'attachable_type' => $this->string('attachable_type'),
'attachable_id' => $this->integer('attachable_id'),
];

View File

@@ -47,7 +47,7 @@ class UpdateRequest extends FormRequest
$fields = [
'filename' => ['filename', 'string'],
'title' => ['title', 'string'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
'attachable_type' => ['attachable_type', 'string'],
'attachable_id' => ['attachable_id', 'integer'],
];

View File

@@ -59,7 +59,7 @@ class StoreRequest extends FormRequest
'skip' => ['skip', 'integer'],
'active' => ['active', 'boolean'],
'order' => ['order', 'integer'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
'object_group_id' => ['object_group_id', 'integer'],
'object_group_title' => ['object_group_title', 'string'],
];

View File

@@ -57,7 +57,7 @@ class UpdateRequest extends FormRequest
'skip' => ['skip', 'integer'],
'active' => ['active', 'boolean'],
'order' => ['order', 'integer'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
'object_group_id' => ['object_group_id', 'integer'],
'object_group_title' => ['object_group_title', 'string'],
];

View File

@@ -46,7 +46,7 @@ class StoreRequest extends FormRequest
{
return [
'name' => $this->string('name'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
];
}

View File

@@ -45,7 +45,7 @@ class UpdateRequest extends FormRequest
{
$fields = [
'name' => ['name', 'string'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
];
return $this->getAllData($fields);

View File

@@ -53,7 +53,7 @@ class StoreRequest extends FormRequest
$data['current_amount'] = $this->string('current_amount');
$data['startdate'] = $this->date('start_date');
$data['targetdate'] = $this->date('target_date');
$data['notes'] = $this->nlString('notes');
$data['notes'] = $this->stringWithNewlines('notes');
$data['object_group_id'] = $this->integer('object_group_id');
$data['object_group_title'] = $this->string('object_group_title');

View File

@@ -52,7 +52,7 @@ class UpdateRequest extends FormRequest
'current_amount' => ['current_amount', 'string'],
'startdate' => ['start_date', 'date'],
'targetdate' => ['target_date', 'string'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
'order' => ['order', 'integer'],
'object_group_title' => ['object_group_title', 'string'],
'object_group_id' => ['object_group_id', 'integer'],

View File

@@ -58,7 +58,7 @@ class StoreRequest extends FormRequest
'nr_of_repetitions' => ['nr_of_repetitions', 'integer'],
'apply_rules' => ['apply_rules', 'boolean'],
'active' => ['active', 'boolean'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
];
$recurrence = $this->getAllData($fields);

View File

@@ -47,7 +47,7 @@ class UpdateRequest extends FormRequest
{
$fields = [
'title' => ['title', 'string'],
'description' => ['description', 'nlString'],
'description' => ['description', 'stringWithNewlines'],
'rule_group_id' => ['rule_group_id', 'integer'],
'trigger' => ['trigger', 'string'],
'strict' => ['strict', 'boolean'],

View File

@@ -46,7 +46,7 @@ class UpdateRequest extends FormRequest
// This is the way.
$fields = [
'title' => ['title', 'string'],
'description' => ['description', 'nlString'],
'description' => ['description', 'stringWithNewlines'],
'active' => ['active', 'boolean'],
'order' => ['order', 'integer'],
];

View File

@@ -78,75 +78,75 @@ class StoreRequest extends FormRequest
foreach ($this->get('transactions') as $transaction) {
$object = new NullArrayObject($transaction);
$return[] = [
'type' => $this->stringFromValue($object['type']),
'type' => $this->clearString($object['type'], false),
'date' => $this->dateFromValue($object['date']),
'order' => $this->integerFromValue((string)$object['order']),
'currency_id' => $this->integerFromValue((string)$object['currency_id']),
'currency_code' => $this->stringFromValue($object['currency_code']),
'currency_code' => $this->clearString($object['currency_code'], false),
// foreign currency info:
'foreign_currency_id' => $this->integerFromValue((string)$object['foreign_currency_id']),
'foreign_currency_code' => $this->stringFromValue((string)$object['foreign_currency_code']),
'foreign_currency_code' => $this->clearString((string)$object['foreign_currency_code'], false),
// amount and foreign amount. Cannot be 0.
'amount' => $this->stringFromValue((string)$object['amount']),
'foreign_amount' => $this->stringFromValue((string)$object['foreign_amount']),
'amount' => $this->clearString((string)$object['amount'], false),
'foreign_amount' => $this->clearString((string)$object['foreign_amount'], false),
// description.
'description' => $this->stringFromValue($object['description']),
'description' => $this->clearString($object['description'], false),
// source of transaction. If everything is null, assume cash account.
'source_id' => $this->integerFromValue((string)$object['source_id']),
'source_name' => $this->stringFromValue((string)$object['source_name']),
'source_iban' => $this->stringFromValue((string)$object['source_iban']),
'source_number' => $this->stringFromValue((string)$object['source_number']),
'source_bic' => $this->stringFromValue((string)$object['source_bic']),
'source_name' => $this->clearString((string)$object['source_name'], false),
'source_iban' => $this->clearString((string)$object['source_iban'], false),
'source_number' => $this->clearString((string)$object['source_number'], false),
'source_bic' => $this->clearString((string)$object['source_bic'], false),
// destination of transaction. If everything is null, assume cash account.
'destination_id' => $this->integerFromValue((string)$object['destination_id']),
'destination_name' => $this->stringFromValue((string)$object['destination_name']),
'destination_iban' => $this->stringFromValue((string)$object['destination_iban']),
'destination_number' => $this->stringFromValue((string)$object['destination_number']),
'destination_bic' => $this->stringFromValue((string)$object['destination_bic']),
'destination_name' => $this->clearString((string)$object['destination_name'], false),
'destination_iban' => $this->clearString((string)$object['destination_iban'], false),
'destination_number' => $this->clearString((string)$object['destination_number'], false),
'destination_bic' => $this->clearString((string)$object['destination_bic'], false),
// budget info
'budget_id' => $this->integerFromValue((string)$object['budget_id']),
'budget_name' => $this->stringFromValue((string)$object['budget_name']),
'budget_name' => $this->clearString((string)$object['budget_name'], false),
// category info
'category_id' => $this->integerFromValue((string)$object['category_id']),
'category_name' => $this->stringFromValue((string)$object['category_name']),
'category_name' => $this->clearString((string)$object['category_name'], false),
// journal bill reference. Optional. Will only work for withdrawals
'bill_id' => $this->integerFromValue((string)$object['bill_id']),
'bill_name' => $this->stringFromValue((string)$object['bill_name']),
'bill_name' => $this->clearString((string)$object['bill_name'], false),
// piggy bank reference. Optional. Will only work for transfers
'piggy_bank_id' => $this->integerFromValue((string)$object['piggy_bank_id']),
'piggy_bank_name' => $this->stringFromValue((string)$object['piggy_bank_name']),
'piggy_bank_name' => $this->clearString((string)$object['piggy_bank_name'], false),
// some other interesting properties
'reconciled' => $this->convertBoolean((string)$object['reconciled']),
'notes' => $this->nlStringFromValue((string)$object['notes']),
'notes' => $this->clearString((string)$object['notes']),
'tags' => $this->arrayFromValue($object['tags']),
// all custom fields:
'internal_reference' => $this->stringFromValue((string)$object['internal_reference']),
'external_id' => $this->stringFromValue((string)$object['external_id']),
'internal_reference' => $this->clearString((string)$object['internal_reference'],false),
'external_id' => $this->clearString((string)$object['external_id'], false),
'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
'recurrence_id' => $this->integerFromValue($object['recurrence_id']),
'bunq_payment_id' => $this->stringFromValue((string)$object['bunq_payment_id']),
'external_uri' => $this->stringFromValue((string)$object['external_uri']),
'bunq_payment_id' => $this->clearString((string)$object['bunq_payment_id'],false),
'external_uri' => $this->clearString((string)$object['external_uri'], false),
'sepa_cc' => $this->stringFromValue($object['sepa_cc']),
'sepa_ct_op' => $this->stringFromValue($object['sepa_ct_op']),
'sepa_ct_id' => $this->stringFromValue($object['sepa_ct_id']),
'sepa_db' => $this->stringFromValue($object['sepa_db']),
'sepa_country' => $this->stringFromValue($object['sepa_country']),
'sepa_ep' => $this->stringFromValue($object['sepa_ep']),
'sepa_ci' => $this->stringFromValue($object['sepa_ci']),
'sepa_batch_id' => $this->stringFromValue($object['sepa_batch_id']),
'sepa_cc' => $this->clearString($object['sepa_cc'],false),
'sepa_ct_op' => $this->clearString($object['sepa_ct_op'],false),
'sepa_ct_id' => $this->clearString($object['sepa_ct_id'],false),
'sepa_db' => $this->clearString($object['sepa_db'],false),
'sepa_country' => $this->clearString($object['sepa_country'],false),
'sepa_ep' => $this->clearString($object['sepa_ep'],false),
'sepa_ci' => $this->clearString($object['sepa_ci'],false),
'sepa_batch_id' => $this->clearString($object['sepa_batch_id'],false),
// custom date fields. Must be Carbon objects. Presence is optional.
'interest_date' => $this->dateFromValue($object['interest_date']),
'book_date' => $this->dateFromValue($object['book_date']),

View File

@@ -194,7 +194,7 @@ class UpdateRequest extends FormRequest
{
foreach ($this->stringFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->stringFromValue((string)$transaction[$fieldName]);
$current[$fieldName] = $this->clearString((string)$transaction[$fieldName], false);
}
}
@@ -211,7 +211,7 @@ class UpdateRequest extends FormRequest
{
foreach ($this->textareaFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->nlStringFromValue((string)$transaction[$fieldName]);
$current[$fieldName] = $this->clearString((string)$transaction[$fieldName]);
}
}

View File

@@ -50,7 +50,7 @@ class StoreRequest extends FormRequest
'link_type_name' => $this->string('link_type_name'),
'inward_id' => $this->integer('inward_id'),
'outward_id' => $this->integer('outward_id'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
];
}

View File

@@ -50,7 +50,7 @@ class UpdateRequest extends FormRequest
'link_type_name' => $this->string('link_type_name'),
'inward_id' => $this->integer('inward_id'),
'outward_id' => $this->integer('outward_id'),
'notes' => $this->nullableNlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
];
}