<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Pembayaran_model extends CI_Model {

	public function __construct()
	{
		parent::__construct();
		$this->load->database();
	}	

	//ambil data data
	public function listing()
	{

		$this->db->select('*');
		$this->db->from('v_rpt_trans_formulir');
		$this->db->order_by('tgl_trans','desc');
		$query = $this->db->get();
		return $query->result();			
	}

	//ambil detail data data
	public function detail($no_trans)
	{

		$this->db->select('*');
		$this->db->from('v_rpt_trans_formulir');
		//where
		$this->db->where('no_trans', $no_trans);
		$this->db->order_by('no_trans','desc');
		$query = $this->db->get();
		return $query->row();			
	}


	//hitung total data
	public function total()
	{

		$this->db->select('COUNT(*) AS total');
		$this->db->from('v_rpt_trans_formulir');
		$this->db->order_by('no_pendaftaran','desc');
		$query = $this->db->get();
		return $query->row();			
	}

	//fungsi edit
	public function edit($data)
	{
		$this->db->where('no_trans', $data['no_trans']);
		$this->db->update('tr_formulir', $data);
	}

	//fungsi delete
	public function delete($data)
	{
		$this->db->where('no_trans', $data['no_trans']);
		$this->db->delete('tr_formulir', $data);
	}

	//ambil data ViewUrut
	public function ViewUrut()
	{

		$this->db->select('*');
		$this->db->from('v_rpt_trans_formulir');
		$this->db->order_by('no_pendaftaran','ASC');
		$query = $this->db->get();
		return $query->result();			
	}

	public function regis($no_pendaftaran)
	{
		$this->db->select('*');
		$this->db->from('v_rpt_data_formulir');
		$this->db->where('no_pendaftaran', $no_pendaftaran);
		$this->db->order_by('no_pendaftaran','desc');
		$query = $this->db->get();
		return $query->row();		
	}

	public function regis2($no_pendaftaran)
	{
		$this->db->select('*');
		$this->db->from('v_rpt_trans_formulir');
		$this->db->where('no_pendaftaran', $no_pendaftaran);
		$this->db->order_by('angsuran','Asc');
		$query = $this->db->get();
		return $query->result();		
	}

	// Total formulir
	public function regis3($no_pendaftaran)
	{
		$this->db->select('SUM(bayar) AS bayar');
		$this->db->from('v_rpt_trans_formulir');
		$this->db->where('no_pendaftaran', $no_pendaftaran);		
		$query = $this->db->get();
		return $query->row();	
	}	

	public function get_sum()
	{
		$sql = "SELECT sum(bayar) as bayar FROM v_rpt_trans_formulir";
		$result = $this->db->query($sql);
		return $result->row()->bayar;
	}	

}

/* End of file Pendaftar_model.php */
/* Location: ./application/models/Pendaftar_model.php */