From 406eca77097f540b583e2498603a444ec6684d62 Mon Sep 17 00:00:00 2001 From: Katos <7927609+katosdev@users.noreply.github.com> Date: Sun, 23 Mar 2025 20:17:40 +0000 Subject: [PATCH] Exclude items that have a solddate from total price calculation --- backend/app/api/handlers/v1/v1_ctrl_items.go | 3 +++ backend/app/api/handlers/v1/v1_ctrl_locations.go | 5 +++++ backend/internal/data/repo/repo_items.go | 3 +++ 3 files changed, 11 insertions(+) diff --git a/backend/app/api/handlers/v1/v1_ctrl_items.go b/backend/app/api/handlers/v1/v1_ctrl_items.go index 6582adac..7242aa54 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items.go @@ -88,6 +88,9 @@ func (ctrl *V1Controller) HandleItemsGetAll() errchain.HandlerFunc { items, err := ctrl.repo.Items.QueryByGroup(ctx, ctx.GID, extractQuery(r)) totalPrice := new(big.Int) for _, item := range items.Items { + if !item.SoldTime.IsZero() { // Skip items with a non-null SoldDate + continue + } totalPrice.Add(totalPrice, big.NewInt(int64(item.PurchasePrice*100))) } diff --git a/backend/app/api/handlers/v1/v1_ctrl_locations.go b/backend/app/api/handlers/v1/v1_ctrl_locations.go index f8099b7a..33f93b30 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_locations.go +++ b/backend/app/api/handlers/v1/v1_ctrl_locations.go @@ -99,6 +99,11 @@ func (ctrl *V1Controller) GetLocationWithPrice(auth context.Context, gid uuid.UU } for _, item := range items.Items { + // Skip items with a non-zero SoldTime + if !item.SoldTime.IsZero() { + continue + } + // Convert item.Quantity to float64 for multiplication quantity := float64(item.Quantity) itemTotal := big.NewInt(int64(item.PurchasePrice * quantity * 100)) diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index 854f28c1..fd4f3aac 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -134,6 +134,9 @@ type ( Labels []LabelSummary `json:"labels"` ImageID *uuid.UUID `json:"imageId,omitempty"` + + // Sale details + SoldTime time.Time `json:"updatedAt"` } ItemOut struct {