diff --git a/app/Controllers/AvanceController.php b/app/Controllers/AvanceController.php
index fe00e709..f09b1181 100644
--- a/app/Controllers/AvanceController.php
+++ b/app/Controllers/AvanceController.php
@@ -31,7 +31,7 @@ class AvanceController extends AdminController
private function isAdmin($user)
{
- return in_array($user['group_name'], ['Conseil', 'Direction']);
+ return in_array($user['group_name'], ['SuperAdmin','DAF','Direction']);
}
private function isCommerciale($user)
@@ -50,7 +50,7 @@ private function buildActionButtons($value, $isAdmin, $isOwner, $isCaissier = fa
{
$session = session();
$users = $session->get('user');
- $isDirection = in_array($users['group_name'], ['Direction', 'Conseil']);
+ $isDirection = in_array($users['group_name'], ['Direction', 'SuperAdmin','DAF']);
$buttons = '';
@@ -468,15 +468,49 @@ public function fetchExpiredAvance()
$Products->update($data['product_id'], ['product_sold' => 1]);
}
- // ✅ NOUVELLE FONCTIONNALITÉ : Envoyer notification au Conseil
- $Notification->createNotification(
- 'Une nouvelle avance a été créée',
- "DAF",
- (int)$users['store_id'],
- 'avances'
- );
+ // ✅ MODIFICATION PRINCIPALE : Envoyer notifications à TOUS les stores
+ $db = \Config\Database::connect();
+
+ // Récupérer tous les stores
+ $storesQuery = $db->table('stores')->select('id')->get();
+ $allStores = $storesQuery->getResultArray();
+
+ $customerName = $this->request->getPost('customer_name_avance');
+ $avanceAmount = number_format((float)$this->request->getPost('avance_amount'), 0, ',', ' ');
+ $typeAvanceLabel = $type_avance === 'terre' ? 'SUR TERRE' : 'SUR MER';
+
+ $notificationMessage = "Nouvelle avance {$typeAvanceLabel} créée par {$users['firstname']} {$users['lastname']} - Client: {$customerName} - Montant: {$avanceAmount} Ar";
+
+ // ✅ Envoyer notification à DAF, Direction et SuperAdmin de TOUS les stores
+ foreach ($allStores as $store) {
+ $storeId = (int)$store['id'];
+
+ // Notification pour DAF
+ $Notification->createNotification(
+ $notificationMessage,
+ "DAF",
+ $storeId,
+ 'avances'
+ );
+
+ // Notification pour Direction
+ $Notification->createNotification(
+ $notificationMessage,
+ "Direction",
+ $storeId,
+ 'avances'
+ );
+
+ // Notification pour SuperAdmin
+ $Notification->createNotification(
+ $notificationMessage,
+ "SuperAdmin",
+ $storeId,
+ 'avances'
+ );
+ }
- // ✅ NOUVELLE FONCTIONNALITÉ : Envoyer notification à la Caissière si l'utilisateur est COMMERCIALE
+ // ✅ Notification à la Caissière UNIQUEMENT du store concerné (si l'utilisateur est COMMERCIALE)
if ($this->isCommerciale($users)) {
$Notification->createNotification(
'Une nouvelle avance a été créée par un commercial',
@@ -486,6 +520,8 @@ public function fetchExpiredAvance()
);
}
+ log_message('info', "✅ Avance {$avance_id} créée - Notifications envoyées à DAF/Direction/SuperAdmin de tous les stores");
+
return $this->response->setJSON([
'success' => true,
'messages' => 'Avance créée avec succès !',
@@ -505,7 +541,6 @@ public function fetchExpiredAvance()
]);
}
}
-
public function updateAvance()
{
@@ -1139,7 +1174,7 @@ public function getInvoicePreview($avance_id)
$users = $session->get('user');
$isCaissier = $this->isCaissier($users);
- $isDirection = in_array($users['group_name'], ['Direction', 'Conseil']);
+ $isDirection = in_array($users['group_name'], ['Direction', 'SuperAdmin','DAF']);
if (!$isCaissier && !$isDirection) {
return $this->response->setJSON([
@@ -1500,6 +1535,13 @@ public function notifyPrintInvoice()
(int)$users['store_id'],
'avances'
);
+
+ $Notification->createNotification(
+ "Il y a une avance N°{$avanceNumber} pour le client {$customerName}",
+ "SuperAdmin",
+ (int)$users['store_id'],
+ 'avances'
+ );
return $this->response->setJSON([
'success' => true,
diff --git a/app/Controllers/Dashboard.php b/app/Controllers/Dashboard.php
index f499c8dd..42d37f73 100644
--- a/app/Controllers/Dashboard.php
+++ b/app/Controllers/Dashboard.php
@@ -136,7 +136,7 @@ class Dashboard extends AdminController
$data['total_products'] = $productModel->countProductsByUserStore();
// === ✅ Récupérer le nom du store pour l'affichage ===
- $isAdmin = in_array($user_id['group_name'], ['DAF', 'Direction']);
+ $isAdmin = in_array($user_id['group_name'], ['DAF', 'Direction','SuperAdmin']);
if (!$isAdmin && !empty($user_id['store_id']) && $user_id['store_id'] != 0) {
$store = $storeModel->getStoresData($user_id['store_id']);
@@ -219,7 +219,7 @@ class Dashboard extends AdminController
$data['isMecanicien'] = false;
$data['isSecurite'] = false;
- if ($user_id['group_name'] == "Direction" || $user_id['group_name'] == "DAF") {
+ if ($user_id['group_name'] == "Direction" || $user_id['group_name'] == "DAF" || $user_id['group_name'] == "SuperAdmin") {
$data['is_admin'] = true;
}
diff --git a/app/Controllers/MecanicienController.php b/app/Controllers/MecanicienController.php
index 49d3c154..bf3aeecd 100644
--- a/app/Controllers/MecanicienController.php
+++ b/app/Controllers/MecanicienController.php
@@ -319,7 +319,7 @@ class MecanicienController extends AdminController
// Iterate through the data
- if($users['group_name'] == "Conseil" || $users['group_name'] == "Direction"){
+ if($users['group_name'] == "SuperAdmin" || $users['group_name'] == "Direction"){
foreach ($reparation as $key => $repa) {
$image = '
';
$produit = esc($repa['name']);
diff --git a/app/Controllers/OrderController.php b/app/Controllers/OrderController.php
index 07218c0b..8015e0d1 100644
--- a/app/Controllers/OrderController.php
+++ b/app/Controllers/OrderController.php
@@ -107,11 +107,11 @@ class OrderController extends AdminController
// Statut de paiement
if ($value['paid_status'] == 1) {
- $paid_status = 'Validé';
+ $paid_status = 'payé';
} elseif ($value['paid_status'] == 2) {
$paid_status = 'En Attente';
} elseif ($value['paid_status'] == 3) {
- $paid_status = 'Validé et Livré';
+ $paid_status = 'payé et Livré';
} else {
$paid_status = 'Refusé';
}
@@ -149,7 +149,7 @@ class OrderController extends AdminController
// ========================================
// POUR DIRECTION OU DAF
// ========================================
- elseif($users['group_name'] == "Direction" || $users['group_name'] == "DAF"){
+ elseif($users['group_name'] == "Direction" || $users['group_name'] == "DAF" || $users['group_name'] == "SuperAdmin" ){
foreach ($data as $key => $value) {
$date_time = date('d-m-Y h:i a', strtotime($value['date_time']));
@@ -172,11 +172,11 @@ class OrderController extends AdminController
// Statut de paiement
if ($value['paid_status'] == 1) {
- $paid_status = 'Validé';
+ $paid_status = 'payé';
} elseif ($value['paid_status'] == 2) {
$paid_status = 'En Attente';
} elseif ($value['paid_status'] == 3) {
- $paid_status = 'Validé et Livré';
+ $paid_status = 'Payé et Livré';
} else {
$paid_status = 'Refusé';
}
@@ -255,11 +255,11 @@ class OrderController extends AdminController
// Statut de paiement
if ($value['paid_status'] == 1) {
- $paid_status = 'Validé';
+ $paid_status = 'Payé';
} elseif ($value['paid_status'] == 2) {
$paid_status = 'En Attente';
} elseif ($value['paid_status'] == 3) {
- $paid_status = 'Validé et Livré';
+ $paid_status = 'Payé et Livré';
} else {
$paid_status = 'Refusé';
}
@@ -331,211 +331,281 @@ class OrderController extends AdminController
- public function create()
- {
- $this->verifyRole('createOrder');
- $data['page_title'] = $this->pageTitle;
-
- $validation = \Config\Services::validation();
- $products = $this->request->getPost('product[]');
-
- if ($products !== null && (count($products) !== count(array_unique($products)))) {
- return redirect()->back()->withInput()->with('errors', ['product' => 'Chaque produit sélectionné doit être unique.']);
+/**
+ * ✅ AMÉLIORATION : Notifications centralisées pour Direction/DAF/SuperAdmin (tous stores)
+ */
+
+public function create()
+{
+ $this->verifyRole('createOrder');
+ $data['page_title'] = $this->pageTitle;
+
+ $validation = \Config\Services::validation();
+ $products = $this->request->getPost('product[]');
+
+ if ($products !== null && (count($products) !== count(array_unique($products)))) {
+ return redirect()->back()->withInput()->with('errors', ['product' => 'Chaque produit sélectionné doit être unique.']);
+ }
+
+ $validation->setRules([
+ 'product[]' => 'required',
+ 'customer_type' => 'required',
+ 'source' => 'required'
+ ]);
+
+ $validationData = [
+ 'product[]' => $this->request->getPost('product[]'),
+ 'customer_type' => $this->request->getPost('customer_type'),
+ 'source' => $this->request->getPost('source')
+ ];
+
+ $Orders = new Orders();
+ $Company = new Company();
+ $Products = new Products();
+
+ if ($this->request->getMethod() === 'post' && $validation->run($validationData)) {
+
+ $session = session();
+ $users = $session->get('user');
+ $user_id = $users['id'];
+
+ $bill_no = $this->generateBillNo($users['store_id']);
+
+ $posts = $this->request->getPost('product[]');
+ $rates = $this->request->getPost('rate_value[]');
+ $amounts = $this->request->getPost('amount_value[]');
+ $puissances = $this->request->getPost('puissance[]');
+ $discount = (float)$this->request->getPost('discount') ?? 0;
+ $gross_amount = $this->calculGross($amounts);
+
+ // Vérification prix minimal SI rabais existe
+ if ($discount > 0) {
+ $FourchettePrix = new \App\Models\FourchettePrix();
+
+ foreach ($posts as $index => $productId) {
+ $productId = (int)$productId;
+
+ $productData = $Products->getProductData($productId);
+ $fourchette = $FourchettePrix->getFourchettePrixByProductId($productId);
+
+ if ($fourchette) {
+ $prixMinimal = (float)$fourchette['prix_minimal'];
+
+ if ($discount < $prixMinimal) {
+ $prixMinimalFormatted = number_format($prixMinimal, 0, ',', ' ');
+ $discountFormatted = number_format($discount, 0, ',', ' ');
+
+ return redirect()->back()
+ ->withInput()
+ ->with('errors', [
+ "⚠️ Commande bloquée : Le rabais de {$discountFormatted} Ar pour « {$productData['name']} » est trop élevé."
+ ]);
+ }
+ }
+ }
}
-
- // ✅ AJOUT DES RÈGLES DE VALIDATION
- $validation->setRules([
- 'product[]' => 'required',
- 'customer_type' => 'required',
- 'source' => 'required'
- ]);
-
- // ✅ AJOUT DES DONNÉES DE VALIDATION
- $validationData = [
- 'product[]' => $this->request->getPost('product[]'),
- 'customer_type' => $this->request->getPost('customer_type'),
- 'source' => $this->request->getPost('source')
+
+ $montant_a_payer = ($discount > 0) ? $discount : $gross_amount;
+
+ $tranche_1 = (float)$this->request->getPost('tranche_1') ?? 0;
+ $tranche_2 = (float)$this->request->getPost('tranche_2') ?? 0;
+
+ if ($tranche_1 > 0 && $tranche_2 > 0) {
+ $net_amount = $tranche_1 + $tranche_2;
+ } else {
+ $net_amount = $montant_a_payer;
+ }
+
+ $data = [
+ 'bill_no' => $bill_no,
+ 'customer_name' => $this->request->getPost('customer_name'),
+ 'customer_address' => $this->request->getPost('customer_address'),
+ 'customer_phone' => $this->request->getPost('customer_phone'),
+ 'customer_cin' => $this->request->getPost('customer_cin'),
+ 'customer_type' => $this->request->getPost('customer_type'),
+ 'source' => $this->request->getPost('source'),
+ 'date_time' => date('Y-m-d H:i:s'),
+ 'service_charge_rate' => 0,
+ 'vat_charge_rate' => 0,
+ 'vat_charge' => 0,
+ 'net_amount' => $net_amount,
+ 'discount' => $discount,
+ 'paid_status' => 2,
+ 'user_id' => $user_id,
+ 'amount_value' => $amounts,
+ 'gross_amount' => $gross_amount,
+ 'rate_value' => $rates,
+ 'puissance' => $puissances,
+ 'store_id' => $users['store_id'],
+ 'tranche_1' => $tranche_1,
+ 'tranche_2' => $tranche_2,
+ 'order_payment_mode' => $this->request->getPost('order_payment_mode_1'),
+ 'order_payment_mode_1' => $this->request->getPost('order_payment_mode_2')
];
-
- $Orders = new Orders();
- $Company = new Company();
- $Products = new Products();
-
- if ($this->request->getMethod() === 'post' && $validation->run($validationData)) {
-
- $session = session();
- $users = $session->get('user');
- $user_id = $users['id'];
-
- $bill_no = $this->generateBillNo($users['store_id']);
-
- // Récupération des produits
- $posts = $this->request->getPost('product[]');
- $rates = $this->request->getPost('rate_value[]');
- $amounts = $this->request->getPost('amount_value[]');
- $puissances = $this->request->getPost('puissance[]');
- $discount = (float)$this->request->getPost('discount') ?? 0;
- $gross_amount = $this->calculGross($amounts);
-
- // Vérification prix minimal SI rabais existe
+
+ $order_id = $Orders->create($data, $posts);
+
+ if ($order_id) {
+ session()->setFlashdata('success', 'Créé avec succès');
+
+ $Notification = new NotificationController();
+ $Stores = new Stores();
+
if ($discount > 0) {
- $FourchettePrix = new \App\Models\FourchettePrix();
-
- foreach ($posts as $index => $productId) {
- $productId = (int)$productId;
-
- $productData = $Products->getProductData($productId);
- $fourchette = $FourchettePrix->getFourchettePrixByProductId($productId);
-
- if ($fourchette) {
- $prixMinimal = (float)$fourchette['prix_minimal'];
-
- if ($discount < $prixMinimal) {
- $prixMinimalFormatted = number_format($prixMinimal, 0, ',', ' ');
- $discountFormatted = number_format($discount, 0, ',', ' ');
-
- return redirect()->back()
- ->withInput()
- ->with('errors', [
- "⚠️ Commande bloquée : Le rabais de {$discountFormatted} Ar pour « {$productData['name']} » est trop élevé."
- ]);
- }
- }
+ // ✅ DEMANDE DE REMISE : NOTIFIER TOUS LES STORES
+ $Order_item1 = new OrderItems();
+ $order_item_data = $Order_item1->getOrdersItemData($order_id);
+ $product_ids = array_column($order_item_data, 'product_id');
+
+ $productData = new Products();
+ $product_data_results = [];
+
+ foreach ($product_ids as $prod_id) {
+ $id = (int) $prod_id;
+ $product_data_results[] = $productData->getProductData($id);
}
- }
-
- // Calculer le montant à payer et net_amount
- $montant_a_payer = ($discount > 0) ? $discount : $gross_amount;
-
- $tranche_1 = (float)$this->request->getPost('tranche_1') ?? 0;
- $tranche_2 = (float)$this->request->getPost('tranche_2') ?? 0;
-
- if ($tranche_1 > 0 && $tranche_2 > 0) {
- $net_amount = $tranche_1 + $tranche_2;
- } else {
- $net_amount = $montant_a_payer;
- }
-
- // ✅ AJOUT DES NOUVEAUX CHAMPS ICI
- $data = [
- 'bill_no' => $bill_no,
- 'customer_name' => $this->request->getPost('customer_name'),
- 'customer_address' => $this->request->getPost('customer_address'),
- 'customer_phone' => $this->request->getPost('customer_phone'),
- 'customer_cin' => $this->request->getPost('customer_cin'),
- 'customer_type' => $this->request->getPost('customer_type'), // ✅ NOUVEAU
- 'source' => $this->request->getPost('source'), // ✅ NOUVEAU
- 'date_time' => date('Y-m-d H:i:s'),
- 'service_charge_rate' => 0,
- 'vat_charge_rate' => 0,
- 'vat_charge' => 0,
- 'net_amount' => $net_amount,
- 'discount' => $discount,
- 'paid_status' => 2,
- 'user_id' => $user_id,
- 'amount_value' => $amounts,
- 'gross_amount' => $gross_amount,
- 'rate_value' => $rates,
- 'puissance' => $puissances,
- 'store_id' => $users['store_id'],
- 'tranche_1' => $tranche_1,
- 'tranche_2' => $tranche_2,
- 'order_payment_mode' => $this->request->getPost('order_payment_mode_1'),
- 'order_payment_mode_1' => $this->request->getPost('order_payment_mode_2')
- ];
-
- $order_id = $Orders->create($data, $posts);
-
- if ($order_id) {
- session()->setFlashdata('success', 'Créé avec succès');
-
- $Notification = new NotificationController();
-
- if ($discount > 0) {
- // Logique demande de remise...
- $Order_item1 = new OrderItems();
- $order_item_data = $Order_item1->getOrdersItemData($order_id);
- $product_ids = array_column($order_item_data, 'product_id');
-
- $productData = new Products();
- $product_data_results = [];
-
- foreach ($product_ids as $prod_id) {
- $id = (int) $prod_id;
- $product_data_results[] = $productData->getProductData($id);
- }
-
- $product_lines = [];
- foreach ($product_data_results as $product) {
- if (isset($product['sku'], $product['price'])) {
- $sku = $product['sku'];
- $price = $product['price'];
- $product_lines[] = "{$sku}:{$price}";
- }
+
+ $product_lines = [];
+ foreach ($product_data_results as $product) {
+ if (isset($product['sku'], $product['price'])) {
+ $sku = $product['sku'];
+ $price = $product['price'];
+ $product_lines[] = "{$sku}:{$price}";
}
-
- $product_output = implode("\n", $product_lines);
-
- $data1 = [
- 'date_demande' => date('Y-m-d H:i:s'),
- 'montant_demande' => $discount,
- 'total_price' => $amounts,
- 'id_store' => $users['store_id'],
- 'id_order' => $order_id,
- 'product' => $product_output,
- 'demande_status' => 'En attente'
- ];
-
- $Remise = new Remise();
- $id_remise = $Remise->addDemande($data1);
-
- $Notification->createNotification(
- "Nouvelle demande de remise à valider - Commande " . $bill_no,
- "Direction",
- (int)$users['store_id'],
- "remise/"
- );
-
- } else {
- $Notification->createNotification(
- "Nouvelle commande à valider - " . $bill_no,
- "Caissière",
- (int)$users['store_id'],
- "orders"
- );
}
-
- if ($users["group_name"] != "COMMERCIALE") {
- $this->checkProductisNull($posts, $users['store_id']);
+
+ $product_output = implode("\n", $product_lines);
+
+ $data1 = [
+ 'date_demande' => date('Y-m-d H:i:s'),
+ 'montant_demande' => $discount,
+ 'total_price' => $amounts,
+ 'id_store' => $users['store_id'],
+ 'id_order' => $order_id,
+ 'product' => $product_output,
+ 'demande_status' => 'En attente'
+ ];
+
+ $Remise = new Remise();
+ $id_remise = $Remise->addDemande($data1);
+
+ // ✅ RÉCUPÉRER TOUS LES STORES
+ $allStores = $Stores->getActiveStore();
+
+ $montantFormatted = number_format($discount, 0, ',', ' ');
+ $message = "💰 Nouvelle demande de remise : {$montantFormatted} Ar
" .
+ "Commande : {$bill_no}
" .
+ "Store : " . $this->returnStore($users['store_id']) . "
" .
+ "Demandeur : {$users['firstname']} {$users['lastname']}";
+
+ // ✅ NOTIFIER SUPERADMIN, DIRECTION, DAF DE TOUS LES STORES
+ if (is_array($allStores) && count($allStores) > 0) {
+ foreach ($allStores as $store) {
+ // SuperAdmin (validation)
+ $Notification->createNotification(
+ $message,
+ "SuperAdmin",
+ (int)$store['id'],
+ 'remise/'
+ );
+
+ // Direction (consultation)
+ $Notification->createNotification(
+ $message . "
Pour information",
+ "Direction",
+ (int)$store['id'],
+ 'remise/'
+ );
+
+ // DAF (consultation)
+ $Notification->createNotification(
+ $message . "
Pour information",
+ "DAF",
+ (int)$store['id'],
+ 'remise/'
+ );
+ }
}
- return redirect()->to('orders/');
} else {
- session()->setFlashdata('errors', 'Error occurred!!');
- return redirect()->to('orders/create/');
+ // ✅ COMMANDE SANS REMISE : NOTIFIER CAISSIÈRE DU STORE + TOUS LES CENTRAUX
+
+ // Caissière du store concerné
+ $Notification->createNotification(
+ "📦 Nouvelle commande à valider : {$bill_no}
" .
+ "Client : {$data['customer_name']}
" .
+ "Montant : " . number_format($gross_amount, 0, ',', ' ') . " Ar",
+ "Caissière",
+ (int)$users['store_id'],
+ "orders"
+ );
+
+ // ✅ RÉCUPÉRER TOUS LES STORES
+ $allStores = $Stores->getActiveStore();
+
+ $messageGlobal = "📋 Nouvelle commande créée : {$bill_no}
" .
+ "Store : " . $this->returnStore($users['store_id']) . "
" .
+ "Client : {$data['customer_name']}
" .
+ "Montant : " . number_format($gross_amount, 0, ',', ' ') . " Ar
" .
+ "Créée par : {$users['firstname']} {$users['lastname']}";
+
+ // ✅ NOTIFIER DIRECTION, DAF, SUPERADMIN DE TOUS LES STORES
+ if (is_array($allStores) && count($allStores) > 0) {
+ foreach ($allStores as $store) {
+ $Notification->createNotification(
+ $messageGlobal,
+ "Direction",
+ (int)$store['id'],
+ 'orders'
+ );
+
+ $Notification->createNotification(
+ $messageGlobal,
+ "DAF",
+ (int)$store['id'],
+ 'orders'
+ );
+
+ $Notification->createNotification(
+ $messageGlobal,
+ "SuperAdmin",
+ (int)$store['id'],
+ 'orders'
+ );
+ }
+ }
}
+
+ if ($users["group_name"] != "COMMERCIALE") {
+ $this->checkProductisNull($posts, $users['store_id']);
+ }
+ return redirect()->to('orders/');
} else {
- // Affichage du formulaire
- $company = $Company->getCompanyData(1);
- $session = session();
- $users = $session->get('user');
- $store_id = $users['store_id'];
-
- $data = [
- 'paid_status' => 2,
- 'company_data' => $company,
- 'is_vat_enabled' => ($company['vat_charge_value'] > 0),
- 'is_service_enabled' => ($company['service_charge_value'] > 0),
- 'products' => $Products->getProductData2($store_id),
- 'validation' => $validation,
- 'page_title' => $this->pageTitle,
- ];
-
- return $this->render_template('orders/create', $data);
+ session()->setFlashdata('errors', 'Error occurred!!');
+ return redirect()->to('orders/create/');
}
+
+ } else {
+ // Affichage du formulaire
+ $company = $Company->getCompanyData(1);
+ $session = session();
+ $users = $session->get('user');
+ $store_id = $users['store_id'];
+
+ $data = [
+ 'paid_status' => 2,
+ 'company_data' => $company,
+ 'is_vat_enabled' => ($company['vat_charge_value'] > 0),
+ 'is_service_enabled' => ($company['service_charge_value'] > 0),
+ 'products' => $Products->getProductData2($store_id),
+ 'validation' => $validation,
+ 'page_title' => $this->pageTitle,
+ ];
+
+ return $this->render_template('orders/create', $data);
}
-
+}
/**
* Marquer une commande comme livrée
* Accessible uniquement par le rôle SECURITE
@@ -583,15 +653,42 @@ public function markAsDelivered()
$updated = $Orders->update((int)$order_id, ['paid_status' => 3]);
if ($updated) {
- // Créer une notification
+ // ✅ Créer une notification centralisée pour tous les stores
try {
$Notification = new NotificationController();
- $Notification->createNotification(
- "Commande " . $current_order['bill_no'] . " livrée avec succès",
- "Direction",
- (int)$current_order['store_id'],
- "orders"
- );
+ $Stores = new Stores();
+ $allStores = $Stores->getActiveStore();
+
+ $messageGlobal = "📦 Commande livrée : {$current_order['bill_no']}
" .
+ "Store : " . $this->returnStore($current_order['store_id']) . "
" .
+ "Client : {$current_order['customer_name']}
" .
+ "Livrée par : {$users['firstname']} {$users['lastname']}";
+
+ // ✅ NOTIFIER DIRECTION, DAF, SUPERADMIN DE TOUS LES STORES
+ if (is_array($allStores) && count($allStores) > 0) {
+ foreach ($allStores as $store) {
+ $Notification->createNotification(
+ $messageGlobal,
+ "Direction",
+ (int)$store['id'],
+ 'orders'
+ );
+
+ $Notification->createNotification(
+ $messageGlobal,
+ "DAF",
+ (int)$store['id'],
+ 'orders'
+ );
+
+ $Notification->createNotification(
+ $messageGlobal,
+ "SuperAdmin",
+ (int)$store['id'],
+ 'orders'
+ );
+ }
+ }
} catch (\Exception $e) {
// Si la notification échoue, on continue quand même
log_message('error', 'Erreur notification: ' . $e->getMessage());
@@ -611,7 +708,6 @@ public function markAsDelivered()
return $this->response->setJSON($response);
}
-
public function getProductValueById()
{
$product_id = $this->request->getPost('product_id');
@@ -793,10 +889,12 @@ public function update(int $id)
$Notification = new NotificationController();
+ // ✅ NOTIFICATION CENTRALISÉE POUR VALIDATION
if ($old_paid_status == 2 && $paid_status == 1) {
$customer_name = $this->request->getPost('customer_name');
$bill_no = $current_order['bill_no'];
+ // ✅ Notification SECURITE du store concerné
$Notification->createNotification(
"Commande validée: {$bill_no} - Client: {$customer_name}",
"SECURITE",
@@ -804,13 +902,39 @@ public function update(int $id)
'orders'
);
- if ($role === 'Caissière') {
- $Notification->createNotification(
- "Commande validée par la caisse: {$bill_no}",
- "Direction",
- (int)$user['store_id'],
- 'orders'
- );
+ // ✅ RÉCUPÉRER TOUS LES STORES
+ $Stores = new Stores();
+ $allStores = $Stores->getActiveStore();
+
+ $messageGlobal = "✅ Commande validée : {$bill_no}
" .
+ "Store : " . $this->returnStore($user['store_id']) . "
" .
+ "Client : {$customer_name}
" .
+ "Validée par : {$user['firstname']} {$user['lastname']}";
+
+ // ✅ NOTIFIER DIRECTION, DAF, SUPERADMIN DE TOUS LES STORES
+ if (is_array($allStores) && count($allStores) > 0) {
+ foreach ($allStores as $store) {
+ $Notification->createNotification(
+ $messageGlobal,
+ "Direction",
+ (int)$store['id'],
+ 'orders'
+ );
+
+ $Notification->createNotification(
+ $messageGlobal,
+ "DAF",
+ (int)$store['id'],
+ 'orders'
+ );
+
+ $Notification->createNotification(
+ $messageGlobal,
+ "SuperAdmin",
+ (int)$store['id'],
+ 'orders'
+ );
+ }
}
}
@@ -973,7 +1097,7 @@ public function update(int $id)
$html = '';
// Vérifier si l'utilisateur a payé
if ($order_data['paid_status'] == 1) {
- $paid_status = "Validé";
+ $paid_status = "Payé";
} elseif ($order_data['paid_status'] == 2) {
$paid_status = "En Attente";
} else {
@@ -1460,7 +1584,7 @@ public function update(int $id)
$company_info = $Company->getCompanyData(1);
$paid_status = $order_data['paid_status'] == 1
- ? "Validé"
+ ? "Payé"
: "Refusé";
// STYLE COMMUN
@@ -2484,7 +2608,7 @@ public function print31(int $id)
}
$paid_status = $order_data['paid_status'] === 1
- ? "Validé"
+ ? "Payé"
: "Refusé";
// Calculs globaux
@@ -2773,4 +2897,4 @@ public function print31(int $id)
echo '