mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
add customer number seed
This commit is contained in:
parent
804d08caba
commit
37cadd8b20
7 changed files with 21 additions and 12 deletions
4
Makefile
4
Makefile
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
package config
|
||||
|
||||
type Host struct{}
|
||||
type Host struct {
|
||||
CustomerSeed int
|
||||
}
|
||||
|
||||
func NewHost() *Host {
|
||||
return &Host{}
|
||||
return &Host{
|
||||
CustomerSeed: 286,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue