diff --git a/ReportImp/Alloheim/Alloheim.csproj b/ReportImp/Alloheim/Alloheim.csproj
index 2dc334f6f..98c263f64 100644
--- a/ReportImp/Alloheim/Alloheim.csproj
+++ b/ReportImp/Alloheim/Alloheim.csproj
@@ -74,6 +74,7 @@
ServiceInvoiceReport.cs
+
Component
diff --git a/ReportImp/Alloheim/Export/SAPExporter.cs b/ReportImp/Alloheim/Export/SAPExporter.cs
index 5b0e96a9d..c599bec6e 100644
--- a/ReportImp/Alloheim/Export/SAPExporter.cs
+++ b/ReportImp/Alloheim/Export/SAPExporter.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Data;
using System.IO;
+using System.Linq;
using System.Text;
using BeWo.Data.Access;
using BeWo.Data.Entities;
@@ -19,12 +20,74 @@ namespace Alloheim.Export
DateTime dt = DateTime.Now;
DateTime.TryParse(query.Parameter[0].Value.ToString(), out dt);
- query.FileName = String.Format("1192_{0:yyyyMMdd}_{0:hhmmss}_FIBU.TXT", DateTime.Now);
- query.QueryResult = GetAbrechnungenString(dt);
+ if (query.Title == "SAP Export Stammdaten")
+ {
+ query.FileName = String.Format("1192_{0:yyyyMMdd}_{0:hhmmss}_DEBSB.TXT", DateTime.Now);
+ query.QueryResult = GetDebitorenString(dt);
+ }
+ else
+ {
+ query.FileName = String.Format("1192_{0:yyyyMMdd}_{0:hhmmss}_FIBU.TXT", DateTime.Now);
+ query.QueryResult = GetAbrechnungenString(dt);
+ }
return query;
}
+
+ public static String GetDebitorenString(DateTime date)
+ {
+ var dt = ExecuteQuery(GetDebitorenSql(date), date);
+
+ StringBuilder sb = new StringBuilder();
+ foreach (DataRow row in dt.Rows)
+ {
+ if (sb.Length > 0)
+ {
+ sb.AppendLine();
+ }
+ for (int i = 0; i < row.ItemArray.Length; i++)
+ {
+ if (i > 0)
+ {
+ sb.Append("\t");
+ }
+ var item = row[i];
+ if (i == 15 && item != null)
+ {
+ var oid = (long)row[i];
+ var p = DAOFactory.GenericDAO.LoadByID(oid);
+ string telefon = null;
+
+ var contact = p.Contacts.FirstOrDefault(c => c.Type == ContactType.business_MobilePhone);
+ contact = p.Contacts.FirstOrDefault(c => c.Type == ContactType.business_Phone);
+ if (contact != null)
+ {
+ telefon = contact.Value;
+ }
+ sb.Append(telefon);
+ }
+ else if (i == 2 && item != null)
+ {
+ var sex = row[i].ToString();
+ if(sex == "0")
+ {
+ sb.Append("Herr");
+ }
+ else
+ {
+ sb.Append("Frau");
+ }
+ }
+ else
+ {
+ sb.Append(item);
+ }
+ }
+ }
+ return sb.ToString();
+ }
+
public static String GetAbrechnungenString(DateTime date)
{
StringBuilder sb = new StringBuilder();
@@ -57,6 +120,7 @@ namespace Alloheim.Export
var sql = GetMonatlicheBetraegeSql(date);
var dt = ExecuteQuery(sql, date);
+ int counter = 0;
StringBuilder sb = new StringBuilder();
foreach (DataRow row in dt.Rows)
{
@@ -75,13 +139,14 @@ namespace Alloheim.Export
*/
DateTime lastDate = new DateTime(date.Year, date.Month, 1);
lastDate = lastDate.AddMonths(1).AddDays(-1);
+ counter += 1;
sb.Append("1192\t"); // Buchungskreis 1192
sb.Append("DR\t"); // Beleg DR für Rechnung / DG für Gutschrift
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} \t", lastDate));// Profitcenter + Rechnungs - Nr.VN
+ sb.Append(String.Format("1192{0:ddMMyyyy}{1} \t", lastDate, counter));// Profitcenter + Rechnungs - Nr.VN
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
@@ -99,7 +164,7 @@ 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} \t", lastDate));// Profitcenter + Rechnungs - Nr.VN
+ sb.Append(String.Format("1192{0:ddMMyyyy}{1} \t", lastDate, counter));// Profitcenter + Rechnungs - Nr.VN
sb.Append("1192\t"); // Belegkopftext 1192
sb.Append("S\t"); // S = Sachkontenposition
sb.Append("50\t"); // Kontoart Kontoart S: S=40 H=50
@@ -221,25 +286,41 @@ ib.AccountingPeriodEnd
//string key = String.Format("{0}_{1}", row[2], row[1]); //Dictionary, damit erste Zeile nur einmal geschrieben wird
//if (!key2Value.ContainsKey(key))
//{
- //key2Value.Add(key, key);
+ //key2Value.Add(key, key);
+
+ String betrag = String.Format("{0:0.00}", row[0]); // Betrag
+ if (betrag.Contains("-")) // Storno
+ {
+ betrag = betrag.Replace("-", "");
+ storno = true;
+ }
// Erste Linie - Rechnung
sb.Append("1192\t"); // Buchungskreis 1192
- sb.Append("DR\t"); // Beleg DR für Rechnung / DG für Gutschrift
+ if (storno)
+ {
+ sb.Append("DG\t"); // DG für Gutschrift
+ }
+ else
+ {
+ sb.Append("DR\t"); // Beleg DR für Rechnung / DG für Gutschrift
+ }
sb.Append(String.Format("{0:ddMMyyyy}\t", row[3]));
sb.Append(String.Format("{0:ddMMyyyy}\t", row[3]));
sb.Append("EUR\t");
sb.Append(String.Format("{0}\t", row[1])); // Rechnungs - Nr.VN (Profitcenter ist in Rechnungsnr. enthalten)
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
- sb.Append(String.Format("1192{0}\t", row[6])); //DebitorNumber Kostenträger / zweite Zeile: Sachkonto SAP
- String betrag = String.Format("{0:0.00}", row[0]); // Betrag
- if (betrag.Contains("-")) // Storno
+ if (storno)
{
- storno = true;
+ sb.Append("11\t"); // Kontoart D: S=01 H=11 / zweite Zeile: Kontoart S: S=40 H=50
}
- sb.Append(String.Format("{0:0.00}\t", row[0])); //Betrag
+ else
+ {
+ sb.Append("01\t"); // Kontoart D: S=01 H=11 / zweite Zeile: Kontoart S: S=40 H=50
+ }
+ sb.Append(String.Format("1192{0}\t", row[6])); //DebitorNumber Kostenträger / zweite Zeile: Sachkonto SAP
+ sb.Append(String.Format("{0:0.00}\t", betrag)); //Betrag
sb.Append("00\t"); // Umsatzsteuerschlüssel
if (storno)
{
@@ -279,7 +360,7 @@ ib.AccountingPeriodEnd
sb.Append("50\t"); // Kontoart Kontoart S: S=40 H=50
}
sb.Append("409600\t"); // zweite Zeile: Sachkonto SAP
- sb.Append(String.Format("{0:0.00}\t", row[0])); //Betrag
+ sb.Append(String.Format("{0:0.00}\t", betrag)); //Betrag
sb.Append("00\t"); // Umsatzsteuerschlüssel
if (storno)
{
@@ -329,7 +410,52 @@ ORDER BY p.`LastName`, p.`FirstName`, cb2sc.`ApprovedStartDate`
return sql;
}
- public static DataTable ExecuteQuery(String sql, DateTime dt)
+ private static String GetDebitorenSql(DateTime date)
+ {
+ String sql = @"
+SELECT
+distinct
+CONCAT('1192', c.DebitorNumber),
+null,
+p.Sex,
+CONCAT(p.`LastName`, ' ', p.`FirstName`),
+CONCAT(p.`LastName`, ' ', p.`FirstName`),
+null,
+null,
+null,
+a.Street,
+null,
+a.Town,
+a.PostalCode,
+null,
+null,
+'D',
+p.oid,
+null,
+null,
+null,
+null,
+null,
+null,
+null,
+null,
+null,
+null,
+null,
+'1192'
+FROM `customer` c
+INNER JOIN `person` p ON p.`Oid` = c.`PersonOid`
+INNER JOIN supportconcept sc on sc.CustomerOID = c.Oid
+INNER JOIN costbearer2supportconcept cb2sc on cb2sc.SupportConceptOID = sc.Oid
+LEFT JOIN Address a on p.addressOid = a.oid
+WHERE c.isactive=1 AND c.Insts >= ':Monat_Start' AND c.Insts < ':Monat_End'
+order by p.`LastName`, p.FirstName
+";
+ return sql;
+ }
+
+
+ public static DataTable ExecuteQuery(String sql, DateTime dt)
{
var newsql = sql;
newsql = newsql.Replace(":Abrechnungsmonat", String.Format("{0:dd.MM.yyyy}", dt));
diff --git a/ReportImp/Alloheim/Service/CustomSaveInterceptor.cs b/ReportImp/Alloheim/Service/CustomSaveInterceptor.cs
new file mode 100644
index 000000000..7b3799f5c
--- /dev/null
+++ b/ReportImp/Alloheim/Service/CustomSaveInterceptor.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using BeWo.Data.Access;
+using BeWo.Service.Plugins;
+using BS.Shared;
+using BS.Shared.Core;
+using BS.Shared.DataContracts;
+using BS.Shared.Extensions;
+using BS.Shared.Services;
+
+namespace Alloheim.Service
+{
+
+ public class CustomSaveInterceptor : SaveInterceptor
+ {
+ public override string AllowSaveCustomer(CustomerDC c)
+ {
+ if (String.IsNullOrWhiteSpace(c.DebitorNumber))
+ {
+ int newNummer = 1;
+
+ var result = DAOFactory.SearchDAO.GetSqlResult("SELECT Max(CONVERT(DebitorNumber, UNSIGNED INTEGER)) FROM customer");
+ //
+ //update customer set debitornumber = '5' + debitornumber where debitornumber is not null
+ if (result.Count > 0)
+ {
+ var test = result[0];
+ int p = 0;
+ if (test != null && Int32.TryParse(test.ToString(), out p))
+ {
+ if (p < 150000)
+ {
+ p = 150000;
+ }
+ newNummer = p + 1;
+ }
+ }
+
+ c.DebitorNumber = newNummer.ToString();
+ }
+ return base.AllowSaveCustomer(c);
+ }
+ }
+}
\ No newline at end of file