Code cleanup and new translations.

This commit is contained in:
James Cole
2024-01-04 15:42:00 +01:00
parent 1873be8d95
commit 0a5d62605a
113 changed files with 7797 additions and 7504 deletions

View File

@@ -128,7 +128,7 @@ class Handler extends ExceptionHandler
$errorCode = 500;
$errorCode = $e instanceof MethodNotAllowedHttpException ? 405 : $errorCode;
$isDebug = (bool) config('app.debug', false);
$isDebug = (bool) config('app.debug', false);
if ($isDebug) {
app('log')->debug(sprintf('Return JSON %s with debug.', get_class($e)));
@@ -191,7 +191,7 @@ class Handler extends ExceptionHandler
return;
}
$userData = [
$userData = [
'id' => 0,
'email' => 'unknown@example.com',
];
@@ -200,9 +200,9 @@ class Handler extends ExceptionHandler
$userData['email'] = auth()->user()->email;
}
$headers = request()->headers->all();
$headers = request()->headers->all();
$data = [
$data = [
'class' => get_class($e),
'errorMessage' => $e->getMessage(),
'time' => date('r'),
@@ -220,8 +220,8 @@ class Handler extends ExceptionHandler
];
// create job that will mail.
$ipAddress = request()->ip() ?? '0.0.0.0';
$job = new MailError($userData, (string) config('firefly.site_owner'), $ipAddress, $data);
$ipAddress = request()->ip() ?? '0.0.0.0';
$job = new MailError($userData, (string) config('firefly.site_owner'), $ipAddress, $data);
dispatch($job);
parent::report($e);
@@ -232,7 +232,7 @@ class Handler extends ExceptionHandler
*
* @param Request $request
*/
protected function invalid($request, LaravelValidationException $exception): \Illuminate\Http\Response | JsonResponse | RedirectResponse
protected function invalid($request, LaravelValidationException $exception): \Illuminate\Http\Response|JsonResponse|RedirectResponse
{
// protect against open redirect when submitting invalid forms.
$previous = app('steam')->getSafePreviousUrl();
@@ -240,17 +240,18 @@ class Handler extends ExceptionHandler
return redirect($redirect ?? $previous)
->withInput(Arr::except($request->input(), $this->dontFlash))
->withErrors($exception->errors(), $request->input('_error_bag', $exception->errorBag));
->withErrors($exception->errors(), $request->input('_error_bag', $exception->errorBag))
;
}
private function shouldntReportLocal(\Throwable $e): bool
{
return null !== Arr::first(
$this->dontReport,
static function ($type) use ($e) {
return $e instanceof $type;
}
);
$this->dontReport,
static function ($type) use ($e) {
return $e instanceof $type;
}
);
}
/**

View File

@@ -50,6 +50,7 @@ use Illuminate\Support\Collection;
/**
* Class TransactionJournalFactory
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class TransactionJournalFactory
{

View File

@@ -118,17 +118,18 @@ class CreateController extends Controller
$parts = parse_url($previousUrl);
$search = sprintf('?%s', $parts['query'] ?? '');
$previousUrl = str_replace($search, '', $previousUrl);
if(!is_array($optionalFields)) {
$optionalFields = [];
}
// not really a fan of this, but meh.
$optionalDateFields = [
'interest_date' => $optionalFields['interest_date'],
'book_date' => $optionalFields['book_date'],
'process_date' => $optionalFields['process_date'],
'due_date' => $optionalFields['due_date'],
'payment_date' => $optionalFields['payment_date'],
'invoice_date' => $optionalFields['invoice_date'],
'interest_date' => $optionalFields['interest_date'] ?? false,
'book_date' => $optionalFields['book_date'] ?? false,
'process_date' => $optionalFields['process_date'] ?? false,
'due_date' => $optionalFields['due_date'] ?? false,
'payment_date' => $optionalFields['payment_date'] ?? false,
'invoice_date' => $optionalFields['invoice_date'] ?? false,
];
// var_dump($optionalFields);
// exit;
$optionalFields['external_url'] ??= false;
$optionalFields['location'] ??= false;
session()->put('preFilled', $preFilled);

View File

@@ -25,6 +25,7 @@ class IsValidAmount implements ValidationRule
$message = sprintf('IsValidAmount: "%s" cannot be empty.', $value);
Log::debug($message);
Log::channel('audit')->info($message);
return;
}
@@ -34,6 +35,7 @@ class IsValidAmount implements ValidationRule
$message = sprintf('IsValidAmount: "%s" is not a number.', $value);
Log::debug($message);
Log::channel('audit')->info($message);
return;
}
@@ -43,16 +45,18 @@ class IsValidAmount implements ValidationRule
$message = sprintf('IsValidAmount: "%s" cannot be in the scientific notation.', $value);
Log::debug($message);
Log::channel('audit')->info($message);
return;
}
// must be more than minus a lots:
if($this->lessThanLots($value)) {
$amount = bcmul('-1', self::BIG_AMOUNT);
$amount = bcmul('-1', self::BIG_AMOUNT);
$fail('validation.gte.numeric')->translate(['value' => $amount]);
$message = sprintf('IsValidAmount: "%s" must be more than %s.', $value, $amount);
Log::debug($message);
Log::channel('audit')->info($message);
return;
}

View File

@@ -24,6 +24,7 @@ class IsValidPositiveAmount implements ValidationRule
$message = sprintf('IsValidPositiveAmount: "%s" cannot be empty.', $value);
Log::debug($message);
Log::channel('audit')->info($message);
return;
}
@@ -33,6 +34,7 @@ class IsValidPositiveAmount implements ValidationRule
$message = sprintf('IsValidPositiveAmount: "%s" is not a number.', $value);
Log::debug($message);
Log::channel('audit')->info($message);
return;
}
// must not be scientific notation:
@@ -41,6 +43,7 @@ class IsValidPositiveAmount implements ValidationRule
$message = sprintf('IsValidPositiveAmount: "%s" cannot be in the scientific notation.', $value);
Log::debug($message);
Log::channel('audit')->info($message);
return;
}
// must be more than zero:
@@ -49,6 +52,7 @@ class IsValidPositiveAmount implements ValidationRule
$message = sprintf('IsValidPositiveAmount: "%s" must be more than zero.', $value);
Log::debug($message);
Log::channel('audit')->info($message);
return;
}
// must be less than 100 million and 1709:

View File

@@ -24,6 +24,7 @@ class IsValidZeroOrMoreAmount implements ValidationRule
$message = sprintf('IsValidZeroOrMoreAmount: "%s" cannot be empty.', $value);
Log::debug($message);
Log::channel('audit')->info($message);
return;
}
@@ -33,6 +34,7 @@ class IsValidZeroOrMoreAmount implements ValidationRule
$message = sprintf('IsValidZeroOrMoreAmount: "%s" is not a number.', $value);
Log::debug($message);
Log::channel('audit')->info($message);
return;
}
// must not be scientific notation:
@@ -41,6 +43,7 @@ class IsValidZeroOrMoreAmount implements ValidationRule
$message = sprintf('IsValidZeroOrMoreAmount: "%s" cannot be in the scientific notation.', $value);
Log::debug($message);
Log::channel('audit')->info($message);
return;
}
// must be zero or more
@@ -49,6 +52,7 @@ class IsValidZeroOrMoreAmount implements ValidationRule
$message = sprintf('IsValidZeroOrMoreAmount: "%s" must be zero or more.', $value);
Log::debug($message);
Log::channel('audit')->info($message);
return;
}
// must be less than 100 million and 1709:

View File

@@ -46,10 +46,10 @@ class TransactionGroupTransformer extends AbstractTransformer
private ExchangeRateConverter $converter;
private array $currencies = [];
private TransactionCurrency $default;
private array $meta = [];
private array $notes = [];
private array $locations = [];
private array $tags = [];
private array $meta = [];
private array $notes = [];
private array $locations = [];
private array $tags = [];
public function collectMetaData(Collection $objects): void
{

View File

@@ -53,11 +53,8 @@ trait CurrencyValidation
if (!array_key_exists('foreign_amount', $transaction)) {
continue;
}
$foreignAmount = '';
if (array_key_exists('foreign_amount', $transaction)) {
$foreignAmount = (string) $transaction['foreign_amount'];
}
if('' === $foreignAmount) {
$foreignAmount = (string) $transaction['foreign_amount'];
if ('' === $foreignAmount) {
continue;
}
// if foreign amount is present, then the currency must be as well.
@@ -65,15 +62,8 @@ trait CurrencyValidation
$validator->errors()->add('transactions.'.$index.'.foreign_amount', (string) trans('validation.require_currency_info'));
}
// if the currency is present, then the amount must be present as well.
if ((array_key_exists('foreign_currency_id', $transaction) || array_key_exists('foreign_currency_code', $transaction))
&& !array_key_exists(
'foreign_amount',
$transaction
)) {
$validator->errors()->add(
'transactions.'.$index.'.foreign_amount',
(string) trans('validation.require_currency_amount')
);
if (array_key_exists('foreign_currency_id', $transaction) || array_key_exists('foreign_currency_code', $transaction)) {
$validator->errors()->add('transactions.'.$index.'.foreign_amount', (string) trans('validation.require_currency_amount'));
}
}
}