<?php
$b_pendaftaran = 0;
$b_atk = 0;
if($biaya!=''){
	if($biaya->num_rows>0){
		foreach ($biaya->result() as $row) {
			if($row->id==61){
				$b_pendaftaran = round($row->jumlah);
			}elseif ($row->id==155) {
				$b_atk = round($row->jumlah);
			}
		}
	}
}
?>
<hr class="thick-line" style="clear:both;">
<div style="padding:20px;"></div>
	<div class="detil" style="font-size:14px;margin-top:25px;width: 50%;margin: 0 auto;border-color: #FFFFFF;">
		<form id="frm_add_perdata" style="background:white;margin:0;" method="post" action="<?php echo base_url().'add_perdata/validateInput';?>">
			<table id="tableDetilPerkara" style="font-size:14px;">
				<col width="30%">
				<col width="70%">
				<tbody>
					<tr id="rw_generate">
						<td >Generate Nomor</td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald" style='width:80px;'>
								<select name="generate" id="generate" style='width:80px;' class="custom-dropdown__select custom-dropdown__select--white">
									<option value="1">Ya</option>
									<option value="0">Tidak</option>
								</select>
							</span>
						</td>
					</tr>
					<tr>
						<td>Tanggal Pendaftaran <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input id="tgl_pendaftaran" name="tgl_pendaftaran" value="<?php echo date('d/m/Y');?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
						</td>
					</tr>
					<tr id="rw_generate">
						<td >Klasifikasi Perkara</td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald" style='width:400px;'>
								<select style='width:400px;' name="klas_perkara" id="klas_perkara" class="custom-dropdown__select custom-dropdown__select--white">
									<option value="-1">Pilih Klasifikasi Perkara</option>
									<?php
									if($jenis_perkara!=''){
										if($jenis_perkara->num_rows>0){
											foreach ($jenis_perkara->result() as $row) {
												echo '<option value="'.$row->id.'">'.$row->nama.'</option>';
											}
										}
									}
									?>
								</select>
							</span>
						</td>
					</tr>
					<tr>
						<td>Nomor Urut <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input type="text" id='no_urut' name='no_urut' value="<?php echo $no_urut;?>" class="standard-input" maxlength="10" readonly="readonly" style="width:50px;">
						</td>
					</tr>
					<tr id="rw_no_perkara_auto">
						<td>Nomor Perkara <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input type="text" id='no_perkara_auto' name='no_perkara_auto' value="<?php echo $no_perkara;?>" style="width:180px;"class="standard-input" maxlength="255" readonly="readonly">
							<input type="hidden" id="urutan" value="<?php echo $no_perkara;?>">
						</td>
					</tr>
					<tr id="rw_no_perkara_manual" disabled>
						<td>Nomor Perkara <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input type="text" id='no_urutan_manual' name='no_urutan_manual' value="<?php echo $no_urutan_perkara;?>" class="standard-input" maxlength="10" style="width:50px;">
							<input type="text" id='no_perkara_manual' name='no_perkara_manual' value="<?php echo $no_perkara_manual;?>" class="standard-input" maxlength="100" style="width:192px;">
						</td>
					</tr>
					<tr>
						<td style="background:white;padding:2px;"></td>
					</tr>
					<tr>
						<td>Biaya Perkara</td>
					</tr>
					<tr id="rw_prodeo">
						<td >Prodeo <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald" style='width:80px;'>
								<select name="prodeo" id="prodeo" style='width:80px;' class="custom-dropdown__select custom-dropdown__select--white">
									<option value="0">Tidak</option>
									<option value="1">Ya</option>
								</select>
							</span>
						</td>
					</tr>
					<tr id="rw_jenis_prodeo">
						<td >Jenis Prodeo <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald" style='width:150px;'>
								<select name="jenis_prodeo" style='width:150px;' id="jenis_prodeo" class="custom-dropdown__select custom-dropdown__select--white">
									<option value="-1">Pilih Jenis Prodeo</option>
									<option value="2">DIPA</option>
									<option value="3">Murni</option>
								</select>
							</span>
						</td>
					</tr>
					<tr>
						<td style="background:white;padding:2px;"></td>
						<input type="hidden" id="enc" name="enc" value="<?php echo $enc;?>">
					</tr>
					<tr id="rw_ref_bank">
						<td>Nomor Referensi Bank</td>
						<td style="padding:0px;padding-left:5px;">
							<input type="text" id='no_ref' name='no_ref' value="" style="width:180px;" class="standard-input" maxlength="150">
						</td>
					</tr>
					<tr>
						<td>Panjar Perkara <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input type="text" id='b_panjar' name='b_panjar' value="" data-a-sep="." data-a-dec="," style="width:180px;text-align:right;" class="standard-input" maxlength="20">
						</td>
					</tr>
					<tr>
						<td>Biaya Pendaftaran <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input type="text" id='b_pendaftaran' name='b_pendaftaran' data-a-sep="." data-a-dec="," value="<?php echo $b_pendaftaran;?>" style="width:150px;text-align:right;" class="standard-input" maxlength="10" readonly="readonly">
						</td>
					</tr>
					<tr>
						<td>Alat Tulis Kantor <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input type="text" id='b_atk' name='b_atk' data-a-sep="." data-a-dec="," value="<?php echo $b_atk;?>" style="width:150px;text-align:right;" class="standard-input" maxlength="10" readonly="readonly">
						</td>
					</tr>
					<input type="hidden" id="curr_date" value="<?php echo $current_date;?>">
					<tr>
						<td colspan="3" style="background:white;" align="center">
							<input type="button" onClick='kembali();' id="goback" value="Kembali" class="btn">
							<input type="submit" id="simpan" value="Simpan" class="btn">
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>
<script src="<?php echo base_url();?>resources/js/autoNumeric.js"></script>
<script type="text/javascript">
$('#klas_perkara').change(function(e){
	generateNomorPerkara();
});

function generateNomorPerkara(){
	if($('#generate').val()==0){
		return;
	}
	openLoadingDialog()
	var val = $('#klas_perkara').val()
	var enc = $('#enc').val()
	var urutan = $('#urutan').val()
	var date = $('#tgl_pendaftaran').val()
	$("#klas_perkara option[value='-1']").remove();
	$.post('<?php echo base_url()?>add_perdata/getFormat', {
		enc: enc,
		val:val,
		urutan:urutan,
		date:date
	}, function(response){
		var json = jQuery.parseJSON(response);
		if(json.st==1){
			$('#no_perkara_auto').val(json.msg)
			$('#no_urut').val(json.nourutregister)
		}
		closeLoading()
	});
}
$('#generate').change(function(e){
	if($('#generate').val()==1){
		$('#rw_no_perkara_manual').hide();
		$('#rw_no_perkara_auto').show();
		$('#no_urut').attr('readonly', true);
		generateNomorPerkara();
	}else{
		$('#rw_no_perkara_auto').hide();
		$('#rw_no_perkara_manual').show();
		$('#no_urut').attr('readonly', false);
	}
});

$('#prodeo').change(function(e){
	if($('#prodeo').val()==0){
		$('#rw_jenis_prodeo').hide();
		$('#prodeo').show();
		$('#rw_ref_bank').show();
		if(b_panjar_tmp==''){
			b_panjar_tmp = $('#b_panjar').val();
		}
        b_pendaftaran_tmp = $('#b_pendaftaran').val();
        b_atk_tmp = $('#b_atk').val();
		$('#b_panjar').val(b_panjar_tmp);
		if (b_pendaftaran_tmp=='0') {
            $('#b_pendaftaran').val('30000');
            $('#b_pendaftaran').prop('readonly', false);
        } else {
            $('#b_pendaftaran').val(b_pendaftaran_tmp);
            $('#b_pendaftaran').prop('readonly', true);
        }

        if (b_atk_tmp=='0') {
            $('#b_atk').val('50000');
            $('#b_atk').prop('readonly', false);
        } else
                {
                    $('#b_atk').val(b_atk_tmp);
                    $('#b_pendaftaran').prop('readonly', true);
                }


		$('#b_panjar').prop('readonly', false);
	}else{
		$('#rw_jenis_prodeo').show();
		$('#rw_ref_bank').hide();

	}
});

$('#jenis_prodeo').change(function(e){
    openLoadingDialog()

    if($('#jenis_prodeo').val()==2){
        b_panjar_tmp = $('#b_panjar').val();
        b_pendaftaran_tmp = $('#b_pendaftaran').val();
        b_atk_tmp = $('#b_atk').val();
        $('#b_panjar').val(b_panjar_tmp);
        $('#b_pendaftaran').val('0');
        if (b_atk_tmp=='0') {
         $('#b_atk').val('50000');
            $('#b_atk').prop('readonly', false);
        } else {
            $('#b_atk').val(b_atk_tmp);
            $('#b_atk').prop('readonly', true);
        }
        $('#b_panjar').prop('readonly', false);
        $('#b_pendaftaran').prop('readonly', true);
    } else if ($('#jenis_prodeo').val()==3) {
        b_panjar_tmp = $('#b_panjar').val();
        b_pendaftaran_tmp = $('#b_pendaftaran').val();
        b_atk_tmp = $('#b_atk').val();
        $('#b_panjar').val('0');
        $('#b_pendaftaran').val('0');
        $('#b_atk').val('0');
        $('#b_panjar').prop('readonly', true);
     } else {

        if(b_panjar_tmp==''){
            b_panjar_tmp = $('#b_panjar').val();
        }
        $('#b_panjar').val(b_panjar_tmp);
        $('#b_pendaftaran').val(b_pendaftaran_tmp);
        $('#b_atk').val(b_atk_tmp);
        $('#b_panjar').prop('readonly', false);
    }


 /*
$('#jenis_prodeo').change(function(e){
	openLoadingDialog()
	if($('#jenis_prodeo').val()==2){
		b_panjar_tmp = $('#b_panjar').val();
		b_pendaftaran_tmp = $('#b_pendaftaran').val();
		b_atk_tmp = $('#b_atk').val();
		$('#b_panjar').val('0');
		$('#b_pendaftaran').val('0');
		$('#b_atk').val('0');
		$('#b_panjar').prop('readonly', true);
	}else{
		if(b_panjar_tmp==''){
			b_panjar_tmp = $('#b_panjar').val();
		}
		$('#b_panjar').val(b_panjar_tmp);
		$('#b_pendaftaran').val(b_pendaftaran_tmp);
		$('#b_atk').val(b_atk_tmp);
		$('#b_panjar').prop('readonly', false);
	}
*/
	closeLoading()
});

$('#no_urutan_manual').change(function(e){
	isNomorPerkaraExsist();
});
$('#no_perkara_manual').change(function(e){
	isNomorPerkaraExsist();
});

$('#no_urut').change(function(e){
	isNomorPerkaraExsist();
});


function isNomorPerkaraExsist(){
	if($('#generate').val()==0){
		openLoadingDialog()
		$.post('<?php echo base_url()?>add_perdata/validateNomorPerkara', {
			urutan:$('#no_urutan_manual').val(),
			date:$('#tgl_pendaftaran').val(),
			no_manual:$('#no_perkara_manual').val(),
			enc:$('#enc').val()
		}, function(response){
			var json = jQuery.parseJSON(response);
			if(json.st==0){
				message_show(json.msg);
				$('#no_urutan_manual').css("background-color", "red");
				$('#no_perkara_manual').css("background-color", "red");
				$('#no_urut').css("background-color", "red");
			}else{
				$('#no_urutan_manual').css("background-color", "#dedbdb");
				$('#no_perkara_manual').css("background-color", "#dedbdb");
				$('#no_urut').css("background-color", "#dedbdb");
			}
			closeLoading()
		});
	}
}
var b_panjar_tmp = '';
var b_pendaftaran_tmp = '';
var b_atk_tmp = '';
var tgl = '';
$( document ).ready(function() {
    $('#rw_no_perkara_manual').hide();
    $('#rw_jenis_prodeo').hide();
    $('#b_pendaftaran').autoNumeric('init', {mDec: '0'});
    $('#b_pendaftaran').ForceNumericOnly();
    $('#b_atk').autoNumeric('init', {mDec: '0'});
    $('#b_atk').ForceNumericOnly();
    $('#b_panjar').autoNumeric('init', {mDec: '0'});
    $('#b_panjar').ForceNumericOnly();
    $('.datepicker').ValidateDateInput();
    $('#frm_add_perdata').SubmitHandling({
		refresh:'1',
		setRefresh:1,
		divRef:'#frm_add_perdata',
		clicked:1,
		btnClicked:'#goback',
		whenStatus:1
	});
    b_panjar_tmp = $('#b_panjar').val();
	b_pendaftaran_tmp = $('#b_pendaftaran').val();
	b_atk_tmp = $('#b_atk').val();
	tgl = $('#tgl_pendaftaran');
	tgl.data('oldVal',  tgl.val() );
    $( function() {
        $('#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 date = $(this).datepicker('getDate');
            	var dayOfWeek = weekday[date.getDay()];
            	var error = 0;
            	var message ='';
            	if(dayOfWeek=='Sunday' || dayOfWeek=='Saturday'){
            		message ='Tidak Dapat Memilih diluar Hari Kerja.';
            		error = 1;
            	}
            	var oldVal_tmp = tgl.data('oldVal').substring(2)
				tgl.data('oldVal',  $(this).val() );
				
				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())){
					if(message!=''){
						message = message+'<br/>';
					}
					message = message+'Tidak Dapat Memilih Melebihi Hari ini. Sekarang Tanggal '+$('#curr_date').val();
					error = 1
				}

				if(error==1){
					message_show(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}

				if(oldVal_tmp==$(this).val().substring(2)){
					return;
				}else{
					generateNomorPerkara();
				}
				error = 0;

        	}
        });
    });
    $('input,select').not('#simpan').keypress(function(event) { return event.keyCode != 13; });
    
});

function kembali(){
	window.open("<?php echo $previous;?>","_self");
}
</script>