private string GetAddrLabel(ContactReportAddress addr, TransFilterType addrType, string gender) { if (addrType == TransFilterType.Family) { return(addr.Label); } switch (gender) { case "Male": return(addr.HisLabel); case "Female": return(addr.HerLabel); } return(addr.Label); }
/// <summary> /// Get rows from database and build correct structure for it /// </summary> /// <param name="response">Response from database</param> /// <param name="reportType">0 - bill 1 - payment, 2 - payment/bills </param> /// <param name="unassignedPayments">out params in case if reportType 2 we create onother one list for payments which not assigned to bills</param> /// <param name="categoriesIds">Out param for contain categories list</param> /// <returns>Return correct list of object for transactions</returns> List <TransactionsReportList> FillTransactions(IList <TransactionsReportDto> response, TransFilterType reportType, out List <TransactionsReportList> unassignedPayments, out List <int> categoriesIds) { unassignedPayments = new List <TransactionsReportList>(); categoriesIds = new List <int>(); var sorted = new List <TransactionsReportList>(); // complette list of reports sorted.AddRange(response.AsParallel().GroupBy(e => e.TransactionID).Select(t => t.First()).Select(q => new TransactionsReportList { Amount = q.Amount, BillID = q.BillID, TransType = q.TransType, FamilyID = q.FamilyID, AddressID = q.AddressID, AuthTransactionId = q.AuthTransactionId, AuthNumber = q.AuthNumber, TransactionID = q.TransactionID, AmountDue = q.AmountDue, CheckNo = q.CheckNo, Date = q.Date, DepartmentID = q.DepartmentID, Details = PrepareTransactionsDetails(q.BillDetails, q.PaymentDetails), HonorMemory = q.HonorMemory, InvoiceNo = q.InvoiceNo, IsReceipt = q.IsReceipt, LetterID = q.LetterID, MailingID = q.MailingID, Note = q.Note, PayID = q.PayID, PaymentMethodID = q.PaymentMethodID, ReceiptNo = q.ReceiptNo, ReceiptSent = q.ReceiptSent, SolicitorID = q.SolicitorID })); CalculeteAmountDueForTransactionDetails(sorted); //fill categoriesIds foreach (List <TransactionDetailReportList> details in sorted.Select(e => e.Details)) { foreach (TransactionDetailReportList det in details) { if (det.CategoryID != null && !categoriesIds.Contains(det.CategoryID.Value)) { categoriesIds.Add(det.CategoryID.Value); } } } // if we have only payment or bill type so we no need to make some addition if (reportType != TransFilterType.Bill) { return(sorted); } //create list of payments without wich unasignet to bill foreach (TransactionsReportList payment in sorted.Where(r => r.TransType == 1)) { if (payment.Details.All(e => e.BillID != null)) { continue; } unassignedPayments.Add(payment); var tmpPayment = unassignedPayments.First(e => e.TransactionID == payment.TransactionID); if (tmpPayment.Details.Any(w => w.BillID != null)) { tmpPayment.Details = payment.Details.Where(r => r.BillID == null).ToList(); } } var result = new List <TransactionsReportList>(); // add to bils detail payment detail foreach (TransactionsReportList report in sorted.Where(r => r.TransType == 2)) { result.Add(new TransactionsReportList { TransactionID = report.TransactionID, FamilyID = report.FamilyID, BillID = report.BillID, AddressID = report.AddressID, InvoiceNo = report.InvoiceNo, Date = report.Date, Amount = report.Amount, AmountDue = report.AmountDue, CheckNo = report.CheckNo, TransType = report.TransType, PayID = report.PayID, AuthNumber = report.AuthNumber, PaymentMethodID = report.PaymentMethodID, IsReceipt = report.IsReceipt, ReceiptNo = report.ReceiptNo, ReceiptSent = report.ReceiptSent, LetterID = report.LetterID, SolicitorID = report.SolicitorID, DepartmentID = report.DepartmentID, MailingID = report.MailingID, HonorMemory = report.HonorMemory, Note = report.Note, AuthTransactionId = report.AuthTransactionId, Details = report.Details }); foreach (List <TransactionDetailReportList> detailReportLists in sorted.Where(p => p.TransType == 1) .Select(r => r.Details)) { if (detailReportLists.Any(e => e.BillID == report.BillID)) { result.First(e => e.TransactionID == report.TransactionID) .Details.AddRange(detailReportLists.Where(e => e.BillID == report.BillID)); } // report.Details.AddRange(detailReportLists.Where(e => e.BillID == report.BillID)); } } //foreach (TransactionsReportList report in sorted.Where(r => r.TransType == 2)) //{ // result.Add(new TransactionsReportList // { // TransactionID = report.TransactionID, // FamilyID = report.FamilyID, // BillID = report.BillID, // AddressID = report.AddressID, // InvoiceNo = report.InvoiceNo, // Date = report.Date, // Amount = report.Amount, // AmountDue = report.AmountDue, // CheckNo = report.CheckNo, // TransType = report.TransType, // PayID = report.PayID, // AuthNumber = report.AuthNumber, // PaymentMethodID = report.PaymentMethodID, // IsReceipt = report.IsReceipt, // ReceiptNo = report.ReceiptNo, // ReceiptSent = report.ReceiptSent, // LetterID = report.LetterID, // SolicitorID = report.SolicitorID, // DepartmentID = report.DepartmentID, // MailingID = report.MailingID, // HonorMemory = report.HonorMemory, // Note = report.Note, // AuthTransactionId = report.AuthTransactionId, // Details = report.Details // }); // foreach (List<TransactionDetailReportList> detailReportLists in sorted.Where(p => p.TransType == 1).Select(r => r.Details)) // { // if (detailReportLists.Any(e => e.BillID == report.BillID)) // result.First(e => e.TransactionID == report.TransactionID).Details.AddRange(detailReportLists.Where(e => e.BillID == report.BillID)); // // report.Details.AddRange(detailReportLists.Where(e => e.BillID == report.BillID)); // } //} //return only bills which contains also payment details return(result); }
/// <summary> /// Convert respose from db and convert to transaction report /// </summary> /// <param name="result">ref obj result</param> /// <param name="response">response from db</param> /// <param name="reportType">Report type: 1 - payment, 2 - bill</param> /// <param name="filter"></param> void ConvertResultToTransactionReport(TransactionReportResultDto result, IList <TransactionsReportDto> response, TransFilterType reportType, FilterTransactionReport filter) { List <TransactionsReportList> unassignedpayments; List <int> categoriesIds; var familiesIds = response.AsParallel().Select(r => r.FamilyID).Distinct().ToList(); result.Families = FillFamilies(familiesIds, response); result.Transactions = FillTransactions(response, reportType, out unassignedpayments, out categoriesIds).ToList(); result.UnassignedPayments = unassignedpayments; result.CategoriesIDs = categoriesIds; if (filter.ExcludeBillsWithCards != null && (bool)filter.ExcludeBillsWithCards) { result.Transactions = ExcludeAutoBills(result.Transactions); } }
EnvelopeAddress AddEnvelopAddress(string customAddress, ContactReportAddress addr, TransFilterType addrType, string gender = null) { string senderAddress = FormAddressStr( GetAddrLabel(addr, addrType, gender), addr.CompanyName, addr.Address, addr.Address2, addr.City, addr.State, addr.Zip, addr.Country, CountryInSettings); return(new EnvelopeAddress(0, customAddress, senderAddress)); }