ContractBaseServerFunctions.cs
7.81 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
using System;
using System.Collections.Generic;
using System.Linq;
using CommonLibrary;
using Sungero.Contracts.ContractBase;
using Sungero.Core;
using Sungero.CoreEntities;
namespace Sungero.Contracts.Server
{
partial class ContractBaseFunctions
{
/// <summary>
/// Получить дубли договора.
/// </summary>
/// <param name="contract">Договор.</param>
/// <param name="businessUnit">НОР.</param>
/// <param name="registrationNumber">Рег. номер.</param>
/// <param name="registrationDate">Дата регистрации.</param>
/// <param name="counterparty">Контрагент.</param>
/// <returns>Дубли.</returns>
[Remote(IsPure = true)]
public static IQueryable<IContractBase> GetDuplicates(IContractBase contract,
Sungero.Company.IBusinessUnit businessUnit,
string registrationNumber,
DateTime? registrationDate,
Sungero.Parties.ICounterparty counterparty)
{
return ContractBases.GetAll()
.Where(l => Equals(contract.DocumentKind, l.DocumentKind))
.Where(l => Equals(businessUnit, l.BusinessUnit))
.Where(l => registrationDate == l.RegistrationDate)
.Where(l => registrationNumber == l.RegistrationNumber)
.Where(l => Equals(counterparty, l.Counterparty))
.Where(l => !Equals(contract, l));
}
/// <summary>
/// Получить часть имени договора игнорируя права доступа.
/// </summary>
/// <param name="contractId">Договор.</param>
/// <returns>Часть имени.</returns>
[Remote(IsPure = true)]
public static string GetNamePartByContractIgnoreAccessRights(int contractId)
{
return Functions.ContractBase.GetNamePartByContract(Functions.ContractualDocument.GetIgnoreAccessRights(contractId));
}
/// <summary>
/// Получить правила согласования для договоров.
/// </summary>
/// <returns>Правила согласования, удовлетворяющие договору.</returns>
[Remote]
public override List<Sungero.Docflow.IApprovalRuleBase> GetApprovalRules()
{
return base.GetApprovalRules()
.Select(r => ContractsApprovalRules.As(r))
.Where(r => r != null)
.OrderByDescending(r => r.Priority)
.ToList<Sungero.Docflow.IApprovalRuleBase>();
}
/// <summary>
/// Построить сводку по документу.
/// </summary>
/// <returns>Сводка по документу.</returns>
[Remote(IsPure = true)]
public override StateView GetDocumentSummary()
{
var documentSummary = StateView.Create();
var documentBlock = documentSummary.AddBlock();
// Краткое имя документа.
var documentName = _obj.DocumentKind.Name;
if (!string.IsNullOrWhiteSpace(_obj.RegistrationNumber))
documentName += Docflow.OfficialDocuments.Resources.Number + _obj.RegistrationNumber;
if (_obj.RegistrationDate != null)
documentName += Docflow.OfficialDocuments.Resources.DateFrom + _obj.RegistrationDate.Value.ToString("d");
documentBlock.AddLabel(documentName);
// Типовой/Не типовой.
var isStandardLabel = _obj.IsStandard.Value ? ContractBases.Resources.isStandartContract : ContractBases.Resources.isNotStandartContract;
documentBlock.AddLabel(string.Format("({0})", isStandardLabel));
documentBlock.AddLineBreak();
documentBlock.AddLineBreak();
// НОР.
documentBlock.AddLabel(string.Format("{0}: ", _obj.Info.Properties.BusinessUnit.LocalizedName));
if (_obj.BusinessUnit != null)
documentBlock.AddLabel(Hyperlinks.Get(_obj.BusinessUnit));
else
documentBlock.AddLabel("-");
documentBlock.AddLineBreak();
// Контрагент.
documentBlock.AddLabel(string.Format("{0}:", ContractBases.Resources.Counterparty));
if (_obj.Counterparty != null)
{
documentBlock.AddLabel(Hyperlinks.Get(_obj.Counterparty));
if (_obj.Counterparty.Nonresident == true)
documentBlock.AddLabel(string.Format("({0})", _obj.Counterparty.Info.Properties.Nonresident.LocalizedName).ToLower());
}
else
{
documentBlock.AddLabel("-");
}
documentBlock.AddLineBreak();
// Содержание.
var subject = !string.IsNullOrEmpty(_obj.Subject) ? _obj.Subject : "-";
documentBlock.AddLabel(string.Format("{0}: {1}", ContractBases.Resources.Subject, subject));
documentBlock.AddLineBreak();
// Сумма договора.
var amount = this.GetTotalAmountDocumentSummary(_obj.TotalAmount);
var amountText = string.Format("{0}: {1}", _obj.Info.Properties.TotalAmount.LocalizedName, amount);
documentBlock.AddLabel(amountText);
documentBlock.AddLineBreak();
// Валюта.
var currencyText = string.Format("{0}: {1}", _obj.Info.Properties.Currency.LocalizedName, _obj.Currency);
documentBlock.AddLabel(currencyText);
documentBlock.AddLineBreak();
// Срок действия договора.
var validity = "-";
var validFrom = _obj.ValidFrom.HasValue ?
string.Format("{0} {1} ", ContractBases.Resources.From, _obj.ValidFrom.Value.Date.ToShortDateString()) :
string.Empty;
var validTill = _obj.ValidTill.HasValue ?
string.Format("{0} {1}", ContractBases.Resources.Till, _obj.ValidTill.Value.Date.ToShortDateString()) :
string.Empty;
var isAutomaticRenewal = _obj.IsAutomaticRenewal.Value && !string.IsNullOrEmpty(validTill) ?
string.Format(", {0}", ContractBases.Resources.Renewal) :
string.Empty;
if (!string.IsNullOrEmpty(validFrom) || !string.IsNullOrEmpty(validTill))
validity = string.Format("{0}{1}{2}", validFrom, validTill, isAutomaticRenewal);
var validityText = string.Format("{0}:", ContractBases.Resources.Validity);
documentBlock.AddLabel(validityText);
documentBlock.AddLabel(validity);
documentBlock.AddLineBreak();
documentBlock.AddEmptyLine();
// Примечание.
var note = string.IsNullOrEmpty(_obj.Note) ? "-" : _obj.Note;
var noteText = string.Format("{0}:", ContractBases.Resources.Note);
documentBlock.AddLabel(noteText);
documentBlock.AddLabel(note);
return documentSummary;
}
/// <summary>
/// Изменить статус документа на "В разработке".
/// </summary>
public override void SetLifeCycleStateDraft()
{
base.SetLifeCycleStateDraft();
if (_obj.LifeCycleState == Sungero.Contracts.ContractBase.LifeCycleState.Terminated)
{
Logger.DebugFormat("UpdateLifeCycleState: Document {0} changed LifeCycleState to 'Draft'.", _obj.Id);
_obj.LifeCycleState = Docflow.OfficialDocument.LifeCycleState.Draft;
}
}
/// <summary>
/// Проверить, связан ли документ специализированной связью.
/// </summary>
/// <returns>True - если связан, иначе - false.</returns>
[Remote(IsPure = true)]
public override bool HasSpecifiedTypeRelations()
{
var hasSpecifiedTypeRelations = false;
AccessRights.AllowRead(
() =>
{
hasSpecifiedTypeRelations = SupAgreements.GetAll().Any(x => Equals(x.LeadingDocument, _obj));
});
return base.HasSpecifiedTypeRelations() || hasSpecifiedTypeRelations;
}
}
}