158 lines
6.7 KiB
PHP
158 lines
6.7 KiB
PHP
<?php
|
|
namespace App\Models\results;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class M415Model extends Model
|
|
{
|
|
|
|
public function getTotalCount($data)
|
|
{
|
|
$sql = "SELECT COUNT(*) AS cnt FROM ( ";
|
|
$sql .= "SELECT
|
|
*
|
|
FROM (
|
|
SELECT
|
|
stan_date,
|
|
'M' vrfc_type,
|
|
AVG((TIME_TO_SEC(conf_required_tm))) AS doc,
|
|
AVG((TIME_TO_SEC(cert_required_tm))) AS cert,
|
|
AVG((TIME_TO_SEC(tot_required_tm))) AS tot
|
|
FROM v2_time_required
|
|
WHERE stan_date BETWEEN '{$data['sdate']}' AND '{$data['edate']}'
|
|
AND vrfc_type IN ('M','O')
|
|
AND tot_required_tm IS NOT NULL
|
|
GROUP BY stan_date
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
stan_date,
|
|
'T' vrfc_type,
|
|
AVG((TIME_TO_SEC(conf_required_tm))) AS doc,
|
|
AVG((TIME_TO_SEC(cert_required_tm))) AS cert,
|
|
AVG((TIME_TO_SEC(tot_required_tm))) AS tot
|
|
FROM v2_time_required
|
|
WHERE stan_date BETWEEN '{$data['sdate']}' AND '{$data['edate']}'
|
|
AND vrfc_type = 'T'
|
|
AND tot_required_tm IS NOT NULL
|
|
GROUP BY stan_date
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
stan_date,
|
|
'D' vrfc_type,
|
|
AVG((TIME_TO_SEC(conf_required_tm))) AS doc,
|
|
AVG((TIME_TO_SEC(cert_required_tm))) AS cert,
|
|
AVG((TIME_TO_SEC(tot_required_tm))) AS tot
|
|
FROM v2_time_required
|
|
WHERE stan_date BETWEEN '{$data['sdate']}' AND '{$data['edate']}'
|
|
AND vrfc_type = 'D'
|
|
AND tot_required_tm IS NOT NULL
|
|
GROUP BY stan_date
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
stan_date,
|
|
'N' vrfc_type,
|
|
AVG((TIME_TO_SEC(conf_required_tm))) AS doc,
|
|
AVG((TIME_TO_SEC(cert_required_tm))) AS cert,
|
|
AVG((TIME_TO_SEC(tot_required_tm))) AS tot
|
|
FROM v2_time_required
|
|
WHERE stan_date BETWEEN '{$data['sdate']}' AND '{$data['edate']}'
|
|
AND vrfc_type = 'N'
|
|
AND tot_required_tm IS NOT NULL
|
|
GROUP BY stan_date
|
|
|
|
|
|
) summary
|
|
GROUP BY stan_date ) AS t ";
|
|
|
|
$query = $this->db->query($sql);
|
|
|
|
return $query->getRow()->cnt;
|
|
}
|
|
|
|
public function getResultList($data)
|
|
{
|
|
$sql = "SELECT
|
|
stan_date,
|
|
SUBSTR(SEC_TO_TIME(AVG(CASE vrfc_type WHEN 'M' THEN doc ELSE NULL END)),1,8) m_doc,
|
|
SUBSTR(SEC_TO_TIME(AVG(CASE vrfc_type WHEN 'M' THEN cert ELSE NULL END)),1,8) m_cert,
|
|
SUBSTR(SEC_TO_TIME(AVG(CASE vrfc_type WHEN 'M' THEN tot ELSE NULL END)),1,8) m_tot,
|
|
SUBSTR(SEC_TO_TIME(AVG(CASE vrfc_type WHEN 'T' THEN doc ELSE NULL END)),1,8) t_doc,
|
|
SUBSTR(SEC_TO_TIME(AVG(CASE vrfc_type WHEN 'T' THEN cert ELSE NULL END)),1,8) t_cert,
|
|
SUBSTR(SEC_TO_TIME(AVG(CASE vrfc_type WHEN 'T' THEN tot ELSE NULL END)),1,8) t_tot,
|
|
SUBSTR(SEC_TO_TIME(AVG(CASE vrfc_type WHEN 'D' THEN doc ELSE NULL END)),1,8) d_doc,
|
|
SUBSTR(SEC_TO_TIME(AVG(CASE vrfc_type WHEN 'D' THEN cert ELSE NULL END)),1,8) d_cert,
|
|
SUBSTR(SEC_TO_TIME(AVG(CASE vrfc_type WHEN 'D' THEN tot ELSE NULL END)),1,8) d_tot,
|
|
SUBSTR(SEC_TO_TIME(AVG(CASE vrfc_type WHEN 'N' THEN doc ELSE NULL END)),1,8) n_doc,
|
|
SUBSTR(SEC_TO_TIME(AVG(CASE vrfc_type WHEN 'N' THEN cert ELSE NULL END)),1,8) n_cert,
|
|
SUBSTR(SEC_TO_TIME(AVG(CASE vrfc_type WHEN 'N' THEN tot ELSE NULL END)),1,8) n_tot
|
|
FROM (
|
|
SELECT
|
|
stan_date,
|
|
'M' vrfc_type,
|
|
AVG((TIME_TO_SEC(conf_required_tm))) AS doc,
|
|
AVG((TIME_TO_SEC(cert_required_tm))) AS cert,
|
|
AVG((TIME_TO_SEC(tot_required_tm))) AS tot
|
|
FROM v2_time_required
|
|
WHERE stan_date BETWEEN '{$data['sdate']}' AND '{$data['edate']}'
|
|
AND vrfc_type IN ('M','O')
|
|
AND tot_required_tm IS NOT NULL
|
|
GROUP BY stan_date
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
stan_date,
|
|
'T' vrfc_type,
|
|
AVG((TIME_TO_SEC(conf_required_tm))) AS doc,
|
|
AVG((TIME_TO_SEC(cert_required_tm))) AS cert,
|
|
AVG((TIME_TO_SEC(tot_required_tm))) AS tot
|
|
FROM v2_time_required
|
|
WHERE stan_date BETWEEN '{$data['sdate']}' AND '{$data['edate']}'
|
|
AND vrfc_type = 'T'
|
|
AND tot_required_tm IS NOT NULL
|
|
GROUP BY stan_date
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
stan_date,
|
|
'D' vrfc_type,
|
|
AVG((TIME_TO_SEC(conf_required_tm))) AS doc,
|
|
AVG((TIME_TO_SEC(cert_required_tm))) AS cert,
|
|
AVG((TIME_TO_SEC(tot_required_tm))) AS tot
|
|
FROM v2_time_required
|
|
WHERE stan_date BETWEEN '{$data['sdate']}' AND '{$data['edate']}'
|
|
AND vrfc_type = 'D'
|
|
AND tot_required_tm IS NOT NULL
|
|
GROUP BY stan_date
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
stan_date,
|
|
'N' vrfc_type,
|
|
AVG((TIME_TO_SEC(conf_required_tm))) AS doc,
|
|
AVG((TIME_TO_SEC(cert_required_tm))) AS cert,
|
|
AVG((TIME_TO_SEC(tot_required_tm))) AS tot
|
|
FROM v2_time_required
|
|
WHERE stan_date BETWEEN '{$data['sdate']}' AND '{$data['edate']}'
|
|
AND vrfc_type = 'N'
|
|
AND tot_required_tm IS NOT NULL
|
|
GROUP BY stan_date
|
|
|
|
|
|
) summary
|
|
GROUP BY stan_date ";
|
|
|
|
|
|
$query = $this->db->query($sql);
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
} |