This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
LuisLeon_FactuGES2/Source/Modulos/Facturas proforma/Model/uBizFacturasProformaServer.pas

142 lines
4.1 KiB
ObjectPascal

unit uBizFacturasProformaServer;
interface
uses
uDAInterfaces, uDADelta, uDABusinessProcessor,
schFacturasProformaServer_Intf;
const
BIZ_SERVER_FACTURAS_PROFORMA = 'Server.FacturasProforma';
type
TBizFacturasProformaServer = class(TFacturasProformaBusinessProcessorRules)
private
FReferenciaAutomatica : Boolean;
function DarReferencia : String;
function IncrementarReferencia : Boolean;
protected
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, uBusinessUtils, uROClasses, uROServer, SysUtils,
uDataModuleServer, schFacturasProformaClient_Intf, FactuGES_Intf;
const
REF_FACTURAS_PROFORMA = 'REF_FACTURAS_PROFORMA';
{ TBizFacturasProformaServer }
procedure TBizFacturasProformaServer.AfterProcessChange(
Sender: TDABusinessProcessor; aChange: TDADeltaChange; Processed: Boolean;
var CanRemoveFromDelta: Boolean);
begin
inherited;
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;
{ Por defecto, mantenemos los deltas por si alguna tabla hija los necesita }
CanRemoveFromDelta := False;
case aChange.ChangeType of
ctInsert, ctUpdate: begin
if FReferenciaAutomatica then
begin
IncrementarReferencia;
FReferenciaAutomatica := False;
end;
end;
end;
end;
procedure TBizFacturasProformaServer.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;
function TBizFacturasProformaServer.DarReferencia: String;
var
AReferenciasService : IsrvReferencias;
Intf : IInterface;
AClientID : TGUID;
begin
// Aunque sea un abono, la referencia es la misma que una factura
CreateGUID(AClientID);
GetClassFactory('srvReferencias').CreateInstance(AClientID, Intf);
AReferenciasService := Intf as IsrvReferencias;
Result := AReferenciasService.DarNuevaReferencia(REF_FACTURAS_PROFORMA, ID_EMPRESA)
end;
function TBizFacturasProformaServer.IncrementarReferencia: Boolean;
var
AReferenciasService : IsrvReferencias;
Intf : IInterface;
AClientID : TGUID;
begin
// Aunque sea un abono, la referencia es la misma que una factura
CreateGUID(AClientID);
GetClassFactory('srvReferencias').CreateInstance(AClientID, Intf);
AReferenciasService := Intf as IsrvReferencias;
Result := AReferenciasService.IncrementarValorReferencia(REF_FACTURAS_PROFORMA, Self.REFERENCIA, ID_EMPRESA)
end;
procedure TBizFacturasProformaServer.Delete_Asiento_Factura(aChange: TDADeltaChange);
var
ASchema : TDASchema;
ACurrentConn : IDAConnection;
ACommand : IDASQLCommand;
begin
ASchema := BusinessProcessor.Schema;
ACurrentConn := GetBusinessProcessorConnection(BusinessProcessor);
{
//Eliminamos los recibos de la factura
ACommand := ASchema.NewCommand(ACurrentConn, 'Delete_RecibosFactura');
try
with ACommand do
begin
ParamByName('ID_FACTURA').Value := aChange.OldValueByName[fld_FacturasClienteID];
Execute;
end;
finally
ACommand := NIL;
end;
}
end;
initialization
RegisterBusinessProcessorRules(BIZ_SERVER_FACTURAS_PROFORMA, TBizFacturasProformaServer);
end.