diff --git a/Source/Informes/1/InformeIVAClientes.fr3 b/Source/Informes/1/InformeIVAClientes.fr3 index f4e4f0fd..26ad5a3c 100644 --- a/Source/Informes/1/InformeIVAClientes.fr3 +++ b/Source/Informes/1/InformeIVAClientes.fr3 @@ -1,16 +1,14 @@ - + - - - - - + + + @@ -23,9 +21,9 @@ - + - + @@ -40,16 +38,15 @@ - - + - + diff --git a/Source/Informes/1/InformeIVAClientesDesglosado.fr3 b/Source/Informes/1/InformeIVAClientesDesglosado.fr3 index 4982acc5..a83d27e8 100644 --- a/Source/Informes/1/InformeIVAClientesDesglosado.fr3 +++ b/Source/Informes/1/InformeIVAClientesDesglosado.fr3 @@ -1,20 +1,17 @@ - + - - - - - + + + - @@ -24,9 +21,9 @@ - + - + @@ -46,10 +43,10 @@ - + - + diff --git a/Source/Informes/1/InformeListadoFacturasCliente.fr3 b/Source/Informes/1/InformeListadoFacturasCliente.fr3 index ce3b13a6..125e3a91 100644 --- a/Source/Informes/1/InformeListadoFacturasCliente.fr3 +++ b/Source/Informes/1/InformeListadoFacturasCliente.fr3 @@ -1,16 +1,14 @@ - + - + - - - + - + @@ -23,7 +21,7 @@ - + @@ -37,21 +35,20 @@ - - - - + + + + - - + - + diff --git a/Source/Informes/1/InformeListadoFacturasClienteDesglosado.fr3 b/Source/Informes/1/InformeListadoFacturasClienteDesglosado.fr3 index f2f5e806..87ba4bfd 100644 --- a/Source/Informes/1/InformeListadoFacturasClienteDesglosado.fr3 +++ b/Source/Informes/1/InformeListadoFacturasClienteDesglosado.fr3 @@ -1,16 +1,14 @@ - + - - - - - + + + @@ -24,7 +22,7 @@ - + @@ -38,20 +36,20 @@ - - - - + + + + - + - + @@ -63,7 +61,7 @@ - + diff --git a/Source/Informes/1/InformeListadoFacturasClientePendientes.fr3 b/Source/Informes/1/InformeListadoFacturasClientePendientes.fr3 index 3513dcb1..d606d18d 100644 --- a/Source/Informes/1/InformeListadoFacturasClientePendientes.fr3 +++ b/Source/Informes/1/InformeListadoFacturasClientePendientes.fr3 @@ -1,30 +1,28 @@ - + - - + - - - - + + + - + - + - + - + @@ -32,11 +30,10 @@ - + - diff --git a/Source/Informes/1/InformeListadoFacturasClientePendientesDesglosado.fr3 b/Source/Informes/1/InformeListadoFacturasClientePendientesDesglosado.fr3 index ffb77458..92daa207 100644 --- a/Source/Informes/1/InformeListadoFacturasClientePendientesDesglosado.fr3 +++ b/Source/Informes/1/InformeListadoFacturasClientePendientesDesglosado.fr3 @@ -1,30 +1,28 @@ - + - - + - - - - + + + - + - + - + - + @@ -32,15 +30,14 @@ - + - - - + + - + diff --git a/Source/Informes/2/InformeIVAClientes.fr3 b/Source/Informes/2/InformeIVAClientes.fr3 index 94b8e14b..80da615e 100644 --- a/Source/Informes/2/InformeIVAClientes.fr3 +++ b/Source/Informes/2/InformeIVAClientes.fr3 @@ -1,16 +1,14 @@ - + - - - - - + + + @@ -23,9 +21,9 @@ - + - + @@ -40,13 +38,12 @@ - - + @@ -55,7 +52,7 @@ - + diff --git a/Source/Informes/2/InformeIVAClientesDesglosado.fr3 b/Source/Informes/2/InformeIVAClientesDesglosado.fr3 index daa2a0f2..cf3e1e93 100644 --- a/Source/Informes/2/InformeIVAClientesDesglosado.fr3 +++ b/Source/Informes/2/InformeIVAClientesDesglosado.fr3 @@ -1,20 +1,17 @@ - + - - - - - + + + - @@ -24,9 +21,9 @@ - + - + @@ -46,7 +43,7 @@ - + @@ -55,13 +52,13 @@ - + - + diff --git a/Source/Informes/2/InformeListadoFacturasCliente.fr3 b/Source/Informes/2/InformeListadoFacturasCliente.fr3 index 4fe1c3c9..8f71b0f5 100644 --- a/Source/Informes/2/InformeListadoFacturasCliente.fr3 +++ b/Source/Informes/2/InformeListadoFacturasCliente.fr3 @@ -1,16 +1,14 @@ - + - - - - - + + + @@ -23,10 +21,10 @@ - + - + @@ -42,13 +40,12 @@ - - + @@ -57,7 +54,7 @@ - + diff --git a/Source/Informes/2/InformeListadoFacturasClienteDesglosado.fr3 b/Source/Informes/2/InformeListadoFacturasClienteDesglosado.fr3 index e40d04c3..59ac9229 100644 --- a/Source/Informes/2/InformeListadoFacturasClienteDesglosado.fr3 +++ b/Source/Informes/2/InformeListadoFacturasClienteDesglosado.fr3 @@ -1,20 +1,17 @@ - + - - - - - + + + - @@ -24,10 +21,10 @@ - + - + @@ -48,7 +45,7 @@ - + @@ -57,7 +54,7 @@ - + diff --git a/Source/Informes/2/InformeListadoFacturasClientePendientes.fr3 b/Source/Informes/2/InformeListadoFacturasClientePendientes.fr3 index b020f48e..256d0bb0 100644 --- a/Source/Informes/2/InformeListadoFacturasClientePendientes.fr3 +++ b/Source/Informes/2/InformeListadoFacturasClientePendientes.fr3 @@ -1,16 +1,14 @@ - + - - - - - + + + @@ -21,10 +19,10 @@ - + - + @@ -37,6 +35,5 @@ - diff --git a/Source/Informes/2/InformeListadoFacturasClientePendientesDesglosado.fr3 b/Source/Informes/2/InformeListadoFacturasClientePendientesDesglosado.fr3 index dbaaf8da..49873835 100644 --- a/Source/Informes/2/InformeListadoFacturasClientePendientesDesglosado.fr3 +++ b/Source/Informes/2/InformeListadoFacturasClientePendientesDesglosado.fr3 @@ -1,16 +1,14 @@ - + - - - - - + + + @@ -21,10 +19,10 @@ - - + + - + @@ -37,9 +35,8 @@ - - + diff --git a/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.dfm b/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.dfm index 8a01dc80..10402e12 100644 --- a/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.dfm +++ b/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.dfm @@ -1,6 +1,7 @@ object RptFacturasCliente: TRptFacturasCliente OldCreateOrder = True OnCreate = DataModuleCreate + OnDestroy = DataModuleDestroy Height = 513 Width = 933 object schReport: TDASchema diff --git a/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.pas b/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.pas index f52f4dfe..61700705 100644 --- a/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.pas +++ b/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.pas @@ -91,6 +91,7 @@ type tbl_InformeListadoFacturasResumen: TDAMemDataTable; Bin2DataStreamer: TDABin2DataStreamer; procedure DataModuleCreate(Sender: TObject); + procedure DataModuleDestroy(Sender: TObject); private FConnection: IDAConnection; FIdEmpresa: Integer; @@ -99,7 +100,9 @@ type FFechaVenInicio: Variant; FFechaVenFin: Variant; FListaIDClientes: TIntegerArray; + FListaNombresClientes : TStringList; FImporteMinimo: Currency; + FDesglosado : Boolean; //Genera cada una de las facturas a imprimir procedure _GenerarFactura(const ID: Integer; const VerSello: Boolean = True); @@ -107,6 +110,8 @@ type procedure PrepararTablaInforme(ATabla: TDAMemDataTable); procedure PrepararTablaResumenInforme(ATabla: IDADataset); function _GenerarInforme(const TipoInforme: String): Binary; + procedure IniciarParametrosInforme; + procedure RecuperarNombresClientes; public function GenerarFactura(const ListaID : TIntegerArray; const VerSello: Boolean = True): Binary; function GenerarFacturaEnPDF(const ListaID : TIntegerArray; const VerSello: Boolean = True): Binary; @@ -120,7 +125,8 @@ implementation {$R *.dfm} uses - uSistemaFunc, StrUtils, uDataModuleServer, schFacturasClienteClient_Intf; + uSistemaFunc, StrUtils, uDataModuleServer, schFacturasClienteClient_Intf, + uROServer, DataAbstract4_Intf; const rptFacturaCliente = 'InfFacturaCliente.fr3'; @@ -144,11 +150,18 @@ begin FConnection := dmServer.DarNuevaConexion; frxReport.EngineOptions.NewSilentMode := simReThrow; + FListaNombresClientes := TStringList.Create; + frxDBCabecera.DataSource := DADSCabecera; frxDBDetalles.DataSource := DADSDetalles; frxDBVencimientos.DataSource := DADSVencimientos; end; +procedure TRptFacturasCliente.DataModuleDestroy(Sender: TObject); +begin + FreeANDNIL(FListaNombresClientes); +end; + function TRptFacturasCliente.GenerarFactura(const ListaID: TIntegerArray; const VerSello: Boolean = True): Binary; var i: Integer; @@ -279,7 +292,8 @@ begin Bin2DataStreamer.ReadDataset(AStream, tbl_InformeListadoFacturasResumen, TRUE, '', TRUE, TRUE); //DESGLOSADO POR CLIENTE EN ESTE INFORME NO SE DESGLOSARÁ POR CLIENTE - if Desglosado then + FDesglosado := Desglosado; + if FDesglosado then ATipoInforme := rptInformeListadoFacturasClienteDesglosado else ATipoInforme := rptInformeListadoFacturasCliente; @@ -342,7 +356,8 @@ begin end; //DESGLOSADO POR CLIENTE EN ESTE INFORME NO SE DESGLOSARÁ POR CLIENTE - if Desglosado then + FDesglosado := Desglosado; + if FDesglosado then ATipoInforme := rptInformeListadoFactuasClientePendienteDesglosado else ATipoInforme := rptInformeListadoFactuasClientePendiente; @@ -359,6 +374,56 @@ begin end; end; +procedure TRptFacturasCliente.IniciarParametrosInforme; +var + ATextos : TStringList; + ACadena : String; +begin + ATextos := TStringList.Create; + + try + if (not VarIsNull(FFechaInicio)) and (not VarIsNull(FFechaFin)) then + ACadena := Format('Fechas de factura desde el %s hasta el %s', [VarToStr(FFechaInicio), VarToStr(FFechaFin)]) + else + ACadena := 'Sin rango de fechas'; + ATextos.Add(ACadena); + ACadena := ''; + + // Filtrar el informe por fechas de vencimiento + if (not VarIsNull(FFechaVenInicio)) and (not VarIsNull(FFechaVenFin)) then + begin + ACadena := Format('Vencimientos desde el %s hasta el %s', [VarToStr(FFechaVenInicio), VarToStr(FFechaVenFin)]); + ATextos.Add(ACadena); + ACadena := ''; + end; + + if (FImporteMinimo > 0) then + begin + ACadena := Format('Facturas con importe superior a %m', [FImporteMinimo]); + ATextos.Add(ACadena); + ACadena := ''; + end; + + if Assigned(FListaIDClientes) and (FListaIDClientes.Count > 0) then + begin + RecuperarNombresClientes; + ACadena := FListaNombresClientes.Text; + end + else begin + ACadena := 'Todos los clientes'; + if FDesglosado then + ACadena := ACadena + ' (desglosados)' + end; + + ATextos.Add(ACadena); + ACadena := ''; + + frxReport.Variables.Variables['TextoParametros'] := ATextos.Text; + finally + FreeAndNil(ATextos); + end; +end; + procedure TRptFacturasCliente.PrepararTablaInforme(ATabla: TDAMemDataTable); var Condicion: TDAWhereExpression; @@ -490,6 +555,96 @@ begin ATabla.Where.AddText(AWhereStr); end; +procedure TRptFacturasCliente.RecuperarNombresClientes; +var + AContactosService : IsrvContactos; + Intf : IInterface; + AClientID : TGUID; + + ATableNameArray: StringArray; + ATableRequestInfoArray: TableRequestInfoArray; + ATableRequestInfo: TableRequestInfoV5; + AStream: TMemoryStream; + ADataTable: TDAMemDataTable; + i: Integer; + AWhereBuilder : TDAWhereBuilder; + ACondicion : TDAWhereExpression; +begin + CreateGUID(AClientID); + + GetClassFactory('srvContactos').CreateInstance(AClientID, Intf); + + if Assigned(Intf) then + begin + AContactosService := Intf as IsrvContactos; + + ATableNameArray := StringArray.Create; + ATableRequestInfoArray := TableRequestInfoArray.Create; + AWhereBuilder := TDAWhereBuilder.Create; + try + ATableNameArray.Add('Clientes'); + ATableRequestInfo := TableRequestInfoV5.Create; + + with ATableRequestInfo do + begin + IncludeSchema := True; + MaxRecords := -1; + UserFilter := ''; + + AWhereBuilder.Clear; + with AWhereBuilder do + for i := 0 to FListaIDClientes.Count - 1 do + begin + ACondicion := NewBinaryExpression( + NewBinaryExpression(NewField('', 'ID'), NewConstant(FListaIDClientes[i], datInteger), dboEqual), + NewBinaryExpression(NewField('', 'ID_EMPRESA'), NewConstant(FIdEmpresa, datInteger), dboEqual), + dboAnd); + + if not AWhereBuilder.IsEmpty then + Expression := NewBinaryExpression(Expression, ACondicion, dboOr) + else + Expression := ACondicion; + end; + + WhereClause := AWhereBuilder.ExpressionToXmlNode(AWhereBuilder.Expression); + end; + + try + ATableRequestInfoArray.Add(ATableRequestInfo); + AStream := AContactosService.GetData(ATableNameArray, ATableRequestInfoArray); + if Assigned(AStream) then + begin + ADataTable := TDAMemDataTable.Create(nil); + try + ADataTable.Name := 'Clientes'; + ADataTable.LocalDataStreamer := Bin2DataStreamer; + ADataTable.RemoteFetchEnabled := False; + Bin2DataStreamer.ReadDataset(AStream, ADataTable, True); + + ADataTable.Open; + FListaNombresClientes.Clear; + for i := 0 to ADataTable.RecordCount - 1 do + begin + FListaNombresClientes.Add(ADataTable.FieldByName('NOMBRE').AsString); + ADataTable.Next; + end; + + finally + FreeANDNil(ADataTable); + end; + end; + except + on e: Exception do + dmServer.EscribirLog(e.Message); + end; + finally + FreeANDNIL(ATableRequestInfoArray); + FreeANDNIL(ATableNameArray); + FreeANDNIL(AWhereBuilder); + end; + end; +end; + procedure TRptFacturasCliente._GenerarFactura(const ID: Integer; const VerSello: Boolean = True); var AInforme: Variant; @@ -527,7 +682,6 @@ end; function TRptFacturasCliente._GenerarInforme(const TipoInforme: String): Binary; var AInforme: Variant; - begin Result := Binary.Create; AInforme := DarRutaFichero(DarRutaInformes, TipoInforme, IntToStr(FIdEmpresa)); @@ -535,8 +689,7 @@ begin raise Exception.Create (('Error Servidor: _GenerarInforme, no encuentra informe ' + TipoInforme)); frxReport.LoadFromFile(AInforme, True); - frxReport.Variables.Variables['FechaInicio'] := FFechaInicio; - frxReport.Variables.Variables['FechaFin'] := FFechaFin; + IniciarParametrosInforme; frxReport.PrepareReport(False); frxReport.PreviewPages.SaveToStream(Result);