git-svn-id: https://192.168.0.254/svn/Proyectos.Acana_FactuGES2/trunk@339 f4e31baf-9722-1c47-927c-6f952f962d4b
284 lines
11 KiB
ObjectPascal
284 lines
11 KiB
ObjectPascal
unit uRptFacturasCliente_Server;
|
||
|
||
interface
|
||
|
||
uses
|
||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
Dialogs, frxClass, frxDBSet, uDAScriptingProvider,
|
||
uDADataTable, uDACDSDataTable, DB, uDAClasses, frxChart, frxGradient,
|
||
frxChBox, frxCross, frxOLE, frxBarcode, frxRich, uDABINAdapter, uROTypes,
|
||
uDAInterfaces, uDADataStreamer, uDABin2DataStreamer, uDAMemDataTable,
|
||
FactuGES_Intf;
|
||
|
||
type
|
||
TRptFacturasCliente = class(TDataModule)
|
||
DADataCabecera: TDADataSource;
|
||
DADataDetalles: TDADataSource;
|
||
tbl_Cabecera: TDAMemDataTable;
|
||
tbl_Detalles: TDAMemDataTable;
|
||
frxRichObject1: TfrxRichObject;
|
||
frxBarCodeObject1: TfrxBarCodeObject;
|
||
frxOLEObject1: TfrxOLEObject;
|
||
frxCrossObject1: TfrxCrossObject;
|
||
frxCheckBoxObject1: TfrxCheckBoxObject;
|
||
frxGradientObject1: TfrxGradientObject;
|
||
frxDBCabecera: TfrxDBDataset;
|
||
frxDBDetalles: TfrxDBDataset;
|
||
DADataVencimientos: TDADataSource;
|
||
tbl_Vencimientos: TDAMemDataTable;
|
||
frxDBDataset1: TfrxDBDataset;
|
||
DataDictionary: TDADataDictionary;
|
||
frxReport: TfrxReport;
|
||
Bin2DataStreamer: TDABin2DataStreamer;
|
||
tbl_InformeListadoFacturas: TDAMemDataTable;
|
||
DADSInformeListadoFacturas: TDADataSource;
|
||
frxDBInformeListadoFacturas: TfrxDBDataset;
|
||
schReport: TDASchema;
|
||
procedure DataModuleCreate(Sender: TObject);
|
||
private
|
||
FConnection: IDAConnection;
|
||
//Genera cada uno de los albaranes a imprimir
|
||
procedure _GenerarFactura(const ID: integer); overload;
|
||
function _GenerarInforme(const TipoInforme: String; const IdEmpresa: Integer; const FechaInicio: DateTime; const FechaFin: DateTime; const ListaIDClientes: TIntegerArray; const ImporteMinimo: Currency): Binary;
|
||
public
|
||
function GenerarFactura(const ListaID : TIntegerArray): Binary; overload;
|
||
function GenerarInformeIVA(const IdEmpresa: Integer; const FechaInicio: DateTime; const FechaFin: DateTime; const ListaIDClientes: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary;
|
||
function GenerarInformeListadoFacturas(const IdEmpresa: Integer; const FechaInicio: DateTime; const FechaFin: DateTime; const ListaIDClientes: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary;
|
||
function GenerarInformeListadoFacturasPendientes(const IdEmpresa: Integer; const FechaInicio: DateTime; const FechaFin: DateTime; const ListaIDClientes: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary;
|
||
end;
|
||
|
||
implementation
|
||
|
||
{$R *.dfm}
|
||
|
||
uses
|
||
uSistemaFunc, uDataModuleServer, schFacturasClienteClient_Intf;
|
||
|
||
const
|
||
rptFacturaCliente = 'InfFacturaCliente.fr3';
|
||
|
||
rptInformeIVA = 'InformeIVAClientes.fr3';
|
||
rptInformeIVADesglosado = 'InformeIVAClientesDesglosado.fr3';
|
||
rptInformeListadoFacturasCliente = 'InformeListadoFacturasCliente.fr3';
|
||
rptInformeListadoFacturasClienteDesglosado = 'InformeListadoFacturasClienteDesglosado.fr3';
|
||
rptInformeListadoFactuasClientePendiente = 'InformeListadoFacturasClientePendientes.fr3';
|
||
rptInformeListadoFactuasClientePendienteDesglosado = 'InformeListadoFacturasClientePendientesDesglosado.fr3';
|
||
|
||
|
||
|
||
{ TRptFacturasCliente }
|
||
|
||
procedure TRptFacturasCliente.DataModuleCreate(Sender: TObject);
|
||
begin
|
||
schReport.ConnectionManager := dmServer.ConnectionManager;
|
||
FConnection := dmServer.DarNuevaConexion;
|
||
frxReport.EngineOptions.NewSilentMode := simReThrow;
|
||
end;
|
||
|
||
function TRptFacturasCliente.GenerarFactura(const ListaID: TIntegerArray): Binary;
|
||
var
|
||
i: Integer;
|
||
begin
|
||
Result := Binary.Create;
|
||
try
|
||
//Vamos generando todos y cada una de las facturas recibidas
|
||
for i := 0 to ListaID.Count - 1 do
|
||
_GenerarFactura(ListaID.Items[i]);
|
||
|
||
frxReport.PreviewPages.SaveToStream(Result);
|
||
finally
|
||
end;
|
||
end;
|
||
|
||
function TRptFacturasCliente.GenerarInformeIVA(const IdEmpresa: Integer; const FechaInicio,
|
||
FechaFin: DateTime; const ListaIDClientes: TIntegerArray; const Desglosado: Boolean;
|
||
const ImporteMinimo: Currency): Binary;
|
||
var
|
||
ATipoInforme: String;
|
||
|
||
begin
|
||
//DESGLOSADO POR CLIENTE EN ESTE INFORME NO SE DESGLOSAR<41> POR CLIENTE
|
||
if Desglosado then
|
||
ATipoInforme := rptInformeIVADesglosado
|
||
else
|
||
ATipoInforme := rptInformeIVA;
|
||
|
||
Result := _GenerarInforme(ATipoInforme, IdEmpresa, FechaInicio, FechaFin, ListaIDClientes, ImporteMinimo);
|
||
end;
|
||
|
||
function TRptFacturasCliente.GenerarInformeListadoFacturas(const IdEmpresa: Integer;
|
||
const FechaInicio, FechaFin: DateTime; const ListaIDClientes: TIntegerArray;
|
||
const Desglosado: Boolean; const ImporteMinimo: Currency): Binary;
|
||
var
|
||
ATipoInforme: String;
|
||
|
||
begin
|
||
|
||
//DESGLOSADO POR CLIENTE EN ESTE INFORME NO SE DESGLOSAR<41> POR CLIENTE
|
||
if Desglosado then
|
||
ATipoInforme := rptInformeListadoFacturasClienteDesglosado
|
||
else
|
||
ATipoInforme := rptInformeListadoFacturasCliente;
|
||
|
||
Result := _GenerarInforme(ATipoInforme, IdEmpresa, FechaInicio, FechaFin, ListaIDClientes, ImporteMinimo);
|
||
end;
|
||
|
||
function TRptFacturasCliente.GenerarInformeListadoFacturasPendientes(
|
||
const IdEmpresa: Integer; const FechaInicio, FechaFin: DateTime;
|
||
const ListaIDClientes: TIntegerArray; const Desglosado: Boolean;
|
||
const ImporteMinimo: Currency): Binary;
|
||
var
|
||
Condicion: TDAWhereExpression;
|
||
ATipoInforme: String;
|
||
|
||
begin
|
||
if tbl_InformeListadoFacturas.Active then
|
||
tbl_InformeListadoFacturas.Active := False;
|
||
|
||
// Filtrar el informe por situacion
|
||
with tbl_InformeListadoFacturas.DynamicWhere do
|
||
begin
|
||
// (ID_EMPRESA >= ID)
|
||
Condicion := NewBinaryExpression(NewField('', fld_FacturasClienteSITUACION), NewConstant('PAGADA', datString), dboNotEqual);
|
||
if IsEmpty then
|
||
Expression := Condicion
|
||
else
|
||
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
||
end;
|
||
|
||
|
||
//DESGLOSADO POR CLIENTE EN ESTE INFORME NO SE DESGLOSAR<41> POR CLIENTE
|
||
if Desglosado then
|
||
ATipoInforme := rptInformeListadoFactuasClientePendienteDesglosado
|
||
else
|
||
ATipoInforme := rptInformeListadoFactuasClientePendiente;
|
||
|
||
Result := _GenerarInforme(ATipoInforme, IdEmpresa, FechaInicio, FechaFin, ListaIDClientes, ImporteMinimo);
|
||
end;
|
||
|
||
procedure TRptFacturasCliente._GenerarFactura(const ID: integer);
|
||
var
|
||
AInforme: Variant;
|
||
|
||
begin
|
||
FConnection.BeginTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
||
try
|
||
tbl_Cabecera.Active := False;
|
||
tbl_Detalles.Active := False;
|
||
tbl_Vencimientos.Active := False;
|
||
|
||
tbl_Cabecera.ParamByName('ID').AsInteger := ID;
|
||
tbl_Detalles.ParamByName('ID_FACTURA').AsInteger := ID;
|
||
tbl_Vencimientos.ParamByName('ID_FACTURA').AsInteger := ID;
|
||
|
||
tbl_Cabecera.Active := True;
|
||
tbl_Detalles.Active := True;
|
||
tbl_Vencimientos.Active := True;
|
||
|
||
AInforme := DarRutaFichero(DarRutaInformes, rptFacturaCliente, tbl_Cabecera.FieldByName('ID_EMPRESA').AsString, tbl_Cabecera.FieldByName('ID_TIENDA').AsString);
|
||
if VarIsNull(AInforme) then
|
||
raise Exception.Create (('Error Servidor: _GenerarFactura, no encuentra informe' + rptFacturaCliente));
|
||
|
||
frxReport.LoadFromFile(AInforme, True);
|
||
frxReport.PrepareReport(False);
|
||
finally
|
||
FConnection.RollbackTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
||
end;
|
||
end;
|
||
|
||
function TRptFacturasCliente._GenerarInforme(const TipoInforme: String;
|
||
const IdEmpresa: Integer; const FechaInicio, FechaFin: DateTime;
|
||
const ListaIDClientes: TIntegerArray; const ImporteMinimo: Currency): Binary;
|
||
var
|
||
Condicion: TDAWhereExpression;
|
||
i: Integer;
|
||
AInforme: Variant;
|
||
|
||
begin
|
||
Result := Binary.Create;
|
||
FConnection.BeginTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
||
|
||
try
|
||
|
||
if tbl_InformeListadoFacturas.Active then
|
||
tbl_InformeListadoFacturas.Active := False;
|
||
|
||
// Filtrar el informe por empresa
|
||
with tbl_InformeListadoFacturas.DynamicWhere do
|
||
begin
|
||
// (ID_EMPRESA >= ID)
|
||
Condicion := NewBinaryExpression(NewField('', fld_FacturasClienteID_EMPRESA), NewConstant(IdEmpresa, datInteger), dboEqual);
|
||
if IsEmpty then
|
||
Expression := Condicion
|
||
else
|
||
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
||
end;
|
||
|
||
// Filtrar el informe por fechas
|
||
if not VarIsNull(FechaInicio)
|
||
and not VarIsNull(FechaFin) then
|
||
begin
|
||
with tbl_InformeListadoFacturas.DynamicWhere do
|
||
begin
|
||
// (FECHA_INICIO between FECHA_FIN)
|
||
Condicion := NewBinaryExpression(NewField('', fld_FacturasClienteFECHA_FACTURA), NewConstant(FechaInicio, datDateTime), dboGreaterOrEqual);
|
||
Condicion := NewBinaryExpression(NewBinaryExpression(NewField('', fld_FacturasClienteFECHA_FACTURA), NewConstant(FechaFin, datDateTime), dboLessOrEqual), Condicion, dboAnd);
|
||
if IsEmpty then
|
||
Expression := Condicion
|
||
else
|
||
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
||
end;
|
||
end;
|
||
|
||
// Filtrar el informe por cliente
|
||
if Assigned(ListaIDClientes) then
|
||
begin
|
||
with tbl_InformeListadoFacturas.DynamicWhere do
|
||
begin
|
||
for i := 0 to ListaIDClientes.Count - 1 do
|
||
begin
|
||
|
||
// (ID_CLIENTE = ID)
|
||
Condicion := NewBinaryExpression(NewField('', fld_FacturasClienteID_CLIENTE), NewConstant(ListaIDClientes.Items[i], datInteger), dboEqual);
|
||
if IsEmpty then
|
||
Expression := Condicion
|
||
else
|
||
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
// Filtrar el informe por importe minimo
|
||
if (ImporteMinimo > 0) then
|
||
begin
|
||
with tbl_InformeListadoFacturas.DynamicWhere do
|
||
begin
|
||
// (IMPORTE_TOTAL > ImporteMinimo)
|
||
Condicion := NewBinaryExpression(NewField('', fld_FacturasClienteIMPORTE_TOTAL), NewConstant(ImporteMinimo, datCurrency), dboGreaterOrEqual);
|
||
if IsEmpty then
|
||
Expression := Condicion
|
||
else
|
||
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
||
end;
|
||
end;
|
||
|
||
|
||
tbl_InformeListadoFacturas.Active := True;
|
||
|
||
AInforme := DarRutaFichero(DarRutaInformes, TipoInforme, tbl_InformeListadoFacturas.FieldByName('ID_EMPRESA').AsString);
|
||
if VarIsNull(AInforme) then
|
||
raise Exception.Create (('Error Servidor: _GenerarInforme, no encuentra informe' + TipoInforme));
|
||
|
||
frxReport.LoadFromFile(AInforme, True);
|
||
frxReport.Variables.Variables['FechaInicio'] := FechaInicio;
|
||
frxReport.Variables.Variables['FechaFin'] := FechaFin;
|
||
frxReport.PrepareReport(False);
|
||
frxReport.PreviewPages.SaveToStream(Result);
|
||
|
||
finally
|
||
FConnection.RollbackTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
||
end;
|
||
end;
|
||
|
||
end.
|