SupAgreementSharedFunctions.cs
11.2 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Contracts.SupAgreement;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow;
namespace Sungero.Contracts.Shared
{
partial class SupAgreementFunctions
{
#region Интеллектуальная обработка
[Public]
public override bool IsVerificationModeSupported()
{
return true;
}
[Public]
public override bool HasEmptyRequiredProperties()
{
return _obj.LeadingDocument == null || base.HasEmptyRequiredProperties();
}
#endregion
/// <summary>
/// Получение категории договора, указанного в доп. соглашении.
/// </summary>
/// <returns>Категория договора.</returns>
public override IDocumentGroupBase GetDocumentGroup()
{
return _obj.LeadingDocument != null ? _obj.LeadingDocument.DocumentGroup : null;
}
/// <summary>
/// Проверить доп. соглашение на дубли.
/// </summary>
/// <param name="supAgreement">Доп. соглашение.</param>
/// <param name="businessUnit">НОР.</param>
/// <param name="registrationNumber">Рег. номер.</param>
/// <param name="registrationDate">Дата регистрации.</param>
/// <param name="counterparty">Контрагент.</param>
/// <param name="contract">Договор.</param>
/// <returns>Признак дублей.</returns>
public static bool HaveDuplicates(ISupAgreement supAgreement,
Sungero.Company.IBusinessUnit businessUnit,
string registrationNumber,
DateTime? registrationDate,
Sungero.Parties.ICounterparty counterparty,
IOfficialDocument contract)
{
if (supAgreement == null ||
businessUnit == null ||
string.IsNullOrWhiteSpace(registrationNumber) ||
registrationDate == null ||
counterparty == null ||
contract == null)
return false;
return Functions.SupAgreement.Remote.GetDuplicates(supAgreement,
businessUnit,
registrationNumber,
registrationDate,
counterparty,
contract)
.Any();
}
#region Регистрация
/// <summary>
/// Получить номер ведущего документа.
/// </summary>
/// <returns>Номер документа либо пустая строка.</returns>
public override string GetLeadDocumentNumber()
{
if (_obj.LeadingDocument != null)
{
return _obj.LeadingDocument.AccessRights.CanRead() ?
_obj.LeadingDocument.RegistrationNumber :
Functions.ContractualDocument.Remote.GetRegistrationNumberIgnoreAccessRights(_obj.LeadingDocument.Id);
}
return string.Empty;
}
#endregion
/// <summary>
/// Получить данные доп.согл. для формирования имени акта.
/// </summary>
/// <param name="supAgreement">Доп. соглашение.</param>
/// <returns>Часть имени.</returns>
/// <remarks>Если нет прав на доп. соглашение, то возникнет исключение.</remarks>
public static string GetNamePartBySupAgreement(ISupAgreement supAgreement)
{
var namePart = ContractBases.Resources.NamePartForLeadDocument + supAgreement.DocumentKind.ShortName.ToLower();
if (!string.IsNullOrWhiteSpace(supAgreement.RegistrationNumber))
namePart += OfficialDocuments.Resources.Number + supAgreement.RegistrationNumber;
namePart += Functions.ContractBase.GetContractNamePart(supAgreement.LeadingDocument);
return namePart;
}
/// <summary>
/// Получить данные доп.согл. для формирования имени акта.
/// </summary>
/// <param name="supAgreement">Доп. соглашение.</param>
/// <returns>Часть имени.</returns>
/// <remarks>Игнорирует права доступа на доп. соглашение.</remarks>
[Public]
public static string GetSupAgreementNamePart(ISupAgreement supAgreement)
{
if (supAgreement == null)
return string.Empty;
return supAgreement.AccessRights.CanRead() ?
GetNamePartBySupAgreement(supAgreement) :
Functions.SupAgreement.Remote.GetNamePartBySupAgreementIgnoreAccessRights(supAgreement.Id);
}
public override void SetObsolete(bool isActive)
{
if (isActive)
_obj.LifeCycleState = LifeCycleState.Terminated;
else
base.SetObsolete(isActive);
}
/// <summary>
/// Заполнить имя.
/// </summary>
public override void FillName()
{
// Не автоформируемое имя.
if (_obj != null && _obj.DocumentKind != null && !_obj.DocumentKind.GenerateDocumentName.Value)
{
if (_obj.Name == OfficialDocuments.Resources.DocumentNameAutotext)
_obj.Name = string.Empty;
if (_obj.VerificationState != null && string.IsNullOrWhiteSpace(_obj.Name))
_obj.Name = _obj.DocumentKind.ShortName;
}
if (_obj.DocumentKind == null || !_obj.DocumentKind.GenerateDocumentName.Value)
return;
// Автоформируемое имя.
var name = string.Empty;
/* Имя в формате:
<Вид документа> №<номер> от <дата> к договору № <номер_договора> с <наименование контрагента> "<содержание>".
*/
using (TenantInfo.Culture.SwitchTo())
{
if (!string.IsNullOrWhiteSpace(_obj.RegistrationNumber))
name += OfficialDocuments.Resources.Number + _obj.RegistrationNumber;
if (_obj.RegistrationDate != null)
name += OfficialDocuments.Resources.DateFrom + _obj.RegistrationDate.Value.ToString("d");
if (_obj.LeadingDocument != null)
name += Functions.ContractBase.GetContractNamePart(_obj.LeadingDocument);
if (!string.IsNullOrEmpty(_obj.Subject))
name += " \"" + _obj.Subject + "\"";
}
if (string.IsNullOrWhiteSpace(name))
{
name = _obj.VerificationState == null ? OfficialDocuments.Resources.DocumentNameAutotext : _obj.DocumentKind.ShortName;
}
else if (_obj.DocumentKind != null)
{
name = _obj.DocumentKind.ShortName + name;
}
name = Docflow.PublicFunctions.Module.TrimSpecialSymbols(name);
_obj.Name = Docflow.PublicFunctions.OfficialDocument.AddClosingQuote(name, _obj);
}
/// <summary>
/// Сменить доступность реквизитов документа.
/// </summary>
/// <param name="isEnabled">True, если свойства должны быть доступны.</param>
/// <param name="isRepeatRegister">Перерегистрация.</param>
public override void ChangeDocumentPropertiesAccess(bool isEnabled, bool isRepeatRegister)
{
if (_obj.VerificationState == VerificationState.InProcess && this.IsNumerationSucceed())
{
this.EnableRequisitesForVerification();
}
else
{
base.ChangeDocumentPropertiesAccess(isEnabled, isRepeatRegister);
var supProperties = _obj.State.Properties;
var enabledState = !(_obj.InternalApprovalState == Docflow.OfficialDocument.InternalApprovalState.OnApproval ||
_obj.InternalApprovalState == Docflow.OfficialDocument.InternalApprovalState.PendingSign ||
_obj.InternalApprovalState == Docflow.OfficialDocument.InternalApprovalState.Signed);
isEnabled = isEnabled && enabledState;
// Признак "Типовой"
supProperties.IsStandard.IsEnabled = isEnabled;
// Ведущий документ.
var leadingNumberIncludedInNumber = isRepeatRegister && _obj.DocumentRegister != null &&
(_obj.DocumentRegister.NumberFormatItems.Any(n => n.Element == Docflow.DocumentRegisterNumberFormatItems.Element.LeadingNumber) ||
_obj.DocumentRegister.NumberingSection == Docflow.DocumentRegister.NumberingSection.LeadingDocument);
supProperties.LeadingDocument.IsEnabled = isEnabled && !leadingNumberIncludedInNumber || _obj.Contact == null;
}
this.EnableRegistrationNumberAndDate();
}
/// <summary>
/// Добавить связанные с допсоглашением документы в группу вложений.
/// </summary>
/// <param name="group">Группа вложений.</param>
public override void AddRelatedDocumentsToAttachmentGroup(Sungero.Workflow.Interfaces.IWorkflowEntityAttachmentGroup group)
{
// Получить договор.
var contractDocuments = _obj.Relations.GetRelatedFrom(Constants.Module.SupAgreementRelationName);
var documentsToAdd = contractDocuments.Where(d => !group.All.Contains(d)).ToList();
foreach (var document in documentsToAdd)
group.All.Add(document);
}
public override void SetRequiredProperties()
{
base.SetRequiredProperties();
// Изменить обязательность полей в зависимости от того, программная или визуальная работа.
var isVisualMode = ((Domain.Shared.IExtendedEntity)_obj).Params.ContainsKey(Sungero.Docflow.PublicConstants.OfficialDocument.IsVisualModeParamName);
// При визуальной работе обязательность ведущего документа как в SupAgreement.
// При программной работе поле делаем необязательными, чтобы сбросить обязательность,
// если она изменилась в вызове текущего метода в базовой сущности.
_obj.State.Properties.LeadingDocument.IsRequired = isVisualMode;
}
/// <summary>
/// Заполнить свойство "Ведущий документ" в зависимости от типа документа.
/// </summary>
/// <param name="leadingDocument">Ведущий документ.</param>
/// <remarks>Используется при смене типа.</remarks>
public override void FillLeadingDocument(Docflow.IOfficialDocument leadingDocument)
{
var contract = ContractBases.As(leadingDocument);
if (contract != null && (_obj.Counterparty == null || Equals(_obj.Counterparty, contract.Counterparty)))
_obj.LeadingDocument = contract;
else
_obj.LeadingDocument = null;
}
}
}