2007-11-05 18:00:22 +00:00
|
|
|
|
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,
|
2008-01-15 10:31:41 +00:00
|
|
|
|
uDAInterfaces, uDADataStreamer, IBCustomDataSet, IBQuery, IBDatabase,
|
2008-08-22 14:52:35 +00:00
|
|
|
|
uDAMemDataTable, FactuGES_Intf, frxExportPDF;
|
2007-11-05 18:00:22 +00:00
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
TRptFacturasCliente = class(TDataModule)
|
|
|
|
|
|
frxDBCabecera: TfrxDBDataset;
|
|
|
|
|
|
frxDBDetalles: TfrxDBDataset;
|
|
|
|
|
|
DataDictionary: TDADataDictionary;
|
2007-12-11 16:24:53 +00:00
|
|
|
|
IBDatabase1: TIBDatabase;
|
|
|
|
|
|
IBTransaction1: TIBTransaction;
|
|
|
|
|
|
DataSource1: TDataSource;
|
|
|
|
|
|
DataSource2: TDataSource;
|
|
|
|
|
|
cabecera: TIBQuery;
|
|
|
|
|
|
detalles: TIBQuery;
|
2008-01-15 10:31:41 +00:00
|
|
|
|
DABINAdapter: TDABINAdapter;
|
|
|
|
|
|
DADSCabecera: TDADataSource;
|
|
|
|
|
|
DADSDetalles: TDADataSource;
|
|
|
|
|
|
tbl_Detalles: TDAMemDataTable;
|
|
|
|
|
|
tbl_Cabecera: TDAMemDataTable;
|
|
|
|
|
|
frxCheckBoxObject1: TfrxCheckBoxObject;
|
|
|
|
|
|
frxChartObject1: TfrxChartObject;
|
|
|
|
|
|
frxGradientObject1: TfrxGradientObject;
|
|
|
|
|
|
frxCrossObject1: TfrxCrossObject;
|
|
|
|
|
|
frxOLEObject1: TfrxOLEObject;
|
|
|
|
|
|
frxBarCodeObject1: TfrxBarCodeObject;
|
|
|
|
|
|
frxRichObject1: TfrxRichObject;
|
|
|
|
|
|
frxReport: TfrxReport;
|
|
|
|
|
|
cabeceraID: TIntegerField;
|
|
|
|
|
|
cabeceraID_EMPRESA: TIntegerField;
|
|
|
|
|
|
cabeceraREFERENCIA: TIBStringField;
|
|
|
|
|
|
cabeceraTIPO: TIBStringField;
|
|
|
|
|
|
cabeceraFECHA_FACTURA: TDateField;
|
|
|
|
|
|
cabeceraBASE_IMPONIBLE: TIBBCDField;
|
|
|
|
|
|
cabeceraSITUACION: TIBStringField;
|
|
|
|
|
|
cabeceraDESCUENTO: TFloatField;
|
|
|
|
|
|
cabeceraIMPORTE_DESCUENTO: TIBBCDField;
|
|
|
|
|
|
cabeceraIVA: TFloatField;
|
|
|
|
|
|
cabeceraIMPORTE_IVA: TIBBCDField;
|
|
|
|
|
|
cabeceraRE: TFloatField;
|
|
|
|
|
|
cabeceraIMPORTE_RE: TIBBCDField;
|
|
|
|
|
|
cabeceraIMPORTE_TOTAL: TIBBCDField;
|
|
|
|
|
|
cabeceraOBSERVACIONES: TMemoField;
|
|
|
|
|
|
cabeceraNIF_CIF: TIBStringField;
|
|
|
|
|
|
cabeceraID_CLIENTE: TIntegerField;
|
|
|
|
|
|
cabeceraNOMBRE: TIBStringField;
|
|
|
|
|
|
cabeceraCALLE: TIBStringField;
|
|
|
|
|
|
cabeceraPROVINCIA: TIBStringField;
|
|
|
|
|
|
cabeceraPOBLACION: TIBStringField;
|
|
|
|
|
|
cabeceraCODIGO_POSTAL: TIBStringField;
|
|
|
|
|
|
cabeceraRECARGO_EQUIVALENCIA: TSmallintField;
|
|
|
|
|
|
cabeceraIMPORTE_NETO: TIBBCDField;
|
|
|
|
|
|
cabeceraIMPORTE_PORTE: TIBBCDField;
|
|
|
|
|
|
cabeceraFORMA_PAGO: TIBStringField;
|
|
|
|
|
|
detallesID: TIntegerField;
|
|
|
|
|
|
detallesID_FACTURA: TIntegerField;
|
|
|
|
|
|
detallesPOSICION: TIntegerField;
|
|
|
|
|
|
detallesTIPO_DETALLE: TIBStringField;
|
|
|
|
|
|
detallesCONCEPTO: TIBStringField;
|
|
|
|
|
|
detallesCANTIDAD: TIntegerField;
|
|
|
|
|
|
detallesIMPORTE_UNIDAD: TIBBCDField;
|
|
|
|
|
|
detallesDESCUENTO: TFloatField;
|
|
|
|
|
|
detallesIMPORTE_TOTAL: TIBBCDField;
|
|
|
|
|
|
detallesVISIBLE: TSmallintField;
|
2008-02-28 19:39:33 +00:00
|
|
|
|
detallesREFERENCIA: TIBStringField;
|
2008-06-11 16:35:39 +00:00
|
|
|
|
frxDBVencimientos: TfrxDBDataset;
|
|
|
|
|
|
DADSVencimientos: TDADataSource;
|
|
|
|
|
|
tbl_Vencimientos: TDAMemDataTable;
|
|
|
|
|
|
vencimientos: TIBQuery;
|
|
|
|
|
|
DataSource3: TDataSource;
|
|
|
|
|
|
cabeceraDATOS_BANCARIOS: TIBStringField;
|
|
|
|
|
|
vencimientosFECHA_VENCIMIENTO: TDateField;
|
|
|
|
|
|
vencimientosIMPORTE_TOTAL: TIBBCDField;
|
2008-08-22 14:52:35 +00:00
|
|
|
|
frxPDFExport1: TfrxPDFExport;
|
2008-10-17 14:07:42 +00:00
|
|
|
|
tbl_InformeListadoFacturas: TDAMemDataTable;
|
|
|
|
|
|
DADSInformeListadoFacturas: TDADataSource;
|
|
|
|
|
|
frxDBInformeListadoFacturas: TfrxDBDataset;
|
2009-01-16 15:00:06 +00:00
|
|
|
|
frxDBInformeListadoFacturasPendientes: TfrxDBDataset;
|
|
|
|
|
|
DADSInformeListadoFacturasPendientes: TDADataSource;
|
|
|
|
|
|
tbl_InformeListadoFacturasPendientes: TDAMemDataTable;
|
2008-09-08 15:46:28 +00:00
|
|
|
|
schReport: TDASchema;
|
2007-11-05 18:00:22 +00:00
|
|
|
|
procedure DataModuleCreate(Sender: TObject);
|
|
|
|
|
|
private
|
|
|
|
|
|
FConnection: IDAConnection;
|
2007-12-11 16:24:53 +00:00
|
|
|
|
//Genera cada una de las facturas a imprimir
|
2008-11-13 10:33:06 +00:00
|
|
|
|
procedure _GenerarFactura(const ID: Integer; const VerSello: Boolean = True);
|
2009-01-16 15:00:06 +00:00
|
|
|
|
function _GenerarInforme(ATabla: TDAMemDataTable; const TipoInforme: String; const IdEmpresa: Integer; const FechaInicio: Variant; const FechaFin: Variant; const FechaVenInicio: Variant; const FechaVenFin: Variant; const ListaIDClientes: TIntegerArray; const ImporteMinimo: Currency): Binary;
|
2007-11-05 18:00:22 +00:00
|
|
|
|
public
|
2008-11-13 10:33:06 +00:00
|
|
|
|
function GenerarFactura(const ListaID : TIntegerArray; const VerSello: Boolean = True): Binary;
|
|
|
|
|
|
function GenerarFacturaEnPDF(const ListaID : TIntegerArray; const VerSello: Boolean = True): Binary;
|
2008-12-15 09:03:56 +00:00
|
|
|
|
function GenerarInformeIVA(const IdEmpresa: Integer; const FechaInicio: Variant; const FechaFin: Variant; const ListaIDClientes: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary;
|
2009-01-08 17:45:28 +00:00
|
|
|
|
function GenerarInformeListadoFacturas(const IdEmpresa: Integer; const FechaInicio: Variant; const FechaFin: Variant; const FechaVenInicio: Variant; const FechaVenFin: Variant; const ListaIDClientes: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary;
|
|
|
|
|
|
function GenerarInformeListadoFacturasPendientes(const IdEmpresa: Integer; const FechaInicio: Variant; const FechaFin: Variant; const FechaVenInicio: Variant; const FechaVenFin: Variant; const ListaIDClientes: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary;
|
2007-11-05 18:00:22 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
2008-11-26 19:25:27 +00:00
|
|
|
|
uSistemaFunc, uDataModuleServer, schFacturasClienteClient_Intf;
|
2007-11-05 18:00:22 +00:00
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
|
rptFacturaCliente = 'InfFacturaCliente.fr3';
|
2008-10-15 18:50:09 +00:00
|
|
|
|
rptInformeIVA = 'InformeIVAClientes.fr3';
|
2008-10-20 10:42:48 +00:00
|
|
|
|
rptInformeIVADesglosado = 'InformeIVAClientesDesglosado.fr3';
|
2008-10-17 14:07:42 +00:00
|
|
|
|
rptInformeListadoFacturasCliente = 'InformeListadoFacturasCliente.fr3';
|
|
|
|
|
|
rptInformeListadoFacturasClienteDesglosado = 'InformeListadoFacturasClienteDesglosado.fr3';
|
|
|
|
|
|
rptInformeListadoFactuasClientePendiente = 'InformeListadoFacturasClientePendientes.fr3';
|
2008-10-20 10:42:48 +00:00
|
|
|
|
rptInformeListadoFactuasClientePendienteDesglosado = 'InformeListadoFacturasClientePendientesDesglosado.fr3';
|
2007-11-05 18:00:22 +00:00
|
|
|
|
|
|
|
|
|
|
{ Dataset names for schReport }
|
2008-10-17 14:07:42 +00:00
|
|
|
|
// ds_InformeFacturasCliente = 'InformeFacturasCliente';
|
|
|
|
|
|
// ds_InformeFacturasCliente_Detalles = 'InformeFacturasCliente_Detalles';
|
|
|
|
|
|
// ds_InformeFacturasCliente_Vencimientos = 'InformeFacturasCliente_Vencimientos';
|
2007-11-05 18:00:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ TRptFacturasCliente }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure TRptFacturasCliente.DataModuleCreate(Sender: TObject);
|
|
|
|
|
|
begin
|
|
|
|
|
|
schReport.ConnectionManager := dmServer.ConnectionManager;
|
|
|
|
|
|
FConnection := dmServer.DarNuevaConexion;
|
2008-09-24 14:41:41 +00:00
|
|
|
|
frxReport.EngineOptions.NewSilentMode := simReThrow;
|
|
|
|
|
|
|
|
|
|
|
|
frxDBCabecera.DataSource := DADSCabecera;
|
|
|
|
|
|
frxDBDetalles.DataSource := DADSDetalles;
|
|
|
|
|
|
frxDBVencimientos.DataSource := DADSVencimientos;
|
2007-11-05 18:00:22 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2008-11-13 10:33:06 +00:00
|
|
|
|
function TRptFacturasCliente.GenerarFactura(const ListaID: TIntegerArray; const VerSello: Boolean = True): Binary;
|
2007-11-05 18:00:22 +00:00
|
|
|
|
var
|
|
|
|
|
|
i: Integer;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := Binary.Create;
|
|
|
|
|
|
try
|
2007-12-11 16:24:53 +00:00
|
|
|
|
//Vamos generando todos y cada una de las facturas recibidas
|
2008-08-22 14:52:35 +00:00
|
|
|
|
for i := 0 to ListaID.Count - 1 do
|
2008-11-13 10:33:06 +00:00
|
|
|
|
_GenerarFactura(ListaID.Items[i], VerSello);
|
2007-11-05 18:00:22 +00:00
|
|
|
|
|
|
|
|
|
|
frxReport.PreviewPages.SaveToStream(Result);
|
2008-08-22 14:52:35 +00:00
|
|
|
|
finally
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2008-11-13 10:33:06 +00:00
|
|
|
|
function TRptFacturasCliente.GenerarFacturaEnPDF(const ListaID: TIntegerArray; const VerSello: Boolean = True): Binary;
|
2008-08-22 14:52:35 +00:00
|
|
|
|
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
|
2008-11-13 10:33:06 +00:00
|
|
|
|
_GenerarFactura(ListaID.Items[i], VerSello);
|
2007-11-05 18:00:22 +00:00
|
|
|
|
|
2008-08-22 14:52:35 +00:00
|
|
|
|
frxPDFExport1.Stream := Result;
|
|
|
|
|
|
frxReport.Export(frxPDFExport1)
|
2007-11-05 18:00:22 +00:00
|
|
|
|
finally
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2008-12-15 09:03:56 +00:00
|
|
|
|
function TRptFacturasCliente.GenerarInformeIVA(const IdEmpresa: Integer; const FechaInicio: Variant; const FechaFin: Variant; const ListaIDClientes: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary;
|
2008-10-20 10:42:48 +00:00
|
|
|
|
var
|
|
|
|
|
|
ATipoInforme: String;
|
|
|
|
|
|
|
2008-10-17 14:07:42 +00:00
|
|
|
|
begin
|
|
|
|
|
|
//DESGLOSADO POR CLIENTE EN ESTE INFORME NO SE DESGLOSAR<41> POR CLIENTE
|
2008-10-20 10:42:48 +00:00
|
|
|
|
if Desglosado then
|
|
|
|
|
|
ATipoInforme := rptInformeIVADesglosado
|
|
|
|
|
|
else
|
|
|
|
|
|
ATipoInforme := rptInformeIVA;
|
2008-10-17 14:07:42 +00:00
|
|
|
|
|
2009-01-16 15:00:06 +00:00
|
|
|
|
Result := _GenerarInforme(tbl_InformeListadoFacturas, ATipoInforme, IdEmpresa, FechaInicio, FechaFin, Null, Null, ListaIDClientes, ImporteMinimo);
|
2008-10-17 14:07:42 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2008-10-21 17:58:25 +00:00
|
|
|
|
function TRptFacturasCliente.GenerarInformeListadoFacturas(const IdEmpresa: Integer;
|
2009-01-08 17:45:28 +00:00
|
|
|
|
const FechaInicio, FechaFin: Variant; const FechaVenInicio: Variant; const FechaVenFin: Variant;
|
|
|
|
|
|
const ListaIDClientes: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary;
|
2008-10-17 14:07:42 +00:00
|
|
|
|
var
|
|
|
|
|
|
ATipoInforme: String;
|
2009-01-08 17:45:28 +00:00
|
|
|
|
|
2008-10-17 14:07:42 +00:00
|
|
|
|
begin
|
|
|
|
|
|
|
|
|
|
|
|
//DESGLOSADO POR CLIENTE EN ESTE INFORME NO SE DESGLOSAR<41> POR CLIENTE
|
|
|
|
|
|
if Desglosado then
|
|
|
|
|
|
ATipoInforme := rptInformeListadoFacturasClienteDesglosado
|
|
|
|
|
|
else
|
|
|
|
|
|
ATipoInforme := rptInformeListadoFacturasCliente;
|
|
|
|
|
|
|
2009-01-16 15:00:06 +00:00
|
|
|
|
Result := _GenerarInforme(tbl_InformeListadoFacturas, ATipoInforme, IdEmpresa, FechaInicio, FechaFin, FechaVenInicio, FechaVenFin, ListaIDClientes, ImporteMinimo);
|
2008-10-17 14:07:42 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2008-10-21 17:58:25 +00:00
|
|
|
|
function TRptFacturasCliente.GenerarInformeListadoFacturasPendientes(
|
2008-12-15 09:03:56 +00:00
|
|
|
|
const IdEmpresa: Integer; const FechaInicio, FechaFin: Variant;
|
2009-01-08 17:45:28 +00:00
|
|
|
|
const FechaVenInicio: Variant; const FechaVenFin: Variant;
|
2008-10-17 14:07:42 +00:00
|
|
|
|
const ListaIDClientes: TIntegerArray; const Desglosado: Boolean;
|
|
|
|
|
|
const ImporteMinimo: Currency): Binary;
|
|
|
|
|
|
var
|
|
|
|
|
|
Condicion: TDAWhereExpression;
|
2008-10-20 10:42:48 +00:00
|
|
|
|
ATipoInforme: String;
|
2008-10-17 14:07:42 +00:00
|
|
|
|
|
|
|
|
|
|
begin
|
2009-01-16 15:00:06 +00:00
|
|
|
|
if tbl_InformeListadoFacturasPendientes.Active then
|
|
|
|
|
|
tbl_InformeListadoFacturasPendientes.Active := False;
|
2008-10-17 14:07:42 +00:00
|
|
|
|
|
|
|
|
|
|
// Filtrar el informe por situacion
|
2009-01-16 15:00:06 +00:00
|
|
|
|
with tbl_InformeListadoFacturasPendientes.DynamicWhere do
|
2008-10-17 14:07:42 +00:00
|
|
|
|
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
|
2008-10-20 10:42:48 +00:00
|
|
|
|
if Desglosado then
|
|
|
|
|
|
ATipoInforme := rptInformeListadoFactuasClientePendienteDesglosado
|
|
|
|
|
|
else
|
|
|
|
|
|
ATipoInforme := rptInformeListadoFactuasClientePendiente;
|
2008-10-17 14:07:42 +00:00
|
|
|
|
|
2008-10-20 10:42:48 +00:00
|
|
|
|
|
2009-01-16 15:00:06 +00:00
|
|
|
|
Result := _GenerarInforme(tbl_InformeListadoFacturasPendientes, ATipoInforme, IdEmpresa, FechaInicio, FechaFin, FechaVenInicio, FechaVenFin, ListaIDClientes, ImporteMinimo);
|
2008-10-17 14:07:42 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2008-11-13 10:33:06 +00:00
|
|
|
|
procedure TRptFacturasCliente._GenerarFactura(const ID: Integer; const VerSello: Boolean = True);
|
2008-11-26 19:25:27 +00:00
|
|
|
|
var
|
|
|
|
|
|
AInforme: Variant;
|
|
|
|
|
|
|
2008-10-17 14:07:42 +00:00
|
|
|
|
begin
|
2008-10-31 18:16:49 +00:00
|
|
|
|
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;
|
2008-10-17 14:07:42 +00:00
|
|
|
|
|
2008-10-31 18:16:49 +00:00
|
|
|
|
tbl_Cabecera.ParamByName('ID').AsInteger := ID;
|
|
|
|
|
|
tbl_Detalles.ParamByName('ID_FACTURA').AsInteger := ID;
|
|
|
|
|
|
tbl_Vencimientos.ParamByName('ID_FACTURA').AsInteger := ID;
|
2008-10-17 14:07:42 +00:00
|
|
|
|
|
2008-10-31 18:16:49 +00:00
|
|
|
|
tbl_Cabecera.Active := True;
|
|
|
|
|
|
tbl_Detalles.Active := True;
|
|
|
|
|
|
tbl_Vencimientos.Active := True;
|
2008-10-17 14:07:42 +00:00
|
|
|
|
|
2008-11-26 19:25:27 +00:00
|
|
|
|
AInforme := DarRutaFichero(DarRutaInformes, rptFacturaCliente, tbl_Cabecera.FieldByName('ID_EMPRESA').AsString);
|
|
|
|
|
|
if VarIsNull(AInforme) then
|
2008-12-01 11:42:52 +00:00
|
|
|
|
raise Exception.Create (('Error Servidor: _GenerarFactura, no encuentra informe ' + rptFacturaCliente));
|
2008-11-26 19:25:27 +00:00
|
|
|
|
|
|
|
|
|
|
frxReport.LoadFromFile(AInforme, True);
|
2008-11-13 10:33:06 +00:00
|
|
|
|
if VerSello then
|
|
|
|
|
|
frxReport.Variables.Variables['VerSello'] := 1
|
|
|
|
|
|
else
|
|
|
|
|
|
frxReport.Variables.Variables['VerSello'] := 0;
|
2008-10-31 18:16:49 +00:00
|
|
|
|
frxReport.PrepareReport(False);
|
|
|
|
|
|
finally
|
|
|
|
|
|
FConnection.RollbackTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
|
|
|
|
|
end;
|
2008-10-17 14:07:42 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2009-01-16 15:00:06 +00:00
|
|
|
|
function TRptFacturasCliente._GenerarInforme(ATabla: TDAMemDataTable; const TipoInforme: String;
|
2008-12-15 09:03:56 +00:00
|
|
|
|
const IdEmpresa: Integer; const FechaInicio, FechaFin: Variant;
|
2009-01-08 17:45:28 +00:00
|
|
|
|
const FechaVenInicio: Variant; const FechaVenFin: Variant;
|
2008-10-17 14:07:42 +00:00
|
|
|
|
const ListaIDClientes: TIntegerArray; const ImporteMinimo: Currency): Binary;
|
2008-10-15 18:50:09 +00:00
|
|
|
|
var
|
|
|
|
|
|
Condicion: TDAWhereExpression;
|
|
|
|
|
|
i: Integer;
|
2008-11-26 19:25:27 +00:00
|
|
|
|
AInforme: Variant;
|
2009-01-08 17:45:28 +00:00
|
|
|
|
|
2008-10-15 18:50:09 +00:00
|
|
|
|
begin
|
|
|
|
|
|
Result := Binary.Create;
|
2008-10-31 18:16:49 +00:00
|
|
|
|
FConnection.BeginTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
2008-10-15 18:50:09 +00:00
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
2009-01-16 15:00:06 +00:00
|
|
|
|
if ATabla.Active then
|
|
|
|
|
|
ATabla.Active := False;
|
2008-10-15 18:50:09 +00:00
|
|
|
|
|
|
|
|
|
|
// Filtrar el informe por empresa
|
2009-01-16 15:00:06 +00:00
|
|
|
|
with ATabla.DynamicWhere do
|
2008-10-15 18:50:09 +00:00
|
|
|
|
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
|
2009-01-16 15:00:06 +00:00
|
|
|
|
with ATabla.DynamicWhere do
|
2008-10-15 18:50:09 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
2009-01-08 17:45:28 +00:00
|
|
|
|
// Filtrar el informe por fechas de vencimiento
|
|
|
|
|
|
if not VarIsNull(FechaVenInicio)
|
|
|
|
|
|
and not VarIsNull(FechaVenFin) then
|
|
|
|
|
|
begin
|
2009-01-16 15:00:06 +00:00
|
|
|
|
with ATabla.DynamicWhere do
|
2009-01-08 17:45:28 +00:00
|
|
|
|
begin
|
|
|
|
|
|
// (FECHA_VENCIMIENTO_INICIO between FECHA_VENCIMIENTO_FIN)
|
|
|
|
|
|
Condicion := NewBinaryExpression(NewField('', fld_FacturasClienteFECHA_VENCIMIENTO), NewConstant(FechaVenInicio, datDateTime), dboGreaterOrEqual);
|
|
|
|
|
|
Condicion := NewBinaryExpression(NewBinaryExpression(NewField('', fld_FacturasClienteFECHA_VENCIMIENTO), NewConstant(FechaVenFin, datDateTime), dboLessOrEqual), Condicion, dboAnd);
|
|
|
|
|
|
if IsEmpty then
|
|
|
|
|
|
Expression := Condicion
|
|
|
|
|
|
else
|
|
|
|
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2008-10-15 18:50:09 +00:00
|
|
|
|
// Filtrar el informe por cliente
|
|
|
|
|
|
if Assigned(ListaIDClientes) then
|
|
|
|
|
|
begin
|
2009-01-16 15:00:06 +00:00
|
|
|
|
with ATabla.DynamicWhere do
|
2008-10-15 18:50:09 +00:00
|
|
|
|
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
|
2009-01-16 15:00:06 +00:00
|
|
|
|
with ATabla.DynamicWhere do
|
2008-10-15 18:50:09 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-01-16 15:00:06 +00:00
|
|
|
|
ATabla.Active := True;
|
2009-01-16 15:21:51 +00:00
|
|
|
|
// showmessage(inttostr(ATabla.RecordCount));
|
2008-10-15 18:50:09 +00:00
|
|
|
|
|
2008-12-01 11:42:52 +00:00
|
|
|
|
AInforme := DarRutaFichero(DarRutaInformes, TipoInforme, IntToStr(IdEmpresa));
|
2008-11-26 19:25:27 +00:00
|
|
|
|
if VarIsNull(AInforme) then
|
2008-12-01 11:42:52 +00:00
|
|
|
|
raise Exception.Create (('Error Servidor: _GenerarInforme, no encuentra informe ' + TipoInforme));
|
2008-11-26 19:25:27 +00:00
|
|
|
|
|
|
|
|
|
|
frxReport.LoadFromFile(AInforme, True);
|
2008-10-15 18:50:09 +00:00
|
|
|
|
frxReport.Variables.Variables['FechaInicio'] := FechaInicio;
|
|
|
|
|
|
frxReport.Variables.Variables['FechaFin'] := FechaFin;
|
|
|
|
|
|
|
|
|
|
|
|
frxReport.PrepareReport(False);
|
|
|
|
|
|
frxReport.PreviewPages.SaveToStream(Result);
|
|
|
|
|
|
|
|
|
|
|
|
finally
|
2008-10-31 18:16:49 +00:00
|
|
|
|
FConnection.RollbackTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
2008-10-15 18:50:09 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 18:00:22 +00:00
|
|
|
|
end.
|