mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Feat(BE-339): make reporting purchase per supplier with filterization
This commit is contained in:
@@ -26,7 +26,6 @@ func NewPurchaseSupplierRepository(db *gorm.DB) PurchaseSupplierRepository {
|
||||
}
|
||||
|
||||
func (r *purchaseSupplierRepositoryImpl) baseSupplierQuery(ctx context.Context, filters *validation.PurchaseSupplierQuery) *gorm.DB {
|
||||
// Tentukan kolom tanggal yang akan dipakai untuk filter
|
||||
dateColumn := "purchase_items.received_date"
|
||||
switch strings.ToLower(strings.TrimSpace(filters.FilterBy)) {
|
||||
case "po_date":
|
||||
@@ -60,14 +59,14 @@ func (r *purchaseSupplierRepositoryImpl) baseSupplierQuery(ctx context.Context,
|
||||
Where("warehouses.area_id = ?", filters.AreaId)
|
||||
}
|
||||
|
||||
if filters.DateFrom != "" {
|
||||
if dateFrom, err := utils.ParseDateString(filters.DateFrom); err == nil {
|
||||
if filters.StartDate != "" {
|
||||
if dateFrom, err := utils.ParseDateString(filters.StartDate); err == nil {
|
||||
db = db.Where(fmt.Sprintf("DATE(%s) >= ?", dateColumn), dateFrom)
|
||||
}
|
||||
}
|
||||
|
||||
if filters.DateTo != "" {
|
||||
if dateTo, err := utils.ParseDateString(filters.DateTo); err == nil {
|
||||
if filters.EndDate != "" {
|
||||
if dateTo, err := utils.ParseDateString(filters.EndDate); err == nil {
|
||||
db = db.Where(fmt.Sprintf("DATE(%s) <= ?", dateColumn), dateTo)
|
||||
}
|
||||
}
|
||||
@@ -171,14 +170,14 @@ func (r *purchaseSupplierRepositoryImpl) GetItemsBySuppliers(ctx context.Context
|
||||
Where("warehouses.area_id = ?", filters.AreaId)
|
||||
}
|
||||
|
||||
if filters.DateFrom != "" {
|
||||
if dateFrom, err := utils.ParseDateString(filters.DateFrom); err == nil {
|
||||
if filters.StartDate != "" {
|
||||
if dateFrom, err := utils.ParseDateString(filters.StartDate); err == nil {
|
||||
db = db.Where(fmt.Sprintf("DATE(%s) >= ?", dateColumn), dateFrom)
|
||||
}
|
||||
}
|
||||
|
||||
if filters.DateTo != "" {
|
||||
if dateTo, err := utils.ParseDateString(filters.DateTo); err == nil {
|
||||
if filters.EndDate != "" {
|
||||
if dateTo, err := utils.ParseDateString(filters.EndDate); err == nil {
|
||||
db = db.Where(fmt.Sprintf("DATE(%s) <= ?", dateColumn), dateTo)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user