|
@@ -217,6 +217,24 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // 货币及汇率
|
|
|
+ rateList, e := fmsService.GetTodayCurrencyRateList()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("操作失败", "获取今日货币汇率失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var rate float64
|
|
|
+ for i := range rateList {
|
|
|
+ if req.CurrencyUnit == rateList[i].Code {
|
|
|
+ rate = rateList[i].RMBRate
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if rate <= 0 {
|
|
|
+ resp.FailMsg("操作失败", "货币汇率信息有误", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
nowTime := time.Now().Local()
|
|
|
ob.ContractCode = req.ContractCode
|
|
|
ob.RelateContractCode = req.RelateContractCode
|
|
@@ -229,6 +247,8 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
ob.SellerName = req.SellerName
|
|
|
ob.ContractType = req.ContractType
|
|
|
ob.ContractAmount = req.ContractAmount
|
|
|
+ ob.CurrencyUnit = req.CurrencyUnit
|
|
|
+ ob.RMBRate = rate
|
|
|
ob.StartDate = startDate
|
|
|
ob.EndDate = endDate
|
|
|
ob.SignDate = signDate
|
|
@@ -348,6 +368,11 @@ func (rg *RegisterController) Edit(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
originHasPayment := item.HasPayment
|
|
|
+ // TODO:确认是否允许修改货币单位,若可修改货币单位则需要相应的处理开票到款
|
|
|
+ if req.CurrencyUnit != item.CurrencyUnit {
|
|
|
+ resp.Fail("暂不允许修改货币单位", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
updateCols := []string{
|
|
|
"ContractCode", "RelateContractCode", "CrmContractId", "ContractSource", "CompanyName", "ActualCompanyName",
|
|
@@ -676,12 +701,13 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
|
|
|
resp.Fail("合同存在代付不允许添加开票/到款登记", c)
|
|
|
return
|
|
|
}
|
|
|
- // 合同有效时长
|
|
|
- dayDiff := item.EndDate.Sub(item.StartDate).Hours() / 24
|
|
|
|
|
|
noChangeInvoiceIds := make([]int, 0)
|
|
|
newInvoice := make([]*fms.ContractInvoice, 0)
|
|
|
if len(req.AmountList) > 0 {
|
|
|
+ // 合同有效时长(计算付款方式)
|
|
|
+ dayDiff := item.EndDate.Sub(item.StartDate).Hours() / 24
|
|
|
+
|
|
|
// 获取销售分组信息
|
|
|
sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
|
|
|
if e != nil {
|
|
@@ -714,12 +740,15 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
|
|
|
}
|
|
|
if req.AmountList[i].InvoiceId > 0 {
|
|
|
noChangeInvoiceIds = append(noChangeInvoiceIds, req.AmountList[i].InvoiceId)
|
|
|
+ continue
|
|
|
}
|
|
|
if req.AmountList[i].InvoiceId == 0 {
|
|
|
v := &fms.ContractInvoice{
|
|
|
ContractRegisterId: req.ContractRegisterId,
|
|
|
ContractCode: item.ContractCode,
|
|
|
Amount: req.AmountList[i].Amount,
|
|
|
+ OriginAmount: req.AmountList[i].OriginAmount,
|
|
|
+ CurrencyUnit: item.CurrencyUnit,
|
|
|
InvoiceType: req.InvoiceType,
|
|
|
InvoiceDate: t,
|
|
|
AdminId: int(adminInfo.AdminId),
|
|
@@ -1070,7 +1099,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
|
|
|
for i := range otherService {
|
|
|
row2Title = append(row2Title, otherService[i].Title)
|
|
|
}
|
|
|
- row2Title = append(row2Title, "套餐备注", "开始时间", "到期时间", "2022年合同金额", "约定付款时间", "签订日", "合同状态",
|
|
|
+ row2Title = append(row2Title, "套餐备注", "开始时间", "到期时间", "2022年合同金额", "金额单位", "约定付款时间", "签订日", "合同状态",
|
|
|
"合同编号", "合规备注")
|
|
|
|
|
|
// 设置表头
|
|
@@ -1175,6 +1204,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
|
|
|
dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", v.StartDate)) // 开始时间
|
|
|
dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", v.EndDate)) // 到期时间
|
|
|
dataRow.AddCell().SetString(fmt.Sprint("¥", v.ContractAmount)) // 2022年合同金额
|
|
|
+ dataRow.AddCell().SetString(v.CurrencyUnit) // 货币单位
|
|
|
dataRow.AddCell().SetString(v.AgreedPayTime) // 约定付款时间
|
|
|
dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", v.SignDate)) // 签订日
|
|
|
dataRow.AddCell().SetString(fms.ContractStatusKeyNameMap[v.ContractStatus]) // 合同状态
|
|
@@ -1239,6 +1269,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
|
|
|
// @Param EndDate query string false "结束日期"
|
|
|
// @Param MinAmount query float64 false "开票金额区间-最小值"
|
|
|
// @Param MaxAmount query float64 false "开票金额区间-最大值"
|
|
|
+// @Param IsExport query int false "是否导出: 0-否; 1-是"
|
|
|
// @Success 200 {object} fms.ContractInvoiceItem
|
|
|
// @router /contract/register/invoice_list [get]
|
|
|
func (rg *RegisterController) InvoiceList(c *gin.Context) {
|
|
@@ -1267,8 +1298,13 @@ func (rg *RegisterController) InvoiceList(c *gin.Context) {
|
|
|
// 合同编号
|
|
|
if req.ContractCode != "" {
|
|
|
kw := fmt.Sprint("%", req.ContractCode, "%")
|
|
|
- cond += ` AND contract_code LIKE ?`
|
|
|
pars = append(pars, kw)
|
|
|
+ // 开票列表同时模糊查询销售名称
|
|
|
+ if req.InvoiceType == fms.ContractInvoiceTypeMake {
|
|
|
+ cond += ` AND (contract_code LIKE ? OR seller_name LIKE ?)`
|
|
|
+ } else {
|
|
|
+ cond += ` AND contract_code LIKE ?`
|
|
|
+ }
|
|
|
}
|
|
|
if req.StartDate != "" && req.EndDate != "" {
|
|
|
st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
@@ -1285,103 +1321,96 @@ func (rg *RegisterController) InvoiceList(c *gin.Context) {
|
|
|
pars = append(pars, req.MaxAmount)
|
|
|
}
|
|
|
|
|
|
+ // 货币列表
|
|
|
+ currencyOB := new(fms.CurrencyUnit)
|
|
|
+ currencyCond := `enable = 1`
|
|
|
+ currencyPars := make([]interface{}, 0)
|
|
|
+ currencyList, e := currencyOB.List(currencyCond, currencyPars)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("获取失败", "获取货币列表失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ unitMap := make(map[string]string)
|
|
|
+ currencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
|
|
|
+ for i := range currencyList {
|
|
|
+ unitMap[currencyList[i].Code] = currencyList[i].UnitName
|
|
|
+ currencyTotals = append(currencyTotals, &fms.InvoiceListCurrencyTotal{
|
|
|
+ Name: currencyList[i].Name,
|
|
|
+ UnitName: currencyList[i].UnitName,
|
|
|
+ Code: currencyList[i].Code,
|
|
|
+ FlagImg: currencyList[i].FlagImg,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
page := new(base.Page)
|
|
|
page.SetPageSize(pageSize)
|
|
|
page.SetCurrent(pageIndex)
|
|
|
page.AddOrderItem(base.OrderItem{Column: "invoice_time", Asc: false})
|
|
|
+ if req.IsExport == 1 {
|
|
|
+ page.SetPageSize(10000)
|
|
|
+ page.SetCurrent(1)
|
|
|
+ }
|
|
|
total, list, e := fms.GetContractInvoiceItemPageList(page, cond, pars)
|
|
|
if e != nil {
|
|
|
resp.FailMsg("获取失败", "获取合同开票/到款列表失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
page.SetTotal(total)
|
|
|
+ for i := range list {
|
|
|
+ list[i].UnitName = unitMap[list[i].CurrencyUnit]
|
|
|
+ }
|
|
|
|
|
|
- // 金额合计
|
|
|
- ob := new(fms.ContractInvoice)
|
|
|
- amountTotal, e := ob.Sum("amount", cond, pars)
|
|
|
+ // 分币种合计金额
|
|
|
+ var amountTotal float64
|
|
|
+ sumList, e := fms.GetInvoiceListCurrencySum(cond, pars, "currency_unit")
|
|
|
if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取合同开票/到款列表合计金额失败, Err: "+e.Error(), c)
|
|
|
+ resp.FailMsg("获取失败", "获取开票/到款列表合计金额失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
- amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountTotal), 64)
|
|
|
-
|
|
|
- type RespData struct {
|
|
|
- Page *base.Page `json:"page"`
|
|
|
- List interface{} `json:"list"`
|
|
|
- AmountTotal float64 `json:"amount_total"`
|
|
|
- }
|
|
|
- respData := &RespData{
|
|
|
- Page: page,
|
|
|
- List: list,
|
|
|
- AmountTotal: amountTotal,
|
|
|
- }
|
|
|
- resp.OkData("获取成功", respData, c)
|
|
|
-}
|
|
|
-
|
|
|
-// InvoiceExport
|
|
|
-// @Title 开票/到款列表-导出
|
|
|
-// @Description 合同登记-导出
|
|
|
-// @Param InvoiceType query int false "类型: 1-开票登记; 2-到款登记"
|
|
|
-// @Param ContractCode query string false "合同编号"
|
|
|
-// @Param StartDate query string false "开始日期"
|
|
|
-// @Param EndDate query string false "结束日期"
|
|
|
-// @Param MinAmount query float64 false "开票金额区间-最小值"
|
|
|
-// @Param MaxAmount query float64 false "开票金额区间-最大值"
|
|
|
-// @Success 200 string "操作成功"
|
|
|
-// @router /contract/register/invoice_export [get]
|
|
|
-func (rg *RegisterController) InvoiceExport(c *gin.Context) {
|
|
|
- var req fms.ContractInvoiceListReq
|
|
|
- if e := c.BindQuery(&req); e != nil {
|
|
|
- err, ok := e.(validator.ValidationErrors)
|
|
|
- if !ok {
|
|
|
- resp.FailData("参数解析失败", "Err:"+e.Error(), c)
|
|
|
- return
|
|
|
+ sumMap := make(map[string]float64)
|
|
|
+ for i := range sumList {
|
|
|
+ if sumList[i].CurrencyUnit == fms.BaseCurrencyCode {
|
|
|
+ amountTotal = sumList[i].AmountTotal
|
|
|
}
|
|
|
- resp.FailData("参数解析失败", err.Translate(global.Trans), c)
|
|
|
- return
|
|
|
+ sumMap[sumList[i].CurrencyUnit] = sumList[i].OriginAmountTotal
|
|
|
}
|
|
|
- listName := "开票"
|
|
|
- if req.InvoiceType == fms.ContractInvoiceTypePay {
|
|
|
- listName = "到款"
|
|
|
+ for i := range currencyTotals {
|
|
|
+ currencyTotals[i].Amount = sumMap[currencyTotals[i].Code]
|
|
|
}
|
|
|
|
|
|
- cond := `invoice_type = ?`
|
|
|
- pars := make([]interface{}, 0)
|
|
|
- pars = append(pars, req.InvoiceType)
|
|
|
- // 合同编号
|
|
|
- if req.ContractCode != "" {
|
|
|
- kw := fmt.Sprint("%", req.ContractCode, "%")
|
|
|
- cond += ` AND contract_code LIKE ?`
|
|
|
- pars = append(pars, kw)
|
|
|
+ respData := &fms.InvoiceListRespData{
|
|
|
+ Page: page,
|
|
|
+ List: list,
|
|
|
+ AmountTotal: amountTotal,
|
|
|
+ CurrencyTotal: currencyTotals,
|
|
|
}
|
|
|
- if req.StartDate != "" && req.EndDate != "" {
|
|
|
- st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
- ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
- cond += ` AND (invoice_time BETWEEN ? AND ?)`
|
|
|
- pars = append(pars, st, ed)
|
|
|
- }
|
|
|
- if req.MinAmount > 0 {
|
|
|
- cond += ` AND amount >= ?`
|
|
|
- pars = append(pars, req.MinAmount)
|
|
|
- }
|
|
|
- if req.MaxAmount > 0 {
|
|
|
- cond += ` AND amount <= ?`
|
|
|
- pars = append(pars, req.MaxAmount)
|
|
|
+ // 是否导出
|
|
|
+ if req.IsExport == 1 {
|
|
|
+ ExportInvoiceList(c, req, respData)
|
|
|
+ return
|
|
|
}
|
|
|
+ resp.OkData("获取成功", respData, c)
|
|
|
+}
|
|
|
|
|
|
- // 获取列表数据
|
|
|
- cr := new(fms.ContractInvoice)
|
|
|
- orderRule := `invoice_time DESC`
|
|
|
- list, e := cr.List(cond, pars, orderRule)
|
|
|
- if e != nil {
|
|
|
- resp.FailData(fmt.Sprintf("获取%s列表失败", listName), "Err:"+e.Error(), c)
|
|
|
+// ExportInvoiceList 导出开票/到款列表
|
|
|
+func ExportInvoiceList(c *gin.Context, req fms.ContractInvoiceListReq, results *fms.InvoiceListRespData) {
|
|
|
+ list := make([]*fms.ContractInvoiceItem, 0)
|
|
|
+ if val, ok := results.List.([]*fms.ContractInvoiceItem); ok {
|
|
|
+ list = val
|
|
|
+ } else {
|
|
|
+ resp.Fail("列表数据有误", c)
|
|
|
return
|
|
|
}
|
|
|
if len(list) == 0 {
|
|
|
- resp.Fail("无有效数据可导出", c)
|
|
|
+ resp.Fail("列表数据为空", c)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ listName := "开票"
|
|
|
+ if req.InvoiceType == fms.ContractInvoiceTypePay {
|
|
|
+ listName = "到款"
|
|
|
+ }
|
|
|
+
|
|
|
// 生成Excel文件
|
|
|
xlsxFile := xlsx.NewFile()
|
|
|
style := xlsx.NewStyle()
|
|
@@ -1399,25 +1428,40 @@ func (rg *RegisterController) InvoiceExport(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 表头
|
|
|
+ // 前两行显示合计金额, 第三行空出与列表数据隔一行
|
|
|
+ rowA := sheet.AddRow()
|
|
|
+ cellAA := rowA.AddCell()
|
|
|
+ cellAA.SetString(fmt.Sprintf("已开票合计金额(换算后):%.2f(元)", results.AmountTotal))
|
|
|
+ rowBData := "已开票金额:"
|
|
|
+ for _, v := range results.CurrencyTotal {
|
|
|
+ rowBData += fmt.Sprintf("%s%.2f(%s) ", v.Name, v.Amount, v.UnitName)
|
|
|
+ }
|
|
|
+ rowB := sheet.AddRow()
|
|
|
+ rowB.AddCell().SetString(rowBData)
|
|
|
+ sheet.AddRow()
|
|
|
+
|
|
|
+ // 列表数据表头
|
|
|
+ titles := []string{"合同编号", fmt.Sprintf("%s金额", listName), "金额单位", "换算金额(元)",
|
|
|
+ fmt.Sprintf("%s日期", listName), "销售", "备注"}
|
|
|
titleRow := sheet.AddRow()
|
|
|
titleRow.SetHeight(40)
|
|
|
- cell1 := titleRow.AddCell()
|
|
|
- cell1.SetString("合同编号")
|
|
|
- cell1.SetStyle(style)
|
|
|
- cell2 := titleRow.AddCell()
|
|
|
- cell2.SetValue(fmt.Sprintf("%s金额", listName))
|
|
|
- cell2.SetStyle(style)
|
|
|
- cell3 := titleRow.AddCell()
|
|
|
- cell3.SetValue(fmt.Sprintf("%s日期", listName))
|
|
|
- cell3.SetStyle(style)
|
|
|
+ for i := range titles {
|
|
|
+ c := titleRow.AddCell()
|
|
|
+ c.SetString(titles[i])
|
|
|
+ c.SetStyle(style)
|
|
|
+ }
|
|
|
|
|
|
+ // 单元格赋值
|
|
|
for _, v := range list {
|
|
|
dataRow := sheet.AddRow()
|
|
|
dataRow.SetHeight(20)
|
|
|
- dataRow.AddCell().SetString(v.ContractCode)
|
|
|
- dataRow.AddCell().SetString(fmt.Sprint(v.Amount))
|
|
|
- dataRow.AddCell().SetString(utils.TimeTransferString("2006-01-02", v.InvoiceDate))
|
|
|
+ dataRow.AddCell().SetString(v.ContractCode) // 合同编号
|
|
|
+ dataRow.AddCell().SetString(fmt.Sprint(v.OriginAmount)) // 开票金额
|
|
|
+ dataRow.AddCell().SetString(v.UnitName) // 金额单位
|
|
|
+ dataRow.AddCell().SetString(fmt.Sprint(v.Amount)) // 换算金额(元)
|
|
|
+ dataRow.AddCell().SetString(v.InvoiceDate) // 开票日
|
|
|
+ dataRow.AddCell().SetString(v.SellerName) // 销售
|
|
|
+ dataRow.AddCell().SetString(v.Remark) // 备注
|
|
|
}
|
|
|
|
|
|
// 输出文件
|
|
@@ -1524,6 +1568,17 @@ func (rg *RegisterController) Import(c *gin.Context) {
|
|
|
serviceTempNameMap[serviceTempList[i].Title] = serviceTempList[i]
|
|
|
}
|
|
|
|
|
|
+ // 获取货币列表及汇率(汇率为导入日的汇率)
|
|
|
+ rateList, e := fmsService.GetTodayCurrencyRateList()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailData("获取货币列表及汇率失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rateMap := make(map[string]float64)
|
|
|
+ for i := range rateList {
|
|
|
+ rateMap[rateList[i].Code] = rateList[i].RMBRate
|
|
|
+ }
|
|
|
+
|
|
|
titleMap := make(map[int]string)
|
|
|
newIds := make([]int, 0)
|
|
|
newCompanyArr := []string{"0", "1"}
|
|
@@ -1776,13 +1831,24 @@ func (rg *RegisterController) Import(c *gin.Context) {
|
|
|
rowRegister.ContractAmount = amount
|
|
|
continue
|
|
|
}
|
|
|
- // 约定付款日期
|
|
|
+ // 金额单位
|
|
|
if k == 37 {
|
|
|
+ rate := rateMap[v]
|
|
|
+ if rate <= 0 {
|
|
|
+ resp.Fail(fmt.Sprintf("第%d行金额单位有误, 请按模板导入", i+1), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rowRegister.CurrencyUnit = v
|
|
|
+ rowRegister.RMBRate = rate
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 约定付款日期
|
|
|
+ if k == 38 {
|
|
|
rowRegister.AgreedPayTime = v
|
|
|
continue
|
|
|
}
|
|
|
// 签订日
|
|
|
- if k == 38 {
|
|
|
+ if k == 39 {
|
|
|
va := cell.Value
|
|
|
if va == "" {
|
|
|
continue
|
|
@@ -1804,7 +1870,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
|
|
|
continue
|
|
|
}
|
|
|
// 合同状态
|
|
|
- if k == 39 {
|
|
|
+ if k == 40 {
|
|
|
rowRegister.ContractStatus = fms.ContractStatusNameKeyMap[v]
|
|
|
if rowRegister.ContractStatus == 0 {
|
|
|
resp.Fail(fmt.Sprintf("第%d行合同状态不匹配, 请按模板导入", i+1), c)
|
|
@@ -1813,7 +1879,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
|
|
|
continue
|
|
|
}
|
|
|
// 合同编号
|
|
|
- if k == 40 {
|
|
|
+ if k == 41 {
|
|
|
rowContractCode := v
|
|
|
if rowContractCode == "" {
|
|
|
resp.Fail(fmt.Sprintf("第%d行合同编号不可为空, 请按模板导入", i+1), c)
|
|
@@ -1828,12 +1894,12 @@ func (rg *RegisterController) Import(c *gin.Context) {
|
|
|
continue
|
|
|
}
|
|
|
// 合规备注
|
|
|
- if k == 41 {
|
|
|
+ if k == 42 {
|
|
|
rowRegister.Remark = v
|
|
|
continue
|
|
|
}
|
|
|
// 开票列表
|
|
|
- k2 := 41
|
|
|
+ k2 := 42
|
|
|
for ir := 0; ir < invoiceMax; ir++ {
|
|
|
n := ir + 1
|
|
|
// 开票日
|
|
@@ -2016,3 +2082,17 @@ func (rg *RegisterController) Import(c *gin.Context) {
|
|
|
|
|
|
resp.Ok("操作成功", c)
|
|
|
}
|
|
|
+
|
|
|
+// CurrencyList
|
|
|
+// @Title 货币单位列表
|
|
|
+// @Description 货币单位列表
|
|
|
+// @Success 200 {object} fms.CurrencyUnitItem
|
|
|
+// @router /contract/register/currency_list [get]
|
|
|
+func (rg *RegisterController) CurrencyList(c *gin.Context) {
|
|
|
+ list, e := fmsService.GetTodayCurrencyRateList()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailData("获取失败", "获取今日货币汇率列表失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.OkData("获取成功", list, c)
|
|
|
+}
|