
v1 = []; 
function Finish_adjust(){
	//command
	 var command =$('#command').val();
	  var id =$('#id').val();
	  var adjust =$('#adjust').val();
	  v1.push(command , id , adjust);
	   BetaCustom('adjust_stock_take_form.php' ,  3 , v1 , '#Load_here' );
	  
	return false;
}
function add_to_stock(){
	 var add =$('[name="add_to_stock"]:checked').map( function(){ return $(this).val(); }).toArray();//trm
	 
	 BetaCustom('adjust_stock_take_form.php' ,  1 , add[0] , '#Load_here' );
	return false; 
}
function remove_from_stock(){
	 var add =$('[name="remove_from_stock"]:checked').map( function(){ return $(this).val(); }).toArray();//trm
	 
	 BetaCustom('adjust_stock_take_form.php' ,  2 , add[0]  , '#Load_here' );
	return false; 
}

function BetaCustom(scrpt ,  com , d , loadHere ){
	 
	 
	
	 var request = $.ajax({ url: scrpt, type: "POST", data: { comand : com , dataSend:d },  dataType: "html"               });

               request.done(function(reply ) {      $(loadHere).html(reply);    });
			  
			   
			   return false;
 
	
}
$(function() 
{
	$("#stockitemstable").dataTable();
	
	itemtransferform = function(item, itemversion)
	{
		$("#servererrormessage").html('');
		
		$.ajax
		(
			{
				url: "transferfromshopform.php",
				async: true, 
				type: "POST",
				dataType: "json",
				data: {stockitem: item, recversion: itemversion},
				success: function(json)
				{
					if(json[0].isdataobtained == 0)
					{
						$("#servererrormessage").html(json[0].message);
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					}
					else
					{
						$("#largemodaldetails").html(json[0].message);
						$('#largemodal').modal('show');
					}
				},
				error: function(jqXHR, exception)
				{	
					if (jqXHR.status === 0) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Not Connected Verify Network.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (jqXHR.status == 404) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested Operation Not Found.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (jqXHR.status == 500) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Internal Server Error.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'parsererror') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested JSON Parse Failed.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'timeout') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Time Out Error.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'abort') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Ajax Request Aborted.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Uncaught Error " + jqXHR.responseText + ".</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					}
				}
			}
		);
		
	}
	
	itemadjustmentform = function(item, itemversion)
	{
		 
		$("#servererrormessage").html('');
		
		$.ajax
		(
			{
				url: "itemadjustmentform.php",
				async: true, 
				type: "POST",
				dataType: "json",
				data: {stockitem: item, recversion: itemversion},
				success: function(json)
				{
					if(json[0].isdataobtained == 0)
					{
						$("#servererrormessage").html(json[0].message);
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					}
					else
					{
					 
						$("#largemodaldetails").html(json[0].message);
						$('#largemodal').modal('show');
					}
				},
				error: function(jqXHR, exception)
				{	
					if (jqXHR.status === 0) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Not Connected Verify Network.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (jqXHR.status == 404) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested Operation Not Found.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (jqXHR.status == 500) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Internal Server Error.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'parsererror') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested JSON Parse Failed.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'timeout') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Time Out Error.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'abort') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Ajax Request Aborted.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Uncaught Error " + jqXHR.responseText + ".</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					}
				}
			}
		);
		
	}
	
	itemstatusupdate = function(item, shopfocus, itemversion)
	{
		$("#servererrormessage").html('');
		
		$.ajax
		(
			{
				url: "shopitemstatusupdate.php",
				async: true, 
				type: "POST",
				dataType: "json",
				data: {stockitem: item, recversion: itemversion},
				success: function(json)
				{
					if(json[0].issaved == 0)
					{
						$("#servererrormessage").html(json[0].message);
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					}
					else
					{
						$("#servererrormessage").html(json[0].message);
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						window.location.reload(true);
					}
				},
				error: function(jqXHR, exception)
				{	
					if (jqXHR.status === 0) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Not Connected Verify Network.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (jqXHR.status == 404) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested Operation Not Found.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (jqXHR.status == 500) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Internal Server Error.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'parsererror') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested JSON Parse Failed.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'timeout') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Time Out Error.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'abort') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Ajax Request Aborted.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Uncaught Error " + jqXHR.responseText + ".</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					}
				}
			}
		);
		
	}
	
	
});