<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<title>Scan Assets</title>
	
	<!--MqRelPath--><link rel="stylesheet" title="silver" type="text/css" href="../../theme/css/censusmain.css"/><!--/MqRelPath--><!--MqAbsPath><link rel="stylesheet" title="silver" type="text/css" href="<BASE_VD>/theme/css/censusmain.css"/></MqAbsPath-->
	<!--MqRelPath--><link rel="stylesheet" title="silver" type="text/css" href="../../theme/css/mqwizard.css"/><!--/MqRelPath--><!--MqAbsPath><link rel="stylesheet" title="silver" type="text/css" href="<BASE_VD>/theme/css/mqwizard.css"/></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/mqsysutils.js" ></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/mqsysutils.js" ></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/cmqsysmsg.js" ></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/cmqsysmsg.js" ></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/window.js" ></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/window.js" ></script></MqAbsPath-->
	
	<!--MqRelPath--><link rel="stylesheet" href="../../js/jquery/jquery.ui.all.css"><!--/MqRelPath--><!--MqAbsPath><link rel="stylesheet" href="<BASE_VD>/js/jquery/jquery.ui.all.css"></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery-1.8.3.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery-1.7.1.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.bgiframe-2.1.2.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.bgiframe-2.1.2.js"></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.core.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.core.js"></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.widget.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.widget.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.mouse.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.mouse.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.draggable.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.draggable.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.position.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.position.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.resizable.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.resizable.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.dialog.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.dialog.js"></script></MqAbsPath-->
	<script type="text/javascript" src="../../js/VNHTMLDocInit.js"></script>
	<link rel="stylesheet" type="text/css" href="../../js/jquery/bootstrap3.3.7/css/bootstrap.min.css"  />	
	<link rel="stylesheet" type="text/css" href="../../js/jquery/jquery-confirm.min.css"  />	
	<script type="text/javascript" src="../../js/jquery/jquery-confirm.min.js"></script>

	<script type="text/javascript">
		// always define this object for the system messages
		var objSysMsg = new CMqSysMsg();
		var m_objMqButton = new MqButton();
		
		var m_objRef;
		
		if(opener){
			if(opener.parent){
				m_objRef=opener.parent;
			}
		}else{
			if(parent){
				m_objRef=parent;
			}
		}
		
		var m_strMsgTitle="";
		var m_strMsgContent="";
		var m_serviceResponse = "";
		
		function OnLoad(){
			
			var objSNs=document.getElementById("memSerialNums");
			document.getElementById("WizardDescription").innerHTML = g_MqRef.RESX['DESC_CHECKOUT_MULTIPLE_ASSETS'];
			document.getElementById("WizardTitle").innerHTML = g_MqRef.RESX['TITLE_CHECKOUT_MULTIPLE_ASSETS'];
			g_MqRef.AlertBox = new AlertBox();
			
			if(objSNs){
				objSNs.focus();
			}
			return true;
		}

		function cmdOK_OnClick(blnCloseAfterSave)
		{
			var objSNs=document.getElementById("memSerialNums");
			var strURL="";
			if(objSNs){
				if(m_objRef){
					var strSNs=objSNs.value;
					var strInDelim=";";
					var strOutDelim=";";
					var strAvailableWhere="Asset_Sub_status=2";//in stock
					
					if(strSNs != "")
					{
						var request = 
						{
							"UserName": g_MqRef.m_strCurrentUser,
							"ProjectName":"resources",
							"UniqueFieldNames":["Serial_Number","Asset_Tag"],
							"UniqueFieldValues":strSNs.split("\n"),
							"Location":parent.g_VWS.RecordMgr().CurrentRecord().FldVals(1).GetValue(),
							"LocationLevel":parent.g_VWS.RecordMgr().CurrentRecord().FldVals(846).GetValue(),
							"WhereFilter":strAvailableWhere						
						}
					
						this.CallExtRestService(request, location.protocol + "//" + location.hostname + "/connect00/Resources/FindRecordsByLocation").then(function(response)
						{
							var strMsg="";
							if (m_serviceResponse.Result)
							{
								strMsg += "<img style='float: left; margin-right:15px;margin-bottom:15px;' src='../../theme/images/images/checked.png' width='35'>";
								strMsg += "<p style='font-weight:bold;'>" + g_MqRef.RESX['MSG_ASSETS_AUDITED']+ "</p>";
								strMsg += "<table style='font-size:12px;'>";
								strMsg += "<tr>";
								
								for(var i = 0; i < m_serviceResponse.Data.ValueCollection.length; i++)
								{
									if(i == m_serviceResponse.Data.ValueCollection.length- 1)
									{
									
										strMsg += GetValueToPrint(m_serviceResponse.Data.ValueCollection[i]) + "</td>";
										
									}
									else
									{
										strMsg += GetValueToPrint(m_serviceResponse.Data.ValueCollection[i]) + ",</td>";
									}
									
								}
								strMsg += "</tr>";
								strMsg += "</table></br>";
								if(m_serviceResponse.Data.NotFoundCollection.length > 0)
								{
									strMsg += "<img style='float: left; margin-right:15px;margin-bottom:15px;' src='../../theme/images/images/warning.png' width='35'>";
									strMsg += "<p style='font-weight:bold;'>" + g_MqRef.RESX['MSG_ASSETS_NOT_IN_CURRENT_LOCATION'] + "</p>";
									strMsg += "<table style='font-size:12px;'>";
									strMsg += "<tr>";
									for(var i = 0; i < m_serviceResponse.Data.NotFoundCollection.length; i++)
									{
										if(i == m_serviceResponse.Data.NotFoundCollection.length- 1)
										{
											strMsg += GetValueToPrint(m_serviceResponse.Data.NotFoundCollection[i])+ "</td>";
										}
										else
										{	
											strMsg += GetValueToPrint(m_serviceResponse.Data.NotFoundCollection[i])+ ",</td>";
										}
																		
									}
									strMsg += "</tr>";
									strMsg += "</table></br>";
								}
								
								if(m_serviceResponse.Data.NotAvaliableCollection.length>0)
								{
									strMsg += "<img style='float: left; margin-right:15px;margin-bottom:15px;' src='../../theme/images/images/info.png' width='35'>";
									strMsg += "<p style='font-weight:bold;'>" + g_MqRef.RESX['MSG_ASSETS_NOT_IN_SYSTEM'] + "</p>";
									strMsg += "<table style='font-size:12px;'>";
									strMsg += "<tr>";
									for(var i = 0; i < m_serviceResponse.Data.NotAvaliableCollection.length; i++)
									{
										if(i == m_serviceResponse.Data.NotAvaliableCollection.length- 1)
										{
											strMsg += GetValueToPrint(m_serviceResponse.Data.NotAvaliableCollection[i]) + "</td>";
											
										}
										else
										{
											strMsg += GetValueToPrint(m_serviceResponse.Data.NotAvaliableCollection[i]) + ",</td>";
											
										}
										
									}
									strMsg += "</tr>";
									strMsg += "</table></br>";
								}
								
								
								
								
								
								g_MqRef.AlertBox.show("",strMsg);
								objSNs.value = "";
							}
							else
							{
									g_MqRef.AlertBox.show("",m_serviceResponse + "</br>");
								
							}
						});
						
					}
					else
					{
						g_MqRef.AlertBox.show("","</br> It is necessary to capture some asset </br></br></br>");
					}
					
					
					
					
					
				}			
			}
		}
		
		function GetValueToPrint(asset)
		{
		
			if(asset != undefined)
			{
				if(asset.SerialNumber == undefined )
				{
					return "<td>" + asset ;
				}
				else
				{
					if(asset.SerialNumber != "")
					{
						return "<td>" + asset.SerialNumber ;
					}
					else
					{
						return "<td>" + asset.Tag;
					}
				}
			}
		}
		
		function CallExtRestService(dataRequest,strURL_Service_Resource )
		{
			var defer = $.Deferred(); 
		
			$.ajax({
			type:"POST",
			//url:location.protocol + "//" + location.hostname + "/" + m_strURL_Service_Resource,
			url: strURL_Service_Resource,
			dataType:"json",
			contentType:" application/json",
			data:JSON.stringify(dataRequest)
			}).success(function (data)
			{
				 m_serviceResponse = data;
				 defer.resolve(m_serviceResponse);
				if ( console && console.log ) 
				{
					console.log( "The request has completed successfully: " + data );
				}
			})
			.error(function (err) {
				console.log(err.statusText);
				 defer.resolve(err);
			});

			return defer;

		}
			
		
	</script>
	<style type="text/css">
	<!--
	input,textarea,select{
		font-family: tahoma, sans-serif;
		font-size:12px;
	}
	// -->
	</style>
</head>

<body id="frmMain" name="frmMain" class="MainBackgroundPopup" 
style="margin:0;" leftmargin="0" rightmargin="0" 
onload="OnLoad();" bottommargin="0" scroll="no">

	<div class="TopToolBarPopup">
		<table width="98%" class="TopToolBarWizard">
			<tr>
				<td>
					<img src="../../theme/images/images/scannericon_big.png" width="48" height="48" />
				</td>
		        <td valign="top" style="padding-top:15px; padding-left:10px" width="100%">
		            <div id="WizardTitle" class="WizardTitle"></div>
		            <div id="WizardDescription" class="WizardDescription" style='margin-bottom:15px;'>
				
						
					</div>
		        </td>
		    </tr>
		</table>
	</div>

	<table id="tblMain" marginwidth="0" cellspacing="0" cellpadding="0" border="0" style="padding-left:10px;width: 97%;margin:15px;" >
		<tr >
			<td align="center" style="padding-top: 15px;padding-bottom: 15px;">
				<textarea style="width:100%" rows='25' cols='25' name='memSerialNums' id='memSerialNums' class='TextBoxWidth'></textarea>
			</td>			
		</tr>
	</table>
	<table align="right" style="padding-right:10px; margin:15px;">
		<tr>
			<td align=right >
				<script type="text/javascript">m_objMqButton.WriteTextButtonHTML("OK", "Audit", 'cmdOK_OnClick(true)', "", 32, "","Audit", 90);</script>
			</td>
			<td align=right>
				<script type="text/javascript">m_objMqButton.WriteTextButtonHTML("Close", g_MqRef.RESX["BUTTON_CLOSE"], 'CloseWindow()', "", 32, "", g_MqRef.RESX["BUTTON_CLOSE"], 90);</script>
			</td>
		</tr>
		</tbody> 
	</table>
	
</body>
</html>