/**********************************MAIN  Validation *******************************************************/

function challan_main_validation()
{
	  var job_card_no = document.getElementById("job_card_no").value;
	if(job_card_no=='')
	{
		document.getElementById("printer_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("job_card_no").focus();
		return false;
	}
}
/********************************** sub Validation *******************************************************/

function printer_sub_validation()
{
    var job_card_no = document.getElementById("job_card_no").value;
	if(job_card_no=='')
	{
		document.getElementById("printer_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_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_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_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("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("pqty_validation_div").innerHTML="* This field is Required.";
		document.getElementById("prod_qty").focus();
		return false;
	}
}

/*************************************validation********************************/

function printer_clear_validation(str)
{
	if(str!='')
	{
		document.getElementById("printer_validation_div").innerHTML="";
	}
	
	if(str!='')
	{
		document.getElementById("shift_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("machine_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("operator_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("size_validation_div").innerHTML="";
	}

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

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

 }
		});
}

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

 }
		});
}


function get_calc_qty(total_qty,prod_qty)
{
	var total_qty=total_qty;
	var prod_qty=prod_qty;
	var dup_total_qty=total_qty+1;
	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!!');
	jQuery("#prod_qty").val('');}
}

function add_print_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!=''))
	{
	  jQuery('#add').hide();
	  jQuery.ajax({
		type: "POST",
		url: "production/printer_production/printer_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();
 }
		});
	//	alert(production_time);
		get_size(job_card_no);		
}
else
{
	printer_sub_validation();
	}	
//}else{ alert('Please Check the Size or Qty!!');}
}
function view_jobcard(job_card_no)
{
		  jQuery.ajax({
		type: "POST",
		url: "production/printer_production/printer_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_print_prod_sub(pr_id,job_card_no)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
  jQuery.ajax({
		type: "POST",
		url: "production/printer_production/printer_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_size(job_card_no);
}
function printer_main_add(job_card_no,print_date,cust_name,job_created,cust_po,style_no,style_name,combo,printed_qty,action,printer_status,edit_id,edit_job_card_id)
{
	
	if((job_card_no!='')&&(cust_name!=''))
	{
		jQuery.ajax({
		type: "POST",
		url: "production/printer_production/printer_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+"&action="+action+"&printer_status="+printer_status+"&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=printer_production_list";

 }
		});
	}
		else
{
    challan_main_validation();
	
}

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

