<!-- Widget ID (each widget will need unique ID)-->
<div class="jarviswidget" id="wid-id-6" data-widget-editbutton="false" data-widget-custombutton="false" data-widget-deletebutton="false">
	<!-- widget options:
		usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">
		
		data-widget-colorbutton="false"	
		data-widget-editbutton="false"
		data-widget-togglebutton="false"
		data-widget-deletebutton="false"
		data-widget-fullscreenbutton="false"
		data-widget-custombutton="false"
		data-widget-collapsed="true" 
		data-widget-sortable="false"
		
	-->
	<header>
		<span class="widget-icon"> <i class="fa fa-edit"></i> </span>
		<h2>Transaksi Siswa</h2>				
		
	</header>

	<!-- widget div-->
	<div>
		
		<!-- widget edit box -->
		<div class="jarviswidget-editbox">
			<!-- This area used as dropdown edit box -->
			
		</div>
		<!-- end widget edit box -->
		
		<!-- widget content -->
		<div class="widget-body no-padding">
			
			<form action="<?php echo @$action; ?>" method="post" id="crud-form" class="smart-form">
				<header>
					<?php echo $header; ?>
				</header>

				<fieldset>
                <!--
					<div class="row">
						<section class="col col-3">
							<label class="label">Nomor Transaksi</label>
							<label class="input"> 
									<input id="last_id" type="hidden" name="last_id"  value="<?php echo @$last_id; ?>" />									
									<?php echo @$faktur; ?>									
							</label>
						</section>
					</div>
                    -->
					<div class="row">
						
						<!--<section class="col col-2">
							<label class="label">Tanggal Transaksi</label>							
								<label class="input"> 
									<input id="tanggal_transaksi" type="text" name="tanggal_transaksi"  value="<?php echo @$t_trans; ?>" />									
								</label>								
						</section>	
						-->
						<section class="col col-3">
							<label class="label">Sekolah</label>
							<?php echo $nama_smk; ?>
						</section>
                        
						<section class="col col-4">
							<label class="label">Nama Siswa</label>							
							<label class="select" >
                            <div id="id-Mapping">
							<select id="id_siswa" name="id_siswa" onchange="getTrans(this.value),getReset(0);" class="chosen-select">			
								<?php echo $siswa; ?> 
							</select>	
                            </div>						
							</label>							
						</section>
								
					</div >
						
					<div class="row">					
						<div id="div-trans"><?php echo $trans; ?></div>						
					</div>	
				</fieldset>
					
					<header>
					Detail Transaksi
				</header>
				
				<fieldset>
					<div id="id-detail">
						<table class="table table-bordered">
						<thead>
							<tr>
								<td>Detail List</td>
								<td>Jenis Pembayaran</td>
								<td>Tahun Ajaran</td>
								<td>Besarnya</td>
                                <td>Dibayarkan</td>
							</tr>
						</thead>
						<tbody>			 
							<tr><td colspan="4" align="right" >Total</td><td>Rp. 0</td></tr>
						</tbody></table>					
					</div>
									
				</fieldset>	

						
				<footer>
					<button type="submit" name="submit" id="myBtn" class="btn btn-primary" value="<?php echo $submit; ?>" onclick="buttonDis()">
						Save
					</button>
					<button type="reset" id="cancel_create" name="cancel" class="btn btn-default" >
						Batal
					</button>
				</footer>

				<div class="message">
					<i class="fa fa-check fa-lg"></i>
					<p>
						Your comment was successfully added!
					</p>
				</div>
			</form>
			
		</div>
		<!-- end widget content -->
		
	</div>
	<!-- end widget div -->
				
</div>
<!-- end widget -->

<script type="text/javascript">
	function buttonDis() {
		document.getElementById("myBtn").style.visibility="hidden";
	}
		
	$(function() {
		
		$(".chosen-select").chosen();
		
		$('#tanggal_transaksi').datetimepicker({
			format: 'DD-MM-YYYY'
		});
		
		alert_cancel = 'Are You Sure to cancel this form ?';
		$('#cancel_create').on('click', function () {
			if (confirm(alert_cancel)) {
				window.location.href = "<?php echo site_url('/').'home#'.$controller; ?>";
			}
		});
		
		// Validation
		$("#crud-form").validate({
			// Rules for form validation
			rules : {
				tanggal_transaksi : {
					required : true
					/*remote	 : {
						url		: "<?php echo base_url();?>index.php/adm_tahun_ajaran/cek_tahun_ajaran",
						type	: "POST",
						data: {
							tahun_ajaran: function() {
								return $("#tahun_ajaran").val();
							}
						}
					}*/	
					//remote : '<?php echo base_url();?>index.php/login/cek_user'		
				},
				id_siswa : {
					required : true							
				},
				'id[]': {
					required: true
				}
				
			},
			ignore: [],
			submitHandler : function(form) {
				
				$(form).ajaxSubmit({
					dataType: 'json',
					success : function(msg) {
						window.location.hash = base_url + 'index.php/<?php echo $controller; ?>/successPage';
						/* if (msg.msg == "noauth") {
							window.location = base_url;
						}
						else if (msg.error == true) {
							write_error_html(msg.field);
							
							//button manipulating
							$("#hiddenElement").val("true");
							$(".fa-spin").remove();
							$("#cancel").removeAttr("disabled");
							$("#button_id").removeAttr("disabled");
						} else {
							window.location.hash = base_url + 'create_agent/';
						} */
					}
				});
				
			},

			// Messages for form validation
			messages : {
					tanggal_transaksi : {
						required : 'Tanggal Transaksi Harus di isi'						
					},
					id_siswa : {
						required : 'Pilih Siswa'						
					},
					'id[]' : {
						required : 'Pilih jenis Transaksi'						
					}	
				},

			// Do not change code below
			errorPlacement : function(error, element) {
				error.insertAfter(element.parent());
			}
		});		
		
	});
	
	function getNama(smk) {
		$.ajax({
			type:"POST",
			dataType: "html",
			beforeSend : function() {
				$("#id-Mapping").html("Populating data, please wait..");
			},
			url : "<?php echo site_url("/") . $controller . "/getNama"; ?>",
			data : "smk="+smk,
			success:function(msg){
				$("#id-Mapping").html(msg);
			},
			error:function(){
				alert("Load failed");
			}
		});
	}
	
	function getReset() {
		$.ajax({
			type:"POST",
			dataType: "html",
			url:"<?php echo site_url("/") . $controller . "/getReset"; ?>",
			success:function(msg){
				$("#id-detail").html(msg);							
			},
			error:function(){
				alert("Load failed");
			}
		});
	}
	
	
	function getTotalBiayaCicilan(test) {
		var total=0;
		
		for (i = 0; i < test; i++) {
			var x = document.getElementById("total_bayar_"+(i+1)+"");
			x = parseInt(x.value);
			total +=  x;
		}
		$.ajax({
			type:"POST",
			dataType: "html",
			beforeSend : function() {
				$("#id-MappingTBC").html("Populating data, please wait..");
			},
			url : "<?php echo site_url("/") . $controller . "/getTotalBiayaCicilan"; ?>",
			data : "total="+total,
			success:function(msg){
				$("#id-MappingTBC").html(msg);
			},
			error:function(){
				alert("Load failed");
			}
		});
	}
	function getDetail(num) {
		var idCoa = [];	
		$('#id-TransSiswa :selected').each(function(i, selected){ 
			idCoa[i] = $(selected).val(); 
		});
		
		//idSiswa.push(num);
		//alert(idSiswa); 
		
		$.ajax({
			type:"POST",
			dataType: "html",
			url:"<?php echo site_url("/") . $controller . "/getDetail"; ?>",
			data : "idCoa="+idCoa,
			success:function(msg){
				$("#id-detail").html(msg);							
			},
			error:function(){
				alert("Load failed");
			}
		});
	}
	
	function getTrans(id_siswa) {
		
		//alert(id_siswa); die();
		$.ajax({
			type:"POST",
			dataType: "html",
			url:"<?php echo site_url("/") . $controller . "/getTrans"; ?>",
			data : "id_siswa="+id_siswa,
			success:function(msg){
				$("#div-trans").html(msg);							
			},
			error:function(){
				alert("Load failed");
			}
		});
	}
	
	
</script>