private List <Customer> parseCustomerQueryRs2(IMsgSetResponse responseMsgSet, int count)
        {
            List <Customer> customers = new List <Customer>();
            IResponse       response  = responseMsgSet.ResponseList.GetAt(0);

            int statusCode = response.StatusCode;

            if (statusCode == 0)
            {
                ICustomerRetList custRetList = response.Detail as ICustomerRetList;
                for (int i = 0; i < count; i++)
                {
                    if (custRetList.GetAt(i).FullName != null)
                    {
                        customers.Add(new Customer {
                            Name = custRetList.GetAt(i).FullName.GetValue().ToString(),
                            //Address = custRetList.GetAt(i).BillAddress.Addr1.GetValue().ToString(),
                            //City = custRetList.GetAt(i).BillAddress.City.GetValue().ToString(),
                            //State = custRetList.GetAt(i).BillAddress.State.GetValue().ToString(),
                            //Zip = custRetList.GetAt(i).BillAddress.PostalCode.GetValue().ToString()
                        });
                    }
                }
            }
            return(customers);
        }
예제 #2
0
        static public void ListCustomers()
        {
            QBSession Session = null;

            try
            {
                Session = new QBSession();

                IResponse response = Session.QueryCustomerList();

                ICustomerRetList customerRetList = response.Detail as ICustomerRetList;
                for (var i = 0; i < customerRetList.Count; i++)
                {
                    ICustomerRet customerRet = customerRetList.GetAt(i);
                    Console.WriteLine(customerRet.FullName.GetValue());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
                Console.WriteLine("Stack Trace:");
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine("Exiting the application");
            }
        }
예제 #3
0
        public ObservableCollection <customer> DbRead()
        {
            ObservableCollection <customer> Customers = new ObservableCollection <customer>();

            QBSessionManager sessionManager = CreateSession();
            IMsgSetRequest   requestMsgSet  = CreateRequestMessage(ref sessionManager);

            sessionManager = DbConnect(sessionManager);

            // Setup requestquery
            ICustomerQuery customerQueryReq = requestMsgSet.AppendCustomerQueryRq();

            customerQueryReq = SetIncludedRetEliments(ref customerQueryReq);
            customerQueryReq = SetCustomerQuery(0, ref customerQueryReq);



            IResponse        response        = GetMessageResponse(ref sessionManager, ref requestMsgSet);
            ICustomerRetList customerRetList = (ICustomerRetList)response.Detail;


            if (customerRetList != null)
            {
                for (int i = 0; i < customerRetList.Count; i++)
                {
                    ICustomerRet customerRet = customerRetList.GetAt(i);
                    customer     Customer    = FillCustomer(customerRet);

                    Customers.Add(Customer);
                }
            }
            return(Customers);
        }
        private ICustomerRet QueryCustomer(QBSessionManager session, string customerFullName)
        {
            // query for the customer information

            IMsgSetRequest requestMsgSet = getLatestMsgSetRequest(session);

            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

            ICustomerQuery      pCustomerQuery  = requestMsgSet.AppendCustomerQueryRq();
            ICustomerListFilter pCustomerFilter = pCustomerQuery.ORCustomerListQuery.CustomerListFilter;

            pCustomerFilter.ORNameFilter.NameFilter.Name.SetValue(customerFullName);
            pCustomerFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcContains);

            IMsgSetResponse responseMsgSet = session.DoRequests(requestMsgSet);

            // Uncomment the following to see the request and response XML for debugging
            //string rq = requestMsgSet.ToXMLString();
            //string rs = responseMsgSet.ToXMLString();

            //m_application.Messenger.AddInfo("Customer Resquest: " + rq);
            //m_application.Messenger.AddInfo("Customer Response: " + rs);

            // Interpret the response

            IResponseList rsList = responseMsgSet.ResponseList;

            //  Retrieve the one response corresponding to our single request

            IResponse response = rsList.GetAt(0);

            if (response.StatusCode != 0)
            {
                string msg = "";
                if (response.StatusCode == 1)  //No record found
                {
                    msg = "Customer not found: " + customerFullName;
                }
                else
                {
                    msg = "Error getting customer.  Status: " + response.StatusCode.ToString() + ", Message: " + response.StatusMessage;
                }

                throw new Exception(msg);
            }

            // We have one or more customers (expect one)

            ICustomerRetList customerList = response.Detail as ICustomerRetList;
            int customerCount             = customerList.Count;

            if (customerCount > 1)
            {
                m_application.Messenger.AddWarning("Multiple customers found: " + customerFullName);
            }

            return(customerList.GetAt(0));
        }
예제 #5
0
        private List <Customer> readCustomers(ICustomerRetList customerRetList)
        {
            List <Customer> customers = new List <Customer>();

            for (int i = 0; i < customerRetList.Count; i++)
            {
                ICustomerRet cutomerRet = customerRetList.GetAt(i);
                Customer     customer   = readBillPayment.readCustomerFromCustomerRet(cutomerRet);
                customers.Add(customer);
            }
            return(customers);
        }
예제 #6
0
        private void GetCustomers()
        {
            sessionManager = new QBSessionManager();
            sessionManager.OpenConnection("appID", "Bluefire Integration TEST");
            _connectionOpen = true;
            sessionManager.BeginSession(COMPANY_FILE, ENOpenMode.omDontCare);
            _sessionBegun = true;

            // Grab the list of customer names to populate our listbox
            IMsgSetRequest messageSet = sessionManager.CreateMsgSetRequest("CA", 12, 0);
            ICustomerQuery custQuery  = messageSet.AppendCustomerQueryRq();

            try
            {
                IMsgSetResponse responseSet = sessionManager.DoRequests(messageSet);
                sessionManager.EndSession();
                _sessionBegun = false;

                IResponse      response;
                ENResponseType responseType;

                for (int i = 0; i < responseSet.ResponseList.Count; i++)
                {
                    response = responseSet.ResponseList.GetAt(i);

                    if (response.Detail == null)
                    {
                        continue;
                    }

                    responseType = (ENResponseType)response.Type.GetValue();
                    if (responseType == ENResponseType.rtCustomerQueryRs)
                    {
                        ICustomerRetList custList = (ICustomerRetList)response.Detail;
                        for (int custIndex = 0; custIndex < custList.Count; custIndex++)
                        {
                            ICustomerRet customer = (ICustomerRet)custList.GetAt(custIndex);

                            if (customer != null && customer.CompanyName != null)
                            {
                                customer_listbox.Items.Add(customer.CompanyName.GetValue());
                            }
                        }
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException comEx)
            {
                // something bad happened; tell the user, smash his computer, whatever; its your choice
                MessageBox.Show(comEx.Message);
            }
        }
예제 #7
0
    /// <summary>
    /// The GetCustomersData.
    /// </summary>
    /// <param name="logsFile">The logsFile<see cref="StreamWriter"/>.</param>
    /// <returns>The <see cref="List{dynamic}"/>.</returns>
    public List <dynamic> GetCustomersData(StreamWriter logsFile)
    {
        IMsgSetRequest requestSet = SessionManager.Instance.CreateMsgSetRequest();

        requestSet.Attributes.OnError = ENRqOnError.roeStop;
        ICustomerQuery  CustomerQueryRq = requestSet.AppendCustomerQueryRq();
        IMsgSetResponse responeSet      = SessionManager.Instance.DoRequests(requestSet, logsFile);
        IResponseList   responseList    = responeSet.ResponseList;
        List <dynamic>  customersArray  = new List <dynamic>();
        var             accountNumber   = "";

        try
        {
            for (int i = 0; i < responseList.Count; i++)
            {
                IResponse response = responseList.GetAt(i);
                if (response.StatusCode == 0)
                {
                    ICustomerRetList customerList = (ICustomerRetList)response.Detail;
                    Console.WriteLine("Number Of Records Being Fetched Are:\t" + customerList.Count + "\n");
                    for (int j = 0; j < customerList.Count; j++)
                    {
                        ICustomerRet customer = customerList.GetAt(j);
                        if (customer.AccountNumber != null)
                        {
                            accountNumber = customer.AccountNumber.GetValue();
                        }
                        else
                        {
                            accountNumber = "Account Number Not Defined...";
                        }
                        customersArray.Add(new string[] { customer.Name.GetValue().ToString(), accountNumber, customer.TotalBalance.GetValue().ToString() });
                    }
                }
            }
        }

        catch (Exception ex)
        {
            logsFile.WriteLine(DateTime.Now + "\tERROR\tError Message:\t" + ex.Message);
            logsFile.WriteLine();
            logsFile.WriteLine(DateTime.Now + "\tERROR\tError Message:\tStack Trace:\t" + ex.StackTrace);
            logsFile.WriteLine();
        }

        return(customersArray);
    }
예제 #8
0
        private ICustomerRet FindCustomer(Quickbooks qb, String fullName)
        {
            IMsgSetRequest msgRequest    = qb.newRequest();
            ICustomerQuery customerQuery = msgRequest.AppendCustomerQueryRq();

            customerQuery.ORCustomerListQuery.FullNameList.Add(fullName);
            IMsgSetResponse response = qb.performRequest(msgRequest);

            ICustomerRetList qbCustomers = (ICustomerRetList)response.ResponseList.GetAt(0).Detail;

            if (qbCustomers == null)
            {
                return(null);
            }

            return(qbCustomers.GetAt(0));
        }
예제 #9
0
        /// <summary>
        /// Obtain a listing of all quickbooks customers.
        /// </summary>
        /// <returns>a list of all quickbooks customers</returns>
        public List <QuickbooksCustomer> getCustomers()
        {
            List <QuickbooksCustomer> customers  = new List <QuickbooksCustomer>();
            IMsgSetRequest            msgRequest = qbMgr.CreateMsgSetRequest("US", 4, 0);

            msgRequest.Attributes.OnError = ENRqOnError.roeStop;
            msgRequest.AppendCustomerQueryRq();
            IMsgSetResponse  response    = qbMgr.DoRequests(msgRequest);
            ICustomerRetList qbCustomers = (ICustomerRetList)response.ResponseList.GetAt(0).Detail;

            for (int i = 0; qbCustomers != null && i < qbCustomers.Count; i++)
            {
                customers.Add(new QuickbooksCustomer()
                {
                    Name = qbCustomers.GetAt(i).Name.GetValue()
                });
            }

            return(customers);
        }
        private IList <Customer> WalkCustomerQuery(IMsgSetResponse responseMsgSet)
        {
            if (responseMsgSet == null)
            {
                return(null);
            }

            IResponseList responseList = responseMsgSet.ResponseList;

            if (responseList == null)
            {
                return(null);
            }

            int count = responseList.Count;

            //if we sent only one request, there is only one response, we'll walk the list for this sample
            for (int i = 0; i < count; i++)
            {
                IResponse response = responseList.GetAt(i);

                if (response.StatusCode == 0)
                {
                    if (response.Detail != null)
                    {
                        ENResponseType responseType = (ENResponseType)response.Type.GetValue();
                        if (responseType == ENResponseType.rtCustomerQueryRs)
                        {
                            ICustomerRetList CustomerRet = (ICustomerRetList)response.Detail;
                            return(WalkCustomers(CustomerRet));
                        }
                    }
                }
                else
                {
                    throw new QBException(response.StatusCode, response.StatusMessage, requestMsgSet.ToXMLString());
                }
            }

            return(null);
        }
        private void editCustomer_Click(object sender, EventArgs e)
        {
            _MySessionManager = SessionManager.NewQBSession();

            IMsgSetRequest requestMsgSet = _MySessionManager.CreateMsgSetRequest("US", 13, 0);

            ICustomerQuery Query = requestMsgSet.AppendCustomerQueryRq();

            IMsgSetResponse responseMsgSet = _MySessionManager.DoRequests(requestMsgSet);

            IResponseList rsList = responseMsgSet.ResponseList;

            IResponse response = rsList.GetAt(0);

            ICustomerRetList CustomerList = (ICustomerRetList)response.Detail;

            if (CustomerList == null)
            {
                throw new Exception("Sorry, no customers found.");
            }

            for (int i = 0; i <= CustomerList.Count - 1; i++)
            {
                ICustomerRet QBCustomer = CustomerList.GetAt(i);

                //string CustomerName = QBCustomer.Name.GetValue().ToString();
                //string listID = QBCustomer.ListID.GetValue();
                //string editSequence = QBCustomer.EditSequence.GetValue();
                if (QBCustomer.Email != null)
                {
                    string email = QBCustomer.Email.GetValue();

                    if (_emailsToDelete.Contains(email))
                    {
                        modifyCustomer(QBCustomer);
                    }
                }
            }
        }
예제 #12
0
        protected override void Action(QBSessionManager sessionManager, IMsgSetRequest request)
        {
            // Add the request to the message set request object
            //ICustomerQuery CustQ = request.AppendCustomerQueryRq();
            request.AppendCustomerQueryRq();

            // Optionally, you can put filter on it.
            //CustQ.ORCustomerListQuery.CustomerListFilter.MaxReturned.SetValue(50);

            // Do the request and get the response message set object
            IMsgSetResponse responseSet = sessionManager.DoRequests(request);

            // Uncomment the following to view and save the request and response XML
            // string requestXML = requestSet.ToXMLString();
            // MessageBox.Show(requestXML);
            // SaveXML(requestXML);
            // string responseXML = responseSet.ToXMLString();
            // MessageBox.Show(responseXML);
            // SaveXML(responseXML);

            IResponse response = responseSet.ResponseList.GetAt(0);
            // int statusCode = response.StatusCode;
            // string statusMessage = response.StatusMessage;
            // string statusSeverity = response.StatusSeverity;
            // MessageBox.Show("Status:\nCode = " + statusCode + "\nMessage = " + statusMessage + "\nSeverity = " + statusSeverity);


            ICustomerRetList customerRetList = response.Detail as ICustomerRetList;

            if (!(customerRetList.Count == 0))
            {
                for (int ndx = 0; ndx <= (customerRetList.Count - 1); ndx++)
                {
                    ICustomerRet customerRet = customerRetList.GetAt(ndx);
                    Customers.Add(customerRet.FullName.GetValue());
                }         // for
            }             // if
        }
예제 #13
0
        public List <Customer> getAllCustomers()
        {
            //Item Request
            IMsgSetRequest customerRequestset = _MySessionManager.CreateMsgSetRequest("US", 13, 0);

            ICustomerQuery customerQuery = customerRequestset.AppendCustomerQueryRq();

            IMsgSetResponse responseCustomerRq = _MySessionManager.DoRequests(customerRequestset);

            IResponseList customerResponseList = responseCustomerRq.ResponseList;

            IResponse customerResponse = customerResponseList.GetAt(0);

            //ENResponseType responseType = (ENResponseType)customerResponse.Type.GetValue();
            ICustomerRetList customerList = (ICustomerRetList)customerResponse.Detail;

            for (int i = 0; i <= customerList.Count - 1; i++)
            {
                ICustomerRet qbCustomer = customerList.GetAt(i);

                Address address = new Address();

                Customer customer = new Customer();
                customer.AccountNumber = qbCustomer.AccountNumber != null?qbCustomer.AccountNumber.GetValue() : null;

                customer.Name    = qbCustomer.Name.GetValue();
                customer.Address = address.getAddress(qbCustomer.BillAddress);
                customer.Email   = qbCustomer.Email != null?qbCustomer.Email.GetValue() : null;

                customer.Phone = qbCustomer.Phone != null?qbCustomer.Phone.GetValue() : null;

                _customers.Add(customer);
            }

            return(_customers);
        }
예제 #14
0
        public override List <ITransactionEntity> Import()
        {
            StartSession();

            IMsgSetRequest request = GetLatestMsgSetRequest();
            ICustomerQuery query   = request.AppendCustomerQueryRq();

            query.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);

            IResponse res = GetResponse(request);

            ICustomerRetList returnList = res.Detail as ICustomerRetList;

            List <MaestroCustomer> mlist = new List <MaestroCustomer>();

            for (int i = 0; i < returnList.Count; i++)
            {
                ICustomerRet qbc = returnList.GetAt(i);
                //if (ReadBool(qbc.IsActive))
                //{
                //mlist.Add(GetMaestroCustomer(qbc));

                /*
                 * if(qbc.ShipToAddressList != null)
                 * {
                 *  Console.WriteLine("count:"+qbc.ShipToAddressList.Count);
                 * }*/
                //}
                mlist.Add(GetMaestroCustomer(qbc));

                //WalkCustomerRet(qbc);
                //
            }

            return(mlist.Cast <ITransactionEntity>().ToList());
        }
예제 #15
0
        private void view_customers_Click(object sender, RoutedEventArgs e)
        {
            bool             sessionBegun   = false;
            bool             connectionOpen = false;
            QBSessionManager sessionManager = null;

            try
            {
                //Create the session Manager object
                sessionManager = new QBSessionManager();

                //Create the message set request object to hold our request
                IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 8, 0);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                //Connect to QuickBooks and begin a session
                sessionManager.OpenConnection("", "WpfApplication1");
                connectionOpen = true;
                sessionManager.BeginSession(@"C:\Users\Public\Documents\Intuit\QuickBooks\Company Files\Imperial2.qbw", ENOpenMode.omDontCare);
                sessionBegun = true;

                ICustomerQuery customerQueryRq = requestMsgSet.AppendCustomerQueryRq();

                //Send the request and get the response from QuickBooks
                IMsgSetResponse  responseMsgSet  = sessionManager.DoRequests(requestMsgSet);
                IResponse        response        = responseMsgSet.ResponseList.GetAt(0);
                ICustomerRetList customerRetList = (ICustomerRetList)response.Detail;

                var customers = new List <Customer>();

                if (customerRetList != null)
                {
                    for (int i = 0; i < customerRetList.Count; i++)
                    {
                        ICustomerRet customerRet = customerRetList.GetAt(i);

                        var customer = new Customer
                        {
                            Name = customerRet.Name.GetValue(),
                            Id   = customerRet.ListID.GetValue()
                                   //EditSequence = customerRet.EditSequence.GetValue()
                        };

                        customers.Add(customer);
                    }
                }
                dataGrid.ItemsSource = customers;
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
            finally
            {
                //End the session and close the connection to QuickBooks
                if (sessionBegun)
                {
                    sessionManager.EndSession();
                }
                if (connectionOpen)
                {
                    sessionManager.CloseConnection();
                }
            }
        }
        private IList <Customer> WalkCustomers(ICustomerRetList Customer)
        {
            if (Customer == null)
            {
                return(null);
            }
            CustomerList = new List <Customer>();
            Customer cust;

            for (int a = 0; a < Customer.Count; a++)
            {
                ICustomerRet CustomerRet = Customer.GetAt(a);

                cust        = new Customer();
                cust.ListID = CustomerRet.ListID.GetValue();
                cust.Name   = (string)CustomerRet.Name.GetValue();
                if (CustomerRet.Phone != null)
                {
                    cust.Phone = CustomerRet.Phone.GetValue();
                }
                if (CustomerRet.Email != null)
                {
                    cust.Email = CustomerRet.Email.GetValue();
                }

                cust.FullName     = (string)CustomerRet.FullName.GetValue();
                cust.EditSequence = CustomerRet.EditSequence.GetValue();
                cust.ListID       = CustomerRet.ListID.GetValue().ToString();
                cust.TotalBalance = CustomerRet.TotalBalance.GetValue();
                if (CustomerRet.FirstName != null)
                {
                    cust.FirstName = CustomerRet.FirstName.GetValue();
                }
                if (CustomerRet.LastName != null)
                {
                    cust.LastName = CustomerRet.LastName.GetValue();
                }
                if (CustomerRet.BillAddress != null)
                {
                    if (CustomerRet.BillAddress.Addr1 != null)
                    {
                        cust.BillAddress1 = CustomerRet.BillAddress.Addr1.GetValue();
                    }
                    if (CustomerRet.BillAddress.Addr2 != null)
                    {
                        cust.BillAddress2 = CustomerRet.BillAddress.Addr2.GetValue();
                    }
                    if (CustomerRet.BillAddress.City != null)
                    {
                        cust.BillCity = CustomerRet.BillAddress.City.GetValue();
                    }
                    if (CustomerRet.BillAddress.Country != null)
                    {
                        cust.BillCounty = CustomerRet.BillAddress.Country.GetValue();
                    }
                    if (CustomerRet.BillAddress.PostalCode != null)
                    {
                        cust.BillPostcode = CustomerRet.BillAddress.PostalCode.GetValue();
                    }
                }

                if (CustomerRet.ShipAddress != null)
                {
                    if (CustomerRet.ShipAddress.Addr1 != null)
                    {
                        cust.ShipAddress1 = CustomerRet.ShipAddress.Addr1.GetValue();
                    }
                    if (CustomerRet.ShipAddress.Addr2 != null)
                    {
                        cust.ShipAddress2 = CustomerRet.ShipAddress.Addr2.GetValue();
                    }
                    if (CustomerRet.ShipAddress.City != null)
                    {
                        cust.ShipCity = CustomerRet.ShipAddress.City.GetValue();
                    }
                    if (CustomerRet.ShipAddress.Country != null)
                    {
                        cust.ShipCountry = CustomerRet.ShipAddress.Country.GetValue();
                    }
                    if (CustomerRet.ShipAddress.PostalCode != null)
                    {
                        cust.ShipPostalCode = CustomerRet.ShipAddress.PostalCode.GetValue();
                    }
                }

                if (CustomerRet.DataExtRetList != null)
                {
                    cust.VaultID = CustomerRet.DataExtRetList.GetAt(0).DataExtValue.GetValue();
                }
                if (CustomerRet.Notes != null)
                {
                    cust.Note = CustomerRet.Notes.GetValue();
                }

                CustomerList.Add(cust);
            }
            return(CustomerList);
        }
예제 #17
0
        private string[] parseCustomerQueryRs(IMsgSetResponse responseMsgSet, int count)
        {
            /*
             * <?xml version="1.0" ?>
             * <QBXML>
             * <QBXMLMsgsRs>
             * <CustomerQueryRs requestID="1" statusCode="0" statusSeverity="Info" statusMessage="Status OK">
             *   <CustomerRet>
             *       <FullName>Abercrombie, Kristy</FullName>
             *   </CustomerRet>
             * </CustomerQueryRs>
             * </QBXMLMsgsRs>
             * </QBXML>
             */
            string[]  retVal     = new string[count];
            IResponse response   = responseMsgSet.ResponseList.GetAt(0);
            int       statusCode = response.StatusCode;

            if (statusCode == 0)
            {
                ICustomerRetList custRetList = response.Detail as ICustomerRetList;
                for (int i = 0; i < count; i++)
                {
                    string fullName = null;
                    if (custRetList.GetAt(i).FullName != null)
                    {
                        fullName = custRetList.GetAt(i).FullName.GetValue().ToString();
                        if (fullName != null)
                        {
                            retVal[i] = fullName;
                        }
                    }
                    IAddress billAddress = null;
                    if (custRetList.GetAt(i).BillAddress != null)
                    {
                        billAddress = custRetList.GetAt(i).BillAddress;
                        string addr1 = "", addr2 = "", addr3 = "", addr4 = "", addr5 = "";
                        string city = "", state = "", postalcode = "";
                        if (billAddress != null)
                        {
                            if (billAddress.Addr1 != null)
                            {
                                addr1 = billAddress.Addr1.GetValue().ToString();
                            }
                            if (billAddress.Addr1 != null)
                            {
                                addr1 = billAddress.Addr1.GetValue().ToString();
                            }
                            if (billAddress.Addr2 != null)
                            {
                                addr2 = billAddress.Addr2.GetValue().ToString();
                            }
                            if (billAddress.Addr3 != null)
                            {
                                addr3 = billAddress.Addr3.GetValue().ToString();
                            }
                            if (billAddress.Addr4 != null)
                            {
                                addr4 = billAddress.Addr4.GetValue().ToString();
                            }
                            if (billAddress.Addr5 != null)
                            {
                                addr5 = billAddress.Addr5.GetValue().ToString();
                            }
                            if (billAddress.City != null)
                            {
                                city = billAddress.City.GetValue().ToString();
                            }
                            if (billAddress.State != null)
                            {
                                state = billAddress.State.GetValue().ToString();
                            }
                            if (billAddress.PostalCode != null)
                            {
                                postalcode = billAddress.PostalCode.GetValue().ToString();
                            }

                            retVal[i] = addr1 + "\r\n" + addr2 + "\r\n"
                                        + addr3 + "\r\n"
                                        + city + "\r\n" + state + "\r\n" + postalcode;
                        }
                    }

                    string currencyRef = null;
                    if (custRetList.GetAt(i).CurrencyRef != null)
                    {
                        currencyRef = custRetList.GetAt(i).CurrencyRef.FullName.GetValue().ToString();
                        if (currencyRef != null)
                        {
                            retVal[i] = currencyRef;
                        }
                    }
                }
            }
            return(retVal);
        }
예제 #18
0
        public IList <Invoice> GetInvoiceWithCustomer()
        {
            bool             sessionBegun   = false;
            QBSessionManager sessionManager = null;
            var invoices = new List <Invoice>();

            sessionManager = new QBSessionManager();

            try
            {
                //Connect to QuickBooks and begin a session
                sessionManager.OpenConnection("", "GenerateInvoicePDFs");
                //connectionOpen = true;
                sessionManager.BeginSession("", ENOpenMode.omDontCare);
                sessionBegun = true;

                //Create the message set request object to hold our request
                IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 13, 0);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                IInvoiceQuery invoiceQueryRq = requestMsgSet.AppendInvoiceQueryRq();
                // all invoices modified in the month of August 2016
                invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.FromModifiedDate.SetValue(new DateTime(2017, 12, 1), true);
                invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.ToModifiedDate.SetValue(new DateTime(2017, 12, 31), true);
                //invoiceQueryRq.IncludeLineItems.SetValue(true);

                //Send the request and get the response from QuickBooks
                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                IResponse       response       = responseMsgSet.ResponseList.GetAt(0);
                IInvoiceRetList invoiceRetList = (IInvoiceRetList)response.Detail;

                if (invoiceRetList != null)
                {
                    for (int i = 0; i < invoiceRetList.Count; i++)
                    {
                        IInvoiceRet invoiceRet = invoiceRetList.GetAt(i);

                        var invoice = new Invoice
                        {
                            QuickBooksID  = invoiceRet.TxnID.GetValue(),
                            EditSequence  = invoiceRet.EditSequence.GetValue(),
                            InvoiceNumber = invoiceRet.RefNumber?.GetValue(),
                            Memo          = invoiceRet.Memo?.GetValue(),
                            JobNumber     = invoiceRet.Other?.GetValue(),
                            CustomerName  = invoiceRet.CustomerRef.FullName?.GetValue()
                        };
                        var customerListId = invoiceRet.CustomerRef?.ListID?.GetValue();
                        if (customerListId != null)
                        {
                            Console.WriteLine($"INv:{invoice.InvoiceNumber}, Job: {invoice.JobNumber}, Name:{invoice.CustomerName}");
                            requestMsgSet.ClearRequests();
                            ICustomerQuery customerQueryRq = requestMsgSet.AppendCustomerQueryRq();
                            customerQueryRq.ORCustomerListQuery.ListIDList.Add(customerListId);

                            //Send the request and get the response from QuickBooks
                            responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                            response       = responseMsgSet.ResponseList.GetAt(0);

                            ICustomerRetList customerRetList = (ICustomerRetList)response.Detail;
                            ICustomerRet     customerRet     = customerRetList.GetAt(0);

                            invoice.Customer = new Customer
                            {
                                Name         = customerRet.Name?.GetValue(),
                                QuickBooksID = customerRet.ListID?.GetValue(),
                                EditSequence = customerRet.EditSequence?.GetValue(),
                                FullName     = customerRet.FullName?.GetValue(),
                                CompanyName  = customerRet.CompanyName?.GetValue()
                            };
                            Console.WriteLine($"{i}\t{invoice.Customer.Name}\t{invoice.Customer.FullName}\t{invoice.Customer.CompanyName}");
                        }


                        invoices.Add(invoice);
                    }
                }
                if (requestMsgSet != null)
                {
                    Marshal.FinalReleaseComObject(requestMsgSet);
                }
                sessionManager.EndSession();
                sessionBegun = false;
                sessionManager.CloseConnection();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString() + "\nStack Trace: \n" + ex.StackTrace + "\nExiting the application");
                if (sessionBegun)
                {
                    sessionManager.EndSession();
                    sessionManager.CloseConnection();
                }
            }
            return(invoices);
        }
예제 #19
0
        public static void DoQbXml()
        {
            bool             sessionBegun   = false;
            bool             connectionOpen = false;
            QBSessionManager sessionManager = null;

            sessionManager = new QBSessionManager();

            //Connect to QuickBooks and begin a session
            sessionManager.OpenConnection("", "GenerateInvoicePDFs");
            connectionOpen = true;
            sessionManager.BeginSession("", ENOpenMode.omDontCare);
            sessionBegun = true;

            //Create the message set request object to hold our request
            IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 13, 0);

            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

            IInvoiceQuery invoiceQueryRq = requestMsgSet.AppendInvoiceQueryRq();

            invoiceQueryRq.IncludeLineItems.SetValue(true);

            //Send the request and get the response from QuickBooks
            IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
            IResponse       response       = responseMsgSet.ResponseList.GetAt(0);
            IInvoiceRetList invoiceRetList = (IInvoiceRetList)response.Detail;

            var invoices = new List <Invoice>();

            if (invoiceRetList != null)
            {
                for (int i = 0; i < invoiceRetList.Count; i++)
                {
                    IInvoiceRet invoiceRet = invoiceRetList.GetAt(i);

                    var invoice = new Invoice
                    {
                        QuickBooksID  = invoiceRet.TxnID.GetValue(),
                        EditSequence  = invoiceRet.EditSequence.GetValue(),
                        InvoiceNumber = invoiceRet.RefNumber?.GetValue(),
                        Memo          = invoiceRet.Memo?.GetValue(),
                        JobNumber     = invoiceRet.Other?.GetValue()
                    };
                    Console.WriteLine($"INv:{invoice.InvoiceNumber}, EditSequence: {invoice.JobNumber}");
                    requestMsgSet.ClearRequests();
                    ICustomerQuery customerQueryRq = requestMsgSet.AppendCustomerQueryRq();
                    customerQueryRq.ORCustomerListQuery.ListIDList.Add(invoiceRet.CustomerRef.ListID.GetValue());

                    //Send the request and get the response from QuickBooks
                    responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                    response       = responseMsgSet.ResponseList.GetAt(0);
                    ICustomerRetList customerRetList = (ICustomerRetList)response.Detail;
                    ICustomerRet     customerRet     = customerRetList.GetAt(0);
                    if (i > 200)
                    {
                        return;
                    }
                    invoice.Customer = new Customer
                    {
                        Name         = customerRet.Name.GetValue(),
                        QuickBooksID = customerRet.ListID.GetValue(),
                        EditSequence = customerRet.EditSequence.GetValue()
                    };
                    if (invoiceRet.ORInvoiceLineRetList != null)
                    {
                        for (int j = 0; j < invoiceRet.ORInvoiceLineRetList.Count; j++)
                        {
                            IORInvoiceLineRet ORInvoiceLineRet = invoiceRet.ORInvoiceLineRetList.GetAt(j);

                            try
                            {
                                var invoiceItem = new InvoiceItem
                                {
                                    Amount       = ORInvoiceLineRet.InvoiceLineRet.Amount.GetValue(),
                                    QuickBooksID = ORInvoiceLineRet.InvoiceLineRet.TxnLineID.GetValue()
                                };


                                requestMsgSet.ClearRequests();
                                IItemQuery itemQueryRq = requestMsgSet.AppendItemQueryRq();
                                itemQueryRq.ORListQuery.ListIDList.Add(ORInvoiceLineRet.InvoiceLineRet.ItemRef.ListID.GetValue());

                                //Send the request and get the response from QuickBooks
                                responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                                response       = responseMsgSet.ResponseList.GetAt(0);
                                IORItemRetList itemRetList = (IORItemRetList)response.Detail;
                                IORItemRet     itemRet     = itemRetList.GetAt(0);

                                if (itemRet.ItemInventoryRet != null)
                                {
                                    IItemInventoryRet itemInventoryRet = itemRet.ItemInventoryRet;

                                    var item = new Item
                                    {
                                        Name        = itemInventoryRet.Name.GetValue(),
                                        Description = itemInventoryRet.SalesDesc.GetValue(),
                                        Rate        = itemInventoryRet.SalesPrice.GetValue(),
                                        //ItemType = ItemType.Inventory,
                                        QuickBooksID = itemInventoryRet.ListID.GetValue(),
                                        EditSequence = itemInventoryRet.EditSequence.GetValue()
                                    };

                                    invoiceItem.Item = item;
                                }
                                else if (itemRet.ItemServiceRet != null)
                                {
                                    IItemServiceRet itemServiceRet = itemRet.ItemServiceRet;

                                    var item = new Item
                                    {
                                        Name        = itemServiceRet.Name.GetValue(),
                                        Description = itemServiceRet.ORSalesPurchase.SalesOrPurchase.Desc.GetValue(),
                                        Rate        = itemServiceRet.ORSalesPurchase.SalesOrPurchase.ORPrice.Price.GetValue(),
                                        //ItemType = ItemType.Service,
                                        QuickBooksID = itemServiceRet.ListID.GetValue(),
                                        EditSequence = itemServiceRet.EditSequence.GetValue()
                                    };

                                    invoiceItem.Item = item;
                                }

                                invoice.InvoiceItems.Add(invoiceItem);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(invoice.Customer.Name);
                                throw;
                            }
                        }
                    }

                    invoices.Add(invoice);
                }
            }
        }
예제 #20
0
        public IList <Invoice> GetInvoiceDetail(DateTime fromDate, DateTime toDate)
        {
            bool             sessionBegun   = false;
            QBSessionManager sessionManager = null;
            var invoices = new List <Invoice>();

            sessionManager = new QBSessionManager();
            IMsgSetRequest requestMsgSet = null;


            try
            {
                //Connect to QuickBooks and begin a session
                sessionManager.OpenConnection("", "GenerateInvoiceSummary");
                //connectionOpen = true;
                sessionManager.BeginSession("", ENOpenMode.omDontCare);
                sessionBegun = true;

                //Create the message set request object to hold our request
                requestMsgSet = sessionManager.CreateMsgSetRequest("US", 13, 0);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                IInvoiceQuery invoiceQueryRq = requestMsgSet.AppendInvoiceQueryRq();
                // all invoices modified in the month of August 2016
                // get all invoices for the month of august 2016
                invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.FromTxnDate.SetValue(fromDate);
                invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.ToTxnDate.SetValue(toDate);

                // invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.FromModifiedDate.SetValue(new DateTime(2017, 12, 1), true);
                // invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.ToModifiedDate.SetValue(new DateTime(2017, 12, 31), true);
                invoiceQueryRq.IncludeLineItems.SetValue(true);


                //Send the request and get the response from QuickBooks
                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                IResponse       response       = responseMsgSet.ResponseList.GetAt(0);
                IInvoiceRetList invoiceRetList = (IInvoiceRetList)response.Detail;
                Console.WriteLine($"Invoices found: {invoiceRetList.Count}");

                if (invoiceRetList != null)
                {
                    for (int i = 0; i < invoiceRetList.Count; i++)
                    {
                        IInvoiceRet invoiceRet = invoiceRetList.GetAt(i);

                        var invoice = new Invoice
                        {
                            QuickBooksID  = invoiceRet.TxnID.GetValue(),
                            EditSequence  = invoiceRet.EditSequence.GetValue(),
                            InvoiceNumber = invoiceRet.RefNumber?.GetValue(),
                            InvoiceDate   = invoiceRet.TimeCreated?.GetValue(),
                            Memo          = invoiceRet.Memo?.GetValue(),
                            JobNumber     = invoiceRet.Other?.GetValue(),
                            CustomerName  = invoiceRet.CustomerRef.FullName?.GetValue(),
                            Amount        = invoiceRet.BalanceRemaining?.GetValue()
                        };
                        if (invoice.Amount == 0)
                        {
                            invoice.Amount = invoiceRet.Subtotal?.GetValue();
                        }
                        var customerListId = invoiceRet.CustomerRef?.ListID?.GetValue();
                        if (customerListId != null)
                        {
                            //  Console.WriteLine($"{i}\tInv:{invoice.InvoiceNumber}, Job: {invoice.JobNumber}, Name:{invoice.CustomerName}");
                            requestMsgSet.ClearRequests();
                            ICustomerQuery customerQueryRq = requestMsgSet.AppendCustomerQueryRq();
                            customerQueryRq.ORCustomerListQuery.ListIDList.Add(customerListId);

                            //Send the request and get the response from QuickBooks
                            responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                            response       = responseMsgSet.ResponseList.GetAt(0);

                            ICustomerRetList customerRetList = (ICustomerRetList)response.Detail;
                            ICustomerRet     customerRet     = customerRetList.GetAt(0);

                            invoice.Customer = new Customer
                            {
                                Name         = customerRet.Name?.GetValue(),
                                QuickBooksID = customerRet.ListID?.GetValue(),
                                EditSequence = customerRet.EditSequence?.GetValue(),
                                FullName     = customerRet.FullName?.GetValue(),
                                CompanyName  = customerRet.CompanyName?.GetValue(),
                            };
                            //  Console.WriteLine($"{i}\t{invoice.Customer.Name}\t{invoice.Customer.FullName}\t{invoice.Customer.CompanyName}");
                            // Console.WriteLine($"{i}\t\tInvoice detail starts");
                            if (invoiceRet.ORInvoiceLineRetList != null)
                            {
                                invoice.Description = "";

                                if (invoiceRet.ORInvoiceLineRetList.Count > 0)
                                {
                                    try
                                    {
                                        IORInvoiceLineRet orInvoiceLineRet = invoiceRet.ORInvoiceLineRetList.GetAt(1);

                                        invoice.Description = orInvoiceLineRet?.InvoiceLineRet?.Desc?.GetValue();
                                        if (string.IsNullOrEmpty(invoice.Description))
                                        {
                                            orInvoiceLineRet = invoiceRet.ORInvoiceLineRetList.GetAt(0);

                                            invoice.Description = orInvoiceLineRet?.InvoiceLineRet?.Desc?.GetValue();
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                        try
                                        {
                                            IORInvoiceLineRet orInvoiceLineRet = invoiceRet.ORInvoiceLineRetList.GetAt(0);

                                            invoice.Description = orInvoiceLineRet?.InvoiceLineRet?.Desc?.GetValue();
                                        }
                                        catch (Exception ex2)
                                        {
                                            Console.WriteLine(ex2.Message);
                                        }
                                    }

                                    Console.WriteLine($"{invoice.InvoiceNumber}\t{invoice.Amount} \t{invoice.JobNumber}\t{invoice.Description}");
                                }
                                // Console.WriteLine($"InvoiceList Count: {invoiceRet.ORInvoiceLineRetList.Count}");

                                /*
                                 * for (int j = 0; j < invoiceRet.ORInvoiceLineRetList.Count; j++)
                                 * {
                                 *  IORInvoiceLineRet orInvoiceLineRet = invoiceRet.ORInvoiceLineRetList.GetAt(j);
                                 *
                                 *
                                 *  if (orInvoiceLineRet != null && orInvoiceLineRet.InvoiceLineRet != null)
                                 *  {
                                 *      var invoiceItem = new InvoiceItem
                                 *      {
                                 *          Amount = orInvoiceLineRet.InvoiceLineRet.Amount?.GetValue(),
                                 *          QuickBooksID = orInvoiceLineRet.InvoiceLineRet.TxnLineID?.GetValue()
                                 *      };
                                 *
                                 *      requestMsgSet.ClearRequests();
                                 *      IItemQuery itemQueryRq = requestMsgSet.AppendItemQueryRq();
                                 *      itemQueryRq.ORListQuery.ListIDList.Add(orInvoiceLineRet.InvoiceLineRet.ItemRef?.ListID?.GetValue());
                                 *
                                 *      //Send the request and get the response from QuickBooks
                                 *      responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                                 *      response = responseMsgSet.ResponseList.GetAt(0);
                                 *      IORItemRetList itemRetList = (IORItemRetList)response.Detail;
                                 *      // Console.WriteLine($"ItemRetList.Count: {itemRetList.Count}");
                                 *
                                 *      IORItemRet itemRet = itemRetList.GetAt(0);
                                 *      var ortype = itemRet.ortype;
                                 *      if (itemRet.ItemInventoryRet != null)
                                 *      {
                                 *          IItemInventoryRet itemInventoryRet = itemRet.ItemInventoryRet;
                                 *
                                 *          var item = new Item
                                 *          {
                                 *              Name = itemInventoryRet.Name?.GetValue(),
                                 *              Description = itemInventoryRet.SalesDesc?.GetValue(),
                                 *              Rate = itemInventoryRet.SalesPrice?.GetValue(),
                                 *              ItemType = ortype.ToString(),
                                 *              QuickBooksID = itemInventoryRet.ListID?.GetValue(),
                                 *              EditSequence = itemInventoryRet.EditSequence?.GetValue()
                                 *
                                 *          };
                                 *          if (string.IsNullOrEmpty(item.Name))
                                 *          {
                                 *              item.Name = itemInventoryRet.FullName?.GetValue();
                                 *          }
                                 *
                                 *          invoiceItem.Item = item;
                                 *      }
                                 *      else if (itemRet.ItemServiceRet != null)
                                 *      {
                                 *          IItemServiceRet itemServiceRet = itemRet.ItemServiceRet;
                                 *
                                 *          var item = new Item
                                 *          {
                                 *              Name = itemServiceRet.Name.GetValue(),
                                 *              Description = itemServiceRet.ORSalesPurchase.SalesOrPurchase.Desc?.GetValue(),
                                 *              Rate = itemServiceRet.ORSalesPurchase.SalesOrPurchase.ORPrice.Price?.GetValue(),
                                 *              //ItemType = ItemType.Service,
                                 *              ItemType = ortype.ToString(),
                                 *              QuickBooksID = itemServiceRet.ListID?.GetValue(),
                                 *              EditSequence = itemServiceRet.EditSequence?.GetValue(),
                                 *             // FullName = itemServiceRet.ToString()
                                 *              };
                                 *          if (string.IsNullOrEmpty(item.Name))
                                 *          {
                                 *              item.Name = itemServiceRet.FullName?.GetValue();
                                 *          }
                                 *          invoiceItem.Item = item;
                                 *      }
                                 *      else if (itemRet.ItemOtherChargeRet != null)
                                 *      {
                                 *          IItemOtherChargeRet itemOtherChargeRet = itemRet.ItemOtherChargeRet;
                                 *          var item = new Item
                                 *          {
                                 *              Name = itemOtherChargeRet.Name?.GetValue(),
                                 *              Description = itemOtherChargeRet.ORSalesPurchase.SalesOrPurchase.Desc?.GetValue(),
                                 *              Rate = itemOtherChargeRet.ORSalesPurchase.SalesOrPurchase.ORPrice.Price?.GetValue(),
                                 *              ItemType = ortype.ToString()
                                 *
                                 *          };
                                 *           if (string.IsNullOrEmpty(item.Name))
                                 *          {
                                 *              item.Name = itemOtherChargeRet.FullName?.GetValue();
                                 *          }
                                 *          invoiceItem.Item = item;
                                 *      }
                                 *      else if (itemRet.ItemNonInventoryRet != null)
                                 *      {
                                 *          IItemNonInventoryRet itemNonInventoryRet = itemRet.ItemNonInventoryRet;
                                 *          var item = new Item
                                 *          {
                                 *              Name = itemNonInventoryRet.Name?.GetValue(),
                                 *              Description = itemNonInventoryRet.ORSalesPurchase.SalesOrPurchase.Desc?.GetValue(),
                                 *              ItemType = ortype.ToString()
                                 *
                                 *          };
                                 *          if (string.IsNullOrEmpty(item.Name))
                                 *          {
                                 *              item.Name = itemNonInventoryRet.FullName?.GetValue();
                                 *          }
                                 *          invoiceItem.Item = item;
                                 *      }
                                 *      Console.WriteLine($"{invoiceItem.Item.FullName}\t{invoice.InvoiceNumber}\t{invoiceItem.Amount}\t{invoiceItem.Item.Description}");
                                 *      invoice.InvoiceItems.Add(invoiceItem);
                                 *
                                 *  }
                                 * }
                                 */
                            }
                        }


                        invoices.Add(invoice);
                    }
                }
                if (requestMsgSet != null)
                {
                    Marshal.FinalReleaseComObject(requestMsgSet);
                }
                sessionManager.EndSession();
                sessionBegun = false;
                sessionManager.CloseConnection();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString() + "\nStack Trace: \n" + ex.StackTrace + "\nExiting the application");
                if (requestMsgSet != null)
                {
                    Marshal.FinalReleaseComObject(requestMsgSet);
                }
                if (sessionBegun)
                {
                    sessionManager.EndSession();
                    sessionManager.CloseConnection();
                }
            }
            return(invoices);
        }