private List <JournalEntryLine> GetGlEntries(FinancialBatch financialBatch, ref string debugLava, string DescriptionLava = "") { if (string.IsNullOrWhiteSpace(DescriptionLava)) { DescriptionLava = "{{ Batch.Id }}: {{ Batch.Name }}"; } var rockContext = new RockContext(); // // Group/Sum Transactions by Account and Project since Project can come from Account or Transaction Details // List <RegistrationInstance> registrationLinks; List <GroupMember> groupMemberLinks; var batchTransactionsSummary = TransactionHelpers.GetTransactionSummary(financialBatch, rockContext, out registrationLinks, out groupMemberLinks); // // Get the Dimensions from the Account since the Transaction Details have been Grouped already // var customDimensions = TransactionHelpers.GetCustomDimensions(); var batchSummary = new List <GLBatchTotals>(); foreach (var summary in batchTransactionsSummary) { var account = new FinancialAccountService(rockContext).Get(summary.FinancialAccountId); var customDimensionValues = new Dictionary <string, dynamic>(); account.LoadAttributes(); var mergeFieldObjects = new MergeFieldObjects { Account = account, Batch = financialBatch, Registrations = registrationLinks, GroupMembers = groupMemberLinks, Summary = summary, CustomDimensions = customDimensions }; Dictionary <string, object> mergeFields = TransactionHelpers.GetMergeFieldsAndDimensions(ref debugLava, customDimensionValues, mergeFieldObjects); var batchSummaryItem = new GLBatchTotals() { Amount = summary.Amount, CreditAccount = account.GetAttributeValue("rocks.kfs.Intacct.ACCOUNTNO"), DebitAccount = account.GetAttributeValue("rocks.kfs.Intacct.DEBITACCOUNTNO"), TransactionFeeAmount = summary.TransactionFeeAmount, TransactionFeeAccount = summary.TransactionFeeAccount, Class = account.GetAttributeValue("rocks.kfs.Intacct.CLASSID"), Department = account.GetAttributeValue("rocks.kfs.Intacct.DEPARTMENT"), Location = account.GetAttributeValue("rocks.kfs.Intacct.LOCATION"), Project = summary.Project, Description = DescriptionLava.ResolveMergeFields(mergeFields), CustomDimensions = customDimensionValues, ProcessTransactionFees = summary.ProcessTransactionFees }; batchSummary.Add(batchSummaryItem); } return(GenerateLineItems(batchSummary)); }
private OtherReceipt BuildOtherReceipt(FinancialBatch financialBatch, ref string debugLava, PaymentMethod paymentMethod, string bankAccountId = null, string unDepGLAccountId = null, string DescriptionLava = "") { if (string.IsNullOrWhiteSpace(DescriptionLava)) { DescriptionLava = "{{ Batch.Id }}: {{ Batch.Name }}"; } var rockContext = new RockContext(); var batchDate = financialBatch.BatchStartDateTime == null ? RockDateTime.Now : ((System.DateTime)financialBatch.BatchStartDateTime); var otherReceipt = new OtherReceipt { Payer = "Rock Batch Import", PaymentDate = batchDate, ReceivedDate = batchDate, PaymentMethod = paymentMethod, BankAccountId = bankAccountId, UnDepGLAccountNo = unDepGLAccountId, DepositDate = batchDate, Description = string.Format("Imported From Rock batch {0}: {1}", financialBatch.Id, financialBatch.Name), RefId = financialBatch.Id.ToString(), ReceiptItems = new List <ReceiptLineItem>() }; List <RegistrationInstance> registrationLinks; List <GroupMember> groupMemberLinks; var receiptTransactions = TransactionHelpers.GetTransactionSummary(financialBatch, rockContext, out registrationLinks, out groupMemberLinks); // // Get the Dimensions from the Account since the Transaction Details have been Grouped already // var customDimensions = TransactionHelpers.GetCustomDimensions(); // Create Receipt Item for each entry within a grouping foreach (var bTran in receiptTransactions) { var account = new FinancialAccountService(rockContext).Get(bTran.FinancialAccountId); var customDimensionValues = new Dictionary <string, dynamic>(); account.LoadAttributes(); var mergeFieldObjects = new MergeFieldObjects { Account = account, Batch = financialBatch, Registrations = registrationLinks, GroupMembers = groupMemberLinks, Summary = bTran, CustomDimensions = customDimensions }; Dictionary <string, object> mergeFields = TransactionHelpers.GetMergeFieldsAndDimensions(ref debugLava, customDimensionValues, mergeFieldObjects); var classId = account.GetAttributeValue("rocks.kfs.Intacct.CLASSID"); var departmentId = account.GetAttributeValue("rocks.kfs.Intacct.DEPARTMENT"); var locationId = account.GetAttributeValue("rocks.kfs.Intacct.LOCATION"); var receiptItem = new ReceiptLineItem { GlAccountNo = account.GetAttributeValue("rocks.kfs.Intacct.ACCOUNTNO"), Amount = bTran.ProcessTransactionFees == 1 ? bTran.Amount - bTran.TransactionFeeAmount : bTran.Amount, Memo = DescriptionLava.ResolveMergeFields(mergeFields), LocationId = locationId, DepartmentId = departmentId, ProjectId = bTran.Project, ClassId = classId, CustomFields = customDimensionValues }; otherReceipt.ReceiptItems.Add(receiptItem); if (bTran.ProcessTransactionFees == 2) { var feeLineItem = new ReceiptLineItem { GlAccountNo = bTran.TransactionFeeAccount, Amount = bTran.TransactionFeeAmount * -1, Memo = "Transaction Fees", LocationId = locationId, DepartmentId = departmentId, ProjectId = bTran.Project, ClassId = classId }; otherReceipt.ReceiptItems.Add(feeLineItem); } } return(otherReceipt); }