2011-11-14 17:40:41 +00:00
|
|
|
|
unit uBizFacturasClienteServer;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
uDAInterfaces, uDADelta, uDABusinessProcessor,
|
|
|
|
|
|
schFacturasClienteServer_Intf;
|
|
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
|
BIZ_SERVER_FACTURAS_CLIENTE = 'Server.FacturasCliente';
|
2023-12-04 14:04:07 +00:00
|
|
|
|
REF_FACTURAS_CLIENTE = 'REF_FACTURAS_CLIENTE';
|
|
|
|
|
|
REF_ABONOS_CLIENTE = 'REF_ABONOS_CLIENTE';
|
|
|
|
|
|
REF_FACTURAS_PROFORMA = 'REF_FACTURAS_PROFORMA';
|
|
|
|
|
|
CTE_TIPO_ABONO = 'A';
|
|
|
|
|
|
CTE_TIPO_FACTURA = 'F';
|
|
|
|
|
|
CTE_TIPO_PROFORMA = 'P';
|
2011-11-14 17:40:41 +00:00
|
|
|
|
|
|
|
|
|
|
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, FactuGES_Intf, uROServer, SysUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ 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);
|
|
|
|
|
|
|
|
|
|
|
|
//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;
|
|
|
|
|
|
|
|
|
|
|
|
//Eliminamos los asientos contables de la factura
|
|
|
|
|
|
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
|
|
|
|
|
|
AReferenciasService : IsrvReferencias;
|
|
|
|
|
|
Intf : IInterface;
|
|
|
|
|
|
AClientID : TGUID;
|
|
|
|
|
|
ATipo : String;
|
|
|
|
|
|
begin
|
2023-12-04 14:04:07 +00:00
|
|
|
|
//Se hacen facturas proforma con diferente referencia y tipo
|
|
|
|
|
|
if TIPO = CTE_TIPO_PROFORMA then
|
|
|
|
|
|
ATipo := REF_FACTURAS_PROFORMA
|
|
|
|
|
|
else
|
2011-11-14 17:40:41 +00:00
|
|
|
|
//No se hace distinci<63>n en la referencia entre facturas y abonos
|
|
|
|
|
|
// if TIPO = CTE_TIPO_FACTURA then
|
|
|
|
|
|
ATipo := REF_FACTURAS_CLIENTE;
|
|
|
|
|
|
// else
|
|
|
|
|
|
// ATipo := REF_ABONOS_CLIENTE;
|
|
|
|
|
|
|
|
|
|
|
|
CreateGUID(AClientID);
|
|
|
|
|
|
|
|
|
|
|
|
GetClassFactory('srvReferencias').CreateInstance(AClientID, Intf);
|
|
|
|
|
|
AReferenciasService := Intf as IsrvReferencias;
|
2022-10-21 09:41:20 +00:00
|
|
|
|
Result := AReferenciasService.DarNuevaReferencia(ATipo, ID_EMPRESA, -1) //Referencia com<6F>n a todas las tiendas de la empresa
|
2011-11-14 17:40:41 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TBizFacturasClienteServer.IncrementarReferencia: Boolean;
|
|
|
|
|
|
var
|
|
|
|
|
|
AReferenciasService : IsrvReferencias;
|
|
|
|
|
|
Intf : IInterface;
|
|
|
|
|
|
AClientID : TGUID;
|
|
|
|
|
|
ATipo : String;
|
|
|
|
|
|
begin
|
2023-12-04 14:04:07 +00:00
|
|
|
|
if TIPO = CTE_TIPO_PROFORMA then
|
|
|
|
|
|
ATipo := REF_FACTURAS_PROFORMA
|
|
|
|
|
|
else
|
2011-11-14 17:40:41 +00:00
|
|
|
|
// if TIPO = CTE_TIPO_FACTURA then
|
|
|
|
|
|
ATipo := REF_FACTURAS_CLIENTE;
|
|
|
|
|
|
// else
|
|
|
|
|
|
// ATipo := REF_ABONOS_CLIENTE;
|
|
|
|
|
|
|
|
|
|
|
|
CreateGUID(AClientID);
|
|
|
|
|
|
|
|
|
|
|
|
GetClassFactory('srvReferencias').CreateInstance(AClientID, Intf);
|
|
|
|
|
|
AReferenciasService := Intf as IsrvReferencias;
|
2022-10-21 09:41:20 +00:00
|
|
|
|
Result := AReferenciasService.IncrementarValorReferencia(ATipo, Self.REFERENCIA, ID_EMPRESA, -1) //Referencia com<6F>n a todas las tiendas de la empresa
|
2011-11-14 17:40:41 +00:00
|
|
|
|
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];
|
|
|
|
|
|
ParamByName('IdSubCuentaVenta').Value := aChange.NewValueByName[fld_FacturasClienteID_SUBCUENTA];
|
|
|
|
|
|
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];
|
|
|
|
|
|
ParamByName('IdSubCuentaVenta').Value := aChange.NewValueByName[fld_FacturasClienteID_SUBCUENTA];
|
|
|
|
|
|
Execute;
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
ACommand := NIL;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
initialization
|
|
|
|
|
|
RegisterBusinessProcessorRules(BIZ_SERVER_FACTURAS_CLIENTE, TBizFacturasClienteServer);
|
|
|
|
|
|
|
|
|
|
|
|
end.
|