From 94af725373d3ee2363a867cc5266b77b6e8366e7 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Fri, 20 Feb 2026 11:59:45 +0100 Subject: [PATCH] new: block order cancellation when invoice has payments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When changing an order status to « Annulé », check if the related invoice has any validated payments via ``Invoices::getPayments()``. If the total paid is greater than zero, the cancellation is refused with a growl error showing the amount already paid. --- .../Controllers/Admin/Shop/OrderController.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/Http/Controllers/Admin/Shop/OrderController.php b/app/Http/Controllers/Admin/Shop/OrderController.php index 0257ba8a..5a83cd2f 100644 --- a/app/Http/Controllers/Admin/Shop/OrderController.php +++ b/app/Http/Controllers/Admin/Shop/OrderController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin\Shop; use App\Datatables\Admin\Shop\OrdersDataTable; use App\Http\Controllers\Controller; +use App\Repositories\Shop\Invoices; use App\Repositories\Shop\OfferStocks; use App\Repositories\Shop\OrderMails; use App\Repositories\Shop\Orders; @@ -44,6 +45,20 @@ class OrderController extends Controller $newStatus = $request->input('status'); + // Interdire l'annulation si la facture a des paiements + if ($previousStatus != 4 && $newStatus == 4 && $request->has('id')) { + $order = Orders::get($request->input('id'), ['invoice']); + if ($order->invoice) { + $totalPaid = Invoices::getPayments($order->invoice->id); + if ($totalPaid > 0) { + return redirect()->back()->withInput()->with( + 'growl', + ['Impossible d\'annuler cette commande : la facture a déjà été réglée ('.number_format($totalPaid, 2, ',', ' ').' €). Veuillez d\'abord gérer le remboursement.', 'danger'] + ); + } + } + } + // Vérifier le stock avant de dés-annuler une commande if ($previousStatus == 4 && $newStatus != 4) { $insufficients = OfferStocks::checkStockForOrder($request->input('id'));