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 RellenarCabecera(Band: TfrBand); override; 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.RellenarCabecera(Band: TfrBand); var iCont : Integer; iDir : Integer; Objeto : TfrView; ObjetoAux : TfrView; CadenaAux : String; begin //Se sobre escribe para que no se imprima el cif en los presupuestos with Band do begin for iCont := 0 to Objects.Count - 1 do begin Objeto := Objects[iCont]; if ((Objeto is TfrMemoView) and (Pos('DatosEmpresa', Objeto.Name) > 0)) then begin with (Objeto as TfrMemoView) do begin Font.Name := 'Arial'; Prop['LINESPACING'] := 1; Prop['GAPX'] := 2; Prop['GAPY'] := 0; Memo.Clear; for iDir := 0 to (EmpresaActiva.Direcciones.Count - 1) do begin Memo.Add(DarTextoDireccion(iDir)); Memo.Add(DarTextoTelefonos(iDir)); Memo.Add(#151 + #151); end; CadenaAux := ''; if not EsCadenaVacia(EmpresaActiva.Web) then CadenaAux := EmpresaActiva.Web; if not EsCadenaVacia(EmpresaActiva.Correo) then begin if not EsCadenaVacia(CadenaAux) then CadenaAux := CadenaAux + ' · '; CadenaAux := CadenaAux + EmpresaActiva.Correo; end; Memo.Add(CadenaAux); end; end; if ((Objeto is TfrPictureView) and (Pos('Logotipo', Objeto.Name) > 0)) then begin with (Objeto as TfrPictureView), EmpresaActiva do begin Picture.Assign(EmpresaActiva.Logotipo); end; end; end; end; 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.