<?php
class M_pelanggan extends CI_Model{

	function get_grafik_pelanggan(){
		$query=$this->db->query("SELECT DATE_FORMAT(plg_register,'%M') AS bulan,COUNT(plg_id) AS total FROM tbl_pelanggan WHERE YEAR(plg_register)=YEAR(CURDATE()) GROUP BY MONTH(plg_register)");

		if($query->num_rows() > 0){
            foreach($query->result() as $data){
                $hasil[] = $data;
            }
            return $hasil;
        }
	}

	function get_all_pelanggan(){
		$hsl=$this->db->query("select * from tbl_pelanggan order by plg_id desc");
		return $hsl;
	}

	function cek_pelanggan($u,$p){
		$hsl=$this->db->query("select * from tbl_pelanggan where plg_notelp='$u'");
		return $hsl;
	}
	function upd_pelanggan($u,$type,$toko,$p,$alamat,$lat,$lng){
		$hsl=$this->db->query("update tbl_pelanggan set kdtoko='$toko',plg_order='$type',plg_nama='$p',plg_alamat='$alamat',lat='$lat',lng='$lng' where plg_notelp='$u'");
		return $hsl;
	}
	function simpan_pelanggan_dengan_gambar($nama,$alamat,$jenkel,$kontak,$email,$facebook,$instagram,$line,$whatapp,$path,$pass,$gambar){
		$hsl=$this->db->query("INSERT ignore INTO tbl_pelanggan(plg_nama,plg_alamat,plg_jenkel,plg_notelp,plg_email,plg_facebook,plg_instagram,plg_line,plg_whatapp,plg_path,plg_photo,plg_password) VALUES ('$nama','$alamat','$jenkel','$kontak','$email','$facebook','$instagram','$line','$whatapp','$path','$gambar',md5('$pass'))");
		return $hsl;
	}
	function simpan_pelanggan_tanpa_gambar($nama,$alamat,$jenkel,$kontak,$email,$facebook,$instagram,$line,$whatapp,$path,$pass){
		$hsl=$this->db->query("INSERT ignore INTO tbl_pelanggan(plg_nama,plg_alamat,plg_jenkel,plg_notelp,plg_email,plg_facebook,plg_instagram,plg_line,plg_whatapp,plg_path,plg_password) VALUES ('$nama','$alamat','$jenkel','$kontak','$email','$facebook','$instagram','$line','$whatapp','$path',md5('$pass'))");
		return $hsl;
	}
	function hapus_pelanggan($kode){
		$hsl=$this->db->query("delete from tbl_pelanggan where plg_id='$kode'");
		return $hsl;
	}

	function get_all_pelanggan_terbaru(){
		$hsl=$this->db->query("select * from tbl_pelanggan order by plg_id desc");
		return $hsl;
	}
	public function get_detail_plg($nim) {
		$hsl = $this->db->query("SELECT * FROM tbl_pelanggan  WHERE plg_notelp='$idbarang'");
		if ($hsl->num_rows() > 0) {
			foreach ($hsl->result() as $data) {
				$hasil = array(
					'nama' => $data->plg_nama,
					'alamat' => $data->plg_alamat,
					'lat' => $data->lat,
					'lng' => $data->lng,
				);
			}
		}
		return $hasil;
	}
	

}