IncomingInvoiceServerFunctions.cs
5.84 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
using System;
using System.Collections.Generic;
using System.Linq;
using CommonLibrary;
using Sungero.Contracts.IncomingInvoice;
using Sungero.Core;
using Sungero.CoreEntities;
namespace Sungero.Contracts.Server
{
partial class IncomingInvoiceFunctions
{
/// <summary>
/// Получить дубли входящего счета.
/// </summary>
/// <param name="incomingInvoice">Счет для проверки.</param>
/// <param name="documentKind">Вид счета.</param>
/// <param name="number">Номер счета.</param>
/// <param name="date">Дата счета.</param>
/// <param name="totalAmount">Сумма счета.</param>
/// <param name="currency">Валюта счета.</param>
/// <param name="counterparty">Контрагент счета.</param>
/// <returns>Счета, дублирующие текущий.</returns>
[Remote(IsPure = true)]
public static IQueryable<IIncomingInvoice> GetDuplicates(IIncomingInvoice incomingInvoice,
Sungero.Docflow.IDocumentKind documentKind,
string number,
DateTime? date,
double? totalAmount,
Commons.ICurrency currency,
Parties.ICounterparty counterparty)
{
return IncomingInvoices.GetAll()
.Where(i => i.DocumentKind.Equals(documentKind))
.Where(i => i.Number == number)
.Where(i => i.Date == date)
.Where(i => i.TotalAmount == totalAmount)
.Where(i => i.Currency.Equals(currency))
.Where(i => i.Counterparty.Equals(counterparty))
.Where(i => !Equals(i, incomingInvoice));
}
/// <summary>
/// Сводка по документу.
/// </summary>
/// <returns>Сводка.</returns>
public override StateView GetDocumentSummary()
{
var documentSummary = StateView.Create();
var block = documentSummary.AddBlock();
// Краткое имя документа.
var documentName = _obj.DocumentKind.Name;
if (!string.IsNullOrWhiteSpace(_obj.RegistrationNumber))
documentName += Docflow.OfficialDocuments.Resources.Number + _obj.RegistrationNumber;
if (_obj.RegistrationDate != null)
documentName += Docflow.OfficialDocuments.Resources.DateFrom + _obj.RegistrationDate.Value.ToString("d");
block.AddLabel(documentName);
block.AddLineBreak();
block.AddEmptyLine();
// НОР.
block.AddLabel(string.Format("{0}: ", _obj.Info.Properties.BusinessUnit.LocalizedName));
if (_obj.BusinessUnit != null)
block.AddLabel(Hyperlinks.Get(_obj.BusinessUnit));
else
block.AddLabel("-");
block.AddLineBreak();
// Контрагент.
block.AddLabel(string.Format("{0}: ", _obj.Info.Properties.Counterparty.LocalizedName));
if (_obj.Counterparty != null)
{
block.AddLabel(Hyperlinks.Get(_obj.Counterparty));
if (_obj.Counterparty.Nonresident == true)
block.AddLabel(string.Format("({0})", _obj.Counterparty.Info.Properties.Nonresident.LocalizedName).ToLower());
}
else
{
block.AddLabel("-");
}
block.AddLineBreak();
// Содержание.
var subject = !string.IsNullOrEmpty(_obj.Subject) ? _obj.Subject : "-";
block.AddLabel(string.Format("{0}: {1}", _obj.Info.Properties.Subject.LocalizedName, subject));
block.AddLineBreak();
// Сумма.
var amount = this.GetTotalAmountDocumentSummary(_obj.TotalAmount);
var amountText = string.Format("{0}: {1}", _obj.Info.Properties.TotalAmount.LocalizedName, amount);
block.AddLabel(amountText);
block.AddLineBreak();
// Валюта.
var currencyText = string.Format("{0}: {1}", _obj.Info.Properties.Currency.LocalizedName, _obj.Currency);
block.AddLabel(currencyText);
block.AddLineBreak();
// Оплатить до.
var paymentDeadline = _obj.PaymentDueDate.HasValue ? _obj.PaymentDueDate.Value.ToString("d") : "-";
var paymentDeadlineText = string.Format("{0}: {1}", _obj.Info.Properties.PaymentDueDate.LocalizedName, paymentDeadline);
block.AddLabel(paymentDeadlineText);
block.AddLineBreak();
block.AddEmptyLine();
// Примечание.
var note = !string.IsNullOrEmpty(_obj.Note) ? _obj.Note : "-";
block.AddLabel(string.Format("{0}: {1}", _obj.Info.Properties.Note.LocalizedName, note));
return documentSummary;
}
/// <summary>
/// Изменить статус документа на "В разработке".
/// </summary>
public override void SetLifeCycleStateDraft()
{
if (_obj.LifeCycleState == null)
{
Logger.DebugFormat("UpdateLifeCycleState: Document {0} changed LifeCycleState to 'Draft'.", _obj.Id);
_obj.LifeCycleState = Docflow.OfficialDocument.LifeCycleState.Draft;
}
}
/// <summary>
/// Установить статус жизненного цикла входящего счета в "Оплачен".
/// </summary>
public virtual void SetLifeCycleStateToPaid()
{
if (_obj.LifeCycleState == Sungero.Contracts.IncomingInvoice.LifeCycleState.Paid)
return;
Logger.DebugFormat("Update LifeCycleState for document {0}. Current state: {1}, new state: Paid.", _obj.Id, _obj.LifeCycleState);
_obj.LifeCycleState = Sungero.Contracts.IncomingInvoice.LifeCycleState.Paid;
}
public override string GetNoteWithCounterpartySigningReason()
{
return _obj.Note;
}
}
}