<?php

class Pelanggan extends Controller{
    public function index(){
        $data['judul']='Daftar Pelanggan';
        $data['plgn']=$this->model('Pelanggan_model')->getPelangganAll();
        $data['plgn']=$this->model('Pelanggan_model')->getAllPelanggann();
        $this->view('templates/header', $data);
        $this->view('pelanggan/index', $data);
        $this->view('templates/footer');
    }
    public function detail($IDPEL){
        $data['judul']='Detail Pelanggan';
        $data['plgn']=$this->model('Pelanggan_model')->getPelangganbyid($IDPEL);
        $this->view('templates/header', $data);
        $this->view('pelanggan/detail', $data);
        $this->view('templates/footer');
    }
    public function tambah(){
        if($this->model('Pelanggan_model')->tambahdataplgn($_POST)>0){
            Flashnotif::setFlash('berhasil','ditambah','alert alert-success');
            header('Location:'. BASEURL .'/pelanggan');
            exit;
        }else{
            Flashnotif::setFlash('gagal','ditambah','alert alert-danger');
            header('Location:'. BASEURL .'/pelanggan');
            exit;
        }
    }
    public function hapus($IDPEL){
        if($this->model('Pelanggan_model')->hapusdataplgn($IDPEL)>0){
            Flashnotif::setFlash('berhasil','dihapus','alert alert-success');
            header('Location:'. BASEURL .'/pelanggan');
            exit;
        }else{
            Flashnotif::setFlash('gagal','dihapus','alert alert-danger');
            header('Location:'. BASEURL .'/pelanggan');
            exit;
        }
    }
    public function editplgn(){
        echo json_encode($this->model('Pelanggan_model')->getpelangganbyid($_POST['IDPEL']));
        
    }
    public function ubah() {
        if ($this->model('Pelanggan_model')->ubahdataplgn($_POST) > 0) {
            Flashnotif::setFlash('berhasil', 'diubah', 'alert alert-success');
            header('Location: ' . BASEURL . '/pelanggan');
            exit;
        } else {
            Flashnotif::setFlash('gagal', 'diubah', 'alert alert-danger');
            header('Location: ' . BASEURL . '/pelanggan');
            exit;
        }
    }
    public function cari(){
        $data['judul']='Daftar Pelanggan';
        $data['plgn']=$this->model('Pelanggan_model')->caridataplgn();
        $this->view('templates/header', $data);
        $this->view('pelanggan/index', $data);
        $this->view('templates/footer');
    }
    

}    
