本文主要是介绍用mysql生成工资条_薪酬模块生成工资条,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
主要运用easyUI 、 Hibernate 、Servlet 。
1.动态生成标签页,
$(function(){
//创建打开新标签页
$(".easyui-linkbutton").click(function(){
$("#img").panel('close');
//获取组件的属性或内容
var tab_title = $(this).text();//关键在this选择当前事件
var tab_href = $(this).attr("title");
var dd = $(this).attr("id");
//alert(tab_href);
if($("#tt").tabs("exists",tab_title))
{
$("#tt").tabs("select",tab_title)
}
else if(dd=="dd")
{
$("#gz").dialog('open');
}
else
{
$("#tt").tabs('add',{
title:tab_title,
closable:true,
//href:tab_href
content:""
});
}
});
})
这里主要是用inframe来获取href,避免多个标签页同时打开产生冲突。
2.然后就是生成工资条的弹窗,
这里是根据考勤表里的状态来获取月份的,(0表示未生成工资条)
注意下拉框是通过URL、valueFeild、textFeild 把value的值传递的,参考:省市区三级联动
3.点击生成按钮后,需要加载数据,需要一段时间,所以加了个进度条
title="生成工资条"
data-options="{
closed:true,
modal:true,
buttons:[{
text:'生成',
iconCls:'icon-ok',
handler:function(){
$('#form1').form('submit',{
url:'PayDateServlet',//把定义的默认值是add的添加的方法传给Servlet然后判断
onSubmit:function(){
var isValid = $(this).form('validate');
if(!isValid)
{
$.messager.show({
title:'消息',
msg:'数据验证未通过'
});
}
else
{
//进度对话框
$.messager.progress(
{
title:'进度条',
msg:'工资加载中。。。',
text:'请稍后。。。',
interval:1000
}
);
}
return isValid;//
},
success:function(data){
var msg = eval('('+ data +')');//eval是js的方法
if(!msg.success)
{
alert(msg.message);
}
else
{
$.messager.progress('close');
$.messager.show({
title:'消息',
msg:'数据验证通过,保存成功'
});
$('#gz').dialog('close');
}
}
});
}
},
{
text:'取消',
iconCls:'icon-cancel',
handler:function(){$('#gz').dialog('close')},
}]
}"
>
页面层
Insert title here.caidan
{
width:120px;
height:40px;
position:relative;
float: left;
margin-left: 40px;
margin-top: 5px;
color:white;
text-align: center;
line-height: 40px;
font-size: 1.2em;
}
.caidan:hover
{
background-color:#595959;
border-radius: 3px;
}
function getDate(date)
{
//得到日期对象
var d = new Date(date);
//得到年 月 日
var year = d.getFullYear();
var month = (d.getMonth()+1);
var day = d.getDate();
//拼装
var rtn = year+"-"+(month<10 ? "0"+month : month) + "-"+(day<10 ? "0"+day : day);
return rtn;
}
$(function(){
//创建打开新标签页
$(".easyui-linkbutton").click(function(){
$("#img").panel('close');
//获取组件的属性或内容
var tab_title = $(this).text();//关键在this选择当前事件
var tab_href = $(this).attr("title");
var dd = $(this).attr("id");
//alert(tab_href);
if($("#tt").tabs("exists",tab_title))
{
$("#tt").tabs("select",tab_title)
}
else if(dd=="dd")
{
$("#gz").dialog('open');
}
else
{
$("#tt").tabs('add',{
title:tab_title,
closable:true,
//href:tab_href
content:""
});
}
});
})
title="生成工资条"
data-options="{
closed:true,
modal:true,
buttons:[{
text:'生成',
iconCls:'icon-ok',
handler:function(){
$('#form1').form('submit',{
url:'PayDateServlet',//把定义的默认值是add的添加的方法传给Servlet然后判断
onSubmit:function(){
var isValid = $(this).form('validate');
if(!isValid)
{
$.messager.show({
title:'消息',
msg:'数据验证未通过'
});
}
else
{
//进度对话框
$.messager.progress(
{
title:'进度条',
msg:'工资加载中。。。',
text:'请稍后。。。',
interval:1000
}
);
}
return isValid;//
},
success:function(data){
var msg = eval('('+ data +')');//eval是js的方法
if(!msg.success)
{
alert(msg.message);
}
else
{
$.messager.progress('close');
$.messager.show({
title:'消息',
msg:'数据验证通过,保存成功'
});
$('#gz').dialog('close');
}
}
});
}
},
{
text:'取消',
iconCls:'icon-cancel',
handler:function(){$('#gz').dialog('close')},
}]
}"
>
生成工资条:
name="date"
data-options="
url:'PayServlet',
valueField:'payID',
textField:'payMonth',
onSelect:function(r){$('#date').combobox('setValue',r.payMonth.toString());}">
获取下拉框月份的Servlet层
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//转码
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
//调用底层查询表月份的集合
SPayDAO sp = new SPayDAO();
List lss = sp.getMonth();
//System.out.println(lss);
List ls = new ArrayList();
for(int i=0;i
{
Month m = new Month();
m.setPayID(i);
m.setPayMonth(lss.get(i).toString());
ls.add(m);
}
String json = JSONArray.toJSONString(ls);
response.getWriter().println(json);
}
提交from表单的select层
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//转码
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
//接受月份
String date = request.getParameter("date");
System.out.println("date="+date);
String msg = "{'success':true,'message':'保存成功'}";
if(date != null)
{
try
{
SPayDAO sp = new SPayDAO();
sp.unite(date);
}
catch(Exception e)
{
msg = "{'success':false,'message':'访问失败'}";
}
response.getWriter().print(msg);
}
else
{
msg = "{'success':false,'message':'没有要生成的工资'}";
response.getWriter().print(msg);
}
}
DAO层
package com.hanqi.dao;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import com.hanqi.entity.Basic;
import com.hanqi.entity.Deal;
import com.hanqi.entity.KqMonthkaoqin;
import com.hanqi.entity.Rank;
import com.hanqi.entity.Rate;
import com.hanqi.entity.SPay;
public class SPayDAO {
Configuration cfg = null;
ServiceRegistry sr = null;
SessionFactory sf = null;
Session se =null;
Transaction tr = null;
public SPayDAO()//注册服务
{
//1.加载配置文件
cfg = new Configuration().configure();
//2.注册服务
sr = new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties()).build();
}
//初始化
private void init()
{
try
{
sf= cfg.buildSessionFactory(sr);
}
catch(Exception e)
{
//1.加载配置文件
cfg = new Configuration().configure();
//2.注册服务
sr = new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties()).build();
sf= cfg.buildSessionFactory(sr);
}
se = sf.openSession();
tr = se.beginTransaction();//启动事物
}
//提交和释放
private void destroy()
{
try
{
tr.commit();//提交事务
}
catch(Exception e)
{
//1.加载配置文件
cfg = new Configuration().configure();
//2.注册服务
sr = new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties()).build();
sf= cfg.buildSessionFactory(sr);
se = sf.openSession();
tr = se.beginTransaction();
tr.commit();//提交事务
}
se.close();
sf.close();
}
//联合查询
public void unite(String date)
{
double zhengchang = getZhengchangJiaban();
double zhoumo = getzhoumo();
double jiaqi = getJiaqi();
double chidao = getChidao ();
double zaotui = getZaotui();
double kuanggong = getKuanggong();
List rate = getRate();
init();
System.out.println("uwef="+date);
List lb = se.createQuery("from KqMonthkaoqin where zhuangtai= 0 and to_char(kaoqinmonth,'yyyy-MM')=?")
.setString(0, date).list() ;
System.out.println(lb);
SPay sp = new SPay();
for(KqMonthkaoqin k : lb)
{
sp.setPayid(date+k.getStaffid());//获取并写入工资表的薪资编号
sp.setYuangongid(k.getStaffid());//获取员工id
sp.setEmployeename(getName(k.getStaffid()));;//员工姓名
//基本工资
double jb = getSalary(Integer.parseInt(getLevels(k.getStaffid())));
sp.setJibengongzi( jb);
//加班总金额
double zc = zhengchang*k.getJiaban();
double zm = zhoumo*k.getZhoumojiaban();
double jq = jiaqi*(k.getJiejiarijiaban());
double z = zc+zm+jq ;
sp.setJiaban(z);
//请假
sp.setQingjia(k.getQingjia());
//迟到
sp.setChidao(chidao*(k.getChidao()));
//早退
sp.setZaotui(zaotui*(k.getZaotui()));
//旷工
sp.setKuanggong(kuanggong*k.getKuanggong());
//五险
sp.setWuxian(jb*0.1);
//公积金
sp.setGongjijin(jb*0.08);
//全勤
if(k.getChidao()!=0 || k.getZaotui() != 0 || k.getQingjia() != 0 ||k.getKuanggong() !=0)
{
sp.setQuanqin(getquanqin());
}
else
{
sp.setQuanqin(0);
}
//应发工资
double yingfa = jb+z-(jb*0.1+jb*0.08);
sp.setYingfa(yingfa);
//纳税
double nashui = 0;
//判断是否纳税
if(yingfa-rate.get(0).getStartpay()<=0)
{
}
else
{
for(int i=0; i
{
double qzd = rate.get(i).getStartpay();
double money = rate.get(i).getMoney();
double tax = rate.get(i).getTax();
double kouchu = rate.get(i).getKouchu();
if(yingfa-qzd
{
nashui=((yingfa-qzd)*tax-kouchu);
System.out.println("起征点="+qzd);
System.out.println("应纳税所得额="+money);
System.out.println("税率="+tax);
System.out.println("扣除数="+kouchu);
break;
}
}
sp.setNashui(nashui);
}
//实发工资
sp.setShifa((jb+z-(jb*0.1+jb*0.08))-nashui);
sp.setZhuangtai('0');
sp.setHedui('0');
getSave(sp);
getzhuangtai(k.getId());//调用更改考勤表状态的方法
}
destroy();
}
//提交保存SPay
public void getSave(SPay spay)
{
init();
se.save(spay);
destroy();
}
//改变考勤表的状态
public void getzhuangtai(String id)
{
init();
KqMonthkaoqin kaoqin = (KqMonthkaoqin)se.get(KqMonthkaoqin.class, id);
kaoqin.setZhuangtai(1);
destroy();
}
//查询Rate税率表
public List getRate()
{
init();
List rtn = new ArrayList();
rtn=se.createQuery("from Rate order by money asc").list();
destroy();
return rtn;
}
//查询考勤表里状态是0 的月份
public List getMonth()
{
init();
List li = new ArrayList();
li = se.createQuery("select distinct to_char(kaoqinmonth,'yyyy-MM') from KqMonthkaoqin where zhuangtai='0' ").list();
destroy();
return li;
}
//根据考勤表的员工id查询员工表的姓名
public String getName(String yuangongid)
{
init();
String rtn = "";
List li = new ArrayList();
li = se.createQuery("select name from Basic where yuangongid = ? ")
.setString(0, yuangongid)
.list() ;
if(li.size()>0)
{
rtn = li.get(0).toString();
}
destroy();
destroy();
return rtn;
}
//根据员工编号查询员工等级
public String getLevels(String yuangongid)
{
init();
String rtn = "";
List li = new ArrayList();
li = se.createQuery("select jibie from Basic where yuangongid = ? and zhuangtai = '在职'")
.setString(0, yuangongid)
.list() ;
if(li.size()>0)
{
rtn = li.get(0).toString();
}
destroy();
return rtn;
}
//根据等级查询员工基本工资
public int getSalary(int levels)
{
init();
int rtn =0;
List li = new ArrayList();
li = se.createQuery("select salary from Rank where levels = ?")
.setLong(0, levels).list();
if(li.size()>0)
{
rtn = Integer.parseInt(li.get(0).toString());
}
destroy();
return rtn;
}
//查询全勤奖励
public int getquanqin()
{
int rtn =0;
init();
List li = new ArrayList();
li = se.createQuery("select quanqin from Deal where state='1'")
.list();
System.out.println("list.size = " + li.size());
if(li.size()>0)
{
rtn = (Integer.parseInt(li.get(0).toString()));
}
destroy();
return rtn;
}
//获取Deal表的正常加班单价
public int getZhengchangJiaban()
{
int rtn =0;
init();
List li = new ArrayList();
//查询启用状态下正常加班的金额
li = se.createQuery("select zhengban from Deal where state='1'")
.list();
if(li.size()>0)
{
rtn = (Integer.parseInt(li.get(0).toString()));
}
destroy();
return rtn;
}
//获取周末加班单价
public int getzhoumo()
{
int rtn =0;
init();
List li = new ArrayList();
//查询启用状态下周末加班的金额
li = se.createQuery("select zhouban from Deal where state='1'")
.list();
if(li.size()>0)
{
rtn = (Integer.parseInt(li.get(0).toString()));
}
destroy();
return rtn;
}
//获取节假日加班
public int getJiaqi()
{
int rtn =0;
init();
List li = new ArrayList();
//查询启用状态下节假日加班的金额
li = se.createQuery("select jieban from Deal where state='1'")
.list();
if(li.size()>0)
{
rtn = (Integer.parseInt(li.get(0).toString()));
}
destroy();
return rtn;
}
//获取迟到金额
public int getChidao ()
{
int rtn =0;
init();
List li = new ArrayList();
//查询启用状态下迟到一次的金额
li = se.createQuery("select chidao from Deal where state='1'")
.list();
if(li.size()>0)
{
rtn = (Integer.parseInt(li.get(0).toString()));
}
destroy();
return rtn;
}
//获取早退
public int getZaotui()
{
int rtn =0;
init();
List li = new ArrayList();
//查询启用状态下迟到一次的金额
li = se.createQuery("select zaotui from Deal where state='1'")
.list();
if(li.size()>0)
{
rtn = (Integer.parseInt(li.get(0).toString()));
}
destroy();
return rtn;
}
//获取旷工
public int getKuanggong()
{
int rtn =0;
init();
List li = new ArrayList();
//查询启用状态下旷工一次的金额
li = se.createQuery("select kuanggong from Deal where state='1'")
.list();
if(li.size()>0)
{
rtn = (Integer.parseInt(li.get(0).toString()));
}
destroy();
return rtn;
}
//获取分页数据集合列表
public List getPageList(int page , int rows,String sort,Map where)
{
init();
//创建基础HQL语句
String sql = "from SPay where 1=1";
//判断传递的的参数
String yuangongid = where.get("yuangongid_s");
if(yuangongid != null && !yuangongid.equals(""))
{
sql += " and yuangongid ";
}
//排序
if(sort != null && !sort.equals(""))
{
sql += " order by " + sort;
}
//得到HQL
//并判断查询条件
Query q = se.createQuery(sql);
if(yuangongid != null && !yuangongid.equals("") )
{
q.setString("yuangongid", yuangongid);//引号的内容必须跟上面引号后的别名一致
}
System.out.println("yuangongid="+yuangongid);
List rtn = new ArrayList();
rtn = q.setMaxResults(rows)//每页行数
.setFirstResult((page-1)*rows).list();//其实页码
destroy();
return rtn;
}
//获取数据条数
public int getTotal(Map where)
{
int rtn= 0;
init();
//创建基础HQL语句
String sql = "select count(1) from SPay where 1=1";
//判断传递的的参数
String yuangongid_s = where.get("yuangongid_s");
if(yuangongid_s != null && !yuangongid_s.equals(""))
{
sql += " and yuangongid )";//and前面加空格
}
//得到HQL
//并判断查询条件
Query q = se.createQuery(sql);
if(yuangongid_s != null && !yuangongid_s.equals("") )
{
q.setString("yuangongid", yuangongid_s);
//引号的内容必须跟上面引号后的别名一致
}
//获取Query对对象,定义集合并实例化
List lo = q.list();
if(lo != null && lo.size() > 0)
{
rtn = Integer.parseInt(lo.get(0).toString());//转换成int并赋值
}
destroy();
return rtn;
}
}
DAO层主要是围绕着联合查询这个方法来的,通过给中小方法,获取其他表的数据,生成工资表SPay中的各个字段,然后添加,也就是一个添加的过程。
这个项目所遇到的一些问题:代码优化,逻辑还不够严谨。
这篇关于用mysql生成工资条_薪酬模块生成工资条的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!