/********************************** Validation *******************************************************/
function fab_deliv_challan_validation()
{
    var job_no = document.getElementById("job_no").value;
	if(job_no=='')
	{
		document.getElementById("delivery_challan_jobno_validation_div").innerHTML="* This field is Required.";
		document.getElementById("job_no").focus();
		return false;
	}
	 var overal_qty = document.getElementById("overal_qty").value;
	if(overal_qty=='')
	{
		alert("Please Fill the Sublist");
		document.getElementById("deliv_particular").focus();
		return false;
	}
	 var delivery_through = document.getElementById("delivery_through").value;
	if(delivery_through=='')
	{
		document.getElementById("delivery_through_chal_validation_div").innerHTML="* This field is Required.";
		document.getElementById("delivery_through").focus();
		return false;
	}
	 var vehicle_no = document.getElementById("vehicle_no").value;
	if(vehicle_no=='')
	{
		document.getElementById("vehicleno_challan_validation_div").innerHTML="* This field is Required.";
		document.getElementById("vehicle_no").focus();
		return false;
	}
}

function fab_deliv_challan_clear_validation(str)
{
	if(str!='')
	{
		document.getElementById("delivery_challan_jobno_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("delivery_through_chal_validation_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("vehicleno_challan_validation_div").innerHTML="";
	}
}
/*************************main list********************************************/
function delivery_challan_add(delivery_no,date_time,job_no,created_by,customer_name,style_no,style_name,combo,cust_po_no,job_type,fabric_type,remarks,overal_qty,deliv_status,delivery_through,vehicle_no,edit_id,action)
{ //alert(date_time);
if((job_no!='')&&(overal_qty!='')&&(delivery_through!='')&&(vehicle_no!=''))
 {
	 if(confirm('Are You Sure! You Want To Print?'))
	{
  jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/delivery_challan_form_db.php",
		data: "delivery_no="+delivery_no+"&date_time="+date_time+"&job_no="+job_no+"&created_by="+created_by+"&customer_name="+customer_name+"&style_no="+style_no+"&style_name="+style_name+"&combo="+combo+"&cust_po_no="+cust_po_no+"&job_type="+job_type+"&fabric_type="+fabric_type+"&remarks="+remarks+"&overal_qty="+overal_qty+"&deliv_status="+deliv_status+"&delivery_through="+delivery_through+"&vehicle_no="+vehicle_no+"&edit_id="+edit_id+"&action="+action,
		success: function(msg){jQuery("#delivery_challan_main_list").html(msg);
		 var url='jobcard/delivery_challan/delivery_details_print.php?customer_name='+customer_name+'&delivery_no='+delivery_no;
	window.open(url,'onmouseover5525','height=500,width=800,scrollbars=yes,resizable=no,left=50,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no');
	    window.location.reload(true);
	 if(edit_id!='')
		 { 
		     window.location.reload(true);
			 window.location.href="main_fram.php?file=delivery_challan_list";
		 }
		
  	    
 }
		});
}
}
else
{
    fab_deliv_challan_validation();
}
}

/**************************** Delivery Sublist***********************************************/
function delivery_sublist_add(delivery_no,date_time,job_no,customer_name,job_type,fabric_type,delivery_dates,deliv_particular,roll_width,kg_height,inward_qty,tot_qty,edit_id,action)
{
	if((parseInt(inward_qty)<=parseInt(tot_qty))&&(inward_qty!=0))
{
	jQuery('#action').hide();
  jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/delivery_challan_form_db.php",
		data: "delivery_no="+delivery_no+"&date_time="+date_time+"&job_no="+job_no+"&customer_name="+customer_name+"&job_type="+job_type+"&fabric_type="+fabric_type+"&delivery_date="+delivery_dates+"&deliv_particular="+deliv_particular+"&roll_width="+roll_width+"&kg_height="+kg_height+"&inward_qty="+inward_qty+"&tot_qty="+tot_qty+"&edit_id="+edit_id+"&action="+action,
		success: function(msg){jQuery("#delivery_challan_sublist_div").html(msg);
		jQuery('#action').show();
		document.getElementById("roll_width").value='';
		document.getElementById("kg_height").value='';
		document.getElementById("inward_qty").value='';
		document.getElementById('add').value='ADD';
		document.getElementById("job_no").focus();
		document.getElementById("delivery_dates").focus();
 }
		});
}
else
{
	alert("Please Check the Quantity");
	document.getElementById("inward_qty").focus();

}
}

/************************* SUB EDIT********************************/
function edit_sublist_delivery(edit_id,delivery_no)
{ 
  jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/delivery_challan_sublist.php",
		data: "edit_id="+edit_id+"&delivery_no="+delivery_no,
		success: function(msg){jQuery("#delivery_challan_sublist_div").html(msg);
		//document.getElementById("job_no").focus();
		//document.getElementById("delivery_dates").focus();

 }
		});
}
/**************************** get_jobcard_details ************************************************/
function get_jobcard_details(job_no)
{
		jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/customer_name.php",
		data: "job_no="+job_no,
		success: function(msg){jQuery("#deliv_cust_name").html(msg);
	}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/style_no.php",
		data: "job_no="+job_no,
		success: function(msg){jQuery("#deliv_style_no_div").html(msg);
	}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/created_by.php",
		data: "job_no="+job_no,
		success: function(msg){jQuery("#deliv_created_by_div").html(msg);
	}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/style_name.php",
		data: "job_no="+job_no,
		success: function(msg){jQuery("#deliv_style_name_div").html(msg);
	}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/cust_po_no.php",
		data: "job_no="+job_no,
		success: function(msg){jQuery("#deliv_customer_po_div").html(msg);
	}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/combo.php",
		data: "job_no="+job_no,
		success: function(msg){jQuery("#deliv_combo_type_div").html(msg);
	}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/job_type.php",
		data: "job_no="+job_no,
		success: function(msg){jQuery("#deliv_job_types_div").html(msg);
	}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/fabric_type.php",
		data: "job_no="+job_no,
		success: function(msg){jQuery("#deliv_fabric_type_div").html(msg);
	}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/inward_particulars.php",
		data: "job_no="+job_no,
		success: function(msg){jQuery("#deliv_particulars_div").html(msg);
	}
	});
	
}

/***************************** Get Sublist details ***********************************************************/
function get_sub_details(job_no,deliv_particulars)
{
	
		jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/delivery_roll_width.php",
		data: "job_no="+job_no+"&deliv_particulars="+deliv_particulars,
		success: function(msg){jQuery("#delivery_roll_width_div").html(msg);
	}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/delivery_kg_height.php",
		data: "job_no="+job_no+"&deliv_particulars="+deliv_particulars,
		success: function(msg){jQuery("#delivery_kg_height_div").html(msg);
	}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/delivery_qty.php",
		data: "job_no="+job_no+"&deliv_particulars="+deliv_particulars,
		success: function(msg){jQuery("#delivery_qty_div").html(msg);
	}
	});
}
/******************************************** SUB DELETE*****************************************************************/
function delete_sublist_delivery_list(id,delivery_no,jobcard_no)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
		jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/delivery_challan_form_db.php",
		data: "id="+id+"&delivery_no="+delivery_no+"&job_no="+jobcard_no+"&action=del_deliv_sublist",
		success: function(msg){jQuery("#delivery_challan_sublist_div").html(msg);
		document.getElementById("job_no").focus();
		document.getElementById("delivery_dates").focus();
	}
	});
    }
}
/******************************main list delte*******************************************/
function delivery_challan_delete(id,job_no,delivery_no)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
		jQuery.ajax({
		type: "POST",
		url: "jobcard/delivery_challan/delivery_challan_form_db.php",
		data: "id="+id+"&job_no="+job_no+"&delivery_no="+delivery_no+"&action=delete_deliv_main",
		success: function(msg){jQuery("#delivery_challan_main_list").html(msg);
		window.location.reload(true);
	}
	});
    }
}
