| | |
| | | |
| | | import ( |
| | | "context" |
| | | "github.com/shopspring/decimal" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "srm/global" |
| | |
| | | |
| | | func (slf *PurchaseService) CreatePurchase(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) |
| | | } |
| | | params.Quantity = quantity |
| | | err = tx.Create(¶ms).Error |
| | | if err != nil { |
| | | return err |
| | |
| | | |
| | | 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) |
| | | } |
| | | params.Quantity = quantity |
| | | err = tx.Where("id = ?", params.ID).Updates(params).Error |
| | | if err != nil { |
| | | return err |