Alloheim/Import/Abschlagszahlung und Export SAPExporter
This commit is contained in:
@@ -51,6 +51,9 @@
|
||||
<Compile Include="CustomReportCreator.cs" />
|
||||
<Compile Include="Export\CustomDataExporter.cs" />
|
||||
<Compile Include="Export\SAPExporter.cs" />
|
||||
<Compile Include="Import\Abschlagszahlung.cs" />
|
||||
<Compile Include="Import\AbschlagszahlungImport.cs" />
|
||||
<Compile Include="Import\HilfeplanInfo.cs" />
|
||||
<Compile Include="InvoiceCustomerReport.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -146,7 +146,18 @@ namespace Alloheim.Export
|
||||
sb.Append(String.Format("{0:ddMMyyyy} \t", lastDate));
|
||||
sb.Append(String.Format("{0:ddMMyyyy} \t", lastDate));
|
||||
sb.Append("EUR\t");
|
||||
sb.Append(String.Format("1192{0:ddMMyyyy}{1} \t", lastDate, counter));// Profitcenter + Rechnungs - Nr.VN
|
||||
if (counter < 10)
|
||||
{
|
||||
sb.Append(String.Format("1192{0:yyyy}{0:MM}00{1} \t", lastDate, counter));// Profitcenter + Rechnungs - Nr.VN, genau 11 Stellen
|
||||
}
|
||||
else if (counter < 100)
|
||||
{
|
||||
sb.Append(String.Format("1192{0:yyyy}{0:MM}0{1} \t", lastDate, counter));// Profitcenter + Rechnungs - Nr.VN, genau 11 Stellen
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(String.Format("1192{0:yyyy}{0:MM}{1} \t", lastDate, counter));// Profitcenter + Rechnungs - Nr.VN, genau 11 Stellen
|
||||
}
|
||||
sb.Append("1192\t"); // Belegkopftext 1192
|
||||
sb.Append("D\t"); // D = Debitorenposition / zweite Zeile: S = Sachkontenposition
|
||||
sb.Append("01\t"); // Kontoart D: S=01 H=11 / zweite Zeile: Kontoart S: S=40 H=50
|
||||
@@ -164,7 +175,18 @@ namespace Alloheim.Export
|
||||
sb.Append(String.Format("{0:ddMMyyyy} \t", lastDate));
|
||||
sb.Append(String.Format("{0:ddMMyyyy} \t", lastDate));
|
||||
sb.Append("EUR\t");
|
||||
sb.Append(String.Format("1192{0:ddMMyyyy}{1} \t", lastDate, counter));// Profitcenter + Rechnungs - Nr.VN
|
||||
if (counter < 10)
|
||||
{
|
||||
sb.Append(String.Format("1192{0:yyyy}{0:MM}00{1} \t", lastDate, counter));// Profitcenter + Rechnungs - Nr.VN, genau 11 Stellen
|
||||
}
|
||||
else if (counter < 100)
|
||||
{
|
||||
sb.Append(String.Format("1192{0:yyyy}{0:MM}0{1} \t", lastDate, counter));// Profitcenter + Rechnungs - Nr.VN, genau 11 Stellen
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(String.Format("1192{0:yyyy}{0:MM}{1} \t", lastDate, counter));// Profitcenter + Rechnungs - Nr.VN, genau 11 Stellen
|
||||
}
|
||||
sb.Append("1192\t"); // Belegkopftext 1192
|
||||
sb.Append("S\t"); // S = Sachkontenposition
|
||||
sb.Append("50\t"); // Kontoart Kontoart S: S=40 H=50
|
||||
|
||||
40
ReportImp/Alloheim/Import/Abschlagszahlung.cs
Normal file
40
ReportImp/Alloheim/Import/Abschlagszahlung.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Alloheim.Import
|
||||
{
|
||||
public class Abschlagszahlung
|
||||
{
|
||||
//Symbol Posten offen/ausg.,Buchungskreis,Zuordnung,Konto,Name 1,Name 2,Referenz,Referenzschlüssel 2,Belegnummer,Belegart,Buchungsperiode,
|
||||
//Geschäftsjahr,Belegdatum,Buchungsdatum,Betrag in Hauswährung,Text,Zahlungssperre,Mahnstufe,Mahnsperre,Datum Sozialhilfe beantragt am,Erfassungsdatum
|
||||
|
||||
public long Auftragskonto { get; set; }
|
||||
public String Gegenkonto { get; set; }
|
||||
public DateTime? Buchungstag { get; set; }
|
||||
public DateTime? Valutadatum { get; set; }
|
||||
public String Buchungstext { get; set; }
|
||||
public String Verwendungszweck { get; set; }
|
||||
//public String GlaeubigerId { get; set; }
|
||||
//public String Mandatsreferenz { get; set; }
|
||||
//public String Kundenreferenz { get; set; }
|
||||
//public String Sammlerreferenz { get; set; }
|
||||
//public decimal LastschriftUrsprungsbetrag { get; set; }
|
||||
//public String AuslagenersatzRuecklastschrift { get; set; }
|
||||
//public String BeguenstigterZahlungspflichtiger { get; set; }
|
||||
//public String Iban { get; set; }
|
||||
//public String Bic { get; set; }
|
||||
public decimal Betrag { get; set; }
|
||||
//public String Waehrung { get; set; }
|
||||
//public String Info { get; set; }
|
||||
|
||||
|
||||
public String CustomerName { get; set; }
|
||||
public String Aktenzeichen { get; set; }
|
||||
public DateTime? DatumAnfang { get; set; }
|
||||
public DateTime? DatumEnde { get; set; }
|
||||
public DateTime? BescheidVom { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
243
ReportImp/Alloheim/Import/AbschlagszahlungImport.cs
Normal file
243
ReportImp/Alloheim/Import/AbschlagszahlungImport.cs
Normal file
@@ -0,0 +1,243 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BeWo.Data.Access;
|
||||
using BeWo.Data.Entities;
|
||||
using BeWo.Service.MessageContracts;
|
||||
using BeWo.Service.Plugins;
|
||||
using DevExpress.XtraPrinting.Native;
|
||||
|
||||
namespace Alloheim.Import
|
||||
{
|
||||
public class AbschlagszahlungImport : DataImporter
|
||||
{
|
||||
private int bereitsVorhandenCount = 0;
|
||||
private int importiertCount = 0;
|
||||
private int keinDebitorCount = 0;
|
||||
private string Debitornr;
|
||||
|
||||
public override UploadImportFileResult ImportData(string filename, byte[] daten)
|
||||
{
|
||||
|
||||
String str = System.Text.Encoding.Default.GetString(daten);
|
||||
|
||||
var abschlagszahlungen = CreateAbschlagszahlungen(str);
|
||||
var hilfeplaene = CreateHilfeplanInfos();
|
||||
|
||||
var importresult = ImportAbschlagszahlungen(abschlagszahlungen, hilfeplaene);
|
||||
|
||||
|
||||
var result = new UploadImportFileResult();
|
||||
result.Success = false;
|
||||
|
||||
String importDaten = "1 Datensatz";
|
||||
String vorhandenDaten = "1 Datensatz";
|
||||
String nichtImport = "";
|
||||
|
||||
if (importiertCount != 1)
|
||||
{
|
||||
importDaten = String.Format("{0} Datensätze", importiertCount);
|
||||
}
|
||||
|
||||
if (bereitsVorhandenCount != 1)
|
||||
{
|
||||
vorhandenDaten = String.Format("{0} Datensätze", bereitsVorhandenCount);
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(importresult))
|
||||
{
|
||||
result.ResultMessage = String.Format(
|
||||
"Die Daten wurden erfolgreich importiert.\nEs wurden {0} neu importiert. {1} waren bereits vorhanden.",
|
||||
importDaten, vorhandenDaten);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.ResultMessage = String.Format("Die Daten wurden erfolgreich importiert.\nEs wurden {0} neu importiert. {1} waren bereits vorhanden.\n\nFolgende Zahlungen konnten nicht importiert werden:\n{2}", importDaten, vorhandenDaten, importresult);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private String ImportAbschlagszahlungen(List<Abschlagszahlung> abschlagszahlungen, List<HilfeplanInfo> hilfeplaene)
|
||||
{
|
||||
StringBuilder ergebnis = new StringBuilder();
|
||||
|
||||
foreach (var az in abschlagszahlungen)
|
||||
{
|
||||
bool importiert = false;
|
||||
foreach (var hilfeplanInfo in hilfeplaene)
|
||||
{
|
||||
importiert = ImportAbschlagszahlung(az, hilfeplanInfo, ergebnis);
|
||||
if (importiert)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!importiert)
|
||||
{
|
||||
if (ergebnis.Length > 0)
|
||||
ergebnis.Append("\n");
|
||||
ergebnis.Append("Debitor " + az.Gegenkonto + " " + az.Verwendungszweck + " " + az.Betrag);
|
||||
}
|
||||
}
|
||||
|
||||
return ergebnis.ToString();
|
||||
}
|
||||
|
||||
private bool ImportAbschlagszahlung(Abschlagszahlung az, HilfeplanInfo hp, StringBuilder log)
|
||||
{
|
||||
if (az.Buchungstag >= hp.Start && az.Buchungstag <= hp.Ende)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(az.Gegenkonto) && !String.IsNullOrEmpty(hp.CustomerDebitorNummer))
|
||||
{
|
||||
var azDebitor = az.Gegenkonto.ToLower().Trim();
|
||||
var debitor = hp.CustomerDebitorNummer.ToLower().Trim();
|
||||
|
||||
if (azDebitor == debitor)
|
||||
{
|
||||
if (!CheckAbschlagszahlung(az, hp))
|
||||
{
|
||||
CreateAbschlagszahlung(az, hp);
|
||||
importiertCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
bereitsVorhandenCount++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void CreateAbschlagszahlung(Abschlagszahlung az, HilfeplanInfo hp)
|
||||
{
|
||||
var newAz = new AccountingTransaction();
|
||||
|
||||
newAz.CostBearer2SupportConcept = hp.CostBearer2SupportConcept;
|
||||
newAz.Amount = az.Betrag;
|
||||
newAz.BookingDate = az.Buchungstag;
|
||||
newAz.ImportNotice = az.Verwendungszweck;
|
||||
if (az.Valutadatum.HasValue)
|
||||
{
|
||||
newAz.ValidityDate = az.Valutadatum;
|
||||
}
|
||||
else
|
||||
{
|
||||
newAz.ValidityDate = az.Buchungstag;
|
||||
}
|
||||
|
||||
newAz.Notice = "Automatischer Import " + az.Verwendungszweck;
|
||||
DAOFactory.GenericDAO.Insert(newAz);
|
||||
}
|
||||
|
||||
private bool CheckAbschlagszahlung(Abschlagszahlung az, HilfeplanInfo hp)
|
||||
{
|
||||
var azAltList = DAOFactory.SearchDAO.FindAccountingTransactionsWithImportNotice(az.Verwendungszweck);
|
||||
return azAltList != null && azAltList.Any();
|
||||
}
|
||||
|
||||
private List<Abschlagszahlung> CreateAbschlagszahlungen(String importfile)
|
||||
{
|
||||
List<Abschlagszahlung> liste = new List<Abschlagszahlung>();
|
||||
String[] lines = importfile.Split('\n');
|
||||
DateTime month = DateTime.Now;
|
||||
int jahr = 0;
|
||||
int monat = 0;
|
||||
|
||||
for (int i = 0; i < lines.Count(); i++)
|
||||
{
|
||||
string line = lines[i];
|
||||
var fields = line.Split(';');
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
// Kopfzeile
|
||||
}
|
||||
|
||||
if (i > 1)
|
||||
{
|
||||
if (fields.Length >= 15)
|
||||
{
|
||||
int.TryParse(fields[11], out jahr);
|
||||
int.TryParse(fields[10], out monat);
|
||||
if (jahr != 0 && monat != 0)
|
||||
{
|
||||
month = new DateTime(jahr, monat, 01);
|
||||
}
|
||||
if (!String.IsNullOrEmpty(fields[11]) && !String.IsNullOrEmpty(fields[14]) && !String.IsNullOrEmpty(fields[15]))
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime buchungstag = new DateTime(month.Year, month.Month, 1);
|
||||
|
||||
Abschlagszahlung az = new Abschlagszahlung();
|
||||
az.Buchungstag = buchungstag;
|
||||
if (DateTime.TryParse(fields[12], out buchungstag))
|
||||
az.Buchungstag = buchungstag;
|
||||
az.Valutadatum = buchungstag;
|
||||
az.Gegenkonto = fields[2].Substring(4,6); //führendes 1192 abschneiden
|
||||
if (!String.IsNullOrEmpty(fields[15]))
|
||||
{
|
||||
az.Verwendungszweck = fields[15];
|
||||
}
|
||||
else
|
||||
{
|
||||
az.Verwendungszweck = fields[6];
|
||||
}
|
||||
|
||||
decimal betrag = 0;
|
||||
if (Decimal.TryParse(fields[14], out betrag))
|
||||
{
|
||||
az.Betrag = -(betrag);
|
||||
}
|
||||
|
||||
//ParseVerwendungszweck(az);
|
||||
liste.Add(az);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return liste;
|
||||
}
|
||||
|
||||
private List<HilfeplanInfo> CreateHilfeplanInfos()
|
||||
{
|
||||
List<HilfeplanInfo> liste = new List<HilfeplanInfo>();
|
||||
var scList = DAOFactory.GenericDAO.GetAllActiveAndArchived<SupportConcept>();
|
||||
|
||||
foreach (var supportConcept in scList)
|
||||
{
|
||||
foreach (var cb2sc in supportConcept.CostBearer2SupportConceptList)
|
||||
{
|
||||
HilfeplanInfo hi = new HilfeplanInfo();
|
||||
|
||||
hi.Start = cb2sc.StartDate;
|
||||
hi.Ende = cb2sc.EndDate;
|
||||
|
||||
hi.CostBearer2SupportConcept = cb2sc;
|
||||
hi.CustomerFirstName = cb2sc.SupportConcept.Customer.Person.FirstName;
|
||||
hi.CustomerLastName = cb2sc.SupportConcept.Customer.Person.LastName;
|
||||
hi.CustomerBirthday = cb2sc.SupportConcept.Customer.Person.DateOfBirth;
|
||||
hi.CustomerDebitorNummer = cb2sc.SupportConcept.Customer.DebitorNumber;
|
||||
hi.Aktenzeichen = cb2sc.CustomerReferenceNumber;
|
||||
|
||||
if (hi.Start.HasValue && hi.Ende.HasValue && !String.IsNullOrEmpty(hi.CustomerDebitorNummer))
|
||||
{
|
||||
liste.Add(hi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return liste;
|
||||
}
|
||||
}
|
||||
}
|
||||
25
ReportImp/Alloheim/Import/HilfeplanInfo.cs
Normal file
25
ReportImp/Alloheim/Import/HilfeplanInfo.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BeWo.Data.Entities;
|
||||
|
||||
namespace Alloheim.Import
|
||||
{
|
||||
public class HilfeplanInfo
|
||||
{
|
||||
//Auftragskonto; Buchungstag; Valutadatum; Buchungstext; Verwendungszweck; Glaeubiger ID; Mandatsreferenz; Kundenreferenz(End - to - End); Sammlerreferenz; Lastschrift Ursprungsbetrag; Auslagenersatz Ruecklastschrift;
|
||||
//Beguenstigter / Zahlungspflichtiger; Kontonummer / IBAN; BIC(SWIFT - Code); Betrag; Waehrung; Info
|
||||
|
||||
public String CustomerFirstName { get; set; }
|
||||
public String CustomerLastName { get; set; }
|
||||
public DateTime? CustomerBirthday { get; set; }
|
||||
public String CustomerDebitorNummer { get; set; }
|
||||
public DateTime? Start { get; set; }
|
||||
public DateTime? Ende { get; set; }
|
||||
public DateTime? BescheidVom { get; set; }
|
||||
public String Aktenzeichen { get; set; }
|
||||
|
||||
public CostBearer2SupportConcept CostBearer2SupportConcept { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user