mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat/BE/US-76/US-78/US-79/TASK-112,120,133,121-Recording growing/TASK-187,189,202,190-Recording Laying/TASK-191,192,194,197,203-Grading Telur
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package recording
|
||||
|
||||
import (
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/production/recordings/validations"
|
||||
)
|
||||
|
||||
func MapBodyWeights(recordingID uint, items []validation.BodyWeight) []entity.RecordingBW {
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
result := make([]entity.RecordingBW, 0, len(items))
|
||||
for _, item := range items {
|
||||
totalWeight := item.TotalWeight
|
||||
if totalWeight == nil {
|
||||
calculated := item.AvgWeight * item.Qty
|
||||
totalWeight = &calculated
|
||||
}
|
||||
|
||||
result = append(result, entity.RecordingBW{
|
||||
RecordingId: recordingID,
|
||||
AvgWeight: item.AvgWeight,
|
||||
Qty: item.Qty,
|
||||
TotalWeight: *totalWeight,
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func MapStocks(recordingID uint, items []validation.Stock) []entity.RecordingStock {
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
result := make([]entity.RecordingStock, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, entity.RecordingStock{
|
||||
RecordingId: recordingID,
|
||||
ProductWarehouseId: item.ProductWarehouseId,
|
||||
UsageQty: item.UsageAmount,
|
||||
PendingQty: item.PendingQty,
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func MapDepletions(recordingID uint, items []validation.Depletion) []entity.RecordingDepletion {
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
result := make([]entity.RecordingDepletion, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, entity.RecordingDepletion{
|
||||
RecordingId: recordingID,
|
||||
ProductWarehouseId: item.ProductWarehouseId,
|
||||
Qty: item.Qty,
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func MapEggs(recordingID uint, createdBy uint, items []validation.Egg) []entity.RecordingEgg {
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
result := make([]entity.RecordingEgg, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, entity.RecordingEgg{
|
||||
RecordingId: recordingID,
|
||||
ProductWarehouseId: item.ProductWarehouseId,
|
||||
Qty: item.Qty,
|
||||
CreatedBy: createdBy,
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func ToGrams(weight float64) float64 {
|
||||
if weight <= 0 {
|
||||
return 0
|
||||
}
|
||||
if weight < 10 {
|
||||
return weight * 1000
|
||||
}
|
||||
return weight
|
||||
}
|
||||
|
||||
func GramsToKg(grams float64) float64 {
|
||||
if grams <= 0 {
|
||||
return 0
|
||||
}
|
||||
return grams / 1000
|
||||
}
|
||||
Reference in New Issue
Block a user