mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +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
|
dev: templ
|
||||||
@air cmd/main.go
|
@air cmd/main.go
|
||||||
templ:
|
templ:
|
||||||
@templ generate --watch &
|
@templ generate --watch --proxy=http://localhost:${PORT} &
|
||||||
format:
|
format:
|
||||||
@templ generate
|
@templ generate internal/views
|
||||||
@templ fmt .
|
@templ fmt .
|
||||||
@go fmt ./...
|
@go fmt ./...
|
||||||
lint:
|
lint:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
type Host struct{}
|
type Host struct {
|
||||||
|
CustomerSeed int
|
||||||
|
}
|
||||||
|
|
||||||
func NewHost() *Host {
|
func NewHost() *Host {
|
||||||
return &Host{}
|
return &Host{
|
||||||
|
CustomerSeed: 286,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/labstack/gommon/log"
|
"github.com/labstack/gommon/log"
|
||||||
|
|
||||||
|
"github.com/rjNemo/rentease/config"
|
||||||
"github.com/rjNemo/rentease/internal/booking"
|
"github.com/rjNemo/rentease/internal/booking"
|
||||||
u "github.com/rjNemo/underscore"
|
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 {
|
data := struct {
|
||||||
Context map[string]any `json:"context"`
|
Context map[string]any `json:"context"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
ProjectId string `json:"projectId"`
|
ProjectId string `json:"projectId"`
|
||||||
}{
|
}{
|
||||||
Context: map[string]any{
|
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,
|
"name": b.Name,
|
||||||
"phone_number": b.PhoneNumber,
|
"phone_number": b.PhoneNumber,
|
||||||
"customers_number": b.CustomerNumber,
|
"customers_number": b.CustomerNumber,
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,12 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/rjNemo/rentease/config"
|
||||||
"github.com/rjNemo/rentease/internal/booking"
|
"github.com/rjNemo/rentease/internal/booking"
|
||||||
"github.com/rjNemo/rentease/internal/pdf"
|
"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 {
|
return func(c echo.Context) error {
|
||||||
idStr := c.Param("id")
|
idStr := c.Param("id")
|
||||||
id, err := strconv.Atoi(idStr)
|
id, err := strconv.Atoi(idStr)
|
||||||
|
|
@ -18,7 +19,7 @@ func handleCreateInvoicePdf(bs *booking.Service, ps *pdf.PdfService) echo.Handle
|
||||||
|
|
||||||
b := bs.One(id)
|
b := bs.One(id)
|
||||||
|
|
||||||
err = ps.BuildInvoice(b)
|
err = ps.BuildInvoice(b, hc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/labstack/gommon/log"
|
"github.com/labstack/gommon/log"
|
||||||
u "github.com/rjNemo/underscore"
|
u "github.com/rjNemo/underscore"
|
||||||
|
|
||||||
|
"github.com/rjNemo/rentease/config"
|
||||||
"github.com/rjNemo/rentease/constants"
|
"github.com/rjNemo/rentease/constants"
|
||||||
"github.com/rjNemo/rentease/internal/booking"
|
"github.com/rjNemo/rentease/internal/booking"
|
||||||
"github.com/rjNemo/rentease/internal/views"
|
"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 {
|
return func(c echo.Context) error {
|
||||||
idStr := c.Param("id")
|
idStr := c.Param("id")
|
||||||
id, err := strconv.Atoi(idStr)
|
id, err := strconv.Atoi(idStr)
|
||||||
|
|
@ -83,7 +84,7 @@ func handleBookingPage(bs *booking.Service) echo.HandlerFunc {
|
||||||
b := bs.One(id)
|
b := bs.One(id)
|
||||||
|
|
||||||
bvm := &views.BookingViewModel{
|
bvm := &views.BookingViewModel{
|
||||||
Id: fmt.Sprintf("%04s", strconv.Itoa(b.Id)),
|
Id: fmt.Sprintf("%04s", strconv.Itoa(b.Id+hc.CustomerSeed)),
|
||||||
Name: b.Name,
|
Name: b.Name,
|
||||||
PhoneNumber: b.PhoneNumber,
|
PhoneNumber: b.PhoneNumber,
|
||||||
CustomerNumber: strconv.Itoa(b.CustomerNumber),
|
CustomerNumber: strconv.Itoa(b.CustomerNumber),
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ func (s Server) MountHandlers() {
|
||||||
s.Router.GET("/bookings", handleListBookingPage(s.bs))
|
s.Router.GET("/bookings", handleListBookingPage(s.bs))
|
||||||
s.Router.GET("/bookings/new", handleNewBookingPage())
|
s.Router.GET("/bookings/new", handleNewBookingPage())
|
||||||
s.Router.POST("/bookings/new", handleCreateBooking(s.bs))
|
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.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", handleReportsPage())
|
||||||
s.Router.GET("/reports/do", handleComputeReport(s.bs))
|
s.Router.GET("/reports/do", handleComputeReport(s.bs))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ type Server struct {
|
||||||
Router *echo.Echo
|
Router *echo.Echo
|
||||||
bs *booking.Service
|
bs *booking.Service
|
||||||
ps *pdf.PdfService
|
ps *pdf.PdfService
|
||||||
|
hc *config.Host
|
||||||
addr string
|
addr string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,6 +32,7 @@ func New(bs *booking.Service, ps *pdf.PdfService, hc *config.Host) *Server {
|
||||||
Router: NewRouter(),
|
Router: NewRouter(),
|
||||||
bs: bs,
|
bs: bs,
|
||||||
ps: ps,
|
ps: ps,
|
||||||
|
hc: hc,
|
||||||
addr: fmt.Sprintf("0.0.0.0:%s", os.Getenv("PORT")),
|
addr: fmt.Sprintf("0.0.0.0:%s", os.Getenv("PORT")),
|
||||||
}
|
}
|
||||||
s.MountHandlers()
|
s.MountHandlers()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue