// JavaScript Document

/*************************************validation********************************/
function jobcard_quot_validation()
{
    var customer_name = document.getElementById("customer_name_quot").value;
	if(customer_name=='')
	{
		document.getElementById("customer_name_quot_validation_div").innerHTML="* This field is Required.";
		document.getElementById("customer_name_quot").focus();
		return false;
	}
	
	var style_no = document.getElementById("style_no_quot").value;
	if(style_no=='')
	{
		document.getElementById("style_no_quot_validation_div").innerHTML="* This field is Required.";
		document.getElementById("style_no_quot").focus();
		return false;
	}
	var created_by = document.getElementById("created_by_quot").value;
	if(created_by=='')
	{
		document.getElementById("job_created_by_quot_validation_div").innerHTML="* This field is Required.";
		document.getElementById("created_by_quot").focus();
		return false;
	}
	var style_name = document.getElementById("style_name_quot").value;
	if(style_name=='')
	{
		document.getElementById("style_name_quot_validation_div").innerHTML="* This field is Required.";
		document.getElementById("style_name_quot").focus();
		return false;
	}
	var cust_po_no = document.getElementById("cust_po_no_quot").value;
	if(cust_po_no=='')
	{
		document.getElementById("cust_po_no_quot_validation_div").innerHTML="* This field is Required.";
		document.getElementById("cust_po_no_quot").focus();
		return false;
	}
	var combo = document.getElementById("combo_quot").value;
	if(combo=='')
	{
		document.getElementById("combo_quot_validation_div").innerHTML="* This field is Required.";
		document.getElementById("combo_quot").focus();
		return false;
	}
	var payment_type = document.getElementById("payment_type").value;
	if(payment_type=='')
	{
		document.getElementById("payment_type_validation_div").innerHTML="* This field is Required.";
		document.getElementById("payment_type").focus();
		return false;
	}
	var net_amt_quot = document.getElementById("net_amt_quot").value;
	if((net_amt_quot=='')||(net_amt_quot!=0.00))
	{
		alert("Please Fill the sublist");
		document.getElementById("particulars_quot").focus();
		return false;
	}
}

/*************************************validation********************************/
function jobcard_sub_quot_validation()
{
    var customer_name = document.getElementById("customer_name_quot").value;
	if(customer_name=='')
	{
		document.getElementById("customer_name_quot_validation_div").innerHTML="* This field is Required.";
		document.getElementById("customer_name_quot").focus();
		return false;
	}
	 var particulars = document.getElementById("particulars_quot").value;
	if(particulars=='')
	{
		document.getElementById("particulars_quot_validation_div").innerHTML="* This field is Required.";
		document.getElementById("particulars_quot").focus();
		return false;
	}
	 var jobcard_width_quot = document.getElementById("jobcard_width_quot").value;
	if(jobcard_width_quot=='')
	{
		document.getElementById("width_quot_validation_div").innerHTML="* This field is Required.";
		document.getElementById("jobcard_width_quot").focus();
		return false;
	}
	 var jobcard_height_quot = document.getElementById("jobcard_height_quot").value;
	if(jobcard_height_quot=='')
	{
		document.getElementById("height_quot_validation_div").innerHTML="* This field is Required.";
		document.getElementById("jobcard_height_quot").focus();
		return false;
	}
	 var rate_quot = document.getElementById("rate_quot").value;
	if(rate_quot=='')
	{
		document.getElementById("rate_quot_validation_div").innerHTML="* This field is Required.";
		document.getElementById("rate_quot").focus();
		return false;
	}
	 var conformed_amt_quot = document.getElementById("conformed_amt_quot").value;
	if(conformed_amt_quot=='')
	{
		document.getElementById("confirm_amt_quot_validation_div").innerHTML="* This field is Required.";
		document.getElementById("conformed_amt_quot").focus();
		return false;
	}
}
/*************************************validation********************************/


function jobcard_quot_clear_validation(str)
{
	if(str!='')
	{
		document.getElementById("customer_name_quot_validation_div").innerHTML="";
	}
	
	if(str!='')
	{
		document.getElementById("style_no_quot_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("job_created_by_quot_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("style_name_quot_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("cust_po_no_quot_validation_div").innerHTML="";
	}

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

function jobcard_quot_sub_clear_validation(str)
{
	if(str!='')
	{
		document.getElementById("customer_name_quot_validation_div").innerHTML="";
	}
	
	if(str!='')
	{
		document.getElementById("particulars_quot_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("width_quot_validation_div").innerHTML="";
	}
	
	if(str!='')
	{
		document.getElementById("height_quot_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("rate_quot_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("confirm_amt_quot_validation_div").innerHTML="";
	}
}


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

function jobcard_quot_main_list(jobcard_no,entry_time,customer_name,style_no,created_by,style_name,cust_po_no,combo,jobtype,fabric_type,overal_tot,net_amt,order_by_quot,payment_type,edit_id,action)
{ 
		if((customer_name!='')&&(style_no!='')&&(created_by!='')&&(style_name!='')&&(cust_po_no!='')&&(combo!='')&&(payment_type!='')&&((net_amt!='')||(net_amt!=0.00)))
 {
	 
	  if(confirm('Are You Sure! You Want To Conform The JobCard..?'))
	{
        jQuery.ajax({
		type: "POST",
		url: "jobcard/quotation_jobcard/jobcard_quot_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+"&net_amt="+net_amt+"&order_by_quot="+order_by_quot+"&payment_type="+payment_type+"&main_edit_id="+edit_id+"&action="+action,
		success: function(msg){jQuery("#jobcard_quot_main_list_div").html(msg);	
		if(edit_id!='')
		{
			
		window.location.href="main_fram.php?file=jobcard_quotation";
		}
		
			else
			{
				window.location.reload(true);
		    }
 }
		});
 }
 }
else
{
   jobcard_quot_validation();
}
}
function jobcard_quot_confirm(jobcard_no_quot,customer_name_quot,entry_time_quot,overal_tot_quot,net_amt_quot,edit_id1,action) 
{ 
jQuery.ajax({
		type: "POST",
		url: "jobcard/quotation_jobcard/jobcard_quot_db.php",
		data: "jobcard_no_quot="+jobcard_no_quot+"&customer_name_quot="+customer_name_quot+"&entry_time_quot="+entry_time_quot+"&overal_tot_quot="+overal_tot_quot+"&net_amt_quot="+net_amt_quot+"&edit_id1="+edit_id1+"&action=conformed",
		success: function(msg){jQuery("#jobcard_main_list_div").html(msg);	
		window.location.href="main_fram.php?file=jobcard_creation&quotation_no="+jobcard_no_quot+"&source_frm=jobcard_quotation";

 }
		});
 }
/******************************* Branch Sublist**********************************************/
function jobcard_quot_sub_list(jobcard_no,entry_time,created_by,cust_po_no,customer_name,jobtype,fabric_type,particulars,width,height,rate,amount,conformed_amt,qty,values,edit_id,action)
{ 

if((particulars!='')&&(width!='')&&(height!='')&&(rate!='')&&(conformed_amt!=''))
 {
        jQuery.ajax({
		type: "POST",
		url: "jobcard/quotation_jobcard/jobcard_quot_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+"&particulars="+particulars+"&jobcard_width="+width+"&jobcard_height="+height+"&rate="+rate+"&amount="+amount+"&conformed_amt="+conformed_amt+"&qty="+qty+"&values="+values+"&edit_id="+edit_id+"&action="+action,
		success: function(msg){jQuery("#jobcard_quot_sublist_div").html(msg);	
		document.getElementById('particulars_quot').value="";
		document.getElementById('jobcard_width_quot').value="";
		document.getElementById('jobcard_height_quot').value="";
		document.getElementById('rate_quot').value="";
		document.getElementById('amount_quot').value="";
		document.getElementById('conformed_amt_quot').value="";
		document.getElementById('qty_quot').value="";
		document.getElementById('values_quot').value="";
          document.getElementById('add').value="ADD";
         document.getElementById('particulars_quot').focus();

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

/***********************************delete************************************/
function edit_jobcard_quot_sub(edit_id,jobcard_no)
{
	
		jQuery.ajax({
		type: "POST",
		url: "jobcard/quotation_jobcard/jobcard_quot_sublist.php",
		data: "edit_id="+edit_id+"&jobcard_no="+jobcard_no,
		success: function(msg){jQuery("#jobcard_quot_sublist_div").html(msg);
	}
	});

}
/********************************************************************************************/
function get_jobcard_quot_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_quot').value=amt.toFixed(4);
}

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_quot').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_quot').value=tot_tax_amt1;
}
/******************************************************************************************/
function get_jobcard_quot_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_quot').value=value_amt;

}
/**********************************************************************************************/
function get_fabric_type(jobtype)
{
	if(jobtype=='sticker')
	{
		            document.getElementById('fabric_type_div').style.display='none'; 
					document.getElementById('fabric_type_div1').style.display='none';
	}
	if(jobtype=='production')
	{
		            document.getElementById('fabric_type_div').style.display='block'; 
					document.getElementById('fabric_type_div1').style.display='block';

	}
	
	}
/***********************************Delete Branch Sublist************************************/
function del_jobcard_quot_sub(job_id,jobcard_no)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
		jQuery.ajax({
		type: "POST",
		url: "jobcard/quotation_jobcard/jobcard_quot_db.php",
		data: "job_id="+job_id+"&jobcard_no="+jobcard_no+"&action=delete_job_sub",
		success: function(msg){jQuery("#jobcard_quot_sublist_div").html(msg);
	}
	});
    }
}
function jobcard_confirm_delete(jobcard_no)
{
	
		jQuery.ajax({
		type: "POST",
		url: "jobcard/quotation_jobcard/confirm_del.php",
		data: "&jobcard_no="+jobcard_no,
		success: function(msg){jQuery("#jobcard_quot_sublist_div1").html(msg);
	}
	});
    
}

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

