U bevindt zich nu op een technische pagina over de software Mercator. Deze pagina bevat specifieke informatie die bestemd is voor professionals van de software Mercator. Wenst u naar algemenere informatie over Mercator door te gaan?


   Deze vraag niet meer stellen

Beheer van de geschenkbonnen in commercieel beheer

0000002199     -      16-04-2020

De code moet in een Billing-customizer geplaatst worden die gecreëerd werd vanuit de bijbehorende sequentie. Dit implementeert de volgende interfaces:

Maakt vooral gebruik van events van de BillingEngine van het huidige document;

  • AfterInsertItem
  • BeforePayment
  • AfterSave

De code wordt als volgt samengesteld:

Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Linq;
using MercatorApi;
using MercatorUi;

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

        public void BillingEngineClosed(MercatorUi.Engine.Gescom.BillingEngine BillingEngine)
        {
            BillingEngine.AfterInsertItem -= AfterInsertItem;
            BillingEngine.BeforePayment -= BeforePayment;
            BillingEngine.AfterSave -= AfterSave;
        }

        void AfterInsertItem(object sender, MercatorUi.Engine.Gescom.BillingEngine.AfterInsertItemEventArgs e)
        {
            MercatorUi.Engine.Gescom.BillingEngine billingEngine = (MercatorUi.Engine.Gescom.BillingEngine)sender;
            if (e.LignesVRecord.S_CLE1 == "UTILBONCAD")
            {
                string id_boncad = Dialogs.AskString("Gelieve de barcode te scannen", "", true, 35).Trim();
                if (id_boncad != "")
                {
                    int nbBoncad = billingEngine.LignesVRecords.Where(l => l.ID_BONCAD == id_boncad).Count();
                    if (nbBoncad == 0)
                    {
                        string reqSqlcad = "select count(*) as nbUtil, sum(q) as q, sum(pu) as pu from lignes_v where id_boncad=@id_boncad";
                        DataSet dscad = Api.Zselect(MercatorUi.Globals.RepData, reqSqlcad, new MercatorSqlParam("@id_boncad", id_boncad, SqlDbType.Char));
                        if (dscad != null)
                        {
                            if (Convert.ToInt16(dscad.Tables[0].Rows[0]["nbUtil"]) == 0)
                            {
                                Dialogs.Stop("Deze geschenkbon bestaat niet!");
                                e.CancelInsertItem = true;
                            }
                            else if (Convert.ToInt16(dscad.Tables[0].Rows[0]["nbUtil"]) > 1)
                            {
                                Dialogs.Stop("Deze geschenkbon werd al gebruikt!");
                                e.CancelInsertItem = true;
                            }
                            else
                            {
                                e.LignesVRecord.Q = Convert.ToDouble(dscad.Tables[0].Rows[0]["q"]) * -1;
                                e.LignesVRecord.PU = Convert.ToDouble(dscad.Tables[0].Rows[0]["pu"]);
                                e.LignesVRecord.ID_BONCAD = id_boncad;
                            }

                        }
                        else
                        {
                            e.CancelInsertItem = true;
                        }
                    }
                    else
                    {
                        Dialogs.Stop("Deze geschenkbon werd al gebruikt in deze verkoop!");
                        e.CancelInsertItem = true;
                    }
                }
                else
                {
                    Dialogs.Stop("Lege barcode !");
                    e.CancelInsertItem = true;
                }
            }
        }

        void BeforePayment(object sender, EventArgs e)
        {
            MercatorUi.Engine.Gescom.BillingEngine billingEngine = (MercatorUi.Engine.Gescom.BillingEngine)sender;
            billingEngine.LignesVRecords.Where(l => l.S_CLE1 == "BONCAD").ToList().ForEach(l => l.ID_BONCAD = billingEngine.PiedsVRecord.ID + l.DL_ID);
        }

        void AfterSave(object sender, EventArgs e)
        {
            MercatorUi.Engine.Gescom.BillingEngine billingEngine = (MercatorUi.Engine.Gescom.BillingEngine)sender;
            if (billingEngine.LignesVRecords.Where(l => l.S_CLE1 == "BONCAD").Count() != 0)
            {
                DataSet ds;
                foreach (DataRow drBC in billingEngine.LIGNES.Select("S_CLE1='BONCAD'"))
                {
                    ds = new DataSet();
                    DataTable dt_lignes = billingEngine.LIGNES.Clone();
                    dt_lignes.ImportRow(drBC);
                    DataTable dt_pieds = billingEngine.PIEDS.Table.Clone();
                    dt_pieds.ImportRow(billingEngine.PIEDS);
                    ds.Tables.Add(dt_lignes);
                    ds.Tables.Add(dt_pieds);
                    ds.Tables.Add(Api.DataTableFromDico(MercatorUi.Globals.ParamIdentif, "ParamIdentif"));

                    /* Edit Layout
                    //string reportFileName = Globals.MainDir + "BonCadeau.repx";
                    string reportFileName = @"<MainDir\BonCadeau.repx";
                    string reportLayout = MercatorUi.Reporting.ReportingStatic.Reporting.EditLayout(Api.JustStem(reportFileName), Api.FileToStr(reportFileName, Encoding.UTF8), ds);
                    Api.StrToFile(reportLayout, reportFileName, Encoding.UTF8);
                    */
                    List<MercatorUi.Reporting.OutputDescriptor> listOutputDescriptors = new List<MercatorUi.Reporting.OutputDescriptor>();
                    // Preview
                    //listOutputDescriptors.Add(new MercatorUi.Reporting.OutputDescriptorPreview ());
                    //
                    listOutputDescriptors.Add(new MercatorUi.Reporting.OutputDescriptorPrint());
                    //MercatorUi.Reporting.ReportingStatic.Reporting.RunReport("GeschenkBon", Globals.MainDir + "BonCadeau.repx", ds, listOutputDescriptors);
                    MercatorUi.Reporting.ReportingStatic.Reporting.RunReport("GeschenkBon", @"<MainDir\BonCadeau.repx", ds, listOutputDescriptors);
                }
            }
        }
    }
}

Het afdrukmodel is beschikbaar in het zipbestand.

 

Eerst moet men:

  • het veld lignes_v.id_boncad (alter table LIGNES_V add ID_BONCAD char(35) not null constraint DF_LIGNES_V_ID_BONCAD default '') toevoegen
  • Een SQL-index toevoegen op het veld (create index ID_BONCAD on dbo.LIGNES_V (ID_BONCAD))
  • Update het databaseschema via de Geavanceerde Tools
  • 2 artikels creëren (zonder voorraadbeheer) 
    • "Cadeaubon" (Sleutel1 = "BONCAD")
    • "Gebruik cadeaubon" (Sleutel 1 = "UTILBONCAD").

Waarschuwing, indien u de barcode van de voucher moet inkorten (billingEngine.PiedsVRecord.ID + l.DL_ID);), dan moet u de waarde van l.DL_ID behouden en niet billingEngine.PiedsVRecord.ID (dat kan identiek zijn aan meerdere vouchers).



Te laden : 0000002199.zip (2 Kb - 24-04-2013)