add customer number seed

This commit is contained in:
Ruidy 2024-02-22 22:08:46 +01:00
parent 804d08caba
commit 37cadd8b20
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
7 changed files with 21 additions and 12 deletions

View file

@ -10,9 +10,9 @@ run: build
dev: templ
@air cmd/main.go
templ:
@templ generate --watch &
@templ generate --watch --proxy=http://localhost:${PORT} &
format:
@templ generate
@templ generate internal/views
@templ fmt .
@go fmt ./...
lint:

View file

@ -1,7 +1,11 @@
package config
type Host struct{}
type Host struct {
CustomerSeed int
}
func NewHost() *Host {
return &Host{}
return &Host{
CustomerSeed: 286,
}
}

View file

@ -12,6 +12,7 @@ import (
"github.com/labstack/gommon/log"
"github.com/rjNemo/rentease/config"
"github.com/rjNemo/rentease/internal/booking"
u "github.com/rjNemo/underscore"
)
@ -32,14 +33,14 @@ func NewPdfService() *PdfService {
}
}
func (ps PdfService) BuildInvoice(b *booking.Booking) error {
func (ps PdfService) BuildInvoice(b *booking.Booking, hc *config.Host) error {
data := struct {
Context map[string]any `json:"context"`
Path string `json:"path"`
ProjectId string `json:"projectId"`
}{
Context: map[string]any{
"id": fmt.Sprintf("VFNI%04s", strconv.Itoa(b.Id)),
"id": fmt.Sprintf("VFNI%04s", strconv.Itoa(b.Id+hc.CustomerSeed)),
"name": b.Name,
"phone_number": b.PhoneNumber,
"customers_number": b.CustomerNumber,

View file

@ -4,11 +4,12 @@ import (
"strconv"
"github.com/labstack/echo/v4"
"github.com/rjNemo/rentease/config"
"github.com/rjNemo/rentease/internal/booking"
"github.com/rjNemo/rentease/internal/pdf"
)
func handleCreateInvoicePdf(bs *booking.Service, ps *pdf.PdfService) echo.HandlerFunc {
func handleCreateInvoicePdf(bs *booking.Service, ps *pdf.PdfService, hc *config.Host) echo.HandlerFunc {
return func(c echo.Context) error {
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
@ -18,7 +19,7 @@ func handleCreateInvoicePdf(bs *booking.Service, ps *pdf.PdfService) echo.Handle
b := bs.One(id)
err = ps.BuildInvoice(b)
err = ps.BuildInvoice(b, hc)
if err != nil {
return err
}

View file

@ -11,6 +11,7 @@ import (
"github.com/labstack/gommon/log"
u "github.com/rjNemo/underscore"
"github.com/rjNemo/rentease/config"
"github.com/rjNemo/rentease/constants"
"github.com/rjNemo/rentease/internal/booking"
"github.com/rjNemo/rentease/internal/views"
@ -72,7 +73,7 @@ func handleCreateBooking(bs *booking.Service) echo.HandlerFunc {
}
}
func handleBookingPage(bs *booking.Service) echo.HandlerFunc {
func handleBookingPage(bs *booking.Service, hc *config.Host) echo.HandlerFunc {
return func(c echo.Context) error {
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
@ -83,7 +84,7 @@ func handleBookingPage(bs *booking.Service) echo.HandlerFunc {
b := bs.One(id)
bvm := &views.BookingViewModel{
Id: fmt.Sprintf("%04s", strconv.Itoa(b.Id)),
Id: fmt.Sprintf("%04s", strconv.Itoa(b.Id+hc.CustomerSeed)),
Name: b.Name,
PhoneNumber: b.PhoneNumber,
CustomerNumber: strconv.Itoa(b.CustomerNumber),

View file

@ -5,9 +5,9 @@ func (s Server) MountHandlers() {
s.Router.GET("/bookings", handleListBookingPage(s.bs))
s.Router.GET("/bookings/new", handleNewBookingPage())
s.Router.POST("/bookings/new", handleCreateBooking(s.bs))
s.Router.GET("/bookings/:id", handleBookingPage(s.bs))
s.Router.GET("/bookings/:id", handleBookingPage(s.bs, s.hc))
s.Router.POST("/bookings/:id/items", handleCreateItem(s.bs))
s.Router.GET("/bookings/pdf/:id", handleCreateInvoicePdf(s.bs, s.ps))
s.Router.GET("/bookings/pdf/:id", handleCreateInvoicePdf(s.bs, s.ps, s.hc))
s.Router.GET("/reports", handleReportsPage())
s.Router.GET("/reports/do", handleComputeReport(s.bs))
}

View file

@ -23,6 +23,7 @@ type Server struct {
Router *echo.Echo
bs *booking.Service
ps *pdf.PdfService
hc *config.Host
addr string
}
@ -31,6 +32,7 @@ func New(bs *booking.Service, ps *pdf.PdfService, hc *config.Host) *Server {
Router: NewRouter(),
bs: bs,
ps: ps,
hc: hc,
addr: fmt.Sprintf("0.0.0.0:%s", os.Getenv("PORT")),
}
s.MountHandlers()