diff --git a/pkg/invoices.go b/pkg/invoices.go index 36a4907..0098e6c 100644 --- a/pkg/invoices.go +++ b/pkg/invoices.go @@ -79,7 +79,11 @@ func mustCollectInvoiceEntries(ctx context.Context, conn *Conn, company *Company maybeAppendWhere("invoice_date >= $%d", filters.FromDate.String(), nil) maybeAppendWhere("invoice_date <= $%d", filters.ToDate.String(), nil) if len(filters.Tags.Tags) > 0 { - appendWhere("invoice.tags && $%d", filters.Tags) + if filters.TagsCondition.String() == "and" { + appendWhere("invoice.tags @> $%d", filters.Tags) + } else { + appendWhere("invoice.tags && $%d", filters.Tags) + } } rows := conn.MustQuery(ctx, fmt.Sprintf(` select invoice.slug @@ -144,6 +148,7 @@ type invoiceFilterForm struct { FromDate *InputField ToDate *InputField Tags *TagsField + TagsCondition *SelectField } func newInvoiceFilterForm(ctx context.Context, conn *Conn, locale *Locale, company *Company) *invoiceFilterForm { @@ -181,6 +186,15 @@ func newInvoiceFilterForm(ctx context.Context, conn *Conn, locale *Locale, compa Name: "tags", Label: pgettext("input", "Tags", locale), }, + TagsCondition: &SelectField{ + Name: "tags_condition", + Label: pgettext("input", "Tags Condition", locale), + Selected: []string{"and"}, + Options: []*SelectOption{ + {Value: "and", Label: pgettext("logical", "AND", locale)}, + {Value: "or", Label: pgettext("logical", "OR", locale)}, + }, + }, } } @@ -194,6 +208,7 @@ func (form *invoiceFilterForm) Parse(r *http.Request) error { form.FromDate.FillValue(r) form.ToDate.FillValue(r) form.Tags.FillValue(r) + form.TagsCondition.FillValue(r) return nil } diff --git a/web/template/invoices/index.gohtml b/web/template/invoices/index.gohtml index 366d6df..3bf0ebd 100644 --- a/web/template/invoices/index.gohtml +++ b/web/template/invoices/index.gohtml @@ -36,6 +36,7 @@ {{ template "input-field" .ToDate }} {{ template "input-field" .InvoiceNumber }} {{ template "tags-field" .Tags }} + {{ template "select-field" .TagsCondition }} {{ end }}