2007-11-28 17:40:31 +00:00
|
|
|
|
unit uRptPresupuestosCliente_Server;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|
|
|
|
|
Dialogs, frxClass, frxDBSet, uDAScriptingProvider,
|
|
|
|
|
|
uDADataTable, uDACDSDataTable, DB, uDAClasses, uDABINAdapter, uROTypes,
|
2008-01-08 12:46:26 +00:00
|
|
|
|
uDAInterfaces, uDAMemDataTable, uDABin2DataStreamer,
|
2007-11-28 17:40:31 +00:00
|
|
|
|
frxGradient, frxChBox, frxCross, frxOLE, frxBarcode, frxRich, uDAEngine,
|
2008-10-03 17:15:51 +00:00
|
|
|
|
IBSQL, IBDatabase, IBCustomDataSet, IBQuery, uDADataStreamer, FactuGES_Intf,
|
|
|
|
|
|
frxExportPDF;
|
2007-11-28 17:40:31 +00:00
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
TRptPresupuestosCliente = class(TDataModule)
|
|
|
|
|
|
DADataCabecera: TDADataSource;
|
|
|
|
|
|
DADataDetalles: TDADataSource;
|
|
|
|
|
|
frxBarCodeObject1: TfrxBarCodeObject;
|
|
|
|
|
|
frxOLEObject1: TfrxOLEObject;
|
|
|
|
|
|
frxCrossObject1: TfrxCrossObject;
|
|
|
|
|
|
frxCheckBoxObject1: TfrxCheckBoxObject;
|
|
|
|
|
|
frxGradientObject1: TfrxGradientObject;
|
|
|
|
|
|
frxDBCabecera: TfrxDBDataset;
|
|
|
|
|
|
frxDBDetalles: TfrxDBDataset;
|
|
|
|
|
|
Bin2DataStreamer: TDABin2DataStreamer;
|
|
|
|
|
|
tbl_Cabecera: TDAMemDataTable;
|
|
|
|
|
|
tbl_Detalles: TDAMemDataTable;
|
|
|
|
|
|
frxReport: TfrxReport;
|
|
|
|
|
|
IBDatabase1: TIBDatabase;
|
|
|
|
|
|
IBTransaction1: TIBTransaction;
|
|
|
|
|
|
DataSource1: TDataSource;
|
|
|
|
|
|
DataSource2: TDataSource;
|
|
|
|
|
|
cabecera: TIBQuery;
|
|
|
|
|
|
detalles: TIBQuery;
|
2008-10-03 17:15:51 +00:00
|
|
|
|
frxPDFExport1: TfrxPDFExport;
|
2008-11-14 20:04:09 +00:00
|
|
|
|
tbl_InformeListadoPresupuestos: TDAMemDataTable;
|
|
|
|
|
|
DADSInformeListadoPresupuestos: TDADataSource;
|
|
|
|
|
|
frxDBInformeListadoPresupuestos: TfrxDBDataset;
|
|
|
|
|
|
schReport: TDASchema;
|
|
|
|
|
|
DataDictionary: TDADataDictionary;
|
2007-11-28 17:40:31 +00:00
|
|
|
|
procedure DataModuleCreate(Sender: TObject);
|
|
|
|
|
|
private
|
|
|
|
|
|
FConnection: IDAConnection;
|
2008-11-14 20:04:09 +00:00
|
|
|
|
procedure _GenerarPresupuesto(const AID : Integer);
|
|
|
|
|
|
function _GenerarInforme(const TipoInforme: String; const IdEmpresa: Integer; const FechaInicio: DateTime; const FechaFin: DateTime; const ListaIDClientes: TIntegerArray; const ImporteMinimo: Currency): Binary;
|
2007-11-28 17:40:31 +00:00
|
|
|
|
public
|
2008-10-03 17:15:51 +00:00
|
|
|
|
function GenerarPresupuesto(const ListaID : TIntegerArray): Binary;
|
|
|
|
|
|
function GenerarPresupuestoEnPDF(const ListaID : TIntegerArray): Binary;
|
2008-11-14 20:04:09 +00:00
|
|
|
|
function GenerarInformeListadoPresupuestos(const IdEmpresa: Integer; const FechaInicio: DateTime; const FechaFin: DateTime; const ListaIDClientes: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary;
|
2007-11-28 17:40:31 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
2008-11-26 19:12:42 +00:00
|
|
|
|
uSistemaFunc, uDataModuleServer, schPresupuestosClienteClient_Intf;
|
2007-11-28 17:40:31 +00:00
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
|
rptInforme = 'InfPresupuestoCliente.fr3';
|
2008-11-14 20:04:09 +00:00
|
|
|
|
rptInformeListadoPresupuestosDesglosado = 'InformeListadoPresupuestosDesglosado.fr3';
|
|
|
|
|
|
rptInformeListadoPresupuestos = 'InformeListadoPresupuestos.fr3';
|
2007-11-28 17:40:31 +00:00
|
|
|
|
|
|
|
|
|
|
{ Dataset names for schReport }
|
2008-11-14 20:04:09 +00:00
|
|
|
|
// ds_InformeCabecera = 'Informe_Cabecera';
|
|
|
|
|
|
// ds_InformeDetalles = 'Informe_Detalles';
|
2007-11-28 17:40:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ TRptPresupuestosProveedor }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure TRptPresupuestosCliente.DataModuleCreate(Sender: TObject);
|
|
|
|
|
|
begin
|
|
|
|
|
|
schReport.ConnectionManager := dmServer.ConnectionManager;
|
|
|
|
|
|
FConnection := dmServer.DarNuevaConexion;
|
|
|
|
|
|
frxReport.EngineOptions.NewSilentMode := simReThrow;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2008-11-14 20:04:09 +00:00
|
|
|
|
function TRptPresupuestosCliente.GenerarInformeListadoPresupuestos(
|
|
|
|
|
|
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 := rptInformeListadoPresupuestosDesglosado
|
|
|
|
|
|
else
|
|
|
|
|
|
ATipoInforme := rptInformeListadoPresupuestos;
|
|
|
|
|
|
|
|
|
|
|
|
Result := _GenerarInforme(ATipoInforme, IdEmpresa, FechaInicio, FechaFin, ListaIDClientes, ImporteMinimo);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2008-10-03 17:15:51 +00:00
|
|
|
|
function TRptPresupuestosCliente.GenerarPresupuesto(const ListaID : TIntegerArray): Binary;
|
2007-11-28 17:40:31 +00:00
|
|
|
|
var
|
|
|
|
|
|
i: Integer;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := Binary.Create;
|
2008-11-14 20:04:09 +00:00
|
|
|
|
try
|
|
|
|
|
|
//Vamos generando todos y cada uno de los presupuestos recibidos
|
|
|
|
|
|
for i := 0 to ListaID.Count - 1 do
|
|
|
|
|
|
_GenerarPresupuesto(ListaID.Items[i]);
|
2007-11-28 17:40:31 +00:00
|
|
|
|
|
2008-11-14 20:04:09 +00:00
|
|
|
|
frxReport.PreviewPages.SaveToStream(Result);
|
|
|
|
|
|
finally
|
|
|
|
|
|
end;
|
2008-10-03 17:15:51 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TRptPresupuestosCliente.GenerarPresupuestoEnPDF(
|
|
|
|
|
|
const ListaID: TIntegerArray): Binary;
|
|
|
|
|
|
var
|
|
|
|
|
|
i: Integer;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := Binary.Create;
|
2008-11-14 20:04:09 +00:00
|
|
|
|
try
|
|
|
|
|
|
//Vamos generando todos y cada uno de los presupuestos recibidos
|
|
|
|
|
|
for i := 0 to ListaID.Count - 1 do
|
|
|
|
|
|
_GenerarPresupuesto(ListaID.Items[i]);
|
|
|
|
|
|
|
|
|
|
|
|
frxPDFExport1.Stream := Result;
|
|
|
|
|
|
frxReport.Export(frxPDFExport1)
|
|
|
|
|
|
finally
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TRptPresupuestosCliente._GenerarInforme(const TipoInforme: String;
|
|
|
|
|
|
const IdEmpresa: Integer; const FechaInicio, FechaFin: DateTime;
|
|
|
|
|
|
const ListaIDClientes: TIntegerArray; const ImporteMinimo: Currency): Binary;
|
|
|
|
|
|
var
|
|
|
|
|
|
Condicion: TDAWhereExpression;
|
|
|
|
|
|
i: Integer;
|
2008-11-26 19:12:42 +00:00
|
|
|
|
AInforme: Variant;
|
2008-11-14 20:04:09 +00:00
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := Binary.Create;
|
|
|
|
|
|
FConnection.BeginTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
|
|
|
|
|
|
|
|
|
|
|
try
|
2008-10-03 17:15:51 +00:00
|
|
|
|
|
2008-11-14 20:04:09 +00:00
|
|
|
|
if tbl_InformeListadoPresupuestos.Active then
|
|
|
|
|
|
tbl_InformeListadoPresupuestos.Active := False;
|
|
|
|
|
|
|
|
|
|
|
|
// Filtrar el informe por empresa
|
|
|
|
|
|
with tbl_InformeListadoPresupuestos.DynamicWhere do
|
|
|
|
|
|
begin
|
|
|
|
|
|
// (ID_EMPRESA >= ID)
|
|
|
|
|
|
Condicion := NewBinaryExpression(NewField('', fld_PresupuestosClienteID_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_InformeListadoPresupuestos.DynamicWhere do
|
|
|
|
|
|
begin
|
|
|
|
|
|
// (FECHA_INICIO between FECHA_FIN)
|
|
|
|
|
|
Condicion := NewBinaryExpression(NewField('', fld_PresupuestosClienteFECHA_PRESUPUESTO), NewConstant(FechaInicio, datDateTime), dboGreaterOrEqual);
|
|
|
|
|
|
Condicion := NewBinaryExpression(NewBinaryExpression(NewField('', fld_PresupuestosClienteFECHA_PRESUPUESTO), 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_InformeListadoPresupuestos.DynamicWhere do
|
|
|
|
|
|
begin
|
|
|
|
|
|
for i := 0 to ListaIDClientes.Count - 1 do
|
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
|
|
|
|
// (ID_CLIENTE = ID)
|
|
|
|
|
|
Condicion := NewBinaryExpression(NewField('', fld_PresupuestosClienteID_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_InformeListadoPresupuestos.DynamicWhere do
|
|
|
|
|
|
begin
|
|
|
|
|
|
// (IMPORTE_TOTAL > ImporteMinimo)
|
|
|
|
|
|
Condicion := NewBinaryExpression(NewField('', fld_PresupuestosClienteIMPORTE_TOTAL), NewConstant(ImporteMinimo, datCurrency), dboGreaterOrEqual);
|
|
|
|
|
|
if IsEmpty then
|
|
|
|
|
|
Expression := Condicion
|
|
|
|
|
|
else
|
|
|
|
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tbl_InformeListadoPresupuestos.Active := True;
|
|
|
|
|
|
|
2008-11-26 19:12:42 +00:00
|
|
|
|
AInforme := DarRutaFichero(DarRutaInformes, TipoInforme, tbl_InformeListadoPresupuestos.FieldByName('ID_EMPRESA').AsString);
|
|
|
|
|
|
if VarIsNull(AInforme) then
|
|
|
|
|
|
raise Exception.Create (('Error Servidor: _GenerarInforme, no encuentra informe' + TipoInforme));
|
|
|
|
|
|
|
|
|
|
|
|
frxReport.LoadFromFile(AInforme, True);
|
2008-11-14 20:04:09 +00:00
|
|
|
|
frxReport.Variables.Variables['FechaInicio'] := FechaInicio;
|
|
|
|
|
|
frxReport.Variables.Variables['FechaFin'] := FechaFin;
|
2007-11-28 17:40:31 +00:00
|
|
|
|
|
2008-11-14 20:04:09 +00:00
|
|
|
|
frxReport.PrepareReport(False);
|
|
|
|
|
|
frxReport.PreviewPages.SaveToStream(Result);
|
|
|
|
|
|
|
|
|
|
|
|
finally
|
|
|
|
|
|
FConnection.RollbackTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
|
|
|
|
|
end;
|
2007-11-28 17:40:31 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2008-10-03 17:15:51 +00:00
|
|
|
|
procedure TRptPresupuestosCliente._GenerarPresupuesto(const AID: Integer);
|
2008-11-26 19:12:42 +00:00
|
|
|
|
var
|
|
|
|
|
|
AInforme: Variant;
|
|
|
|
|
|
|
2007-11-28 17:40:31 +00:00
|
|
|
|
begin
|
2008-11-14 20:04:09 +00:00
|
|
|
|
FConnection.BeginTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
2008-11-12 16:06:28 +00:00
|
|
|
|
try
|
2008-11-14 20:04:09 +00:00
|
|
|
|
tbl_Cabecera.Active := False;
|
|
|
|
|
|
tbl_Detalles.Active := False;
|
2007-11-28 17:40:31 +00:00
|
|
|
|
tbl_Cabecera.ParamByName('ID').AsInteger := AID;
|
|
|
|
|
|
tbl_Detalles.ParamByName('ID').AsInteger := AID;
|
|
|
|
|
|
tbl_Cabecera.Active := True;
|
|
|
|
|
|
tbl_Detalles.Active := True;
|
|
|
|
|
|
|
2008-11-26 19:12:42 +00:00
|
|
|
|
AInforme := DarRutaFichero(DarRutaInformes, rptInforme, tbl_Cabecera.FieldByName('ID_EMPRESA').AsString, tbl_Cabecera.FieldByName('ID_TIENDA').AsString);
|
|
|
|
|
|
if VarIsNull(AInforme) then
|
|
|
|
|
|
raise Exception.Create (('Error Servidor: _GenerarPresupuesto, no encuentra informe' + rptInforme));
|
|
|
|
|
|
|
|
|
|
|
|
frxReport.LoadFromFile(AInforme, True);
|
2007-11-28 17:40:31 +00:00
|
|
|
|
frxReport.PrepareReport(False);
|
2008-11-12 16:06:28 +00:00
|
|
|
|
finally
|
2008-11-14 20:04:09 +00:00
|
|
|
|
FConnection.RollbackTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
2008-11-12 16:06:28 +00:00
|
|
|
|
end;
|
2007-11-28 17:40:31 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end.
|