Ejemplo n.º 1
0
            /// <summary>
            /// Converts the transaction service result XML into the SaleInvoice object.
            /// </summary>
            /// <param name="xmlInvoice">The XML representing the SaleInvoice.</param>
            /// <returns>SaleInvoice array.</returns>
            /// <exception cref="XmlException">Thrown when xmlInvoice does not represent a valid XML text.</exception>
            private static List <SalesInvoice> ConvertXmlToSaleInvoice(string xmlInvoice)
            {
                List <SalesInvoice> invoices    = new List <SalesInvoice>();
                SalesInvoice        invoice     = null;
                SalesInvoiceLine    invoiceLine = null;
                XDocument           doc         = null;

                if (!string.IsNullOrWhiteSpace(xmlInvoice))
                {
                    doc = XDocument.Parse(xmlInvoice);

                    if (doc != null && doc.Root != null)
                    {
                        foreach (XElement header in doc.Descendants("CustInvoiceJour"))
                        {
                            invoice                  = new SalesInvoice();
                            invoice.RecordId         = long.Parse(header.Attribute("RecId").Value);
                            invoice.Id               = header.Attribute("InvoiceId").Value;
                            invoice.SalesId          = header.Attribute("SalesId").Value;
                            invoice.SalesType        = (SalesInvoiceType)int.Parse(header.Attribute("SalesType").Value);
                            invoice.InvoiceDate      = Utilities.ParseDateString(header.Attribute("InvoiceDate").Value, DateTime.UtcNow, DateTimeStyles.AssumeUniversal);
                            invoice.CurrencyCode     = header.Attribute("CurrencyCode").Value;
                            invoice.Amount           = decimal.Parse(header.Attribute("InvoiceAmount").Value);
                            invoice.Account          = header.Attribute("InvoiceAccount").Value;
                            invoice.Name             = header.Attribute("InvoicingName").Value;
                            invoice.SalesInvoiceLine = new List <SalesInvoiceLine>();
                            foreach (XElement detail in header.Elements("CustInvoiceTrans"))
                            {
                                invoiceLine                     = new SalesInvoiceLine();
                                invoiceLine.RecordId            = long.Parse(detail.Attribute("RecId").Value);
                                invoiceLine.ItemId              = detail.Attribute("ItemId").Value;
                                invoiceLine.ProductName         = detail.Attribute("EcoResProductName").Value;
                                invoiceLine.InventDimensionId   = detail.Attribute("InventDimId").Value;
                                invoiceLine.InventTransactionId = detail.Attribute("InventTransId").Value;
                                invoiceLine.Quantity            = decimal.Parse(detail.Attribute("Qty").Value);
                                invoiceLine.Price               = decimal.Parse(detail.Attribute("SalesPrice").Value);
                                invoiceLine.DiscountPercent     = decimal.Parse(detail.Attribute("DiscPercent").Value);
                                invoiceLine.DiscountAmount      = decimal.Parse(detail.Attribute("DiscAmount").Value);
                                invoiceLine.NetAmount           = decimal.Parse(detail.Attribute("LineAmount").Value);
                                invoiceLine.SalesMarkup         = decimal.Parse(detail.Attribute("SalesMarkup").Value);
                                invoiceLine.SalesTaxGroup       = detail.Attribute("TaxGroup").Value;
                                invoiceLine.ItemTaxGroup        = detail.Attribute("TaxItemGroup").Value;
                                invoiceLine.BatchId             = detail.Attribute("InventBatchId").Value;
                                invoiceLine.Site                = detail.Attribute("InventSiteId").Value;
                                invoiceLine.Warehouse           = detail.Attribute("InventLocationId").Value;
                                invoiceLine.SerialId            = detail.Attribute("InventSerialId").Value;

                                // Dimension details
                                invoiceLine.ColorId    = InvoiceHelper.GetAttribute(detail, "InventColorId");
                                invoiceLine.ColorName  = InvoiceHelper.GetAttribute(detail, "InventColorName");
                                invoiceLine.SizeId     = InvoiceHelper.GetAttribute(detail, "InventSizeId");
                                invoiceLine.SizeName   = InvoiceHelper.GetAttribute(detail, "InventSizeName");
                                invoiceLine.StyleId    = InvoiceHelper.GetAttribute(detail, "InventStyleId");
                                invoiceLine.StyleName  = InvoiceHelper.GetAttribute(detail, "InventStyleName");
                                invoiceLine.ConfigId   = InvoiceHelper.GetAttribute(detail, "ConfigId");
                                invoiceLine.ConfigName = InvoiceHelper.GetAttribute(detail, "ConfigName");
                                invoice.SalesInvoiceLine.Add(invoiceLine);
                            }

                            invoices.Add(invoice);
                        }
                    }
                }

                return(invoices);
            }