mapper
点击查看代码
package com.Moonbeams.mapper;import com.Moonbeams.pojo.BusinessApply;
import com.Moonbeams.pojo.DepartmentExpense;
import com.Moonbeams.pojo.Reimburse;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;import java.util.List;
import java.util.Map;public interface ReimburseMapper {/*** 报销表申请* @param reimburse*/@Insert("INSERT INTO ter_reimburse (id, name, position, yearsold, department, destination, departure_date, return_date, reason, start_fare, return_fare, food_allowance, local_trans, accommodation, total_amount, schedule, schedule_reason,applytime) " +"VALUES (#{id}, #{name}, #{position}, #{yearsold}, #{department}, #{destination}, #{departureDate}, #{returnDate}, #{reason}, #{startFare}, #{returnFare}, #{foodAllowance}, #{localTrans}, #{accommodation}, #{totalAmount}, #{schedule}, #{scheduleReason},#{applyTime})")@ResultMap("ReimburseResultMap")void insertReimbursement(Reimburse reimburse);@Update("update ter_reimburse set yearsold = #{yearsold},destination = #{destination},departure_date = #{departureDate},return_date = #{returnDate},reason = #{reason},start_fare = #{startFare},return_fare = #{returnFare},food_allowance = #{foodAllowance},local_trans = #{localTrans},accommodation = #{accommodation},total_amount = #{totalAmount},schedule = #{schedule},schedule_reason = #{scheduleReason},applytime = #{applyTime} Where id = #{id} AND (schedule = '未审批'or schedule = '退回')")@ResultMap("ReimburseResultMap")void updateReimbursement(Reimburse reimburse);/*** 根据ID查询报销表* @param id* @return*/@Select("SELECT * FROM ter_reimburse WHERE id = #{id}")@ResultMap("ReimburseResultMap")Reimburse selectReimbursementById(String id);/*** 报销列表* @return*/@Select("SELECT * FROM ter_reimburse")@ResultMap("ReimburseResultMap")List<Reimburse> selectAllReimbursement();/*** 根据状态搜索未通过报销单* @return*/@Select("SELECT *from ter_reimburse WHERE (schedule = '未审批' or schedule = '部门审批通过')")@ResultMap("ReimburseResultMap")List<Reimburse> getPendingReimbursement();/*** 更新报销表状态* @param reimburse*/@Update("UPDATE ter_reimburse SET schedule = #{schedule}, schedule_reason = #{scheduleReason} WHERE id = #{id}")void updateReimbursementStatus(Reimburse reimburse);/*** 获取当前用户所有报销单* @param name* @return*/@Select("SELECT * FROM ter_reimburse WHERE name = #{name}")@ResultMap("ReimburseResultMap")List<Reimburse> getReimbursementsByUser(String name);/*** 获取当前部门提交的所有报销单* @param department* @return*/@Select("SELECT * FROM ter_reimburse where department = #{department}")@ResultMap("ReimburseResultMap")List<Reimburse> getReimbursementsByDepartment(String department);@ResultMap("ReimburseResultMap")List<Reimburse> searchApprovedReimbursements(@Param("name") String name, @Param("department") String department, @Param("totalAmountGreaterThan") Integer totalAmountGreaterThan);@Select({"SELECT department AS departmentName, SUM(total_amount) AS totalAmount FROM ter_reimburse WHERE YEAR(applytime) = YEAR(CURDATE()) GROUP BY department"})List<DepartmentExpense> getAnnualDepartmentExpenses();}
点击查看代码
package com.Moonbeams.mapper;import com.Moonbeams.pojo.BusinessApply;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;import java.util.List;public interface BusinessApplyMapper {/*** 提交出差申请* @param businessApply*/@Insert("INSERT INTO ter_businessapply (id, name, department, position, destination, departure_date, return_date, type, type_content, reason, state, state_reason,applytime) " +"VALUES (#{id}, #{name}, #{department}, #{position}, #{destination}, #{departureDate}, #{returnDate}, #{type}, #{typeContent}, #{reason}, #{state}, #{stateReason},#{applytime})")void insertBusinessApply(BusinessApply businessApply);/*** 根据id查询出差表* @param id* @return*/@Select("SELECT * FROM ter_businessapply WHERE id = #{id}")@ResultMap("BusinessApplyResultMap")BusinessApply getBusinessApplyById(String id);@Select("select * from ter_businessapply")@ResultMap("BusinessApplyResultMap")BusinessApply selectAllBusinessAppply(String id);/*** 更新出差表* @param businessApply*/@Update("UPDATE ter_businessapply SET destination = #{destination}, departure_date = #{departureDate}, return_date = #{returnDate}, type = #{type}, type_content = #{typeContent}, reason = #{reason} ,applytime = #{applytime} ,state = #{state},state_reason = #{stateReason} Where id = #{id} AND (state = '未审批'or state = '退回')")void updateBusinessApply(BusinessApply businessApply);@Update("update ter_businessapply set state = #{state},state_reason = #{stateReason} WHERE id = #{id}")@ResultMap("BusinessApplyResultMap")void updateBusinessDate(BusinessApply businessApply);/*** 撤回出差表* @param id*/@Delete("DELETE FROM ter_businessapply WHERE id = #{id} AND state = '未审批'")void deleteBusinessApply(String id);/***根据状态搜索未审批出差表* @return*/@Select("SELECT * FROM ter_businessapply WHERE state = '未审批'")@ResultMap("BusinessApplyResultMap")List<BusinessApply> getPendingApplications();/*** 获取当前用户的所有出差申请* @param name* @return*/@Select("SELECT * FROM ter_businessapply WHERE name = #{name} ORDER BY applytime DESC")@ResultMap("BusinessApplyResultMap")List<BusinessApply> getApplicationsByUser(String name);/*** 获取当前部门的所有出差申请* @param department* @return*/@Select("SELECT * FROM ter_businessapply WHERE department = #{department}")@ResultMap("BusinessApplyResultMap")List<BusinessApply> getApplicationsByDepartment(String department);
}
点击查看代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.Moonbeams.mapper.BusinessApplyMapper"><resultMap id="BusinessApplyResultMap" type="businessApply"><result column="id" property="id"/><result column="name" property="name"/><result column="department" property="department"/><result column="position" property="position"/><result column="destination" property="destination"/><result column="departure_date" property="departureDate"/><result column="return_date" property="returnDate"/><result column="type" property="type"/><result column="type_content" property="typeContent"/><result column="reason" property="reason"/><result column="state" property="state"/><result column="state_reason" property="stateReason"/><result column="applytime" property="applytime"/></resultMap></mapper>
点击查看代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.Moonbeams.mapper.ReimburseMapper"><resultMap id="ReimburseResultMap" type="reimburse"><result column="id" property="id"/><result column="name" property="name"/><result column="position" property="position"/><result column="yearsold" property="yearsold"/><result column="department" property="department"/><result column="destination" property="destination"/><result column="departure_date" property="departureDate"/><result column="return_date" property="returnDate"/><result column="reason" property="reason"/><result column="start_fare" property="startFare"/><result column="return_fare" property="returnFare"/><result column="food_allowance" property="foodAllowance"/><result column="local_trans" property="localTrans"/><result column="accommodation" property="accommodation"/><result column="total_amount" property="totalAmount"/><result column="schedule" property="schedule"/><result column="schedule_reason" property="scheduleReason"/><result column="applytime" property="applyTime"/></resultMap><select id="searchApprovedReimbursements" parameterType="map" resultMap="ReimburseResultMap">SELECT * FROM ter_reimburse WHERE schedule = '财务审核通过'<if test="name != null and name.trim() != ''">AND name LIKE CONCAT('%', #{name}, '%')</if><if test="department != null and department.trim() != ''">AND department LIKE CONCAT('%', #{department}, '%')</if><if test="totalAmountGreaterThan != null">AND total_amount > #{totalAmountGreaterThan}</if></select></mapper>
pojo,service,servlet
点击查看代码
package com.Moonbeams.pojo;public class BusinessApply {private String id;private String name;private String department;private String position;private String destination;private String departureDate;private String returnDate;private String type;private String typeContent;private String reason;private String state;private String stateReason;private String applytime;public String getId() {return id;}public void setId(String id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getDepartment() {return department;}public void setDepartment(String department) {this.department = department;}public String getPosition() {return position;}public void setPosition(String position) {this.position = position;}public String getDestination() {return destination;}public void setDestination(String destination) {this.destination = destination;}public String getDepartureDate() {return departureDate;}public void setDepartureDate(String departureDate) {this.departureDate = departureDate;}public String getReturnDate() {return returnDate;}public void setReturnDate(String returnDate) {this.returnDate = returnDate;}public String getType() {return type;}public void setType(String type) {this.type = type;}public String getTypeContent() {return typeContent;}public void setTypeContent(String typeContent) {this.typeContent = typeContent;}public String getReason() {return reason;}public void setReason(String reason) {this.reason = reason;}public String getState() {return state;}public void setState(String state) {this.state = state;}public String getStateReason() {return stateReason;}public void setStateReason(String stateReason) {this.stateReason = stateReason;}public String getApplytime() {return applytime;}public void setApplytime(String applytime) {this.applytime = applytime;}@Overridepublic String toString() {return "BusinessApply{" +"id='" + id + '\'' +", name='" + name + '\'' +", department='" + department + '\'' +", position='" + position + '\'' +", destination='" + destination + '\'' +", departureDate='" + departureDate + '\'' +", returnDate='" + returnDate + '\'' +", type='" + type + '\'' +", typeContent='" + typeContent + '\'' +", reason='" + reason + '\'' +", state='" + state + '\'' +", stateReason='" + stateReason + '\'' +", applytime='" + applytime + '\'' +'}';}}
点击查看代码
package com.Moonbeams.pojo;public class DepartmentExpense {private String departmentName; // 部门名称private double totalAmount; // 总金额public String getDepartmentName() {return departmentName;}public void setDepartmentName(String departmentName) {this.departmentName = departmentName;}public double getTotalAmount() {return totalAmount;}public void setTotalAmount(double totalAmount) {this.totalAmount = totalAmount;}
}
点击查看代码
package com.Moonbeams.pojo;public class Reimburse {private String id;private String name;private String position;private int yearsold;private String department;private String destination;private String departureDate;private String returnDate;private String reason;private int startFare;private int returnFare;private int foodAllowance;private int localTrans;private int accommodation;private int totalAmount;private String schedule;private String scheduleReason;private String applyTime;public String getId() {return id;}public void setId(String id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPosition() {return position;}public void setPosition(String position) {this.position = position;}public int getYearsold() {return yearsold;}public void setYearsold(int yearsold) {this.yearsold = yearsold;}public String getDepartment() {return department;}public void setDepartment(String department) {this.department = department;}public String getDestination() {return destination;}public void setDestination(String destination) {this.destination = destination;}public String getDepartureDate() {return departureDate;}public void setDepartureDate(String departureDate) {this.departureDate = departureDate;}public String getReturnDate() {return returnDate;}public void setReturnDate(String returnDate) {this.returnDate = returnDate;}public String getReason() {return reason;}public void setReason(String reason) {this.reason = reason;}public int getStartFare() {return startFare;}public void setStartFare(int startFare) {this.startFare = startFare;}public int getReturnFare() {return returnFare;}public void setReturnFare(int returnFare) {this.returnFare = returnFare;}public int getFoodAllowance() {return foodAllowance;}public void setFoodAllowance(int foodAllowance) {this.foodAllowance = foodAllowance;}public int getLocalTrans() {return localTrans;}public void setLocalTrans(int localTrans) {this.localTrans = localTrans;}public int getAccommodation() {return accommodation;}public void setAccommodation(int accommodation) {this.accommodation = accommodation;}public int getTotalAmount() {return totalAmount;}public void setTotalAmount(int totalAmount) {this.totalAmount = totalAmount;}public String getSchedule() {return schedule;}public void setSchedule(String schedule) {this.schedule = schedule;}public String getScheduleReason() {return scheduleReason;}public void setScheduleReason(String scheduleReason) {this.scheduleReason = scheduleReason;}public String getApplyTime() {return applyTime;}public void setApplyTime(String applyTime) {this.applyTime = applyTime;}@Overridepublic String toString() {return "Reimburse{" +"id='" + id + '\'' +", name='" + name + '\'' +", position='" + position + '\'' +", yearsold=" + yearsold +", department='" + department + '\'' +", destination='" + destination + '\'' +", departureDate='" + departureDate + '\'' +", returnDate='" + returnDate + '\'' +", reason='" + reason + '\'' +", startFare=" + startFare +", returnFare=" + returnFare +", foodAllowance=" + foodAllowance +", localTrans=" + localTrans +", accommodation=" + accommodation +", totalAmount=" + totalAmount +", schedule='" + schedule + '\'' +", scheduleReason='" + scheduleReason + '\'' +", applyTime='" + applyTime + '\'' +'}';}}
点击查看代码
package com.Moonbeams.service;import com.Moonbeams.mapper.BusinessApplyMapper;
import com.Moonbeams.mapper.ReimburseMapper;
import com.Moonbeams.pojo.BusinessApply;
import com.Moonbeams.pojo.Reimburse;
import com.Moonbeams.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;import java.util.List;public class BusinessApplyService {private SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();public void createBusinessApply(BusinessApply businessApply) {try (SqlSession session = factory.openSession()) {BusinessApplyMapper mapper = session.getMapper(BusinessApplyMapper.class);mapper.insertBusinessApply(businessApply);session.commit();}}public BusinessApply getBusinessApplyById(String id) {try (SqlSession session = factory.openSession()) {BusinessApplyMapper mapper = session.getMapper(BusinessApplyMapper.class);return mapper.getBusinessApplyById(id);}}public void updateBusinessApply(BusinessApply businessApply) {try (SqlSession session = factory.openSession()) {BusinessApplyMapper mapper = session.getMapper(BusinessApplyMapper.class);mapper.updateBusinessApply(businessApply);session.commit();}}public void deleteBusinessApply(String id) {try (SqlSession session = factory.openSession()) {BusinessApplyMapper mapper = session.getMapper(BusinessApplyMapper.class);mapper.deleteBusinessApply(id);session.commit();}}public List<BusinessApply> getPendingApplications() {try (SqlSession session = factory.openSession()) {BusinessApplyMapper mapper = session.getMapper(BusinessApplyMapper.class);return mapper.getPendingApplications();}}public List<BusinessApply> getApplicationsByUser(String name) {try (SqlSession session = factory.openSession()) {BusinessApplyMapper mapper = session.getMapper(BusinessApplyMapper.class);return mapper.getApplicationsByUser(name);}}public List<BusinessApply> getApplicationsByDepartment(String department) {try (SqlSession session = factory.openSession()) {BusinessApplyMapper mapper = session.getMapper(BusinessApplyMapper.class);return mapper.getApplicationsByDepartment(department);}}public void approveApplication(String id, String approvalReason, String department) {try (SqlSession session = factory.openSession()) {BusinessApplyMapper mapper = session.getMapper(BusinessApplyMapper.class);BusinessApply businessApply = mapper.getBusinessApplyById(id);if (businessApply != null && "未审批".equals(businessApply.getState())&&businessApply.getDepartment().equals(department)) {businessApply.setState("通过");businessApply.setStateReason(approvalReason);mapper.updateBusinessDate(businessApply);session.commit();}}}public void approveApplication2(String id, String approvalReason) {try (SqlSession session = factory.openSession()) {BusinessApplyMapper mapper = session.getMapper(BusinessApplyMapper.class);BusinessApply businessApply = mapper.getBusinessApplyById(id);if (businessApply != null && "未审批".equals(businessApply.getState())) {businessApply.setState("通过");businessApply.setStateReason(approvalReason);mapper.updateBusinessDate(businessApply);session.commit();}}}public void rejectApplication(String id, String rejectionReason,String department) {try (SqlSession session = factory.openSession()) {BusinessApplyMapper mapper = session.getMapper(BusinessApplyMapper.class);BusinessApply businessApply = mapper.getBusinessApplyById(id);if (businessApply != null && "未审批".equals(businessApply.getState()) && businessApply.getDepartment().equals(department)) {businessApply.setState("退回");businessApply.setStateReason(rejectionReason);mapper.updateBusinessDate(businessApply);session.commit();}}}
}
点击查看代码
package com.Moonbeams.service;import com.Moonbeams.mapper.ReimburseMapper;
import com.Moonbeams.pojo.DepartmentExpense;
import com.Moonbeams.pojo.Reimburse;
import com.Moonbeams.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;public class ReimburseService {SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();public void applyForReimbursement(Reimburse reimburse) {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);mapper.insertReimbursement(reimburse);session.commit();}}public Reimburse getReimbursementById(String id) {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);return mapper.selectReimbursementById(id);}}public void updateReimbursement(Reimburse reimburse) {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);mapper.updateReimbursement(reimburse);session.commit();}}public List<Reimburse> getPendingReimbursement() {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);return mapper.getPendingReimbursement();}}public List<Reimburse> searchApprovedReimbursements(String name, String department, Integer totalAmountGreaterThan, String userDepartment, String userPosition) {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);if ("总经理".equals(userPosition)) {return mapper.searchApprovedReimbursements(name, department, totalAmountGreaterThan);} else {return mapper.searchApprovedReimbursements(name, userDepartment, totalAmountGreaterThan);}}}public List<DepartmentExpense> getAnnualDepartmentExpenses() {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);return mapper.getAnnualDepartmentExpenses();}}public List<Reimburse> getAllReimbursements() {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);return mapper.selectAllReimbursement();}}public List<Reimburse> getReimbursementsByUser(String name) {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);return mapper.getReimbursementsByUser(name);}}public List<Reimburse> getReimbursementsByDepartment(String department) {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);return mapper.getReimbursementsByDepartment(department);}}public List<Reimburse> getAllApproveReimbursements() {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);return mapper.selectAllReimbursement();}}public void approveReimbursement(String id, String ScheduleReason, String department) {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);Reimburse reimburse = mapper.selectReimbursementById(id);int money = 10000;if (reimburse != null && "未审批".equals(reimburse.getSchedule()) && reimburse.getDepartment().equals(department) && reimburse.getTotalAmount() <= money) {reimburse.setSchedule("通过");reimburse.setScheduleReason(ScheduleReason);mapper.updateReimbursementStatus(reimburse);session.commit();} else if (reimburse != null && "未审批".equals(reimburse.getSchedule()) && reimburse.getDepartment().equals(department) && reimburse.getTotalAmount() > money) {reimburse.setSchedule("部门审批通过");reimburse.setScheduleReason(ScheduleReason);mapper.updateReimbursementStatus(reimburse);session.commit();}}}public void approveReimbursement2(String id, String ScheduleReason) {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);Reimburse reimburse = mapper.selectReimbursementById(id);int money = 10000;if (reimburse != null && "未审批".equals(reimburse.getSchedule()) && reimburse.getTotalAmount() <= money) {reimburse.setSchedule("通过");reimburse.setScheduleReason(ScheduleReason);mapper.updateReimbursementStatus(reimburse);session.commit();} else if (reimburse != null && "未审批".equals(reimburse.getSchedule()) && reimburse.getTotalAmount() > money) {reimburse.setSchedule("通过");reimburse.setScheduleReason(ScheduleReason);mapper.updateReimbursementStatus(reimburse);session.commit();} else if (reimburse != null && "部门审批通过".equals(reimburse.getSchedule()) && reimburse.getTotalAmount() > money) {reimburse.setSchedule("通过");reimburse.setScheduleReason(ScheduleReason);mapper.updateReimbursementStatus(reimburse);session.commit();}}}public void rejectReimbursement(String id, String rejectScheduleReason, String department) {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);Reimburse reimburse = mapper.selectReimbursementById(id);int money = 10000;if (reimburse != null && "未审批".equals(reimburse.getSchedule()) && reimburse.getDepartment().equals(department) && reimburse.getTotalAmount() <= money) {reimburse.setSchedule("退回");reimburse.setScheduleReason(rejectScheduleReason);mapper.updateReimbursementStatus(reimburse);session.commit();}}}public void rejectReimbursement2(String id, String rejectScheduleReason) {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);Reimburse reimburse = mapper.selectReimbursementById(id);int money = 10000;if (reimburse != null && "未审批".equals(reimburse.getSchedule()) && reimburse.getTotalAmount() <= money) {reimburse.setSchedule("退回");reimburse.setScheduleReason(rejectScheduleReason);mapper.updateReimbursementStatus(reimburse);session.commit();} else if (reimburse != null && ("部门审批通过".equals(reimburse.getSchedule()) || "未审批".equals(reimburse.getSchedule())) && reimburse.getTotalAmount() > money) {reimburse.setSchedule("退回");reimburse.setScheduleReason(rejectScheduleReason);mapper.updateReimbursementStatus(reimburse);session.commit();}}}public void auditReimbursement(String id) {try (SqlSession session = factory.openSession()) {ReimburseMapper mapper = session.getMapper(ReimburseMapper.class);Reimburse reimburse = mapper.selectReimbursementById(id);if (reimburse != null && "通过".equals(reimburse.getSchedule())) {// 计算实际天数int days = calculateDays(reimburse.getDepartureDate(), reimburse.getReturnDate());int foodAllowanceStandard = "普通职员".equals(reimburse.getPosition()) ? 100 : 200;int localTransStandard = "普通职员".equals(reimburse.getPosition()) ? 80 : 100;int accommodationStandard = "普通职员".equals(reimburse.getPosition()) ? 400 : 600;// 计算伙食补助、公杂补助和住宿费的总额是否超出标准boolean isFoodAllowanceQualified = (foodAllowanceStandard * days) >= reimburse.getFoodAllowance();boolean isLocalTransQualified = (localTransStandard * days) >= reimburse.getLocalTrans();boolean isAccommodationQualified = (accommodationStandard * days) >= reimburse.getAccommodation();boolean isQualified = isFoodAllowanceQualified && isLocalTransQualified && isAccommodationQualified;if (isQualified) {// 如果合格,状态保持为"通过"reimburse.setSchedule("财务审核通过");reimburse.setScheduleReason(reimburse.getScheduleReason());} else {// 如果不合格,状态修改为"退回"reimburse.setSchedule("退回");reimburse.setScheduleReason("超出报销标准或往返时间有误");}mapper.updateReimbursementStatus(reimburse);session.commit();}}}private int calculateDays(String startDate, String endDate) {SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");try {Date start = sdf.parse(startDate);Date end = sdf.parse(endDate);return (int) ((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24)) + 1;} catch (ParseException e) {e.printStackTrace();return 0;}}}
点击查看代码
package com.Moonbeams.web;import com.Moonbeams.pojo.BusinessApply;
import com.Moonbeams.pojo.User;
import com.Moonbeams.service.BusinessApplyService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;@WebServlet("/businessApplyServlet")
public class BusinessApplyServlet extends HttpServlet {private BusinessApplyService service = new BusinessApplyService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8");HttpSession session = request.getSession();User currentUser = (User) session.getAttribute("user");if (currentUser == null) {// 用户未登录,重定向到登录页面response.sendRedirect("login.jsp");return;}String action = request.getParameter("action");if ("create".equals(action)) {// 创建出差申请BusinessApply businessApply = new BusinessApply();businessApply.setId(request.getParameter("id"));businessApply.setName(currentUser.getUsername()); // 设置申请人为当前登录用户businessApply.setDepartment(request.getParameter("department"));businessApply.setPosition(request.getParameter("position"));businessApply.setDestination(request.getParameter("destination"));businessApply.setDepartureDate(request.getParameter("departureDate"));businessApply.setReturnDate(request.getParameter("returnDate"));if(request.getParameter("type").equalsIgnoreCase("其他")){businessApply.setType(request.getParameter("typeContent"));}else{businessApply.setType(request.getParameter("type"));}businessApply.setTypeContent(request.getParameter("typeContent"));businessApply.setReason(request.getParameter("reason"));businessApply.setState("未审批");businessApply.setApplytime(request.getParameter("applyTime"));service.createBusinessApply(businessApply);response.sendRedirect("businessApplyList.jsp");} else if ("update".equals(action)) {// 修改出差申请String id = request.getParameter("id");BusinessApply businessApply = service.getBusinessApplyById(id);if (businessApply != null && businessApply.getName().equals(currentUser.getUsername())&&("未审批".equals(businessApply.getState())|| "退回".equals(businessApply.getState()))) {// 从请求参数中获取更新的值String destination = request.getParameter("destination");String departureDate = request.getParameter("departureDate");String returnDate = request.getParameter("returnDate");String type = request.getParameter("type");String typeContent = request.getParameter("typeContent");String reason = request.getParameter("reason");String applyTime = request.getParameter("applyTime");// 检查每个字段是否为空if (destination == null || destination.isEmpty()) {request.setAttribute("error", "目的地不能为空");RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);return;}if (departureDate == null || departureDate.isEmpty()) {request.setAttribute("error", "出发日期不能为空");RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);return;}if (returnDate == null || returnDate.isEmpty()) {request.setAttribute("error", "返回日期不能为空");RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);return;}// 更新申请信息businessApply.setDestination(destination);businessApply.setDepartureDate(departureDate);businessApply.setReturnDate(returnDate);businessApply.setType(type);businessApply.setTypeContent(typeContent);businessApply.setReason(reason);businessApply.setState("未审批");businessApply.setStateReason("");businessApply.setApplytime(applyTime);service.updateBusinessApply(businessApply);response.sendRedirect("businessApplyList.jsp");} else {request.setAttribute("error", "已审批的申请无法修改");RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);}} else if ("delete".equals(action)) {// 撤回出差申请String id = request.getParameter("id");BusinessApply businessApply = service.getBusinessApplyById(id);if (businessApply != null && businessApply.getName().equals(currentUser.getUsername())&&"未审批".equals(businessApply.getState())) {service.deleteBusinessApply(id);response.sendRedirect("businessApplyList.jsp");} else {request.setAttribute("error", "您没有权限撤回此申请,已审批的申请无法撤回");RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);}}else if ("approve".equals(action)) {String id = request.getParameter("id");String reason = request.getParameter("reason");try {if(currentUser.getPosition().equals("总经理")){service.approveApplication2(id,reason);}else{service.approveApplication(id, reason, currentUser.getDepartment());}response.sendRedirect("approveBusinessList.jsp");}catch (RuntimeException e) {request.setAttribute("error", e.getMessage());RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);}} else if ("reject".equals(action)) {String id = request.getParameter("id");String reason = request.getParameter("reason");try {service.rejectApplication(id, reason, currentUser.getDepartment());response.sendRedirect("approveBusinessList.jsp");} catch (RuntimeException e) {request.setAttribute("error", e.getMessage());RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);}} else if ("list".equals(action)) {// 获取当前用户提交的出差申请列表List<BusinessApply> applications = service.getApplicationsByUser(currentUser.getUsername());request.setAttribute("applications", applications);RequestDispatcher dispatcher = request.getRequestDispatcher("businessApplyList.jsp");dispatcher.forward(request, response);} else if("list2".equals(action)) {//获取当前部门提交的出差申请表List<BusinessApply> applications = service.getApplicationsByDepartment(currentUser.getDepartment());request.setAttribute("applications", applications);RequestDispatcher dispatcher = request.getRequestDispatcher("approveBusinessList.jsp");dispatcher.forward(request, response);}}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}
点击查看代码
package com.Moonbeams.web;import com.Moonbeams.pojo.BusinessApply;
import com.Moonbeams.pojo.Reimburse;
import com.Moonbeams.pojo.User;
import com.Moonbeams.service.ReimburseService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;@WebServlet("/reimburseApplyServlet")
public class ReimburseApplyServlet extends HttpServlet {private ReimburseService service = new ReimburseService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8");HttpSession session = request.getSession();User currentUser = (User) session.getAttribute("user");if (currentUser == null) {// 用户未登录,重定向到登录页面response.sendRedirect("login.jsp");return;}String action = request.getParameter("action");if ("create".equals(action)) {// 创建报销申请Reimburse reimburse = new Reimburse();reimburse.setId(request.getParameter("id"));reimburse.setName(currentUser.getUsername());// 设置申请人为当前登录用户reimburse.setPosition(request.getParameter("position"));try {String yearsOldStr = request.getParameter("yearsold");if (yearsOldStr != null && !yearsOldStr.isEmpty()) {reimburse.setYearsold(Integer.parseInt(yearsOldStr));} else {reimburse.setYearsold(0); // 或其他默认值}reimburse.setDepartment(request.getParameter("department"));reimburse.setDestination(request.getParameter("destination"));reimburse.setDepartureDate(request.getParameter("departureDate"));reimburse.setReturnDate(request.getParameter("returnDate"));reimburse.setReason(request.getParameter("reason"));// 解析其他费用参数String startFareStr = request.getParameter("startFare");String returnFareStr = request.getParameter("returnFare");String foodAllowanceStr = request.getParameter("foodAllowance");String localTransStr = request.getParameter("localTrans");String accommodationStr = request.getParameter("accommodation");String totalAmountStr = request.getParameter("totalAmount");String applyTimeStr = request.getParameter("applyTime");reimburse.setStartFare(parseOrDefault(startFareStr, 0));reimburse.setReturnFare(parseOrDefault(returnFareStr, 0));reimburse.setFoodAllowance(parseOrDefault(foodAllowanceStr, 0));reimburse.setLocalTrans(parseOrDefault(localTransStr, 0));reimburse.setAccommodation(parseOrDefault(accommodationStr, 0));reimburse.setTotalAmount(parseOrDefault(totalAmountStr, 0));reimburse.setSchedule("未审批");reimburse.setApplyTime(applyTimeStr);service.applyForReimbursement(reimburse);response.sendRedirect("reimburseList.jsp");} catch (NumberFormatException e) {// 处理解析错误request.setAttribute("errorMessage", "输入的数字格式不正确");request.getRequestDispatcher("re.jsp").forward(request, response);}} else if ("update".equals(action)) {String id = request.getParameter("id");Reimburse reimburse = service.getReimbursementById(id);if (reimburse != null && reimburse.getName().equals(currentUser.getUsername()) && "退回".equals(reimburse.getSchedule())) {//从请求参数中获取更新的值String position = request.getParameter("position");String yearsold = request.getParameter("yearsold");String department = request.getParameter("department");String destination = request.getParameter("destination");String departureDate = request.getParameter("departureDate");String returnDate = request.getParameter("returnDate");String reason = request.getParameter("reason");String startFare = request.getParameter("startFare");String returnFare = request.getParameter("returnFare");String foodAllowance = request.getParameter("foodAllowance");String localTrans = request.getParameter("localTrans");String accommodation = request.getParameter("accommodation");String totalAmount = request.getParameter("totalAmount");String applyTime = request.getParameter("applyTime");// 检查每个字段是否为空if (destination == null || destination.isEmpty()) {request.setAttribute("error", "目的地不能为空");RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);return;}if (departureDate == null || departureDate.isEmpty()) {request.setAttribute("error", "出发日期不能为空");RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);return;}if (returnDate == null || returnDate.isEmpty()) {request.setAttribute("error", "返回日期不能为空");RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);return;}reimburse.setPosition(position);reimburse.setYearsold(Integer.parseInt(yearsold));reimburse.setDepartment(department);reimburse.setDestination(destination);reimburse.setDepartureDate(departureDate);reimburse.setReturnDate(returnDate);reimburse.setReason(reason);reimburse.setStartFare(parseOrDefault(startFare, 0));reimburse.setReturnFare(parseOrDefault(returnFare, 0));reimburse.setFoodAllowance(parseOrDefault(foodAllowance, 0));reimburse.setLocalTrans(parseOrDefault(localTrans, 0));reimburse.setAccommodation(parseOrDefault(accommodation, 0));reimburse.setTotalAmount(parseOrDefault(totalAmount, 0));reimburse.setSchedule("未审批");reimburse.setScheduleReason("");reimburse.setApplyTime(applyTime);service.updateReimbursement(reimburse);response.sendRedirect("reimburseList.jsp");} else {request.setAttribute("error", "未审批的报销无法修改");RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);}}else if("select".equals(action)) {String name = request.getParameter("name");String department = request.getParameter("department");String totalAmountStr = request.getParameter("totalAmountGreaterThan");Integer totalAmountGreaterThan = null;if (totalAmountStr != null && !totalAmountStr.isEmpty()) {totalAmountGreaterThan = Integer.parseInt(totalAmountStr);}List<Reimburse> reimburses = service.searchApprovedReimbursements(name, department, totalAmountGreaterThan, currentUser.getDepartment(), currentUser.getPosition());request.setAttribute("reimburses", reimburses);RequestDispatcher dispatcher = request.getRequestDispatcher("reimburseListForSelect.jsp");dispatcher.forward(request, response);} else if ("approve".equals(action)) {String id = request.getParameter("id");String scheduleReason = request.getParameter("ScheduleReason");try {if (currentUser.getPosition().equals("总经理")) {service.approveReimbursement2(id, scheduleReason);} else {service.approveReimbursement(id, scheduleReason, currentUser.getDepartment());}response.sendRedirect("approveReimbursesList.jsp");} catch (RuntimeException e) {request.setAttribute("error", e.getMessage());RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);}} else if ("reject".equals(action)) {String id = request.getParameter("id");String scheduleReason = request.getParameter("ScheduleReason");try {if (currentUser.getPosition().equals("总经理")) {service.rejectReimbursement2(id, scheduleReason);} else {service.rejectReimbursement(id, scheduleReason, currentUser.getDepartment());}response.sendRedirect("approveReimbursesList.jsp");} catch (RuntimeException e) {request.setAttribute("error", e.getMessage());RequestDispatcher dispatcher = request.getRequestDispatcher("error.jsp");dispatcher.forward(request, response);}} else if ("audit".equals(action)) {String id = request.getParameter("id");service.auditReimbursement(id);response.sendRedirect("approveReimbursesListByFinancial.jsp");} else if ("list".equals(action)) {//获取当前用户提交的报销申请列表List<Reimburse> reimburses = service.getReimbursementsByUser(currentUser.getUsername());request.setAttribute("reimburses", reimburses);RequestDispatcher dispatcher = request.getRequestDispatcher("reimburseList.jsp");dispatcher.forward(request, response);} else if ("list2".equals(action)) {//获取当前部门提交的报销申请表List<Reimburse> reimburses = service.getReimbursementsByDepartment(currentUser.getDepartment());request.setAttribute("reimburses", reimburses);RequestDispatcher dispatcher = request.getRequestDispatcher("approveReimbursesList.jsp");dispatcher.forward(request, response);} else if ("list3".equals(action)) {//获取所有通过的报销表List<Reimburse> reimburses = service.getAllApproveReimbursements();request.setAttribute("reimburses", reimburses);RequestDispatcher dispatcher = request.getRequestDispatcher("approveReimbursesListByFinancial.jsp");dispatcher.forward(request, response);}}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}private int parseOrDefault(String value, int defaultValue) {if (value != null && !value.isEmpty()) {return Integer.parseInt(value);}return defaultValue;}
}
jsp
createBusinessApply.jsp
点击查看代码
<%@ page import="javax.swing.text.html.Option" %>
<%@ page import="com.Moonbeams.pojo.User" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page isELIgnored="false" %>
<%User currentUser = (User) session.getAttribute("user");if (currentUser == null) {response.sendRedirect("login.jsp");return;}
%><!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"> <!-- 可选的样式文件 --><meta charset="UTF-8"><title>出差申请</title><script type="text/javascript">function toggleOtherType() {var typeSelect = document.getElementById("typeSelect");var otherTypeInput = document.getElementById("otherTypeInput");otherTypeInput.style.display = (typeSelect.value === "其他") ? "block" : "none";if (typeSelect.value !== "其他") {otherTypeInput.value = ""; // 清空文本框}}function validateDateDifference() {var departureDate = document.getElementById("departureDate").value;var returnDate = document.getElementById("returnDate").value;var applyTime = document.getElementById("applyTime").value;if (!departureDate || !returnDate || !applyTime) {alert("日期不能为空");return false;}// 将日期字符串转换为日期对象var departureDateObj = new Date(departureDate);var returnDateObj = new Date(returnDate);var applyDateObj = new Date(applyTime);// 检查日期对象是否有效if (isNaN(departureDateObj.getTime()) || isNaN(returnDateObj.getTime()) || isNaN(applyDateObj.getTime())) {alert("请输入有效的日期格式");return false;}if (departureDateObj > returnDateObj) {alert("出差出发时间不能晚于出差返回时间。");return false;}if (applyDateObj > departureDateObj) {alert("申请时间不能晚于出差返回时间。");return false;}return true;}</script>
</head>
<body>
<h1>出差申请</h1>
<div class="transparent-box"> <!-- 将表单包裹在透明框容器中 --><form action="businessApplyServlet" method="post" onsubmit="return validateDateDifference();"><input type="hidden" name="action" value="create"><label>出差编号:</label><input type="text" name="id" required><br><label>出差人姓名:</label><input type="text" name="name" value="<%=currentUser.getUsername() %>" readonly><br><label>部门:</label><input type="text" name="department" value="<%=currentUser.getDepartment() %>" readonly><br><label>岗位:</label><input type="text" name="position" value="<%=currentUser.getPosition() %>" readonly><br><label>目的地:</label><input type="text" name="destination" required><br><label>暂定出发日期:</label><input type="date" id="departureDate" name="departureDate" required><br><label>预计返回日期:</label><input type="date" id="returnDate" name="returnDate" required><br><label>出差类别:</label><select name="type" id="typeSelect" onchange="toggleOtherType()"><option value="业务洽谈">业务洽谈</option><option value="培训">培训</option><option value="会议">会议</option><option value="其他">其他</option></select><br><div id="otherTypeInput" style="display:none;"><label>其他出差类别:</label><input type="text" name="typeContent"><br></div><label>出差事由:</label><textarea name="reason" required></textarea><br><label>申请时间:</label><input type="date" id="applyTime" name="applyTime" required><br><input type="submit" value="提交申请"></form>
</div>
<div class="transparent-box"><%if(currentUser.getPosition().equals("普通职员")){%><a href="employee.jsp">返回主界面</a><%} else if(currentUser.getPosition().equals("部门经理")){%><a href="departmentManager.jsp">返回主界面</a><%}%>
</div>
</body>
</html>
createReimburse.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.Moonbeams.pojo.User" %>
<%@page isELIgnored="false" %><%User currentUser = (User) session.getAttribute("user");if (currentUser == null) {response.sendRedirect("login.jsp");return;}
%><!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"><meta charset="UTF-8"><title>报销申请</title><script type="text/javascript">function calculateTotal() {var startFare = parseInt(document.getElementById("startFare").value) || 0;var returnFare = parseInt(document.getElementById("returnFare").value) || 0;var foodAllowance = parseInt(document.getElementById("foodAllowance").value) || 0;var localTrans = parseInt(document.getElementById("localTrans").value) || 0;var accommodation = parseInt(document.getElementById("accommodation").value) || 0;var totalAmount = startFare + returnFare + foodAllowance + localTrans + accommodation;document.getElementById("totalAmount").value = totalAmount;}function validateDateDifference() {var departureDate = document.getElementById("departureDate").value;var returnDate = document.getElementById("returnDate").value;var applyDate = document.getElementById("applyTime").value;if (!returnDate || !applyDate||!departureDate) {alert("日期不能为空");return false;}// 将日期字符串转换为日期对象var departureDateObj = new Date(departureDate);var returnDateObj = new Date(returnDate);var applyDateObj = new Date(applyDate);// 检查日期对象是否有效if (isNaN(departureDateObj.getTime()) || isNaN(returnDateObj.getTime()) || isNaN(applyDateObj.getTime())) {alert("请输入有效的日期格式");return false;}// 计算出差返回日期一个月后的日期var oneMonthLater = new Date(returnDate);oneMonthLater.setMonth(oneMonthLater.getMonth() + 1);if (applyDateObj > oneMonthLater) {alert("报销申请时间超过出差返回时间一个月,不允许申请。");return false;}if(departureDateObj > returnDateObj){alert("报销出差出发时间大于出差返回时间,不允许申请。");return false;}return true;}window.onload = function() {calculateTotal();};</script>
</head>
<body>
<h1>报销申请</h1>
<div class="transparent-box"><form action="reimburseApplyServlet" method="post" onsubmit="return validateDateDifference();"><input type="hidden" name="action" value="create"><label>报销编号:</label><input type="text" name="id" required><br><label>申请人姓名:</label><input type="text" name="name" value="<%= currentUser.getUsername() %>" readonly><br><label>部门:</label><input type="text" name="department" value="<%= currentUser.getDepartment() %>" readonly><br><label>职位:</label><input type="text" name="position" value="<%= currentUser.getPosition() %>" readonly><br><label>年龄:</label><input type="text" name="yearsold" required><br><label>目的地:</label><input type="text" name="destination" required><br><label>出发日期:</label><input type="date" name="departureDate" id ="departureDate" required><br><label>返回日期:</label><input type="date" name="returnDate" id="returnDate" required><br><label>报销事由:</label><textarea name="reason" required></textarea><br><label>出发车费:</label><input type="number" name="startFare" id="startFare" oninput="calculateTotal()" required><br><label>返回车费:</label><input type="number" name="returnFare" id="returnFare" oninput="calculateTotal()" required><br><label>伙食补助:</label><input type="number" name="foodAllowance" id="foodAllowance" oninput="calculateTotal()" required><br><label>公杂补助:</label><input type="number" name="localTrans" id="localTrans" oninput="calculateTotal()" required><br><label>住宿费:</label><input type="number" name="accommodation" id="accommodation" oninput="calculateTotal()" required><br><label>总金额:</label><input type="number" name="totalAmount" id="totalAmount" readonly><br><label>申请日期:</label><input type="date" name="applyTime" id="applyTime" required><br><input type="submit" value="提交申请"></form>
</div>
<div class="transparent-box"><%if (currentUser.getPosition().equals("普通职员")) {%><a href="employee.jsp">返回主界面</a><%} else if (currentUser.getPosition().equals("部门经理")) {%><a href="departmentManager.jsp">返回主界面</a><%}%>
</div>
</body>
</html>
approveBusinessList.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.Moonbeams.pojo.BusinessApply" %>
<%@ page import="com.Moonbeams.service.BusinessApplyService" %>
<%@ page import="com.Moonbeams.pojo.User" %>
<%@page isELIgnored="false" %><%BusinessApplyService service = new BusinessApplyService();User currentUser = (User) session.getAttribute("user");if (currentUser == null) {response.sendRedirect("login.jsp");return;}List<BusinessApply> applications = service.getPendingApplications();
%>
<%if(currentUser.getPosition().equals("总经理")){applications = service.getPendingApplications();}
%>
<!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"><meta charset="UTF-8"><title>出差申请审批列表</title>
</head>
<body>
<h1>出差申请审批列表</h1>
<table border="1"><tr><th>出差编号</th><th>姓名</th><th>部门</th><th>目的地</th><th>出发日期</th><th>返回日期</th><th>状态</th><th>申请事由</th><th>申请时间</th></tr><%if (applications != null) {for (BusinessApply apply : applications) {if (!apply.getDepartment().equals(currentUser.getDepartment())) {continue;}%><tr><td><%= apply.getId() %></td><td><%= apply.getName() %></td><td><%= apply.getDepartment() %></td><td><%= apply.getDestination() %></td><td><%= apply.getDepartureDate() %></td><td><%= apply.getReturnDate() %></td><td><%= apply.getState() %></td><td><%= apply.getReason() %></td><td><%= apply.getApplytime() %></td><td><% if ("未审批".equals(apply.getState())) { %><form action="businessApplyServlet" method="post"><input type="hidden" name="action" value="approve"><input type="hidden" name="id" value="<%= apply.getId() %>"><input type="text" name="reason" placeholder="审批理由"><input type="submit" value="通过"></form><form action="businessApplyServlet" method="post"><input type="hidden" name="action" value="reject"><input type="hidden" name="id" value="<%= apply.getId() %>"><input type="text" name="reason" placeholder="退回理由"><input type="submit" value="退回"></form><% } %></td></tr><%}}%>
</table>
<br>
<div class="transparent-box"><%if(currentUser.getPosition().equals("总经理")){%><a href="generalManager.jsp">返回主界面</a><%}else if(currentUser.getPosition().equals("部门经理")){%><a href="departmentManager.jsp">返回主界面</a><%}%>
</div>
</body>
</html>
approveReimbursesList.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.Moonbeams.pojo.User" %>
<%@ page import="com.Moonbeams.service.ReimburseService" %>
<%@ page import="com.Moonbeams.pojo.Reimburse" %>
<%@page isELIgnored="false" %><%ReimburseService service = new ReimburseService();User currentUser = (User) session.getAttribute("user");if (currentUser == null) {response.sendRedirect("login.jsp");return;}List<Reimburse> reimburses = service.getReimbursementsByDepartment(currentUser.getDepartment());
%>
<%if(currentUser.getPosition().equals("总经理")){reimburses = service.getPendingReimbursement();}
%>
<!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"><meta charset="UTF-8"><title>报销申请审批列表</title>
</head>
<body>
<h1>报销申请审批列表</h1>
<table border="1"><tr><th>报销编号</th><th>姓名</th><th>部门</th><th>目的地</th><th>出发日期</th><th>返回日期</th><th>报销事由</th><th>审批事由</th><th>状态</th><th>申请时间</th></tr><%if (reimburses != null) {for (Reimburse reimburse : reimburses) {if (currentUser.getPosition().equals("部门经理")&&!reimburse.getDepartment().equals(currentUser.getDepartment())) {continue;}%><tr><td><%= reimburse.getId() %></td><td><%= reimburse.getName() %></td><td><%= reimburse.getDepartment() %></td><td><%= reimburse.getDestination() %></td><td><%= reimburse.getDepartureDate() %></td><td><%= reimburse.getReturnDate() %></td><td><%= reimburse.getReason() %></td><td><%= reimburse.getScheduleReason() %></td><td><%= reimburse.getSchedule() %></td><td><%= reimburse.getApplyTime() %></td><td><% if ("未审批".equals(reimburse.getSchedule())) { %><form action="reimburseApplyServlet" method="post"><input type="hidden" name="action" value="approve"><input type="hidden" name="id" value="<%= reimburse.getId() %>"><label><input type="text" name="ScheduleReason" placeholder="审批理由"></label><input type="submit" value="通过"></form><form action="reimburseApplyServlet" method="post"><input type="hidden" name="action" value="reject"><input type="hidden" name="id" value="<%= reimburse.getId() %>"><label><input type="text" name="ScheduleReason" placeholder="退回理由"></label><input type="submit" value="退回"></form><% }else if("部门审批通过".equals(reimburse.getSchedule())&&"总经理".equals(currentUser.getPosition())){ %><form action="reimburseApplyServlet" method="post"><input type="hidden" name="action" value="approve"><input type="hidden" name="id" value="<%= reimburse.getId() %>"><label><input type="text" name="ScheduleReason" placeholder="审批理由"></label><input type="submit" value="通过"></form><form action="reimburseApplyServlet" method="post"><input type="hidden" name="action" value="reject"><input type="hidden" name="id" value="<%= reimburse.getId() %>"><input type="text" name="ScheduleReason" placeholder="退回理由"><input type="submit" value="退回"></form><%}%></td></tr><%}}%>
</table>
<br>
<div class="transparent-box"><%if(currentUser.getPosition().equals("总经理")){%><a href="generalManager.jsp">返回主界面</a><%}else if(currentUser.getPosition().equals("部门经理")){%><a href="departmentManager.jsp">返回主界面</a><%}%>
</div>
</body>
</html>
approveReimbursesListByFinancial.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.Moonbeams.pojo.User" %>
<%@ page import="com.Moonbeams.service.ReimburseService" %>
<%@ page import="com.Moonbeams.pojo.Reimburse" %>
<%@ page isELIgnored="false" %><%ReimburseService service = new ReimburseService();User currentUser = (User) session.getAttribute("user");if (currentUser == null) {response.sendRedirect("login.jsp");return;}// 获取所有报销单List<Reimburse> reimburses = service.getAllApproveReimbursements();
%>
<!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"><meta charset="UTF-8"><title>报销申请财务审核列表</title>
</head>
<body>
<h1>报销申请财务审核列表</h1>
<table border="1"><tr><th>报销编号</th><th>姓名</th><th>部门</th><th>职位</th><th>目的地</th><th>出发日期</th><th>返回日期</th><th>出发车费</th><th>返回车费</th><th>伙食补助</th><th>公杂补助</th><th>住宿费</th><th>总金额</th><th>报销事由</th><th>状态</th><th>审批事由</th><th>申请时间</th><th>操作</th></tr><%if (reimburses != null) {for (Reimburse reimburse : reimburses) {// 仅显示当前用户部门的报销单if (!reimburse.getDepartment().equals(currentUser.getDepartment())) {continue;}%><tr><td><%= reimburse.getId() %></td><td><%= reimburse.getName() %></td><td><%= reimburse.getDepartment() %></td><td><%= reimburse.getPosition() %></td><td><%= reimburse.getDestination() %></td><td><%= reimburse.getDepartureDate() %></td><td><%= reimburse.getReturnDate() %></td><td><%= reimburse.getStartFare() %></td><td><%= reimburse.getReturnFare() %></td><td><%= reimburse.getFoodAllowance() %></td><td><%= reimburse.getLocalTrans() %><td><%= reimburse.getAccommodation() %></td><td><%= reimburse.getTotalAmount() %></td><td><%= reimburse.getReason() %></td><td><%= reimburse.getSchedule() %></td><td><%= reimburse.getScheduleReason() %></td><td><%= reimburse.getApplyTime() %></td><td><% if ("通过".equals(reimburse.getSchedule())) { %><form action="reimburseApplyServlet" method="post"><input type="hidden" name="action" value="audit"><input type="hidden" name="id" value="<%= reimburse.getId() %>"><input type="submit" value="审核"></form><% } else { %><span>已审核</span><% } %></td></tr><%}} else {%><tr><td colspan="18">没有找到符合条件的报销单。</td></tr><%}%>
</table>
<br>
<div class="transparent-box"><a href="financialStaff.jsp">返回主界面</a>
</div>
</body>
</html>
businessApplyList.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.Moonbeams.pojo.BusinessApply" %>
<%@ page import="com.Moonbeams.service.BusinessApplyService" %>
<%@ page import="com.Moonbeams.pojo.User" %>
<%@page isELIgnored="false" %><%BusinessApplyService service = new BusinessApplyService();User currentUser = (User) session.getAttribute("user");if (currentUser == null) {response.sendRedirect("login.jsp");return;}List<BusinessApply> applications = service.getApplicationsByUser(currentUser.getUsername());
%>
<!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"><meta charset="UTF-8"><title>出差申请列表</title>
</head>
<body>
<h1>出差申请列表</h1>
<table border="1"><tr><th>出差编号</th><th>姓名</th><th>部门</th><th>目的地</th><th>出发日期</th><th>返回日期</th><th>状态</th><th>申请事由</th><th>通过/退回事由</th><th>申请时间</th></tr><%if (applications != null) {for (BusinessApply apply : applications) {String rowClass = "row"; // Add this lineif ("未审批".equals(apply.getState())||"退回".equals(apply.getState())) {rowClass = "row-unapproved"; // Add this line}%><tr class="<%= rowClass %>"><td><%= apply.getId() %></td><td><%= apply.getName() %></td><td><%= apply.getDepartment() %></td><td><%= apply.getDestination() %></td><td><%= apply.getDepartureDate() %></td><td><%= apply.getReturnDate() %></td><td><%= apply.getState() %></td><td><%= apply.getReason() %></td><td><%= apply.getStateReason() %></td><td><%= apply.getApplytime() %></td><td><% if ("未审批".equals(apply.getState()) || "退回".equals(apply.getState())) { %><form action="updateBusinessApply.jsp" method="post"><input type="hidden" name="action" value="update"><input type="hidden" name="id" value="<%= apply.getId() %>"><input type="submit" value="修改"></form><form action="businessApplyServlet" method="post"><input type="hidden" name="action" value="delete"><input type="hidden" name="id" value="<%= apply.getId() %>"><input type="submit" value="撤回"></form><% } %></td></tr><%}}%>
</table>
<br>
<div class="transparent-box"><a href="createBusinessApply.jsp">提交新的出差申请</a>
</div>
<div class="transparent-box"><%if(currentUser.getPosition().equals("普通职员")){%><a href="employee.jsp">返回主界面</a><%}else if(currentUser.getPosition().equals("部门经理")){%><a href="departmentManager.jsp">返回主界面</a><%}%>
</div>
</body>
</html>
departmentExpenses.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.Moonbeams.pojo.DepartmentExpense" %>
<%@ page import="com.Moonbeams.service.ReimburseService" %>
<%@ page import="com.Moonbeams.pojo.User" %><%User currentUser = (User) session.getAttribute("user");if (currentUser == null || !"总经理".equals(currentUser.getPosition())) {response.sendRedirect("login.jsp");return;}ReimburseService service = new ReimburseService();List<DepartmentExpense> departmentExpenses = service.getAnnualDepartmentExpenses();
%><!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"><meta charset="UTF-8"><title>各部门差旅费统计</title>
</head>
<body>
<h1>各部门差旅费统计(本年度)</h1><%if (departmentExpenses == null || departmentExpenses.isEmpty()) {
%>
<p>没有找到符合条件的报销单。</p>
<%
} else {
%>
<table border="1"><tr><th>部门名称</th><th>花费总金额</th></tr><%for (DepartmentExpense expense : departmentExpenses) {%><tr><td><%= expense.getDepartmentName() %></td><td><%= expense.getTotalAmount() %></td></tr><%}%>
</table>
<%}
%><div class="transparent-box"><a href="generalManager.jsp">返回主界面</a>
</div>
</body>
</html>
departmentManager.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.Moonbeams.pojo.DepartmentExpense" %>
<%@ page import="com.Moonbeams.service.ReimburseService" %>
<%@ page import="com.Moonbeams.pojo.User" %><%User currentUser = (User) session.getAttribute("user");if (currentUser == null || !"总经理".equals(currentUser.getPosition())) {response.sendRedirect("login.jsp");return;}ReimburseService service = new ReimburseService();List<DepartmentExpense> departmentExpenses = service.getAnnualDepartmentExpenses();
%><!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"><meta charset="UTF-8"><title>各部门差旅费统计</title>
</head>
<body>
<h1>各部门差旅费统计(本年度)</h1><%if (departmentExpenses == null || departmentExpenses.isEmpty()) {
%>
<p>没有找到符合条件的报销单。</p>
<%
} else {
%>
<table border="1"><tr><th>部门名称</th><th>花费总金额</th></tr><%for (DepartmentExpense expense : departmentExpenses) {%><tr><td><%= expense.getDepartmentName() %></td><td><%= expense.getTotalAmount() %></td></tr><%}%>
</table>
<%}
%><div class="transparent-box"><a href="generalManager.jsp">返回主界面</a>
</div>
</body>
</html>
employee.jsp
点击查看代码
<%@ page import="com.Moonbeams.pojo.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page isELIgnored="false" %>
<%User currentUser = (User) session.getAttribute("user");String currentUsername = currentUser.getUsername();String currentDepartment = currentUser.getDepartment();
%><html>
<head><title>出差报销系统</title><link rel="stylesheet" type="text/css" href="css/styles.css"> <!-- 可选的样式文件 -->
</head>
<body>
<h1>出差报销系统</h1>
<h2><%=currentUsername%>,<%=currentDepartment%> 职员,你好!</h2>
<nav><ul><li><a href="createBusinessApply.jsp">出差申请</a></li><li><a href="createReimburse.jsp">报销申请</a></li><li><a href="businessApplyList.jsp">查看出差申请列表</a></li><li><a href="reimburseList.jsp">查看报销申请列表</a></li></ul>
</nav>
<nav><ul><li><a href="login.jsp">重新登录</a></li></ul>
</nav>
</body>
</html>
error.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"> <!-- 可选的样式文件 --><meta charset="UTF-8"><title>错误</title>
</head>
<body>
<h1>错误</h1>
<%String errorMessage = (String) request.getAttribute("error");if (errorMessage != null) {
%>
<p><%= errorMessage %></p>
<%
} else {
%>
<p>发生了一些错误,请重试。</p>
<%}
%>
<%// 获取返回的URL标识符String returnUrl = (String) request.getAttribute("returnUrl");String redirectUrl = "https://www.bilibili.com/"; // 默认// 根据returnUrl的值判断应该重定向到哪个页面if ("reimburse".equals(returnUrl)) {redirectUrl = "reimburseList.jsp"; // 报销申请列表页面} else if ("business".equals(returnUrl)) {redirectUrl = "businessApplyList.jsp"; // 出差申请列表页面}
%>
<div class="transparent-box"><a href="<%= redirectUrl %>">返回申请列表</a>
</div>
</body>
</html>
financialStaff.jsp
点击查看代码
<%@ page import="com.Moonbeams.pojo.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page isELIgnored="false" %>
<%User currentUser = (User) session.getAttribute("user");String currentUsername = currentUser.getUsername();String currentDepartment = currentUser.getDepartment();
%><html>
<head><title>出差报销系统</title><link rel="stylesheet" type="text/css" href="css/styles.css"> <!-- 可选的样式文件 -->
</head>
<body>
<h1>出差报销系统</h1>
<h2><%=currentUsername%>,<%=currentDepartment%> 财务人员,您好!</h2>
<nav><ul><li><a href="approveReimbursesListByFinancial.jsp">审核报销单据</a></li></ul>
</nav>
<nav><ul><li><a href="login.jsp">重新登录</a></li></ul>
</nav>
</body>
</html>
generalManager.jsp
点击查看代码
<%@ page import="com.Moonbeams.pojo.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page isELIgnored="false" %>
<%User currentUser = (User) session.getAttribute("user");String currentUsername = currentUser.getUsername();String currentDepartment = currentUser.getDepartment();
%><html>
<head><title>出差报销系统</title><link rel="stylesheet" type="text/css" href="css/styles.css"> <!-- 可选的样式文件 -->
</head>
<body>
<h1>出差报销系统</h1>
<h2><%=currentUsername%>,<%=currentDepartment%> 总经理,您好!</h2>
<nav><ul><li><a href="approveBusinessList.jsp">出差审批</a></li><li><a href="approveReimbursesList.jsp">差旅费报销审批</a></li><li><a href="reimburseSearch.jsp">查询全公司的报销情况</a></li><li><a href="departmentExpenses.jsp">查看各部门本年度差旅费花费情况</a></li></ul>
</nav>
<nav><ul><li><a href="login.jsp">重新登录</a></li></ul>
</nav>
</body>
</html>
reimburseDetailForSelect.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.Moonbeams.pojo.Reimburse" %>
<%@ page import="com.Moonbeams.service.ReimburseService" %>
<%@ page import="com.Moonbeams.pojo.User" %><%User currentUser = (User) session.getAttribute("user");if (currentUser == null) {response.sendRedirect("login.jsp");return;}String id = request.getParameter("id");ReimburseService service = new ReimburseService();Reimburse reimburse = service.getReimbursementById(id);if (reimburse == null) {out.print("未找到报销单据。");return;}
%><!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"><meta charset="UTF-8"><title>报销单据详情</title>
</head>
<body>
<h1>报销单据详情</h1>
<table border="1"><tr><th>报销编号</th><th>申请人姓名</th><th>部门</th><th>职位</th><th>年龄</th><th>目的地</th><th>出发日期</th><th>返回日期</th><th>出发车费</th><th>返回车费</th><th>伙食补助</th><th>公杂补助</th><th>住宿费</th><th>总金额</th><th>报销事由</th><th>审批事由</th><th>状态</th><th>申请时间</th></tr><tr><td><%= reimburse.getId() %></td><td><%= reimburse.getName() %></td><td><%=reimburse.getDepartment() %></td><td><%= reimburse.getPosition() %></td><td><%= reimburse.getYearsold() %></td><td><%= reimburse.getDestination() %></td><td><%= reimburse.getDepartureDate() %></td><td><%= reimburse.getReturnDate() %></td><td><%= reimburse.getStartFare() %></td><td><%= reimburse.getReturnFare() %></td><td><%= reimburse.getFoodAllowance() %></td><td><%= reimburse.getLocalTrans() %></td><td><%= reimburse.getAccommodation() %></td><td><%= reimburse.getTotalAmount() %></td><td><%= reimburse.getReason() %></td><td><%= reimburse.getScheduleReason() %></td><td><%= reimburse.getSchedule() %></td><td><%= reimburse.getApplyTime() %></td></tr>
</table>
<br><div class="transparent-box"><%if(currentUser.getPosition().equals("总经理")) {%><a href="generalManager.jsp">返回主界面</a><%} else if(currentUser.getPosition().equals("部门经理")) {%><a href="departmentManager.jsp">返回主界面</a><%}%>
</div>
</body>
</html>
reimburseList.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.Moonbeams.pojo.Reimburse" %>
<%@ page import="com.Moonbeams.service.ReimburseService" %>
<%@ page import="com.Moonbeams.pojo.User" %>
<%@page isELIgnored="false" %><%ReimburseService service = new ReimburseService();User currentUser = (User) session.getAttribute("user");if (currentUser == null) {response.sendRedirect("login.jsp");return;}List<Reimburse> reimburses = service.getReimbursementsByUser(currentUser.getUsername());
%><!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"><meta charset="UTF-8"><title>报销申请列表</title>
</head>
<body>
<h1>报销申请列表</h1>
<table border="1"><tr><th>报销编号</th><th>姓名</th><th>部门</th><th>目的地</th><th>出发日期</th><th>返回日期</th><th>状态</th><th>申请时间</th><th>申请/退回理由</th></tr><%if (reimburses != null) {for (Reimburse reimburse : reimburses) {String rowClass = "row";if ("未审批".equals(reimburse.getSchedule()) || "退回".equals(reimburse.getSchedule())) {rowClass = "row-unapproved";}%><tr class="<%= rowClass %>"><td><%= reimburse.getId() %></td><td><%= reimburse.getName() %></td><td><%= reimburse.getDepartment() %></td><td><%= reimburse.getDestination() %></td><td><%= reimburse.getDepartureDate() %></td><td><%= reimburse.getReturnDate() %></td><td><%= reimburse.getSchedule() %></td><td><%= reimburse.getApplyTime() %></td><%if (reimburse.getScheduleReason() == null || reimburse.getScheduleReason().isEmpty()) {reimburse.setScheduleReason("无");}%><td><%= reimburse.getScheduleReason() %></td><td><% if ("退回".equals(reimburse.getSchedule())) { %><form action="updateReimburse.jsp" method="post"><input type="hidden" name="action" value="update"><input type="hidden" name="id" value="<%= reimburse.getId() %>"><input type="submit" value="修改"></form><% } %></td></tr><%}}%>
</table>
<br>
<div class="transparent-box"><a href="createReimburse.jsp">提交新的报销申请</a>
</div>
<div class="transparent-box"><%if (currentUser.getPosition().equals("普通职员")) {%><a href="employee.jsp">返回主界面</a><%} else if (currentUser.getPosition().equals("部门经理")) {%><a href="departmentManager.jsp">返回主界面</a><%}%>
</div>
</body>
</html>
reimburseListForSelect.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page isELIgnored="false" %>
<%@ page import="java.util.List" %>
<%@ page import="com.Moonbeams.pojo.Reimburse" %>
<%@ page import="com.Moonbeams.pojo.User" %><%User currentUser = (User) session.getAttribute("user");if (currentUser == null) {response.sendRedirect("login.jsp");return;}
%><!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"><meta charset="UTF-8"><title>报销申请查询结果</title>
</head>
<body>
<h1>报销申请查询结果</h1><%List<Reimburse> reimburses = (List<Reimburse>) request.getAttribute("reimburses");if (reimburses == null || reimburses.isEmpty()) {
%>
<p>没有找到符合条件的报销单。</p>
<%
} else {
%>
<table border="1"><tr><th>报销日期</th><th>报销人姓名</th><th>报销人部门</th><th>报销事由</th><th>报销总金额</th><th>详细信息</th></tr><%for (Reimburse reimburse : reimburses) {%><tr><td><%= reimburse.getApplyTime() %></td><td><%= reimburse.getName() %></td><td><%= reimburse.getDepartment() %></td><td><%= reimburse.getReason() %></td><td><%= reimburse.getTotalAmount() %></td><td><a href="reimburseDetail.jsp?id=<%= reimburse.getId() %>">查看详情</a></td></tr><%}%>
</table>
<%}
%><br>
<div class="transparent-box"><%if(currentUser.getPosition().equals("总经理")) {%><a href="generalManager.jsp">返回主界面</a><%} else if(currentUser.getPosition().equals("部门经理")) {%><a href="departmentManager.jsp">返回主界面</a><%}%>
</div>
</body>
</html>
reimburseSearch.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page isELIgnored="false" %>
<%@ page import="com.Moonbeams.pojo.User" %>
<%User currentUser = (User) session.getAttribute("user");if (currentUser == null) {response.sendRedirect("login.jsp");return;}
%><!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"><meta charset="UTF-8"><title>查询报销单</title>
</head>
<body>
<h1>查询报销单</h1>
<form action="reimburseApplyServlet" method="get"><input type="hidden" name="action" value="select"><label>姓名:</label><input type="text" name="name"><br><label>部门:</label><input type="text" name="department"><br><label>报销总金额大于:</label><input type="number" name="totalAmountGreaterThan"><br><input type="submit" value="查询">
</form><br>
<div class="transparent-box"><%if(currentUser.getPosition().equals("总经理")) {%><a href="generalManager.jsp">返回主界面</a><%} else if(currentUser.getPosition().equals("部门经理")) {%><a href="departmentManager.jsp">返回主界面</a><%}%>
</div>
</body>
</html>
updateBusinessApply.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.Moonbeams.pojo.BusinessApply" %>
<%@ page import="java.util.Date" %>
<%@ page import="com.Moonbeams.service.BusinessApplyService" %>
<%@ page import="com.Moonbeams.pojo.User" %>
<%@page isELIgnored="false" %>
<%User currentUser = (User) session.getAttribute("user");if (currentUser == null) {response.sendRedirect("login.jsp");return;}
%>
<%String Id = request.getParameter("id");BusinessApplyService service = new BusinessApplyService();BusinessApply businessApply = service.getBusinessApplyById(Id);if (businessApply == null) {response.sendRedirect("error.jsp");return;}
%>
<!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"> <!-- 可选的样式文件 --><meta charset="UTF-8"><title>修改出差申请</title><script type="text/javascript">function toggleOtherType() {var typeSelect = document.getElementById("typeSelect");var otherTypeInput = document.getElementById("otherTypeInput");if (typeSelect.value === "其他") {otherTypeInput.style.display = "block"; // 显示文本框} else {otherTypeInput.style.display = "none"; // 隐藏文本框otherTypeInput.value = ""; // 清空文本框}}window.onload = function() {toggleOtherType();};function validateDateDifference() {var departureDate = document.getElementById("departureDate").value;var returnDate = document.getElementById("returnDate").value;var applyDate = document.getElementById("applyTime").value;if (!returnDate || !applyDate || !departureDate) {alert("日期不能为空");return false;}// 将日期字符串转换为日期对象var departureDateObj = new Date(departureDate);var returnDateObj = new Date(returnDate);var applyDateObj = new Date(applyDate);// 检查日期对象是否有效if (isNaN(departureDateObj.getTime()) || isNaN(returnDateObj.getTime()) || isNaN(applyDateObj.getTime())) {alert("请输入有效的日期格式");return false;}if (departureDateObj > returnDateObj) {alert("出差出发时间不能晚于出差返回时间。");return false;} else if (applyDateObj > departureDateObj) {alert("申请时间不能晚于出差出发时间。");return false;}return true;}</script></head>
<body>
<h1>修改出差申请</h1>
<form action="businessApplyServlet" method="post" onsubmit="return validateDateDifference();"><input type="hidden" name="action" value="update"><input type="hidden" name="id" value="<%= businessApply.getId() %>">姓名: <input type="text" name="name" value="<%= businessApply.getName() %>" readonly><br>部门: <input type="text" name="department" value="<%= businessApply.getDepartment() %>" readonly><br>职位: <input type="text" name="position" value="<%= businessApply.getPosition() %>" readonly><br>目的地: <input type="text" name="destination" value="<%= businessApply.getDestination() %>"><br>出发日期: <input type="date" id="departureDate" name="departureDate" value="<%= businessApply.getDepartureDate() %>"><br>返回日期: <input type="date" id="returnDate" name="returnDate" value="<%= businessApply.getReturnDate() %>"><br><label>出差类别:</label><select name="type" id="typeSelect" onchange="toggleOtherType()"><option value="业务洽谈" <%= "业务洽谈".equals(businessApply.getType()) ? "selected" : "" %>>业务洽谈</option><option value="培训" <%= "培训".equals(businessApply.getType()) ? "selected" : "" %>>培训</option><option value="会议" <%= "会议".equals(businessApply.getType()) ? "selected" : "" %>>会议</option><option value="其他" <%= "其他".equals(businessApply.getType()) ? "selected" : "" %>>其他</option></select><br><div id="otherTypeInput" style="display:none;"><label>其他出差类别:</label><input type="text" name="typeContent" value="<%= businessApply.getTypeContent() %>"><br></div>出差事由: <textarea name="reason"><%= businessApply.getReason() %></textarea><br>申请时间: <input type="date" id="applyTime" name="applyTime" value="<%= businessApply.getApplytime() %>" required><br><input type="submit" value="提交修改">
</form>
<div class="transparent-box"> <!-- 将表单包裹在透明框容器中 --><a href="businessApplyList.jsp">返回申请列表</a>
</div></body>
</html>
updateReimburse.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.Moonbeams.pojo.Reimburse" %>
<%@ page import="com.Moonbeams.service.ReimburseService" %>
<%@ page import="com.Moonbeams.pojo.User" %>
<%@page isELIgnored="false" %><%User currentUser = (User) session.getAttribute("user");if (currentUser == null) {response.sendRedirect("login.jsp");return;}String id = request.getParameter("id");ReimburseService service = new ReimburseService();Reimburse reimburse = service.getReimbursementById(id);if (reimburse == null) {response.sendRedirect("error.jsp");return;}
%><!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="css/styles.css"><meta charset="UTF-8"><title>修改报销申请</title><script type="text/javascript">function calculateTotal() {var startFare = parseInt(document.getElementById("startFare").value) || 0;var returnFare = parseInt(document.getElementById("returnFare").value) || 0;var foodAllowance = parseInt(document.getElementById("foodAllowance").value) || 0;var localTrans = parseInt(document.getElementById("localTrans").value) || 0;var accommodation = parseInt(document.getElementById("accommodation").value) || 0;var totalAmount = startFare + returnFare + foodAllowance + localTrans + accommodation;document.getElementById("totalAmount").value = totalAmount;}function validateDateDifference() {var departureDate = document.getElementById("departureDate").value;var returnDate = document.getElementById("returnDate").value;var applyDate = document.getElementById("applyTime").value;if (!returnDate || !applyDate) {alert("日期不能为空");return false;}// 将日期字符串转换为日期对象var departureDateObj = new Date(departureDate);var returnDateObj = new Date(returnDate);var applyDateObj = new Date(applyDate);// 检查日期对象是否有效if (isNaN(departureDateObj.getTime()) || isNaN(returnDateObj.getTime()) || isNaN(applyDateObj.getTime())) {alert("请输入有效的日期格式");return false;}// 计算出差返回日期一个月后的日期var oneMonthLater = new Date(returnDate);oneMonthLater.setMonth(oneMonthLater.getMonth() + 1);if (applyDateObj> oneMonthLater) {alert("报销申请时间超过出差返回时间一个月,不允许申请。");return false;}if(departureDateObj > returnDateObj){alert("报销出差出发时间超过出差返回时间,不允许申请。");return false;}return true;}window.onload = function() {calculateTotal();};</script>
</head>
<body>
<h1>修改报销申请</h1>
<div class="transparent-box"><form action="reimburseApplyServlet" method="post" onsubmit="return validateDateDifference();"><input type="hidden" name="action" value="update"><input type="hidden" name="id" value="<%= reimburse.getId() %>"><label>报销编号:</label><input type="text" name="id" value="<%= reimburse.getId() %>" readonly><br><label>申请人姓名:</label><input type="text" name="name" value="<%= currentUser.getUsername() %>" readonly><br><label>部门:</label><input type="text" name="department" value="<%= currentUser.getDepartment() %>" required><br><label>职位:</label><input type="text" name="position" value="<%= currentUser.getPosition() %>" required><br><label>年龄:</label><input type="text" name="yearsold" value="<%= reimburse.getYearsold() %>" required><br><label>目的地:</label><input type="text" name="destination" value="<%= reimburse.getDestination() %>" required><br><label>出发日期:</label><input type="date" name="departureDate" id = "departureDate" value="<%= reimburse.getDepartureDate() %>" required><br><label>返回日期:</label><input type="date" name="returnDate" id="returnDate" value="<%= reimburse.getReturnDate() %>" required><br><label>报销事由:</label><textarea name="reason"><%= reimburse.getReason() %></textarea><br><label>出发车费:</label><input type="number" name="startFare" id="startFare" value="<%= reimburse.getStartFare() %>" oninput="calculateTotal()" required><br><label>返回车费:</label><input type="number" name="returnFare" id="returnFare" value="<%= reimburse.getReturnFare() %>" oninput="calculateTotal()" required><br><label>伙食补助:</label><input type="number" name="foodAllowance" id="foodAllowance" value="<%= reimburse.getFoodAllowance() %>" oninput="calculateTotal()" required><br><label>公杂补助:</label><input type="number" name="localTrans" id="localTrans" value="<%= reimburse.getLocalTrans() %>" oninput="calculateTotal()" required><br><label>住宿费:</label><input type="number" name="accommodation" id="accommodation" value="<%= reimburse.getAccommodation() %>" oninput="calculateTotal()" required><br><label>总金额:</label><input type="number" name="totalAmount" id="totalAmount" value="<%= reimburse.getTotalAmount() %>" readonly><br><label>申请时间:</label><input type="date" name="applyTime" id="applyTime" value="<%= reimburse.getApplyTime() %>" required><br><input type="submit" value="提交修改"></form>
</div>
<div class="transparent-box"><a href="reimburseList.jsp">返回报销列表</a>
</div>
</body>
</html>