95 lines
4.1 KiB
C#
95 lines
4.1 KiB
C#
using BeWo.Data.Entities;
|
|
using BeWo.Service.Invoicing;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AutismusKoelnBonn.Invoicing
|
|
{
|
|
public class CustomSettlementInvoiceCreation : SettlementInvoiceCreation
|
|
{
|
|
// Änderung: Rundung von AmountTotal
|
|
public override void CalculateInvoiceItemAmounts(Settlement2DC si)
|
|
{
|
|
decimal maxApprovedFls = si.ApprovedFLS ?? 0;
|
|
|
|
foreach (var ii in si.InvoiceItems)
|
|
{
|
|
if (ii.UnitCount.HasValue)
|
|
{
|
|
var unitCountBudget = Math.Round(ii.UnitCountBudget ?? ii.UnitCount ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
if (maxApprovedFls < unitCountBudget)
|
|
unitCountBudget = maxApprovedFls;
|
|
|
|
maxApprovedFls -= unitCountBudget;
|
|
|
|
if (unitCountBudget < ii.UnitCount)
|
|
{
|
|
ii.UnitCount = unitCountBudget;
|
|
}
|
|
if (ii.AmountPerUnit.HasValue)
|
|
{
|
|
if (!String.IsNullOrEmpty(ii.ItemDescription) && ii.ItemDescription == "Fehlkontakte")
|
|
{
|
|
ii.AmountPerUnit = ii.AmountPerUnit * ii.ProzentAbrechenbar / 100;
|
|
}
|
|
// ÄNDERUNG NACHFOLGENDE ZEILE
|
|
ii.AmountTotal = Math.Round(ii.UnitCount.Value, 2, MidpointRounding.AwayFromZero) * ii.AmountPerUnit.Value;
|
|
if (ii.RateFactor.HasValue && ii.RateFactor.Value != 0)
|
|
ii.GrossAmountTotal = Math.Round(ii.AmountTotal.Value * ((100m + ii.RateFactor.Value) / 100m), 2,
|
|
MidpointRounding.AwayFromZero);
|
|
else
|
|
ii.GrossAmountTotal = ii.AmountTotal;
|
|
|
|
}
|
|
if (ii.MaxApprovedUnitCount < ii.UnitCount)
|
|
{
|
|
ii.MaxApprovedUnitCount = ii.UnitCount;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public override void CreateRecipientInformation(Settlement2DC settlementInvoice, CostBearer2SupportConcept c2s)
|
|
{
|
|
base.CreateRecipientInformation(settlementInvoice, c2s);
|
|
|
|
if (c2s.CostBearer.Organisation.Name.Contains("(") && c2s.CostBearer.Organisation.Name.Contains(")"))
|
|
{
|
|
var ersterIndex = c2s.CostBearer.Organisation.Name.IndexOf('(');
|
|
var zweiterIndex = c2s.CostBearer.Organisation.Name.IndexOf(')');
|
|
|
|
settlementInvoice.RecipientOrganisation = c2s.CostBearer.Organisation.Name.Remove(ersterIndex, zweiterIndex - ersterIndex + 1);
|
|
}
|
|
|
|
// Schema mit Bezeichnungen der Labels in Organisationen:
|
|
// 1. Name
|
|
// 2. Abteilung (ersetzt Straße)
|
|
// 3. Adresszusatz (im Zweifel aus Rechnungsadresse)
|
|
// 4. PLZ + Ort(im Zweifel aus Rechnungsadresse)
|
|
|
|
|
|
var invoiceAdress = c2s.CostBearer.Organisation.InvoiceAddress;
|
|
if (!invoiceAdress.AddressLine1.IsNullOrEmpty())
|
|
settlementInvoice.RecipientDivision = invoiceAdress.AddressLine1;
|
|
if (!c2s.CostBearer.Organisation.Name2.IsNullOrEmpty())
|
|
settlementInvoice.RecipientStreet = c2s.CostBearer.Organisation.Name2;
|
|
if (!invoiceAdress.PostalCode.IsNullOrEmpty())
|
|
settlementInvoice.RecipientPostCode = invoiceAdress.PostalCode;
|
|
if (!invoiceAdress.Town.IsNullOrEmpty())
|
|
settlementInvoice.RecipientTown = invoiceAdress.Town;
|
|
if (c2s.CostBearer.Organisation.Contacts.Count > 0)
|
|
{
|
|
foreach (var i in c2s.CostBearer.Organisation.Contacts)
|
|
{
|
|
if (i.Type == BS.Shared.ContactType.private_POBox)
|
|
settlementInvoice.RecipientPostBox = i.Value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|