// JavaScript Document

/*************************************validation********************************/
function jobcard_validation()
{
    var customer_name = document.getElementById("customer_name").value;
	if(customer_name=='')
	{
		document.getElementById("customer_name_validation_div").innerHTML="* This field is Required.";
		document.getElementById("customer_name").focus();
		return false;
	}
	
	var style_no = document.getElementById("style_no").value;
	if(style_no=='')
	{
		document.getElementById("style_no_validation_div").innerHTML="* This field is Required.";
		document.getElementById("style_no").focus();
		return false;
	}
	var created_by = document.getElementById("created_by").value;
	if(created_by=='')
	{
		document.getElementById("job_created_by_validation_div").innerHTML="* This field is Required.";
		document.getElementById("created_by").focus();
		return false;
	}
	var style_name = document.getElementById("style_name").value;
	if(style_name=='')
	{
		document.getElementById("style_name_validation_div").innerHTML="* This field is Required.";
		document.getElementById("style_name").focus();
		return false;
	}
	var cust_po_no = document.getElementById("cust_po_no").value;
	if(cust_po_no=='')
	{
		document.getElementById("cust_po_no_validation_div").innerHTML="* This field is Required.";
		document.getElementById("cust_po_no").focus();
		return false;
	}
	var combo = document.getElementById("combo").value;
	if(combo=='')
	{
		document.getElementById("combo_validation_div").innerHTML="* This field is Required.";
		document.getElementById("combo").focus();
		return false;
	}
}

/*************************************validation********************************/
function jobcard_sub_validation()
{
    var customer_name = document.getElementById("customer_name").value;
	if(customer_name=='')
	{
		document.getElementById("customer_name_validation_div").innerHTML="* This field is Required.";
		document.getElementById("customer_name").focus();
		return false;
	}
	 var particulars = document.getElementById("particulars").value;
	if(particulars=='')
	{
		document.getElementById("particulars_validation_div").innerHTML="* This field is Required.";
		document.getElementById("particulars").focus();
		return false;
	}
	
}
/*************************************validation********************************/


function jobcard_clear_validation(str)
{
	if(str!='')
	{
		document.getElementById("customer_name_validation_div").innerHTML="";
	}
	
	if(str!='')
	{
		document.getElementById("style_no_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("job_created_by_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("style_name_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("cust_po_no_validation_div").innerHTML="";
	}

    if(str!='')
	{
		document.getElementById("combo_validation_div").innerHTML="";
	}
}
/************************************validation*********************************/

function jobcard_sub_clear_validation(str)
{
	if(str!='')
	{
		document.getElementById("customer_name_validation_div").innerHTML="";
	}
	
	if(str!='')
	{
		document.getElementById("particulars_validation_div").innerHTML="";
	}
	
	
}


/*************************************Main list add********************************/

function jobcard_main_list(jobcard_no,entry_time,customer_name,style_no,created_by,style_name,cust_po_no,combo,jobtype,fabric_type,overal_tot,tax,tax_amt,net_amt,edit_id,action)
{ 

		if((customer_name!='')&&(style_no!='')&&(created_by!='')&&(style_name!='')&&(cust_po_no!='')&&(combo!=''))
 {
	 
	  if(confirm('Are You Sure! You Want To Conform The JobCard..?'))
	{
        jQuery.ajax({
		type: "POST",
		url: "jobcard/jobcard_entry/jobcard_db.php",
		data: "jobcard_no="+jobcard_no+"&entry_time="+entry_time+"&customer_name="+customer_name+"&style_no="+style_no+"&created_by="+created_by+"&style_name="+style_name +"&cust_po_no="+cust_po_no+"&combo="+combo+"&jobtype="+jobtype+"&fabric_type="+fabric_type +"&overal_tot="+overal_tot+"&tax="+tax+"&tax_amt="+tax_amt+"&net_amt="+net_amt+"&main_edit_id="+edit_id+"&action="+action,
		success: function(msg){jQuery("#jobcard_main_list_div").html(msg);	
		if(edit_id!='')
		{
			
		window.location.href="main_fram.php?file=jobcard_creation";
		}
		
			else
			{
			window.location.reload(true);
		    }
 }
		});
 }
 }
else
{
   jobcard_validation();
}
}

/******************************* Branch Sublist**********************************************/
function jobcard_sub_list(jobcard_no,entry_time,created_by,cust_po_no,customer_name,jobtype,fabric_type,hsn_code,particulars,width,height,rate,amount,conformed_amt,qty,values,edit_id,quotation_no,action)
{
if((particulars!='')&&(amount!='')&&(conformed_amt!='')&&(values!=''))
 {
        jQuery.ajax({
		type: "POST",
		url: "jobcard/jobcard_entry/jobcard_db.php",
		data: "jobcard_no="+jobcard_no+"&entry_time="+entry_time+"&created_by="+created_by+"&cust_po_no="+cust_po_no+"&customer_name="+customer_name+"&jobtype="+jobtype+"&fabric_type="+fabric_type+"&hsn_code="+hsn_code+"&particulars="+particulars+"&jobcard_width="+width+"&jobcard_height="+height+"&rate="+rate+"&amount="+amount+"&conformed_amt="+conformed_amt+"&qty="+qty+"&values="+values+"&edit_id="+edit_id+"&quotation_no="+quotation_no+"&action="+action,
		success: function(msg){jQuery("#jobcard_sublist_div").html(msg);	
		document.getElementById('particulars').value="";
		document.getElementById('jobcard_width').value="";
		document.getElementById('jobcard_height').value="";
		document.getElementById('rate').value="";
		document.getElementById('amount').value="";
		document.getElementById('conformed_amt').value="";
		document.getElementById('qty').value="";
		document.getElementById('values').value="";
          document.getElementById('add').value="ADD";
         document.getElementById('particulars').focus();

		//alert(msg);
		//window.close();
		//window.opener.location.reload(true);
		
 }
		});
 }
else
{
  jobcard_sub_validation();
}
}

/***********************************delete************************************/
function edit_jobcard_sub(edit_id,jobcard_no,quotation_no,source_frm)
{
	//alert("edit_id="+edit_id+"&jobcard_no="+jobcard_no+"&quotation_no="+quotation_no);
	
		jQuery.ajax({
		type: "POST",
		url: "jobcard/jobcard_entry/jobcard_sublist.php",
		data: "edit_id="+edit_id+"&jobcard_no="+jobcard_no+"&quotation_no="+quotation_no+"&source_frm="+source_frm,
		success: function(msg){jQuery("#jobcard_sublist_div").html(msg);
	}
	});

}
/********************************************************************************************/
function get_jobcard_amt(jobcard_width,jobcard_height,rate)
{
if(jobcard_width=='')
{
var jobcard_width=0;
}
if(jobcard_height=='')
{
var jobcard_height=0;
}
if(rate=='')
{
var rate=0;
}
var amt=(jobcard_width)*(jobcard_height)*(rate);
document.getElementById('amount').value=amt.toFixed(2);
}

function get_total(overal_tot,tax)
{
	if(overal_tot=='')
{
var overal_tot=0;
}
	if(tax=='')
{
var tax=0;
}
var tax_amt=(overal_tot/100)*tax;
var tot_tax_amt2=tax_amt.toFixed(2);
document.getElementById('tax_amt').value=tot_tax_amt2;
var tot_tax_amt=parseFloat(overal_tot)+parseFloat(tax_amt);
var tot_tax_amt1=tot_tax_amt.toFixed(2);
document.getElementById('net_amt').value=tot_tax_amt1;
}
/******************************************************************************************/
function get_jobcard_tot(conformed_amt,qty)
{
if(conformed_amt=='')
{	
var	conformed_amt=0;
}
if(qty=='')
{	
var	qty=0;
}
var value_amt=parseFloat(conformed_amt)*parseFloat(qty);
document.getElementById('values').value=value_amt;

}
/**********************************************************************************************/
function get_fabric_type1(jobtype)
{
	if(jobtype=='TBilling')
	{
		jQuery.ajax({
			type: "POST",
			url: "jobcard/jobcard_entry/jobcard_entry_fabric_type_tbilling.php",
			success: function(data){
				jQuery("#fabric_type_main").html(data);
			}
		});
		
	}
	if(jobtype=='Re Production' || jobtype=='sample' || jobtype=='sticker' || jobtype=='T fusing work')
	{
		jQuery.ajax({
			type: "POST",
			url: "jobcard/jobcard_entry/jobcard_entry_fabric_type_empty.php",
			success: function(data){
				jQuery("#fabric_type_main").html(data);
			}
		});
		
	}

	if(jobtype=='production')
	{
		jQuery.ajax({
			type: "POST",
			url: "jobcard/jobcard_entry/jobcard_entry_fabric_type.php",
			success: function(data){
				jQuery("#fabric_type_main").html(data);
			}
		});

	}
	
}
/***************************************************************************************/	
	function get_hsn_code(fabric_type,jobtype)
{

	
	if((fabric_type!='')&&(jobtype=='production'))
	{
		        document.getElementById('hsn_div').style.display='block'; 
				document.getElementById('hsn_div1').style.display='block';    
	}
	else
	{
		            
             document.getElementById('hsn_div').style.display='none'; 
			 document.getElementById('hsn_div1').style.display='none';
	}
	
	}
	
	function get_hsn_value(jobtype)
	{
		if(jobtype=='sticker')
		{
		   document.getElementById('hsn_code').value='998821'; 
		}
		else
		{
		   document.getElementById('hsn_code').value='998821'; 
		}
		
	}
	
/***********************************Delete Branch Sublist************************************/
function del_jobcard_sub(job_id,jobcard_no)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
		jQuery.ajax({
		type: "POST",
		url: "jobcard/jobcard_entry/jobcard_db.php",
		data: "job_id="+job_id+"&jobcard_no="+jobcard_no+"&action=delete_job_sub",
		success: function(msg){jQuery("#jobcard_sublist_div").html(msg);
	}
	});
    }
}

function del_job_main(job_id,jobcard_no)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
		jQuery.ajax({
		type: "POST",
		url: "jobcard/jobcard_entry/jobcard_db.php",
		data: "job_id="+job_id+"&jobcard_no="+jobcard_no+"&action=delete_job_main",
		success: function(msg){jQuery("#jobcard_main_list_div").html(msg);
	window.location.reload(true);
	}
	});
    }
}

