Quickbooks: проблема при синхронизации оценок (запрос эстимейда) из базы данных в quickbooks C# - PullRequest
0 голосов
/ 23 января 2020

Я использую оконное приложение (c#) для синхронизации c данных от QB до веб-конца (asp. net веб-приложение) и наоборот. Теперь пытаюсь синхронизировать c оценки (цитата) и работать нормально, за исключением того, что когда я обновляю оценку в конце сети и запускаю syn c (Web -> QB), она не обновляется в конце QB, и нет ошибок или исключений в коде. end.

Вот мой код для мода Estimate:

public static QBEstimate Mod(QBEstimate estimate, out string resonOfError)
    {
        resonOfError = "";
        try
        {
            IMsgSetRequest reqSet = QBCommunication.QBSessionManager.CreateMsgSetRequest(ObjContant.cCountry, QBCommunication.QBXmlMajorVersion, QBCommunication.QBXmlMinorVersion);
            reqSet.Attributes.OnError = ENRqOnError.roeContinue;

            IEstimateMod requestQuery = reqSet.AppendEstimateModRq();
            requestQuery.TxnID.SetValue(estimate.TxnID);
            requestQuery.EditSequence.SetValue(estimate.EditSequence);               


            if (estimate.TxnDate > DateTime.MinValue)
            {
                requestQuery.TxnDate.SetValue(estimate.TxnDate);
            }

            if (!string.IsNullOrEmpty(estimate.PONumber))
            {
                requestQuery.PONumber.SetValue(estimate.PONumber);
            }

            if (!string.IsNullOrEmpty(estimate.FOB))
            {
                requestQuery.FOB.SetValue(estimate.FOB);
            }

            if (!String.IsNullOrEmpty(estimate.RefNumber))
            {
                requestQuery.RefNumber.SetValue(estimate.RefNumber);
            }

            if (!String.IsNullOrEmpty(estimate.Memo))
            {
                requestQuery.Memo.SetValue(estimate.Memo);
            }

            if (!String.IsNullOrEmpty(estimate.Other))
            {
                requestQuery.Other.SetValue(estimate.Other);
            }

            if (!string.IsNullOrEmpty(estimate.CustomerFullName))
            {
                requestQuery.CustomerRef.FullName.SetValue(estimate.CustomerFullName);
            }
            else if (!string.IsNullOrEmpty(estimate.CustomerListID))
            {
                requestQuery.CustomerRef.ListID.SetValue(estimate.CustomerListID);
            }

            if (!string.IsNullOrEmpty(estimate.ClassFullName))
            {
                requestQuery.ClassRef.FullName.SetValue(estimate.ClassFullName);
            }
            else if (!string.IsNullOrEmpty(estimate.ClassListID))
            {
                requestQuery.ClassRef.ListID.SetValue(estimate.ClassListID);
            }

            if (!string.IsNullOrEmpty(estimate.TermsFullName))
            {
                requestQuery.TermsRef.FullName.SetValue(estimate.TermsFullName);
            }
            else if (!string.IsNullOrEmpty(estimate.TermsListID))
            {
                requestQuery.TermsRef.ListID.SetValue(estimate.TermsListID);
            }


            if (!string.IsNullOrEmpty(estimate.CustomerMsgFullName))
            {
                requestQuery.CustomerMsgRef.FullName.SetValue(estimate.CustomerMsgFullName);
            }
            else if (!string.IsNullOrEmpty(estimate.CustomerMsgListID))
            {
                requestQuery.CustomerMsgRef.ListID.SetValue(estimate.CustomerMsgListID);
            }

            if (!string.IsNullOrEmpty(estimate.ItemSalesTaxFullName))
            {
                requestQuery.ItemSalesTaxRef.FullName.SetValue(estimate.ItemSalesTaxFullName);
            }
            else if (!string.IsNullOrEmpty(estimate.ItemSalesTaxListID))
            {
                requestQuery.ItemSalesTaxRef.ListID.SetValue(estimate.ItemSalesTaxListID);
            }

            if (estimate.BillAddress != null)
            {
                if (!string.IsNullOrEmpty(estimate.BillAddress.Addr1))
                {
                    requestQuery.BillAddress.Addr1.SetValue(estimate.BillAddress.Addr1);
                }

                if (!string.IsNullOrEmpty(estimate.BillAddress.Addr2))
                {
                    requestQuery.BillAddress.Addr2.SetValue(estimate.BillAddress.Addr2);
                }

                if (!string.IsNullOrEmpty(estimate.BillAddress.Addr3))
                {
                    requestQuery.BillAddress.Addr3.SetValue(estimate.BillAddress.Addr3);
                }

                if (!string.IsNullOrEmpty(estimate.BillAddress.Addr4))
                {
                    requestQuery.BillAddress.Addr4.SetValue(estimate.BillAddress.Addr4);
                }

                if (!string.IsNullOrEmpty(estimate.BillAddress.Addr5))
                {
                    requestQuery.BillAddress.Addr5.SetValue(estimate.BillAddress.Addr5);
                }

                if (!string.IsNullOrEmpty(estimate.BillAddress.City))
                {
                    requestQuery.BillAddress.City.SetValue(estimate.BillAddress.City);
                }

                if (!string.IsNullOrEmpty(estimate.BillAddress.State))
                {
                    requestQuery.BillAddress.State.SetValue(estimate.BillAddress.State);
                }

                if (!string.IsNullOrEmpty(estimate.BillAddress.PostalCode))
                {
                    requestQuery.BillAddress.PostalCode.SetValue(estimate.BillAddress.PostalCode);
                }

                if (!string.IsNullOrEmpty(estimate.BillAddress.Country))
                {
                    requestQuery.BillAddress.Country.SetValue(estimate.BillAddress.Country);
                }
            }
            if (estimate.ShipAddress != null)
            {
                if (!string.IsNullOrEmpty(estimate.ShipAddress.Addr1))
                {
                    requestQuery.ShipAddress.Addr1.SetValue(estimate.ShipAddress.Addr1);
                }

                if (!string.IsNullOrEmpty(estimate.ShipAddress.Addr2))
                {
                    requestQuery.ShipAddress.Addr2.SetValue(estimate.ShipAddress.Addr2);
                }

                if (!string.IsNullOrEmpty(estimate.ShipAddress.Addr3))
                {
                    requestQuery.ShipAddress.Addr3.SetValue(estimate.ShipAddress.Addr3);
                }

                if (!string.IsNullOrEmpty(estimate.ShipAddress.Addr4))
                {
                    requestQuery.ShipAddress.Addr4.SetValue(estimate.ShipAddress.Addr4);
                }

                if (!string.IsNullOrEmpty(estimate.ShipAddress.Addr5))
                {
                    requestQuery.ShipAddress.Addr5.SetValue(estimate.ShipAddress.Addr5);
                }

                if (!string.IsNullOrEmpty(estimate.ShipAddress.City))
                {
                    requestQuery.ShipAddress.City.SetValue(estimate.ShipAddress.City);
                }

                if (!string.IsNullOrEmpty(estimate.ShipAddress.State))
                {
                    requestQuery.ShipAddress.State.SetValue(estimate.ShipAddress.State);
                }

                if (!string.IsNullOrEmpty(estimate.ShipAddress.PostalCode))
                {
                    requestQuery.ShipAddress.PostalCode.SetValue(estimate.ShipAddress.PostalCode);
                }

                if (!string.IsNullOrEmpty(estimate.ShipAddress.Country))
                {
                    requestQuery.ShipAddress.Country.SetValue(estimate.ShipAddress.Country);
                }
            }



            if (estimate.ItemLine.Count > 0)
            {
                foreach (var item in estimate.ItemLine)
                {
                    IOREstimateLineMod lineMod = requestQuery.OREstimateLineModList.Append();
                    if (!string.IsNullOrEmpty(item.ItemType) && item.ItemType == "orirItemSalesTaxRet")
                    {
                        lineMod.EstimateLineMod.TxnLineID.SetValue("-1");
                        if (!string.IsNullOrEmpty(item.ItemListFullName))
                        {
                            lineMod.EstimateLineMod.ItemRef.FullName.SetValue(item.ItemListFullName);
                        }
                        else if (!string.IsNullOrEmpty(item.ItemListID))
                        {
                            lineMod.EstimateLineMod.ItemRef.ListID.SetValue(item.ItemListID);
                        }

                        if (!string.IsNullOrEmpty(item.Desc))
                        {
                            lineMod.EstimateLineMod.Desc.SetValue(item.Desc);
                        }

                        lineMod.EstimateLineMod.Amount.SetValue(item.Price);
                    }
                    else
                    {
                        lineMod.EstimateLineMod.TxnLineID.SetValue("-1");
                        if (!string.IsNullOrEmpty(item.ItemListFullName))
                        {
                            lineMod.EstimateLineMod.ItemRef.FullName.SetValue(item.ItemListFullName);
                        }
                        else if (!string.IsNullOrEmpty(item.ItemListID))
                        {
                            lineMod.EstimateLineMod.ItemRef.ListID.SetValue(item.ItemListID);
                        }

                        if (!string.IsNullOrEmpty(item.Desc))
                        {
                            lineMod.EstimateLineMod.Desc.SetValue(item.Desc);
                        }

                        if (!String.IsNullOrEmpty(item.SalesTaxCodeFullName))
                        {
                            lineMod.EstimateLineMod.SalesTaxCodeRef.FullName.SetValue(item.SalesTaxCodeFullName);
                        }
                        else if (!String.IsNullOrEmpty(item.SalesTaxCodeListID))
                        {
                            lineMod.EstimateLineMod.SalesTaxCodeRef.ListID.SetValue(item.SalesTaxCodeListID);
                        }

                        if (item.ItemType.ToLower() != ENORItemRet.orirItemDiscountRet.ToString().ToLower() && item.ItemType.ToLower() != ENORItemRet.orirItemFixedAssetRet.ToString().ToLower())
                        {
                            lineMod.EstimateLineMod.Quantity.SetValue(item.Quantity);
                        }
                        lineMod.EstimateLineMod.ORRate.Rate.SetValue(item.Price);
                    }
                }
            }

            IMsgSetResponse resp = QBHelpers.QBCommunication.QBSessionManager.DoRequests(reqSet);
            IEstimateRet ret = (IEstimateRet)resp.ResponseList.GetAt(0).Detail;
            if (ret != null)
            {
                estimate.EditSequence = ret.EditSequence.GetValue();
                estimate.TxnID = ret.TxnID.GetValue();
                log.Info(reqSet.ToXMLString());

                //Update Tracking number in estimate
                try
                {
                    if (!string.IsNullOrEmpty(estimate.TrackingNumber))
                    {
                        SaveCustomField(ret, "Tracking Number", estimate.TrackingNumber);
                    }
                }
                catch
                {

                }

                return estimate;
            }
            else
            {
                log.Error("Error in QBEstimate.Mod(). estimateRet is null.");
                log.Error(reqSet.ToXMLString());
                log.Error(resp.ResponseList.GetAt(0).StatusMessage);
                resonOfError = new frmSetting().QBErMsgApnd(resp.ResponseList.GetAt(0).StatusMessage);
                return null;
            }
        }
        catch (Exception ex)
        {
            log.Error("Error in QBEstimate.Mod()", ex);
            return null;
        }
    }

Заранее спасибо.

...