Browse Source

update:财务扣除

zoie 1 year ago
parent
commit
2a626841ee
5 changed files with 67 additions and 29 deletions
  1. 1 1
      controllers/Overtime.go
  2. 28 7
      controllers/leave.go
  3. 11 10
      main.go
  4. 19 6
      models/Attendance/Attendance.go
  5. 8 5
      models/Attendance/AttendanceType.go

+ 1 - 1
controllers/Overtime.go

@@ -288,7 +288,7 @@ func (c *OvertimeController) Overtime_Stat() {
 	Account.Read_User_All_Map(userList)
 	var duration int
 	for i := 0; i < len(attendance); i++ {
-		if attendance[i].T_type == Attendance.AttendanceDaysOff || attendance[i].T_type == Attendance.AttendanceShiftPerf {
+		if attendance[i].T_type == Attendance.AttendanceDaysOff || attendance[i].T_type == Attendance.AttendanceShiftPerf || attendance[i].T_type > 100 {
 			duration -= attendance[i].T_duration
 			attendance[i].T_duration = -attendance[i].T_duration
 		} else {

+ 28 - 7
controllers/leave.go

@@ -101,7 +101,9 @@ func (c *LeaveController) Leave_Finance_List() {
 }
 
 func (c *LeaveController) Leave_Type_List() {
-	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Attendance.Read_AttendanceType_All()}
+	T_deduct, _ := c.GetInt("T_deduct")
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Attendance.Read_AttendanceType_All(T_deduct)}
 	c.ServeJSON()
 	return
 }
@@ -165,16 +167,35 @@ func (c *LeaveController) Leave_Add() {
 func (c *LeaveController) Leave_Deduct() {
 	T_type, _ := c.GetInt("T_type")
 	T_duration, _ := c.GetInt("T_duration")
+	T_month := c.GetString("T_month")
 	T_text := c.GetString("T_text")
 	T_uuid := c.GetString("T_uuid")
 
+	month, is := lib.MonthStrToTime(T_month)
+	if !is {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式不正确"}
+		c.ServeJSON()
+		return
+	}
+
+	duration := Attendance.GetRemainingDaysOff(c.User.T_uuid)
+	if T_duration > duration {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "超过加班总时长!"}
+		c.ServeJSON()
+		return
+	}
+
+	month = month.AddDate(0, 1, -1)
+
 	var_ := Attendance.Attendance{
-		T_uid:      T_uuid,
-		T_type:     T_type,
-		T_duration: T_duration,
-		T_text:     T_text,
-		T_approver: c.User.T_uuid,
-		T_State:    Attendance.AttendancePass,
+		T_uid:        T_uuid,
+		T_type:       T_type + 100,
+		T_duration:   T_duration,
+		T_text:       T_text,
+		T_approver:   c.User.T_uuid,
+		T_start_time: month,
+		T_end_time:   month,
+		T_State:      Attendance.AttendancePass,
 	}
 
 	Id, err := Attendance.Add_Attendance(var_)

+ 11 - 10
main.go

@@ -48,7 +48,7 @@ func main() {
 
 	beego.BConfig.AppName = appname              // 项目名
 	beego.BConfig.ServerName = appname           //server  名称
-	beego.BConfig.RunMode = "dev"                //  应用的运行模式
+	beego.BConfig.RunMode = conf.RunMode         //  应用的运行模式
 	beego.BConfig.Listen.HTTPPort = HTTPPort_int //监听端口  本地:8518  线上:8528
 	beego.BConfig.WebConfig.AutoRender = false
 	beego.BConfig.RecoverPanic = true
@@ -72,15 +72,16 @@ func RecoverPanic(ctx *context.Context, config *beego.Config) {
 		}
 		//显示错误
 		data := map[string]interface{}{
-			"ret":           4000,
-			"AppError":      fmt.Sprintf("%v", err),
-			"RequestMethod": ctx.Input.Method(),
-			"RequestURL":    ctx.Input.URI(),
-			"RemoteAddr":    ctx.Input.IP(),
-			"Stack":         stack,
-			"GoVersion":     runtime.Version(),
-			"Code":          500,
-			"Msg":           "请稍后重试!",
+			"AppError": fmt.Sprintf("%v", err),
+			"Code":     500,
+			"Msg":      "请稍后重试!",
+		}
+		if conf.RunMode == "dev" {
+			data["RequestMethod"] = ctx.Input.Method()
+			data["RequestURL"] = ctx.Input.URI()
+			data["RemoteAddr"] = ctx.Input.IP()
+			data["Stack"] = stack
+			data["GoVersion"] = runtime.Version()
 		}
 		_ = ctx.Output.JSON(data, true, true)
 		//if ctx.Output.Status != 0 {

+ 19 - 6
models/Attendance/Attendance.go

@@ -80,7 +80,11 @@ func AttendanceToAttendance_R(t Attendance) (r Attendance_R) {
 	r.Id = t.Id
 	r.T_uid = t.T_uid
 	r.T_type = t.T_type
-	r.T_type_name = Read_AttendanceType_Get(t.T_type)
+	T_type_name := Read_AttendanceType_Get(t.T_type)
+	if t.T_type > 100 {
+		T_type_name = "扣除-" + Read_AttendanceType_Get(t.T_type-100)
+	}
+	r.T_type_name = T_type_name
 	r.T_user_name = Account.Read_User_T_name_Get(t.T_uid)
 	r.T_start_time = t.T_start_time.Format("2006-01-02 15:04:05")
 	r.T_prove_img = t.T_prove_img
@@ -91,13 +95,21 @@ func AttendanceToAttendance_R(t Attendance) (r Attendance_R) {
 	r.T_approver_name = Account.Read_User_T_name_Get(t.T_approver)
 	r.T_State = t.T_State
 	r.UpdateTime = t.UpdateTime.Format("2006-01-02 15:04:05")
+	if t.T_type > 100 {
+		r.T_start_time = "-"
+		r.T_end_time = "-"
+	}
 	return r
 }
 
 func AttendanceToAttendance_S(t Attendance) (r Attendance_S) {
 	r.Id = t.Id
 	r.T_type = t.T_type
-	r.T_type_name = Read_AttendanceType_Get(t.T_type)
+	T_type_name := Read_AttendanceType_Get(t.T_type)
+	if t.T_type > 100 {
+		T_type_name = "扣除-" + Read_AttendanceType_Get(t.T_type-100)
+	}
+	r.T_type_name = T_type_name
 	r.T_duration = t.T_duration
 	r.T_text = t.T_text
 	r.T_approver = t.T_approver
@@ -268,7 +280,8 @@ func Read_Attendance_List_For_Finance(T_uid, T_month string) (r []Attendance_R)
 	}
 
 	list := Get_LeaveType_List()
-	cond = cond.And("T_State", AttendancePass).And("T_uid", T_uid).And("T_type__in", list).
+	cond = cond.And("T_State", AttendancePass).And("T_uid", T_uid).
+		AndCond(cond.Or("T_type__in", list).Or("T_type__gt", 100)).
 		AndCond(cond.Or("T_start_time__startswith", T_month).Or("T_end_time__startswith", T_month))
 
 	_, err := qs.SetCond((*orm2.Condition)(cond)).OrderBy("Id").All(&map_r)
@@ -323,13 +336,13 @@ func Read_Attendance_List_For_Stat(T_uid string, page, page_z int) (r []Attendan
 	var T_type_list = []int{AttendanceOvertime, AttendanceDaysOff, AttendanceShiftPerf}
 
 	cond := orm.NewCondition()
-	cond = cond.And("T_State__gt", AttendanceDelete).And("T_uid", T_uid).And("T_State", AttendancePass).And("T_type__in", T_type_list)
+	cond = cond.And("T_uid", T_uid).And("T_State", AttendancePass).
+		AndCond(cond.Or("T_type__in", T_type_list).Or("T_type__gt", 100))
 
 	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)
 	}
 
@@ -356,7 +369,7 @@ func GetRemainingDaysOff(T_uuid string) int {
 	var duration int
 	for i := 0; i < len(attendance); i++ {
 		// 调休,转绩效 减时长
-		if attendance[i].T_type == AttendanceDaysOff || attendance[i].T_type == AttendanceShiftPerf {
+		if attendance[i].T_type == AttendanceDaysOff || attendance[i].T_type == AttendanceShiftPerf || attendance[i].T_type > 100 {
 			duration -= attendance[i].T_duration
 		} else {
 			// 加班 加时长

+ 8 - 5
models/Attendance/AttendanceType.go

@@ -8,12 +8,12 @@ const (
 	AttendanceSick                 // 2 病假
 	AttendanceDaysOff              // 3 调休
 	AttendanceAnnual               // 4 年假
-	AttendanceShiftPerf            // 5 转绩效
 	AttendanceMarriage             // 婚假
 	AttendanceFuneral              // 丧假
 	AttendanceMaternity            // 产假
 	AttendanceBreastfeeding        // 哺乳假
 	Attendancepaternity            // 陪产假
+	AttendanceShiftPerf            // 5 转绩效
 
 )
 
@@ -29,12 +29,12 @@ var AttendanceType_list = map[int]string{
 	AttendancePersonal:      "事假",
 	AttendanceDaysOff:       "调休",
 	AttendanceAnnual:        "年假",
-	AttendanceShiftPerf:     "转绩效",
 	AttendanceFuneral:       "丧假",
 	AttendanceMarriage:      "婚假",
 	AttendanceMaternity:     "产假",
 	AttendanceBreastfeeding: "哺乳假",
 	Attendancepaternity:     "陪产假",
+	AttendanceShiftPerf:     "加班转绩效",
 }
 
 // 获取全部
@@ -48,10 +48,13 @@ func Read_AttendanceType_Get(id int) string {
 }
 
 // 获取全部
-func Read_AttendanceType_All() (r []AttendanceType) {
+func Read_AttendanceType_All(T_deduct int) (r []AttendanceType) {
 
 	for k, v := range AttendanceType_list {
-		if k == AttendanceOvertime || k == AttendanceShiftPerf {
+		if k == AttendanceOvertime {
+			continue
+		}
+		if T_deduct != 1 && k == AttendanceShiftPerf {
 			continue
 		}
 		r = append(r, AttendanceType{
@@ -68,7 +71,7 @@ func Read_AttendanceType_All() (r []AttendanceType) {
 func Get_LeaveType_List() (r []int) {
 
 	for k, _ := range AttendanceType_list {
-		if k == AttendanceOvertime || k == AttendanceShiftPerf {
+		if k == AttendanceOvertime {
 			continue
 		}
 		r = append(r, k)