Exemple #1
0
        public static void ProcessFailedOrder(int requestID, string xmlMessage)
        {
            var rep = new Repository();
            var failure = new FailedOrder()
            {
                Imported = false,
                RequestID = requestID,
                OrderID = rep.GetQuickBooksOrderByRequestID(requestID).OrderID,
                DateAdded = DateTime.Now,
                ClientID = rep.GetUser(WebSecurity.CurrentUserId).ClientID ?? 0
            };

            var order = rep.GetQuickBooksOrderByRequestID(requestID);
            order.ResponseXML = xmlMessage;
            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("There was an error processing a website sale with Quickbooks");
            body.AppendLine("The most likely cause was that an item on the order was not found in your quickbooks inventory.");
            body.AppendLine("Please view the order that failed and create the invoice manually here: " + importUrl);
            body.AppendLine("You can modify your inventory naming schema here: " + modifyUrl);
            body.AppendLine(order.Receipt);
            body.AppendLine(xmlMessage);
            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);
        }
Exemple #2
0
        public static void ItemSalesTaxGroupQueryRs(string response)
        {
            var rep = new Repository();
            var client = rep.GetClient(rep.GetUser(WebSecurity.CurrentUserId).ClientID ?? 0);
            var db = Database.Open("Quickbooks");
            var taxCodes = XDocument.Parse(response).Document.Root.Descendants("QBXMLMsgsRs").Descendants("ItemSalesTaxGroupQueryRs").FirstOrDefault().Descendants("ItemSalesTaxGroupRet");
            var clientID = rep.GetUser(WebSecurity.CurrentUserId).ClientID;
            foreach (var item in taxCodes)
            {
                var taxCode = rep.GetSalesTaxCode(rep.GetUser(WebSecurity.CurrentUserId).ClientID ?? 0, item.Descendants("Name").FirstOrDefault().Value);
                var taxCodeExists = taxCode != null;
                var name = item.Descendants("Name").FirstOrDefault().Value;
                var listID = item.Descendants("ListID").FirstOrDefault().Value;
                decimal rate = 0;

                foreach(var rat in item.Descendants("ItemSalesTaxRef"))
                {
                    rate += rep.GetSalesTaxCode(clientID ?? 0,rat.Descendants("FullName").FirstOrDefault().Value).Rate;
                }
                var taxRate = rate;
                if (!taxCodeExists)
                {
                    var taxcode = new SalesTaxCode()
                    {
                        ClientID = clientID ?? 0,
                        QuickbooksFullName = name,
                        Rate = taxRate
                    };
                    rep.Add(taxcode);
                }

                rep.Save();
            }
        }
Exemple #3
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);
        }
Exemple #4
0
        private static void ParseItemQuery(string retType,string itemNode,string response)
        {
            var rep = new Repository();
            var clientID = rep.GetUser(WebSecurity.CurrentUserId).ClientID ?? 0;
            var items = XDocument.Parse(response).Document.Root.Descendants("QBXMLMsgsRs").Descendants(retType).FirstOrDefault().Descendants(itemNode);
            List<QuickbooksInventory> inventoryList = new List<QuickbooksInventory>();
            foreach(var item in items)
            {
                var DatabaseItem = rep.GetQuickbooksInventoryItem(clientID,item.Descendants("ListID").FirstOrDefault().Value);
                if (DatabaseItem != null)
                {
                    DatabaseItem.FullName = item.Descendants("FullName").FirstOrDefault().Value;
                }
                else
                {
                    inventoryList.Add(new QuickbooksInventory(){
                        ClientID = clientID,
                        ListID = item.Descendants("ListID").FirstOrDefault().Value,
                        FullName = item.Descendants("FullName").FirstOrDefault().Value
                    });
                }

            }
            rep.Add(inventoryList);
            rep.Save();
        }
Exemple #5
0
        private XDocument buildInfomediaRequest(string ticket)
        {
            var rep = new Repository();
            var docMaker = new CustomerAdd();
            var user = rep.GetUser(WebSecurity.CurrentUserId);
            bool requiresInventoryUpdate = user.Client.RequiresInventoryUpdate ?? false;
            bool requiresTaxCodeUpdate = user.Client.RequiresTaxCodeUpdate ?? false;
            var customer = rep.GetUnprocessedCustomersByTransaction(ticket).FirstOrDefault();
            var order = rep.GetUnprocessedOrdersByTransaction(ticket).FirstOrDefault();
            var transaction = rep.GetTransaction(ticket);
            if(requiresTaxCodeUpdate && transaction.ProcessedItemSalesTaxQueryRs != true)
            {
                var doc =  SalesTax.ItemSalesTaxQueryRq;
                transaction.ProcessedItemSalesTaxQueryRs = true;
                rep.Save();
                return doc;
            }
            else if(requiresTaxCodeUpdate)
            {
                var doc =  SalesTax.ItemSalesTaxGroupQueryRq;
                user.Client.RequiresTaxCodeUpdate = false;
                rep.Save();
                return doc;
            }
            else if(requiresInventoryUpdate && transaction.ProcessedItemInventoryQuery != true)
            {
                var doc = Inventory.ItemInventoryFullQueryRq();
                transaction.ProcessedItemInventoryQuery = true;
                rep.Save();
                return doc;
            }
            else if(requiresInventoryUpdate)
            {
                if(user.Client.IsContentEditsShop ?? false)
                {
                    UpdateShopInventory();
                }
                var doc =  Inventory.ItemNonInventoryFullQueryRq();
                user.Client.RequiresInventoryUpdate = false;
                rep.Save();
                return doc;
            }
            else if(customer != null)
            {
                var doc = docMaker.GetCustomer(customer.CustomerID,customer.Orders.FirstOrDefault().OrderNumber);
                customer.CurrentRequest = true;
                customer.Reported = true;
                rep.Save();
                return doc;
            }
            if (order.AmountDiscount != null && order.AmountDiscount > 0 )
            {
                Error.ProcessFailedOrder(order);
                order.Reported = true;
                rep.Save();
                order = rep.GetUnprocessedOrdersByTransaction(ticket).FirstOrDefault();
            }
            else if ( order != null)
            {
                var fullinvoice = new FullInvoice();
                //var invoice = new Invoice();

                var doc =	fullinvoice.GetInvoice(order.Customer.CustomerID, order.OrderID);
                order.Reported = true;
                rep.Save();
                return doc;
            }
            return null;
        }