예제 #1
0
        public XDocument GetInvoice(int customerID, int orderID)
        {
            customer = rep.GetCustomer(customerID);
            order =		rep.GetQuickBooksOrder(false, orderID);
            requestID = order.RequestID;
            List<KeyValuePair<int,string>> orderLineItem_itemNames = new List<KeyValuePair<int,string>>();
            var lineItems = rep.GetOrderLineItems(orderID);
            foreach (var item in lineItems)
            {
                var shopItem = rep.GetShopInventoryItems(order.ClientID).Where(i => i.Name == item.InventoryName).FirstOrDefault();
                if (shopItem == null)
                {
                    if (order.Client.IsContentEditsShop ?? false)
                    {
                        WebShopInventory.GetCeInventory(rep.GetUser(order.Client.webpages_Memberships.FirstOrDefault().UserID));
                        shopItem = rep.GetShopInventoryItems(order.ClientID).Where(i => i.Name == item.InventoryName).FirstOrDefault();
                    }
                }
                var exists =  shopItem != null && shopItem.QuickbooksInventoryID != null;
                if (!exists)
                {
                    var qbItem = rep.GetQuickbooksInventoryItem(item.InventoryName,order.ClientID);
                    if (qbItem != null && shopItem != null)
                    {
                        shopItem.QuickbooksInventoryID = qbItem.QuickbooksInventoryID;
                        rep.Save();
                        orderLineItem_itemNames.Add(new KeyValuePair<int, string>(item.LineItemID, qbItem.FullName));
                    }
                    else
                    {
                        itemsExist = false;
                        missingInventoryItem = item.InventoryName;
                    }
                }
                else
                {
                    orderLineItem_itemNames.Add(new KeyValuePair<int,string>(item.LineItemID,shopItem.QuickbooksInventory.FullName));
                }
            }
            if (itemsExist)
            {
                doc = new XDocument(
                    new XDeclaration("1.0", "utf-8", null),
                    new XProcessingInstruction("qbxml", "version=\"6.0\""),
                    new XElement("QBXML",
                        new XElement("QBXMLMsgsRq", new XAttribute("onError", "stopOnError"),
                            new XElement("InvoiceAddRq",
                                new XAttribute("requestID", requestID),
                                new XElement("InvoiceAdd",
                                    new XElement("CustomerRef",
                                        new XElement("FullName", Name)),
                                    new XElement("TxnDate", String.Format("{0:yyyy-MM-dd}", DateTime.Now)),
                                    new XElement("BillAddress",
                                        new XElement("Addr1", FirstName + " " + LastName),
                                        new XElement("Addr2", BillAddress1),
                                        new XElement("Addr3", BillAddress2),
                                        new XElement("City", BillCity),
                                        new XElement("State", BillState),
                                        new XElement("PostalCode", BillPostalCode),
                                        new XElement("Country", BillCountry)),
                                    new XElement("ShipAddress",
                                        new XElement("Addr1", S_firstname + " " + S_lastname),
                                        new XElement("Addr2", ShipAddress1),
                                        new XElement("Addr3", ShipAddress2),
                                        new XElement("City", ShipCity),
                                        new XElement("State", ShipState),
                                        new XElement("PostalCode", ShipPostalCode),
                                        new XElement("Country", ShipCountry)),
                                    new XElement("ItemSalesTaxRef",
                                        new XElement("FullName", TaxFullName)
                                    )
                                )
                            )
                        )
                    )
                );
                var customerNode = doc.LastNode.Document.Descendants().Where(n => n.Name == "CustomerRef").SingleOrDefault();
                var salesTaxNode = doc.LastNode.Document.Descendants().Where(n => n.Name == "ItemSalesTaxRef").SingleOrDefault();

                foreach (var item in lineItems)
                {
                    (lastLineItemNode == null ? salesTaxNode : lastLineItemNode).AddAfterSelf(
                        new XElement("InvoiceLineAdd",
                            new XElement("ItemRef",
                                new XElement("FullName", orderLineItem_itemNames.Where(o => o.Key == item.LineItemID).FirstOrDefault().Value)),//Mapped Value from Quickbooks Inventory//item.InventoryName)),
                            new XElement("Desc", item.FullDescription),
                            new XElement("Quantity", item == null ? 1 : item.Quantity),
                            new XElement("Rate", ((decimal)item.PriceEach).ToString("N2")),
                            new XElement("Amount", ((decimal)(item.Quantity * item.PriceEach)).ToString("N2"))
                        )
                    );
                }

                if (ClassRef != null && ClassRef != String.Empty)
                {
                    customerNode.AddAfterSelf(
                        new XElement("ClassRef",
                                new XElement("FullName", ClassRef)
                        )
                    );
                }
                if (TemplateRef != null && TemplateRef != String.Empty)
                {
                    var element = doc.LastNode.Document.Descendants().Where(n => n.Name == "ClassRef").SingleOrDefault() == null ? customerNode : doc.LastNode.Document.Descendants().Where(n => n.Name == "ClassRef").SingleOrDefault();
                    element.AddAfterSelf(
                        new XElement("TemplateRef",
                                new XElement("FullName", TemplateRef)
                        )
                    );
                }

                lastLineItemNode.AddAfterSelf(
                        new XElement("InvoiceLineAdd",
                            new XElement("ItemRef",
                                new XElement("FullName", ShippingFullName)),
                            new XElement("Desc", "Shipping"),
                            new XElement("Amount", Shipping)
                            )
                        );
            }
            else //Query Quickbooks to see if the inventory Item Exists
            {
                doc = Inventory.ItemQuery(requestID, missingInventoryItem);
            }
            order.RequestXML = doc.ToString();
            rep.Save();
            return doc;
        }
예제 #2
0
		private void detach_Customers(Customer entity)
		{
			this.SendPropertyChanging();
			entity.Transaction = null;
		}
예제 #3
0
 partial void DeleteCustomer(Customer instance);
예제 #4
0
 partial void UpdateCustomer(Customer instance);
예제 #5
0
 partial void InsertCustomer(Customer instance);
예제 #6
0
        public XDocument GetCustomer(int customerID,int orderID)
        {
            _orderID = orderID;
            shopper = rep.GetCustomer(customerID);
            //order = rep.GetShopperOrder(shopper.id);
            XDocument doc = new XDocument(
                new XDeclaration("1.0", "utf-8",null),
                new XProcessingInstruction("qbxml","version=\"9.0\""),
                new XElement("QBXML",
                    new XElement("QBXMLMsgsRq",new XAttribute("onError","stopOnError"),
                        new XElement("CustomerAddRq",
                            new XElement("CustomerAdd",
                                new XElement("Name",Name),
                                new XElement("IsActive",1),
                                new XElement("FirstName",FirstName),
                                new XElement("LastName",LastName),
                                new XElement("BillAddress",
                                    new XElement("Addr1",BillAddress1),
                                    new XElement("Addr2",BillAddress2),
                                    new XElement("City",BillCity),
                                    new XElement("State",BillState),
                                    new XElement("PostalCode",BillPostalCode),
                                    new XElement("Country",BillCountry)),
                                new XElement("ShipAddress",
                                    new XElement("Addr1",ShipAddress1),
                                    new XElement("Addr2",ShipAddress2),
                                    new XElement("City",ShipCity),
                                    new XElement("State",ShipState),
                                    new XElement("PostalCode",ShipPostalCode),
                                    new XElement("Country",ShipCountry)),
                                new XElement("Phone",Phone),
                                new XElement("Email",Email)

                            )
                        )
                    )
                )
            );
            if(!String.IsNullOrEmpty(AltContact))
            {
                doc.Root.Descendants("Email").FirstOrDefault().AddAfterSelf(
                    new XElement("AltContact",AltContact)
                );
            }
            return doc;
        }