报销流程的报销单

来源:互联网 发布:平均分配算法 编辑:程序博客网 时间:2024/06/02 14:41

这是给房地产项目做报销流程时的填报报销单。报销单的所用到的知识有:

利用jquery计算合计值,给另一个文本框直接赋值,利用script增减行信息,显示和隐藏下拉框,利用json向后台传递信息。



jsp页面是:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/jsp/public/common.jspf"%>
<html>
<head>
<title>报销信息</title>
<script type="text/javascript">
 function department(){
   $("#projectid").css('display','block');//显示部门信息
   $("#other").attr('checked',true);//选中其他部门按钮
   $("#benbumen").attr('checked',false);//不选中本部门按钮
 $.ajax({type:"post",
         url:"<%=request.getContextPath()%>/reinbursementAction_getdepartment.action",
dataType : "json",
timeout : 4000,
success : function(data) {
var obj = eval(data);//将string转化成ajax可识别的对象
$("#projectid").empty();
for ( var i = 0; i < obj.length; i++) {
$("#projectid").append(
"<option value="+obj[i].id+">"
+ obj[i].name + "</option>");
}
},
error : function() {
alert("与服务器连接超时...");
}
});
}
</script>
<script type="text/javascript">
num = 1;//记录行数
function add() {//增加行
var tr = document.createElement('tr');
var td = document.createElement('td');


td.innerHTML = "<td ><input type='text' id='mc"+num+"' name='addList["+num+"].mc'></td>";
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = "<td ><input type='text' id='sl"+num+"' name='addList["+num+"].sl'></td>";
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = "<td ><input type='text' id='dj"+num+"' name='addList["+num+"].dj' onblur=\"jisuanzhi('"+num+"')\"></td>";
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = "<td ><input type='text' id='hj"+num+"' name='addList["+num+"].hj' readonly='readonly'></td>";
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = "<td ><input type='text' id='bz"+num+"' name='addList["+num+"].bz'></td>";
tr.appendChild(td);
var dct = document.getElementById("table");
dct.tBodies[0].appendChild(tr);
++num;
};
function del() {//删除一行
var i = document.getElementById("table").rows.length;
if (i < 3) {
alert("不能再删除了!!");
} else {
num--;
document.getElementById("table").deleteRow(i - 1);
}
};


function sum() {//计算总金额
var zhjje = 0;
for ( var i = 1; i <= num; i++) {
var hj = document.getElementById("hj" + (i - 1) + "").value;//取出每行合计的值
zhjje = parseFloat(zhjje) +parseFloat(hj);
}
zhjje=Math.round(zhjje*100)/100;
$("#zhj").val(zhjje);
}
</script>
<script type="text/javascript">
window.onload = function() {//开始加载时将本部门选中,其他部门不选中(根据的是id号而不是name号)
$("#benbumen").attr('checked', true);
$("#projectid").css('display', 'none');//将部门信息不展示
};
function qihuan() {
$("#projectid").css('display', 'none');
$("#other").attr('checked', false);
$("#benbumen").attr('checked', true);
}
</script>
<script type="text/javascript">
function jisuanzhi(num) {
var sl = document.getElementById("sl" + num + "").value;
var dj = document.getElementById("dj" + num + "").value;
if (isNaN(sl)) {
alert("'数量'的格式不对,应该输入数字!");

if (isNaN(dj)) {
alert("'单价'的格式不对,应该输入数字!");

if(!isNaN(sl)&&!isNaN(dj)) {
$("#hj"+num+"").val(Math.round(sl*dj*100)/100);
}
}
</script>
<style type="text/css">
.tab {
border: none;
border-collapse: collapse;
}


td {
height: 28px;
border: 1px solid #b5d6e6;
text-align: center;
}
</style>
</head>
<body>


<!-- 标题显示 -->
<div id="Title_bar">
<div id="Title_bar_Head">
<div id="Title_Head"></div>
<div id="Title">
<!--页面标题-->
<img border="0" width="13" height="13"
src="${pageContext.request.contextPath}/style/images/title_arrow.gif" />
报销申请信息
</div>
<div id="Title_End"></div>
</div>
</div>


<!--显示表单内容-->
<div id=MainArea>
<div class="ItemBlock_Title1" style=" margin-left:50px;">
<!-- 信息说明 -->
<div class="ItemBlock_Title1">
<img border="0" width="4" height="7"src="${pageContext.request.contextPath}/style/blue/images/item_point.gif" />
申请信息
</div>
</div>
<div class="ItemBlock" style=" margin-left:-50px; ">
<s:form action="flowAction_normalreimbursement" method="post" id="myForm">
<table style=" border:none; border-collapse:collapse; width:100%;">
<tr>
<td style="height:28px; border:1px solid #b5d6e6; text-align:center;">报销依据</td>
<td style="height:26px; border:1px solid #b5d6e6; text-align:center;">
<input type="radio" id="benbumen" onclick="qihuan()" />本部门 <input
type="radio" id="other" onclick="department()">其他部门
&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td style="height:26px; border:1px solid #b5d6e6; text-align:center;" align="center">
 <select id="projectid" name="projectid"
style="width: 120px;" >
<option></option> 
</select> 
</td>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;">知情人/经办人</td>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;">
<input type="text" name="jbr" /></td>
</tr>
<tr>
<td colspan="5"
style="height:28px; border:1px solid #b5d6e6; text-align:center;">
<table id="table"
style=" border:none; border-collapse:collapse; width:100%;">
<tr>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;">名称</td>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;">数量</td>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;">单价</td>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;">合计</td>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;">
备注</td>
</tr>
<tr>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;"><input
type="text" name="addList[0].mc" id="mc0" />
</td>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;"><input
type="text" name="addList[0].sl" id="sl0" />
</td>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;"><input
type="text" name="addList[0].dj" id="dj0" onblur="jisuanzhi('0')">
</td>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;"><input
type="text" name="addList[0].hj" id="hj0" readonly="readonly">
</td>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;"><input
type="text" name="addList[0].bz" id="bz0">
</td>
</tr>
<tr>
</tr>
</table></td>
</tr>


<tr>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;"
colspan="1">金额合计:<input type="text" id="zhj" name="zhj"
readonly="readonly" onclick="sum()" /></td>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;"
colspan="1">实际金额:<input type="text" id="reallypay" name="reallypay"/></td>
<td
style="height:28px; border:1px solid #b5d6e6; text-align:center;"
colspan="3"><input type="button" id="bt1" value="增加行"
onclick="add()" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" id="bt1" value="减少行"
onclick="del()" /></td>
</tr>


</table>
            <div id="InputDetailBar">
           <input type="image" src="${pageContext.request.contextPath}/style/blue/images/button/submit.PNG"/>
           <a href="javascript:history.go(-1);"><img src="${pageContext.request.contextPath}/style/images/goBack.png"/></a>
          </div>
</s:form>
</div>
</div>
</body>
</html>


contrallor层内容是:


package cn.itcast.oa.view.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.jbpm.api.ProcessDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.itcast.oa.base.BaseAction;
import cn.itcast.oa.domain.Department;
import cn.itcast.oa.domain.PrintData;
import cn.itcast.oa.domain.Role;
import cn.itcast.oa.domain.User;
import com.opensymphony.xwork2.ActionContext;

@SuppressWarnings("serial")
@Controller
@Scope("prototype")
public class ReinbursementAction extends BaseAction{
private String printda;//是否打印装订  
    private String money;//是否现金或转账  
    private String account;//是否记账
    private String timestamp;//标记,和报销关联
public String getPrintda() {
return printda;
}
public void setPrintda(String printda) {
this.printda = printda;
}
public String getMoney() {
return money;
}
public void setMoney(String money) {
this.money = money;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
private HttpServletResponse reponse;
public HttpServletResponse getReponse() {
return reponse;
}
public void setReponse(HttpServletResponse reponse) {
this.reponse = reponse;
}
public String save() throws Exception{
PrintData printData=new PrintData();
printData=normalreimbursementService.findPrintData(timestamp);
printData.setPrintda(printda);
printData.setAccount(account);
printData.setMoney(money);
printData.setTimestamp(printData.getTimestamp());
normalreimbursementService.upprintData(printData);
return "toMyTaskList";
}
public void getdepartment()throws Exception{
reponse = ServletActionContext.getResponse();
reponse.setCharacterEncoding("UTF-8");// 指定返回值的编码方式,必须放在out声明之前
StringBuffer sb = new StringBuffer();
sb.append("[");
List<Department> departmentlist=departmentService.findAll();
for(Department dep:departmentlist){
sb.append("{\"id\":"+dep.getId()+",\"name\":\""+dep.getName()+"\"},");
}
sb.deleteCharAt(sb.length()-1).append("]");
String depart=sb.toString();
System.out.println(depart);
PrintWriter out = null;
reponse.setContentType("text/javascript;charset=UTF-8");
try {
out = reponse.getWriter();
out.print(sb);
out.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
out.close();
}

}
public String reinbursementaddUI() throws Exception {
//查找登录人员的角色有没有员工或部门主管的角色
User user=getCurrentUser();
Set<Role> userolelist = user.getRoles();
Iterator<Role> it = userolelist.iterator();
boolean flag = false;
while (it.hasNext()) {
Role str = it.next();
if (str.getName() .contains("员工")||str.getName().contains("主管")) {
flag = true;
break;
}
}
if(flag == true){
// 准备数据
List<ProcessDefinition> processDefinitionList = processDefinitionService.findAllLatestVersions();
ActionContext.getContext().put("processDefinitionList", processDefinitionList);
return "reinbursementaddUI";

}

else{
return "errorUI";
}
}
}



0 0
原创粉丝点击