mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-06 04:34:00 +00:00
This commit is contained in:
@@ -43,6 +43,15 @@ class TransactionCurrencyFactory
|
|||||||
*/
|
*/
|
||||||
public function create(array $data): TransactionCurrency
|
public function create(array $data): TransactionCurrency
|
||||||
{
|
{
|
||||||
|
// if the code already exists (deleted)
|
||||||
|
// force delete it and then create the transaction:
|
||||||
|
$count = TransactionCurrency::withTrashed()->whereCode($data['code'])->count();
|
||||||
|
if(1 === $count) {
|
||||||
|
$old = TransactionCurrency::withTrashed()->whereCode($data['code'])->first();
|
||||||
|
$old->forceDelete();
|
||||||
|
Log::warning(sprintf('Force deleted old currency with ID #%d and code "%s".', $old->id, $data['code']));
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/** @var TransactionCurrency $result */
|
/** @var TransactionCurrency $result */
|
||||||
$result = TransactionCurrency::create(
|
$result = TransactionCurrency::create(
|
||||||
|
@@ -59,9 +59,9 @@ class CurrencyFormRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
// fixed
|
// fixed
|
||||||
$rules = [
|
$rules = [
|
||||||
'name' => 'required|max:48|min:1|unique:transaction_currencies,name',
|
'name' => 'required|max:48|min:1|uniqueCurrencyName',
|
||||||
'code' => 'required|min:3|max:51|unique:transaction_currencies,code',
|
'code' => 'required|min:3|max:51|uniqueCurrencyCode',
|
||||||
'symbol' => 'required|min:1|max:51|unique:transaction_currencies,symbol',
|
'symbol' => 'required|min:1|max:51|uniqueCurrencySymbol',
|
||||||
'decimal_places' => 'required|min:0|max:12|numeric',
|
'decimal_places' => 'required|min:0|max:12|numeric',
|
||||||
'enabled' => 'in:0,1',
|
'enabled' => 'in:0,1',
|
||||||
];
|
];
|
||||||
|
@@ -53,6 +53,48 @@ use function is_string;
|
|||||||
*/
|
*/
|
||||||
class FireflyValidator extends Validator
|
class FireflyValidator extends Validator
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $attribute
|
||||||
|
* @param $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validateUniqueCurrencyName($attribute, $value): bool
|
||||||
|
{
|
||||||
|
return $this->validateUniqueCurrency('name', (string) $attribute, (string) $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $attribute
|
||||||
|
* @param $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validateUniqueCurrencyCode($attribute, $value): bool
|
||||||
|
{
|
||||||
|
return $this->validateUniqueCurrency('code', (string) $attribute, (string) $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $attribute
|
||||||
|
* @param $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validateUniqueCurrencySymbol($attribute, $value): bool
|
||||||
|
{
|
||||||
|
return $this->validateUniqueCurrency('symbol', (string) $attribute, (string) $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $attribute
|
||||||
|
* @param $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validateUniqueCurrency(string $field, string $attribute, string $value): bool
|
||||||
|
{
|
||||||
|
return 0 === DB::table('transaction_currencies')->where($field, $value)->whereNull('deleted_at')->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
|
Reference in New Issue
Block a user