From 3b7d4e0d3e2011b384624d9d14372fc9e2eb42c9 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Sat, 28 Jan 2023 12:24:52 +0100 Subject: [PATCH] Add fieldset for currency in tax details page --- pkg/company.go | 38 +++++++++++- po/ca.po | 13 ++-- po/es.po | 13 ++-- web/template/tax-details.html | 108 +++++++++++++++++++--------------- 4 files changed, 113 insertions(+), 59 deletions(-) diff --git a/pkg/company.go b/pkg/company.go index 468572e..f2fdac8 100644 --- a/pkg/company.go +++ b/pkg/company.go @@ -65,6 +65,11 @@ func getCompany(r *http.Request) *Company { return company.(*Company) } +type CurrencyOption struct { + Code string + Symbol string +} + type CountryOption struct { Code string Name string @@ -84,6 +89,8 @@ type TaxDetailsPage struct { PostalCode string CountryCode string Countries []CountryOption + CurrencyCode string + Currencies []CurrencyOption } func CompanyTaxDetailsHandler() http.Handler { @@ -107,15 +114,17 @@ func CompanyTaxDetailsHandler() http.Handler { page.City = r.FormValue("city") page.Province = r.FormValue("province") page.PostalCode = r.FormValue("postal_code") - conn.MustExec(r.Context(), "update company set business_name = $1, vatin = $2, trade_name = $3, phone = parse_packed_phone_number($4, $11), email = $5, web = $6, address = $7, city = $8, province = $9, postal_code = $10, country_code = $11 where company_id = $12", page.BusinessName, page.VATIN, page.TradeName, page.Phone, page.Email, page.Web, page.Address, page.City, page.Province, page.PostalCode, page.CountryCode, company.Id) + page.CurrencyCode = r.FormValue("currency") + conn.MustExec(r.Context(), "update company set business_name = $1, vatin = $2, trade_name = $3, phone = parse_packed_phone_number($4, $11), email = $5, web = $6, address = $7, city = $8, province = $9, postal_code = $10, country_code = $11, currency_code = $12 where company_id = $13", page.BusinessName, page.VATIN, page.TradeName, page.Phone, page.Email, page.Web, page.Address, page.City, page.Province, page.PostalCode, page.CountryCode, page.CurrencyCode, company.Id) http.Redirect(w, r, "/company/"+company.Slug+"/tax-details", http.StatusSeeOther) } else { - err := conn.QueryRow(r.Context(), "select business_name, substr(vatin::text, 3), trade_name, phone, email, web, address, city, province, postal_code, country_code from company where company_id = $1", company.Id).Scan(&page.BusinessName, &page.VATIN, &page.TradeName, &page.Phone, &page.Email, &page.Web, &page.Address, &page.City, &page.Province, &page.PostalCode, &page.CountryCode) + err := conn.QueryRow(r.Context(), "select business_name, substr(vatin::text, 3), trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code from company where company_id = $1", company.Id).Scan(&page.BusinessName, &page.VATIN, &page.TradeName, &page.Phone, &page.Email, &page.Web, &page.Address, &page.City, &page.Province, &page.PostalCode, &page.CountryCode, &page.CurrencyCode) if err != nil { panic(err) } } page.Countries = mustGetCountryOptions(r.Context(), conn, locale) + page.Currencies = mustGetCurrencyOptions(r.Context(), conn) mustRenderAppTemplate(w, r, "tax-details.html", page) }) } @@ -129,7 +138,7 @@ func mustGetCompany(r *http.Request) *Company { } func mustGetCountryOptions(ctx context.Context, conn *Conn, locale *Locale) []CountryOption { - rows, err := conn.Query(ctx, "select country.country_code, coalesce(i18n.name, country.name) from country left join country_i18n as i18n on country.country_code = i18n.country_code and i18n.lang_tag = $1", locale.Language) + rows, err := conn.Query(ctx, "select country.country_code, coalesce(i18n.name, country.name) as l10n_name from country left join country_i18n as i18n on country.country_code = i18n.country_code and i18n.lang_tag = $1 order by l10n_name", locale.Language) if err != nil { panic(err) } @@ -150,3 +159,26 @@ func mustGetCountryOptions(ctx context.Context, conn *Conn, locale *Locale) []Co return countries } + +func mustGetCurrencyOptions(ctx context.Context, conn *Conn) []CurrencyOption { + rows, err := conn.Query(ctx, "select currency_code, currency_symbol from currency order by currency_code") + if err != nil { + panic(err) + } + defer rows.Close() + + var currencies []CurrencyOption + for rows.Next() { + var currency CurrencyOption + err = rows.Scan(¤cy.Code, ¤cy.Symbol) + if err != nil { + panic(err) + } + currencies = append(currencies, currency) + } + if rows.Err() != nil { + panic(rows.Err()) + } + + return currencies +} diff --git a/po/ca.po b/po/ca.po index 4b040ab..9e8f8fa 100644 --- a/po/ca.po +++ b/po/ca.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: numerus\n" "Report-Msgid-Bugs-To: jordi@tandem.blog\n" -"POT-Creation-Date: 2023-01-24 21:37+0100\n" +"POT-Creation-Date: 2023-01-28 12:22+0100\n" "PO-Revision-Date: 2023-01-18 17:08+0100\n" "Last-Translator: jordi fita mas \n" "Language-Team: Catalan \n" @@ -77,12 +77,12 @@ msgctxt "language option" msgid "Automatic" msgstr "Automàtic" -#: web/template/profile.html:42 +#: web/template/profile.html:42 web/template/tax-details.html:66 msgctxt "action" msgid "Save changes" msgstr "Desa canvis" -#: web/template/tax-details.html:3 pkg/company.go:87 +#: web/template/tax-details.html:3 pkg/company.go:100 msgctxt "title" msgid "Tax Details" msgstr "Configuració fiscal" @@ -132,11 +132,16 @@ msgctxt "input" msgid "Postal code" msgstr "Codi postal" -#: web/template/tax-details.html:47 +#: web/template/tax-details.html:52 msgctxt "input" msgid "Country" msgstr "País" +#: web/template/tax-details.html:56 +msgctxt "input" +msgid "Currency" +msgstr "Moneda" + #: web/template/app.html:20 msgctxt "menu" msgid "Account" diff --git a/po/es.po b/po/es.po index 212b929..fa92b45 100644 --- a/po/es.po +++ b/po/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: numerus\n" "Report-Msgid-Bugs-To: jordi@tandem.blog\n" -"POT-Creation-Date: 2023-01-24 21:37+0100\n" +"POT-Creation-Date: 2023-01-28 12:22+0100\n" "PO-Revision-Date: 2023-01-18 17:45+0100\n" "Last-Translator: jordi fita mas \n" "Language-Team: Spanish \n" @@ -77,12 +77,12 @@ msgctxt "language option" msgid "Automatic" msgstr "Automático" -#: web/template/profile.html:42 +#: web/template/profile.html:42 web/template/tax-details.html:66 msgctxt "action" msgid "Save changes" msgstr "Guardar cambios" -#: web/template/tax-details.html:3 pkg/company.go:87 +#: web/template/tax-details.html:3 pkg/company.go:100 msgctxt "title" msgid "Tax Details" msgstr "Configuración fiscal" @@ -132,11 +132,16 @@ msgctxt "input" msgid "Postal code" msgstr "Código postal" -#: web/template/tax-details.html:47 +#: web/template/tax-details.html:52 msgctxt "input" msgid "Country" msgstr "País" +#: web/template/tax-details.html:56 +msgctxt "input" +msgid "Currency" +msgstr "Moneda" + #: web/template/app.html:20 msgctxt "menu" msgid "Account" diff --git a/web/template/tax-details.html b/web/template/tax-details.html index f8a3db4..742bd16 100644 --- a/web/template/tax-details.html +++ b/web/template/tax-details.html @@ -2,57 +2,69 @@

{{(pgettext "Tax Details" "title")}}

-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
-
- -
+
+ +
+
+ {{( pgettext "Currency" "input" )}} + + +
+ +
+
{{- end }}