/*************************************validation********************************/
function fusing_sub_validation()
{
    var job_card_no = document.getElementById("job_card_no").value;
	if(job_card_no=='')
	{
		document.getElementById("job_card_no_validation_div").innerHTML="* This field is Required.";
		document.getElementById("job_card_no").focus();
		return false;
	}
	
	var shift_time = document.getElementById("shift_time").value;
	if(shift_time=='')
	{
		document.getElementById("shift_time_validation_div").innerHTML="* This field is Required.";
		document.getElementById("shift_time").focus();
		return false;
	}
	var machine_no = document.getElementById("machine_no").value;
	if(machine_no=='')
	{
		document.getElementById("machine_no_validation_div").innerHTML="* This field is Required.";
		document.getElementById("machine_no").focus();
		return false;
	}
		var operator_name = document.getElementById("operator_name").value;
	if(operator_name=='')
	{
		document.getElementById("operator_name_validation_div").innerHTML="* This field is Required.";
		document.getElementById("operator_name").focus();
		return false;
	}
	var prod_size = document.getElementById("prod_size").value;
	if(prod_size=='')
	{
		document.getElementById("prod_size_validation_div").innerHTML="* This field is Required.";
		document.getElementById("prod_size").focus();
		return false;
	}
	var prod_qty = document.getElementById("prod_qty").value;
	if(prod_qty=='')
	{
		document.getElementById("prod_qty_validation_div").innerHTML="* This field is Required.";
		document.getElementById("prod_qty").focus();
		return false;
	}
}
function fusing_main_validation()
{
    var job_card_no = document.getElementById("job_card_no").value;
	if(job_card_no=='')
	{
		document.getElementById("job_card_no_validation_div").innerHTML="* This field is Required.";
		document.getElementById("job_card_no").focus();
		return false;
	}
	var cust_name = document.getElementById("cust_name").value;
	if(cust_name=='')
	{
	alert("Customer name is requierd");
			document.getElementById("cust_name").focus();
		return false;
	}
	   var count = document.getElementById("count").value;
	if(count=='0')
	{
		alert("please fill jobcard particulars");
		return false;
	}
}
/*************************************validation********************************/
function fusing_clear_validation(str)
{
	if(str!='')
	{
		document.getElementById("job_card_no_validation_div").innerHTML="";
	}
	
	if(str!='')
	{
		document.getElementById("shift_time_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("machine_no_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("operator_name_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("prod_size_validation_div").innerHTML="";
	}

    if(str!='')
	{
		document.getElementById("prod_qty_validation_div").innerHTML="";
	}
}

/******************************************** SUB EDIT*****************************************************************/
function get_fusing_size(jobcard_no)
{ 
  jQuery.ajax({
		type: "POST",
		url: "production/fusing_production/get_size.php",
		data: "jobcard_no="+jobcard_no,
		success: function(msg){jQuery("#get_size_div").html(msg);

 }
		});
}

function get_fusing_job_details(jobcard_no)
{ 
  jQuery.ajax({
		type: "POST",
		url: "production/fusing_production/get_job_details.php",
		data: "jobcard_no="+jobcard_no,
		success: function(msg){jQuery("#get_job_details_div").html(msg);

 }
		});
}

function get_fusing_tot_qty(jobcard_no,size)
{ 
  jQuery.ajax({
		type: "POST",
		url: "production/fusing_production/get_total_qty.php",
		data: "jobcard_no="+jobcard_no+"&size="+size,
		success: function(msg){jQuery("#get_tot_qty_div").html(msg);

 }
		});
}

function get_fusing_calc_qty(total_qty,prod_qty)
{
	
	var total_qty=total_qty;
	var prod_qty=prod_qty;
	if(total_qty>0){
	if(total_qty!=''){var total_qty=total_qty;}else{var total_qty="0";}
	if(prod_qty!=''){var prod_qty=prod_qty;}else{var prod_qty="0";}
	var total=parseFloat(total_qty-prod_qty);
	jQuery("#balance_qty").val(total);
	}
	else{ alert('Please Check the Size or qty!!');}
}
//fusing_entry_qty_validation
function fusing_entry_qty_validation(total_qty,prod_qty)
{
  
	var prod_qty = document.getElementById("prod_qty").value;
		var total_qty = document.getElementById("total_qty").value;
	if((parseFloat(prod_qty)>parseFloat(total_qty)))
	{
		alert("Check The Total Quantity..!");
     
		$('#prod_qty').val('');
		return false;
	}
	else if(prod_qty=="0")
	{
		alert("Production Quantity Should Not be Zero..!");
     
		$('#prod_qty').val('');
		return false;
	}
}

function add_fusing_prod_sub(job_card_no,production_time,shift_time,machine_no,operator_name,prod_size,total_qty,prod_qty,balance_qty,action)
{
	if((job_card_no!='')&&(shift_time!='')&&(machine_no!='')&&(operator_name!='')&&(prod_size!='')&&(prod_qty!=''))
	{
	//if(total_qty>0){.
	jQuery('#add').hide();
	  jQuery.ajax({
		type: "POST",
		url: "production/fusing_production/fusing_production_entry_db.php",
		data: "job_card_no="+job_card_no+"&production_time="+production_time+"&shift_time="+shift_time+"&machine_no="+machine_no+"&operator_name="+operator_name+"&prod_size="+prod_size+"&total_qty="+total_qty+"&prod_qty="+prod_qty+"&balance_qty="+balance_qty+"&action="+action,
		success: function(msg){jQuery("#get_prod_print_sub_div").html(msg);
       jQuery('#add').show();
 }
		});
		/*}
	else{ 
	alert('Please Check the Size or qty!!');
	}*/
		get_fusing_size(job_card_no);
}

else
{
	fusing_sub_validation();
	}}
	
	
	function view_fusing_jobcard(job_card_no)
{
		  jQuery.ajax({
		type: "POST",
		url: "production/fusing_production/fusing_production_entry_db.php",
		data: "job_card_no="+job_card_no+"&action=viewjobcard",
		success: function(msg){jQuery("#get_prod_print_sub_div").html(msg);

 }
		});
}

function del_fusing_prod_sub(pr_id,job_card_no)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
  jQuery.ajax({
		type: "POST",
		url: "production/fusing_production/fusing_production_entry_db.php",
		data: "pr_id="+pr_id+"&job_card_no="+job_card_no+"&action=Del_sub",
		success: function(msg){jQuery("#get_prod_print_sub_div").html(msg);
 		}
		});	
	}
	get_fusing_size(job_card_no);
}
function fusing_main_add(job_card_no,print_date,cust_name,job_created,cust_po,style_no,style_name,combo,printed_qty,fusing_status,count,fabric_type,action,edit_id,edit_job_card_id)
{
		if((job_card_no!='')&&(cust_name!='')&&(count!='0'))
		{
		document.getElementById("submit").disabled=true;
		jQuery.ajax({
		type: "POST",
		url: "production/fusing_production/fusing_production_entry_db.php",
		data: "job_card_no="+job_card_no+"&print_date="+print_date+"&cust_name="+cust_name+"&job_created="+job_created+"&cust_po="+cust_po+"&style_no="+style_no+"&style_name="+style_name+"&combo="+combo+"&printed_qty="+printed_qty+"&fusing_status="+fusing_status+"&action="+action+"&fabric_type="+fabric_type+"&edit_id="+edit_id+"&edit_job_card_id="+edit_job_card_id,
		success: function(msg){ jQuery("#get_prod_print_main_div").html(msg);
		window.location.href="main_fram.php?file=fusing_production_list";

 }
		});
		}
		else
		{
			fusing_main_validation()
		}
}
function edit_fusing_prod_dfetails(p_id,job_card_no)
{
window.location.href="main_fram.php?file=fusing_production&edit_id=" + p_id + "&job_card_no=" + job_card_no;
}
function del_fusing_main(p_id,job_card_no)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
  jQuery.ajax({
		type: "POST",
		url: "production/fusing_production/fusing_production_entry_db.php",
		data: "p_id="+p_id+"&job_card_no="+job_card_no+"&action=delete_fusing_main",
		success: function(msg){jQuery("#get_prod_print_main_div").html(msg);
		window.location.reload(true);
 		}
		});	
	}
}

