Files
BeWoPlaner/Data/Entities/InvoiceBase.cs
Rene Evertz 71d1bfd2c2 Merge branch 'feature_rene_17_xrechnung'
# Conflicts:
#	Data/Data.csproj
#	Data/Entities/InvoiceBase.cs
#	Host/Web.Secrets.config.template
#	Host/Web.config
#	Service/ServiceBehavior/AdminServiceMessageInspector.cs
#	Service/ServiceContracts/IAdminService.cs
#	Shared/BeWoEntityEnums.cs
#	Shared/DataContracts/InvoiceBaseDC.cs
2025-09-27 19:41:52 +02:00

882 lines
22 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using BeWo.Data.Access;
using BS.Shared;
using BS.Shared.Interface;
namespace BeWo.Data.Entities
{
public class InvoiceBase : BeWoEntityBase, IInvoiceBase
{
public static string PropertyName_AccountingPeriodEnd = "AccountingPeriodEnd";
public static string PropertyName_AccountingPeriodStart = "AccountingPeriodStart";
public static string PropertyName_CostBearer2SupportConcept = "CostBearer2SupportConcept";
public static string PropertyName_CostBearer2SupportConceptOid = "CostBearer2SupportConceptOid";
public static string PropertyName_CreatorFirstName = "CreatorFirstName";
public static string PropertyName_CreatorLastName = "CreatorLastName";
public static string PropertyName_CustomerReferenceNumber = "CustomerReferenceNumber";
public static string PropertyName_DueDate = "DueDate";
public static string PropertyName_DunningLetterCount = "DunningLetterCount";
public static string PropertyName_InvoiceDate = "InvoiceDate";
public static string PropertyName_InvoiceItems = "InvoiceItems";
public static string PropertyName_InvoiceNumber = "InvoiceNumber";
public static string PropertyName_InvoiceTitle = "InvoiceTitle";
public static string PropertyName_InvoiceId = "InvoiceId";
public static string PropertyName_IsPaid = "IsPaid";
public static string PropertyName_IsPrinted = "IsPrinted";
public static string PropertyName_RecipientAddress = "RecipientAddress";
public static string PropertyName_RecipientContacts = "RecipientContacts";
public static string PropertyName_RecipientCostBearerOid = "RecipientCostBearerOid";
public static string PropertyName_RecipientCustomerOid = "RecipientCustomerOid";
public static string PropertyName_RecipientDivision = "RecipientDivision";
public static string PropertyName_RecipientOrganisation = "RecipientOrganisation";
public static string PropertyName_RecipientOrganisationOid = "RecipientOrganisationOid";
public static string PropertyName_RecipientPersonFirstName = "RecipientPersonFirstName";
public static string PropertyName_RecipientPersonLastName = "RecipientPersonLastName";
public static string PropertyName_RecipientPersonOid = "RecipientPersonOid";
public static string PropertyName_SenderAddress = "SenderAddress";
public static string PropertyName_SenderContacts = "SenderContacts";
public static string PropertyName_SenderDivision = "SenderDivision";
public static string PropertyName_SenderFirstName = "SenderFirstName";
public static string PropertyName_SenderLastName = "SenderLastName";
public static string PropertyName_SenderOrganisation = "SenderOrganisation";
public static string PropertyName_SupportConceptOid = "SupportConceptOid";
public static string PropertyName_Type = "Type";
public static string PropertyName_XMLData = "XMLData";
private DateTime? _AccountingPeriodEnd;
private DateTime? _AccountingPeriodStart;
private CostBearer2SupportConcept _CostBearer2SupportConcept;
private string _CreatorFirstName;
private string _CreatorLastName;
private string _CustomerReferenceNumber;
private DateTime? _DueDate;
private int? _DunningLetterCount;
private DateTime? _InvoiceDate;
private IList<InvoiceItem> _InvoiceItems = new List<InvoiceItem>();
private string _InvoiceNumber;
private string _InvoiceTitle;
private string _InvoiceId;
private bool _IsReviewed;
private bool _IsSent;
private bool _IsExported;
private bool _IsPaid;
private string _PartialPayment;
private bool _IsPrinted;
private Address _RecipientAddress;
private IList<Contact> _RecipientContacts = new List<Contact>();
private long? _RecipientCostBearerOid;
private long? _RecipientCustomerOid;
private string _RecipientDivision;
private string _RecipientOrganisation;
private long? _RecipientOrganisationOid;
private string _RecipientPersonFirstName;
private string _RecipientPersonLastName;
private long? _RecipientPersonOid;
private Address _SenderAddress;
private IList<Contact> _SenderContacts = new List<Contact>();
private string _SenderDivision;
private string _SenderFirstName;
private string _SenderLastName;
private string _SenderOrganisation;
private long? _SupportConceptOid;
private long? _CostBearer2SupportConceptOid;
private long? _StornoInvoiceBaseOid;
private InvoiceType _Type;
private string _XMLData;
public InvoiceBase()
{
this._Tid = TableID.InvoiceBase;
}
public override DateTime? InsTs
{
get
{
return this._InsTs;
}
set
{
if (this.AreDifferent(this._InsTs, value))
{
this._InsTs = value;
}
}
}
public virtual DateTime? AccountingPeriodEnd
{
get
{
return this._AccountingPeriodEnd;
}
set
{
if (this.AreDifferent(this._AccountingPeriodEnd, value))
{
this._AccountingPeriodEnd = value;
}
}
}
public virtual DateTime? AccountingPeriodStart
{
get
{
return this._AccountingPeriodStart;
}
set
{
if (this.AreDifferent(this._AccountingPeriodStart, value))
{
this._AccountingPeriodStart = value;
}
}
}
public virtual CostBearer2SupportConcept CostBearer2SupportConcept
{
get
{
return this._CostBearer2SupportConcept;
}
set
{
if (this.AreDifferent(this._CostBearer2SupportConcept, value))
{
this._CostBearer2SupportConcept = value;
}
}
}
// public virtual long? CostBearer2SupportConceptOid
// {
// get
// {
// return this._CostBearer2SupportConceptOid;
// }
// set
// {
// if (this.AreDifferent(this._CostBearer2SupportConceptOid, value))
// {
// this._CostBearer2SupportConceptOid = value;
// }
// }
// }
public virtual string CreatorFirstName
{
get
{
return this._CreatorFirstName;
}
set
{
if (this.AreDifferent(this._CreatorFirstName, value))
{
this._CreatorFirstName = value;
}
}
}
public virtual string CreatorLastName
{
get
{
return this._CreatorLastName;
}
set
{
if (this.AreDifferent(this._CreatorLastName, value))
{
this._CreatorLastName = value;
}
}
}
public virtual string CustomerReferenceNumber
{
get
{
return this._CustomerReferenceNumber;
}
set
{
if (this.AreDifferent(this._CustomerReferenceNumber, value))
{
this._CustomerReferenceNumber = value;
}
}
}
public virtual DateTime? DueDate
{
get
{
return this._DueDate;
}
set
{
if (this.AreDifferent(this._DueDate, value))
{
this._DueDate = value;
}
}
}
public virtual int? DunningLetterCount
{
get
{
return this._DunningLetterCount;
}
set
{
if (this.AreDifferent(this._DunningLetterCount, value))
{
this._DunningLetterCount = value;
}
}
}
public virtual DateTime? InvoiceDate
{
get
{
return this._InvoiceDate;
}
set
{
if (this.AreDifferent(this._InvoiceDate, value))
{
this._InvoiceDate = value;
}
}
}
public virtual IList<InvoiceItem> InvoiceItems
{
get
{
return this._InvoiceItems ?? (this._InvoiceItems = new List<InvoiceItem>());
}
set
{
if (this.AreDifferent(this._InvoiceItems, value))
{
this._InvoiceItems = value;
}
}
}
public virtual string InvoiceNumber
{
get
{
return this._InvoiceNumber;
}
set
{
if (this.AreDifferent(this._InvoiceNumber, value))
{
this._InvoiceNumber = value;
}
}
}
public virtual string InvoiceTitle
{
get
{
return this._InvoiceTitle;
}
set
{
if (this.AreDifferent(this._InvoiceTitle, value))
{
this._InvoiceTitle = value;
}
}
}
public virtual string InvoiceId
{
get
{
return this._InvoiceId;
}
set
{
if (this.AreDifferent(this._InvoiceId, value))
{
this._InvoiceId = value;
}
}
}
public virtual string InvoiceTypeText { get; set; }
public virtual bool IsReviewed
{
get
{
return this._IsReviewed;
}
set
{
if (this.AreDifferent(this._IsReviewed, value))
{
this._IsReviewed = value;
}
}
}
public virtual bool IsSent
{
get
{
return this._IsSent;
}
set
{
if (this.AreDifferent(this._IsSent, value))
{
this._IsSent = value;
}
}
}
public virtual bool IsExported
{
get
{
return this._IsExported;
}
set
{
if (this.AreDifferent(this._IsExported, value))
{
this._IsExported = value;
}
}
}
public virtual bool IsPaid
{
get
{
return this._IsPaid;
}
set
{
if (this.AreDifferent(this._IsPaid, value))
{
this._IsPaid = value;
}
}
}
public virtual string PartialPayment
{
get
{
return this._PartialPayment;
}
set
{
if (this.AreDifferent(this._PartialPayment, value))
{
this._PartialPayment = value;
}
}
}
public virtual bool IsPrinted
{
get
{
return this._IsPrinted;
}
set
{
if (this.AreDifferent(this._IsPrinted, value))
{
this._IsPrinted = value;
}
}
}
public virtual Address RecipientAddress
{
get
{
return this._RecipientAddress;
}
set
{
if (this.AreDifferent(this._RecipientAddress, value))
{
this._RecipientAddress = value;
}
}
}
public virtual IList<Contact> RecipientContacts
{
get
{
return this._RecipientContacts;
}
set
{
if (this.AreDifferent(this._RecipientContacts, value))
{
this._RecipientContacts = value;
}
}
}
public virtual long? RecipientCostBearerOid
{
get
{
return this._RecipientCostBearerOid;
}
set
{
if (this.AreDifferent(this._RecipientCostBearerOid, value))
{
this._RecipientCostBearerOid = value;
}
}
}
public virtual long? RecipientCustomerOid
{
get
{
return this._RecipientCustomerOid;
}
set
{
if (this.AreDifferent(this._RecipientCustomerOid, value))
{
this._RecipientCustomerOid = value;
}
}
}
public virtual string RecipientDivision
{
get
{
return this._RecipientDivision;
}
set
{
if (this.AreDifferent(this._RecipientDivision, value))
{
this._RecipientDivision = value;
}
}
}
public virtual string RecipientOrganisation
{
get
{
return this._RecipientOrganisation;
}
set
{
if (this.AreDifferent(this._RecipientOrganisation, value))
{
this._RecipientOrganisation = value;
}
}
}
public virtual long? RecipientOrganisationOid
{
get
{
return this._RecipientOrganisationOid;
}
set
{
if (this.AreDifferent(this._RecipientOrganisationOid, value))
{
this._RecipientOrganisationOid = value;
}
}
}
public virtual string RecipientPersonFirstName
{
get
{
return this._RecipientPersonFirstName;
}
set
{
if (this.AreDifferent(this._RecipientPersonFirstName, value))
{
this._RecipientPersonFirstName = value;
}
}
}
public virtual string RecipientPersonLastName
{
get
{
return this._RecipientPersonLastName;
}
set
{
if (this.AreDifferent(this._RecipientPersonLastName, value))
{
this._RecipientPersonLastName = value;
}
}
}
public virtual long? RecipientPersonOid
{
get
{
return this._RecipientPersonOid;
}
set
{
if (this.AreDifferent(this._RecipientPersonOid, value))
{
this._RecipientPersonOid = value;
}
}
}
public virtual Address SenderAddress
{
get
{
return this._SenderAddress;
}
set
{
if (this.AreDifferent(this._SenderAddress, value))
{
this._SenderAddress = value;
}
}
}
public virtual IList<Contact> SenderContacts
{
get
{
return this._SenderContacts;
}
set
{
if (this.AreDifferent(this._SenderContacts, value))
{
this._SenderContacts = value;
}
}
}
public virtual string SenderDivision
{
get
{
return this._SenderDivision;
}
set
{
if (this.AreDifferent(this._SenderDivision, value))
{
this._SenderDivision = value;
}
}
}
public virtual string SenderFirstName
{
get
{
return this._SenderFirstName;
}
set
{
if (this.AreDifferent(this._SenderFirstName, value))
{
this._SenderFirstName = value;
}
}
}
public virtual string SenderLastName
{
get
{
return this._SenderLastName;
}
set
{
if (this.AreDifferent(this._SenderLastName, value))
{
this._SenderLastName = value;
}
}
}
public virtual string SenderOrganisation
{
get
{
return this._SenderOrganisation;
}
set
{
if (this.AreDifferent(this._SenderOrganisation, value))
{
this._SenderOrganisation = value;
}
}
}
public virtual long? SupportConceptOid
{
get
{
return this._SupportConceptOid;
}
set
{
if (this.AreDifferent(this._SupportConceptOid, value))
{
this._SupportConceptOid = value;
}
}
}
public virtual long? CostBearer2SupportConceptOid
{
get
{
return this._CostBearer2SupportConceptOid;
}
set
{
if (this.AreDifferent(this._CostBearer2SupportConceptOid, value))
{
this._CostBearer2SupportConceptOid = value;
}
}
}
public virtual InvoiceType Type
{
get
{
return this._Type;
}
set
{
if (this.AreDifferent(this._Type, value))
{
this._Type = value;
}
}
}
public virtual string XMLData
{
get
{
return this._XMLData;
}
set
{
if (this.AreDifferent(this._XMLData, value))
{
this._XMLData = value;
}
}
}
public virtual long? StornoInvoiceBaseOid
{
get; set;
}
public virtual string SenderStreet => SenderAddress?.Street;
public virtual string SenderTown => SenderAddress?.Town;
public virtual string SenderPostCode => SenderAddress?.PostalCode;
public virtual IEnumerable<IInvoiceItem> IInvoiceItems => InvoiceItems.Select(x => x as IInvoiceItem).ToList();
public virtual StoredFile XRechnungStoredFile { get; set; }
public virtual IEnumerable<InvoiceItem> GetInvoiceItems()
{
IEnumerable < InvoiceItem > ret = null;
if (Type == InvoiceType.Service && Oid.HasValue)
{
var inv = DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(Oid.Value);
if (inv != null)
{
ret = inv.GetInvoiceItems();
}
else
{
//pDataContract.TotalAmount = -99999999;
}
}
else if (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(XMLData))
{
//var settlementdc = BS.Shared.Core.Utils.XMLDeserializeFromString<SettlementDC>(invoiceBase.XMLData);
//pDataContract.TotalAmount = settlementdc.Claim;
}
else
{
ret = InvoiceItems;
}
}
else
{
ret = InvoiceItems;
}
if(ret == null)
throw new NotImplementedException($"GetInvoiceItems: {Type} unbekannt.");
if (!ret.Any())
throw new NotImplementedException($"Keine InvoiceItems gefunden. InvoiceBaseOid: {Oid}");
return ret;
}
}
}