static void Main(string[] args) { int convertedValue; int vatCode; decimal convertedDecimalValue; bool cycle = true; List <VatNumberNormal> vatsNormal = new List <VatNumberNormal>(); InitializeNormals(vatsNormal); List <VatNumberSimple> vatsSimple = new List <VatNumberSimple>(); InitializeSimples(vatsSimple); while (cycle) { TemporalValues temporalValues = new TemporalValues(); Console.Write("1.Add bill to VAT Number\n2.Add expense to VAT Number\n3.Calculate profit of VAT Number\n4.Show all VAT Numbers\n5.Exit\n"); convertedValue = CheckMenuNumber(); switch (convertedValue) { case 1: vatCode = VATcode(); temporalValues = CheckBothCodePosition(vatsNormal, vatsSimple, vatCode, temporalValues); if (temporalValues.TemporalPosition == -1) { Console.Write("The VAT number code doesn't exist.\n"); break; } convertedDecimalValue = InsertDecimalAmount(); if (temporalValues.VatType) { vatsNormal[temporalValues.TemporalPosition].Bills.Add(convertedDecimalValue); } if (temporalValues.VatType == false) { vatsSimple[temporalValues.TemporalPosition].Bills.Add(convertedDecimalValue); } break; case 2: vatCode = VATcode(); temporalValues = CheckBothCodePosition(vatsNormal, vatsSimple, vatCode, temporalValues); if (temporalValues.TemporalPosition == -1) { Console.Write("The VAT number code doesn't exist.\n"); break; } if (temporalValues.VatType == false) { Console.Write("The VAT number code is of a Simple type, reinsert a valid one.\n"); break; } convertedDecimalValue = InsertDecimalAmount(); vatsNormal[temporalValues.TemporalPosition].Expenses.Add(convertedDecimalValue); break; case 3: vatCode = VATcode(); temporalValues = CheckBothCodePosition(vatsNormal, vatsSimple, vatCode, temporalValues); if (temporalValues.TemporalPosition == -1) { Console.Write("The VAT number code doesn't exist."); break; } Console.Write(CalculateProfit(vatsNormal, vatsSimple, temporalValues)); break; case 4: WriteVATSList(vatsNormal, vatsSimple); break; case 5: cycle = false; break; } } Console.Read(); }
static TemporalValues CheckBothCodePosition(List <VatNumberNormal> vatsNormal, List <VatNumberSimple> vatsSimple, int vatCode, TemporalValues temporalValues) { for (int i = 0; i < vatsNormal.Count; i++) { if (vatCode == vatsNormal[i].CodeId) { temporalValues.TemporalPosition = i; temporalValues.VatType = true; return(temporalValues); } } for (int i = 0; i < vatsSimple.Count; i++) { if (vatCode == vatsSimple[i].CodeId) { temporalValues.TemporalPosition = i; temporalValues.VatType = false; return(temporalValues); } } temporalValues.TemporalPosition = -1; return(temporalValues); }
static string CalculateProfit(List <VatNumberNormal> vatsNormal, List <VatNumberSimple> vatsSimple, TemporalValues temporalValues) { decimal totalBill = 0; decimal expenseTotal = 0; decimal profit = 0; string returnProfit = ""; if (temporalValues.VatType) { for (int j = 0; j < vatsNormal[temporalValues.TemporalPosition].Bills.Count; j++) { totalBill = totalBill + vatsNormal[temporalValues.TemporalPosition].Bills[j]; expenseTotal = expenseTotal + vatsNormal[temporalValues.TemporalPosition].Expenses[j]; } profit = totalBill - expenseTotal; profit = profit - ((profit * 22) / 100) - ((profit * 23) / 100); returnProfit = $"The profit of this VAT number is: {profit} subtracted with 22% of IVA and 23% of IRPEF\n"; return(returnProfit); } if (temporalValues.VatType == false) { for (int j = 0; j < vatsSimple[temporalValues.TemporalPosition].Bills.Count; j++) { totalBill = totalBill + vatsSimple[temporalValues.TemporalPosition].Bills[j]; } totalBill = totalBill - ((totalBill * 22) / 100); totalBill = totalBill - ((totalBill * 15) / 100); returnProfit = $"The profit of this VAT number is: {totalBill}, with 78% of the original value due to IVA, subtracted with 15% of taxes\n"; return(returnProfit); } return(returnProfit); }