// ===============================
function call_medium(id){
	var datastr="shift_id="+id;
	$("#medium_id").load("module/settings/get_medium_list_for_form.php",datastr);
}
function call_class(id){
	var datastr="medium_id="+id;
	$("#class_id").load("module/settings/get_class_list_for_form.php",datastr);
}
function call_department(id){
	var datastr="class_id="+id;
	$("#department_id").load("module/settings/get_department_list_for_form.php",datastr);
}
function call_std_type(id){
		var datastr="department_id="+id;
	$("#student_type_id").load("module/settings/get_student_type_list_for_form.php",datastr);
}
function call_section(id){
		var datastr="student_type_id="+id;
	$("#section_id").load("module/settings/get_section_list_for_form.php",datastr);
}


function show_edit2(invoice_no){

var datastr = "invoice_no="+invoice_no;
//alert(datastr);
$("#model_table_value_edit2").load("module/fees/fee_edit_invoice.php",datastr);

//$('.chzn-select').css("width","200px");

}

function add_head(invoice_no){

var datastr = "invoice_no="+invoice_no;
//alert(datastr);
$("#model_table_value_add").load("module/fees/head_add_invoice.php",datastr);

//$('.chzn-select').css("width","200px");

}

function call_update_invoice(){
	var tr = $("#btn_invoice").parents('#modal-table_edit2').find('div#model_table_value_edit2 table tbody tr');
	var total_amount 		= $('#total_amount').val();
	var total_d_amount 		= $('#total_d_amount').val();
	var invoice_no_master 	= $('#invoice_no_master').val();
	var grand_total = parseFloat(total_amount)-parseFloat(total_d_amount)
	var opers='update';
	//alert(total_d_amount);
	//var data1	=headamount.split(',');
	//alert(total_amount);
	var datastr1="oper="+opers+"&invoice_no_master="+invoice_no_master+"&grand_total="+grand_total;
	//alert(datastr1);
	var datastr2="invoice_no="+invoice_no_master;
	
	$.ajax({
			type:"post",
			url:"module/fees/edit_fee_invoice_ajax.php",
			data:datastr1 ,
			success:function(result){	
				/*$(".section_wise_scholarship").load("module/fees/sec_scholar_std_list.php",datastr);*/
				alert(result);
				$("#second_part").load("module/fees/search_invoice_list.php",datastr2);
			}
		});
	
	$(tr).each(function(){
		   //alert($(this).find('td:eq(1) select').val());
	  var oper			= 'update';
	  var e_fee_head 	= $(this).find('td:eq(1) select').val();
	  var e_amount 		= $(this).find('td:eq(2) input#e_amount').val();
	  var id 			= $(this).find('td:eq(2) input#e_id').val();
	  var invoice_no 	= $(this).find('td:eq(2) input#e_invoice').val();
		
	  var datastr = "oper="+oper+"&e_fee_head="+e_fee_head+"&e_amount="+e_amount+"&id="+id+"&invoice_no="+invoice_no;
          //alert(datastr);

		  	/*if(e_fee_head==""){
			alert("Enter Fee Head");
			$('#e_fee_head').focus();
			}
			else*/ if(e_amount==""){
				alert("Enter Amount");
				$('#e_amount').focus();
			}else{
				$.ajax({
					type:"post",
					url:"module/fees/edit_fee_invoice_ajax.php",
					data:datastr ,
					success:function(result){	
						/*$(".section_wise_scholarship").load("module/fees/sec_scholar_std_list.php",datastr);*/
						//alert(result);	
					}
				});
			}

	});
	


	
}

function call_add_fee(){
	var std_id 				= $("#std_id").val();
	var month 				= $('#month').val();
	var year 				= $('#year').val();	
	var fee_head 			= $('#fee_head').val();
	var last_payment_date 	= $('#last_payment_date').val();
	var class_id 			= $('#class_id').val();
	var section_id 			= $('#section_id').val();
	var branch_id 			= $('#branch_id').val();
	var invoice_no_master 	= $('#invoice_no_master').val();
	var head_amount 		= $('#head_amount').val();
	var discount_head 		= $('#discount_head').val();
	var discount_amount 	= $('#discount_amount').val();
	var oper 				= 'mfs';
	
	var datast_mfs ="oper="+oper+"&std_id="+std_id+"&month="+month+"&year="+year+"&fee_head="+fee_head+"&last_payment_date="+last_payment_date+"&class_id="+class_id+"&section_id="+section_id+"&branch_id="+branch_id+"&head_amount="+head_amount+"&invoice_no_master="+invoice_no_master+"&discount_head="+discount_head+"&discount_amount="+discount_amount;
	
	var datastr2="invoice_no="+invoice_no_master;
	//alert(datast_mfs);
	$.ajax({
			type:"post",
			url:"module/fees/invoice_fee_head_ajax.php",
			data:datast_mfs ,
			success:function(result){
				alert(result);
				$("#second_part").load("module/fees/search_invoice_list.php",datastr2);
				
			}
		});
	
	}

// ===============
function call_std_invoice(){
	/*var month = $("#month").val();
	var year = $("#year").val();
	var shift_id = $("#shift_id").val();
	var medium_id = $("#medium_id").val();
	var class_id = $("#class_id").val();
	var department_id = $("#department_id").val();
	var student_type_id = $("#student_type_id").val();
	var section_id = $("#section_id").val();*/
	var invoice_no = $("#invoice_no").val();

	//var datastr="section_id="+section_id+"&month="+month+"&year="+year;
	var datastr="invoice_no="+invoice_no;
	//alert(datastr);
	$(".section_wise_invoice").show();
	$('.section_wise_invoice').html("<span style='color:#2e8965;font-size:16px;font-weight:bold;'>Data Generating.... Please Wait.  <img src='php_crud/img/preloader.gif' /></span>");
	
	if(invoice_no==""){
		alert("Enter Invoice No");
		$('#invoice_no').focus();
		return false;
	}
	/*else if(year==""){
		alert("Select Year");
		$('#year').focus();
		$(".section_wise_invoice").hide();
		return false;
	}
	else if(shift_id==""){
		alert("Select Shift");
		$('#shift_id').focus();
		$(".section_wise_invoice").hide();
		return false;
	}
	else if(medium_id==""){
		alert("Select Medium");
		$('#medium_id').focus();
		$(".section_wise_invoice").hide();
		return false;
	}
	else if(class_id==""){
		alert("Select Class");
		$('#class_id').focus();
		$(".section_wise_invoice").hide();
		return false;
	}
	else if(department_id==""){
		alert("Select Department");
		$('#department_id').focus();
		$(".section_wise_invoice").hide();
		return false;
	}
	else if(student_type_id==""){
		alert("Select Student Type");
		$('#student_type_id').focus();
		$(".section_wise_invoice").hide();
		return false;
	}
	else if(section_id==""){
		alert("Select Section");
		$('#section_id').focus();
		$(".section_wise_invoice").hide();
		return false;
	}*/
	else{
		$(".section_wise_invoice").load("module/fees/search_invoice_list.php",datastr);
	}
}

function delete_invoice(invoice_no){

    var operation = 'delete';
	//alert(invoice_no);
	//alert(1);
	if (confirm("Are You Confirmed To Continue!") == true) {
	var datastr="invoice_no="+invoice_no+"&operation="+operation;
	//var datastr1 = "student_id="+student_id+"&month="+month+"&year="+year;
	//var datastr2="class_id="+class_id;
	
	var datastr2="invoice_no="+invoice_no;
	
	//alert(datastr);
	$.ajax({
			type:"post",
			url:"module/fees/fee_invoice_delete_ajax.php",
			data:datastr ,
			success:function(result){
				
				alert(result);//$("#model_table_value_edit").load("module/fees/edit_invoice.php",datastr1);
				$("#second_part").load("module/fees/search_invoice_list.php",datastr2);
				
				

			}
		});
	
	}else{
	
	}
}


