From 97ad76d82cc2556932ec076846833d71a9dcfd51 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Wed, 3 May 2023 12:40:07 +0200 Subject: [PATCH] =?UTF-8?q?Deduplicate=20the=20SQL=20for=20getting=20the?= =?UTF-8?q?=20options=20for=20customer=E2=80=99s=20select=20field?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/invoices.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/invoices.go b/pkg/invoices.go index 42bbd4c..a20274d 100644 --- a/pkg/invoices.go +++ b/pkg/invoices.go @@ -159,7 +159,7 @@ func newInvoiceFilterForm(ctx context.Context, conn *Conn, locale *Locale, compa Name: "customer", Label: pgettext("input", "Customer", locale), EmptyLabel: gettext("All customers", locale), - Options: MustGetOptions(ctx, conn, "select contact_id::text, business_name from contact where company_id = $1 order by business_name", company.Id), + Options: mustGetContactOptions(ctx, conn, company), }, InvoiceStatus: &SelectField{ Name: "invoice_status", @@ -579,7 +579,7 @@ func newInvoiceForm(ctx context.Context, conn *Conn, locale *Locale, company *Co Name: "customer", Label: pgettext("input", "Customer", locale), Required: true, - Options: MustGetOptions(ctx, conn, "select contact_id::text, business_name from contact where company_id = $1 order by business_name", company.Id), + Options: mustGetContactOptions(ctx, conn, company), }, Date: &InputField{ Name: "date", @@ -738,6 +738,10 @@ func mustGetTaxOptions(ctx context.Context, conn *Conn, company *Company) []*Sel return MustGetGroupedOptions(ctx, conn, "select tax_id::text, tax.name, tax_class.name from tax join tax_class using (tax_class_id) where tax.company_id = $1 order by tax_class.name, tax.name", company.Id) } +func mustGetContactOptions(ctx context.Context, conn *Conn, company *Company) []*SelectOption { + return MustGetOptions(ctx, conn, "select contact_id::text, business_name from contact where company_id = $1 order by business_name", company.Id) +} + type invoiceProductForm struct { locale *Locale company *Company