static public Dictionary <string, VATNumberSimple> CreateSimpleMock() { /* Creazione e pre_popolamento dizionari di P_IVA (simple), per lungo. */ Dictionary <string, VATNumberSimple> dicVATSimple = new Dictionary <string, VATNumberSimple>(); #region Creazione ed aggiunta P_IVA VATNumberSimple vAT_S1 = new VATNumberSimple(); vAT_S1.Bills = new List <decimal>(); vAT_S1.VATCode = "222222"; dicVATSimple.Add(vAT_S1.VATCode, vAT_S1); VATNumberSimple vAT_S2 = new VATNumberSimple(); vAT_S2.Bills = new List <decimal>(); vAT_S2.VATCode = "333333"; dicVATSimple.Add(vAT_S2.VATCode, vAT_S2); VATNumberSimple vAT_S3 = new VATNumberSimple(); vAT_S3.Bills = new List <decimal>(); vAT_S3.VATCode = "741000"; dicVATSimple.Add(vAT_S3.VATCode, vAT_S3); VATNumberSimple vAT_S4 = new VATNumberSimple(); vAT_S4.Bills = new List <decimal>(); vAT_S4.VATCode = "111111"; dicVATSimple.Add(vAT_S4.VATCode, vAT_S4); #endregion #region Aggiunte di Bills /* Creazione ed aggiunta per lungo, senza "scorciatoie". */ decimal[] bills_S1 = { 1111.11m, 2222.22m, 3333.33m, 4444.44m }; vAT_S1.Bills.Add(bills_S1[0]); vAT_S1.Bills.Add(bills_S1[1]); vAT_S1.Bills.Add(bills_S1[2]); vAT_S1.Bills.Add(bills_S1[3]); decimal[] bills_S2 = { 1111.11m, 2222.22m, 3333.33m, 4444.44m }; vAT_S2.Bills.Add(bills_S2[0]); vAT_S2.Bills.Add(bills_S2[1]); vAT_S2.Bills.Add(bills_S2[2]); vAT_S2.Bills.Add(bills_S2[3]); decimal[] bills_S3 = { 1111.11m, 2222.22m, 3333.33m, 4444.44m }; vAT_S3.Bills.Add(bills_S3[0]); vAT_S3.Bills.Add(bills_S3[1]); vAT_S3.Bills.Add(bills_S3[2]); vAT_S3.Bills.Add(bills_S3[3]); decimal[] bills_S4 = { 1111.11m, 2222.22m, 3333.33m, 4444.44m }; vAT_S4.Bills.Add(bills_S4[0]); vAT_S4.Bills.Add(bills_S4[1]); vAT_S4.Bills.Add(bills_S4[2]); vAT_S4.Bills.Add(bills_S4[3]); #endregion /* I "simple" non hanno Expenses. */ return(dicVATSimple); }
static void CalculateTaxesOfA_VATNr(Dictionary <string, VATNumberNormal> normals, Dictionary <string, VATNumberSimple> simples) { #region Const Tax values const decimal VAT_PERCENTAGE = 22m; // IVA 22% const decimal INCOME_TAX = 23m; // IRPEF 38% const decimal SIMPLE_TAXABLE_PERCENTAGE = 78m; // [% d'importo tassabile se P.IVA"semplice", 78%] const decimal SIMPLE_TAX_PERCENTAGE = 15m; // [% aliquota se P.IVA"semplice"?, 78%] #endregion Console.Write("Enter a VAT number: "); string inputCode = Console.ReadLine(); // LOOK IN NORMALS VATNumberNormal selectedNormal = null; foreach (string vATKey in normals.Keys) { if (normals[vATKey].VATCode == inputCode) { selectedNormal = normals[vATKey]; break; } } // FOUND A NORMAL VAT if (selectedNormal != null) { decimal billTotal = 0M; foreach (decimal bill in selectedNormal.Bills) { billTotal += bill; } decimal expenseTotal = 0M; foreach (decimal expense in selectedNormal.Expenses) { expenseTotal += expense; } decimal profit = billTotal - expenseTotal; if (profit > 0) { decimal VATAmount = profit * VAT_PERCENTAGE / 100; decimal profitWithoutVAT = profit - VATAmount; decimal incomeTaxAmount = profitWithoutVAT * INCOME_TAX / 100; decimal net = profitWithoutVAT - incomeTaxAmount; decimal taxTotal = VATAmount + incomeTaxAmount; Console.WriteLine($"Total net gain: {net}; total taxes: {taxTotal}"); } else { Console.WriteLine("Profit: {profit}; total taxes: 0"); } } // LOOK FOR A SIMPLE VAT else { // LOOK INTO SIMPLES VATNumberSimple selectedSimple = null; foreach (string vatKey in simples.Keys) { if (simples[vatKey].VATCode == inputCode) { selectedSimple = simples[vatKey]; break; } } // FOUND A SIMPLE VAT if (selectedSimple != null) { decimal billTotal = 0M; foreach (decimal bill in selectedSimple.Bills) { billTotal += bill; } decimal profit = billTotal; if (profit > 0) { decimal taxable = profit * SIMPLE_TAXABLE_PERCENTAGE / 100; decimal taxes = taxable * SIMPLE_TAX_PERCENTAGE / 100; decimal net = profit - taxes; Console.WriteLine($"Net gain: {net}; total taxation: {taxes}"); } else { Console.WriteLine($"Profit: {profit}"); } } // VAT NUMBER NOT FOUND else { Console.WriteLine("The entered VAT number does not exist!"); } } }
static void AddExpenseToAVATNr(Dictionary <string, VATNumberNormal> normals, Dictionary <string, VATNumberSimple> simples) { #region ConstStrings const string STR_NAN = "Il dato immesso NON è un numero."; const string STR_NOT_POSITIVE = "Il numero immesso NON è positivo."; const string STR_NOT_A_VAT_NR = "Il numero immesso NON corrisponde ad una P.IVA salvata."; const string STR_IS_A_VAT_NR = "P.IVA presente."; const string IMPORT_IS_NEGATIVE = "L\'importo immesso è negativo."; const string INVITE_BILL = "Immettere l\'importo della fattura d\'aggiungere: \a"; const string STR_ERR_BILL = "Valore immesso non valido."; #endregion Console.Write("Immettere il numero della P.IVA."); string inputCode = Console.ReadLine(); // LOOK IN NORMALS VATNumberNormal selectedNormal = null; foreach (string vATKey in normals.Keys) { if (normals[vATKey].VATCode == inputCode) { selectedNormal = normals[vATKey]; break; } } // FOUND A NORMAL VAT if (selectedNormal != null) { Console.Write("Enter the value of the expense: "); decimal newExpense; while (true) { if (decimal.TryParse(Console.ReadLine(), out newExpense)) { break; } Console.Write("Invalid value. Re-enter: "); } selectedNormal.Expenses.Add(newExpense); } // LOOK FOR A SIMPLE VAT else { // LOOK INTO SIMPLES VATNumberSimple selectedSimple = null; foreach (string vATKey in simples.Keys) { if (simples[vATKey].VATCode == inputCode) { selectedSimple = simples[vATKey]; break; } } // FOUND A SIMPLE VAT if (selectedSimple != null) { Console.WriteLine("The selected VAT number is of type 'simple' and does not allow expenses"); } // VAT NUMBER NOT FOUND else { Console.WriteLine("The entered VAT number does not exist!"); } } // break; }
static void AddBillToA_VATNr(Dictionary <string, VATNumberNormal> normals, Dictionary <string, VATNumberSimple> simples) { #region ConstStrings const string STR_NAN = "Il dato immesso NON è un numero."; const string STR_NOT_POSITIVE = "Il numero immesso NON è positivo."; const string STR_NOT_A_VAT_NR = "Il numero immesso NON corrisponde ad una P.IVA salvata."; const string STR_IS_A_VAT_NR = "P.IVA presente."; const string IMPORT_IS_NEGATIVE = "L\'importo immesso è negativo."; const string INVITE_BILL = "Immettere l\'importo della fattura d\'aggiungere: \a"; const string STR_ERR_BILL = "Valore immesso non valido."; #endregion Console.Write("Enter a VAT number: "); string inputCode = Console.ReadLine(); /* Cerca nelle P.IVA "normali". */ /* Creazione d'un oggetto VATNumberNormal vuoto/null. */ VATNumberNormal selectedNormal = null; foreach (string vATKey in normals.Keys) { if (normals[vATKey].VATCode == inputCode) { /* Se esiste una P.IVA corrispondente di tipo "normale", * viene "riempito" l'oggetto « selectedNormal » con la corrispettiva P.IVA * (altrimenti l'oggetto resta vuoto/null). */ selectedNormal = normals[vATKey]; break; } } /* Trovata una P.IVA "normale" (l'oggetto « selectedNormal » è stato "riempito" quindi non è più vuoto/null). */ if (selectedNormal != null) { Console.Write(INVITE_BILL); decimal newBill; while (true) { if (decimal.TryParse(Console.ReadLine(), out newBill)) { break; } Console.WriteLine(STR_ERR_BILL); } selectedNormal.Bills.Add(newBill); } /* Cerca nelle P.IVA "semplici" (se non è una P.IVA "normale" ...). */ else { /* Creazione d'un oggetto VATNumberNormal vuoto/null. */ VATNumberSimple selectedSimple = null; foreach (string vATKey in simples.Keys) { if (simples[vATKey].VATCode == inputCode) { selectedSimple = simples[vATKey]; break; } } /* Trovata una P.IVA "normale" (l'oggetto « selectedSimple » è stato "riempito" quindi non è più vuoto/null). */ if (selectedSimple != null) { Console.Write(INVITE_BILL); decimal newBill; while (true) { if (decimal.TryParse(Console.ReadLine(), out newBill)) { break; } Console.WriteLine(STR_ERR_BILL); Console.Write(INVITE_BILL); } selectedSimple.Bills.Add(newBill); } /* P.IVA non trovata. */ else { Console.WriteLine(STR_NOT_A_VAT_NR); } } //break; return; }
static VATNumberSimple SearchVATNrSimple(Dictionary <string, VATNumberSimple> simples) { VATNumberSimple foundVATSimple = new VATNumberSimple(); return(foundVATSimple); }