Skip to content
Snippets Groups Projects
Commit f7a43ec9 authored by Alexander Tumin's avatar Alexander Tumin
Browse files

Merge branch 'feature/MRM-4063' into 'release/v0.13'

MRM-4063: fix total and taxAmount fields

See merge request mashroom/backend/invoice!84
parents 8e375459 f90033ec
No related merge requests found
......@@ -178,6 +178,12 @@ func (srv *serverImpl) reportUserdata(ctx context.Context, i *model.ReportItem)
func (srv *serverImpl) reportRenderCSV(ctx context.Context, items []*model.ReportItem) ([]byte, error) {
var rows []csvRow
total := make(map[string]float64)
for _, i := range items {
total[i.SystemReference] += float64(i.Quantity) * (i.Price + i.TaxAmount)
}
for _, i := range items {
userdata, _ := srv.reportUserdata(ctx, i)
......@@ -202,6 +208,8 @@ func (srv *serverImpl) reportRenderCSV(ctx context.Context, items []*model.Repor
reference = i.SystemReference
}
taxAmount := float64(i.Quantity) * i.TaxAmount
rows = append(rows, csvRow{
ContactName: contactName,
EmailAddress: userdata.Contacts.EmailPrimary,
......@@ -217,7 +225,7 @@ func (srv *serverImpl) reportRenderCSV(ctx context.Context, items []*model.Repor
Reference: reference,
InvoiceDate: i.Created.Format("02/01/2006 15:04:05"),
DueDate: i.Created.Format("02/01/2006 15:04:05"),
Total: fmt.Sprintf("%.2f", i.Price+i.TaxAmount),
Total: fmt.Sprintf("%.2f", total[i.SystemReference]),
InventoryItemCode: strconv.FormatUint(i.ID, 10),
Description: i.Title,
Quantity: strconv.FormatInt(i.Quantity, 10),
......@@ -225,7 +233,7 @@ func (srv *serverImpl) reportRenderCSV(ctx context.Context, items []*model.Repor
Discount: "0.00",
AccountCode: "207",
TaxType: fmt.Sprintf("%.0f%% (%s)", i.TaxPercentage, taxType),
TaxAmount: fmt.Sprintf("%.2f", i.TaxAmount),
TaxAmount: fmt.Sprintf("%.2f", taxAmount),
TrackingName1: "Activity",
TrackingOption1: "Rentals",
TrackingName2: "",
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment