Vous consultez une page technique concernant le logiciel de gestion Mercator. Celle-ci contient des informations spécifiques destinées aux professionnels de Mercator. Souhaitez-vous être redirigés vers des informations plus générales ?


   Ne plus poser cette question

Dans une écriture de vente ou d'achat, disposer des 10 derniers comptes d'imputation utilisés pour ce client/fournisseur

0000002148     -      27/08/2017

Cette programmation permet, en saisie d'une écriture comptable de vente ou d'achat, d'obtenir la liste des précédents comptes généraux utilisés pour le client/fournisseur en cours. L'utilisateur peut dès lors sélectionner le compte dans la boîte de dialogue qui lui est présentée. La fonctionnalité est activée en appuyant sur la touche = dans la colonne du compte général.

Le code est constuit sur base d'un customizer SigGen implémentant l'interface MercatorUi.ICustomizers.ISigCreated et exploitant l'évènement BeforeSearch de la classe MercatorUi.Sig.Sig.

Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorUi;
using System.Windows.Forms;

namespace SigGen
{
    public class Customizer : MercatorUi.ICustomizers.ISigCreated
    {

        public void SigCreated(MercatorUi.Sig.Sig Sig)
        {
            Sig.BeforeSearch += Sig_BeforeSearch;
        }

        void Sig_BeforeSearch(object sender, MercatorUi.Sig.SigClasses.BeforeSearchEventArgs e)
        {
            Form form = MercatorUi.Globals.Main.WonTopForm();
            if ((form == null) || !(form is MercatorUi.Forms.Booking.BookingForm)) // on n'est pas dans un écran d'écriture comptable
                return;
            MercatorUi.Forms.Booking.BookingForm bookingForm = (MercatorUi.Forms.Booking.BookingForm)form;
            if (bookingForm.BookingEngine == null) // on est dans une écriture comptable mais en mode paramétrage
                return;
            if ((bookingForm.BookingEngine.Type != 1) && (bookingForm.BookingEngine.Type != 2)) // on n'est pas dans une écriture de vente ou d'achat
                return;
            if (e.Key != "=") // l'utilisateur n'a pas saisi = : donc il veut une recherche normale
                return;
            if ((bookingForm.BookingEngine.Type == 1) && bookingForm.BookingEngine.CLI == null) // le fournisseur n'est pas sélectionné
                return;
            if ((bookingForm.BookingEngine.Type == 2) && bookingForm.BookingEngine.FOU == null) // le fournisseur n'est pas sélectionné
                return;

            string reqSql = string.Format("create table #id_gen_tmp (id_gen char(10)) \r\n"
                                        + "insert into #id_gen_tmp \r\n"
                                        + "    exec {0}.dbo.SP_GET_LAST_BOOKINGS @id_tiers,@type_doc \r\n"
                                        + "select rtrim(g_id)+' '+g_nom as nom,g_id as id from #id_gen_tmp inner join gen on (id_gen COLLATE DATABASE_DEFAULT=g_id COLLATE DATABASE_DEFAULT) \r\n"
                                        + "drop table #id_gen_tmp \r\n"
                                        , MercatorUi.Globals.DatabaseName);
            MercatorUi.Sig.Sig sigGen = MercatorUi.Sig._SigsStatic.SigByModule(MercatorUi.Sig._SigEnum.GEN);
            string langue = Globals.Langue.ToString();
            if ((langue != Globals.Params["LANGUE_DEF"]) && sigGen.FieldList.ContainsKey("G_NOM" + langue))
                reqSql = reqSql.Replace("g_nom", string.Format("(case when g_nom{0} = '' then g_nom else g_nom{0} end)", langue.ToLower()));

            DataSet ds = Api.Zselect(MercatorUi.Globals.RepData, reqSql
                , new MercatorSqlParam("@id_tiers", (bookingForm.BookingEngine.Type == 1 ? bookingForm.BookingEngine.CliRecord.C_ID : bookingForm.BookingEngine.FouRecord.F_ID), SqlDbType.Char)
                , new MercatorSqlParam("@type_doc", bookingForm.BookingEngine.Type));
            if (ds == null) // cette requête SQL a provoqué une erreur -> on continue avec la recherche normale
                return;
            if (ds.Tables[0].Rows.Count == 0) // aucune ligne trouvée -> on continue avec la recherche normale
                return;

            Api.TrimEndDataTable(ds.Tables[0]);

            string id_gen_selected = MercatorUi.Dialogs.AskList(MercatorUi._Divers.Iif_langue(MercatorUi.Globals.Langue, "Previous bookings :", "Vorige boekingen :", "Imputations précédentes :"), "", ds.Tables[0]);
            if (string.IsNullOrEmpty(id_gen_selected)) // on a choisi "Annuler" -> on continue avec la recherche normale
                return;

            e.DesiredWhereClause = string.Format("g_id='{0}'", id_gen_selected);
        }
    }
}