Пример #1
0
        public static void ProcessFailedOrder(Order order)
        {
            var rep = new Repository();
            var failure = new FailedOrder()
            {
                Imported = false,
                OrderID = order.OrderID,
                DateAdded = DateTime.Now,
                ClientID = rep.GetUser(WebSecurity.CurrentUserId).ClientID ?? 0
            };
            order.Reported = true;
            rep.Add(failure);
            rep.Save();

            var hostUrl = HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
            hostUrl = "http://quickbooks.infomedia.com";
            var importUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/Unprocessed-Invoices");
            var modifyUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/Inventory");
            var body = new System.Text.StringBuilder();
            body.AppendLine("Someone has made a purchase on your website which was not possible to import through the Web Connector and is ready for manual import.");
            body.AppendLine("Please view the order that failed and create the invoice manually here: " + importUrl);
            body.AppendLine(order.Receipt);
            var user = rep.GetUser(WebSecurity.CurrentUserId);
            var email = user.Client.EmailRecipient != null ? user.Client.EmailRecipient : WebSecurity.CurrentUserName;
            WebMail.Send(email, "Quickbooks Web Connector Failed Invoice Attempt", body.ToString(), cc: "*****@*****.**", isBodyHtml: false);
        }
Пример #2
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;
        }
Пример #3
0
		private void detach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.Client = null;
		}
Пример #4
0
		private void attach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.Client = this;
		}
Пример #5
0
 partial void DeleteOrder(Order instance);
Пример #6
0
 partial void UpdateOrder(Order instance);
Пример #7
0
 partial void InsertOrder(Order instance);
Пример #8
0
		private void detach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.Transaction = null;
		}