การเรียกใช้ฟังก์ชั่นแสดงรายงานแนวนอน แสดงผลรวมผู้ใช้บริการ แยกตามประเภท

โดย SONGCHAI SAETERN
การเรียกใช้ฟังก์ชั่นแสดงรายงานแนวนอน แสดงผลรวมผู้ใช้บริการ แยกตามประเภท



มาดูขั้นตอนการเรียกใช้งานฟังก์ชั่นกันแบบทีละขั้นตอนกันครับ






ส่วนของ Model

        public function report_summary($begin_date, $final_date)
{
$begin_date = setDateToStandard($begin_date);
$final_date = setDateToStandard($final_date);
//SET data list
$left_join = "LEFT JOIN group_enrolment ON enrolment.Enrolment_id = group_enrolment.Enrolment_id";
$where_search = "WHERE begin_date >= '$begin_date' AND final_date <= '$final_date'";

//Group data by vertical_id and horizontal_id
$summary_config = array(
'table_name' => 'enrolment',
'vertical_id' => 'enrolment.Enrolment_id', 
'vertical_name' => 'enrolment.organization',
'horizontal_id' => 'group_enrolment.`type`', 
'summary_field' => 'group_enrolment.num', 
'other_select' => 'enrolment.begin_date', 
'join_condition' => $left_join, 
'where_condition' => $where_search
);
$this->summary = $summary_config;
//SET thead list
$thead_config = array(
'table' => 'type', 
'id' => 'type_id', 
'name' => 'type_name'
);
$this->summary_hor = $thead_config;
//
$data = $this->summary_group_hor();
return $data;
}


ส่วนของ Controller

        public function report_summary()
{
$this->breadcrumb_data['breadcrumb'] = array(
array('title' => 'Enrolment', 'url' => site_url('ice_siep/enrolment')),
array('title' => 'สรุป', 'url' => '#', 'class' => 'active')
);
$begin_date = $this->input->post('begin_date', TRUE);
$final_date = $this->input->post('final_date', TRUE);
if($begin_date == ''){
$begin_date = '01/'. date('m') . '/'. (date('Y') + 543);
}
if($final_date == ''){
$final_date = date('t'). '/' . date('m') . '/'. (date('Y') + 543);
}
$summary = $this->Enrolment->report_summary($begin_date, $final_date);
$this->data['colspan'] = $summary['colspan'];
$this->data['thead_list'] = $summary['thead_list'];
$this->data['data_list'] = $summary['data_list'];
$this->data['sum_column'] = $summary['sum_column'];
$this->data['grand_total'] = $summary['grand_total'];
$this->data['begin_date'] = $begin_date;
$this->data['final_date'] = $final_date;
$this->render_view('ice_siep/enrolment/report_summary');
}

ส่วนของ View


                        <table class="table table-bordered table-striped table-hover">
<thead class="info">
<tr bgcolor="#eeeeee">
<th rowspan="2">วันที่</th>
<th rowspan="2">สถาบัน / หน่วยงาน</th>
<th colspan="{colspan}" class="text-center">ผู้มาใช้บริการแบบกลุ่ม</th>
<th rowspan="2">รวม</th>
</tr>
<tr bgcolor="#dddddd">
{thead_list}
</tr>
</thead>
<tbody>
<tr parser-repeat="[data_list]">
<td>{begin_date}</td>
<td>{organization}</td>
{sum_td_list}
<td>{sub_total}</td>
</tr>
<tr>
<td colspan="2">รวม</td>
{sum_column}
<td>{grand_total}</td>
</tr>
</tbody>
</table>




วิธีเพิ่มคอมม่าหลักพัน และเปลี่ยนช่องว่าเป็น 0






ดูตัวอย่างเพิ่มเติม และคู่มือฉบับเต็มได้ที่
https://phpcodemania.blogspot.com/p/php-ci-mania.html#fqa






PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม
http://fastcoding.phpcodemania.com