1.如图
2.前台代码
<td background="${ctx }/root/images/l.gif" style="width:8px; background-repeat:repeat-y; "> </td>
<td>
<form id="searchForm" name="searchForm" action="">
<table class="tab" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="11%" align="right"><label style="">供应商ID:</label></td>
<td align="left" width="15%"><input type="text" name="SUPPLY_ID" id="SUPPLY_ID" size="10" value="${mainstock.SUPPLY_ID}" class="input_text" readonly="readonly"/>
<input type="hidden" name="IN_STORE_TYPE" id="IN_STORE_TYPE" size="10" value="${mainstock.IN_STORE_TYPE}" class="input_text" />
<input type="hidden" name="SALE_NO" id="SALE_NO" size="10" value="${mainstock.IN_STORE_M_ID}" class="input_text" />
<input type="hidden" name="IN_STORE_ACOUNT" id="IN_STORE_ACOUNT" size="10" value="${mainstock.IN_STORE_ACOUNT}" class="input_text" />
<input type="hidden" name="COST_ACCOUNT" id="COST_ACCOUNT" size="10" value="${mainstock.COST_ACCOUNT}" class="input_text" />
<input type="hidden" name="BILL_TYPE" id="BILL_TYPE" size="10" value="${mainstock.BILL_TYPE}" class="input_text" />
</td>
<td align="right" width="11%"><label style="">退货日期:</label></td>
<td align="left" width="17%"><input type="text" name="orlename6" size="10" value="" class="input_text"/>
<img src="${ctx }/root/images/sy_time.gif" width="16" height="18" alt=""/></td>
<td width="7%" align="right"><label style="">退货单号:</label></td>
<td width="15%" align="left"><input type="text" name="IN_STORE_NO" id="IN_STORE_NO" size="10" value="${mainstock.IN_STORE_NO}" class="input_text"/></td>
</tr>
<tr>
<td align="right"><label style="">仓库人员:</label></td>
<td align="left" width="15%"><input type="text" name="orlename5" size="10" value="超级管理员" class="input_text"/></td>
<td align="right" width="11%"><label style="">入库单号:</label></td>
<td align="left" width="17%"><input type="text" name="orlename5" size="10" value="I0905210005" class="input_text" readonly="readonly"/></td>
<td align="right" width="11%"><label style="">退货税率:</label></td>
<td align="left" width="17%"><input type="text" name="TAXRATE" id="TAXRATE" size="10" value="${mainstock.TAXRATE}" class="input_text" readonly="readonly"/></td>
</tr>
<tr>
<td align="right" colspan="12">
<hr/>
<input type="button" value="保存" οnclick="sa()"/>
</td>
</tr>
</table>
</form>
</td>
<td style="width:8px; background-repeat:repeat-y; background-image:url(${ctx }/root/images/r.gif); background-position:right;"> </td>
</tr>
<!-- 条件查询 tr 结束-->
<tr>
<td background="${ctx }/root/images/l.gif" style="width:8px; background-repeat:repeat-y; "> </td>
<td> </td>
<td style="width:8px; background-repeat:repeat-y; background-image:url(${ctx }/root/images/r.gif); background-position:right;"> </td>
</tr>
<!-- 条件查询 tr 开始-->
<tr>
<td background="${ctx }/root/images/l.gif" style="width:8px; background-repeat:repeat-y; "> </td>
<td>
<div style=" width:100%; overflow-y: auto; height: 280px; margin-top: 5px; overflow-x: auto;" >
<table width="150%" cellpadding="0" cellspacing="0" class="tablel2" style=" margin-top: 0px;">
<thead id="listTitle" >
<tr class="tittle_bg">
<td align="center">物料图号</td>
<td align="center" >物料名称</td>
<td align="center">单位</td>
<td align="center">入库数量</td>
<td align="center">库存数量</td>
<td align="center">单据可退数量</td>
<td align="center">退货数量+</td>
<td align="center">税率</td>
<td align="center">入库单价(含税)</td>
<td align="center">入库单价(不含税)</td>
<td align="center">可退金额(含税)</td>
<td align="center">可退金额(不含税)</td>
<td align="center">退货金额(含税)</td>
<td align="center">退货金额(不含税)</td>
<td align="center">仓库名称</td>
<td align="center">仓库编号</td>
</tr>
</thead>
<tbody id="listDatas" >
<c:forEach items="${detaillist}" var="item" varStatus="status">
<tr>
<td align="center">${item.MATERIAL_CODE}</td>
<td align="center">${item.MATERIAL_NAME}</td>
<td align="center">${item.MATERIAL_UNIT}</td>
<td align="center">${item.AMOUNTS}</td>
<td align="center">${item.EFF_STOCK_COUNT}</td>
<td align="center">${item.AMOUNTS}</td>
<td align="center"><input type="text" name="AMOUNTS" /></td>
<td align="center">${item.TAXRATE}
<input type="hidden" name="M_ID" value="${item.M_ID}">
<input type="hidden" name="LOCATION_ID" value="${item.LOCATION_ID}">
<input type="hidden" name="STORE_ID" value="${item.STORE_ID}">
<input type="hidden" name="IN_STORE_PRICE" value="${item.IN_STORE_PRICE}">
<input type="hidden" name="COST_ACCOUNT" value="${item.COST_ACCOUNT}">
</td>
<td align="center">${item.SALE_PRICE}<input type="hidden" name="SALE_PRICE" value="${item.SALE_PRICE}" id="SALE_PRICE" ></td>
<td align="center">${item.SALE_PRICE*(1-item.TAXRATE)}</td>
<td align="center"></td>
<td align="center">}</td>
<td align="center"></td>
<td align="center"> </td>
<td align="center">${item.STOCK_NAME}</td>
<td align="center">${item.STOCK_ID}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</td>
3.js代码
<script type="text/javascript">
$(function(){
$("input[name='AMOUNTS']").each(function(){
//可退数量
var leastcount=$(this).parent().prev().text();
//单价
var dj=$("#SALE_PRICE").val();
var ktje=leastcount*dj;
var keje=$(this).parent().next().next().next().next();
keje.empty();
keje.append(ktje);
//税率
var TAXRATE=$("#TAXRATE").val();
//可退金额(不含税)
var ktjent=leastcount*dj*(1-TAXRATE);
var kejent=$(this).parent().next().next().next().next().next();
kejent.empty();
kejent.append(ktjent);
});
$("input[name='AMOUNTS']").blur(function(){
if(!isNaN($(this).val())){
var count=parseInt($(this).val(),10);
//可退数量
var leastcount=parseInt($(this).parent().prev().text(),10);
if(leastcount<count){
alert("不能大于可退数量");
$(this).attr("value", "");
$(this).focus();
return;
}
//单价
var dj=$("#SALE_PRICE").val();
var thje=dj*count;
var thjea=$(this).parent().next().next().next().next().next().next();
thjea.empty();
thjea.append(thje);
//税率
var TAXRATE=$("#TAXRATE").val();
var thjet=dj*count*(1-TAXRATE);
var thjeta=$(this).parent().next().next().next().next().next().next().next();
thjeta.empty();
thjeta.append(thjet);
}else{
alert("请填写数字!");
}
});
});
function sa(){
var IN_STORE_NO=$("#IN_STORE_NO").val();
var IN_STORE_TYPE=$("#IN_STORE_TYPE").val();
var SUPPLY_ID=$("#SUPPLY_ID").val();
var SALE_NO=$("#SALE_NO").val();
var TAXRATE=$("#TAXRATE").val();
var IN_STORE_ACOUNT=$("#IN_STORE_ACOUNT").val();
var COST_ACCOUNT=$("#COST_ACCOUNT").val();
var BILL_TYPE=$("#BILL_TYPE").val();
var list=[];
var getAll= $("input[name='AMOUNTS']").val();
var count=0;
var size=$("input[name='AMOUNTS']").size();
$("input[name='AMOUNTS']").each(function(){
if($(this).val()==''){
alert("请输入退货数量!");
$(this).focus();
return;
}else{
//退货数量
var AMOUNTS=$(this).val();
var M_ID=$(this).parent().next().children(":input[name='M_ID']").val();
var LOCATION_ID=$(this).parent().next().children(":input[name='LOCATION_ID']").val();
var STORE_ID=$(this).parent().next().children(":input[name='STORE_ID']").val();
var IN_STORE_PRICE=$(this).parent().next().children(":input[name='IN_STORE_PRICE']").val();
var COST_ACCOUNT=$(this).parent().next().children(":input[name='COST_ACCOUNT']").val();
var IN_STORE_ACCOUNT=AMOUNTS*IN_STORE_PRICE;
alert(IN_STORE_ACCOUNT+","+M_ID+","+LOCATION_ID+","+STORE_ID+","+IN_STORE_PRICE+","+COST_ACCOUNT);
//list.push('{"AMOUNTS":"'+$(this).val()+'","SALE_PRICE":"'+SALE_PRICE+'"}');
list.push('{"AMOUNTS":"'+$(this).val()+'","IN_STORE_ACCOUNT":"'+IN_STORE_ACCOUNT+'","M_ID":"'+M_ID+'","LOCATION_ID":"'+LOCATION_ID+'","STORE_ID":"'+STORE_ID+'","IN_STORE_PRICE":"'+IN_STORE_PRICE+'","COST_ACCOUNT":"'+COST_ACCOUNT+'"}');
count++;
}
})
if(count==size){
var param='jsonParams={"list":['+list.join(",")+'],"IN_STORE_NO":"'+IN_STORE_NO+'","IN_STORE_TYPE":"'+IN_STORE_TYPE+'","SUPPLY_ID":"'+SUPPLY_ID+'","SALE_NO":"'+SALE_NO+'","COST_ACCOUNT":"'+COST_ACCOUNT+'","TAXRATE":"'+TAXRATE+'","BILL_TYPE":"'+BILL_TYPE+'","IN_STORE_ACOUNT":"'+IN_STORE_ACOUNT+'"}';
//alert(param);
var url = '${ctx}/painstore/painstoreAction!save.action';
$.post(url, param, function(res){
if(res=='1'){
alert("新增成功!");
}else{
alert("新增失败!");
}
});
}
}
</script>
4.java代码
/**
* 入库退货保存
*/
public void save() {
Map<Object, Object> map = super.generateMapFromJsonForPage(this
.getJsonParams());
List<Object> params = new ArrayList<Object>();
// 获取传来的值(这五个对应报废单表)
// 得到报废主表的最新id
StringBuffer sqlnum = new StringBuffer();
List<Map<Object, Object>> list = JsonUtils
.getListFormJson((List<JSONObject>) map.get("list"));
List<String[]> paramItems = new ArrayList<String[]>();
String sql = "";
String sql2 = "";
Map<String, Object> numMap = null;
String rel = "1";
try {
//新入库单号
String IN_STORE_NO = this.getCoding("RKTH");
String IN_STORE_TYPE = (String) map.get("IN_STORE_TYPE");
String SUPPLY_ID = (String) map.get("SUPPLY_ID");
//原入库单号ID
String SALE_NO = (String) map.get("SALE_NO");
String TAXRATE = (String) map.get("TAXRATE");
String IN_STORE_ACOUNT = (String) map.get("IN_STORE_ACOUNT");
String COST_ACCOUNT = (String) map.get("COST_ACCOUNT");
this.beginSession();
this.beginTransaction();
//insert into t_pa_in_stock_m values(seq_t_pa_in_stock_m.nextval,'dh',516,11,11,11,sysdate,0.1,1000,1000,sysdate,null,null,null,1,1,null,1)
sql = "insert into t_pa_in_stock_m values(seq_t_pa_in_stock_m.nextval,?,?,?,?,to_number(?),sysdate,?,?,?,sysdate,null,null,null,1,0,null,2)";
params.add(IN_STORE_NO);
params.add(IN_STORE_TYPE);
params.add(SUPPLY_ID);
params.add(SALE_NO);
params.add(this.getCurrentUserID());
//params.add(1);
params.add(TAXRATE);
params.add(IN_STORE_ACOUNT);
params.add(COST_ACCOUNT);
this.insert(sql.toString(), params);
//插入附表
// 新增报废明细表
if (list != null & list.size() != 0) {
// 得到报废表的下一个id以便插入
sqlnum
.append("select seq_t_pa_in_stock_m.currval as C from dual");
// Integer stock_id = 0;
numMap = this.queryObject(sqlnum.toString());
String Id_Str = numMap.get("C").toString();
//insert into T_PA_IN_STOCK_D values(seq_t_pa_in_stock_d.nextval,2,3,4,5,6,100,200,300,'admin',sysdate,null,null,1,0,null)
sql2 = "insert into T_PA_IN_STOCK_D values(seq_t_pa_in_stock_d.nextval,?,?,?,?,?,?,?,?,?,sysdate,null,null,1,0,null)";
// 新增入库退货明细表
for (Map<Object, Object> item : list) {
String[] tmp = new String[9];
tmp[0] = Id_Str;
tmp[1] = (null == item.get("M_ID") ? "" : item.get(
"M_ID").toString());
tmp[2] = (null == item.get("LOCATION_ID") ? "" : item.get(
"LOCATION_ID").toString());
tmp[3] = (null == item.get("STORE_ID") ? "" : item.get(
"STORE_ID").toString());
tmp[4] = (null == item.get("AMOUNTS") ? "" : item.get(
"AMOUNTS").toString());
tmp[5] = (null == item.get("IN_STORE_PRICE") ? "" : item.get(
"IN_STORE_PRICE").toString());
tmp[6] = (null == item.get("IN_STORE_ACCOUNT") ? "" : item.get(
"IN_STORE_ACCOUNT").toString());
tmp[7] = (null == item.get("COST_ACCOUNT") ? "" : item.get(
"COST_ACCOUNT").toString());
tmp[8]=this.getCurrentLoginName();
paramItems.add(tmp);
}
this.operateItemBatch(sql2, paramItems);
}
this.submit();
} catch (Exception e) {
rel = "4";
this.rollback();
e.printStackTrace();
} finally {
this.close();
Struts2Utils.renderText(rel);
}
}