static VatSumOperationReport CreateSum(VatSumOperationReport[] vatReportSum, int pos, double rate = 0d) { var sumLine = vatReportSum[pos]; if (sumLine != null) { return(sumLine); } return(vatReportSum[pos] = new VatSumOperationReport() { _Line = pos, _Pct = rate }); }
private async void LoadVatReport() { DateTime FromDate, ToDate; if (txtDateFrm.Text == string.Empty) { FromDate = DateTime.Today; FromDate = FromDate.AddDays(1 - FromDate.Day); // first day in current month } else { FromDate = localFromDate = txtDateFrm.DateTime.Date; } if (txtDateTo.Text == string.Empty) { ToDate = DateTime.Today.AddMonths(1); ToDate = ToDate.AddDays(-ToDate.Day); // last day in current month } else { ToDate = localToDate = txtDateTo.DateTime.Date; } busyIndicator.IsBusy = true; var qapi = api; var country = qapi.CompanyEntity._CountryId; var rapi = new ReportAPI(qapi); string journal = cmbJournal.Text; var vatTask = rapi.VatCodeSum(FromDate, ToDate, journal); SQLCache accounts = qapi.GetCache(typeof(Uniconta.DataModel.GLAccount)) ?? await qapi.LoadCache(typeof(Uniconta.DataModel.GLAccount)); SQLCache vats = qapi.GetCache(typeof(Uniconta.DataModel.GLVat)) ?? await qapi.LoadCache(typeof(Uniconta.DataModel.GLVat)); SQLCache vattypes = qapi.GetCache(typeof(Uniconta.DataModel.GLVatType)) ?? await qapi.LoadCache(typeof(Uniconta.DataModel.GLVatType)); FinancialBalance[] sumVat = await vatTask; if (sumVat == null || accounts == null || vats == null || vattypes == null) { busyIndicator.IsBusy = false; UtilDisplay.ShowErrorCode(rapi.LastError); return; } Array.Sort(sumVat, new AccountSorter()); VatReportLine v; var lst = new List <VatReportLine>(sumVat.Length); int decm = 2; bool RoundTo100 = false; if (!qapi.CompanyEntity.HasDecimals) { CalculatedVAT.HasDecimals = PostedVAT.HasDecimals = WithoutVAT.HasDecimals = Accumulated.HasDecimals = false; RoundTo100 = true; decm = 0; } var countrySelected = (CountryCode)Math.Max(0, vatCountry.SelectedIndex); var AccsFound = new HashSet <int>(); GLAccount Account; GLVat Vat; int i; bool HasOffsetType0 = false, HasOffsetType1 = false; int PrevAccount = 0; for (i = 0; (i < sumVat.Length); i++) { var sum = sumVat[i]; Account = (GLAccount)accounts.Get(sum.AccountRowId); if (Account == null) // || Account._SystemAccount == (byte)SystemAccountTypes.SalesTaxOffset) { continue; } //if (sum._Debit == 0 && sum._Credit == 0) // continue; Vat = (GLVat)vats.Get(sum.VatRowId); if (Vat == null) { continue; } var acStr = Account._Account; v = new VatReportLine(); v.AmountWithVat = sum.Debit; v._PostedVAT = sum.Credit; v._BaseVAT = sum.AmountBase; v.AccountNumber = acStr; v.Account = Account; v.AccountIsVat = Account._SystemAccount == (byte)SystemAccountTypes.SalesTaxPayable || Account._SystemAccount == (byte)SystemAccountTypes.SalesTaxReceiveable ? (byte)1 : (byte)0; if (Vat._Account == acStr || Vat._OffsetAccount == acStr) { if (Vat._Account == acStr) { v.AccountIsVat = 1; v.IsOffsetAccount = 0; } else { v.AccountIsVat = 1; v.IsOffsetAccount = 1; if (Vat._VatType == 0) { HasOffsetType0 = true; } else { HasOffsetType1 = true; } } } else { foreach (var va in (IEnumerable <GLVat>)vats.GetNotNullArray) { if (va._Account == acStr) { v.AccountIsVat = 1; v.IsOffsetAccount = 0; break; } if (va._OffsetAccount == acStr) { v.AccountIsVat = 1; v.IsOffsetAccount = 1; if (va._VatType == 0) { HasOffsetType0 = true; } else { HasOffsetType1 = true; } // do not break in case we foind the same account as _Account } } } v.Vat = Vat; v.VatType = (byte)Vat._VatType; if (v.IsOffsetAccount == 1 && Vat._OffsetVatOperation != null) { v._VatOperation = (byte)vattypes.Get(Vat._OffsetVatOperation).RowId; } else { v._VatOperation = sum.VatOperation != 0 ? sum.VatOperation : Vat._VatOperationCode; } v._CalculatedVAT = Vat.VatAmount1(v.AmountWithVat, FromDate, RoundTo100, GLVatCalculationMethod.Netto); v.FromDate = FromDate; v.CalcRate(RoundTo100); var vattp = (GLVatType)vattypes.Get(v._VatOperation); if (vattp != null) { v.VatOpr = vattp; v.vatOperation = vattp._Code; v.BaseVatText = vattp._Name; } lst.Add(v); if (PrevAccount != sum.AccountRowId) { PrevAccount = sum.AccountRowId; AccsFound.Add(sum.AccountRowId); } } foreach (var acc in (GLAccount[])accounts.GetNotNullArray) { if (acc._Vat != null) { Vat = (GLVat)vats.Get(acc._Vat); if (Vat == null) { continue; } if (countrySelected != 0 && countrySelected != (Vat._VatCountry != 0 ? Vat._VatCountry : country)) { continue; } AccsFound.Add(acc.RowId); } } List <int> AccLst = AccsFound.ToList(); AccsFound.Clear(); FinancialBalance[] AccTotals = await rapi.GenerateTotal(AccLst, FromDate, ToDate, journal, null, 0, true, false); SQLCacheTemplate <FinancialBalance> AccLookup = null; if (AccTotals != null && AccTotals.Length > 0) { AccLookup = new SQLCacheTemplate <FinancialBalance>(AccTotals, false); } lst.Sort(new VatAccountSort()); FinancialBalance AccTotal; int AccountRowId = 0; double AmountDif = 0d; VatReportLine vDif = new VatReportLine(); for (i = lst.Count; (--i >= 0);) { v = lst[i]; if (v.Account.RowId != AccountRowId) { if (AmountDif > 0.005d || AmountDif < -0.005d) { vDif.AmountWithout = GLVat.Round(AmountDif); lst.Add(vDif); vDif = new VatReportLine(); } AccountRowId = v.Account.RowId; AccTotal = AccLookup?.Get(AccountRowId); if (AccTotal != null) { AmountDif = (AccTotal._Debit - AccTotal._Credit) / 100d; } else { AmountDif = 0d; } AccsFound.Add(AccountRowId); } AmountDif -= v.AmountWithVat; vDif.Account = v.Account; vDif.AccountNumber = v.AccountNumber; vDif.VatType = v.VatType; vDif.AccountIsVat = v.AccountIsVat; vDif.IsOffsetAccount = v.IsOffsetAccount; } if (AmountDif > 0.005d || AmountDif < -0.005d) { vDif.AmountWithout = GLVat.Round(AmountDif); lst.Add(vDif); } if (AccLookup != null) { // Add account, that has a VAT-code but no transactios with VAT. for (i = 0; (i < AccTotals.Length); i++) { AccTotal = AccTotals[i]; if (!AccsFound.Contains(AccTotal.RowId) && (AccTotal._Debit - AccTotal._Credit) != 0) { Account = (GLAccount)accounts.Get(AccTotal.RowId); if (Account?._Vat == null) { continue; } Vat = (GLVat)vats.Get(Account._Vat); if (Vat == null) { continue; } vDif = new VatReportLine(); vDif.AmountWithout = (AccTotal._Debit - AccTotal._Credit) / 100d; vDif.Account = Account; vDif.AccountNumber = Account._Account; vDif.VatType = (byte)Vat._VatType; lst.Add(vDif); } } } if (countrySelected != 0) { for (i = lst.Count; (--i >= 0);) { Vat = (GLVat)vats.Get(lst[i].VatCode); if (Vat != null) { if (countrySelected != (Vat._VatCountry != 0 ? Vat._VatCountry : country)) { lst.RemoveAt(i); continue; } } } } vDif = null; for (int k = 0; (k < 4); k++) { string helptext; if (k == 0) { helptext = "sales"; } else if (k == 1) { helptext = "buy"; } else if (k == 2) { helptext = "sales vat"; } else { helptext = "buy vat"; } for (int n = 0; n < 3; n++) { vDif = new VatReportLine(); vDif.helptext = helptext; vDif.Order = (n > 0) ? n : -1; // header, total, empty vDif.VatType = (byte)(k % 2); vDif.AccountIsVat = (byte)(k / 2); vDif.isvatotal = (k >= 2 && n == 1); lst.Add(vDif); if (vDif.AccountIsVat == 1) { if ((HasOffsetType0 && vDif.VatType == 0) || (HasOffsetType1 && vDif.VatType == 1)) { vDif = new VatReportLine(); vDif.helptext = "import vat"; vDif.Order = (n > 0) ? n : -1; // header, total, empty vDif.VatType = (byte)(k % 2); vDif.AccountIsVat = 1; vDif.IsOffsetAccount = 1; vDif.isvatotal = true; lst.Add(vDif); } } } } vDif = null; lst.Sort(new VatTotalsSort()); double d1 = 0d, d2 = 0d, d3 = 0d, d4 = 0d; double[] VatOperationValues = new double[256]; double[] VatOperationBases = new double[256]; double[] VatValues = new double[256]; double[] VatBases = new double[256]; VatSumOperationReport[] vatReportSum = new VatSumOperationReport[127]; for (i = 0; (i < lst.Count); i++) { v = lst[i]; if (v.Order == 1) // total { v.AmountWithVat = Math.Round(d1, decm); var AmountWithout = Math.Round(d2, decm); v.AmountWithout = AmountWithout; v._CalculatedVAT = Math.Round(d3, decm); v._PostedVAT = Math.Round(d4, decm); d1 = d2 = d3 = d4 = 0d; if (country == CountryCode.Denmark && AmountWithout != 0 && v.AccountIsVat == 1) { if (v.IsOffsetAccount == 0) { // here we sum up the amount without vatcodes if (v.VatType == 0) { var sumLine = CreateSum(vatReportSum, 33); sumLine._Amount -= AmountWithout; } else { var sumLine = CreateSum(vatReportSum, 23); sumLine._Amount += AmountWithout; sumLine = CreateSum(vatReportSum, 31); sumLine._Amount += AmountWithout; } } else { if (v.VatType == 1) { var sumLine = CreateSum(vatReportSum, 34); sumLine._Amount -= AmountWithout; } } } } else { d1 += v.AmountWithVat; d2 += v.AmountWithout; d3 += v._CalculatedVAT; d4 += v._PostedVAT; if (v.AccountIsVat == 1) { if (v.IsOffsetAccount == 0) { VatOperationValues[v._VatOperation] += v.AmountWithVat; if (v.Vat != null) { VatValues[v.Vat.RowId] += v.AmountWithVat; } } } else { VatOperationBases[v._VatOperation] += v.AmountWithVat; if (v.Vat != null) { VatBases[v.Vat.RowId] += v.AmountWithVat; } } } } vDif = new VatReportLine(); vDif.Text = string.Format("{0}: {1}, {2}", Uniconta.ClientTools.Localization.lookup("FinalVatStatus"), Uniconta.ClientTools.Localization.lookup("AmountBase"), Uniconta.ClientTools.Localization.lookup("VATamount")); lst.Add(vDif); foreach (var c in (GLVatType[])vattypes.GetNotNullArray) { if (c == null) { continue; } vDif = new VatReportLine(); vDif.vatOperation = c._Code; vDif._Rate = c._Pct1; vDif.Text = string.Concat(c._Code, ", ", c._Name); vDif.AmountWithVat = VatOperationBases[c._RowNo]; vDif._PostedVAT = VatOperationValues[c._RowNo]; vDif.AccountIsVat = 1; lst.Add(vDif); int pos = c._Position1; if (pos > 0) { UpdateSum(vatReportSum, vDif, pos, c._Position2, c._Position3); } pos = c._Position4; if (pos > 0) { UpdateSum(vatReportSum, vDif, pos, c._Position5, c._Position6); } pos = c._Position7; if (pos > 0) { UpdateSum(vatReportSum, vDif, pos, c._Position8, c._Position9); } pos = c._Position10; if (pos > 0) { UpdateSum(vatReportSum, vDif, pos, c._Position11, c._Position12); } pos = c._Position13; if (pos > 0) { UpdateSum(vatReportSum, vDif, pos, c._Position14, c._Position15); } } List <VatReportLine> vatlst = new List <VatReportLine>(); this.vatlst = vatlst; for (int k = 0; (k < 2); k++) { vDif = new VatReportLine(); vDif.Text = string.Empty; lst.Add(vDif); vDif = new VatReportLine(); vDif.VatType = (byte)k; vDif.Order = -1; vDif.AccountIsVat = 1; lst.Add(vDif); foreach (var c in (GLVat[])vats.GetNotNullArray) { if (c != null && (int)c._VatType == k) { if (countrySelected != 0 && countrySelected != (c._VatCountry != 0 ? c._VatCountry : country)) { continue; } vDif = new VatReportLine(); vDif.Vat = c; vDif.Text = string.Concat(c._Vat, ", ", c._Name); vDif.AmountWithVat = VatBases[c.RowId]; vDif._PostedVAT = VatValues[c.RowId]; vDif.AccountIsVat = 1; vDif.FromDate = FromDate; vDif.CalcRate(RoundTo100); lst.Add(vDif); vatlst.Add(vDif); } } } dgVatReport.ItemsSource = lst; if (lst.Count > 0) { SetMenuItem(); } if (country == CountryCode.Denmark) { AccLst.Clear(); foreach (var acc in (GLAccount[])accounts.GetNotNullArray) { if (acc._SystemAccount == (byte)SystemAccountTypes.OtherTax) { AccLst.Add(acc.RowId); } } if (AccLst != null && AccLst.Count > 0) { AccTotals = await rapi.GenerateTotal(AccLst, FromDate, ToDate); if (AccTotals != null && AccTotals.Length > 0) { var otherTaxList = new ReportDataDenmark[AccTotals.Length]; i = 14; foreach (var acTot in AccTotals) { var Acc = accounts.Get(acTot.AccountRowId); var lin = new VatSumOperationReport() { _Text = Acc.KeyName, _Amount = (acTot._Debit - acTot._Credit) / 100d, _Line = i }; vatReportSum[i] = lin; i++; if (i == 19) { break; } } } } } for (i = vatReportSumSize + 1; (--i >= 1);) { if (vatReportSum[i] == null) { vatReportSum[i] = new VatSumOperationReport() { _Line = i } } } ; this.vatReportSum = vatReportSum.Where(r => r != null).ToList(); dgVatReport.Visibility = Visibility.Visible; busyIndicator.IsBusy = false; }
public VatReportNorway(List <VatSumOperationReport> VatSumOperationLst, DateTime fromDate, DateTime toDate) : base(null) { this.VatSumOperationLst = VatSumOperationLst; this.FromDate = fromDate; this.ToDate = toDate; InitializeComponent(); this.DataContext = this; localMenu.dataGrid = dgVatReportNorway; SetRibbonControl(localMenu, dgVatReportNorway); localMenu.OnItemClicked += localMenu_OnItemClicked; dgVatReportNorway.api = api; dgVatReportNorway.BusyIndicator = busyIndicator; #if !SILVERLIGHT txtFromDate.DateTime = fromDate; txtToDate.DateTime = toDate; #endif VatSumOperationReport post2 = null; double sum = 0d, sumBase = 0d; foreach (var rec in VatSumOperationLst) { string s; switch (rec._Line) { case 1: s = "Samlet omsetning og uttak utenfor merverdiavgiftsloven"; break; case 2: s = "Samlet omsetning og uttak innenfor merverdiavgiftsloven og innførsel"; post2 = rec; break; case 3: s = "Innenlands omsetning og uttak, og beregnet avgift 25 %"; break; case 4: s = "Innenlands omsetning og uttak, og beregnet avgift 15 %"; break; case 5: s = "Innenlands omsetning og uttak, og beregnet avgift 10 %"; break; case 6: s = "Innenlands omsetning og uttak fritatt for merverdiavgift"; break; case 7: s = "Innenlands omsetning med omvendt avgiftsplikt"; break; case 8: s = "Utførsel av varer og tjenester fritatt for merverdiavgift"; break; case 9: s = "Innførsel av varer, og beregnet avgift 25 %"; break; case 10: s = "Innførsel av varer, og beregnet avgift 15 %"; break; case 11: s = "Innførsel av varer som det ikke skal beregnes merverdiavgift av"; break; case 12: s = "Tjenester kjøpt fra utlandet, og beregnet avgift 25 %"; break; case 13: s = "Innenlands kjøp av varer og tjenester, og beregnet avgift 25 %"; break; case 14: s = "Fradragsberettiget innenlands inngående avgift 25 %"; break; case 15: s = "Fradragsberettiget innenlands inngående avgift 15 %"; break; case 16: s = "Fradragsberettiget innenlands inngående avgift 10 %"; break; case 17: s = "Fradragsberettiget innførselsmerverdiavgift 25 %"; break; case 18: s = "Fradragsberettiget innførselsmerverdiavgift 15 %"; break; case 19: s = "Avgift å betale / Avgift til gode"; rec._Amount = sum; break; default: s = null; break; } rec._Text = s; if (rec._Line >= 3) { sum += rec._Amount; if (rec._Line <= 13) { sumBase += rec._AmountBase; } } } if (post2 != null) { post2._ExtraBase = sumBase; } dgVatReportNorway.ItemsSource = VatSumOperationLst; dgVatReportNorway.Visibility = Visibility.Visible; this.DataContext = null; this.DataContext = this; }
public VatReportHolland(List <VatSumOperationReport> vatSumOperationLst, DateTime fromDate, DateTime toDate) : base(null) { this.VatSumOperationLst = vatSumOperationLst; this.fromDate = fromDate; this.toDate = toDate; InitializeComponent(); this.DataContext = this; dgVatReportHolland.api = api; dgVatReportHolland.BusyIndicator = busyIndicator; bool SumIsneg = false; double sum = 0d, sumBase = 0d, sum19 = 0d; int lastIndex = 0; var lst = new VatSumOperationReport[23]; for (int lin = 1; (lin <= 23); lin++) //foreach (var rec in VatSumOperationLst) { string s, opr; VatSumOperationReport rec = null; while (lastIndex < VatSumOperationLst.Count) { rec = VatSumOperationLst[lastIndex]; if (rec != null) { if (rec._Line == lin) { break; } if (rec._Line > lin) { rec = null; break; } rec = null; } lastIndex++; } if (rec == null) { rec = new VatSumOperationReport() { _Line = lin } } ; lst[lin - 1] = rec; if (lin == 17 || lin == 19 || lin == 23) { rec._Amount = rec._AmountBase = 0d; } if (lin >= 16) { var d = rec._Amount; if (d != 0) { if (lin <= 18) { if (d >= 0) { d += 0.499d; } else { d -= 0.499d; } } rec._Amount = Math.Round(d); } sum += rec._Amount; sumBase += rec._AmountBase; } else { var d = rec._Amount; if (d != 0) { if (d > 0) { d -= 0.499d; } else { d += 0.499d; } rec._Amount = Math.Round(d); } sum -= rec._Amount; sumBase -= rec._AmountBase; } switch (lin) { case 1: s = "Prestaties binnenland"; opr = "1"; opr = "1"; break; case 2: s = "Leveringen/diensten belast met hoog tarief"; opr = "1a"; break; case 3: s = "Leveringen/diensten belast met laag tarief"; opr = "1b"; break; case 4: s = "Leveringen/diensten belast met overige tarieven behalve 0%"; opr = "1c"; break; case 5: s = "Prive-gebruik"; opr = "1d"; break; case 6: s = "Leveringen/diensten belast met 0% of niet bij u belast"; opr = "1e"; break; case 7: s = "Verleggingsregelingen binnenland"; opr = "2"; break; case 8: s = "Leveringen/diensten waarbij de heffing van omzetbelasting naar u is verlegd."; opr = "2a"; break; case 9: s = "Prestaties naar/in het buitenland"; opr = "3"; break; case 10: s = "Leveringen naar landen buiten de EU (uitvoer)"; opr = "3a"; break; case 11: s = "Leveringen naar/diensten in landen binnen de EU"; opr = "3b"; break; case 12: s = "Installatie/afstandsverkopen binnen de EU"; opr = "3c"; break; case 13: s = "Prestaties uit het buitenland aan u verricht"; opr = "4"; break; case 14: s = "Leveringen/diensten uit landen buiten de EU"; opr = "4a"; break; case 15: s = "Leveringen/diensten uit landen binnen de EU"; opr = "4b"; break; case 16: s = "Voorbelasting, kleinondernemersregeling, schatting en eindtotaal"; opr = "5"; break; case 17: s = "Verschuldigde omzetbelasting"; rec._Amount = sum19 = -sum; opr = "5a"; break; case 18: s = "Voorbelasting"; opr = "5b"; sum19 -= rec._Amount; break; case 19: s = "Subtotal: bereken 5a min 5b."; sum = sum19; rec._Amount = sum; SumIsneg = (sum < 0d); opr = "5c"; break; case 20: s = "Vermindering volges de kleindondernemersregeling"; opr = "5d"; break; case 21: s = "Schatting vorige aangifte(n)"; opr = "5e"; break; case 22: s = "Schatting deze aangifte"; opr = "5f"; break; case 23: if (SumIsneg) { s = "Totaal te vorderen"; sum = -sum; } else { s = "Totaal te betalen"; } rec._Amount = sum; opr = "5g"; break; default: s = null; opr = null; break; } rec._Text = s; rec._UnicontaOperation = opr; } dgVatReportHolland.ItemsSource = lst; dgVatReportHolland.Visibility = Visibility.Visible; } }