git-svn-id: https://192.168.0.254/svn/Proyectos.Acana_FactuGES2/trunk@91 f4e31baf-9722-1c47-927c-6f952f962d4b
193 lines
5.3 KiB
ObjectPascal
193 lines
5.3 KiB
ObjectPascal
unit uBizFacturasClienteServer;
|
|
|
|
interface
|
|
|
|
uses
|
|
uDAInterfaces, uDADelta, uDABusinessProcessor,
|
|
schFacturasClienteServer_Intf;
|
|
|
|
const
|
|
BIZ_SERVER_FACTURAS_CLIENTE = 'Server.FacturasCliente';
|
|
|
|
type
|
|
TBizFacturasClienteServer = class(TFacturasClienteBusinessProcessorRules)
|
|
private
|
|
FReferenciaAutomatica : Boolean;
|
|
function DarReferencia : String;
|
|
function IncrementarReferencia : Boolean;
|
|
protected
|
|
procedure Insert_Asiento_Factura(aChange: TDADeltaChange); virtual;
|
|
procedure Update_Asiento_Factura(aChange: TDADeltaChange); virtual;
|
|
procedure Delete_Asiento_Factura(aChange: TDADeltaChange); virtual;
|
|
|
|
procedure BeforeProcessDelta(Sender: TDABusinessProcessor; const aDelta: IDADelta); override;
|
|
procedure AfterProcessChange(Sender: TDABusinessProcessor; aChange: TDADeltaChange; Processed: Boolean; var CanRemoveFromDelta: Boolean); override;
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
Variants, uDAClasses, uReferenciasUtils, uBusinessUtils, uROClasses, uDataModuleServer,
|
|
schFacturasClienteClient_Intf, srvReferencias_Impl;
|
|
|
|
const
|
|
REF_FACTURAS_CLIENTE = 'REF_FACTURAS_CLIENTE';
|
|
REF_ABONOS_CLIENTE = 'REF_ABONOS_CLIENTE';
|
|
CTE_TIPO_ABONO = 'A';
|
|
CTE_TIPO_FACTURA = 'F';
|
|
|
|
{ TBizFacturasClienteServer }
|
|
|
|
procedure TBizFacturasClienteServer.AfterProcessChange(Sender: TDABusinessProcessor; aChange: TDADeltaChange; Processed: Boolean;
|
|
var CanRemoveFromDelta: Boolean);
|
|
begin
|
|
case aChange.ChangeType of
|
|
ctInsert: begin
|
|
Insert_Asiento_Factura(aChange);
|
|
end;
|
|
ctUpdate: begin
|
|
Update_Asiento_Factura(aChange);
|
|
end;
|
|
ctDelete: begin
|
|
Delete_Asiento_Factura(aChange);
|
|
end;
|
|
end;
|
|
|
|
// No hay que quitar los deltas para que los datos del contacto se
|
|
// mantengan por si alguna tabla detalle lo necesita
|
|
// (por ejemplo, DireccionesContacto)
|
|
CanRemoveFromDelta := False;
|
|
|
|
// Actualizamos el contador de referencias.
|
|
case aChange.ChangeType of
|
|
ctInsert, ctUpdate: begin
|
|
if FReferenciaAutomatica then
|
|
begin
|
|
IncrementarReferencia;
|
|
FReferenciaAutomatica := False;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TBizFacturasClienteServer.BeforeProcessDelta(
|
|
Sender: TDABusinessProcessor; const aDelta: IDADelta);
|
|
begin
|
|
FReferenciaAutomatica := False;
|
|
|
|
case Sender.CurrentChange.ChangeType of
|
|
ctInsert, ctUpdate: begin
|
|
//Si la referencia no ha sido asignada le asignamos una nosotros
|
|
if REFERENCIAIsNull or (Length(REFERENCIA) = 0) then
|
|
begin
|
|
FReferenciaAutomatica := True;
|
|
REFERENCIA := DarReferencia;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TBizFacturasClienteServer.Delete_Asiento_Factura(aChange: TDADeltaChange);
|
|
var
|
|
ASchema : TDASchema;
|
|
ACurrentConn : IDAConnection;
|
|
ACommand : IDASQLCommand;
|
|
begin
|
|
ASchema := BusinessProcessor.Schema;
|
|
ACurrentConn := GetBusinessProcessorConnection(BusinessProcessor);
|
|
|
|
ACommand := ASchema.NewCommand(ACurrentConn, 'Delete_AsientoFactura');
|
|
try
|
|
with ACommand do
|
|
begin
|
|
ParamByName('IdFactura').Value := aChange.OldValueByName[fld_FacturasClienteID];
|
|
ParamByName('Tipo').Value := 'c';
|
|
Execute;
|
|
end;
|
|
finally
|
|
ACommand := NIL;
|
|
end;
|
|
end;
|
|
|
|
function TBizFacturasClienteServer.DarReferencia: String;
|
|
var
|
|
ATipo : String;
|
|
begin
|
|
if TIPO = CTE_TIPO_FACTURA then
|
|
ATipo := REF_FACTURAS_CLIENTE
|
|
else
|
|
ATipo := REF_ABONOS_CLIENTE;
|
|
|
|
with TsrvReferencias.Create(NIL) do
|
|
try
|
|
Result := DarNuevaReferencia(ATipo, ID_EMPRESA)
|
|
finally
|
|
Free;
|
|
end;
|
|
end;
|
|
|
|
function TBizFacturasClienteServer.IncrementarReferencia: Boolean;
|
|
var
|
|
ATipo : String;
|
|
begin
|
|
if TIPO = CTE_TIPO_FACTURA then
|
|
ATipo := REF_FACTURAS_CLIENTE
|
|
else
|
|
ATipo := REF_ABONOS_CLIENTE;
|
|
|
|
with TsrvReferencias.Create(NIL) do
|
|
try
|
|
Result := IncrementarValorReferencia(ATipo,
|
|
Self.REFERENCIA, ID_EMPRESA)
|
|
finally
|
|
Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TBizFacturasClienteServer.Insert_Asiento_Factura(aChange: TDADeltaChange);
|
|
var
|
|
ASchema : TDASchema;
|
|
ACurrentConn : IDAConnection;
|
|
ACommand : IDASQLCommand;
|
|
begin
|
|
ASchema := BusinessProcessor.Schema;
|
|
ACurrentConn := GetBusinessProcessorConnection(BusinessProcessor);
|
|
|
|
ACommand := ASchema.NewCommand(ACurrentConn, 'Insert_AsientoFactura');
|
|
try
|
|
with ACommand do
|
|
begin
|
|
ParamByName('IdFactura').Value := aChange.NewValueByName[fld_FacturasClienteID];
|
|
Execute;
|
|
end;
|
|
finally
|
|
ACommand := NIL;
|
|
end;
|
|
end;
|
|
|
|
procedure TBizFacturasClienteServer.Update_Asiento_Factura(aChange: TDADeltaChange);
|
|
var
|
|
ASchema : TDASchema;
|
|
ACurrentConn : IDAConnection;
|
|
ACommand : IDASQLCommand;
|
|
begin
|
|
ASchema := BusinessProcessor.Schema;
|
|
ACurrentConn := GetBusinessProcessorConnection(BusinessProcessor);
|
|
|
|
ACommand := ASchema.NewCommand(ACurrentConn, 'Insert_AsientoFactura');
|
|
try
|
|
with ACommand do
|
|
begin
|
|
ParamByName('IdFactura').Value := aChange.NewValueByName[fld_FacturasClienteID];
|
|
Execute;
|
|
end;
|
|
finally
|
|
ACommand := NIL;
|
|
end;
|
|
end;
|
|
|
|
initialization
|
|
RegisterBusinessProcessorRules(BIZ_SERVER_FACTURAS_CLIENTE, TBizFacturasClienteServer);
|
|
|
|
end.
|