AccountingDocumentBaseHandlers.cs
6.38 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow.AccountingDocumentBase;
namespace Sungero.Docflow
{
partial class AccountingDocumentBaseVersionsSharedCollectionHandlers
{
public override void VersionsAdded(Sungero.Domain.Shared.CollectionPropertyAddedEventArgs e)
{
base.VersionsAdded(e);
// Если это формализованный документ и один титул уже есть, то при формировании второго титула не сбрасываем статусы эл. обмена и согласования с КА.
if (_obj.IsFormalized == true && _obj.SellerTitleId.HasValue)
{
_obj.ExternalApprovalState = _obj.State.Properties.ExternalApprovalState.OriginalValue;
_obj.ExchangeState = _obj.State.Properties.ExchangeState.OriginalValue;
}
}
}
partial class AccountingDocumentBaseSharedHandlers
{
public virtual void CounterpartySigningReasonChanged(Sungero.Domain.Shared.StringPropertyChangedEventArgs e)
{
if (e.NewValue == e.OldValue || e.NewValue == null)
return;
var trimmedReason = e.NewValue.Trim();
if (e.NewValue == trimmedReason)
return;
_obj.CounterpartySigningReason = trimmedReason;
}
public virtual void CorrectedChanged(Sungero.Docflow.Shared.AccountingDocumentBaseCorrectedChangedEventArgs e)
{
_obj.Relations.AddFromOrUpdate(Constants.Module.CorrectionRelationName, e.OldValue, e.NewValue);
if (e.NewValue != null && _obj.Counterparty == null)
_obj.Counterparty = e.NewValue.Counterparty;
}
public virtual void IsAdjustmentChanged(Sungero.Domain.Shared.BooleanPropertyChangedEventArgs e)
{
FillName();
if (e.NewValue == false)
_obj.Corrected = null;
}
public override void LeadingDocumentChanged(Sungero.Docflow.Shared.OfficialDocumentLeadingDocumentChangedEventArgs e)
{
base.LeadingDocumentChanged(e);
if (Equals(e.NewValue, e.OldValue))
return;
if (e.NewValue != null && _obj.Counterparty == null)
_obj.Counterparty = AccountingDocumentBases.Is(e.NewValue)
? Docflow.AccountingDocumentBases.As(e.NewValue).Counterparty
: Contracts.ContractualDocuments.As(e.NewValue).Counterparty;
if (e.NewValue != null && _obj.BusinessUnit == null)
_obj.BusinessUnit = e.NewValue.BusinessUnit;
if (e.NewValue != null)
Docflow.PublicFunctions.OfficialDocument.CopyProjects(e.NewValue, _obj);
FillName();
_obj.Relations.AddFromOrUpdate(Contracts.PublicConstants.Module.AccountingDocumentsRelationName, e.OldValue, e.NewValue);
}
public override void LifeCycleStateChanged(Sungero.Domain.Shared.EnumerationPropertyChangedEventArgs e)
{
}
public override void OurSignatoryChanged(Sungero.Docflow.Shared.OfficialDocumentOurSignatoryChangedEventArgs e)
{
base.OurSignatoryChanged(e);
if (e.NewValue != null && e.NewValue != e.OldValue)
{
if (_obj.BusinessUnit == null)
{
var businessUnit = Company.PublicFunctions.BusinessUnit.Remote.GetBusinessUnit(e.NewValue);
if (businessUnit != null)
_obj.BusinessUnit = businessUnit;
}
}
}
public virtual void CounterpartySignatoryChanged(Sungero.Docflow.Shared.AccountingDocumentBaseCounterpartySignatoryChangedEventArgs e)
{
if (e.NewValue != null && _obj.Counterparty == null)
_obj.Counterparty = e.NewValue.Company;
if (_obj.ExternalApprovalState != ExternalApprovalState.Signed)
{
_obj.CounterpartySigningReason = e.NewValue != null
? e.NewValue.SigningReason
: string.Empty;
}
}
public virtual void CounterpartyChanged(Sungero.Docflow.Shared.AccountingDocumentBaseCounterpartyChangedEventArgs e)
{
// При изменении организации почистить подписывающего и контакта.
if (e.NewValue != null && !Equals(e.NewValue, e.OldValue))
{
if (_obj.CounterpartySignatory != null && !Equals(_obj.CounterpartySignatory.Company, e.NewValue))
_obj.CounterpartySignatory = null;
if (_obj.Contact != null && !Equals(_obj.Contact.Company, e.NewValue))
_obj.Contact = null;
if (_obj.LeadingDocument != null &&
((Docflow.AccountingDocumentBases.Is(_obj.LeadingDocument) && !Equals(Docflow.AccountingDocumentBases.As(_obj.LeadingDocument).Counterparty, e.NewValue)) ||
(Contracts.ContractualDocuments.Is(_obj.LeadingDocument) && !Equals(Contracts.ContractualDocuments.As(_obj.LeadingDocument).Counterparty, e.NewValue))))
_obj.LeadingDocument = null;
}
var isCompany = Sungero.Parties.CompanyBases.Is(e.NewValue) || e.NewValue == null;
_obj.State.Properties.Contact.IsEnabled = isCompany;
_obj.State.Properties.CounterpartySignatory.IsEnabled = isCompany;
FillName();
}
public virtual void ContactChanged(Sungero.Docflow.Shared.AccountingDocumentBaseContactChangedEventArgs e)
{
if (e.NewValue != null && _obj.Counterparty == null)
_obj.Counterparty = e.NewValue.Company;
}
public virtual void ResponsibleEmployeeChanged(Sungero.Docflow.Shared.AccountingDocumentBaseResponsibleEmployeeChangedEventArgs e)
{
if (e.NewValue != null && _obj.BusinessUnit == null)
{
var businessUnit = Company.PublicFunctions.BusinessUnit.Remote.GetBusinessUnit(e.NewValue);
if (businessUnit != null)
_obj.BusinessUnit = businessUnit;
}
}
public virtual void TotalAmountChanged(Sungero.Domain.Shared.DoublePropertyChangedEventArgs e)
{
if (e.NewValue == null)
return;
// Подставить по умолчанию валюту рубль.
if (_obj.Currency == null)
{
var defaultCurrency = Commons.PublicFunctions.Currency.Remote.GetDefaultCurrency();
if (defaultCurrency != null)
_obj.Currency = defaultCurrency;
}
}
public virtual void DateChanged(Sungero.Domain.Shared.DateTimePropertyChangedEventArgs e)
{
FillName();
}
public virtual void NumberChanged(Sungero.Domain.Shared.StringPropertyChangedEventArgs e)
{
FillName();
}
}
}