@ -421,7 +421,7 @@ class OrderController extends AdminController
for ($i = 0; $i < count ( $ product_id ) ; $ i + + ) {
$singleProduct = $product->getProductData($product_id[$i]);
if ($singleProduct['product_sold'] == true) {
$notification->createNotification("Produit en rupture de stock", "Direction ", $store_id, "products");
$notification->notifyGroupsByPermission('notifProduit', "Produit en rupture de stock ", $store_id, "products");
}
}
}
@ -448,20 +448,20 @@ class OrderController extends AdminController
$data['page_title'] = $this->pageTitle;
$validation = \Config\Services::validation();
$products = $this->request->getPost('product[] ');
$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',
'product' => 'required',
'customer_type' => 'required',
'source' => 'required'
]);
$validationData = [
'product[] ' => $this->request->getPost('product[] '),
'product' => $this->request->getPost('product'),
'customer_type' => $this->request->getPost('customer_type'),
'source' => $this->request->getPost('source')
];
@ -470,7 +470,7 @@ class OrderController extends AdminController
$Company = new Company();
$Products = new Products();
if ($this->request->getMethod() === 'post' & & $validation->run($validationData)) {
if (strtolower( $this->request->getMethod() ) === 'post' & & $validation->run($validationData)) {
$session = session();
$users = $session->get('user');
@ -479,11 +479,11 @@ class OrderController extends AdminController
$bill_no = $this->generateSimpleSequentialBillNo($users['store_id']);
$document_type = $this->request->getPost('document_type') ?? 'facture';
$posts = $this->request->getPost('product[] ');
$rates = $this->request->getPost('rate_value[] ');
$amounts = $this->request->getPost('amount_value[] ');
$puissances = $this->request->getPost('puissance[] ');
$quantities = $this->request->getPost('qty[] '); // ✅ RÉCUPÉRER LES QUANTITÉS
$posts = $this->request->getPost('product');
$rates = $this->request->getPost('rate_value');
$amounts = $this->request->getPost('amount_value');
$puissances = $this->request->getPost('puissance');
$quantities = $this->request->getPost('qty'); // ✅ RÉCUPÉRER LES QUANTITÉS
$discount = (float)$this->request->getPost('discount') ?? 0;
$gross_amount = $this->calculGross($amounts);
@ -599,10 +599,36 @@ class OrderController extends AdminController
if (isset($product['sku'], $product['price'])) {
$product_lines[] = $product['sku'] . ':' . $product['price'];
}
$product_info_lines[] = "• " . ($product['name'] ?? '-') .
" | N° Série : " . ($product['sku'] ?? '-') .
" | N° Moteur : " . ($product['numero_de_moteur'] ?? '-') .
" | Châssis : " . ($product['chasis'] ?? '-');
$name = $product['name'] ?? '-';
$sku = $product['sku'] ?? '-';
$moteur = $product['numero_de_moteur'] ?? '-';
$chasis = $product['chasis'] ?? '-';
$puissance= $product['puissance'] ?? '-';
$image = $product['image'] ?? '';
$imgUrl = base_url('assets/images/product_image/' . $image);
$details = htmlspecialchars(json_encode([
'name' => $name,
'sku' => $sku,
'moteur' => $moteur,
'chasis' => $chasis,
'puissance' => $puissance,
'image' => $image ? $imgUrl : '',
], JSON_UNESCAPED_UNICODE), ENT_QUOTES);
$imgTag = $image
? "< img src = '{$imgUrl}' style = 'width:50px;height:40px;object-fit:cover;border-radius:4px;margin-right:8px;vertical-align:middle;' alt = '{$name}' > "
: "< span style = 'display:inline-block;width:50px;height:40px;background:#eee;border-radius:4px;margin-right:8px;vertical-align:middle;text-align:center;line-height:40px;font-size:10px;color:#999;' > No img< / span > ";
$product_info_lines[] =
"< div style = 'display:flex;align-items:center;padding:4px 0;' > " .
$imgTag .
"< div style = 'flex:1;' > < strong > {$name}< / strong > < br > < small > N\u00b0 S\u00e9rie : {$sku}< / small > < / div > " .
"< button onclick = 'event.preventDefault();event.stopPropagation();showMotoDetails(this)' " .
"data-moto='{$details}' " .
"style='background:none;border:none;cursor:pointer;color:#3c8dbc;font-size:18px;padding:0 4px;' title='Voir d\u00e9tails'>" .
"< i class = 'fa fa-info-circle' > < / i > < / button > " .
"< / div > ";
}
$product_output = implode("\n", $product_lines);
@ -629,21 +655,15 @@ class OrderController extends AdminController
"Demandeur : {$users['firstname']} {$users['lastname']}< br > " .
implode("< br > ", $product_info_lines);
if (is_array($allStores) & & count($allStores) > 0) {
foreach ($allStores as $store) {
$Notification->createNotification($message, "SuperAdmin", (int)$store['id'], 'remise/');
$Notification->createNotification($message . "< br > < em > Pour information< / em > ", "Direction", (int)$store['id'], 'remise/');
$Notification->createNotification($message . "< br > < em > Pour information< / em > ", "DAF", (int)$store['id'], 'remise/');
}
}
$Notification->notifyGroupsByPermissionAllStores('notifRemise', $message, 'remise/');
} else {
// Commande sans remise
$Notification->createNotification(
$Notification->notifyGroupsByPermission(
'notifSortieCaisse',
"📦 Nouvelle commande à valider : {$bill_no}< br > " .
"Client : {$data['customer_name']}< br > " .
"Montant : " . number_format($gross_amount, 0, ',', ' ') . " Ar",
"Caissière",
(int)$users['store_id'],
"orders"
);
@ -744,31 +764,8 @@ public function markAsDelivered()
"Livrée par : {$users['firstname']} {$users['lastname']}< br > " .
"Date livraison : " . date('d/m/Y H:i');
// ✅ 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'
);
}
}
// ✅ NOTIFIER TOUS LES GROUPES AYANT validateCommande1
$Notification->notifyGroupsByPermissionAllStores('notifCommande', $messageGlobal, 'orders');
} catch (\Exception $e) {
// Si la notification échoue, on continue quand même
log_message('error', 'Erreur notification: ' . $e->getMessage());
@ -903,7 +900,7 @@ public function update(int $id)
$user = $session->get('user');
$role = $user['group_name'] ?? null;
if ($this->request->getMethod() === 'post' & & $validation->run($validationData)) {
if (strtolower( $this->request->getMethod() ) === 'post' & & $validation->run($validationData)) {
$current_order_check = $Orders->getOrdersData($id);
if (in_array($current_order_check['paid_status'], [1, 3])) {
@ -1030,10 +1027,10 @@ public function update(int $id)
$customer_name = $this->request->getPost('customer_name');
$bill_no = $current_order['bill_no'];
// ✅ Notification SECURITE du store concerné
$Notification->createNotification(
// ✅ Notification groupes ayant createSecurite
$Notification->notifyGroupsByPermission(
'notifSecurite',
"Commande validée: {$bill_no} - Client: {$customer_name}",
"SECURITE",
(int)$user['store_id'],
'orders'
);
@ -1047,31 +1044,8 @@ public function update(int $id)
"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) {
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'
);
}
}
// ✅ NOTIFIER TOUS LES GROUPES AYANT validateCommande1
$Notification->notifyGroupsByPermissionAllStores('notifCommande', $messageGlobal, 'orders');
}
if ((float)$discount > 0) {
@ -1113,13 +1087,7 @@ public function update(int $id)
"Store : " . $this->returnStore($user['store_id']) . "< br > " .
"Demandeur : {$user['firstname']} {$user['lastname']}";
if (is_array($allStores) & & count($allStores) > 0) {
foreach ($allStores as $store) {
$Notification->createNotification($message, "SuperAdmin", (int)$store['id'], 'remise/');
$Notification->createNotification($message . "< br > < em > Pour information< / em > ", "Direction", (int)$store['id'], 'remise/');
$Notification->createNotification($message . "< br > < em > Pour information< / em > ", "DAF", (int)$store['id'], 'remise/');
}
}
$Notification->notifyGroupsByPermissionAllStores('notifRemise', $message, 'remise/');
}
session()->setFlashData('success', 'Commande mise à jour avec succès.');