private string buildInvoiceAddRqXML(InvoiceData inv) { string requestXML = ""; //if (!validateInput()) return null; //GET ALL INPUT INTO XML XmlDocument xmlDoc = new XmlDocument(); XmlElement qbXMLMsgsRq = buildRqEnvelope(xmlDoc, maxVersion); qbXMLMsgsRq.SetAttribute("onError", "stopOnError"); XmlElement InvoiceAddRq = xmlDoc.CreateElement("InvoiceAddRq"); qbXMLMsgsRq.AppendChild(InvoiceAddRq); XmlElement InvoiceAdd = xmlDoc.CreateElement("InvoiceAdd"); InvoiceAddRq.AppendChild(InvoiceAdd); // CustomerRef -> FullName if (inv.CustomerFullName != "") { XmlElement Element_CustomerRef = xmlDoc.CreateElement("CustomerRef"); InvoiceAdd.AppendChild(Element_CustomerRef); XmlElement Element_CustomerRef_FullName = xmlDoc.CreateElement("FullName"); Element_CustomerRef.AppendChild(Element_CustomerRef_FullName).InnerText = inv.CustomerFullName; } // TxnDate DateTime DT_TxnDate = System.DateTime.Today; if (inv.InvDate != "") { XmlElement Element_TxnDate = xmlDoc.CreateElement("TxnDate"); InvoiceAdd.AppendChild(Element_TxnDate).InnerText = inv.InvDate; } // RefNumber if (inv.InvNo != "") { XmlElement Element_RefNumber = xmlDoc.CreateElement("RefNumber"); InvoiceAdd.AppendChild(Element_RefNumber).InnerText = inv.InvNo; } // BillAddress if (inv.BillTo != "") { string[] BillAddress = inv.BillTo.Split('\n'); XmlElement Element_BillAddress = xmlDoc.CreateElement("BillAddress"); InvoiceAdd.AppendChild(Element_BillAddress); for (int i = 0; i < BillAddress.Length; i++) { if (BillAddress[i] != "" || BillAddress[i] != null) { XmlElement Element_Addr = xmlDoc.CreateElement("Addr" + (i + 1)); Element_BillAddress.AppendChild(Element_Addr).InnerText = BillAddress[i]; } } } // TermsRef -> FullName bool termsAvailable = false; if (inv.Term != "") { termsAvailable = true; XmlElement Element_TermsRef = xmlDoc.CreateElement("TermsRef"); InvoiceAdd.AppendChild(Element_TermsRef); XmlElement Element_TermsRef_FullName = xmlDoc.CreateElement("FullName"); Element_TermsRef.AppendChild(Element_TermsRef_FullName).InnerText = inv.Term; } // DueDate if (termsAvailable) { DateTime DT_DueDate = System.DateTime.Today; double dueInDays = getDueInDays(inv.InvDate); DT_DueDate = DT_TxnDate.AddDays(dueInDays); string DueDate = getDateString(DT_DueDate); XmlElement Element_DueDate = xmlDoc.CreateElement("DueDate"); InvoiceAdd.AppendChild(Element_DueDate).InnerText = DueDate; } // CustomerMsgRef -> FullName if (inv.CustomerMessage != "") { XmlElement Element_CustomerMsgRef = xmlDoc.CreateElement("CustomerMsgRef"); InvoiceAdd.AppendChild(Element_CustomerMsgRef); XmlElement Element_CustomerMsgRef_FullName = xmlDoc.CreateElement("FullName"); Element_CustomerMsgRef.AppendChild(Element_CustomerMsgRef_FullName).InnerText = inv.CustomerMessage; } // ExchangeRate if (inv.ExchangeRate != "") { XmlElement Element_ExchangeRate = xmlDoc.CreateElement("ExchangeRate"); InvoiceAdd.AppendChild(Element_ExchangeRate).InnerText = inv.ExchangeRate; } //Line Items XmlElement Element_InvoiceLineAdd; foreach (InvoiceRow r in inv.Rows) { for (int x = 1; x < 6; x++) { Element_InvoiceLineAdd = xmlDoc.CreateElement("InvoiceLineAdd"); InvoiceAdd.AppendChild(Element_InvoiceLineAdd); if (r.ItemRef != "") { XmlElement Element_InvoiceLineAdd_ItemRef = xmlDoc.CreateElement("ItemRef"); Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_ItemRef); XmlElement Element_InvoiceLineAdd_ItemRef_FullName = xmlDoc.CreateElement("FullName"); Element_InvoiceLineAdd_ItemRef.AppendChild(Element_InvoiceLineAdd_ItemRef_FullName).InnerText = r.ItemRef; } if (r.Desc != "") { XmlElement Element_InvoiceLineAdd_Desc = xmlDoc.CreateElement("Desc"); Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Desc).InnerText = r.Desc; } if (r.Quantity != "") { XmlElement Element_InvoiceLineAdd_Quantity = xmlDoc.CreateElement("Quantity"); Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Quantity).InnerText = r.Quantity; } if (r.Rate != "") { XmlElement Element_InvoiceLineAdd_Rate = xmlDoc.CreateElement("Rate"); Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Rate).InnerText = r.Rate; } if (r.Amount != "") { XmlElement Element_InvoiceLineAdd_Amount = xmlDoc.CreateElement("Amount"); Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Amount).InnerText = r.Amount; } } } InvoiceAddRq.SetAttribute("requestID", "99"); requestXML = xmlDoc.OuterXml; return(requestXML); }
public string buildInvoiceAddRqXML(string CustomerRef, string ARAccountRef, string TxDate, string RefNo, string InvLineRef, string InvLineDesc, string InvLineQuantity, string InvLineAmt) { string requestXML = ""; //GET ALL INPUT INTO XML XmlDocument xmlDoc = new XmlDocument(); XmlElement qbXMLMsgsRq = buildRqEnvelope(xmlDoc, maxVersion ?? "6.1"); qbXMLMsgsRq.SetAttribute("onError", "stopOnError"); XmlElement InvoiceAddRq = xmlDoc.CreateElement("InvoiceAddRq"); qbXMLMsgsRq.AppendChild(InvoiceAddRq); XmlElement InvoiceAdd = xmlDoc.CreateElement("InvoiceAdd"); InvoiceAddRq.AppendChild(InvoiceAdd); // CustomerRef -> FullName if (!string.IsNullOrEmpty(CustomerRef)) { XmlElement Element_CustomerRef = xmlDoc.CreateElement("CustomerRef"); InvoiceAdd.AppendChild(Element_CustomerRef); XmlElement Element_CustomerRef_FullName = xmlDoc.CreateElement("ListID"); Element_CustomerRef.AppendChild(Element_CustomerRef_FullName).InnerText = CustomerRef; } // AccountRef -> FullName if (!string.IsNullOrEmpty(ARAccountRef)) { XmlElement Element_AccountRef = xmlDoc.CreateElement("ARAccountRef"); InvoiceAdd.AppendChild(Element_AccountRef); XmlElement Element_AccountRef_FullName = xmlDoc.CreateElement("FullName"); Element_AccountRef.AppendChild(Element_AccountRef_FullName).InnerText = ARAccountRef; } // TxnDate DateTime DT_TxnDate = System.DateTime.Today; if (!string.IsNullOrEmpty(TxDate)) { DT_TxnDate = Convert.ToDateTime(TxDate); string TxnDate = getDateString(DT_TxnDate); XmlElement Element_TxnDate = xmlDoc.CreateElement("TxnDate"); InvoiceAdd.AppendChild(Element_TxnDate).InnerText = TxnDate; } // RefNumber if (!string.IsNullOrEmpty(RefNo)) { XmlElement Element_RefNumber = xmlDoc.CreateElement("RefNumber"); InvoiceAdd.AppendChild(Element_RefNumber).InnerText = RefNo; } //Invoice Line (REQUIRED) XmlElement Element_InvoiceLineAdd; Element_InvoiceLineAdd = xmlDoc.CreateElement("InvoiceLineAdd"); InvoiceAdd.AppendChild(Element_InvoiceLineAdd); if (!string.IsNullOrEmpty(InvLineRef)) { XmlElement Element_InvoiceLineAdd_ItemRef = xmlDoc.CreateElement("ItemRef"); Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_ItemRef); XmlElement Element_InvoiceLineAdd_ItemRef_FullName = xmlDoc.CreateElement("FullName"); Element_InvoiceLineAdd_ItemRef.AppendChild(Element_InvoiceLineAdd_ItemRef_FullName).InnerText = InvLineRef; } if (!string.IsNullOrEmpty(InvLineDesc)) { XmlElement Element_InvoiceLineAdd_Desc = xmlDoc.CreateElement("Desc"); Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Desc).InnerText = InvLineDesc; } if (!string.IsNullOrEmpty(InvLineQuantity)) { XmlElement Element_InvoiceLineAdd_Quantity = xmlDoc.CreateElement("Quantity"); Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Quantity).InnerText = InvLineQuantity; } if (!string.IsNullOrEmpty(InvLineAmt)) { XmlElement Element_InvoiceLineAdd_Amount = xmlDoc.CreateElement("Amount"); Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Amount).InnerText = InvLineAmt; } InvoiceAddRq.SetAttribute("requestID", "99"); requestXML = xmlDoc.OuterXml; return(requestXML); }