|
|
@ -915,14 +915,28 @@ public function update(int $id) |
|
|
|
|
|
|
|
|
if ($role === 'COMMERCIALE') { |
|
|
if ($role === 'COMMERCIALE') { |
|
|
$paid_status = 2; |
|
|
$paid_status = 2; |
|
|
} else { |
|
|
} elseif ($role === 'Caissière') { |
|
|
$paid_status = $this->request->getPost('paid_status'); |
|
|
$paid_status = $this->request->getPost('paid_status'); |
|
|
|
|
|
} else { |
|
|
|
|
|
// SuperAdmin, Direction, DAF ne peuvent pas valider (paid_status=1) directement |
|
|
|
|
|
// Leur rôle est de valider les remises via la page remise/, pas les commandes |
|
|
|
|
|
$requested_status = (int)$this->request->getPost('paid_status'); |
|
|
|
|
|
$paid_status = ($requested_status == 1) ? $old_paid_status : $requested_status; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$validated_by = $current_order['validated_by'] ?? null; |
|
|
$validated_by = $current_order['validated_by'] ?? null; |
|
|
$validated_at = $current_order['validated_at'] ?? null; |
|
|
$validated_at = $current_order['validated_at'] ?? null; |
|
|
|
|
|
|
|
|
if ($old_paid_status != 1 && $paid_status == 1 && $role === 'Caissière') { |
|
|
if ($old_paid_status != 1 && $paid_status == 1 && $role === 'Caissière') { |
|
|
|
|
|
// ✅ Bloquer si la commande a une remise non encore approuvée par SuperAdmin |
|
|
|
|
|
$currentDiscount = (float)($current_order['discount'] ?? 0); |
|
|
|
|
|
if ($currentDiscount > 0) { |
|
|
|
|
|
$RemiseCheck = new Remise(); |
|
|
|
|
|
if (!$RemiseCheck->hasRemiseValidatedForOrder($id)) { |
|
|
|
|
|
session()->setFlashData('errors', 'Cette commande a une demande de remise en attente de validation par le SuperAdmin.'); |
|
|
|
|
|
return redirect()->to('orders/'); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
$validated_by = $user['id']; |
|
|
$validated_by = $user['id']; |
|
|
$validated_at = date('Y-m-d H:i:s'); |
|
|
$validated_at = date('Y-m-d H:i:s'); |
|
|
} |
|
|
} |
|
|
@ -1030,7 +1044,7 @@ public function update(int $id) |
|
|
$customer_name = $this->request->getPost('customer_name'); |
|
|
$customer_name = $this->request->getPost('customer_name'); |
|
|
$bill_no = $current_order['bill_no']; |
|
|
$bill_no = $current_order['bill_no']; |
|
|
|
|
|
|
|
|
// ✅ Notification SECURITE du store concerné |
|
|
// ✅ Notification SECURITE du store concerné (toujours) |
|
|
$Notification->createNotification( |
|
|
$Notification->createNotification( |
|
|
"Commande validée: {$bill_no} - Client: {$customer_name}", |
|
|
"Commande validée: {$bill_no} - Client: {$customer_name}", |
|
|
"SECURITE", |
|
|
"SECURITE", |
|
|
@ -1038,38 +1052,39 @@ public function update(int $id) |
|
|
'orders' |
|
|
'orders' |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// ✅ RÉCUPÉRER TOUS LES STORES |
|
|
// ✅ Notifier Direction, DAF, SuperAdmin UNIQUEMENT pour les commandes avec remise |
|
|
$Stores = new Stores(); |
|
|
if ((float)$discount > 0) { |
|
|
$allStores = $Stores->getActiveStore(); |
|
|
$Stores = new Stores(); |
|
|
|
|
|
$allStores = $Stores->getActiveStore(); |
|
|
$messageGlobal = "✅ Commande validée : {$bill_no}<br>" . |
|
|
|
|
|
"Store : " . $this->returnStore($user['store_id']) . "<br>" . |
|
|
$messageGlobal = "✅ Commande validée : {$bill_no}<br>" . |
|
|
"Client : {$customer_name}<br>" . |
|
|
"Store : " . $this->returnStore($user['store_id']) . "<br>" . |
|
|
"Validée par : {$user['firstname']} {$user['lastname']}"; |
|
|
"Client : {$customer_name}<br>" . |
|
|
|
|
|
"Validée par : {$user['firstname']} {$user['lastname']}"; |
|
|
// ✅ NOTIFIER DIRECTION, DAF, SUPERADMIN DE TOUS LES STORES |
|
|
|
|
|
if (is_array($allStores) && count($allStores) > 0) { |
|
|
if (is_array($allStores) && count($allStores) > 0) { |
|
|
foreach ($allStores as $store) { |
|
|
foreach ($allStores as $store) { |
|
|
$Notification->createNotification( |
|
|
$Notification->createNotification( |
|
|
$messageGlobal, |
|
|
$messageGlobal, |
|
|
"Direction", |
|
|
"Direction", |
|
|
(int)$store['id'], |
|
|
(int)$store['id'], |
|
|
'orders' |
|
|
'orders' |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
$Notification->createNotification( |
|
|
$Notification->createNotification( |
|
|
$messageGlobal, |
|
|
$messageGlobal, |
|
|
"DAF", |
|
|
"DAF", |
|
|
(int)$store['id'], |
|
|
(int)$store['id'], |
|
|
'orders' |
|
|
'orders' |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
$Notification->createNotification( |
|
|
$Notification->createNotification( |
|
|
$messageGlobal, |
|
|
$messageGlobal, |
|
|
"SuperAdmin", |
|
|
"SuperAdmin", |
|
|
(int)$store['id'], |
|
|
(int)$store['id'], |
|
|
'orders' |
|
|
'orders' |
|
|
); |
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|