Merge branch 'new_theme' of bitbucket.org:venbainformationtechnology/ria into new_theme
This commit is contained in:
commit
8a415fce6e
@ -1538,6 +1538,7 @@ class User extends BaseController
|
|||||||
if (isset($rs['line_items']) && count($rs['line_items']) > 0) {
|
if (isset($rs['line_items']) && count($rs['line_items']) > 0) {
|
||||||
log_message('error', 'Processing line items' . count($rs['line_items']));
|
log_message('error', 'Processing line items' . count($rs['line_items']));
|
||||||
|
|
||||||
|
dd($rs);
|
||||||
for ($i = 0; $i < count($rs['line_items']); $i++) { //start insert line items
|
for ($i = 0; $i < count($rs['line_items']); $i++) { //start insert line items
|
||||||
$sku = $rs['line_items'][$i]['sku'];
|
$sku = $rs['line_items'][$i]['sku'];
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use CodeIgniter\Model;
|
use CodeIgniter\Model;
|
||||||
|
use Predis\Client;
|
||||||
|
|
||||||
class TrpProductionModel extends Model
|
class TrpProductionModel extends Model
|
||||||
{
|
{
|
||||||
@ -53,168 +54,208 @@ class TrpProductionModel extends Model
|
|||||||
public function trpProductionDetails($startDate,$endDate){
|
public function trpProductionDetails($startDate,$endDate){
|
||||||
|
|
||||||
|
|
||||||
|
$data =[];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Subquery definition
|
// Subquery definition
|
||||||
$subquery = $this->db->table('t_materialmaster')
|
$subquery = $this->db->table('t_materialmaster')
|
||||||
->select('materialCode')
|
->select('materialCode')
|
||||||
->where('Category', 'waste core')
|
->where('Category = 328')
|
||||||
->get()
|
->get()
|
||||||
->getResultArray();
|
->getResultArray();
|
||||||
|
|
||||||
$materialCodes = array_column($subquery, 'materialCode'); // Extracts 'materialCode' values
|
$materialCodes = array_column($subquery, 'materialCode'); // Extracts 'materialCode' values
|
||||||
|
|
||||||
|
// dd($this->db->getLastQuery());
|
||||||
|
|
||||||
// Convert the array of material codes to a comma-separated string
|
// Convert the array of material codes to a comma-separated string
|
||||||
$materialCodesString = "'" . implode("','", $materialCodes) . "'";
|
// $materialCodesString = "'" . implode("','", $materialCodes) . "'";
|
||||||
|
|
||||||
// dd($materialCodes);
|
// dd($materialCodes);
|
||||||
|
|
||||||
|
|
||||||
|
// Define your table
|
||||||
|
$builder = $this->db->table('t_trpProductionMaintenanceDetails tpmd');
|
||||||
|
|
||||||
$sql = "SELECT
|
// Select required columns
|
||||||
|
$builder->select([
|
||||||
|
'tpmd.date',
|
||||||
|
'tpmd.openingTime',
|
||||||
|
'tpmd.closingTime',
|
||||||
|
'tpmd.totalHours',
|
||||||
|
'tpmd.coldStart',
|
||||||
|
'tpmd.breakdownHours',
|
||||||
|
'tpmd.burnerFiringHours',
|
||||||
|
'tpmd.sandFeedingHours',
|
||||||
|
'tpmd.workingPersonEngineers',
|
||||||
|
'tpmd.workingPersonSupervisiors',
|
||||||
|
'tpmd.workingPersonOperators',
|
||||||
|
'tpmd.rollerDrivers',
|
||||||
|
'tpmd.natureOfMaintenance',
|
||||||
|
'tpmd.location',
|
||||||
|
'tpmd.description',
|
||||||
|
|
||||||
|
'tpd.gasReceiptBg',
|
||||||
|
'tpd.gasReceiptPg',
|
||||||
|
'tpd.physicalGasConsumption',
|
||||||
|
'tpd.trpPlusDrierGasConsumption',
|
||||||
|
'tpd.trpPhysicalGasPerTon',
|
||||||
|
'tpd.panelGasConsumption',
|
||||||
|
'tpd.panelGasPerTon',
|
||||||
|
'tpd.edRunningHours',
|
||||||
|
'tpd.edProduction',
|
||||||
|
'tpd.edUsage',
|
||||||
|
'tpd.trpProduction',
|
||||||
|
'tpd.trpProductionPerHour',
|
||||||
|
'tpd.waterReceipt',
|
||||||
|
'tpd.waterConsumption',
|
||||||
|
'tpd.ebReading',
|
||||||
|
'tpd.ebReadingPerUnitTon',
|
||||||
|
|
||||||
|
'tpwd.msSeperation',
|
||||||
|
'tpwd.edWaste',
|
||||||
|
'tpwd.coolerBags',
|
||||||
|
'tpwd.edPlus20Waste',
|
||||||
|
'tpwd.cycloneWaste',
|
||||||
|
|
||||||
tpmd.date,
|
// Aggregated gas consumption
|
||||||
tpmd.openingTime,
|
'IFNULL(tcmd.totalGasConsumption, 0) AS coatingGasConsumption',
|
||||||
tpmd.closingTime,
|
'IFNULL(tdmd.totalGasConsumption, 0) AS drierGasConsumption',
|
||||||
tpmd.totalHours,
|
|
||||||
tpmd.coldStart,
|
'tsu.total_kgs AS coating' ,
|
||||||
tpmd.breakdownHours,
|
|
||||||
tpmd.burnerFiringHours,
|
'tigrdot.*',
|
||||||
tpmd.sandFeedingHours,
|
'invItems.*'
|
||||||
tpmd.workingPersonEngineers,
|
|
||||||
tpmd.workingPersonSupervisiors,
|
|
||||||
tpmd.workingPersonOperators,
|
]);
|
||||||
tpmd.rollerDrivers,
|
|
||||||
tpmd.natureOfMaintenance,
|
// Join with other tables
|
||||||
tpmd.location,
|
$builder->join('t_trpProductionDetails tpd', 'tpd.date = tpmd.date', 'inner');
|
||||||
tpmd.description,
|
$builder->join('t_trpProductionWasteDetails tpwd', 'tpwd.date = tpmd.date', 'inner');
|
||||||
|
$builder->join('t_trp_sand_use tsu', 'tsu.date = tpmd.date', 'left');
|
||||||
|
|
||||||
|
// Subquery: Coating Machine Gas Consumption
|
||||||
|
$subquery1 = $this->db->table('t_coatingMachineDetails')
|
||||||
|
->select('date, SUM(totalGasConsumption) AS totalGasConsumption')
|
||||||
|
->groupBy('date')
|
||||||
|
->getCompiledSelect(false); // Convert Query Builder to raw SQL;
|
||||||
|
|
||||||
|
$builder->join("({$subquery1}) tcmd", 'tcmd.date = tpmd.date', 'left');
|
||||||
|
|
||||||
|
// Subquery: Drier Machine Gas Consumption
|
||||||
|
$subquery2 = $this->db->table('t_drierMachineDetails')
|
||||||
|
->select('date, SUM(total_gas_consumption) AS totalGasConsumption')
|
||||||
|
->groupBy('date')
|
||||||
|
->getCompiledSelect(false); // Convert Query Builder to raw SQL;
|
||||||
|
|
||||||
|
$builder->join("({$subquery2}) tdmd", 'tdmd.date = tpmd.date', 'left');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Subquery: Core Sand Reclaimed by Clients
|
||||||
|
|
||||||
|
$crsClientList = $this->db->table('ip_clients clients')
|
||||||
|
->distinct()
|
||||||
|
->select( 'clients.client_name')
|
||||||
|
->join('ip_invoices inv', 'inv.client_id = clients.client_id')
|
||||||
|
->join('ip_invoice_items invItems', 'inv.invoice_id = invItems.invoice_id')
|
||||||
|
->whereIn('invItems.item_product_id', [81, 93])
|
||||||
|
->where('invItems.item_date_added >=', $startDate)
|
||||||
|
->where('invItems.item_date_added <=', $endDate)
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
|
||||||
|
|
||||||
|
$crsClientList = array_column($crsClientList, 'client_name');
|
||||||
|
|
||||||
|
// Initialize an empty array for dynamic SQL conditions
|
||||||
|
$caseStatements = [];
|
||||||
|
|
||||||
|
// Loop through the client list and build dynamic SUM(CASE WHEN...)
|
||||||
|
foreach ($crsClientList as $client) {
|
||||||
|
// Escape column name (remove spaces and special characters)
|
||||||
|
$safeClient = str_replace(' ', '_', $client);
|
||||||
|
|
||||||
|
// Add the condition to the array
|
||||||
|
$caseStatements[] = "SUM(CASE WHEN clients.client_name = " . $this->db->escape($client) . " THEN invItems.item_quantity ELSE 0 END) AS `$safeClient`";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert array to a comma-separated string
|
||||||
|
$caseSQL = implode(', ', $caseStatements);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tpd.gasReceiptBg,
|
$subquery3 = $this->db->table('ip_invoice_items invItems')
|
||||||
tpd.gasReceiptPg,
|
->select([
|
||||||
tpd.physicalGasConsumption,
|
'invItems.item_date_added',
|
||||||
tpd.trpPlusDrierGasConsumption,
|
$caseSQL
|
||||||
tpd.trpPhysicalGasPerTon,
|
])
|
||||||
tpd.panelGasConsumption,
|
->join('ip_invoices inv', 'inv.invoice_id = invItems.invoice_id', 'left')
|
||||||
tpd.panelGasPerTon,
|
->join('ip_clients clients', 'clients.client_id = inv.client_id', 'left')
|
||||||
tpd.edRunningHours,
|
->whereIn('invItems.item_product_id', [81, 93])
|
||||||
tpd.edProduction,
|
->where('invItems.item_date_added >=', $startDate)
|
||||||
tpd.edUsage,
|
->where('invItems.item_date_added <=', $endDate)
|
||||||
tpd.trpProduction,
|
->groupBy('invItems.item_date_added')
|
||||||
tpd.trpProductionPerHour,
|
|
||||||
tpd.waterReceipt,
|
->getCompiledSelect(false); // Convert Query Builder to raw SQL;
|
||||||
tpd.waterConsumption,
|
|
||||||
tpd.ebReading,
|
|
||||||
tpd.ebReadingPerUnitTon,
|
$builder->join("({$subquery3}) invItems", 'invItems.item_date_added = tpmd.date', 'left');
|
||||||
|
|
||||||
tpwd.msSeperation,
|
|
||||||
tpwd.edWaste,
|
|
||||||
tpwd.coolerBags,
|
|
||||||
tpwd.edPlus20Waste,
|
|
||||||
tpwd.cycloneWaste,
|
|
||||||
|
|
||||||
-- Aggregated totalGasConsumption for Coating Machine
|
$materialCodes = ! empty($materialCodes) ? $materialCodes : ['600374','600422','600434'];
|
||||||
IFNULL(tcmd.totalGasConsumption, 0) AS coatingGasConsumption,
|
|
||||||
|
|
||||||
-- Aggregated totalGasConsumption for Drier Machine
|
|
||||||
IFNULL(tdmd.totalGasConsumption, 0) AS drierGasConsumption,
|
|
||||||
|
|
||||||
tsu.total_kgs AS coating,
|
|
||||||
|
|
||||||
invItems.*,
|
|
||||||
tigrdot.*
|
|
||||||
|
|
||||||
FROM
|
|
||||||
t_trpProductionMaintenanceDetails tpmd
|
|
||||||
|
|
||||||
JOIN
|
|
||||||
t_trpProductionDetails tpd ON tpd.date = tpmd.date
|
|
||||||
JOIN
|
|
||||||
t_trpProductionWasteDetails tpwd ON tpwd.date = tpmd.date
|
|
||||||
LEFT JOIN
|
|
||||||
t_trp_sand_use tsu ON tsu.date = tpmd.date
|
|
||||||
|
|
||||||
-- Aggregated Coating Machine Gas Consumption
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT date, SUM(totalGasConsumption) AS totalGasConsumption
|
|
||||||
FROM t_coatingMachineDetails
|
|
||||||
GROUP BY date
|
|
||||||
) tcmd ON tcmd.date = tpmd.date
|
|
||||||
|
|
||||||
-- Aggregated Drier Machine Gas Consumption
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT date, SUM(total_gas_consumption) AS totalGasConsumption
|
|
||||||
FROM t_drierMachineDetails
|
|
||||||
GROUP BY date
|
|
||||||
) tdmd ON tdmd.date = tpmd.date
|
|
||||||
|
|
||||||
-- Aggregating Core Sand Reclaimed by Client
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT
|
|
||||||
invItems.item_date_added,
|
|
||||||
SUM(CASE WHEN clients.client_name = 'ASHOK LEYLAND LIMITED (FOUNDRY DIVISION-SRIPERUMBUDUR)' THEN invItems.item_quantity ELSE 0 END) AS `ALs_crs`,
|
|
||||||
SUM(CASE WHEN clients.client_name = 'NEMAK ALUMINIUM CASTING INDIA PVT LTD' THEN invItems.item_quantity ELSE 0 END) AS `Nemak_crs`,
|
|
||||||
SUM(CASE WHEN clients.client_name = 'MADRAS ENGINEERING INDUSTRIES PRIVATE LIMITED' THEN invItems.item_quantity ELSE 0 END) AS `ME_crs`,
|
|
||||||
SUM(CASE WHEN clients.client_name = 'BRAKES INDIA PRIVATE LIMITED' THEN invItems.item_quantity ELSE 0 END) AS `BI_crs`,
|
|
||||||
SUM(CASE WHEN clients.client_name = 'KARMEN INTERNATIONAL PVT LTD' THEN invItems.item_quantity ELSE 0 END) AS `Karmen_crs`
|
|
||||||
FROM
|
|
||||||
ip_invoice_items invItems
|
|
||||||
LEFT JOIN
|
|
||||||
ip_invoices inv ON inv.invoice_id = invItems.invoice_id
|
|
||||||
LEFT JOIN
|
|
||||||
ip_clients clients ON clients.client_id = inv.client_id
|
|
||||||
WHERE
|
|
||||||
invItems.item_name = 'Core Sand Reclaimed'
|
|
||||||
OR invItems.item_name = 'Core Sand Reclaimed - Code No: 1203838'
|
|
||||||
OR invItems.item_name = 'Nemak Reclaimed Silica Sand 39-43'
|
|
||||||
AND invItems.item_date_added >= '$startDate'
|
|
||||||
AND invItems.item_date_added <= '$endDate'
|
|
||||||
GROUP BY
|
|
||||||
invItems.item_date_added
|
|
||||||
) invItems ON invItems.item_date_added = tpmd.date
|
|
||||||
|
|
||||||
-- Aggregating Waste Core Sand Suppliers
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT
|
|
||||||
tigrd.CreatedDate,
|
|
||||||
SUM(CASE WHEN ts.SupplierName = 'Ashok leyland limited foundry divn-SPU' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS `ALs_wcs`,
|
|
||||||
SUM(CASE WHEN ts.SupplierName = 'Ashok leyland limited foundry divn-ENU' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS `ALe_wcs`,
|
|
||||||
SUM(CASE WHEN ts.SupplierName = 'MADRAS ENGINEERING INDUSTRIES PRIVATE LIMITED' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS `ME_wcs`,
|
|
||||||
SUM(CASE WHEN ts.SupplierName = 'SIDDHARTH INDUSTRIES' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS `SI_wcs`,
|
|
||||||
SUM(CASE WHEN ts.SupplierName = 'Caparo Engineering India Limited' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS `caparo_wcs`,
|
|
||||||
SUM(CASE WHEN ts.SupplierName = 'NEMAK ALUMINIUM CASTING INDIA PVT LTD' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS `Nemak_wcs`,
|
|
||||||
SUM(CASE WHEN ts.SupplierName = 'DR Axion India Private Limited' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS `DR_wcs`
|
|
||||||
FROM t_igr_details tigrd
|
|
||||||
LEFT JOIN t_igr_master tigm ON tigm.IGRNo = tigrd.IGRNo
|
|
||||||
LEFT JOIN t_purchaseorder_master tpom ON tpom.PONO = tigm.PONO
|
|
||||||
LEFT JOIN t_supplierdetailsn ts ON tpom.SupplierID = ts.SupplierID
|
|
||||||
WHERE
|
|
||||||
tigrd.MaterialCode IN ($materialCodesString)
|
|
||||||
AND Date(tigrd.CreatedDate) >= '$startDate'
|
|
||||||
AND Date(tigrd.CreatedDate) <= '$endDate'
|
|
||||||
GROUP BY Date(tigrd.CreatedDate)
|
|
||||||
) tigrdot ON DATE(tigrdot.CreatedDate) = tpmd.date
|
|
||||||
|
|
||||||
WHERE
|
|
||||||
tpmd.date >= ?
|
|
||||||
AND tpmd.date <= ?
|
|
||||||
|
|
||||||
ORDER BY
|
|
||||||
tpmd.date ASC";
|
|
||||||
|
|
||||||
|
|
||||||
|
// Subquery: Waste Core Sand Suppliers
|
||||||
|
$subquery4 = $this->db->table('t_igr_details tigrd')
|
||||||
|
->select([
|
||||||
|
'DATE(tigrd.CreatedDate) AS CreatedDate', // Convert CreatedDate to DATE format
|
||||||
|
"SUM(CASE WHEN ts.SupplierName = 'Ashok leyland limited foundry divn-SPU' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS ALs_wcs",
|
||||||
|
"SUM(CASE WHEN ts.SupplierName = 'Ashok leyland limited foundry divn-ENU' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS ALe_wcs",
|
||||||
|
"SUM(CASE WHEN ts.SupplierName = 'MADRAS ENGINEERING INDUSTRIES PRIVATE LIMITED' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS ME_wcs",
|
||||||
|
"SUM(CASE WHEN ts.SupplierName = 'SIDDHARTH INDUSTRIES' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS SI_wcs",
|
||||||
|
"SUM(CASE WHEN ts.SupplierName = 'Caparo Engineering India Limited' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS caparo_wcs",
|
||||||
|
"SUM(CASE WHEN ts.SupplierName = 'NEMAK ALUMINIUM CASTING INDIA PVT LTD' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS Nemak_wcs",
|
||||||
|
"SUM(CASE WHEN ts.SupplierName = 'DR Axion India Private Limited' THEN tigrd.QuantityAsPerInvoice ELSE 0 END) AS DR_wcs"
|
||||||
|
])
|
||||||
|
->join('t_igr_master tigm', 'tigm.IGRNo = tigrd.IGRNo', 'left')
|
||||||
|
->join('t_purchaseorder_master tpom', 'tpom.PONO = tigm.PONO', 'left')
|
||||||
|
->join('t_supplierdetailsn ts', 'tpom.SupplierID = ts.SupplierID', 'left')
|
||||||
|
->whereIn('tigrd.MaterialCode', $materialCodes)
|
||||||
|
->where('tigrd.CreatedDate >=', $startDate)
|
||||||
|
->where('tigrd.CreatedDate <=', $endDate)
|
||||||
|
->groupBy('DATE(tigrd.CreatedDate)')
|
||||||
|
->getCompiledSelect(false); // Convert Query Builder to raw SQL
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Correcting the JOIN condition
|
||||||
|
$builder->join("($subquery4) tigrdot", "CAST(tigrdot.CreatedDate AS DATE) = CAST(tpmd.date AS DATE)", 'left');
|
||||||
|
|
||||||
|
|
||||||
|
// Where conditions for main query
|
||||||
|
$builder->where('tpmd.date >=', $startDate);
|
||||||
|
$builder->where('tpmd.date <=', $endDate);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Execute the query
|
// Order by date
|
||||||
$query = $this->db->query($sql, [ $startDate, $endDate]);
|
$builder->orderBy('tpmd.date', 'ASC');
|
||||||
|
|
||||||
$result = $query->getResultArray();
|
|
||||||
|
|
||||||
|
// Execute the query
|
||||||
|
$query = $builder->get();
|
||||||
|
$result = $query->getResultArray();
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
|
||||||
return $result;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -484,6 +484,10 @@ $timeOtions[] = "12:00 AM";
|
|||||||
|
|
||||||
|
|
||||||
<?php if (!empty($trpProductionDetails)) {
|
<?php if (!empty($trpProductionDetails)) {
|
||||||
|
|
||||||
|
dd(array_keys($trpProductionDetails[0]));
|
||||||
|
// dd($trpProductionDetails);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php foreach ($trpProductionDetails as $trpProductionDetailIndex => $trpProductionDetail) {
|
<?php foreach ($trpProductionDetails as $trpProductionDetailIndex => $trpProductionDetail) {
|
||||||
@ -765,7 +769,7 @@ $timeOtions[] = "12:00 AM";
|
|||||||
|
|
||||||
<!-- Hindhuja -->
|
<!-- Hindhuja -->
|
||||||
<!-- td:eq(30) -->
|
<!-- td:eq(30) -->
|
||||||
<td class="celda_normal trpProductionStock ALs_crs"
|
<td class="celda_normal trpProductionStock ALs_crs"
|
||||||
data-id="<?= $trpProductionDetail['date'] ?> ALs_crs">
|
data-id="<?= $trpProductionDetail['date'] ?> ALs_crs">
|
||||||
<?= $trpProductionDetail['ALs_crs'] == 0 ? " " : $trpProductionDetail['ALs_crs'] ?>
|
<?= $trpProductionDetail['ALs_crs'] == 0 ? " " : $trpProductionDetail['ALs_crs'] ?>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user