unit InformePresupuestoCliente; 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, Entidades; type TdmInformePresupuestoCliente = class(TdmInformeBase) TablaCab: TfrDBDataSet; TablaDet: TfrDBDataSet; TablaPresupuesto: TIBQuery; TablaDetallesPresupuesto: TIBQuery; TablaPropiedadesPresupuesto: TIBQuery; TablaProp: TfrDBDataSet; dsDetallesPresupuesto: TDataSource; dsPropiedadesPresupuesto: TDataSource; dsPresupuesto: TDataSource; TablaPrecios1: TIBQuery; TablaPrec1: TfrDBDataSet; dsPrecios1: TDataSource; private FCodigoPresupuesto : Variant; FEntidad: TRdxEntidad; procedure SetEntidad(const Value: TRdxEntidad); protected procedure PrepararConsultas; override; procedure PrepararInforme; override; public constructor Create(AOwner: TComponent); override; procedure ImprimirFinanciacion; published property CodigoPresupuesto : variant read FCodigoPresupuesto write FCodigoPresupuesto; property Entidad : TRdxEntidad read FEntidad write SetEntidad; end; var dmInformePresupuestoCliente: TdmInformePresupuestoCliente; implementation {$R *.dfm} uses StrFunc, Constantes, ShellAPI, Mensajes; { TdmInformePresupuestoCliente } constructor TdmInformePresupuestoCliente.Create(AOwner: TComponent); begin inherited; //FNombreInforme := 'PresupuestoCliente.frf'; end; procedure TdmInformePresupuestoCliente.ImprimirFinanciacion; var RutaAux : string; begin RutaAux := ExtractFileDir(ParamStr(0))+ '\financiacion\financiacion.pdf'; if not FileExists(RutaAux) then raise Exception.CreateFmt('No se ha encontrado el documento PDF' + #10#13 + 'de financiación en:' + #10#13 + '%s',[RutaAux]); if True then //AcrobatReader is installed then: ShellExecute(0, 'print', PChar(RutaAux), nil, nil, SW_SHOWNORMAL); end; procedure TdmInformePresupuestoCliente.PrepararConsultas; begin inherited; with TablaPresupuesto do begin Database := FBaseDatos; Transaction := FTransaccion; SQL.Clear; SQL.Add('select * from PRESUPUESTOSCLIENTE '); SQL.Add('where CODIGO = :CODIGO'); ParamByName('CODIGO').AsString := FCodigoPresupuesto; Prepare; Open; end; with TablaDetallesPresupuesto do begin Database := FBaseDatos; Transaction := FTransaccion; SQL.Clear; SQL.Add('select * from DETALLESPRESUPUESTOSARTICULOS '); SQL.Add('where CODIGOPRESUPUESTO = :CODIGO '); case Entidad of entPresupuestoCocina, entPresupuestoBano : SQL.Add('and NUMCONCEPTO = 0'); entPresupuestoArmarios : SQL.Add('and NUMCONCEPTO < 2'); end; Params.ParseSQL(SQL.Text, True); Prepare; Open; end; with TablaPropiedadesPresupuesto do begin Database := FBaseDatos; Transaction := FTransaccion; SQL.Clear; SQL.Add('select CODIGOPRESUPUESTO, NUMCONCEPTO, NUMPROPIEDAD, '); SQL.Add('PROP.DESCRIPCION as DESCRIPCION, CODIGOPROPIEDAD, VALOR '); SQL.Add('from DETALLESPRESUPUESTOSPROPIEDADES, PROPIEDADES PROP '); SQL.Add('where CODIGOPRESUPUESTO = :CODIGOPRESUPUESTO and '); SQL.Add('NUMCONCEPTO = :NUMCONCEPTO and '); SQL.Add('PROP.CODIGO = CODIGOPROPIEDAD '); SQL.Add('order by NUMPROPIEDAD'); Params.ParseSQL(SQL.Text, True); Prepare; Open; end; TablaCab.Open; TablaDet.Open; TablaProp.Open; with TablaPrecios1 do begin Database := FBaseDatos; Transaction := FTransaccion; SQL.Clear; SQL.Add('select * '); SQL.Add('from DETALLESPRESUPUESTOSARTICULOS '); SQL.Add('where CODIGOPRESUPUESTO = :CODIGO '); SQL.Add('and TIPOCONCEPTO = ''PRECIO'' '); SQL.Add('order by NUMCONCEPTO'); Params.ParseSQL(SQL.Text, True); Prepare; Open; end; TablaPrec1.Open; end; procedure TdmInformePresupuestoCliente.PrepararInforme; begin inherited; if Entidad = entPresupuestoCocina then if esCadenaVacia(TablaPresupuesto.FieldByName('DESGLOSES').AsVariant) then FReport.Pages.Pages[1].Visible := False; end; procedure TdmInformePresupuestoCliente.SetEntidad( const Value: TRdxEntidad); begin if FEntidad = Value then Exit; FEntidad := Value; case FEntidad of entPresupuestoCocina : FNombreInforme := 'PresupuestoCocina.frf'; entPresupuestoBano : FNombreInforme := 'PresupuestoBano.frf'; entPresupuestoArmarios : FNombreInforme := 'PresupuestoArmarios.frf'; else FNombreInforme := 'PresupuestoCliente.frf'; end; end; end.