mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Merge pull request #10196 from turbo124/v5-develop
Updates for client props
This commit is contained in:
commit
bfd8f4e98e
@ -265,15 +265,45 @@ class BaseModel extends Model
|
||||
{
|
||||
$number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
|
||||
|
||||
$formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $number);
|
||||
// Remove control characters
|
||||
$formatted_number = preg_replace('/[\x00-\x1F\x7F]/u', '', $number);
|
||||
|
||||
$formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number);
|
||||
// Replace slash, backslash, and null byte with underscore
|
||||
$formatted_number = str_replace(['/', '\\', "\0"], '_', $formatted_number);
|
||||
|
||||
$formatted_number = preg_replace('/\s+/', '_', $formatted_number);
|
||||
// Remove any other characters that are invalid in most filesystems
|
||||
$formatted_number = str_replace(['<', '>', ':', '"', '|', '?', '*'], '', $formatted_number);
|
||||
|
||||
return \Illuminate\Support\Str::ascii($formatted_number);
|
||||
// Replace multiple spaces or underscores with a single underscore
|
||||
$formatted_number = preg_replace('/[\s_]+/', '_', $formatted_number);
|
||||
|
||||
// Trim underscores from start and end
|
||||
$formatted_number = trim($formatted_number, '_');
|
||||
|
||||
// Ensure the filename is not empty
|
||||
if (empty($formatted_number)) {
|
||||
$formatted_number = 'file_' . Str::random(5);
|
||||
}
|
||||
|
||||
// Limit the length of the filename (adjust as needed)
|
||||
$formatted_number = mb_substr($formatted_number, 0, 255);
|
||||
|
||||
return $formatted_number;
|
||||
}
|
||||
|
||||
// public function numberFormatter()
|
||||
// {
|
||||
// $number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
|
||||
|
||||
// $formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $number);
|
||||
|
||||
// $formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number);
|
||||
|
||||
// $formatted_number = preg_replace('/\s+/', '_', $formatted_number);
|
||||
|
||||
// return \Illuminate\Support\Str::ascii($formatted_number);
|
||||
// }
|
||||
|
||||
public function translate_entity()
|
||||
{
|
||||
return ctrans('texts.item');
|
||||
|
@ -399,23 +399,32 @@ class BaseRepository
|
||||
if(in_array($column, ['tax1','tax2','tax3'])) {
|
||||
|
||||
$parts = explode("||", $new_value);
|
||||
|
||||
if (count($parts) !== 2)
|
||||
return;
|
||||
|
||||
$tax_name_column = str_replace("tax", "tax_name", $column);
|
||||
$rate = filter_var($parts[1], FILTER_VALIDATE_FLOAT);
|
||||
$tax_name = $parts[0];
|
||||
|
||||
if ($rate === false)
|
||||
return;
|
||||
|
||||
$taxrate_column = str_replace("tax", "tax_rate", $column);
|
||||
$tax_rate_column = str_replace("tax", "tax_rate", $column);
|
||||
|
||||
/** Harvest the tax name and rate */
|
||||
if (count($parts) == 2)
|
||||
{
|
||||
|
||||
$rate = filter_var($parts[1], FILTER_VALIDATE_FLOAT);
|
||||
$tax_name = $parts[0];
|
||||
|
||||
if ($rate === false)
|
||||
return;
|
||||
|
||||
}
|
||||
else { //else we need to clear the value
|
||||
|
||||
$rate = 0;
|
||||
$tax_name = "";
|
||||
|
||||
}
|
||||
|
||||
$model->update([
|
||||
$tax_name_column => $tax_name,
|
||||
$taxrate_column => $rate,
|
||||
$tax_rate_column => $rate,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -934,6 +934,8 @@ class TemplateService
|
||||
'balance' => $entity->client->balance,
|
||||
'payment_balance' => $entity->client->payment_balance,
|
||||
'credit_balance' => $entity->client->credit_balance,
|
||||
'number' => $entity->client->number ?? '',
|
||||
'id_number' => $entity->client->id_number ?? '',
|
||||
'vat_number' => $entity->client->vat_number ?? '',
|
||||
'currency' => $entity->client->currency()->code ?? 'USD',
|
||||
'custom_value1' => $entity->client->custom_value1 ?? '',
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Requests\EInvoice\Peppol;
|
||||
namespace Tests\Feature\EInvoice\Validation;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
Loading…
Reference in New Issue
Block a user