2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
use App\Actions\Discounts\CreateDiscount;
|
|
|
|
|
use App\Actions\Discounts\DeleteDiscount;
|
|
|
|
|
use App\Actions\Discounts\DeleteDiscountInput;
|
|
|
|
|
use App\Actions\Discounts\UpdateDiscount;
|
|
|
|
|
use App\Contracts\Executor;
|
2026-06-14 21:32:07 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Http\Requests\Bo\Discounts\StoreDiscountRequest;
|
|
|
|
|
use App\Http\Requests\Bo\Discounts\UpdateDiscountRequest;
|
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees)
- Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue)
- Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts
- Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs
- Remove legacy and dead CSV employee import/export code
- Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation
- Add comprehensive Pest unit, integration, and feature test coverage
2026-10-01 17:26:30 +02:00
|
|
|
use App\Lib\Helpers\RequestHelper;
|
2026-06-14 21:32:07 +02:00
|
|
|
use App\Models\Discount;
|
2026-09-30 12:43:55 +02:00
|
|
|
use App\Queries\Discounts\GetDiscountFormDataQuery;
|
|
|
|
|
use App\Queries\Discounts\GetDiscountFormDataQueryInput;
|
|
|
|
|
use App\Queries\Discounts\GetPaginatedDiscountsQuery;
|
|
|
|
|
use App\Queries\Discounts\GetPaginatedDiscountsQueryInput;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
2026-09-29 16:59:07 +02:00
|
|
|
use Illuminate\Http\Request;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
|
|
class DiscountsController extends Controller
|
|
|
|
|
{
|
2026-09-30 12:43:55 +02:00
|
|
|
public function __construct(
|
|
|
|
|
private readonly Executor $executor,
|
|
|
|
|
) {
|
|
|
|
|
}
|
2026-06-14 21:32:07 +02:00
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
public function index(Request $request, GetPaginatedDiscountsQuery $query): View
|
2026-06-14 21:32:07 +02:00
|
|
|
{
|
|
|
|
|
$this->authorize('viewAny', Discount::class);
|
|
|
|
|
|
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees)
- Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue)
- Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts
- Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs
- Remove legacy and dead CSV employee import/export code
- Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation
- Add comprehensive Pest unit, integration, and feature test coverage
2026-10-01 17:26:30 +02:00
|
|
|
$pagination = RequestHelper::pagination($request);
|
2026-09-30 12:43:55 +02:00
|
|
|
|
|
|
|
|
$discounts = $this->executor->execute(
|
|
|
|
|
$query,
|
|
|
|
|
new GetPaginatedDiscountsQueryInput(
|
|
|
|
|
pagination: $pagination,
|
|
|
|
|
)
|
|
|
|
|
);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
return view('bo.discounts.index', compact('discounts'));
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
public function create(GetDiscountFormDataQuery $query): View
|
2026-06-14 21:32:07 +02:00
|
|
|
{
|
|
|
|
|
$this->authorize('create', Discount::class);
|
|
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
$formData = $this->executor->execute(
|
|
|
|
|
$query,
|
|
|
|
|
new GetDiscountFormDataQueryInput()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return view('bo.discounts.create', [
|
|
|
|
|
'discountTypes' => $formData->discountTypes,
|
|
|
|
|
'existingProds' => $formData->existingProds,
|
|
|
|
|
'selectedProds' => $formData->selectedProds,
|
|
|
|
|
]);
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
public function store(StoreDiscountRequest $request, CreateDiscount $action): RedirectResponse
|
2026-06-14 21:32:07 +02:00
|
|
|
{
|
|
|
|
|
$this->authorize('create', Discount::class);
|
|
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
$discount = $this->executor->execute(
|
|
|
|
|
$action,
|
2026-10-01 11:25:05 +02:00
|
|
|
$request->toCreateDiscountInput(),
|
2026-09-30 12:43:55 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return to_route('bo.discounts.edit', $discount)
|
|
|
|
|
->with('success', trans('crud.messages.has_been_created', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice('models.classes.discounts', 1)),
|
|
|
|
|
]));
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
public function edit(Discount $discount, GetDiscountFormDataQuery $query): View
|
2026-06-14 21:32:07 +02:00
|
|
|
{
|
|
|
|
|
$this->authorize('update', $discount);
|
|
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
$formData = $this->executor->execute(
|
|
|
|
|
$query,
|
|
|
|
|
new GetDiscountFormDataQueryInput($discount)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return view('bo.discounts.edit', [
|
|
|
|
|
'discount' => $formData->discount,
|
|
|
|
|
'discountTypes' => $formData->discountTypes,
|
|
|
|
|
'existingProds' => $formData->existingProds,
|
|
|
|
|
'selectedProds' => $formData->selectedProds,
|
|
|
|
|
]);
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
public function update(UpdateDiscountRequest $request, Discount $discount, UpdateDiscount $action): RedirectResponse
|
2026-06-14 21:32:07 +02:00
|
|
|
{
|
|
|
|
|
$this->authorize('update', $discount);
|
|
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
$this->executor->execute(
|
|
|
|
|
$action,
|
2026-10-01 11:25:05 +02:00
|
|
|
$request->toUpdateDiscountInput($discount),
|
2026-09-30 12:43:55 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return to_route('bo.discounts.edit', $discount)
|
|
|
|
|
->with('success', trans('crud.messages.has_been_updated', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice('models.classes.discounts', 1)),
|
|
|
|
|
]));
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
public function destroy(Discount $discount, DeleteDiscount $action): RedirectResponse
|
2026-06-14 21:32:07 +02:00
|
|
|
{
|
|
|
|
|
$this->authorize('delete', $discount);
|
|
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
$this->executor->execute(
|
|
|
|
|
$action,
|
|
|
|
|
new DeleteDiscountInput(discount: $discount),
|
|
|
|
|
);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
2026-09-30 12:43:55 +02:00
|
|
|
return to_route('bo.discounts.index')
|
|
|
|
|
->with('warning', trans('crud.messages.has_been_deleted', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice('models.classes.discounts', 1)),
|
|
|
|
|
]));
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
}
|