package model import ( "time" "github.com/pkg/errors" "kpt.xdmy/pkg/util" ) type BigPartLaid struct { // 入库单 CreatDate time.Time `gorm:"column:creatDate"` EmpID int `gorm:"column:empId"` ID int `gorm:"column:id"` Issync int `gorm:"column:issync"` LaidCode string `gorm:"column:laidCode"` LaidType int `gorm:"column:laidType"` Msg string `gorm:"column:msg"` PastureID int `gorm:"column:pastureId"` PurchaseID string `gorm:"column:purchaseId"` StorageTime time.Time `gorm:"column:storageTime"` // add ProofCode string ` gorm:"column:proofCode"` ProofYear string ` gorm:"column:proofYear"` } type PartLaid struct { BigID int `gorm:"column:bigId"` BigBuyerId string ` gorm:"column:bigBuyerId"` BrandID int `gorm:"column:brandId"` BuydetailID int `gorm:"column:buydetailId"` ContractID int `gorm:"column:contractId"` LocationID int `gorm:"column:locationId"` PartID int `gorm:"column:partId"` ProviderID int `gorm:"column:providerId"` PastureID int `gorm:"column:pastureId"` BuyAmount int `gorm:"column:buyAmount"` ID int `gorm:"column:id"` Note string `gorm:"column:note"` OrderNumber string `gorm:"column:orderNumber"` PartCode string `gorm:"column:partCode"` PartName string `gorm:"column:partName"` Price float32 `gorm:"column:price"` Purpose string `gorm:"column:purpose"` ReceivedAmount string `gorm:"column:receivedAmount"` Reportery string `gorm:"column:reportery"` Specification string `gorm:"column:specification"` StorageAmount float32 `gorm:"column:storageAmount"` StorageType int `gorm:"column:storageType"` SubscribePasture string `gorm:"column:subscribePasture"` SubscribeProvider string `gorm:"column:subscribeProvider"` SumPrice float32 `gorm:"column:sumPrice"` Unit string `gorm:"column:unit"` Dflag int `gorm:"column:dflag"` RowNumber int `gorm:"column:rowNumber"` IsZeroStock int `gorm:"column:isZeroStock"` } func (p *PartLaid) ToProofPart() (r *ProofPart, e error) { mb := &Brand{ID: p.BrandID} mp := &Provider{ID: p.ProviderID} mw := &Warehouse{ID: p.LocationID} e = First(mb) e = First(mp) e = First(mw) if e != nil { e = errors.Wrapf(e, " PartLaid ToProofPart()") return } r = &ProofPart{ RowNumber: p.RowNumber, PartCode: p.PartCode, PartName: p.PartName, Specification: p.Specification, PartBrand: mb.BrandName, Supplier: mp.ProviderName, Warehouse: mw.WarehoseCode, ChangeCount: p.StorageAmount, UnitPrice: p.Price, TotalPrice: p.SumPrice, } return } func (p *BigPartLaid) NewProofPart() (mps []ProofPart, e error) { path := " BigPartLaid NewProof()" c := util.NewMap("bigid", p.ID) m := make([]PartLaid, 0) if e = Find(c, &m); e != nil { e = errors.Wrapf(e, path) return } mps = make([]ProofPart, 0) mp := new(ProofPart) for i, v := range m { if mp, e = v.ToProofPart(); e != nil { continue } mp.RowNumber = i mps = append(mps, *mp) } return } func (p *BigPartLaid) NewProof(pa *ProofReq) { pa.ChargeDate = p.CreatDate.Format("2006-01-02") pa.ProofCode = p.ProofCode pa.ProofYear = p.CreatDate.Format("2006") pa.OrderNumberId = p.ID }