277 lines
7.9 KiB
PHP
277 lines
7.9 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) . "'";
|
|
|
|
|
|
$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,
|
|
|
|
|
|
tcmd.totalGasConsumption as coatingGasConsumption,
|
|
|
|
tdmd.total_gas_consumption 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_coatingMachineDetails tcmd ON tcmd.date = tpmd.date
|
|
LEFT JOIN
|
|
t_drierMachineDetails tdmd ON tdmd.date = tpmd.date
|
|
LEFT JOIN
|
|
t_trp_sand_use tsu ON tsu.date = tpmd.date
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
-- All joins to get supplier name thats it
|
|
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
|
|
|
|
-- getting waste core sands using three distinct material codes
|
|
Where
|
|
tigrd.MaterialCode IN ($materialCodesString)
|
|
|
|
AND
|
|
tigrd.CreatedDate >= '$startDate'
|
|
|
|
AND
|
|
tigrd.CreatedDate <= '$endDate'
|
|
|
|
-- grouping supplier who provides waste core on a particular date with 1 or more IGRS
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|