<?php


class Laporandetail extends CI_Controller
{


    public function __construct()
    {
        parent::__construct();
        chek_session();
        $this->load->model('Model_detail');
    }


    function index($start = null , $end = null)
    {
        if (isset($_POST['search'])) {
            $start = $this->input->post('start_date');
            $end = $this->input->post('end_date');
            $metode = $this->input->post('metode');
            $data['laporan'] = $this->Model_detail->get_range($start,$end,$metode);
            $data['metode'] = $this->Model_detail->get_metode();
            $this->template->load('Template/template', 'Laporan/lap_detail', $data);
            $this->load->view('Template/datatables');
        } 
        
        elseif (isset($_POST['print'])) {
            $start = $this->input->post('start_date');
            $end = $this->input->post('end_date');
            $metode = $this->input->post('metode');
            $data['laporan'] = $this->Model_detail->get_range($start,$end,$metode);
            $data['metode'] = $this->Model_detail->get_metode();
            $data['start'] = $start;
            $data['end'] = $end;
           
            $this->load->view('laporan/printlaporan',$data);
        }
        else {
            $data['laporan'] = $this->Model_detail->get_data();
            $data['metode'] = $this->Model_detail->get_metode();
            $this->template->load('Template/template', 'Laporan/lap_detail', $data);
            $this->load->view('Template/datatables');
        }
    }

    public function print_pdf($start = null, $end = null) {
        // Mengambil data dari model berdasarkan rentang tanggal dan metode yang diberikan
        $start = $this->input->get('start_date');
        $end = $this->input->get('end_date');
        $metode = $this->input->get('metode');
        $data['laporan'] = $this->Model_detail->get_range($start, $end, $metode);
        $data['start'] = $start;
        $data['end'] = $end;
    
        
        $this->load->view('laporan/printlaporan', $data);
    }
    

    function hapus($id)
    {
        $this->Model_laporan->hapus_trf($id);
        $this->Model_laporan->hapus_id($id);
    }
}
