<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Epayment extends CI_Model{

	function epayment_va($search=FALSE, $status=0){
		try {
			$where = " status_bayar=".$status;
			if($search==FALSE){
				$where .= " AND TIME_TO_SEC((TIMEDIFF(expired_date,NOW())))>=0";
			}else{
				$where .= " AND is_jurnal<>1 AND (LOWER(customer_name) like '%".$search."%' OR  va_id like '%".$search."%')";
			}
			$query = $this->db->query( "SELECT epayment_id,
										  perkara_id,
										  alur_perkara_id,
										  jenis_biaya,
										  tahapan_id,
										  va_id,
										  customer_name,
										  email,
										  telepon,
										  nominal,
										  DATE(created_time) AS tgl_rekam,
										  DATE_FORMAT(created_time,'%H:%i') AS jam_rekam,
										  DATE(expired_date) AS tgl_hbs,
										  DATE_FORMAT(expired_date,'%H:%i') AS jam_hbs,
										  status_bayar,
										  TIME_TO_SEC((TIMEDIFF(expired_date,NOW()))) AS selisih,
										  is_jurnal 
										FROM
										  epayment_virtual_account 
										WHERE ".$where."  ORDER BY created_time ASC");
			return $query;
		} catch (Exception $e) {
			
		}
	}

	function tampil_alurperkara(){
		try {
			$query = $this->db->query( "SELECT id,nama,jenis_pengadilan FROM alur_perkara WHERE id<100;");
			return $query;
		} catch (Exception $e) {
			
		}
	}

	function cari($nomor_perkara){		
		try{				 	
			$sql = "SELECT nomor_perkara FROM perkara WHERE alur_perkara_id<100  AND nomor_perkara LIKE '".$nomor_perkara."/%' AND tahapan_terakhir_id>=15 ORDER BY split_string(nomor_perkara,'/',3) DESC, split_string(nomor_perkara,'/',2) DESC, split_string(nomor_perkara,'/',1) DESC";		
			$query = $this->db->query($sql);
			return $query;
		}catch(Exception $e){
		}
	}

	function cari_data_pihak($nomor_perkara){
		try {
			$query = $this->db->query( "SELECT p.perkara_id,p1.nama,ph.telepon,ph.email,p.alur_perkara_id,ap.nama AS nama_alur FROM perkara AS p
										LEFT JOIN perkara_pihak1 AS p1 ON p.perkara_id=p1.perkara_id
										LEFT JOIN pihak AS ph ON p1.pihak_id=ph.id
										LEFT JOIN alur_perkara AS ap ON ap.id=p.alur_perkara_id
										WHERE p1.urutan=1 AND nomor_perkara LIKE '%".$nomor_perkara."%';");
			return $query;
		} catch (Exception $e) {
			
		}
	}
}

?>