OutgoingDocumentBaseServerFunctions.cs
5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow.OutgoingDocumentBase;
namespace Sungero.Docflow.Server
{
partial class OutgoingDocumentBaseFunctions
{
/// <summary>
/// Получить договор, если он был связан с исходящим документом.
/// </summary>
/// <param name="document">Исходящий документ.</param>
/// <returns>Договор.</returns>
[Sungero.Core.Converter("Contract")]
public static IOfficialDocument Contract(IOutgoingDocumentBase document)
{
// Вернуть договор, если он был связан с исходящим письмом.
var contractTypeGuid = Guid.Parse("f37c7e63-b134-4446-9b5b-f8811f6c9666");
var contracts = document.Relations.GetRelatedFrom(Constants.Module.CorrespondenceRelationName).Where(d => d.TypeDiscriminator == contractTypeGuid);
return Sungero.Docflow.OfficialDocuments.As(contracts.FirstOrDefault());
}
/// <summary>
/// Получить список адресатов для шаблона исходящего письма.
/// </summary>
/// <param name="document">Исходящее письмо.</param>
/// <returns>Список адресатов.</returns>
[Sungero.Core.Converter("GetAddressees")]
public static string GetAddressees(IOutgoingDocumentBase document)
{
var result = string.Empty;
if (document.Addressees.Count() > Constants.Module.AddresseesShortListLimit)
result = OfficialDocuments.Resources.ToManyAddressees;
else
{
foreach (var addressee in document.Addressees.OrderBy(a => a.Number))
{
var person = Sungero.Parties.People.As(addressee.Correspondent);
// Не выводить должность для персоны.
if (person == null)
{
// Должность адресата в дательном падеже.
var jobTitle = string.Format("<{0}>", OfficialDocuments.Resources.JobTitle);
if (addressee.Addressee != null && !string.IsNullOrEmpty(addressee.Addressee.JobTitle))
jobTitle = CaseConverter.ConvertJobTitleToTargetDeclension(addressee.Addressee.JobTitle, Sungero.Core.DeclensionCase.Dative);
result += jobTitle;
result += Environment.NewLine;
}
// Организация адресата/ФИО Персоны.
if (person == null)
result += addressee.Correspondent.Name;
else
{
var personName = CommonLibrary.PersonFullName.Create(person.LastName, person.FirstName, person.MiddleName, CommonLibrary.PersonFullNameDisplayFormat.LastNameAndInitials);
result += CaseConverter.ConvertPersonFullNameToTargetDeclension(personName, Sungero.Core.DeclensionCase.Dative);
}
result += Environment.NewLine;
// Не выводить ФИО адресата для персоны.
if (person == null)
{
var addresseeName = string.Format("<{0}>", OutgoingDocumentBases.Resources.InitialsAndLastName);
// И.О. Фамилия адресата в дательном падеже.
if (addressee.Addressee != null)
{
addresseeName = addressee.Addressee.Name;
if (addressee.Addressee.Person != null)
{
var personFullName = CommonLibrary.PersonFullName.Create(addressee.Addressee.Person.LastName,
addressee.Addressee.Person.FirstName,
addressee.Addressee.Person.MiddleName,
CommonLibrary.PersonFullNameDisplayFormat.InitialsAndLastName);
addresseeName = CaseConverter.ConvertPersonFullNameToTargetDeclension(personFullName, Sungero.Core.DeclensionCase.Dative);
}
}
result += addresseeName;
result += Environment.NewLine;
}
// Адрес доставки.
var postalAddress = string.Format("<{0}>", OutgoingDocumentBases.Resources.PostalAddress);
if (!string.IsNullOrEmpty(addressee.Correspondent.PostalAddress))
postalAddress = addressee.Correspondent.PostalAddress;
result += postalAddress;
result += Environment.NewLine;
result += Environment.NewLine;
}
}
return result.Trim();
}
/// <summary>
/// Проверить, связан ли документ специализированной связью.
/// </summary>
/// <returns>True - если связан, иначе - false.</returns>
[Remote(IsPure = true)]
public override bool HasSpecifiedTypeRelations()
{
var hasSpecifiedTypeRelations = false;
AccessRights.AllowRead(
() =>
{
hasSpecifiedTypeRelations = IncomingDocumentBases.GetAll().Any(x => Equals(x.InResponseTo, _obj));
});
return base.HasSpecifiedTypeRelations() || hasSpecifiedTypeRelations;
}
}
}