Skip to content
Snippets Groups Projects
Unverified Commit 0f198974 authored by meskio's avatar meskio :tent:
Browse files

List transactions by product

parent 8dece1dc
Branches
No related tags found
No related merge requests found
......@@ -4,6 +4,8 @@ import (
"errors"
"fmt"
"log"
"strconv"
"strings"
"time"
"gorm.io/gorm"
......@@ -69,6 +71,22 @@ func (d *DB) ListTransactions(query map[string][]string) (transactions []Transac
tx = tx.Where("proxy in ?", v)
case "type":
tx = tx.Where("type in ?", v)
case "product":
var ids []interface{}
where := make([]string, len(v))
for i := range v {
var id int
id, err = strconv.Atoi(v[i])
if err != nil {
return
}
ids = append(ids, id, id)
where[i] = "purchases.product = ? OR order_products.product_code = ?"
}
tx = tx.Joins("left join purchases on purchases.`transaction` = transactions.id").
Joins("left join order_purchases on order_purchases.transaction_id = transactions.id").
Joins("left join order_products on order_products.id = order_purchases.order_product_id").
Where(strings.Join(where, " OR "), ids...)
default:
log.Printf("Unexpected transaction query: %s %v", k, v)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment