Skr51Hbv.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. internal class Skr51Hbv : IMandant
  10. {
  11. private const string Country = "DE";
  12. private const string Currency = "EUR";
  13. private static readonly XNamespace Tns = XNamespace.None;
  14. internal enum Hauptmarke { Citroen, Hyundai, Kia, Peugeot };
  15. internal Hauptmarke MandantHauptmarke = Hauptmarke.Kia;
  16. private XDocument _xmlDocument;
  17. private readonly XElement _accounts = new XElement(Tns + "RecordList");
  18. private readonly HashSet<string> _makes = new HashSet<string>();
  19. private readonly HashSet<string> _sites = new HashSet<string>();
  20. private readonly HashSet<string> _departments = new HashSet<string>();
  21. private readonly Konfiguration _config = Konfiguration.GetInstance();
  22. public bool BalanceDatei
  23. {
  24. get { return true; }
  25. }
  26. public bool AccountsDatei
  27. {
  28. get { return false; }
  29. }
  30. public string BalanceHeader
  31. {
  32. get
  33. {
  34. return String.Empty;
  35. }
  36. }
  37. private IEnumerable<XElement> MakeList
  38. {
  39. get
  40. {
  41. return (from make in _makes
  42. select new XElement("MakeListEntry", new XElement("Make", make), new XElement("MakeCode", make == "01" ? GetMakeNumber() : "0000")));
  43. }
  44. }
  45. private string GetMakeNumber()
  46. {
  47. switch (MandantHauptmarke)
  48. {
  49. case Hauptmarke.Citroen:
  50. return "3001";
  51. case Hauptmarke.Hyundai:
  52. return "8252";
  53. case Hauptmarke.Kia:
  54. return "8253";
  55. case Hauptmarke.Peugeot:
  56. return "3003";
  57. }
  58. return "0000";
  59. }
  60. private IEnumerable<XElement> BmCodeList
  61. {
  62. get
  63. {
  64. return (from dept in _departments
  65. select
  66. new XElement("BmCodeListEntry", new XElement("Make", dept.Split(new[] {'-'})[0]),
  67. new XElement("Site", dept.Split(new[] {'-'})[1]),
  68. new XElement("BmCode", _config.HaendlernummerBmCode)));
  69. }
  70. }
  71. public string BalanceFooter
  72. {
  73. get
  74. {
  75. _xmlDocument = new XDocument();
  76. _xmlDocument.Add(new XElement(Tns + "HbvData",
  77. new XElement(Tns + "Header",
  78. new XElement(Tns + "Country", Country),
  79. new XElement(Tns + "MainBmCode", _config.HaendlernummerBmCode),
  80. new XElement(Tns + "Month", _config.AktuellePeriode.Monat),
  81. new XElement(Tns + "Year", _config.AktuellePeriode.Jahr),
  82. new XElement(Tns + "Currency", Currency),
  83. new XElement(Tns + "NumberOfMakes", _makes.Count),
  84. new XElement(Tns + "NumberOfSites", _sites.Count),
  85. new XElement(Tns + "ExtractionDate", DateTime.Now.ToShortDateString()),
  86. new XElement(Tns + "ExtractionTime", string.Format("{0:T}", DateTime.Now)),
  87. new XElement(Tns + "BeginFiscalYear", _config.Geschaeftsjahr)
  88. ),
  89. new XElement(Tns + "MakeList", MakeList),
  90. new XElement(Tns + "BmCodeList", BmCodeList),
  91. _accounts
  92. ));
  93. return _xmlDocument.ToString();
  94. }
  95. }
  96. public string BalanceBody(HaendlerKonto konto)
  97. {
  98. // Konto: Account-Make-Site-Origin-SalesChannel-CostCarrier
  99. var split = konto.Kontonummer.Split(new[] {'-'});
  100. var make = (split[1] == "??") ? konto.Marke : split[1];
  101. if (!_makes.Contains(make))
  102. {
  103. _makes.Add(make);
  104. }
  105. var site = (split[2] == "??") ? konto.Betrieb : split[2];
  106. if (!_sites.Contains(site))
  107. {
  108. _sites.Add(site);
  109. }
  110. var department = make + "-" + site;
  111. if (!_departments.Contains(department))
  112. {
  113. _departments.Add(department);
  114. }
  115. _accounts.Add(new XElement(Tns + "Record",
  116. new XElement(Tns + "Account", split[0].PadLeft(4, '0')),
  117. new XElement(Tns + "Make", make.PadLeft(2, '0')),
  118. new XElement(Tns + "Site", site.PadLeft(2, '0')),
  119. new XElement(Tns + "Origin", split[3].PadLeft(2, '0')),
  120. new XElement(Tns + "SalesChannel", split[4].PadLeft(2, '0')),
  121. new XElement(Tns + "CostCarrier", split[5].PadLeft(2, '0')),
  122. new XElement(Tns + "CostAccountingString", make.PadLeft(2, '0') + site.PadLeft(2, '0') + split[3].PadLeft(2, '0') + split[4].PadLeft(2, '0') + split[5].PadLeft(2, '0')),
  123. new XElement(Tns + "Decimals", "2"),
  124. new XElement(Tns + "OpeningBalance", string.Format("{0:0.}", konto.Eroeffnungsbilanz * 100)),
  125. new XElement(Tns + "Period01", MonatFormat(konto, 1)),
  126. new XElement(Tns + "Period02", MonatFormat(konto, 2)),
  127. new XElement(Tns + "Period03", MonatFormat(konto, 3)),
  128. new XElement(Tns + "Period04", MonatFormat(konto, 4)),
  129. new XElement(Tns + "Period05", MonatFormat(konto, 5)),
  130. new XElement(Tns + "Period06", MonatFormat(konto, 6)),
  131. new XElement(Tns + "Period07", MonatFormat(konto, 7)),
  132. new XElement(Tns + "Period08", MonatFormat(konto, 8)),
  133. new XElement(Tns + "Period09", MonatFormat(konto, 9)),
  134. new XElement(Tns + "Period10", MonatFormat(konto, 10)),
  135. new XElement(Tns + "Period11", MonatFormat(konto, 11)),
  136. new XElement(Tns + "Period12", MonatFormat(konto, 12)),
  137. new XElement(Tns + "CumulatedYear", string.Format("{0:0.}", konto.Summe * 100))
  138. ));
  139. return String.Empty;
  140. }
  141. private static string MonatFormat(HaendlerKonto konto, int monat)
  142. {
  143. return string.Format("{0:0.}", konto.Monatssumme(monat)*100);
  144. }
  145. public string AccountsHeader
  146. {
  147. get { return String.Empty; }
  148. }
  149. public string AccountsBody(HaendlerKonto kto)
  150. {
  151. return String.Empty;
  152. }
  153. public string AccountsFooter
  154. {
  155. get { return String.Empty; }
  156. }
  157. public string KontonummerFormatieren(HaendlerKonto konto)
  158. {
  159. // Konto: Account-Make-Site-Origin-SalesChannel-CostCarrier
  160. var split = konto.Kontonummer.Split(new[] { '-' });
  161. if (split.Count() < 6) return konto.ToString();
  162. var make = (split[1] == "??") ? konto.Marke : split[1];
  163. var site = (split[2] == "??") ? konto.Betrieb : split[2];
  164. return split[0].PadLeft(4, '0') + "-" + make.PadLeft(2, '0') + site.PadLeft(2, '0') + split[3].PadLeft(2, '0') + split[4].PadLeft(2, '0') + split[5].PadLeft(2, '0');
  165. }
  166. public Encoding Encoding
  167. {
  168. get { return Encoding.Default; }
  169. }
  170. }
  171. }