diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 27fc28b3..4a97066f 100644
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -226,7 +226,7 @@ $routes->group('', ['filter' => 'auth'], function ($routes) {
$routes->get('detail/stock', [ReportController::class, 'stockDetail']);
// Corrections fetct → fetch
- $routes->get('detail/fetchData/(:num)', [ReportController::class, 'fetchProductSold/$1']);
+ $routes->get('detail/fetchData/(:num)', [ReportController::class, 'fetchProductSodled/$1']);
$routes->get('detail/fetchDataStock/(:num)', [ReportController::class, 'fetchProductStock/$1']);
$routes->get('detail/fetchDataStock2/(:num)', [ReportController::class, 'fetchProductStock2/$1']);
diff --git a/app/Controllers/AdminController.php b/app/Controllers/AdminController.php
index 36e13482..c482e939 100644
--- a/app/Controllers/AdminController.php
+++ b/app/Controllers/AdminController.php
@@ -24,7 +24,7 @@ abstract class AdminController extends BaseController
$group_data = $Groups->getUserGroupByUserId($userId);
$this->permission = unserialize($group_data['permission']);
-
+
}
}
diff --git a/app/Controllers/Auth.php b/app/Controllers/Auth.php
index f990c17a..c956c3a1 100644
--- a/app/Controllers/Auth.php
+++ b/app/Controllers/Auth.php
@@ -129,7 +129,8 @@ public function loginPost()
$buttons .= " ";
}
- if (is_array($this->permission) && in_array('createOrder', $this->permission)) {
+ $productSoldStatus = (int)($value['product_sold'] ?? 0);
+ if (is_array($this->permission) && in_array('createOrder', $this->permission) && $productSoldStatus === 0) {
$buttons .= ($value['qty'] == 1)
? " "
: " ";
@@ -139,6 +140,16 @@ public function loginPost()
$img = '';
+ // Statut basé sur product_sold
+ $productSold = (int)($value['product_sold'] ?? 0);
+ if ($productSold === 2) {
+ $statut = 'En attente de livraison';
+ } elseif ($productSold === 1) {
+ $statut = 'Livré';
+ } else {
+ $statut = 'Disponible';
+ }
+
// Populate the result data
$result['data'][] = [
$img,
@@ -147,6 +158,7 @@ public function loginPost()
number_format($value['prix_vente'], 0, ',', ' '),
$value['puissance'] . ' CC',
$value['numero_de_moteur'],
+ $statut,
$buttons
];
}
diff --git a/app/Controllers/AvanceController.php b/app/Controllers/AvanceController.php
index 96df98b7..a18f9868 100644
--- a/app/Controllers/AvanceController.php
+++ b/app/Controllers/AvanceController.php
@@ -116,21 +116,23 @@ private function buildDataRow($value, $product, $isAdmin, $isCommerciale, $isCai
{
$date_time = date('d-m-Y h:i a', strtotime($value['avance_date']));
- // ✅ Gestion sécurisée du nom du produit
+ // Gestion du nom du produit et numéro de série
+ $productSku = '';
if ($value['type_avance'] === 'mere') {
$productName = $value['product_name'] ?? 'Produit sur mer';
} else {
- $productName = !empty($value['product_name'])
- ? $value['product_name']
- : $product->getProductNameById($value['product_id'] ?? 0);
+ $productData = !empty($value['product_id']) ? $product->find($value['product_id']) : null;
+ $productName = $productData['name'] ?? ($value['product_name'] ?? 'N/A');
+ $productSku = $productData['sku'] ?? '';
}
-
+
if ($isAdmin) {
return [
$value['customer_name'],
$value['customer_phone'],
$value['customer_address'],
$productName,
+ $productSku,
number_format((int)$value['gross_amount'], 0, ',', ' '),
number_format((int)$value['avance_amount'], 0, ',', ' '),
number_format((int)$value['amount_due'], 0, ',', ' '),
@@ -141,6 +143,7 @@ private function buildDataRow($value, $product, $isAdmin, $isCommerciale, $isCai
return [
$value['avance_id'],
$productName,
+ $productSku,
number_format((int)$value['avance_amount'], 0, ',', ' '),
number_format((int)$value['amount_due'], 0, ',', ' '),
$date_time,
@@ -228,12 +231,13 @@ private function fetchAvanceDataGeneric($methodName = 'getAllAvanceData')
$date_time = date('d-m-Y h:i a', strtotime($value['avance_date']));
+ $productSku = '';
if ($value['type_avance'] === 'mere') {
$productName = $value['product_name'] ?? 'Produit sur mer';
} else {
- $productName = !empty($value['product_name'])
- ? $value['product_name']
- : $product->getProductNameById($value['product_id'] ?? 0);
+ $productData = !empty($value['product_id']) ? $product->find($value['product_id']) : null;
+ $productName = $productData['name'] ?? ($value['product_name'] ?? 'N/A');
+ $productSku = $productData['sku'] ?? '';
}
if ($isAdmin) {
@@ -242,6 +246,7 @@ private function fetchAvanceDataGeneric($methodName = 'getAllAvanceData')
$value['customer_phone'],
$value['customer_address'],
$productName,
+ $productSku,
number_format((int)$value['gross_amount'], 0, ',', ' '),
number_format((int)$value['avance_amount'], 0, ',', ' '),
$status,
@@ -252,6 +257,7 @@ private function fetchAvanceDataGeneric($methodName = 'getAllAvanceData')
$result['data'][] = [
$value['avance_id'],
$productName,
+ $productSku,
number_format((int)$value['avance_amount'], 0, ',', ' '),
$status,
$date_time,
diff --git a/app/Controllers/HistoriqueController.php b/app/Controllers/HistoriqueController.php
index 0a65604d..4c4af9b3 100644
--- a/app/Controllers/HistoriqueController.php
+++ b/app/Controllers/HistoriqueController.php
@@ -71,6 +71,7 @@ class HistoriqueController extends AdminController
$row['product_name'] ?? 'N/A',
$row['sku'] ?? 'N/A',
$row['store_name'] ?? 'N/A',
+ $row['user_name'] ?? 'N/A',
$this->getActionBadge($row['action']),
$row['description'] ?? ''
];
diff --git a/app/Controllers/MecanicienController.php b/app/Controllers/MecanicienController.php
index 40b406fb..1e7594d5 100644
--- a/app/Controllers/MecanicienController.php
+++ b/app/Controllers/MecanicienController.php
@@ -298,7 +298,7 @@ class MecanicienController extends AdminController
$date_debut = date("d/m/Y", strtotime($repa['reparation_debut']));
$date_fin = date("d/m/Y", strtotime($repa['reparation_fin']));
$storeName = $repa['store_name'] ?? 'N/A';
-
+
$result['data'][$key] = [
$user_name,
$image,
diff --git a/app/Controllers/OrderController.php b/app/Controllers/OrderController.php
index 9933daa2..27910e9d 100644
--- a/app/Controllers/OrderController.php
+++ b/app/Controllers/OrderController.php
@@ -663,16 +663,21 @@ class OrderController extends AdminController
$Notification->notifyGroupsByPermissionAllStores('notifRemise', $message, 'remise/');
- } else {
- // Commande sans remise
- $Notification->notifyGroupsByPermission(
- 'notifSortieCaisse',
- "📦 Nouvelle commande à valider : {$bill_no}
" .
+ // Notifier la Caissière (notifCommande) et l'admin/direction (notifSortieCaisse)
+ $messageCommande = "📦 Nouvelle commande (avec remise) à traiter : {$bill_no}
" .
"Client : {$data['customer_name']}
" .
- "Montant : " . number_format($gross_amount, 0, ',', ' ') . " Ar",
- (int)$users['store_id'],
- "orders"
- );
+ "Montant demandé : " . number_format($discount, 0, ',', ' ') . " Ar
" .
+ "En attente de validation remise";
+ $Notification->notifyGroupsByPermission('notifCommande', $messageCommande, (int)$users['store_id'], "orders");
+ $Notification->notifyGroupsByPermission('notifSortieCaisse', $messageCommande, (int)$users['store_id'], "orders");
+
+ } else {
+ // Commande sans remise - notifier Caissière (notifCommande) et admin/direction (notifSortieCaisse)
+ $messageCommande = "📦 Nouvelle commande à traiter : {$bill_no}
" .
+ "Client : {$data['customer_name']}
" .
+ "Montant : " . number_format($gross_amount, 0, ',', ' ') . " Ar";
+ $Notification->notifyGroupsByPermission('notifCommande', $messageCommande, (int)$users['store_id'], "orders");
+ $Notification->notifyGroupsByPermission('notifSortieCaisse', $messageCommande, (int)$users['store_id'], "orders");
}
if ($users["group_name"] != "COMMERCIALE") {
@@ -1721,23 +1726,18 @@ public function update(int $id)
}
- public function printDiv(int $id)
+ public function printDiv(int $id)
{
$Orders = new Orders();
+ $OrderItems = new OrderItems();
$order = $Orders->getOrdersData($id);
-
- $docType = $order['document_type'] ?? 'facture';
-
- // Rediriger vers la bonne méthode selon le type
- switch($docType) {
- case 'facture':
- return $this->print31($id); // Factures individuelles
- case 'bl':
- return $this->print7($id); // Bon de livraison
- case 'both':
- return $this->print31($id); // Factures + Bon de livraison
- default:
- return $this->print31($id);
+ $items = $OrderItems->getOrdersItemData($id);
+
+ // Plus d'1 produit = BL, 1 seul produit = Facture
+ if (count($items) > 1) {
+ return $this->print7($id); // Bon de livraison
+ } else {
+ return $this->print5($id); // Facture
}
}
@@ -2007,23 +2007,26 @@ public function print5(int $id)
$discount = (float) $order['discount'];
$grossAmount = (float) $order['gross_amount'];
- $totalTTC = ($discount > 0) ? $discount : $grossAmount;
- $inWords = strtoupper($this->numberToWords((int) round($totalTTC)));
+ $totalAPayer = ($discount > 0) ? $discount : $grossAmount;
+ $remiseAmount = ($discount > 0) ? ($grossAmount - $discount) : 0;
+ $inWords = strtoupper($this->numberToWords((int) round($totalAPayer)));
// Construire les lignes du tableau
$tableRows = '';
+ $totalPrixIndividuels = 0;
foreach ($items as $it) {
$details = $this->getOrderItemDetails($it);
if (!$details) continue;
$qty = isset($it['qty']) ? (int)$it['qty'] : 1;
- $prix = ($discount > 0) ? ($discount / $qty) : $details['prix'];
+ $prixItem = $details['prix'] * $qty;
+ $totalPrixIndividuels += $prixItem;
$tableRows .= '