<script type="text/javascript" src="<?php echo base_url();?>resources/js/jquery.simplePagination.js"></script>
<div id="popup_harta_list" class="centering" style="width:100%;margin-top: 1%;background:white;">
	<div style="margin:3px;clear:both;"></div>
	<hr class="thick-line" style="clear:both;">
	<div id="left">
		<?php
		$attributes = array('id' => 'form_search_pihak');
		echo form_open(base_url().'perkara_harta_pailit_list/search',$attributes);
		?>
		<?php
		$attributes = array('name' => 'search', 'id' => 'search-box', 'type' => 'text','size' => '50','placeholder'=>"  Ketik kata kunci  ");
		echo form_input($attributes);
		$data = array(
			'enc' => "enc"
		);
		echo form_hidden($data);
		echo "<span>  </span>";
		$attributes = array('value' => 'Search', 'class' => 'btn', 'id' => 'search-btn1', 'type' => 'submit');
		echo form_submit($attributes);
		echo form_close('');
		?>
	</div>
	<div id="left" style="margin-left:50px;"><input type="button" id='addPihak' value="Tambah" class="btn"></div>
	<div id="pages" >
    	<div id="selector" style="padding: 4px 5px 5px 0;"></div>
    </div>
	<div class="cssTable">
		<table id="tablePerkaraAll">
			<col  width="3%" />
			<col  width="11%" />
			<col  width="12%" />
			<col  width="13%" />
			<col  width="12%" />
			<col  width="12%" />
			<col  width="12%" />
			<col  width="12%" />
			<col  width="9%" />
			<col  width="5%" />
        	<tbody>
				<tr>
				 	<td>No</td>
					<td onclick="sorting(1)">Tanggal Pendaftaran</td>
					<td onclick="sorting(2)">Nomor Perkara</td>
					<td onclick="sorting(3)">Para Pihak</td>
					<td onclick="sorting(4)">Tanggal Putusan Yang Dimohonkan</td>
					<td onclick="sorting(5)">Nama Hakim Pengawas</td>
					<td onclick="sorting(6)">Nama Panitera</td>
					<td onclick="sorting(7)">Nama Kurator</td>
					<td onclick="sorting(8)">Nama Kreditur</td>
					<td></td>
				</tr>
				<?php
				if($pailit!=''){
					$i=$page_active+1;
					if($pailit->num_rows>0){
						foreach ($pailit->result() as $row) {
							echo "<tr>";
								echo "<td>".$i."</td>";
								echo "<td>".$this->tanggalhelper->convertDate($row->tanggal_pendaftaran_harta)."</td>";
								echo "<td>".$row->nomor_perkara."</td>";
								echo "<td style='text-overflow: ellipsis;white-space: nowrap;overflow: hidden;'>".$row->para_pihak."</td>";
								echo "<td>".$this->tanggalhelper->convertDate($row->tanggal_putusan)."</td>";
								echo "<td style='text-overflow: ellipsis;white-space: nowrap;overflow: hidden;'>".$row->hakim_pengawas."</td>";
								echo "<td style='text-overflow: ellipsis;white-space: nowrap;overflow: hidden;'>".$row->panitera."</td>";
								echo "<td>".$row->nama_kurator."</td>";
								echo "<td>".$row->nama_kreditur."</td>";
								echo "<td style='text-align:center;'>
									<a href='#' onClick='popup_form(\"".base_url('manageHartaPailit/viewDetil/'.base64_encode($this->encrypt->encode($row->perkara_id)))."\")'>[Detil]</a>
									<a href='#' onClick='edit(\"".base64_encode($this->encrypt->encode($row->perkara_id))."\")'>[Edit]</a></td>";
							echo "</tr>";
							$i++;
						}
					}
				}
				?>
			</tbody>
		</table>
	</div>
	<div id="pages_bottom" style="width:100%;padding-left:5px;padding-top:5px;">
    	<div id="selector_bottom"></div>
	</div>
	<div style="margin:bottom:5px;"></div>
</div>
<div id="popup_harta" class="popup">
	<div style="margin: 0 auto;top: 50%;margin-top: 1%;margin-bottom: 25px;">
		<div class="detil" style="background-color:white;border-color: white;font-size:14px;margin-top:25px;width: 85%;margin: 0 auto;">
			<div id="sub_title" style="padding:10px;color:#5FB85C;text-align:center;"><?php echo 'TAMBAH/EDIT '.$page_title;?></div>
			<form id="frm_ref_harta" style="background:white;margin:0;" method="post" action="<?php echo base_url().'manageHartaPailit/validateInput';?>">
				<table id="tableDetilPerkara" style="font-size:14px;width:100%;">
				<col width="25%">
				<col width="75%">
					<tbody>
						<tr>
							<td>Tanggal Pendaftaran<font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input id="tgl_pendaftaran" name="tgl_pendaftaran" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td>Nomor Perkara <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input list="no_perkara_list" type="text" id='no_perkara' name='no_perkara' value="" class="standard-input" maxlength="200">
								<datalist id="no_perkara_list" style="height:200px;overflow:scroll;">
									<?php
									if($list_perkara!=''){
										if($list_perkara->num_rows>0){
											foreach ($list_perkara->result() as $row) {
												echo '<option data-id="'.base64_encode($this->encrypt->encode($row->perkara_id)).'" value="'.$row->nomor_perkara.'">'.$row->nomor_perkara.'</option>';
											}
										}
									}
									?>
								</datalist>
							</td>
						</tr>
						<tr id="tr_parapihak">
							<td>Para Pihak <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;" id='parapihak'></td>
						</tr>
						<tr>
							<td>Putusan Yang Dimohonkan Pemberesan Harta Pailit </td>
							<td style="padding:0px;padding-left:5px;" id="put_no"></td>
						</tr>
						<tr>
							<td>Tanggal Putusan Yang Dimohonkan Pemberesan Harta Pailit </td>
							<td style="padding:0px;padding-left:5px;" id="td_putusan"></td>
						</tr>
						<tr>
							<td>Tanggal Penetapan Hakim Pengawas</td>
							<td style="padding:0px;padding-left:5px;">
								<input id="tgl_pen_hakim" name="tgl_pen_hakim" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td id="first-child">Hakim Pengawas</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style='width:180px;'>
									<select name="hakim" id="hakim" style='width:180px;' class="custom-dropdown__select custom-dropdown__select--white">
										<option value="0">Pilih Hakim Pengawas</option>
										<?php
										if($hakim !=''){
											if($hakim->num_rows>0){
												foreach ($hakim->result() as $row) {
													echo '<option value="'.$row->id.'">'.$row->nama_gelar.'</option>';
												}
											}
										}
										?>
									</select>
								</span>
							</td>
						</tr>
						<tr>
							<td id="first-child">Kurator</td>
								<td style="padding:0px;padding-left:5px;">
									<span class="custom-dropdown custom-dropdown--emerald" style='width:180px;'>
										<select name="kurator" id="kurator" style='width:180px;' class="custom-dropdown__select custom-dropdown__select--white">
											<option value="">Pilih Kurator</option>
											<?php
											if($kurator !=''){
												if($kurator->num_rows>0){
													foreach ($kurator->result() as $row) {
														echo '<option value="'.$row->pihak_id.'">'.$row->nama.'</option>';
													}
												}
											}
											?>
										</select>
									</span>
							</td>
						</tr>
						<tr>
							<td>Terjadinya Insolvensi</td>
							<td style="padding:0px;padding-left:5px;">
								<input id="tgl_insolvensi" name="tgl_insolvensi" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td>Amar Penetapan Hakim Pengawas</td>
							<td style="background:white;" id="amar_text">
								<?php echo $this->ckeditor->editor("amar",'');?>
							</td>
						</tr>
						<tr>
							<td id="first-child">Nama Panitera</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style='width:180px;'>
									<select name="panitera" id="panitera" style='width:180px;' class="custom-dropdown__select custom-dropdown__select--white">
										<option value="0">Pilih Panitera</option>
										<?php
										if($panitera !=''){
											if($panitera->num_rows>0){
												foreach ($panitera->result() as $row) {
													echo '<option value="'.$row->id.'">'.$row->nama_gelar.'</option>';
												}
											}
										}
										?>
									</select>
								</span>
							</td>
						</tr>
						<tr>
							<td id="first-child">Nama Jurusita</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style='width:180px;'>
									<select name="jurusita" id="jurusita" style='width:180px;' class="custom-dropdown__select custom-dropdown__select--white">
										<option value="0">Pilih Jurusita</option>
										<?php
										if($jurusita !=''){
											if($jurusita->num_rows>0){
												foreach ($jurusita->result() as $row) {
													echo '<option value="'.$row->id.'">'.$row->nama_gelar.'</option>';
												}
											}
										}
										?>
									</select>
								</span>
							</td>
						</tr>
						<tr>
							<td>Tanggal Pelelangan</td>
							<td style="padding:0px;padding-left:5px;">
								<input id="tgl_lelang" name="tgl_lelang" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td>Tanggal Pembagian</td>
							<td style="padding:0px;padding-left:5px;">
								<input id="tgl_bagi" name="tgl_bagi" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td>Nama Kreditur</td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='kreditur' name='kreditur' value="" class="standard-input" maxlength="200">
							</td>
						</tr>
						<tr>
							<td>Jumlah Pembagian <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='jml_bagi' name='jml_bagi' value="" class="standard-input" maxlength="200">
							</td>
						</tr>
						<tr>
							<td>Keterangan</td>
							<td style="padding:0px;padding-left:5px;border:0px;">
								<input type="hidden" id="curr_date" value="<?php echo $curr_date;?>">
								<input type="hidden" id="enc" name="enc" value="">
								<input type="hidden" id="enc_pihak" name="enc_pihak" value="">
								<input type="hidden" id="refresh" value="0">
								<input type="hidden" id="enc_act" name="enc_act" value="<?php echo $enc_act;?>">
								<textarea id="keterangan" name="keterangan" class="standard-input" style="width: 600px; height: 70px;resize: none;"></textarea>
							</td>
						</tr>
						<tr>
								<td colspan="2" style="background:white;" align="center">
								<input type="button" id='back_harta' value="Kembali" class="btn">
								<?php
								#if($this->authorization->isAuthorized('hakim_pn_edit',$AuthorizationForm)){
								?>
								<?php
								echo '<input type="submit" id="hapus" value="Hapus" class="del_btn" onclick="return false;">';
								?>
									<input type="submit" id="simpan_btn" value="Simpan" class="btn">
								<?php
								#}
								?>
							</td>
							</tr>
					</tbody>
				</table>
			</form>
		</div>
	</div>
</div>
<script type="text/javascript">
function refreshPihakList(){
	$("#popup_form_2nd").remove();
	popup_form2nd('<?php echo base_url("pihak_list");?>')
	$("#refresh").remove();
}
$('#close_form_2nd').closingForm2ndWin();
var act = 'add';
$('#no_perkara').change(function() {
	var np = $('#no_perkara').val();
    var val = $('#no_perkara_list option').filter(function() {
        return this.value == np;
    }).data('id');
	if(np==''){
		message_error_show('Nomor Perkara Wajib Diisikan');
		$('#no_perkara').css("background-color", "red");
		return
	}else{
		$('#no_perkara').css("background-color", "#dedbdb");
	}
	openLoadingDialog()
	$.post('<?php echo base_url()?>manageHartaPailit/fetchData', {
		val:val,
		act:act
	}, function(response){
		var json = jQuery.parseJSON(response);
		closeLoading()
		if(json.st==1){
			$('#enc').val(json.enc);
			$('#enc_act').val(json.enc_act);
			$('#td_putusan').text(json.tglPutusan);
			$('#put_no').text(json.noPerkara);
			$('#parapihak').remove();
			$("#tr_parapihak").append(json.parapihak);
			$('#hakim').val(json.hakim);
			$('#kurator').val(json.kurator);
			$('#panitera').val(json.panitera);
			$('#jurusita').val(json.jurusita);
			$('#tgl_pen_hakim').val(json.penHakim);
		}else if(json.st==0){
			clearInput();
			message_error_show(json.msg);
		}
	});
});

function clearInput(){
	$('#no_perkara').val('');
	$('#td_putusan').text('');
	$('#td_minut').text('');
	$('#parapihak').text('');
	$('#tgl_pendaftaran').val('');
	$('#keterangan').val('');
	$('#hakim').val('');
	$('#kurator').val('');
	$('#panitera').val('');
	$('#jurusita').val('');
	$('#tgl_pen_hakim').val('');
	CKEDITOR.instances['amar'].setData('');
}

$("#back_harta").click(function() {
	$('#popup_harta_list').fadeIn();
	clearInput();
	$('#popup_harta').fadeOut();
    $("body").css({overflow: 'hidden'});
    if($("#refresh").val()==1){
    	window.open('<?php echo $url_requested;?>','_self')
    }
});

$('#frm_ref_harta').SubmitHandling({
	refresh:'1',
	setRefresh:1,
	divRef:'#konten',
	clicked:1,
	btnClicked:'#back_harta',
	whenStatus:1,
	isCKEdit:1,
	tdID:'amar_text',
	textID:'amar',
});

$('#hapus').ButtonClickHandling({
	refresh:'1',
	setRefresh:0,
	divRef:'#konten',
	clicked:1,
	btnClicked:'#back_harta',
	whenStatus:1,
	actions:'<?php echo base_url()?>manageHartaPailit/validateDelete',
	formName:'#frm_ref_harta',
	actionName:'Menghapus Data'
});

function edit(val){
	if(val==""){
		message_show("Error <br/> Refresh Browser Anda");
		return;
	}

	openLoadingDialog()
	$.post('<?php echo base_url()?>manageHartaPailit/fetchData', {
		val:val,
		act:'updt'
	}, function(response){
		var json = jQuery.parseJSON(response);
		closeLoading()
		if(json.st==1){
			$('#no_perkara').prop('readonly', true);
			//$('#no_perkara_list').prop('readonly', true);
			$('#no_perkara').css("background-color", "#26CFDD");
			$('#hapus').show();
			$('#enc').val(json.enc);
			$('#enc_act').val(json.enc_act);

			$('#no_perkara').val(json.noPerkara);
			$('#td_putusan').text(json.tglPutusan);
			$('#tgl_pendaftaran').val(json.tglPendaftaranHarta);
			$('#td_minut').text(json.tglMinutasi);
			$('#parapihak').remove();
			$("#tr_parapihak").append(json.parapihak);
			$('#hakim').val(json.hakim);
			$('#kurator').val(json.kurator);
			$('#panitera').val(json.panitera);
			$('#jurusita').val(json.jurusita);
			$('#tgl_pen_hakim').val(json.penHakim);

			$("#tgl_insolvensi").val(json.tglInsol);
			$('#tgl_lelang').val(json.tglLelang);
			$('#tgl_bagi').val(json.tglPembagi);
			$('#kreditur').val(json.kreditur);
			$('#jml_bagi').val(json.jmlPembagi);
			$('#keterangan').val(json.catatatn);
			CKEDITOR.instances['amar'].setData(json.amar);
			
			$('#popup_harta').fadeIn();
			act = 'updt';
			$("body").css({overflow: 'hidden'});
			return
		}else if(json.st==0){
			message_show(json.msg);
		}
	});
	
}
$("#addPihak").click(function() {
	openLoadingDialog()
	clearInput()
	$('#no_perkara').prop('readonly', false);
	//$('#no_perkara_list').prop('readonly', false);
	$('#no_perkara').css("background-color", "white");
	$('#popup_harta_list').fadeOut();
	$('#popup_harta').fadeIn();
	$('#hapus').hide();
	$('#act').val('add');
	act = 'add';
    $("body").css({overflow: 'hidden'});
    closeLoading()
});
</script>
<script language="javascript">
$(function() {
    var totalPage = '<?php echo $total_rows; ?>';
    var page = '<?php echo $page_number;?>';
    $('#selector').pagination({
        items: totalPage,
        itemsOnPage: 50,
        displayedPages: 3,
        cssStyle: 'light-theme',
        currentPage:page,
        onPageClick: function(pageNumber){
        	openLoadingDialog()
        	$.post('<?php echo base_url()?>perkara_harta_pailit_list/setPage', {
        		pageNumber:pageNumber,
        		keyword:$('#keyword_pihak').val()
			}, function(response){
				var json = jQuery.parseJSON(response);
				closeLoading()
				if(json.st==1){
					refreshPihakList()
				}else{
					message_show("Error, Tutup Browser anda kemudian login kembali");
				}
			});
            
        	}
        });
    $('#selector_bottom').pagination({
        items: totalPage,
        itemsOnPage: 50,
        displayedPages: 3,
        cssStyle: 'light-theme',
        currentPage:page,
        onPageClick: function(pageNumber){
            openLoadingDialog()
        	$.post('<?php echo base_url()?>perkara_harta_pailit_list/setPage', {
        		pageNumber:pageNumber,
        		keyword:$('#keyword_pihak').val()
			}, function(response){
				var json = jQuery.parseJSON(response);
				closeLoading()
				if(json.st==1){
					refreshPihakList()
				}else{
					message_show("Error, Tutup Browser anda kemudian login kembali");
				}
			});
            
        	}
        });
    $('#tgl_pendaftaran').datepicker({
    	inline: true,
    	showOtherMonths: true,
    	dateFormat: 'dd/mm/yy',
    	dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
    	beforeShowDay: $.datepicker.noWeekends,
    	onSelect: function(dateText, inst) {
            var tmp = $(this).val().split("/");
			var tmp2 = $('#curr_date').val().split("/");
			if((new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00").getTime() > new Date(tmp2[2]+"-"+tmp2[1]+"-"+tmp2[0]+"T00:00:00").getTime())){
				message = 'Tidak Dapat Memilih Melebihi Hari ini. Sekarang Tanggal '+$('#curr_date').val();
				message_error_show(message);
				$(this).css("background-color", "red");
			}else{
				$(this).css("background-color", "#dedbdb");
			}
        }
    });

    $('#tgl_pen_hakim').datepicker({
    	inline: true,
    	showOtherMonths: true,
    	dateFormat: 'dd/mm/yy',
    	dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
    	beforeShowDay: $.datepicker.noWeekends,
    	onSelect: function(dateText, inst) {
            var tmp = $(this).val().split("/");
			var tmp2 = $('#curr_date').val().split("/");
			if((new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00").getTime() > new Date(tmp2[2]+"-"+tmp2[1]+"-"+tmp2[0]+"T00:00:00").getTime())){
				message = 'Tidak Dapat Memilih Melebihi Hari ini. Sekarang Tanggal '+$('#curr_date').val();
				message_error_show(message);
				$(this).css("background-color", "red");
			}else{
				$(this).css("background-color", "#dedbdb");
			}
        }
    });

    $('#tgl_insolvensi').datepicker({
    	inline: true,
    	showOtherMonths: true,
    	dateFormat: 'dd/mm/yy',
    	dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
    	beforeShowDay: $.datepicker.noWeekends,
    	onSelect: function(dateText, inst) {
            var tmp = $(this).val().split("/");
			var tmp2 = $('#curr_date').val().split("/");
			if((new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00").getTime() > new Date(tmp2[2]+"-"+tmp2[1]+"-"+tmp2[0]+"T00:00:00").getTime())){
				message = 'Tidak Dapat Memilih Melebihi Hari ini. Sekarang Tanggal '+$('#curr_date').val();
				message_error_show(message);
				$(this).css("background-color", "red");
			}else{
				$(this).css("background-color", "#dedbdb");
			}
        }
    });

    $('#tgl_lelang').datepicker({
    	inline: true,
    	showOtherMonths: true,
    	dateFormat: 'dd/mm/yy',
    	dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
    	beforeShowDay: $.datepicker.noWeekends,
    	onSelect: function(dateText, inst) {
            var tmp = $(this).val().split("/");
			var tmp2 = $('#curr_date').val().split("/");
			if((new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00").getTime() > new Date(tmp2[2]+"-"+tmp2[1]+"-"+tmp2[0]+"T00:00:00").getTime())){
				message = 'Tidak Dapat Memilih Melebihi Hari ini. Sekarang Tanggal '+$('#curr_date').val();
				message_error_show(message);
				$(this).css("background-color", "red");
			}else{
				$(this).css("background-color", "#dedbdb");
			}
        }
    });

    $('#tgl_bagi').datepicker({
    	inline: true,
    	showOtherMonths: true,
    	dateFormat: 'dd/mm/yy',
    	dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
    	beforeShowDay: $.datepicker.noWeekends,
    	onSelect: function(dateText, inst) {
            var tmp = $(this).val().split("/");
			var tmp2 = $('#curr_date').val().split("/");
			if((new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00").getTime() > new Date(tmp2[2]+"-"+tmp2[1]+"-"+tmp2[0]+"T00:00:00").getTime())){
				message = 'Tidak Dapat Memilih Melebihi Hari ini. Sekarang Tanggal '+$('#curr_date').val();
				message_error_show(message);
				$(this).css("background-color", "red");
			}else{
				$(this).css("background-color", "#dedbdb");
			}
        }
    });

});

$('.datepicker').ValidateDateInput();
</script>
