public void ExportBillDemand(BillDemandForExport billDemandForExport) { using (var client = new IccBossNewDocExport_IccBossNewDocHttpService()) { createDoc doc = new createDoc() { request = new BossNewDocRequest() { idPaydoc = billDemandForExport.Id.ToString("N"), basePayDocIds = billDemandForExport.PaymentPlanItemIds.Select( p => p.ToString(CultureInfo.InvariantCulture)).ToArray (), currCode = billDemandForExport.CurrencyCode, currCourseDate = billDemandForExport.CurrencyRevisionDate, currCourseDateSpecified = true, custIdFrom = billDemandForExport.CustomerCounteragentId.ToString( CultureInfo.InvariantCulture), custIdTo = billDemandForExport.CounteragentId.ToString( CultureInfo.InvariantCulture), docDate = billDemandForExport.DocumentDate, docDateSpecified = true, rDocDate = string.Format("{0:yyyy-MM-dd}",billDemandForExport.DocumentDate), sDocStringNum = billDemandForExport.Number, idFirm = billDemandForExport.FirmCode, docStringNum = billDemandForExport.IdNumber.ToString(CultureInfo.InvariantCulture), rDocStringNum = billDemandForExport.IdNumber.ToString(CultureInfo.InvariantCulture), rootDocId = billDemandForExport.ContractId.ToString( CultureInfo.InvariantCulture), typeDoc = TypeDoc, taxString = billDemandForExport.NDSTaxValue.ToString("0.00", CultureInfo. CreateSpecificCulture ("en-US")), docSum = billDemandForExport.SumWIthNDS.ToString("0.00", CultureInfo. CreateSpecificCulture ("en-US")), rUserSmeta = billDemandForExport.BudgetPartId.ToString(CultureInfo.InvariantCulture), rUserExpenses = billDemandForExport.SmetaCode, rUserCfuExpenses = billDemandForExport.OPCode, rUserCfuPotreb = billDemandForExport.PPCode, rUserProject = billDemandForExport.ProjectCode } }; if (billDemandForExport.AccountDate.HasValue) { doc.request.sDocDate = billDemandForExport.AccountDate.Value; doc.request.sDocDateSpecified = true; } else { doc.request.sDocDateSpecified = false; } #if DEBUG return; // throw new InvalidOperationException("sad"); #else try { var response = client.createDoc(doc); if (response.response.respCode != 0) throw new InvalidOperationException( string.Format("Не удалось выгрузить документ BillDemandId = {0} Описание ошибки = {1}", billDemandForExport.Id, response.response.errDesc)); } catch (SoapException ex) { Logger.Log.Error(string.Format("Не удалось выгрузить документ BillDemandId = {0} Описание ошибки = {1}", billDemandForExport.Id,ex.Detail.InnerText)); Logger.Log.Error(string.Format("Не удалось выгрузить документ BillDemandId = {0} Описание ошибки = {1}", billDemandForExport.Id, ex.Message)); string[] errorMessages = ex.Detail.InnerText.Split(']'); string errorMessage = errorMessages[errorMessages.Length - 1]; throw new InvalidOperationException( string.Format("Не удалось выгрузить документ BillDemandId = {0} Описание ошибки = {1}", billDemandForExport.Id, string.IsNullOrEmpty(errorMessage) ? "Не определено" : errorMessage )); } #endif } }
public BillDemandForExport GetBillDemandForExport(Guid billDemandUid) { using (var scope = ReadCommittedSupressedScope) { using (var context = this.CreateContext()) { var dlo = new DataLoadOptions(); dlo.LoadWith <BillDemand>(p => p.Contract); dlo.LoadWith <BillDemand>(p => p.Currency); dlo.LoadWith <BillDemand>(p => p.Currency1); dlo.LoadWith <BillDemand>(p => p.Filial); dlo.LoadWith <BillDemand>(p => p.Counteragent); dlo.LoadWith <BillDemand>(p => p.BillDemandContractMoneys); dlo.LoadWith <Currency>(p => p.CurrencyRateActual); dlo.LoadWith <Contract>(p => p.ContractMoneys); dlo.LoadWith <Contract>(p => p.CustomerCounteragent); //context.DeferredLoadingEnabled = false; context.LoadOptions = dlo; BillDemand billDemand = GetBillDemand(context, billDemandUid); if (billDemand.ContractId == null) { throw new InvalidOperationException( string.Format( "Невозможно выгрузить расходный документ не привязанный к контракту BillDemandId = {0}", billDemand.Id)); } if (billDemand.CurrencyId == null) { throw new InvalidOperationException( string.Format( "Невозможно выгрузить расходный документ для котрого не задана валюта BillDemandId = {0}", billDemand.Id)); } if (billDemand.PaymentCurrencyId == null) { throw new InvalidOperationException( string.Format( "Невозможно выгрузить расходный документ для котрого не задана платежная валюта BillDemandId = {0}", billDemand.Id)); } if (billDemand.CounteragentId == null) { throw new InvalidOperationException( string.Format( "Невозможно выгрузить расходный документ для котрого не задан Контрагент BillDemandId = {0}", billDemand.Id)); } if (!billDemand.Currency.IsBase && billDemand.Currency.CurrencyRateActual == null) { throw new InvalidOperationException( string.Format( "Невозможно выгрузить расходный документ не найден актуальный курс BillDemandId = {0}", billDemand.Id)); } if (billDemand.AllocationDate == null) { throw new InvalidOperationException( string.Format( "Невозможно выгрузить расходный документ для котрого не задана дата отправки на маршрут BillDemandId = {0}", billDemand.Id)); } if (billDemand.FilialId == null) { throw new InvalidOperationException( string.Format( "Невозможно выгрузить расходный документ для котрого не задан Плательщик BillDemandId = {0}", billDemand.Id)); } if (billDemand.Contract.CustomerCounteragent == null) { throw new InvalidOperationException( string.Format( "Невозможно выгрузить расходный документ для конракта которого не задан контрагент заказчик BillDemandId = {0}", billDemand.Id)); } if (billDemand.Contract.ExternalId == null) { throw new InvalidOperationException( string.Format( "Невозможно выгрузить контракт не загруженный из БОСС BillDemandId = {0} (ExternalId = {1}) ", billDemand.Id, billDemand.Contract.ExternalId)); } var billDemandForExport = new BillDemandForExport() { Id = billDemand.Id, ContractId = billDemand.Contract.ExternalId, CurrencyCode = billDemand.Currency1.IsBase ? billDemand.Currency.Code : billDemand.Currency1.Code, CurrencyRevisionDate = ((billDemand.CurrencyRateTypeId.HasValue && billDemand.CurrencyRateTypeId >= 2) || billDemand.Currency.IsBase) ? billDemand.AllocationDate.Value : billDemand.Currency.CurrencyRateActual.ReevaluationDate, CustomerCounteragentId = billDemand.Contract.CustomerCounteragent.Number, CounteragentId = billDemand.Counteragent.Number, Number = billDemand.Number, IdNumber = billDemand.IdNumber, SumWIthNDS = billDemand.Sum, NDSTaxValue = billDemand.Currency1.IsBase ? (billDemand.NDSValue.HasValue ? billDemand.NDSValue.Value : (billDemand.Sum - (billDemand.SumWithoutNDS.HasValue ? billDemand.SumWithoutNDS.Value : 0))) : (billDemand.CurrencySum.HasValue ? billDemand.CurrencySum.Value : 0), DocumentDate = billDemand.AllocationDate.Value, AccountDate = billDemand.AccountDate, FirmCode = billDemand.Filial.Code, BudgetPartId = billDemand.BudgetPartId }; billDemandForExport.PaymentPlanItemIds = billDemand.Contract.ContractMoneys.Where(p => p.ExternalId.HasValue && billDemand.BillDemandContractMoneys.Count(bdcm => bdcm.ContractMoneyId == p.Id && bdcm.ToPayment) > 0).Select( p => p.ExternalId.Value).Distinct().ToList(); var firstDistribution = billDemand.BillDemandDistributions.FirstOrDefault(); if (firstDistribution != null && firstDistribution.Demand != null) { if (firstDistribution.Demand.Project != null) { billDemandForExport.ProjectCode = firstDistribution.Demand.Project.Code; } if (firstDistribution.Demand.ExecutorStructDivision != null) { billDemandForExport.OPCode = firstDistribution.Demand.ExecutorStructDivision.Code; } } var firstAllocation = billDemand.BillDemandAllocations.FirstOrDefault(); if (firstAllocation != null) { if (firstAllocation.CostArticle != null) { billDemandForExport.SmetaCode = firstAllocation.CostArticle.Code; } if (firstAllocation.CFO != null) { billDemandForExport.PPCode = firstAllocation.CFO.Code; } } return(billDemandForExport); } } }