Add fieldset for currency in tax details page

This commit is contained in:
jordi fita mas 2023-01-28 12:24:52 +01:00
parent 7513030334
commit 3b7d4e0d3e
4 changed files with 113 additions and 59 deletions

View File

@ -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(&currency.Code, &currency.Symbol)
if err != nil {
panic(err)
}
currencies = append(currencies, currency)
}
if rows.Err() != nil {
panic(rows.Err())
}
return currencies
}

View File

@ -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 <jordi@tandem.blog>\n"
"Language-Team: Catalan <ca@dodds.net>\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"

View File

@ -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 <jordi@tandem.blog>\n"
"Language-Team: Spanish <es@tp.org.es>\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"

View File

@ -52,7 +52,19 @@
<label for="country">{{( pgettext "Country" "input" )}}<label>
</div>
<fieldset>
<legend id="currency-legend">{{( pgettext "Currency" "input" )}}</legend>
<select id="currency" name="currency" aria-labelledby="currency-legend">
{{- range $currency := .Currencies }}
<option value="{{ .Code }}" {{ if eq .Code $.CurrencyCode }}selected="selected"{{ end }}>{{ .Symbol }} ({{ .Code }})</option>
{{- end }}
</select>
</fieldset>
<fieldset>
<button type="submit">{{( pgettext "Save changes" "action" )}}</button>
</fieldset>
</form>
</section>
{{- end }}