$(document).keypress(function(event) {
    var keycode = (event.keyCode ? event.keyCode : event.which);

    if(keycode == '13') {
    	var mod_id = $("#mod_id").val();
        var invoice = $("#invoice").val();
        var datastr = "invoice="+invoice+"&mod_id="+mod_id;
    	$("#call_det_invoice").load("module/fees/partial_fee_receive.php",datastr);
    }
});

$("#search").click(function(){
        	var mod_id = $("#mod_id").val();
        var invoice = $("#invoice").val();
        var datastr = "invoice="+invoice+"&mod_id="+mod_id;
		$("#call_det_invoice").show();
	$('#call_det_invoice').html("<span style='color:#2e8965;font-size:16px;font-weight:bold;'>Data Generating.... Please Wait.  <img src='php_crud/img/preloader.gif' /></span>");
       $("#call_det_invoice").load("module/fees/partial_fee_receive.php",datastr);
});
// =============================================================

$("#submit12").click(function(){
	var i = 0;
	var names =	 $('select[name="fh_name[]"]').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="fhamount[]"]').map(function(){
				   return this.value;
				 }).get();
	var leng = values.length;
				// alert(leng);
	var a=0;
	for(a;a<leng;a++){
		if(values[a]==''){
				alert('<br/><b><span style="color:white;background-color:red;padding:3px;">Please Enter Amount.</span></b>');
				//$('fhamount[i]').focus();
				return false;
			}
	}

	var names =	 $('select[name="fh_name[]"]').map(function(){
					return $(this).val();}).get(); 
	 
	var id = $("#id").val();
	var inv = $("#inv").val();
	var payable_tk = $("#tot_amount").val();
	var receive_amount = $("#receive_amount").val();
	var mod_id = $("#mod_id_1").val();
	var total_amount = $("#total_amount").val();
	//var discount = $("#discount").val();
	var last_payment_date = $("#last_payment_date").val();
	var chk_today 		= $("#today").val();
	if(receive_amount>total_amount){
			alert("<br/><b><span style='color:white;background-color:red;padding:3px;'>Please Enter Receive Amount Less Then or Equal Payable Amount</sapn></b>")
			return false;
		}
	var datastr = "id="+id+"&invoice="+inv+"&payable_tk="+payable_tk+"&receive_amount="+receive_amount+"&mod_id="+mod_id+"&total_amount="+total_amount+"&values="+values+"&names="+names;
	if(chk_today>last_payment_date){
		 if (confirm("Are You Confirmed To Add Late Fine!") == true) {
		 	$('#call_det_invoice').html("<span style='color:#2e8965;font-size:16px;font-weight:bold;'>Data Generating.... Please Wait.  <img src='php_crud/img/preloader.gif' /></span>");
       $("#call_det_invoice").load("module/fees/partial_fee_receive_chk.php",datastr);
		 }else{
			 	
				if(receive_amount==""){
		alert("Please Enter Receive Amount");
		$('#receive_amount').focus();
		return false;
	}
	else if(parseFloat(receive_amount)<1){
		alert("Please Enter Receive Amount Greater Then 0");
		$('#receive_amount').focus();
		return false;
	}
	else if(parseFloat(receive_amount)>parseFloat(payable_tk)){
		alert("Please Enter Receive Amount Less Then or Equal Payable Amount");
		$('#receive_amount').focus();
		return false;
	}	
	else{
	    $.ajax({
	        type:"get",
	        url:"module/fees/partialy_fee_rec_conf.php",
	        data:datastr ,
	        success:function(result){
	          //alert(result);
	            load();
				 //$("#main_content_div").load("module/fees/fee_collection.php");
	        }
	    });
    }
				
			 }
	}else{
	
	//var datastr = "id="+id+"&invoice="+inv+"&payable_tk="+payable_tk+"&receive_amount="+receive_amount+"&mod_id="+mod_id;
    //alert(datastr);
   if(receive_amount==""){
		alert("Please Enter Receive Amount");
		$('#receive_amount').focus();
		return false;
	}
	else if(parseFloat(receive_amount)<1){
		alert("Please Enter Receive Amount Greater Then 0");
		$('#receive_amount').focus();
		return false;
	}
	else if(parseFloat(receive_amount)>parseFloat(payable_tk)){
		alert("Please Enter Receive Amount Less Then or Equal Payable Amount");
		$('#receive_amount').focus();
		return false;
	}	
	else{
	    $.ajax({
	        type:"get",
	        url:"module/fees/partialy_fee_rec_conf.php",
	        data:datastr ,
	        success:function(result){
	          //alert(result);
	            load();
				 //$("#main_content_div").load("module/fees/fee_collection.php");
	        }
	    });
    }
  }
	
});


$("#submit13").click(function(){
	var i = 0;
	var names =	 $('select[name="fh_name[]"]').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="fhamount[]"]').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 id = $("#id").val();
	var inv = $("#inv").val();
	var payable_tk = $("#tot_amount").val();
	var receive_amount = $("#receive_amount").val();
	var mod_id = $("#mod_id_1").val();
	var total_amount = $("#total_amount").val();
	//var discount = $("#discount").val();
	var last_payment_date = $("#last_payment_date").val();
	var chk_today 		= $("#today").val();
	var datastr = "id="+id+"&invoice="+inv+"&payable_tk="+payable_tk+"&receive_amount="+receive_amount+"&mod_id="+mod_id+"&total_amount="+total_amount+"&values="+values+"&names="+names;
	//var datastr = "id="+id+"&invoice="+inv+"&payable_tk="+payable_tk+"&receive_amount="+receive_amount+"&mod_id="+mod_id;
    //alert(datastr);
   if(receive_amount==""){
		alert("Please Enter Receive Amount");
		$('#receive_amount').focus();
		return false;
	}
	else if(parseFloat(receive_amount)<1){
		alert("Please Enter Receive Amount Greater Then 0");
		$('#receive_amount').focus();
		return false;
	}
	else if(parseFloat(receive_amount)>parseFloat(payable_tk)){
		alert("Please Enter Receive Amount Less Then or Equal Payable Amount");
		$('#receive_amount').focus();
		return false;
	}	
	else{
	    $.ajax({
	        type:"get",
	        url:"module/fees/partialy_fee_rec_conf.php",
	        data:datastr ,
	        success:function(result){
	          //alert(result);
	            load();
				 //$("#main_content_div").load("module/fees/fee_collection.php");
	        }
	    });
    }
});
/* function load(){
	var std_id = $("#std_id").val();
	alert(std_id);
	var month = $("#_month").val();
	alert(month);
	var year = $("#_year").val();
	alert(year);
	var section_id = $("#_section_id").val();
	alert(section_id);
    $("#main_content_div").load("module/fees/student_invoice_pdf.php?stdid=std_id&month=month&year=year&section_id=section_id");
} */




function load(){
	var invoice = $("#invoice").val();
     var datastr = "invoice="+invoice;
    $("#main_content_div").load("module/fees/partial_print_invoice.php",datastr);
}

$("#goto_back").click(function(){
	 $("#main_content_div").load("module/fees/partialy_fee_collect.php");
	
});


