-4

MODEL

public function LaporanQuery($dari, $sampai, $pertashop){
       return $this->db->query("SELECT DATE_FORMAT(tbl_laporan1.tanggal,'%d/%m/%Y') AS tanggal, 
       id_pertashop, 
       ( SELECT ketinggian_stick 
         FROM tbl_stick 
         WHERE id_shift='1' 
           AND id_pengecekan='1' 
           AND DATE_FORMAT(tbl_stick.tanggal,'%d/%m/%Y') = DATE_FORMAT(tbl_laporan1.tanggal,'%d/%m/%Y') 
           AND tbl_stick.id_pertashop=tbl_laporan1.id_pertashop) AS StokAwal, 
       ( SELECT tbl_pembelian.jumlah 
         FROM tbl_pembelian 
         WHERE DATE_FORMAT(tbl_pembelian.tanggal,'%d/%m/%Y') = DATE_FORMAT(tbl_laporan1.tanggal,'%d/%m/%Y')
           AND tbl_pembelian.id_pertashop=tbl_laporan1.id_pertashop) AS Pembelian, 
       ( SELECT teller 
         FROM tbl_teller 
         WHERE id_pengecekan ='2'
           AND id_shift ='2' 
           AND DATE_FORMAT(tbl_teller.tanggal,'%d/%m/%Y')=DATE_FORMAT(tbl_laporan1.tanggal,'%d/%m/%Y') 
           AND tbl_teller.id_pertashop=tbl_laporan1.id_pertashop)
       - 
       ( SELECT teller 
         FROM tbl_teller 
         WHERE id_pengecekan ='1'
           AND id_shift = '1'
           AND DATE_FORMAT(tbl_teller.tanggal,'%d/%m/%Y')= DATE_FORMAT(tbl_laporan1.tanggal,'%d/%m/%Y')
           AND tbl_teller.id_pertashop=tbl_laporan1.id_pertashop) AS Penjualan, 
       ( SELECT ketinggian_stick
         FROM tbl_stick
         WHERE id_shift='2'
           AND id_pengecekan='2'
           AND DATE_FORMAT(tbl_stick.tanggal,'%d/%m/%Y') = DATE_FORMAT(tbl_laporan1.tanggal,'%d/%m/%Y')
           AND tbl_stick.id_pertashop=tbl_laporan1.id_pertashop) AS StockAkhir 
        FROM tbl_laporan1 
        ORDER BY tbl_laporan1.tanggal;
        ");
        return $query;
    }

Controller

public function index(){
        // $query['data'] = $this->M_AStick->DaftarStick()->result_array();
        $dari                       = $this->input->post('dari');
        $sampai                     = $this->input->post('sampai');
        $pertashop                  = $this->input->post('pertashop');
        $query['data_dari']         =  $dari;
        $query['data_sampai']       =  $sampai;
        $query['data_pertashop']    =  $pertashop;
        $query['nama_pertashop']    = $this->M_APertashop->daftar_pertashop();
        $query['pertashop']         = $this->M_APertashop->idpertashop()->result_array();
        $query['data']              = $this->M_APertashop->LaporanQuery($dari, $sampai,$pertashop)->result_array();
        
        // $query['yy'] = $this->M_APertashop->LaporanQueryAkhir($dari, $sampai,$pertashop);

        $this->template->set('title','Laporan');
        $this->template->load('layout_admin', 'contents', 'admin/laporan/daftar_laporan',$query);
    }
New contributor
eacm is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Browse other questions tagged or ask your own question.