go/svc/invoice: add statusz
diff --git a/go/svc/invoice/model.go b/go/svc/invoice/model.go
index 0ed8245..cb15a16 100644
--- a/go/svc/invoice/model.go
+++ b/go/svc/invoice/model.go
@@ -211,3 +211,62 @@
}
return p, nil
}
+
+type invoice struct {
+ ID int64
+ Number string
+ Sealed bool
+ Proto *pb.Invoice
+ TotalNet int
+ Total int
+}
+
+func (m *model) getInvoices(ctx context.Context) ([]invoice, error) {
+ q := `
+ select invoice_seal.final_uid, invoice.id, invoice.proto from invoice
+ left join invoice_seal
+ on invoice_seal.invoice_id = invoice.id
+ `
+ rows, err := m.db.QueryContext(ctx, q)
+ if err != nil {
+ return []invoice{}, err
+ }
+ defer rows.Close()
+
+ res := []invoice{}
+ for rows.Next() {
+ i := invoice{
+ Proto: &pb.Invoice{},
+ }
+ buf := []byte{}
+
+ number := sql.NullString{}
+ if err := rows.Scan(&number, &i.ID, &buf); err != nil {
+ return []invoice{}, err
+ }
+
+ if err := proto.Unmarshal(buf, i.Proto); err != nil {
+ return []invoice{}, err
+ }
+
+ if number.Valid {
+ i.Sealed = true
+ i.Number = number.String
+ } else {
+ i.Number = "proforma"
+ }
+
+ i.Total = 0
+ i.TotalNet = 0
+ for _, it := range i.Proto.Item {
+ rowTotalNet := int(it.UnitPrice * it.Count)
+ rowTotal := int(float64(rowTotalNet) * (float64(1) + float64(it.Vat)/100000))
+ i.TotalNet += rowTotalNet
+ i.Total += rowTotal
+ }
+
+ res = append(res, i)
+ }
+
+ return res, nil
+}