
// =============================================================

$("#btn_full_pay_submit").click(function(){
	var i = 0;
	var names =	 $('input[name="adjust_head[]"]').map(function(){
					return $(this).val();}).get();
	
	
	/*var length = names.length;
	for(i;i<length;i++){
	if(names[i]==''){
			alert('Please Select Fee Head');
			//$('fhamount[i]').focus();
			return false;
		}
	}*/
	
	var values = $('input[name="cr[]"]').map(function(){
				   return this.value;
				 }).get();
	/*var leng = values.length;
				// alert(leng);
	var a=0;
	for(a;a<leng;a++){
		if(values[a]==''){
				alert('Please Enter Amount');
				//$('fhamount[i]').focus();
				return false;
			}
	}*/

	//var names =	 $('select[name="fh_name[]"]').map(function(){
					//return $(this).val();}).get();

	var discount = $("#full_pay_discount").val();
    var inv = $("#inv").val();
    var mod_id = $("#mod_id34").val();
    var amount = $("#tot_amount").val();
    var total_amount = $("#total_amount").val();
	var last_payment_date = $("#last_payment_date").val();
	//var chk_today 		= $("#today").val();
	var payment_date 		= $("#full_payment_date").val();
	
	var initize_year = new Date();
	var curr_year = initize_year.getFullYear();
	
	var pay_date_arr = payment_date.split("-");
	var payment_year = pay_date_arr[2];
	
	//var al_msg = "";
	
	
    var datastr = "invoice="+inv+"&discount="+discount+"&amount="+amount+"&total_amount="+total_amount+"&mod_id="+mod_id+
				"&values="+values+"&names="+names+"&payment_date="+payment_date;
				
	var modal_datastr = "invoice="+inv;
   //alert(datastr);
	if(payment_date == ""){
		alert('Please enter payment date');
		$('#full_payment_date').focus();
		return false;
	}
	if(curr_year!=payment_year){
		alert('Please check the payment date');
		$('#full_payment_date').focus();
		return false;
	}
	else{
		if(parseFloat(discount)>parseFloat(amount)){
			alert("Please Enter Discount Amount Less Then or Equal Payable Amount");
			$('#full_pay_discount').focus();
			return false;
		}else{
			$.ajax({
				type:"get",
				url:"module/fees/ins_fee_rec_conf.php",
				data:datastr ,
				success:function(result){
				  //alert(result);
					load();
					 //$("#main_content_div").load("module/fees/fee_collection.php");
				}
			});
		}
	}
	/*if(payment_date>last_payment_date){
		 if (confirm("Are You Confirmed To Late Fine Payment!") == true) {
		 	alert('Under Procesing...');
		 }else{
		  if(parseFloat(discount)>parseFloat(amount)){
				alert("Please Enter Discount Amount Less Then or Equal Payable Amount");
				$('#full_pay_discount').focus();
				return false;
			}else{
			$.ajax({
				type:"get",
				url:"module/fees/ins_fee_rec_conf.php",
				data:datastr ,
				success:function(result){
					document.getElementById('full_payment_date').readOnly = true;
					document.getElementById('add_discount_btn').disabled = true;
					document.getElementById('btn_full_pay_submit').disabled = true;
					document.getElementById('full_pay_discount').disabled = true;
					$("#modal_body_pay_con_msg").load("module/fees/std_print_invoice.php",modal_datastr);
				  //alert(result);
					//load();
					 //$("#main_content_div").load("module/fees/fee_collection.php");
				}
			});
		  }
		}
	}*/
	
		
});


function perform_invoice_print(invoice_no){
	window.open("module/fees/student_invoice_all_copies_pdf.php?invoice_id="+invoice_no);
}

function load(){
	var invoice = $("#inv").val();
     var datastr = "invoice="+invoice;
    $("#main_content_div").load("module/fees/std_print_invoice.php",datastr);
}
$("#go_back").click(function(){
	 $("#main_content_div").load("module/fees/fee_collection_id.php");
	
});


