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().
This commit is contained in:
jordi fita mas 2024-01-15 01:45:58 +01:00
parent 76456aa9b2
commit 0beb0bb315
9 changed files with 89 additions and 33 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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)
}

View File

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

View File

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

View File

@ -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 <info@oriolcarbonell.cat>\n"
"Language-Team: French <traduc@traduc.org>\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"

View File

@ -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;
}

View File

@ -96,6 +96,8 @@
</div>
{{- end }}
</dl>
<p>{{( gettext "10 % VAT included." )}}</p>
<p>{{printf (gettext "Tourist tax: %s per person aged 16 or over.") (formatPrice $.TouristTax)}}</p>
</article>
{{- end }}
</div>