diff --git a/internal/database/migrations/20260608135241_deactivate_phases.down.sql b/internal/database/migrations/20260608135241_deactivate_phases.down.sql new file mode 100644 index 00000000..640e6620 --- /dev/null +++ b/internal/database/migrations/20260608135241_deactivate_phases.down.sql @@ -0,0 +1,2 @@ +UPDATE phases SET is_active = true +WHERE id IN (2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26); diff --git a/internal/database/migrations/20260608135241_deactivate_phases.up.sql b/internal/database/migrations/20260608135241_deactivate_phases.up.sql new file mode 100644 index 00000000..7262224d --- /dev/null +++ b/internal/database/migrations/20260608135241_deactivate_phases.up.sql @@ -0,0 +1,2 @@ +UPDATE phases SET is_active = false +WHERE id IN (2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26); diff --git a/internal/modules/daily-checklists/services/daily-checklist.service.go b/internal/modules/daily-checklists/services/daily-checklist.service.go index 91f43d06..a4e2fde9 100644 --- a/internal/modules/daily-checklists/services/daily-checklist.service.go +++ b/internal/modules/daily-checklists/services/daily-checklist.service.go @@ -1215,7 +1215,9 @@ func (s dailyChecklistService) AssignPhases(c *fiber.Ctx, id uint, req *validati } if len(phaseIDs) > 0 { - phases, err := s.PhaseRepo.GetByIDs(c.Context(), phaseIDs, nil) + phases, err := s.PhaseRepo.GetByIDs(c.Context(), phaseIDs, func(db *gorm.DB) *gorm.DB { + return db.Where("is_active = true") + }) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return fiber.NewError(fiber.StatusBadRequest, "Phase not found") diff --git a/internal/modules/master/phasess/services/phases.service.go b/internal/modules/master/phasess/services/phases.service.go index bd5cf08f..d045e696 100644 --- a/internal/modules/master/phasess/services/phases.service.go +++ b/internal/modules/master/phasess/services/phases.service.go @@ -50,6 +50,7 @@ func (s phasesService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity. phasess, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) + db = db.Where("is_active = true") if params.Search != "" { return db.Where("name ILIKE ?", "%"+params.Search+"%") } diff --git a/internal/modules/repports/dto/repportMarketing.dto_test.go b/internal/modules/repports/dto/repportMarketing.dto_test.go new file mode 100644 index 00000000..5476af42 --- /dev/null +++ b/internal/modules/repports/dto/repportMarketing.dto_test.go @@ -0,0 +1,71 @@ +package dto + +import ( + "math" + "testing" + + entity "gitlab.com/mbugroup/lti-api.git/internal/entities" +) + +func TestToMarketingReportItemsUsesDeliveryProductTotalWeight(t *testing.T) { + mdps := []entity.MarketingDeliveryProduct{ + { + Id: 1, + UsageQty: 10, + AvgWeight: 2.5, + TotalWeight: 17.75, + UnitPrice: 1000, + }, + } + + got := ToMarketingReportItems(mdps, nil, nil, nil) + + if len(got) != 1 { + t.Fatalf("expected 1 marketing report item, got %d", len(got)) + } + if got[0].TotalWeightKg != 17.75 { + t.Fatalf("expected total_weight_kg to use delivery product total_weight 17.75, got %.2f", got[0].TotalWeightKg) + } + if got[0].Qty != 10 { + t.Fatalf("expected qty to stay from usage_qty, got %.2f", got[0].Qty) + } + if got[0].AverageWeightKg != 2.5 { + t.Fatalf("expected average_weight_kg to stay from avg_weight, got %.2f", got[0].AverageWeightKg) + } + if got[0].SalesAmount != 17750 { + t.Fatalf("expected sales_amount to use delivery product total_weight, got %.2f", got[0].SalesAmount) + } +} + +func TestMarketingSummaryUsesReportItemTotalWeight(t *testing.T) { + items := []RepportMarketingItemDTO{ + { + Qty: 10, + TotalWeightKg: 17.75, + SalesAmount: 17750, + }, + { + Qty: 5, + TotalWeightKg: 8.25, + SalesAmount: 8250, + }, + } + + got := ToSummaryFromDTOItems(items) + + if got == nil { + t.Fatal("expected summary, got nil") + } + if got.TotalWeightKg != 26 { + t.Fatalf("expected summary total_weight_kg to sum item total weights, got %.2f", got.TotalWeightKg) + } + if diff := math.Abs(got.AverageWeightKg - (26.0 / 15.0)); diff > 0.000001 { + t.Fatalf("expected summary average_weight_kg to use total_weight_kg / total_qty, got %.6f", got.AverageWeightKg) + } + if got.TotalQty != 15 { + t.Fatalf("expected total qty 15, got %d", got.TotalQty) + } + if got.TotalSalesAmount != 26000 { + t.Fatalf("expected total sales amount 26000, got %d", got.TotalSalesAmount) + } +}