using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using GCHR.Model;
using GCHR.Model.Konto;
namespace GCHR.Mandantenschnittstelle
{
class Volkswagen : IMandant
{
///
/// V = Volkswagen,
/// A = Audi,
/// S = Seat,
/// C = Skoda,
/// E = Bentley,
/// L = Lamborghini
///
enum Hauptmarke { V, A, S, C, E, L };
///
/// 1 = Istdaten,
/// 2 = Plandaten
///
private const string Level = "1";
private const string Country = "DEU";
private const string Currency = "EUR";
private static readonly XNamespace Tns = "http://xmldefs.volkswagenag.com/Retail/AccountBalanceDTS/V1";
private static XNamespace _tns1 = "http://xmldefs.volkswagenag.com/DD/BasicTypes";
private static XNamespace _xsi = "http://www.w3.org/2001/XMLSchema-instance";
private XDocument _xmlDocument;
private readonly XElement _accounts = new XElement(Tns + "Accounts");
private readonly Konfiguration _config = Konfiguration.GetInstance();
public bool BalanceDatei
{
get
{
return true;
}
}
public bool AccountsDatei
{
get { return false; }
}
public string BalanceHeader
{
get
{
_xmlDocument = new XDocument();
_xmlDocument.Add(new XElement(Tns + "ShowAccountBalance",
new XAttribute(XNamespace.Xmlns + "tns", Tns),
// new XAttribute(XNamespace.Xmlns + "tns1", tns1),
// new XAttribute(XNamespace.Xmlns + "xsi", xsi),
// new XAttribute(xsi + "schemaLocation", "http://xmldefs.volkswagenag.com/Retail/AccountBalanceDTS/V1 AccountBalanceDTS.xsd"),
new XElement(Tns + "PartnerKey",
new XElement(Tns + "Country", Country),
new XElement(Tns + "Brand", Hauptmarke.V),
new XElement(Tns + "PartnerNumber", _config.Händlernummer)
),
new XElement(Tns + "IsCumulative", "true"),
new XElement(Tns + "AccountingDate",
new XElement(Tns + "AccountingMonth", HaendlerKonto.AktuellePeriode.Monat),
new XElement(Tns + "AccountingYear", HaendlerKonto.AktuellePeriode.Jahr)
),
new XElement(Tns + "Currency", Currency),
new XElement(Tns + "Level", Level),
_accounts
));
return "";
/*
return String.Format("" + Environment.NewLine +
"" + Environment.NewLine +
" " + Environment.NewLine +
" {0}" + Environment.NewLine +
" {1}" + Environment.NewLine +
" {2}" + Environment.NewLine +
" " + Environment.NewLine +
" true" + Environment.NewLine +
" " + Environment.NewLine +
" {3}" + Environment.NewLine +
" {4}" + Environment.NewLine +
" " + Environment.NewLine +
" {5}" + Environment.NewLine +
" {6}" + Environment.NewLine +
" ",
country, Hauptmarke.V, config.Händlernummer, Konto.aktuellePeriode.Monat, Konto.aktuellePeriode.Jahr, currency, level);
*/
}
}
public string BalanceFooter
{
get
{
return _xmlDocument.ToString();
}
}
public string BalanceBody(HaendlerKonto kto)
{
_accounts.Add(new XElement(Tns + "Account",
new XElement(Tns + "ProfitCenter", "00"),
new XElement(Tns + "AccountKey",
AccountKey(kto)
// accountAttributes(kto)
),
new XElement(Tns + "AccountValue", AccountValue(kto))
));
return String.Empty;
}
private string AccountKey(HaendlerKonto kto)
{
return String.Join("", AccountKeyDict(kto).Values.ToArray());
}
private object[] AccountAttributes(HaendlerKonto kto)
{
return (from attrib in AccountKeyDict(kto)
select new XAttribute(attrib.Key, attrib.Value)).ToArray();
}
private static Dictionary AccountKeyDict(HaendlerKonto kto)
{
var marke = kto.Marke.PadRight(6, '?');
var kontonummer = kto.Kontonummer.PadRight(10, '?');
var dict = new Dictionary();
dict.Add("Brand", marke.Substring(0,2));
dict.Add("ModelCode", marke.Substring(2));
dict.Add("Account", kontonummer.Substring(0,4));
dict.Add("CostCentre", kontonummer.Substring(4, 2));
dict.Add("TradeChannel", kontonummer.Substring(6, 2));
dict.Add("CostUnit", kontonummer.Substring(8, 2));
dict.Add("Location", kto.Betrieb);
dict.Add("TaxCode", "000");
return dict;
}
private static string AccountValue(HaendlerKonto kto)
{
/*
if (kto.KontoTyp == KontoTypen.SuSa)
{
return String.Format("{0:-0.00;+0.00;+0.00}", kto.Summe).Replace(',', '.');
}*/
return String.Format("{0:+0.00;-0.00;+0.00}", kto.Summe).Replace(',', '.');
}
public string AccountsHeader
{
get
{
return String.Empty;
}
}
public string AccountsFooter
{
get
{
return String.Empty;
}
}
public string AccountsBody(HaendlerKonto kto)
{
return String.Empty;
}
}
}