// JavaScript Document
/********************************** Validation *******************************************************/
function con_ret_media_pur_sublist_validation()
{
	var job_card_nos = document.getElementById("job_card_nos").value;
	if(job_card_nos=='')
	{
		document.getElementById("purchase_no_con_ret_valid_div").innerHTML="* This field is Required.";
		document.getElementById("job_card_nos").focus();
		return false;
	}
var invoice_no = document.getElementById("invoice_no").value;
	if(invoice_no=='')
	{
		document.getElementById("invoice_no_media_con_ret_valid_div").innerHTML="* This field is Required.";
		document.getElementById("invoice_no").focus();
		return false;
	}
		 var sup_name = document.getElementById("sup_name").value;
	if(sup_name=='')
	{
		document.getElementById("supp_name_media_con_ret_valid_div").innerHTML="* This field is Required.";
		document.getElementById("sup_name").focus();
		return false;
	}
	 var particulars = document.getElementById("particulars").value;
	if(particulars=='')
	{
		document.getElementById("particulars_media_con_ret_valid_div").innerHTML="* This field is Required.";
		document.getElementById("particulars").focus();
		return false;
	}
	 var qty = document.getElementById("qty").value;
	if(qty==0)
	{
		document.getElementById("qty_media_con_ret_valid_div").innerHTML="* This field is Required.";
		document.getElementById("qty").focus();
		return false;
	}
	 var mtr_roll = document.getElementById("mtr_roll").value;
	if(mtr_roll==0)
	{
		document.getElementById("mtr_roll_media_con_ret_valid_div").innerHTML="* This field is Required.";
		document.getElementById("mtr_roll").focus();
		return false;
	}
}

function cons_ret_media_clear_valid_sub(str)
{
	if(str!='')
	{
		document.getElementById("invoice_no_media_con_ret_valid_div").innerHTML="";
	}
	
	if(str!='')
	{
		document.getElementById("supp_name_media_con_ret_valid_div").innerHTML="";
	}
	
	if(str!='')
	{
		document.getElementById("particulars_media_con_ret_valid_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("qty_media_con_ret_valid_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("mtr_roll_media_con_ret_valid_div").innerHTML="";
	}
	
}


function cons_ret_ink_pur_sublist_valid()
{
	var job_card_nos = document.getElementById("job_card_nos").value;
	if(job_card_nos=='')
	{
		document.getElementById("purchase_no_con_ret_valid_div").innerHTML="* This field is Required.";
		document.getElementById("job_card_nos").focus();
		return false;
	}
var invoice_no = document.getElementById("ink_invoice_no").value;
	if(invoice_no=='')
	{
		document.getElementById("ink_invoice_no_con_ret_valid_div").innerHTML="* This field is Required.";
		document.getElementById("ink_invoice_no").focus();
		return false;
	}
	
	
		 var sup_name = document.getElementById("ink_sup_name").value;
	if(sup_name=='')
	{
		document.getElementById("ink_supp_name_con_ret_valid_div").innerHTML="* This field is Required.";
		document.getElementById("ink_sup_name").focus();
		return false;
	}
	 var particulars = document.getElementById("ink_particulars").value;
	if(particulars=='')
	{
		document.getElementById("ink_particulars_con_ret_valid_div").innerHTML="* This field is Required.";
		document.getElementById("ink_particulars").focus();
		return false;
	}
	 var qty = document.getElementById("ink_qty").value;
	if(qty==0)
	{
		document.getElementById("ink_qty_con_ret_valid_div").innerHTML="* This field is Required.";
		document.getElementById("ink_qty").focus();
		return false;
	}
	 
}
function cons_ret_ink_clear_valid_sub(str)
{
	if(str!='')
	{
		document.getElementById("ink_invoice_no_con_ret_valid_div").innerHTML="";
	}
	
	if(str!='')
	{
		document.getElementById("ink_supp_name_con_ret_valid_div").innerHTML="";
	}
	
	if(str!='')
	{
		document.getElementById("ink_particulars_con_ret_valid_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("ink_qty_con_ret_valid_div").innerHTML="";
	}
	
	
}
function cons_return_main_validation(job_card_nos,total,ink_total_res)
{
	var job_card_nos = document.getElementById("job_card_nos").value;
	if(job_card_nos=='')
	{
		document.getElementById("purchase_no_con_ret_valid_div").innerHTML="* This field is Required.";
		document.getElementById("job_card_nos").focus();
		return false;
	}
	
	if((total=="")||(ink_total_res=""))
	{
		
		alert("Please fill the sublist");
	document.getElementById("job_card_nos").focus();	
	
	}
}
function cons_ret_main_clear_valid(str)
{
	if(str!='')
	{
		document.getElementById("purchase_no_con_ret_valid_div").innerHTML="";
	}
	
	
	
	
	
}

/*************************main list********************************************/
function return_add_main(return_no,date_time,job_card_nos,total,edit_id,ink_total_res,action)
{ 

	if((total!="") || (ink_total_res)!="")
{

jQuery.ajax({
type: "POST",
url: "consumable/consumable_return_form/return_form_db.php",
data: "return_no="+return_no+"&date_time="+date_time+"&job_card_nos="+job_card_nos+"&total="+total+"&edit_id="+edit_id+"&action="+action+"&ink_total_res="+ink_total_res,
success: function(msg){
    jQuery("#return_main_add").html(msg);
window.location.reload(true);
if(edit_id!='')
{ 
window.location.reload(true);
window.location.href="main_fram.php?file=consumable_return_form";
}
}
});
}
else
{
cons_return_main_validation(job_card_nos,total,ink_total_res)

}
}
/**************************** get_consumable_details ************************************************/
function card_details(job_card_nos,return_no)
{
var x =job_card_nos;
var blo=x.charAt(0); 

if(blo=='I')
{
jQuery("#consumable_return_sublist_div").css("display","none")
jQuery("#return_ink").css("display","block")
jQuery.ajax({
type: "POST",
url: "consumable/consumable_return_form/ink_invoice_no.php",
data: "job_card_nos="+job_card_nos+"&return_no="+return_no,
success: function(data){jQuery("#ink_voice_div").html(data);
}
});
}

if(blo=='M')
{
jQuery("#consumable_return_sublist_div").css("display","block")
jQuery("#return_ink").css("display","none")

jQuery.ajax({
type: "POST",
url: "consumable/consumable_return_form/invoice_no.php",
data: "job_card_nos="+job_card_nos,
success: function(data){jQuery("#voice_div").html(data);
}
});
}

}



function get_qty_fun(particulars,job_card_nos,return_no)
{
jQuery.ajax({
type: "POST",
url: "consumable/consumable_return_form/qty_name.php",
data: "particulars="+particulars+"&job_card_nos="+job_card_nos+"&return_no="+return_no,
success: function(msg){jQuery("#qty_div_media_con").html(msg);
}
});
jQuery.ajax({
type: "POST",
url: "consumable/consumable_return_form/mtr_qty.php",
data: "particulars="+particulars+"&job_card_nos="+job_card_nos+"&return_no="+return_no,
success: function(msg){jQuery("#res_mtrsss").html(msg);
}
});

jQuery.ajax({
type: "POST",
url: "consumable/consumable_return_form/tot_mtr_qty.php",
data: "particulars="+particulars+"&job_card_nos="+job_card_nos+"&return_no="+return_no,
success: function(msg){jQuery("#res_tot_mtr").html(msg);
}
});
}
function get_ink_qty_con(particulars,job_card_nos,return_no)
{

jQuery.ajax({
type: "POST",
url: "consumable/consumable_return_form/ink_qty_name.php",
data: "particulars="+particulars+"&job_card_nos="+job_card_nos+"&return_no="+return_no,
success: function(msg){jQuery("#ink_qty_div").html(msg);
}
});
}

function get_tot_mtr_consumable(qty,mtr_roll)
{
	var total_meters = qty*mtr_roll;
	document.getElementById("tot_mtr").value = total_meters;
}
/***************************** Get Sublist details ***********************************************************/
function get_con_ret_sup_part_name_media(return_no,job_card_nos,invoice_no)
{
jQuery.ajax({
type: "POST",
url: "consumable/consumable_return_form/particulars.php",
data: "job_card_nos="+job_card_nos+"&return_no="+return_no+"&invoice_no="+invoice_no,
success: function(data){jQuery("#ret_particulars_div").html(data);
}
});

jQuery.ajax({
type: "POST",
url: "consumable/consumable_return_form/suppliers_name.php",
data: "job_card_nos="+job_card_nos+"&return_no="+return_no+"&invoice_no="+invoice_no,
success: function(data){jQuery("#sup_div").html(data);
}
});
}

function get_con_ret_sup_part_ink1(return_no,job_card_nos,invoice_no)
{
jQuery.ajax({
type: "POST",
url: "consumable/consumable_return_form/ink_suppliers_name.php",
data: "job_card_nos="+job_card_nos+"&invoice_no="+invoice_no,
success: function(data){jQuery("#ink_sup_div").html(data);
}
});

jQuery.ajax({
type: "POST",
url: "consumable/consumable_return_form/ink_particulars.php",
data: "job_card_nos="+job_card_nos+"&return_no="+return_no+"&invoice_no="+invoice_no,
success: function(data){jQuery("#ink_ret_particulars_div").html(data);
}
});
}

/******************************main list delte*******************************************/


function media_pur_sublist_sublist_con_ret(job_card_nos,entrydates,invoice_no,sup_name,particulars,qty,mtr_roll,tot_mtr,edit_id,action,return_no,qty_hide)
{
	if((job_card_nos)&&(invoice_no!='')&&(sup_name!='')&&(particulars!='')&&(qty!=0)&&(mtr_roll!=''))
{
	if((parseInt(qty)<=parseInt(qty_hide))||(parseInt(qty_hide!=0)))
	{
jQuery.ajax({
type: "POST",
url: "consumable/consumable_return_form/return_form_db.php?edit_id="+edit_id,
data: "job_card_nos="+job_card_nos+"&entrydates="+entrydates+"&invoice_no="+invoice_no+"&sup_name="+sup_name+"&particulars="+particulars+"&qty="+qty+"&mtr_roll="+mtr_roll+"&tot_mtr="+tot_mtr+"&edit_id="+edit_id+"&action="+action+"&return_no="+return_no+"&qty_hide="+qty_hide,
success: function(msg){jQuery("#consumable_return_sublist_div").html(msg);
card_details(job_card_nos,return_no);

document.getElementById("invoice_no").value='';
document.getElementById("sup_name").value='';
document.getElementById("particulars").value='';
document.getElementById("qty").value='';
document.getElementById("mtr_roll").value='';
document.getElementById("tot_mtr").value='';

document.getElementById('add').value='ADD';
document.getElementById("job_card_nos").focus();
document.getElementById("invoice_no").focus();
}
});
	}
	else
	{
		alert("Please Check The Quantity");
	document.getElementById("qty").focus();

	}
}
else
{
	con_ret_media_pur_sublist_validation();
}
}

function ink_pur_sub_con_ret(job_card_nos,ink_entrydates,ink_invoice_no,ink_sup_name,ink_particulars,ink_qty,edit_id,action,return_no,qty_hid)
{
	if((job_card_nos)&&(ink_invoice_no!='')&&(ink_sup_name!='')&&(ink_particulars!='')&&(ink_qty!=0))
	{
		if((parseInt(ink_qty)<=parseInt(qty_hid))||(parseInt(qty_hid!=0)))
		{
			jQuery.ajax({
				type: "POST",
				url: "consumable/consumable_return_form/return_form_db.php",
				data: "job_card_nos="+job_card_nos+"&ink_entrydates="+ink_entrydates+"&ink_invoice_no="+ink_invoice_no+"&ink_sup_name="+ink_sup_name+"&ink_particulars="+ink_particulars+"&ink_qty="+ink_qty+"&edit_id="+edit_id+"&action="+action+"&return_no="+return_no+"&qty_hid="+qty_hid,
				success: function(msg){jQuery("#return_ink").html(msg);
				card_details(job_card_nos,return_no);
				document.getElementById("ink_invoice_no").value='';
				document.getElementById("ink_sup_name").value='';
				document.getElementById("ink_particulars").value='';
				document.getElementById("ink_qty").value='';
				document.getElementById('add').value='ADD';
				document.getElementById("job_card_nos").focus();
				}
				});
		}
		else
		{
			alert("Please Check The Quantity");
			document.getElementById("ink_qty").focus();
		}
	}
	else
	{
		cons_ret_ink_pur_sublist_valid();
	}

}

function mediapurchase_sublist_edit_con_ret(edit_id,job_card_nos,return_no)
{  
	$.ajax({
    type: "POST",
    url: "consumable/consumable_return_form/consumable_return_sublist.php?edit_id="+edit_id,
	data: "job_card_nos="+job_card_nos+"&return_no="+return_no,
    success: function(data) {
		$( "#consumable_return_sublist_div" ).html(data);
    },
    error: function() {
        alert('error handing here');
    }
	});
}
function inkpurchase_sublist_edit_con_ret(edit_id,job_card_nos,return_no)
{  
	$.ajax({
    type: "POST",
    url: "consumable/consumable_return_form/ink_sublist.php?edit_id="+edit_id,
	data: "job_card_nos="+job_card_nos+"&return_no="+return_no,
    success: function(data) {
		$( "#return_ink" ).html(data);
    },
    error: function() {
        alert('error handing here');
    }
	});
}

function delete_sublist_media_pur_con_ret(delete_id,return_no)
{
	$.ajax({
    type: "POST",
    url: "consumable/consumable_return_form/return_form_db.php?action=delete_trans&delete_id="+delete_id+"&return_no="+return_no,
    success: function(data) {
$( "#consumable_return_sublist_div" ).html(data);  
card_details(job_card_nos,return_no);
  },
    error: function() {
        alert('error handing here');
    }
	});
	}
	
	function delete_sublist_ink_pur_cons_ret(delete_id,return_no)
{
	$.ajax({
    type: "POST",
    url: "consumable/consumable_return_form/return_form_db.php?action=delete_ink&delete_id="+delete_id+"&return_no="+return_no,
    success: function(data) {
$( "#return_ink").html(data);   
card_details(job_card_nos,return_no);
 },
    error: function() {
        alert('error handing here');
    }
	});
	}

function return_delete_medi_ink(delete_id,purchase_noss,return_noss)
{
	
	if(confirm('Are You Sure! You Want To Delete?'))
	{
		jQuery.ajax({
		type: "POST",
		url: "consumable/consumable_return_form/return_form_db.php?action=delete_media_ink&return_noss="+return_noss+"&purchase_noss="+purchase_noss+"&delete_id="+delete_id,
	//	data: "delete_id="+delete_id+"purchase_noss="+purchase_noss+"return_noss="+return_noss,
		success: function(msg){jQuery("#return_media_ink").html(msg);
		  window.location.reload(true);
}
	});
    }
}

