feat: more options
Some checks failed
Go / build (push) Failing after 1m16s

This commit is contained in:
2025-11-04 20:16:44 +01:00
parent 8f5ae15ef0
commit cfbb475a42
6 changed files with 58 additions and 22 deletions

View File

@@ -9,6 +9,7 @@ import (
"time"
"git.schreifuchs.ch/lou-taylor/accounting/internal/email"
"git.schreifuchs.ch/lou-taylor/accounting/pkg/invoice"
)
const bufSize = 1024 * 1024 // 1Mib
@@ -28,7 +29,9 @@ func (s Service) createInvoice(w http.ResponseWriter, r *http.Request) {
return
}
invoice, report, err := s.invoice.Generate(req.Creditor, &req.Debtor, time.Duration(req.DurationThreshold), req.HourlyRate, repos)
opts := invoice.DefaultOptions
opts.Mindur = time.Duration(req.DurationThreshold)
invoice, report, err := s.invoice.Generate(req.Creditor, &req.Debtor, req.HourlyRate, repos, &opts)
if err != nil {
s.sendErr(w, http.StatusInternalServerError, "internal server error")
return
@@ -65,11 +68,15 @@ func (s Service) sendInvoice(w http.ResponseWriter, r *http.Request) {
s.sendErr(w, 500, err.Error())
return
}
invoice, report, err := s.invoice.Generate(req.Invoice.Creditor, &req.Invoice.Debtor, time.Duration(req.Invoice.DurationThreshold), req.Invoice.HourlyRate, repos)
opts := invoice.DefaultOptions
opts.Mindur = time.Duration(req.Invoice.DurationThreshold)
invoice, report, err := s.invoice.Generate(req.Invoice.Creditor, &req.Invoice.Debtor, req.Invoice.HourlyRate, repos, &opts)
if err != nil {
s.sendErr(w, http.StatusInternalServerError, "error while processing invoice:", err)
return
}
// if no time has to be billed aka if bill for 0 CHF
if report.Total() <= time.Duration(0) {
s.sendErr(w, http.StatusNotFound, "no suitable issues to be billed")