diff --git a/app/Http/Controllers/Bo/TicketController.php b/app/Http/Controllers/Bo/TicketController.php index a7be411..4295d11 100644 --- a/app/Http/Controllers/Bo/TicketController.php +++ b/app/Http/Controllers/Bo/TicketController.php @@ -178,8 +178,8 @@ class TicketController extends Controller $ticket = new Ticket($request->validated()); - /** @var null|array<\Illuminate\Http\UploadedFile> */ - $fileTickets = $request->file_tickets; + /** @var array<\Illuminate\Http\UploadedFile> */ + $fileTickets = $request->file_tickets ?? []; if (count($fileTickets) > 0) { foreach ($fileTickets as $key => $file) { if ($key === 0) { @@ -544,8 +544,13 @@ class TicketController extends Controller Session::has('tickets.sort_col') and Session::has('tickets.sort_way') and in_array(Session::get('tickets.sort_col'), [ - 'id', 'site_id', 'created_at', 'created_by', - 'type', 'status', 'assigned_to' + 'id', + 'site_id', + 'created_at', + 'created_by', + 'type', + 'status', + 'assigned_to' ]) ) { $tickets->orderBy( @@ -653,30 +658,32 @@ class TicketController extends Controller }; try { - if (!\is_null($ticket->file)) { - $uploadedFile = GitLab::projects()->uploadFile($gitlabRepoId, $ticket->file); - $description .= $this->formatGitlabFiles($ticket, $uploadedFile, 1); + foreach ($ticket->getFiles() as $key => $file) { + if (!\is_null($file)) { + $uploadedFile = GitLab::projects()->uploadFile($gitlabRepoId, $file); + $description .= $this->formatGitlabFiles($ticket, $uploadedFile, $key + 1); + } } - if (!\is_null($ticket->file2)) { - $uploadedFile2 = GitLab::projects()->uploadFile($gitlabRepoId, $ticket->file2); - $description .= $this->formatGitlabFiles($ticket, $uploadedFile2, 2); - } + // if (!\is_null($ticket->file2)) { + // $uploadedFile2 = GitLab::projects()->uploadFile($gitlabRepoId, $ticket->file2); + // $description .= $this->formatGitlabFiles($ticket, $uploadedFile2, 2); + // } - if (!\is_null($ticket->file3)) { - $uploadedFile3 = GitLab::projects()->uploadFile($gitlabRepoId, $ticket->file3); - $description .= $this->formatGitlabFiles($ticket, $uploadedFile3, 3); - } + // if (!\is_null($ticket->file3)) { + // $uploadedFile3 = GitLab::projects()->uploadFile($gitlabRepoId, $ticket->file3); + // $description .= $this->formatGitlabFiles($ticket, $uploadedFile3, 3); + // } - if (!\is_null($ticket->file4)) { - $uploadedFile4 = GitLab::projects()->uploadFile($gitlabRepoId, $ticket->file4); - $description .= $this->formatGitlabFiles($ticket, $uploadedFile4, 4); - } + // if (!\is_null($ticket->file4)) { + // $uploadedFile4 = GitLab::projects()->uploadFile($gitlabRepoId, $ticket->file4); + // $description .= $this->formatGitlabFiles($ticket, $uploadedFile4, 4); + // } - if (!\is_null($ticket->file5)) { - $uploadedFile5 = GitLab::projects()->uploadFile($gitlabRepoId, $ticket->file5); - $description .= $this->formatGitlabFiles($ticket, $uploadedFile5, 5); - } + // if (!\is_null($ticket->file5)) { + // $uploadedFile5 = GitLab::projects()->uploadFile($gitlabRepoId, $ticket->file5); + // $description .= $this->formatGitlabFiles($ticket, $uploadedFile5, 5); + // } $issue = GitLab::issues()->create($gitlabRepoId, [ 'title' => 'ts-' . $ticket->id, diff --git a/app/Http/Requests/Bo/Credit/CreateEstimateRequest.php b/app/Http/Requests/Bo/Credit/CreateEstimateRequest.php index 0c30c4e..da90770 100644 --- a/app/Http/Requests/Bo/Credit/CreateEstimateRequest.php +++ b/app/Http/Requests/Bo/Credit/CreateEstimateRequest.php @@ -33,14 +33,18 @@ class CreateEstimateRequest extends FormRequest $ticket = $this->ticket; return [ 'amount' => [ - 'required', 'numeric', 'gt:0', function ($attribute, $value, $fail) { - if ((\floatval($value) * 1000) % 62.5 !== 0) { + 'required', + 'numeric', + 'gt:0', + function ($attribute, $value, $fail) { + if (fmod((\floatval($value) * 1000), 62.5) !== 0.0) { $fail("$attribute doit être un multiple de 62.5 (soit 0.0625)"); } } ], 'credit_account_id' => [ - 'required', 'exists:credit_accounts,id', + 'required', + 'exists:credit_accounts,id', function ($attribute, $value, $fail) use ($ticket) { /** @var \App\Models\Credit\Account|null */ $account = Account::whereId($value)->first(); @@ -57,11 +61,11 @@ class CreateEstimateRequest extends FormRequest * * @return array */ - public function messages(): array + public function attributes(): array { return [ 'amount' => 'Montant', - 'credit_account_id' => 'Compte' + 'credit_account_id' => 'Compte à débiter' ]; } } diff --git a/app/Lib/Helpers/ToolboxHelper.php b/app/Lib/Helpers/ToolboxHelper.php index 68bd885..507eadc 100644 --- a/app/Lib/Helpers/ToolboxHelper.php +++ b/app/Lib/Helpers/ToolboxHelper.php @@ -68,6 +68,18 @@ class ToolboxHelper return \preg_match('/(\.png|\.jpg|\.jpeg|\.gif)$/', $url, $m) === 1; } + /** + * Check uri points to pdf file + * + * @param string $url + * @return boolean + */ + public static function isPdfFile(string $url): bool + { + $m = []; + return \preg_match('/(\.pdf)$/', $url, $m) === 1; + } + /** * Strip scheme (https) on oembed urls * Only embed allowed are for MP4 self hosted videos right now @@ -339,7 +351,7 @@ class ToolboxHelper ): Builder { $currentLocale = app()->currentLocale(); $locales = collect(config('app.locales')) - ->mapWithKeys(fn (string $locale) => [$locale => $locale]); + ->mapWithKeys(fn(string $locale) => [$locale => $locale]); if (!$locales->has($defaultLocale)) { // * Remove default locale. $locales->pull($defaultLocale); @@ -357,7 +369,7 @@ class ToolboxHelper $q->whereRaw("JSON_EXTRACT({$column}, '$.{$currentLocale}') = '{$value}'"); } // * Query any other locale - $locales->each(fn ($locale) => $q->orWhereRaw( + $locales->each(fn($locale) => $q->orWhereRaw( "JSON_EXTRACT({$column}, '$.{$locale}') = '{$value}'" )); }); @@ -449,7 +461,10 @@ class ToolboxHelper $fileFullPath = self::getUploadedFileFullPath($value, $useStorage); if ( !\in_array(self::getUploadedFileMimeType($value, $useStorage), [ - 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' + 'image/jpeg', + 'image/jpg', + 'image/png', + 'image/gif' ]) ) { $fail(trans(':attribute doit être une image de type \'image/jpeg,image/jpg,image/png,image/gif\'', [ diff --git a/app/Models/Ticket.php b/app/Models/Ticket.php index 4fe561e..460ef6d 100644 --- a/app/Models/Ticket.php +++ b/app/Models/Ticket.php @@ -275,4 +275,20 @@ class Ticket extends Model Str::limit(\preg_replace('/[[:cntrl:]]+/', '', $ticket->text), 35), ); } + + /** + * Get an array of all files columns of the ticket. + * + * @return array + */ + public function getFiles(): array + { + return [ + $this->file, + $this->file2, + $this->file3, + $this->file4, + $this->file5, + ]; + } } diff --git a/resources/views/bo/pages/tickets/index.blade.php b/resources/views/bo/pages/tickets/index.blade.php index 1d3c8ac..6642a15 100644 --- a/resources/views/bo/pages/tickets/index.blade.php +++ b/resources/views/bo/pages/tickets/index.blade.php @@ -226,101 +226,101 @@