rentease/internal/cron/job_report.go
Ruidy d4e6b35a96
Create taxes for taxable items automatically (#16)
* refactor return error when building booking service

* fix the description

* set taxable item by amount

* auto create tax items if the item is taxable

* fix linter

* remove legacy tax entry

* display multiple items

* use the price from the form

* improve item sorting

* lintfix
2024-08-26 21:44:31 +02:00

42 lines
1 KiB
Go

package cron
import (
"fmt"
"log"
"os"
"time"
"github.com/joho/godotenv"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"github.com/rjNemo/rentease/internal/booking"
"github.com/rjNemo/rentease/internal/pdf"
)
func JobMonthlyBookingReport() error {
_ = godotenv.Load()
db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL")), &gorm.Config{})
if err != nil {
return fmt.Errorf("error connecting to the database %s", err)
}
now := time.Now()
log.Println("Start Monthly Booking Report job at:", now)
service, _ := booking.NewService(db)
report := service.BuildReport("monthly", int(now.Month()), now.Year())
ps, err := pdf.NewPdfService(
os.Getenv("HTMLDOCS_PROJECT_ID"),
os.Getenv("HTMLDOCS_REPORT_PROJECT_ID"),
os.Getenv("HTMLDOCS_URL"),
os.Getenv("HTMLDOCS_KEY"),
)
if err != nil {
return fmt.Errorf("error starting pdf service %s", err)
}
_ = ps.BuildReport(report, "", int(now.Month()), now.Year())
log.Printf("Executed Monthly Booking Report job at %v with errors: %s:", time.Now().Format(time.DateTime), err)
return err
}