ModuleServerFunctions.cs
3.65 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow;
namespace Sungero.RecordManagementUI.Server
{
public class ModuleFunctions
{
#region Поиски
/// <summary>
/// Получить все регистрируемые документы.
/// </summary>
/// <param name="registrationNumber">Регистрационный номер.</param>
/// <param name="registrationDateFrom">Зарегистрирован от.</param>
/// <param name="registrationDateTo">Зарегистрирован по.</param>
/// <param name="documentRegister">Журнал регистрации.</param>
/// <param name="caseFile">Дело.</param>
/// <param name="registeredBy">Кем зарегистрирован.</param>
/// <returns>Список документов, удовлетворяющий условиям.</returns>
[Remote(IsPure = true)]
public static IQueryable<IOfficialDocument> GetFilteredRegisteredDocuments(
string registrationNumber, DateTime? registrationDateFrom, DateTime? registrationDateTo, IDocumentRegister documentRegister, ICaseFile caseFile, Company.IEmployee registeredBy)
{
var documents = OfficialDocuments.GetAll();
if (registrationNumber != null)
documents = documents.Where(l => l.RegistrationNumber.Contains(registrationNumber));
if (registrationDateFrom != null)
documents = documents.Where(l => l.RegistrationDate >= registrationDateFrom);
if (registrationDateTo != null)
{
registrationDateTo = registrationDateTo.Value.Date.EndOfDay();
documents = documents.Where(l => l.RegistrationDate <= registrationDateTo);
}
if (documentRegister != null)
documents = documents.Where(l => Equals(l.DocumentRegister, documentRegister));
if (caseFile != null)
documents = documents.Where(l => Equals(l.CaseFile, caseFile));
if (registeredBy != null)
{
// TODO Zamerov: ересь с операциями.
var regitrationOperation = new Enumeration(Docflow.PublicFunctions.OfficialDocument.GetRegistrationOperation());
documents = documents.WhereDocumentHistory(h => Equals(h.User, registeredBy) && h.Operation == regitrationOperation);
}
return documents;
}
/// <summary>
/// Получить документы с указанным корреспондентом.
/// </summary>
/// <param name="counterparty">Контрагент-корреспондент.</param>
/// <param name="periodBegin">Документы от.</param>
/// <param name="periodEnd">Документы по.</param>
/// <returns>Связанные с корреспондентом документы.</returns>
[Remote(IsPure = true)]
public static IQueryable<IOfficialDocument> GetOfficialCorrespondenceWithCounterparty(
Parties.ICounterparty counterparty, DateTime? periodBegin, DateTime? periodEnd)
{
return OfficialDocuments.GetAll()
.Where(l => l.RegistrationState == Docflow.OfficialDocument.RegistrationState.Reserved ||
l.RegistrationState == Docflow.OfficialDocument.RegistrationState.Registered)
.Where(l => periodBegin == null || l.RegistrationDate >= periodBegin)
.Where(l => periodEnd == null || l.RegistrationDate <= periodEnd)
.Where(l => (IncomingDocumentBases.Is(l) && Equals(IncomingDocumentBases.As(l).Correspondent, counterparty)) ||
(OutgoingDocumentBases.Is(l) && OutgoingDocumentBases.As(l).Addressees.Select(x => x.Correspondent).Any(y => Equals(y, counterparty))));
}
#endregion
}
}