Esempio n. 1
0
    public function consumption_ajax($sub_category = null)
    {
        $commodity_id = $this->input->post('commodity_id');
        $from = $this->input->post('from');
        $to = $this->input->post('to');
        $total = 0;
        $to = $to == "NULL" || !isset($to) ? date('Y-m-d 23:59:59') : date('Y-m-d 23:59:59', strtotime(urldecode($to)));
        $from = $from == "NULL" || !isset($from) ? date('Y-m-d 00:00:00') : date('Y-m-d 00:00:00', strtotime(urldecode($from)));
        $consumption = facility_stocks::get_dispensing_consumption($commodity_id, $from, $to, $sub_category);
        $result_table = "";
        $result_table .= '
		<table class="table table-bordered row-fluid datatable" id="ajax_commodity_table">
			<thead>				
				<th>Commodity Name</th>
				<th>Units Consumed</th>				
			</thead>

			<tbody>';
        if (count($consumption) > 0) {
            foreach ($consumption as $data) {
                $total += intval($data['total']);
                $result_table .= '<tr>						
						<td>' . $data['commodity'] . '</td>
						<td>' . $data['total'] . '</td>						
						</tr>';
            }
        } else {
            $result_table .= '<tr><td><b>There is no consumption history on this Commodity</b></td><td>N/A</td></tr>';
        }
        $result_table .= '<tr><td><b>Total:</b></td><td><b>' . $total . '</b></td></tr>';
        $result_table .= '</tbody></table>';
        echo $result_table;
    }