246 lines
7.6 KiB
ObjectPascal
246 lines
7.6 KiB
ObjectPascal
|
|
{
|
|||
|
|
===============================================================================
|
|||
|
|
Copyright (<EFBFBD>) 2002. Rodax Software.
|
|||
|
|
===============================================================================
|
|||
|
|
Los contenidos de este fichero son propiedad de Rodax Software titular del
|
|||
|
|
copyright. Este fichero s<EFBFBD>lo podr<EFBFBD> ser copiado, distribuido y utilizado,
|
|||
|
|
en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
|
|||
|
|
acuerdo con los t<EFBFBD>rminos y condiciones establecidas en el acuerdo/contrato
|
|||
|
|
bajo el que se suministra.
|
|||
|
|
-----------------------------------------------------------------------------
|
|||
|
|
Web: www.rodax-software.com
|
|||
|
|
===============================================================================
|
|||
|
|
Fecha primera versi<EFBFBD>n: 31-12-2003
|
|||
|
|
Versi<EFBFBD>n actual: 1.0.1
|
|||
|
|
Fecha versi<EFBFBD>n actual: 02-04-2004
|
|||
|
|
===============================================================================
|
|||
|
|
Modificaciones:
|
|||
|
|
|
|||
|
|
Fecha Comentarios
|
|||
|
|
---------------------------------------------------------------------------
|
|||
|
|
02-04-2004 Se ha eliminado el atributo SERIE (P8 MULTIEMPRESA)
|
|||
|
|
===============================================================================
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
unit InformeTrimestralCompras;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|||
|
|
Dialogs, InformeBase, FR_IBXDB, FR_Shape, FR_DSet, FR_DBSet, FR_Class,
|
|||
|
|
DB, IBCustomDataSet, IBQuery, RdxEmpresaActiva, TablaFacturasProveedor;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
TdmInformeTrimestralCompras = class(TdmInformeBase)
|
|||
|
|
TablaCab: TfrDBDataSet;
|
|||
|
|
TablaDet: TfrDBDataSet;
|
|||
|
|
TablaTrimestres: TIBQuery;
|
|||
|
|
TablaFacturas: TIBQuery;
|
|||
|
|
TablaRes: TfrDBDataSet;
|
|||
|
|
TablaResumen: TIBQuery;
|
|||
|
|
private
|
|||
|
|
FTipo : TTipoFacturaProveedor;
|
|||
|
|
FCodigoTrimestre : Variant;
|
|||
|
|
FListaCodTiposOp : TStringList;
|
|||
|
|
FListaDesTiposOp : TStringList;
|
|||
|
|
function RellenarListaTipoOp : boolean;
|
|||
|
|
protected
|
|||
|
|
procedure RellenarCabecera(Band: TfrBand); override;
|
|||
|
|
procedure PrepararConsultas; override;
|
|||
|
|
procedure PrepararInforme; override;
|
|||
|
|
|
|||
|
|
public
|
|||
|
|
constructor Create(AOwner: TComponent); override;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
published
|
|||
|
|
property Tipo : TTipoFacturaProveedor read FTipo write FTipo;
|
|||
|
|
property CodigoTrimestre : variant read FCodigoTrimestre write FCodigoTrimestre;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
var
|
|||
|
|
dmInformeTrimestralCompras: TdmInformeTrimestralCompras;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
{$R *.dfm}
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
IBSQL, StrFunc, Mensajes, Constantes, Literales, BaseDatos, TablaEmpresas;
|
|||
|
|
|
|||
|
|
{ TdmInformeBase1 }
|
|||
|
|
|
|||
|
|
constructor TdmInformeTrimestralCompras.Create(AOwner: TComponent);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
FListaCodTiposOp := TStringList.Create;
|
|||
|
|
FListaDesTiposOp := TStringList.Create;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TdmInformeTrimestralCompras.PrepararConsultas;
|
|||
|
|
var
|
|||
|
|
i, ContAux: integer;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
|
|||
|
|
if (not RellenarListaTipoOp) then
|
|||
|
|
raise Exception.Create('No se puede realizar el informe');
|
|||
|
|
|
|||
|
|
with TablaTrimestres do
|
|||
|
|
begin
|
|||
|
|
Database := FBaseDatos;
|
|||
|
|
Transaction := FTransaccion;
|
|||
|
|
SQL.Clear;
|
|||
|
|
SQL.Add('select EXTRACT (YEAR FROM FECHAINI) as ANO, NOMBRE, FECHAINI, FECHAFIN from TRIMESTRES ');
|
|||
|
|
SQL.Add('where CODIGOEMPRESA = :CODIGOEMPRESA');
|
|||
|
|
SQL.Add('and CODIGO = :CODIGO');
|
|||
|
|
ParamByName('CODIGOEMPRESA').AsInteger := EmpresaActiva.Codigo;
|
|||
|
|
ParamByName('CODIGO').AsString := FCodigoTrimestre;
|
|||
|
|
Prepare;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
with TablaFacturas do
|
|||
|
|
begin
|
|||
|
|
Database := FBaseDatos;
|
|||
|
|
Transaction := FTransaccion;
|
|||
|
|
SQL.Clear;
|
|||
|
|
SQL.Add('select EXTRACT (MONTH FROM FECHAFACTURA) as MES, EXTRACT (DAY FROM FECHAFACTURA) as DIA, REFERENCIA, ');
|
|||
|
|
SQL.Add('NIFCIF, NOMBRE, ');
|
|||
|
|
|
|||
|
|
if Tipo = tipGeneral
|
|||
|
|
then ContAux := 13
|
|||
|
|
else ContAux := 2;
|
|||
|
|
for i := 0 to ContAux do
|
|||
|
|
begin
|
|||
|
|
if i < FListaCodTiposOp.Count then
|
|||
|
|
SQL.Add('case TIPOFACTURA when ' + FListaCodTiposOp.Strings[i] + ' then (BASEIMPONIBLE - IMPORTEDESCUENTO) else null end as OP' + IntToStr(i) + ', ')
|
|||
|
|
else
|
|||
|
|
SQL.Add('0 as OP' + IntToStr(i) + ', ');
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
SQL.Add('IVA, IMPORTEIVA, IMPORTETOTAL ');
|
|||
|
|
SQL.Add('from FACTURASPROVEEDOR');
|
|||
|
|
SQL.Add('where CODIGOEMPRESA = :CODIGOEMPRESA');
|
|||
|
|
SQL.Add('and CODIGOTRIMESTRE = :CODIGO ');
|
|||
|
|
|
|||
|
|
if Tipo = tipGeneral
|
|||
|
|
then SQL.Add('and TIPOFACTURA between 0 and 13 ')
|
|||
|
|
else SQL.Add('and TIPOFACTURA between 50 and 51 ');
|
|||
|
|
|
|||
|
|
SQL.Add('order by FECHAFACTURA, NOMBRE');
|
|||
|
|
ParamByName('CODIGOEMPRESA').AsInteger := EmpresaActiva.Codigo;
|
|||
|
|
ParamByName('CODIGO').AsString := FCodigoTrimestre;
|
|||
|
|
Prepare;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
with TablaResumen do
|
|||
|
|
begin
|
|||
|
|
Database := FBaseDatos;
|
|||
|
|
Transaction := FTransaccion;
|
|||
|
|
SQL.Clear;
|
|||
|
|
SQL.Add('select T.CODIGO, T.DESCRIPCION, SUM((F.BASEIMPONIBLE - F.IMPORTEDESCUENTO)) BASEIMPONIBLE, SUM(F.IMPORTEIVA) IMPORTEIVA, SUM(F.IMPORTETOTAL) IMPORTETOTAL');
|
|||
|
|
SQL.Add('from FACTURASPROVEEDOR F, TIPOSFACTURAS T');
|
|||
|
|
SQL.Add('where F.TIPOFACTURA = T.CODIGO');
|
|||
|
|
SQL.Add('and F.CODIGOEMPRESA = :CODIGOEMPRESA');
|
|||
|
|
SQL.Add('and F.CODIGOTRIMESTRE = :CODIGO');
|
|||
|
|
|
|||
|
|
if Tipo = tipGeneral
|
|||
|
|
then SQL.Add('and TIPOFACTURA between 0 and 13 ')
|
|||
|
|
else SQL.Add('and TIPOFACTURA between 50 and 51 ');
|
|||
|
|
|
|||
|
|
SQL.Add('group by T.CODIGO, T.DESCRIPCION');
|
|||
|
|
SQL.Add('order by T.CODIGO, T.DESCRIPCION');
|
|||
|
|
ParamByName('CODIGOEMPRESA').AsInteger := EmpresaActiva.Codigo;
|
|||
|
|
ParamByName('CODIGO').AsString := FCodigoTrimestre;
|
|||
|
|
Prepare;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TdmInformeTrimestralCompras.RellenarCabecera(Band: TfrBand);
|
|||
|
|
var
|
|||
|
|
iCont, i : Integer;
|
|||
|
|
Objeto : TfrView;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
with Band do
|
|||
|
|
begin
|
|||
|
|
for iCont := 0 to Objects.Count - 1 do
|
|||
|
|
begin
|
|||
|
|
Objeto := Objects[iCont];
|
|||
|
|
|
|||
|
|
if (Objeto is TfrMemoView) then
|
|||
|
|
begin
|
|||
|
|
if (Objeto.Name = 'Empresa') then
|
|||
|
|
begin
|
|||
|
|
(Objeto as TfrMemoView).Memo.Clear;
|
|||
|
|
(Objeto as TfrMemoView).Memo.Add('Empresa: ' + EmpresaActiva.NombreComercial);
|
|||
|
|
end
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if ((Objeto is TfrMemoView) and (Pos('eOP', Objeto.Name) > 0)) then
|
|||
|
|
begin
|
|||
|
|
(Objeto as TfrMemoView).Memo.Clear;
|
|||
|
|
i := Pos('eOP', Objeto.Name) + 3;
|
|||
|
|
i := StrToInt(System.Copy(Objeto.Name, i, length(Objeto.Name) - 3));
|
|||
|
|
if (FListaDesTiposOp.Count-1) >= i then
|
|||
|
|
(Objeto as TfrMemoView).Memo.Add(FListaDesTiposOp.Strings[i]);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TdmInformeTrimestralCompras.Destroy;
|
|||
|
|
begin
|
|||
|
|
FreeAndNil(FListaCodTiposOp);
|
|||
|
|
FreeAndNil(FListaDesTiposOp);
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TdmInformeTrimestralCompras.RellenarListaTipoOp: boolean;
|
|||
|
|
var
|
|||
|
|
oSQL : TIBSQL;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
oSQL := TIBSQL.Create(Self);
|
|||
|
|
with oSQL do
|
|||
|
|
begin
|
|||
|
|
Database := dmBaseDatos.BD;
|
|||
|
|
Transaction := dmBaseDatos.Transaccion;
|
|||
|
|
SQL.Add('select CODIGO, DESCRIPCION');
|
|||
|
|
SQL.Add('from tiposfacturas');
|
|||
|
|
SQL.Add('where entidad = ''PROVEEDOR''');
|
|||
|
|
if Tipo = tipGeneral
|
|||
|
|
then SQL.Add('and codigo < 50')
|
|||
|
|
else SQL.Add('and codigo > 49');
|
|||
|
|
SQL.Add('order by codigo');
|
|||
|
|
try
|
|||
|
|
Prepare;
|
|||
|
|
ExecQuery;
|
|||
|
|
FListaCodTiposOp.Clear;
|
|||
|
|
FListaDesTiposOp.Clear;
|
|||
|
|
while not EOF do begin
|
|||
|
|
FListaCodTiposOp.Append(Fields[0].AsVariant);
|
|||
|
|
FListaDesTiposOp.Append(Fields[1].AsVariant);
|
|||
|
|
Next;
|
|||
|
|
end;
|
|||
|
|
result := True;
|
|||
|
|
finally
|
|||
|
|
Close;
|
|||
|
|
Transaction := NIL;
|
|||
|
|
Free;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TdmInformeTrimestralCompras.PrepararInforme;
|
|||
|
|
begin
|
|||
|
|
if Tipo = tipGeneral
|
|||
|
|
then FNombreInforme := 'InformeTrimestralComprasGeneral.frf'
|
|||
|
|
else FNombreInforme := 'InformeTrimestralComprasInmovilizado.frf';
|
|||
|
|
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|