/// <summary>
        /// Creates the XML to submit to Intacct for a new Other Receipt entry.
        /// </summary>
        /// <param name="AuthCreds">The IntacctAuth object with authentication. <see cref="IntacctAuth"/></param>
        /// <param name="Batch">The Rock FinancialBatch that a Journal Entry will be created from. <see cref="FinancialBatch"/></param>
        /// <returns>Returns the XML needed to create an Intacct Other Receipt.</returns>
        public XmlDocument CreateOtherReceiptXML(IntacctAuth AuthCreds, int BatchId, ref string debugLava, PaymentMethod paymentMethod, string bankAccountId = null, string unDepGLAccountId = null, string DescriptionLava = "")
        {
            var doc            = new XmlDocument();
            var financialBatch = new FinancialBatchService(new RockContext()).Get(BatchId);

            if (financialBatch.Id > 0)
            {
                var otherReceipt = BuildOtherReceipt(financialBatch, ref debugLava, paymentMethod, bankAccountId, unDepGLAccountId, DescriptionLava);
                if (otherReceipt.ReceiptItems.Any())
                {
                    using (var writer = doc.CreateNavigator().AppendChild())
                    {
                        writer.WriteStartDocument();
                        writer.WriteStartElement("request");
                        writer.WriteStartElement("control");
                        writer.WriteElementString("senderid", AuthCreds.SenderId);
                        writer.WriteElementString("password", AuthCreds.SenderPassword);
                        writer.WriteElementString("controlid", $"RequestControl_{financialBatch.Id}");
                        writer.WriteElementString("uniqueid", "false");
                        writer.WriteElementString("dtdversion", "3.0");
                        writer.WriteElementString("includewhitespace", "false");
                        writer.WriteEndElement();  // close control
                        writer.WriteStartElement("operation");
                        writer.WriteStartElement("authentication");
                        writer.WriteStartElement("login");
                        writer.WriteElementString("userid", AuthCreds.UserId);
                        writer.WriteElementString("companyid", AuthCreds.CompanyId);
                        writer.WriteElementString("password", AuthCreds.UserPassword);
                        if (!string.IsNullOrWhiteSpace(AuthCreds.LocationId))
                        {
                            writer.WriteElementString("locationid", AuthCreds.LocationId);
                        }
                        writer.WriteEndElement();  // close login
                        writer.WriteEndElement();  // close authentication
                        writer.WriteStartElement("content");
                        writer.WriteStartElement("function");
                        writer.WriteAttributeString("controlid", $"Batch_{financialBatch.Id}");
                        writer.WriteStartElement("record_otherreceipt");
                        writer.WriteStartElement("paymentdate");
                        writer.WriteElementString("year", otherReceipt.PaymentDate.Year.ToString());
                        writer.WriteElementString("month", otherReceipt.PaymentDate.Month.ToString());
                        writer.WriteElementString("day", otherReceipt.PaymentDate.Day.ToString());
                        writer.WriteEndElement();  // close paymentdate
                        writer.WriteElementString("payee", otherReceipt.Payer);
                        writer.WriteStartElement("receiveddate");
                        writer.WriteElementString("year", otherReceipt.ReceivedDate.Year.ToString());
                        writer.WriteElementString("month", otherReceipt.ReceivedDate.Month.ToString());
                        writer.WriteElementString("day", otherReceipt.ReceivedDate.Day.ToString());
                        writer.WriteEndElement();  // close receiveddate
                        writer.WriteElementString("paymentmethod", otherReceipt.PaymentMethod.GetDescription());
                        if (!string.IsNullOrWhiteSpace(otherReceipt.BankAccountId))
                        {
                            writer.WriteElementString("bankaccountid", otherReceipt.BankAccountId);
                            writer.WriteStartElement("depositdate");
                            writer.WriteElementString("year", otherReceipt.DepositDate.Value.Year.ToString());
                            writer.WriteElementString("month", otherReceipt.DepositDate.Value.Month.ToString());
                            writer.WriteElementString("day", otherReceipt.DepositDate.Value.Day.ToString());
                            writer.WriteEndElement();  // close depositdate
                        }
                        else if (!string.IsNullOrWhiteSpace(otherReceipt.UnDepGLAccountNo))
                        {
                            writer.WriteElementString("undepglaccountno", otherReceipt.UnDepGLAccountNo);
                        }
                        if (!string.IsNullOrWhiteSpace(otherReceipt.RefId))
                        {
                            writer.WriteElementString("refid", otherReceipt.RefId);
                        }
                        writer.WriteElementString("description", otherReceipt.Description);
                        if (!string.IsNullOrWhiteSpace(otherReceipt.Currency))
                        {
                            writer.WriteElementString("currency", otherReceipt.Currency);
                        }
                        if (otherReceipt.ExchRateDate.HasValue)
                        {
                            writer.WriteElementString("exchratedate", (( DateTime )otherReceipt.ExchRateDate).ToShortDateString());
                        }
                        if (!string.IsNullOrWhiteSpace(otherReceipt.ExchRateType))
                        {
                            writer.WriteElementString("exchratetype", otherReceipt.ExchRateType);
                        }
                        else if (otherReceipt.ExchRate.HasValue)
                        {
                            writer.WriteElementString("exchrate", otherReceipt.ExchRate.Value.ToString());
                        }
                        else if (!string.IsNullOrWhiteSpace(otherReceipt.Currency))
                        {
                            writer.WriteElementString("exchratetype", otherReceipt.ExchRateType);
                        }
                        writer.WriteStartElement("receiptitems");

                        // Add Receipt Items
                        foreach (var item in otherReceipt.ReceiptItems)
                        {
                            writer.WriteStartElement("lineitem");
                            writer.WriteElementString("glaccountno", item.GlAccountNo ?? string.Empty);
                            writer.WriteElementString("amount", item.Amount.ToString());
                            writer.WriteElementString("memo", item.Memo ?? string.Empty);
                            writer.WriteElementString("locationid", item.LocationId ?? string.Empty);
                            writer.WriteElementString("departmentid", item.DepartmentId ?? string.Empty);
                            if (!string.IsNullOrWhiteSpace(item.ProjectId))
                            {
                                writer.WriteElementString("projectid", item.ProjectId);
                            }
                            if (!string.IsNullOrWhiteSpace(item.TaskId))
                            {
                                writer.WriteElementString("taskid", item.TaskId);
                            }
                            if (!string.IsNullOrWhiteSpace(item.CustomerId))
                            {
                                writer.WriteElementString("customerid", item.CustomerId);
                            }
                            if (!string.IsNullOrWhiteSpace(item.VendorId))
                            {
                                writer.WriteElementString("vendorid", item.VendorId);
                            }
                            if (!string.IsNullOrWhiteSpace(item.EmployeeId))
                            {
                                writer.WriteElementString("employeeid", item.EmployeeId);
                            }
                            if (!string.IsNullOrWhiteSpace(item.ItemId))
                            {
                                writer.WriteElementString("itemid", item.ItemId);
                            }
                            if (!string.IsNullOrWhiteSpace(item.ClassId))
                            {
                                writer.WriteElementString("classid", item.ClassId);
                            }
                            if (item.CustomFields.Count > 0)
                            {
                                foreach (KeyValuePair <string, dynamic> customField in item.CustomFields)
                                {
                                    writer.WriteElementString(customField.Key, customField.Value ?? string.Empty);
                                }
                            }
                            writer.WriteEndElement();  // close lineitem
                        }

                        writer.WriteEndElement();  // close receiptitems
                        writer.WriteEndElement();  // close record_otherreceipt
                        writer.WriteEndElement();  // close function
                        writer.WriteEndElement();  // close content
                        writer.WriteEndElement();  // close operation
                        writer.WriteEndElement();  // close request
                        writer.WriteEndDocument(); // close document
                    }
                }
            }

            XmlDeclaration xmldecl;

            xmldecl            = doc.CreateXmlDeclaration("1.0", null, null);
            xmldecl.Encoding   = "UTF-8";
            xmldecl.Standalone = "yes";

            XmlElement root = doc.DocumentElement;

            doc.InsertBefore(xmldecl, root);

            return(doc);
        }
예제 #2
0
        /// <summary>
        /// Creates the XML to submit to Intacct to capture a list of Bank Accounts
        /// </summary>
        /// <param name="AuthCreds">The IntacctAuth object with authentication. <see cref="IntacctAuth"/></param>
        /// <returns>Returns the XML needed to request a list of Bank Accounts.</returns>
        public XmlDocument GetBankAccountsXML(IntacctAuth AuthCreds, int batchId, List <string> fields = null)
        {
            var doc = new XmlDocument();

            using (var writer = doc.CreateNavigator().AppendChild())
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("request");
                writer.WriteStartElement("control");
                writer.WriteElementString("senderid", AuthCreds.SenderId);
                writer.WriteElementString("password", AuthCreds.SenderPassword);
                writer.WriteElementString("controlid", $"RequestControl_{batchId}");
                writer.WriteElementString("uniqueid", "false");
                writer.WriteElementString("dtdversion", "3.0");
                writer.WriteElementString("includewhitespace", "false");
                writer.WriteEndElement();  // close control
                writer.WriteStartElement("operation");
                writer.WriteStartElement("authentication");
                writer.WriteStartElement("login");
                writer.WriteElementString("userid", AuthCreds.UserId);
                writer.WriteElementString("companyid", AuthCreds.CompanyId);
                writer.WriteElementString("password", AuthCreds.UserPassword);
                if (!string.IsNullOrWhiteSpace(AuthCreds.LocationId))
                {
                    writer.WriteElementString("locationid", AuthCreds.LocationId);
                }
                writer.WriteEndElement();  // close login
                writer.WriteEndElement();  // close authentication
                writer.WriteStartElement("content");
                writer.WriteStartElement("function");
                writer.WriteAttributeString("controlid", $"Batch_{batchId}");
                writer.WriteStartElement("readByQuery");
                writer.WriteElementString("object", "CHECKINGACCOUNT");
                if (fields == null)
                {
                    writer.WriteElementString("fields", "*");
                }
                else
                {
                    var fieldsString = string.Join(",", fields.Select(f => f.Trim()));
                    writer.WriteElementString("fields", fieldsString);
                }
                writer.WriteElementString("query", null);
                writer.WriteEndElement();  // close readByQuery
                writer.WriteEndElement();  // close function
                writer.WriteEndElement();  // close content
                writer.WriteEndElement();  // close operation
                writer.WriteEndElement();  // close request
                writer.WriteEndDocument(); // close document
            }

            XmlDeclaration xmldecl;

            xmldecl            = doc.CreateXmlDeclaration("1.0", null, null);
            xmldecl.Encoding   = "UTF-8";
            xmldecl.Standalone = "yes";

            XmlElement root = doc.DocumentElement;

            doc.InsertBefore(xmldecl, root);

            return(doc);
        }
예제 #3
0
        /// <summary>
        /// Creates the XML to submit to Intacct for a new Journal
        /// </summary>
        /// <param name="AuthCreds">The IntacctAuth object with authentication. <see cref="IntacctAuth"/></param>
        /// <param name="Batch">The Rock FinancialBatch that a Journal Entry will be created from. <see cref="FinancialBatch"/></param>
        /// <param name="JournalId">The Intacct Symbol of the Journal that the Entry should be posted to. For example: GJ</param>
        /// <returns>Returns the XML needed to create an Intacct Journal Entry.</returns>
        public XmlDocument CreateJournalEntryXML(IntacctAuth AuthCreds, int BatchId, string JournalId, ref string debugLava, string DescriptionLava = "")
        {
            var doc            = new XmlDocument();
            var financialBatch = new FinancialBatchService(new RockContext()).Get(BatchId);

            if (financialBatch.Id > 0)
            {
                var lines = GetGlEntries(financialBatch, ref debugLava, DescriptionLava);
                if (lines.Any())
                {
                    var batchDate = financialBatch.BatchStartDateTime == null?RockDateTime.Now.ToShortDateString() : ((System.DateTime)financialBatch.BatchStartDateTime).ToShortDateString();

                    using (var writer = doc.CreateNavigator().AppendChild())
                    {
                        writer.WriteStartDocument();
                        writer.WriteStartElement("request");
                        writer.WriteStartElement("control");
                        writer.WriteElementString("senderid", AuthCreds.SenderId);
                        writer.WriteElementString("password", AuthCreds.SenderPassword);
                        writer.WriteElementString("controlid", $"RequestControl_{financialBatch.Id}");
                        writer.WriteElementString("uniqueid", "false");
                        writer.WriteElementString("dtdversion", "3.0");
                        writer.WriteElementString("includewhitespace", "false");
                        writer.WriteEndElement();  // close control
                        writer.WriteStartElement("operation");
                        writer.WriteStartElement("authentication");
                        writer.WriteStartElement("login");
                        writer.WriteElementString("userid", AuthCreds.UserId);
                        writer.WriteElementString("companyid", AuthCreds.CompanyId);
                        writer.WriteElementString("password", AuthCreds.UserPassword);
                        if (!string.IsNullOrWhiteSpace(AuthCreds.LocationId))
                        {
                            writer.WriteElementString("locationid", AuthCreds.LocationId);
                        }
                        writer.WriteEndElement();  // close login
                        writer.WriteEndElement();  // close authentication
                        writer.WriteStartElement("content");
                        writer.WriteStartElement("function");
                        writer.WriteAttributeString("controlid", $"Batch_{financialBatch.Id}");
                        writer.WriteStartElement("create");
                        writer.WriteStartElement("GLBATCH");
                        writer.WriteElementString("JOURNAL", JournalId);
                        writer.WriteElementString("REFERENCENO", financialBatch.Id.ToString());
                        writer.WriteElementString("BATCH_DATE", batchDate);
                        writer.WriteElementString("BATCH_TITLE", financialBatch.Name);
                        writer.WriteElementString("HISTORY_COMMENT", "Imported from RockRMS");
                        writer.WriteStartElement("ENTRIES");

                        if (lines.Count > 0)
                        {
                            foreach (var line in lines)
                            {
                                writer.WriteStartElement("GLENTRY");
                                writer.WriteElementString("DOCUMENT", line.DocumentNumber ?? string.Empty);
                                writer.WriteElementString("ACCOUNTNO", line.GlAccountNumber ?? string.Empty);
                                decimal?transactionAmount = line.TransactionAmount;
                                decimal num = new decimal();
                                if ((transactionAmount.GetValueOrDefault() < num ? !transactionAmount.HasValue : true))
                                {
                                    writer.WriteElementString("TR_TYPE", "1");
                                    writer.WriteElementString("TRX_AMOUNT", line.TransactionAmount.ToString());
                                }
                                else
                                {
                                    writer.WriteElementString("TR_TYPE", "-1");
                                    writer.WriteElementString("TRX_AMOUNT", new decimal?(Math.Abs(line.TransactionAmount.Value)).ToString());
                                }
                                writer.WriteElementString("CURRENCY", line.TransactionCurrency ?? string.Empty);
                                if (line.ExchangeRateDate.HasValue)
                                {
                                    writer.WriteElementString("EXCH_RATE_DATE", (( DateTime )line.ExchangeRateDate).ToShortDateString());
                                }
                                if (!string.IsNullOrWhiteSpace(line.ExchangeRateType))
                                {
                                    writer.WriteElementString("EXCH_RATE_TYPE_ID", line.ExchangeRateType);
                                }
                                else if (line.ExchangeRateValue.HasValue)
                                {
                                    writer.WriteElementString("EXCHANGE_RATE", line.ExchangeRateValue.ToString());
                                }
                                else if (!string.IsNullOrWhiteSpace(line.TransactionCurrency))
                                {
                                    writer.WriteElementString("EXCH_RATE_TYPE_ID", line.ExchangeRateType);
                                }
                                if (string.IsNullOrWhiteSpace(line.AllocationId))
                                {
                                    writer.WriteElementString("LOCATION", line.LocationId ?? string.Empty);
                                    writer.WriteElementString("DEPARTMENT", line.DepartmentId ?? string.Empty);
                                    writer.WriteElementString("PROJECTID", line.ProjectId ?? string.Empty);
                                    writer.WriteElementString("CUSTOMERID", line.CustomerId ?? string.Empty);
                                    writer.WriteElementString("VENDORID", line.VendorId ?? string.Empty);
                                    writer.WriteElementString("EMPLOYEEID", line.EmployeeId ?? string.Empty);
                                    writer.WriteElementString("ITEMID", line.ItemId ?? string.Empty);
                                    writer.WriteElementString("CLASSID", line.ClassId ?? string.Empty);
                                    writer.WriteElementString("CONTRACTID", line.ContractId ?? string.Empty);
                                    writer.WriteElementString("WAREHOUSEID", line.WarehouseId ?? string.Empty);
                                }
                                else
                                {
                                    writer.WriteElementString("ALLOCATION", line.AllocationId);
                                    if (line.AllocationId == "Custom")
                                    {
                                        foreach (var split in line.CustomAllocationSplits)
                                        {
                                            writer.WriteStartElement("SPLIT");
                                            writer.WriteElementString("AMOUNT", split.Amount.ToString());
                                            writer.WriteElementString("LOCATIONID", split.LocationId ?? string.Empty);
                                            writer.WriteElementString("DEPARTMENTID", split.DepartmentId ?? string.Empty);
                                            writer.WriteElementString("PROJECTID", split.ProjectId ?? string.Empty);
                                            writer.WriteElementString("CUSTOMERID", split.CustomerId ?? string.Empty);
                                            writer.WriteElementString("VENDORID", split.VendorId ?? string.Empty);
                                            writer.WriteElementString("EMPLOYEEID", split.EmployeeId ?? string.Empty);
                                            writer.WriteElementString("ITEMID", split.ItemId ?? string.Empty);
                                            writer.WriteElementString("CLASSID", split.ClassId ?? string.Empty);
                                            writer.WriteElementString("CONTRACTID", split.ContractId ?? string.Empty);
                                            writer.WriteElementString("WAREHOUSEID", split.WarehouseId ?? string.Empty);
                                            writer.WriteEndElement();
                                        }
                                    }
                                }
                                writer.WriteElementString("DESCRIPTION", line.Memo);
                                if (line.CustomFields.Count > 0)
                                {
                                    foreach (KeyValuePair <string, dynamic> customField in line.CustomFields)
                                    {
                                        writer.WriteElementString(customField.Key, customField.Value ?? string.Empty);
                                    }
                                }
                                writer.WriteEndElement();
                            }
                        }

                        writer.WriteEndElement();  // close ENTRIES
                        writer.WriteEndElement();  // close GLBATCH
                        writer.WriteEndElement();  // close create
                        writer.WriteEndElement();  // close function
                        writer.WriteEndElement();  // close content
                        writer.WriteEndElement();  // close operation
                        writer.WriteEndElement();  // close request
                        writer.WriteEndDocument(); // close document
                    }
                }
            }

            XmlDeclaration xmldecl;

            xmldecl            = doc.CreateXmlDeclaration("1.0", null, null);
            xmldecl.Encoding   = "UTF-8";
            xmldecl.Standalone = "yes";

            XmlElement root = doc.DocumentElement;

            doc.InsertBefore(xmldecl, root);

            return(doc);
        }