-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathReportGenerator.cs
51 lines (41 loc) · 1.77 KB
/
ReportGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*******************************************************************************
*
* Copyright (c) {2003-2019} Murex S.A.S. and its affiliates.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the MIT License
* which accompanies this distribution, and is available at
* https://opensource.org/licenses/MIT
*
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using Application.Finance;
using Application.Purchase;
using Application.Storage;
namespace Application.Report
{
public class ReportGenerator
{
private readonly IRepository _repository = MainRepository.ConfiguredRepository;
public double GetTotalAmount()
{
var invoices = _repository.GetInvoiceMap().Values;
// BUG: There was a bug with the following line of code
// var totalAmount = invoices.Sum(invoice => invoice.ComputeTotalAmount());
// FIX: The above bug was fixed by the following line of code
var totalAmount = invoices.Sum(invoice =>
CurrencyConverter.ToUsd(invoice.ComputeTotalAmount(), invoice.Country.Currency));
return GetRoundedAmount(totalAmount);
}
private double GetRoundedAmount(double totalAmount) => Math.Round(totalAmount, 2);
public int GetTotalSoldBooks()
{
var invoices = _repository.GetInvoiceMap().Values;
var totalSoldBooks = invoices
.Sum(invoice => invoice.PurchasedBooks.Sum(purchasedBook => purchasedBook.Quantity));
return totalSoldBooks;
}
public long GetNumberOfIssuedInvoices() => _repository.GetInvoiceMap().Count;
}
}