| | |
| | | //@return: err error |
| | | |
| | | func (slf *PurchaseService) CreatePurchase(record *purchase.Purchase, productList []*purchase.PurchaseProducts) (err error) { |
| | | err = DealPrice(record, productList) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { |
| | | err = tx.Create(&record).Error |
| | | if err != nil { |
| | | return err |
| | | } |
| | | for _, product := range productList { |
| | | product.PurchaseId = cast.ToInt(record.ID) |
| | | } |
| | | return tx.Create(productList).Error |
| | | }) |
| | | |
| | | return err |
| | | } |
| | | |
| | | func DealPrice(record *purchase.Purchase, productList []*purchase.PurchaseProducts) error { |
| | | var quantity decimal.Decimal |
| | | var totalPrice decimal.Decimal |
| | | var realTotalPrice decimal.Decimal |
| | |
| | | } |
| | | record.UnInvoiceAmount = record.RealTotalPrice |
| | | record.ShouldPayAmount = record.RealTotalPrice |
| | | |
| | | err = tx.Create(&record).Error |
| | | if err != nil { |
| | | return err |
| | | } |
| | | for _, product := range productList { |
| | | product.PurchaseId = cast.ToInt(record.ID) |
| | | } |
| | | return tx.Create(productList).Error |
| | | }) |
| | | |
| | | return err |
| | | return nil |
| | | } |
| | | |
| | | //@function: DeletePurchase |
| | |
| | | //@return: err error |
| | | |
| | | func (slf *PurchaseService) UpdatePurchase(params *purchase.Purchase, productList []*purchase.PurchaseProducts) (err error) { |
| | | err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { |
| | | var quantity decimal.Decimal |
| | | for _, product := range productList { |
| | | quantity = quantity.Add(product.Amount) |
| | | err = DealPrice(params, productList) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | params.Quantity = quantity |
| | | err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { |
| | | err = tx.Where("id = ?", params.ID).Updates(params).Error |
| | | if err != nil { |
| | | return err |
| | |
| | | Or("Product.name like ?", "%"+info.Keyword+"%"). |
| | | Or("supplier.name like ?", "%"+info.Keyword+"%") |
| | | } |
| | | var purchaseList []purchase.Purchase |
| | | var purchaseList []*purchase.Purchase |
| | | err = db.Count(&total).Error |
| | | if err != nil { |
| | | return purchaseList, total, err |
| | |
| | | ReportAmount: productItem.Amount.InexactFloat64(), |
| | | InspectMethod: qualityinspect.InspectMethod_InspectMethodAll, |
| | | InspectAmount: productItem.Amount.InexactFloat64(), |
| | | PurchaseOrderId: record.Number, |
| | | } |
| | | inspectOrders = append(inspectOrders, inspectOrder) |
| | | } |
| | | if len(inspectOrders) == 0 { |
| | | return nil |
| | | } |
| | | inspectRequest := qualityinspect.SendPurchaseInspectRequest{List: inspectOrders} |
| | | _, err = qualityinspect.NewQualityInspectServiceClient(qualityinspect.Conn).SendPurchaseInspect(context.Background(), &inspectRequest) |
| | | return err |