229 lines
8.6 KiB
PHP
229 lines
8.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class TrpProductionModel extends Model
|
|
{
|
|
protected $table = 't_trpProductionDetails';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = false;
|
|
protected $protectFields = true;
|
|
protected $allowedFields = ['date', 'gasReceiptBg', 'gasReceiptPg', 'physicalGasConsumption', 'trpPlusDrierGasConsumption',
|
|
'trpPhysicalGasPerTon', 'panelGasConsumption','panelGasPerTon','edRunningHours','edProduction','edUsage',
|
|
'trpProduction', 'trpProductionPerHour', 'waterReceipt', 'waterConsumption' ,'ebReading',
|
|
'ebReadingPerUnitTon'];
|
|
|
|
protected bool $allowEmptyInserts = false;
|
|
protected bool $updateOnlyChanged = true;
|
|
|
|
protected array $casts = [];
|
|
protected array $castHandlers = [];
|
|
|
|
// Dates
|
|
protected $useTimestamps = false;
|
|
protected $dateFormat = 'datetime';
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
protected $deletedField = 'deleted_at';
|
|
|
|
// Validation
|
|
protected $validationRules = [];
|
|
protected $validationMessages = [];
|
|
protected $skipValidation = false;
|
|
protected $cleanValidationRules = true;
|
|
|
|
// Callbacks
|
|
protected $allowCallbacks = true;
|
|
protected $beforeInsert = [];
|
|
protected $afterInsert = [];
|
|
protected $beforeUpdate = [];
|
|
protected $afterUpdate = [];
|
|
protected $beforeFind = [];
|
|
protected $afterFind = [];
|
|
protected $beforeDelete = [];
|
|
protected $afterDelete = [];
|
|
|
|
|
|
|
|
|
|
public function trpProductionDetails($startDate,$endDate){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Subquery definition
|
|
$subquery = $this->db->table('t_materialmaster')
|
|
->select('materialCode')
|
|
->where('Category', 'waste core')
|
|
->get()
|
|
->getResultArray();
|
|
|
|
$materialCodes = array_column($subquery, 'materialCode'); // Extracts 'materialCode' values
|
|
|
|
// Convert the array of material codes to a comma-separated string
|
|
$materialCodesString = "'" . implode("','", $materialCodes) . "'";
|
|
|
|
// dd($materialCodes);
|
|
|
|
|
|
$sql = "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,
|
|
|
|
-- Aggregated totalGasConsumption for Coating Machine
|
|
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'
|
|
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 tigrd.CreatedDate >= '$startDate'
|
|
AND 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";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Execute the query
|
|
$query = $this->db->query($sql, [ $startDate, $endDate]);
|
|
|
|
$result = $query->getResultArray();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|