Le code ci-dessous montre comment, dans la mécanique des documents liés-croisés, modifier la quantité du document opposé pour la rendre différente de celle du document d'origine. La situation est la suivante : le document d'origine est une commande client. Le document opposé est donc une préparation de commande fournisseur. Dans la table LIGNES_V, on a ajouté une colonne Q_RESERVE.
alter table LIGNES_V add Q_RESERVE float not null default 0
Le montant dans la préparation de commande fournisseur doit toujours être égal à Q de la commande client - Q_RESERVE. La modification par rapport au comportement standard de Mercator consiste donc à toujours déduire la valeur de Q_RESERVE définie dans la commande client.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorExtensions;
using MercatorUi;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Linq;
using MercatorUi.Engine.Gescom;
namespace Billing
{
public class Customizer : MercatorUi.ICustomizers.IBillingEngineCreated, MercatorUi.ICustomizers.IBillingEngineClosed
{
public void BillingEngineCreated(BillingEngine billingEngine)
{
billingEngine.EvaluatingQtyForLinkedDocLineUpdate += BillingEngine_EvaluatingQtyForLinkedDocLineUpdate;
billingEngine.HandlingLinkedDocLine += BillingEngine_HandlingLinkedDocLine;
}
public void BillingEngineClosed(BillingEngine billingEngine)
{
billingEngine.EvaluatingQtyForLinkedDocLineUpdate -= BillingEngine_EvaluatingQtyForLinkedDocLineUpdate;
billingEngine.HandlingLinkedDocLine -= BillingEngine_HandlingLinkedDocLine;
}
private void BillingEngine_EvaluatingQtyForLinkedDocLineUpdate(object sender, BillingEngine.EvaluatingQtyForLinkedDocLineUpdateEventArgs e)
{
if (e.LignesVRecord.Q_RESERVE.CompareTo(e.LignesVRecord2.Q_RESERVE, Globals.N_DEC_Q) != 0)
e.ShouldUpdateOppositeDocument = true;
}
private void BillingEngine_HandlingLinkedDocLine(object sender, BillingEngine.HandlingLinkedDocLineEventArgs e)
{
e.LignesARecordOpposite.Q = e.LignesVRecordSource.Q - e.LignesVRecordSource.Q_RESERVE;
}
}
}
La modification de la quantité en tant que telle est assurée par le code dans l'événement HandlingLinkedDocLine. L'événement EvaluatingQtyForLinkedDocLineUpdate sert à indiquer à Mercator que la valeur de Q_RESERVE a éventuellement été modifiée (colonne que Mercator ne connaît pas) et qu'en conséquence, la préparation de commande fournisseur doit être adaptée.