From a8fd42f4dfa4c198f03e03017384b90bcfe4eb53 Mon Sep 17 00:00:00 2001 From: roberto Date: Fri, 23 Jan 2009 17:54:44 +0000 Subject: [PATCH] Informes de pedidos de proveedor adaptados al resumen git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@881 0c75b7a4-871f-7646-8a2f-f78d34cc349f --- Source/Base/Base.dproj | 102 +++---- Source/Informes/1/InformeListadoPedidos.fr3 | 65 +++-- .../1/InformeListadoPedidosDesglosado.fr3 | 75 +++-- Source/Informes/2/InformeListadoPedidos.fr3 | 65 +++-- .../2/InformeListadoPedidosDesglosado.fr3 | 73 +++-- .../Views/uEditorInformePedidosReport.dfm | 3 + .../uEditorInformePresupuestosReport.pas | 6 +- .../Views/uGestorInformesViewRegister.pas | 4 +- .../Reports/uRptPedidosProveedor_Server.dfm | 211 +++++++++----- .../Reports/uRptPedidosProveedor_Server.pas | 270 ++++++++++++------ .../uRptPresupuestosCliente_Server.pas | 2 +- 11 files changed, 540 insertions(+), 336 deletions(-) diff --git a/Source/Base/Base.dproj b/Source/Base/Base.dproj index 33f14f33..e686c9e1 100644 --- a/Source/Base/Base.dproj +++ b/Source/Base/Base.dproj @@ -54,57 +54,57 @@ MainSource - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
fConfigurarConexion
diff --git a/Source/Informes/1/InformeListadoPedidos.fr3 b/Source/Informes/1/InformeListadoPedidos.fr3 index 2fc4c9e1..c3d0a961 100644 --- a/Source/Informes/1/InformeListadoPedidos.fr3 +++ b/Source/Informes/1/InformeListadoPedidos.fr3 @@ -1,43 +1,56 @@ - + - - + + - - - + + + - + - + - + - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - + + + + + + + + + + + + + + + + diff --git a/Source/Informes/1/InformeListadoPedidosDesglosado.fr3 b/Source/Informes/1/InformeListadoPedidosDesglosado.fr3 index 3e7756d6..d0ce0f48 100644 --- a/Source/Informes/1/InformeListadoPedidosDesglosado.fr3 +++ b/Source/Informes/1/InformeListadoPedidosDesglosado.fr3 @@ -1,47 +1,60 @@ - + - - + + - - - + + + - + - + + - + - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + - - - + + + - - - + + + + + + + + + + + + + + + - + diff --git a/Source/Informes/2/InformeListadoPedidos.fr3 b/Source/Informes/2/InformeListadoPedidos.fr3 index 7add131f..6e4c9fc5 100644 --- a/Source/Informes/2/InformeListadoPedidos.fr3 +++ b/Source/Informes/2/InformeListadoPedidos.fr3 @@ -1,43 +1,56 @@ - + - - + + - - - + + + - + - + - + - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - + + + + + + + + + + + + + + + + diff --git a/Source/Informes/2/InformeListadoPedidosDesglosado.fr3 b/Source/Informes/2/InformeListadoPedidosDesglosado.fr3 index 732fa824..61a44250 100644 --- a/Source/Informes/2/InformeListadoPedidosDesglosado.fr3 +++ b/Source/Informes/2/InformeListadoPedidosDesglosado.fr3 @@ -1,47 +1,60 @@ - + - - + + - - - + + + - + - + + - + - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - + + + - - - + + + + + + + + + + + + + + + - + diff --git a/Source/Modulos/Gestor de informes/Views/uEditorInformePedidosReport.dfm b/Source/Modulos/Gestor de informes/Views/uEditorInformePedidosReport.dfm index ad6bcb1d..c690c0c8 100644 --- a/Source/Modulos/Gestor de informes/Views/uEditorInformePedidosReport.dfm +++ b/Source/Modulos/Gestor de informes/Views/uEditorInformePedidosReport.dfm @@ -178,6 +178,9 @@ inherited fEditorInformePedidosReport: TfEditorInformePedidosReport inherited TBXAlignmentPanel1: TTBXAlignmentPanel Width = 182 ExplicitWidth = 182 + inherited cbxDesglosado: TCheckBox + Caption = 'Solo pedidos que superen:' + end inherited eImporte: TcxSpinEdit Style.LookAndFeel.SkinName = '' StyleDisabled.LookAndFeel.SkinName = '' diff --git a/Source/Modulos/Gestor de informes/Views/uEditorInformePresupuestosReport.pas b/Source/Modulos/Gestor de informes/Views/uEditorInformePresupuestosReport.pas index 42701e98..c5ec706d 100644 --- a/Source/Modulos/Gestor de informes/Views/uEditorInformePresupuestosReport.pas +++ b/Source/Modulos/Gestor de informes/Views/uEditorInformePresupuestosReport.pas @@ -49,7 +49,7 @@ implementation {$R *.dfm} -uses uROTypes, uGestorInformesController, uFactuGES_App; +uses uROTypes, DateUtils, uGestorInformesController, uFactuGES_App; { TfEditorGestorInformesReport } @@ -82,6 +82,10 @@ end; function TfEditorInformePresupuestosReport.GetFechaFin: Variant; begin Result := frViewPeriodoFechas1.edtFechaFin.EditValue; + + //Esto es para quitar la hora del timestamp para que luego no me redondee al dia siguiente + if not VarIsNull(Result) then + Result := DateOf(frViewPeriodoFechas1.edtFechaFin.Date); end; function TfEditorInformePresupuestosReport.GetFechaInicio: Variant; diff --git a/Source/Modulos/Gestor de informes/Views/uGestorInformesViewRegister.pas b/Source/Modulos/Gestor de informes/Views/uGestorInformesViewRegister.pas index 30f52964..8c2f0a6a 100644 --- a/Source/Modulos/Gestor de informes/Views/uGestorInformesViewRegister.pas +++ b/Source/Modulos/Gestor de informes/Views/uGestorInformesViewRegister.pas @@ -11,7 +11,7 @@ uses uEditorRegistryUtils, uEditorInformeIVAClientesReport, uEditorInformeFacturasClienteReport, uEditorInformeFacturasClientePendientesReport, uEditorInformeRecibosClienteReport, uEditorInformeRecibosCliPendientesReport, - uEditorInformePresupuestosReport, + uEditorInformePresupuestosReport, uEditorInformePedidosReport, uEditorInformeIVAProveedoresReport, uEditorInformeFacturasProveedorReport, uEditorInformeFacturasProveedorPendientesReport, uEditorInformeRecibosProveedorReport, uEditorInformeRecibosProvPendientesReport; @@ -19,6 +19,7 @@ uses procedure RegisterViews; begin EditorRegistry.RegisterClass(TfEditorInformePresupuestosReport, 'EditorInformePresupuestosReport'); + EditorRegistry.RegisterClass(TfEditorInformePedidosReport, 'EditorInformePedidosReport'); EditorRegistry.RegisterClass(TfEditorInformeIVAClientesReport, 'EditorInformeIVAClientesReport'); EditorRegistry.RegisterClass(TfEditorInformeFacturasClienteReport, 'EditorInformeFacturasClienteReport'); EditorRegistry.RegisterClass(TfEditorInformeFacturasClientePendientesReport, 'EditorInformeFacturasClientePendientesReport'); @@ -35,6 +36,7 @@ end; procedure UnregisterViews; begin EditorRegistry.UnRegisterClass(TfEditorInformePresupuestosReport); + EditorRegistry.UnRegisterClass(TfEditorInformePedidosReport); EditorRegistry.UnRegisterClass(TfEditorInformeIVAClientesReport); EditorRegistry.UnRegisterClass(TfEditorInformeFacturasClienteReport); EditorRegistry.UnRegisterClass(TfEditorInformeFacturasClientePendientesReport); diff --git a/Source/Modulos/Pedidos a proveedor/Reports/uRptPedidosProveedor_Server.dfm b/Source/Modulos/Pedidos a proveedor/Reports/uRptPedidosProveedor_Server.dfm index f1308056..31907263 100644 --- a/Source/Modulos/Pedidos a proveedor/Reports/uRptPedidosProveedor_Server.dfm +++ b/Source/Modulos/Pedidos a proveedor/Reports/uRptPedidosProveedor_Server.dfm @@ -3,10 +3,6 @@ object RptPedidosProveedor: TRptPedidosProveedor OnCreate = DataModuleCreate Height = 522 Width = 766 - object DABINAdapter: TDABINAdapter - Left = 48 - Top = 80 - end object schReport: TDASchema ConnectionManager = dmServer.ConnectionManager DataDictionary = DataDictionary @@ -472,6 +468,85 @@ object RptPedidosProveedor: TRptPedidosProveedor Size = 255 end> ReadOnly = True + end + item + Params = <> + Statements = < + item + Connection = 'IBX' + TargetTable = 'V_PEDIDOS_PROVEEDOR' + SQL = + #10' '#10'select ID_EMPRESA,'#10'extract (year from fecha_pedido) as ANO,'#10 + + 'extract (month from fecha_pedido) as MES,'#10'case'#10'when extract (mon' + + 'th from fecha_pedido) = 1 then '#39'ENERO - '#39' || extract (year from ' + + 'fecha_pedido)'#10'when extract (month from fecha_pedido) = 2 then '#39'F' + + 'EBRERO - '#39' || extract (year from fecha_pedido)'#10'when extract (mon' + + 'th from fecha_pedido) = 3 then '#39'MARZO - '#39' || extract (year from ' + + 'fecha_pedido)'#10'when extract (month from fecha_pedido) = 4 then '#39'A' + + 'BRIL - '#39' || extract (year from fecha_pedido)'#10'when extract (month' + + ' from fecha_pedido) = 5 then '#39'MAYO - '#39' || extract (year from fec' + + 'ha_pedido)'#10'when extract (month from fecha_pedido) = 6 then '#39'JUNI' + + 'O - '#39' || extract (year from fecha_pedido)'#10'when extract (month fr' + + 'om fecha_pedido) = 7 then '#39'JULIO - '#39' || extract (year from fecha' + + '_pedido)'#10'when extract (month from fecha_pedido) = 8 then '#39'AGOSTO' + + ' - '#39' || extract (year from fecha_pedido)'#10'when extract (month fro' + + 'm fecha_pedido) = 9 then '#39'SEPTIEMBRE - '#39' || extract (year from f' + + 'echa_pedido)'#10'when extract (month from fecha_pedido) = 10 then '#39'O' + + 'CTUBRE - '#39' || extract (year from fecha_pedido)'#10'when extract (mon' + + 'th from fecha_pedido) = 11 then '#39'NOVIEMBRE - '#39' || extract (year ' + + 'from fecha_pedido)'#10'when extract (month from fecha_pedido) = 12 t' + + 'hen '#39'DICIEMBRE - '#39' || extract (year from fecha_pedido)'#10'end as TI' + + 'TULO,'#10'sum(IMPORTE_TOTAL) as importe_total'#10#10'from V_PEDIDOS_PROVEE' + + 'DOR'#10'group by 1,2,3,4'#10'order by ANO, MES'#10 + StatementType = stSQL + ColumnMappings = < + item + DatasetField = 'ID_EMPRESA' + TableField = 'ID_EMPRESA' + end + item + DatasetField = 'ANO' + TableField = '' + SQLOrigin = 'ANO' + end + item + DatasetField = 'MES' + TableField = '' + SQLOrigin = 'MES' + end + item + DatasetField = 'TITULO' + TableField = '' + SQLOrigin = 'TITULO' + end + item + DatasetField = 'IMPORTE_TOTAL' + TableField = 'IMPORTE_TOTAL' + end> + end> + Name = 'InformeListadoPedidosResumen' + Fields = < + item + Name = 'ID_EMPRESA' + DataType = datInteger + end + item + Name = 'ANO' + DataType = datSmallInt + end + item + Name = 'MES' + DataType = datSmallInt + end + item + Name = 'TITULO' + DataType = datString + Size = 19 + end + item + Name = 'IMPORTE_TOTAL' + DataType = datCurrency + end> end> JoinDataTables = <> UnionDataTables = <> @@ -496,68 +571,17 @@ object RptPedidosProveedor: TRptPedidosProveedor PreviewOptions.Zoom = 1.000000000000000000 PrintOptions.Printer = 'Por defecto' PrintOptions.PrintOnSheet = 0 - ReportOptions.CreateDate = 39065.872423495400000000 - ReportOptions.LastChange = 39827.743311446760000000 + ReportOptions.CreateDate = 37800.807714351900000000 + ReportOptions.LastChange = 39836.753662280090000000 ScriptLanguage = 'PascalScript' ScriptText.Strings = ( - '' - 'procedure DatosEmpresaOnBeforePrint(Sender: TfrxComponent);' - 'var' - ' Cadena: String;' + 'procedure frxReportOnStartReport(Sender: TfrxComponent);' 'begin' - '{ DatosEmpresa.Lines.Clear;' - ' if ( <> '#39#39') then' - ' Cadena := '#39'TLF: '#39' + ;' - ' if ( <> '#39#39') then' - - ' Cadena := Cadena + '#39' FAX: '#39' + ;' - ' DatosEmpresa.Lines.Add(Cadena);' - '}' + ' Set('#39'Pagina'#39', 0);' + ' Set('#39'TotalPaginas'#39', 0); ' 'end;' '' - 'procedure NombreEmpresaOnBeforePrint(Sender: TfrxComponent);' - 'begin' - '{ NombreEmpresa.Lines.Clear;' - ' NombreEmpresa.Lines.Add();' - '}' - 'end;' - '' - 'procedure Memo11OnBeforePrint(Sender: TfrxComponent);' - 'begin' - ' if = 0 then' - - ' Memo11.Visible := False ' + - ' ' - ' else' - ' Memo11.Visible := True; ' - 'end;' - '' - 'procedure Memo35OnBeforePrint(Sender: TfrxComponent);' - 'begin' - - ' if not then ' + - ' ' - ' Memo35.Lines.Clear; ' - 'end;' - '' - 'procedure Memo36OnBeforePrint(Sender: TfrxComponent);' - 'begin' - - ' if not then ' + - ' ' - ' Memo36.Lines.Clear; ' - 'end;' - '' - 'procedure Memo6OnBeforePrint(Sender: TfrxComponent);' - 'begin' - - ' if not then ' + - ' ' - ' Memo6.Lines.Clear; ' - 'end;' - '' - 'procedure PageHeader2OnBeforePrint(Sender: TfrxComponent);' + 'procedure Band1OnBeforePrint(Sender: TfrxComponent);' 'begin' ' if not Engine.FinalPass then' ' Set('#39'TotalPaginas'#39', ( + 1));' @@ -566,18 +590,26 @@ object RptPedidosProveedor: TRptPedidosProveedor ' Set('#39'Pagina'#39', ( + 1)); ' 'end;' '' - 'procedure frxReportOnStartReport(Sender: TfrxComponent);' - 'begin' - ' Set('#39'Pagina'#39', 0);' - ' Set('#39'TotalPaginas'#39', 0); ' - 'end;' - '' - 'procedure Memo34OnBeforePrint(Sender: TfrxComponent);' + 'procedure mContinuaOnBeforePrint(Sender: TfrxComponent);' 'begin' + ' if Engine.FinalPass then' + ' begin' - ' if not then ' + - ' ' - ' Memo34.Lines.Clear; ' + ' //A la vez que salta este salta la asignacion de pagina por ' + + 'lo que no coincide nunca si no suponemos +1 ' + + ' ' + + ' ' + + ' ' + + ' ' + ' if (( + 1) = ) then' + ' begin ' + ' mContinua.Visible := True;' + ' end ' + ' else' + ' begin ' + ' mContinua.Visible := False;' + ' end ' + ' end; ' 'end;' '' 'begin' @@ -913,7 +945,7 @@ object RptPedidosProveedor: TRptPedidosProveedor StreamingOptions = [soDisableEventsWhileStreaming] RemoteFetchEnabled = False LocalSchema = schReport - LocalDataStreamer = DABINAdapter + LocalDataStreamer = DABin2DataStreamer1 DetailFields = 'ID_PEDIDO' DetailOptions = [dtCascadeOpenClose, dtCascadeApplyUpdates, dtAutoFetch, dtCascadeDelete, dtCascadeUpdate, dtDisableLogOfCascadeDeletes, dtDisableLogOfCascadeUpdates, dtIncludeInAllInOneFetch] MasterOptions = [moCascadeOpenClose, moCascadeApplyUpdates, moCascadeDelete, moCascadeUpdate, moDisableLogOfCascadeDeletes, moDisableLogOfCascadeUpdates] @@ -1005,7 +1037,7 @@ object RptPedidosProveedor: TRptPedidosProveedor StreamingOptions = [soDisableEventsWhileStreaming] RemoteFetchEnabled = False LocalSchema = schReport - LocalDataStreamer = DABINAdapter + LocalDataStreamer = DABin2DataStreamer1 DetailOptions = [dtCascadeOpenClose, dtCascadeApplyUpdates, dtAutoFetch, dtCascadeDelete, dtCascadeUpdate, dtDisableLogOfCascadeDeletes, dtDisableLogOfCascadeUpdates, dtIncludeInAllInOneFetch] MasterOptions = [moCascadeOpenClose, moCascadeApplyUpdates, moCascadeDelete, moCascadeUpdate, moDisableLogOfCascadeDeletes, moDisableLogOfCascadeUpdates] LogicalName = 'Informe_Cabecera' @@ -1096,7 +1128,7 @@ object RptPedidosProveedor: TRptPedidosProveedor StreamingOptions = [soDisableEventsWhileStreaming] RemoteFetchEnabled = False LocalSchema = schReport - LocalDataStreamer = DABINAdapter + LocalDataStreamer = DABin2DataStreamer1 DetailOptions = [dtCascadeOpenClose, dtCascadeApplyUpdates, dtAutoFetch, dtCascadeDelete, dtCascadeUpdate, dtDisableLogOfCascadeDeletes, dtDisableLogOfCascadeUpdates, dtIncludeInAllInOneFetch] MasterOptions = [moCascadeOpenClose, moCascadeApplyUpdates, moCascadeDelete, moCascadeUpdate, moDisableLogOfCascadeDeletes, moDisableLogOfCascadeUpdates] LogicalName = 'InformeListadoPedidos' @@ -1104,4 +1136,35 @@ object RptPedidosProveedor: TRptPedidosProveedor Left = 600 Top = 136 end + object frxDBInformeListadoPedidosResumen: TfrxDBDataset + UserName = 'frxDBInformeListadoPedidosResumen' + CloseDataSource = True + DataSource = DADSInformeListadoPedidosResumen + Left = 600 + Top = 208 + end + object DADSInformeListadoPedidosResumen: TDADataSource + DataSet = tbl_InformeListadoPedidosResumen.Dataset + DataTable = tbl_InformeListadoPedidosResumen + Left = 600 + Top = 264 + end + object tbl_InformeListadoPedidosResumen: TDAMemDataTable + RemoteUpdatesOptions = [] + Fields = <> + Params = <> + MasterMappingMode = mmDataRequest + LogChanges = False + StreamingOptions = [soDisableEventsWhileStreaming] + RemoteFetchEnabled = False + DetailOptions = [dtCascadeOpenClose, dtCascadeApplyUpdates, dtAutoFetch, dtCascadeDelete, dtCascadeUpdate, dtDisableLogOfCascadeDeletes, dtDisableLogOfCascadeUpdates, dtIncludeInAllInOneFetch] + MasterOptions = [moCascadeOpenClose, moCascadeApplyUpdates, moCascadeDelete, moCascadeUpdate, moDisableLogOfCascadeDeletes, moDisableLogOfCascadeUpdates] + IndexDefs = <> + Left = 600 + Top = 320 + end + object DABin2DataStreamer1: TDABin2DataStreamer + Left = 48 + Top = 80 + end end diff --git a/Source/Modulos/Pedidos a proveedor/Reports/uRptPedidosProveedor_Server.pas b/Source/Modulos/Pedidos a proveedor/Reports/uRptPedidosProveedor_Server.pas index 49e6dda1..6a49322f 100644 --- a/Source/Modulos/Pedidos a proveedor/Reports/uRptPedidosProveedor_Server.pas +++ b/Source/Modulos/Pedidos a proveedor/Reports/uRptPedidosProveedor_Server.pas @@ -8,11 +8,10 @@ uses uDADataTable, uDACDSDataTable, DB, uDAClasses, frxChart, frxGradient, frxChBox, frxCross, frxOLE, frxBarcode, frxRich, uDABINAdapter, uROTypes, uDAInterfaces, uDADataStreamer, IBCustomDataSet, IBQuery, IBDatabase, - uDAMemDataTable, frxExportPDF, FactuGES_Intf; + uDAMemDataTable, frxExportPDF, FactuGES_Intf, uDABin2DataStreamer; type TRptPedidosProveedor = class(TDataModule) - DABINAdapter: TDABINAdapter; frxDBCabecera: TfrxDBDataset; frxDBDetalles: TfrxDBDataset; frxReport: TfrxReport; @@ -63,16 +62,29 @@ type frxDBInformeListadoPedidos: TfrxDBDataset; DADSInformeListadoPedidos: TDADataSource; tbl_InformeListadoPedidos: TDAMemDataTable; + frxDBInformeListadoPedidosResumen: TfrxDBDataset; + DADSInformeListadoPedidosResumen: TDADataSource; + tbl_InformeListadoPedidosResumen: TDAMemDataTable; schReport: TDASchema; DataDictionary: TDADataDictionary; + DABin2DataStreamer1: TDABin2DataStreamer; procedure DataModuleCreate(Sender: TObject); procedure frxReportGetValue(const VarName: string; var Value: Variant); private FConnection: IDAConnection; + FIdEmpresa: Integer; + FFechaInicio: Variant; + FFechaFin: Variant; + FListaIDProveedores: TIntegerArray; + FImporteMinimo: Currency; FImprimirPrecio : Boolean; FImprimirRefProveedor : Boolean; + procedure _GenerarPedido(const ID : Integer); - function _GenerarInforme(const TipoInforme: String; const IdEmpresa: Integer; const FechaInicio: DateTime; const FechaFin: DateTime; const ListaIDClientes: TIntegerArray; const ImporteMinimo: Currency): Binary; + + procedure PrepararTablaInforme(ATabla: TDAMemDataTable); + procedure PrepararTablaResumenInforme(ATabla: IDADataset); + function _GenerarInforme(const TipoInforme: String): Binary; public function GenerarPedido(const ListaID : TIntegerArray; @@ -83,7 +95,7 @@ type const ImprimirPrecio: Boolean = True; const ImprimirRefProveedor: Boolean = True): Binary; - function GenerarInformeListadoPedidos(const IdEmpresa: Integer; const FechaInicio, FechaFin: DateTime; const ListaIDProveedores: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary; + function GenerarInformeListadoPedidos(const IdEmpresa: Integer; const FechaInicio, FechaFin: Variant; const ListaIDProveedores: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary; end; implementation @@ -91,7 +103,7 @@ implementation {$R *.dfm} uses - uSistemaFunc, uDataModuleServer, schPedidosProveedorClient_Intf; + uSistemaFunc, StrUtils, uDataModuleServer, schPedidosProveedorClient_Intf; const rptInforme = 'InfPedidoProveedor.fr3'; @@ -99,6 +111,7 @@ const rptInformeListadoPedidos = 'InformeListadoPedidos.fr3'; { Dataset names for schReport } + ds_InformeListadoPedidosResumen = 'InformeListadoPedidosResumen'; ds_InformeCabecera = 'Informe_Cabecera'; ds_InformeDetalles = 'Informe_Detalles'; @@ -114,7 +127,6 @@ begin frxDBCabecera.DataSource := DADSCabecera; frxDBDetalles.DataSource := DADSDetalles; - end; procedure TRptPedidosProveedor.frxReportGetValue(const VarName: string; @@ -127,22 +139,61 @@ begin end; function TRptPedidosProveedor.GenerarInformeListadoPedidos( - const IdEmpresa: Integer; const FechaInicio, FechaFin: DateTime; + const IdEmpresa: Integer; const FechaInicio, FechaFin: Variant; const ListaIDProveedores: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary; var ATipoInforme: String; + AStream: TMemoryStream; + dsMaster: IDADataset; begin + FConnection.BeginTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO" -//DESGLOSADO POR CLIENTE EN ESTE INFORME NO SE DESGLOSARÁ POR CLIENTE + AStream := TMemoryStream.Create; + try + //Inicializamos parametros + FIdEmpresa := IdEmpresa; + FFechaInicio := FechaInicio; + FFechaFin := FechaFin; + FImporteMinimo := ImporteMinimo; + + if Assigned(FListaIDProveedores) then + FListaIDProveedores.Free; + FListaIDProveedores := ListaIDProveedores; + + if tbl_InformeListadoPedidos.Active then + tbl_InformeListadoPedidos.Active := False; + PrepararTablaInforme(tbl_InformeListadoPedidos); + + //Se prepara la tabla del listado resumen del informe + if tbl_InformeListadoPedidosResumen.Active then + tbl_InformeListadoPedidosResumen.Active := False; + dsMaster := schReport.NewDataset(FConnection, ds_InformeListadoPedidosResumen, [], [], False); + PrepararTablaResumenInforme(dsMaster); + //Esto se hace para rellenar la tabla del datamodule que usa el informe. + dsMaster.Open; + AStream.Clear; + DABin2DataStreamer1.WriteDataset(AStream, dsMaster, [woRows, woSchema], -1); + DABin2DataStreamer1.ReadDataset(AStream, tbl_InformeListadoPedidosResumen, TRUE, '', TRUE, TRUE); + + //DESGLOSADO POR PROVEEDOR EN ESTE INFORME NO SE DESGLOSARÁ POR PROVEEDOR if Desglosado then ATipoInforme := rptInformeListadoPedidosDesglosado else ATipoInforme := rptInformeListadoPedidos; - Result := _GenerarInforme(ATipoInforme, IdEmpresa, FechaInicio, FechaFin, ListaIDProveedores, ImporteMinimo); + //Finalmente se abren las tablas del informe + tbl_InformeListadoPedidos.Active := True; + tbl_InformeListadoPedidosResumen.Active := True; + Result := _GenerarInforme(ATipoInforme); + + finally + AStream.Free; + dsMaster := Nil; + FConnection.RollbackTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO" + end; end; function TRptPedidosProveedor.GenerarPedido(const ListaID : TIntegerArray; @@ -164,99 +215,22 @@ begin end; end; -function TRptPedidosProveedor._GenerarInforme(const TipoInforme: String; - const IdEmpresa: Integer; const FechaInicio, FechaFin: DateTime; - const ListaIDClientes: TIntegerArray; const ImporteMinimo: Currency): Binary; +function TRptPedidosProveedor._GenerarInforme(const TipoInforme: String): 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" + AInforme := DarRutaFichero(DarRutaInformes, TipoInforme, IntToStr(FIdEmpresa)); + if VarIsNull(AInforme) then + raise Exception.Create (('Error Servidor: _GenerarInforme, no encuentra informe ' + TipoInforme)); - try + frxReport.LoadFromFile(AInforme, True); + frxReport.Variables.Variables['FechaInicio'] := FFechaInicio; + frxReport.Variables.Variables['FechaFin'] := FFechaFin; - if tbl_InformeListadoPedidos.Active then - tbl_InformeListadoPedidos.Active := False; - - // Filtrar el informe por empresa - with tbl_InformeListadoPedidos.DynamicWhere do - begin - // (ID_EMPRESA >= ID) - Condicion := NewBinaryExpression(NewField('', fld_PedidosProveedorID_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_InformeListadoPedidos.DynamicWhere do - begin - // (FECHA_INICIO between FECHA_FIN) - Condicion := NewBinaryExpression(NewField('', fld_PedidosProveedorFECHA_PEDIDO), NewConstant(FechaInicio, datDateTime), dboGreaterOrEqual); - Condicion := NewBinaryExpression(NewBinaryExpression(NewField('', fld_PedidosProveedorFECHA_PEDIDO), 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_InformeListadoPedidos.DynamicWhere do - begin - for i := 0 to ListaIDClientes.Count - 1 do - begin - - // (ID_CLIENTE = ID) - Condicion := NewBinaryExpression(NewField('', fld_PedidosProveedorID_PROVEEDOR), 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_InformeListadoPedidos.DynamicWhere do - begin - // (IMPORTE_TOTAL > ImporteMinimo) - Condicion := NewBinaryExpression(NewField('', fld_PedidosProveedorIMPORTE_TOTAL), NewConstant(ImporteMinimo, datCurrency), dboGreaterOrEqual); - if IsEmpty then - Expression := Condicion - else - Expression := NewBinaryExpression(Expression, Condicion, dboAnd); - end; - end; - - - tbl_InformeListadoPedidos.Active := True; - - AInforme := DarRutaFichero(DarRutaInformes, TipoInforme, IntToStr(IdEmpresa)); - 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; + frxReport.PrepareReport(False); + frxReport.PreviewPages.SaveToStream(Result); end; procedure TRptPedidosProveedor._GenerarPedido(const ID: Integer); @@ -306,4 +280,110 @@ begin end; +procedure TRptPedidosProveedor.PrepararTablaInforme(ATabla: TDAMemDataTable); +var + Condicion: TDAWhereExpression; + i: Integer; + +begin + // Filtrar el informe por empresa + with ATabla.DynamicWhere do + begin + // (ID_EMPRESA >= ID) + Condicion := NewBinaryExpression(NewField('', fld_PedidosProveedorID_EMPRESA), NewConstant(FIdEmpresa, datInteger), dboEqual); + if IsEmpty then + Expression := Condicion + else + Expression := NewBinaryExpression(Expression, Condicion, dboAnd); + end; + + // Filtrar el informe por fechas + if not VarIsNull(FFechaInicio) + and not VarIsNull(FFechaFin) then + begin + with ATabla.DynamicWhere do + begin + // (FECHA_INICIO between FECHA_FIN) + Condicion := NewBinaryExpression(NewField('', fld_PedidosProveedorFECHA_PEDIDO), NewConstant(FFechaInicio, datDateTime), dboGreaterOrEqual); + Condicion := NewBinaryExpression(NewBinaryExpression(NewField('', fld_PedidosProveedorFECHA_PEDIDO), NewConstant(FFechaFin, datDateTime), dboLessOrEqual), Condicion, dboAnd); + if IsEmpty then + Expression := Condicion + else + Expression := NewBinaryExpression(Expression, Condicion, dboAnd); + end; + end; + + // Filtrar el informe por proveedor + if Assigned(FListaIDProveedores) then + begin + with ATabla.DynamicWhere do + begin + for i := 0 to FListaIDProveedores.Count - 1 do + begin + + // (ID_PROVEEDOR = ID) + Condicion := NewBinaryExpression(NewField('', fld_PedidosProveedorID_PROVEEDOR), NewConstant(FListaIDProveedores.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 (FImporteMinimo > 0) then + begin + with ATabla.DynamicWhere do + begin + // (IMPORTE_TOTAL > ImporteMinimo) + Condicion := NewBinaryExpression(NewField('', fld_PedidosProveedorIMPORTE_TOTAL), NewConstant(FImporteMinimo, datCurrency), dboGreaterOrEqual); + if IsEmpty then + Expression := Condicion + else + Expression := NewBinaryExpression(Expression, Condicion, dboAnd); + end; + end; +end; + +procedure TRptPedidosProveedor.PrepararTablaResumenInforme(ATabla: IDADataset); +var + i: Integer; + AWhereStr : String; + +begin + // Filtrar el informe por empresa + AWhereStr := ' (' + fld_PedidosProveedorID_EMPRESA + ' = ' + IntToStr(FIdEmpresa) + ') '; + + // Filtrar el informe por fechas + if not VarIsNull(FFechaInicio) + and not VarIsNull(FFechaFin) then + begin + if Length(AWhereStr) > 0 then + AWhereStr := AWhereStr + 'AND'; + AWhereStr := AWhereStr + ' (' + fld_PedidosProveedorFECHA_PEDIDO + ' between ''' + ReplaceStr(VarToStr(FFechaInicio),'/','.') + ''' and ''' + ReplaceStr(VarToStr(FFechaFin),'/','.') + ''') '; + end; + + // Filtrar el informe por proveedor + if Assigned(FListaIDProveedores) then + begin + for i := 0 to FListaIDProveedores.Count - 1 do + begin + if Length(AWhereStr) > 0 then + AWhereStr := AWhereStr + 'AND'; + AWhereStr := AWhereStr + ' (' + fld_PedidosProveedorID_PROVEEDOR + ' = ' + IntToStr(FListaIDProveedores.Items[i]) + ') '; + end; + end; + + // Filtrar el informe por importe minimo + if (FImporteMinimo > 0) then + begin + if Length(AWhereStr) > 0 then + AWhereStr := AWhereStr + 'AND'; + AWhereStr := AWhereStr + ' (' + fld_PedidosProveedorIMPORTE_TOTAL + ' >= ' + CurrToStr(FImporteMinimo) + ') '; + end; + + ATabla.Where.AddText(AWhereStr); +end; + end. diff --git a/Source/Modulos/Presupuestos de cliente/Reports/uRptPresupuestosCliente_Server.pas b/Source/Modulos/Presupuestos de cliente/Reports/uRptPresupuestosCliente_Server.pas index 2840444f..86c64f7b 100644 --- a/Source/Modulos/Presupuestos de cliente/Reports/uRptPresupuestosCliente_Server.pas +++ b/Source/Modulos/Presupuestos de cliente/Reports/uRptPresupuestosCliente_Server.pas @@ -197,7 +197,7 @@ begin for i := 0 to FListaIDClientes.Count - 1 do begin - // (ID_PROVEEDOR = ID) + // (ID_CLIENTE = ID) Condicion := NewBinaryExpression(NewField('', fld_PresupuestosClienteID_CLIENTE), NewConstant(FListaIDClientes.Items[i], datInteger), dboEqual); if IsEmpty then Expression := Condicion