123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- package http
- import (
- "time"
- "github.com/pkg/errors"
- "kpt.xdmy/apiserver/dao"
- "kpt.xdmy/pkg/log"
- "kpt.xdmy/pkg/util"
- )
- type ProofReq struct {
- Dest `json:"DEST"`
- Data ProofReqData `json:"DATA"`
- }
- type ProofReqData struct {
- CreateTime string `json:"BLDAT"` //业务日期
- PostDate string `json:"BUDAT"` //过账日期
- EqNumber string `json:"FRBNR"` //设备管理平台单号(入库、退货、领用、退库)
- Detail []ProofDetail `json:"MSEG"`
- }
- type ProofDetail struct {
- RowNumber string `json:"ZEILE"` //行号,入库单行号
- Code string `json:"MATNR"` //物料编码
- Factory string `json:"WERKS"` //工厂
- Location string `json:"LGORT"` //库存地点
- Quantity string `json:"MENGE"` //数量
- Unit string `json:"MEINS"` //单位
- OrderNumber string `json:"EBELN"` //采购订单号,※仅采购入库业务传输,SAP的采购订单号
- OrderRowNum string `json:"EBPLP"` //采购订单行项目号,※仅采购入库业务传输,SAP的采购订单行项目号
- MoveType string `json:"BWART"` //出入库类型 ,"采购入库:101// 退货:161// 领用:201// 退库:202(字典)// 报废:Z19"
- SaveType string `json:"SOBKZ"` //库存类型 特殊库存标识 "自有:空// 寄售:'K' " ,寄售表示零库存,1
- CostCenter string `json:"KOSTL"` //成本中心,※仅领用、退库时,输入,编码
- AssetCode string `json:"ANLN1"` //资产,※仅领用、退库时,财务资产码
- AssetSon string `json:"ANLN2"` //资产子项
- Provider string `json:"LIFNR"` //供应商编码,仅寄售入库业务时,输入
- }
- // "ZEILE": "1",
- // "MATNR": "14.01.01.01.000071",
- // "WERKS": "",
- // "LGORT": "1001",
- // "MENGE": "11.000000",
- // "MEINS": "M2",
- // "EBELN": "4900000026",
- // "EBPLP": "1",
- // "BWART": "101",
- // "SOBKZ": "",
- // "KOSTL": "",
- // "ANLN1": "",
- // "ANLN2": "",
- // "LIFNR": ""
- type ProofResp struct {
- Dest Dest `json:"DEST"`
- Data ProofRespData `json:"DATA"`
- }
- type ProofRespData struct {
- Status string `json:"MSGTY"`
- MsgText string `json:"MSGTX"`
- EqNumber string `json:"EXT01"`
- SapNumber string `json:"EXT02"`
- Ext03 string `json:"EXT03"`
- }
- type BigPartRefundReq struct {
- PastureID int `json:"pastureId"`
- ProviderID int `json:"providerId"`
- UseForm string `json:"useForm"`
- EmployeID int `json:"employeId"`
- CreateTime string `json:"createTime"`
- Note string `json:"note"`
- }
- type ProofPartReq struct {
- ID int `json:"id"`
- PastureID int `json:"pastureId"`
- ProviderID int `json:"providerId"`
- DepartmentID int `json:"departmentId"`
- EmpID string `json:"empId"`
- EmployeID int `json:"employeId"`
- Note string `json:"note"`
- ApplicatID int `json:"applicatId"`
- LaidType int `json:"laidType"` //入库类型
- UseType int `json:"useType"` //出库类型
- LaidCode string `json:"laidCode"` // 入库单号
- PurchaseID string `json:"purchaseId"` // 入库单采购单号
- BuyCode string `json:"No1Id"` // 入库单采购订单号
- UseForm string `json:"useForm"` // 出库单号,退库单号,退货单号
- OddCode string `json:"oddCode"` // 领用单号
- StorageTime string `json:"storageTime"` // 入库时间
- CreateTime string `json:"createTime"` // 退货时间
- ReceiveTime string `json:"receiveTime"` // 出库时间
- QuitDate string `json:"quitDate"` // 退库时间
- PartCode string
- SapNumber string `json:"sapNumber"`
- }
- func (p *ProofReq) NewReq(pr *ProofPartReq, orderType int) (e error) {
- p.Dest = Dest{
- DestID: "EQMAN",
- BussTp: "MM001",
- Url: "https://app.modernfarming.cn:7443/sap/Common/MM001/ModifyMblnr",
- }
- switch orderType {
- case 1:
- t, _ := util.ParseDate(pr.StorageTime)
- ds := []ProofDetail{}
- data := ProofReqData{
- PostDate: t.Format("20060102"),
- EqNumber: pr.LaidCode,
- }
- dao.D.DB.Raw(`select bp.partcode,bd.SapNumber from partlaid p
- join bigpartlaid bp on p.bigid=bp.id
- left join bigBuydetail bd on bp.purchaseId=bd.buyecode
- where bp.laidcode=?`, pr.LaidCode).Scan(&pr)
- // Factory: ,
- // Location: v.LocationID,
- // Quantity: v.ReceivedAmount,
- // Unit: v.Unit,
- detail := ProofDetail{
- // RowNumber: 1,
- // Code: "14.01.07.01.000243",
- Code: pr.PartCode,
- Factory: "M001",
- Location: "1004",
- Quantity: "3",
- Unit: "EA",
- OrderNumber: pr.SapNumber,
- OrderRowNum: "10",
- MoveType: "101",
- }
- ds = append(ds, detail)
- data.Detail = ds
- p.Data = data
- case 2:
- if pr.UseForm == "" {
- e = errors.New("退货单号为空")
- return
- }
- t, e := time.Parse("2006-01-02", pr.CreateTime)
- if e != nil {
- log.Errorf(e, "退货时间解析错误")
- }
- p.Data = ProofReqData{
- PostDate: t.Format("20060102"),
- EqNumber: pr.UseForm,
- }
- dao.D.DB.Raw(`select pf.partcode from PartRefund pf
- join bigPartRefund bpf on pf.bigid=bpf.id
- where bpf.useform=?`, pr.UseForm).Scan(&pr.PartCode)
- ds := []ProofDetail{}
- detail := ProofDetail{
- RowNumber: "1",
- Code: pr.PartCode,
- Factory: "M001",
- Location: "1004",
- Quantity: "1",
- Unit: "EA",
- MoveType: "161",
- OrderNumber: "4900000005",
- OrderRowNum: "10",
- }
- ds = append(ds, detail)
- p.Data.Detail = ds
- case 3:
- t, e := util.ParseDate(pr.ReceiveTime)
- if e != nil {
- return errors.Errorf("出库凭证 时间解析错误 time=%s", pr.ReceiveTime)
- }
- data := ProofReqData{
- PostDate: t.Format("20060102"),
- EqNumber: pr.UseForm,
- }
- dao.D.DB.Raw(`select partcode from partuse p
- join bigpartuse bp on p.bigid=bp.id where bp.useForm=?`, pr.UseForm).Scan(&pr.PartCode)
- ds := []ProofDetail{}
- detail := ProofDetail{
- // RowNumber: 1,
- // Code: "14.01.07.01.000243",
- Code: pr.PartCode,
- Factory: "M001",
- Location: "1004",
- Quantity: "1",
- Unit: "EA",
- MoveType: "201",
- // CostCenter: "1004",
- AssetCode: "40501000000",
- CostCenter: "9099010506",
- }
- ds = append(ds, detail)
- data.Detail = ds
- p.Data = data
- // Location: v.LocationID,
- // OrderNumber: v.BigBuyerID,
- // Code: v.PartCode,
- // Quantity: v.ReceivedAmount,
- // Unit: v.Unit,
- // RowNumber: 1,
- // Code: "14.01.01.01.000001",
- // Factory: "M001",
- // Location: "1004",
- // Quantity: "10",
- // Unit: "EA",
- // OrderNumber: "4900000003",
- // OrderRowNum: "10",
- // MoveType: "101",
- case 4: //退库
- t, e := util.ParseDate(pr.QuitDate)
- if e != nil {
- return errors.Errorf("退库凭证 时间解析错误 QuitDate=%s,useform=%s", pr.QuitDate, pr.UseForm)
- }
- data := ProofReqData{
- PostDate: t.Format("20060102"),
- EqNumber: pr.UseForm,
- }
- if e := dao.D.DB.Raw(`select partcode from partuse p
- join bigpartuse bp on p.bigid=bp.id where bp.useForm=?`, pr.UseForm).Scan(&pr.PartCode).Error; e != nil {
- return errors.Errorf("退库凭证 备件编号查询错误 useform=%s", pr.UseForm)
- }
- ds := []ProofDetail{}
- detail := ProofDetail{
- // RowNumber: 1,
- Code: pr.PartCode,
- Factory: "M001",
- Location: "1004",
- Quantity: "1",
- Unit: "EA",
- MoveType: "202",
- AssetCode: "40501000000",
- CostCenter: "9099010506",
- }
- ds = append(ds, detail)
- data.Detail = ds
- p.Data = data
- }
- return
- }
|