Ejemplo n.º 1
0
        public IResponse DbGetResponseSet(ref QBSessionManager sessionManager, IMsgSetRequest requestMsgSet)
        {
            //Send the request and get the response from QuickBooks
            IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);

            return(responseMsgSet.ResponseList.GetAt(0));
        }
Ejemplo n.º 2
0
    public List <string> QueryEmployeeNames()
    {
        try
        {
            IMsgSetRequest requestSet = SessionManager.Instance.CreateMsgSetRequest();
            requestSet.Attributes.OnError = ENRqOnError.roeStop;
            IEmployeeQuery employeeQuery = requestSet.AppendEmployeeQueryRq();

            IMsgSetResponse responeSet   = SessionManager.Instance.DoRequests(requestSet);
            IResponseList   responseList = responeSet.ResponseList;

            List <string> employeeNames = new List <string>();

            for (int i = 0; i < responseList.Count; i++)
            {
                IResponse response = responseList.GetAt(i);
                if (response.StatusCode == 0)
                {
                    IEmployeeRetList employeeList = (IEmployeeRetList)response.Detail;
                    for (int j = 0; j < employeeList.Count; j++)
                    {
                        IEmployeeRet employee = employeeList.GetAt(j);
                        employeeNames.Add(employee.Name.GetValue());
                    }
                }
            }

            return(employeeNames);
        }
        catch (Exception ex)
        {
            // Handle exception
        }
    }
    private static void buildCustomerRequest(string[,] customers, ref IMsgSetRequest requestSet)
    {
        //Walk customers array and build CustomerAdd xmls
        int length = customers.GetLength(0);

        for (int x = 0; x < length; x++)
        {
            string firstname = (customers[x, 0] != null) ? customers[x, 0] : "";
            string lastname  = (customers[x, 1] != null) ? customers[x, 1] : "";
            string addr1     = (customers[x, 2] != null) ? customers[x, 2] : "";
            string addr2     = (customers[x, 3] != null) ? customers[x, 3] : "";
            string city      = (customers[x, 4] != null) ? customers[x, 4] : "";
            string state     = (customers[x, 5] != null) ? customers[x, 5] : "";
            string zip       = (customers[x, 6] != null) ? customers[x, 6] : "";
            string phone     = (customers[x, 7] != null) ? customers[x, 7] : "";
            string email     = (customers[x, 8] != null) ? customers[x, 8] : "";

            ICustomerAdd CustAdd = requestSet.AppendCustomerAddRq();
            CustAdd.Name.SetValue(firstname + " " + lastname);
            CustAdd.FirstName.SetValue(firstname);
            CustAdd.LastName.SetValue(lastname);
            CustAdd.BillAddress.Addr1.SetValue(addr1);
            CustAdd.BillAddress.Addr2.SetValue(addr2);
            CustAdd.BillAddress.City.SetValue(city);
            CustAdd.BillAddress.State.SetValue(state);
            CustAdd.BillAddress.PostalCode.SetValue(zip);
            CustAdd.Phone.SetValue(phone);
            CustAdd.Email.SetValue(email);
        }
    }
Ejemplo n.º 4
0
        public void vendorAdd(string name)
        {
            //open session to add vendor
            QBSessionManager sessionManager = new QBSessionManager();

            sessionManager.OpenConnection("appID", "Create Vendor");
            sessionManager.BeginSession("", ENOpenMode.omDontCare);
            IMsgSetRequest messageSet = sessionManager.CreateMsgSetRequest("US", 13, 0);

            IVendorAdd vendorAddRequest = messageSet.AppendVendorAddRq();

            vendorAddRequest.Name.SetValue(name); //add vendor
                                                  // name is the string passed from the list containing the vendors that need to be added to quickbooks

            IMsgSetResponse responseSet = sessionManager.DoRequests(messageSet);

            sessionManager.EndSession();
            sessionManager.CloseConnection();

            for (int i = 0; i < responseSet.ResponseList.Count; i++)
            {
                IResponse response = responseSet.ResponseList.GetAt(i);
                var       code     = response.StatusCode;
                string    code2    = code.ToString();
                string    code3    = response.StatusMessage;
                if (response.StatusCode > 0)
                {
                }
                // MessageBox.Show(code3);
            }
        }
Ejemplo n.º 5
0
        public SalesReceiptRet AddSalesReceipt(SalesReceipt salesreceipt)
        {
            //Create the message set request object to hold our request

            if (sessionManager != null)
            {
                IMsgSetRequest SalesReceiptRequestMsgSet = sessionManager.CreateMsgSetRequest(3, 0);
                SalesReceiptRequestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
                SalesReceiptViewModel SalesReceiptVM = new SalesReceiptViewModel();
                SalesReceiptVM.BuildSalesReceiptAddRq(SalesReceiptRequestMsgSet,
                                                      SalesReceiptVM.BuildSalesReceipt(salesreceipt));

                try
                {
                    return(GetQBSalesReceipt(salesreceipt, SalesReceiptRequestMsgSet, SalesReceiptVM));
                }
                catch (COMException ce)
                {
                    // MessageBox.Show("QuickBooks Problem: " + ce.Message);
                    return(new SalesReceiptRet()
                    {
                        Comments = "QuickBooks Problem: " + ce.Message
                    });
                }
            }
            return(new SalesReceiptRet());
        }
        public void BuildSalesReceiptQueryRq(IMsgSetRequest requestMsgSet, DateTime startDate, DateTime endDate)
        {
            var salesReceiptQueryRq = requestMsgSet.AppendSalesReceiptQueryRq();

            salesReceiptQueryRq.ORTxnDateFilters.TxnDateRangeFilter.FromTxnDate.SetValue(startDate.Date);
            salesReceiptQueryRq.ORTxnDateFilters.TxnDateRangeFilter.ToTxnDate.SetValue(endDate.Date);
        }
Ejemplo n.º 7
0
        public void addBillItems(List <ExtractInfo> List1, IMsgSetRequest messageSet, int i)
        {
            // input top of bill items
            IBillAdd BillAddRequest = messageSet.AppendBillAddRq();

            BillAddRequest.VendorRef.FullName.SetValue(List1[i].vendorName);
            BillAddRequest.RefNumber.SetValue(List1[i].invoiceNumber);
            BillAddRequest.TxnDate.SetValue(DateTime.Parse(List1[i].invoiceDate));
            BillAddRequest.DueDate.SetValue(DateTime.Parse(List1[i].dueDate));
            //input expense items
            addExpense(List1, BillAddRequest, i);
            //check for repeated invoice numbers and add expense items as necessary
            for (int z = List1.Count - 1; z > i; z--)
            {
                if (List1[z].invoiceNumber != List1[i].invoiceNumber)
                {
                    continue;
                }
                if (List1[z].invoiceNumber == List1[i].invoiceNumber)
                {
                    addExpense(List1, BillAddRequest, z);
                    List1.RemoveAt(z);
                }
            }
        }
        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);
        }
        public void BuildCreatedItemInventoryQuery(IMsgSetRequest ItemInventoryRequestMsgSet, int days)
        {
            //when open first time download all, then download from last time to now.

            //
            //Set attributes
            //Set field value for MatchNumericCriterion

            if (days != 1)
            {
                lastDownloadTime = DateTime.Now.AddDays(days * -1);
            }

            if (lastDownloadTime != DateTime.MinValue)
            {
                IItemInventoryQuery ItemInventoryQueryRq = ItemInventoryRequestMsgSet.AppendItemInventoryQueryRq();
                ItemInventoryQueryRq.ORTimeCreatedFilters.TimeCreatedRangeFilter.FromTimeCreated.SetValue(DateTime.Now.AddMinutes(-45),//lastDownloadTime
                                                                                                          false);
                ItemInventoryQueryRq.ORTimeCreatedFilters.TimeCreatedRangeFilter.ToTimeCreated.SetValue(DateTime.Now,
                                                                                                        false);
                //ItemInventoryQueryRq.ORItemNumberFilters.ItemNumberFilter.MatchNumericCriterion.SetValue(ENMatchNumericCriterion.mncEqual);
                //ItemInventoryQueryRq.ORItemNumberFilters.ItemNumberFilter.ItemNumber.SetValue(6315);
            }
            lastDownloadTime = DateTime.Now;
        }
Ejemplo n.º 10
0
 void BuildPreferencesQueryRq(IMsgSetRequest requestMsgSet)
 {
     IPreferencesQuery PreferencesQueryRq = requestMsgSet.AppendPreferencesQueryRq();
     //Set field value for IncludeRetElementList
     //May create more than one of these if needed
     //PreferencesQueryRq.IncludeRetElementList.Add("ab");
 }
        private IORItemRet QueryItem(QBSessionManager session, string itemFullName)
        {
            // query for the customer information

            IMsgSetRequest requestMsgSet = getLatestMsgSetRequest(session);

            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

            IItemQuery pItemQuery = requestMsgSet.AppendItemQueryRq();

            pItemQuery.ORListQuery.ListFilter.ORNameFilter.NameFilter.Name.SetValue(itemFullName);
            pItemQuery.ORListQuery.ListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcContains);

            pItemQuery.OwnerIDList.Add("0");

            IMsgSetResponse responseMsgSet = session.DoRequests(requestMsgSet);

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

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

            // Interpret the response

            IResponseList rsList = responseMsgSet.ResponseList;

            //  Retrieve the one response corresponding to our single request

            IResponse response = rsList.GetAt(0);

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

                throw new Exception(msg);
            }

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

            IORItemRetList orItemRetList = response.Detail as IORItemRetList;

            int itemCount = orItemRetList.Count;

            if (itemCount > 1)
            {
                m_application.Messenger.AddWarning("Multiple items found: " + itemFullName);
            }

            return(orItemRetList.GetAt(0));
        }
Ejemplo n.º 12
0
        public IMsgSetRequest newRequest()
        {
            IMsgSetRequest msgRequest = qbMgr.CreateMsgSetRequest("US", 4, 0);

            msgRequest.Attributes.OnError = ENRqOnError.roeStop;
            return(msgRequest);
        }
Ejemplo n.º 13
0
        public void OpenQB()
        {
            QBSessionManager sessionManager = null;

            try
            {
                sessionManager = new QBSessionManager();
                IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("CA", 13, 0);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                sessionManager.OpenConnection("QBAPI", "Quickbooks SDK Demo Test");
                string qbFile = ConfigurationSettings.AppSettings["companyfile"].ToString();
                Console.WriteLine(qbFile);
                sessionManager.BeginSession(
                    qbFile, ENOpenMode.omMultiUser);

                ICustomerQuery customerQueryRq = requestMsgSet.AppendCustomerQueryRq();
                customerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);


                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);

                sessionManager.EndSession();
                sessionManager.CloseConnection();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                sessionManager.EndSession();
                sessionManager.CloseConnection();
            }
        }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
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);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Method for handling different versions of QuickBooks.
        /// </summary>
        private double QBFCLatestVersion()
        {
            // Use oldest version to ensure that this application work with any QuickBooks (US)
            IMsgSetRequest msgset = SessionManager.CreateMsgSetRequest("US", 1, 0);

            msgset.AppendHostQueryRq();
            IMsgSetResponse QueryResponse = SessionManager.DoRequests(msgset);
            //Console.WriteLine("Host query = " + msgset.ToXMLString());

            // The response list contains only one response,
            // which corresponds to our single HostQuery request.
            IResponse response = QueryResponse.ResponseList.GetAt(0);

            // Please refer to QBFC Developers Guide for details on why
            // "as" clause was used to link this derived class to its base class.
            IHostRet  HostResponse      = response.Detail as IHostRet;
            IBSTRList supportedVersions = HostResponse.SupportedQBXMLVersionList as IBSTRList;

            double LastVers = 0;

            for (var i = 0; i <= supportedVersions.Count - 1; i++)
            {
                string svers = null;
                svers = supportedVersions.GetAt(i);
                var vers = Convert.ToDouble(svers);
                if (vers > LastVers)
                {
                    LastVers = vers;
                }
            }
            return(LastVers);
        }
Ejemplo n.º 17
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);
        }
        /// <summary>
        /// Creates the request body to send to the service.
        /// </summary>
        /// <returns>The generated request</returns>
        private IMsgSetRequest CreateRequest()
        {
            IMsgSetRequest request = _manager.CreateMsgSetRequest(_country, _qbsdkMajor, _qbsdkMinor);

            request.Attributes.OnError = ENRqOnError.roeContinue;

            return(request);
        }
Ejemplo n.º 19
0
 private void prepareQuery()
 {
     session.open();
     request = session.getRequest();
     sessionManager = session.getSession();
     invoiceQuery = request.AppendInvoiceQueryRq();
     invoiceQuery.IncludeLineItems.SetValue(true);
 }
Ejemplo n.º 20
0
        public IResponseList LoadQBItemInventoryList(int maxRecords, QBSessionManager sessionManager)
        {
            // IMsgSetRequest requestMsgSet = null;
            QBSession     QBMgr        = null;
            IResponseList responseList = null;

            try
            {
                QBMgr = new QBSession();
                if (sessionManager == null)
                {
                    QBMgr.CreateQBSession(out sessionManager);
                }

                if (sessionManager != null)
                {
                    // Get the RequestMsgSet based on the correct QB Version
                    IMsgSetRequest requestSet = QBMgr.getLatestMsgSetRequest(sessionManager);

                    if (requestSet != null)
                    {
                        // Initialize the message set request object
                        requestSet.Attributes.OnError = ENRqOnError.roeStop;

                        IItemInventoryQuery itemInventory = requestSet.AppendItemInventoryQueryRq();

                        //Set field value for metaData
                        itemInventory.metaData.SetValue(ENmetaData.mdMetaDataAndResponseData); //"IQBENmetaDataType"

                        // Optionally, you can put filter on it.
                        if (maxRecords != 0)
                        {
                            itemInventory.ORListQueryWithOwnerIDAndClass.ListWithClassFilter.MaxReturned.SetValue(maxRecords);
                        }

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

                        //IItemInventoryRetList itemInventoryRetList = null;
                        if (responseMsgSet == null)
                        {
                            return(null);
                        }
                        responseList = responseMsgSet.ResponseList;
                        if (responseList == null)
                        {
                            return(null);
                        }

                        // string responseXML = responseMsgSet.ToXMLString();
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(responseList);
        }
Ejemplo n.º 21
0
        public IResponse GetMessageResponse(ref QBSessionManager sessionManager, ref IMsgSetRequest requestMsgSet)
        {
            // Send Request Get Responce
            //Send the request and get the response from QuickBooks
            IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
            IResponse       response       = responseMsgSet.ResponseList.GetAt(0);

            return(response);
        }
Ejemplo n.º 22
0
        public IMsgSetRequest CreateRequestMessage(ref QBSessionManager sessionManager)
        {
            //Create the message set request object to hold our request
            IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("UK", 12, 0);

            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

            return(requestMsgSet);
        }
        /// <inheritdoc/>
        public async Task <ObservableCollection <InventoryItem> > GetInventoryFromQBFC()
        {
            IMsgSetRequest request = CreateRequest();

            request.AppendItemQueryRq();
            IMsgSetResponse queryResponse = await MakeRequestAsync(request).ConfigureAwait(false);

            return(await ProcessItemQuery(queryResponse));
        }
 public void BuildItemInventoryQueryRq(IMsgSetRequest ItemInventoryRequestMsgSet)
 {
     IItemInventoryQuery ItemInventoryQueryRq = ItemInventoryRequestMsgSet.AppendItemInventoryQueryRq();
     //Set attributes
     //Set field value for MatchNumericCriterion
     //ItemInventoryQueryRq.ORTimeCreatedFilters.TimeCreatedFilter.MatchNumericCriterion.SetValue(ENMatchNumericCriterion.mncGreaterThanEqual);
     ////Set field value for TimeCreated
     //ItemInventoryQueryRq.ORTimeCreatedFilters.TimeCreatedFilter.TimeCreated.SetValue(DateTime.Parse("1/1/2000"), false);
 }
        public void BuildInventoryAdjustmentQueryRq(IMsgSetRequest InventoryAdjusmentRequestMsgSet)
        {
            IInventoryQtyAdjustmentQuery InventoryQtyAdjustmentQueryRq = InventoryAdjusmentRequestMsgSet.AppendInventoryQtyAdjustmentQueryRq();

            //Set field value for MatchNumericCriterion
            InventoryQtyAdjustmentQueryRq.ORTxnDateFilters.TxnDateFilter.MatchNumericCriterion.SetValue(ENMatchNumericCriterion.mncGreaterThanEqual);
            //Set field value for TxnDate
            InventoryQtyAdjustmentQueryRq.ORTxnDateFilters.TxnDateFilter.TxnDate.SetValue(DateTime.Parse("9/1/2012"));
        }
        public void BuildSalesReceiptQueryRq(IMsgSetRequest requestMsgSet)
        {
            ISalesReceiptQuery SalesReceiptQueryRq = requestMsgSet.AppendSalesReceiptQueryRq();

            //Set field value for MatchNumericCriterion
            SalesReceiptQueryRq.ORTxnDateFilters.TxnDateFilter.MatchNumericCriterion.SetValue(ENMatchNumericCriterion.mncGreaterThanEqual);
            //Set field value for TimeCreated
            SalesReceiptQueryRq.ORTxnDateFilters.TxnDateFilter.TxnDate.SetValue(DateTime.Parse("09/01/2012"));
        }
        protected IMsgSetRequest GetLatestMsgSetRequest()
        {
            IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest(MaestroApplication.Instance.QuickBooksCountry,
                                                                              MaestroApplication.Instance.QuickBooksMajorVersion, MaestroApplication.Instance.QuickBooksMinorVersion);

            requestMsgSet.Attributes.OnError = ENRqOnError.roeStop;

            return(requestMsgSet);
        }
Ejemplo n.º 28
0
        public void DoAccountQuery()
        {
            bool             sessionBegun   = false;
            bool             connectionOpen = false;
            QBSessionManager sessionManager = null;
            QBSessionMgr     QBMgr          = null;

            try
            {
                //Create the session Manager object
                QBMgr = new QBSessionMgr();
                QBMgr.CreateQBSession(out sessionManager);

                // Get the RequestMsgSet based on the correct QB Version
                IMsgSetRequest requestMsgSet = QBMgr.getLatestMsgSetRequest(sessionManager);

                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                // BuildAccountQueryRq(requestMsgSet);

                IAccountQuery AccountQueryRq = requestMsgSet.AppendAccountQueryRq();

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

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

                string responseXML = responseMsgSet.ToXMLString();
                //MessageBox.Show(responseXML);

                WalkAccountQueryRs(responseMsgSet);

                //End the session and close the connection to QuickBooks
                //Close the session and connection with QuickBooks
                QBMgr.CloseQBConnection(sessionManager);
            }
            catch (Exception ex)
            {
                // MessageBox.Show(e.Message, "Error");
                // MessageBox.Show(ex.Message.ToString() + "\nStack Trace: \n" + ex.StackTrace + "\nExiting the application");
                if (sessionBegun)
                {
                    sessionManager.EndSession();
                }
                if (connectionOpen)
                {
                    sessionManager.CloseConnection();
                }
            }
            finally
            {
                QBMgr.CloseQBConnection(sessionManager);
            }
        }
Ejemplo n.º 29
0
    public static string buildSalesReceiptAddRqXML(Session sess, string[,] sales)
    {
        QBSessionManager sessionManager = new QBSessionManager();
        IMsgSetRequest   requestSet     = sessionManager.CreateMsgSetRequest(sess.getCountry(), sess.getMajorVers(), sess.getMinorVers());

        requestSet.Attributes.OnError = ENRqOnError.roeStop;

        buildSalesRequest(sales, requestSet);
        return(requestSet.ToXMLString());
    }
        /// <summary>
        /// Determines the most recent version supported by
        /// the quickbooks instance to which we are connecting.
        /// We should always use the latest version supported
        /// by the target instance.
        /// </summary>
        private async Task GetSDKVersionAsync()
        {
            IMsgSetRequest request = _manager.CreateMsgSetRequest(_country, 1, 0);

            request.AppendHostQueryRq();

            IMsgSetResponse queryResponse = await MakeRequestAsync(request).ConfigureAwait(false);

            ProcessSDkQuery(queryResponse);
        }
Ejemplo n.º 31
0
        private SalesReceiptRet GetQBSalesReceipt(SalesReceipt salesreceipt, IMsgSetRequest SalesReceiptRequestMsgSet, SalesReceiptViewModel SalesReceiptVM)
        {
            BeginSession();

            IMsgSetResponse SalesReceiptResponseMsgSet = sessionManager.DoRequests(SalesReceiptRequestMsgSet);

            CloseSession();

            return(SalesReceiptVM.WalkSalesReceiptAddRs(SalesReceiptResponseMsgSet, salesreceipt));
        }
Ejemplo n.º 32
0
		///<summary>Creates a new QB connection and begins the session.  Session will be left open until CloseConnection is called.  Major and minor version refer to the implementation version of the paticular QB request you are trying to run.  The connection will fail if the version you pass in does not support the type of request you are trying to run.</summary>
		private static void OpenConnection(short majorVer,short minorVer,string companyPath) {
			SessionManager=new QBSessionManager();
			//Create the message set request object to hold our request.
			RequestMsgSet=SessionManager.CreateMsgSetRequest("US",majorVer,minorVer);
			RequestMsgSet.Attributes.OnError=ENRqOnError.roeContinue;
			//Connect to QuickBooks and begin a session
			SessionManager.OpenConnection("","Open Dental");
			ConnectionOpen=true;
			SessionManager.BeginSession(companyPath,ENOpenMode.omDontCare);
			SessionBegun=true;
		}
        void BuildInvoiceAddRq(IMsgSetRequest requestMsgSet, Site_Manager.DataModel.BC_BillingAddress customer, QBRequest wqObject)
        {
            IInvoiceAdd InvoiceAddRq = requestMsgSet.AppendInvoiceAddRq();
            var invoice = new Site_Manager.DataModel.BC_Order();
            using (PreferredFloristDBDataContext pfDB = new PreferredFloristDBDataContext())
            {
                invoice = pfDB.BC_Orders.FirstOrDefault(p => p.pfOrderID == wqObject.InvoiceNumber);
            }
            InvoiceAddRq.defMacro.SetValue("1234");
            //Set field value for ListID
            InvoiceAddRq.CustomerRef.ListID.SetValue(wqObject.QBListID);
            //Set field value for FullName
            InvoiceAddRq.ARAccountRef.FullName.SetValue("Accounts Receivable");
            InvoiceAddRq.ClassRef.FullName.SetValue(String.Format("{0}:Orders",wqObject.QBClass));
            //Set field value for FullName
            InvoiceAddRq.TemplateRef.FullName.SetValue("PF Invoice Template");
            //Set field value for TxnDate   DateTime.Parse("12/15/2007")
            if ((invoice.Date_Created == null))
                InvoiceAddRq.TxnDate.SetValue(Convert.ToDateTime(System.DateTime.Now.ToShortDateString()));
            else
                InvoiceAddRq.TxnDate.SetValue(Convert.ToDateTime(invoice.Date_Created.ToString()));
               //Set field value for RefNumber
            InvoiceAddRq.RefNumber.SetValue(wqObject.InvoiceNumber.ToString());
            InvoiceAddRq.RefNumber.SetValue(String.Format("{0}-{1}", wqObject.SiteID, wqObject.BC_OrderID));
            //Set field value for Addr1
            InvoiceAddRq.BillAddress.Addr1.SetValue(String.Format("{0} {1}", customer.first_name, customer.last_name));
            //Set field value for Addr2
            InvoiceAddRq.BillAddress.Addr2.SetValue(customer.street_1);
            //Set field value for City
            InvoiceAddRq.BillAddress.City.SetValue(customer.city);
            //Set field value for State
            InvoiceAddRq.BillAddress.State.SetValue(customer.state);
            //Set field value for PostalCode
            InvoiceAddRq.BillAddress.PostalCode.SetValue(customer.zip);
            //Set field value for Country
            InvoiceAddRq.BillAddress.Country.SetValue(customer.country);
            InvoiceAddRq.IsPending.SetValue(false);
            //Set field value for PONumber
            InvoiceAddRq.PONumber.SetValue(String.Empty);
            //Set field value for FullName
            InvoiceAddRq.TermsRef.FullName.SetValue("Due on receipt");
             //Set field value for ShipDate DateTime.Parse("12/15/2007")
            InvoiceAddRq.ShipDate.SetValue((invoice.Date_Created == null) ? Convert.ToDateTime(System.DateTime.Now.ToShortDateString()) : Convert.ToDateTime(invoice.Date_Created.ToString()));
            ////Set field value for ListID
            //InvoiceAddRq.ShipMethodRef.ListID.SetValue("200000-1011023419");
            //Set field value for FullName
            //InvoiceAddRq.ShipMethodRef.FullName.SetValue("ab");
            //Set field value for FullName
            InvoiceAddRq.ItemSalesTaxRef.FullName.SetValue("In State");
            //Set field value for FullName
            InvoiceAddRq.CustomerMsgRef.FullName.SetValue("Thank you for shopping at preferredflorist.com");
            //Set field value for IsToBePrinted
            InvoiceAddRq.IsToBePrinted.SetValue(false);
            //Set field value for IsToBeEmailed
            //InvoiceAddRq.IsToBeEmailed.SetValue(isValid);
            InvoiceAddRq.IsToBeEmailed.SetValue(false);
            //InvoiceAddRq.FOB.SetValue(invoice.CustomerJobNumber);
            //InvoiceAddRq.Other.SetValue(invoice.WorkOrderNumber.ToString());

            using (var db = new PreferredFloristDBDataContext())
            {
                int countOfInvolis = 0;
                var bagOfInvolis = from pi in db.BC_OrderLineItems
                                   where pi.PFOrderID == wqObject.InvoiceNumber
                                   select pi;
                countOfInvolis = bagOfInvolis.Count();
                if (countOfInvolis > 0)
                {
                    foreach (Site_Manager.DataModel.BC_OrderLineItem involi in bagOfInvolis)
                    {
                        IORInvoiceLineAdd ORInvoiceLineAddListElement1 = InvoiceAddRq.ORInvoiceLineAddList.Append();
                        string ORInvoiceLineAddListElementType2 = "InvoiceLineAdd";
                        if (ORInvoiceLineAddListElementType2 == "InvoiceLineAdd")
                        {
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.ItemRef.FullName.SetValue("Product");

                            //Get the value of the card sentiment, card signature, verse, ribbon etc.
                            var bagOfProductOptions = from pi in db.BC_OrderProductOptions
                                                      where pi.PF_Line_Item_ID == involi.pf_line_item_id
                                                      orderby pi.option_id ascending
                                                      select pi;
                            var prodOptsText = new StringBuilder();
                            foreach (Site_Manager.DataModel.BC_OrderProductOption oPo in bagOfProductOptions)
                            {
                                prodOptsText.Append(String.Format("{0}:\r\n", oPo.display_name));
                                prodOptsText.Append(String.Format("{0}:\r\n\r\n", oPo.value));
                            }
                            //Set field value for Desc
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Desc.SetValue(String.Format("{0}   {1}\r\n\r\n{2}\r\n\r\n", involi.sku, involi.name, prodOptsText));
                            //Set field value for Quantity
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Quantity.SetValue(Convert.ToInt32(involi.quantity));

                            ORInvoiceLineAddListElement1.InvoiceLineAdd.ORRatePriceLevel.Rate.SetValue(Convert.ToDouble(involi.price_ex_tax));
                            if (null == customer.IsTaxable || customer.IsTaxable == false)
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Non");
                            }
                            else
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Tax");
                            }
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Other1.SetValue(involi.sku);

                        }
                    }

                    //Add order coupons if there are any
                    if (invoice.coupon_discount > 0)
                    {
                        int countOfCoupons = 0;
                        var bagOfCoupons = from pi in db.BC_OrderCoupons
                                           where pi.pf_Order_ID == wqObject.InvoiceNumber
                                           select pi;
                        countOfCoupons = bagOfCoupons.Count();
                        if (countOfCoupons > 0)
                        {
                            foreach (Site_Manager.DataModel.BC_OrderCoupon couponLi in bagOfCoupons)
                            {
                                IORInvoiceLineAdd ORInvoiceLineAddListElement1 = InvoiceAddRq.ORInvoiceLineAddList.Append();
                                string ORInvoiceLineAddListElementType2 = "InvoiceLineAdd";
                                if (ORInvoiceLineAddListElementType2 == "InvoiceLineAdd")
                                {
                                    ORInvoiceLineAddListElement1.InvoiceLineAdd.ItemRef.FullName.SetValue("Coupon");
                                    //Set field value for Desc
                                    ORInvoiceLineAddListElement1.InvoiceLineAdd.Desc.SetValue(couponLi.code);
                                    //Set field value for Quantity
                                    //ORInvoiceLineAddListElement1.InvoiceLineAdd.Quantity.SetValue(1); //Cannot set quantity for item of this type

                                    ORInvoiceLineAddListElement1.InvoiceLineAdd.ORRatePriceLevel.Rate.SetValue(Convert.ToDouble(invoice.coupon_discount));
                                    if (null == customer.IsTaxable || customer.IsTaxable == false)
                                    {
                                        ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Non");
                                    }
                                    else
                                    {
                                        ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Tax");
                                    }
                                    ORInvoiceLineAddListElement1.InvoiceLineAdd.Other1.SetValue(couponLi.code);
                                }
                            }
                        }
                    }

                        //Add Service Fee. Note: in some of the earlier stores, the handling fee was billed as shipping

                        if (invoice.handling_cost_ex_tax > 0)
                        {
                            IORInvoiceLineAdd ORInvoiceLineAddListElement1 = InvoiceAddRq.ORInvoiceLineAddList.Append();
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.ItemRef.FullName.SetValue("Service Fee");
                            //Set field value for Desc
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Desc.SetValue("Service Fee");
                            //Set field value for Quantity
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Quantity.SetValue(1);
                            //ORInvoiceLineAddListElement1.InvoiceLineAdd.Other1.SetValue(dr["PartNumber"].ToString());

                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Amount.SetValue(Convert.ToDouble(invoice.handling_cost_ex_tax));
                            if (invoice.handling_cost_tax > 0)
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Tax");
                            }
                            else
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Non");                            }
                        }

                        if (invoice.shipping_cost_ex_tax > 0) // Note: in some of the earlier stores, the handling fee was billed as shipping
                        {
                            IORInvoiceLineAdd ORInvoiceLineAddListElement1 = InvoiceAddRq.ORInvoiceLineAddList.Append();
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.ItemRef.FullName.SetValue("Shipping");
                            //Set field value for Desc
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Desc.SetValue("Shipping");
                            //Set field value for Quantity
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Quantity.SetValue(1);

                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Amount.SetValue(Convert.ToDouble(invoice.shipping_cost_ex_tax));
                            if (invoice.shipping_cost_tax > 0)
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Tax");
                            }
                            else
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Non"); //////////////////HEEEEEEEEEEEEEEY??????????????????
                            }
                        }

                        //Add Order Discounts
                        if (!(String.IsNullOrEmpty(invoice.discount_amount.ToString())) && invoice.discount_amount > 0)
                        {
                            Decimal aCredit = invoice.discount_amount > 0 ? (decimal)invoice.discount_amount : 0;
                            IORInvoiceLineAdd ORInvoiceLineAddListElement1 = InvoiceAddRq.ORInvoiceLineAddList.Append();
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.ItemRef.FullName.SetValue("Discount");
                            //Set field value for Desc
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Desc.SetValue("Discount");

                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Amount.SetValue(Convert.ToDouble(aCredit));
                            if (null == customer.IsTaxable || customer.IsTaxable == false)
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Non");
                            }
                            else
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Tax");
                            }
                        }
                }
            }
        }
Ejemplo n.º 34
0
 public IMsgSetResponse performRequest(IMsgSetRequest request)
 {
     return qbMgr.DoRequests(request);
 }