Volkswagen.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml.Linq;
  6. using GCHR.Model.Konto;
  7. namespace GCHR.Model.Mandant
  8. {
  9. class Volkswagen : IMandant
  10. {
  11. /// <summary>
  12. /// V = Volkswagen,
  13. /// A = Audi,
  14. /// S = Seat,
  15. /// C = Skoda,
  16. /// E = Bentley,
  17. /// L = Lamborghini
  18. /// </summary>
  19. internal enum Hauptmarke { V, A, S, C, E, L };
  20. /// <summary>
  21. /// 1 = Istdaten,
  22. /// 2 = Plandaten
  23. /// </summary>
  24. private const string Level = "1";
  25. private const string Country = "DEU";
  26. private const string Currency = "EUR";
  27. private static readonly XNamespace Tns = "http://xmldefs.volkswagenag.com/Retail/AccountBalanceDTS/V1";
  28. private static XNamespace _tns1 = "http://xmldefs.volkswagenag.com/DD/BasicTypes";
  29. private static XNamespace _xsi = "http://www.w3.org/2001/XMLSchema-instance";
  30. private XDocument _xmlDocument;
  31. private readonly XElement _accounts = new XElement(Tns + "Accounts");
  32. private readonly Konfiguration _config = Konfiguration.GetInstance();
  33. internal Hauptmarke MandantHauptmarke = Hauptmarke.V;
  34. public bool BalanceDatei
  35. {
  36. get
  37. {
  38. return true;
  39. }
  40. }
  41. public bool AccountsDatei
  42. {
  43. get { return false; }
  44. }
  45. public string BalanceHeader
  46. {
  47. get
  48. {
  49. _xmlDocument = new XDocument();
  50. _xmlDocument.Add(new XElement(Tns + "ShowAccountBalance",
  51. new XAttribute(XNamespace.Xmlns + "tns", Tns),
  52. // new XAttribute(XNamespace.Xmlns + "tns1", tns1),
  53. // new XAttribute(XNamespace.Xmlns + "xsi", xsi),
  54. // new XAttribute(xsi + "schemaLocation", "http://xmldefs.volkswagenag.com/Retail/AccountBalanceDTS/V1 AccountBalanceDTS.xsd"),
  55. new XElement(Tns + "PartnerKey",
  56. new XElement(Tns + "Country", Country),
  57. new XElement(Tns + "Brand", MandantHauptmarke),
  58. new XElement(Tns + "PartnerNumber", _config.HaendlernummerBmCode)
  59. ),
  60. new XElement(Tns + "IsCumulative", "true"),
  61. new XElement(Tns + "AccountingDate",
  62. new XElement(Tns + "AccountingMonth", _config.AktuellePeriode.Monat),
  63. new XElement(Tns + "AccountingYear", _config.AktuellePeriode.Jahr)
  64. ),
  65. new XElement(Tns + "Currency", Currency),
  66. new XElement(Tns + "Level", Level),
  67. _accounts
  68. ));
  69. return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
  70. /*
  71. return String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + Environment.NewLine +
  72. "<tns:ShowAccountBalance" + Environment.NewLine +
  73. " xmlns:tns=\"http://xmldefs.volkswagenag.com/Retail/AccountBalanceDTS/V1\" " + Environment.NewLine +
  74. " xmlns:tns1=\"http://xmldefs.volkswagenag.com/DD/BasicTypes\" " + Environment.NewLine +
  75. " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + Environment.NewLine +
  76. " xsi:schemaLocation=\"http://xmldefs.volkswagenag.com/Retail/AccountBalanceDTS/V1 AccountBalanceDTS.xsd\">" + Environment.NewLine +
  77. " <tns:PartnerKey>" + Environment.NewLine +
  78. " <tns:Country>{0}</tns:Country>" + Environment.NewLine +
  79. " <tns:Brand>{1}</tns:Brand>" + Environment.NewLine +
  80. " <tns:PartnerNumber>{2}</tns:PartnerNumber>" + Environment.NewLine +
  81. " </tns:PartnerKey>" + Environment.NewLine +
  82. " <tns:IsCumulative>true</tns:IsCumulative>" + Environment.NewLine +
  83. " <tns:AccountingDate>" + Environment.NewLine +
  84. " <tns:AccountingMonth>{3}</tns:AccountingMonth>" + Environment.NewLine +
  85. " <tns:AccountingYear>{4}</tns:AccountingYear>" + Environment.NewLine +
  86. " </tns:AccountingDate>" + Environment.NewLine +
  87. " <tns:Currency>{5}</tns:Currency>" + Environment.NewLine +
  88. " <tns:Level>{6}</tns:Level>" + Environment.NewLine +
  89. " <tns:Accounts>",
  90. country, Hauptmarke.V, config.Händlernummer, Konto.aktuellePeriode.Monat, Konto.aktuellePeriode.Jahr, currency, level);
  91. */
  92. }
  93. }
  94. public string BalanceFooter
  95. {
  96. get
  97. {
  98. return _xmlDocument.ToString();
  99. }
  100. }
  101. public string BalanceBody(HaendlerKonto konto)
  102. {
  103. _accounts.Add(new XElement(Tns + "Account",
  104. new XElement(Tns + "ProfitCenter", "00"),
  105. new XElement(Tns + "AccountKey",
  106. KontonummerFormatieren(konto)
  107. // accountAttributes(kto)
  108. ),
  109. new XElement(Tns + "AccountValue", AccountValue(konto))
  110. ));
  111. return String.Empty;
  112. }
  113. private XAttribute[] AccountAttributes(HaendlerKonto kto)
  114. {
  115. return (from attrib in AccountKeyDict(kto)
  116. select new XAttribute(attrib.Key, attrib.Value)).ToArray();
  117. }
  118. private static Dictionary<string, string> AccountKeyDict(HaendlerKonto konto)
  119. {
  120. // Konto: Account-Make-Site-Origin-SalesChannel-CostCarrier
  121. var split = konto.Kontonummer.Split(new[] { '-' });
  122. if (split.Count() == 6)
  123. {
  124. var marke = (split[1].Contains("?")) ? konto.Marke : split[1];
  125. marke = marke.PadLeft(6, '0');
  126. var betrieb = (split[2] == "??") ? konto.Betrieb : split[2];
  127. return new Dictionary<string, string>
  128. {
  129. {"Brand", marke.Substring(0, 2)},
  130. {"ModelCode", marke.Substring(2)},
  131. {"Account", split[0].PadLeft(4, '0')},
  132. {"CostCentre", split[3].PadLeft(2, '0')},
  133. {"TradeChannel", split[4].PadLeft(2, '0')},
  134. {"CostUnit", split[5].PadLeft(2, '0')},
  135. {"Location", betrieb.PadLeft(2, '0')},
  136. {"TaxCode", "000"}
  137. };
  138. }
  139. var marke2 = konto.Marke.PadRight(6, '?');
  140. var kontonummer = konto.Kontonummer.PadRight(10, '?');
  141. return new Dictionary<string, string>
  142. {
  143. {"Brand", marke2.Substring(0, 2)},
  144. {"ModelCode", marke2.Substring(2)},
  145. {"Account", kontonummer.Substring(0, 4)},
  146. {"CostCentre", kontonummer.Substring(4, 2)},
  147. {"TradeChannel", kontonummer.Substring(6, 2)},
  148. {"CostUnit", kontonummer.Substring(8, 2)},
  149. {"Location", konto.Betrieb},
  150. {"TaxCode", "000"}
  151. };
  152. }
  153. private static string AccountValue(HaendlerKonto kto)
  154. {
  155. /*
  156. if (kto.KontoTyp == KontoTypen.SuSa)
  157. {
  158. return String.Format("{0:-0.00;+0.00;+0.00}", kto.Summe).Replace(',', '.');
  159. }*/
  160. return String.Format("{0:+0.00;-0.00;+0.00}", kto.Summe).Replace(',', '.');
  161. }
  162. public string AccountsHeader
  163. {
  164. get
  165. {
  166. return String.Empty;
  167. }
  168. }
  169. public string AccountsBody(HaendlerKonto kto)
  170. {
  171. return String.Empty;
  172. }
  173. public string AccountsFooter
  174. {
  175. get
  176. {
  177. return String.Empty;
  178. }
  179. }
  180. public string KontonummerFormatieren(HaendlerKonto konto)
  181. {
  182. return String.Join("", AccountKeyDict(konto).Values.ToArray());
  183. }
  184. public Encoding Encoding
  185. {
  186. get { return Encoding.Default; }
  187. }
  188. }
  189. }