Ejemplo n.º 1
0
        public CustomerOrderObject GetPendingOrderByFilename(string file)
        {
            try
            {

                CustomerOrderObject coo = new CustomerOrderObject();
                XDocument xDoc = XDocument.Load(file);
                coo.FileKey = xDoc.Root.Attribute("FileKey").Value;
                coo.SaveLocation = _util.ParseEnum<PendingOrderSaveLocation>(xDoc.Root.Attribute("SaveLocation").Value);
                coo.Customer.LoadPersonalInfo(XmlToCustInfo(xDoc.Root.Element("Customer")));
                coo.Customer.BillingAddress = XmlToAddress(xDoc.Root.Element("AddressSet"), Enums.AddressType.Billing);
                coo.Customer.ShippingAddress = XmlToAddress(xDoc.Root.Element("AddressSet"), Enums.AddressType.Shipping);
                coo.Customer.CreditCards = XmlToCreditCardSet(xDoc.Root.Element("CreditCardSet"));
                coo.Order = XmlToOrder(xDoc.Root.Element("Order"));
                coo.Vehicle = XmlToVehicle(xDoc.Root.Element("Vehicle"));

                return coo;

            }
            catch (Exception ex)
            {
                _logger.LogException("Error in GetPendingOrderByFilename.  Filename is " + file, ex);
                throw new QuickBooksException("Error retrieving order from disk.  See log for details.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
 public void Initialize(CustomerOrderObject coo)
 {
     _isPreExistingOrder = true;
     mnuDelete.Enabled = true;
     LoadCustomerOrderObj(coo);
 }
Ejemplo n.º 3
0
        private void LoadCustomerOrderObj(CustomerOrderObject coo)
        {
            _saveLocation = coo.SaveLocation;
            _fileKey = coo.FileKey;

            txtNotes.Text = coo.Order.Notes;
            dtOrderDate.Value = coo.Order.OrderDate;
            ucCustomerInfo1.SetCustomerInfo(coo.Customer);
            ucBillingAddress.SetAddress(coo.Customer.BillingAddress);
            ucShippingAddress.SetAddress(coo.Customer.ShippingAddress);
            ucCC1.SetCreditCard(coo.Customer.CreditCards[0]);
            ucCC2.SetCreditCard(coo.Customer.CreditCards[1]);
            ucCC3.SetCreditCard(coo.Customer.CreditCards[2]);
            SetVehicleInfo(coo.Vehicle);
            SetPaymentMethod(coo.Order.PaymentMethod);
            ClearOrderDetails();
            foreach (var item in coo.Order.OrderItems)
            {
                var ucLi = ObjectFactory.GetInstance<ucLineItem>();
                ucLi.LoadOrderItems(_orderItems);

                flpMain.Controls.Add(ucLi);
                ucLi.SetOrderItem(item);
                ucLi.DeleteItem += new Action<ucLineItem>(li_DeleteItem);
                ucLi.TotalOrTaxableChanged += new Action(li_TotalChanged);
                ucLi.InsertItem += new Action<ucLineItem>(InsertItem);
            }
            flpMain.Controls.Add(btnAddItem);
            RecalculateTotals();
        }
Ejemplo n.º 4
0
        private CustomerOrderObject GetCustomerOrderObj()
        {
            CustomerOrderObject coo = new CustomerOrderObject();

            Customer c = coo.Customer;
            Vehicle v = coo.Vehicle;
            Order o = coo.Order;
            o.Notes = txtNotes.Text;

            c.LoadPersonalInfo(ucCustomerInfo1.GetCustomer());

            c.BillingAddress = ucBillingAddress.GetAddress();
            c.ShippingAddress = ucShippingAddress.GetAddress();

            c.CreditCards[0] = ucCC1.GetCreditCard();
            c.CreditCards[1] = ucCC2.GetCreditCard();
            c.CreditCards[2] = ucCC3.GetCreditCard();

            v.Make = txtMake.Text;
            v.Model = txtModel.Text;
            v.Row1 = txtRow1.Text;
            v.Row2 = txtRow2.Text;
            v.Row3 = txtRow3.Text;
            v.Trim = txtTrim.Text;

            try
            {
                v.Year = int.Parse(txtYear.Text);
            }
            catch { }

            try
            {
                o.GrandTotal = double.Parse(txtGrandTotal.Text);
            }
            catch { }

            try
            {
                o.SubTotal = double.Parse(txtSubTotal.Text);
            }
            catch { }

            try
            {
                o.Taxes = double.Parse(txtTaxes.Text);
            }
            catch { }

            o.PaymentMethod = GetPaymentMethod();
            o.OrderDate = dtOrderDate.Value;

            for(int i = 0; i<flpMain.Controls.Count-1; i++)
            {
                ucLineItem ucLineItem = (ucLineItem)flpMain.Controls[i];
                OrderItem oi = ucLineItem.GetOrderItem();
                o.OrderItems.Add(oi);
            }

            return coo;
        }
Ejemplo n.º 5
0
 private PendingOrderFile CooToPendingOrderFile(CustomerOrderObject order)
 {
     var file = new PendingOrderFile(order.FileKey, order.Customer.FullName, order.Order.OrderDate, order.SaveLocation);
     return file;
 }
Ejemplo n.º 6
0
        public string SavePendingOrder(CustomerOrderObject coo)
        {
            try
            {
                if (string.IsNullOrEmpty(coo.FileKey))
                    coo.FileKey = Guid.NewGuid().ToString("N");

                XElement xCustOrderContainer = new XElement("CustomerOrderContainer",
                                                        new XAttribute("FileKey", coo.FileKey),
                                                        new XAttribute("SaveLocation", coo.SaveLocation.ToString())
                                                        );

                XElement xCustomer = CustomerToXml(coo.Customer);
                XElement xVehicle = VehicleToXml(coo.Vehicle);
                XElement xOrder = OrderToXml(coo.Order);
                XElement xCreditCardSet = CreditCardSetToXml(coo.Customer.CreditCards);
                XElement xAddressSet = AddressSetToXml(new List<Address>() { coo.Customer.BillingAddress, coo.Customer.ShippingAddress });

                xCustOrderContainer.Add(xCustomer);
                xCustOrderContainer.Add(xVehicle);
                xCustOrderContainer.Add(xOrder);
                xCustOrderContainer.Add(xCreditCardSet);
                xCustOrderContainer.Add(xAddressSet);

                XDocument xDoc = new XDocument();
                xDoc.Add(xCustOrderContainer);

                xDoc.Save(_settings.PendingOrdersPath + "\\" + coo.FileKey + ".inv");

                return coo.FileKey;
            }
            catch (Exception ex)
            {
                _logger.LogException("Error writing CustomerOrderObject xml file to disk.", ex);
                throw new QuickBooksException(string.Format("Error writing file to disk for customer {0}.  See log for details.", coo.Customer.FullName), "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 7
0
        public string SaveInvoice(CustomerOrderObject coo)
        {
            Customer customer = null;
            string s = string.Empty;
            bool custExists = false;

            if (!string.IsNullOrEmpty(coo.Customer.CustomerID))
            {
                try
                {
                    customer = this.GetCustomerByID(coo.Customer.CustomerID);
                }
                catch (Exception)
                {
                }
            }

            if (customer != null)
                custExists = true;

            if (!custExists)
            {
                string id = this.AddCustomer(coo.Customer);
                customer = this.GetCustomerByID(id);
                coo.Customer.CustomerID = id;
            }
            else //customer does exist
            {
                string listID = string.Empty;
                listID = customer.CustomerID;

                if (!string.IsNullOrEmpty(listID))
                {
                    this.ModifyCustomer(coo.Customer, false);
                    if (customer.CreditCardFieldsExistInQB)
                        this.ModifyCreditCardsForCustomer(coo.Customer.CreditCards, customer.CustomerID);
                    else
                        AddCreditCardsForCustomer(coo.Customer.CreditCards, listID);
                }
            }

            QBSessionManager session = new QBSessionManagerClass();
            IMsgSetRequest requestMsgSet = session.CreateMsgSetRequest("US", 8, 0);
            try
            {
                requestMsgSet.ClearRequests();
                requestMsgSet.Attributes.OnError = ENRqOnError.roeStop;
                session.OpenConnection("", _settings.QbAppName);
                session.BeginSession(_settings.QuickBooksFilePath, ENOpenMode.omDontCare);
                IInvoiceAdd invoice = requestMsgSet.AppendInvoiceAddRq();

                invoice.CustomerRef.ListID.SetValue(customer.CustomerID);
                invoice.ShipAddress.Addr1.SetValue(coo.Customer.ShippingAddress.Line1);
                invoice.ShipAddress.Addr2.SetValue(coo.Customer.ShippingAddress.Line2);
                invoice.ShipAddress.Addr3.SetValue(coo.Customer.ShippingAddress.Line3);
                invoice.ShipAddress.Addr4.SetValue(coo.Customer.ShippingAddress.Line4);

                invoice.ShipAddress.City.SetValue(coo.Customer.ShippingAddress.City);
                invoice.ShipAddress.State.SetValue(coo.Customer.ShippingAddress.State);
                invoice.ShipAddress.PostalCode.SetValue(coo.Customer.ShippingAddress.Zip);

                Address billing = coo.Customer.BillingAddress;
                invoice.BillAddress.Addr1.SetValue(billing.Line1);
                invoice.BillAddress.Addr2.SetValue(billing.Line2);
                invoice.BillAddress.Addr3.SetValue(billing.Line3);
                invoice.BillAddress.Addr4.SetValue(billing.Line4);

                invoice.BillAddress.City.SetValue(billing.City);
                invoice.BillAddress.State.SetValue(billing.State);
                invoice.BillAddress.PostalCode.SetValue(billing.Zip);
                invoice.TxnDate.SetValue(coo.Order.OrderDate);  //TODO confirm how this date gets set
                invoice.PONumber.SetValue(coo.Customer.PoBox);
                invoice.IsToBePrinted.SetValue(true);
                invoice.Memo.SetValue(coo.Vehicle.Year.ToString() + " " + coo.Vehicle.Make + " " + coo.Vehicle.Model);
                if (coo.Customer.BillingAddress.State == _settings.TaxableState)
                    invoice.ItemSalesTaxRef.FullName.SetValue(_settings.InStateTaxCodeName);
                else
                    invoice.ItemSalesTaxRef.FullName.SetValue(_settings.OutOfStateTaxCodeName);

                foreach (var lineItem in coo.Order.OrderItems)
                {
                    IORInvoiceLineAdd invoiceLine = invoice.ORInvoiceLineAddList.Append();
                    invoiceLine.InvoiceLineAdd.Quantity.SetValue(lineItem.Quantity);
                    invoiceLine.InvoiceLineAdd.ORRatePriceLevel.Rate.SetValue(lineItem.Price);
                    invoiceLine.InvoiceLineAdd.Desc.SetValue(lineItem.Description);
                    invoiceLine.InvoiceLineAdd.ItemRef.ListID.SetValue(lineItem.ItemID);

                    if (lineItem.IsTaxed)
                        invoiceLine.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Tax");
                    else
                        invoiceLine.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Non");
                }

                IResponse response = session.DoRequests(requestMsgSet).ResponseList.GetAt(0);
                IInvoiceRet invoiceRet = (IInvoiceRet)response.Detail;
                if(invoiceRet == null)
                {
                    string msg = string.Format("Error adding invoice.{0}Status = {1}{0}Response={2}", Environment.NewLine,response.StatusCode, response.StatusMessage);
                    _logger.Log(msg);
                    throw new QuickBooksException(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                s = invoiceRet.RefNumber.GetValue();
                return s;
            }
            catch(QuickBooksException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogException("Error in Save Invoice method.", ex);
                throw new QuickBooksException("There was an error saving the invoice.  See log for details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                session.EndSession();
                session.CloseConnection();
            }
        }
Ejemplo n.º 8
0
        public void SaveInvoice_NewCustomer()
        {
            var cust = GetPopulatedCustomer();
            string custName = cust.FullName;
            CustomerOrderObject coo = new CustomerOrderObject()
            {
                Customer =  cust,
                Order = new Order()
                {
                    OrderDate = DateTime.Now,
                    OrderItems = new List<OrderItem>()
                    {
                        new OrderItem(){
                             ItemID  = "8000005C-1213652981",
                              IsTaxed = false,
                               Description = "test desc",
                                Quantity = 5,
                                 Price  = 10

                        }
                    }
                }
            };

            ISettings s = GetPopulatedSettingsObj();

            var mockLogger = new Mock<ILogger>();

            var repo = new QBRepository(mockLogger.Object, s);
            repo.SaveInvoice(coo);

            var custs = repo.SearchCustomers(custName);
            Assert.IsTrue(custs[0].CreditCards[0].IsUsed);
        }