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 tegoedbonnen in commercieel beheer Aruba

0000002200     -      06-09-2018

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;
using MercatorExtensions;

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 == "UTILBONVAL")
            {
                string id_bonval = Dialogs.AskString("Gelieve de barcode te scannen", "", true, 35).Trim();
                if (id_bonval != "")
                {
                    int nbBon = billingEngine.LignesVRecords.Where(l => l.ID_BONVAL == id_bonval).Count();
                    if (nbBon == 0)
                    {
                        string reqSql = "select count(*) as nbUtil, sum(q) as q, sum(pu) as pu from lignes_v where id_bonval=@id_bonval";
                        DataSet ds = Api.Zselect(MercatorUi.Globals.RepData, reqSql, new MercatorSqlParam("@id_bonval", id_bonval, SqlDbType.Char));
                        if (ds != null)
                        {
                            if (Convert.ToInt16(ds.Tables[0].Rows[0]["nbUtil"]) == 0)
                            {
                                Dialogs.Stop("Deze geschenkbon bestaat niet!");
                                e.CancelInsertItem = true;
                            }
                            else if (Convert.ToInt16(ds.Tables[0].Rows[0]["nbUtil"]) > 1)
                            {
                                Dialogs.Stop("Deze tegoedbon werd al gebruikt!");
                                e.CancelInsertItem = true;
                            }
                            else
                            {
                                e.LignesVRecord.Q = Convert.ToDouble(ds.Tables[0].Rows[0]["q"]) * -1;
                                e.LignesVRecord.PU = Convert.ToDouble(ds.Tables[0].Rows[0]["pu"]);
                                e.LignesVRecord.ID_BONVAL = id_bonval;
                            }
                        }
                        else
                        {
                            e.CancelInsertItem = true;
                        }
                    }
                    else
                    {
                        Dialogs.Stop("Deze tegoedbon 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;
            if (billingEngine.PiedsVRecord.TOT_TTC_FB.CompareTo(0, Globals.DEC_DEV_B) < 0)
            {
                string reqSql = "select * from stock (NOLOCK) where s_cle1 ='BONVAL'";
                DataSet dsStock = Api.Zselect(Globals.RepData, reqSql);
                if ((dsStock == null) || (dsStock.Tables[0].Rows.Count == 0))
                {
                    Dialogs.Stop("Artikel niet gevonden!");
                }
                else
                {
                    DataRow drStock = dsStock.Tables[0].Rows[0];
                    int nLigne = billingEngine.AppendLine();
                    if (nLigne < 0)
                    {
                        Dialogs.Stop("AppendLine BillingEngine : " + billingEngine.LastError + (Api.LastError == "" ? " - " + Api.LastError : ""));
                    }
                    else if (!billingEngine.InsertItem(drStock, billingEngine.LIGNES.Rows[nLigne]))
                    {
                        Dialogs.Stop("InsertItem BillingEngine : " + billingEngine.LastError + (Api.LastError == "" ? " - " + Api.LastError : ""));
                    }
                    else
                    {
                        billingEngine.LignesVRecords[nLigne].PU = Math.Abs(billingEngine.PiedsVRecord.TOT_TTC_FB);
                        billingEngine.LignesVRecords[nLigne].ID_BONVAL = billingEngine.PiedsVRecord.ID + billingEngine.LignesVRecords[nLigne].DL_ID;
                        billingEngine.UpdateAmounts();
                    }
                }
            }
        }

        void AfterSave(object sender, EventArgs e)
        {
            MercatorUi.Engine.Gescom.BillingEngine billingEngine = (MercatorUi.Engine.Gescom.BillingEngine)sender;
            if (billingEngine.LignesVRecords.Where(l => l.S_CLE1 == "BONVAL").Count() != 0)
            {
                DataSet ds = new DataSet();
                DataTable dt_lignes;
                DataTable dt_pieds;
                foreach (DataRow drBC in billingEngine.LIGNES.Select("S_CLE1='BONVAL'"))
                {
                    ds = new DataSet();
                    dt_lignes = new DataTable();
                    dt_lignes = billingEngine.LIGNES.Clone();
                    dt_lignes.ImportRow(drBC);
                    dt_pieds = new 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 + "BonValoir.repx";
                    string reportFileName = @"<MainDir\BonValoir.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("BonValoir", Globals.MainDir + "BonValoir.repx", ds, listOutputDescriptors);
                    MercatorUi.Reporting.ReportingStatic.Reporting.RunReport("TegoedBon", @"<MainDir\BonValoir.repx", ds, listOutputDescriptors);
                }
            }
        }
    }
}

Het afdrukmodel is beschikbaar in het zipbestand.

Eerst moet men:

  • het veld lignes_v.id_bonval (alter table LIGNES_V add ID_BONVAL char(35) not null constraint DF_LIGNES_V_ID_BONVAL default '') toevoegen
  • Een SQL-index toevoegen op het veld (create index ID_BONVAL on dbo.LIGNES_V (ID_BONVAL))
  • 2 artikels creëren (zonder voorraadbeheer)
    • "Tegoedbon" (sleutel 1 = "BONVAL")
    • "Gebruik tegoedbon" (sleutel 1 = "UTILBONVAL").

 



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