This commit refactors the import statements in various controllers and jobs to improve code organization and readability. Unused imports were removed, and necessary imports were added to ensure proper functionality.
90 lines
2.6 KiB
PHP
90 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Contracts\Executor;
|
|
use App\Cqs\Actions\Orders\CancelOrder;
|
|
use App\Cqs\Actions\Orders\CancelOrderInput;
|
|
use App\Cqs\Queries\Orders\GetBoOrderDetailQuery;
|
|
use App\Cqs\Queries\Orders\GetBoOrderDetailQueryInput;
|
|
use App\Cqs\Queries\Orders\GetBoPaginatedOrdersQuery;
|
|
use App\Cqs\Queries\Orders\GetBoTodayOrdersQuery;
|
|
use App\Cqs\Queries\Orders\GetBoTodayOrdersQueryInput;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\Orders\IndexOrdersRequest;
|
|
use App\Lib\Helpers\RequestHelper;
|
|
use App\Models\Order;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class OrdersController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly Executor $executor,
|
|
) {
|
|
}
|
|
|
|
public function index(IndexOrdersRequest $request, GetBoPaginatedOrdersQuery $query): View
|
|
{
|
|
$this->authorize('viewAny', Order::class);
|
|
|
|
$output = $this->executor->execute(
|
|
$query,
|
|
$request->toGetBoPaginatedOrdersQueryInput(),
|
|
);
|
|
|
|
return view('bo.orders.index', [
|
|
'orders' => $output->orders,
|
|
'searchFields' => $output->searchFields,
|
|
'orderStatusList' => $output->orderStatusList,
|
|
]);
|
|
}
|
|
|
|
public function today(Request $request, GetBoTodayOrdersQuery $query): View
|
|
{
|
|
$this->authorize('viewAnyToday', Order::class);
|
|
|
|
$orders = $this->executor->execute(
|
|
$query,
|
|
new GetBoTodayOrdersQueryInput(RequestHelper::pagination($request)),
|
|
);
|
|
|
|
return view('bo.orders.index-today', compact('orders'));
|
|
}
|
|
|
|
public function show(Order $order, GetBoOrderDetailQuery $query): View
|
|
{
|
|
$this->authorize('view', $order);
|
|
|
|
$output = $this->executor->execute(
|
|
$query,
|
|
new GetBoOrderDetailQueryInput($order),
|
|
);
|
|
|
|
return view('bo.orders.view', [
|
|
'order' => $output->order,
|
|
'shop' => $output->shop,
|
|
'employee' => $output->employee,
|
|
'crmCustomer' => $output->crmCustomer,
|
|
]);
|
|
}
|
|
|
|
public function cancel(Order $order, CancelOrder $action): RedirectResponse
|
|
{
|
|
$this->authorize('cancel', $order);
|
|
|
|
try {
|
|
$this->executor->execute(
|
|
$action,
|
|
new CancelOrderInput($order),
|
|
);
|
|
} catch (\Throwable) {
|
|
return back()->with('error', trans('Action failed'));
|
|
}
|
|
|
|
return back()->with('warning', trans('Order cancelled'));
|
|
}
|
|
}
|