show newest invoice first, show datetime
All checks were successful
Go / build (push) Successful in 13m34s

This commit is contained in:
2025-07-02 11:09:33 +02:00
parent db3dc9ecd1
commit 249cccd240
3 changed files with 22 additions and 4 deletions

View File

@@ -212,7 +212,7 @@ func (rc *configController) GetAllPaper(c *gin.Context) {
//////////////////////////////////////////////////////////////////////
func (rc *configController) InvoiceView(c *gin.Context) {
invoices, err := repositories.Invoices.GetAll()
invoices, err := repositories.Invoices.GetAllNewestFirst()
if err != nil {
c.HTML(http.StatusBadRequest, "invoiceview.html", gin.H{"data": gin.H{"error": err}})

View File

@@ -11,8 +11,11 @@ import (
type InvoiceRepository interface {
Create(models.Invoice) (models.Invoice, error)
GetAll() ([]models.Invoice, error)
GetAllSorted(string) ([]models.Invoice, error)
GetAllNewestFirst() ([]models.Invoice, error)
GetAllNewestLast() ([]models.Invoice, error)
GetById(string) (models.Invoice, error)
//GetByShopItemId(string) (models.Invoice, error)
//GetByInvoiceId(string) (models.Invoice, error)
Update(models.Invoice) (models.Invoice, error)
DeleteById(string) error
}
@@ -44,6 +47,21 @@ func (t *GORMInvoiceRepository) GetAll() ([]models.Invoice, error) {
return invoice, result.Error
}
func (t *GORMInvoiceRepository) GetAllSorted(sortString string) ([]models.Invoice, error) {
var invoices []models.Invoice
result := t.DB.Preload("PrintJobs.ShopItem").Preload("PrintJobs.Variant").Preload("PrintJobs.PaperType").Preload("PrintJobs.CoverPaperType").Preload("PrintJobs").Order(sortString).Find(&invoices)
return invoices, result.Error
}
func (r *GORMInvoiceRepository) GetAllNewestFirst() ([]models.Invoice, error) {
return r.GetAllSorted("created_at desc")
}
func (r *GORMInvoiceRepository) GetAllNewestLast() ([]models.Invoice, error) {
return r.GetAllSorted("created_at asc")
}
func (t *GORMInvoiceRepository) GetById(id string) (models.Invoice, error) {
invoiceId, err := strconv.Atoi(id)

View File

@@ -8,10 +8,10 @@
</div>
{{ range .data.invoices }}
<div class="w-full grid grid-cols-1 gap-4 mx-auto p-4 m-4 flex flex-wrap border rounded shadow-md">
<div class="w-full grid grid-cols-1 gap-4 mx-auto p-4 m-4 flex flex-wrap border rounded shadow-md max-w-4xl">
<div class="">
<div class="font-bold text-center mb-4">
Invoice #{{ .ID }}
Invoice #{{ .ID }} - {{ .CreatedAt }}
</div>
</div>
<div class="flex flex-col">