mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 23:05:44 +00:00
feat[BE]: membetulkan perhitungan hpp di module penjualan harian
This commit is contained in:
@@ -50,7 +50,7 @@ func ToRepportMarketingItemDTO(mdp entity.MarketingDeliveryProduct, hppPricePerK
|
||||
agingDays := 0
|
||||
if mdp.MarketingProduct.Marketing.SoDate.Year() > 1 {
|
||||
soDate = mdp.MarketingProduct.Marketing.SoDate
|
||||
agingDays = int(time.Now().Sub(soDate).Hours() / 24)
|
||||
agingDays = int(time.Since(soDate).Hours() / 24)
|
||||
}
|
||||
|
||||
realizationDate := time.Time{}
|
||||
@@ -113,6 +113,20 @@ func ToRepportMarketingItemDTOs(mdps []entity.MarketingDeliveryProduct, hppPrice
|
||||
return items
|
||||
}
|
||||
|
||||
func ToRepportMarketingItemDTOsWithHppMap(mdps []entity.MarketingDeliveryProduct, hppMap map[uint]float64) []RepportMarketingItemDTO {
|
||||
items := make([]RepportMarketingItemDTO, 0, len(mdps))
|
||||
for _, mdp := range mdps {
|
||||
hppPerKg := float64(0)
|
||||
if projectFlockKandang := mdp.MarketingProduct.ProductWarehouse.ProjectFlockKandang; projectFlockKandang != nil {
|
||||
if hpp, exists := hppMap[projectFlockKandang.ProjectFlockId]; exists {
|
||||
hppPerKg = hpp
|
||||
}
|
||||
}
|
||||
items = append(items, ToRepportMarketingItemDTO(mdp, hppPerKg))
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func ToSummary(mdps []entity.MarketingDeliveryProduct, hppPricePerKg float64) *Summary {
|
||||
if len(mdps) == 0 {
|
||||
return nil
|
||||
@@ -153,6 +167,37 @@ func generateDoNumber(soNumber string, deliveryDate *time.Time, warehouseId uint
|
||||
return fmt.Sprintf("%s-%s-%d", soNumber, dateStr, warehouseId)
|
||||
}
|
||||
|
||||
func ToSummaryFromDTOItems(items []RepportMarketingItemDTO) *Summary {
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
totalQty := 0
|
||||
totalWeightKg := 0.0
|
||||
totalSalesAmount := int64(0)
|
||||
totalHppAmount := int64(0)
|
||||
|
||||
for _, item := range items {
|
||||
totalQty += int(item.Qty)
|
||||
totalWeightKg += item.TotalWeightKg
|
||||
totalSalesAmount += int64(item.SalesAmount)
|
||||
totalHppAmount += int64(item.HppAmount)
|
||||
}
|
||||
|
||||
totalHppPricePerKg := float64(0)
|
||||
if totalWeightKg > 0 {
|
||||
totalHppPricePerKg = float64(totalHppAmount) / totalWeightKg
|
||||
}
|
||||
|
||||
return &Summary{
|
||||
TotalQty: totalQty,
|
||||
TotalWeightKg: totalWeightKg,
|
||||
TotalSalesAmount: totalSalesAmount,
|
||||
TotalHppAmount: totalHppAmount,
|
||||
TotalHppPricePerKg: totalHppPricePerKg,
|
||||
}
|
||||
}
|
||||
|
||||
func ToRepportMarketingResponseDTO(mdps []entity.MarketingDeliveryProduct, hppPricePerKg float64) RepportMarketingResponseDTO {
|
||||
items := ToRepportMarketingItemDTOs(mdps, hppPricePerKg)
|
||||
total := ToSummary(mdps, hppPricePerKg)
|
||||
|
||||
Reference in New Issue
Block a user