Merge branch 'development' into 'staging'

Development

See merge request mbugroup/lti-api!314
This commit is contained in:
Adnan Zahir
2026-02-06 11:31:55 +07:00
7 changed files with 102 additions and 6 deletions
@@ -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
@@ -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,
)
}
@@ -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", ""),
}
@@ -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
}
@@ -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)
@@ -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"`
}
+9
View File
@@ -161,6 +161,15 @@ const (
ExpenseCategoryNonBOP ExpenseCategory = "NON-BOP"
)
// -------------------------------------------------------------------
// Filter Customer Payment
// -------------------------------------------------------------------
const (
CustomerPaymentFilterByTransDate = "TRANS_DATE"
CustomerPaymentFilterByRealizationDate = "REALIZATION_DATE"
)
// -------------------------------------------------------------------
// Payment Method
// -------------------------------------------------------------------