mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 07:15:43 +00:00
Feat(BE-339):Fixing dto reporting per supplier
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||||
@@ -30,6 +31,8 @@ type PurchaseSupplierSummaryDTO struct {
|
|||||||
TotalPurchaseValue float64 `json:"total_purchase_value"`
|
TotalPurchaseValue float64 `json:"total_purchase_value"`
|
||||||
TotalTransportValue float64 `json:"total_transport_value"`
|
TotalTransportValue float64 `json:"total_transport_value"`
|
||||||
TotalAmount float64 `json:"total_amount"`
|
TotalAmount float64 `json:"total_amount"`
|
||||||
|
TotalUnitPrice float64 `json:"total_unit_price"`
|
||||||
|
TotalTransportUnitPrice float64 `json:"total_transport_unit_price"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PurchaseSupplierDTO struct {
|
type PurchaseSupplierDTO struct {
|
||||||
@@ -119,6 +122,11 @@ func ToPurchaseSupplierDTO(supplier entity.Supplier, items []entity.PurchaseItem
|
|||||||
rows := make([]PurchaseSupplierRowDTO, 0, len(items))
|
rows := make([]PurchaseSupplierRowDTO, 0, len(items))
|
||||||
summary := PurchaseSupplierSummaryDTO{}
|
summary := PurchaseSupplierSummaryDTO{}
|
||||||
|
|
||||||
|
var unitPriceSum float64
|
||||||
|
var unitPriceCount int
|
||||||
|
var transportUnitPriceSum float64
|
||||||
|
var transportUnitPriceCount int
|
||||||
|
|
||||||
for i := range items {
|
for i := range items {
|
||||||
row := ToPurchaseSupplierRowDTO(&items[i])
|
row := ToPurchaseSupplierRowDTO(&items[i])
|
||||||
rows = append(rows, row)
|
rows = append(rows, row)
|
||||||
@@ -127,6 +135,20 @@ func ToPurchaseSupplierDTO(supplier entity.Supplier, items []entity.PurchaseItem
|
|||||||
summary.TotalPurchaseValue += row.PurchaseValue
|
summary.TotalPurchaseValue += row.PurchaseValue
|
||||||
summary.TotalTransportValue += row.TransportValue
|
summary.TotalTransportValue += row.TransportValue
|
||||||
summary.TotalAmount += row.TotalAmount
|
summary.TotalAmount += row.TotalAmount
|
||||||
|
|
||||||
|
unitPriceSum += row.UnitPrice
|
||||||
|
unitPriceCount++
|
||||||
|
|
||||||
|
transportUnitPriceSum += row.TransportUnitPrice
|
||||||
|
transportUnitPriceCount++
|
||||||
|
}
|
||||||
|
|
||||||
|
if unitPriceCount > 0 {
|
||||||
|
summary.TotalUnitPrice = math.Round(unitPriceSum / float64(unitPriceCount))
|
||||||
|
}
|
||||||
|
|
||||||
|
if transportUnitPriceCount > 0 {
|
||||||
|
summary.TotalTransportUnitPrice = math.Round(transportUnitPriceSum / float64(transportUnitPriceCount))
|
||||||
}
|
}
|
||||||
|
|
||||||
return PurchaseSupplierDTO{
|
return PurchaseSupplierDTO{
|
||||||
@@ -135,4 +157,3 @@ func ToPurchaseSupplierDTO(supplier entity.Supplier, items []entity.PurchaseItem
|
|||||||
Summary: summary,
|
Summary: summary,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user