contract_pre_register.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. package fms
  2. import (
  3. "hongze/fms_api/global"
  4. "hongze/fms_api/models/base"
  5. "hongze/fms_api/utils"
  6. "time"
  7. )
  8. // PreRegister 合同开票表
  9. type ContractPreRegister struct {
  10. PreRegisterId int `gorm:"primaryKey;column:pre_register_id" json:"pre_register_id" description:"预登记ID"`
  11. ContractRegisterId int `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
  12. InvoiceId int `gorm:"column:invoice_id" json:"invoice_id" description:"开票ID"`
  13. ArriveId int `gorm:"column:arrive_id" json:"arrive_id" description:"到款ID"`
  14. CompanyName string `json:"company_name" description:"客户名称"`
  15. Amount float64 `gorm:"column:amount" json:"amount" description:"开票换算后的金额(人民币)"`
  16. OriginAmount float64 `gorm:"column:origin_amount" json:"origin_amount" description:"开票金额"`
  17. CurrencyUnit string `gorm:"column:currency_unit" json:"currency_unit" description:"开票货币国际代码"`
  18. ArriveAmount float64 `gorm:"column:arrive_amount" json:"arrive_amount" description:"到款换算后的金额(人民币)"`
  19. ArriveOriginAmount float64 `gorm:"column:arrive_origin_amount" json:"arrive_origin_amount" description:"到款金额"`
  20. ArriveCurrencyUnit string `gorm:"column:arrive_currency_unit" json:"arrive_currency_unit" description:"到款货币国际代码"`
  21. InvoiceType int `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记;3-开票预登记;4-到款预登记"`
  22. InvoiceDate time.Time `gorm:"column:invoice_time" json:"invoice_time" description:"开票日"`
  23. ArriveDate time.Time `gorm:"column:arrive_time" json:"arrive_time" description:"到款日"`
  24. SellerId int `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
  25. SellerName string `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
  26. SellerGroupId int `gorm:"column:seller_group_id" json:"seller_group_id" description:"销售分组ID"`
  27. SellerGroupName string `gorm:"column:seller_group_name" json:"seller_group_name" description:"销售分组名称"`
  28. SellerTeamId int `gorm:"column:seller_team_id" json:"seller_team_id" description:"销售小组ID"`
  29. SellerTeamName string `gorm:"column:seller_team_name" json:"seller_team_name" description:"销售小组名称"`
  30. AdminId int `gorm:"column:admin_id" json:"admin_id" description:"操作人ID"`
  31. AdminName string `gorm:"column:admin_name" json:"admin_name" description:"操作人姓名"`
  32. Remark string `gorm:"column:remark" json:"remark" description:"备注信息"`
  33. ServiceProductId int `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
  34. IsPrePay int `gorm:"column:is_pre_pay" json:"is_pre_pay" description:"是否预付款: 0-不是; 1-是"`
  35. StartDate time.Time `gorm:"column:start_date" json:"start_date" description:"约定开始时间"`
  36. EndDate time.Time `gorm:"column:end_date" json:"end_date" description:"约定结束时间"`
  37. base.TimeBase
  38. }
  39. func (c *ContractPreRegister) TableName() string {
  40. return "contract_pre_register"
  41. }
  42. // ContractPreRegisterItem 合同开票/到款
  43. type ContractPreRegisterItem struct {
  44. PreRegisterId int `gorm:"primaryKey;column:pre_register_id" json:"pre_register_id" description:"预登记ID"`
  45. ContractRegisterId int `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
  46. InvoiceId int `gorm:"column:invoice_id" json:"invoice_id" description:"开票ID"`
  47. ArriveId int `gorm:"column:arrive_id" json:"arrive_id" description:"到款ID"`
  48. CompanyName string `json:"company_name" description:"客户名称"`
  49. Amount float64 `gorm:"column:amount" json:"amount" description:"开票换算后的金额(人民币)"`
  50. OriginAmount float64 `gorm:"column:origin_amount" json:"origin_amount" description:"开票金额"`
  51. CurrencyUnit string `gorm:"column:currency_unit" json:"currency_unit" description:"开票货币国际代码"`
  52. ArriveAmount float64 `gorm:"column:arrive_amount" json:"arrive_amount" description:"到款换算后的金额(人民币)"`
  53. ArriveOriginAmount float64 `gorm:"column:arrive_origin_amount" json:"arrive_origin_amount" description:"到款金额"`
  54. ArriveCurrencyUnit string `gorm:"column:arrive_currency_unit" json:"arrive_currency_unit" description:"到款货币国际代码"`
  55. UnitName string `json:"unit_name" description:"货币单位名称"`
  56. InvoiceType int `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记;3-开票预登记;4-到款预登记"`
  57. InvoiceDate string `gorm:"column:invoice_time" json:"invoice_time" description:"开票日"`
  58. ArriveDate string `gorm:"column:arrive_time" json:"arrive_time" description:"到款日"`
  59. SellerId int `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
  60. SellerName string `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
  61. PayType int `gorm:"column:pay_type" json:"pay_type" description:"付款方式:0-无;1-年付;2-半年付;3-季付;4-次付;5-异常"`
  62. Remark string `gorm:"column:remark" json:"remark" description:"开票备注信息"`
  63. ArriveRemark string `gorm:"column:arrive_remark" json:"arrive_remark" description:"到款备注信息"`
  64. ServiceProductId int `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
  65. IsPrePay int `gorm:"column:is_pre_pay" json:"is_pre_pay" description:"是否预付款: 0-不是; 1-是"`
  66. StartDate string `gorm:"column:start_date" json:"start_date" description:"约定开始时间"`
  67. EndDate string `gorm:"column:end_date" json:"end_date" description:"约定结束时间"`
  68. AdminId int `gorm:"column:admin_id" json:"admin_id" description:"操作人ID"`
  69. CreateTime string `gorm:"column:create_time" json:"create_time" description:"创建时间"`
  70. }
  71. // formatContractInvoice2Item 格式化ContractInvoiceItem
  72. func formatContractPreRegister2Item(item *ContractPreRegister) (formatItem *ContractPreRegisterItem) {
  73. formatItem = new(ContractPreRegisterItem)
  74. formatItem.PreRegisterId = item.PreRegisterId
  75. formatItem.ContractRegisterId = item.ContractRegisterId
  76. formatItem.InvoiceId = item.InvoiceId
  77. formatItem.ArriveId = item.ArriveId
  78. formatItem.CompanyName = item.CompanyName
  79. formatItem.Amount = item.Amount
  80. formatItem.OriginAmount = item.OriginAmount
  81. formatItem.CurrencyUnit = item.CurrencyUnit
  82. formatItem.ArriveAmount = item.ArriveAmount
  83. formatItem.ArriveOriginAmount = item.ArriveOriginAmount
  84. formatItem.ArriveCurrencyUnit = item.ArriveCurrencyUnit
  85. formatItem.InvoiceType = item.InvoiceType
  86. formatItem.InvoiceDate = utils.TimeTransferString(utils.FormatDate, item.InvoiceDate)
  87. formatItem.ArriveDate = utils.TimeTransferString(utils.FormatDate, item.ArriveDate)
  88. formatItem.SellerId = item.SellerId
  89. formatItem.SellerName = item.SellerName
  90. formatItem.Remark = item.Remark
  91. formatItem.IsPrePay = item.IsPrePay
  92. formatItem.ServiceProductId = item.ServiceProductId
  93. formatItem.AdminId = item.AdminId
  94. formatItem.CreateTime = utils.TimeTransferString(utils.FormatDateTime, item.CreateTime)
  95. formatItem.StartDate = item.StartDate.Format(utils.FormatDate)
  96. formatItem.EndDate = item.EndDate.Format(utils.FormatDate)
  97. return
  98. }
  99. // GetContractInvoiceItemPageList 获取合同开票/到款列表-分页
  100. func GetContractPreRegisterItemPageList(page base.IPage, condition string, pars []interface{}) (count int64, results []*ContractPreRegisterItem, err error) {
  101. list := make([]*ContractPreRegister, 0)
  102. query := global.DEFAULT_MYSQL.Table("contract_pre_register").
  103. Where(condition, pars...)
  104. query.Count(&count)
  105. if len(page.GetOrderItemsString()) > 0 {
  106. query = query.Order(page.GetOrderItemsString())
  107. }
  108. err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&list).Error
  109. if err != nil {
  110. return
  111. }
  112. for i := range list {
  113. results = append(results, formatContractPreRegister2Item(list[i]))
  114. }
  115. return
  116. }
  117. func (c *ContractPreRegister) Create() (err error) {
  118. err = global.DEFAULT_MYSQL.Create(c).Error
  119. return
  120. }
  121. // GetContractInvoiceItemList 获取开票到款列表
  122. func GetContractPreRegisterItemList(condition string, pars []interface{}) (itemList []*ContractPreRegisterItem, err error) {
  123. list := make([]*ContractPreRegister, 0)
  124. err = global.DEFAULT_MYSQL.Model(ContractPreRegister{}).
  125. Where("is_deleted = 0").
  126. Where(condition, pars...).
  127. Order("contract_invoice_id ASC").
  128. Find(&list).Error
  129. if err != nil {
  130. return
  131. }
  132. itemList = formatContractPreRegister2ItemList(list)
  133. return
  134. }
  135. // formatContractPreRegister2ItemList 格式化ContractInvoice
  136. func formatContractPreRegister2ItemList(list []*ContractPreRegister) (itemList []*ContractPreRegisterItem) {
  137. itemList = make([]*ContractPreRegisterItem, 0)
  138. for i := range list {
  139. itemList = append(itemList, &ContractPreRegisterItem{
  140. PreRegisterId: list[i].PreRegisterId,
  141. ContractRegisterId: list[i].ContractRegisterId,
  142. Amount: list[i].Amount,
  143. OriginAmount: list[i].OriginAmount,
  144. CurrencyUnit: list[i].CurrencyUnit,
  145. ArriveAmount: list[i].ArriveAmount,
  146. ArriveOriginAmount: list[i].ArriveOriginAmount,
  147. ArriveCurrencyUnit: list[i].ArriveCurrencyUnit,
  148. InvoiceType: list[i].InvoiceType,
  149. InvoiceDate: utils.TimeTransferString(utils.FormatDate, list[i].InvoiceDate),
  150. SellerId: list[i].SellerId,
  151. SellerName: list[i].SellerName,
  152. Remark: list[i].Remark,
  153. ServiceProductId: list[i].ServiceProductId,
  154. IsPrePay: list[i].IsPrePay,
  155. StartDate: list[i].StartDate.Format(utils.FormatDate),
  156. EndDate: list[i].StartDate.Format(utils.FormatDate),
  157. CreateTime: utils.TimeTransferString(utils.FormatDateTime, list[i].CreateTime),
  158. })
  159. }
  160. return
  161. }
  162. // ContractPreRegisterList 预登记列表
  163. type ContractPreRegisterList struct {
  164. *ContractPreRegisterItem
  165. ServicesName string `json:"services" description:"套餐名称"`
  166. }
  167. // PreRegisterDetailReq 预登记详情请求体
  168. type PreRegisterDetailReq struct {
  169. ContractRegisterId int `json:"contract_register_id" form:"contract_register_id" binding:"required,gte=1"`
  170. InvoiceType int `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记;3-开票预登记;4-到款预登记"`
  171. }
  172. // ContractPreRegisterDetail 预登记详情
  173. type ContractPreRegisterDetail struct {
  174. *ContractRegister
  175. List []*ContractInvoiceItem `json:"list" description:"开票到款列表"`
  176. }