} // End of the constructor #endregion #region Get methods /// <summary> /// Get vat specifications as a dictionary /// </summary> /// <param name="orderRows">A list of order rows</param> /// <param name="decimalMultiplier">A decimal multiplier</param> /// <returns>A dictionary with vat specifications</returns> public static Dictionary<decimal, VatSpecification> GetVatSpecifications(List<OrderRow> orderRows, Int32 decimalMultiplier) { // Create the dictionary to return Dictionary<decimal, VatSpecification> vatSpecificationDictionary = new Dictionary<decimal, VatSpecification>(10); // Loop the order rows and calculate the vat specification for (int i = 0; i < orderRows.Count; i++) { // Calculate the price and vat value decimal priceValue = Math.Round(orderRows[i].unit_price * orderRows[i].quantity * 100, MidpointRounding.AwayFromZero) / 100; decimal vatValue = priceValue * orderRows[i].vat_percent; // Check if the dicitionary contains the key if (vatSpecificationDictionary.ContainsKey(orderRows[i].vat_percent) == true) { // Get the vat specification VatSpecification vatSpecification = vatSpecificationDictionary[orderRows[i].vat_percent]; // Add to amounts vatSpecification.price_amount += priceValue; vatSpecification.vat_amount += vatValue; } else { // Create a new vat specification VatSpecification vatSpec = new VatSpecification(); // Add amounts vatSpec.price_amount = priceValue; vatSpec.vat_amount = vatValue; // Add the key and value to the dictionary vatSpecificationDictionary.Add(orderRows[i].vat_percent, vatSpec); } } // Round sums foreach(KeyValuePair<decimal, VatSpecification> entry in vatSpecificationDictionary) { // Get the vat specifiction VatSpecification vatSpec = entry.Value; // Round sums vatSpec.price_amount = Math.Round(vatSpec.price_amount * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier; vatSpec.vat_amount = Math.Round(vatSpec.vat_amount * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier; } // Return the dictionary return vatSpecificationDictionary; } // End of the GetVatSpecifications method
} // End of the constructor #endregion #region Get methods /// <summary> /// Get vat specifications as a dictionary /// </summary> /// <param name="orderRows">A list of order rows</param> /// <param name="decimalMultiplier">A decimal multiplier</param> /// <returns>A dictionary with vat specifications</returns> public static Dictionary <decimal, VatSpecification> GetVatSpecifications(List <OrderRow> orderRows, Int32 decimalMultiplier) { // Create the dictionary to return Dictionary <decimal, VatSpecification> vatSpecificationDictionary = new Dictionary <decimal, VatSpecification>(10); // Loop the order rows and calculate the vat specification for (int i = 0; i < orderRows.Count; i++) { // Calculate the price and vat value decimal priceValue = Math.Round(orderRows[i].unit_price * orderRows[i].quantity * 100, MidpointRounding.AwayFromZero) / 100; decimal vatValue = priceValue * orderRows[i].vat_percent; // Check if the dicitionary contains the key if (vatSpecificationDictionary.ContainsKey(orderRows[i].vat_percent) == true) { // Get the vat specification VatSpecification vatSpecification = vatSpecificationDictionary[orderRows[i].vat_percent]; // Add to amounts vatSpecification.price_amount += priceValue; vatSpecification.vat_amount += vatValue; } else { // Create a new vat specification VatSpecification vatSpec = new VatSpecification(); // Add amounts vatSpec.price_amount = priceValue; vatSpec.vat_amount = vatValue; // Add the key and value to the dictionary vatSpecificationDictionary.Add(orderRows[i].vat_percent, vatSpec); } } // Round sums foreach (KeyValuePair <decimal, VatSpecification> entry in vatSpecificationDictionary) { // Get the vat specifiction VatSpecification vatSpec = entry.Value; // Round sums vatSpec.price_amount = Math.Round(vatSpec.price_amount * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier; vatSpec.vat_amount = Math.Round(vatSpec.vat_amount * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier; } // Return the dictionary return(vatSpecificationDictionary); } // End of the GetVatSpecifications method
} // End of the GetEncoding method /// <summary> /// Get a vat specification from product rows /// </summary> public static IList<VatSpecification> GetVatSpecification(IList<ProductRow> rows) { // Create the list to return IList<VatSpecification> vat_specification = new List<VatSpecification>(); // Create a sorted dictionary SortedDictionary<decimal?, VatSpecification> vat_rows = new SortedDictionary<decimal?, VatSpecification>(); // Loop product rows foreach (ProductRow row in rows) { // Calculate sums decimal? row_sum = row.unit_price * row.quantity; decimal? vat_sum = row_sum * row.vat_rate; // Add the vat to the dictionary if (vat_rows.ContainsKey(row.vat_rate) == true) { VatSpecification vs = vat_rows[row.vat_rate]; vs.taxable_amount += row_sum; vs.tax_amount += vat_sum; } else { vat_rows.Add(row.vat_rate, new VatSpecification { tax_rate = row.vat_rate, taxable_amount = row.unit_price * row.quantity, tax_amount = row.unit_price * row.quantity * row.vat_rate }); } } // Add vat specifications to the list foreach(KeyValuePair<decimal?, VatSpecification> row in vat_rows) { vat_specification.Add(row.Value); } // Return the list return vat_specification; } // End of the GetVatSpecification method