<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
<head>
<base href="<%=basePath%>" />
<sx:head extraLocales="en-us" />
<title>进货单</title>
<link rel="stylesheet" href="css/main.css" type="text/css" />
<script language="javascript" src="script/main.js"></script>
<script type='text/javascript' src='dwr/interface/stockinAction.js'></script>
<script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/util.js'></script>

</head>
<body>
<script type="text/javascript">
	var textPrice;
	var textMoney;
	var textAmount;
	var hiddenPrice;
	var hiddenMoney;
	var textCode;
	var textMerchandise;
	var codeChk=false;
	

	function init() {
		textPrice = document.getElementById("price");
		textCode = document.getElementById("code");
		textMoney = document.getElementById("money");
		textAmount = document.getElementById("amount");
		textMerchandise = document.getElementById("merchandise");
		hiddenPrice = document.getElementById("hiddenPrice");
		hiddenMoney = document.getElementById("hiddenMoney");
		textCode.focus();

	}
	
	function out_merchandise() {
		var chk = false;
		if (trimString(textMerchandise.value) != '') {
			stockinAction.findMerchandisePriceById(textMerchandise.value,
					showMerchandisePrice);
			show_message("msg_merchandise", "1", '输入正确!');
			chk = true;
		} else {
			show_message("msg_merchandise", "0", '货物名称不能为空!');
		}
		return chk;
	}
	function showMerchandisePrice(price) {
		textPrice.value = price;
		hiddenPrice.value = price;
		var exp = /[^\d]/;
		if ((!isNaN(price)) && (!exp.test(textAmount.value))) {
			textMoney.value = textAmount.value * price;
			hiddenMoney.value = textAmount.value * price;
		}
	}

	function out_amount() {
		var chk = false;
		var exp = /[^\d]/;
		if (!exp.test(textAmount.value) && textAmount.value > 0 && textAmount.value<999) {
			textMoney.value = textAmount.value * textPrice.value;
			hiddenMoney.value = textAmount.value * textPrice.value;
			show_message("msg_amount", "1", '输入正确!');
			chk = true;
		} else {
			show_message('msg_amount', '0', '进货数量必须输入大于零小于999的整型数字形式');

		}
		return chk;
	}
	function out_code() {
		codeChk = false;
		if (trimString(textCode.value).length > 0
				&& trimString(textCode.value).length < 12) {
			stockinAction.findStockinByCode(textCode.value, function(ret) {
				if (ret > 0) {
					show_message("msg_code", "0", '输入的进货单编号[' + textCode.value
							+ ']重复请重新输入!');
					codeChk = false;
					//textCode.focus();
					//textCode.select();
				} else {
					show_message("msg_code", "1", '输入正确!');
					codeChk = true;
				}
			});
		} else {
			show_message('msg_code', '0', '进货单编号不能为空且不能超过11位长度!');
			codeChk = false;
		}

	}
	
	function formSubmit() {
		var chk = false;
		var chkRetMerchandise = out_merchandise();
		
		var chkRetAmount = out_amount();
		var chkRetStockdate = out_pickerDate('stockdate', 'msg_stockdate',
				'进货日期不能为空!');			
			
		var chkRetEmployee = out_chkEmpty('employee', 'msg_employee', '经手人不能为空!');
		var chkRetClient = out_chkEmpty('client', 'msg_client', '供应商不能为空!');
		if (codeChk&&chkRetMerchandise && chkRetAmount && chkRetEmployee && chkRetClient && chkRetStockdate) {
			chk = true;
		}
		return chk;
	}
	dojo.event.topic.subscribe("/value", function(textEntered, date, widget) {

		out_pickerDate('stockdate', 'msg_stockdate', '进货日期不能为空!');

	});

	window.onload = init;
</script>
<p></p>
<p><font style="font-size: 10pt;">进货管理->进货单->新增</font></p>
<s:form action="stockinAction" method="post" theme="simple"
	onsubmit="return formSubmit();">
	<s:hidden name="stockin.price" id="hiddenPrice"></s:hidden>
	<s:hidden name="stockin.money" id="hiddenMoney"></s:hidden>
	<p></p>
	<table border="0" cellpadding="1" cellspacing="1" width="95%">
		<tr>
			<td align="right" width="7%" nowrap="true">进货单编号</td>
			<td width="16%"><s:textfield name="stockin.code"
				cssClass="TextInput" id="code"
				onFocus="show_message('msg_code','2','请输入进货单编号');"
				onBlur="out_code()"></s:textfield>
			<DIV style="DISPLAY: show" id="msg_code" class="box_div_right">&nbsp;</DIV>
			</td>
			<td align="right" width="7%" nowrap="true">货物名称</td>
			<td width="16%"><s:select list="merchandises"
				name="stockin.merchandise.id" listKey="id" listValue="name"
				emptyOption="true" theme="simple"
				onFocus="show_message('msg_merchandise','2','请选择货物名称')"
				onBlur="out_merchandise()" id="merchandise"></s:select>
			<DIV style="DISPLAY: show" id="msg_merchandise" class="box_div_right">&nbsp;</DIV>
			</td>
			<td align="right" width="6%">进货数量</td>
			<td width="16%"><s:textfield name="stockin.amount"
				cssClass="TextInput" id="amount"
				onFocus="show_message('msg_amount','2','请输入进货数量')"
				onBlur="out_amount()"></s:textfield>
			<DIV style="DISPLAY: show" id="msg_amount" class="box_div_right">&nbsp;</DIV>
			</td>
			<td width="6%">&nbsp;</td>
		</tr>
		<tr>
			<td align="right" width="7%" nowrap="true">进货日期</td>
			<td width="16%"><sx:datetimepicker label=""
				name="stockin.stockindate" displayFormat="yyyy-MM-dd"
				language="en-us" type="date" id="stockdate" required="true" valueNotifyTopics="/value" />
			<DIV style="DISPLAY: show" id="msg_stockdate" class="box_div_right">&nbsp;</DIV>
			</td>
			<td align="right" width="7%" nowrap="true">经手人</td>
			<td width="16%"><s:select list="employees"
				name="stockin.employee.id" listKey="id" listValue="name"
				emptyOption="true" theme="simple" id="employee"
				onFocus="show_message('msg_employee','2','请选择经手人名称!')"
				onBlur="out_chkEmpty('employee','msg_employee','经手人不能为空!')"></s:select>
			<DIV style="DISPLAY: show" id="msg_employee" class="box_div_right">&nbsp;</DIV>
			</td>
			<td align="right">供应商</td>
			<td><s:select list="clients" name="stockin.client.id"
				listKey="id" listValue="name" emptyOption="true" theme="simple"
				id="client" onFocus="show_message('msg_client','2','请选择供应商名称!')"
				onBlur="out_chkEmpty('client','msg_client','供应商不能为空!')"></s:select>
			<DIV style="DISPLAY: show" id="msg_client" class="box_div_right">&nbsp;</DIV>
			</td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td align="right" width="7%" nowrap="true">货物单价（元）</td>
			<td width="16%"><s:textfield id="price" name="stockin.price"
				cssClass="TextInput" disabled="true"></s:textfield></td>
			<td align="right" width="7%" nowrap="true">货物金额（元）</td>
			<td width="16%"><s:textfield name="money" cssClass="TextInput"
				disabled="true" id="stockin.money"></s:textfield></td>
			<td align="right">&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
		</tr>
	</table>

	<p></p>
	<div style="margin-left: 30px; margin-right: 0px">
	<table border="0" cellpadding="0" cellspacing="0" width="95%">
		<tr>
			<td width="10%"><s:submit value="保存" cssClass="BtnAction"
				method="saveStockin"></s:submit></td>
			<td width="10%"><input type="button" class="BtnAction"
				value="返回" onClick="history.go(-1);"></td>
			<td width="80%">&nbsp;</td>
		</tr>
	</table>
	</div>
</s:form>
</body>
</html>