diff --git a/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.dfm b/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.dfm index 574fdcee..fbc7ebde 100644 --- a/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.dfm +++ b/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.dfm @@ -1,8 +1,8 @@ object RptFacturasCliente: TRptFacturasCliente OldCreateOrder = True OnCreate = DataModuleCreate - Height = 577 - Width = 609 + Height = 513 + Width = 711 object schReport: TDASchema ConnectionManager = dmServer.ConnectionManager Datasets = < @@ -458,6 +458,145 @@ object RptFacturasCliente: TRptFacturasCliente Name = 'IMPORTE_TOTAL' DataType = datCurrency end> + end + item + Params = <> + Statements = < + item + Connection = 'IBX' + TargetTable = 'FACTURAS_CLIENTE' + SQL = + 'select ID_EMPRESA, extract (month from fecha_factura) as MES, ex' + + 'tract (year from fecha_factura) as ANO,'#10'case'#10'when extract (month' + + ' from fecha_factura) = 1 then '#39'ENERO - '#39' || extract (year from f' + + 'echa_factura)'#10'when extract (month from fecha_factura) = 2 then '#39 + + 'FEBRERO - '#39' || extract (year from fecha_factura)'#10'when extract (m' + + 'onth from fecha_factura) = 3 then '#39'MARZO - '#39' || extract (year fr' + + 'om fecha_factura)'#10'when extract (month from fecha_factura) = 4 th' + + 'en '#39'ABRIL - '#39' || extract (year from fecha_factura)'#10'when extract ' + + '(month from fecha_factura) = 5 then '#39'MAYO - '#39' || extract (year f' + + 'rom fecha_factura)'#10'when extract (month from fecha_factura) = 6 t' + + 'hen '#39'JUNIO - '#39' || extract (year from fecha_factura)'#10'when extract' + + ' (month from fecha_factura) = 7 then '#39'JULIO - '#39' || extract (year' + + ' from fecha_factura)'#10'when extract (month from fecha_factura) = 8' + + ' then '#39'AGOSTO - '#39' || extract (year from fecha_factura)'#10'when extr' + + 'act (month from fecha_factura) = 9 then '#39'SEPTIEMBRE - '#39' || extra' + + 'ct (year from fecha_factura)'#10'when extract (month from fecha_fact' + + 'ura) = 10 then '#39'OCTUBRE - '#39' || extract (year from fecha_factura)' + + #10'when extract (month from fecha_factura) = 11 then '#39'NOVIEMBRE - ' + + #39' || extract (year from fecha_factura)'#10'when extract (month from ' + + 'fecha_factura) = 12 then '#39'DICIEMBRE - '#39' || extract (year from fe' + + 'cha_factura)'#10'end as TITULO,'#10'REFERENCIA, ID_CLIENTE, NOMBRE, NIF' + + '_CIF, FECHA_FACTURA, BASE_IMPONIBLE, IMPORTE_IVA, IMPORTE_TOTAL'#10 + + #10'from facturas_cliente'#10'where {where}'#10'order by FECHA_FACTURA'#10#10 + StatementType = stSQL + ColumnMappings = < + item + DatasetField = 'ID_EMPRESA' + TableField = 'ID_EMPRESA' + end + item + DatasetField = 'MES' + TableField = '' + SQLOrigin = 'MES' + end + item + DatasetField = 'ANO' + TableField = '' + SQLOrigin = 'ANO' + end + item + DatasetField = 'TITULO' + TableField = '' + SQLOrigin = 'TITULO' + end + item + DatasetField = 'REFERENCIA' + TableField = 'REFERENCIA' + end + item + DatasetField = 'ID_CLIENTE' + TableField = 'ID_CLIENTE' + end + item + DatasetField = 'NOMBRE' + TableField = 'NOMBRE' + end + item + DatasetField = 'NIF_CIF' + TableField = 'NIF_CIF' + end + item + DatasetField = 'FECHA_FACTURA' + TableField = 'FECHA_FACTURA' + end + item + DatasetField = 'BASE_IMPONIBLE' + TableField = 'BASE_IMPONIBLE' + end + item + DatasetField = 'IMPORTE_IVA' + TableField = 'IMPORTE_IVA' + end + item + DatasetField = 'IMPORTE_TOTAL' + TableField = 'IMPORTE_TOTAL' + end> + end> + Name = 'InformeIVA' + Fields = < + item + Name = 'ID_EMPRESA' + DataType = datInteger + end + item + Name = 'MES' + DataType = datSmallInt + end + item + Name = 'ANO' + DataType = datSmallInt + end + item + Name = 'TITULO' + DataType = datString + Size = 19 + end + item + Name = 'REFERENCIA' + DataType = datString + Size = 255 + end + item + Name = 'ID_CLIENTE' + DataType = datInteger + end + item + Name = 'NOMBRE' + DataType = datString + Size = 255 + end + item + Name = 'NIF_CIF' + DataType = datString + Size = 15 + end + item + Name = 'FECHA_FACTURA' + DataType = datDateTime + end + item + Name = 'BASE_IMPONIBLE' + DataType = datCurrency + end + item + Name = 'IMPORTE_IVA' + DataType = datCurrency + end + item + Name = 'IMPORTE_TOTAL' + DataType = datCurrency + end> end> JoinDataTables = <> UnionDataTables = <> @@ -1242,139 +1381,20 @@ object RptFacturasCliente: TRptFacturasCliente object frxReport: TfrxReport Version = '4.3' DotMatrixReport = False - EngineOptions.DoublePass = True IniFile = '\Software\Fast Reports' PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick] PreviewOptions.Zoom = 1.000000000000000000 PrintOptions.Printer = 'Por defecto' PrintOptions.PrintOnSheet = 0 - ReportOptions.CreateDate = 39065.872423495400000000 - ReportOptions.LastChange = 39610.732841435190000000 + ReportOptions.CreateDate = 37800.807714351900000000 + ReportOptions.LastChange = 39736.806221423610000000 ScriptLanguage = 'PascalScript' ScriptText.Strings = ( - '' - 'procedure DatosEmpresaOnBeforePrint(Sender: TfrxComponent);' - 'var' - ' Cadena: String;' - '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);' - '}' - 'end;' - '' - 'procedure NombreEmpresaOnBeforePrint(Sender: TfrxComponent);' - 'begin' - '{ NombreEmpresa.Lines.Clear;' - ' NombreEmpresa.Lines.Add();' - '}' - 'end;' - '' - 'procedure DireccionEnvioOnBeforePrint(Sender: TfrxComponent);' - 'var' - ' ACadena : String;' - 'begin' - '{ ACadena := '#39#39';' - ' DireccionEnvio.Lines.Clear;' - ' if ( <> '#39#39') then' - ' ACadena := ;' - '' - ' if ( <> '#39#39') then' - - ' ACadena := ACadena + '#39' '#39' + ;' - '' - ' DireccionEnvio.Lines.Add(ACadena);' - ' ACadena := '#39#39';' - ' DireccionEnvio.Lines.Add();' - ' if ( <> '#39#39') then' - ' ACadena := + '#39' '#39';' - ' if ( <> '#39#39') then' - ' ACadena := ACadena + ;' - '' - ' if (ACadena <> '#39#39') then' - ' DireccionEnvio.Lines.Add(ACadena);' - '' - ' if ( <> '#39#39') then' - ' DireccionEnvio.Lines.Add();' - '' - ' if ( <> '#39#39') then' - ' DireccionEnvio.Lines.Add();' - '}' - 'end;' - '' - 'procedure PageHeader1OnBeforePrint(Sender: TfrxComponent);' - 'begin' - '{ if not Engine.FinalPass then' - ' Set('#39'TotalPaginas'#39', ( + 1));' - '' - ' if Engine.FinalPass then' - ' Set('#39'Pagina'#39', ( + 1));} ' - 'end;' - '' - 'procedure frxReportOnStartReport(Sender: TfrxComponent);' - 'begin' - ' Set('#39'Pagina'#39', 0);' - ' Set('#39'TotalPaginas'#39', 0);' - ' Set('#39'Capitulo'#39', 0);' - ' Set('#39'NumCapitulos'#39', 0); ' - 'end;' - '' - 'procedure Memo4OnBeforePrint(Sender: TfrxComponent);' - 'begin' - ' if (Length() = 0) then' - ' Memo4.Visible := False; ' - 'end;' - '' - 'procedure Memo22OnBeforePrint(Sender: TfrxComponent);' - 'begin' - ' if ( = 0) then' - ' begin ' - ' Memo22.Text := '#39'Base imponible:'#39';' - '' - ' Memo10.Text := '#39'Importe total:'#39';' - ' Memo10.Font.Style := fsBold; ' - '' - - ' Memo9.Text := FormatFloat('#39'#,##0.00 '#8364#39', );' - ' Memo9.Font.Style := fsBold; ' - ' ' - ' Memo23.Text := '#39'[]% IVA:'#39';' - ' Memo25.Text := '#39'[frxDBCabecera."IMPORTE_IVA"]'#39';' - ' Memo12.Visible := False;' - ' Memo14.Visible := False;' - ' Memo16.Visible := False; ' - '' - ' Memo13.Visible := False;' - ' Memo15.Visible := False;' - ' Memo17.Visible := False;' - ' Memo11.Color := $00CCFFCC;' - ' end; ' - 'end;' - '' - 'procedure Memo39OnBeforePrint(Sender: TfrxComponent);' - 'begin' - ' Memo39.Clear; ' - ' if ( = '#39'F'#39') then' - - ' Memo39.Text := '#39'FACTURA'#39' ' + - ' ' - ' else' - ' Memo39.Text := '#39'ABONO'#39'; ' - 'end;' - '' 'begin' '' 'end.') ShowProgress = False StoreInDFM = False - OnStartReport = 'frxReportOnStartReport' Left = 145 Top = 16 end @@ -1475,4 +1495,85 @@ object RptFacturasCliente: TRptFacturasCliente Left = 424 Top = 288 end + object tbl_InformeIVA: TDAMemDataTable + RemoteUpdatesOptions = [] + Fields = < + item + Name = 'ID_EMPRESA' + DataType = datInteger + end + item + Name = 'MES' + DataType = datSmallInt + end + item + Name = 'ANO' + DataType = datSmallInt + end + item + Name = 'TITULO' + DataType = datString + Size = 19 + end + item + Name = 'REFERENCIA' + DataType = datString + Size = 255 + end + item + Name = 'ID_CLIENTE' + DataType = datInteger + end + item + Name = 'NOMBRE' + DataType = datString + Size = 255 + end + item + Name = 'NIF_CIF' + DataType = datString + Size = 15 + end + item + Name = 'FECHA_FACTURA' + DataType = datDateTime + end + item + Name = 'BASE_IMPONIBLE' + DataType = datCurrency + end + item + Name = 'IMPORTE_IVA' + DataType = datCurrency + end + item + Name = 'IMPORTE_TOTAL' + DataType = datCurrency + end> + Params = <> + LogChanges = False + StreamingOptions = [soDisableEventsWhileStreaming] + RemoteFetchEnabled = False + LocalSchema = schReport + LocalDataStreamer = DABINAdapter + DetailOptions = [dtCascadeOpenClose, dtCascadeApplyUpdates, dtAutoFetch, dtCascadeDelete, dtCascadeUpdate, dtDisableLogOfCascadeDeletes, dtDisableLogOfCascadeUpdates, dtIncludeInAllInOneFetch] + MasterOptions = [moCascadeOpenClose, moCascadeApplyUpdates, moCascadeDelete, moCascadeUpdate, moDisableLogOfCascadeDeletes, moDisableLogOfCascadeUpdates] + LogicalName = 'InformeIVA' + IndexDefs = <> + Left = 576 + Top = 128 + end + object DADSInformeIVA: TDADataSource + DataSet = tbl_InformeIVA.Dataset + DataTable = tbl_InformeIVA + Left = 576 + Top = 72 + end + object frxDBDataset1: TfrxDBDataset + UserName = 'frxDBInformeIVA' + CloseDataSource = True + DataSource = DADSInformeIVA + Left = 576 + Top = 16 + end end diff --git a/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.pas b/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.pas index 87423942..bd91db86 100644 --- a/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.pas +++ b/Source/Modulos/Facturas de cliente/Reports/uRptFacturasCliente_Server.pas @@ -80,6 +80,9 @@ type vencimientosFECHA_VENCIMIENTO: TDateField; vencimientosIMPORTE_TOTAL: TIBBCDField; frxPDFExport1: TfrxPDFExport; + tbl_InformeIVA: TDAMemDataTable; + DADSInformeIVA: TDADataSource; + frxDBDataset1: TfrxDBDataset; schReport: TDASchema; procedure DataModuleCreate(Sender: TObject); private @@ -88,7 +91,8 @@ type procedure _GenerarFactura(const ID: Integer); public function GenerarFactura(const ListaID : TIntegerArray): Binary; - function GenerarFacturaEnPDF(const ListaID : TIntegerArray): Binary; + function GenerarFacturaEnPDF(const ListaID : TIntegerArray): Binary; + function GenerarInformeIVA(const IdEmpresa: Integer; const FechaInicio: DateTime; const FechaFin: DateTime; const ListaIDClientes: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary; end; implementation @@ -100,11 +104,12 @@ uses const rptFacturaCliente = 'InfFacturaCliente.fr3'; + rptInformeIVA = 'InformeIVAClientes.fr3'; { Dataset names for schReport } ds_InformeFacturasCliente = 'InformeFacturasCliente'; ds_InformeFacturasCliente_Detalles = 'InformeFacturasCliente_Detalles'; - ds_InformeFacturasCliente_Vencimientos = 'InformeFacturasCliente_Vencimientos'; + ds_InformeFacturasCliente_Vencimientos = 'InformeFacturasCliente_Vencimientos'; { TRptFacturasCliente } @@ -159,6 +164,100 @@ begin end; end; +function TRptFacturasCliente.GenerarInformeIVA(const IdEmpresa: Integer; const FechaInicio: DateTime; const FechaFin: DateTime; const ListaIDClientes: TIntegerArray; const Desglosado: Boolean; const ImporteMinimo: Currency): Binary; +var + Condicion: TDAWhereExpression; + i: Integer; + +begin + Result := Binary.Create; + //FConnection.BeginTransaction; <--- Creo que no va a hacer falta. + + try + + if tbl_InformeIVA.Active then + tbl_InformeIVA.Active := False; + + // Filtrar el informe por empresa + with tbl_InformeIVA.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_InformeIVA.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_InformeIVA.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_InformeIVA.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_InformeIVA.Active := True; + +//DESGLOSADO POR CLIENTE EN ESTE INFORME NO SE DESGLOSARÁ POR CLIENTE +// if Desglosado then +// frxReport.LoadFromFile(DarRutaInformes + rptInformeIVA, True) +// else + + frxReport.LoadFromFile(DarRutaInformes + rptInformeIVA, 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. + end; +end; + procedure TRptFacturasCliente._GenerarFactura(const ID: Integer); begin tbl_Cabecera.Active := False;