From 248ca1d5228ffa480eb6c04495288759a6b7f2c5 Mon Sep 17 00:00:00 2001 From: giovanni Date: Thu, 5 Feb 2026 10:27:00 +0700 Subject: [PATCH 1/4] adjust query value notes --- internal/modules/closings/repositories/closing.repository.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/modules/closings/repositories/closing.repository.go b/internal/modules/closings/repositories/closing.repository.go index a4db4694..5fd6b7e9 100644 --- a/internal/modules/closings/repositories/closing.repository.go +++ b/internal/modules/closings/repositories/closing.repository.go @@ -522,7 +522,7 @@ SELECT std.usage_qty AS quantity, u.id AS unit_id, u.name AS unit, - 'Stock Refill' AS notes + st.reason AS notes FROM stock_transfer_details std JOIN stock_transfers st ON st.id = std.stock_transfer_id LEFT JOIN warehouses fw ON fw.id = st.from_warehouse_id @@ -622,7 +622,7 @@ SELECT std.usage_qty AS quantity, u.id AS unit_id, u.name AS unit, - 'Transfer to other unit' AS notes + st.reason AS notes FROM stock_transfer_details std JOIN stock_transfers st ON st.id = std.stock_transfer_id LEFT JOIN warehouses fw ON fw.id = st.from_warehouse_id From fc157dfd79f43283f65c1dcd773c20c18f709feb Mon Sep 17 00:00:00 2001 From: "Hafizh A. Y" Date: Thu, 5 Feb 2026 14:16:02 +0700 Subject: [PATCH 2/4] fix(BE): filter by transaction or realization in report customer payment --- .../controllers/repport.controller.go | 1 + .../repports/services/repport.service.go | 20 ++++++++++++++++--- .../validations/repport.validation.go | 1 + internal/utils/constant.go | 9 +++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/internal/modules/repports/controllers/repport.controller.go b/internal/modules/repports/controllers/repport.controller.go index 9becdf87..aff0a718 100644 --- a/internal/modules/repports/controllers/repport.controller.go +++ b/internal/modules/repports/controllers/repport.controller.go @@ -324,6 +324,7 @@ func (c *RepportController) GetCustomerPayment(ctx *fiber.Ctx) error { Page: ctx.QueryInt("page", 1), Limit: ctx.QueryInt("limit", 10), CustomerIDs: customerIDs, + FilterBy: strings.ToUpper(ctx.Query("filter_by", "")), StartDate: ctx.Query("start_date", ""), EndDate: ctx.Query("end_date", ""), } diff --git a/internal/modules/repports/services/repport.service.go b/internal/modules/repports/services/repport.service.go index 713fe6a4..38fdd74b 100644 --- a/internal/modules/repports/services/repport.service.go +++ b/internal/modules/repports/services/repport.service.go @@ -582,6 +582,11 @@ func (s *repportService) processCustomerPayment(ctx context.Context, customerID return dto.CustomerPaymentReportItem{}, err } + filterBy := strings.ToUpper(strings.TrimSpace(params.FilterBy)) + if filterBy == "" { + filterBy = utils.CustomerPaymentFilterByTransDate + } + var startDate, endDate *time.Time if params.StartDate != "" { parsed, err := time.ParseInLocation("2006-01-02", params.StartDate, location) @@ -600,11 +605,20 @@ func (s *repportService) processCustomerPayment(ctx context.Context, customerID } for _, row := range rows { - transDate := row.TransDate.In(location) - if startDate != nil && transDate.Before(*startDate) { + var compareDate time.Time + if filterBy == utils.CustomerPaymentFilterByRealizationDate { + if row.DeliveryDate == nil { + continue + } + compareDate = row.DeliveryDate.In(location) + } else { + compareDate = row.TransDate.In(location) + } + + if startDate != nil && compareDate.Before(*startDate) { continue } - if endDate != nil && transDate.After(*endDate) { + if endDate != nil && compareDate.After(*endDate) { continue } filteredRows = append(filteredRows, row) diff --git a/internal/modules/repports/validations/repport.validation.go b/internal/modules/repports/validations/repport.validation.go index 37c581d9..97ea60fa 100644 --- a/internal/modules/repports/validations/repport.validation.go +++ b/internal/modules/repports/validations/repport.validation.go @@ -85,6 +85,7 @@ type CustomerPaymentQuery struct { Page int `query:"page" validate:"omitempty,min=1,gt=0"` Limit int `query:"limit" validate:"omitempty,min=1,max=100,gt=0"` CustomerIDs []uint `query:"customer_ids" validate:"omitempty,dive,gt=0"` + FilterBy string `query:"filter_by" validate:"omitempty,oneof=TRANS_DATE REALIZATION_DATE"` StartDate string `query:"start_date" validate:"omitempty,datetime=2006-01-02"` EndDate string `query:"end_date" validate:"omitempty,datetime=2006-01-02"` } diff --git a/internal/utils/constant.go b/internal/utils/constant.go index d395ad3c..2b91f579 100644 --- a/internal/utils/constant.go +++ b/internal/utils/constant.go @@ -161,6 +161,15 @@ const ( ExpenseCategoryNonBOP ExpenseCategory = "NON-BOP" ) +// ------------------------------------------------------------------- +// Filter Customer Payment +// ------------------------------------------------------------------- + +const ( + CustomerPaymentFilterByTransDate = "TRANS_DATE" + CustomerPaymentFilterByRealizationDate = "REALIZATION_DATE" +) + // ------------------------------------------------------------------- // Payment Method // ------------------------------------------------------------------- From 58aed76bbb9666bd4cefef89e6ce33d167b0d47a Mon Sep 17 00:00:00 2001 From: giovanni Date: Fri, 6 Feb 2026 10:58:54 +0700 Subject: [PATCH 3/4] add query for feed supplier --- .../hpp_per_kandang.repository.go | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/internal/modules/repports/repositories/hpp_per_kandang.repository.go b/internal/modules/repports/repositories/hpp_per_kandang.repository.go index eeb09e92..e13d3f17 100644 --- a/internal/modules/repports/repositories/hpp_per_kandang.repository.go +++ b/internal/modules/repports/repositories/hpp_per_kandang.repository.go @@ -6,6 +6,7 @@ import ( entity "gitlab.com/mbugroup/lti-api.git/internal/entities" "gitlab.com/mbugroup/lti-api.git/internal/utils" + "gitlab.com/mbugroup/lti-api.git/internal/utils/fifo" "gorm.io/gorm" ) @@ -208,6 +209,75 @@ func (r *hppPerKandangRepository) GetFeedOvkDocCostByPeriod(ctx context.Context, } } + feedRows := make([]struct { + ProjectFlockKandangID uint + FeedCost float64 + SupplierID *uint + SupplierName *string + SupplierAlias *string + }, 0) + + feedQuery := r.db.WithContext(ctx). + Table("recordings AS r"). + Select(` + r.project_flock_kandangs_id AS project_flock_kandang_id, + s.id AS supplier_id, + s.name AS supplier_name, + s.alias AS supplier_alias`). + Joins("JOIN recording_stocks AS rs ON rs.recording_id = r.id"). + Joins("JOIN product_warehouses AS pw ON pw.id = rs.product_warehouse_id"). + Joins("JOIN flags AS f ON f.flagable_id = pw.product_id AND f.flagable_type = ?", entity.FlagableTypeProduct). + Joins("JOIN stock_allocations AS sa ON sa.usable_type = ? AND sa.usable_id = rs.id AND sa.stockable_type = ?", fifo.UsableKeyRecordingStock.String(), fifo.StockableKeyPurchaseItems.String()). + Joins("JOIN purchase_items AS pi ON pi.id = sa.stockable_id"). + Joins("LEFT JOIN purchases AS pur ON pur.id = pi.purchase_id"). + Joins("LEFT JOIN suppliers AS s ON s.id = pur.supplier_id"). + Where("r.project_flock_kandangs_id IN ?", projectFlockKandangIDs). + Where("r.record_datetime >= ? AND r.record_datetime < ?", start, end). + Where("f.name = ?", utils.FlagPakan). + Group("r.project_flock_kandangs_id, s.id, s.name, s.alias") + + if err := feedQuery.Scan(&feedRows).Error; err != nil { + return nil, nil, err + } + + feedSuppliers := make([]HppPerKandangSupplierRow, 0) + feedSeen := make(map[uint]map[uint]bool) + for _, feed := range feedRows { + entry, ok := costMap[feed.ProjectFlockKandangID] + if !ok { + rows = append(rows, HppPerKandangCostRow{ + ProjectFlockKandangID: feed.ProjectFlockKandangID, + }) + entry = &rows[len(rows)-1] + costMap[feed.ProjectFlockKandangID] = entry + } + entry.FeedCost += feed.FeedCost + if feed.SupplierID != nil { + if feedSeen[feed.ProjectFlockKandangID] == nil { + feedSeen[feed.ProjectFlockKandangID] = make(map[uint]bool) + } + if !feedSeen[feed.ProjectFlockKandangID][*feed.SupplierID] { + feedSeen[feed.ProjectFlockKandangID][*feed.SupplierID] = true + supplierName := "" + if feed.SupplierName != nil { + supplierName = *feed.SupplierName + } + supplierAlias := "" + if feed.SupplierAlias != nil { + supplierAlias = *feed.SupplierAlias + } + feedSuppliers = append(feedSuppliers, HppPerKandangSupplierRow{ + ProjectFlockKandangID: feed.ProjectFlockKandangID, + SupplierID: *feed.SupplierID, + SupplierName: supplierName, + SupplierAlias: supplierAlias, + Category: "FEED", + }) + } + } + } + + docSuppliers = append(docSuppliers, feedSuppliers...) return rows, docSuppliers, nil } From 18672f541e06e6001afb4dfb3037f4c7b21e5aa6 Mon Sep 17 00:00:00 2001 From: "Hafizh A. Y" Date: Fri, 6 Feb 2026 11:27:48 +0700 Subject: [PATCH 4/4] fix(BE): add payment method search in module finance --- .../finance/transactions/services/transaction.service.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/modules/finance/transactions/services/transaction.service.go b/internal/modules/finance/transactions/services/transaction.service.go index 4526b817..c72ff2a3 100644 --- a/internal/modules/finance/transactions/services/transaction.service.go +++ b/internal/modules/finance/transactions/services/transaction.service.go @@ -86,12 +86,13 @@ func (s transactionService) GetAll(c *fiber.Ctx, params *validation.Query) ([]en db = db.Where( `LOWER(payment_code) LIKE ? OR LOWER(COALESCE(reference_number, '')) LIKE ? OR + LOWER(COALESCE(payment_method, '')) LIKE ? OR LOWER(COALESCE(transaction_type, '')) LIKE ? OR LOWER(COALESCE(notes, '')) LIKE ? OR LOWER(COALESCE(customers.name, '')) LIKE ? OR LOWER(COALESCE(suppliers.name, '')) LIKE ? OR LOWER(COALESCE(banks.name, '')) LIKE ?`, - like, like, like, like, like, like, like, + like, like, like, like, like, like, like, like, ) }