proof.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package http
  2. import (
  3. "time"
  4. "github.com/pkg/errors"
  5. "kpt.xdmy/apiserver/dao"
  6. "kpt.xdmy/pkg/log"
  7. "kpt.xdmy/pkg/util"
  8. )
  9. type ProofReq struct {
  10. Dest `json:"DEST"`
  11. Data ProofReqData `json:"DATA"`
  12. }
  13. type ProofReqData struct {
  14. CreateTime string `json:"BLDAT"` //业务日期
  15. PostDate string `json:"BUDAT"` //过账日期
  16. EqNumber string `json:"FRBNR"` //设备管理平台单号(入库、退货、领用、退库)
  17. Detail []ProofDetail `json:"MSEG"`
  18. }
  19. type ProofDetail struct {
  20. RowNumber string `json:"ZEILE"` //行号,入库单行号
  21. Code string `json:"MATNR"` //物料编码
  22. Factory string `json:"WERKS"` //工厂
  23. Location string `json:"LGORT"` //库存地点
  24. Quantity string `json:"MENGE"` //数量
  25. Unit string `json:"MEINS"` //单位
  26. OrderNumber string `json:"EBELN"` //采购订单号,※仅采购入库业务传输,SAP的采购订单号
  27. OrderRowNum string `json:"EBPLP"` //采购订单行项目号,※仅采购入库业务传输,SAP的采购订单行项目号
  28. MoveType string `json:"BWART"` //出入库类型 ,"采购入库:101// 退货:161// 领用:201// 退库:202(字典)// 报废:Z19"
  29. SaveType string `json:"SOBKZ"` //库存类型 特殊库存标识 "自有:空// 寄售:'K' " ,寄售表示零库存,1
  30. CostCenter string `json:"KOSTL"` //成本中心,※仅领用、退库时,输入,编码
  31. AssetCode string `json:"ANLN1"` //资产,※仅领用、退库时,财务资产码
  32. AssetSon string `json:"ANLN2"` //资产子项
  33. Provider string `json:"LIFNR"` //供应商编码,仅寄售入库业务时,输入
  34. }
  35. // "ZEILE": "1",
  36. // "MATNR": "14.01.01.01.000071",
  37. // "WERKS": "",
  38. // "LGORT": "1001",
  39. // "MENGE": "11.000000",
  40. // "MEINS": "M2",
  41. // "EBELN": "4900000026",
  42. // "EBPLP": "1",
  43. // "BWART": "101",
  44. // "SOBKZ": "",
  45. // "KOSTL": "",
  46. // "ANLN1": "",
  47. // "ANLN2": "",
  48. // "LIFNR": ""
  49. type ProofResp struct {
  50. Dest Dest `json:"DEST"`
  51. Data ProofRespData `json:"DATA"`
  52. }
  53. type ProofRespData struct {
  54. Status string `json:"MSGTY"`
  55. MsgText string `json:"MSGTX"`
  56. EqNumber string `json:"EXT01"`
  57. SapNumber string `json:"EXT02"`
  58. Ext03 string `json:"EXT03"`
  59. }
  60. type BigPartRefundReq struct {
  61. PastureID int `json:"pastureId"`
  62. ProviderID int `json:"providerId"`
  63. UseForm string `json:"useForm"`
  64. EmployeID int `json:"employeId"`
  65. CreateTime string `json:"createTime"`
  66. Note string `json:"note"`
  67. }
  68. type ProofPartReq struct {
  69. ID int `json:"id"`
  70. PastureID int `json:"pastureId"`
  71. ProviderID int `json:"providerId"`
  72. DepartmentID int `json:"departmentId"`
  73. EmpID string `json:"empId"`
  74. EmployeID int `json:"employeId"`
  75. Note string `json:"note"`
  76. ApplicatID int `json:"applicatId"`
  77. LaidType int `json:"laidType"` //入库类型
  78. UseType int `json:"useType"` //出库类型
  79. LaidCode string `json:"laidCode"` // 入库单号
  80. PurchaseID string `json:"purchaseId"` // 入库单采购单号
  81. BuyCode string `json:"No1Id"` // 入库单采购订单号
  82. UseForm string `json:"useForm"` // 出库单号,退库单号,退货单号
  83. OddCode string `json:"oddCode"` // 领用单号
  84. StorageTime string `json:"storageTime"` // 入库时间
  85. CreateTime string `json:"createTime"` // 退货时间
  86. ReceiveTime string `json:"receiveTime"` // 出库时间
  87. QuitDate string `json:"quitDate"` // 退库时间
  88. PartCode string
  89. SapNumber string `json:"sapNumber"`
  90. }
  91. func (p *ProofReq) NewReq(pr *ProofPartReq, orderType int) (e error) {
  92. p.Dest = Dest{
  93. DestID: "EQMAN",
  94. BussTp: "MM001",
  95. Url: "https://app.modernfarming.cn:7443/sap/Common/MM001/ModifyMblnr",
  96. }
  97. switch orderType {
  98. case 1:
  99. t, _ := util.ParseDate(pr.StorageTime)
  100. ds := []ProofDetail{}
  101. data := ProofReqData{
  102. PostDate: t.Format("20060102"),
  103. EqNumber: pr.LaidCode,
  104. }
  105. dao.D.DB.Raw(`select bp.partcode,bd.SapNumber from partlaid p
  106. join bigpartlaid bp on p.bigid=bp.id
  107. left join bigBuydetail bd on bp.purchaseId=bd.buyecode
  108. where bp.laidcode=?`, pr.LaidCode).Scan(&pr)
  109. // Factory: ,
  110. // Location: v.LocationID,
  111. // Quantity: v.ReceivedAmount,
  112. // Unit: v.Unit,
  113. detail := ProofDetail{
  114. // RowNumber: 1,
  115. // Code: "14.01.07.01.000243",
  116. Code: pr.PartCode,
  117. Factory: "M001",
  118. Location: "1004",
  119. Quantity: "3",
  120. Unit: "EA",
  121. OrderNumber: pr.SapNumber,
  122. OrderRowNum: "10",
  123. MoveType: "101",
  124. }
  125. ds = append(ds, detail)
  126. data.Detail = ds
  127. p.Data = data
  128. case 2:
  129. if pr.UseForm == "" {
  130. e = errors.New("退货单号为空")
  131. return
  132. }
  133. t, e := time.Parse("2006-01-02", pr.CreateTime)
  134. if e != nil {
  135. log.Errorf(e, "退货时间解析错误")
  136. }
  137. p.Data = ProofReqData{
  138. PostDate: t.Format("20060102"),
  139. EqNumber: pr.UseForm,
  140. }
  141. dao.D.DB.Raw(`select pf.partcode from PartRefund pf
  142. join bigPartRefund bpf on pf.bigid=bpf.id
  143. where bpf.useform=?`, pr.UseForm).Scan(&pr.PartCode)
  144. ds := []ProofDetail{}
  145. detail := ProofDetail{
  146. RowNumber: "1",
  147. Code: pr.PartCode,
  148. Factory: "M001",
  149. Location: "1004",
  150. Quantity: "1",
  151. Unit: "EA",
  152. MoveType: "161",
  153. OrderNumber: "4900000005",
  154. OrderRowNum: "10",
  155. }
  156. ds = append(ds, detail)
  157. p.Data.Detail = ds
  158. case 3:
  159. t, e := util.ParseDate(pr.ReceiveTime)
  160. if e != nil {
  161. return errors.Errorf("出库凭证 时间解析错误 time=%s", pr.ReceiveTime)
  162. }
  163. data := ProofReqData{
  164. PostDate: t.Format("20060102"),
  165. EqNumber: pr.UseForm,
  166. }
  167. dao.D.DB.Raw(`select partcode from partuse p
  168. join bigpartuse bp on p.bigid=bp.id where bp.useForm=?`, pr.UseForm).Scan(&pr.PartCode)
  169. ds := []ProofDetail{}
  170. detail := ProofDetail{
  171. // RowNumber: 1,
  172. // Code: "14.01.07.01.000243",
  173. Code: pr.PartCode,
  174. Factory: "M001",
  175. Location: "1004",
  176. Quantity: "1",
  177. Unit: "EA",
  178. MoveType: "201",
  179. // CostCenter: "1004",
  180. AssetCode: "40501000000",
  181. CostCenter: "9099010506",
  182. }
  183. ds = append(ds, detail)
  184. data.Detail = ds
  185. p.Data = data
  186. // Location: v.LocationID,
  187. // OrderNumber: v.BigBuyerID,
  188. // Code: v.PartCode,
  189. // Quantity: v.ReceivedAmount,
  190. // Unit: v.Unit,
  191. // RowNumber: 1,
  192. // Code: "14.01.01.01.000001",
  193. // Factory: "M001",
  194. // Location: "1004",
  195. // Quantity: "10",
  196. // Unit: "EA",
  197. // OrderNumber: "4900000003",
  198. // OrderRowNum: "10",
  199. // MoveType: "101",
  200. case 4: //退库
  201. t, e := util.ParseDate(pr.QuitDate)
  202. if e != nil {
  203. return errors.Errorf("退库凭证 时间解析错误 QuitDate=%s,useform=%s", pr.QuitDate, pr.UseForm)
  204. }
  205. data := ProofReqData{
  206. PostDate: t.Format("20060102"),
  207. EqNumber: pr.UseForm,
  208. }
  209. if e := dao.D.DB.Raw(`select partcode from partuse p
  210. join bigpartuse bp on p.bigid=bp.id where bp.useForm=?`, pr.UseForm).Scan(&pr.PartCode).Error; e != nil {
  211. return errors.Errorf("退库凭证 备件编号查询错误 useform=%s", pr.UseForm)
  212. }
  213. ds := []ProofDetail{}
  214. detail := ProofDetail{
  215. // RowNumber: 1,
  216. Code: pr.PartCode,
  217. Factory: "M001",
  218. Location: "1004",
  219. Quantity: "1",
  220. Unit: "EA",
  221. MoveType: "202",
  222. AssetCode: "40501000000",
  223. CostCenter: "9099010506",
  224. }
  225. ds = append(ds, detail)
  226. data.Detail = ds
  227. p.Data = data
  228. }
  229. return
  230. }