diff --git a/app/Console/Commands/UserCreate.php b/app/Console/Commands/UserCreate.php index 533eb23..d656d86 100644 --- a/app/Console/Commands/UserCreate.php +++ b/app/Console/Commands/UserCreate.php @@ -175,9 +175,9 @@ class UserCreate extends Command [ Str::ucFirst(RoleEnum::conceptor->label()), Str::ucFirst(RoleEnum::admin->label()), - Str::ucFirst(RoleEnum::visitor->label()) + Str::ucFirst(RoleEnum::marketing->label()) ], - Str::ucFirst(RoleEnum::visitor->label()), + Str::ucFirst(RoleEnum::marketing->label()), ); if ($tmp === Str::ucFirst(RoleEnum::conceptor->label())) { $tmp = RoleEnum::conceptor; @@ -185,8 +185,8 @@ class UserCreate extends Command if ($tmp === Str::ucFirst(RoleEnum::admin->label())) { $tmp = RoleEnum::admin; } - if ($tmp === Str::ucFirst(RoleEnum::visitor->label())) { - $tmp = RoleEnum::visitor; + if ($tmp === Str::ucFirst(RoleEnum::marketing->label())) { + $tmp = RoleEnum::marketing; } $validator = Validator::make(['role' => $tmp], [ 'role' => 'required' diff --git a/app/Enums/Claims/ClaimMessageType.php b/app/Enums/Claims/ClaimMessageType.php new file mode 100644 index 0000000..3b2e965 --- /dev/null +++ b/app/Enums/Claims/ClaimMessageType.php @@ -0,0 +1,21 @@ +name => 'Système', + self::human->name => 'Humain', + ]; +} diff --git a/app/Enums/Claims/ClaimResponseType.php b/app/Enums/Claims/ClaimResponseType.php new file mode 100644 index 0000000..c8575eb --- /dev/null +++ b/app/Enums/Claims/ClaimResponseType.php @@ -0,0 +1,51 @@ +name => 'Non défini', + self::manual->name => 'Manuelle', + self::mail->name => 'Courrier', + self::email->name => 'E-mail', + self::phone->name => 'Téléphone', + self::other->name => 'Autre', + ]; + + /** + * Optionnal labels definition. + */ + private const COLORS = [ + self::none->name => '#b8b8b8', + self::manual->name => '#a7a7a7', + self::mail->name => '#757575', + self::email->name => '#5e5e5e', + self::phone->name => '#414141', + self::other->name => '#2b2b2b', + ]; + + /** + * Get Class. + * + * @return string + */ + public function color(): string + { + return self::COLORS[$this->name]; + } +} diff --git a/app/Enums/Claims/ClaimStatus.php b/app/Enums/Claims/ClaimStatus.php new file mode 100644 index 0000000..29ca37b --- /dev/null +++ b/app/Enums/Claims/ClaimStatus.php @@ -0,0 +1,45 @@ +name => 'Non traitée', + self::sentDigital->name => 'Transférée au service Digital', + self::sentMarketing->name => 'Retournée au Marketing', + self::treated->name => 'Traitée', + ]; + + /** + * Optionnal labels definition. + */ + private const COLORS = [ + self::untreated->name => '#5a5a5a', + self::sentDigital->name => '#0033c0', + self::sentMarketing->name => '#69077c', + self::treated->name => '#188618', + ]; + + /** + * Get Class. + * + * @return string + */ + public function color(): string + { + return self::COLORS[$this->name]; + } +} diff --git a/app/Enums/Claims/ClaimType.php b/app/Enums/Claims/ClaimType.php new file mode 100644 index 0000000..bab2dca --- /dev/null +++ b/app/Enums/Claims/ClaimType.php @@ -0,0 +1,42 @@ +name => 'Classique', + self::br->name => 'BR', + self::rgpd->name => 'RGPD', + ]; + + /** + * Optionnal labels definition. + */ + private const COLORS = [ + self::classic->name => '#08818a', + self::br->name => '#9021f8', + self::rgpd->name => '#c2237a', + ]; + + /** + * Get Class. + * + * @return string + */ + public function color(): string + { + return self::COLORS[$this->name]; + } +} diff --git a/app/Enums/Users/RoleEnum.php b/app/Enums/Users/RoleEnum.php index 53b5ada..b72f1cb 100644 --- a/app/Enums/Users/RoleEnum.php +++ b/app/Enums/Users/RoleEnum.php @@ -10,7 +10,7 @@ enum RoleEnum: int case conceptor = 1; case admin = 2; - case visitor = 3; + case marketing = 3; /** * Optionnal labels definition. @@ -18,6 +18,6 @@ enum RoleEnum: int private const LABELS = [ self::conceptor->name => 'Concepteur', self::admin->name => 'Administrateur', - self::visitor->name => 'Visiteur', + self::marketing->name => 'Marketing', ]; } diff --git a/app/Events/ClaimModelChanged.php b/app/Events/ClaimModelChanged.php new file mode 100644 index 0000000..9b0b937 --- /dev/null +++ b/app/Events/ClaimModelChanged.php @@ -0,0 +1,55 @@ +claim = $claim; + $this->field = $field; + $this->label = $label; + $this->user = $user; + $this->content = $content; + } +} diff --git a/app/Http/Controllers/Api/V4/ClaimController.php b/app/Http/Controllers/Api/V4/ClaimController.php new file mode 100644 index 0000000..01945e2 --- /dev/null +++ b/app/Http/Controllers/Api/V4/ClaimController.php @@ -0,0 +1,31 @@ +fill($request->validated()); + if (!$claimModel->saveOrFail()) { + throw new CrmException('Api failed to store claim.'); + } + $claimModel->brand()->associate($service->brand); + + return response()->json(); + } +} diff --git a/app/Http/Controllers/Bo/ActivityLogsController.php b/app/Http/Controllers/Bo/ActivityLogsController.php index 7dbf191..a88b9ef 100644 --- a/app/Http/Controllers/Bo/ActivityLogsController.php +++ b/app/Http/Controllers/Bo/ActivityLogsController.php @@ -13,6 +13,14 @@ class ActivityLogsController extends Controller use ChangesModelOrder; use UpdateModelPublished; + /** + * Create the controller instance. + */ + public function __construct() + { + $this->authorizeResource(ActivityLog::class); + } + /** * Display a listing of the resource. * diff --git a/app/Http/Controllers/Bo/AnswerController.php b/app/Http/Controllers/Bo/AnswerController.php index c44b595..074d1a8 100644 --- a/app/Http/Controllers/Bo/AnswerController.php +++ b/app/Http/Controllers/Bo/AnswerController.php @@ -13,6 +13,14 @@ use Illuminate\Support\Str; class AnswerController extends Controller { + /** + * Create the controller instance. + */ + public function __construct() + { + $this->authorizeResource(Answer::class); + } + /** * Display a listing of the resource. * diff --git a/app/Http/Controllers/Bo/BrandController.php b/app/Http/Controllers/Bo/BrandController.php index d70e1d9..fc666af 100644 --- a/app/Http/Controllers/Bo/BrandController.php +++ b/app/Http/Controllers/Bo/BrandController.php @@ -5,14 +5,24 @@ namespace App\Http\Controllers\Bo; use App\Http\Controllers\Controller; use App\Http\Requests\Bo\Brands\StoreBrandRequest; use App\Http\Requests\Bo\Brands\UpdateBrandRequest; +use App\Http\Requests\Bo\PaginateModelsRequest; use App\Models\Brand; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; +use Uwil\LaravelCommon\Helpers\CollectionHelper; class BrandController extends Controller { + /** + * Create the controller instance. + */ + public function __construct() + { + $this->authorizeResource(Brand::class); + } + /** * Display a listing of the resource. * @@ -128,16 +138,18 @@ class BrandController extends Controller } /** - * Store a newly created resource in storage. + * Get a paginate resource. * + * @param \App\Http\Requests\Bo\PaginateModelsRequest $request * @return \Illuminate\Http\JsonResponse */ - public function jsonPaginate(): \Illuminate\Http\JsonResponse + public function jsonPaginateModels(PaginateModelsRequest $request): \Illuminate\Http\JsonResponse { - return DB::transaction(function () { - /** @var \App\Models\Brand */ - $brandModels = Brand::paginate(12); - return \response()->json($brandModels ?? 500); - }); + $models = CollectionHelper::paginateManually( + Brand::getUserAssociatedBrands(), + $this->jsonItemPerPagination, + (int)$request->validated('page'), + ); + return \response()->json($models); } } diff --git a/app/Http/Controllers/Bo/ClaimController.php b/app/Http/Controllers/Bo/ClaimController.php new file mode 100644 index 0000000..b405b9b --- /dev/null +++ b/app/Http/Controllers/Bo/ClaimController.php @@ -0,0 +1,204 @@ +authorizeResource(Claim::class); + } + + /** + * Display a listing of the resource. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Contracts\View\View + */ + public function index(Request $request): \Illuminate\Contracts\View\View + { + /** @var \App\Models\User $userModel */ + $userModel = auth('backend')->user(); + + /** @var \Illuminate\Database\Eloquent\Builder $claimModels */ + $claimModels = Claim::query() + ->when( + $request->filled('brand'), + fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand)) + )->when( + $userModel->role->equals(RoleEnum::marketing), + fn($q) => $q->whereHas('brand', fn($q) => $q->whereIn('id', $userModel->brands->modelKeys())) + ); + + /** @var string $search Search field */ + $search = $request->search; + if ($search) { + $this->searchQuery( + $claimModels, + $search, + null, + 'reference', + 'first_name', + 'last_name', + 'email', + ); + } + $searchFields = \implode(', ', [ + trans('validation.custom.reference'), + trans('validation.attributes.first_name'), + trans('validation.attributes.last_name'), + trans('validation.attributes.email'), + ]); + + /** Sort columns with a query */ + $this->sortQuery($claimModels); + + /** Custom pagination */ + $claimModels = $this->paginate($claimModels); + + return view('bo.pages.claims.index', compact('claimModels', 'search', 'searchFields')); + } + + /** + * Show the form for editing the specified resource. + * + * @param App\Models\Claim $claim + * @return \Illuminate\Contracts\View\View + */ + public function edit(Claim $claim): \Illuminate\Contracts\View\View + { + $customerClaimModels = !is_null($claim->customer) ? $this->paginate(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(); + $brandModels = CollectionHelper::paginate( + Brand::getUserAssociatedBrands(), + $this->jsonItemPerPagination, + ); + $claimMessageModels = ClaimMessage::getAllModelsFromClaim($claim->getKey()); + $claimSubjectModels = CollectionHelper::paginate( + ClaimSubject::getAllModelsFromBrand($claim->brand->getKey()), + $this->jsonItemPerPagination, + ); + $claimTemplateModels = CollectionHelper::paginate( + ClaimMailTemplate::getAllModelsFromBrand($claim->brand->getKey()), + $this->jsonItemPerPagination, + ); + + return view('bo.pages.claims.edit', [ + 'claimModel' => $claim->load(['brand', 'claimSubject']), + 'customerClaimModels' => $customerClaimModels, + 'brandModels' => $brandModels, + 'claimMessageModels' => $claimMessageModels, + 'claimSubjectModels' => $claimSubjectModels, + 'claimTemplateModels' => $claimTemplateModels, + ]); + } + + /** + * Update the specified resource. + * + * @param \App\Http\Requests\Bo\Claims\UpdateClaimRequest $request + * @param \App\Models\Claim $claim + * @return \Illuminate\Http\JsonResponse + */ + public function update(UpdateClaimRequest $request, Claim $claim): \Illuminate\Http\JsonResponse + { + return DB::transaction(function () use ($request, $claim) { + $claim->fill($request->validated()); + + if ($claim->saveOrFail()) { + $claimMessageModels = ClaimMessage::getAllModelsFromClaim($claim->getKey()); + return response()->json($claimMessageModels); + } + return response()->json([], 500); + }); + } + + /** + * Send the claim answer. + * + * @param \App\Http\Requests\Bo\Claims\SendClaimAnswerRequest $request + * @param \App\Models\Claim $claim + * @return \Illuminate\Http\JsonResponse + */ + public function answer(SendClaimAnswerRequest $request, Claim $claim): \Illuminate\Http\JsonResponse + { + return DB::transaction(function () use ($request, $claim) { + /** @var \App\Models\User $userModel */ + $userModel = auth()->user(); + $enum = ClaimResponseType::manual; + $claim->response_type = $enum; + $claim->status = ClaimStatus::treated; + + if ($claim->saveOrFail()) { + // Send the response to the claim author. + Mail::to($claim->email)->send(new ClaimAnswerMail($claim, $request->validated()['content'])); + + // Create custom event with content message. + // @phpcs:disable Generic.Files.LineLength.TooLong + $content = sprintf( + "%s %s %s %s
- {{ parseValidationInput(`${name}[${String(index)}][name]`, allErrors) }} -
- - - - - - -|
+
+ |
+
+ + {{ brandLabel }} + | ++ {{ selectParameters.brand.name }} + | + +|
|
+
+ |
+
+ + {{ trans.methods.__("models.classes.claimsubjects") }} + | ++ {{ selectParameters.subject?.label }} + | + +|
|
+
+
+
+
+
+
+ {{ errors.methods.parseValidationInput(`${enumField.name}`, allErrors) }}
+
+ |
+
+ + {{ ucfirst(trans.methods.__(`validation.custom.${enumField.name}`)) }} + | ++ {{ Object.values(enumField.associatedEnum).find(item => item.value == selectParameters.enums[enumField.name])?.label }} + | + +|
- {{ __("vue.ImageInputComponent.preview_picture") }} + {{ trans.methods.__("vue.ImageInputComponent.preview_picture") }}
-