mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +00:00
new rport builder
This commit is contained in:
parent
575dc5ad7b
commit
96710d033a
2 changed files with 54 additions and 49 deletions
|
|
@ -17,22 +17,25 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type PdfService struct {
|
type PdfService struct {
|
||||||
invoicePath string
|
path string
|
||||||
projectId string
|
invoiceId string
|
||||||
|
reportId string
|
||||||
url string
|
url string
|
||||||
apiKey string
|
apiKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPdfService() (*PdfService, error) {
|
func NewPdfService() (*PdfService, error) {
|
||||||
pid := os.Getenv("HTMLDOCS_PROJECT_ID")
|
pid := os.Getenv("HTMLDOCS_PROJECT_ID")
|
||||||
|
rid := os.Getenv("HTMLDOCS_REPORT_PROJECT_ID")
|
||||||
url := os.Getenv("HTMLDOCS_URL")
|
url := os.Getenv("HTMLDOCS_URL")
|
||||||
key := os.Getenv("HTMLDOCS_KEY")
|
key := os.Getenv("HTMLDOCS_KEY")
|
||||||
if pid == "" || url == "" || key == "" {
|
if pid == "" || rid == "" || url == "" || key == "" {
|
||||||
return nil, errors.New("error building Pdf service. Verify your env variables")
|
return nil, errors.New("error building Pdf service. Verify your env variables")
|
||||||
}
|
}
|
||||||
return &PdfService{
|
return &PdfService{
|
||||||
invoicePath: "index.html",
|
path: "index.html",
|
||||||
projectId: pid,
|
invoiceId: pid,
|
||||||
|
reportId: rid,
|
||||||
url: url,
|
url: url,
|
||||||
apiKey: key,
|
apiKey: key,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -72,8 +75,8 @@ func (ps PdfService) BuildInvoice(b *booking.Booking, hc *config.Host) error {
|
||||||
return sum + i.Price*float64(i.Quantity)
|
return sum + i.Price*float64(i.Quantity)
|
||||||
}, 0.0), 'f', 2, 64),
|
}, 0.0), 'f', 2, 64),
|
||||||
},
|
},
|
||||||
Path: ps.invoicePath,
|
Path: ps.path,
|
||||||
ProjectId: ps.projectId,
|
ProjectId: ps.invoiceId,
|
||||||
}
|
}
|
||||||
|
|
||||||
payload, err := json.Marshal(data)
|
payload, err := json.Marshal(data)
|
||||||
|
|
@ -85,44 +88,46 @@ func (ps PdfService) BuildInvoice(b *booking.Booking, hc *config.Host) error {
|
||||||
return ps.sendData(payload)
|
return ps.sendData(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ps PdfService) BuildReport(r *booking.Report) error {
|
func (ps PdfService) BuildReport(r *booking.Report, period string, month, year int) error {
|
||||||
// data := struct {
|
data := struct {
|
||||||
// Context map[string]any `w`
|
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": r.InvoiceNumber(hc),
|
"month": month,
|
||||||
// "name": r.Name,
|
"year": year,
|
||||||
// "phone_number": r.PhoneNumber,
|
"total": r.Total,
|
||||||
// "customers_number": r.CustomerNumber,
|
"platform_fees": r.PlatformFees,
|
||||||
// "platform": r.Platform,
|
"fee": r.Fee,
|
||||||
// "from": r.From.Format("02/01/2006"),
|
"profit": r.Profit,
|
||||||
// "to": r.To.Format("02/01/2006"),
|
"card_total": r.CardTotal,
|
||||||
// "lines": u.Map(b.Items, func(i booking.Item) map[string]any {
|
"booking_fees": r.BookingFees,
|
||||||
// return map[string]any{
|
"lines": u.Map(r.Lines, func(l *booking.Line) map[string]any {
|
||||||
// "name": i.Item,
|
return map[string]any{
|
||||||
// "quantity": i.Quantity,
|
"id": l.Id,
|
||||||
// "price": i.Price,
|
"name": l.CustomerName,
|
||||||
// "total": i.Price * float64(i.Quantity),
|
"from": l.From.Format("2006-01-02"),
|
||||||
// }
|
"to": l.To.Format("2006-01-02"),
|
||||||
// }),
|
"total": l.Total,
|
||||||
// "total": strconv.FormatFloat(u.Reduce(b.Items, func(i booking.Item, sum float64) float64 {
|
"platform": l.Platform,
|
||||||
// return sum + i.Price*float64(i.Quantity)
|
"platform_fees": l.PlatformFees,
|
||||||
// }, 0.0), 'f', 2, 64),
|
"fee": l.Fee(),
|
||||||
// },
|
"profit": l.Profit(),
|
||||||
// Path: ps.invoicePath,
|
}
|
||||||
// ProjectId: ps.projectId,
|
}),
|
||||||
// }
|
},
|
||||||
|
Path: ps.path,
|
||||||
|
ProjectId: ps.reportId,
|
||||||
|
}
|
||||||
|
|
||||||
// payload, err := json.Marshal(data)
|
payload, err := json.Marshal(data)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// log.Warnf("Error marshalling JSON:", err)
|
log.Warnf("Error marshalling JSON:", err)
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return ps.sendData(payload)
|
return ps.sendData(payload)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ps PdfService) sendData(payload []byte) error {
|
func (ps PdfService) sendData(payload []byte) error {
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ func handleCreateReportPdf(bs *booking.Service, ps *pdf.PdfService) echo.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
report := bs.BuildReport(period, month, year)
|
report := bs.BuildReport(period, month, year)
|
||||||
err = ps.BuildReport(report, month, year)
|
err = ps.BuildReport(report, period, month, year)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue