コード例 #1
0
        public Tuple <List <string>, List <string> > ConvertToCsv(FullDatabaseModel data)
        {
            try
            {
                if (data == null || !data.FullDatabase.Any())
                {
                    return(new Tuple <List <string>, List <string> >(new List <string>(), new List <string>()));
                }
                var csvData = new List <string>();

                var header   = $"{ClientId},{InvoiceNumber},{PaymentDue},{PaymentDueDate}";
                var payments = Math.Ceiling((double)data.FullDatabase.Max(row => row.Payments.Count) / 3);
                for (var i = 1; i <= payments; i++)
                {
                    header = $"{header},{PaymentDate}{i},{PaymentPaid}{i},{Latency}{i}";
                }
                csvData.Add(header);
                csvData.AddRange(
                    from databaseRow
                    in data.FullDatabase
                    let databaseRowString = $"{databaseRow.ClientId},{databaseRow.InvoiceNumber},{databaseRow.PaymentDue},{databaseRow.PaymentDueDate.Day}.{databaseRow.PaymentDueDate.Month}.{databaseRow.PaymentDueDate.Year}"
                                            select databaseRow.Payments
                                            .Aggregate(databaseRowString, (current, paymentDateLatencyPaid) => $"{current},{paymentDateLatencyPaid.PaymentDate.Day}.{paymentDateLatencyPaid.PaymentDate.Month}.{paymentDateLatencyPaid.PaymentDate.Year},{paymentDateLatencyPaid.PaymentPaid},{paymentDateLatencyPaid.Latency}"));

                return(new Tuple <List <string>, List <string> >(csvData, new List <string>()));
            }
            catch (Exception e)
            {
                MessageBox.Show($@"Failed converting full report to csv. InnerMessage: {e.Message}");
                throw;
            }
        }
コード例 #2
0
        private SummedDatabaseModel ConvertFullReportToSummedReport(FullDatabaseModel fullReportModel)
        {
            var dataBaseRowsByClientId = SplitFullDbRowsByClientId(fullReportModel);

            var summedDatabase = new SummedDatabaseModel();

            foreach (var clientInFullDb in dataBaseRowsByClientId)
            {
                summedDatabase.SummedDatabase.Add(clientInFullDb.Key, GetSummedDatabasePartner(clientInFullDb.Value));
            }

            return(summedDatabase);
        }
コード例 #3
0
        private List <string> AddCenturionLogsGetBackIssues(FullDatabaseModel fullDatabase, List <CenturionLog> centurionLogs)
        {
            var issues = new List <string>();

            if (!centurionLogs.Any())
            {
                return(issues);
            }
            var uniqueCenturionReportRows =
                centurionLogs
                .Select(report => report.CenturionReport)
                .Aggregate((a, b) => a.Union(b).ToList());

            foreach (var uniqueCenturionReportRow in uniqueCenturionReportRows)
            {
                var fullDbRow = fullDatabase
                                .FullDatabase
                                .FirstOrDefault(row => row.InvoiceNumber.Equals(uniqueCenturionReportRow.InvoiceNumber));

                if (fullDbRow == null)
                {
                    continue;
                }

                fullDbRow.ClientId = uniqueCenturionReportRow.ClientId;
                var payment = new PaymentDateLatencyPaid
                {
                    PaymentDate = uniqueCenturionReportRow.PaymentDate,
                    PaymentPaid = uniqueCenturionReportRow.AmountPaid
                };

                var totalDaysBetweenDueAndPaid = (uniqueCenturionReportRow.PaymentDate - fullDbRow.PaymentDueDate).TotalDays;
                payment.Latency = totalDaysBetweenDueAndPaid > 0 ? (int)totalDaysBetweenDueAndPaid : 0;


                if (fullDbRow.Payments == null)
                {
                    fullDbRow.Payments = new List <PaymentDateLatencyPaid>();
                }
                fullDbRow.Payments.Add(payment);
            }

            return(issues);
        }
コード例 #4
0
        public Tuple <FullDatabaseModel, List <string> > GetFullReportModel(List <string> centurionLogNames, List <string> clientLogNames, string latencyTable = null)
        {
            try
            {
                var fullDatabaseModel = new FullDatabaseModel();
                var issues            = new List <string>();

                var centurionLogsAndIssues = centurionLogNames.Select(_logDal.GetCenturionLog).ToList();
                var latencyConversionTable = _logDal.GetReportLatencyLog(latencyTable);
                var clientLogsAndIssues    = clientLogNames.Select(logName => _logDal.GetClientLog(logName, latencyConversionTable)).ToList();

                centurionLogsAndIssues.ForEach(x => issues.AddRange(x.Item2));
                clientLogsAndIssues.ForEach(x => issues.AddRange(x.Item2));

                try
                {
                    issues.AddRange(AddClientLogsGetBackIssues(fullDatabaseModel, clientLogsAndIssues.Select(x => x.Item1).ToList()).Where(x => !string.IsNullOrEmpty(x)));
                }
                catch (Exception e)
                {
                    MessageBox.Show($@"Failed adding client logs to full report model. InnerMessage: {e.Message}, issues cataloged in issues file.");
                    throw;
                }
                try
                {
                    issues.AddRange(AddCenturionLogsGetBackIssues(fullDatabaseModel, centurionLogsAndIssues.Select(x => x.Item1).ToList()).Where(x => !string.IsNullOrEmpty(x)));
                }
                catch (Exception e)
                {
                    MessageBox.Show($@"Failed adding centurions logs to full report model. InnerMessage: {e.Message}, issues cataloged in issues file.");
                    throw;
                }

                return(new Tuple <FullDatabaseModel, List <string> >(fullDatabaseModel, issues));
            }
            catch (Exception e)
            {
                MessageBox.Show($@"Failed calculating full report model. InnerMessage: {e.Message}, issues cataloged in issues file.");
                throw;
            }
        }
コード例 #5
0
        private List <string> AddClientLogsGetBackIssues(FullDatabaseModel fullDatabase, List <ClientLog> clientLogs)
        {
            var issues = new List <string>();

            if (!clientLogs.Any())
            {
                return(issues);
            }
            var uniqueClientReportRows =
                clientLogs
                .Select(report => report.ClientReport)
                .Aggregate((a, b) => a.Union(b).ToList());

            foreach (var clientReportRow in uniqueClientReportRows)
            {
                if (fullDatabase.FullDatabase.Any(fullDatabaseRow => fullDatabaseRow.InvoiceNumber.Equals(clientReportRow.InvoiceNumber)))
                {
                    continue;
                }

                var newDatabaseRow = new FullDatabaseRow
                {
                    InvoiceNumber  = clientReportRow.InvoiceNumber,
                    PaymentDue     = clientReportRow.AmountDue,
                    PaymentDueDate = new DateTime(
                        clientReportRow.InvoiceDate.Year,
                        clientReportRow.InvoiceDate.Month,
                        DateTime.DaysInMonth(clientReportRow.InvoiceDate.Year, clientReportRow.InvoiceDate.Month)).
                                     AddDays(clientReportRow.PaymentTerms),
                    ClientId = clientReportRow.ClientId
                };

                fullDatabase.FullDatabase.Add(newDatabaseRow);
            }

            return(issues);
        }
コード例 #6
0
        private Dictionary <string, List <FullDatabaseRow> > SplitFullDbRowsByClientId(FullDatabaseModel fullReportModel)
        {
            var dataBaseRowsByClientId = new Dictionary <string, List <FullDatabaseRow> >();

            foreach (var fullDatabaseRow in fullReportModel.FullDatabase)
            {
                if (string.IsNullOrEmpty(fullDatabaseRow.ClientId))
                {
                    continue;
                }
                var fullDbRowClientId = fullDatabaseRow.ClientId.Replace(" ", "");
                if (dataBaseRowsByClientId.ContainsKey(fullDbRowClientId))
                {
                    dataBaseRowsByClientId[fullDbRowClientId].Add(fullDatabaseRow);
                }
                else
                {
                    dataBaseRowsByClientId.Add(fullDbRowClientId, new List <FullDatabaseRow> {
                        fullDatabaseRow
                    });
                }
            }

            return(dataBaseRowsByClientId);
        }