Skip to content

Commit

Permalink
fix: Search Customer filter query
Browse files Browse the repository at this point in the history
  • Loading branch information
yigithancolak committed Nov 4, 2023
1 parent 941ea41 commit 65eeef6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions postgresdb/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,23 @@ func (s *Store) ListCustomersWithSearchFilter(filter model.SearchCustomerFilter,
argCount++
}

var latePaymentCondition, upcomingPaymentCondition string

if filter.LatePayment != nil && *filter.LatePayment {
query += " AND next_payment <= CURRENT_DATE"
latePaymentCondition = "next_payment <= CURRENT_DATE"
}

if filter.UpcomingPayment != nil && *filter.UpcomingPayment {
query += " AND next_payment > CURRENT_DATE AND next_payment <= CURRENT_DATE + INTERVAL '7 days'"
upcomingPaymentCondition = "next_payment > CURRENT_DATE AND next_payment <= CURRENT_DATE + INTERVAL '7 days'"
}

// If both conditions are provided, combine them with OR
if latePaymentCondition != "" && upcomingPaymentCondition != "" {
query += fmt.Sprintf(" AND (%s OR %s)", latePaymentCondition, upcomingPaymentCondition)
} else if latePaymentCondition != "" {
query += " AND " + latePaymentCondition
} else if upcomingPaymentCondition != "" {
query += " AND " + upcomingPaymentCondition
}

if offset != nil && limit != nil {
Expand Down

0 comments on commit 65eeef6

Please sign in to comment.