102 lines
3.9 KiB
PHP
102 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class GasStockModel extends Model
|
|
{
|
|
protected $table = 't_gasstockdetails';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = false;
|
|
protected $protectFields = true;
|
|
protected $allowedFields = ['date','opening','purchaseBharath','purchaseIndian',
|
|
'total','consumption','balanceStock',
|
|
'trp_panel_gas_consumption','trp_physical_gas_consumption','trp_sand_production','rotary_drier_consumption'];
|
|
|
|
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 gasStockDetails($startDate,$endDate){
|
|
|
|
$result = $this->db->table('t_gasstockdetails')
|
|
|
|
->select(
|
|
't_gasstockdetails.*,
|
|
drier_summary.drierMachineGasconsumption AS drierMachineGasConsumption,
|
|
drier_summary.driedSand AS sandDried,
|
|
coating_summary.coatingMachineGasconsumption,
|
|
coating_summary.coatedSand'
|
|
)
|
|
// Subquery with early date filtering
|
|
->join(
|
|
'(SELECT date,
|
|
SUM(totalGasconsumption) AS coatingMachineGasconsumption,
|
|
SUM(totalCoatingSandInKg) AS coatedSand
|
|
FROM t_coatingmachinedetails
|
|
WHERE is_active = 1
|
|
AND date >= ' . $this->db->escape($startDate) . '
|
|
AND date <= ' . $this->db->escape($endDate) . '
|
|
GROUP BY date
|
|
) AS coating_summary',
|
|
'coating_summary.date = t_gasstockdetails.date',
|
|
'left'
|
|
)
|
|
->join(
|
|
'(SELECT date,
|
|
SUM(total_gas_consumption) AS drierMachineGasconsumption,
|
|
SUM(sand_dried_qty) AS driedSand
|
|
FROM t_driermachinedetails
|
|
WHERE date >= ' . $this->db->escape($startDate) . '
|
|
AND date <= ' . $this->db->escape($endDate) . '
|
|
GROUP BY date
|
|
) AS drier_summary',
|
|
'drier_summary.date = t_gasstockdetails.date',
|
|
'left'
|
|
)
|
|
|
|
->where('t_gasstockdetails.date >=', $startDate)
|
|
->where('t_gasstockdetails.date <=', $endDate)
|
|
->groupBy('t_gasstockdetails.date')
|
|
->get()
|
|
->getResultArray();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|