mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
FIX[BE] :add handling for empty input in ToSummaryDto function to return zeroed summary
This commit is contained in:
@@ -122,16 +122,23 @@ func ToSalesAgeDTO(e entity.MarketingDeliveryProduct) SalesDTO {
|
||||
}
|
||||
|
||||
func ToSummaryDto(e []entity.MarketingDeliveryProduct) SummaryDTO {
|
||||
|
||||
var totalSalesPrice, totalActualPrice, sumSales, sumActual float64
|
||||
count := len(e)
|
||||
|
||||
if count == 0 {
|
||||
return SummaryDTO{
|
||||
TotalSalesPrice: 0,
|
||||
TotalActualPrice: 0,
|
||||
AvgSalesPrice: 0,
|
||||
AvgActualPrice: 0,
|
||||
}
|
||||
}
|
||||
|
||||
for _, item := range e {
|
||||
totalSalesPrice += item.MarketingProduct.TotalPrice
|
||||
totalActualPrice += item.TotalPrice
|
||||
sumSales += item.MarketingProduct.UnitPrice
|
||||
sumActual += item.UnitPrice
|
||||
|
||||
}
|
||||
|
||||
return SummaryDTO{
|
||||
|
||||
Reference in New Issue
Block a user