Various code cleanup.

This commit is contained in:
James Cole
2018-08-04 17:30:06 +02:00
parent 5af026674f
commit f0d3ca5d53
88 changed files with 552 additions and 311 deletions

View File

@@ -48,7 +48,7 @@ class AccountFormRequest extends Request
*/
public function getAccountData(): array
{
return [
$data = [
'name' => $this->string('name'),
'active' => $this->boolean('active'),
'accountType' => $this->string('what'),
@@ -64,7 +64,22 @@ class AccountFormRequest extends Request
'ccType' => $this->string('ccType'),
'ccMonthlyPaymentDate' => $this->string('ccMonthlyPaymentDate'),
'notes' => $this->string('notes'),
'interest' => $this->string('interest'),
'interest_period' => $this->string('interest_period'),
];
// if the account type is "liabilities" there are actually four types of liability
// that could have been selected.
if ($data['accountType'] === 'liabilities') {
$data['accountType'] = null;
$data['account_type_id'] = $this->integer('liability_type_id');
// also reverse the opening balance:
if ('' !== $data['openingBalance']) {
$data['openingBalance'] = bcmul($data['openingBalance'], '-1');
}
}
return $data;
}
/**
@@ -93,8 +108,14 @@ class AccountFormRequest extends Request
'amount_currency_id_openingBalance' => 'exists:transaction_currencies,id',
'amount_currency_id_virtualBalance' => 'exists:transaction_currencies,id',
'what' => 'in:' . $types,
'interest_period' => 'in:daily,monthly,yearly',
];
if ('liabilities' === $this->get('what')) {
$rules['openingBalance'] = 'numeric|required|more:0';
$rules['openingBalanceDate'] = 'date|required';
}
/** @var Account $account */
$account = $this->route()->parameter('account');
if (null !== $account) {

View File

@@ -50,7 +50,7 @@ class ExportFormRequest extends Request
/** @var Carbon $sessionFirst */
$sessionFirst = clone session('first');
$first = $sessionFirst->subDay()->format('Y-m-d');
$today = Carbon::create()->addDay()->format('Y-m-d');
$today = Carbon::now()->addDay()->format('Y-m-d');
$formats = implode(',', array_keys(config('firefly.export_formats')));
// fixed

View File

@@ -149,7 +149,7 @@ class RecurrenceFormRequest extends Request
public function rules(): array
{
$today = new Carbon;
$tomorrow = Carbon::create()->addDay();
$tomorrow = Carbon::now()->addDay();
$rules = [
// mandatory info for recurrence.
'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title',

View File

@@ -53,7 +53,7 @@ class SelectTransactionsRequest extends Request
/** @var Carbon $sessionFirst */
$sessionFirst = clone session('first');
$first = $sessionFirst->subDay()->format('Y-m-d');
$today = Carbon::create()->addDay()->format('Y-m-d');
$today = Carbon::now()->addDay()->format('Y-m-d');
return [
'start_date' => 'required|date|after:' . $first,