DocumentKindServerFunctions.cs
6.24 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Content;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow.DocumentKind;
using Sungero.Domain.Shared;
namespace Sungero.Docflow.Server
{
partial class DocumentKindFunctions
{
/// <summary>
/// Получить список доступных видов документов для документа.
/// </summary>
/// <param name="document">Документ.</param>
/// <returns>Доступные виды.</returns>
[Public]
public static IQueryable<IDocumentKind> GetAvailableDocumentKinds(IOfficialDocument document)
{
var documentKinds = DocumentKinds.GetAll(r => r.Status == CoreEntities.DatabookEntry.Status.Active);
var type = document.GetType();
var typeProperty = type.GetProperty("TypeGuid");
if (typeProperty != null)
{
var typeGuid = ((Guid)typeProperty.GetValue(document)).GetOriginalTypeGuid().ToString();
documentKinds = documentKinds.Where(k => k.DocumentType.DocumentTypeGuid == typeGuid);
}
return documentKinds;
}
/// <summary>
/// Получить вид, созданный при инициализации.
/// </summary>
/// <param name="externalLink">Уникальный GUID для конкретного вида.</param>
/// <returns>Вид документа.</returns>
[Public]
public static IDocumentKind GetNativeDocumentKind(Guid externalLink)
{
var link = Functions.Module.GetExternalLink(DocumentKind.ClassTypeGuid, externalLink);
if (link == null)
return null;
return DocumentKinds.GetAll(r => r.Id == link.EntityId).SingleOrDefault();
}
/// <summary>
/// Получить вид, созданный при инициализации.
/// </summary>
/// <param name="externalLink">Уникальный GUID для конкретного вида.</param>
/// <returns>Вид документа.</returns>
/// <remarks>Используется при импорте шаблонов документов.</remarks>
[Public, Remote(IsPure = true)]
public static IDocumentKind GetNativeDocumentKindRemote(Guid externalLink)
{
return GetNativeDocumentKind(externalLink);
}
/// <summary>
/// Получить Guid вида документа.
/// </summary>
/// <returns>Guid вида документа.</returns>
public virtual string GetDocumentKindGuid()
{
return Domain.ModuleFunctions.GetAllExternalLinks(l => l.EntityTypeGuid == Constants.Module.DocumentKindTypeGuid && Equals(l.EntityId, _obj.Id))
.Select(s => s.ExternalEntityId)
.FirstOrDefault();
}
/// <summary>
/// Определить, относится ли вид документа к документам МКДО, созданным при инициализации.
/// </summary>
/// <returns>True, если вид документа создан при инициализации.</returns>
public bool IsExchangeNativeDocumentKind()
{
return Domain.ModuleFunctions.GetAllExternalLinks(l => l.ExternalSystemId == Constants.Module.InitializeExternalLinkSystem && Equals(l.EntityId, _obj.Id) &&
(l.ExternalEntityId == Constants.DocumentKind.ContractStatementKind.ToString() ||
l.ExternalEntityId == Constants.DocumentKind.IncomingTaxInvoiceKind.ToString() ||
l.ExternalEntityId == Constants.DocumentKind.OutgoingTaxInvoiceKind.ToString() ||
l.ExternalEntityId == Constants.DocumentKind.UniversalBasicKind.ToString() ||
l.ExternalEntityId == Constants.DocumentKind.UniversalTaxInvoiceAndBasicKind.ToString() ||
l.ExternalEntityId == Constants.DocumentKind.WaybillDocumentKind.ToString() ||
l.ExternalEntityId == Docflow.Constants.Module.Initialize.ExchangeKind.ToString() ||
l.ExternalEntityId == Docflow.Constants.Module.Initialize.FormalizedPowerOfAttorneyKind.ToString()))
.Any();
}
/// <summary>
/// Получить виды документов.
/// </summary>
/// <returns>Виды документов.</returns>
[Remote(IsPure = true), Public]
public static IQueryable<IDocumentKind> GetDocumentKinds()
{
var approvalAction = Functions.Module.GetSendAction(OfficialDocuments.Info.Actions.SendForApproval);
return DocumentKinds.GetAll().Where(k => k.Status == Docflow.DocumentKind.Status.Active && k.AvailableActions.Any(a => a.Action == approvalAction));
}
/// <summary>
/// Признак того, что есть виды документов с незаполненным кодом.
/// </summary>
/// <returns>True - если есть виды документов без кода, иначе - false.</returns>
[Remote(IsPure = true)]
public static bool HasDocumentKindWithNullCode()
{
return DocumentKinds.GetAll().Any(x => x.Status == CoreEntities.DatabookEntry.Status.Active && x.Code == null);
}
/// <summary>
/// Получить виды документов.
/// </summary>
/// <returns>Виды документов.</returns>
[Remote(IsPure = true)]
public static IQueryable<IDocumentKind> GetAllDocumentKinds()
{
return DocumentKinds.GetAll();
}
/// <summary>
/// Выдать права по умолчанию на вид документа.
/// </summary>
public virtual void GrantDefaultAccessRightDocumentKind()
{
_obj.AccessRights.Grant(Roles.AllUsers, Constants.DocumentKind.DocumentKindChoiseAccessRightType);
// Если выдали права в событии создания, то платформа не добавляет автора с полными правами.
_obj.AccessRights.Grant(Users.Current, DefaultAccessRightsTypes.FullAccess);
}
}
}