104 lines
2.9 KiB
C#
104 lines
2.9 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using BS.Shared.Core;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Light;
|
|
using DevExpress.CodeParser;
|
|
|
|
namespace BeWo.Service.DCEntityMapper
|
|
{
|
|
public class CompactInvoiceBaseDC_InvoiceBase : AbstractIDCEntityMapper<InvoiceBase, CompactInvoiceBaseDC>
|
|
{
|
|
public override CompactInvoiceBaseDC MergeWithDC(InvoiceBase pEntity, CompactInvoiceBaseDC pDataContract)
|
|
{
|
|
pDataContract.InvoiceBaseOid = pEntity.Oid;
|
|
|
|
pDataContract.RecipientOrganisation = pEntity.RecipientOrganisation;
|
|
pDataContract.InvoiceNumber = pEntity.InvoiceNumber;
|
|
pDataContract.InvoiceDate = pEntity.InvoiceDate;
|
|
pDataContract.AccountingPeriodEnd = pEntity.AccountingPeriodEnd;
|
|
pDataContract.AccountingPeriodStart = pEntity.AccountingPeriodStart;
|
|
pDataContract.Notice = pEntity.Notice;
|
|
pDataContract.InvoiceTypeText = pEntity.InvoiceTypeText;
|
|
pDataContract.IsPaid = pEntity.IsPaid;
|
|
|
|
if (pEntity.Type == InvoiceType.Service && pEntity.Oid.HasValue)
|
|
{
|
|
var inv = DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(pEntity.Oid.Value);
|
|
if (inv != null)
|
|
{
|
|
pDataContract.TotalAmount = inv.GetTotalClaim();
|
|
}
|
|
else
|
|
{
|
|
//pDataContract.TotalAmount = -99999999;
|
|
}
|
|
}
|
|
else if (pEntity.Type == InvoiceType.Settlement)
|
|
{
|
|
//Ist eigentlich ein Fehler. Bei Spitzabrechnungen muss immer ein InvoiceItem vorhanden sein.
|
|
//Durch einen mittlerweile behobenen Programmfehler gibt es einzelen ältere Rechnungen, bei denen das nicht so ist.
|
|
if (!string.IsNullOrEmpty(pEntity.XMLData))
|
|
{
|
|
var settlementdc = Utils.XMLDeserializeFromString<SettlementDC>(pEntity.XMLData);
|
|
pDataContract.TotalAmount = settlementdc.Claim;
|
|
}
|
|
else
|
|
{
|
|
pDataContract.TotalAmount = pEntity.InvoiceItems.Sum(i => i.AmountTotal);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
pDataContract.TotalAmount = pEntity.InvoiceItems.Sum(i => i.AmountTotal);
|
|
}
|
|
|
|
Customer customer = null;
|
|
if (pEntity.CostBearer2SupportConcept != null)
|
|
{
|
|
try
|
|
{
|
|
customer = pEntity.CostBearer2SupportConcept.SupportConcept.Customer;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
//ignore
|
|
}
|
|
|
|
}
|
|
else if (pEntity.SupportConceptOid.HasValue)
|
|
{
|
|
SupportConcept sc = DAOFactory.GenericDAO.LoadByID<SupportConcept>(pEntity.SupportConceptOid.Value);
|
|
customer = sc.Customer;
|
|
}
|
|
|
|
if (customer is object)
|
|
{
|
|
pDataContract.CustomerName = customer.Person.LastNameFirstName;
|
|
}
|
|
|
|
return pDataContract;
|
|
}
|
|
|
|
public override InvoiceBase MergeWithEntity(CompactInvoiceBaseDC pDataContract, InvoiceBase pEntity)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
protected override bool AreDCAndEntityEqual(CompactInvoiceBaseDC pDataContract, InvoiceBase pEntity)
|
|
{
|
|
if (pDataContract.InvoiceBaseOid == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return pDataContract.InvoiceBaseOid == pEntity.Oid;
|
|
}
|
|
}
|
|
} |