mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-22 22:35:43 +00:00
[FEAT/BE]Fix create avaible qty
This commit is contained in:
@@ -1073,19 +1073,37 @@ func (s *recordingService) computeAndUpdateMetrics(ctx context.Context, tx *gorm
|
||||
var remainingChick float64
|
||||
if totalChick > 0 {
|
||||
totalChickFloat := float64(totalChick)
|
||||
remainingChick = totalChickFloat - cumDepletionQty
|
||||
if remainingChick < 0 {
|
||||
remainingChick = 0
|
||||
}
|
||||
updates["total_chick_qty"] = remainingChick
|
||||
recording.TotalChickQty = &remainingChick
|
||||
if s.FifoSvc != nil {
|
||||
// totalChick already represents available qty (total_qty - total_used_qty).
|
||||
remainingChick = totalChickFloat
|
||||
updates["total_chick_qty"] = remainingChick
|
||||
recording.TotalChickQty = &remainingChick
|
||||
|
||||
cumRate := 0.0
|
||||
if totalChickFloat > 0 {
|
||||
cumRate = (cumDepletionQty / totalChickFloat) * 100
|
||||
baseChick := initialChickin
|
||||
if baseChick <= 0 {
|
||||
baseChick = totalChickFloat + cumDepletionQty
|
||||
}
|
||||
cumRate := 0.0
|
||||
if baseChick > 0 {
|
||||
cumRate = (cumDepletionQty / baseChick) * 100
|
||||
}
|
||||
updates["cum_depletion_rate"] = cumRate
|
||||
recording.CumDepletionRate = &cumRate
|
||||
} else {
|
||||
remainingChick = totalChickFloat - cumDepletionQty
|
||||
if remainingChick < 0 {
|
||||
remainingChick = 0
|
||||
}
|
||||
updates["total_chick_qty"] = remainingChick
|
||||
recording.TotalChickQty = &remainingChick
|
||||
|
||||
cumRate := 0.0
|
||||
if totalChickFloat > 0 {
|
||||
cumRate = (cumDepletionQty / totalChickFloat) * 100
|
||||
}
|
||||
updates["cum_depletion_rate"] = cumRate
|
||||
recording.CumDepletionRate = &cumRate
|
||||
}
|
||||
updates["cum_depletion_rate"] = cumRate
|
||||
recording.CumDepletionRate = &cumRate
|
||||
} else {
|
||||
updates["total_chick_qty"] = gorm.Expr("NULL")
|
||||
updates["cum_depletion_rate"] = gorm.Expr("NULL")
|
||||
|
||||
Reference in New Issue
Block a user