<?php
class Profil extends CI_Model {
    

    function __construct()
    {        
        parent::__construct();
    }
	
	
	public function saldo()
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT at_jenis.jenis, (sum(d)-sum(k)) as saldo FROM `at_jenis` left join transaksi on at_jenis.id = transaksi.id_jenis group by at_jenis.id");
        return $query->result();
    }
	
	public function jenis()
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * from at_jenis");
        return $query->result();
    }
	
	public function saldo_jenis($id)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT sum(d) as d, sum(k) as k, at_sub_jenis.id, at_sub_jenis.sub_jenis, (sum(d) - sum(k)) as saldo FROM `at_sub_jenis` left join transaksi on transaksi.id_sub_jenis = at_sub_jenis.id where at_sub_jenis.id_jenis='$id' group by at_sub_jenis.id");
        return $query->result();
    }
	
	public function saldo_sub_jenis($id)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM `transaksi` where id_sub_jenis='$id' order by tgl asc, waktu asc");
        return $query->result();
    }
	
    public function donasi($tabel)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM $tabel where v='1' order by tgl desc, id desc");
        return $query->result();
    }
	
	public function berita($jum, $tipe)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_berita where tipe='$tipe' order by tanggal desc limit $jum");
        return $query->result();
    }
	
	public function bukutamu_hal($tipe)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_bukutamu where tenan_id='$tipe'  and balas !=''");
        return $query->num_rows();
    }
	
	public function blog_hal($tipe)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_berita where tipe='$tipe'");
        return $query->num_rows();
    }
	
	public function pengeluaran_hal()
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM donasi_keluar where v='1'");
        return $query->num_rows();
    }
	
	public function promo_hal($tipe)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_promo where tipe='$tipe'");
        return $query->num_rows();
    }
	
	public function download_hal($tipe)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_download where tenan_id='$tipe'");
        return $query->num_rows();
    }
	
	public function testimoni_hal($tipe)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_testimoni where tipe='$tipe'");
        return $query->num_rows();
    }
    
    
    public function detail_berita($id)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_berita where id='$id'");
        return $query->result();
    }
    
    
	public function galeri_semua($cari, $limit)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_galeri $cari order by id DESC $limit");
        return $query->result();
    }
    
    
    public function bukutamu_semua($cari, $tipe, $limit)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_bukutamu where tenan_id='$tipe' and balas !='' order by waktu DESC $limit");
        return $query->result();
    }
	
	public function berita_semua($cari, $tipe, $limit)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_berita where tipe='$tipe' order by tanggal DESC $limit");
        return $query->result();
    }
	
	public function pengeluaran_semua($cari, $limit)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM donasi_keluar where v='1' order by tgl DESC $limit");
        return $query->result();
    }
	
	public function promo_semua($cari, $tipe, $limit)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_promo where tipe='$tipe' order by id DESC $limit");
        return $query->result();
    }
	
	public function download_semua($cari, $tipe, $limit)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_download where tenan_id='$tipe' order by id DESC $limit");
        return $query->result();
    }
	
	public function testimoni_semua($cari, $tipe, $limit)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_testimoni where tipe='$tipe' $limit");
        return $query->result();
    }
    
    
	public function galeri_hal($cari, $limit)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_galeri $cari order by id DESC $limit");
        return $query->num_rows();
    }
    
    
    public function gambar($id)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_gambar where id_produk='$id' order by id ASC");
        $jum= $query->num_rows();
        
        
        if($jum > 1){
            
            if($jum > 2){ $jum=$jum-1;}
        $this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_gambar where id_produk='$id' order by id ASC limit $jum");
        return $query->result();
        }
        
        if($jum < 2){
            
            if($jum > 2){ $jum=$jum-1;}
        $this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_gambar where id_produk='aaaad' order by id ASC limit $jum");
        return $query->result();
        }
        
        
        
        
        
    }
    
	
	
	


}