// JavaScript Document
/********************************** Validation *******************************************************/
function main_empty_delete(delete_id,empty_return_noss)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
		jQuery.ajax({
		type: "POST",
		url: "consumable/empty_can_dc_form/empty_can_form_db.php?action=delete_empty_main&empty_return_noss="+empty_return_noss+"&delete_id="+delete_id,
		    success: function(msg){jQuery("#return_media_ink").html(msg);
		    window.location.reload(true);
            }
	    });
    }
}
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(total,ink_total_res)
{
	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 empty_return_add_main(empty_return_no,date_time,total,edit_id,pac_total,action)
{ 
 // alert(edit_id);
	if((total!="") || (pac_total)!="")
{

jQuery.ajax({
type: "POST",
url: "consumable/empty_can_dc_form/empty_can_form_db.php",
data: "empty_return_no="+empty_return_no+"&date_time="+date_time+"&total="+total+"&edit_id="+edit_id+"&action="+action+"&pac_total="+pac_total,
success: function(msg){
   // console.log(msg);
   // alert(msg);
   // jQuery("#return_main_add").html(msg);
if(edit_id!='')
{ 
window.location.reload(true);
window.location.href="main_fram.php?file=empty_can_form_list";
}else {
window.location.reload(true);
}
}
});
}
else
{
    
cons_return_main_validation(total,pac_total)

}
}
/**************************** 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_ink_details(particulars,batch_no)
{
jQuery.ajax({
type: "POST",
url: "consumable/empty_can_dc_form/qty_name.php",
data: "particulars="+particulars+"&batch_no="+batch_no,
success: function(msg){
   // alert(msg);
   // console.log(msg);
    var data = JSON.parse(msg);
    document.getElementById("uom").value = data.uom;
    document.getElementById("nos").value = data.nos;
    document.getElementById("qty").value = data.qty;
    document.getElementById("qty_hide1").value = data.hide_qty; 
   // jQuery("#uom").val(data.uom);
   // jQuery("#qty_div_media_con").html(msg);
}
});
}
function get_particular_batchno(particulars)
{
jQuery.ajax({
type: "POST",
url: "consumable/empty_can_dc_form/batch_no.php",
data: "particulars="+particulars,
success: function(msg){jQuery("#empty_batch_no_div").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 empty_can_sublist(entrydates,particulars,batch_no,uom,nos,packing,qty,edit_id,action,empty_return_no,qty_hide1)
{  // alert(entrydates+particulars+batch_no+uom+nos+packing+qty+edit_id+action+empty_return_no+qty_hide1);
	if((particulars)&&(batch_no!='')&&(uom!='')&&(nos!='')&&(qty!=0))
{ 
	if((parseInt(qty)<=parseInt(qty_hide1))||(parseInt(qty_hide1!=0)))
	{
	    if(parseInt(packing)<=parseInt(qty))
	    {
            jQuery.ajax({
            type: "POST",
            url: "consumable/empty_can_dc_form/empty_can_form_db.php?edit_id="+edit_id,
            data: "entrydates="+entrydates+"&particulars="+particulars+"&batch_no="+batch_no+"&uom="+uom+"&nos="+nos+"&packing="+packing+"&qty="+qty+"&edit_id="+edit_id+"&action="+action+"&empty_return_no="+empty_return_no+"&qty_hide1="+qty_hide1,
            success: function(msg){
                jQuery("#empty_return_sublist_div").html(msg);
           // card_details(job_card_nos,return_no);
            
            document.getElementById("particulars").value='';
            document.getElementById("batch_no").value='';
            document.getElementById("uom").value='';
            document.getElementById("nos").value='';
            document.getElementById("packing").value='';
            document.getElementById("qty").value='';
            document.getElementById("qty_hide1").value='';
            
            document.getElementById('add').value='ADD';
            document.getElementById("particulars").focus();
            }
            });
	    }else
    	{
    		alert("Please Check The Packing");
    	document.getElementById("packing").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 empty_return_sublist_edit(edit_id,empty_return_no)
{  
	$.ajax({
    type: "POST",
    url: "consumable/empty_can_dc_form/empty_can_return_sublist.php?edit_id="+edit_id,
	data: "empty_return_no="+empty_return_no,
    success: function(data) {
		$( "#empty_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_empty(delete_id,empty_return_no)
{ //alert(delete_id,empty_return_no)
	$.ajax({
    type: "POST",
    url: "consumable/empty_can_dc_form/empty_can_form_db.php?action=delete_sublist&delete_id="+delete_id+"&empty_return_no="+empty_return_no,
    success: function(data) {
$("#empty_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');
    }
	});
	}



