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) return company.(*Company)
} }
type CurrencyOption struct {
Code string
Symbol string
}
type CountryOption struct { type CountryOption struct {
Code string Code string
Name string Name string
@ -84,6 +89,8 @@ type TaxDetailsPage struct {
PostalCode string PostalCode string
CountryCode string CountryCode string
Countries []CountryOption Countries []CountryOption
CurrencyCode string
Currencies []CurrencyOption
} }
func CompanyTaxDetailsHandler() http.Handler { func CompanyTaxDetailsHandler() http.Handler {
@ -107,15 +114,17 @@ func CompanyTaxDetailsHandler() http.Handler {
page.City = r.FormValue("city") page.City = r.FormValue("city")
page.Province = r.FormValue("province") page.Province = r.FormValue("province")
page.PostalCode = r.FormValue("postal_code") 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) http.Redirect(w, r, "/company/"+company.Slug+"/tax-details", http.StatusSeeOther)
} else { } 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 { if err != nil {
panic(err) panic(err)
} }
} }
page.Countries = mustGetCountryOptions(r.Context(), conn, locale) page.Countries = mustGetCountryOptions(r.Context(), conn, locale)
page.Currencies = mustGetCurrencyOptions(r.Context(), conn)
mustRenderAppTemplate(w, r, "tax-details.html", page) 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 { 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 { if err != nil {
panic(err) panic(err)
} }
@ -150,3 +159,26 @@ func mustGetCountryOptions(ctx context.Context, conn *Conn, locale *Locale) []Co
return countries 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 "" msgstr ""
"Project-Id-Version: numerus\n" "Project-Id-Version: numerus\n"
"Report-Msgid-Bugs-To: jordi@tandem.blog\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" "PO-Revision-Date: 2023-01-18 17:08+0100\n"
"Last-Translator: jordi fita mas <jordi@tandem.blog>\n" "Last-Translator: jordi fita mas <jordi@tandem.blog>\n"
"Language-Team: Catalan <ca@dodds.net>\n" "Language-Team: Catalan <ca@dodds.net>\n"
@ -77,12 +77,12 @@ msgctxt "language option"
msgid "Automatic" msgid "Automatic"
msgstr "Automàtic" msgstr "Automàtic"
#: web/template/profile.html:42 #: web/template/profile.html:42 web/template/tax-details.html:66
msgctxt "action" msgctxt "action"
msgid "Save changes" msgid "Save changes"
msgstr "Desa canvis" 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" msgctxt "title"
msgid "Tax Details" msgid "Tax Details"
msgstr "Configuració fiscal" msgstr "Configuració fiscal"
@ -132,11 +132,16 @@ msgctxt "input"
msgid "Postal code" msgid "Postal code"
msgstr "Codi postal" msgstr "Codi postal"
#: web/template/tax-details.html:47 #: web/template/tax-details.html:52
msgctxt "input" msgctxt "input"
msgid "Country" msgid "Country"
msgstr "País" msgstr "País"
#: web/template/tax-details.html:56
msgctxt "input"
msgid "Currency"
msgstr "Moneda"
#: web/template/app.html:20 #: web/template/app.html:20
msgctxt "menu" msgctxt "menu"
msgid "Account" msgid "Account"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: numerus\n" "Project-Id-Version: numerus\n"
"Report-Msgid-Bugs-To: jordi@tandem.blog\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" "PO-Revision-Date: 2023-01-18 17:45+0100\n"
"Last-Translator: jordi fita mas <jordi@tandem.blog>\n" "Last-Translator: jordi fita mas <jordi@tandem.blog>\n"
"Language-Team: Spanish <es@tp.org.es>\n" "Language-Team: Spanish <es@tp.org.es>\n"
@ -77,12 +77,12 @@ msgctxt "language option"
msgid "Automatic" msgid "Automatic"
msgstr "Automático" msgstr "Automático"
#: web/template/profile.html:42 #: web/template/profile.html:42 web/template/tax-details.html:66
msgctxt "action" msgctxt "action"
msgid "Save changes" msgid "Save changes"
msgstr "Guardar cambios" 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" msgctxt "title"
msgid "Tax Details" msgid "Tax Details"
msgstr "Configuración fiscal" msgstr "Configuración fiscal"
@ -132,11 +132,16 @@ msgctxt "input"
msgid "Postal code" msgid "Postal code"
msgstr "Código postal" msgstr "Código postal"
#: web/template/tax-details.html:47 #: web/template/tax-details.html:52
msgctxt "input" msgctxt "input"
msgid "Country" msgid "Country"
msgstr "País" msgstr "País"
#: web/template/tax-details.html:56
msgctxt "input"
msgid "Currency"
msgstr "Moneda"
#: web/template/app.html:20 #: web/template/app.html:20
msgctxt "menu" msgctxt "menu"
msgid "Account" msgid "Account"

View File

@ -2,57 +2,69 @@
<section class="dialog-content"> <section class="dialog-content">
<h2>{{(pgettext "Tax Details" "title")}}</h2> <h2>{{(pgettext "Tax Details" "title")}}</h2>
<form method="POST"> <form method="POST">
<div class="input"> <div class="input">
<input type="text" name="business_name" id="business_name" required="required" value="{{ .BusinessName }}" placeholder="{{( pgettext "Business name" "input" )}}"> <input type="text" name="business_name" id="business_name" required="required" value="{{ .BusinessName }}" placeholder="{{( pgettext "Business name" "input" )}}">
<label for="business_name">{{( pgettext "Business name" "input" )}}</label> <label for="business_name">{{( pgettext "Business name" "input" )}}</label>
</div> </div>
<div class="input"> <div class="input">
<input type="text" name="vatin" id="vatin" required="required" value="{{ .VATIN }}" placeholder="{{( pgettext "VAT number" "input" )}}"> <input type="text" name="vatin" id="vatin" required="required" value="{{ .VATIN }}" placeholder="{{( pgettext "VAT number" "input" )}}">
<label for="vatin">{{( pgettext "VAT number" "input" )}}</label> <label for="vatin">{{( pgettext "VAT number" "input" )}}</label>
</div> </div>
<div class="input"> <div class="input">
<input type="text" name="trade_name" id="trade_name" value="{{ .TradeName }}" placeholder="{{( pgettext "Trade name" "input" )}}"> <input type="text" name="trade_name" id="trade_name" value="{{ .TradeName }}" placeholder="{{( pgettext "Trade name" "input" )}}">
<label for="trade_name">{{( pgettext "Trade name" "input" )}}</label> <label for="trade_name">{{( pgettext "Trade name" "input" )}}</label>
</div> </div>
<div class="input"> <div class="input">
<input type="tel" name="phone" id="phone" required="required" value="{{ .Phone }}" placeholder="{{( pgettext "Phone" "input" )}}"> <input type="tel" name="phone" id="phone" required="required" value="{{ .Phone }}" placeholder="{{( pgettext "Phone" "input" )}}">
<label for="phone">{{( pgettext "Phone" "input" )}}</label> <label for="phone">{{( pgettext "Phone" "input" )}}</label>
</div> </div>
<div class="input"> <div class="input">
<input type="email" name="email" id="email" required="required" value="{{ .Email }}" placeholder="{{( pgettext "Email" "input" )}}"> <input type="email" name="email" id="email" required="required" value="{{ .Email }}" placeholder="{{( pgettext "Email" "input" )}}">
<label for="email">{{( pgettext "Email" "input" )}}</label> <label for="email">{{( pgettext "Email" "input" )}}</label>
</div> </div>
<div class="input"> <div class="input">
<input type="url" name="web" id="web" value="{{ .Web }}" placeholder="{{( pgettext "Web" "input" )}}"> <input type="url" name="web" id="web" value="{{ .Web }}" placeholder="{{( pgettext "Web" "input" )}}">
<label for="web">{{( pgettext "Web" "input" )}}</label> <label for="web">{{( pgettext "Web" "input" )}}</label>
</div> </div>
<div class="input"> <div class="input">
<input type="text" name="address" id="address" class="width-2x" required="required" value="{{ .Address }}" placeholder="{{( pgettext "Address" "input" )}}"> <input type="text" name="address" id="address" class="width-2x" required="required" value="{{ .Address }}" placeholder="{{( pgettext "Address" "input" )}}">
<label for="address">{{( pgettext "Address" "input" )}}</label> <label for="address">{{( pgettext "Address" "input" )}}</label>
</div> </div>
<div class="input"> <div class="input">
<input type="text" name="city" id="city" required="required" value="{{ .City }}" placeholder="{{( pgettext "City" "input" )}}"> <input type="text" name="city" id="city" required="required" value="{{ .City }}" placeholder="{{( pgettext "City" "input" )}}">
<label for="city">{{( pgettext "City" "input" )}}</label> <label for="city">{{( pgettext "City" "input" )}}</label>
</div> </div>
<div class="input"> <div class="input">
<input type="text" name="province" id="province" required="required" value="{{ .City }}" placeholder="{{( pgettext "Province" "input" )}}"> <input type="text" name="province" id="province" required="required" value="{{ .City }}" placeholder="{{( pgettext "Province" "input" )}}">
<label for="province">{{( pgettext "Province" "input" )}}</label> <label for="province">{{( pgettext "Province" "input" )}}</label>
</div> </div>
<div class="input"> <div class="input">
<input type="text" name="postal_code" id="postal_code" required="required" value="{{ .PostalCode }}" placeholder="{{( pgettext "Postal code" "input" )}}"> <input type="text" name="postal_code" id="postal_code" required="required" value="{{ .PostalCode }}" placeholder="{{( pgettext "Postal code" "input" )}}">
<label for="postal_code">{{( pgettext "Postal code" "input" )}}</label> <label for="postal_code">{{( pgettext "Postal code" "input" )}}</label>
</div> </div>
<div class="input"> <div class="input">
<select id="country" name="country" class="width-fixed"> <select id="country" name="country" class="width-fixed">
{{- range $country := .Countries }} {{- range $country := .Countries }}
<option value="{{ .Code }}" {{ if eq .Code $.CountryCode }}selected="selected"{{ end }}>{{ .Name }}</option> <option value="{{ .Code }}" {{ if eq .Code $.CountryCode }}selected="selected"{{ end }}>{{ .Name }}</option>
{{- end }} {{- end }}
</select> </select>
<label for="country">{{( pgettext "Country" "input" )}}<label> <label for="country">{{( pgettext "Country" "input" )}}<label>
</div> </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> <button type="submit">{{( pgettext "Save changes" "action" )}}</button>
</fieldset>
</form> </form>
</section> </section>
{{- end }} {{- end }}