ModuleServerFunctions.cs
8.35 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Company;
using Sungero.Contracts;
using Sungero.Core;
using Sungero.CoreEntities;
namespace Sungero.ContractsUI.Server
{
public class ModuleFunctions
{
#region Виджеты
/// <summary>
/// Получить все договоры и доп. соглашения в стадии согласования, где Я ответственный.
/// </summary>
/// <param name="query">Запрос виджета.</param>
/// <param name="substitution">Параметр "Учитывать замещения".</param>
/// <param name="show">Параметр "Показывать".</param>
/// <returns>Список договоров и доп. соглашений.</returns>
public IQueryable<Sungero.Contracts.IContractualDocument> GetMyContractualDocuments(IQueryable<Sungero.Contracts.IContractualDocument> query,
bool substitution,
Enumeration show)
{
query = query.Where(cd => ContractBases.Is(cd) || SupAgreements.Is(cd));
// Проверить статус жизненного цикла.
query = query.Where(cd => cd.LifeCycleState == Docflow.OfficialDocument.LifeCycleState.Draft)
.Where(cd => cd.InternalApprovalState == Docflow.OfficialDocument.InternalApprovalState.OnApproval ||
cd.InternalApprovalState == Docflow.OfficialDocument.InternalApprovalState.OnRework ||
cd.InternalApprovalState == Docflow.OfficialDocument.InternalApprovalState.PendingSign ||
cd.InternalApprovalState == Docflow.OfficialDocument.InternalApprovalState.Signed ||
cd.ExternalApprovalState == Docflow.OfficialDocument.ExternalApprovalState.OnApproval);
// Если показывать надо не все Договоры, то дофильтровываем по ответственному.
if (show != Sungero.ContractsUI.Widgets.MyContracts.Show.All)
{
var currentEmployee = Company.Employees.Current;
var responsibleEmployees = new List<IUser>();
if (currentEmployee != null)
responsibleEmployees.Add(currentEmployee);
var employeeDepartment = currentEmployee != null ? currentEmployee.Department : null;
// Учитывать замещения, если выставлен соответствующий параметр.
if (substitution)
{
var substitutions = Substitutions.ActiveSubstitutedUsersWithoutSystem;
responsibleEmployees.AddRange(substitutions);
}
// Если выбрано значение параметра "Договоры подразделения", то добавляем к списку ответственных всех сотрудников подразделения.
if (show == Sungero.ContractsUI.Widgets.MyContracts.Show.Department)
{
var departmentsEmployees = Company.Employees.GetAll(e => Equals(e.Department, employeeDepartment));
responsibleEmployees.AddRange(departmentsEmployees);
}
query = query.Where(cd => responsibleEmployees.Contains(cd.ResponsibleEmployee));
}
return query;
}
/// <summary>
/// Получить все договоры и доп. соглашения на завершении, где Я ответственный.
/// </summary>
/// <param name="query">Запрос виджета.</param>
/// <param name="needAutomaticRenewal">Признак "С пролонгацией".</param>
/// <param name="substitution">Параметр "Учитывать замещения".</param>
/// <param name="show">Параметр "Показывать".</param>
/// <returns>Список договоров и доп. соглашений на завершении.</returns>
public IQueryable<Sungero.Contracts.IContractualDocument> GetMyExpiringSoonContracts(IQueryable<Sungero.Contracts.IContractualDocument> query,
bool? needAutomaticRenewal,
bool substitution,
Enumeration show)
{
var today = Calendar.UserToday;
var lastDate = today.AddDays(14);
// Если показывать надо не все Договоры, то дофильтровываем по ответственному.
if (show != Sungero.ContractsUI.Widgets.MyContracts.Show.All)
{
var currentEmployee = Employees.Current;
var responsibleEmployees = new List<IUser>();
if (currentEmployee != null)
responsibleEmployees.Add(currentEmployee);
var employeeDepartment = currentEmployee != null ? currentEmployee.Department : null;
// Учитывать замещения, если выставлен соответствующий параметр.
if (substitution)
{
var substitutions = Substitutions.ActiveSubstitutedUsersWithoutSystem;
responsibleEmployees.AddRange(substitutions);
}
// Если выбрано значение параметра "Договоры подразделения", то добавляем к списку ответственных всех сотрудников подразделения.
if (show == Sungero.ContractsUI.Widgets.MyContracts.Show.Department)
{
var departmentsEmployees = Company.Employees.GetAll(e => Equals(e.Department, employeeDepartment));
responsibleEmployees.AddRange(departmentsEmployees);
}
query = query.Where(cd => responsibleEmployees.Contains(cd.ResponsibleEmployee));
}
query = query
.Where(q => ContractBases.Is(q) || SupAgreements.Is(q))
.Where(q => q.LifeCycleState == Sungero.Contracts.SupAgreement.LifeCycleState.Active);
query = query.Where(q => q.ValidTill.HasValue)
.Where(q => (ContractBases.Is(q) && today.AddDays(ContractBases.As(q).DaysToFinishWorks ?? 14) >= q.ValidTill) ||
(SupAgreements.Is(q) && q.ValidTill.Value <= lastDate))
.Where(q => SupAgreements.Is(q) || ContractBases.Is(q) && (ContractBases.As(q).DaysToFinishWorks == null ||
ContractBases.As(q).DaysToFinishWorks <= Docflow.PublicConstants.Module.MaxDaysToFinish));
// Признак с автопролонгацией у договоров.
if (needAutomaticRenewal.HasValue)
query = query.Where(q => ContractBases.Is(q) &&
ContractBases.As(q).IsAutomaticRenewal.HasValue &&
ContractBases.As(q).IsAutomaticRenewal.Value == needAutomaticRenewal.Value);
return query;
}
#endregion
/// <summary>
/// Отфильтровать действующие виды документов с документопотоком "Договоры".
/// </summary>
/// <param name="query">Фильтруемые виды документов.</param>
/// <param name="withoutActs">True, если получить наследников договоров и доп. соглашений. Иначе - все договорные виды документов.</param>
/// <returns>Виды документов.</returns>
[Public]
public static IQueryable<Docflow.IDocumentKind> ContractsFilterContractsKind(IQueryable<Docflow.IDocumentKind> query, bool withoutActs)
{
query = query
.Where(d => d.Status == CoreEntities.DatabookEntry.Status.Active)
.Where(d => d.DocumentFlow == Docflow.DocumentKind.DocumentFlow.Contracts);
if (withoutActs)
{
var supKinds = Docflow.PublicFunctions.DocumentKind.GetAvailableDocumentKinds(typeof(ISupAgreement));
var contractKinds = Docflow.PublicFunctions.DocumentKind.GetAvailableDocumentKinds(typeof(IContractBase));
query = query.Where(k => supKinds.Contains(k) || contractKinds.Contains(k));
}
return query;
}
}
}