public static void GenerateInvoiceForSubscription(Subscription subscription, FirmInstitution firm, string pDirectory, string pLogoPath, out string pFactName, DateTime? dateUpdated = null)
        {
            FoxitPDFGenerator pdfGen = new FoxitPDFGenerator();
            pdfGen.AddImage(pLogoPath, 0, 10);
            string sdateUpdated = dateUpdated.HasValue ? dateUpdated.Value.ToShortDateString() : subscription.IsPaid ? DateTime.Now.ToShortDateString() : string.Empty;

            if (!string.IsNullOrEmpty(sdateUpdated))
                pdfGen.AddLabelArial(string.Format(LanguageContentBL.Translate("PdfBill_001"), sdateUpdated), 400, 30, 150, 12);
            //pdfGen.AddLabelArialBold("UPSIDEO\n", 400, 30, 150, 12);
            //pdfGen.AddLabelArial("89 Boulevard Malesherbes\n75008 PARIS\nFRANCE\[email protected]", 400, 40, 150, 100);

            Dictionary<int, string[]> dataFacturation = new Dictionary<int, string[]>();
            string[] columnsFacturation = { LanguageContentBL.Translate("PdfBill_002") };
            StringBuilder sbAdresse = new StringBuilder();
            sbAdresse.Append(string.Format("\n{0}\n", firm.FirmInstitutionName));
            sbAdresse.Append(string.Format("{0}\n", firm.FirmStreet));
            sbAdresse.Append(string.Format("{0} {1}\n", firm.FirmPostCode, firm.FirmCity));

            int i = 0;
            string[] adresseLine = { sbAdresse.ToString() };
            dataFacturation.Add(i++, adresseLine);

            pdfGen.AddTable1(columnsFacturation, dataFacturation, 0, 200, 500, 300, 11, false);

            // Generation du tableau de la facture
            // Entete 1
            string[] ColumnsEntete = { string.Format(LanguageContentBL.Translate("PdfBill_003"), subscription.DateCreated.ToString("ddMMyyyy"), subscription.IdSubscription), string.Format(LanguageContentBL.Translate("PdfBill_004"), DateTime.Now.ToShortDateString()) };
            pdfGen.AddEnteteTable(ColumnsEntete, 0, 325, 510, 20, 11);

            //Entete 2
            i = 0;
            string[] columns = { LanguageContentBL.Translate("PdfBill_005"), LanguageContentBL.Translate("PdfBill_006"), LanguageContentBL.Translate("PdfBill_007"), LanguageContentBL.Translate("PdfBill_008") };

            Dictionary<int, string[]> data = new Dictionary<int, string[]>();

            //TODO
            string licenseInvoiceLineLabel = string.Empty;

            //Display license : autre que renouvellement renouvellement
            if (subscription.UserCount > 0)
            {
                string applicationName = (!string.IsNullOrEmpty(subscription.Application)) ? subscription.Application : string.Empty;
                licenseInvoiceLineLabel = string.Format(LanguageContentBL.Translate("PdfBill_009"), subscription.UserCount, applicationName, subscription.Duration.Value, subscription.Duration.Value == 1 ? LanguageContentBL.Translate("PdfBill_011_1") : LanguageContentBL.Translate("PdfBill_011_2"));

                string[] applicationLine = { licenseInvoiceLineLabel
                                             , subscription.UserCount.ToString()
                                             , string.Format(LanguageContentBL.Translate("PdfBill_010"), (subscription.ApplicationCost / (decimal)subscription.UserCount))
                                             , string.Format(LanguageContentBL.Translate("PdfBill_010"),subscription.ApplicationCost)};

                data.Add(i++, applicationLine);
            }

            //Display license : Cas renouvellement
            if (subscription.Product.Contains(SouscriptionBL.Product_Type_renouvellement))
            {
                IList<Data.Model.License> licencesToRenew = SouscriptionBL.GetLicensesToRenewByIdSubscription(subscription.IdSubscription);
                subscription.LicensesToRenew = licencesToRenew.ToList();

                //Cas superadmin
                if (subscription.LicensesToRenewGroupedByApplicationType == null)
                {
                    subscription = SouscriptionBL.GroupLicencesToRenewByApplicationType(subscription);
                }

                foreach (var lic in subscription.LicensesToRenewGroupedByApplicationType)
                {
                    int licensesCount = lic.Licences.Count;

                    if (licensesCount > 0)
                    {
                        //licenseInvoiceLineLabel = string.Format("{0} licence(s) {1}", lic.Licences.Count, lic.ApplicationType);
                        licenseInvoiceLineLabel = string.Format(LanguageContentBL.Translate("PdfBill_009"), lic.Licences.Count, lic.ApplicationType, subscription.Duration.Value, subscription.Duration.Value == 1 ? LanguageContentBL.Translate("PdfBill_011_1") : LanguageContentBL.Translate("PdfBill_011_2"));

                        decimal? applicationCost = 0;
                        if (lic.ApplicationType == SouscriptionBL.ReportLabApplication.ToString())
                        {
                            applicationCost = subscription.RenewReportLabCost;
                        }
                        else if (lic.ApplicationType == SouscriptionBL.ReportApplication.ToString())
                        {
                            applicationCost = subscription.RenewReportCost;
                        }
                        else if (lic.ApplicationType == SouscriptionBL.LabApplication.ToString())
                        {
                            applicationCost = subscription.RenewLabCost;
                        }

                        if (applicationCost.HasValue && applicationCost.Value > 0)
                        {
                            //appilcationCost = applicationCost :)
                        }
                        else
                        {
                            applicationCost = lic.AmountHT;
                        }

                        string[] applicationLine = { licenseInvoiceLineLabel
                                                     , licensesCount.ToString()
                                                     , string.Format(LanguageContentBL.Translate("PdfBill_010"), (applicationCost.Value / (decimal)licensesCount))
                                                     , string.Format(LanguageContentBL.Translate("PdfBill_010"), applicationCost.Value)};

                        data.Add(i++, applicationLine);
                    }
                }

            }

            #region Reduction parrainage
            //Display reduction
            //if (!string.IsNullOrEmpty(subscription.SponsorshipCode))
            if (!string.IsNullOrEmpty(subscription.SponsorshipCode) || subscription.Reduction > 0)
            {
                string remiseLabel = (subscription.ReductionPercent > 0) ? string.Format(LanguageContentBL.Translate("PdfBill_011"), subscription.ReductionPercent) : LanguageContentBL.Translate("PdfBill_011_0");
                string[] applicationLine = { remiseLabel
                                                 , ""
                                                 , ""
                                                 , string.Format("- "+LanguageContentBL.Translate("PdfBill_010"), subscription.Reduction)};
                data.Add(i++, applicationLine);
            }
            #endregion

            #region Credit
            //Display credit
            if (subscription.CreditNumber > 0)
            {
                string[] creditLine = { string.Format(LanguageContentBL.Translate("PdfBill_012"), subscription.CreditNumber),
                                                subscription.CreditNumber.ToString(),
                                                string.Empty,
                                                string.Format(LanguageContentBL.Translate("PdfBill_010"),subscription.CreditCost)};
                data.Add(i++, creditLine);
            }
            #endregion

            #region Sponsor
            //Display sponsoring²
            if (subscription.IdSponsor.HasValue)
            {
                Sponsor spons = SponsorBL.GetById(subscription.IdSponsor.Value);
                string[] sponsorLine = { string.Format(LanguageContentBL.Translate("PdfBill_sponsor_1"), spons.Name)
                                           , ""
                                           , ""
                                           , string.Format("- "+LanguageContentBL.Translate("PdfBill_010"), subscription.SponsorAmount)};
                data.Add(i++, sponsorLine);
            }
            #endregion

            string[] EmptyLines = { "", "", "", "" };
            data.Add(i++, EmptyLines);

            pdfGen.AddTable2(columns, data, 0, 345, 510, 300, 9, false);

            i = 0;
            Dictionary<int, string[]> AmountData = new Dictionary<int, string[]>();
            string[] htLine = { LanguageContentBL.Translate("PdfBill_008"), string.Format(LanguageContentBL.Translate("PdfBill_010"), subscription.AmountHT) };
            AmountData.Add(i++, htLine);
         
            if (subscription.AmountHT != subscription.TotalAmount)
            {
                decimal taux = ConfigurationManager.ExtranetHostCode == Upsilab.Business.Language.LanguageContentBL.HostCode.FR.ToString() ? ConfigurationManager.TauxTVA : ConfigurationManager.TauxTVABe;
                string[] TauxTvaLine = { LanguageContentBL.Translate("PdfBill_013"), string.Format("{0}%", taux) };
                AmountData.Add(i++, TauxTvaLine);
                string[] TvaLine = { LanguageContentBL.Translate("PdfBill_014"), string.Format(LanguageContentBL.Translate("PdfBill_010"), (subscription.TotalAmount - subscription.AmountHT)) };
                AmountData.Add(i++, TvaLine);
                string[] TTCLine = { LanguageContentBL.Translate("PdfBill_015"), string.Format(LanguageContentBL.Translate("PdfBill_010"), subscription.TotalAmount) };
                AmountData.Add(i++, TTCLine);
            }

            pdfGen.AddTable3(AmountData, 350, 460, 160, 300, 10, false);

            string[] Columns = { "UPSIDEO\n89 Boulevard Malesherbes 75008 PARIS\nTel : 01.44.69.59.80 / Fax : 01.43.87.20.45 \nN° R.C.S. PARIS 538 768 003 " };
            pdfGen.AddTable(null, Columns, -30, 650, 10, 60, false, true, false, 200);


            pFactName = string.Format("FA_{0}_{1}.pdf", subscription.DateCreated.ToString("ddMMyyyy"), subscription.IdSubscription);

            if (!Directory.Exists(pDirectory))
            {
                Directory.CreateDirectory(pDirectory);
            }

            string pathFileName = System.IO.Path.Combine(pDirectory, pFactName);

            if (File.Exists(pathFileName))
            {
                pFactName = string.Format("FA_{0}_{1}_2.pdf", subscription.DateCreated.ToString("ddMMyyyy"), subscription.IdSubscription);
            }

            pdfGen.GeneratePdf(System.IO.Path.Combine(pDirectory, pFactName));

        }