public Customer readCustomerFromCustomerRet(ICustomerRet customerRet)
 {
     Customer customer = new Customer();
     customer.Name = customerRet.Name.GetValue().ToString();
     customer.QBId = customerRet.ListID.GetValue().ToString();
     return customer;
 }
Beispiel #2
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 void modifyCustomer(ICustomerRet QBCustomer)
        {
            Console.WriteLine(QBCustomer.Name.GetValue() + ": " + QBCustomer.Email.GetValue());

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

            ICustomerMod Query = requestMsgSet.AppendCustomerModRq();

            Query.ListID.SetValue(QBCustomer.ListID.GetValue());
            Query.EditSequence.SetValue(QBCustomer.EditSequence.GetValue());
            Query.Email.SetValue("");

            IMsgSetResponse responseMsgSet = _MySessionManager.DoRequests(requestMsgSet);

            //IResponseList rsList = responseMsgSet.ResponseList;
            //IResponse response = rsList.GetAt(0);

            //ICustomerRet QBCustomer = (ICustomerRet)response.Detail;

            //if (QBCustomer == null)
            //{
            //    throw new Exception("Sorry, sales order not found.");
            //}

            //string CustomerName = QBCustomer.Name.GetValue().ToString();
            ////string email = QBCustomer.Email.GetValue();

            //Console.WriteLine(CustomerName);
        }
        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");
            }
        }
Beispiel #5
0
        private void UpdateCustomer(Quickbooks qb, ICustomerRet customer, CheckToWrite r)
        {
            List <String>  account    = new List <string>();
            IMsgSetRequest msgRequest = qb.newRequest();

            msgRequest.Attributes.OnError = ENRqOnError.roeStop;
            ICustomerMod customerMod = msgRequest.AppendCustomerModRq();

            customerMod.ListID.SetValue(customer.ListID.GetValue());
            customerMod.AccountNumber.SetValue(r.RecipientId);
            customerMod.Name.SetValue(r.FullName);
            customerMod.BillAddress.Addr1.SetValue(customerMod.Name.GetValue());
            customerMod.BillAddress.Addr2.SetValue(r.Address1);
            customerMod.BillAddress.Addr3.SetValue(r.Address2);

            customerMod.Contact.SetValue(customerMod.Name.GetValue());
            customerMod.BillAddress.City.SetValue(r.City);
            customerMod.BillAddress.State.SetValue(r.State);
            customerMod.BillAddress.PostalCode.SetValue(r.Zip);
            customerMod.EditSequence.SetValue(customer.EditSequence.GetValue());
            IMsgSetResponse response = qb.performRequest(msgRequest);

            if (response.ResponseList.GetAt(0).StatusCode != 0)
            {
                throw new Exception("Unable to update customer " + response.ResponseList.GetAt(0).StatusMessage);
            }
        }
Beispiel #6
0
        private ICustomerRet addCustomer(Quickbooks qb, CheckToWrite r)
        {
            IMsgSetRequest msgRequest = qb.newRequest();

            msgRequest.Attributes.OnError = ENRqOnError.roeStop;

            ICustomerAdd addCustomer = msgRequest.AppendCustomerAddRq();

            addCustomer.AccountNumber.SetValue(r.RecipientId);
            addCustomer.Name.SetValue(r.FullName);
            addCustomer.BillAddress.Addr1.SetValue(addCustomer.Name.GetValue());
            addCustomer.BillAddress.Addr2.SetValue(r.Address1);
            addCustomer.BillAddress.Addr3.SetValue(r.Address2);
            addCustomer.Contact.SetValue(addCustomer.Name.GetValue());
            addCustomer.BillAddress.City.SetValue(r.City);
            addCustomer.BillAddress.State.SetValue(r.State);
            addCustomer.BillAddress.PostalCode.SetValue(r.Zip);

            IMsgSetResponse response = qb.performRequest(msgRequest);

            if (response.ResponseList.GetAt(0).StatusCode == 0)
            {
                ICustomerRet result = (ICustomerRet)response.ResponseList.GetAt(0).Detail;
                return(result);
            }
            else
            {
                throw new Exception("Unable to add customer " + response.ResponseList.GetAt(0).StatusMessage);
            }
        }
        private static Customer GetCustomerFromCustomerRet(string name, ICustomerRet customerRet)
        {
            var customer = new Customer
            {
                Name                         = customerRet.FullName != null?customerRet.FullName.GetValue() : name,
                                       Phone = customerRet.Phone != null?customerRet.Phone.GetValue() : ""
            };

            if (customerRet.BillAddress != null)
            {
                customer.BillingAddress = GetAddressFromQbAddress(customerRet.BillAddress);
            }
            if (customerRet.ShipAddress != null)
            {
                customer.ShippingAddress = GetAddressFromQbAddress(customerRet.ShipAddress);
            }

            customer.ShippingAddress = customer.ShippingAddress ?? customer.BillingAddress;
            customer.BillingAddress  = customer.BillingAddress ?? customer.ShippingAddress;

            customer.ShippingAddress = customer.ShippingAddress ?? Address.Empty;
            customer.BillingAddress  = customer.BillingAddress ?? Address.Empty;

            return(customer);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
            }
        }
Beispiel #10
0
        private void button_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("", ENOpenMode.omDontCare);
                sessionBegun = true;

                ICustomerAdd customerAddRq = requestMsgSet.AppendCustomerAddRq();
                customerAddRq.Name.SetValue(Customer.Text);

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

                QuickBooksID.Text = customerRet.ListID.GetValue();
            }
            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();
                }
            }
        }
Beispiel #11
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);
    }
        private static string[,] getCustomers(IMsgSetResponse responseSet, int count)
        {
            int row = 0;

            string[,] customers = new string[count, 3];
            for (int x = 0; x < count; x++)
            {
                IResponse iresponse = responseSet.ResponseList.GetAt(x);
                if (iresponse.StatusCode == 0)
                {
                    ICustomerRet customerRet = (ICustomerRet)(iresponse.Detail) as ICustomerRet;
                    String       lookie      = customerRet.ToString();
                    customers[row, 0] = customerRet.FirstName.GetValue();
                    customers[row, 1] = customerRet.LastName.GetValue();
                    customers[row, 2] = customerRet.ListID.GetValue();
                    row++;
                }
            }
            return(customers);
        }
Beispiel #13
0
        private void WriteRefundCheck(Quickbooks qb, CheckToWrite r)
        {
            ICustomerRet customer = FindCustomer(qb, r.FullName);

            if (customer == null)
            {
                customer = addCustomer(qb, r);
            }
            else
            {
                UpdateCustomer(qb, customer, r);
            }

            IMsgSetRequest msgRequest = qb.newRequest();

            msgRequest.Attributes.OnError = ENRqOnError.roeStop;

            ICheckAdd addCheckRequest = msgRequest.AppendCheckAddRq();

            addCheckRequest.PayeeEntityRef.ListID.SetValue(customer.ListID.GetValue());

            addCheckRequest.Memo.SetValue(r.Memo);
            addCheckRequest.AccountRef.FullName.SetValue(r.QbBankAccount);
            IExpenseLineAdd expenseAdd = addCheckRequest.ExpenseLineAddList.Append();

            expenseAdd.AccountRef.FullName.SetValue(r.QbIncomeAccount);
            expenseAdd.Amount.SetValue((double)r.Amount);
            expenseAdd.Memo.SetValue(r.Memo);

            addCheckRequest.IsToBePrinted.SetValue(true);
            addCheckRequest.RefNumber.SetEmpty();

            IMsgSetResponse response = qb.performRequest(msgRequest);

            if (response.ResponseList.GetAt(0).StatusCode != 0)
            {
                throw new Exception("failed to write refund check " + response.ResponseList.GetAt(0).StatusMessage);
            }
        }
        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);
                    }
                }
            }
        }
Beispiel #15
0
        MaestroCustomer GetMaestroCustomer(ICustomerRet qbc)
        {
            MaestroCustomer result = new MaestroCustomer();

            result.Address          = ReadAddress(qbc.BillAddress);
            result.Email            = ReadString(qbc.Email);
            result.Name             = ReadString(qbc.Name);
            result.Phone            = ReadString(qbc.Phone);
            result.Region           = GetRegion(qbc.BillAddress);
            result.Title            = ReadString(qbc.JobTitle);
            result.QuickBooksId     = ReadQbId(qbc.ListID);
            result.QuickBoosCompany = ReadString(qbc.CompanyName);
            result.CreateDate       = DateTime.Now;
            result.UpdateDate       = DateTime.Now;
            result.UpdatedUser      = context.UserName;
            result.CreatedUser      = context.UserName;
            result.CustomerGroup    = qbc.CustomerTypeRef == null ? string.Empty : ReadString(qbc.CustomerTypeRef.FullName);
            result.RecordStatus     = qbc.IsActive.GetValue() ? "A" : "P";
            if (qbc.ShipToAddressList != null)
            {
                for (int i = 0; i < qbc.ShipToAddressList.Count; i++)
                {
                    StringBuilder  bld         = new StringBuilder();
                    IShipToAddress shipAddress = qbc.ShipToAddressList.GetAt(i);
                    bld.AppendLine(shipAddress.Name.GetValue());
                    bld.AppendLine(shipAddress.Addr1.GetValue());
                    bld.AppendLine(shipAddress.Addr2.GetValue());
                    bld.AppendLine(shipAddress.Addr3.GetValue());
                    bld.AppendLine(shipAddress.Addr4.GetValue());
                    bld.AppendLine(shipAddress.Addr5.GetValue());
                    bld.AppendLine(shipAddress.City.GetValue());
                    bld.AppendLine(shipAddress.PostalCode.GetValue());
                    bld.AppendLine(shipAddress.State.GetValue());
                    Console.WriteLine(bld.ToString());
                }
            }

            return(result);
        }
Beispiel #16
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
        }
Beispiel #17
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());
        }
Beispiel #18
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);
        }
        private void UpdateCustomer(Quickbooks qb, ICustomerRet customer, CheckToWrite r)
        {
            List<String> account = new List<string>();
            IMsgSetRequest msgRequest = qb.newRequest();
            msgRequest.Attributes.OnError = ENRqOnError.roeStop;
            ICustomerMod customerMod = msgRequest.AppendCustomerModRq();

            customerMod.ListID.SetValue(customer.ListID.GetValue());
            customerMod.AccountNumber.SetValue(r.RecipientId);
            customerMod.Name.SetValue(r.FullName);
            customerMod.BillAddress.Addr1.SetValue(customerMod.Name.GetValue());
            customerMod.BillAddress.Addr2.SetValue(r.Address1);
            customerMod.BillAddress.Addr3.SetValue(r.Address2);

            customerMod.Contact.SetValue(customerMod.Name.GetValue());
            customerMod.BillAddress.City.SetValue(r.City);
            customerMod.BillAddress.State.SetValue(r.State);
            customerMod.BillAddress.PostalCode.SetValue(r.Zip);
            customerMod.EditSequence.SetValue(customer.EditSequence.GetValue());
            IMsgSetResponse response = qb.performRequest(msgRequest);

            if (response.ResponseList.GetAt(0).StatusCode != 0)
                throw new Exception("Unable to update customer " + response.ResponseList.GetAt(0).StatusMessage);
        }
Beispiel #20
0
        customer FillCustomer(ICustomerRet customerRet)
        {
            var customerdal = new customer
            {
                //Go through all the elements of ICustomerRetList
                //Get value of ListID
                ID = (string)customerRet.ListID.GetValue(),
                //Get value of TimeCreated
                TimeCreated = (DateTime)customerRet.TimeCreated.GetValue(),
                //Get value of TimeModified
                TimeModified = (DateTime)customerRet.TimeModified.GetValue(),
                //Get value of EditSequence
                EditSequence = (string)customerRet.EditSequence.GetValue(),
                //Get value of Name
                Name = (string)customerRet.Name.GetValue(),
                //Get value of FullName
                FullName = (string)customerRet.FullName.GetValue()
            };

            //Get value of IsActive
            if (customerRet.IsActive != null)
            {
                customerdal.IsActive = (bool)customerRet.IsActive.GetValue();
            }
            if (customerRet.ClassRef != null)
            {
                //Get value of ListID
                if (customerRet.ClassRef.ListID != null)
                {
                    customerdal.ClassId = (string)customerRet.ClassRef.ListID.GetValue();
                }
                //Get value of FullName
                if (customerRet.ClassRef.FullName != null)
                {
                    customerdal.ClassName = (string)customerRet.ClassRef.FullName.GetValue();
                }
            }
            if (customerRet.ParentRef != null)
            {
                //Get value of ListID
                if (customerRet.ParentRef.ListID != null)
                {
                    customerdal.ParentId = (string)customerRet.ParentRef.ListID.GetValue();
                }
                //Get value of FullName
                if (customerRet.ParentRef.FullName != null)
                {
                    customerdal.ParentName = (string)customerRet.ParentRef.FullName.GetValue();
                }
            }
            //Get value of Sublevel
            customerdal.Sublevel = (int)customerRet.Sublevel.GetValue();
            //Get value of CompanyName
            if (customerRet.CompanyName != null)
            {
                customerdal.Company = (string)customerRet.CompanyName.GetValue();
            }
            //Get value of Salutation
            if (customerRet.Salutation != null)
            {
                customerdal.Salutation = (string)customerRet.Salutation.GetValue();
            }
            //Get value of FirstName
            if (customerRet.FirstName != null)
            {
                customerdal.FirstName = (string)customerRet.FirstName.GetValue();
            }
            //Get value of MiddleName
            if (customerRet.MiddleName != null)
            {
                customerdal.MiddleInitial = (string)customerRet.MiddleName.GetValue();
            }
            //Get value of LastName
            if (customerRet.LastName != null)
            {
                customerdal.LastName = (string)customerRet.LastName.GetValue();
            }
            ////Get value of JobTitle
            //if (customerRet.JobTitle != null)
            //{
            //    customerdal.JobTitle = (string)customerRet.JobTitle.GetValue();
            //}
            if (customerRet.BillAddress != null)
            {
                //Get value of Addr1
                if (customerRet.BillAddress.Addr1 != null)
                {
                    customerdal.BillingLine1 = (string)customerRet.BillAddress.Addr1.GetValue();
                }
                //Get value of Addr2
                if (customerRet.BillAddress.Addr2 != null)
                {
                    customerdal.BillingLine2 = (string)customerRet.BillAddress.Addr2.GetValue();
                }
                //Get value of Addr3
                if (customerRet.BillAddress.Addr3 != null)
                {
                    customerdal.BillingLine3 = (string)customerRet.BillAddress.Addr3.GetValue();
                }
                //Get value of Addr4
                if (customerRet.BillAddress.Addr4 != null)
                {
                    customerdal.BillingLine4 = (string)customerRet.BillAddress.Addr4.GetValue();
                }
                //Get value of Addr5
                if (customerRet.BillAddress.Addr5 != null)
                {
                    customerdal.BillingLine5 = (string)customerRet.BillAddress.Addr5.GetValue();
                }
                //Get value of City
                if (customerRet.BillAddress.City != null)
                {
                    customerdal.BillingCity = (string)customerRet.BillAddress.City.GetValue();
                }
                //Get value of State
                if (customerRet.BillAddress.State != null)
                {
                    customerdal.BillingState = (string)customerRet.BillAddress.State.GetValue();
                }
                //Get value of PostalCode
                if (customerRet.BillAddress.PostalCode != null)
                {
                    customerdal.BillingPostalCode = (string)customerRet.BillAddress.PostalCode.GetValue();
                }
                //Get value of Country
                if (customerRet.BillAddress.Country != null)
                {
                    customerdal.BillingCountry = (string)customerRet.BillAddress.Country.GetValue();
                }
                //Get value of Note
                if (customerRet.BillAddress.Note != null)
                {
                    customerdal.BillingNote = (string)customerRet.BillAddress.Note.GetValue();
                }
            }
            //if (customerRet.BillAddressBlock != null)
            //{
            //    //Get value of Addr1
            //    if (customerRet.BillAddressBlock.Addr1 != null)
            //    {
            //        customerdal.Addr1 = (string)customerRet.BillAddressBlock.Addr1.GetValue();
            //    }
            //    //Get value of Addr2
            //    if (customerRet.BillAddressBlock.Addr2 != null)
            //    {
            //        customerdal.Addr2 = (string)customerRet.BillAddressBlock.Addr2.GetValue();
            //    }
            //    //Get value of Addr3
            //    if (customerRet.BillAddressBlock.Addr3 != null)
            //    {
            //        customerdal.Addr3 = (string)customerRet.BillAddressBlock.Addr3.GetValue();
            //    }
            //    //Get value of Addr4
            //    if (customerRet.BillAddressBlock.Addr4 != null)
            //    {
            //        customerdal.Addr4 = (string)customerRet.BillAddressBlock.Addr4.GetValue();
            //    }
            //    //Get value of Addr5
            //    if (customerRet.BillAddressBlock.Addr5 != null)
            //    {
            //        customerdal.Addr5 = (string)customerRet.BillAddressBlock.Addr5.GetValue();
            //    }
            //}
            if (customerRet.ShipAddress != null)
            {
                //Get value of Addr1
                if (customerRet.ShipAddress.Addr1 != null)
                {
                    customerdal.ShippingLine1 = (string)customerRet.ShipAddress.Addr1.GetValue();
                }
                //Get value of Addr2
                if (customerRet.ShipAddress.Addr2 != null)
                {
                    customerdal.ShippingLine2 = (string)customerRet.ShipAddress.Addr2.GetValue();
                }
                //Get value of Addr3
                if (customerRet.ShipAddress.Addr3 != null)
                {
                    customerdal.ShippingLine3 = (string)customerRet.ShipAddress.Addr3.GetValue();
                }
                //Get value of Addr4
                if (customerRet.ShipAddress.Addr4 != null)
                {
                    customerdal.ShippingLine4 = (string)customerRet.ShipAddress.Addr4.GetValue();
                }
                //Get value of Addr5
                if (customerRet.ShipAddress.Addr5 != null)
                {
                    customerdal.ShippingLine5 = (string)customerRet.ShipAddress.Addr5.GetValue();
                }
                //Get value of City
                if (customerRet.ShipAddress.City != null)
                {
                    customerdal.ShippingCity = (string)customerRet.ShipAddress.City.GetValue();
                }
                //Get value of State
                if (customerRet.ShipAddress.State != null)
                {
                    customerdal.ShippingState = (string)customerRet.ShipAddress.State.GetValue();
                }
                //Get value of PostalCode
                if (customerRet.ShipAddress.PostalCode != null)
                {
                    customerdal.ShippingPostalCode = (string)customerRet.ShipAddress.PostalCode.GetValue();
                }
                //Get value of Country
                if (customerRet.ShipAddress.Country != null)
                {
                    customerdal.ShippingCountry = (string)customerRet.ShipAddress.Country.GetValue();
                }
                //Get value of Note
                if (customerRet.ShipAddress.Note != null)
                {
                    customerdal.ShippingNote = (string)customerRet.ShipAddress.Note.GetValue();
                }
            }
            //if (customerRet.ShipAddressBlock != null)
            //{
            //    //Get value of Addr1
            //    if (customerRet.ShipAddressBlock.Addr1 != null)
            //    {
            //        customerdal.Addr1 = (string)customerRet.ShipAddressBlock.Addr1.GetValue();
            //    }
            //    //Get value of Addr2
            //    if (customerRet.ShipAddressBlock.Addr2 != null)
            //    {
            //        customerdal.Addr2 = (string)customerRet.ShipAddressBlock.Addr2.GetValue();
            //    }
            //    //Get value of Addr3
            //    if (customerRet.ShipAddressBlock.Addr3 != null)
            //    {
            //        customerdal.Addr3 = (string)customerRet.ShipAddressBlock.Addr3.GetValue();
            //    }
            //    //Get value of Addr4
            //    if (customerRet.ShipAddressBlock.Addr4 != null)
            //    {
            //        customerdal.Addr4 = (string)customerRet.ShipAddressBlock.Addr4.GetValue();
            //    }
            //    //Get value of Addr5
            //    if (customerRet.ShipAddressBlock.Addr5 != null)
            //    {
            //        customerdal.Addr5 = (string)customerRet.ShipAddressBlock.Addr5.GetValue();
            //    }
            //}
            //if (customerRet.ShipToAddressList != null)
            //{
            //    for (int i = 0; i < customerRet.ShipToAddressList.Count; i++)
            //    {
            //        IShipToAddress ShipToAddress = customerRet.ShipToAddressList.GetAt(i);
            //        //Get value of Name
            //        customerdal.Name = (string)ShipToAddress.Name.GetValue();
            //        //Get value of Addr1
            //        if (ShipToAddress.Addr1 != null)
            //        {
            //            customerdal.ShippingLine1 = (string)ShipToAddress.Addr1.GetValue();
            //        }
            //        //Get value of Addr2
            //        if (ShipToAddress.Addr2 != null)
            //        {
            //            customerdal.ShippingLine2 = (string)ShipToAddress.Addr2.GetValue();
            //        }
            //        //Get value of Addr3
            //        if (ShipToAddress.Addr3 != null)
            //        {
            //            customerdal.ShippingLine3 = (string)ShipToAddress.Addr3.GetValue();
            //        }
            //        //Get value of Addr4
            //        if (ShipToAddress.Addr4 != null)
            //        {
            //            customerdal.ShippingLine4 = (string)ShipToAddress.Addr4.GetValue();
            //        }
            //        //Get value of Addr5
            //        if (ShipToAddress.Addr5 != null)
            //        {
            //            customerdal.ShippingLine5 = (string)ShipToAddress.Addr5.GetValue();
            //        }
            //        //Get value of City
            //        if (ShipToAddress.City != null)
            //        {
            //            customerdal.ShippingCity = (string)ShipToAddress.City.GetValue();
            //        }
            //        //Get value of State
            //        if (ShipToAddress.State != null)
            //        {
            //            customerdal.ShippingState = (string)ShipToAddress.State.GetValue();
            //        }
            //        //Get value of PostalCode
            //        if (ShipToAddress.PostalCode != null)
            //        {
            //            customerdal.ShippingPostalCode = (string)ShipToAddress.PostalCode.GetValue();
            //        }
            //        //Get value of Country
            //        if (ShipToAddress.Country != null)
            //        {
            //            customerdal.Country = (string)ShipToAddress.Country.GetValue();
            //        }
            //        //Get value of Note
            //        if (ShipToAddress.Note != null)
            //        {
            //            customerdal.ShippingNote = (string)ShipToAddress.Note.GetValue();
            //        }
            ////Get value of DefaultShipTo
            //if (ShipToAddress.DefaultShipTo != null)
            //{
            //    customerdal.DefaultShipTo = (bool)ShipToAddress.DefaultShipTo.GetValue();
            //}
            //}
            //}
            //Get value of Phone
            if (customerRet.Phone != null)
            {
                customerdal.Phone = (string)customerRet.Phone.GetValue();
            }
            //Get value of AltPhone
            if (customerRet.AltPhone != null)
            {
                customerdal.AlternatePhone = (string)customerRet.AltPhone.GetValue();
            }
            //Get value of Fax
            if (customerRet.Fax != null)
            {
                customerdal.Fax = (string)customerRet.Fax.GetValue();
            }
            //Get value of Email
            if (customerRet.Email != null)
            {
                customerdal.Email = (string)customerRet.Email.GetValue();
            }
            //Get value of Cc
            if (customerRet.Cc != null)
            {
                customerdal.Cc = (string)customerRet.Cc.GetValue();
            }
            //Get value of Contact
            if (customerRet.Contact != null)
            {
                customerdal.Contact = (string)customerRet.Contact.GetValue();
            }
            //Get value of AltContact
            if (customerRet.AltContact != null)
            {
                customerdal.AlternateContact = (string)customerRet.AltContact.GetValue();
            }
            //if (customerRet.AdditionalContactRefList != null)
            //{
            //    for (int i = 0; i < customerRet.AdditionalContactRefList.Count; i++)
            //    {
            //        IQBBaseRef QBBaseRef = customerRet.AdditionalContactRefList.GetAt(i);
            //        //Get value of ContactName
            //        customerdal.ContactName = (string)QBBaseRef.ContactName.GetValue();
            //        //Get value of ContactValue
            //        customerdal.ContactValue = (string)QBBaseRef.ContactValue.GetValue();
            //    }
            //}
            //if (customerRet.ContactsRetList != null)
            //{
            //    for (int i = 0; i < customerRet.ContactsRetList.Count; i++)
            //    {
            //        IContactsRet ContactsRet = customerRet.ContactsRetList.GetAt(i);
            //        //Get value of ListID
            //        customerdal.ListID = (string)ContactsRet.ListID.GetValue();
            //        //Get value of TimeCreated
            //        customerdal.TimeCreated = (DateTime)ContactsRet.TimeCreated.GetValue();
            //        //Get value of TimeModified
            //        customerdal.TimeModified = (DateTime)ContactsRet.TimeModified.GetValue();
            //        //Get value of EditSequence
            //        customerdal.EditSequence = (string)ContactsRet.EditSequence.GetValue();
            //        //Get value of Contact
            //        if (ContactsRet.Contact != null)
            //        {
            //            customerdal.Contact = (string)ContactsRet.Contact.GetValue();
            //        }
            //        //Get value of Salutation
            //        if (ContactsRet.Salutation != null)
            //        {
            //            customerdal.Salutation = (string)ContactsRet.Salutation.GetValue();
            //        }
            //        //Get value of FirstName
            //        customerdal.FirstName = (string)ContactsRet.FirstName.GetValue();
            //        //Get value of MiddleName
            //        if (ContactsRet.MiddleName != null)
            //        {
            //            customerdal.MiddleName = (string)ContactsRet.MiddleName.GetValue();
            //        }
            //        //Get value of LastName
            //        if (ContactsRet.LastName != null)
            //        {
            //            customerdal.LastName = (string)ContactsRet.LastName.GetValue();
            //        }
            //        ////Get value of JobTitle
            //        //if (ContactsRet.JobTitle != null)
            //        //{
            //        //    customerdal.JobTitle = (string)ContactsRet.JobTitle.GetValue();
            //        //}
            //        if (ContactsRet.AdditionalContactRefList != null)
            //        {
            //            for (int i = 0; i < ContactsRet.AdditionalContactRefList.Count; i++)
            //            {
            //                IQBBaseRef QBBaseRef = ContactsRet.AdditionalContactRefList.GetAt(i);
            //                //Get value of ContactName
            //                customerdal.ContactName = (string)QBBaseRef.ContactName.GetValue();
            //                //Get value of ContactValue
            //                customerdal.ContactValue = (string)QBBaseRef.ContactValue.GetValue();
            //            }
            //        }
            //    }
            //}
            if (customerRet.CustomerTypeRef != null)
            {
                //Get value of ListID
                if (customerRet.CustomerTypeRef.ListID != null)
                {
                    customerdal.TypeId = (string)customerRet.CustomerTypeRef.ListID.GetValue();
                }
                //Get value of FullName
                if (customerRet.CustomerTypeRef.FullName != null)
                {
                    customerdal.Type = (string)customerRet.CustomerTypeRef.FullName.GetValue();
                }
            }
            if (customerRet.TermsRef != null)
            {
                //Get value of ListID
                if (customerRet.TermsRef.ListID != null)
                {
                    customerdal.TermsId = (string)customerRet.TermsRef.ListID.GetValue();
                }
                //Get value of FullName
                if (customerRet.TermsRef.FullName != null)
                {
                    customerdal.Terms = (string)customerRet.TermsRef.FullName.GetValue();
                }
            }
            if (customerRet.SalesRepRef != null)
            {
                //Get value of ListID
                if (customerRet.SalesRepRef.ListID != null)
                {
                    customerdal.SalesRepId = (string)customerRet.SalesRepRef.ListID.GetValue();
                }
                //Get value of FullName
                if (customerRet.SalesRepRef.FullName != null)
                {
                    customerdal.SalesRep = (string)customerRet.SalesRepRef.FullName.GetValue();
                }
            }
            //Get value of Balance
            if (customerRet.Balance != null)
            {
                customerdal.Balance = (double)customerRet.Balance.GetValue();
            }
            //Get value of TotalBalance
            //if (customerRet.TotalBalance != null)
            //{
            //    customerdal.TotalBalance = (double)customerRet.TotalBalance.GetValue();
            //}
            if (customerRet.SalesTaxCodeRef != null)
            {
                //Get value of ListID
                if (customerRet.SalesTaxCodeRef.ListID != null)
                {
                    customerdal.TaxCodeId = (string)customerRet.SalesTaxCodeRef.ListID.GetValue();
                }
                //Get value of FullName
                if (customerRet.SalesTaxCodeRef.FullName != null)
                {
                    customerdal.TaxCode = (string)customerRet.SalesTaxCodeRef.FullName.GetValue();
                }
            }
            if (customerRet.ItemSalesTaxRef != null)
            {
                //Get value of ListID
                if (customerRet.ItemSalesTaxRef.ListID != null)
                {
                    customerdal.TaxItemId = (string)customerRet.ItemSalesTaxRef.ListID.GetValue();
                }
                //Get value of FullName
                if (customerRet.ItemSalesTaxRef.FullName != null)
                {
                    customerdal.TaxItem = (string)customerRet.ItemSalesTaxRef.FullName.GetValue();
                }
            }
            //Get value of ResaleNumber
            if (customerRet.ResaleNumber != null)
            {
                customerdal.ResaleNumber = (string)customerRet.ResaleNumber.GetValue();
            }
            //Get value of AccountNumber
            if (customerRet.AccountNumber != null)
            {
                customerdal.AccountNumber = (string)customerRet.AccountNumber.GetValue();
            }
            //Get value of CreditLimit
            if (customerRet.CreditLimit != null)
            {
                customerdal.CreditLimit = (double)customerRet.CreditLimit.GetValue();
            }
            if (customerRet.PreferredPaymentMethodRef != null)
            {
                //Get value of ListID
                if (customerRet.PreferredPaymentMethodRef.ListID != null)
                {
                    customerdal.PreferredPaymentMethodId = (string)customerRet.PreferredPaymentMethodRef.ListID.GetValue();
                }
                //Get value of FullName
                if (customerRet.PreferredPaymentMethodRef.FullName != null)
                {
                    customerdal.PreferredPaymentMethodName = (string)customerRet.PreferredPaymentMethodRef.FullName.GetValue();
                }
            }
            if (customerRet.CreditCardInfo != null)
            {
                //Get value of CreditCardNumber
                if (customerRet.CreditCardInfo.CreditCardNumber != null)
                {
                    customerdal.CreditCardNumber = (string)customerRet.CreditCardInfo.CreditCardNumber.GetValue();
                }
                //Get value of ExpirationMonth
                if (customerRet.CreditCardInfo.ExpirationMonth != null)
                {
                    customerdal.CreditCardExpMonth = (int)customerRet.CreditCardInfo.ExpirationMonth.GetValue();
                }
                //Get value of ExpirationYear
                if (customerRet.CreditCardInfo.ExpirationYear != null)
                {
                    customerdal.CreditCardExpYear = (int)customerRet.CreditCardInfo.ExpirationYear.GetValue();
                }
                //Get value of NameOnCard
                if (customerRet.CreditCardInfo.NameOnCard != null)
                {
                    customerdal.CreditCardNameOnCard = (string)customerRet.CreditCardInfo.NameOnCard.GetValue();
                }
                //Get value of CreditCardAddress
                if (customerRet.CreditCardInfo.CreditCardAddress != null)
                {
                    customerdal.CreditCardAddress = (string)customerRet.CreditCardInfo.CreditCardAddress.GetValue();
                }
                //Get value of CreditCardPostalCode
                if (customerRet.CreditCardInfo.CreditCardPostalCode != null)
                {
                    customerdal.CreditCardPostalCode = (string)customerRet.CreditCardInfo.CreditCardPostalCode.GetValue();
                }
            }
            //Get value of JobStatus
            if (customerRet.JobStatus != null)
            {
                ENJobStatus JobStatus = (ENJobStatus)customerRet.JobStatus.GetValue();
            }
            //Get value of JobStartDate
            if (customerRet.JobStartDate != null)
            {
                customerdal.JobStartDate = (DateTime)customerRet.JobStartDate.GetValue();
            }
            //Get value of JobProjectedEndDate
            if (customerRet.JobProjectedEndDate != null)
            {
                customerdal.JobProjectedEndDate = (DateTime)customerRet.JobProjectedEndDate.GetValue();
            }
            //Get value of JobEndDate
            if (customerRet.JobEndDate != null)
            {
                customerdal.JobEndDate = (DateTime)customerRet.JobEndDate.GetValue();
            }
            //Get value of JobDesc
            if (customerRet.JobDesc != null)
            {
                customerdal.JobDescription = (string)customerRet.JobDesc.GetValue();
            }
            if (customerRet.JobTypeRef != null)
            {
                //Get value of ListID
                if (customerRet.JobTypeRef.ListID != null)
                {
                    customerdal.JobTypeId = (string)customerRet.JobTypeRef.ListID.GetValue();
                }
                //Get value of FullName
                if (customerRet.JobTypeRef.FullName != null)
                {
                    customerdal.JobType = (string)customerRet.JobTypeRef.FullName.GetValue();
                }
            }
            //Get value of Notes
            if (customerRet.Notes != null)
            {
                customerdal.Notes = (string)customerRet.Notes.GetValue();
            }
            //if (customerRet.AdditionalNotesRetList != null)
            //{
            //    for (int i = 0; i < customerRet.AdditionalNotesRetList.Count; i++)
            //    {
            //        IAdditionalNotesRet AdditionalNotesRet = customerRet.AdditionalNotesRetList.GetAt(i121);
            //        //Get value of NoteID
            //        customerdal.NoteID = (int)AdditionalNotesRet.NoteID.GetValue();
            //        //Get value of Date
            //        customerdal.Date = (DateTime)AdditionalNotesRet.Date.GetValue();
            //        //Get value of Note
            //        customerdal.Note = (string)AdditionalNotesRet.Note.GetValue();
            //    }
            //}
            //Get value of PreferredDeliveryMethod
            if (customerRet.PreferredDeliveryMethod != null)
            {
                customerdal.PreferredDeliveryMethod = customerRet.PreferredDeliveryMethod.ToString();
            }
            if (customerRet.PriceLevelRef != null)
            {
                //Get value of ListID
                if (customerRet.PriceLevelRef.ListID != null)
                {
                    customerdal.PriceLevelId = (string)customerRet.PriceLevelRef.ListID.GetValue();
                }
                //Get value of FullName
                if (customerRet.PriceLevelRef.FullName != null)
                {
                    customerdal.PriceLevel = (string)customerRet.PriceLevelRef.FullName.GetValue();
                }
            }
            ////Get value of ExternalGUID
            //if (customerRet.ExternalGUID != null)
            //{
            //    customerdal.ExternalGUID = (string)customerRet.ExternalGUID.GetValue();
            //}
            if (customerRet.CurrencyRef != null)
            {
                //Get value of ListID
                if (customerRet.CurrencyRef.ListID != null)
                {
                    customerdal.CurrencyId = (string)customerRet.CurrencyRef.ListID.GetValue();
                }
                //Get value of FullName
                if (customerRet.CurrencyRef.FullName != null)
                {
                    customerdal.CurrencyName = (string)customerRet.CurrencyRef.FullName.GetValue();
                }
            }
            //if (customerRet.DataExtRetList != null)
            //{
            //    for (int i = 0; i < customerRet.DataExtRetList.Count; i++)
            //    {
            //        IDataExtRet DataExtRet = customerRet.DataExtRetList.GetAt(i131);
            //        //Get value of OwnerID
            //        if (DataExtRet.OwnerID != null)
            //        {
            //            customerdal.OwnerID = (string)DataExtRet.OwnerID.GetValue();
            //        }
            //        //Get value of DataExtName
            //        customerdal.DataExtName = (string)DataExtRet.DataExtName.GetValue();
            //        //Get value of DataExtType
            //        ENDataExtType DataExtType = (ENDataExtType)DataExtRet.DataExtType.GetValue();
            //        //Get value of DataExtValue
            //        customerdal.DataExtValue = (string)DataExtRet.DataExtValue.GetValue();
            //    }
            //}

            return(customerdal);
        }
Beispiel #21
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();
                }
            }
        }
Beispiel #22
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);
        }
        public string createCustomer(Customer customer)
        {
            requestMsgSet.ClearRequests();
            ICustomerAdd CustomerAddRq = requestMsgSet.AppendCustomerAddRq();

            //if (!string.IsNullOrEmpty(customer.Parent))
            //  CustomerAddRq.ParentRef.FullName.SetValue(customer.Parent);
            CustomerAddRq.Name.SetValue(customer.Name);
            CustomerAddRq.MiddleName.SetValue(customer.MiddleName);
            CustomerAddRq.AccountNumber.SetValue(customer.AccountNumber);
            CustomerAddRq.OpenBalance.SetValue(customer.OpeningBalance);
            CustomerAddRq.OpenBalanceDate.SetValue(customer.OpeningDate);
            CustomerAddRq.IsActive.SetValue(customer.isActive);
            CustomerAddRq.BillAddress.Addr1.SetValue(customer.BillAddress1);
            CustomerAddRq.BillAddress.Addr2.SetValue(customer.BillAddress2);
            CustomerAddRq.BillAddress.Addr3.SetValue(customer.BillAddress3);
            CustomerAddRq.BillAddress.Addr4.SetValue(customer.BillAddress4);
            //CustomerAddRq.BillAddress.Addr5.SetValue(customer.BillAddress5);
            CustomerAddRq.BillAddress.City.SetValue(customer.BillCity);
            CustomerAddRq.BillAddress.State.SetValue(customer.BillState);
            CustomerAddRq.BillAddress.PostalCode.SetValue(customer.BillPostcode);
            CustomerAddRq.BillAddress.Country.SetValue(customer.BillCounty);
            CustomerAddRq.Phone.SetValue(customer.Phone);
            CustomerAddRq.Email.SetValue(customer.Email);
            CustomerAddRq.Fax.SetValue(customer.Fax);
            CustomerAddRq.Pager.SetValue(customer.Pager);
            CustomerAddRq.Contact.SetValue(customer.Contact);
            CustomerAddRq.AltContact.SetValue(customer.AltContact);
            CustomerAddRq.AltPhone.SetValue(customer.AltPhone);
            CustomerAddRq.CreditCardInfo.CreditCardAddress.SetValue(customer.CreditCardAddress);
            CustomerAddRq.CreditCardInfo.CreditCardNumber.SetValue(customer.CreditCardNumber);
            CustomerAddRq.CreditCardInfo.CreditCardPostalCode.SetValue(customer.CreditCardPostalCode);
            if (customer.ExpirationMonth >= 1)
            {
                CustomerAddRq.CreditCardInfo.ExpirationMonth.SetValue(customer.ExpirationMonth);
            }
            if (customer.ExpirationYear >= 1)
            {
                CustomerAddRq.CreditCardInfo.ExpirationYear.SetValue(customer.ExpirationYear);
            }
            CustomerAddRq.CreditCardInfo.NameOnCard.SetValue(customer.NameOnCard);
            CustomerAddRq.Salutation.SetValue(customer.Salutation);
            CustomerAddRq.ShipAddress.Addr1.SetValue(customer.ShipAddress1);
            CustomerAddRq.ShipAddress.Addr2.SetValue(customer.ShipAddress2);
            CustomerAddRq.ShipAddress.Addr3.SetValue(customer.ShipAddress3);
            CustomerAddRq.ShipAddress.Addr4.SetValue(customer.ShipAddress4);

            CustomerAddRq.ShipAddress.City.SetValue(customer.ShipCity);
            CustomerAddRq.ShipAddress.Country.SetValue(customer.ShipCountry);
            CustomerAddRq.Notes.SetValue(customer.Note);
            CustomerAddRq.JobDesc.SetValue(customer.JobDesc);


            //------------------------- Customer Fields Need to be added
            if (customer.SalesRepRef_FullName != null)
            {
                CustomerAddRq.SalesRepRef.FullName.SetValue(customer.SalesRepRef_FullName);
            }
            if (customer.ResaleNumber != null)
            {
                CustomerAddRq.ResaleNumber.SetValue(customer.ResaleNumber);
            }

            if (customer.TermsRef_FullName != null)
            {
                CustomerAddRq.TermsRef.FullName.SetValue(customer.TermsRef_FullName);
            }
            if (customer.Preferd_PaymentMethod_FullName != null)
            {
                CustomerAddRq.PreferredPaymentMethodRef.FullName.SetValue(customer.Preferd_PaymentMethod_FullName);
            }

            responseMsgSet = sessionManager.DoRequests(requestMsgSet);

            if (responseMsgSet.ResponseList.GetAt(0).StatusCode == 0)
            {
                IResponse response = responseMsgSet.ResponseList.GetAt(0);

                //the request-specific response is in the details, make sure we have some
                if (response.Detail != null)
                {
                    //make sure the response is the type we're expecting
                    ENResponseType responseType = (ENResponseType)response.Type.GetValue();
                    if (responseType == ENResponseType.rtCustomerAddRs)
                    {
                        //upcast to more specific type here, this is safe because we checked with response.Type check above
                        ICustomerRet CustomerRet = (ICustomerRet)response.Detail;
                        if (CustomerRet != null)
                        {
                            return(CustomerRet.ListID.GetValue());
                        }
                    }
                }
                return("-1");
            }
            else
            {
                throw new QBException(responseMsgSet.ResponseList.GetAt(0).StatusCode, "QBEngine :" + responseMsgSet.ResponseList.GetAt(0).StatusMessage, requestMsgSet.ToXMLString());
                return("-1");
            }
        }
Beispiel #24
0
        void WalkCustomerRet(ICustomerRet CustomerRet)
        {
            if (CustomerRet == null)
            {
                return;
            }
            if (CustomerRet.ShipToAddressList == null)
            {
                return;
            }
            //Go through all the elements of ICustomerRetList
            //Get value of ListID
            string ListID5 = (string)CustomerRet.ListID.GetValue();
            //Get value of TimeCreated
            DateTime TimeCreated6 = (DateTime)CustomerRet.TimeCreated.GetValue();
            //Get value of TimeModified
            DateTime TimeModified7 = (DateTime)CustomerRet.TimeModified.GetValue();
            //Get value of EditSequence
            string EditSequence8 = (string)CustomerRet.EditSequence.GetValue();
            //Get value of Name
            string Name9 = (string)CustomerRet.Name.GetValue();
            //Get value of FullName
            string FullName10 = (string)CustomerRet.FullName.GetValue();

            //Get value of IsActive

            if (CustomerRet.IsActive != null)
            {
                bool IsActive11 = (bool)CustomerRet.IsActive.GetValue();
            }
            if (CustomerRet.ClassRef != null)
            {
                //Get value of ListID
                if (CustomerRet.ClassRef.ListID != null)
                {
                    string ListID12 = (string)CustomerRet.ClassRef.ListID.GetValue();
                }
                //Get value of FullName
                if (CustomerRet.ClassRef.FullName != null)
                {
                    string FullName13 = (string)CustomerRet.ClassRef.FullName.GetValue();
                }
            }
            if (CustomerRet.ParentRef != null)
            {
                //Get value of ListID
                if (CustomerRet.ParentRef.ListID != null)
                {
                    string ListID14 = (string)CustomerRet.ParentRef.ListID.GetValue();
                }
                //Get value of FullName
                if (CustomerRet.ParentRef.FullName != null)
                {
                    string FullName15 = (string)CustomerRet.ParentRef.FullName.GetValue();
                }
            }
            //Get value of Sublevel
            int Sublevel16 = (int)CustomerRet.Sublevel.GetValue();

            //Get value of CompanyName
            if (CustomerRet.CompanyName != null)
            {
                string CompanyName17 = (string)CustomerRet.CompanyName.GetValue();
            }
            //Get value of Salutation
            if (CustomerRet.Salutation != null)
            {
                string Salutation18 = (string)CustomerRet.Salutation.GetValue();
            }
            //Get value of FirstName
            if (CustomerRet.FirstName != null)
            {
                string FirstName19 = (string)CustomerRet.FirstName.GetValue();
            }
            //Get value of MiddleName
            if (CustomerRet.MiddleName != null)
            {
                string MiddleName20 = (string)CustomerRet.MiddleName.GetValue();
            }
            //Get value of LastName
            if (CustomerRet.LastName != null)
            {
                string LastName21 = (string)CustomerRet.LastName.GetValue();
            }
            //Get value of JobTitle
            if (CustomerRet.JobTitle != null)
            {
                string JobTitle22 = (string)CustomerRet.JobTitle.GetValue();
            }
            if (CustomerRet.BillAddress != null)
            {
                //Get value of Addr1
                if (CustomerRet.BillAddress.Addr1 != null)
                {
                    string Addr123 = (string)CustomerRet.BillAddress.Addr1.GetValue();
                }
                //Get value of Addr2
                if (CustomerRet.BillAddress.Addr2 != null)
                {
                    string Addr224 = (string)CustomerRet.BillAddress.Addr2.GetValue();
                }
                //Get value of Addr3
                if (CustomerRet.BillAddress.Addr3 != null)
                {
                    string Addr325 = (string)CustomerRet.BillAddress.Addr3.GetValue();
                }
                //Get value of Addr4
                if (CustomerRet.BillAddress.Addr4 != null)
                {
                    string Addr426 = (string)CustomerRet.BillAddress.Addr4.GetValue();
                }
                //Get value of Addr5
                if (CustomerRet.BillAddress.Addr5 != null)
                {
                    string Addr527 = (string)CustomerRet.BillAddress.Addr5.GetValue();
                }
                //Get value of City
                if (CustomerRet.BillAddress.City != null)
                {
                    string City28 = (string)CustomerRet.BillAddress.City.GetValue();
                }
                //Get value of State
                if (CustomerRet.BillAddress.State != null)
                {
                    string State29 = (string)CustomerRet.BillAddress.State.GetValue();
                }
                //Get value of PostalCode
                if (CustomerRet.BillAddress.PostalCode != null)
                {
                    string PostalCode30 = (string)CustomerRet.BillAddress.PostalCode.GetValue();
                }
                //Get value of Country
                if (CustomerRet.BillAddress.Country != null)
                {
                    string Country31 = (string)CustomerRet.BillAddress.Country.GetValue();
                }
                //Get value of Note
                if (CustomerRet.BillAddress.Note != null)
                {
                    string Note32 = (string)CustomerRet.BillAddress.Note.GetValue();
                }
            }
            if (CustomerRet.BillAddressBlock != null)
            {
                //Get value of Addr1
                if (CustomerRet.BillAddressBlock.Addr1 != null)
                {
                    string Addr133 = (string)CustomerRet.BillAddressBlock.Addr1.GetValue();
                }
                //Get value of Addr2
                if (CustomerRet.BillAddressBlock.Addr2 != null)
                {
                    string Addr234 = (string)CustomerRet.BillAddressBlock.Addr2.GetValue();
                }
                //Get value of Addr3
                if (CustomerRet.BillAddressBlock.Addr3 != null)
                {
                    string Addr335 = (string)CustomerRet.BillAddressBlock.Addr3.GetValue();
                }
                //Get value of Addr4
                if (CustomerRet.BillAddressBlock.Addr4 != null)
                {
                    string Addr436 = (string)CustomerRet.BillAddressBlock.Addr4.GetValue();
                }
                //Get value of Addr5
                if (CustomerRet.BillAddressBlock.Addr5 != null)
                {
                    string Addr537 = (string)CustomerRet.BillAddressBlock.Addr5.GetValue();
                }
            }
            if (CustomerRet.ShipAddress != null)
            {
                //Get value of Addr1
                if (CustomerRet.ShipAddress.Addr1 != null)
                {
                    string Addr138 = (string)CustomerRet.ShipAddress.Addr1.GetValue();
                }
                //Get value of Addr2
                if (CustomerRet.ShipAddress.Addr2 != null)
                {
                    string Addr239 = (string)CustomerRet.ShipAddress.Addr2.GetValue();
                }
                //Get value of Addr3
                if (CustomerRet.ShipAddress.Addr3 != null)
                {
                    string Addr340 = (string)CustomerRet.ShipAddress.Addr3.GetValue();
                }
                //Get value of Addr4
                if (CustomerRet.ShipAddress.Addr4 != null)
                {
                    string Addr441 = (string)CustomerRet.ShipAddress.Addr4.GetValue();
                }
                //Get value of Addr5
                if (CustomerRet.ShipAddress.Addr5 != null)
                {
                    string Addr542 = (string)CustomerRet.ShipAddress.Addr5.GetValue();
                }
                //Get value of City
                if (CustomerRet.ShipAddress.City != null)
                {
                    string City43 = (string)CustomerRet.ShipAddress.City.GetValue();
                }
                //Get value of State
                if (CustomerRet.ShipAddress.State != null)
                {
                    string State44 = (string)CustomerRet.ShipAddress.State.GetValue();
                }
                //Get value of PostalCode
                if (CustomerRet.ShipAddress.PostalCode != null)
                {
                    string PostalCode45 = (string)CustomerRet.ShipAddress.PostalCode.GetValue();
                }
                //Get value of Country
                if (CustomerRet.ShipAddress.Country != null)
                {
                    string Country46 = (string)CustomerRet.ShipAddress.Country.GetValue();
                }
                //Get value of Note
                if (CustomerRet.ShipAddress.Note != null)
                {
                    string Note47 = (string)CustomerRet.ShipAddress.Note.GetValue();
                }
            }

            if (CustomerRet.ShipAddressBlock != null)
            {
                //Get value of Addr1
                if (CustomerRet.ShipAddressBlock.Addr1 != null)
                {
                    string Addr148 = (string)CustomerRet.ShipAddressBlock.Addr1.GetValue();
                }
                //Get value of Addr2
                if (CustomerRet.ShipAddressBlock.Addr2 != null)
                {
                    string Addr249 = (string)CustomerRet.ShipAddressBlock.Addr2.GetValue();
                }
                //Get value of Addr3
                if (CustomerRet.ShipAddressBlock.Addr3 != null)
                {
                    string Addr350 = (string)CustomerRet.ShipAddressBlock.Addr3.GetValue();
                }
                //Get value of Addr4
                if (CustomerRet.ShipAddressBlock.Addr4 != null)
                {
                    string Addr451 = (string)CustomerRet.ShipAddressBlock.Addr4.GetValue();
                }
                //Get value of Addr5
                if (CustomerRet.ShipAddressBlock.Addr5 != null)
                {
                    string Addr552 = (string)CustomerRet.ShipAddressBlock.Addr5.GetValue();
                }
            }
            if (CustomerRet.ShipToAddressList != null)
            {
                for (int i53 = 0; i53 < CustomerRet.ShipToAddressList.Count; i53++)
                {
                    IShipToAddress ShipToAddress = CustomerRet.ShipToAddressList.GetAt(i53);
                    //Get value of Name
                    string Name54 = (string)ShipToAddress.Name.GetValue();
                    //Get value of Addr1
                    if (ShipToAddress.Addr1 != null)
                    {
                        string Addr155 = (string)ShipToAddress.Addr1.GetValue();
                    }
                    //Get value of Addr2
                    if (ShipToAddress.Addr2 != null)
                    {
                        string Addr256 = (string)ShipToAddress.Addr2.GetValue();
                    }
                    //Get value of Addr3
                    if (ShipToAddress.Addr3 != null)
                    {
                        string Addr357 = (string)ShipToAddress.Addr3.GetValue();
                    }
                    //Get value of Addr4
                    if (ShipToAddress.Addr4 != null)
                    {
                        string Addr458 = (string)ShipToAddress.Addr4.GetValue();
                    }
                    //Get value of Addr5
                    if (ShipToAddress.Addr5 != null)
                    {
                        string Addr559 = (string)ShipToAddress.Addr5.GetValue();
                    }
                    //Get value of City
                    if (ShipToAddress.City != null)
                    {
                        string City60 = (string)ShipToAddress.City.GetValue();
                    }
                    //Get value of State
                    if (ShipToAddress.State != null)
                    {
                        string State61 = (string)ShipToAddress.State.GetValue();
                    }
                    //Get value of PostalCode
                    if (ShipToAddress.PostalCode != null)
                    {
                        string PostalCode62 = (string)ShipToAddress.PostalCode.GetValue();
                    }
                    //Get value of Country
                    if (ShipToAddress.Country != null)
                    {
                        string Country63 = (string)ShipToAddress.Country.GetValue();
                    }
                    //Get value of Note
                    if (ShipToAddress.Note != null)
                    {
                        string Note64 = (string)ShipToAddress.Note.GetValue();
                    }
                    //Get value of DefaultShipTo
                    if (ShipToAddress.DefaultShipTo != null)
                    {
                        bool DefaultShipTo65 = (bool)ShipToAddress.DefaultShipTo.GetValue();
                    }
                }
            }
            //Get value of Phone
            if (CustomerRet.Phone != null)
            {
                string Phone66 = (string)CustomerRet.Phone.GetValue();
            }
            //Get value of AltPhone
            if (CustomerRet.AltPhone != null)
            {
                string AltPhone67 = (string)CustomerRet.AltPhone.GetValue();
            }
            //Get value of Fax
            if (CustomerRet.Fax != null)
            {
                string Fax68 = (string)CustomerRet.Fax.GetValue();
            }
            //Get value of Email
            if (CustomerRet.Email != null)
            {
                string Email69 = (string)CustomerRet.Email.GetValue();
            }
            //Get value of Cc
            if (CustomerRet.Cc != null)
            {
                string Cc70 = (string)CustomerRet.Cc.GetValue();
            }
            //Get value of Contact
            if (CustomerRet.Contact != null)
            {
                string Contact71 = (string)CustomerRet.Contact.GetValue();
            }
            //Get value of AltContact
            if (CustomerRet.AltContact != null)
            {
                string AltContact72 = (string)CustomerRet.AltContact.GetValue();
            }

            if (CustomerRet.ContactsRetList != null)
            {
                for (int i76 = 0; i76 < CustomerRet.ContactsRetList.Count; i76++)
                {
                    IContactsRet ContactsRet = CustomerRet.ContactsRetList.GetAt(i76);
                    //Get value of ListID
                    string ListID77 = (string)ContactsRet.ListID.GetValue();
                    //Get value of TimeCreated
                    DateTime TimeCreated78 = (DateTime)ContactsRet.TimeCreated.GetValue();
                    //Get value of TimeModified
                    DateTime TimeModified79 = (DateTime)ContactsRet.TimeModified.GetValue();
                    //Get value of EditSequence
                    string EditSequence80 = (string)ContactsRet.EditSequence.GetValue();
                    //Get value of Contact
                    if (ContactsRet.Contact != null)
                    {
                        string Contact81 = (string)ContactsRet.Contact.GetValue();
                    }
                    //Get value of Salutation
                    if (ContactsRet.Salutation != null)
                    {
                        string Salutation82 = (string)ContactsRet.Salutation.GetValue();
                    }
                    //Get value of FirstName
                    string FirstName83 = (string)ContactsRet.FirstName.GetValue();
                    //Get value of MiddleName
                    if (ContactsRet.MiddleName != null)
                    {
                        string MiddleName84 = (string)ContactsRet.MiddleName.GetValue();
                    }
                    //Get value of LastName
                    if (ContactsRet.LastName != null)
                    {
                        string LastName85 = (string)ContactsRet.LastName.GetValue();
                    }
                    //Get value of JobTitle
                    if (ContactsRet.JobTitle != null)
                    {
                        string JobTitle86 = (string)ContactsRet.JobTitle.GetValue();
                    }
                    if (ContactsRet.AdditionalContactRefList != null)
                    {
                        for (int i87 = 0; i87 < ContactsRet.AdditionalContactRefList.Count; i87++)
                        {
                            IQBBaseRef QBBaseRef = ContactsRet.AdditionalContactRefList.GetAt(i87);
                            //Get value of ContactName
                            string ContactName88 = (string)QBBaseRef.FullName.GetValue();
                            //Get value of ContactValue
                            string ContactValue89 = (string)QBBaseRef.ListID.GetValue();
                        }
                    }
                }
            }
            if (CustomerRet.CustomerTypeRef != null)
            {
                //Get value of ListID
                if (CustomerRet.CustomerTypeRef.ListID != null)
                {
                    string ListID90 = (string)CustomerRet.CustomerTypeRef.ListID.GetValue();
                }
                //Get value of FullName
                if (CustomerRet.CustomerTypeRef.FullName != null)
                {
                    string FullName91 = (string)CustomerRet.CustomerTypeRef.FullName.GetValue();
                }
            }
            if (CustomerRet.TermsRef != null)
            {
                //Get value of ListID
                if (CustomerRet.TermsRef.ListID != null)
                {
                    string ListID92 = (string)CustomerRet.TermsRef.ListID.GetValue();
                }
                //Get value of FullName
                if (CustomerRet.TermsRef.FullName != null)
                {
                    string FullName93 = (string)CustomerRet.TermsRef.FullName.GetValue();
                }
            }
            if (CustomerRet.SalesRepRef != null)
            {
                //Get value of ListID
                if (CustomerRet.SalesRepRef.ListID != null)
                {
                    string ListID94 = (string)CustomerRet.SalesRepRef.ListID.GetValue();
                }
                //Get value of FullName
                if (CustomerRet.SalesRepRef.FullName != null)
                {
                    string FullName95 = (string)CustomerRet.SalesRepRef.FullName.GetValue();
                }
            }
            //Get value of Balance
            if (CustomerRet.Balance != null)
            {
                double Balance96 = (double)CustomerRet.Balance.GetValue();
            }
            //Get value of TotalBalance
            if (CustomerRet.TotalBalance != null)
            {
                double TotalBalance97 = (double)CustomerRet.TotalBalance.GetValue();
            }
            if (CustomerRet.SalesTaxCodeRef != null)
            {
                //Get value of ListID
                if (CustomerRet.SalesTaxCodeRef.ListID != null)
                {
                    string ListID98 = (string)CustomerRet.SalesTaxCodeRef.ListID.GetValue();
                }
                //Get value of FullName
                if (CustomerRet.SalesTaxCodeRef.FullName != null)
                {
                    string FullName99 = (string)CustomerRet.SalesTaxCodeRef.FullName.GetValue();
                }
            }
            if (CustomerRet.ItemSalesTaxRef != null)
            {
                //Get value of ListID
                if (CustomerRet.ItemSalesTaxRef.ListID != null)
                {
                    string ListID100 = (string)CustomerRet.ItemSalesTaxRef.ListID.GetValue();
                }
                //Get value of FullName
                if (CustomerRet.ItemSalesTaxRef.FullName != null)
                {
                    string FullName101 = (string)CustomerRet.ItemSalesTaxRef.FullName.GetValue();
                }
            }
            //Get value of ResaleNumber
            if (CustomerRet.ResaleNumber != null)
            {
                string ResaleNumber102 = (string)CustomerRet.ResaleNumber.GetValue();
            }
            //Get value of AccountNumber
            if (CustomerRet.AccountNumber != null)
            {
                string AccountNumber103 = (string)CustomerRet.AccountNumber.GetValue();
            }
            //Get value of CreditLimit
            if (CustomerRet.CreditLimit != null)
            {
                double CreditLimit104 = (double)CustomerRet.CreditLimit.GetValue();
            }
            if (CustomerRet.PreferredPaymentMethodRef != null)
            {
                //Get value of ListID
                if (CustomerRet.PreferredPaymentMethodRef.ListID != null)
                {
                    string ListID105 = (string)CustomerRet.PreferredPaymentMethodRef.ListID.GetValue();
                }
                //Get value of FullName
                if (CustomerRet.PreferredPaymentMethodRef.FullName != null)
                {
                    string FullName106 = (string)CustomerRet.PreferredPaymentMethodRef.FullName.GetValue();
                }
            }
            if (CustomerRet.CreditCardInfo != null)
            {
                //Get value of CreditCardNumber
                if (CustomerRet.CreditCardInfo.CreditCardNumber != null)
                {
                    string CreditCardNumber107 = (string)CustomerRet.CreditCardInfo.CreditCardNumber.GetValue();
                }
                //Get value of ExpirationMonth
                if (CustomerRet.CreditCardInfo.ExpirationMonth != null)
                {
                    int ExpirationMonth108 = (int)CustomerRet.CreditCardInfo.ExpirationMonth.GetValue();
                }
                //Get value of ExpirationYear
                if (CustomerRet.CreditCardInfo.ExpirationYear != null)
                {
                    int ExpirationYear109 = (int)CustomerRet.CreditCardInfo.ExpirationYear.GetValue();
                }
                //Get value of NameOnCard
                if (CustomerRet.CreditCardInfo.NameOnCard != null)
                {
                    string NameOnCard110 = (string)CustomerRet.CreditCardInfo.NameOnCard.GetValue();
                }
                //Get value of CreditCardAddress
                if (CustomerRet.CreditCardInfo.CreditCardAddress != null)
                {
                    string CreditCardAddress111 = (string)CustomerRet.CreditCardInfo.CreditCardAddress.GetValue();
                }
                //Get value of CreditCardPostalCode
                if (CustomerRet.CreditCardInfo.CreditCardPostalCode != null)
                {
                    string CreditCardPostalCode112 = (string)CustomerRet.CreditCardInfo.CreditCardPostalCode.GetValue();
                }
            }
            //Get value of JobStatus
            if (CustomerRet.JobStatus != null)
            {
                ENJobStatus JobStatus113 = (ENJobStatus)CustomerRet.JobStatus.GetValue();
            }
            //Get value of JobStartDate
            if (CustomerRet.JobStartDate != null)
            {
                DateTime JobStartDate114 = (DateTime)CustomerRet.JobStartDate.GetValue();
            }
            //Get value of JobProjectedEndDate
            if (CustomerRet.JobProjectedEndDate != null)
            {
                DateTime JobProjectedEndDate115 = (DateTime)CustomerRet.JobProjectedEndDate.GetValue();
            }
            //Get value of JobEndDate
            if (CustomerRet.JobEndDate != null)
            {
                DateTime JobEndDate116 = (DateTime)CustomerRet.JobEndDate.GetValue();
            }
            //Get value of JobDesc
            if (CustomerRet.JobDesc != null)
            {
                string JobDesc117 = (string)CustomerRet.JobDesc.GetValue();
            }
            if (CustomerRet.JobTypeRef != null)
            {
                //Get value of ListID
                if (CustomerRet.JobTypeRef.ListID != null)
                {
                    string ListID118 = (string)CustomerRet.JobTypeRef.ListID.GetValue();
                }
                //Get value of FullName
                if (CustomerRet.JobTypeRef.FullName != null)
                {
                    string FullName119 = (string)CustomerRet.JobTypeRef.FullName.GetValue();
                }
            }
            //Get value of Notes
            if (CustomerRet.Notes != null)
            {
                string Notes120 = (string)CustomerRet.Notes.GetValue();
            }
            if (CustomerRet.AdditionalNotesRetList != null)
            {
                for (int i121 = 0; i121 < CustomerRet.AdditionalNotesRetList.Count; i121++)
                {
                    IAdditionalNotesRet AdditionalNotesRet = CustomerRet.AdditionalNotesRetList.GetAt(i121);
                    //Get value of NoteID
                    int NoteID122 = (int)AdditionalNotesRet.NoteID.GetValue();
                    //Get value of Date
                    DateTime Date123 = (DateTime)AdditionalNotesRet.Date.GetValue();
                    //Get value of Note
                    string Note124 = (string)AdditionalNotesRet.Note.GetValue();
                }
            }
            //Get value of PreferredDeliveryMethod
            if (CustomerRet.PreferredDeliveryMethod != null)
            {
                ENPreferredDeliveryMethod PreferredDeliveryMethod125 = (ENPreferredDeliveryMethod)CustomerRet.PreferredDeliveryMethod.GetValue();
            }
            if (CustomerRet.PriceLevelRef != null)
            {
                //Get value of ListID
                if (CustomerRet.PriceLevelRef.ListID != null)
                {
                    string ListID126 = (string)CustomerRet.PriceLevelRef.ListID.GetValue();
                }
                //Get value of FullName
                if (CustomerRet.PriceLevelRef.FullName != null)
                {
                    string FullName127 = (string)CustomerRet.PriceLevelRef.FullName.GetValue();
                }
            }
            //Get value of ExternalGUID
            if (CustomerRet.ExternalGUID != null)
            {
                string ExternalGUID128 = (string)CustomerRet.ExternalGUID.GetValue();
            }
            if (CustomerRet.CurrencyRef != null)
            {
                //Get value of ListID
                if (CustomerRet.CurrencyRef.ListID != null)
                {
                    string ListID129 = (string)CustomerRet.CurrencyRef.ListID.GetValue();
                }
                //Get value of FullName
                if (CustomerRet.CurrencyRef.FullName != null)
                {
                    string FullName130 = (string)CustomerRet.CurrencyRef.FullName.GetValue();
                }
            }
            if (CustomerRet.DataExtRetList != null)
            {
                for (int i131 = 0; i131 < CustomerRet.DataExtRetList.Count; i131++)
                {
                    IDataExtRet DataExtRet = CustomerRet.DataExtRetList.GetAt(i131);
                    //Get value of OwnerID
                    if (DataExtRet.OwnerID != null)
                    {
                        string OwnerID132 = (string)DataExtRet.OwnerID.GetValue();
                    }
                    //Get value of DataExtName
                    string DataExtName133 = (string)DataExtRet.DataExtName.GetValue();
                    //Get value of DataExtType
                    ENDataExtType DataExtType134 = (ENDataExtType)DataExtRet.DataExtType.GetValue();
                    //Get value of DataExtValue
                    string DataExtValue135 = (string)DataExtRet.DataExtValue.GetValue();
                }
            }
        }
        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);
        }
        private ESRI.ArcLogistics.DomainObjects.Order MakeOrderFromInvoice(IInvoiceRet invoiceRet, QBSessionManager session)
        {
            ESRI.ArcLogistics.DomainObjects.Order resultOrder = null;

            ICustomerRet customerRet = QueryCustomer(session, invoiceRet.CustomerRef.FullName.GetValue());

            CapacitiesInfo            capInfo  = m_application.Project.CapacitiesInfo;
            OrderCustomPropertiesInfo propInfo = m_application.Project.OrderCustomPropertiesInfo;

            resultOrder = new ESRI.ArcLogistics.DomainObjects.Order(capInfo, propInfo);

            resultOrder.PlannedDate = m_application.CurrentDate;
            if (customerRet.ParentRef != null)
            {
                resultOrder.Name = customerRet.ParentRef.FullName.GetValue();
            }
            else
            {
                resultOrder.Name = customerRet.FullName.GetValue();
            }

            IAddress useAddress = null;

            if (customerRet.ShipAddress != null)
            {
                useAddress = customerRet.ShipAddress;
            }
            else if (customerRet.BillAddress != null)
            {
                useAddress = customerRet.BillAddress;
            }
            else
            {
                m_application.Messenger.AddWarning("No address for: " + resultOrder.Name);
            }

            if (useAddress != null)
            {
                if (useAddress.Addr2 != null)
                {
                    resultOrder.Address.AddressLine = useAddress.Addr2.GetValue();
                }
                else
                {
                    resultOrder.Address.AddressLine = useAddress.Addr1.GetValue();
                }

                resultOrder.Address.Locality3     = useAddress.City.GetValue();
                resultOrder.Address.StateProvince = useAddress.State.GetValue();
                resultOrder.Address.PostalCode1   = useAddress.PostalCode.GetValue();

                AddressCandidate candidate = m_application.Geocoder.Geocode(resultOrder.Address);

                resultOrder.GeoLocation = candidate.GeoLocation;
            }

            // Look in the order custom properties for matching invoice detail items (by item description).
            // Look in the order capacities for matching item type custom fields.

            OrderCustomPropertiesInfo orderPropertiesInfo = resultOrder.CustomPropertiesInfo;
            OrderCustomProperties     orderProperties     = resultOrder.CustomProperties;

            CapacitiesInfo orderCapacitiesInfo = resultOrder.CapacitiesInfo;
            Capacities     orderCapacities     = resultOrder.Capacities;

            // Retrieve invoice line list
            // Each line can be either InvoiceLineRet OR InvoiceLineGroupRet

            IORInvoiceLineRetList orInvoiceLineRetList = invoiceRet.ORInvoiceLineRetList;

            if (orInvoiceLineRetList != null && (orderProperties.Count > 0 || orderCapacities.Count > 0))
            {
                int lineCount = orInvoiceLineRetList.Count;
                for (int i = 0; i < lineCount; i++)
                {
                    IORInvoiceLineRet orInvoiceLineRet = orInvoiceLineRetList.GetAt(i);

                    // Check what to retrieve from the orInvoiceLineRet object
                    // based on the "ortype" property.  Skip summary lines.

                    if (orInvoiceLineRet.ortype != ENORInvoiceLineRet.orilrInvoiceLineRet)
                    {
                        continue;
                    }

                    if (orInvoiceLineRet.InvoiceLineRet.ItemRef.FullName != null)
                    {
                        string itemName     = orInvoiceLineRet.InvoiceLineRet.ItemRef.FullName.GetValue();
                        double itemQuantity = 0;
                        if (orInvoiceLineRet.InvoiceLineRet.ItemRef != null)
                        {
                            itemQuantity = System.Convert.ToDouble(orInvoiceLineRet.InvoiceLineRet.Quantity.GetValue());
                        }

                        // look for matching custom order property

                        OrderCustomProperty orderPropertyInfoItem = null;
                        for (int j = 0; j < orderPropertiesInfo.Count; j++)
                        {
                            orderPropertyInfoItem = orderPropertiesInfo.ElementAt(j) as OrderCustomProperty;
                            if (orderPropertyInfoItem.Name == itemName)
                            {
                                if (orderPropertyInfoItem.Type == OrderCustomPropertyType.Numeric)
                                {
                                    orderProperties[j] = itemQuantity;
                                }
                                else
                                {
                                    orderProperties[j] = itemQuantity.ToString();
                                }

                                break;
                            }
                        }

                        // look for matching capacity

                        // need to lookup item record so we get the extra field(s)
                        // TODO: It might be a good idea to cache these locally to avoid
                        // excess QB queries.

                        IORItemRet      orItemRet             = QueryItem(session, itemName);
                        IDataExtRetList custItemFieldsRetList = null;

                        switch (orItemRet.ortype)
                        {
                        case ENORItemRet.orirItemServiceRet:
                        {
                            // orir prefix comes from OR + Item + Ret
                            IItemServiceRet ItemServiceRet = orItemRet.ItemServiceRet;
                            custItemFieldsRetList = ItemServiceRet.DataExtRetList;
                        }
                        break;

                        case ENORItemRet.orirItemInventoryRet:
                        {
                            IItemInventoryRet ItemInventoryRet = orItemRet.ItemInventoryRet;
                            custItemFieldsRetList = ItemInventoryRet.DataExtRetList;
                        }
                        break;

                        case ENORItemRet.orirItemNonInventoryRet:
                        {
                            IItemNonInventoryRet ItemNonInventoryRet = orItemRet.ItemNonInventoryRet;
                            custItemFieldsRetList = ItemNonInventoryRet.DataExtRetList;
                        }
                        break;
                        }

                        int custItemFieldCount = 0;
                        if (custItemFieldsRetList != null)
                        {
                            custItemFieldCount = custItemFieldsRetList.Count;
                        }

                        for (int j = 0; j < custItemFieldCount; j++)
                        {
                            IDataExtRet custItemField     = custItemFieldsRetList.GetAt(j);
                            string      custItemFieldName = custItemField.DataExtName.GetValue();

                            CapacityInfo orderCapacityInfoItem = null;
                            for (int k = 0; k < orderCapacitiesInfo.Count; k++)
                            {
                                orderCapacityInfoItem = orderCapacitiesInfo.ElementAt(k);
                                if (orderCapacityInfoItem.Name == custItemFieldName)
                                {
                                    orderCapacities[k] += System.Convert.ToDouble(custItemField.DataExtValue.GetValue()) * itemQuantity;

                                    break;
                                }
                            }
                        }
                    }
                }
            }

            resultOrder.CustomProperties = orderProperties;
            resultOrder.Capacities       = orderCapacities;

            return(resultOrder);
        }
Beispiel #27
0
        protected Dictionary <string, string> QuickBooksExcuet(IMsgSetRequest requestMsgSet, string externalId = null)
        {
            try
            {
                SessionManager.OpenConnection("QuickBooks Application", "QuickBooks Application");
                ConnectionOpen = true;

                SessionManager.BeginSession("", ENOpenMode.omDontCare);
                SessionBegun = true;

                IMsgSetResponse responseMsgSet = SessionManager.DoRequests(requestMsgSet);
                SessionManager.EndSession();
                SessionBegun = false;

                SessionManager.CloseConnection();
                ConnectionOpen = false;

                if (responseMsgSet != null)
                {
                    IResponseList responseList = responseMsgSet.ResponseList;
                    for (int i = 0; i < responseList.Count; i++)
                    {
                        IResponse response = responseList.GetAt(i);
                        //check the status code of the response, 0=ok, >0 is warning
                        if (response.StatusCode >= 0)
                        {
                            var result = new Dictionary <string, string>();
                            result.Add("StatusCode", response.StatusCode + "");
                            //the request-specific response is in the details, make sure we have some
                            if (response.Detail != null)
                            {
                                //make sure the response is the type we're expecting
                                ENResponseType responseType = (ENResponseType)response.Type.GetValue();
                                if (responseType == ENResponseType.rtCustomerAddRs)
                                {
                                    //upcast to more specific type here, this is safe because we checked with response.Type check above
                                    ICustomerRet customerRet = (ICustomerRet)response.Detail;
                                    if (customerRet != null)
                                    {
                                        string newId = customerRet.ListID.GetValue();
                                        result.Add("Message", "Customer has been Added successfully");
                                        result.Add("ListID", newId);
                                        return(result);
                                    }
                                }
                                if (responseType == ENResponseType.rtCustomerModRs)
                                {
                                    ICustomerRet ItemInventoryRet = (ICustomerRet)response.Detail;
                                    if (ItemInventoryRet != null)
                                    {
                                        string newId = ItemInventoryRet.ListID.GetValue();
                                        result.Add("Message", $"Customer with Id {newId} has been updated Successfully");
                                        return(result);
                                    }
                                }
                                if (responseType == ENResponseType.rtListDelRs)
                                {
                                    IQBENListDelTypeType ListDelType = (IQBENListDelTypeType)response.Detail;
                                    result.Add("Message", $"Customer with Id {externalId} has been deleted Successfully");
                                    return(result);
                                }
                                if (responseType == ENResponseType.rtAccountQueryRs)
                                {
                                    IAccountRetList AccountRet = (IAccountRetList)response.Detail;
                                    for (int j = 0; j < AccountRet.Count; j++)
                                    {
                                        var    acc      = AccountRet.GetAt(j);
                                        string FullName = (string)acc.FullName.GetValue();
                                        result.Add("Name", FullName);
                                    }
                                }
                            }
                            else
                            {
                                result.Add("Error", response.StatusMessage);
                                return(result);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (SessionBegun)
                {
                    SessionManager.EndSession();
                }
                if (ConnectionOpen)
                {
                    SessionManager.CloseConnection();
                }
                return(new Dictionary <string, string>()
                {
                    { "Error", ex.Message }
                });
            }

            return(new Dictionary <string, string>());
        }
Beispiel #28
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);
                }
            }
        }
Beispiel #29
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);
        }