new: block order cancellation when invoice has payments
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.
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin\Shop;
|
|||||||
|
|
||||||
use App\Datatables\Admin\Shop\OrdersDataTable;
|
use App\Datatables\Admin\Shop\OrdersDataTable;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Repositories\Shop\Invoices;
|
||||||
use App\Repositories\Shop\OfferStocks;
|
use App\Repositories\Shop\OfferStocks;
|
||||||
use App\Repositories\Shop\OrderMails;
|
use App\Repositories\Shop\OrderMails;
|
||||||
use App\Repositories\Shop\Orders;
|
use App\Repositories\Shop\Orders;
|
||||||
@@ -44,6 +45,20 @@ class OrderController extends Controller
|
|||||||
|
|
||||||
$newStatus = $request->input('status');
|
$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
|
// Vérifier le stock avant de dés-annuler une commande
|
||||||
if ($previousStatus == 4 && $newStatus != 4) {
|
if ($previousStatus == 4 && $newStatus != 4) {
|
||||||
$insufficients = OfferStocks::checkStockForOrder($request->input('id'));
|
$insufficients = OfferStocks::checkStockForOrder($request->input('id'));
|
||||||
|
|||||||
Reference in New Issue
Block a user