public virtual void AddOrReplaceSellerTitleInfo(Docflow.IAccountingDocumentBase document) { if (document == null || !document.HasVersions) { return; } var version = document.Versions.SingleOrDefault(v => v.Id == document.SellerTitleId); if (version == null) { return; } using (var memory = new System.IO.MemoryStream()) { version.Body.Read().CopyTo(memory); var newBody = AddOrReplaceSellerTitleInfo(memory, document.BusinessUnitBox, document.Counterparty, document.FormalizedServiceType.Value, document.IsAdjustment == true); version.Body.Write(newBody); document.Save(); } }
public static void GenerateSellerTitle(Docflow.IAccountingDocumentBase statement, Docflow.Structures.AccountingDocumentBase.ISellerTitle sellerTitle) { if (statement.IsFormalized != true) { return; } var sellerSignatoryInfo = new FormalizeDocumentsParser.SellerSignatoryInfo(); sellerSignatoryInfo.CompanyName = statement.BusinessUnit.LegalName; sellerSignatoryInfo.FirstName = sellerTitle.Signatory.Person.FirstName; sellerSignatoryInfo.LastName = sellerTitle.Signatory.Person.LastName; sellerSignatoryInfo.MiddleName = sellerTitle.Signatory.Person.MiddleName; sellerSignatoryInfo.JobTitle = sellerTitle.Signatory.JobTitle != null ? sellerTitle.Signatory.JobTitle.Name : null; // Лицо, совершившее сделку и ответственное за ее оформление. if (sellerTitle.SignatoryPowers == Docflow.AccountingDocumentBases.Resources.PropertiesFillingDialog_HasAuthority_DealAndRegister) { sellerSignatoryInfo.Powers = Constants.Module.SellerTitlePowers.MadeAndSignOperation; } // Лицо, ответственное за оформление свершившегося события. else if (sellerTitle.SignatoryPowers == Docflow.AccountingDocumentBases.Resources.PropertiesFillingDialog_HasAuthority_Register) { sellerSignatoryInfo.Powers = Constants.Module.SellerTitlePowers.PersonDocumentedOperation; } // Лицо, совершившее сделку и операцию, ответственное за ее оформление и за подписание счетов-фактур. else if (sellerTitle.SignatoryPowers == Docflow.AccountingDocumentBases.Resources.PropertiesFillingDialog_HasAuthority_DealAndRegisterAndInvoiceSignatory) { sellerSignatoryInfo.Powers = Constants.Module.SellerTitlePowers.MadeAndResponsibleForOperationAndSignedInvoice; } // Лицо, ответственное за оформление свершившегося события и за подписание счетов-фактур. else if (sellerTitle.SignatoryPowers == Docflow.AccountingDocumentBases.Resources.PropertiesFillingDialog_HasAuthority_RegisterAndInvoiceSignatory) { sellerSignatoryInfo.Powers = Constants.Module.SellerTitlePowers.ResponsibleForOperationAndSignatoryForInvoice; } if (sellerTitle.SignatoryPowerOfAttorney != null) { sellerSignatoryInfo.PowersBase = Docflow.SignatureSettings.Info.Properties.Reason.GetLocalizedValue(Docflow.SignatureSetting.Reason.PowerOfAttorney); if (!string.IsNullOrWhiteSpace(sellerTitle.SignatoryPowerOfAttorney.RegistrationNumber)) { sellerSignatoryInfo.PowersBase += Docflow.OfficialDocuments.Resources.Number + sellerTitle.SignatoryPowerOfAttorney.RegistrationNumber; } if (sellerTitle.SignatoryPowerOfAttorney.RegistrationDate != null) { sellerSignatoryInfo.PowersBase += Docflow.OfficialDocuments.Resources.DateFrom + sellerTitle.SignatoryPowerOfAttorney.RegistrationDate.Value.ToString("d"); } } else if (!string.IsNullOrWhiteSpace(sellerTitle.SignatoryOtherReason)) { sellerSignatoryInfo.PowersBase = sellerTitle.SignatoryOtherReason; } else { sellerSignatoryInfo.PowersBase = Docflow.SignatureSettings.Info.Properties.Reason.GetLocalizedValue(Docflow.SignatureSetting.Reason.Duties); } sellerSignatoryInfo.TIN = statement.BusinessUnit.TIN; using (var body = statement.Versions.Single(v => v.Id == statement.SellerTitleId).Body.Read()) { using (var patchedXml = sellerSignatoryInfo.AddOrReplaceToXml(body)) { if (!HasUnsignedSellerTitle(statement)) { // При создании версии чистится статус эл. обмена, восстанавливаем его. var exchangeState = statement.ExchangeState; statement.CreateVersion(); statement.ExchangeState = exchangeState; } var version = statement.LastVersion; statement.SellerTitleId = version.Id; version.Body.Write(patchedXml); statement.IsFormalizedSignatoryEmpty = false; statement.Save(); } } }