diff --git a/.env.example b/.env.example index d012610..8495881 100644 --- a/.env.example +++ b/.env.example @@ -15,7 +15,7 @@ DB_USERNAME=root DB_PASSWORD= BROADCAST_DRIVER=log -CACHE_DRIVER=apc +CACHE_DRIVER=file QUEUE_CONNECTION=database SESSION_DRIVER=file SESSION_LIFETIME=120 diff --git a/.gitignore b/.gitignore index c06ef95..5a0e861 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ npm-debug.log yarn-error.log .npmrc .phpdoc +.zshrc +.npm/ +.composer/ diff --git a/README.md b/README.md index f924ece..cd56bdc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ -# Comment lancer les tests unitaires ? +# CRM + +## Documentation +https://cdlfr.sharepoint.com/:b:/r/sites/LDCWEB/Documents%20partages/Documentations/Projets/CRM/FICHE%20FONCTIONNELLE%20OUTIL%20R%C3%89CLAMATIONS%20CONSO.pdf?csf=1&web=1&e=qktL4V + +## Tests unitaire + +### Comment lancer les tests unitaires ? [Suivre le wiki dédié au tests unitaires](https://lab.s-web.fr/ldc-web/projets/crm/-/wikis/Tests-unitaires) diff --git a/app/Enums/Claims/ClaimStatus.php b/app/Enums/Claims/ClaimStatus.php index 53d2c64..afa8e99 100644 --- a/app/Enums/Claims/ClaimStatus.php +++ b/app/Enums/Claims/ClaimStatus.php @@ -12,6 +12,7 @@ enum ClaimStatus: int case sentDigital = 2; case sentMarketing = 3; case treated = 4; + case refused = 5; /** * Optionnal labels definition @@ -21,6 +22,7 @@ enum ClaimStatus: int self::sentDigital->name => 'Transférée au service Digital', self::sentMarketing->name => 'Retournée au Marketing', self::treated->name => 'Traitée', + self::refused->name => 'Refusé de répondre', ]; /** @@ -31,6 +33,7 @@ enum ClaimStatus: int self::sentDigital->name => '#0033c0', self::sentMarketing->name => '#69077c', self::treated->name => '#188618', + self::refused->name => '#dc143c', ]; /** diff --git a/app/Enums/ExportFormat.php b/app/Enums/ExportFormat.php new file mode 100644 index 0000000..7d9731a --- /dev/null +++ b/app/Enums/ExportFormat.php @@ -0,0 +1,85 @@ +name => 'csv', + self::csvWithoutAttachment->name => 'csv sans pièces jointes', + self::pdf->name => 'pdf', + ]; + + /** + * Bootstrap color class to use for the export buttons. + * + * @return string + */ + public function class(): string + { + return match ($this) { + self::csv, + self::csvWithoutAttachment => 'success', + self::pdf => 'danger', + default => 'primary', + }; + } + + /** + * Font Awesome picto to use for the export buttons. + * + * @return string + */ + public function picto(): string + { + return match ($this) { + self::csv, + self::csvWithoutAttachment => 'fa-solid fa-file-csv', + self::pdf => 'fa-solid fa-file-pdf', + default => 'fa-solid fa-file', + }; + } + + + /** + * File headers to use when the exported file is return with StreamedResponse. + * + * @return array + */ + public function fileHeaders(): array + { + return match ($this) { + self::csv, + self::csvWithoutAttachment => [ + 'Content-Type' => 'text/csv', + 'Content-Disposition' => 'attachment; filename="export.csv"', + ], + default => [], + }; + } + + /** + * Export file name. + * + * @return string + */ + public function fileName(): string + { + return match ($this) { + self::csv, + self::csvWithoutAttachment => 'export.csv', + self::pdf => 'export.pdf', + }; + } +} diff --git a/app/Http/Controllers/Api/V4/ClaimController.php b/app/Http/Controllers/Api/V4/ClaimController.php index 784127c..f2e5fd2 100644 --- a/app/Http/Controllers/Api/V4/ClaimController.php +++ b/app/Http/Controllers/Api/V4/ClaimController.php @@ -24,7 +24,7 @@ class ClaimController extends Controller { $claimModel = (new Claim())->fill(Arr::except($request->validated(), 'file')); if ($request->filled('file')) { - $claimModel->file = FileHelper::storeBase64File('claim', $request->file); + $claimModel->file = FileHelper::storeBase64File('claim', $request->file, private: true); } if (!$claimModel->saveOrFail()) { diff --git a/app/Http/Controllers/Bo/AnswerController.php b/app/Http/Controllers/Bo/AnswerController.php index e93a74f..2972b6f 100644 --- a/app/Http/Controllers/Bo/AnswerController.php +++ b/app/Http/Controllers/Bo/AnswerController.php @@ -47,7 +47,7 @@ class AnswerController extends Controller $this->sortQuery($query); $searchFields = trans('Réponse'); - $answerModels = $this->paginate($this->getPagination()); + $answerModels = $query->paginate($this->getPagination()); return view('bo.pages.answers.index', compact('answerModels', 'questionModel', 'searchFields')); } diff --git a/app/Http/Controllers/Bo/ClaimController.php b/app/Http/Controllers/Bo/ClaimController.php index a6586bc..bd3ed5c 100644 --- a/app/Http/Controllers/Bo/ClaimController.php +++ b/app/Http/Controllers/Bo/ClaimController.php @@ -4,27 +4,36 @@ namespace App\Http\Controllers\Bo; use App\Enums\Claims\ClaimResponseType; use App\Enums\Claims\ClaimStatus; +use App\Enums\ExportFormat; use App\Enums\Users\RoleEnum; use App\Events\ClaimModelChanged; use App\Http\Controllers\Controller; +use App\Http\Requests\Bo\Claims\ExportClaimRequest; use App\Http\Requests\Bo\Claims\SendClaimAnswerRequest; use App\Http\Requests\Bo\Claims\UpdateClaimRequest; +use App\Http\Requests\Bo\Claims\ViewClaimAttachmentRequest; use App\Http\Requests\Bo\PaginateModelsRequest; +use App\Lib\Helpers\FileHelper; use App\Mail\ClaimAnswerMail; use App\Models\Brand; use App\Models\Claim; use App\Models\ClaimMailTemplate; use App\Models\ClaimMessage; use App\Models\ClaimSubject; +use App\Models\CustomerInfo; +use App\Traits\Controllers\ExportDatas; use App\Traits\Controllers\UpdateModelPublished; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Facades\Storage; +use Symfony\Component\HttpFoundation\StreamedResponse; use Uwil\LaravelCommon\Helpers\CollectionHelper; class ClaimController extends Controller { use UpdateModelPublished; + use ExportDatas; /** * Create the controller instance. @@ -53,6 +62,15 @@ class ClaimController extends Controller )->when( $userModel->role->equals(RoleEnum::marketing), fn($q) => $q->whereHas('brand', fn($q) => $q->whereIn('id', $userModel->brands->modelKeys())) + ) + ->when( + $request->filled('subject'), + fn($q) => $q->whereHas('claimSubject', fn($q) => $q->where('id', $request->subject)) + ) + ->when( + $request->filled('status'), + fn($q) => $q->whereIn('status', $request->status), + fn($q) => $q->whereNotIn('status', [ClaimStatus::treated, ClaimStatus::refused]) ); /** @var string $search Search field */ @@ -81,7 +99,25 @@ class ClaimController extends Controller /** Custom pagination */ $claimModels = $query->simplePaginate($this->getPagination()); - return view('bo.pages.claims.index', compact('claimModels', 'search', 'searchFields')); + /** Define request brand filter if user only has 1 brand */ + if (auth('backend')->user()->brands()->count() === 1) { + $request->merge(['brand' => auth('backend')->user()->brands()->value('id')]); + }; + + $claimSubjectModels = ClaimSubject::query() + ->when( + $request->filled('brand'), + fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand)), + ) + ->when( + auth('backend')->user()->brands()->count() === 1, + fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', auth('backend')->user()->brands()->pluck('id'))) + ); + $claimSubjectModels = $request->filled('brand') || (auth('backend')->user()->brands()->count() === 1) ? + $claimSubjectModels->orderBy('label', 'ASC')->get() : + null; + + return view('bo.pages.claims.index', compact('claimModels', 'search', 'searchFields', 'claimSubjectModels')); } /** @@ -92,12 +128,12 @@ class ClaimController extends Controller */ public function edit(Claim $claim): \Illuminate\Contracts\View\View { - $customerClaimModels = !is_null($claim->customer) ? $this->paginate(Claim::query() + $customerClaimModels = !is_null($claim->customer) ? Claim::query() ->whereNotNull('customer_id') ->whereHas('brand', fn($q) => $q->whereKey($claim->brand->getKey())) ->whereHas('customer', fn($q) => $q->whereKey($claim->customer->getKey())) ->whereNot('id', $claim->getKey()) - ->whereNot('status', ClaimStatus::treated)) : collect(); + ->whereNot('status', ClaimStatus::treated)->paginate($this->jsonItemPerPagination) : collect(); $brandModels = CollectionHelper::paginate( Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination, @@ -111,6 +147,7 @@ class ClaimController extends Controller ClaimMailTemplate::getAllModelsFromBrand($claim->brand->getKey()), $this->jsonItemPerPagination, ); + $customerModel = CustomerInfo::query()->where('hashcode', $claim->hashcode)->first(); return view('bo.pages.claims.edit', [ 'claimModel' => $claim->load(['brand', 'claimSubject']), @@ -119,6 +156,7 @@ class ClaimController extends Controller 'claimMessageModels' => $claimMessageModels, 'claimSubjectModels' => $claimSubjectModels, 'claimTemplateModels' => $claimTemplateModels, + 'customerModel' => $customerModel, ]); } @@ -168,7 +206,7 @@ class ClaimController extends Controller "%s %s %s %s
{{ e($claimModel->email) }}
- @if ($claimModel->customer && auth()->user()->can('view', $claimModel->customer)) - - {{ __('Lien vers la fiche client') }} - - - @endif - @if ($claimModel->getFormatedAddress()) -{{ $claimModel->getFormatedAddress() ? e($claimModel->getFormatedAddress()) : null }}
- @endif -Fichier:
- - {{ __('Voir la pièce jointe associée') }} +{{ e($claimModel->email) }}
+ @if ($customerModel && auth()->user()->can('view', \App\Models\Customer::class)) + + {{ __('Lien vers la fiche client') }} + -+ {{ $claimModel->getFormatedAddress() ? e($claimModel->getFormatedAddress()) : null }} +
+ @endif +Fichier:
+ + {{ __('Voir la pièce jointe associée') }} + +| {{ $claimModel->reference }} | ++ + {{ $claimModel->created_at->format('d/m/Y') }} + + |
{{ sprintf('%s %s', $claimModel->first_name, $claimModel->last_name) }} {{ e($claimModel->email) }} |
- {{ $claimModel->brand->name }} | -
- |
+ {{ $claimModel->message }} | + @if (!request()->brand) +{{ $claimModel->brand->name }} | + @endif
|
- - - {{ $claimModel->updated_at->isoFormat('LLLL') }} - - |
@canAny(['preview', 'update'], $claimModel)
@@ -52,6 +57,16 @@
@endcan
+ @can('export', $claimModel)
+
+
+
+ @endcan
@else
@@ -61,12 +76,16 @@
|
| {{ __('crud.other.no_model_found', ['model' => str(__('models.classes.claims'))->singular()]) }} | -|||||||||
| + + {{ __('Aucun résultat pour les :models', ['models' => __('models.classes.claims')]) }} + + | +|||||||||