mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package pdf
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"os"
|
|
"text/template"
|
|
|
|
"github.com/labstack/gommon/log"
|
|
"github.com/rjNemo/rentease/assets"
|
|
"github.com/rjNemo/rentease/internal/service/booking"
|
|
)
|
|
|
|
type HtmlPdfClient struct{}
|
|
|
|
func NewPdfClient() (*HtmlPdfClient, error) {
|
|
return &HtmlPdfClient{}, nil
|
|
}
|
|
|
|
func (pc *HtmlPdfClient) BuildInvoice(data booking.Invoice) (string, error) {
|
|
log.Info("building invoice")
|
|
tmpl, err := template.ParseFS(assets.Static, "assets/html/invoice.html")
|
|
if err != nil {
|
|
return "", fmt.Errorf("error parsing template: %v", err)
|
|
}
|
|
|
|
// Create a buffer to hold the rendered HTML.
|
|
var buf bytes.Buffer
|
|
if err := tmpl.Execute(&buf, data); err != nil {
|
|
return "", fmt.Errorf("error executing template: %v", err)
|
|
}
|
|
|
|
outputPath := fmt.Sprintf("%s.html", data.ID)
|
|
if err := os.WriteFile(outputPath, buf.Bytes(), 0644); err != nil {
|
|
return "", fmt.Errorf("error writing HTML file: %v", err)
|
|
}
|
|
|
|
log.Info("building invoice")
|
|
return outputPath, nil
|
|
}
|
|
|
|
func (pc *HtmlPdfClient) BuildReport(context map[string]any, period string, month int, year int) error {
|
|
panic("unimplemented")
|
|
}
|