package model

import (
	"git.u8t.cn/open/gosdk/qyweixin"
	"github.com/smbrave/goutil"
	"github.com/spf13/cast"
	"strings"
	"time"
)

var (
	ApprovalRefundStatusCreated = 1
	ApprovalRefundStatusPayed   = 2
	ApprovalTypeRefund          = "refund"
	ApprovalTypeCheckin         = "checkin"
	ApprovalTypeVacation        = "vacation"
	ApprovalTypePayment         = "payment"
)

type ApprovalRefund struct {
	Id           int64
	CorpId       int64
	Username     string
	Month        string
	SpNo         string
	CostSubject  string
	RefundType   string
	RefundDate   string
	RefundAmount float64
	RefundRemark string
	ApplyTime    string
	Status       int
	CreateTime   int64
	UpdateTime   int64
}

func (refund *ApprovalRefund) From(d *qyweixin.ApproveDetail) {
	refund.SpNo = d.SpNo
	refund.Username = strings.ToLower(d.GetUserid())
	refund.ApplyTime = goutil.TimeToDateTime(d.ApplyTime)
	refund.Status = ApprovalRefundStatusCreated
	refund.RefundType = d.GetValue("报销类型")
	refund.CostSubject = d.GetValue("成本主体")
	refundTime := cast.ToInt64(d.GetValue("发生时间"))
	refund.Month = time.Unix(refundTime, 0).Format("200601")
	refund.RefundDate = goutil.TimeToDateTime(refundTime)
	refund.RefundAmount = cast.ToFloat64(d.GetValue("报销费用"))
	refund.RefundRemark = d.GetValue("报销说明")
}