This repository has been archived on 2024-11-29. You can view files and clone it, but cannot push or open issues or pull requests.
Tecsitel_FactuGES/Informes/InformeEstBeneficios.pas

930 lines
32 KiB
ObjectPascal
Raw Permalink Normal View History

unit InformeEstBeneficios;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
InformeEstadistico, Db, RxMemDS, StdCtrls, RdxComboBox, dxCntner, dxTL,
dxDBCtrl, dxDBGrid, ExtCtrls, RdxTitulos, RdxPaneles,
IBCustomDataSet, BaseDatos, IBSQL, IB, Excepciones, TeEngine, TeeFunci,
Series, TeeProcs, Chart, DBChart, IBDatabase, Grids, DBGrids, RdxBotones,
RdxBarras;
type
TfrInformeEstBeneficios = class(TfrInformeEstadistico)
DBChart1: TDBChart;
Series1: TBarSeries;
Series2: TBarSeries;
Series3: TBarSeries;
IBDatabase1: TIBDatabase;
IBTransaction1: TIBTransaction;
DataSource1: TDataSource;
IBDataSet1: TIBDataSet;
IBDataSet3: TIBDataSet;
IBDataSet2: TIBDataSet;
Series4: TBarSeries;
Series5: TBarSeries;
Series6: TBarSeries;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label10: TLabel;
pnlA1T1: TLabel;
pnlA1T2: TLabel;
pnlA1T3: TLabel;
Label11: TLabel;
Label27: TLabel;
pnlA1T4: TLabel;
pnlA3T1: TLabel;
pnlA3T2: TLabel;
pnlA3T3: TLabel;
Panel1: TPanel;
Label17: TLabel;
cbxFiltroGrafico: TRdxComboBox;
Label8: TLabel;
Label9: TLabel;
Label15: TLabel;
pnlA2T1: TLabel;
pnlA2T2: TLabel;
pnlA2T3: TLabel;
pnlA2T4: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label12: TLabel;
Label13: TLabel;
etiComp: TLabel;
procedure gridCustomDrawCell(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxTreeListColumn;
ASelected, AFocused, ANewItemRow: Boolean; var AText: String;
var AColor: TColor; AFont: TFont; var AAlignment: TAlignment;
var ADone: Boolean); override;
procedure bCancelarClick(Sender: TObject);
procedure bImprimirClick(Sender: TObject);
procedure cbxFiltroGraficoChange(Sender: TObject);
private
FTotAno11: Double;
FTotAno12: Double;
FTotAno13: Double;
FTotAno14: Double;
FTotAno21: Double;
FTotAno22: Double;
FTotAno23: Double;
FTotAno24: Double;
FTotAno31: Double;
FTotAno32: Double;
FTotAno33: Double;
FTotAno34: Double;
procedure LimpiarTotales;
function CalcularPre(const pSituacion: String; var TotalAno1: Double; var TotalAno2: Double): Boolean;
function CalcularDifPor: Boolean;
function GenerarTablaInforme: TRxMemoryData;
protected
function InicializarFiltros: Boolean; override;
function InicializarCamposTMem: Boolean; override;
function InicializarGrids: Boolean; override;
function CalcularDatos: Boolean; override;
function InicializarResumenes: Boolean; override;
function RefrescarResumenes: Boolean; override;
function FinalizarResumenes: Boolean; override;
procedure SetAno2(const Value: Variant); override;
public
constructor Create (AOwner : TComponent); override;
end;
var
frInformeEstBeneficios: TfrInformeEstBeneficios;
implementation
uses Tipos, Literales, Constantes, dxGrClms, Mensajes, TablaPresupuestos, RdxEmpresaActiva,
StrFunc, InfEstReportBeneficios, TablaFacturasCliente, Configuracion, SysFunc;
{$R *.DFM}
{ TfrInformeEstPresupuestos }
{ TfrInformeEstPresupuestos }
function TfrInformeEstBeneficios.CalcularDatos: Boolean;
var
Aux: Double;
i: Integer;
Aux2: String;
begin
LimpiarTotales;
FTotAno11:= 0;
FTotAno12:= 0;
FTotAno13:= 0;
FTotAno14:= 0;
FTotAno21:= 0;
FTotAno22:= 0;
FTotAno23:= 0;
FTotAno24:= 0;
FTotAno31:= 0;
FTotAno32:= 0;
FTotAno33:= 0;
FTotAno34:= 0;
CalcularPre('INGRESOS',FTotAno11,FTotAno21);
CalcularPre('GASTOS',FTotAno12,FTotAno22);
CalcularDifPor;
if FTotAno11 <> 0 then
pnlA1T1.Caption := FormatFloat(DISPLAY_EUROS2, FTotAno11);
if FTotAno12 <> 0 then
pnlA1T2.Caption := FormatFloat(DISPLAY_EUROS2, FTotAno12);
FTotAno13 := CalcularResta(FTotAno11, FTotAno12);
if FTotAno13 < 0 then
pnlA1T3.Font.Color := COLOR_NEGATIVO
else
pnlA1T3.Font.Color := COLOR_POSITIVO;
if FTotAno13 <> 0 then
pnlA1T3.Caption := FormatFloat(DISPLAY_EUROS2, FTotAno13);
FTotAno14 := CalcularPorcentaje(FTotAno11, FTotAno13, False);
if FTotAno14 < 0 then
pnlA1T4.Font.Color := COLOR_PORCENTAJENEG
else
pnlA1T4.Font.Color := COLOR_PORCENTAJEPOS;
if FTotAno14 <> 0 then
pnlA1T4.Caption := FormatFloat(DISPLAY_PORCENTAJE, FTotAno14);
//Solo calculamos totales en el caso de que se comparen dos a<>os
if not varIsNull(Ano2) then
begin
if FTotAno21 <> 0 then
pnlA2T1.Caption := FormatFloat(DISPLAY_EUROS2, FTotAno21);
if FTotAno22 <> 0 then
pnlA2T2.Caption := FormatFloat(DISPLAY_EUROS2, FTotAno22);
FTotAno23 := CalcularResta(FTotAno21, FTotAno22);
if FTotAno23 < 0 then
pnlA2T3.Font.Color := COLOR_NEGATIVO
else
pnlA2T3.Font.Color := COLOR_POSITIVO;
if FTotAno23 <> 0 then
pnlA2T3.Caption := FormatFloat(DISPLAY_EUROS2, FTotAno23);
FTotAno24 := CalcularPorcentaje(FTotAno21, FTotAno23, False);
if FTotAno24 < 0 then
pnlA2T4.Font.Color := COLOR_PORCENTAJENEG
else
pnlA2T4.Font.Color := COLOR_PORCENTAJEPOS;
if FTotAno24 <> 0 then
pnlA2T4.Caption := FormatFloat(DISPLAY_PORCENTAJE, FTotAno24);
FTotAno31 := CalcularResta(FTotAno11, FTotAno21);
if FTotAno31 < 0 then
pnlA3T1.Font.Color := COLOR_NEGATIVO
else
pnlA3T1.Font.Color := COLOR_POSITIVO;
if FTotAno31 <> 0 then
pnlA3T1.Caption := FormatFloat(DISPLAY_EUROS2, FTotAno31);
FTotAno32 := CalcularResta(FTotAno12, FTotAno22);
if FTotAno32 < 0 then
pnlA3T2.Font.Color := COLOR_NEGATIVO
else
pnlA3T2.Font.Color := COLOR_POSITIVO;
if FTotAno32 <> 0 then
pnlA3T2.Caption := FormatFloat(DISPLAY_EUROS2, FTotAno32);
FTotAno33 := CalcularResta(FTotAno13, FTotAno23);
if FTotAno33 < 0 then
pnlA3T3.Font.Color := COLOR_NEGATIVO
else
pnlA3T3.Font.Color := COLOR_POSITIVO;
if FTotAno33 <> 0 then
pnlA3T3.Caption := FormatFloat(DISPLAY_EUROS2, FTotAno33);
end;
for i:=0 to DBChart1.SeriesList.CountActive-1 do
begin
Aux2 := DBChart1.SeriesList.Series[i].Title;
case i of
0,3: begin
if i=0
then DBChart1.SeriesList.Series[i].Title := (CTE_ING + ' ' + cbxFiltro2.Text)
else DBChart1.SeriesList.Series[i].Title := (CTE_ING + ' ' + cbxFiltro3.Text);
DBChart1.SeriesList.Series[i].XLabelsSource := CTE_CAMPO2;
DBChart1.SeriesList.Series[i].XValues.ValueSource := CTE_CAMPO1;
DBChart1.SeriesList.Series[i].YValues.ValueSource := 'INGRESOS';
end;
1,4: begin
if i=1
then DBChart1.SeriesList.Series[i].Title := (CTE_GAS + ' ' + cbxFiltro2.Text)
else DBChart1.SeriesList.Series[i].Title := (CTE_GAS + ' ' + cbxFiltro3.Text);
DBChart1.SeriesList.Series[i].XLabelsSource := CTE_CAMPO2;
DBChart1.SeriesList.Series[i].XValues.ValueSource := CTE_CAMPO1;
DBChart1.SeriesList.Series[i].YValues.ValueSource := 'GASTOS';
end;
2,5: begin
if i=2
then DBChart1.SeriesList.Series[i].Title := (CTE_BEN + ' ' + cbxFiltro2.Text)
else DBChart1.SeriesList.Series[i].Title := (CTE_BEN + ' ' + cbxFiltro3.Text);
DBChart1.SeriesList.Series[i].XLabelsSource := CTE_CAMPO2;
DBChart1.SeriesList.Series[i].XValues.ValueSource := CTE_CAMPO1;
DBChart1.SeriesList.Series[i].YValues.ValueSource := 'BENEFICIOS';
end;
end;
end;
end;
function TfrInformeEstBeneficios.CalcularPre(const pSituacion: String; var TotalAno1: Double;
var TotalAno2: Double): Boolean;
var
oSQL: TIBSQL;
Semaforo: Boolean; //Semaforo para controlar la pasada del Ano2 y asi empezar
Contador: Integer; //a compara con los datos de la tabla de memoria en lugar de
//el recordset
begin
Result := False;
Semaforo := False;
//PREPARAMOS LA SENTENCIA SQL A LANZAR
oSQL := TIBSQL.Create(Self);
with oSQL do
begin
Database := dmBaseDatos.BD;
Transaction := dmBaseDatos.Transaccion;
SQL.Add('select EXTRACT(YEAR FROM P.FECHAALTA) as ANO');
//Calculamos el intervalo correspondiente a cada una de las posibilidades
Case Intervalo of
tiMensual : SQL.Add(',EXTRACT(MONTH FROM FECHAALTA) as NFILA');
tiTrimestral : SQL.Add(',CAST((DIV(EXTRACT(MONTH FROM FECHAALTA),4)+1) AS SMALLINT) as NFILA');
tiSemestral : SQL.Add(',CAST((DIV(EXTRACT(MONTH FROM FECHAALTA),8)+1) AS SMALLINT) as NFILA');
end;
if pSituacion = 'INGRESOS' then
begin
SQL.Add(',SUM(P.IMPORTETOTAL) as INGRESOS');
SQL.Add('from FACTURASCLIENTE P');
end
else
begin
SQL.Add(',SUM(P.IMPORTETOTAL) as GASTOS');
SQL.Add('from FACTURASPROVEEDOR P');
end;
SQL.Add('where P.CODIGOEMPRESA = :CODIGOEMPRESA');
SQL.Add('and (EXTRACT(YEAR FROM P.FECHAALTA) = :ANO1');
SQL.Add('or EXTRACT(YEAR FROM P.FECHAALTA) = :ANO2)');
SQL.Add('group by 1,2');
if (not VarIsNull(Ano2)) and (Ano1 < Ano2)
then SQL.Add('order by 1,2 asc')
else SQL.Add('order by 1 desc,2 asc');
try
ParamByName('CODIGOEMPRESA').AsString := EmpresaActiva.Codigo;
ParamByName('ANO1').AsString := Ano1;
//En el caso de no compara con otro a<>o se busca solo el a<>o1
if VarIsNull(Ano2)
then ParamByName('ANO2').AsString := Ano1
else ParamByName('ANO2').AsString := Ano2;
Prepare;
ExecQuery;
//Rellenamos los grid resultado
TMemAnoCom1.First;
TMemAnoCom2.First;
TMemComparativa.First;
TMemGraficoAno1.First;
TMemGraficoAno2.First;
//Inicio de recorrido del resultado
while not EOF do begin
//Rellenamos los datos del A<>o1
if (FieldByName('ANO').AsString = Ano1) then
begin
//En el caso de solo tener datos en ciertos intervalos, los que no tienen datos los
//rellenamos no los rellenamos
while TMemAnoCom1.FieldByName(CTE_CAMPO1).AsInteger <> FieldByName(CTE_CAMPO1).AsInteger do
begin
TMemAnoCom1.Next;
TMemGraficoAno1.Next;
end;
//Metemos el dato obtenido en la sql en su intervalo correspondiente
TMemAnoCom1.Edit;
TMemAnoCom1.FieldByName(pSituacion).AsFloat := FieldByName(pSituacion).AsFloat;
TMemAnoCom1.Post;
TMemGraficoAno1.Edit;
TMemGraficoAno1.FieldByName(pSituacion).AsFloat := FieldByName(pSituacion).AsFloat;
TMemGraficoAno1.Post;
//Vamos incrementando la suma total
TotalAno1 := TotalAno1 + FieldByName(pSituacion).AsFloat;
TMemAnoCom1.Next;
TMemGraficoAno1.Next;
end
//Rellenamos los datos del A<>o2
else
begin
//Si es la primera tupla del recordset de este a<>o establecemos el semaforo
//y la tabla de datos del A<>o1 en el primer elemento para tener en cuenta los
//datos de dicha tabla en lugar de los del recordset para el A<>o1
if not Semaforo then
begin
TMemAnoCom1.First;
Semaforo := True;
end
else
TMemAnoCom1.Next;
//En el caso de solo tener datos en ciertos intervalos, los que no tienen datos los
//no los rellenamos
while TMemAnoCom2.FieldByName(CTE_CAMPO1).AsInteger <> FieldByName(CTE_CAMPO1).AsInteger do
begin
//Calculamos TablaComaprativa
//En el caso de no existir el valor en A<>o1 o A<>o2 de este determinado intervalo
//no rellenariamos calculo ninguno
if (not VarIsNull(TMemAnoCom1.FieldByName(pSituacion).AsVariant))
and (not VarIsNull(TMemAnoCom2.FieldByName(pSituacion).AsVariant)) then
begin
TMemComparativa.Edit;
TMemComparativa.FieldByName(pSituacion).AsFloat := TMemAnoCom1.FieldByName(pSituacion).AsFloat;
TMemComparativa.Post;
end;
TMemComparativa.Next;
TMemAnoCom2.Next;
TMemAnoCom1.Next;
TMemGraficoAno2.Next;
end;
//Metemos el dato obtenido en la sql en su intervalo correspondiente y calculamos
TMemAnoCom2.Edit;
TMemAnoCom2.FieldByName(pSituacion).AsFloat := FieldByName(pSituacion).AsFloat;
TMemAnoCom2.Post;
TMemGraficoAno2.Edit;
TMemGraficoAno2.FieldByName(pSituacion).AsFloat := FieldByName(pSituacion).AsFloat;
TMemGraficoAno2.Post;
//Calculamos TablaComaprativa
//En el caso de no existir el valor en A<>o1 o A<>o2 de este determinado intervalo
//no rellenariamos calculo ninguno
if (not VarIsNull(TMemAnoCom1.FieldByName(pSituacion).AsVariant))
and (not VarIsNull(TMemAnoCom2.FieldByName(pSituacion).AsVariant)) then
begin
TMemComparativa.Edit;
TMemComparativa.FieldByName(pSituacion).AsFloat := CalcularResta(TMemAnoCom1.FieldByName(pSituacion).AsFloat, TMemAnoCom2.FieldByName(pSituacion).AsFloat);
TMemComparativa.Post;
end;
//Vamos incrementando la suma total
TotalAno2 := TotalAno2 + FieldByName(pSituacion).AsFloat;
TMemComparativa.Next;
TMemAnoCom2.Next;
TMemGraficoAno2.Next;
end;
Next;
end;
//Fin de recorrido del resultado
Result := True;
finally
Close;
Transaction := NIL;
Free;
end;
end;
end;
function TfrInformeEstBeneficios.FinalizarResumenes: Boolean;
begin
//
end;
procedure TfrInformeEstBeneficios.gridCustomDrawCell(Sender: TObject;
ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode;
AColumn: TdxTreeListColumn; ASelected, AFocused, ANewItemRow: Boolean;
var AText: String; var AColor: TColor; AFont: TFont;
var AAlignment: TAlignment; var ADone: Boolean);
var
IndiceCol: Integer;
begin
inherited;
if ((Sender as TdxDBGrid).Name = gridAnoCom1.Name)
or ((Sender as TdxDBGrid).Name = gridAnoCom2.Name)
or ((Sender as TdxDBGrid).Name = gridComparativa.Name) then
begin
if (AColumn.Caption = 'INGRESOS') then
begin
IndiceCol := (Sender as TdxDBGrid).ColumnByFieldName('INGRESOS').Index;
if (ANode.Values[IndiceCol] < 0) then
AFont.Color := COLOR_NEGATIVO
else
AFont.Color := COLOR_POSITIVO;
end;
if (AColumn.Caption = 'GASTOS') then
begin
IndiceCol := (Sender as TdxDBGrid).ColumnByFieldName('GASTOS').Index;
if (ANode.Values[IndiceCol] < 0) then
AFont.Color := COLOR_NEGATIVO
else
AFont.Color := COLOR_POSITIVO;
end;
if (AColumn.Caption = 'BENEFICIOS') then
begin
IndiceCol := (Sender as TdxDBGrid).ColumnByFieldName('BENEFICIOS').Index;
if (ANode.Values[IndiceCol] < 0) then
AFont.Color := COLOR_NEGATIVO
else
AFont.Color := COLOR_POSITIVO;
end;
if (AColumn.Caption = 'PORCENTAJE') then
begin
IndiceCol := (Sender as TdxDBGrid).ColumnByFieldName('PORCENTAJE').Index;
if (ANode.Values[IndiceCol] < 0) then
AFont.Color := COLOR_PORCENTAJENEG
else
AFont.Color := COLOR_PORCENTAJEPOS;
end;
end;
end;
function TfrInformeEstBeneficios.InicializarCamposTMem: Boolean;
begin
inherited InicializarCamposTMem;
//ANO1
TMemAnoCom1.FieldDefs.Add('INGRESOS',ftFloat);
TMemAnoCom1.FieldDefs.Items[TMemAnoCom1.FieldDefs.IndexOf('INGRESOS')].CreateField(Self);
TMemAnoCom1.FieldDefs.Add('GASTOS',ftFloat);
TMemAnoCom1.FieldDefs.Items[TMemAnoCom1.FieldDefs.IndexOf('GASTOS')].CreateField(Self);
TMemAnoCom1.FieldDefs.Add('BENEFICIOS',ftFloat);
TMemAnoCom1.FieldDefs.Items[TMemAnoCom1.FieldDefs.IndexOf('BENEFICIOS')].CreateField(Self);
TMemAnoCom1.FieldDefs.Add('PORCENTAJE',ftFloat);
TMemAnoCom1.FieldDefs.Items[TMemAnoCom1.FieldDefs.IndexOf('PORCENTAJE')].CreateField(Self);
//ANO2
TMemAnoCom2.FieldDefs.Add('INGRESOS',ftFloat);
TMemAnoCom2.FieldDefs.Items[TMemAnoCom2.FieldDefs.IndexOf('INGRESOS')].CreateField(Self);
TMemAnoCom2.FieldDefs.Add('GASTOS',ftFloat);
TMemAnoCom2.FieldDefs.Items[TMemAnoCom2.FieldDefs.IndexOf('GASTOS')].CreateField(Self);
TMemAnoCom2.FieldDefs.Add('BENEFICIOS',ftFloat);
TMemAnoCom2.FieldDefs.Items[TMemAnoCom2.FieldDefs.IndexOf('BENEFICIOS')].CreateField(Self);
TMemAnoCom2.FieldDefs.Add('PORCENTAJE',ftFloat);
TMemAnoCom2.FieldDefs.Items[TMemAnoCom2.FieldDefs.IndexOf('PORCENTAJE')].CreateField(Self);
//COMPARATIVA
TMemComparativa.FieldDefs.Add('INGRESOS',ftFloat);
TMemComparativa.FieldDefs.Items[TMemComparativa.FieldDefs.IndexOf('INGRESOS')].CreateField(Self);
TMemComparativa.FieldDefs.Add('GASTOS',ftFloat);
TMemComparativa.FieldDefs.Items[TMemComparativa.FieldDefs.IndexOf('GASTOS')].CreateField(Self);
TMemComparativa.FieldDefs.Add('BENEFICIOS',ftFloat);
TMemComparativa.FieldDefs.Items[TMemComparativa.FieldDefs.IndexOf('BENEFICIOS')].CreateField(Self);
//Grafico
TMemGraficoAno1.FieldDefs.Add('INGRESOS',ftFloat);
TMemGraficoAno1.FieldDefs.Items[TMemGraficoAno1.FieldDefs.IndexOf('INGRESOS')].CreateField(Self);
TMemGraficoAno1.FieldDefs.Add('GASTOS',ftFloat);
TMemGraficoAno1.FieldDefs.Items[TMemGraficoAno1.FieldDefs.IndexOf('GASTOS')].CreateField(Self);
TMemGraficoAno1.FieldDefs.Add('BENEFICIOS',ftFloat);
TMemGraficoAno1.FieldDefs.Items[TMemGraficoAno1.FieldDefs.IndexOf('BENEFICIOS')].CreateField(Self);
TMemGraficoAno2.FieldDefs.Add('INGRESOS',ftFloat);
TMemGraficoAno2.FieldDefs.Items[TMemGraficoAno2.FieldDefs.IndexOf('INGRESOS')].CreateField(Self);
TMemGraficoAno2.FieldDefs.Add('GASTOS',ftFloat);
TMemGraficoAno2.FieldDefs.Items[TMemGraficoAno2.FieldDefs.IndexOf('GASTOS')].CreateField(Self);
TMemGraficoAno2.FieldDefs.Add('BENEFICIOS',ftFloat);
TMemGraficoAno2.FieldDefs.Items[TMemGraficoAno1.FieldDefs.IndexOf('BENEFICIOS')].CreateField(Self);
end;
function TfrInformeEstBeneficios.InicializarFiltros: Boolean;
begin
inherited InicializarFiltros;
AnosMem := dmTablaFacturasCliente.DarListaAnos(EmpresaActiva.Codigo, False);
cbxFiltroGrafico.Items.Append(CTE_TODOS);
cbxFiltroGrafico.Items.Append(CTE_ING);
cbxFiltroGrafico.Items.Append(CTE_GAS);
cbxFiltroGrafico.Items.Append(CTE_BEN);
cbxFiltroGrafico.ItemIndex := 0;
DBChart1.Title.Text.Text := CTE_TODOS;
end;
function TfrInformeEstBeneficios.InicializarGrids: Boolean;
var
Columna : TdxDBTreeListColumn;
begin
inherited InicializarGrids;
//Titulo general
cGeneral.Caption := msgInfEstBeneficios;
//ANO1
Columna := gridAnoCom1.CreateColumn(TdxDBGridCurrencyColumn);
Columna.FieldName := 'INGRESOS';
Columna.Caption := 'INGRESOS';
Columna.Width := tamColPrecio5;
(Columna as TdxDBGridCurrencyColumn).DisplayFormat := DISPLAY_EUROS2;
Columna := gridAnoCom1.CreateColumn(TdxDBGridCurrencyColumn);
Columna.FieldName := 'GASTOS';
Columna.Caption := 'GASTOS';
Columna.Width := tamColPrecio5;
(Columna as TdxDBGridCurrencyColumn).DisplayFormat := DISPLAY_EUROS2;
Columna := gridAnoCom1.CreateColumn(TdxDBGridCurrencyColumn);
Columna.FieldName := 'BENEFICIOS';
Columna.Caption := 'BENEFICIOS';
Columna.Width := tamColPrecio5;
(Columna as TdxDBGridCurrencyColumn).DisplayFormat := DISPLAY_EUROS2;
Columna := gridAnoCom1.CreateColumn(TdxDBGridCurrencyColumn);
Columna.FieldName := 'PORCENTAJE';
Columna.Caption := 'PORCENTAJE';
Columna.Width := tamColPorcentaje3;
(Columna as TdxDBGridCurrencyColumn).DisplayFormat := DISPLAY_PORCENTAJE;
//ANO2
Columna := gridAnoCom2.CreateColumn(TdxDBGridCurrencyColumn);
Columna.FieldName := 'INGRESOS';
Columna.Caption := 'INGRESOS';
Columna.Width := tamColPrecio5;
(Columna as TdxDBGridCurrencyColumn).DisplayFormat := DISPLAY_EUROS2;
Columna := gridAnoCom2.CreateColumn(TdxDBGridCurrencyColumn);
Columna.FieldName := 'GASTOS';
Columna.Caption := 'GASTOS';
Columna.Width := tamColPrecio5;
(Columna as TdxDBGridCurrencyColumn).DisplayFormat := DISPLAY_EUROS2;
Columna := gridAnoCom2.CreateColumn(TdxDBGridCurrencyColumn);
Columna.FieldName := 'BENEFICIOS';
Columna.Caption := 'BENEFICIOS';
Columna.Width := tamColPrecio5;
(Columna as TdxDBGridCurrencyColumn).DisplayFormat := DISPLAY_EUROS2;
Columna := gridAnoCom2.CreateColumn(TdxDBGridCurrencyColumn);
Columna.FieldName := 'PORCENTAJE';
Columna.Caption := 'PORCENTAJE';
Columna.Width := tamColPorcentaje3;
(Columna as TdxDBGridCurrencyColumn).DisplayFormat := DISPLAY_PORCENTAJE;
//COMPARATIVA
Columna := gridComparativa.CreateColumn(TdxDBGridCurrencyColumn);
Columna.FieldName := 'INGRESOS';
Columna.Caption := 'INGRESOS';
Columna.Width := tamColPrecio5;
(Columna as TdxDBGridCurrencyColumn).DisplayFormat := DISPLAY_EUROS2;
Columna := gridComparativa.CreateColumn(TdxDBGridCurrencyColumn);
Columna.FieldName := 'GASTOS';
Columna.Caption := 'GASTOS';
Columna.Width := tamColPrecio5;
(Columna as TdxDBGridCurrencyColumn).DisplayFormat := DISPLAY_EUROS2;
Columna := gridComparativa.CreateColumn(TdxDBGridCurrencyColumn);
Columna.FieldName := 'BENEFICIOS';
Columna.Caption := 'BENEFICIOS';
Columna.Width := tamColPrecio5;
(Columna as TdxDBGridCurrencyColumn).DisplayFormat := DISPLAY_EUROS2;
gridIntervalo.ShowHeader := False;
gridAnoCom1.ShowHeader := False;
gridAnoCom2.ShowHeader := False;
gridComparativa.ShowHeader := False;
end;
function TfrInformeEstBeneficios.InicializarResumenes: Boolean;
begin
//
end;
procedure TfrInformeEstBeneficios.limpiarTotales;
begin
pnlA1T1.Caption := '';
pnlA1T2.Caption := '';
pnlA1T3.Caption := '';
pnlA1T4.Caption := '';
pnlA2T1.Caption := '';
pnlA2T2.Caption := '';
pnlA2T3.Caption := '';
pnlA2T4.Caption := '';
pnlA3T1.Caption := '';
pnlA3T2.Caption := '';
pnlA3T3.Caption := '';
end;
function TfrInformeEstBeneficios.RefrescarResumenes: Boolean;
begin
//
end;
procedure TfrInformeEstBeneficios.bCancelarClick(Sender: TObject);
begin
CloseFrame;
end;
procedure TfrInformeEstBeneficios.bImprimirClick(Sender: TObject);
var
lInforme: TdmInfEstReportBeneficios;
DatosGenerales: TRxMemoryData;
begin
try
//Creamos informe
lInforme:= TdmInfEstReportBeneficios.Create(Self);
//Asignamos la informaci<63>n al informe
lInforme.Ano1 := Ano1;
lInforme.Ano2 := Ano2;
//Creamos una tabla con todos los datos del informe general, y la pasamos
//al informe para que la copie, luego los destruimos
DatosGenerales := GenerarTablaInforme;
lInforme.setDatosGeneral(DatosGenerales);
lInforme.A1T1 := pnlA1T1.Caption;
lInforme.A1T2 := pnlA1T2.Caption;
lInforme.A1T3 := pnlA1T3.Caption;
lInforme.A1T4 := pnlA1T4.Caption;
lInforme.A2T1 := pnlA2T1.Caption;
lInforme.A2T2 := pnlA2T2.Caption;
lInforme.A2T3 := pnlA2T3.Caption;
lInforme.A2T4 := pnlA2T4.Caption;
lInforme.A3T1 := pnlA3T1.Caption;
lInforme.A3T2 := pnlA3T2.Caption;
lInforme.A3T3 := pnlA3T3.Caption;
//Creamos una imagen del grafico para luego insertarla en el informe
lInforme.Fichero := DarFicheroBMPTemporal;
DBChart1.SaveToBitmapFile(lInforme.Fichero);
//Imprimimos
// lInforme.Previsualizar;
lInforme.Imprimir;
finally
FreeAndNil(DatosGenerales);
DeleteFile(lInforme.Fichero);
FreeAndNil(lInforme);
end;
end;
function TfrInformeEstBeneficios.GenerarTablaInforme: TRxMemoryData;
var
TablaAux: TRxMemoryData;
begin
//Creamos la tabla con los campos que vamos a tener
TablaAux:= TRxMemoryData.Create(Self);
with TablaAux do
begin
FieldDefs.Add('TITINTERVALO',ftString,20);
FieldDefs.Items[FieldDefs.IndexOf('TITINTERVALO')].CreateField(Self);
FieldDefs.Add('ANO1INGRESOS',ftString,50);
FieldDefs.Items[FieldDefs.IndexOf('ANO1INGRESOS')].CreateField(Self);
FieldDefs.Add('ANO1GASTOS',ftString,50);
FieldDefs.Items[FieldDefs.IndexOf('ANO1GASTOS')].CreateField(Self);
FieldDefs.Add('ANO1BENEFICIOS',ftString,50);
FieldDefs.Items[FieldDefs.IndexOf('ANO1BENEFICIOS')].CreateField(Self);
FieldDefs.Add('ANO1PORCENTAJE',ftString,50);
FieldDefs.Items[FieldDefs.IndexOf('ANO1PORCENTAJE')].CreateField(Self);
FieldDefs.Add('ANO2INGRESOS',ftString,50);
FieldDefs.Items[FieldDefs.IndexOf('ANO2INGRESOS')].CreateField(Self);
FieldDefs.Add('ANO2GASTOS',ftString,50);
FieldDefs.Items[FieldDefs.IndexOf('ANO2GASTOS')].CreateField(Self);
FieldDefs.Add('ANO2BENEFICIOS',ftString,50);
FieldDefs.Items[FieldDefs.IndexOf('ANO2BENEFICIOS')].CreateField(Self);
FieldDefs.Add('ANO2PORCENTAJE',ftString,50);
FieldDefs.Items[FieldDefs.IndexOf('ANO2PORCENTAJE')].CreateField(Self);
FieldDefs.Add('ANO3INGRESOS',ftString,50);
FieldDefs.Items[FieldDefs.IndexOf('ANO3INGRESOS')].CreateField(Self);
FieldDefs.Add('ANO3GASTOS',ftString,50);
FieldDefs.Items[FieldDefs.IndexOf('ANO3GASTOS')].CreateField(Self);
FieldDefs.Add('ANO3BENEFICIOS',ftString,50);
FieldDefs.Items[FieldDefs.IndexOf('ANO3BENEFICIOS')].CreateField(Self);
end;
TablaAux.Open;
//Rellenamos el campo TITINTERVALO
with TMemIntervalo do
begin
DisableControls;
First;
while not Eof do
begin
TablaAux.Append;
TablaAux.FieldByName('TITINTERVALO').AsString := FieldByName('TITINTERVALO').AsString;
TablaAux.Post;
Next;
end;
EnableControls;
end;
//Rellenamos los campos ANO1INGRESOS, ANO1GASTOS, ANO1BENEFICIOS, ANO1PORCENTAJE
with TMemAnoCom1 do
begin
DisableControls;
First;
TablaAux.First;
while not Eof do
begin
TablaAux.Edit;
TablaAux.FieldByName('ANO1INGRESOS').AsString := FieldByName('INGRESOS').AsString;
TablaAux.FieldByName('ANO1GASTOS').AsString := FieldByName('GASTOS').AsString;
TablaAux.FieldByName('ANO1BENEFICIOS').AsString := FieldByName('BENEFICIOS').AsString;
TablaAux.FieldByName('ANO1PORCENTAJE').AsString := FieldByName('PORCENTAJE').AsString;
TablaAux.Post;
TablaAux.Next;
Next;
end;
EnableControls;
end;
//Rellenamos los campos ANO2INGRESOS, ANO2GASTOS, ANO2BENEFICIOS, ANO2PORCENTAJE
with TMemAnoCom2 do
begin
DisableControls;
First;
TablaAux.First;
while not Eof do
begin
TablaAux.Edit;
TablaAux.FieldByName('ANO2INGRESOS').AsString := FieldByName('INGRESOS').AsString;
TablaAux.FieldByName('ANO2GASTOS').AsString := FieldByName('GASTOS').AsString;
TablaAux.FieldByName('ANO2BENEFICIOS').AsString := FieldByName('BENEFICIOS').AsString;
TablaAux.FieldByName('ANO2PORCENTAJE').AsString := FieldByName('PORCENTAJE').AsString;
TablaAux.Post;
TablaAux.Next;
Next;
end;
EnableControls;
end;
//Rellenamos los campos ANO3INGRESOS, ANO3GASTOS, ANO3BENEFICIOS
with TMemComparativa do
begin
DisableControls;
First;
TablaAux.First;
while not Eof do
begin
TablaAux.Edit;
TablaAux.FieldByName('ANO3INGRESOS').AsString := FieldByName('INGRESOS').AsString;
TablaAux.FieldByName('ANO3GASTOS').AsString := FieldByName('GASTOS').AsString;
TablaAux.FieldByName('ANO3BENEFICIOS').AsString := FieldByName('BENEFICIOS').AsString;
TablaAux.Post;
TablaAux.Next;
Next;
end;
EnableControls;
end;
Result:= TablaAux;
end;
function TfrInformeEstBeneficios.CalcularDifPor: Boolean;
begin
//Calculamos Beneficios y porcentajes de A<>o1
with TMemAnoCom1 do
begin
DisableControls;
First;
TMemGraficoAno1.First;
while not EOF do
begin
if (not VarIsNull(FieldByName('INGRESOS').AsVariant)) then
begin
Edit;
FieldByName('BENEFICIOS').AsFloat := CalcularResta(FieldByName('INGRESOS').AsFloat, FieldByName('GASTOS').AsFloat);
FieldByName('PORCENTAJE').AsFloat := CalcularPorcentaje(FieldByName('INGRESOS').AsFloat,FieldByName('BENEFICIOS').AsFloat, False);
Post;
TMemGraficoAno1.Edit;
TMemGraficoAno1.FieldByName('BENEFICIOS').AsFloat := FieldByName('BENEFICIOS').AsFloat;
TMemGraficoAno1.Post;
end;
Next;
TMemGraficoAno1.Next;
end;
EnableControls;
end;
//Calculamos Beneficios y porcentajes de A<>o2
with TMemAnoCom2 do
begin
DisableControls;
First;
TMemGraficoAno2.First;
while not EOF do
begin
if (not VarIsNull(FieldByName('INGRESOS').AsVariant)) then
begin
Edit;
FieldByName('BENEFICIOS').AsFloat := CalcularResta(FieldByName('INGRESOS').AsFloat, FieldByName('GASTOS').AsFloat);
FieldByName('PORCENTAJE').AsFloat := CalcularPorcentaje(FieldByName('INGRESOS').AsFloat,FieldByName('BENEFICIOS').AsFloat, False);
Post;
TMemGraficoAno2.Edit;
TMemGraficoAno2.FieldByName('BENEFICIOS').AsFloat := FieldByName('BENEFICIOS').AsFloat;
TMemGraficoAno2.Post;
end;
Next;
TMemGraficoAno2.Next;
end;
EnableControls;
end;
//Calculamos Beneficios y porcentajes de Comparativa
with TMemComparativa do
begin
DisableControls;
First;
TMemAnoCom1.First;
TMemAnoCom2.First;
while not EOF do
begin
if (not VarIsNull(TMemAnoCom1.FieldByName('BENEFICIOS').AsVariant))
and (not VarIsNull(TMemAnoCom2.FieldByName('BENEFICIOS').AsVariant)) then
begin
Edit;
FieldByName('BENEFICIOS').AsFloat := CalcularResta(TMemAnoCom1.FieldByName('BENEFICIOS').AsFloat, TMemAnoCom2.FieldByName('BENEFICIOS').AsFloat);
Post;
end;
Next;
TMemAnoCom1.Next;
TMemAnoCom2.Next;
end;
EnableControls;
end;
end;
procedure TfrInformeEstBeneficios.cbxFiltroGraficoChange(Sender: TObject);
begin
if cbxFiltroGrafico.Text = CTE_TODOS then
begin
DBChart1.SeriesList.Series[0].Active := True;
DBChart1.SeriesList.Series[1].Active := True;
DBChart1.SeriesList.Series[2].Active := True;
DBChart1.SeriesList.Series[3].Active := True;
DBChart1.SeriesList.Series[4].Active := True;
DBChart1.SeriesList.Series[5].Active := True;
DBChart1.Title.Text.Text := CTE_TODOS;
end
else if cbxFiltroGrafico.Text = CTE_ING then
begin
DBChart1.SeriesList.Series[0].Active := True;
DBChart1.SeriesList.Series[1].Active := False;
DBChart1.SeriesList.Series[2].Active := False;
DBChart1.SeriesList.Series[3].Active := True;
DBChart1.SeriesList.Series[4].Active := False;
DBChart1.SeriesList.Series[5].Active := False;
DBChart1.Title.Text.Text := CTE_ING;
end
else if cbxFiltroGrafico.Text = CTE_GAS then
begin
DBChart1.SeriesList.Series[0].Active := False;
DBChart1.SeriesList.Series[1].Active := True;
DBChart1.SeriesList.Series[2].Active := False;
DBChart1.SeriesList.Series[3].Active := False;
DBChart1.SeriesList.Series[4].Active := True;
DBChart1.SeriesList.Series[5].Active := False;
DBChart1.Title.Text.Text := CTE_GAS;
end
else if cbxFiltroGrafico.Text = CTE_BEN then
begin
DBChart1.SeriesList.Series[0].Active := False;
DBChart1.SeriesList.Series[1].Active := False;
DBChart1.SeriesList.Series[2].Active := True;
DBChart1.SeriesList.Series[3].Active := False;
DBChart1.SeriesList.Series[4].Active := False;
DBChart1.SeriesList.Series[5].Active := True;
DBChart1.Title.Text.Text := CTE_BEN;
end;
end;
constructor TfrInformeEstBeneficios.Create(AOwner: TComponent);
begin
inherited;
Entidad := entInfEstBeneficios;
ConfigurarFrame(Self, Self.Entidad);
end;
procedure TfrInformeEstBeneficios.SetAno2(const Value: Variant);
begin
inherited;
if not VarIsNull(Ano2) then
etiComp.Caption := msgInfEstTit31 + IntToStr(Ano1) + msgInfEstTit32 + IntToStr(Ano2)
else
etiComp.Caption := '';
end;
end.