- 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
126 lines
3.9 KiB
PHP
126 lines
3.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Actions\Discounts\CreateDiscount;
|
|
use App\Actions\Discounts\DeleteDiscount;
|
|
use App\Actions\Discounts\DeleteDiscountInput;
|
|
use App\Actions\Discounts\UpdateDiscount;
|
|
use App\Contracts\Executor;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\Discounts\StoreDiscountRequest;
|
|
use App\Http\Requests\Bo\Discounts\UpdateDiscountRequest;
|
|
use App\Lib\Helpers\RequestHelper;
|
|
use App\Models\Discount;
|
|
use App\Queries\Discounts\GetDiscountFormDataQuery;
|
|
use App\Queries\Discounts\GetDiscountFormDataQueryInput;
|
|
use App\Queries\Discounts\GetPaginatedDiscountsQuery;
|
|
use App\Queries\Discounts\GetPaginatedDiscountsQueryInput;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Str;
|
|
|
|
class DiscountsController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly Executor $executor,
|
|
) {
|
|
}
|
|
|
|
public function index(Request $request, GetPaginatedDiscountsQuery $query): View
|
|
{
|
|
$this->authorize('viewAny', Discount::class);
|
|
|
|
$pagination = RequestHelper::pagination($request);
|
|
|
|
$discounts = $this->executor->execute(
|
|
$query,
|
|
new GetPaginatedDiscountsQueryInput(
|
|
pagination: $pagination,
|
|
)
|
|
);
|
|
|
|
return view('bo.discounts.index', compact('discounts'));
|
|
}
|
|
|
|
public function create(GetDiscountFormDataQuery $query): View
|
|
{
|
|
$this->authorize('create', Discount::class);
|
|
|
|
$formData = $this->executor->execute(
|
|
$query,
|
|
new GetDiscountFormDataQueryInput()
|
|
);
|
|
|
|
return view('bo.discounts.create', [
|
|
'discountTypes' => $formData->discountTypes,
|
|
'existingProds' => $formData->existingProds,
|
|
'selectedProds' => $formData->selectedProds,
|
|
]);
|
|
}
|
|
|
|
public function store(StoreDiscountRequest $request, CreateDiscount $action): RedirectResponse
|
|
{
|
|
$this->authorize('create', Discount::class);
|
|
|
|
$discount = $this->executor->execute(
|
|
$action,
|
|
$request->toCreateDiscountInput(),
|
|
);
|
|
|
|
return to_route('bo.discounts.edit', $discount)
|
|
->with('success', trans('crud.messages.has_been_created', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.discounts', 1)),
|
|
]));
|
|
}
|
|
|
|
public function edit(Discount $discount, GetDiscountFormDataQuery $query): View
|
|
{
|
|
$this->authorize('update', $discount);
|
|
|
|
$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,
|
|
]);
|
|
}
|
|
|
|
public function update(UpdateDiscountRequest $request, Discount $discount, UpdateDiscount $action): RedirectResponse
|
|
{
|
|
$this->authorize('update', $discount);
|
|
|
|
$this->executor->execute(
|
|
$action,
|
|
$request->toUpdateDiscountInput($discount),
|
|
);
|
|
|
|
return to_route('bo.discounts.edit', $discount)
|
|
->with('success', trans('crud.messages.has_been_updated', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.discounts', 1)),
|
|
]));
|
|
}
|
|
|
|
public function destroy(Discount $discount, DeleteDiscount $action): RedirectResponse
|
|
{
|
|
$this->authorize('delete', $discount);
|
|
|
|
$this->executor->execute(
|
|
$action,
|
|
new DeleteDiscountInput(discount: $discount),
|
|
);
|
|
|
|
return to_route('bo.discounts.index')
|
|
->with('warning', trans('crud.messages.has_been_deleted', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.discounts', 1)),
|
|
]));
|
|
}
|
|
}
|