123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- package Salary
- import (
- "ERP_salary/logs"
- "ERP_salary/models/Account"
- "fmt"
- "github.com/beego/beego/v2/adapter/orm"
- orm2 "github.com/beego/beego/v2/client/orm"
- "github.com/shopspring/decimal"
- "gogs.baozhida.cn/zoie/ERP_libs/lib"
- "time"
- )
- // 考勤
- type Salary struct {
- Id int `orm:"column(ID);size(11);auto;pk"`
- T_uid string `orm:"index;size(64);null"` // 用户uuid
- T_date string `orm:"index;size(64);null"` // 记薪周期,2023-03
- T_base float32 `orm:"digits(12);decimals(2)"` // 基础工资
- T_post float32 `orm:"digits(12);decimals(2)"` // 岗位工资
- T_seniority float32 `orm:"digits(12);decimals(2)"` // 工龄工资
- T_perf float32 `orm:"digits(12);decimals(2)"` // 绩效金额
- T_perf_score int `orm:"size(20);default(100)"` // 绩效得分 百分制
- T_back_payment float32 `orm:"digits(12);decimals(2)"` // 其他补款
- T_attendance float32 `orm:"digits(12);decimals(2)"` // 考勤扣款
- T_cut_payment float32 `orm:"digits(12);decimals(2)"` // 其他扣款
- T_pension_insurance float32 `orm:"digits(12);decimals(2)"` // 需缴养老保险
- T_unemployment_insurance float32 `orm:"digits(12);decimals(2)"` // 需缴纳失业保险
- T_medical_insurance float32 `orm:"digits(12);decimals(2)"` // 需缴医疗保险
- T_large_medical_insurance float32 `orm:"digits(12);decimals(2)"` // 需缴大额医疗保险
- T_housing_fund float32 `orm:"digits(12);decimals(2)"` // 需缴住房公积金MergeCell
- T_tax float32 `orm:"digits(12);decimals(2)"` // 需缴个人所得税
- T_remark string `orm:"type(text);null"`
- T_State int `orm:"size(20);default(1)"` // 1 未发送 2 已发送 3-未提交
- CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
- UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now 每次 model 保存时都会对时间自动更新
- }
- func (t *Salary) TableName() string {
- return "salary"
- }
- func init() {
- //注册模型
- orm2.Debug = true
- orm.RegisterModel(new(Salary))
- }
- type Salary_R struct {
- Id int
- T_uid string // 用户uuid
- T_user_name string // 员工名称
- T_user_dept string // 部门
- T_user_post string // 岗位
- T_date string // 记薪周期,2023-03
- T_base float32 // 基础工资
- T_post float32 // 岗位工资
- T_seniority float32 // 工龄工资
- T_perf float32 // 绩效金额
- T_perf_score int // 绩效得分
- T_actual_Perf float32 // 实发绩效
- T_back_payment float32 // 其他补款
- T_attendance float32 // 考勤扣款
- T_cut_payment float32 // 其他扣款
- T_laballot float32 // 应发合计=基本工资+岗位工资+工龄工资+实发绩效+其他补款-考勤扣款-其他扣款
- T_pension_insurance float32 // 需缴养老保险
- T_unemployment_insurance float32 // 需缴纳失业保险
- T_medical_insurance float32 // 需缴医疗保险
- T_large_medical_insurance float32 // 需缴大额医疗保险
- T_housing_fund float32 // 需缴住房公积金
- T_tax float32 // 需缴个人所得税
- T_laborage float32 // 扣款合计=养老保险+失业保险+基本医疗保险+大额医疗保险+公积金+个税扣款
- T_total float32 // 实发合计
- T_remark string // 备注
- T_State int
- }
- // ---------------- 特殊方法 -------------------
- func SalaryToSalary_R(t Salary) (r Salary_R) {
- r.Id = t.Id
- r.T_uid = t.T_uid
- r.T_user_name = Account.Read_User_T_name_Get(t.T_uid)
- r.T_user_dept = Account.Read_User_T_dept_Get(t.T_uid)
- r.T_user_post = Account.Read_User_T_post_Get(t.T_uid)
- r.T_date = t.T_date
- r.T_base = t.T_base
- r.T_post = t.T_post
- r.T_seniority = t.T_seniority
- r.T_perf = t.T_perf
- r.T_perf_score = t.T_perf_score
- r.T_actual_Perf = t.T_perf * float32(t.T_perf_score/100)
- r.T_back_payment = t.T_back_payment
- r.T_attendance = t.T_attendance
- r.T_cut_payment = t.T_cut_payment
- // 应发合计=基本工资+岗位工资+工龄工资+实发绩效+其他补款-考勤扣款-其他扣款
- T_laballot := t.T_base + t.T_post + t.T_seniority + r.T_actual_Perf + t.T_back_payment - t.T_attendance - t.T_cut_payment
- T_laballot64, _ := decimal.NewFromFloat32(T_laballot).Round(2).Float64()
- r.T_laballot = float32(T_laballot64)
- r.T_pension_insurance = t.T_pension_insurance
- r.T_unemployment_insurance = t.T_unemployment_insurance
- r.T_medical_insurance = t.T_medical_insurance
- r.T_large_medical_insurance = t.T_large_medical_insurance
- r.T_housing_fund = t.T_housing_fund
- r.T_tax = t.T_tax
- // 扣款合计=养老保险+失业保险+基本医疗保险+大额医疗保险+公积金+个税扣款
- T_laborage := t.T_pension_insurance + t.T_unemployment_insurance + t.T_medical_insurance + t.T_large_medical_insurance + t.T_housing_fund + t.T_tax
- T_laborage64, _ := decimal.NewFromFloat32(T_laborage).Round(2).Float64()
- r.T_laborage = float32(T_laborage64)
- T_total := r.T_laballot - r.T_laborage
- T_total64, _ := decimal.NewFromFloat32(T_total).Round(2).Float64()
- r.T_total = float32(T_total64)
- r.T_remark = t.T_remark
- r.T_State = t.T_State
- return r
- }
- // 获取 ById
- func Read_Salary_ById(id int) (r Salary, err error) {
- o := orm.NewOrm()
- r = Salary{Id: id}
- err = o.Read(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return r, err
- }
- return r, err
- }
- func Read_Salary_ByT_uuid_T_date(T_uuid, T_date string) (r Salary, err error) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(Salary))
- //r = Salary{T_uid: T_uuid, T_date: T_date}
- //err = o.Read(&r, "T_uid", "T_date")
- err = qs.Filter("T_uid", T_uuid).Filter("T_date", T_date).One(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return r, err
- }
- return r, err
- }
- func Read_Salary_ByT_date(T_uuid, T_date string) (r Salary, err error) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(Salary))
- //r = Salary{T_uid: T_uuid, T_date: T_date}
- //err = o.Read(&r, "T_uid", "T_date")
- err = qs.Filter("T_uid", T_uuid).Filter("T_date", T_date).Filter("T_State", 2).One(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return r, err
- }
- return r, err
- }
- // 添加
- func Add_Salary(m Salary) (id int, err error) {
- o := orm.NewOrm()
- _, err = o.Insert(&m)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- id = m.Id
- return
- }
- // 修改
- func Update_Salary(m Salary, cols ...string) (id int64, err error) {
- o := orm.NewOrm()
- id, err = o.Update(&m, cols...)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- fmt.Println("Number of records updated in database:", id)
- return id, nil
- }
- // 发送工资条
- func Send_Salary(m Salary) (id int64, err error) {
- m.T_State = 2
- o := orm.NewOrm()
- id, err = o.Update(&m, "T_State")
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- fmt.Println("Number of records updated in database:", id)
- return id, nil
- }
- // 获取列表
- func Read_Salary_List(T_uid, T_date string, T_state, page, page_z int) (r []Salary_R, cnt int64) {
- o := orm.NewOrm()
- // 也可以直接使用 Model 结构体作为表名
- var map_r []Salary
- qs := o.QueryTable(new(Salary))
- var offset int64
- if page <= 1 {
- offset = 0
- } else {
- offset = int64((page - 1) * page_z)
- }
- cond := orm.NewCondition()
- if len(T_uid) > 0 {
- cond = cond.And("T_uid", T_uid)
- }
- if len(T_date) > 0 {
- cond = cond.And("T_date", T_date)
- }
- if T_state == 2 {
- cond = cond.And("T_State", T_state)
- }
- var err error
- if page_z == 9999 {
- _, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&map_r)
- } else {
- _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&map_r)
- }
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- for _, v := range map_r {
- r = append(r, SalaryToSalary_R(v))
- }
- return r, cnt
- }
- // 获取列表
- func Read_Latest_Salary_ByT_uid(T_uid string) (r Salary_R, err error) {
- o := orm.NewOrm()
- // 也可以直接使用 Model 结构体作为表名
- var map_r []Salary
- qs := o.QueryTable(new(Salary))
- _, err = qs.Limit(1, 0).Filter("T_uid", T_uid).OrderBy("-T_date").All(&map_r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- if len(map_r) == 0 {
- return
- }
- return SalaryToSalary_R(map_r[0]), nil
- }
|