namespace Billing
{
    public class Customizer : MercatorUi.ICustomizers.IBillingEngineCreated, MercatorUi.ICustomizers.IBillingEngineClosed
    {
        public void BillingEngineCreated(MercatorUi.Engine.Gescom.BillingEngine billingEngine)
        {
            billingEngine.BeforeEinvoiceExport += BillingEngine_BeforeEinvoiceExport;
        }

        public void BillingEngineClosed(MercatorUi.Engine.Gescom.BillingEngine billingEngine)
        {
            billingEngine.BeforeEinvoiceExport -= BillingEngine_BeforeEinvoiceExport;
        }

        void BillingEngine_BeforeEinvoiceExport(object sender, MercatorUi.Engine.Gescom.BillingEngine.BeforeEinvoiceExportEventArgs e)
        {
            MercatorUi.Engine.Gescom.BillingEngine billingEngine = (MercatorUi.Engine.Gescom.BillingEngine)sender;
            if (string.IsNullOrWhiteSpace(e.Reference))
                e.Reference = billingEngine.PiedsVRecord.JOURNAL + " " + billingEngine.PiedsVRecord.PIECE;
        }
    }
}