From 0beb0bb3156f71807d107d23d82c075435bd6c20 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Mon, 15 Jan 2024 01:45:58 +0100 Subject: [PATCH] Add VAT and tourist tax information Since i need the number of decimals to format the price in the template, i added them to the company, and used them in the call to price_parse(). --- pkg/auth/company.go | 8 +++++++ pkg/campsite/types/public.go | 4 ++++ pkg/company/admin.go | 5 ++-- pkg/template/render.go | 17 ++++++++++++++ po/ca.po | 28 +++++++++++++++-------- po/es.po | 28 +++++++++++++++-------- po/fr.po | 28 +++++++++++++++-------- web/static/public.css | 2 +- web/templates/public/campsite/type.gohtml | 2 ++ 9 files changed, 89 insertions(+), 33 deletions(-) diff --git a/pkg/auth/company.go b/pkg/auth/company.go index 2833bed..8f2ef67 100644 --- a/pkg/auth/company.go +++ b/pkg/auth/company.go @@ -15,6 +15,8 @@ import ( type Company struct { ID int + DecimalDigits int + CurrencySymbol string DefaultLanguage language.Tag Locales locale.Locales } @@ -26,10 +28,16 @@ func CompanyByHost(ctx context.Context, conn *database.Conn, host string, allLoc } if err := conn.QueryRow(ctx, ` select company_id + , decimal_digits + , currency_symbol from company_host + join company using (company_id) + join currency using (currency_code) where host = $1 `, host).Scan( &company.ID, + &company.DecimalDigits, + &company.CurrencySymbol, ); err != nil { return nil, err } diff --git a/pkg/campsite/types/public.go b/pkg/campsite/types/public.go index 352c764..ce8a430 100644 --- a/pkg/campsite/types/public.go +++ b/pkg/campsite/types/public.go @@ -66,6 +66,7 @@ type publicPage struct { Name string Carousel []*carousel.Slide Prices []*typePrice + TouristTax string Features []*typeFeature Calendar *season.Calendar Spiel gotemplate.HTML @@ -130,6 +131,9 @@ func newPublicPage(ctx context.Context, company *auth.Company, conn *database.Co if err := row.Scan(&page.Name, &page.Spiel, &page.Info, &page.Facilities, &page.Description, &page.AdditionalInfo); err != nil { return nil, err } + if err := conn.QueryRow(ctx, "select to_price(tourist_tax, $1) from company where company_id = $2", company.DecimalDigits, company.ID).Scan(&page.TouristTax); err != nil { + return nil, err + } return page, nil } diff --git a/pkg/company/admin.go b/pkg/company/admin.go index 6365ffe..8073ebc 100644 --- a/pkg/company/admin.go +++ b/pkg/company/admin.go @@ -282,8 +282,8 @@ func editTaxDetails(w http.ResponseWriter, r *http.Request, user *auth.User, com , invoice_number_format = $14 , legal_disclaimer = $15 , rtc_number = $16 - , tourist_tax = parse_price($17) - where company_id = $18 + , tourist_tax = parse_price($17, $18) + where company_id = $19 `, f.BusinessName, f.VATIN, @@ -302,6 +302,7 @@ func editTaxDetails(w http.ResponseWriter, r *http.Request, user *auth.User, com f.LegalDisclaimer, f.RTCNumber, f.TouristTax, + company.DecimalDigits, company.ID) httplib.Redirect(w, r, "/admin/company", http.StatusSeeOther) } diff --git a/pkg/template/render.go b/pkg/template/render.go index b6347db..98b8541 100644 --- a/pkg/template/render.go +++ b/pkg/template/render.go @@ -9,6 +9,7 @@ import ( "fmt" "html/template" "io" + "math" "net/http" "net/url" "path" @@ -16,6 +17,10 @@ import ( "strings" "time" + "golang.org/x/text/language" + "golang.org/x/text/message" + "golang.org/x/text/number" + "dev.tandem.ws/tandem/camper/pkg/auth" httplib "dev.tandem.ws/tandem/camper/pkg/http" ) @@ -91,6 +96,9 @@ func mustRenderLayout(w io.Writer, user *auth.User, company *auth.Company, templ "humanizeBytes": func(bytes int64) string { return humanizeBytes(bytes) }, + "formatPrice": func(price string) string { + return formatPrice(price, user.Locale.Language, user.Locale.CurrencyPattern, company.DecimalDigits, company.CurrencySymbol) + }, "queryEscape": func(s string) string { return url.QueryEscape(s) }, @@ -136,3 +144,12 @@ func mustRenderLayout(w io.Writer, user *auth.User, company *auth.Company, templ panic(err) } } + +func formatPrice(price string, language language.Tag, currencyPattern string, decimalDigits int, currencySymbol string) string { + p := message.NewPrinter(language) + f, err := strconv.ParseFloat(price, 64) + if err != nil { + f = math.NaN() + } + return p.Sprintf(currencyPattern, decimalDigits, number.Decimal(f), currencySymbol) +} diff --git a/po/ca.po b/po/ca.po index 3923305..58631b2 100644 --- a/po/ca.po +++ b/po/ca.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: camper\n" "Report-Msgid-Bugs-To: jordi@tandem.blog\n" -"POT-Creation-Date: 2024-01-15 01:00+0100\n" +"POT-Creation-Date: 2024-01-15 01:40+0100\n" "PO-Revision-Date: 2023-07-22 23:45+0200\n" "Last-Translator: jordi fita mas \n" "Language-Team: Catalan \n" @@ -150,46 +150,54 @@ msgstr "%s €/nit" msgid "*Minimum %d nights per stay" msgstr "*Mínim %d nits per estada" -#: web/templates/public/campsite/type.gohtml:105 +#: web/templates/public/campsite/type.gohtml:99 +msgid "10 % VAT included." +msgstr "IVA del 10 % inclòs." + +#: web/templates/public/campsite/type.gohtml:100 +msgid "Tourist tax: %s per person aged 16 or over." +msgstr "Impost turístic: %s per persona de 16 anys o més." + +#: web/templates/public/campsite/type.gohtml:107 msgctxt "title" msgid "Features" msgstr "Característiques" -#: web/templates/public/campsite/type.gohtml:116 +#: web/templates/public/campsite/type.gohtml:118 msgctxt "title" msgid "Info" msgstr "Informació" -#: web/templates/public/campsite/type.gohtml:120 +#: web/templates/public/campsite/type.gohtml:122 msgctxt "title" msgid "Facilities" msgstr "Equipaments" -#: web/templates/public/campsite/type.gohtml:124 +#: web/templates/public/campsite/type.gohtml:126 msgctxt "title" msgid "Description" msgstr "Descripció" -#: web/templates/public/campsite/type.gohtml:128 +#: web/templates/public/campsite/type.gohtml:130 msgctxt "title" msgid "Additional Information" msgstr "Informació addicional" -#: web/templates/public/campsite/type.gohtml:131 +#: web/templates/public/campsite/type.gohtml:133 msgctxt "time" msgid "Check in" msgstr "Entrada" -#: web/templates/public/campsite/type.gohtml:132 +#: web/templates/public/campsite/type.gohtml:134 msgid "4 p.m. to 9 p.m." msgstr "16 h a 21 h" -#: web/templates/public/campsite/type.gohtml:135 +#: web/templates/public/campsite/type.gohtml:137 msgctxt "time" msgid "Check out" msgstr "Sortida" -#: web/templates/public/campsite/type.gohtml:136 +#: web/templates/public/campsite/type.gohtml:138 msgid "10 a.m." msgstr "10 h" diff --git a/po/es.po b/po/es.po index 384475a..db3bcbd 100644 --- a/po/es.po +++ b/po/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: camper\n" "Report-Msgid-Bugs-To: jordi@tandem.blog\n" -"POT-Creation-Date: 2024-01-15 01:00+0100\n" +"POT-Creation-Date: 2024-01-15 01:40+0100\n" "PO-Revision-Date: 2023-07-22 23:46+0200\n" "Last-Translator: jordi fita mas \n" "Language-Team: Spanish \n" @@ -150,46 +150,54 @@ msgstr "%s €/noche" msgid "*Minimum %d nights per stay" msgstr "*Mínimo %d noches por estancia" -#: web/templates/public/campsite/type.gohtml:105 +#: web/templates/public/campsite/type.gohtml:99 +msgid "10 % VAT included." +msgstr "IVA del 10 % incluido." + +#: web/templates/public/campsite/type.gohtml:100 +msgid "Tourist tax: %s per person aged 16 or over." +msgstr "Impuesto turístico: %s por persona de 16 años en adelante." + +#: web/templates/public/campsite/type.gohtml:107 msgctxt "title" msgid "Features" msgstr "Características" -#: web/templates/public/campsite/type.gohtml:116 +#: web/templates/public/campsite/type.gohtml:118 msgctxt "title" msgid "Info" msgstr "Información" -#: web/templates/public/campsite/type.gohtml:120 +#: web/templates/public/campsite/type.gohtml:122 msgctxt "title" msgid "Facilities" msgstr "Equipamiento" -#: web/templates/public/campsite/type.gohtml:124 +#: web/templates/public/campsite/type.gohtml:126 msgctxt "title" msgid "Description" msgstr "Descripción" -#: web/templates/public/campsite/type.gohtml:128 +#: web/templates/public/campsite/type.gohtml:130 msgctxt "title" msgid "Additional Information" msgstr "Información adicional" -#: web/templates/public/campsite/type.gohtml:131 +#: web/templates/public/campsite/type.gohtml:133 msgctxt "time" msgid "Check in" msgstr "Entrada" -#: web/templates/public/campsite/type.gohtml:132 +#: web/templates/public/campsite/type.gohtml:134 msgid "4 p.m. to 9 p.m." msgstr "16 h a 21 h" -#: web/templates/public/campsite/type.gohtml:135 +#: web/templates/public/campsite/type.gohtml:137 msgctxt "time" msgid "Check out" msgstr "Salida" -#: web/templates/public/campsite/type.gohtml:136 +#: web/templates/public/campsite/type.gohtml:138 msgid "10 a.m." msgstr "10 h" diff --git a/po/fr.po b/po/fr.po index c5b7766..75e8f1c 100644 --- a/po/fr.po +++ b/po/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: camper\n" "Report-Msgid-Bugs-To: jordi@tandem.blog\n" -"POT-Creation-Date: 2024-01-15 01:00+0100\n" +"POT-Creation-Date: 2024-01-15 01:40+0100\n" "PO-Revision-Date: 2023-12-20 10:13+0100\n" "Last-Translator: Oriol Carbonell \n" "Language-Team: French \n" @@ -151,46 +151,54 @@ msgstr "%s €/nuit" msgid "*Minimum %d nights per stay" msgstr "*Minimum %d nuits par séjour" -#: web/templates/public/campsite/type.gohtml:105 +#: web/templates/public/campsite/type.gohtml:99 +msgid "10 % VAT included." +msgstr "10 % TVA incluse." + +#: web/templates/public/campsite/type.gohtml:100 +msgid "Tourist tax: %s per person aged 16 or over." +msgstr "Taxe touristique: %s par personne de 16 ans ou plus." + +#: web/templates/public/campsite/type.gohtml:107 msgctxt "title" msgid "Features" msgstr "Caractéristiques" -#: web/templates/public/campsite/type.gohtml:116 +#: web/templates/public/campsite/type.gohtml:118 msgctxt "title" msgid "Info" msgstr "Info" -#: web/templates/public/campsite/type.gohtml:120 +#: web/templates/public/campsite/type.gohtml:122 msgctxt "title" msgid "Facilities" msgstr "Installations" -#: web/templates/public/campsite/type.gohtml:124 +#: web/templates/public/campsite/type.gohtml:126 msgctxt "title" msgid "Description" msgstr "Description" -#: web/templates/public/campsite/type.gohtml:128 +#: web/templates/public/campsite/type.gohtml:130 msgctxt "title" msgid "Additional Information" msgstr "Informations Complémentaires" -#: web/templates/public/campsite/type.gohtml:131 +#: web/templates/public/campsite/type.gohtml:133 msgctxt "time" msgid "Check in" msgstr "Arrivée" -#: web/templates/public/campsite/type.gohtml:132 +#: web/templates/public/campsite/type.gohtml:134 msgid "4 p.m. to 9 p.m." msgstr "16 h à 21 h" -#: web/templates/public/campsite/type.gohtml:135 +#: web/templates/public/campsite/type.gohtml:137 msgctxt "time" msgid "Check out" msgstr "Départ" -#: web/templates/public/campsite/type.gohtml:136 +#: web/templates/public/campsite/type.gohtml:138 msgid "10 a.m." msgstr "10 h" diff --git a/web/static/public.css b/web/static/public.css index 09e2519..9c0d4c8 100644 --- a/web/static/public.css +++ b/web/static/public.css @@ -136,7 +136,7 @@ p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; } -p + p { +p + p, dl + p { margin-top: 1.5em; } diff --git a/web/templates/public/campsite/type.gohtml b/web/templates/public/campsite/type.gohtml index c10cd3b..359f67a 100644 --- a/web/templates/public/campsite/type.gohtml +++ b/web/templates/public/campsite/type.gohtml @@ -96,6 +96,8 @@ {{- end }} +

{{( gettext "10 % VAT included." )}}

+

{{printf (gettext "Tourist tax: %s per person aged 16 or over.") (formatPrice $.TouristTax)}}

{{- end }}