薪资计算单位更新为float64

This commit is contained in:
pbrong
2021-04-27 15:46:41 +08:00
parent 2e8044db7f
commit b7b771ea6b
12 changed files with 67 additions and 47 deletions

View File

@@ -101,7 +101,7 @@ func Login(c *gin.Context) {
var loginDb model.Authority
var staff model.Staff
hrmsDB.Where("staff_id = ? and user_password = ?",
loginR.UserNo, loginR.UserPassword).First(&loginDb)
loginR.UserNo, service.MD5(loginR.UserPassword)).First(&loginDb)
if loginDb.StaffId != loginR.UserNo {
log.Printf("[handler.Login] user login fail, user = %v", loginR)
c.JSON(200, gin.H{

View File

@@ -153,7 +153,7 @@ func GetAttendRecordApproveByLeaderStaffId(c *gin.Context) {
// 审批通过考勤信息
func ApproveAccept(c *gin.Context) {
attendId := c.Param("attendId")
if err := service.ApproveAccept(c, attendId); err != nil {
if err := service.Compute(c, attendId); err != nil {
c.JSON(200, gin.H{
"status": 5000,
"err": err,

View File

@@ -89,7 +89,7 @@ func PasswordEdit(c *gin.Context) {
return
}
staffId := passwordEditDTO.StaffId
password := passwordEditDTO.Password
password := service.MD5(passwordEditDTO.Password)
if err := resource.HrmsDB(c).Where("staff_id = ?", staffId).Updates(&model.Authority{
UserPassword: password,
}).Error; err != nil {

View File

@@ -61,9 +61,9 @@ func StaffCreate(c *gin.Context) {
login := model.Authority{
AuthorityId: service.RandomID("auth"),
StaffId: staffId,
UserPassword: staff.IdentityNum[identLen-6 : identLen],
Aval: 1,
UserType: "normal", // 暂时只能创建普通员工
UserPassword: service.MD5(staff.IdentityNum[identLen-6 : identLen]),
//Aval: 1,
UserType: "normal", // 暂时只能创建普通员工
}
err := resource.HrmsDB(c).Transaction(func(tx *gorm.DB) error {
if err := tx.Create(&staff).Error; err != nil {

View File

@@ -15,8 +15,8 @@ type Authority struct {
AuthorityId string `gorm:"column:authority_id" json:"authority_id"`
StaffId string `gorm:"column:staff_id" json:"staff_id"`
UserPassword string `gorm:"column:user_password" json:"user_password"`
Aval int64 `gorm:"column:aval" json:"aval"`
UserType string `gorm:"column:user_type" json:"user_type"`
//Aval int64 `gorm:"column:aval" json:"aval"`
UserType string `gorm:"column:user_type" json:"user_type"`
}
type PasswordQueryVO struct {

View File

@@ -1,6 +1,8 @@
package model
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
httpReq "github.com/kirinlabs/HttpRequest"
@@ -86,10 +88,9 @@ func TestSMS(t *testing.T) {
}
func TestComputeSalary(t *testing.T) {
leaveDays := 2
var bonus int64 = 500
x := float64(5-leaveDays) / 5.0
bonus = int64(float64(bonus) * x)
fmt.Println(x)
fmt.Println(bonus)
data := []byte("215517test")
md5Ctx := md5.New()
md5Ctx.Write(data)
cipherStr := md5Ctx.Sum(nil)
fmt.Println(hex.EncodeToString(cipherStr))
}

View File

@@ -42,21 +42,21 @@ type SalaryEditDTO struct {
type SalaryRecord struct {
gorm.Model
SalaryRecordId string `gorm:"column:salary_record_id" json:"salary_record_id"`
StaffId string `gorm:"column:staff_id" json:"staff_id"`
StaffName string `gorm:"column:staff_name" json:"staff_name"`
Base int64 `gorm:"column:base" json:"base"`
Subsidy int64 `gorm:"column:subsidy" json:"subsidy"`
Bonus int64 `gorm:"column:bonus" json:"bonus"`
Commission int64 `gorm:"column:commission" json:"commission"`
Other int64 `gorm:"column:other" json:"other"`
PensionInsurance int64 `gorm:"column:pension_insurance" json:"pension_insurance"`
UnemploymentInsurance int64 `gorm:"column:unemployment_insurance" json:"unemployment_insurance"`
MedicalInsurance int64 `gorm:"column:medical_insurance" json:"medical_insurance"`
HousingFund int64 `gorm:"column:housing_fund" json:"housing_fund"`
Tax int64 `gorm:"column:tax" json:"tax"`
Overtime int64 `gorm:"column:overtime" json:"overtime"`
Total int64 `gorm:"column:total" json:"total"`
IsPay int64 `gorm:"column:is_pay" json:"is_pay"`
SalaryDate string `gorm:"column:salary_date" json:"salary_date"`
SalaryRecordId string `gorm:"column:salary_record_id" json:"salary_record_id"`
StaffId string `gorm:"column:staff_id" json:"staff_id"`
StaffName string `gorm:"column:staff_name" json:"staff_name"`
Base int64 `gorm:"column:base" json:"base"`
Subsidy int64 `gorm:"column:subsidy" json:"subsidy"`
Bonus int64 `gorm:"column:bonus" json:"bonus"`
Commission int64 `gorm:"column:commission" json:"commission"`
Other int64 `gorm:"column:other" json:"other"`
PensionInsurance float64 `gorm:"column:pension_insurance" json:"pension_insurance"`
UnemploymentInsurance float64 `gorm:"column:unemployment_insurance" json:"unemployment_insurance"`
MedicalInsurance float64 `gorm:"column:medical_insurance" json:"medical_insurance"`
HousingFund float64 `gorm:"column:housing_fund" json:"housing_fund"`
Tax float64 `gorm:"column:tax" json:"tax"`
Overtime int64 `gorm:"column:overtime" json:"overtime"`
Total float64 `gorm:"column:total" json:"total"`
IsPay int64 `gorm:"column:is_pay" json:"is_pay"`
SalaryDate string `gorm:"column:salary_date" json:"salary_date"`
}

View File

@@ -151,7 +151,7 @@ func GetAttendRecordApproveByLeaderStaffId(c *gin.Context, leaderStaffId string)
}
// 通过考勤审批信息,修改考勤信息为通过,并且按该员工工资套账进行相应的薪资详情计算,得到五险一金税后薪资
func ApproveAccept(c *gin.Context, attendId string) error {
func Compute(c *gin.Context, attendId string) error {
err := resource.HrmsDB(c).Transaction(func(tx *gorm.DB) error {
// 更新考勤信息为审批通过状态
if err := tx.Model(&model.AttendanceRecord{}).Where("attendance_id = ?", attendId).Update("approve", 1).Error; err != nil {
@@ -195,7 +195,7 @@ func ApproveAccept(c *gin.Context, attendId string) error {
overtimeSalary := int64((float64(base) / getCurMonthWorkdays()) * 2.0 * float64(overtimeDays))
// 判断是否交五险一金,不交的话不计算三险
salaryRecord := model.SalaryRecord{}
amount := overtimeSalary + base + subsidy + bonus + commission + other
amount := float64(overtimeSalary + base + subsidy + bonus + commission + other)
if fund == 1 {
// 缴纳五险一金,计算个人需缴纳养老保险、失业保险和医疗保险及住房公积金
//养老保险金: 800.00 (8%) 1900.00 (19%)
@@ -205,33 +205,33 @@ func ApproveAccept(c *gin.Context, attendId string) error {
//补充住房公积金: 0.00 (0%) 0.00 (0%)
//工伤保险金: 0 40.00 (0.4%)
///生育保险金: 0 80.00 (0.8%)
salaryRecord.PensionInsurance = int64(float64(amount) * 0.08)
salaryRecord.MedicalInsurance = int64(float64(amount) * 0.02)
salaryRecord.UnemploymentInsurance = int64(float64(amount) * 0.002)
salaryRecord.HousingFund = int64(float64(amount) * 0.12)
salaryRecord.PensionInsurance = amount * 0.08
salaryRecord.MedicalInsurance = amount * 0.02
salaryRecord.UnemploymentInsurance = amount * 0.002
salaryRecord.HousingFund = amount * 0.12
}
// 计算扣除三险及住房公积金后薪资,并以此计算扣税金额
amount = amount - salaryRecord.PensionInsurance - salaryRecord.MedicalInsurance -
salaryRecord.UnemploymentInsurance - salaryRecord.HousingFund
// 以最新税法起征点5000元计算七级扣税
var tax int64 = 0
var tax float64 = 0
if amount > 5000 {
total := amount - 5000
// 按法定税率扣税
if total <= 3000 {
tax = int64(float64(total) * 0.03)
tax = total * 0.03
} else if total <= 12000 {
tax = int64(float64(total)*0.10) - 210
tax = total*0.10 - 210
} else if total <= 25000 {
tax = int64(float64(total)*0.20) - 1410
tax = total*0.20 - 1410
} else if total <= 35000 {
tax = int64(float64(total)*0.25) - 2660
tax = total*0.25 - 2660
} else if total <= 55000 {
tax = int64(float64(total)*0.30) - 4410
tax = total*0.30 - 4410
} else if total <= 80000 {
tax = int64(float64(total)*0.35) - 7160
tax = total*0.35 - 7160
} else if total > 80000 {
tax = int64(float64(total)*0.45) - 15160
tax = total*0.45 - 15160
}
}
// 计算税后工资

View File

@@ -1,6 +1,8 @@
package service
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
@@ -120,6 +122,7 @@ func Transfer(from, to interface{}) error {
const SMS_URL = "https://api.apishop.net/communication/sms/send"
// 向指定手机号发放短信通知
func sendNoticeMsg(msgType string, phone int64, content []string) {
if phone == 0 || phone != 15521306934 {
// 给自己手机号发短信验证效果
@@ -149,3 +152,11 @@ func sendNoticeMsg(msgType string, phone int64, content []string) {
body, _ := resp.Body()
log.Printf("[sendNoticeMsg] resp = %v", string(body))
}
func MD5(input string) string {
data := []byte(input)
md5Ctx := md5.New()
md5Ctx.Write(data)
cipherStr := md5Ctx.Sum(nil)
return hex.EncodeToString(cipherStr)
}

View File

@@ -103,9 +103,15 @@ func PaySalaryRecordById(c *gin.Context, id int64) error {
date := salarys[0].SalaryDate
sendNoticeMsg("salary", getStaffPhoneByStaffId(c, salarys[0].StaffId), []string{date})
}
// 通过税务系统上报税款并将工资发放至员工银行卡中
payStaffSalaryAndTax(salarys[0])
return nil
}
func payStaffSalaryAndTax(record *model.SalaryRecord) {
// 需要对接银行系统及税务系统
}
func getStaffPhoneByStaffId(c *gin.Context, staffId string) int64 {
var staffs []*model.Staff
resource.HrmsDB(c).Where("staff_id = ?", staffId).Find(&staffs)

View File

@@ -88,7 +88,9 @@
{width: 60, title: '序号', sort: true, type:'numbers'},
{field: 'notice_title', width: 250, title: '通知标题'},
{field: 'type', width: 150, title: '通知类别'},
{field: 'date', width: 170, title: '生效日期'},
{field: 'date', width: 170, title: '生效日期', templet: function(data) {
return data.date.slice(0, 10)
}},
{field: 'notice_content', width: 150, title: '通知内容'},
{title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center", fixed: 'right'}
]],

View File

@@ -231,7 +231,7 @@
form.on('submit(saveBtn)', function (req) {
req.field.base_salary = parseInt(req.field.base_salary)
req.field.phone = parseInt(req.field.phone)
alert(JSON.stringify(req.field))
// alert(JSON.stringify(req.field))
$.ajax({
type: "POST",
url: "/staff/create",