mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
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 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 {
|
|
usagePtr := new(float64)
|
|
*usagePtr = item.Qty
|
|
result = append(result, entity.RecordingStock{
|
|
RecordingId: recordingID,
|
|
ProductWarehouseId: item.ProductWarehouseId,
|
|
UsageQty: usagePtr,
|
|
})
|
|
}
|
|
return result
|
|
}
|
|
|
|
func MapDepletions(recordingID uint, items []validation.Depletion) []entity.RecordingDepletion {
|
|
if len(items) == 0 {
|
|
return nil
|
|
}
|
|
|
|
aggregate := make(map[uint]float64, len(items))
|
|
for _, item := range items {
|
|
if item.ProductWarehouseId == 0 || item.Qty == 0 {
|
|
continue
|
|
}
|
|
aggregate[item.ProductWarehouseId] += item.Qty
|
|
}
|
|
if len(aggregate) == 0 {
|
|
return nil
|
|
}
|
|
|
|
result := make([]entity.RecordingDepletion, 0, len(aggregate))
|
|
for warehouseID, qty := range aggregate {
|
|
if qty == 0 {
|
|
continue
|
|
}
|
|
result = append(result, entity.RecordingDepletion{
|
|
RecordingId: recordingID,
|
|
ProductWarehouseId: warehouseID,
|
|
Qty: 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,
|
|
Weight: item.Weight,
|
|
CreatedBy: createdBy,
|
|
})
|
|
}
|
|
return result
|
|
}
|