void BillingEngine_EinvNodeAdding(object sender, MercatorUi.Engine.Gescom.BillingEngine.EinvNodeAddingEventArgs e)
{
MercatorUi.Engine.Gescom.BillingEngine billingEngine = (MercatorUi.Engine.Gescom.BillingEngine)sender;
if (e.Node.Name == "cac:AccountingSupplierParty")
{
string dirSqlFiles = "<" + Api.SqlFilePathRoots.Files + "\\" + billingEngine.Journal + "\\" + billingEngine.Id + "\\";
string[] pdfs = Api.GetFiles(dirSqlFiles, "%.pdf");
if (pdfs.Length > 0)
{
ListViewItem[] selectedListViewItems = Dialogs.AskListEx("Joindre quel(s) fichier(s) PDF ?", new ColumnHeader[]
{
new ColumnHeader { Text = "", Width = 20 },
new ColumnHeader { Text = "Fichier", Width = 250 }
}, pdfs.Select(pdf => new ListViewItem(new string[] { "", Api.JustFName(pdf) })).ToArray(), showCheckBox: true, removeCancelButton: true);
byte[] pdfBytes = null;
if (selectedListViewItems?.Where(i => i.Checked).Count() == 1)
{
pdfBytes = Api.SqlFileToBytes(dirSqlFiles + selectedListViewItems.First(i => i.Checked).SubItems[1].Text);
}
else if (selectedListViewItems?.Where(i => i.Checked).Count() > 1)
{
List<byte[]> pdfBytesList = new List<byte[]>();
foreach (ListViewItem lvi in selectedListViewItems.Where(i => i.Checked))
{
pdfBytesList.Add(Api.SqlFileToBytes(dirSqlFiles + lvi.SubItems[1].Text));
}
pdfBytes = MercatorUi.Reporting.ReportingStatic.Reporting.MergePdfToBytes(pdfBytesList.Where(b => b != null).ToArray(), out string error);
if (!string.IsNullOrEmpty(error))
Dialogs.Stop("Fusion des PDF : " + error);
}
if (pdfBytes != null)
{
XmlNode n1 = billingEngine.EinvAddNode(e.eInvoiceEnum, e.ParentNode, "cac:AdditionalDocumentReference");
billingEngine.EinvAddNode(e.eInvoiceEnum, n1, "cbc:ID", "Annexes.pdf");
billingEngine.EinvAddNode(e.eInvoiceEnum, n1, "cbc:DocumentType", "Appendix");
XmlNode n2 = billingEngine.EinvAddNode(e.eInvoiceEnum, n1, "cac:Attachment");
billingEngine.EinvAddNode(e.eInvoiceEnum, n2, "cbc:EmbeddedDocumentBinaryObject", Convert.ToBase64String(pdfBytes), new MercatorUi.Engine.Gescom.Tools.EinvNodeAttribute("mimeCode", "application/pdf"), new MercatorUi.Engine.Gescom.Tools.EinvNodeAttribute("filename", "Annexes.pdf"));
}
}
}
}