diff --git a/app/Models/TrpProductionModel.php b/app/Models/TrpProductionModel.php index 5302d616..8b8366ae 100644 --- a/app/Models/TrpProductionModel.php +++ b/app/Models/TrpProductionModel.php @@ -166,38 +166,42 @@ class TrpProductionModel extends Model ->getResultArray(); - $crsClientList = array_column($crsClientList, 'client_name'); + $crsClientList = array_column($crsClientList, 'client_name'); - // Initialize an empty array for dynamic SQL conditions - $caseStatementsCrs = []; + // Initialize an empty array for dynamic SQL conditions + $caseStatementsCrs = []; + + // Loop through the client list and build dynamic SUM(CASE WHEN...) + foreach ($crsClientList as $index => $client) { + + $crsClientList[$index] = $client."_crs"; + $clientCrs = $client."_crs"; + + // Add the condition to the array + $caseStatementsCrs[] = "SUM(CASE WHEN clients.client_name = " . $this->db->escape($client) . " THEN invItems.item_quantity ELSE 0 END) AS `$clientCrs`"; + } + + // Convert array to a comma-separated string + $caseSQLCrs = implode(', ', $caseStatementsCrs); + + // Subquery: Get unique invoice_id with item_date_added and total item_quantity per invoice + $subquery = $this->db->table('ip_invoice_items') + ->select('invoice_id, item_date_added, item_quantity') + ->whereIn('item_product_id', [81, 93]) + ->groupBy(['invoice_id']) + ->getCompiledSelect(); // Convert to raw SQL for subquery + + // Main Query: Use the subquery as invItems and join with ip_invoices and ip_clients + $subquery3 = $this->db->table("($subquery) invItems") + ->select(array_merge(['invItems.item_date_added'], $caseStatementsCrs)) // Add dynamic SUM(CASE WHEN..) + ->join('ip_invoices inv', 'inv.invoice_id = invItems.invoice_id', 'left') + ->join('ip_clients clients', 'clients.client_id = inv.client_id', 'left') + ->where("invItems.item_date_added BETWEEN '$startDate' AND '$endDate'", null, false) // Use BETWEEN for date filtering + ->groupBy('invItems.item_date_added') + ->getCompiledSelect(false); // Convert Query Builder to raw SQL; + - // Loop through the client list and build dynamic SUM(CASE WHEN...) - foreach ($crsClientList as $index => $client) { - - $crsClientList[$index] = $client."_crs"; - $clientCrs = $client."_crs"; - - // Add the condition to the array - $caseStatementsCrs[] = "SUM(CASE WHEN clients.client_name = " . $this->db->escape($client) . " THEN invItems.item_quantity ELSE 0 END) AS `$clientCrs`"; - } - - // Convert array to a comma-separated string - $caseSQLCrs = implode(', ', $caseStatementsCrs); - - - - $subquery3 = $this->db->table('ip_invoice_items invItems') - ->select([ - 'invItems.item_date_added', - $caseSQLCrs - ]) - ->join('ip_invoices inv', 'inv.invoice_id = invItems.invoice_id', 'left') - ->join('ip_clients clients', 'clients.client_id = inv.client_id', 'left') - ->whereIn('invItems.item_product_id', [81, 93]) - ->where("invItems.item_date_added BETWEEN '$startDate' AND '$endDate'", null, false) // Use BETWEEN for date filtering - ->groupBy('invItems.item_date_added') - - ->getCompiledSelect(false); // Convert Query Builder to raw SQL; + $builder->join("({$subquery3}) invItems", 'invItems.item_date_added = tpmd.date', 'left'); diff --git a/app/Views/stock/CoatingMachineDetail.php b/app/Views/stock/CoatingMachineDetail.php index 28473619..6fe97770 100644 --- a/app/Views/stock/CoatingMachineDetail.php +++ b/app/Views/stock/CoatingMachineDetail.php @@ -43,8 +43,15 @@ } .fht-table td:hover { - background-color: #50bbd9; - color: #ffffff; + background-color: rgb(170, 222, 167); + color:rgb(2, 2, 2); + transform: scale(1.25); /* Increases size by 25% */ + transition: transform 0.2s ease-in-out; /* Smooth scaling effect */ + } + + .fht-table tr:hover { + background-color: rgb(170, 222, 167); + color:rgb(2, 2, 2); } .fht-table { @@ -226,7 +233,7 @@ .table-responsive { overflow-y: auto; - max-height: 500px; + max-height: 700px; } .fht-table thead th { @@ -239,6 +246,13 @@ background-color:rgb(235, 236, 203); } + body[data-layout-mode = horizontal] .container-fluid{ + max-width: 100%; + } + .card-body{ padding-bottom: 0;} + .card{ margin-bottom: 5px;} + +