diff --git a/Kotlib.test/Kotlib_452.test.csproj b/Kotlib.test/Kotlib_452.test.csproj
index c65779a..22514c0 100644
--- a/Kotlib.test/Kotlib_452.test.csproj
+++ b/Kotlib.test/Kotlib_452.test.csproj
@@ -12,7 +12,7 @@
Properties
False
- v0.1-alpha.1
+ v0.1-alpha.3
x86
diff --git a/Kotlib.test/Program.cs b/Kotlib.test/Program.cs
index ca7e647..8f78a9d 100644
--- a/Kotlib.test/Program.cs
+++ b/Kotlib.test/Program.cs
@@ -277,16 +277,27 @@ public static void Main(string[] args)
Console.WriteLine();
Console.WriteLine("Exportation des mouvements de tous les éléments bancaires au format CSV:");
- var csvs = fi2.Accounts.Export2CSV(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fi2.Accounts.Select(a => a.Id).ToList(), DateTime.MinValue, DateTime.MaxValue);
+ var csvs = fi2.ToCSV(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fi2.Accounts.Select(a => a.Id).ToList(), DateTime.MinValue, DateTime.MaxValue);
foreach(var csv in csvs)
Console.WriteLine("- {0} : {1}", fi2.Accounts.GetById(csv.Item1).Name, csv.Item2);
Console.WriteLine();
Console.WriteLine("Exportation des mouvements de tous les éléments bancaires au format HTML:");
- var htmls = fi2.Export2Html(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fi2.Accounts.Select(a => a.Id).ToList(), DateTime.MinValue, DateTime.MaxValue);
+ var htmls = fi2.ToHtml(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fi2.Accounts.Select(a => a.Id).ToList(), DateTime.MinValue, DateTime.MaxValue);
foreach (KeyValuePair html in htmls)
Console.WriteLine("- {0} : {1}", fi2.Accounts.GetById(html.Key).Name, html.Value);
+ Console.WriteLine();
+ Console.WriteLine("Exportation des mouvements de tous les éléments bancaires au format OFX:");
+ var ofxs = fi2.ToOfx(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fi2.Accounts.Select(a => a.Id).ToList(), DateTime.MinValue, DateTime.MaxValue);
+ foreach (KeyValuePair ofx in ofxs)
+ Console.WriteLine("- {0} : {1}", fi2.Accounts.GetById(ofx.Key).Name, ofx.Value);
+
+ Console.WriteLine();
+ Console.WriteLine("Exportation des mouvements de tous les éléments bancaires au format QIF:");
+ var qif = fi2.ToQif(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fi2.Accounts.Select(a => a.Id).ToList(), DateTime.MinValue, DateTime.MaxValue);
+ Console.WriteLine("- {0}", qif);
+
Console.ReadLine();
}
diff --git a/Kotlib/Financial.cs b/Kotlib/Financial.cs
index f710dc8..b290c49 100644
--- a/Kotlib/Financial.cs
+++ b/Kotlib/Financial.cs
@@ -27,14 +27,16 @@
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
+using System.Security;
using System.Text;
-using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using Kotlib.Objects;
using Kotlib.Tools;
using System.Reflection;
+using System.Linq.Expressions;
+
namespace Kotlib
{
@@ -886,18 +888,136 @@ public Tuple GetEventsInfosAt(Guid accountID, DateTime st
}
///
- /// Exporte les mouvements des éléments bancaires souhaités entre les dates spécifiées.
+ /// Exporte les mouvements d'un élément bancaire au format CSV
///
///
- /// Liste des fichiers html résultants:
- /// - Key: Identifiant unique de l'élément bancaire
- /// - Value: Chemin du fichier HTML correspondant
+ /// Liste de structures comprenant chacune:
+ /// - Item 1: Identifiant unique de l'élément bancaire
+ /// - Item 2: Chemin du fichier CSV.
///
/// Chemin du répertoire recevant les fichiers CSV.
/// Liste d'identifiants uniques correspondant aux éléments bancaires à traiter.
/// Date de début des mouvements pris en compte.
/// Date de fin des mouvements pris en compte.
- public Dictionary Export2Html(string directory, List accountsId, DateTime startDate, DateTime endDate)
+ /// Délimiteur de colones CSV.
+ /// Délimiteur des décimales.
+ /// Format des dates enregistrées.
+ public List> ToCSV(string directory, List accountsId, DateTime startDate, DateTime endDate, string delimiter = ";", string decimalSeparator = ",", string dateFormat = "dd/MM/yyyy")
+ {
+ var d = directory.Trim().Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.Personal));
+ if (!Directory.Exists(d))
+ throw new DirectoryNotFoundException();
+
+ var filenames = new List>();
+
+ var columns = new string[] { "Date", "Débit", "Crédit", "Libellé" };
+ foreach (var uid in accountsId)
+ {
+ var a = Accounts.GetById(uid);
+ if (a == null || a.Equals(default(Account)))
+ continue;
+
+ var operations = a.Operations.Items
+ .Where(o => o.Active && o.Date.Date >= startDate.Date && o.Date.Date <= endDate.Date)
+ .Select(o => new Dictionary()
+ {
+ ["Sorter"] = o.Date.Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture),
+ [columns[0]] = o.Date.Date.ToString(dateFormat),
+ [columns[1]] = (o.Amount < 0m) ? Math.Round(o.Amount, 2).ToString("0.00").Replace(".", decimalSeparator) : "0.00",
+ [columns[2]] = (o.Amount >= 0m) ? Math.Round(o.Amount, 2).ToString("0.00").Replace(".", decimalSeparator) : "0.00",
+ [columns[3]] = o.Name
+ })
+ .ToList();
+
+ var transfersOut = Accounts.Transfers.Items
+ .Where(t => t.Active && t.FromAccountId.Equals(a.Id) && t.Date.Date >= startDate.Date && t.Date.Date <= endDate.Date)
+ .Select(t => new Dictionary()
+ {
+ ["Sorter"] = t.Date.Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture),
+ [columns[0]] = t.Date.Date.ToString(dateFormat),
+ [columns[1]] = "-" + Math.Round(Math.Abs(t.Amount), 2).ToString("0.00").Replace(".", decimalSeparator),
+ [columns[2]] = "0.00",
+ [columns[3]] = t.Name
+ })
+ .ToList();
+
+ var transfersIn = Accounts.Transfers.Items
+ .Where(t => t.Active && t.ToAccountId.Equals(a.Id) && t.Date.Date >= startDate.Date && t.Date.Date <= endDate.Date)
+ .Select(t => new Dictionary()
+ {
+ ["Sorter"] = t.Date.Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture),
+ [columns[0]] = t.Date.Date.ToString(dateFormat),
+ [columns[1]] = "0.00",
+ [columns[2]] = Math.Round(Math.Abs(t.Amount), 2).ToString("0.00").Replace(".", decimalSeparator),
+ [columns[3]] = t.Name
+ })
+ .ToList();
+
+ var mvts = new List>();
+ mvts.AddRange(operations);
+ mvts.AddRange(transfersIn);
+ mvts.AddRange(transfersOut);
+
+ mvts.Sort((mvt1, mvt2) =>
+ {
+ var d1 = DateTime.ParseExact(mvt1["Sorter"], "yyyy-MM-dd", CultureInfo.InvariantCulture);
+ var d2 = DateTime.ParseExact(mvt2["Sorter"], "yyyy-MM-dd", CultureInfo.InvariantCulture);
+
+ if (d2 > d1)
+ return -1;
+
+ if (d2 < d1)
+ return 1;
+
+ return 0;
+ });
+
+ var lines = new List() { string.Join(delimiter, columns.ToArray()) };
+ foreach (var m in mvts)
+ {
+ var lColumns = new List();
+ foreach (var c in columns)
+ {
+ if (m.Keys.Contains(c))
+ lColumns.Add(m[c]);
+ else
+ lColumns.Add("");
+ }
+ lines.Add(string.Join(delimiter, lColumns.ToArray()));
+ }
+
+ var filename = String.Join("_", a.Name.Split(Path.GetInvalidFileNameChars(), StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
+
+ var fp = Path.Combine(d, filename) + ".csv";
+ fp = Path.GetFullPath(fp);
+
+ using (StreamWriter sw = new StreamWriter(File.Open(fp, FileMode.Create), Encoding.UTF8))
+ {
+ foreach (var line in lines)
+ sw.WriteLine(line);
+ }
+ lines.Clear();
+
+ filenames.Add(new Tuple(a.Id, fp));
+ }
+
+ return filenames;
+ }
+
+ ///
+ /// Exporte les mouvements des éléments bancaires souhaités entre les dates spécifiées.
+ ///
+ ///
+ /// Liste des fichiers HTML résultants:
+ /// - Key: Identifiant unique de l'élément bancaire
+ /// - Value: Chemin du fichier HTML correspondant
+ ///
+ /// Chemin du répertoire recevant les fichiers HTML.
+ /// Liste d'identifiants uniques correspondant aux éléments bancaires à traiter.
+ /// Date de début des mouvements pris en compte.
+ /// Date de fin des mouvements pris en compte.
+ /// true, retourne le contenu HTML sans crééer de fichier HTML, sinon, false
+ public Dictionary ToHtml(string directory, List accountsId, DateTime startDate, DateTime endDate, bool contentReturns = false)
{
var d = directory.Trim().Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.Personal));
if (!Directory.Exists(d))
@@ -905,7 +1025,7 @@ public Dictionary Export2Html(string directory, List account
var filenames = new Dictionary();
- var lst = Accounts.Export2List(directory, accountsId, startDate, endDate);
+ var lst = Accounts.GetAccountStatements(directory, accountsId, startDate, endDate);
foreach (KeyValuePair>> kvp in lst)
{
@@ -924,7 +1044,7 @@ public Dictionary Export2Html(string directory, List account
{4} |
{5} |
{6} |
- ",
+ ",
CultureName, a.Name, "Dénomination", "Note", "Type", "Débit", "Crédit");
var mvts = kvp.Value.OrderByDescending(i => i.Key);
@@ -935,7 +1055,7 @@ public Dictionary Export2Html(string directory, List account
html += string.Format(@"
{0} |
{1} {2} |
-
",
+ ",
kvp2.Key.ToLongDateString(), "solde:", Currency.Format(amount), (amount < 0m ? "red" : "black"));
foreach (var ot in kvp2.Value)
@@ -976,11 +1096,178 @@ public Dictionary Export2Html(string directory, List account
}
}
- html += string.Format(@"{0} {1}