108 lines
3.7 KiB
C#
108 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.Eventing.Reader;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Invoicing;
|
|
using BeWo.Service.Plugins;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Services;
|
|
using DevExpress.XtraPrinting.BarCode;
|
|
|
|
namespace Ruhrstern.Invoicing
|
|
{
|
|
internal class CustomInvoiceNumberGenerator : InvoiceNumberGenerator
|
|
{
|
|
public long oid_ = 1;
|
|
|
|
public override string GetNextInvoiceNumber(int increment, InvoiceBase invoiceBase)
|
|
{
|
|
string next = String.Empty;
|
|
Customer c = null;
|
|
|
|
if (invoiceBase.Type == InvoiceType.General && invoiceBase.RecipientCustomerOid.HasValue || invoiceBase.Type == InvoiceType.CustomerEquity && invoiceBase.RecipientCustomerOid.HasValue)
|
|
{
|
|
c = DAOFactory.GenericDAO.LoadByID<Customer>(invoiceBase.RecipientCustomerOid.Value);
|
|
}
|
|
else if (invoiceBase.CostBearer2SupportConcept != null)
|
|
{
|
|
c = invoiceBase.CostBearer2SupportConcept.SupportConcept.Customer;
|
|
}
|
|
if (c != null)
|
|
{
|
|
var team = c.Team2CustomerList != null && c.Team2CustomerList.Count > 0 ? c.Team2CustomerList[0].Team : null;
|
|
if (team != null)
|
|
{
|
|
if (team.Name.ToLower().Contains("jugend"))
|
|
{
|
|
oid_ = 2;
|
|
}
|
|
}
|
|
|
|
InvoiceNumberDC invoiceNumber = LoadInvoiceNumber(oid_);
|
|
|
|
if (invoiceNumber != null && invoiceNumber.Use)
|
|
{
|
|
next = ApplyPattern(invoiceNumber.Pattern, invoiceNumber.CurrentNumber + increment, invoiceBase);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (invoiceBase.RecipientOrganisation != null && invoiceBase.RecipientOrganisation.Contains("Essen"))
|
|
{
|
|
oid_ = 2;
|
|
}
|
|
}
|
|
return next;
|
|
}
|
|
|
|
protected override String ApplyPattern(String pattern, long number, InvoiceBase invoiceBase)
|
|
{
|
|
String id = String.Empty;
|
|
if (invoiceBase != null && !String.IsNullOrEmpty(invoiceBase.InvoiceId))
|
|
{
|
|
id = invoiceBase.InvoiceId;
|
|
}
|
|
|
|
return ApplyPatternWithId(pattern, number, id, invoiceBase);
|
|
}
|
|
|
|
protected String ApplyPatternWithId(String pattern, long number, String id, InvoiceBase invoiceBase)
|
|
{
|
|
string next = base.ApplyPatternWithId(pattern, number, id);
|
|
|
|
return next;
|
|
}
|
|
|
|
private InvoiceNumberDC LoadInvoiceNumber(long oid)
|
|
{
|
|
var inr = DAOFactory.GenericDAO.LoadByID<InvoiceNumber>(oid_);
|
|
if (inr != null)
|
|
return MapperFactory.InvoiceNumberDC_InvoiceNumber.MapToNewDC(inr);
|
|
return null;
|
|
}
|
|
|
|
public override InvoiceNumberDC UpdateInvoiceNumber(InvoiceNumberDC dc)
|
|
{
|
|
var old = DAOFactory.GenericDAO.LoadByID<InvoiceNumber>(oid_);
|
|
MapperFactory.InvoiceNumberDC_InvoiceNumber.MergeWithEntity(dc, old);
|
|
DAOFactory.GenericDAO.Update(old);
|
|
|
|
return MapperFactory.InvoiceNumberDC_InvoiceNumber.MapToNewDC(old);
|
|
}
|
|
|
|
public override InvoiceNumberDC LoadInvoiceNumber()
|
|
{
|
|
var inr = DAOFactory.GenericDAO.LoadByID<InvoiceNumber>(oid_);
|
|
if (inr != null)
|
|
return MapperFactory.InvoiceNumberDC_InvoiceNumber.MapToNewDC(inr);
|
|
return null;
|
|
}
|
|
}
|
|
}
|