private static void addTxsTotal(ref ds.TransactionsDataTable tdtTot, string sku, string label, decimal currencyTotal) { ds.TransactionsRow t1 = tdtTot.NewTransactionsRow(); t1.sku = sku; t1.amount = Decimal.Round(currencyTotal, 2); t1.currency = label; tdtTot.AddTransactionsRow(t1); }
private static void loadTransactionsFromWeb(out ds.TransactionsDataTable tdt, bool refreshFromWeb) { if (refreshFromWeb) { TableTools.GetTableFromWebAndStoreFile(txUri, currentTxFile); } DataTable txsRaw = TableTools.LoadTableFromFile(currentTxFile); tdt = new ds.TransactionsDataTable(); TableTools.SerializeTableAs(tdt, ref txsRaw); }
private static void cleanTxsConversion(string desiredCurrency, ref ds.TransactionsDataTable tdt) { foreach (var item in tdt) { if (string.IsNullOrEmpty(desiredCurrency)) { item.currency = item.currency.Replace(separator, null); } else { item.currency = desiredCurrency; } } }
private static DataTable convertTransactionsRates(string desiredCurrency, ref ds.TransactionsDataTable tdt, ref ds.RatesDataTable rdt, bool fillTotals) { ds.TransactionsDataTable tdtTot = new ds.TransactionsDataTable(); var distinctSku = tdt.SelectDistinctSKU(); bool conversionNeeded = !string.IsNullOrEmpty(desiredCurrency); foreach (var sku in distinctSku) { //transacciones de 1 sku IEnumerable <ds.TransactionsRow> txsBySKU = tdt.WhereSKU(sku); //distintos tipos de monedas (distintas a desiredCurrency) para ese sku string[] distinctCurrencies = txsBySKU.Select(o => o.currency).Distinct().ToArray(); //computar el total en el desiredCurrency foreach (string thisCurrency in distinctCurrencies) { //la tasa decimal rate = 1; if (conversionNeeded) { var r = rdt.First(thisCurrency, desiredCurrency); if (r != null) { rate = r.rate; } } decimal currencyTotal = 0; currencyTotal = convertAndGetTotalAmount(ref txsBySKU, rate, thisCurrency); if (fillTotals) { string label = string.Empty; label = thisCurrency + to + thisCurrency; if (conversionNeeded) { label = thisCurrency + to + desiredCurrency; } addTxsTotal(ref tdtTot, sku, label, currencyTotal); } } if (conversionNeeded) { decimal sum = tdtTot.Where(o => o.sku.CompareTo(sku) == 0).Sum(o => o.amount); string label = "TOTAL" + to + desiredCurrency; addTxsTotal(ref tdtTot, sku, label, sum); } } if (fillTotals) { tdtTot.AcceptChanges(); return(tdtTot); } else { cleanTxsConversion(desiredCurrency, ref tdt); tdt.AcceptChanges(); return(tdt); } }