save method
save a book.
Implementation
void save({Book? book, KontoPlan? kpl, Journal? jrl, FibuSettings? conf}) {
if (book == null) book = Book();
if (kpl != null) book.kpl = kpl;
if (jrl != null) book.jrl = jrl;
if (conf != null) settings = conf;
///Save the operations
List<List<dynamic>> fibuAsList = book.kpl.asList();
fibuAsList = book.jrl.asList(fibuAsList);
fibuAsList.add(["OPS"]);
fibuAsList.add([
"tag",
"date",
"compte_accredite",
"compte_retrait",
"description",
"monnaie",
"montant",
"modif"
]);
book.ops.forEach((key, val) => (val as Operation).asList(fibuAsList));
final res = const ListToCsvConverter().convert(fibuAsList);
//print("retrieved list\n$fibuAsList\n");
//print("retrieved csv\n$res\n");
//print("check settings output = ${settings['output']}");
String fname =
((settings["output"]) != null && (settings["output"].isNotEmpty))
? settings["output"] + ".csv"
: settings["base"] + ".csv";
//print("created fname = $fname");
File(fname).writeAsString(res).then((file) {
print("write seems successful, please check $fname");
});
}