ModuleInitializer.cs
22 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow;
using Sungero.Docflow.ApprovalStage;
using Sungero.Domain.Initialization;
using Init = Sungero.FinancialArchive.Constants.Module.Initialize;
namespace Sungero.FinancialArchive.Server
{
public partial class ModuleInitializer
{
public override void Initializing(Sungero.Domain.ModuleInitializingEventArgs e)
{
// Создание ролей.
InitializationLogger.Debug("Init: Create roles.");
CreateRoles();
// Выдача прав роли "Ответственные за финансовый архив".
InitializationLogger.Debug("Init: Grant right on financial documents for responsible.");
GrantRightToFinancialResponsible();
CreateDocumentTypes();
CreateDocumentKinds();
CreateFinancialDocumentRegistersAndSettings();
CreateDefaultFinancialApprovalRules();
CreateReportsTables();
}
/// <summary>
/// Создать предопределенные роли.
/// </summary>
public static void CreateRoles()
{
InitializationLogger.Debug("Init: Create Default Roles");
Docflow.PublicInitializationFunctions.Module.CreateRole(Resources.RoleNameFinancialArchiveResponsible, Resources.DescriptionFinancialArchiveResponsible, FinancialArchive.Constants.Module.FinancialArchiveResponsibleRole);
}
/// <summary>
/// Выдать права роли "Ответственные за финансовый архив".
/// </summary>
public static void GrantRightToFinancialResponsible()
{
InitializationLogger.Debug("Init: Grant rights on financial document to responsible managers.");
var financialResponsible = Roles.GetAll().Where(n => n.Sid == FinancialArchive.Constants.Module.FinancialArchiveResponsibleRole).FirstOrDefault();
if (financialResponsible == null)
return;
var allUsers = Roles.AllUsers;
// Если нет лицензии на финансовые документы (есть такие неудачные лицензии, где оно требуется), то используем РОФ.
var hasLicense = Docflow.PublicFunctions.Module.Remote.IsModuleAvailableByLicense(Guid.Parse("59797aba-7718-45df-8ac1-5bb7a36c7a66"));
Dictionary<int, byte[]> licenses = null;
try
{
if (!hasLicense)
{
licenses = Docflow.PublicFunctions.Module.ReadLicense();
Docflow.PublicFunctions.Module.DeleteLicense();
}
// Права на документы.
IncomingTaxInvoices.AccessRights.Grant(financialResponsible, DefaultAccessRightsTypes.Create);
OutgoingTaxInvoices.AccessRights.Grant(financialResponsible, DefaultAccessRightsTypes.Create);
Waybills.AccessRights.Grant(financialResponsible, DefaultAccessRightsTypes.Create);
ContractStatements.AccessRights.Grant(financialResponsible, DefaultAccessRightsTypes.Create);
UniversalTransferDocuments.AccessRights.Grant(financialResponsible, DefaultAccessRightsTypes.Create);
IncomingTaxInvoices.AccessRights.Save();
OutgoingTaxInvoices.AccessRights.Save();
Waybills.AccessRights.Save();
ContractStatements.AccessRights.Save();
UniversalTransferDocuments.AccessRights.Save();
Contracts.OutgoingInvoices.AccessRights.Grant(financialResponsible, DefaultAccessRightsTypes.Create);
Contracts.OutgoingInvoices.AccessRights.Save();
// Права на отчет.
Reports.AccessRights.Grant(Reports.GetFinArchiveExportReport().Info, allUsers, DefaultReportAccessRightsTypes.Execute);
}
finally
{
Docflow.PublicFunctions.Module.RestoreLicense(licenses);
}
GrantRightOnFolders(allUsers);
}
/// <summary>
/// Выдать права на спец.папки.
/// </summary>
/// <param name="role">Роль.</param>
public static void GrantRightOnFolders(IRole role)
{
var hasLicense = Docflow.PublicFunctions.Module.Remote.IsModuleAvailableByLicense(Guid.Parse("e99ae7e2-edb7-4904-a19a-4577f07609a4"));
Dictionary<int, byte[]> licenses = null;
try
{
if (!hasLicense)
{
licenses = Docflow.PublicFunctions.Module.ReadLicense();
Docflow.PublicFunctions.Module.DeleteLicense();
}
// Права на папку "Договоры и доп.согл.".
FinancialArchiveUI.SpecialFolders.FinContractList.AccessRights.Grant(role, DefaultAccessRightsTypes.Read);
FinancialArchiveUI.SpecialFolders.FinContractList.AccessRights.Save();
// Права на папку "Отсутствуют скан-копии".
FinancialArchiveUI.SpecialFolders.DocumentsWithoutScan.AccessRights.Grant(role, DefaultAccessRightsTypes.Read);
FinancialArchiveUI.SpecialFolders.DocumentsWithoutScan.AccessRights.Save();
// Права на папку "Ожидают подписания".
FinancialArchiveUI.SpecialFolders.SignAwaitedDocuments.AccessRights.Grant(role, DefaultAccessRightsTypes.Read);
FinancialArchiveUI.SpecialFolders.SignAwaitedDocuments.AccessRights.Save();
// Права на папку "Реестр доверенностей".
FinancialArchiveUI.SpecialFolders.PowerOfAttorneyList.AccessRights.Grant(role, DefaultAccessRightsTypes.Read);
FinancialArchiveUI.SpecialFolders.PowerOfAttorneyList.AccessRights.Save();
}
finally
{
Docflow.PublicFunctions.Module.RestoreLicense(licenses);
}
}
/// <summary>
/// Получить вид документа, созданный при инициализации.
/// </summary>
/// <param name="documentKindEntityGuid">ИД экземпляра, созданного при инициализации.</param>
/// <returns>Вид документа.</returns>
public static Docflow.IDocumentKind GetDefaultDocumentKind(Guid documentKindEntityGuid)
{
var externalLink = Docflow.PublicFunctions.Module.GetExternalLink(Init.DocumentKindTypeGuid, documentKindEntityGuid);
return Docflow.DocumentKinds.GetAll().Where(x => x.Id == externalLink.EntityId).FirstOrDefault();
}
/// <summary>
/// Создать правило по умолчанию.
/// </summary>
/// <param name="ruleName">Имя правила.</param>
/// <param name="documentFlow">Документопоток.</param>
/// <param name="stages">Этапы.</param>
/// <returns>Созданное правило. Если правило создано не было, то null.</returns>
[Public]
public static Contracts.IContractsApprovalRule CreateDefaultRule(string ruleName, Enumeration documentFlow, List<Enumeration> stages)
{
var hasNotDefaultRule = Docflow.ApprovalRuleBases.GetAll().Any(r => r.IsDefaultRule != true);
var hasDefaultRule = Docflow.ApprovalRuleBases.GetAll().Any(r => r.DocumentFlow == documentFlow
&& r.DocumentKinds.Any(d => d.DocumentKind.DocumentType.DocumentTypeGuid == Waybill.ClassTypeGuid.ToString() ||
d.DocumentKind.DocumentType.DocumentTypeGuid == UniversalTransferDocument.ClassTypeGuid.ToString() ||
d.DocumentKind.DocumentType.DocumentTypeGuid == ContractStatement.ClassTypeGuid.ToString()));
if (hasNotDefaultRule || hasDefaultRule)
return null;
var rule = Contracts.ContractsApprovalRules.Create();
rule.Status = Sungero.Docflow.ApprovalRuleBase.Status.Active;
rule.Name = ruleName;
rule.DocumentFlow = documentFlow;
rule.IsDefaultRule = true;
// Виды финансовых документов.
var documentKindsGuids = new List<Guid> { Init.ContractStatementKind, Init.WaybillDocumentKind, Init.UniversalTaxInvoiceAndBasicKind, Init.UniversalBasicKind };
foreach (var docKindGuid in documentKindsGuids)
{
var docKind = GetDefaultDocumentKind(docKindGuid);
if (docKind != null)
rule.DocumentKinds.AddNew().DocumentKind = docKind;
}
Docflow.PublicInitializationFunctions.Module.SetRuleStages(rule, stages);
Docflow.PublicFunctions.ApprovalRuleBase.CreateAutoTransitions(rule);
rule.Save();
return rule;
}
/// <summary>
/// Создать правила согласования по умолчанию для финансовых документов.
/// </summary>
public static void CreateDefaultFinancialApprovalRules()
{
InitializationLogger.Debug("Init: Create default financial approval rules.");
var stages = new List<Enumeration>
{ StageType.Manager, StageType.Approvers, StageType.Print, StageType.Sign, StageType.Sending, StageType.CheckReturn, StageType.Notice };
var rule = CreateDefaultRule(Resources.DefaultApprovalRuleNameFinancial,
Docflow.ApprovalRuleBase.DocumentFlow.Contracts,
stages);
// Добавить условие по способу отправки и непосредственный руководитель - подписывающий, для созданного правила.
if (rule != null)
{
var condition = Contracts.ContractConditions.Create();
condition.ConditionType = Docflow.ConditionBase.ConditionType.DeliveryMethod;
var newDeliveryMethod = condition.DeliveryMethods.AddNew();
newDeliveryMethod.DeliveryMethod = Docflow.MailDeliveryMethods.GetAll(m => m.Sid == Docflow.Constants.MailDeliveryMethod.Exchange).FirstOrDefault();
condition.Save();
var printStageNumber = stages.IndexOf(StageType.Print) + 1;
Docflow.PublicInitializationFunctions.Module.AddConditionToRule(rule, condition, printStageNumber);
var rolesCompareCondition = Docflow.PublicInitializationFunctions.Module.CreateRoleCompareSignatoryAndInitManagerCondition(Contracts.ContractConditions.Create());
var managerStageNumber = stages.IndexOf(StageType.Manager) + 1;
Docflow.PublicInitializationFunctions.Module.AddConditionToRule(rule, rolesCompareCondition, managerStageNumber);
}
}
/// <summary>
/// Создать типы документов для финансового архива.
/// </summary>
public static void CreateDocumentTypes()
{
Docflow.PublicInitializationFunctions.Module.CreateDocumentType(Resources.WaybillDocumentTypeName, Waybill.ClassTypeGuid,
Docflow.DocumentType.DocumentFlow.Contracts, true);
Docflow.PublicInitializationFunctions.Module.CreateDocumentType(Resources.IncomingTaxInvoiceTypeName, IncomingTaxInvoice.ClassTypeGuid,
Docflow.DocumentType.DocumentFlow.Incoming, true);
Docflow.PublicInitializationFunctions.Module.CreateDocumentType(Resources.OutgoingTaxInvoiceTypeName, OutgoingTaxInvoice.ClassTypeGuid,
Docflow.DocumentType.DocumentFlow.Outgoing, true);
Docflow.PublicInitializationFunctions.Module.CreateDocumentType(Resources.ContractStatementTypeName, ContractStatement.ClassTypeGuid,
Docflow.DocumentType.DocumentFlow.Contracts, true);
Docflow.PublicInitializationFunctions.Module.CreateDocumentType(Resources.UniversalTransferDocumentTypeName, UniversalTransferDocument.ClassTypeGuid,
Docflow.DocumentType.DocumentFlow.Contracts, true);
}
/// <summary>
/// Создать виды документов для финансового архива.
/// </summary>
public static void CreateDocumentKinds()
{
var notifiable = Docflow.DocumentKind.NumberingType.Registrable;
var numerable = Docflow.DocumentKind.NumberingType.Numerable;
var notNumerable = Docflow.DocumentKind.NumberingType.NotNumerable;
Docflow.PublicInitializationFunctions.Module.CreateDocumentKind(Resources.WaybillDocumentKindName,
Resources.WaybillDocumentKindShortName,
numerable, Docflow.DocumentKind.DocumentFlow.Contracts,
true, false, Waybill.ClassTypeGuid,
new[] { Waybills.Info.Actions.SendForFreeApproval, Waybills.Info.Actions.SendForApproval },
Init.WaybillDocumentKind);
Docflow.PublicInitializationFunctions.Module.CreateDocumentKind(Resources.IncomingTaxInvoiceKindName,
Resources.IncomingTaxInvoiceKindShortName,
numerable, Docflow.DocumentKind.DocumentFlow.Incoming,
true, false, IncomingTaxInvoice.ClassTypeGuid,
new[] { IncomingTaxInvoices.Info.Actions.SendForFreeApproval },
Init.IncomingTaxInvoiceKind);
Docflow.PublicInitializationFunctions.Module.CreateDocumentKind(Resources.OutgoingTaxInvoiceKindName,
Resources.OutgoingTaxInvoiceKindShortName,
numerable, Docflow.DocumentKind.DocumentFlow.Outgoing,
true, false, OutgoingTaxInvoice.ClassTypeGuid,
new[] { OutgoingTaxInvoices.Info.Actions.SendForFreeApproval },
Init.OutgoingTaxInvoiceKind);
Docflow.PublicInitializationFunctions.Module.CreateDocumentKind(Resources.ContractStatementKindName,
Resources.ContractStatementKindShortName,
numerable, Docflow.DocumentKind.DocumentFlow.Contracts,
true, false, ContractStatement.ClassTypeGuid, null, Init.ContractStatementKind, true);
Docflow.PublicInitializationFunctions.Module.CreateDocumentKind(Resources.UniversalTaxInvoiceAndBasicKindName,
Resources.UniversalTaxInvoiceAndBasicKindShortName,
numerable, Docflow.DocumentKind.DocumentFlow.Contracts,
true, false, UniversalTransferDocument.ClassTypeGuid, null, Init.UniversalTaxInvoiceAndBasicKind, false);
Docflow.PublicInitializationFunctions.Module.CreateDocumentKind(Resources.UniversalBasicKindName,
Resources.UniversalBasicKindShortName,
numerable, Docflow.DocumentKind.DocumentFlow.Contracts,
true, false, UniversalTransferDocument.ClassTypeGuid, null, Init.UniversalBasicKind);
}
/// <summary>
/// Создать журнал и настройки регистрации для счетов и накладных.
/// </summary>
public static void CreateFinancialDocumentRegistersAndSettings()
{
InitializationLogger.Debug("Init: Create default logs and settings for financial archive.");
var taxInvoiceOutgoingDocumentRegister = CreateLeadNumberedDocumentRegister(Resources.RegistersAndSettingsOutgoingTaxInvoiceName,
Resources.RegistersAndSettingsOutgoingTaxInvoiceIndex,
Docflow.RegistrationSetting.DocumentFlow.Outgoing,
Init.OutgoingTaxInvoiceRegister);
var taxInvoiceIncomingDocumentRegister = CreateLeadNumberedDocumentRegister(Resources.RegistersAndSettingsIncomingTaxInvoiceName,
Resources.RegistersAndSettingsIncomingTaxInvoiceIndex,
Docflow.RegistrationSetting.DocumentFlow.Incoming,
Init.IncomingTaxInvoiceRegister);
var waybillDocumentRegister = CreateLeadNumberedDocumentRegister(Resources.RegistersAndSettingsWaybillName,
Resources.RegistersAndSettingsWaybillIndex,
Docflow.RegistrationSetting.DocumentFlow.Contracts,
Init.WaybillRegister);
var actDocumentRegister = CreateLeadNumberedDocumentRegister(Resources.RegistersAndSettingsActName,
Resources.RegistersAndSettingsActIndex,
Docflow.DocumentRegister.DocumentFlow.Contracts,
Init.ContractStatementRegister);
var universalDocumentRegister = CreateLeadNumberedDocumentRegister(Resources.RegistersAndSettingsUniversalName,
Resources.RegistersAndSettingsUniversalIndex,
Docflow.DocumentRegister.DocumentFlow.Contracts,
Init.UniversalRegister);
Docflow.PublicInitializationFunctions.Module.CreateNumerationSetting(OutgoingTaxInvoice.ClassTypeGuid,
Docflow.RegistrationSetting.DocumentFlow.Outgoing,
taxInvoiceOutgoingDocumentRegister);
Docflow.PublicInitializationFunctions.Module.CreateNumerationSetting(IncomingTaxInvoice.ClassTypeGuid,
Docflow.RegistrationSetting.DocumentFlow.Incoming,
taxInvoiceIncomingDocumentRegister);
Docflow.PublicInitializationFunctions.Module.CreateNumerationSetting(Waybill.ClassTypeGuid,
Docflow.RegistrationSetting.DocumentFlow.Contracts,
waybillDocumentRegister);
Docflow.PublicInitializationFunctions.Module.CreateNumerationSetting(ContractStatement.ClassTypeGuid,
Docflow.RegistrationSetting.DocumentFlow.Contracts,
actDocumentRegister);
Docflow.PublicInitializationFunctions.Module.CreateNumerationSetting(UniversalTransferDocument.ClassTypeGuid,
Docflow.RegistrationSetting.DocumentFlow.Contracts,
universalDocumentRegister);
}
/// <summary>
/// Создать журнал.
/// </summary>
/// <param name="name">Название.</param>
/// <param name="index">Индекс.</param>
/// <param name="documentFlow">Документопоток.</param>
/// <param name="entityId">ИД инициализации.</param>
/// <returns>Журнал.</returns>
public static Docflow.IDocumentRegister CreateLeadNumberedDocumentRegister(string name, string index, Enumeration documentFlow, Guid entityId)
{
var documentRegister = Docflow.PublicInitializationFunctions.Module.CreateNumerationDocumentRegister(name,
index,
documentFlow,
entityId);
if (documentRegister != null &&
documentRegister.NumberingPeriod != Docflow.DocumentRegister.NumberingPeriod.Year)
documentRegister.NumberingPeriod = Docflow.DocumentRegister.NumberingPeriod.Year;
return documentRegister;
}
/// <summary>
/// Создать таблицы для отчетов.
/// </summary>
public static void CreateReportsTables()
{
var finArchiveExportReportTableName = Constants.FinArchiveExportReport.SourceTableName;
Docflow.PublicFunctions.Module.DropReportTempTables(new[] { finArchiveExportReportTableName });
Docflow.PublicFunctions.Module.ExecuteSQLCommandFormat(Queries.FinArchiveExportReport.CreateFinArchiveExportReportTable, new[] { finArchiveExportReportTableName });
}
}
}