From 38d37a09874a319b2a17b549cf56dbf1d3f954c2 Mon Sep 17 00:00:00 2001 From: andrymodeste Date: Sat, 4 Apr 2026 08:49:40 +0200 Subject: [PATCH] feat: modifications et corrections du 03-04-2026 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Bouton impression conditionnel : 2 boutons (Facture + BL) si 1 produit, 1 bouton (BL) si plusieurs produits - Ajout filtres (date, point de vente, utilisateur) sur la page Rapports principale - Ajout filtres (date, point de vente) sur la page Rapports/Stock pour les 3 tableaux - Remplacement affichage "UGS" par "N° SERIE" dans toutes les pages - Mise en page facture avec remise : titre FACTURE repositionné, tableau plus compact - Correction remise commandes multi-produits : total_price recevait un tableau au lieu d'un nombre - SuperAdmin voit toutes les remises (tous statuts) au lieu de seulement "En attente" Co-Authored-By: Claude Opus 4.6 (1M context) --- app/Controllers/OrderController.php | 78 ++++++--- app/Controllers/ReportController.php | 135 ++++++++------- app/Controllers/SecuriteController.php | 4 +- app/Models/OrderItems.php | 31 +++- app/Models/Orders.php | 225 ++++++++++++++----------- app/Models/Remise.php | 5 +- app/Models/Reports.php | 42 +++-- app/Views/reports/index.php | 65 +++++-- app/Views/reports/stockDetail.php | 67 ++++---- app/Views/securite/index.php | 14 +- 10 files changed, 402 insertions(+), 264 deletions(-) diff --git a/app/Controllers/OrderController.php b/app/Controllers/OrderController.php index 27910e9d..cb726efe 100644 --- a/app/Controllers/OrderController.php +++ b/app/Controllers/OrderController.php @@ -96,14 +96,23 @@ class OrderController extends AdminController // POUR CAISSIÈRE // ======================================== if ($users['group_name'] == "Caissière") { - $Remise = new Remise(); - + $Remise = new Remise(); + foreach ($data as $key => $value) { - $date_time = date('d-m-Y h:i a', strtotime($value['date_time'])); - + $date_time = date('d-m-Y h:i a', strtotime($value['date_time'])); + $buttons = ''; $discount = (float)$value['discount']; - + $itemCount = (int)$value['item_count']; + + // Génération des boutons d'impression + if ($itemCount > 1) { + $printButtons = ''; + } else { + $printButtons = ''; + $printButtons .= ' '; + } + // ✅ VÉRIFICATION : Si la commande est refusée (paid_status = 0), aucun bouton if ($value['paid_status'] == 0) { $buttons = ' Accès bloqué'; @@ -112,15 +121,15 @@ class OrderController extends AdminController if (in_array('viewOrder', $this->permission)) { // CAS 1 : Commande payée (1) ou livrée (3) → Toujours afficher imprimer if (in_array($value['paid_status'], [1, 3])) { - $buttons .= ''; + $buttons .= $printButtons; } // CAS 2 : Commande en attente (2) SANS remise → Afficher imprimer elseif ($value['paid_status'] == 2 && $discount == 0) { - $buttons .= ''; - } + $buttons .= $printButtons; + } // CAS 3 : Commande en attente (2) AVEC remise validée → Afficher imprimer elseif ($value['paid_status'] == 2 && $Remise->hasRemiseValidatedForOrder($value['id'])) { - $buttons .= ''; + $buttons .= $printButtons; } // CAS 4 : Commande en attente (2) AVEC remise en attente → Indicateur elseif ($value['paid_status'] == 2 && $Remise->hasRemisePendingForOrder($value['id'])) { @@ -221,15 +230,21 @@ class OrderController extends AdminController // ======================================== elseif(in_array($users['group_name'], ["Direction", "DAF", "SuperAdmin", "Administrator"])){ foreach ($data as $key => $value) { - $date_time = date('d-m-Y h:i a', strtotime($value['date_time'])); - + $date_time = date('d-m-Y h:i a', strtotime($value['date_time'])); + $buttons = ''; - + $itemCount = (int)$value['item_count']; + // Bouton imprimer if (in_array('viewOrder', $this->permission) && $users['group_name'] != "SECURITE" && $users['group_name'] != "COMMERCIALE") { - $buttons .= ''; + if ($itemCount > 1) { + $buttons .= ''; + } else { + $buttons .= ''; + $buttons .= ' '; + } } - + // ✅ Bouton modifier pour statuts 0 (Refusé) et 2 (En Attente) if (in_array('updateOrder', $this->permission) && in_array($value['paid_status'], [0, 2])) { $buttons .= ' '; @@ -287,15 +302,21 @@ class OrderController extends AdminController // ======================================== else { foreach ($data as $key => $value) { - $date_time = date('d-m-Y h:i a', strtotime($value['date_time'])); - + $date_time = date('d-m-Y h:i a', strtotime($value['date_time'])); + $buttons = ''; - + $itemCount = (int)$value['item_count']; + // Bouton imprimer if (in_array('viewOrder', $this->permission) && $users['group_name'] != "SECURITE" && $users['group_name'] != "COMMERCIALE") { - $buttons .= ''; + if ($itemCount > 1) { + $buttons .= ''; + } else { + $buttons .= ''; + $buttons .= ' '; + } } - + // ✅ Bouton modifier pour statuts 0 et 2, ET si c'est l'utilisateur créateur if (in_array('updateOrder', $this->permission) && $users["id"] == $value['user_id'] @@ -642,7 +663,7 @@ class OrderController extends AdminController $data1 = [ 'date_demande' => date('Y-m-d H:i:s'), 'montant_demande' => $discount, - 'total_price' => $amounts, + 'total_price' => $gross_amount, 'id_store' => $users['store_id'], 'id_order' => $order_id, 'product' => $product_output, @@ -1112,7 +1133,7 @@ public function update(int $id) $data1 = [ 'date_demande' => date('Y-m-d H:i:s'), 'montant_demande' => $this->request->getPost('discount'), - 'total_price' => $amounts, + 'total_price' => $gross_amount, 'id_store' => $user['store_id'], 'id_order' => $id, 'product' => $product_output, @@ -2080,6 +2101,7 @@ public function print5(int $id) display: flex; flex-direction: column; border-bottom: 2px dashed #aaa; + overflow: hidden; } .facture-box:last-child { @@ -2091,7 +2113,6 @@ public function print5(int $id) font-size: 24px; font-weight: bold; text-decoration: underline; - margin-bottom: 12px; } .f-company { @@ -2120,13 +2141,13 @@ public function print5(int $id) .f-table { width: 100%; border-collapse: collapse; - margin-bottom: 10px; + margin-bottom: 6px; } .f-table th, .f-table td { border-left: 2px solid #000; border-right: 2px solid #000; - padding: 8px 10px; + padding: 3px 8px; text-align: center; font-size: 12px; } @@ -2137,7 +2158,7 @@ public function print5(int $id) border-bottom: 2px solid #000; } - .f-table td { height: 30px; } + .f-table td { height: 20px; } .f-table tbody tr:last-child td { border-bottom: 2px solid #000; @@ -2147,7 +2168,7 @@ public function print5(int $id) .f-words { font-size: 12px; line-height: 1.3; - margin-bottom: 12px; + margin-bottom: 8px; } /* Signatures */ @@ -2268,8 +2289,6 @@ public function print5(int $id) $qrId = 'qr_recto_'.$i; $html .= '
-
FACTURE
-
'.$companyName.'
@@ -2278,6 +2297,9 @@ public function print5(int $id) Contact : '.$companyPhone.' / '.$companyPhone2.'
'.$companyAddress.'
+
+
FACTURE
+
DATE : '.$today.'
N° : '.$billNo.'
diff --git a/app/Controllers/ReportController.php b/app/Controllers/ReportController.php index 4a012001..1f21f2fd 100644 --- a/app/Controllers/ReportController.php +++ b/app/Controllers/ReportController.php @@ -25,102 +25,125 @@ class ReportController extends AdminController { $this->verifyRole('viewReports'); $data['page_title'] = $this->pageTitle; - + // Get the current year or the selected year from the form $today_year = date('Y'); if ($this->request->getPost('select_year')) { $today_year = $this->request->getPost('select_year'); } - + + // Récupérer les filtres + $startDate = $this->request->getPost('start_date') ?: null; + $endDate = $this->request->getPost('end_date') ?: null; + $storeId = $this->request->getPost('store_id') ?: null; + $userId = $this->request->getPost('user_id') ?: null; + // Fetch order data and years $Reports = new Reports(); $Orders = new Orders(); $Store = new Stores(); - $parking_data = $Reports->getOrderData($today_year); + $parking_data = $Reports->getOrderData($today_year, $startDate, $endDate, $storeId, $userId); $data['report_years'] = $Reports->getOrderYear(); - - - // Process the parking data and calculate total amounts - $final_parking_data = []; - foreach ($parking_data as $month => $orders) { - $total_amount_earned = 0; - if (!empty($orders)) { - foreach ($orders as $order) { - // Utiliser le montant selon la logique : discount si existe, sinon gross_amount - if (!empty($order['discount']) && $order['discount'] > 0) { - $total_amount_earned += (float) $order['discount']; - } else { - $total_amount_earned += (float) $order['gross_amount']; - } + // Charger les stores et users pour les filtres + $data['stores'] = $Store->getActiveStore(); + + $db = \Config\Database::connect(); + $data['users_list'] = $db->table('users u') + ->select('u.id, u.firstname, u.lastname, g.group_name') + ->join('user_group ug', 'u.id = ug.user_id') + ->join('groups g', 'ug.group_id = g.id') + ->whereIn('g.group_name', ['COMMERCIALE', 'Caissière', "Cheffe d'Agence"]) + ->orderBy('u.firstname', 'ASC') + ->get()->getResultArray(); + + // Conserver les filtres sélectionnés + $data['selected_start_date'] = $startDate; + $data['selected_end_date'] = $endDate; + $data['selected_store_id'] = $storeId; + $data['selected_user_id'] = $userId; + + // Process the parking data and calculate total amounts + $final_parking_data = []; + foreach ($parking_data as $month => $orders) { + $total_amount_earned = 0; + + if (!empty($orders)) { + foreach ($orders as $order) { + if (!empty($order['discount']) && $order['discount'] > 0) { + $total_amount_earned += (float) $order['discount']; + } else { + $total_amount_earned += (float) $order['gross_amount']; } } - - $final_parking_data[$month] = $total_amount_earned; } + + $final_parking_data[$month] = $total_amount_earned; + } + // Data for the camembert (pie chart) - $paymentModes = $Orders->getPaymentModes(); - $total_mvola1 = $paymentModes->total_mvola1; - $total_mvola2 = $paymentModes->total_mvola2; - $total_espece1 = $paymentModes->total_espece1; - $total_espece2 = $paymentModes->total_espece2; - $total_banque1 = $paymentModes->total_virement_bancaire1; - $total_banque2 = $paymentModes->total_virement_bancaire2; + $paymentModes = $Orders->getPaymentModes($startDate, $endDate, $storeId, $userId); + $total_mvola1 = $paymentModes->total_mvola1 ?? 0; + $total_mvola2 = $paymentModes->total_mvola2 ?? 0; + $total_espece1 = $paymentModes->total_espece1 ?? 0; + $total_espece2 = $paymentModes->total_espece2 ?? 0; + $total_banque1 = $paymentModes->total_virement_bancaire1 ?? 0; + $total_banque2 = $paymentModes->total_virement_bancaire2 ?? 0; $total_mvola = $total_mvola1 + $total_mvola2; $total_banque = $total_banque1 + $total_banque2; $total_espece = $total_espece1 + $total_espece2; - $totalOrders = $Orders->getTotalOrders(); + $totalOrders = $Orders->getTotalOrders($startDate, $endDate, $storeId, $userId); $totalAmountPerPaymentModes = ["MVOLA" => $total_mvola, "Espece" => $total_espece, "Virement Bancaire" => $total_banque]; $totalOrdersCount = (int) $totalOrders->total_orders; $labels = []; $totals = []; - + if ($totalOrdersCount > 0) { foreach ($totalAmountPerPaymentModes as $mode => $total) { $labels[] = $mode; $totals[] = $total; } } - + $data['labels'] = json_encode($labels); $data['totals'] = json_encode($totals); - + // Prepare data for product chart $OrderItem = new OrderItems(); - $productTable = $OrderItem->getAllSoldProductToday(); - - $product_sold = (int) $productTable->total_product_sold; - $unsold_product = (int) $productTable->total_unsold_product; - + $productTable = $OrderItem->getAllSoldProductToday($startDate, $endDate, $storeId, $userId); + + $product_sold = (int) ($productTable->total_product_sold ?? 0); + $unsold_product = (int) ($productTable->total_unsold_product ?? 0); + $labels1 = ["Produits vendus", "Produits non vendus"]; $totals2 = [$product_sold, $unsold_product]; - + $data['labels_product'] = json_encode($labels1); $data['totals_product'] = json_encode($totals2); - + // Prepare data for the view $data['selected_year'] = $today_year; $data['company_currency'] = $this->companycurrency(); $data['results'] = $final_parking_data; - + // Data for the camembert in dashboard - $totalStoreOrder = $Orders->getTotalOrderPerStore(); - $totalOrders = $Orders->getTotalOrders(); + $totalStoreOrder = $Orders->getTotalOrderPerStore($startDate, $endDate, $storeId, $userId); + $totalOrders = $Orders->getTotalOrders($startDate, $endDate, $storeId, $userId); $totalOrdersCount = (int) $totalOrders->total_orders; - + // Initialisation des variables pour éviter l'erreur "Undefined variable" $labelStore = []; $totalPerStore = []; - + foreach ($totalStoreOrder as $totalOrdersInStore) { $storeList = $Store->getStoreById($totalOrdersInStore->store_id); $labelStore[] = $storeList->name ?? 'Inconnu'; - $totalPerStore[] = ((int) $totalOrdersInStore->total / $totalOrdersCount) * 100; + $totalPerStore[] = ($totalOrdersCount > 0) ? ((int) $totalOrdersInStore->total / $totalOrdersCount) * 100 : 0; } - + $data['labelStore'] = json_encode($labelStore); $data['totalPerStore'] = json_encode($totalPerStore); - + // Load the view return $this->render_template('reports/index', $data); } @@ -169,13 +192,13 @@ class ReportController extends AdminController { $Orders = new Orders(); - $productVente = $Orders->getTotalProductvente2($id); + $startDate = $this->request->getGet('startDate'); + $endDate = $this->request->getGet('endDate'); + + $productVente = $Orders->getTotalProductvente2($id, $startDate, $endDate); $result = ['data' => []]; foreach ($productVente as $key => $value) { - // die(var_dump($value)); // Debugging: Check what $value contains - - // Add the row data $result['data'][$key] = [ $value->sku, $value->date_time, @@ -183,7 +206,6 @@ class ReportController extends AdminController ]; } - // Return data in JSON format return $this->response->setJSON($result); } @@ -223,15 +245,13 @@ class ReportController extends AdminController { $Products = new Orders(); - $produitStock = $Products->getOrderVendue(); + $startDate = $this->request->getGet('startDate'); + $endDate = $this->request->getGet('endDate'); + + $produitStock = $Products->getOrderVendue($id, $startDate, $endDate); $result = ['data' => []]; - // echo '
';
-        // die(var_dump($produitStock));
 
         foreach ($produitStock as $key => $value) {
-            // die(var_dump($value)); // Debugging: Check what $value contains
-
-            // Add the row data
             $result['data'][$key] = [
                 $value['sku'],
                 $value['qty'],
@@ -241,7 +261,6 @@ class ReportController extends AdminController
             ];
         }
 
-        // Return data in JSON format
         return $this->response->setJSON($result);
     }
 
@@ -526,7 +545,7 @@ class ReportController extends AdminController
                         $imageUrl,                          // 0 - Image
                         $order['bill_no'] ?? 'N/A',        // 1 - N° Facture
                         $product['name'],                   // 2 - Désignation
-                        $product['sku'],                    // 3 - UGS
+                        $product['sku'],                    // 3 - N° SERIE
                         $brandName,                         // 4 - Marque
                         $order['customer_name'],           // 5 - Client
                         $agentName,                         // 6 - Agent Sécurité
diff --git a/app/Controllers/SecuriteController.php b/app/Controllers/SecuriteController.php
index a5b3f84f..9b2a7d51 100644
--- a/app/Controllers/SecuriteController.php
+++ b/app/Controllers/SecuriteController.php
@@ -61,7 +61,7 @@ class SecuriteController extends AdminController
 
                      $result['data'][] = [
                         'image'       => $img,
-                        'ugs'         => esc($product['sku']),
+                        'num_serie'         => esc($product['sku']),
                         'designation' => esc($product['name']),
                         'statut'      => $statut,
                         'action'      => $buttons
@@ -88,7 +88,7 @@ class SecuriteController extends AdminController
             $response = [
                 'image'          => base_url('assets/images/product_image/' . $product['image']),
                 'nom'            => $product['name'],
-                'ugs'            => $product['sku'],
+                'num_serie'            => $product['sku'],
                 'bill_no'        => $data['bill_no'],
                 'customer_name'  => $order_data['customer_name'],
                 'customer_address' => $order_data['customer_address'],
diff --git a/app/Models/OrderItems.php b/app/Models/OrderItems.php
index 6382c784..9d02f5b0 100644
--- a/app/Models/OrderItems.php
+++ b/app/Models/OrderItems.php
@@ -24,15 +24,32 @@ class OrderItems extends Model
         return $this->where('order_id', $order_id)->findAll();
     }
 
-    public function getAllSoldProductToday() {
-        return $this->select('
-                    COUNT(orders_item.id) as total_product_sold, 
+    public function getAllSoldProductToday($startDate = null, $endDate = null, $storeId = null, $userId = null) {
+        $builder = $this->select('
+                    COUNT(orders_item.id) as total_product_sold,
                     (SELECT SUM(products.qty) FROM products) as total_unsold_product
                 ')
-                ->join('orders', 'orders_item.order_id = orders.id')
-                ->where('DATE(orders.date_time)', date('Y-m-d')) 
-                ->get()
-                ->getRow();
+                ->join('orders', 'orders_item.order_id = orders.id');
+
+        if (!empty($startDate) || !empty($endDate) || !empty($storeId) || !empty($userId)) {
+            if (!empty($startDate)) {
+                $builder->where('DATE(orders.date_time) >=', $startDate);
+            }
+            if (!empty($endDate)) {
+                $builder->where('DATE(orders.date_time) <=', $endDate);
+            }
+        } else {
+            $builder->where('DATE(orders.date_time)', date('Y-m-d'));
+        }
+
+        if (!empty($storeId)) {
+            $builder->where('orders.store_id', $storeId);
+        }
+        if (!empty($userId)) {
+            $builder->where('orders.user_id', $userId);
+        }
+
+        return $builder->get()->getRow();
     }
     
     public function getSumOrdersItemData($order_id = null)
diff --git a/app/Models/Orders.php b/app/Models/Orders.php
index 392db9e9..48d64309 100644
--- a/app/Models/Orders.php
+++ b/app/Models/Orders.php
@@ -124,6 +124,7 @@ class Orders extends Model
             ->join('orders_item', 'orders_item.order_id = orders.id', 'left')
             ->join('products', 'products.id = orders_item.product_id', 'left')
             ->select("IFNULL(GROUP_CONCAT(DISTINCT products.name SEPARATOR '\\n'), '') AS product_names", false)
+            ->select("COUNT(DISTINCT orders_item.id) AS item_count", false)
             ->groupBy('orders.id');
     
         // Récupération du groupe de l'utilisateur
@@ -387,7 +388,7 @@ class Orders extends Model
             ->findAll();
     }
 
-    public function getPaymentModes($startDate = null, $endDate = null)
+    public function getPaymentModes($startDate = null, $endDate = null, $storeId = null, $userId = null)
     {
         $session = session();
         $users = $session->get('user');
@@ -395,79 +396,85 @@ class Orders extends Model
 
         $baseQuery = $this->db->table('orders')
             ->select('
-                
-                SUM(CASE 
-                    WHEN orders.discount > 0 AND orders.discount IS NOT NULL 
+
+                SUM(CASE
+                    WHEN orders.discount > 0 AND orders.discount IS NOT NULL
                     THEN orders.discount
-                    ELSE orders.net_amount 
+                    ELSE orders.net_amount
                 END) AS total,
-                
-                
-                SUM(CASE 
-                    WHEN orders.order_payment_mode = "MVOLA" THEN 
-                        CASE 
-                            WHEN orders.discount > 0 AND orders.discount IS NOT NULL 
+
+
+                SUM(CASE
+                    WHEN orders.order_payment_mode = "MVOLA" THEN
+                        CASE
+                            WHEN orders.discount > 0 AND orders.discount IS NOT NULL
                             THEN (orders.tranche_1 * orders.discount / orders.net_amount)
-                            ELSE orders.tranche_1 
+                            ELSE orders.tranche_1
                         END
-                    ELSE 0 
+                    ELSE 0
                 END) AS total_mvola1,
-                SUM(CASE 
-                    WHEN orders.order_payment_mode_1 = "MVOLA" THEN 
-                        CASE 
-                            WHEN orders.discount > 0 AND orders.discount IS NOT NULL 
+                SUM(CASE
+                    WHEN orders.order_payment_mode_1 = "MVOLA" THEN
+                        CASE
+                            WHEN orders.discount > 0 AND orders.discount IS NOT NULL
                             THEN (orders.tranche_2 * orders.discount / orders.net_amount)
-                            ELSE orders.tranche_2 
+                            ELSE orders.tranche_2
                         END
-                    ELSE 0 
+                    ELSE 0
                 END) AS total_mvola2,
-                
-               
-                SUM(CASE 
-                    WHEN orders.order_payment_mode = "En espèce" THEN 
-                        CASE 
-                            WHEN orders.discount > 0 AND orders.discount IS NOT NULL 
+
+
+                SUM(CASE
+                    WHEN orders.order_payment_mode = "En espèce" THEN
+                        CASE
+                            WHEN orders.discount > 0 AND orders.discount IS NOT NULL
                             THEN (orders.tranche_1 * orders.discount / orders.net_amount)
-                            ELSE orders.tranche_1 
+                            ELSE orders.tranche_1
                         END
-                    ELSE 0 
+                    ELSE 0
                 END) AS total_espece1,
-                SUM(CASE 
-                    WHEN orders.order_payment_mode_1 = "En espèce" THEN 
-                        CASE 
-                            WHEN orders.discount > 0 AND orders.discount IS NOT NULL 
+                SUM(CASE
+                    WHEN orders.order_payment_mode_1 = "En espèce" THEN
+                        CASE
+                            WHEN orders.discount > 0 AND orders.discount IS NOT NULL
                             THEN (orders.tranche_2 * orders.discount / orders.net_amount)
-                            ELSE orders.tranche_2 
+                            ELSE orders.tranche_2
                         END
-                    ELSE 0 
+                    ELSE 0
                 END) AS total_espece2,
-                
-              
-                SUM(CASE 
-                    WHEN orders.order_payment_mode = "Virement bancaire" THEN 
-                        CASE 
-                            WHEN orders.discount > 0 AND orders.discount IS NOT NULL 
+
+
+                SUM(CASE
+                    WHEN orders.order_payment_mode = "Virement bancaire" THEN
+                        CASE
+                            WHEN orders.discount > 0 AND orders.discount IS NOT NULL
                             THEN (orders.tranche_1 * orders.discount / orders.net_amount)
-                            ELSE orders.tranche_1 
+                            ELSE orders.tranche_1
                         END
-                    ELSE 0 
+                    ELSE 0
                 END) AS total_virement_bancaire1,
-                SUM(CASE 
-                    WHEN orders.order_payment_mode_1 = "Virement bancaire" THEN 
-                        CASE 
-                            WHEN orders.discount > 0 AND orders.discount IS NOT NULL 
+                SUM(CASE
+                    WHEN orders.order_payment_mode_1 = "Virement bancaire" THEN
+                        CASE
+                            WHEN orders.discount > 0 AND orders.discount IS NOT NULL
                             THEN (orders.tranche_2 * orders.discount / orders.net_amount)
-                            ELSE orders.tranche_2 
+                            ELSE orders.tranche_2
                         END
-                    ELSE 0 
+                    ELSE 0
                 END) AS total_virement_bancaire2
             ')
             ->whereIn('orders.paid_status', [1, 3]);
 
-        if (!$isAdmin) {
+        if (!empty($storeId)) {
+            $baseQuery->where('orders.store_id', $storeId);
+        } elseif (!$isAdmin) {
             $baseQuery->where('orders.store_id', $users['store_id']);
         }
 
+        if (!empty($userId)) {
+            $baseQuery->where('orders.user_id', $userId);
+        }
+
         if ($startDate) {
             $baseQuery->where('DATE(orders.date_time) >=', $startDate);
         }
@@ -478,21 +485,47 @@ class Orders extends Model
         return $baseQuery->get()->getRowObject();
     }
 
-    public function getTotalOrders()
+    public function getTotalOrders($startDate = null, $endDate = null, $storeId = null, $userId = null)
     {
-        return $this->db->table('orders')
-            ->select(' COUNT(*) as total_orders')
-            ->get()
-            ->getRow();
+        $builder = $this->db->table('orders')
+            ->select('COUNT(*) as total_orders');
+
+        if (!empty($storeId)) {
+            $builder->where('store_id', $storeId);
+        }
+        if (!empty($userId)) {
+            $builder->where('user_id', $userId);
+        }
+        if (!empty($startDate)) {
+            $builder->where('DATE(date_time) >=', $startDate);
+        }
+        if (!empty($endDate)) {
+            $builder->where('DATE(date_time) <=', $endDate);
+        }
+
+        return $builder->get()->getRow();
     }
 
-    public function getTotalOrderPerStore()
+    public function getTotalOrderPerStore($startDate = null, $endDate = null, $storeId = null, $userId = null)
     {
-        return $this->db->table('orders')
+        $builder = $this->db->table('orders')
             ->select('store_id, COUNT(*) as total')
-            ->groupBy('store_id')
-            ->get()
-            ->getResult();
+            ->groupBy('store_id');
+
+        if (!empty($storeId)) {
+            $builder->where('store_id', $storeId);
+        }
+        if (!empty($userId)) {
+            $builder->where('user_id', $userId);
+        }
+        if (!empty($startDate)) {
+            $builder->where('DATE(date_time) >=', $startDate);
+        }
+        if (!empty($endDate)) {
+            $builder->where('DATE(date_time) <=', $endDate);
+        }
+
+        return $builder->get()->getResult();
     }
 
     public function getPaymentModesPercentage()
@@ -556,53 +589,57 @@ class Orders extends Model
         return $order;
     }
     
-    public function getTotalProductvente2(?int $id)
+    public function getTotalProductvente2(?int $id, $startDate = null, $endDate = null)
     {
+        $builder = $this->db->table('orders')
+            ->select('orders.id, orders.paid_status, orders.store_id, orders.date_time, brands.name, products.name as Pname, products.sku')
+            ->join('orders_item', 'orders.id = orders_item.order_id')
+            ->join('products', 'orders_item.product_id = products.id')
+            ->join('brands', 'brands.id = products.marque')
+            ->whereIn('orders.paid_status', [1, 3]);
+
         if ($id != 0) {
-            $order = $this->db->table('orders')
-                ->select('orders.id, orders.paid_status, orders.store_id, orders.date_time, brands.name, products.name as Pname, products.sku')
-                ->join('orders_item', 'orders.id = orders_item.order_id')
-                ->join('products', 'orders_item.product_id = products.id')
-                ->join('brands', 'brands.id = products.marque')
-                ->whereIn('orders.paid_status', [1, 3]) // ← CHANGÉ ICI
-                ->where('orders.store_id', $id)
-                ->get()
-                ->getResult();
-        } else {
-            $order = $this->db->table('orders')
-                ->select('orders.id, orders.paid_status, orders.store_id, orders.date_time, brands.name, products.name as Pname, products.sku')
-                ->join('orders_item', 'orders.id = orders_item.order_id')
-                ->join('products', 'orders_item.product_id = products.id')
-                ->join('brands', 'brands.id = products.marque')
-                ->whereIn('orders.paid_status', [1, 3]) // ← CHANGÉ ICI
-                ->get()
-                ->getResult();
+            $builder->where('orders.store_id', $id);
         }
-    
-        return $order;
+        if (!empty($startDate)) {
+            $builder->where('DATE(orders.date_time) >=', $startDate);
+        }
+        if (!empty($endDate)) {
+            $builder->where('DATE(orders.date_time) <=', $endDate);
+        }
+
+        return $builder->get()->getResult();
     }
 
-    public function getOrderVendue()
+    public function getOrderVendue($storeId = null, $startDate = null, $endDate = null)
     {
-        $order = $this->db->table('products')
+        $builder = $this->db->table('products')
             ->select('
-                products.*, 
-                products.name as Pname, 
-                products.sku, 
-                CASE 
-                    WHEN orders.discount > 0 AND orders.discount IS NOT NULL 
-                    THEN orders.discount 
-                    ELSE orders.gross_amount 
+                products.*,
+                products.name as Pname,
+                products.sku,
+                CASE
+                    WHEN orders.discount > 0 AND orders.discount IS NOT NULL
+                    THEN orders.discount
+                    ELSE orders.gross_amount
                 END as totalNet,
                 orders.date_time as DateTime
-            ', false) // ← MODIFIÉ ICI
+            ', false)
             ->join('orders_item', 'products.id = orders_item.product_id')
             ->join('orders', 'orders_item.order_id = orders.id')
-            ->whereIn('orders.paid_status', [1, 3]) // ← ET ICI
-            ->get()
-            ->getResultArray();
-    
-        return $order;
+            ->whereIn('orders.paid_status', [1, 3]);
+
+        if (!empty($storeId) && $storeId != 0) {
+            $builder->where('orders.store_id', $storeId);
+        }
+        if (!empty($startDate)) {
+            $builder->where('DATE(orders.date_time) >=', $startDate);
+        }
+        if (!empty($endDate)) {
+            $builder->where('DATE(orders.date_time) <=', $endDate);
+        }
+
+        return $builder->get()->getResultArray();
     }
 
     public function getPerformanceByOrders($startDate = null, $endDate = null, $pvente = null, $commercialId = null)
diff --git a/app/Models/Remise.php b/app/Models/Remise.php
index 0364139a..2e7adb69 100644
--- a/app/Models/Remise.php
+++ b/app/Models/Remise.php
@@ -16,10 +16,9 @@ class Remise extends Model
             $session = session();
             $users = $session->get('user');
    
-            // ✅ SUPERADMIN VOIT TOUTES LES DEMANDES "EN ATTENTE" (POUR VALIDATION)
+            // ✅ SUPERADMIN VOIT TOUTES LES DEMANDES (TOUS STATUTS)
             if ($users["group_name"] === "SuperAdmin") {
-                return $this->where('demande_status', 'En attente')
-                            ->orderBy('date_demande', 'DESC')
+                return $this->orderBy('date_demande', 'DESC')
                             ->findAll();
             }
    
diff --git a/app/Models/Reports.php b/app/Models/Reports.php
index dec52b01..6c7d536c 100644
--- a/app/Models/Reports.php
+++ b/app/Models/Reports.php
@@ -39,37 +39,51 @@ class Reports extends Model
      * @param mixed $year
      * @return array
      */
-    public function getOrderData($year)
-    {    
+    public function getOrderData($year, $startDate = null, $endDate = null, $storeId = null, $userId = null)
+    {
         if ($year) {
             $months = $this->months();
-           
+
             // Fetch orders with paid_status = 1 or 3
-            $result = $this->whereIn('paid_status', [1, 3])->findAll();
-            
+            $builder = $this->whereIn('paid_status', [1, 3]);
+
+            if (!empty($storeId)) {
+                $builder->where('store_id', $storeId);
+            }
+            if (!empty($userId)) {
+                $builder->where('user_id', $userId);
+            }
+            if (!empty($startDate)) {
+                $builder->where('DATE(date_time) >=', $startDate);
+            }
+            if (!empty($endDate)) {
+                $builder->where('DATE(date_time) <=', $endDate);
+            }
+
+            $result = $builder->findAll();
+
             $final_data = [];
-            
+
             foreach ($months as $month) {
-                $get_mon_year = $year . '-' . $month;    
+                $get_mon_year = $year . '-' . $month;
                 $final_data[$get_mon_year] = [];
-               
+
                 foreach ($result as $v) {
-                    $month_year = date('Y-m', strtotime($v['date_time']));                    
+                    $month_year = date('Y-m', strtotime($v['date_time']));
                     if ($get_mon_year == $month_year) {
-                        // Modifier le montant selon votre logique
                         if (!empty($v['discount']) && $v['discount'] > 0) {
-                            $v['amount_to_display'] = $v['discount']; // Utiliser le rabais
+                            $v['amount_to_display'] = $v['discount'];
                         } else {
-                            $v['amount_to_display'] = $v['gross_amount']; // Utiliser gross_amount
+                            $v['amount_to_display'] = $v['gross_amount'];
                         }
                         $final_data[$get_mon_year][] = $v;
                     }
                 }
             }
-           
+
             return $final_data;
         }
-        
+
         return [];
     }
 }
\ No newline at end of file
diff --git a/app/Views/reports/index.php b/app/Views/reports/index.php
index 06429a2c..c919dc33 100644
--- a/app/Views/reports/index.php
+++ b/app/Views/reports/index.php
@@ -13,20 +13,59 @@
   
-
-
- - + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ - - Details Stock - Performances
diff --git a/app/Views/reports/stockDetail.php b/app/Views/reports/stockDetail.php index 75d13044..620d7a7e 100644 --- a/app/Views/reports/stockDetail.php +++ b/app/Views/reports/stockDetail.php @@ -136,20 +136,27 @@
-
+
-
+
-
+
+ + +
+

- - + +
@@ -228,14 +235,16 @@ ] }); - const filterBtn = document.getElementById('storeFilter'); + const storeSelect = document.getElementById('storeFilter'); - filterBtn.addEventListener('change', function () { - let filterValue = filterBtn.value === "TOUS" ? "0" : filterBtn.value; + storeSelect.addEventListener('change', function () { + let filterValue = storeSelect.value === "TOUS" ? "0" : storeSelect.value; + let startDate = $('#startDateStock').val(); + let endDate = $('#endDateStock').val(); + let params = '?startDate=' + startDate + '&endDate=' + endDate; - // Update the DataTable dynamically without reinitialization - manageTable.ajax.url('fetchData/' + filterValue).load(); - manageTable2.ajax.url('fetchDataStock/' + filterValue).load(); + manageTable.ajax.url('fetchData/' + filterValue + params).load(); + manageTable2.ajax.url('fetchDataStock/' + filterValue + params).load(); }); let productsSold = ; @@ -272,32 +281,14 @@ applyFilter("TOUS"); }); - $.fn.dataTable.ext.search.push(function (settings, data, dataIndex) { - if (settings.nTable.id !== 'export1') return true; // Apply only to your table - - const startDate = $('#startDate').val(); - const endDate = $('#endDate').val(); - const saleDate = data[3]; // assuming column 4 is "Date de vente" - - // If no start date, show everything (default) - if (!startDate) { - return true; - } - - const sale = new Date(saleDate); - const start = new Date(startDate); - const end = endDate ? new Date(endDate) : null; - - if (end) { - return sale >= start && sale <= end; - } else { - return sale >= start; - } - }); - - $('#filteredB1').on('click', function () { - manageTable3.draw(); // re-filter table + let storeId = $('#exportStoreFilter').val(); + let filterValue = storeId === "TOUS" ? "0" : storeId; + let startDate = $('#startDate').val(); + let endDate = $('#endDate').val(); + let params = '?startDate=' + startDate + '&endDate=' + endDate; + + manageTable3.ajax.url('fetchDataStock2/' + filterValue + params).load(); }); diff --git a/app/Views/securite/index.php b/app/Views/securite/index.php index 947b357a..7612d076 100644 --- a/app/Views/securite/index.php +++ b/app/Views/securite/index.php @@ -308,7 +308,7 @@

Produit :

-

UGS :

+

N° SERIE :

N° Facture :

Client :

Adresse :

@@ -353,8 +353,8 @@
-
UGS:
-
+
N° SERIE:
+
Marque:
@@ -430,7 +430,7 @@ $(function() { }, columns: [ { data: 'image', orderable: false }, - { data: 'ugs' }, + { data: 'num_serie' }, { data: 'designation' }, { data: 'statut' }, { data: 'action', orderable: false } @@ -462,7 +462,7 @@ $(function() { success: function(response) { $('#editImage').attr('src', response.image); $('#editNom').text(response.nom); - $('#editUgs').text(response.ugs); + $('#editNumSerie').text(response.num_serie); $('#editBillNo').text(response.bill_no); $('#editClient').text(response.customer_name); $('#editAddress').text(response.customer_address); @@ -767,7 +767,7 @@ $(function() { data.push([ 'N° Facture', 'Désignation', - 'UGS', + 'N° SERIE', 'Marque', 'Client', 'Magasin', @@ -818,7 +818,7 @@ function viewDetails(id) { $('#detailImage').attr('src', data[0]); $('#detailBillNo').text(data[1]); $('#detailDesignation').text(data[2]); - $('#detailUGS').text(data[3]); + $('#detailNumSerie').text(data[3]); $('#detailMarque').text(data[4]); $('#detailSerie').text(data[3]); $('#detailStore').text(data[7]);