73 lines
2.8 KiB
C#
73 lines
2.8 KiB
C#
using System.Globalization;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace _1CDataBus.Structure
|
|
{
|
|
public class Contract
|
|
{
|
|
private Dictionary<int, string> _contractKinds = new Dictionary<int, string>()
|
|
{
|
|
{ 1, "Поставщик" },
|
|
{ 2, "Покупатель" },
|
|
{ 3, "Прочее" }
|
|
};
|
|
|
|
private List<string> _orderDealKinds = ["Приобретение ТМЦ", "Приобретение топлива"];
|
|
|
|
public Contract(dynamic contract)
|
|
{
|
|
//Name = contract["Name"];
|
|
Name = GetName();
|
|
BusinessUnit = contract["BusinessUnit"]["ExternalId"];
|
|
BusinessUnitBIN = contract["BusinessUnit"]["BINArmadoc"];
|
|
Counterparty = contract["Counterparty"]["ExternalId"];
|
|
CounterpartyBIN = contract["Counterparty"]["BINArmadoc"];
|
|
Number = contract["RegistrationNumber"];
|
|
Date = contract["ContractDateSungero"].Date.ToString("yyyy-MM-dd");
|
|
Currency = contract["Currency"] == null ? "KZT" : contract["Currency"]["AlphaCode"];
|
|
QDocID = contract["Id"].ToString();
|
|
|
|
string dealKind = contract["DealKindSungero"]["Name"];
|
|
if (dealKind != null && _orderDealKinds.Contains(dealKind)) Orders = true;
|
|
}
|
|
|
|
private string GetName()
|
|
{
|
|
var culture = CultureInfo.InvariantCulture;
|
|
var result = "Договор";
|
|
|
|
if (!string.IsNullOrEmpty(this.Number)) result += $" {this.Number}";
|
|
if (!string.IsNullOrEmpty(this.Date)) result += $" от {DateTime.ParseExact(this.Date, "yyyy-MM-dd", culture).ToString("dd.MM.yyyy")}";
|
|
|
|
return result;
|
|
}
|
|
|
|
[JsonConstructor]
|
|
public Contract(string name, string businessUnit, string businessUnitBIN, string counterparty, string counterpartyBIN,
|
|
string number, DateTime date, string currency, string qDocID)
|
|
{
|
|
Name = name;
|
|
BusinessUnit = businessUnit;
|
|
BusinessUnitBIN = businessUnitBIN;
|
|
Counterparty = counterparty;
|
|
CounterpartyBIN = counterpartyBIN;
|
|
Number = number;
|
|
Date = date.ToString("yyyy-MM-dd");
|
|
Currency = currency;
|
|
QDocID = qDocID;
|
|
}
|
|
|
|
public string Name { get; set; }
|
|
public string BusinessUnit { get; set; }
|
|
public string BusinessUnitBIN { get; set; }
|
|
public string Counterparty { get; set; }
|
|
public string CounterpartyBIN { get; set; }
|
|
public string Number { get; set; }
|
|
public string Date { get; set; }
|
|
public string ContractKind { get; set; } = "Поставщик";
|
|
public string Currency { get; set; }
|
|
public bool Orders { get; set; } = false;
|
|
public string QDocID { get; set; }
|
|
}
|
|
}
|