Add filters and pagination to payments

This commit is contained in:
jordi fita mas 2024-05-03 20:09:07 +02:00
parent 48c1529e6c
commit b4ccdeff2f
7 changed files with 358 additions and 120 deletions

View File

@ -108,17 +108,24 @@ func (h *AdminHandler) paymentHandler(user *auth.User, company *auth.Company, co
} }
func servePaymentIndex(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company, conn *database.Conn) { func servePaymentIndex(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company, conn *database.Conn) {
payments, err := collectPaymentEntries(r.Context(), company, conn, user.Locale) filters := newFilterForm(r.Context(), conn, company, user.Locale)
if err := filters.Parse(r); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
payments, err := collectPaymentEntries(r.Context(), company, conn, user.Locale, filters)
if err != nil { if err != nil {
panic(err) panic(err)
} }
page := &paymentIndex{ page := &paymentIndex{
Payments: payments, Payments: filters.buildCursor(payments),
Filters: filters,
} }
page.MustRender(w, r, user, company) page.MustRender(w, r, user, company)
} }
type paymentEntry struct { type paymentEntry struct {
ID int
URL string URL string
Reference string Reference string
DownPayment string DownPayment string
@ -128,9 +135,11 @@ type paymentEntry struct {
CreatedAt time.Time CreatedAt time.Time
} }
func collectPaymentEntries(ctx context.Context, company *auth.Company, conn *database.Conn, locale *locale.Locale) ([]*paymentEntry, error) { func collectPaymentEntries(ctx context.Context, company *auth.Company, conn *database.Conn, locale *locale.Locale, filters *filterForm) ([]*paymentEntry, error) {
rows, err := conn.Query(ctx, ` where, args := filters.BuildQuery([]interface{}{locale.Language})
select '/admin/payments/' || payment.slug rows, err := conn.Query(ctx, fmt.Sprintf(`
select payment_id
, '/admin/payments/' || payment.slug
, payment.reference , payment.reference
, to_price(payment.down_payment, decimal_digits) , to_price(payment.down_payment, decimal_digits)
, to_price(total, decimal_digits) , to_price(total, decimal_digits)
@ -141,10 +150,12 @@ func collectPaymentEntries(ctx context.Context, company *auth.Company, conn *dat
join currency using (currency_code) join currency using (currency_code)
join payment_status using (payment_status) join payment_status using (payment_status)
left join payment_status_i18n on payment_status_i18n.payment_status = payment.payment_status left join payment_status_i18n on payment_status_i18n.payment_status = payment.payment_status
and payment_status_i18n.lang_tag = $2 and payment_status_i18n.lang_tag = $1
where company_id = $1 where (%s)
order by created_at desc order by created_at desc
`, company.ID, locale.Language) , payment_id
limit %d
`, where, filters.PerPage()+1), args...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -154,6 +165,7 @@ func collectPaymentEntries(ctx context.Context, company *auth.Company, conn *dat
for rows.Next() { for rows.Next() {
entry := &paymentEntry{} entry := &paymentEntry{}
if err = rows.Scan( if err = rows.Scan(
&entry.ID,
&entry.URL, &entry.URL,
&entry.Reference, &entry.Reference,
&entry.DownPayment, &entry.DownPayment,
@ -172,10 +184,15 @@ func collectPaymentEntries(ctx context.Context, company *auth.Company, conn *dat
type paymentIndex struct { type paymentIndex struct {
Payments []*paymentEntry Payments []*paymentEntry
Filters *filterForm
} }
func (page *paymentIndex) MustRender(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company) { func (page *paymentIndex) MustRender(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company) {
template.MustRenderAdmin(w, r, user, company, "payment/index.gohtml", page) if httplib.IsHTMxRequest(r) && page.Filters.Paginated() {
template.MustRenderAdminNoLayout(w, r, user, company, "payment/results.gohtml", page)
} else {
template.MustRenderAdminFiles(w, r, user, company, page, "payment/index.gohtml", "payment/results.gohtml")
}
} }
type paymentDetails struct { type paymentDetails struct {

125
pkg/payment/filter.go Normal file
View File

@ -0,0 +1,125 @@
package payment
import (
"context"
"fmt"
"net/http"
"strconv"
"strings"
"dev.tandem.ws/tandem/camper/pkg/auth"
"dev.tandem.ws/tandem/camper/pkg/database"
"dev.tandem.ws/tandem/camper/pkg/form"
"dev.tandem.ws/tandem/camper/pkg/locale"
)
type filterForm struct {
company *auth.Company
PaymentStatus *form.Select
Reference *form.Input
FromDate *form.Input
ToDate *form.Input
Cursor *form.Cursor
}
func newFilterForm(ctx context.Context, conn *database.Conn, company *auth.Company, locale *locale.Locale) *filterForm {
return &filterForm{
company: company,
PaymentStatus: &form.Select{
Name: "payment_status",
Options: mustGetPaymentStatusOptions(ctx, conn, locale),
},
Reference: &form.Input{
Name: "reference",
},
FromDate: &form.Input{
Name: "from_date",
},
ToDate: &form.Input{
Name: "to_date",
},
Cursor: &form.Cursor{
Name: "cursor",
PerPage: 25,
},
}
}
func mustGetPaymentStatusOptions(ctx context.Context, conn *database.Conn, locale *locale.Locale) []*form.Option {
return form.MustGetOptions(ctx, conn, `
select payment_status.payment_status
, isi18n.name
from payment_status
join payment_status_i18n isi18n using(payment_status)
where isi18n.lang_tag = $1
order by payment_status`, locale.Language)
}
func (f *filterForm) Parse(r *http.Request) error {
if err := r.ParseForm(); err != nil {
return err
}
f.PaymentStatus.FillValue(r)
f.Reference.FillValue(r)
f.FromDate.FillValue(r)
f.ToDate.FillValue(r)
f.Cursor.FillValue(r)
return nil
}
func (f *filterForm) BuildQuery(args []interface{}) (string, []interface{}) {
var where []string
appendWhere := func(expression string, value interface{}) {
args = append(args, value)
where = append(where, fmt.Sprintf(expression, len(args)))
}
maybeAppendWhere := func(expression string, value string, conv func(string) interface{}) {
if value != "" {
if conv == nil {
appendWhere(expression, value)
} else {
appendWhere(expression, conv(value))
}
}
}
appendWhere("payment.company_id = $%d", f.company.ID)
maybeAppendWhere("payment.payment_status = $%d", f.PaymentStatus.String(), nil)
maybeAppendWhere("payment.reference like $%d", f.Reference.Val, func(v string) interface{} {
return "%" + v
})
maybeAppendWhere("payment.created_at >= $%d", f.FromDate.Val, nil)
maybeAppendWhere("payment.created_at <= $%d", f.ToDate.Val, nil)
if f.Paginated() {
params := f.Cursor.Params()
if len(params) == 2 {
where = append(where, fmt.Sprintf("(payment.created_at, payment_id) < ($%d, $%d)", len(args)+1, len(args)+2))
args = append(args, params[0])
args = append(args, params[1])
}
}
return strings.Join(where, ") AND ("), args
}
func (f *filterForm) buildCursor(customers []*paymentEntry) []*paymentEntry {
return form.BuildCursor(f.Cursor, customers, func(entry *paymentEntry) []string {
return []string{entry.CreatedAt.Format(database.ISODateTimeFormat), strconv.Itoa(entry.ID)}
})
}
func (f *filterForm) HasValue() bool {
return (len(f.PaymentStatus.Selected) > 0 && f.PaymentStatus.Selected[0] != "") ||
f.Reference.Val != "" ||
f.FromDate.Val != "" ||
f.ToDate.Val != ""
}
func (f *filterForm) PerPage() int {
return f.Cursor.PerPage
}
func (f *filterForm) Paginated() bool {
return f.Cursor.Pagination
}

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: camper\n" "Project-Id-Version: camper\n"
"Report-Msgid-Bugs-To: jordi@tandem.blog\n" "Report-Msgid-Bugs-To: jordi@tandem.blog\n"
"POT-Creation-Date: 2024-05-03 19:12+0200\n" "POT-Creation-Date: 2024-05-03 20:07+0200\n"
"PO-Revision-Date: 2024-02-06 10:04+0100\n" "PO-Revision-Date: 2024-02-06 10:04+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"
@ -78,7 +78,7 @@ msgid "Payment"
msgstr "Pagament" msgstr "Pagament"
#: web/templates/mail/payment/details.gotxt:9 #: web/templates/mail/payment/details.gotxt:9
#: web/templates/admin/payment/index.gohtml:21 #: web/templates/admin/payment/index.gohtml:73
#: web/templates/admin/payment/details.gohtml:52 #: web/templates/admin/payment/details.gohtml:52
#: web/templates/admin/prebooking/index.gohtml:59 #: web/templates/admin/prebooking/index.gohtml:59
#: web/templates/admin/booking/index.gohtml:73 #: web/templates/admin/booking/index.gohtml:73
@ -87,7 +87,7 @@ msgid "Reference"
msgstr "Referència" msgstr "Referència"
#: web/templates/mail/payment/details.gotxt:10 #: web/templates/mail/payment/details.gotxt:10
#: web/templates/admin/payment/index.gohtml:22 #: web/templates/admin/payment/index.gohtml:74
#: web/templates/admin/payment/details.gohtml:56 #: web/templates/admin/payment/details.gohtml:56
#: web/templates/admin/booking/index.gohtml:77 #: web/templates/admin/booking/index.gohtml:77
msgctxt "header" msgctxt "header"
@ -1114,25 +1114,66 @@ msgctxt "action"
msgid "Save changes" msgid "Save changes"
msgstr "Desa els canvis" msgstr "Desa els canvis"
#: web/templates/admin/payment/index.gohtml:20 #: web/templates/admin/payment/index.gohtml:24
msgctxt "input"
msgid "Payment status"
msgstr "Estat del pagament"
#: web/templates/admin/payment/index.gohtml:28
#: web/templates/admin/invoice/index.gohtml:55
#: web/templates/admin/booking/index.gohtml:38
msgid "All statuses"
msgstr "Tots els estats"
#: web/templates/admin/payment/index.gohtml:36
#: web/templates/admin/invoice/index.gohtml:63
#: web/templates/admin/prebooking/index.gohtml:32
#: web/templates/admin/booking/index.gohtml:46
msgctxt "input"
msgid "From date"
msgstr "De la data"
#: web/templates/admin/payment/index.gohtml:45
#: web/templates/admin/invoice/index.gohtml:72
#: web/templates/admin/prebooking/index.gohtml:41
#: web/templates/admin/booking/index.gohtml:55
msgctxt "input"
msgid "To date"
msgstr "A la data"
#: web/templates/admin/payment/index.gohtml:54
msgctxt "input"
msgid "Reference"
msgstr "Referència"
#: web/templates/admin/payment/index.gohtml:64
#: web/templates/admin/customer/index.gohtml:43
#: web/templates/admin/invoice/index.gohtml:94
#: web/templates/admin/prebooking/index.gohtml:51
#: web/templates/admin/booking/index.gohtml:65
msgctxt "action"
msgid "Reset"
msgstr "Restableix"
#: web/templates/admin/payment/index.gohtml:72
#: web/templates/admin/user/login-attempts.gohtml:19 #: web/templates/admin/user/login-attempts.gohtml:19
msgctxt "header" msgctxt "header"
msgid "Date" msgid "Date"
msgstr "Data" msgstr "Data"
#: web/templates/admin/payment/index.gohtml:23 #: web/templates/admin/payment/index.gohtml:75
msgctxt "header" msgctxt "header"
msgid "Down payment" msgid "Down payment"
msgstr "A compte" msgstr "A compte"
#: web/templates/admin/payment/index.gohtml:24 #: web/templates/admin/payment/index.gohtml:76
#: web/templates/admin/booking/fields.gohtml:75 #: web/templates/admin/booking/fields.gohtml:75
#: web/templates/admin/booking/fields.gohtml:173 #: web/templates/admin/booking/fields.gohtml:173
msgctxt "header" msgctxt "header"
msgid "Total" msgid "Total"
msgstr "Total" msgstr "Total"
#: web/templates/admin/payment/index.gohtml:40 #: web/templates/admin/payment/index.gohtml:84
msgid "No payments found." msgid "No payments found."
msgstr "No sha trobat cap pagament." msgstr "No sha trobat cap pagament."
@ -1925,14 +1966,6 @@ msgctxt "action"
msgid "Add Customer" msgid "Add Customer"
msgstr "Afegeix client" msgstr "Afegeix client"
#: web/templates/admin/customer/index.gohtml:43
#: web/templates/admin/invoice/index.gohtml:94
#: web/templates/admin/prebooking/index.gohtml:51
#: web/templates/admin/booking/index.gohtml:65
msgctxt "action"
msgid "Reset"
msgstr "Restableix"
#: web/templates/admin/customer/index.gohtml:52 #: web/templates/admin/customer/index.gohtml:52
#: web/templates/admin/user/login-attempts.gohtml:20 #: web/templates/admin/user/login-attempts.gohtml:20
#: web/templates/admin/user/index.gohtml:21 #: web/templates/admin/user/index.gohtml:21
@ -2063,25 +2096,6 @@ msgstr "Client"
msgid "All customers" msgid "All customers"
msgstr "Tots els clients" msgstr "Tots els clients"
#: web/templates/admin/invoice/index.gohtml:55
#: web/templates/admin/booking/index.gohtml:38
msgid "All statuses"
msgstr "Tots els estats"
#: web/templates/admin/invoice/index.gohtml:63
#: web/templates/admin/prebooking/index.gohtml:32
#: web/templates/admin/booking/index.gohtml:46
msgctxt "input"
msgid "From date"
msgstr "De la data"
#: web/templates/admin/invoice/index.gohtml:72
#: web/templates/admin/prebooking/index.gohtml:41
#: web/templates/admin/booking/index.gohtml:55
msgctxt "input"
msgid "To date"
msgstr "A la data"
#: web/templates/admin/invoice/index.gohtml:81 #: web/templates/admin/invoice/index.gohtml:81
msgctxt "input" msgctxt "input"
msgid "Invoice number" msgid "Invoice number"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: camper\n" "Project-Id-Version: camper\n"
"Report-Msgid-Bugs-To: jordi@tandem.blog\n" "Report-Msgid-Bugs-To: jordi@tandem.blog\n"
"POT-Creation-Date: 2024-05-03 19:12+0200\n" "POT-Creation-Date: 2024-05-03 20:07+0200\n"
"PO-Revision-Date: 2024-02-06 10:04+0100\n" "PO-Revision-Date: 2024-02-06 10:04+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"
@ -78,7 +78,7 @@ msgid "Payment"
msgstr "Pago" msgstr "Pago"
#: web/templates/mail/payment/details.gotxt:9 #: web/templates/mail/payment/details.gotxt:9
#: web/templates/admin/payment/index.gohtml:21 #: web/templates/admin/payment/index.gohtml:73
#: web/templates/admin/payment/details.gohtml:52 #: web/templates/admin/payment/details.gohtml:52
#: web/templates/admin/prebooking/index.gohtml:59 #: web/templates/admin/prebooking/index.gohtml:59
#: web/templates/admin/booking/index.gohtml:73 #: web/templates/admin/booking/index.gohtml:73
@ -87,7 +87,7 @@ msgid "Reference"
msgstr "Referencia" msgstr "Referencia"
#: web/templates/mail/payment/details.gotxt:10 #: web/templates/mail/payment/details.gotxt:10
#: web/templates/admin/payment/index.gohtml:22 #: web/templates/admin/payment/index.gohtml:74
#: web/templates/admin/payment/details.gohtml:56 #: web/templates/admin/payment/details.gohtml:56
#: web/templates/admin/booking/index.gohtml:77 #: web/templates/admin/booking/index.gohtml:77
msgctxt "header" msgctxt "header"
@ -1114,25 +1114,66 @@ msgctxt "action"
msgid "Save changes" msgid "Save changes"
msgstr "Guardar los cambios" msgstr "Guardar los cambios"
#: web/templates/admin/payment/index.gohtml:20 #: web/templates/admin/payment/index.gohtml:24
msgctxt "input"
msgid "Payment status"
msgstr "Estado del pago"
#: web/templates/admin/payment/index.gohtml:28
#: web/templates/admin/invoice/index.gohtml:55
#: web/templates/admin/booking/index.gohtml:38
msgid "All statuses"
msgstr "Todos los estados"
#: web/templates/admin/payment/index.gohtml:36
#: web/templates/admin/invoice/index.gohtml:63
#: web/templates/admin/prebooking/index.gohtml:32
#: web/templates/admin/booking/index.gohtml:46
msgctxt "input"
msgid "From date"
msgstr "De la fecha"
#: web/templates/admin/payment/index.gohtml:45
#: web/templates/admin/invoice/index.gohtml:72
#: web/templates/admin/prebooking/index.gohtml:41
#: web/templates/admin/booking/index.gohtml:55
msgctxt "input"
msgid "To date"
msgstr "A la fecha"
#: web/templates/admin/payment/index.gohtml:54
msgctxt "input"
msgid "Reference"
msgstr "Referencia"
#: web/templates/admin/payment/index.gohtml:64
#: web/templates/admin/customer/index.gohtml:43
#: web/templates/admin/invoice/index.gohtml:94
#: web/templates/admin/prebooking/index.gohtml:51
#: web/templates/admin/booking/index.gohtml:65
msgctxt "action"
msgid "Reset"
msgstr "Restablecer"
#: web/templates/admin/payment/index.gohtml:72
#: web/templates/admin/user/login-attempts.gohtml:19 #: web/templates/admin/user/login-attempts.gohtml:19
msgctxt "header" msgctxt "header"
msgid "Date" msgid "Date"
msgstr "Fecha" msgstr "Fecha"
#: web/templates/admin/payment/index.gohtml:23 #: web/templates/admin/payment/index.gohtml:75
msgctxt "header" msgctxt "header"
msgid "Down payment" msgid "Down payment"
msgstr "A cuenta" msgstr "A cuenta"
#: web/templates/admin/payment/index.gohtml:24 #: web/templates/admin/payment/index.gohtml:76
#: web/templates/admin/booking/fields.gohtml:75 #: web/templates/admin/booking/fields.gohtml:75
#: web/templates/admin/booking/fields.gohtml:173 #: web/templates/admin/booking/fields.gohtml:173
msgctxt "header" msgctxt "header"
msgid "Total" msgid "Total"
msgstr "Total" msgstr "Total"
#: web/templates/admin/payment/index.gohtml:40 #: web/templates/admin/payment/index.gohtml:84
msgid "No payments found." msgid "No payments found."
msgstr "No se ha encontrado ningún pago." msgstr "No se ha encontrado ningún pago."
@ -1925,14 +1966,6 @@ msgctxt "action"
msgid "Add Customer" msgid "Add Customer"
msgstr "Añadir cliente" msgstr "Añadir cliente"
#: web/templates/admin/customer/index.gohtml:43
#: web/templates/admin/invoice/index.gohtml:94
#: web/templates/admin/prebooking/index.gohtml:51
#: web/templates/admin/booking/index.gohtml:65
msgctxt "action"
msgid "Reset"
msgstr "Restablecer"
#: web/templates/admin/customer/index.gohtml:52 #: web/templates/admin/customer/index.gohtml:52
#: web/templates/admin/user/login-attempts.gohtml:20 #: web/templates/admin/user/login-attempts.gohtml:20
#: web/templates/admin/user/index.gohtml:21 #: web/templates/admin/user/index.gohtml:21
@ -2063,25 +2096,6 @@ msgstr "Cliente"
msgid "All customers" msgid "All customers"
msgstr "Todos los clientes" msgstr "Todos los clientes"
#: web/templates/admin/invoice/index.gohtml:55
#: web/templates/admin/booking/index.gohtml:38
msgid "All statuses"
msgstr "Todos los estados"
#: web/templates/admin/invoice/index.gohtml:63
#: web/templates/admin/prebooking/index.gohtml:32
#: web/templates/admin/booking/index.gohtml:46
msgctxt "input"
msgid "From date"
msgstr "De la fecha"
#: web/templates/admin/invoice/index.gohtml:72
#: web/templates/admin/prebooking/index.gohtml:41
#: web/templates/admin/booking/index.gohtml:55
msgctxt "input"
msgid "To date"
msgstr "A la fecha"
#: web/templates/admin/invoice/index.gohtml:81 #: web/templates/admin/invoice/index.gohtml:81
msgctxt "input" msgctxt "input"
msgid "Invoice number" msgid "Invoice number"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: camper\n" "Project-Id-Version: camper\n"
"Report-Msgid-Bugs-To: jordi@tandem.blog\n" "Report-Msgid-Bugs-To: jordi@tandem.blog\n"
"POT-Creation-Date: 2024-05-03 19:12+0200\n" "POT-Creation-Date: 2024-05-03 20:07+0200\n"
"PO-Revision-Date: 2024-02-06 10:05+0100\n" "PO-Revision-Date: 2024-02-06 10:05+0100\n"
"Last-Translator: Oriol Carbonell <info@oriolcarbonell.cat>\n" "Last-Translator: Oriol Carbonell <info@oriolcarbonell.cat>\n"
"Language-Team: French <traduc@traduc.org>\n" "Language-Team: French <traduc@traduc.org>\n"
@ -78,7 +78,7 @@ msgid "Payment"
msgstr "Paiement" msgstr "Paiement"
#: web/templates/mail/payment/details.gotxt:9 #: web/templates/mail/payment/details.gotxt:9
#: web/templates/admin/payment/index.gohtml:21 #: web/templates/admin/payment/index.gohtml:73
#: web/templates/admin/payment/details.gohtml:52 #: web/templates/admin/payment/details.gohtml:52
#: web/templates/admin/prebooking/index.gohtml:59 #: web/templates/admin/prebooking/index.gohtml:59
#: web/templates/admin/booking/index.gohtml:73 #: web/templates/admin/booking/index.gohtml:73
@ -87,7 +87,7 @@ msgid "Reference"
msgstr "Référence" msgstr "Référence"
#: web/templates/mail/payment/details.gotxt:10 #: web/templates/mail/payment/details.gotxt:10
#: web/templates/admin/payment/index.gohtml:22 #: web/templates/admin/payment/index.gohtml:74
#: web/templates/admin/payment/details.gohtml:56 #: web/templates/admin/payment/details.gohtml:56
#: web/templates/admin/booking/index.gohtml:77 #: web/templates/admin/booking/index.gohtml:77
msgctxt "header" msgctxt "header"
@ -1114,25 +1114,66 @@ msgctxt "action"
msgid "Save changes" msgid "Save changes"
msgstr "Enregistrer les changements" msgstr "Enregistrer les changements"
#: web/templates/admin/payment/index.gohtml:20 #: web/templates/admin/payment/index.gohtml:24
msgctxt "input"
msgid "Payment status"
msgstr "Statut du paiement"
#: web/templates/admin/payment/index.gohtml:28
#: web/templates/admin/invoice/index.gohtml:55
#: web/templates/admin/booking/index.gohtml:38
msgid "All statuses"
msgstr "Tous les statuts"
#: web/templates/admin/payment/index.gohtml:36
#: web/templates/admin/invoice/index.gohtml:63
#: web/templates/admin/prebooking/index.gohtml:32
#: web/templates/admin/booking/index.gohtml:46
msgctxt "input"
msgid "From date"
msgstr "Partir de la date"
#: web/templates/admin/payment/index.gohtml:45
#: web/templates/admin/invoice/index.gohtml:72
#: web/templates/admin/prebooking/index.gohtml:41
#: web/templates/admin/booking/index.gohtml:55
msgctxt "input"
msgid "To date"
msgstr "À ce jour"
#: web/templates/admin/payment/index.gohtml:54
msgctxt "input"
msgid "Reference"
msgstr "Référence"
#: web/templates/admin/payment/index.gohtml:64
#: web/templates/admin/customer/index.gohtml:43
#: web/templates/admin/invoice/index.gohtml:94
#: web/templates/admin/prebooking/index.gohtml:51
#: web/templates/admin/booking/index.gohtml:65
msgctxt "action"
msgid "Reset"
msgstr "Réinitialiser"
#: web/templates/admin/payment/index.gohtml:72
#: web/templates/admin/user/login-attempts.gohtml:19 #: web/templates/admin/user/login-attempts.gohtml:19
msgctxt "header" msgctxt "header"
msgid "Date" msgid "Date"
msgstr "Date" msgstr "Date"
#: web/templates/admin/payment/index.gohtml:23 #: web/templates/admin/payment/index.gohtml:75
msgctxt "header" msgctxt "header"
msgid "Down payment" msgid "Down payment"
msgstr "Acompte" msgstr "Acompte"
#: web/templates/admin/payment/index.gohtml:24 #: web/templates/admin/payment/index.gohtml:76
#: web/templates/admin/booking/fields.gohtml:75 #: web/templates/admin/booking/fields.gohtml:75
#: web/templates/admin/booking/fields.gohtml:173 #: web/templates/admin/booking/fields.gohtml:173
msgctxt "header" msgctxt "header"
msgid "Total" msgid "Total"
msgstr "Totale" msgstr "Totale"
#: web/templates/admin/payment/index.gohtml:40 #: web/templates/admin/payment/index.gohtml:84
msgid "No payments found." msgid "No payments found."
msgstr "Aucun paiement trouvée." msgstr "Aucun paiement trouvée."
@ -1925,14 +1966,6 @@ msgctxt "action"
msgid "Add Customer" msgid "Add Customer"
msgstr "Ajouter un client" msgstr "Ajouter un client"
#: web/templates/admin/customer/index.gohtml:43
#: web/templates/admin/invoice/index.gohtml:94
#: web/templates/admin/prebooking/index.gohtml:51
#: web/templates/admin/booking/index.gohtml:65
msgctxt "action"
msgid "Reset"
msgstr "Réinitialiser"
#: web/templates/admin/customer/index.gohtml:52 #: web/templates/admin/customer/index.gohtml:52
#: web/templates/admin/user/login-attempts.gohtml:20 #: web/templates/admin/user/login-attempts.gohtml:20
#: web/templates/admin/user/index.gohtml:21 #: web/templates/admin/user/index.gohtml:21
@ -2063,25 +2096,6 @@ msgstr "Client"
msgid "All customers" msgid "All customers"
msgstr "Tous les clients" msgstr "Tous les clients"
#: web/templates/admin/invoice/index.gohtml:55
#: web/templates/admin/booking/index.gohtml:38
msgid "All statuses"
msgstr "Tous les statuts"
#: web/templates/admin/invoice/index.gohtml:63
#: web/templates/admin/prebooking/index.gohtml:32
#: web/templates/admin/booking/index.gohtml:46
msgctxt "input"
msgid "From date"
msgstr "Partir de la date"
#: web/templates/admin/invoice/index.gohtml:72
#: web/templates/admin/prebooking/index.gohtml:41
#: web/templates/admin/booking/index.gohtml:55
msgctxt "input"
msgid "To date"
msgstr "À ce jour"
#: web/templates/admin/invoice/index.gohtml:81 #: web/templates/admin/invoice/index.gohtml:81
msgctxt "input" msgctxt "input"
msgid "Invoice number" msgid "Invoice number"

View File

@ -12,6 +12,58 @@
{{ define "content" -}} {{ define "content" -}}
{{- /*gotype: dev.tandem.ws/tandem/camper/pkg/payment.paymentIndex*/ -}} {{- /*gotype: dev.tandem.ws/tandem/camper/pkg/payment.paymentIndex*/ -}}
<a href="/admin/payments/settings">{{( pgettext "Payment Settings" "title" )}}</a> <a href="/admin/payments/settings">{{( pgettext "Payment Settings" "title" )}}</a>
{{ template "filters-toggle" }}
<form class="filters" method="GET" action="/admin/payments"
data-hx-target="main" data-hx-boost="true" data-hx-trigger="change,search,submit"
aria-labelledby="filters-toggle"
>
{{ with .Filters }}
<fieldset>
{{ with .PaymentStatus -}}
<label>
{{( pgettext "Payment status" "input" )}}<br>
<select name="{{ .Name }}"
{{ template "error-attrs" . }}
>
<option value="">{{( gettext "All statuses" )}}</option>
{{ template "list-options" . }}
</select><br>
{{ template "error-message" . }}
</label>
{{- end }}
{{ with .FromDate -}}
<label>
{{( pgettext "From date" "input" )}}<br>
<input type="date"
name="{{ .Name }}" value="{{ .Val }}" {{ template "error-attrs" . }}
><br>
{{ template "error-message" . }}
</label>
{{- end }}
{{ with .ToDate -}}
<label>
{{( pgettext "To date" "input" )}}<br>
<input type="date"
name="{{ .Name }}" value="{{ .Val }}" {{ template "error-attrs" . }}
><br>
{{ template "error-message" . }}
</label>
{{- end }}
{{ with .Reference -}}
<label>
{{( pgettext "Reference" "input" )}}<br>
<input type="search"
name="{{ .Name }}" value="{{ .Val }}" {{ template "error-attrs" . }}
><br>
{{ template "error-message" . }}
</label>
{{- end }}
</fieldset>
{{ end }}
{{ if .Filters.HasValue }}
<a href="/admin/payments" class="button">{{( pgettext "Reset" "action" )}}</a>
{{ end }}
</form>
<h2>{{ template "title" . }}</h2> <h2>{{ template "title" . }}</h2>
{{ if .Payments -}} {{ if .Payments -}}
<table> <table>
@ -25,15 +77,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{{ range .Payments -}} {{ template "results.gohtml" . }}
<tr class="payment-{{ .Status }}">
<td>{{ .CreatedAt | formatDate }}</td>
<td><a href="{{ .URL }}">{{ .Reference }}</a></td>
<td class="payment-status">{{ .StatusLabel }}</td>
<td class="numeric">{{ .DownPayment | formatPrice }}</td>
<td class="numeric">{{ .Total | formatPrice }}</td>
</tr>
{{- end }}
</tbody> </tbody>
</table> </table>
{{ else -}} {{ else -}}

View File

@ -0,0 +1,10 @@
{{ range .Payments -}}
<tr class="payment-{{ .Status }}">
<td>{{ .CreatedAt | formatDate }}</td>
<td><a href="{{ .URL }}">{{ .Reference }}</a></td>
<td class="payment-status">{{ .StatusLabel }}</td>
<td class="numeric">{{ .DownPayment | formatPrice }}</td>
<td class="numeric">{{ .Total | formatPrice }}</td>
</tr>
{{- end }}
{{ template "pagination" .Filters.Cursor | colspan 5 }}