123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- package http
- import (
- "time"
- "github.com/pkg/errors"
- "kpt.xdmy/apiserver/dao"
- "kpt.xdmy/apiserver/model"
- "kpt.xdmy/pkg/log"
- "kpt.xdmy/pkg/util"
- )
- type OrderResp struct {
- Dest `json:"DEST"`
- Data OrderRespData `json:"DATA"`
- }
- type OrderRespData struct {
- Status string `json:"MSGTY"`
- MsgText string `json:"MSGTX"`
- EqNumber string `json:"EXT01"`
- SapNumber string `json:"EXT02"`
- }
- type OrderReq struct {
- Dest `json:"DEST"`
- Data Order `json:"DATA"`
- }
- type Order struct {
- CompanyCode string `json:"BUKRS"` // 公司代码
- SupplierCode string `json:"LIFNR"` // 供应商编码
- IsCancle string `json:"ZKHFLG"` // 是否退货 "是:X
- ProofType string `json:"BSART"` // 采购凭证类型 字典
- OrderDate string `json:"BEDAT"` // 订单日期
- Organization string `json:"EKORG"` // 采购组织 字典
- Group string `json:"EKGRP"` // 采购组 字典
- PayCondition string `json:"ZTERM"` // 付款条件 字典
- CurrencyCode string `json:"WAERS"` // 货币码 默认:CNY
- EqSysCode string `json:"ZEBELN"` // 订单编号
- Detail []OrderDetail `json:"TEKPO"`
- }
- type OrderDetail struct {
- IsOwn string `json:"PSTYP"` // 自有订单,"自有:空// 寄售:'K' "
- MaterialCode string `json:"MATNR"` //物料编码
- Quantity string `json:"MENGE"` // 数量
- DeliveryDate string `json:"EINDT"` // 交货日期
- Unit string `json:"MEINS"` // 单位
- NetPrice string `json:"NETPR"` // 净价
- Per string `json:"PEINH"` // 每 默认:1
- Factory string `json:"WERKS"` // 工厂
- Location string `json:"LGORT"` //库存地点 字典
- IsFree string `json:"UMSON"` //是否免费 "是:X
- TaxCode string `json:"MWSKZ"` // 税码 字典
- RowNumber string `json:"EBELP"` //行号
- Dflag string `json:"LOEKZ"` // 删除标识 "是:L// 否:空"
- }
- func (o *OrderReq) NewReq(p *model.BigBuyDetail) (e error) {
- path := "http OrderReq NewReq"
- o.Dest = Dest{
- DestID: "EQMAN",
- BussTp: "MM007",
- Url: "https://app.modernfarming.cn:7443/sap/Common/MM007/PurchaseOrder",
- }
- pv := &model.Provider{ID: p.ProviderID}
- ps := &model.Pasture{ID: p.PastureID}
- bds := make([]model.BuyDetail, 0)
- c := util.NewMap("bigid", p.ID)
- sl := make([]OrderDetail, 0)
- if e = model.First(pv); e != nil {
- log.Printf("%s:采购订单供应商查不到", path)
- return
- }
- if e = model.First(ps); e != nil {
- log.Printf("%s:采购订单牧场查不到", path)
- return
- }
- model.Find(c, &bds)
- if len(bds) == 0 {
- e = errors.Errorf("%s:采购订单明细查询为空", path)
- log.Print(e.Error())
- return
- }
- o.Data = Order{
- IsCancle: "",
- SupplierCode: "100224",
- OrderDate: p.BuyerDate.Format("20060102"),
- PayCondition: "",
- CompanyCode: "1004",
- CurrencyCode: "CNY",
- ProofType: "ZNB4",
- EqSysCode: p.BuyeCode[4:],
- // EqSysCode: "A0001",
- Organization: "9099",
- Group: "A02",
- // CompanyCode: ps.PastureNumber,
- // SupplierCode: pv.ProviderNumber,
- // OrderDate: p.BuyerDate.Format("20060102"),
- }
- for _, v := range bds {
- dao.D.DB.Raw(`SELECT p.partcode from parts p join contract c on c.partid=p.id where
- c.id=?`, v.ContractID).Scan(&v.PartCode)
- pd := OrderDetail{
- // Quantity: v.Amount,
- // DeliveryDate: v.ReceiveDate.Format("20060102"),
- // IsOwn: util.ZeroStr(c.IsZeroStock == 1, "K"),
- // NetPrice: v.Price,
- // Unit: ps.Unit,
- // Factory: p.Data.CompanyCode,
- // Location: "",
- // IsFree: "",
- MaterialCode: v.PartCode,
- // MaterialCode: "14.01.07.01.000243",
- Quantity: "11",
- DeliveryDate: p.BuyerDate.Add(time.Hour * 24 * 7).Format("20060102"),
- Unit: "EA",
- NetPrice: "11",
- Per: "1",
- Factory: "M001",
- TaxCode: "J0",
- RowNumber: "10",
- }
- sl = append(sl, pd)
- }
- o.Data.Detail = sl
- return
- }
|