contract_invoice.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. package fms
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. // ContractInvoice 合同开票表
  8. type ContractInvoice struct {
  9. ContractInvoiceId int `gorm:"primaryKey;column:contract_invoice_id" json:"contract_invoice_id" description:"开票ID"`
  10. ContractRegisterId int `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
  11. ContractCode string `gorm:"column:contract_code" json:"contract_code" description:"合同编号"`
  12. Amount float64 `gorm:"column:amount" json:"amount" description:"换算后的金额(人民币)"`
  13. OriginAmount float64 `gorm:"column:origin_amount" json:"origin_amount" description:"开票/到款金额"`
  14. CurrencyUnit string `gorm:"column:currency_unit" json:"currency_unit" description:"货币国际代码"`
  15. InvoiceType int `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记"`
  16. InvoiceDate time.Time `gorm:"column:invoice_time" json:"invoice_time" description:"开票日期/到款月"`
  17. SellerId int `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
  18. SellerName string `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
  19. SellerGroupId int `gorm:"column:seller_group_id" json:"seller_group_id" description:"销售分组ID"`
  20. SellerGroupName string `gorm:"column:seller_group_name" json:"seller_group_name" description:"销售分组名称"`
  21. SellerTeamId int `gorm:"column:seller_team_id" json:"seller_team_id" description:"销售小组ID"`
  22. SellerTeamName string `gorm:"column:seller_team_name" json:"seller_team_name" description:"销售小组名称"`
  23. PayType int `gorm:"column:pay_type" json:"pay_type" description:"付款方式:0-无;1-年付;2-半年付;3-季付;4-次付;5-异常"`
  24. AdminId int `gorm:"column:admin_id" json:"admin_id" description:"操作人ID"`
  25. AdminName string `gorm:"column:admin_name" json:"admin_name" description:"操作人姓名"`
  26. Remark string `gorm:"column:remark" json:"remark" description:"备注信息"`
  27. IsDeleted int `gorm:"column:is_deleted" json:"is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
  28. ServiceProductId int `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
  29. IsPrePay int `gorm:"column:is_pre_pay" json:"is_pre_pay" description:"是否预付款: 0-不是; 1-是"`
  30. StartDate time.Time `gorm:"column:start_date" json:"start_date" description:"约定开始时间"`
  31. EndDate time.Time `gorm:"column:end_date" json:"end_date" description:"约定结束时间"`
  32. PreRegisterId int `gorm:"column:pre_register_id" json:"pre_register_id" description:"预登记ID"`
  33. CreateTime time.Time `gorm:"autoCreateTime;column:create_time" json:"create_time" description:"创建时间"`
  34. ModifyTime time.Time `gorm:"autoUpdateTime:milli;column:modify_time" json:"modify_time" description:"最后更新时间"`
  35. }
  36. func (c *ContractInvoice) TableName() string {
  37. return "contract_invoice"
  38. }
  39. // ContractInvoiceItem 合同开票/到款
  40. type ContractInvoiceItem struct {
  41. ContractInvoiceId int `gorm:"column:contract_invoice_id" json:"contract_invoice_id" description:"开票ID"`
  42. ContractRegisterId int `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
  43. ContractCode string `gorm:"column:contract_code" json:"contract_code" description:"合同编号"`
  44. ContractStatus int `json:"contract_status" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回"`
  45. Amount float64 `gorm:"column:amount" json:"amount" description:"换算金额"`
  46. OriginAmount float64 `gorm:"column:origin_amount" json:"origin_amount" description:"开票/到款金额"`
  47. CurrencyUnit string `gorm:"column:currency_unit" json:"currency_unit" description:"货币国际代码"`
  48. UnitName string `json:"unit_name" description:"货币单位名称"`
  49. InvoiceType int `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记;3-开票预登记;4-到款预登记"`
  50. InvoiceDate string `gorm:"column:invoice_time" json:"invoice_time" description:"开票日期/到款月"`
  51. SellerId int `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
  52. SellerName string `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
  53. PayType int `gorm:"column:pay_type" json:"pay_type" description:"付款方式:0-无;1-年付;2-半年付;3-季付;4-次付;5-异常"`
  54. Remark string `gorm:"column:remark" json:"remark" description:"备注信息"`
  55. ServiceProductId int `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
  56. IsPrePay int `gorm:"column:is_pre_pay" json:"is_pre_pay" description:"是否预付款: 0-不是; 1-是"`
  57. StartDate string `gorm:"column:start_date" json:"start_date" description:"约定开始时间"`
  58. EndDate string `gorm:"column:end_date" json:"end_date" description:"约定结束时间"`
  59. CreateTime string `gorm:"column:create_time" json:"create_time" description:"创建时间"`
  60. CompanyName string `gorm:"column:company_name" json:"company_name" description:"客户名称"`
  61. }
  62. // ContractInvoiceSaveReq 合同开票-请求体
  63. type ContractInvoiceSaveReq struct {
  64. ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"登记ID"`
  65. InvoiceType int `json:"invoice_type" binding:"oneof=1 2 3" description:"类型: 1-开票登记; 2-到款登记; 3-预到款登记"`
  66. AmountList []*ContractInvoiceSaveItem `json:"amount_list"`
  67. }
  68. // ContractInvoiceSaveItem 合同开票数据
  69. type ContractInvoiceSaveItem struct {
  70. ServiceProductId int `json:"service_product_id" binding:"oneof=1 2" description:"套餐类型:1ficc套餐,2权益套餐"`
  71. InvoiceId int `json:"invoice_id" description:"开票ID"`
  72. OriginAmount float64 `json:"origin_amount" description:"开票(到款)金额"`
  73. Amount float64 `json:"amount" description:"换算后的金额"`
  74. InvoiceDate string `json:"invoice_date" description:"开票日期/到款月"`
  75. Remark string `json:"remark" description:"备注"`
  76. SellerId int `json:"seller_id" description:"销售ID"`
  77. }
  78. // formatContractInvoice2ItemList 格式化ContractInvoice
  79. func formatContractInvoice2ItemList(list []*ContractInvoice) (itemList []*ContractInvoiceItem) {
  80. itemList = make([]*ContractInvoiceItem, 0)
  81. for i := range list {
  82. itemList = append(itemList, &ContractInvoiceItem{
  83. ContractInvoiceId: list[i].ContractInvoiceId,
  84. ContractRegisterId: list[i].ContractRegisterId,
  85. ContractCode: list[i].ContractCode,
  86. Amount: list[i].Amount,
  87. OriginAmount: list[i].OriginAmount,
  88. CurrencyUnit: list[i].CurrencyUnit,
  89. InvoiceType: list[i].InvoiceType,
  90. InvoiceDate: utils.TimeTransferString(utils.FormatDate, list[i].InvoiceDate),
  91. SellerId: list[i].SellerId,
  92. SellerName: list[i].SellerName,
  93. PayType: list[i].PayType,
  94. Remark: list[i].Remark,
  95. ServiceProductId: list[i].ServiceProductId,
  96. IsPrePay: list[i].IsPrePay,
  97. StartDate: list[i].StartDate.Format(utils.FormatDate),
  98. EndDate: list[i].StartDate.Format(utils.FormatDate),
  99. CreateTime: utils.TimeTransferString(utils.FormatDateTime, list[i].CreateTime),
  100. })
  101. }
  102. return
  103. }
  104. // formatContractInvoice2Item 格式化ContractInvoiceItem
  105. func formatContractInvoice2Item(item *ContractInvoiceRespItem) (formatItem *ContractInvoiceItem) {
  106. formatItem = new(ContractInvoiceItem)
  107. formatItem.ContractInvoiceId = item.ContractInvoiceId
  108. formatItem.ContractRegisterId = item.ContractRegisterId
  109. formatItem.ContractCode = item.ContractCode
  110. formatItem.Amount = item.Amount
  111. formatItem.OriginAmount = item.OriginAmount
  112. formatItem.CurrencyUnit = item.CurrencyUnit
  113. formatItem.InvoiceType = item.InvoiceType
  114. formatItem.InvoiceDate = utils.TimeTransferString(utils.FormatDate, item.InvoiceDate)
  115. formatItem.SellerId = item.SellerId
  116. formatItem.SellerName = item.SellerName
  117. formatItem.PayType = item.PayType
  118. formatItem.Remark = item.Remark
  119. formatItem.IsPrePay = item.IsPrePay
  120. formatItem.ServiceProductId = item.ServiceProductId
  121. formatItem.CreateTime = utils.TimeTransferString(utils.FormatDateTime, item.CreateTime)
  122. formatItem.CompanyName = item.CompanyName
  123. return
  124. }
  125. // InvoicePaymentCensusResp 商品到款统计响应体
  126. type InvoicePaymentCensusRespItem struct {
  127. DataList []*InvoicePaymentCensusItem `json:"data_list"`
  128. InvoiceTotal float64 `json:"invoice_total" description:"开票总金额(换算后)"`
  129. PaymentTotal float64 `json:"payment_total" description:"到款总金额(换算后)"`
  130. AmountTotal float64 `json:"amount_total" description:"合计总金额(换算后)"`
  131. InvoiceCurrencyTotal []*InvoiceListCurrencyTotal `json:"invoice_currency_total" description:"开票-分币种总金额"`
  132. PaymentCurrencyTotal []*InvoiceListCurrencyTotal `json:"payment_currency_total" description:"到款-分币种总金额"`
  133. }
  134. type InvoicePaymentCensusResp struct {
  135. InvoicePaymentCensusRespItem
  136. Paging *paging.PagingItem
  137. }
  138. // InvoicePaymentCensusItem 商品到款统计信息
  139. type InvoicePaymentCensusItem struct {
  140. SummaryId int `json:"summary_id" description:"汇总ID"`
  141. ContractRegisterId int `json:"contract_register_id" description:"登记ID"`
  142. CompanyName string `json:"company_name" description:"客户名称"`
  143. NewCompany int `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
  144. StartDate string `json:"start_date" description:"合同开始日期"`
  145. EndDate string `json:"end_date" description:"合同结束日期"`
  146. ServicesName string `json:"services_name" description:"套餐信息字符串拼接"`
  147. ContractType int `json:"contract_type" description:"合同类型: 0-无 1-新签; 2-续约"`
  148. ActualPayCompanies string `json:"actual_pay_companies" description:"该合同关联的所有代付方, 英文逗号拼接"`
  149. InvoicePaymentList []*InvoicePaymentCensusInfo `json:"invoice_payment_list" description:"开票到款列表"`
  150. ContractCode string `gorm:"column:contract_code" json:"contract_code" description:"合同编号"`
  151. ContractAmount float64 `gorm:"column:contract_amount" json:"contract_amount" description:"合同金额"`
  152. UnitName string `gorm:"unit_name" json:"unit_name" description:"单位名称"`
  153. ProductIds string `gorm:"column:product_ids" json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
  154. NotInvoiceTotal float64 `json:"not_invoice_total" description:"未开票总金额(换算后)"`
  155. }
  156. // InvoicePaymentCensusInfo 开票到款统计信息
  157. type InvoicePaymentCensusInfo struct {
  158. InvoiceId int `json:"invoice_id" description:"开票ID"`
  159. InvoiceDate string `json:"invoice_time" description:"开票日期"`
  160. InvoiceAmount float64 `json:"invoice_amount" description:"开票金额"`
  161. SellerId int `json:"seller_id" description:"销售ID"`
  162. SellerName string `json:"seller_name" description:"销售名称"`
  163. SellerGroupId int `json:"seller_group_id" description:"销售组别ID"`
  164. SellerGroupName string `json:"seller_group_name" description:"销售组别名称"`
  165. PaymentId int `json:"payment_id" description:"到款ID"`
  166. PaymentDate string `json:"payment_date" description:"到款日期"`
  167. PaymentAmount float64 `json:"payment_amount" description:"到款金额"`
  168. PayType int `json:"pay_type" description:"付款方式:0-无;1-年付;2-半年付;3-季付;4-次付;5-异常"`
  169. ServiceAmountList []*ContractPaymentServiceAmountItem `json:"service_amount_list" description:"到款套餐金额分配信息"`
  170. SellerType int `json:"seller_type" description:"销售类型:1ficc销售,2权益销售"`
  171. }
  172. // ContractInvoiceAmountTotal 开票到款金额合计信息
  173. type ContractInvoiceAmountTotal struct {
  174. InvoiceType int `json:"invoice_type" description:"类型: 1-开票; 2-到款"`
  175. TotalAmount float64 `json:"total_amount" description:"金额合计"`
  176. }
  177. // UpdatePaymentPayTypeReq 到款登记-修改付款方式请求体
  178. type UpdatePaymentPayTypeReq struct {
  179. ContractPaymentId int `json:"contract_payment_id" binding:"required,gte=1" description:"到款登记ID"`
  180. PayType int `json:"pay_type" binding:"oneof=1 2 3 4" description:"付款方式: 1-年付; 2-半年付; 3-季付; 4-次付"`
  181. }
  182. // CensusSellerGroupInvoiceItem 销售组开票统计数据
  183. type CensusSellerGroupInvoiceItem struct {
  184. GroupId int `json:"group_id" description:"分组ID"`
  185. GroupName string `json:"group_name" description:"分组名称"`
  186. InvoiceAmount float64 `json:"invoice_amount" description:"开票金额"`
  187. GroupRate float64 `json:"group_rate" description:"分组占比"`
  188. }
  189. // CensusSellerInvoiceItem 销售组开票统计数据
  190. type CensusSellerInvoiceItem struct {
  191. SellerId int `json:"seller_id" description:"销售ID"`
  192. SellerName string `json:"seller_name" description:"销售名称"`
  193. GroupId int `json:"group_id" description:"分组ID"`
  194. GroupName string `json:"group_name" description:"分组名称"`
  195. InvoiceAmount float64 `json:"invoice_amount" description:"开票金额"`
  196. GroupRate float64 `json:"group_rate" description:"分组占比"`
  197. SellerRate float64 `json:"seller_rate" description:"全员占比"`
  198. }
  199. // InvoiceListCurrencyTotal 开票/到款列表分币种合计信息
  200. type InvoiceListCurrencyTotal struct {
  201. Name string `json:"name" description:"货币名称"`
  202. UnitName string `json:"unit_name" description:"单位名称"`
  203. Code string `json:"code" description:"国际代码"`
  204. Amount float64 `json:"amount" description:"金额"`
  205. FlagImg string `json:"flag_img" description:"国旗图标"`
  206. }
  207. // InvoiceListCurrencySum 开票/到款列表分币种总和
  208. type InvoiceListCurrencySum struct {
  209. CurrencyUnit string `json:"currency_unit" description:"货币代码"`
  210. InvoiceType int `json:"invoice_type" description:"开票类型:1-开票; 2-到款"`
  211. AmountTotal float64 `json:"amount_total" description:"换算后合计金额"`
  212. OriginAmountTotal float64 `json:"origin_amount_total" description:"原合计金额"`
  213. }
  214. // ContractInvoiceDetailItem 预登记列表详情用-invoice_time换register_time
  215. type ContractInvoiceDetailItem struct {
  216. ContractInvoiceId int `gorm:"column:contract_invoice_id" json:"contract_invoice_id" description:"开票ID"`
  217. ContractRegisterId int `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
  218. ContractCode string `gorm:"column:contract_code" json:"contract_code" description:"合同编号"`
  219. ContractStatus int `json:"contract_status" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回"`
  220. OriginAmount float64 `gorm:"column:amount" json:"amount" description:"开票/到款金额"`
  221. CurrencyUnit string `gorm:"column:currency_unit" json:"currency_unit" description:"货币国际代码"`
  222. UnitName string `json:"unit_name" description:"货币单位名称"`
  223. InvoiceType int `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记;3-开票预登记;4-到款预登记"`
  224. InvoiceDate string `gorm:"column:register_date" json:"register_date" description:"开票日期/到款月"`
  225. SellerId int `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
  226. SellerName string `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
  227. PayType int `gorm:"column:pay_type" json:"pay_type" description:"付款方式:0-无;1-年付;2-半年付;3-季付;4-次付;5-异常"`
  228. Remark string `gorm:"column:remark" json:"remark" description:"备注信息"`
  229. ServiceProductId int `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
  230. IsPrePay int `gorm:"column:is_pre_pay" json:"is_pre_pay" description:"是否预付款: 0-不是; 1-是"`
  231. StartDate string `gorm:"column:start_date" json:"start_date" description:"约定开始时间"`
  232. EndDate string `gorm:"column:end_date" json:"end_date" description:"约定结束时间"`
  233. CreateTime string `gorm:"column:create_time" json:"create_time" description:"创建时间"`
  234. PreRegisterId int `gorm:"column:pre_register_id" json:"pre_register_id" description:"预登记ID"`
  235. }
  236. type ContractInvoiceRespItem struct {
  237. ContractInvoice
  238. CompanyName string `gorm:"column:company_name" json:"company_name" description:"客户名称"`
  239. }
  240. type DupInvoice struct {
  241. ContractInvoice
  242. TemplateIds string
  243. }