partuse.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package model
  2. import (
  3. "time"
  4. "github.com/pkg/errors"
  5. "kpt.xdmy/pkg/util"
  6. )
  7. type BigPartUse struct {
  8. ApplicatID int `gorm:"column:applicatId"`
  9. DepartmentID int `gorm:"column:departmentId"`
  10. EmpID int `gorm:"column:empId"`
  11. FClassID int `gorm:"column:fClassId"`
  12. ID int `gorm:"column:id"`
  13. MaintainID int `gorm:"column:maintainId"`
  14. PastureID int `gorm:"column:pastureId"`
  15. WorkflowID int `gorm:"column:workflowId"`
  16. PlanUpkeepID int `gorm:"column:planUpkeepId"`
  17. SClassID int `gorm:"column:sClassId"`
  18. ReceiveTime time.Time `gorm:"column:receiveTime"` //'领用时间'
  19. CreatDate time.Time `gorm:"column:creatDate"`
  20. FlowworkNote string `gorm:"column:flowworkNote"`
  21. ListType string `gorm:"column:listType"`
  22. OddCode string `gorm:"column:oddCode"`
  23. RefuseStatue int `gorm:"column:refuseStatue"`
  24. Msg string `gorm:"column:msg"`
  25. FlowCompeleted int `gorm:"column:flowCompeleted"`
  26. Issync int `gorm:"column:issync"`
  27. Note string `gorm:"column:note"`
  28. SumPrice string `gorm:"column:sumPrice"`
  29. UseType int `gorm:"column:useType"`
  30. UseForm string `gorm:"column:useForm"`
  31. UseStatus int `gorm:"column:useStatus"`
  32. ProofCode string `gorm:"column:proofCode"`
  33. }
  34. type PartUse struct {
  35. ID int `gorm:"column:id"`
  36. BigID int `gorm:"column:bigId"`
  37. BrandID int `gorm:"column:brandId"`
  38. ContractID int `gorm:"column:contractId"`
  39. LocationID int `gorm:"column:locationId"`
  40. MaintainID int `gorm:"column:maintainId"`
  41. PlanUpkeepID int `gorm:"column:planUpkeepId"`
  42. PartID int `gorm:"column:partId"`
  43. ProID int `gorm:"column:proId"`
  44. EqCode string `gorm:"column:eqCode"`
  45. EqID int `gorm:"column:eqId"`
  46. Cpm int `gorm:"column:CPM"`
  47. CheckoutNumber float32 `gorm:"column:checkoutNumber"` // 出库数量
  48. EqName string `gorm:"column:eqName"`
  49. IsRefuse int `gorm:"column:isRefuse"`
  50. Note string `gorm:"column:note"`
  51. PartCode string `gorm:"column:partCode"`
  52. PartName string `gorm:"column:partName"`
  53. Price float32 `gorm:"column:price"` // 单价
  54. ProName string `gorm:"column:proName"`
  55. QuitNumber string `gorm:"column:quitNumber"`
  56. RefuseNumber int `gorm:"column:refuseNumber"`
  57. RefuseStatue int `gorm:"column:refuseStatue"`
  58. Reportery string `gorm:"column:reportery"`
  59. Specification string `gorm:"column:specification"`
  60. SumPrice float32 `gorm:"column:sumPrice"` // 总价
  61. Unit string `gorm:"column:unit"`
  62. UseNumber string `gorm:"column:useNumber"`
  63. UseTypeV string `gorm:"column:useTypeV"`
  64. Dflag int `gorm:"column:dflag"`
  65. RowNumber int `gorm:"column:rowNumber"`
  66. }
  67. func (p *PartUse) ToProofPart() (r *ProofPart, e error) {
  68. mb := &Brand{ID: p.BrandID}
  69. mw := &Warehouse{ID: p.LocationID}
  70. e = First(mb)
  71. e = First(mw)
  72. if e != nil {
  73. e = errors.Wrapf(e, "model PartLaid ToProofPart()")
  74. return
  75. }
  76. r = &ProofPart{
  77. RowNumber: p.RowNumber,
  78. PartCode: p.PartCode,
  79. PartName: p.PartName,
  80. Specification: p.Specification,
  81. PartBrand: mb.BrandName,
  82. Supplier: p.ProName,
  83. Warehouse: mw.WarehoseCode,
  84. ChangeCount: p.CheckoutNumber,
  85. UnitPrice: p.Price,
  86. TotalPrice: p.SumPrice,
  87. }
  88. return
  89. }
  90. func (p *BigPartUse) NewProof(pa *ProofReq) {
  91. pa.ChargeDate = p.ReceiveTime.Format("2006-01-02")
  92. pa.ProofCode = p.UseForm
  93. pa.ProofYear = p.ReceiveTime.Format("2006")
  94. pa.OrderNumberId = p.ID
  95. }
  96. func (p *BigPartUse) NewProofPart() (mps []ProofPart, e error) {
  97. path := " BigPartUse NewProofPart()"
  98. c := util.NewMap("bigid", p.ID)
  99. m := make([]PartUse, 0)
  100. if e = Find(c, &m); e != nil {
  101. e = errors.Wrapf(e, path)
  102. return
  103. }
  104. mps = make([]ProofPart, 0)
  105. mp := new(ProofPart)
  106. for i, v := range m {
  107. mp, e = v.ToProofPart()
  108. mp.RowNumber = i
  109. mps = append(mps, *mp)
  110. }
  111. if e != e {
  112. e = errors.Wrapf(e, path)
  113. }
  114. return
  115. }