| | |
| | | var ids []uint |
| | | var purchaseList = make([]*purchase.Purchase, 0) |
| | | if info.Keyword != "" { |
| | | kw := "%" + info.Keyword + "%" |
| | | db.Distinct("srm_purchase.id").Joins("left join srm_purchase_products on srm_purchase_products.purchase_id = srm_purchase.id"). |
| | | Joins("left join srm_supplier_material on srm_supplier_material.supplier_id = srm_purchase.id"). |
| | | Joins("left join srm_supplier on srm_supplier.Id = srm_purchase.supplier_id"). |
| | | Where("srm_purchase.name like ?", "%"+info.Keyword+"%"). |
| | | Or("srm_supplier_material.name like ?", "%"+info.Keyword+"%"). |
| | | Or("srm_supplier.name like ?", "%"+info.Keyword+"%") |
| | | Where("srm_purchase.name like ? or srm_purchase.source_order like ? or srm_purchase.number like ?", kw, kw, kw). |
| | | Or("srm_supplier_material.name like ?", kw). |
| | | Or("srm_supplier.name like ?", kw) |
| | | err = db.Limit(limit).Offset(offset).Find(&ids).Error |
| | | if err != nil { |
| | | return purchaseList, total, err |
| | |
| | | return int(total), err |
| | | } |
| | | |
| | | func (slf *PurchaseService) SavePurchaseProductConfirm(list []*purchase.PurchaseProductConfirm) (err error) { |
| | | func (slf *PurchaseService) SavePurchaseProductConfirm(list []*purchase.PurchaseProductConfirm, first bool) (err error) { |
| | | if len(list) == 0 { |
| | | return errors.New("产品列表不能为空") |
| | | } |
| | |
| | | } |
| | | |
| | | m := make(map[string]interface{}) |
| | | now := int64(0) |
| | | yu := int64(0) |
| | | for _, confirm := range list { |
| | | if !confirm.NowReceiveAmount.IsZero() { |
| | | now = confirm.NowReceiveAmount.IntPart() |
| | | } |
| | | if !confirm.SurplusReceiveAmount.IsZero() { |
| | | yu = confirm.SurplusReceiveAmount.IntPart() |
| | | } |
| | | confirm.OverReceiveAmount = confirm.OverReceiveAmount.Add(confirm.NowReceiveAmount) |
| | | confirm.NotReceiveAmount = confirm.Amount.Sub(confirm.OverReceiveAmount) |
| | | } |
| | | if now == 0 && yu > 0 { |
| | | if first { |
| | | m["status"] = purchase.OrderStatusWaitReceive |
| | | } |
| | | if now > 0 && yu > 0 { |
| | | m["status"] = purchase.OrderStatusPartReceive |
| | | } |
| | | if now > 0 && yu == 0 { |
| | | m["status"] = purchase.OrderStatusWaitQuality |
| | | } else { |
| | | yu := int64(0) |
| | | for _, confirm := range list { |
| | | confirm.OverReceiveAmount = confirm.OverReceiveAmount.Add(confirm.NowReceiveAmount) |
| | | confirm.NotReceiveAmount = confirm.Amount.Sub(confirm.OverReceiveAmount) |
| | | if !confirm.SurplusReceiveAmount.IsZero() { |
| | | yu = confirm.SurplusReceiveAmount.IntPart() |
| | | } |
| | | } |
| | | if yu > 0 { |
| | | m["status"] = purchase.OrderStatusPartReceive |
| | | } |
| | | if yu == 0 { |
| | | m["status"] = purchase.OrderStatusWaitQuality |
| | | } |
| | | } |
| | | |
| | | err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { |
| | |
| | | purchaseNumber := list[0].PurchaseNumber |
| | | qualityList := make([]*purchase.PurchaseQualityInspection, 0) |
| | | for _, confirm := range list { |
| | | if confirm.NowReceiveAmount.IsZero() { |
| | | continue |
| | | } |
| | | var pqi purchase.PurchaseQualityInspection |
| | | pqi.PurchaseNumber = purchaseNumber |
| | | pqi.Principal = confirm.Principal |
| | |
| | | |
| | | func (slf *PurchaseService) UpdatePurchaseStatus(number string, status int) error { |
| | | var total int64 |
| | | err := global.GVA_DB.Model(&purchase.PurchaseQualityInspection{}).Where("purchase_number = ?", number).Where("status = ?", status).Count(&total).Error |
| | | err := global.GVA_DB.Model(&purchase.Purchase{}).Where("number = ?", number).Where("status = ?", purchase.OrderStatusWaitQuality).Count(&total).Error |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if total == 0 { |
| | | err = global.GVA_DB.Model(&purchase.Purchase{}).Where("number = ?", number).Updates(map[string]interface{}{"status": purchase.OrderStatusReceived}).Error |
| | | if total > 0 { |
| | | err = global.GVA_DB.Model(&purchase.PurchaseQualityInspection{}).Where("purchase_number = ?", number).Where("status = ?", status).Count(&total).Error |
| | | if err != nil { |
| | | return err |
| | | } |
| | | |
| | | if total == 0 { |
| | | err = global.GVA_DB.Model(&purchase.Purchase{}).Where("number = ?", number).Updates(map[string]interface{}{"status": purchase.OrderStatusReceived}).Error |
| | | if err != nil { |
| | | return err |
| | | } |
| | | } |
| | | } |
| | | return nil |
| | | } |