ContractStatementSharedFunctions.cs
6.63 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow;
using Sungero.FinancialArchive.ContractStatement;
namespace Sungero.FinancialArchive.Shared
{
partial class ContractStatementFunctions
{
/// <summary>
/// Проверить акт на дубли.
/// </summary>
/// <param name="contractStatement">Акт.</param>
/// <param name="businessUnit">НОР.</param>
/// <param name="registrationNumber">Рег. номер.</param>
/// <param name="registrationDate">Дата регистрации.</param>
/// <param name="counterparty">Контрагент.</param>
/// <param name="leadingDocument">Ведущий документ.</param>
/// <returns>Признак дублей.</returns>
public static bool HaveDuplicates(IContractStatement contractStatement,
Sungero.Company.IBusinessUnit businessUnit,
string registrationNumber,
DateTime? registrationDate,
Sungero.Parties.ICounterparty counterparty,
Docflow.IOfficialDocument leadingDocument)
{
if (contractStatement == null ||
businessUnit == null ||
string.IsNullOrWhiteSpace(registrationNumber) ||
registrationDate == null ||
counterparty == null ||
leadingDocument == null)
return false;
return Functions.ContractStatement.Remote.GetDuplicates(contractStatement,
businessUnit,
registrationNumber,
registrationDate,
counterparty,
leadingDocument)
.Any();
}
#region Регистрация
/// <summary>
/// Получить номер ведущего документа.
/// </summary>
/// <returns>Номер документа либо пустая строка.</returns>
public override string GetLeadDocumentNumber()
{
if (_obj.LeadingDocument != null)
{
return _obj.LeadingDocument.AccessRights.CanRead() ?
_obj.LeadingDocument.RegistrationNumber :
Contracts.PublicFunctions.ContractualDocument.Remote.GetRegistrationNumberIgnoreAccessRights(_obj.LeadingDocument.Id);
}
return string.Empty;
}
#endregion
/// <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 && _obj.IsFormalized != true))
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)
{
if (Contracts.ContractBases.Is(_obj.LeadingDocument))
name += Contracts.PublicFunctions.ContractBase.GetContractNamePart(Contracts.ContractBases.As(_obj.LeadingDocument));
else
name += Contracts.PublicFunctions.SupAgreement.GetSupAgreementNamePart(Contracts.SupAgreements.As(_obj.LeadingDocument));
}
else
{
if (_obj.Counterparty != null)
name += Docflow.AccountingDocumentBases.Resources.NamePartForContractor + _obj.Counterparty.DisplayValue;
}
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>
/// <returns>Ответственный за документ.</returns>
public override Sungero.Company.IEmployee GetDocumentResponsibleEmployee()
{
if (_obj.ResponsibleEmployee != null)
return _obj.ResponsibleEmployee;
return base.GetDocumentResponsibleEmployee();
}
/// <summary>
/// Получить список адресатов с электронной почтой для отправки вложением в письмо.
/// </summary>
/// <returns>Список адресатов.</returns>
[Public]
public override List<Sungero.Docflow.Structures.OfficialDocument.IEmailAddressee> GetEmailAddressees()
{
return Functions.Module.GetEmailAddressees(_obj);
}
#region Интеллектуальная обработка
[Public]
public override bool IsVerificationModeSupported()
{
return true;
}
#endregion
}
}