/// <summary> /// Сконвертировать документы в pdf. /// </summary> /// <param name="args">Параметры вызова асинхронного обработчика.</param> public virtual void ConvertDocumentToPdf(Sungero.Docflow.Server.AsyncHandlerInvokeArgs.ConvertDocumentToPdfInvokeArgs args) { int documentId = args.DocumentId; int versionId = args.VersionId; Logger.DebugFormat("ConvertDocumentToPdf: start convert document to pdf. Document id - {0}.", documentId); var document = OfficialDocuments.GetAll(x => x.Id == documentId).FirstOrDefault(); if (document == null) { Logger.DebugFormat("ConvertDocumentToPdf: not found document with id {0}.", documentId); return; } var version = document.Versions.SingleOrDefault(v => v.Id == versionId); if (version == null) { Logger.DebugFormat("ConvertDocumentToPdf: not found version. Document id - {0}, version number - {1}.", documentId, versionId); return; } if (!Locks.TryLock(version.Body)) { Logger.DebugFormat("ConvertDocumentToPdf: version is locked. Document id - {0}, version number - {1}.", documentId, versionId); args.Retry = true; return; } var result = Docflow.Functions.OfficialDocument.ConvertToPdfAndAddSignatureMark(document, version.Id); Locks.Unlock(version.Body); if (result.HasErrors) { Logger.DebugFormat("ConvertDocumentToPdf: {0}", result.ErrorMessage); if (result.HasLockError) { args.Retry = true; } else { var operation = new Enumeration(Constants.OfficialDocument.Operation.ConvertToPdf); document.History.Write(operation, operation, string.Empty, version.Number); document.Save(); } } Logger.DebugFormat("ConvertDocumentToPdf: convert document {0} to pdf successfully.", documentId); }
/// <summary> /// Отправка ответа контрагенту. /// </summary> /// <param name="document">Документ, по которому требуется отправка ответа.</param> /// <param name="documentInfo">Информация о документе, связанная с коммуникацией с контрагентом.</param> /// <param name="addenda">Приложения.</param> public static void SendAnswerToCounterparty(Docflow.IOfficialDocument document, Sungero.Exchange.Structures.Module.SendToCounterpartyInfo documentInfo, List <Docflow.IOfficialDocument> addenda) { var dialog = Dialogs.CreateInputDialog(Resources.SendAnswerToCounterpartyDialogTitle); dialog.HelpCode = Constants.Module.HelpCodes.SendAnswerOnDocument; var positiveResult = Resources.SendCounterpartyPositiveResult; var amendmentResult = Resources.SendCounterpartyNegativeResult; var invoiceAmendmentResult = Resources.SendCounterpartyRejectResult; var allowedResults = new List <string>(); if (documentInfo.CanSendSignAsAnswer) { allowedResults.Add(positiveResult); } if (documentInfo.CanSendInvoiceAmendmentRequestAsAnswer) { allowedResults.Add(invoiceAmendmentResult); } if (documentInfo.CanSendAmendmentRequestAsAnswer) { allowedResults.Add(amendmentResult); } var formParams = ((Domain.Shared.IExtendedEntity)document).Params; var signAndSend = formParams.ContainsKey(Exchange.PublicConstants.Module.DefaultSignResult) && (bool)formParams[Exchange.PublicConstants.Module.DefaultSignResult]; var defaultSignResult = documentInfo.IsSignedByUs || signAndSend == true? allowedResults.FirstOrDefault() : allowedResults.LastOrDefault(); var signResult = dialog.AddSelect(Resources.SendCounterpartyResult, true, defaultSignResult) .From(allowedResults.ToArray()); var counterparty = dialog.AddSelect(Resources.SendCounterpartyReceiver, true, documentInfo.DefaultCounterparty); counterparty.IsEnabled = false; var box = dialog.AddSelect(Resources.SendCounterpartySender, true, documentInfo.DefaultBox); box.IsEnabled = false; var users = new List <Sungero.CoreEntities.IUser>(); if (documentInfo.Certificates.Certificates != null) { users = documentInfo.Certificates.Certificates.Select(c => c.Owner).ToList(); } var signatureOwner = dialog.AddSelect(Docflow.OfficialDocuments.Info.Properties.OurSignatory.LocalizedName, false, users.FirstOrDefault()) .From(users); signatureOwner.IsEnabled = documentInfo.IsSignedByUs; var allowedAddenda = documentInfo.Addenda.Select(a => a.Addendum).ToList(); var defaultSelectedAddenda = addenda.Intersect(allowedAddenda).ToArray(); var selectedAddenda = dialog.AddSelectMany(Resources.SendCounterpartyAddenda, false, defaultSelectedAddenda) .From(allowedAddenda); selectedAddenda.IsEnabled = documentInfo.HasAddendaToSend; var comment = dialog.AddMultilineString(Resources.SendCounterpartyComment, false); comment.IsEnabled = defaultSignResult != positiveResult; var sendButton = dialog.Buttons.AddCustom(Resources.SendCounterpartySendButton); dialog.Buttons.Default = sendButton; dialog.Buttons.AddCancel(); var currentUserSelectedCertificate = Certificates.Null; if (!documentInfo.IsSignedByUs && !documentInfo.Certificates.MyCertificates.Any()) { Dialogs.NotifyMessage(Resources.NotificationNoCertificates); return; } signResult.SetOnValueChanged(x => { if (x.NewValue != x.OldValue) { if (x.NewValue != positiveResult) { signatureOwner.Value = null; signatureOwner.IsEnabled = false; comment.IsEnabled = true; } else { signatureOwner.Value = users.FirstOrDefault(); signatureOwner.IsEnabled = documentInfo.IsSignedByUs; comment.Value = string.Empty; comment.IsEnabled = false; } } }); dialog.SetOnButtonClick(x => { if (x.Button == sendButton && x.IsValid) { var hasExchangeWithCounterparty = counterparty.Value.ExchangeBoxes .Any(c => Equals(c.Box, box.Value) && Equals(c.Status, Parties.CounterpartyExchangeBoxes.Status.Active) && c.IsDefault == true); if (!hasExchangeWithCounterparty) { x.AddError(Exchange.Resources.NoExchangeThroughThisService); return; } if (IsLocked(document, x)) { return; } if (comment.Value != null && comment.Value.Length > 1000) { x.AddError(Exchange.ExchangeDocumentProcessingAssignments.Resources.TextOverlong, comment); return; } if (signResult.Value == Resources.SendCounterpartyPositiveResult) { #region Отправка подписи if (signatureOwner.Value == null && documentInfo.IsSignedByUs && !documentInfo.Certificates.CanSign) { x.AddError(Resources.SendCounterpartyCertificateNotSelected); return; } var noSign = signatureOwner.Value == null; if (noSign) { if (!documentInfo.Certificates.CanSign) { x.AddError(Resources.NotificationNoCertificates); return; } var signDialog = Dialogs.CreateTaskDialog(Resources.SendCounterpartySignAndSendQuestion); var signButtons = signDialog.Buttons.AddCustom(Resources.SendCounterpartySignAndSendButton); signDialog.Buttons.AddCancel(); if (signDialog.Show() == signButtons) { try { if (IsLocked(document, x)) { return; } currentUserSelectedCertificate = GetCurrentUserExchangeCertificate(box.Value, Company.Employees.Current); List <Docflow.IOfficialDocument> lockedDocuments = new List <Docflow.IOfficialDocument>(); foreach (Docflow.IOfficialDocument docAddendum in selectedAddenda.Value) { if (docAddendum.LastVersion != null) { var bodyAddendum = docAddendum.LastVersion.PublicBody; var lockInfoAddendum = Locks.GetLockInfo(bodyAddendum); if (lockInfoAddendum != null) { if (lockInfoAddendum.IsLockedByOther) { x.AddError(lockInfoAddendum.LockedMessage); return; } else if (!lockInfoAddendum.IsLocked) { Locks.TryLock(bodyAddendum); lockedDocuments.Add(docAddendum); } } } } if (currentUserSelectedCertificate == null || !Docflow.PublicFunctions.Module .ApproveWithAddenda(document, selectedAddenda.Value.ToList(), currentUserSelectedCertificate, null, true, true, string.Empty)) { UnlockAddenda(lockedDocuments); x.AddError(Resources.NotificationNoCertificates); return; } UnlockAddenda(lockedDocuments); signatureOwner.Value = Users.Current; documentInfo.Certificates = Functions.Module.Remote.GetDocumentCertificatesToBox(document, box.Value); } catch (Exception ex) { x.AddError(ex.Message); return; } } else { return; } } try { var certificate = signatureOwner.Value == null ? null : documentInfo.Certificates.Certificates.Single(c => Equals(c.Owner, signatureOwner.Value)); var documentsToSend = new List <Docflow.IOfficialDocument>() { document }; documentsToSend.AddRange(selectedAddenda.Value); Functions.Module.Remote.SendAnswers(documentsToSend, counterparty.Value, box.Value, certificate, false); if (Equals(certificate.Owner, Company.Employees.Current)) { Functions.Module.SendDeliveryConfirmation(box.Value, certificate, false); } else { Functions.Module.SendDeliveryConfirmation(box.Value, null, false); } } catch (AppliedCodeException ex) { x.AddError(ex.Message); return; } catch (Exception ex) { Logger.ErrorFormat("Error sending sign: ", ex); x.AddError(Resources.ErrorWhileSendingSignToCounterparty); return; } Dialogs.NotifyMessage(Resources.SendAnswerCounterpartySuccessfully); #endregion } else { #region Отправка отказа в подписании currentUserSelectedCertificate = GetCurrentUserExchangeCertificate(box.Value, Company.Employees.Current); if (currentUserSelectedCertificate != null) { var documents = selectedAddenda.Value.ToList(); documents.Add(document); var error = SendAmendmentRequest(documents, counterparty.Value, comment.Value, false, box.Value, currentUserSelectedCertificate, signResult.Value == invoiceAmendmentResult); Functions.Module.SendDeliveryConfirmation(box.Value, currentUserSelectedCertificate, false); if (!string.IsNullOrWhiteSpace(error)) { x.AddError(error); } else { Dialogs.NotifyMessage(Resources.SendAnswerCounterpartySuccessfully); } } else { x.AddError(Resources.RejectCertificateNotFound); } #endregion } } }); dialog.Show(); }
public static void SendResultToCounterparty(Docflow.IOfficialDocument document, ExchangeCore.IExchangeService service, List <Docflow.IOfficialDocument> addenda) { var isNonformalizedTaxInvoice = false; if (FinancialArchive.IncomingTaxInvoices.Is(document) || FinancialArchive.OutgoingTaxInvoices.Is(document)) { isNonformalizedTaxInvoice = Docflow.AccountingDocumentBases.As(document).IsFormalized != true; } if (isNonformalizedTaxInvoice) { Dialogs.NotifyMessage(Resources.NonFormalizedTaxInvoiceSendingError); return; } var lockInfo = document != null?Locks.GetLockInfo(document) : null; if (lockInfo != null && lockInfo.IsLockedByOther) { Dialogs.NotifyMessage(lockInfo.LockedMessage); return; } var documentInfo = Functions.Module.Remote.GetInfoForSendToCounterparty(document); if (documentInfo.HasError) { Dialogs.NotifyMessage(documentInfo.Error); return; } if (documentInfo.AnswerIsSent) { Dialogs.NotifyMessage(Resources.AnswerIsAlreadySent); return; } if (document.LastVersion.Body.Size >= Constants.Module.ExchangeDocumentMaxSize) { Dialogs.NotifyMessage(Resources.DocumentOversized); return; } var isForcedLocked = false; if (!lockInfo.IsLocked) { isForcedLocked = Locks.TryLock(document); } if (!lockInfo.IsLocked && !isForcedLocked) { var lockInfoError = document != null?Locks.GetLockInfo(document) : null; Dialogs.NotifyMessage(lockInfoError.LockedMessage); return; } if (documentInfo.IsSignedByCounterparty) { SendAnswerToCounterparty(document, documentInfo, addenda); } else { SendDocumentToCounterparty(document, documentInfo, service, addenda); } if (isForcedLocked) { Locks.Unlock(document); } }