blob: 9c411dace7976981c5c17d1fc2a15f19674bf735 [file] [log] [blame]
package main
import (
"time"
pb "code.hackerspace.pl/hscloud/bgpwtf/invoice/proto"
)
func calculateInvoiceData(p *pb.Invoice) {
p.Unit = p.Data.Unit
if p.Unit == "" {
p.Unit = "€"
}
p.TotalNet = 0
p.Total = 0
for _, i := range p.Data.Item {
rowTotalNet := uint64(i.UnitPrice * i.Count)
rowTotal := uint64(float64(rowTotalNet) * (float64(1) + float64(i.Vat)/100000))
p.TotalNet += rowTotalNet
p.Total += rowTotal
i.TotalNet = rowTotalNet
i.Total = rowTotal
}
due := int64(time.Hour*24) * p.Data.DaysDue
p.DueDate = time.Unix(0, p.Date).Add(time.Duration(due)).UnixNano()
}