git-svn-id: https://192.168.0.254/svn/Proyectos.Acana_FactuGES/trunk@6 3f40d355-893c-4141-8e64-b1d9be72e7e7
3044 lines
93 KiB
ObjectPascal
3044 lines
93 KiB
ObjectPascal
{
|
|
===============================================================================
|
|
Copyright (©) 2003. Rodax Software.
|
|
===============================================================================
|
|
Los contenidos de este fichero son propiedad de Rodax Software titular del
|
|
copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
|
|
en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
|
|
acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
|
|
bajo el que se suministra.
|
|
-----------------------------------------------------------------------------
|
|
Web: www.rodax-software.com
|
|
===============================================================================
|
|
Fecha primera versión: 19-01-2003
|
|
Versión actual: 1.0.6
|
|
Fecha versión actual: 17-11-2004
|
|
===============================================================================
|
|
Modificaciones:
|
|
|
|
Fecha Comentarios
|
|
---------------------------------------------------------------------------
|
|
25-08-2003 Al dar de alta una factura, el cliente debe estar también
|
|
dado de alta.
|
|
|
|
31-01-2004 La vigencia del presupuesto es por defecto de 6 meses.
|
|
|
|
06-02-2004 Se ha ocultado el campo de IVA.
|
|
|
|
17-05-2004 Codigo de presupuesto no se puede modificar porque hay dos tablas
|
|
que dependen de él y seria muy costoso mantener la politica de codigos
|
|
de la aplicacion en este apartado.
|
|
|
|
11-11-2004 p34. Las observaciones en contratos de armarios no funcionaban
|
|
correctamente.
|
|
|
|
15-11-2004 Error en SalvarDetalles y SalvarPropiedades para armarios.
|
|
|
|
17-11-2004 Cuando ha mejorado la inserción de un presupuesto cuando el código
|
|
ya ha sido utilizado por otro usuario.
|
|
===============================================================================
|
|
}
|
|
|
|
unit PresupuestoCliente;
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, messages, RdxBarras, RdxBotones, StdCtrls, RdxComboBox, RdxCampos,
|
|
RdxMemo, RdxTitulos, Controls, ExtCtrls, RdxPaneles, Forms, Classes,
|
|
RdxFramePresupuestos, ComCtrls, RdxPageControl, Grids, DBGrids, RXDBCtrl,
|
|
Db, RdxRichEdit, Graphics, RxMemDS,IBCustomDataSet, Configuracion,
|
|
Colores, cxDBEdit, cxDropDownEdit, cxCalendar, cxControls, cxContainer, cxEdit, cxTextEdit,
|
|
cxMaskEdit, cxButtonEdit, AdvPanel, cxStyles, cxCustomData, cxGraphics,
|
|
cxFilter, cxData, cxDBData, cxGridLevel, cxClasses, cxGridCustomView,
|
|
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid,
|
|
cxSpinEdit, ActnList, RdxFrame, RdxFrameVendedores, cxMemo,
|
|
cxGridCardView, cxGridDBCardView, TablaArticulos, DBCtrls, ArticuloModelo,
|
|
Menus, am2000menuitem, am2000popupmenu, am2000, IBQuery, cxLookupEdit,
|
|
cxDBLookupEdit, cxDBLookupComboBox, TablaDocumentos, TablaPropiedades,
|
|
RdxEmpresaActiva, am2000utils, cxCurrencyEdit, RXCtrls, Mask, dbcgrids,
|
|
cxImage, cxDBExtLookupComboBox, cxDataStorage, ShellCtrls, Dialogs, Entidades,
|
|
SysUtils, JvExMask, JvToolEdit, ShlObj, cxShellCommon, cxShellListView,
|
|
JvComponent, JvChangeNotify, JvExForms, JvBaseThumbnail, JvThumbViews,
|
|
JvExComCtrls, JvComCtrls, JvComponentBase, cxRichEdit, cxDBRichEdit,
|
|
ToolWin, ImgList;
|
|
|
|
type
|
|
TfrPresupuestoCliente = class(TRdxFramePresupuestos)
|
|
brSalir: TRdxBarraInferior;
|
|
bSalir: TRdxBoton;
|
|
brGuardar: TRdxBarraInferior;
|
|
bGuardar: TRdxBoton;
|
|
bCancelar: TRdxBoton;
|
|
pnlPaginas: TRdxPanel;
|
|
Paginas: TRdxPagesControl;
|
|
pagContenido: TTabSheet;
|
|
pnlGridArticulos: TPanel;
|
|
pnlBarraContenido: TRdxPanel;
|
|
bAnadirCon: TRdxBoton;
|
|
bEliminar: TRdxBoton;
|
|
bEliminarTodo: TRdxBoton;
|
|
dsPresupuesto: TDataSource;
|
|
dsDetallesPresupuesto: TDataSource;
|
|
pnlTitulo: TRdxPanelTituloOperacion;
|
|
pnlCuerpo: TPanel;
|
|
pnlFactura: TAdvPanel;
|
|
eCodigo: TLabel;
|
|
eFechaEmision: TLabel;
|
|
eFechaAlta: TLabel;
|
|
eEstadoPresupuesto: TLabel;
|
|
eVendedor: TLabel;
|
|
Codigo: TcxDBButtonEdit;
|
|
FechaPresupuesto: TcxDBDateEdit;
|
|
cbxSituacion: TcxDBComboBox;
|
|
FechaDecision: TcxDBDateEdit;
|
|
Vendedor: TcxDBButtonEdit;
|
|
gridDetalles: TcxGrid;
|
|
VistaDetalles: TcxGridDBTableView;
|
|
gridDetallesLevel1: TcxGridLevel;
|
|
ActionList1: TActionList;
|
|
actAnadirDetalle: TAction;
|
|
actEliminarDetalle: TAction;
|
|
actEliminarTodoDetalle: TAction;
|
|
pagNotasVarias: TTabSheet;
|
|
pnlFormasPago: TPanel;
|
|
RdxPanel4: TPanel;
|
|
eFormasPago: TLabel;
|
|
RdxPanel5: TPanel;
|
|
FormasPago: TcxDBMemo;
|
|
dsPropiedadesPresupuesto: TDataSource;
|
|
eDocumento: TLabel;
|
|
pnlImportes: TAdvPanel;
|
|
pagDesgloses: TTabSheet;
|
|
pagDocumentos: TTabSheet;
|
|
eVigencia: TLabel;
|
|
Vigencia: TcxDBDateEdit;
|
|
cbxDocumento: TcxDBLookupComboBox;
|
|
dsDocumentos: TDataSource;
|
|
TablaDocumentos: TIBQuery;
|
|
VistaPropiedades: TcxGridDBCardView;
|
|
VistaPropiedadesDBCardViewRow2: TcxGridDBCardViewRow;
|
|
VistaPropiedadesDBCardViewRow3: TcxGridDBCardViewRow;
|
|
TablaPropiedades: TIBQuery;
|
|
TablaValores: TIBQuery;
|
|
dsValores: TDataSource;
|
|
dsPropiedades: TDataSource;
|
|
Label7: TLabel;
|
|
Descuento: TcxDBTextEdit;
|
|
Label8: TLabel;
|
|
IVA: TcxDBTextEdit;
|
|
actAnadirPropiedad: TAction;
|
|
actEliminarPropiedad: TAction;
|
|
pnlBarraPropiedades: TRdxPanel;
|
|
bAnadirProp: TRdxBoton;
|
|
bEliminarProp: TRdxBoton;
|
|
bSubir: TRdxBoton;
|
|
bBajar: TRdxBoton;
|
|
pagPrecios: TTabSheet;
|
|
pnlPrecios: TPanel;
|
|
pnlBarraPrecio: TRdxPanel;
|
|
RdxBoton1: TRdxBoton;
|
|
RdxBoton2: TRdxBoton;
|
|
gridPrecios: TDBCtrlGrid;
|
|
DBEdit1: TDBEdit;
|
|
DBEdit2: TDBEdit;
|
|
pnlGrid: TRdxPanel;
|
|
Label5: TLabel;
|
|
Label10: TLabel;
|
|
Label11: TLabel;
|
|
Label9: TLabel;
|
|
BaseImponible: TcxDBTextEdit;
|
|
ImporteDescuento: TcxDBTextEdit;
|
|
ImporteIVA: TcxDBTextEdit;
|
|
ImporteTotal: TcxDBTextEdit;
|
|
eSeccion: TLabel;
|
|
Seccion: TcxComboBox;
|
|
pnlObservaciones: TRdxPanel;
|
|
Observaciones: TcxMemo;
|
|
Label1: TLabel;
|
|
pagCliente: TTabSheet;
|
|
Label2: TLabel;
|
|
eNIFCIF: TLabel;
|
|
eNumero: TLabel;
|
|
ePiso: TLabel;
|
|
eCodigoPostal: TLabel;
|
|
eNombre: TLabel;
|
|
eDireccion: TLabel;
|
|
eProvincia: TLabel;
|
|
ePoblacion: TLabel;
|
|
CodCliente: TcxDBButtonEdit;
|
|
NIFCIF: TcxDBTextEdit;
|
|
Numero: TcxDBTextEdit;
|
|
Piso: TcxDBTextEdit;
|
|
CodigoPostal: TcxDBTextEdit;
|
|
Nombre: TcxDBTextEdit;
|
|
Calle: TcxDBTextEdit;
|
|
Provincia: TcxDBButtonEdit;
|
|
Poblacion: TcxDBButtonEdit;
|
|
eTelefono1: TLabel;
|
|
Telefono1: TcxDBTextEdit;
|
|
eTelefono2: TLabel;
|
|
Telefono2: TcxDBTextEdit;
|
|
eMovil1: TLabel;
|
|
Movil1: TcxDBTextEdit;
|
|
eMovil2: TLabel;
|
|
Movil2: TcxDBTextEdit;
|
|
eFax: TLabel;
|
|
Fax: TcxDBTextEdit;
|
|
ePersona: TLabel;
|
|
PersonaContacto: TcxDBTextEdit;
|
|
VistaCombo: TcxGridDBTableView;
|
|
VistaComboDBDescripcion: TcxGridDBColumn;
|
|
VistaComboDBImagen: TcxGridDBColumn;
|
|
pnlPlazosEntrega: TPanel;
|
|
Panel2: TPanel;
|
|
ePlazosEntrega: TLabel;
|
|
Panel3: TPanel;
|
|
PlazosEntrega: TcxDBMemo;
|
|
pnlNota: TPanel;
|
|
Panel4: TPanel;
|
|
eNota: TLabel;
|
|
Panel5: TPanel;
|
|
Nota: TcxDBMemo;
|
|
Panel1: TPanel;
|
|
Panel6: TPanel;
|
|
Label3: TLabel;
|
|
Panel7: TPanel;
|
|
Desgloses: TcxDBMemo;
|
|
Panel8: TPanel;
|
|
Panel9: TPanel;
|
|
Panel10: TPanel;
|
|
Panel11: TPanel;
|
|
pnlBarraDocumentos: TPanel;
|
|
bAnadirDoc: TRdxBoton;
|
|
bEliminarDoc: TRdxBoton;
|
|
actAnadirDocumento: TAction;
|
|
actElliminarDocumento: TAction;
|
|
OpenDialog1: TOpenDialog;
|
|
MenuOpciones: TPopupMenu2000;
|
|
Empresa: TMenuItem2000;
|
|
Contadores: TMenuItem2000;
|
|
actAbrirDocumento: TAction;
|
|
explo: TcxShellListView;
|
|
JvChangeNotify1: TJvChangeNotify;
|
|
pagAumento: TTabSheet;
|
|
Panel12: TPanel;
|
|
Label4: TLabel;
|
|
Panel13: TPanel;
|
|
Aumento: TcxDBMemo;
|
|
pagPlanos: TTabSheet;
|
|
tvPlanos: TJvThumbView;
|
|
Panel14: TPanel;
|
|
RdxBoton3: TRdxBoton;
|
|
RdxBoton4: TRdxBoton;
|
|
JvTrackBar1: TJvTrackBar;
|
|
Label6: TLabel;
|
|
actAnadirPlano: TAction;
|
|
actEliminarPlano: TAction;
|
|
actRefrescarPlano: TAction;
|
|
RdxBoton6: TRdxBoton;
|
|
actEliminarTodoPropiedad: TAction;
|
|
RdxBoton5: TRdxBoton;
|
|
procedure bSalirClick(Sender: TObject);
|
|
procedure bGuardarClick(Sender: TObject);
|
|
procedure bCancelarClick(Sender: TObject);
|
|
procedure CodClienteButtonClick(Sender: TObject);
|
|
procedure ProvinciaButtonClick(Sender: TObject);
|
|
procedure PoblacionButtonClick(Sender: TObject);
|
|
procedure actAnadirDetalleExecute(Sender: TObject);
|
|
procedure actEliminarDetalleExecute(Sender: TObject);
|
|
procedure actEliminarTodoDetalleExecute(Sender: TObject);
|
|
procedure VendedorPropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
procedure CodClientePropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
procedure ProvinciaPropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
procedure PoblacionPropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
procedure CodigoPropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
procedure actEliminarDetalleUpdate(Sender: TObject);
|
|
procedure actEliminarTodoDetalleUpdate(Sender: TObject);
|
|
procedure cbXDocumentoPropertiesValidate(Sender: TObject;
|
|
var DisplayValue: Variant; var ErrorText: TCaption;
|
|
var Error: Boolean);
|
|
procedure actEditarPropiedadesUpdate(Sender: TObject);
|
|
procedure actAnadirDetalleUpdate(Sender: TObject);
|
|
procedure TablaDetallesNewRecord(DataSet: TDataSet);
|
|
procedure FechaPresupuestoPropertiesEditValueChanged(Sender: TObject);
|
|
procedure actAnadirPropiedadExecute(Sender: TObject);
|
|
procedure actAnadirPropiedadUpdate(Sender: TObject);
|
|
procedure actEliminarPropiedadExecute(Sender: TObject);
|
|
procedure actEliminarPropiedadUpdate(Sender: TObject);
|
|
procedure actSubirExecute(Sender: TObject);
|
|
procedure actSubirUpdate(Sender: TObject);
|
|
procedure actBajarExecute(Sender: TObject);
|
|
procedure actBajarUpdate(Sender: TObject);
|
|
procedure gridDetallesResize(Sender: TObject);
|
|
procedure pnlPreciosResize(Sender: TObject);
|
|
procedure SeccionPropertiesChange(Sender: TObject);
|
|
procedure ObservacionesExit(Sender: TObject);
|
|
procedure VistaPropiedadesDBCardViewRow3CustomDrawCell(
|
|
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
|
|
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
|
|
procedure actAnadirDocumentoExecute(Sender: TObject);
|
|
procedure actElliminarDocumentoExecute(Sender: TObject);
|
|
procedure actAnadirDocumentoUpdate(Sender: TObject);
|
|
procedure actElliminarDocumentoUpdate(Sender: TObject);
|
|
procedure pagNotasVariasResize(Sender: TObject);
|
|
procedure actAbrirDocumentoExecute(Sender: TObject);
|
|
procedure actAbrirDocumentoUpdate(Sender: TObject);
|
|
procedure JvChangeNotify1ChangeNotify(Sender: TObject; Dir: String;
|
|
Actions: TJvChangeActions);
|
|
procedure tvPlanosStartScanning(Sender: TObject; Max: Integer);
|
|
procedure tvPlanosStopScanning(Sender: TObject);
|
|
procedure tvPlanosDblClick(Sender: TObject);
|
|
procedure JvTrackBar1Change(Sender: TObject);
|
|
procedure actAnadirPlanoExecute(Sender: TObject);
|
|
procedure actEliminarPlanoExecute(Sender: TObject);
|
|
procedure actEliminarPlanoUpdate(Sender: TObject);
|
|
procedure actRefrescarPlanoExecute(Sender: TObject);
|
|
procedure actAnadirPlanoUpdate(Sender: TObject);
|
|
procedure actEliminarTodoPropiedadExecute(Sender: TObject);
|
|
procedure actEliminarTodoPropiedadUpdate(Sender: TObject);
|
|
private
|
|
FRootDocumentos: Variant;
|
|
FRootPlanos: Variant;
|
|
FDirectorio: Variant;
|
|
FDirectorioPlanos : Variant;
|
|
FCodigoProvincia : Variant;
|
|
FCodigoPoblacion : Variant;
|
|
FCodigoCliente : Variant;
|
|
FCodigoArticulo : Variant;
|
|
FCodigoVendedor : Variant;
|
|
FTablaDetallesMem : TRxMemoryData;
|
|
FTablaPropiedadesMem : TRxMemoryData;
|
|
FObservaciones1 : String;
|
|
FObservaciones2 : String;
|
|
procedure HabilitarDocumentos;
|
|
procedure DeshabilitarDocumentos;
|
|
|
|
procedure HabilitarPlanos;
|
|
procedure DeshabilitarPlanos;
|
|
function CrearDirPlanos: Boolean;
|
|
procedure ComprobarEstadoDirPlanos;
|
|
function EliminarDirPlanos : Boolean;
|
|
|
|
function darRutaDocumentosPresupuesto: Variant;
|
|
function darRutaPlanosPresupuesto: Variant;
|
|
function AnadirDocumento(RutaDocumento: String): Boolean;
|
|
function AnadirPlano(RutaPlano: String): Boolean;
|
|
|
|
|
|
function CrearDirDocumentos: Boolean;
|
|
procedure ComprobarEstadoDirDocumentos;
|
|
function EliminarDirDocumentos : Boolean;
|
|
|
|
procedure CalcularTotalDetalle;
|
|
procedure CalcularTotalPresupuesto;
|
|
procedure ActivarEventosCampos;
|
|
procedure DesactivarEventosCampos;
|
|
procedure SalvarDetalles;
|
|
procedure SalvarPropiedades;
|
|
procedure CargarDetalles;
|
|
procedure CargarPropiedades;
|
|
procedure DetalleAfterDelete (DataSet: TDataSet);
|
|
procedure DetallesAfterInsert(DataSet: TDataSet);
|
|
procedure PropiedadesAfterDelete (DataSet: TDataSet);
|
|
procedure PropiedadesAfterInsert(DataSet: TDataSet);
|
|
procedure CodCliSetText(Sender: TField; const Text: String);
|
|
procedure ProvinciaSetText(Sender: TField; const Text: String);
|
|
procedure IVASetText(Sender: TField; const Text: String);
|
|
procedure DtoSetText(Sender: TField; const Text: String);
|
|
procedure CodigoArticuloDetalleSetText(Sender: TField; const Text: String);
|
|
procedure ReferenciaArticuloDetalleSetText(Sender: TField; const Text: String);
|
|
procedure CantidadDetalleSetText(Sender: TField; const Text: String);
|
|
procedure PrecioDetalleSetText(Sender: TField; const Text: String);
|
|
procedure GridBotonCodigoArticuloClick(Sender: TObject; AButtonIndex: Integer);
|
|
procedure GridBotonReferenciaArticuloClick(Sender: TObject; AButtonIndex: Integer);
|
|
procedure InsertarPropiedades(NumConcepto : Integer; Seccion : String = '');
|
|
procedure CargarPropiedadesArticulo(NumConcepto : Integer; DatosArticulo : TDatosArticulo);
|
|
procedure BorrarPropiedadesConcepto(NumConcepto : Integer);
|
|
procedure AsignarNumConceptoDetalles;
|
|
procedure AsignarNumPropiedad;
|
|
procedure ReasignarNumConceptoPropiedades(NumConAnt, NumConNue : Integer);
|
|
procedure cbxSituacionPropertiesChange(Sender: TObject);
|
|
procedure SetCodigoProvincia (Value : Variant); virtual;
|
|
procedure SetCodigoPoblacion (Value : Variant); virtual;
|
|
procedure SetCodigoCliente (Value : Variant);
|
|
procedure SetCodigoVendedor (Value : Variant); virtual;
|
|
procedure SetCodigoArticulo (Value : Variant);
|
|
function ArticuloConPropiedades(NumConcepto : Integer) : Boolean;
|
|
procedure CargarDatosDocumento(CodigoDocumento : String);
|
|
procedure CargarPreciosDocumento (CodigoDocumento : String; NumConcepto : Integer);
|
|
procedure VALORGetProperties(
|
|
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
|
|
var AProperties: TcxCustomEditProperties);
|
|
procedure ConfigurarPantallaDocumento;
|
|
procedure InsertarDetallesDefecto;
|
|
procedure TablaMemDetallesFilterRecord(DataSet: TDataSet;
|
|
var Accept: Boolean);
|
|
procedure TablaMemPropiedadesFilterRecord(DataSet: TDataSet;
|
|
var Accept: Boolean);
|
|
protected
|
|
procedure ActivarModoAnadir; override;
|
|
procedure ActivarModoModificar; override;
|
|
procedure ActivarModoConsultar; override;
|
|
procedure ActivarModoEliminar; override;
|
|
function AnadirDatos : Boolean; override;
|
|
function ModificarDatos : Boolean; override;
|
|
function EliminarDatos : Boolean; override;
|
|
function CancelarAnadir : Boolean; override;
|
|
function CancelarModificar : Boolean; override;
|
|
function CancelarEliminar : Boolean; override;
|
|
function ComprobarDatos : Boolean; override;
|
|
procedure VerModal; override;
|
|
procedure FreeContenido; override;
|
|
procedure BuscarPresupuesto; override;
|
|
property CodigoProvincia : Variant read FCodigoProvincia write SetCodigoProvincia;
|
|
property CodigoPoblacion : Variant read FCodigoPoblacion write SetCodigoPoblacion;
|
|
property CodigoCliente : Variant read FCodigoCliente write SetCodigoCliente;
|
|
property CodigoArticulo : Variant read FCodigoArticulo write SetCodigoArticulo;
|
|
property CodigoVendedor : Variant read FCodigoVendedor write SetCodigoVendedor;
|
|
property TablaDetallesMem : TRxMemoryData read FTablaDetallesMem write FTablaDetallesMem;
|
|
property TablaPropiedadesMem : TRxMemoryData read FTablaPropiedadesMem write FTablaPropiedadesMem;
|
|
public
|
|
constructor Create (AOwner : TComponent); override;
|
|
destructor Destroy; override;
|
|
published
|
|
property TablaPresupuestos;
|
|
property TablaDetallesPresupuestos;
|
|
property CodigoPresupuesto;
|
|
end;
|
|
|
|
var
|
|
frPresupuestoCliente: TfrPresupuestoCliente;
|
|
|
|
implementation
|
|
|
|
{$R *.DFM}
|
|
|
|
uses
|
|
cxGridDBDataDefinitions, PresupuestosClientes, BaseDatos, TablaPresupuestos,
|
|
IBDatabase, Literales, Mensajes, Clientes, RdxFrameProvincias, RdxFramePoblaciones,
|
|
TablaProvincias, Provincias, Poblaciones, TablaClientes, RdxFrameClientes,
|
|
IB, Articulos, RdxFrameArticulos, Variants, TablaPropiedadesArticulo,
|
|
StrFunc, TablaPoblaciones, Excepciones, IBErrorCodes,
|
|
IBSQL, NumFunc, Vendedores, TablaVendedores, PropiedadesArticulo,
|
|
RdxDBFrame, TablaFamilias, ElegirDireccionCliente, TablaEmpresas, Constantes,
|
|
SysFunc, JclFileUtils, ShellApi, WinProcs;
|
|
|
|
{ TfrPresupuestoCliente }
|
|
procedure TfrPresupuestoCliente.ActivarModoAnadir;
|
|
var
|
|
CodNuevo : Variant;
|
|
begin
|
|
dsPresupuesto.AutoEdit := True;
|
|
dsDetallesPresupuesto.AutoEdit := True;
|
|
dsPropiedadesPresupuesto.AutoEdit := True;
|
|
|
|
Codigo.Properties.Buttons[0].Visible := False;
|
|
Codigo.Properties.ReadOnly := False;
|
|
CodCliente.Properties.Buttons[0].Visible := True;
|
|
Poblacion.Properties.Buttons[0].Visible := True;
|
|
Provincia.Properties.Buttons[0].Visible := True;
|
|
|
|
DesactivarEventosCampos;
|
|
try
|
|
CodNuevo := dmTablaPresupuestos.DarNuevoCodigo;
|
|
with TablaPresupuestos do
|
|
begin
|
|
Close;
|
|
Prepare;
|
|
Open;
|
|
FieldByName('PROVINCIA').OnSetText := ProvinciaSetText;
|
|
Insert;
|
|
FCodigoPresupuesto := CodNuevo;
|
|
Codigo.DataBinding.Field.AsString := FCodigoPresupuesto;
|
|
Codigo.Properties.ReadOnly := True;
|
|
FieldByName('FECHAALTA').AsDateTime := dmBaseDatos.DarFecha;
|
|
FieldByName('USUARIO').AsString := dmBaseDatos.Usuario;
|
|
FieldByName('IVA').AsString := EmpresaActiva.IvaDefecto;
|
|
FechaPresupuesto.DataBinding.Field.AsDateTime := dmBaseDatos.DarFecha;
|
|
Vigencia.DataBinding.Field.AsDateTime := IncMonth(dmBaseDatos.DarFecha, EmpresaActiva.ValidezDefecto);
|
|
|
|
cbxSituacion.DataBinding.Field.AsString := cbxSituacion.Properties.Items[0];
|
|
end;
|
|
|
|
with TablaDetallesPresupuestos do
|
|
begin
|
|
Close;
|
|
Params.ByName('CODIGOPRESUPUESTO').AsString := CodNuevo;
|
|
Prepare;
|
|
Open;
|
|
end;
|
|
|
|
with TablaPropiedadesPresupuestos do
|
|
begin
|
|
Close;
|
|
Params.ByName('CODIGOPRESUPUESTO').AsString := CodNuevo;
|
|
Prepare;
|
|
Open;
|
|
end;
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
Close;
|
|
Filtered := False;
|
|
OnFilterRecord := NIL;
|
|
Open;
|
|
end;
|
|
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
Close;
|
|
Filtered := False;
|
|
onFilterRecord := NIL;
|
|
Open;
|
|
end;
|
|
|
|
dmTablaPresupuestos.InicializarTablaPresupuestos(@TablaPresupuestos);
|
|
dmTablaPresupuestos.InicializarTablaDetalles(@TablaDetallesMem);
|
|
ActivarEdicionGridDetalles(VistaDetalles);
|
|
cbxDocumento.DataBinding.Field.AsString := dmTablaDocumentos.DarCodigoDocumento(Entidad);
|
|
CargarDatosDocumento(cbxDocumento.DataBinding.Field.AsString);
|
|
|
|
ConfigurarPantallaDocumento;
|
|
InsertarDetallesDefecto;
|
|
|
|
if Entidad = entPresupuestoCocina then
|
|
begin
|
|
Desgloses.Clear;
|
|
with Desgloses.Lines do
|
|
begin
|
|
Add('ESTE PRESUPUESTO INCLUYE:');
|
|
Add('');
|
|
Add('- Muebles bajos de altura 80 cm y zócalo de 5 cm, para ganar capacidad en zona baja.');
|
|
Add('- Todos los cajones y gavetas incluyen el sistema de frenado automático (Sitema Blumotion).');
|
|
Add('- Lavavajillas Integrable Total.');
|
|
Add('- Todos los costados, cornisas y cubreluces tienen un grosor de 3 cm.');
|
|
end;
|
|
TablaPresupuestos.FieldByName('DESGLOSES').AsVariant := Desgloses.Lines.Text;
|
|
end;
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
if not (Entidad in [entPresupuestoCliente, entPresupuestoVarios, entPresupuestoElectro]) then
|
|
begin
|
|
OnFilterRecord := TablaMemDetallesFilterRecord;
|
|
Filtered := True;
|
|
end;
|
|
end;
|
|
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
if (Entidad = entPresupuestoArmarios) then
|
|
begin
|
|
OnFilterRecord := TablaMemPropiedadesFilterRecord;
|
|
Filtered := True;
|
|
end;
|
|
end;
|
|
|
|
FObservaciones1 := '';
|
|
FObservaciones2 := '';
|
|
Observaciones.Lines.Text := '';
|
|
|
|
ActivarEventosCampos;
|
|
Visible := True;
|
|
|
|
|
|
//Documentos asociados al presupuesto
|
|
if (Entidad in [entPresupuestoCocina, entPresupuestoArmarios]) then
|
|
begin
|
|
pnlBarraDocumentos.Visible := True;
|
|
FDirectorio := '\' + ExtractFileName(darFicheroTemporal);
|
|
FDirectorioPlanos := FDirectorio;
|
|
|
|
CrearDirDocumentos;
|
|
CrearDirPlanos;
|
|
end;
|
|
|
|
FechaPresupuesto.SetFocus;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ActivarModoConsultar;
|
|
begin
|
|
dsPresupuesto.AutoEdit := False;
|
|
dsDetallesPresupuesto.AutoEdit := False;
|
|
dsPropiedadesPresupuesto.AutoEdit := False;
|
|
|
|
Codigo.Properties.Buttons[0].Visible := True;
|
|
CodCliente.Properties.Buttons[0].Visible := False;
|
|
Poblacion.Properties.Buttons[0].Visible := False;
|
|
Provincia.Properties.Buttons[0].Visible := False;
|
|
|
|
try
|
|
with TablaPresupuestos do
|
|
begin
|
|
if RecordCount = 0 then
|
|
begin
|
|
VerMensajeFmt(msgCliNoExistePre, [CodigoPresupuesto]);
|
|
CloseFrame;
|
|
Exit;
|
|
end;
|
|
Cancel;
|
|
end;
|
|
|
|
dmTablaPresupuestos.InicializarTablaPresupuestos(@TablaPresupuestos);
|
|
dmTablaPresupuestos.InicializarTablaDetalles(@TablaDetallesMem);
|
|
DesactivarEdicionGridDetalles(gridDetalles);
|
|
Entidad := dmTablaDocumentos.DarEntidadDocumento(entPresupuestoCliente,cbxDocumento.DataBinding.Field.AsString);
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
if not (Entidad in [entPresupuestoCliente, entPresupuestoVarios, entPresupuestoElectro]) then
|
|
begin
|
|
OnFilterRecord := TablaMemDetallesFilterRecord;
|
|
Filtered := True;
|
|
end;
|
|
end;
|
|
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
if (Entidad = entPresupuestoArmarios) then
|
|
begin
|
|
OnFilterRecord := TablaMemPropiedadesFilterRecord;
|
|
Filtered := True;
|
|
end;
|
|
end;
|
|
|
|
ConfigurarPantallaDocumento;
|
|
Visible := True;
|
|
|
|
//Documentos asociados al presupuesto
|
|
if (Entidad in [entPresupuestoCocina, entPresupuestoArmarios]) then
|
|
begin
|
|
pnlBarraDocumentos.Visible := False;
|
|
FDirectorio := PathDelim + StringReplace(CodigoPresupuesto,'/','',[rfReplaceAll]);
|
|
FDirectorioPlanos := FDirectorio;
|
|
if DirectoryExists(darRutaDocumentosPresupuesto) then
|
|
HabilitarDocumentos
|
|
else
|
|
DeshabilitarDocumentos;
|
|
|
|
if DirectoryExists(darRutaPlanosPresupuesto) then
|
|
HabilitarPlanos
|
|
else
|
|
DeshabilitarPlanos;
|
|
end;
|
|
|
|
FechaPresupuesto.SetFocus;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ActivarModoEliminar;
|
|
begin
|
|
dsPresupuesto.AutoEdit := False;
|
|
dsDetallesPresupuesto.AutoEdit := False;
|
|
dsPropiedadesPresupuesto.AutoEdit := False;
|
|
|
|
Codigo.Properties.Buttons[0].Visible := True;
|
|
CodCliente.Properties.Buttons[0].Visible := False;
|
|
Poblacion.Properties.Buttons[0].Visible := False;
|
|
Provincia.Properties.Buttons[0].Visible := False;
|
|
|
|
try
|
|
with TablaPresupuestos do
|
|
begin
|
|
if RecordCount = 0 then
|
|
begin
|
|
VerMensajeFmt(msgCliNoExistePre, [CodigoPresupuesto]);
|
|
CancelarEliminar;
|
|
CloseFrame;
|
|
Exit;
|
|
end;
|
|
Cancel;
|
|
end;
|
|
|
|
dmTablaPresupuestos.InicializarTablaPresupuestos(@TablaPresupuestos);
|
|
dmTablaPresupuestos.InicializarTablaDetalles(@TablaDetallesMem);
|
|
Entidad := dmTablaDocumentos.darEntidadDocumento(entPresupuestoCliente, cbxDocumento.DataBinding.Field.AsString);
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
if not (Entidad in [entPresupuestoCliente, entPresupuestoVarios, entPresupuestoElectro]) then
|
|
begin
|
|
OnFilterRecord := TablaMemDetallesFilterRecord;
|
|
Filtered := True;
|
|
end;
|
|
end;
|
|
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
if (Entidad = entPresupuestoArmarios) then
|
|
begin
|
|
OnFilterRecord := TablaMemPropiedadesFilterRecord;
|
|
Filtered := True;
|
|
end;
|
|
end;
|
|
|
|
ConfigurarPantallaDocumento;
|
|
DesactivarEdicionGridDetalles(gridDetalles);
|
|
Visible := True;
|
|
|
|
//Documentos asociados al presupuesto
|
|
if (Entidad in [entPresupuestoCocina, entPresupuestoArmarios]) then
|
|
begin
|
|
pnlBarraDocumentos.Visible := False;
|
|
FDirectorio := PathDelim + StringReplace(CodigoPresupuesto,'/','',[rfReplaceAll]);
|
|
FDirectorioPlanos := FDirectorio;
|
|
if DirectoryExists(darRutaDocumentosPresupuesto) then
|
|
HabilitarDocumentos
|
|
else
|
|
DeshabilitarDocumentos;
|
|
|
|
if DirectoryExists(darRutaPlanosPresupuesto) then
|
|
HabilitarPlanos
|
|
else
|
|
DeshabilitarPlanos;
|
|
end;
|
|
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ActivarModoModificar;
|
|
var
|
|
s: String;
|
|
begin
|
|
dsPresupuesto.AutoEdit := True;
|
|
dsDetallesPresupuesto.AutoEdit := True;
|
|
dsPropiedadesPresupuesto.AutoEdit := True;
|
|
|
|
Codigo.Properties.Buttons[0].Visible := True;
|
|
Codigo.Properties.ReadOnly := True;
|
|
CodCliente.Properties.Buttons[0].Visible := True;
|
|
Poblacion.Properties.Buttons[0].Visible := True;
|
|
Provincia.Properties.Buttons[0].Visible := True;
|
|
|
|
try
|
|
with TablaPresupuestos do
|
|
begin
|
|
if RecordCount = 0 then
|
|
begin
|
|
VerMensajeFmt(msgCliNoExistePre, [CodigoPresupuesto]);
|
|
CancelarModificar;
|
|
CloseFrame;
|
|
Exit;
|
|
end;
|
|
|
|
Edit;
|
|
Post;
|
|
Edit;
|
|
end;
|
|
|
|
dmTablaPresupuestos.InicializarTablaPresupuestos(@TablaPresupuestos);
|
|
dmTablaPresupuestos.InicializarTablaDetalles(@TablaDetallesMem);
|
|
ActivarEdicionGridDetalles(gridDetalles);
|
|
FCodigoProvincia := dmTablaProvincias.DarCodigoProvincia(Provincia.Text);
|
|
Entidad := dmTablaDocumentos.darEntidadDocumento(entPresupuestoCliente, cbxDocumento.DataBinding.Field.AsString);
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
if not (Entidad in [entPresupuestoCliente, entPresupuestoVarios, entPresupuestoElectro]) then
|
|
begin
|
|
OnFilterRecord := TablaMemDetallesFilterRecord;
|
|
Filtered := True;
|
|
end;
|
|
end;
|
|
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
if (Entidad = entPresupuestoArmarios) then
|
|
begin
|
|
OnFilterRecord := TablaMemPropiedadesFilterRecord;
|
|
Filtered := True;
|
|
end;
|
|
end;
|
|
|
|
ActivarEventosCampos;
|
|
ConfigurarPantallaDocumento;
|
|
Visible := True;
|
|
|
|
//Documentos asociados al presupuesto
|
|
if (Entidad in [entPresupuestoCocina, entPresupuestoArmarios]) then
|
|
begin
|
|
pnlBarraDocumentos.Visible := True;
|
|
FDirectorio := '\' + StringReplace(CodigoPresupuesto,'/','',[rfReplaceAll]);
|
|
FDirectorioPlanos := FDirectorio;
|
|
|
|
CrearDirDocumentos;
|
|
CrearDirPlanos;
|
|
end;
|
|
|
|
FechaPresupuesto.SetFocus;
|
|
except
|
|
on E : EIBError do
|
|
begin
|
|
case E.IBErrorCode of
|
|
isc_lock_conflict : begin
|
|
VerMensajeFmt(msgCliPreBloqueado, [CodigoPresupuesto]);
|
|
CancelarModificar;
|
|
CloseFrame;
|
|
Exit;
|
|
end
|
|
else
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.AnadirDatos: Boolean;
|
|
var
|
|
CodAux : String;
|
|
begin
|
|
try
|
|
CalcularTotalPresupuesto;
|
|
TablaPresupuestos.Post;
|
|
|
|
BorrarTabla(TablaDetallesPresupuestos);
|
|
SalvarDetalles;
|
|
BorrarTabla(TablaPropiedadesPresupuestos);
|
|
SalvarPropiedades;
|
|
|
|
dmTablaPresupuestos.IncrementarCodigo;
|
|
Commit;
|
|
FCodigoPresupuesto := TablaPresupuestos.FieldByName('CODIGO').AsString;
|
|
|
|
ComprobarEstadoDirDocumentos;
|
|
ComprobarEstadoDirPlanos;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do begin
|
|
if E.IBErrorCode = isc_unique_key_violation then
|
|
begin
|
|
// El código ya se ha utilizado
|
|
CodAux := dmTablaPresupuestos.DarNuevoCodigo;
|
|
VerMensajeFmt(msgCliCodPreRepetido, [Codigo.DataBinding.Field.AsString, CodAux]);
|
|
TablaPresupuestos.Edit;
|
|
TablaPresupuestos.FieldByName('CODIGO').AsString := CodAux;
|
|
TablaPresupuestos.Post;
|
|
AnadirDatos;
|
|
// Codigo.DataBinding.Field.AsString := CodAux;
|
|
end
|
|
else
|
|
TratarExcepcion(E);
|
|
end;
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.BuscarPresupuesto;
|
|
begin
|
|
if Transaccion = NIL then
|
|
Exit;
|
|
|
|
try
|
|
TablaPresupuestos.DisableControls;
|
|
TablaDetallesPresupuestos.DisableControls;
|
|
TablaDetallesMem.DisableControls;
|
|
TablaPropiedadesPresupuestos.DisableControls;
|
|
TablaPropiedadesMem.DisableControls;
|
|
|
|
DesactivarEventosCampos;
|
|
|
|
TablaPresupuestos.Close;
|
|
TablaDetallesPresupuestos.Close;
|
|
with TablaDetallesMem do
|
|
begin
|
|
Close;
|
|
Filtered := False;
|
|
OnFilterRecord := NIL;
|
|
end;
|
|
|
|
with TablaPropiedadesPresupuestos do
|
|
begin
|
|
Close;
|
|
Filtered := False;
|
|
OnFilterRecord := NIL;
|
|
end;
|
|
|
|
// Buscar la fila a tratar si es necesario
|
|
if not EsCadenaVacia(FCodigoPresupuesto) then
|
|
begin
|
|
TablaPresupuestos.Params.ByName('CODIGO').AsString := FCodigoPresupuesto;
|
|
TablaDetallesPresupuestos.Params.ByName('CODIGOPRESUPUESTO').AsString := FCodigoPresupuesto;
|
|
TablaPropiedadesPresupuestos.Params.ByName('CODIGOPRESUPUESTO').AsString := FCodigoPresupuesto;
|
|
end;
|
|
|
|
TablaPresupuestos.Prepare;
|
|
TablaPresupuestos.Open;
|
|
|
|
Entidad := dmTablaDocumentos.DarEntidadDocumento(entPresupuestoCliente,TablaPresupuestos.FieldByName('CODIGODOCUMENTO').AsString);
|
|
|
|
TablaDetallesPresupuestos.Prepare;
|
|
TablaDetallesPresupuestos.Open;
|
|
|
|
TablaPropiedadesPresupuestos.Prepare;
|
|
TablaPropiedadesPresupuestos.Open;
|
|
|
|
TablaDetallesMem.Open;
|
|
CargarDetalles;
|
|
if not (Entidad in [entPresupuestoCliente, entPresupuestoVarios, entPresupuestoElectro]) then
|
|
begin
|
|
with TablaDetallesMem do
|
|
begin
|
|
First;
|
|
FObservaciones1 := FieldByName('OBSERVACIONES').AsString;
|
|
Observaciones.Lines.Clear;
|
|
Observaciones.Lines.Text := FObservaciones1;
|
|
if Entidad = entPresupuestoArmarios then
|
|
begin
|
|
Next;
|
|
FObservaciones2 := FieldByName('OBSERVACIONES').AsString;
|
|
end;
|
|
end;
|
|
|
|
TablaDetallesMem.OnFilterRecord := TablaMemDetallesFilterRecord;
|
|
TablaDetallesMem.Filtered := True;
|
|
end;
|
|
|
|
TablaPropiedadesMem.Open;
|
|
CargarPropiedades;
|
|
if Entidad = entPresupuestoArmarios then
|
|
begin
|
|
TablaDetallesMem.OnFilterRecord := TablaMemPropiedadesFilterRecord;
|
|
TablaDetallesMem.Filtered := True;
|
|
end;
|
|
|
|
if not TablaDocumentos.Active then
|
|
TablaDocumentos.Open;
|
|
|
|
dmTablaPresupuestos.InicializarTablaPresupuestos(@TablaPresupuestos);
|
|
dmTablaPresupuestos.InicializarTablaDetalles(@TablaDetallesMem);
|
|
|
|
ActivarEventosCampos;
|
|
|
|
TablaPresupuestos.EnableControls;
|
|
TablaDetallesPresupuestos.EnableControls;
|
|
TablaDetallesMem.EnableControls;
|
|
TablaPropiedadesPresupuestos.EnableControls;
|
|
TablaPropiedadesMem.EnableControls;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CalcularTotalDetalle;
|
|
var
|
|
auxCantidad,
|
|
auxPrecio,
|
|
auxTotal : double;
|
|
begin
|
|
with TablaDetallesMem do
|
|
begin
|
|
Edit;
|
|
auxCantidad := FieldByName('CANTIDAD').AsFloat;
|
|
auxPrecio := FieldByName('IMPORTEUNIDAD').AsFloat;
|
|
auxTotal := (auxCantidad * auxPrecio);
|
|
FieldByName('IMPORTETOTAL').AsFloat := auxTotal;
|
|
end;
|
|
CalcularTotalPresupuesto;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CalcularTotalPresupuesto;
|
|
var
|
|
BaseImponible,
|
|
ImporteIVA,
|
|
ImporteDto,
|
|
ImporteTotal : Double;
|
|
FDetallesBookmark : string;
|
|
begin
|
|
BaseImponible := 0;
|
|
ImporteTotal := 0;
|
|
with TablaDetallesMem do
|
|
begin
|
|
DisableControls;
|
|
FDetallesBookmark := Bookmark;
|
|
try
|
|
First;
|
|
while not EOF do begin
|
|
BaseImponible := BaseImponible + FieldByName('IMPORTETOTAL').AsFloat;
|
|
Next;
|
|
end;
|
|
|
|
ImporteDto := BaseImponible * (TablaPresupuestos.FieldByName('DESCUENTO').AsFloat/100);
|
|
ImporteTotal := BaseImponible - ImporteDto;
|
|
ImporteIVA := ImporteTotal * (TablaPresupuestos.FieldByName('IVA').AsFloat/100);
|
|
ImporteTotal := ImporteTotal + ImporteIVA;
|
|
|
|
TablaPresupuestos.Edit;
|
|
TablaPresupuestos.FieldByName('BASEIMPONIBLE').AsFloat := BaseImponible;
|
|
TablaPresupuestos.FieldByName('IMPORTEDESCUENTO').AsFloat := ImporteDto;
|
|
TablaPresupuestos.FieldByName('IMPORTEIVA').AsFloat := ImporteIVA;
|
|
TablaPresupuestos.FieldByName('IMPORTETOTAL').AsFloat := ImporteTotal;
|
|
finally
|
|
Bookmark := FDetallesBookmark;
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.CancelarAnadir: Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
TablaPresupuestos.Cancel;
|
|
TablaDetallesMem.Cancel;
|
|
TablaPropiedadesMem.Cancel;
|
|
RollBack;
|
|
|
|
if (Entidad in [entPresupuestoCocina, entPresupuestoArmarios]) then
|
|
begin
|
|
EliminarDirDocumentos;
|
|
EliminarDirPlanos;
|
|
end;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.CancelarEliminar: Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
RollBack;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.CancelarModificar: Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
TablaPresupuestos.Cancel;
|
|
TablaDetallesMem.Cancel;
|
|
TablaPropiedadesMem.Cancel;
|
|
RollBack;
|
|
|
|
ComprobarEstadoDirDocumentos;
|
|
ComprobarEstadoDirPlanos;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.ComprobarDatos: Boolean;
|
|
var
|
|
AuxNumDetalles : integer;
|
|
begin
|
|
Result := False;
|
|
|
|
if not (Modo in [Anadir, Modificar]) then
|
|
begin
|
|
Result := True;
|
|
exit;
|
|
end;
|
|
|
|
if EsCadenaVacia(FechaPresupuesto.DataBinding.Field.AsString) then
|
|
begin
|
|
VerMensaje(msgCliFaltaFechaAltaPre);
|
|
FechaPresupuesto.SetFocus;
|
|
Exit;
|
|
end;
|
|
|
|
if ((UpperCase(cbxSituacion.DataBinding.Field.AsString) = 'ACEPTADO') or
|
|
(UpperCase(cbxSituacion.DataBinding.Field.AsString) = 'ANULADO')) and
|
|
EsCadenaVacia(FechaDecision.DataBinding.Field.AsString) then
|
|
begin
|
|
VerMensaje(msgCliFaltaFechaDecisionPre);
|
|
FechaDecision.SetFocus;
|
|
Exit;
|
|
end;
|
|
|
|
if (UpperCase(cbxSituacion.DataBinding.Field.AsString) = 'PENDIENTE') and
|
|
not EsCadenaVacia(FechaDecision.DataBinding.Field.AsString) then
|
|
begin
|
|
VerMensaje(msgCliSobraFechaDecisionPre);
|
|
FechaDecision.SetFocus;
|
|
Exit;
|
|
end;
|
|
|
|
if Modo = Anadir then
|
|
begin
|
|
if EsCadenaVacia(CodCliente.DataBinding.Field.AsString) then
|
|
begin
|
|
VerMensaje(msgCliFaltaCodCli);
|
|
Paginas.ActivePageIndex := 0;
|
|
CodCliente.SetFocus;
|
|
Exit;
|
|
end
|
|
end
|
|
else
|
|
begin
|
|
if EsCadenaVacia(Nombre.DataBinding.Field.AsString) then
|
|
begin
|
|
VerMensaje(msgCliFaltaNombreCli);
|
|
Paginas.ActivePageIndex := 0;
|
|
Nombre.SetFocus;
|
|
Exit;
|
|
end
|
|
end;
|
|
|
|
if TablaDetallesMem.IsEmpty then
|
|
begin
|
|
VerMensaje(msgCliFaltaArticulosPre);
|
|
Paginas.ActivePage := pagContenido;
|
|
gridDetalles.SetFocus;
|
|
Exit
|
|
end;
|
|
|
|
Result := True;
|
|
end;
|
|
|
|
constructor TfrPresupuestoCliente.Create(AOwner: TComponent);
|
|
begin
|
|
inherited Create(AOwner);
|
|
Entidad := entPresupuestoCliente;
|
|
|
|
FObservaciones1 := '';
|
|
FObservaciones2 := '';
|
|
FCodigoProvincia := NULL;
|
|
FCodigoPoblacion := NULL;
|
|
FCodigoCliente := NULL;
|
|
FCodigoArticulo := NULL;
|
|
FCodigoVendedor := NULL;
|
|
FRootDocumentos := dmBaseDatos.DarValorConfiguracion(CTE_DOCUMENTOS);
|
|
FRootPlanos := dmBaseDatos.DarValorConfiguracion(CTE_PLANOS);
|
|
FDirectorio := NULL;
|
|
FDirectorioPlanos := NULL;
|
|
|
|
BaseDatos := dmBaseDatos.BD;
|
|
Transaccion := dmBaseDatos.Transaccion;
|
|
|
|
TablaPresupuestos := TIBDataSet.Create(Self);
|
|
TablaDetallesPresupuestos := TIBDataSet.Create(Self);
|
|
TablaPropiedadesPresupuestos := TIBDataSet.Create(Self);
|
|
TablaDetallesMem := TRxMemoryData.Create(Self);
|
|
TablaPropiedadesMem := TRxMemoryData.Create(Self);
|
|
|
|
dsPresupuesto.DataSet := TablaPresupuestos;
|
|
dsDetallesPresupuesto.DataSet := TablaDetallesMem;
|
|
dsPropiedadesPresupuesto.DataSet := TablaPropiedadesMem;
|
|
|
|
with TablaDocumentos do
|
|
begin
|
|
Database := BaseDatos;
|
|
Transaction := Transaccion;
|
|
end;
|
|
|
|
with TablaPresupuestos do
|
|
begin
|
|
Database := BaseDatos;
|
|
Transaction := Transaccion;
|
|
SelectSQL.Assign(dmTablaPresupuestos.sqlConsultarPresupuesto);
|
|
InsertSQL.Assign(dmTablaPresupuestos.sqlInsertarPresupuesto);
|
|
ModifySQL.Assign(dmTablaPresupuestos.sqlModificarPresupuesto);
|
|
DeleteSQL.Assign(dmTablaPresupuestos.sqlEliminarPresupuesto);
|
|
RefreshSQL.Assign(dmTablaPresupuestos.sqlConsultarPresupuesto);
|
|
end;
|
|
|
|
with TablaDetallesPresupuestos do
|
|
begin
|
|
Database := BaseDatos;
|
|
Transaction := Transaccion;
|
|
SelectSQL.Assign(dmTablaPresupuestos.sqlConsultarGridDetalles);
|
|
InsertSQL.Assign(dmTablaPresupuestos.sqlInsertarDetalles);
|
|
ModifySQL.Assign(dmTablaPresupuestos.sqlModificarDetalles);
|
|
DeleteSQL.Assign(dmTablaPresupuestos.sqlEliminarDetalles);
|
|
RefreshSQL.Assign(dmTablaPresupuestos.sqlConsultarDetalles);
|
|
end;
|
|
|
|
with TablaPropiedadesPresupuestos do
|
|
begin
|
|
Database := BaseDatos;
|
|
Transaction := Transaccion;
|
|
SelectSQL.Assign(dmTablaPresupuestos.sqlConsultarGridPropiedades);
|
|
InsertSQL.Assign(dmTablaPresupuestos.sqlInsertarPropiedades);
|
|
ModifySQL.Assign(dmTablaPresupuestos.sqlModificarPropiedades);
|
|
DeleteSQL.Assign(dmTablaPresupuestos.sqlEliminarPropiedades);
|
|
RefreshSQL.Assign(dmTablaPresupuestos.sqlConsultarPropiedades);
|
|
end;
|
|
|
|
with TablaPropiedades do
|
|
begin
|
|
Database := BaseDatos;
|
|
Transaction := Transaccion;
|
|
Open;
|
|
end;
|
|
|
|
with TablaValores do
|
|
begin
|
|
Database := BaseDatos;
|
|
Transaction := Transaccion;
|
|
end;
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
CopyStructure(TablaDetallesPresupuestos);
|
|
end;
|
|
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
CopyStructure(TablaPropiedadesPresupuestos);
|
|
end;
|
|
|
|
dmTablaPresupuestos.InicializarGridPropiedades(VistaPropiedades);
|
|
with TcxLookupComboBoxProperties(VistaPropiedades.GetRowByFieldName('CODIGOPROPIEDAD').Properties) do
|
|
begin
|
|
ListSource := dsPropiedades;
|
|
end;
|
|
VistaPropiedades.GetRowByFieldName('VALOR').OnGetProperties := VALORGetProperties;
|
|
|
|
dmTablaPresupuestos.InicializarGridDetalles(VistaDetalles);
|
|
//dmTablaPresupuestos.InicializarGridPrecios(VistaPrecios);
|
|
cbxSituacion.Properties.Items := dmTablaPresupuestos.DarSituaciones;
|
|
dmTablaArticulos.ArtModelo := entArticulo;
|
|
Paginas.ActivePage := pagCliente;
|
|
end;
|
|
|
|
destructor TfrPresupuestoCliente.Destroy;
|
|
begin
|
|
TablaDocumentos.Close;
|
|
TablaPropiedades.Close;
|
|
TablaValores.Close;
|
|
|
|
TablaDetallesMem.Close;
|
|
TablaDetallesMem.Free;
|
|
|
|
TablaPropiedadesMem.Close;
|
|
TablaPropiedadesMem.Free;
|
|
|
|
TablaPresupuestos.Close;
|
|
TablaPresupuestos.UnPrepare;
|
|
TablaPresupuestos.Free;
|
|
|
|
TablaDetallesPresupuestos.Close;
|
|
TablaDetallesPresupuestos.Unprepare;
|
|
TablaDetallesPresupuestos.Free;
|
|
|
|
TablaPropiedadesPresupuestos.Close;
|
|
TablaPropiedadesPresupuestos.UnPrepare;
|
|
TablaPropiedadesPresupuestos.Free;
|
|
inherited;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.EliminarDatos: Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
TablaPresupuestos.Delete;
|
|
BorrarTabla(TablaDetallesMem);
|
|
BorrarTabla(TablaPropiedadesMem);
|
|
Commit;
|
|
|
|
|
|
if (Entidad in [entPresupuestoCocina, entPresupuestoArmarios]) then
|
|
begin
|
|
EliminarDirDocumentos;
|
|
EliminarDirPlanos;
|
|
end;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
begin
|
|
case E.IBErrorCode of
|
|
isc_lock_conflict : VerMensajeFmt(msgCliPreBloqueado, [Codigo.DataBinding.Field.AsString]);
|
|
else
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.FreeContenido;
|
|
var
|
|
Contador : integer;
|
|
AListaCodigos : TStringList;
|
|
begin
|
|
if (ContenidoModal is TRdxFramePresupuestos) then
|
|
begin
|
|
CodigoPresupuesto := (ContenidoModal as TRdxFramePresupuestos).CodigoPresupuesto;
|
|
ActivarModo;
|
|
end;
|
|
if (ContenidoModal is TRdxFrameClientes) then
|
|
CodigoCliente := (ContenidoModal as TRdxFrameClientes).CodigoCliente;
|
|
if (ContenidoModal is TRdxFrameVendedores) then
|
|
CodigoVendedor := (ContenidoModal as TRdxFrameVendedores).CodigoVendedor;
|
|
if (ContenidoModal is TRdxFrameProvincias) then
|
|
CodigoProvincia := (ContenidoModal as TRdxFrameProvincias).CodigoProvincia;
|
|
|
|
if (ContenidoModal is TfrArticulos) then
|
|
begin
|
|
//CodigoArticulo := (ContenidoModal as TRdxFrameArticulos).CodigoArticulo;
|
|
|
|
AListaCodigos := (ContenidoModal as TfrArticulos).ListaArticulos;
|
|
for Contador := AListaCodigos.Count - 1 downto 0 do
|
|
begin
|
|
CodigoArticulo := AListaCodigos.Strings[Contador];
|
|
actAnadirDetalle.Execute;
|
|
end;
|
|
TablaDetallesMem.Delete;
|
|
end;
|
|
|
|
if (ContenidoModal is TRdxFramePoblaciones) then
|
|
begin
|
|
CodigoProvincia := (ContenidoModal as TRdxFramePoblaciones).CodigoProvincia;
|
|
CodigoPoblacion := (ContenidoModal as TRdxFramePoblaciones).CodigoPoblacion;
|
|
end;
|
|
inherited FreeContenido;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.ModificarDatos: Boolean;
|
|
var
|
|
cadena :String;
|
|
attrs : Integer;
|
|
begin
|
|
Result := False;
|
|
try
|
|
CalcularTotalPresupuesto;
|
|
TablaPresupuestos.Post;
|
|
|
|
BorrarTabla(TablaDetallesPresupuestos);
|
|
SalvarDetalles;
|
|
|
|
BorrarTabla(TablaPropiedadesPresupuestos);
|
|
SalvarPropiedades;
|
|
|
|
Commit;
|
|
|
|
ComprobarEstadoDirDocumentos;
|
|
ComprobarEstadoDirPlanos;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.SetCodigoArticulo(Value: Variant);
|
|
var
|
|
CodigoAux : String;
|
|
DatosArticulo : TDatosArticulo;
|
|
begin
|
|
if (EsCadenaVacia(Value)) then
|
|
begin
|
|
FCodigoArticulo := CodigoAux;
|
|
Exit;
|
|
end;
|
|
|
|
CodigoAux := Trim(Value);
|
|
if (dmTablaArticulos.ValidarCodigo(CodigoAux)) then
|
|
begin
|
|
CodigoAux := dmTablaArticulos.FormatearCodigo(CodigoAux);
|
|
if (dmTablaArticulos.ExisteCodigo(CodigoAux)) then
|
|
FCodigoArticulo := CodigoAux
|
|
else begin
|
|
raise Exception.CreateFmt(msgDatosCodArtNoExiste, [CodigoAux]);
|
|
end;
|
|
end
|
|
else begin
|
|
raise Exception.CreateFmt(msgDatosCodArtIncorrecto, [CodigoAux]);
|
|
Exit;
|
|
end;
|
|
|
|
DatosArticulo := TDatosArticulo.Create(CodigoAux);
|
|
try
|
|
with TablaDetallesMem do
|
|
begin
|
|
Edit;
|
|
FieldByName('CODIGOPRESUPUESTO').AsString := Codigo.DataBinding.Field.AsString;
|
|
FieldByName('NUMCONCEPTO').AsInteger := RecNo;
|
|
FieldByName('CODIGOARTICULO').AsString := DatosArticulo.Codigo;
|
|
FieldByName('REFERENCIA').AsString := DatosArticulo.Referencia;
|
|
FieldByName('DESCRIPCION').AsString := DatosArticulo.Descripcion;
|
|
FieldByName('TIPOCONCEPTO').AsVariant := '';
|
|
FieldByName('IMPORTEUNIDAD').AsFloat := DatosArticulo.Precio;
|
|
if EsCadenaVacia(FieldByName('CANTIDAD').AsString) then
|
|
FieldByName('CANTIDAD').AsString := '1';
|
|
Post;
|
|
InsertarPropiedades(FieldByName('NUMCONCEPTO').AsInteger);
|
|
gridDetalles.Refresh;
|
|
CalcularTotalDetalle;
|
|
end;
|
|
FCodigoArticulo := Value;
|
|
finally
|
|
DatosArticulo.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.SetCodigoCliente(Value: Variant);
|
|
var
|
|
DatosCliente : TDatosCliente;
|
|
CodAux : Variant;
|
|
DireccionElegida : TDireccionElegida;
|
|
NumSucursal : Integer;
|
|
begin
|
|
if EsCadenaVacia(Value) then
|
|
exit;
|
|
|
|
CodAux := Trim(Value);
|
|
if (dmTablaClientes.ValidarCodigo(CodAux)) then begin
|
|
CodAux := dmTablaClientes.FormatearCodigo(CodAux);
|
|
if (dmTablaClientes.ExisteCodigo(CodAux)) then
|
|
FCodigoCliente := CodAux
|
|
else begin
|
|
raise Exception.CreateFmt(msgCliCodCliNoExiste, [CodAux]);
|
|
end;
|
|
end
|
|
else begin
|
|
raise Exception.CreateFmt(msgCliCodCliIncorrecto, [CodAux]);
|
|
end;
|
|
|
|
DatosCliente := TDatosCliente.Create(FCodigoCliente);
|
|
try
|
|
CodCliente.DataBinding.Field.AsString := DatosCliente.Codigo;
|
|
if DatosCliente.Sucursales.Count > 0 then
|
|
begin
|
|
frElegirDireccionCliente := TfrElegirDireccionCliente.Create(Self);
|
|
try
|
|
frElegirDireccionCliente.Cliente := DatosCliente;
|
|
frElegirDireccionCliente.ShowModal;
|
|
DireccionElegida := frElegirDireccionCliente.DireccionSeleccionada;
|
|
NumSucursal := frElegirDireccionCliente.NumSucursal;
|
|
finally
|
|
frElegirDireccionCliente.Free;
|
|
end;
|
|
end
|
|
else
|
|
DireccionElegida := dePrincipal;
|
|
|
|
if DireccionElegida = dePrincipal then
|
|
begin
|
|
NIFCIF.DataBinding.Field.AsString := DatosCliente.Nifcif;
|
|
Nombre.DataBinding.Field.AsString := DatosCliente.Nombre;
|
|
Calle.DataBinding.Field.AsString := DatosCliente.Calle;
|
|
Numero.DataBinding.Field.AsString := DatosCliente.Numero;
|
|
Piso.DataBinding.Field.AsString := DatosCliente.Piso;
|
|
Provincia.DataBinding.Field.AsString := DatosCliente.Provincia;
|
|
FCodigoProvincia := dmTablaProvincias.DarCodigoProvincia(DatosCliente.Provincia);
|
|
Poblacion.DataBinding.Field.AsString := DatosCliente.Poblacion;
|
|
CodigoPostal.DataBinding.Field.AsString := DatosCliente.CodigoPostal;
|
|
Telefono1.DataBinding.Field.AsString := DatosCliente.Telefono1;
|
|
Telefono2.DataBinding.Field.AsString := DatosCliente.Telefono2;
|
|
Movil1.DataBinding.Field.AsString := DatosCliente.Movil1;
|
|
Movil2.DataBinding.Field.AsString := DatosCliente.Movil2;
|
|
Fax.DataBinding.Field.AsString := DatosCliente.Fax;
|
|
PersonaContacto.DataBinding.Field.AsString := DatosCliente.PersonaContacto;
|
|
end
|
|
else begin
|
|
with DatosCliente.Sucursales do
|
|
begin
|
|
NIFCIF.DataBinding.Field.AsString := Sucursal[NumSucursal].Nifcif;
|
|
Nombre.DataBinding.Field.AsString := Sucursal[NumSucursal].Nombre;
|
|
Calle.DataBinding.Field.AsString := Sucursal[NumSucursal].Calle;
|
|
Numero.DataBinding.Field.AsString := Sucursal[NumSucursal].Numero;
|
|
Piso.DataBinding.Field.AsString := Sucursal[NumSucursal].Piso;
|
|
Provincia.DataBinding.Field.AsString := Sucursal[NumSucursal].Provincia;
|
|
FCodigoProvincia := dmTablaProvincias.DarCodigoProvincia(Sucursal[NumSucursal].Provincia);
|
|
Poblacion.DataBinding.Field.AsString := Sucursal[NumSucursal].Poblacion;
|
|
CodigoPostal.DataBinding.Field.AsString := Sucursal[NumSucursal].CodigoPostal;
|
|
Telefono1.DataBinding.Field.AsString := Sucursal[NumSucursal].Telefono1;
|
|
Telefono2.DataBinding.Field.AsString := Sucursal[NumSucursal].Telefono2;
|
|
Movil1.DataBinding.Field.AsString := Sucursal[NumSucursal].Movil1;
|
|
Movil2.DataBinding.Field.AsString := Sucursal[NumSucursal].Movil2;
|
|
Fax.DataBinding.Field.AsString := Sucursal[NumSucursal].Fax;
|
|
PersonaContacto.DataBinding.Field.AsString := Sucursal[NumSucursal].PersonaContacto;
|
|
end;
|
|
end;
|
|
finally
|
|
DatosCliente.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.SetCodigoPoblacion(Value: Variant);
|
|
begin
|
|
if (not EsCadenaVacia(Value)) then
|
|
begin
|
|
FCodigoPoblacion := Value;
|
|
Poblacion.DataBinding.Field.AsString := dmTablaPoblaciones.darNombrePoblacion(FCodigoProvincia, FCodigoPoblacion);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.SetCodigoProvincia(Value: Variant);
|
|
begin
|
|
if (not EsCadenaVacia(Value)) then
|
|
begin
|
|
FCodigoProvincia := Value;
|
|
Provincia.DataBinding.Field.AsString := dmTablaProvincias.DarNombreProvincia(FCodigoProvincia);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.VerModal;
|
|
var
|
|
DatosFamilia : TDatosFamilia;
|
|
begin
|
|
if (ContenidoModal is TRdxFramePoblaciones) then
|
|
(ContenidoModal as TRdxFramePoblaciones).CodigoProvincia := CodigoProvincia;
|
|
|
|
if (ContenidoModal is TRdxFrameClientes) then
|
|
(ContenidoModal as TRdxFrameClientes).CodigoCliente := CodigoCliente;
|
|
|
|
if (ContenidoModal is TfrArticulos) then
|
|
begin
|
|
FCodigoArticulo := TablaDetallesMem.FieldByName('CODIGOARTICULO').AsString;
|
|
if EsCadenaVacia(FCodigoArticulo) then
|
|
begin
|
|
if (not EsCadenaVacia(TablaDocumentos.FieldByName('DESCFAMILIA').AsString)) then
|
|
(ContenidoModal as TfrArticulos).Familia := TablaDocumentos.FieldByName('DESCFAMILIA').AsString;
|
|
end
|
|
else begin
|
|
//DatosFamilia := TDatosFamilia.Create(TablaDetallesMem.FieldByName('FAMILIA').AsInteger);
|
|
try
|
|
//(ContenidoModal as TfrArticulos).Familia := DatosFamilia.Descripcion;
|
|
(ContenidoModal as TfrArticulos).CodigoArticulo := FCodigoArticulo;
|
|
finally
|
|
// DatosFamilia.Free;
|
|
end;
|
|
end;
|
|
end;
|
|
inherited;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.bSalirClick(Sender: TObject);
|
|
begin
|
|
try
|
|
Rollback;
|
|
CloseFrame;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.bGuardarClick(Sender: TObject);
|
|
begin
|
|
if (RealizarOperacion) then
|
|
CloseFrame;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.bCancelarClick(Sender: TObject);
|
|
begin
|
|
if (TratarCambios = IDOK) then
|
|
CloseFrame;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CodClienteButtonClick(Sender: TObject);
|
|
begin
|
|
ContenidoModal := TfrClientes.Create(Self);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CodigoArticuloDetalleSetText(
|
|
Sender: TField; const Text: String);
|
|
begin
|
|
Sender.AsString := Text;
|
|
CodigoArticulo := Text;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CantidadDetalleSetText(Sender: TField;
|
|
const Text: String);
|
|
begin
|
|
if EsCadenaVacia(Text) then
|
|
Sender.AsString := '1'
|
|
else
|
|
Sender.AsString := Text;
|
|
CalcularTotalDetalle;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.PrecioDetalleSetText(Sender: TField;
|
|
const Text: String);
|
|
begin
|
|
if EsCadenaVacia(Text) then
|
|
Sender.AsString := '0'
|
|
else
|
|
Sender.AsString := Text;
|
|
CalcularTotalDetalle;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ProvinciaButtonClick(Sender: TObject);
|
|
begin
|
|
CaptionModal := msgListaProvincias;
|
|
WidthModal := 280;
|
|
HeightModal := 460;
|
|
ContenidoModal := TfrProvincias.Create(Self);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.PoblacionButtonClick(Sender: TObject);
|
|
begin
|
|
if (EsCadenaVacia(CodigoProvincia)) then begin
|
|
VerMensaje(msgSinProvincia);
|
|
Paginas.ActivePageIndex := 0;
|
|
Provincia.SetFocus;
|
|
Exit;
|
|
end;
|
|
CaptionModal := Format(msgListaPoblaciones, [dmTablaProvincias.darNombreProvincia(CodigoProvincia)]);
|
|
WidthModal := 280;
|
|
HeightModal := 460;
|
|
ContenidoModal := TfrPoblaciones.Create(Self);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ActivarEventosCampos;
|
|
begin
|
|
with TablaPresupuestos do
|
|
begin
|
|
FieldByName('CODIGOCLIENTE').OnSetText := CodCliSetText;
|
|
FieldByName('IVA').OnSetText := IVASetText;
|
|
FieldByName('DESCUENTO').OnSetText := DtoSetText;
|
|
end;
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
FieldByName('CODIGOARTICULO').OnSetText := CodigoArticuloDetalleSetText;
|
|
FieldByName('REFERENCIA').OnSetText := ReferenciaArticuloDetalleSetText;
|
|
FieldByName('CANTIDAD').OnSetText := CantidadDetalleSetText;
|
|
FieldByName('IMPORTEUNIDAD').OnSetText := PrecioDetalleSetText;
|
|
AfterDelete := DetalleAfterDelete;
|
|
AfterInsert := DetallesAfterInsert;
|
|
end;
|
|
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
AfterInsert := PropiedadesAfterInsert;
|
|
AfterDelete := PropiedadesAfterDelete;
|
|
end;
|
|
|
|
with VistaDetalles do
|
|
begin
|
|
TcxButtonEditProperties(GetColumnByFieldName('CODIGOARTICULO').Properties).OnButtonClick := GridBotonCodigoArticuloClick;
|
|
TcxButtonEditProperties(GetColumnByFieldName('REFERENCIA').Properties).OnButtonClick := GridBotonReferenciaArticuloClick;
|
|
end;
|
|
|
|
cbxSituacion.Properties.OnChange := cbxSituacionPropertiesChange;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.SalvarDetalles;
|
|
var
|
|
NumeroCampo : Integer;
|
|
begin
|
|
try
|
|
with TablaDetallesMem do
|
|
begin
|
|
DisableControls;
|
|
Filtered := False;
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
TablaDetallesPresupuestos.Append;
|
|
for NumeroCampo := 0 to FieldCount-1 do
|
|
begin
|
|
if Fields[NumeroCampo].FieldName = 'CODIGOPRESUPUESTO' then
|
|
TablaDetallesPresupuestos.Fields[NumeroCampo].AsString := Codigo.DataBinding.Field.AsString
|
|
else
|
|
if Fields[NumeroCampo].FieldName = 'NUMCONCEPTO' then
|
|
TablaDetallesPresupuestos.Fields[NumeroCampo].AsInteger := RecNo - 1
|
|
else
|
|
TablaDetallesPresupuestos.Fields[NumeroCampo].AsVariant := Fields[NumeroCampo].AsVariant;
|
|
end;
|
|
|
|
if (RecNo-1 = 0) and (not (Entidad in [entPresupuestoCliente, entPresupuestoVarios, entPresupuestoElectro])) then
|
|
TablaDetallesPresupuestos.FieldByName('OBSERVACIONES').AsString := FObservaciones1;
|
|
|
|
if (RecNo-1 = 1) and (Entidad = entPresupuestoArmarios) then
|
|
TablaDetallesPresupuestos.FieldByName('OBSERVACIONES').AsString := FObservaciones2;
|
|
|
|
TablaDetallesPresupuestos.Post;
|
|
Next;
|
|
end;
|
|
EnableControls;
|
|
end
|
|
except
|
|
on E : EIBError do begin
|
|
if E.IBErrorCode = isc_unique_key_violation then
|
|
begin
|
|
TablaDetallesPresupuestos.Delete;
|
|
TablaDetallesMem.EnableControls;
|
|
end;
|
|
raise EIBError.Create(E.SQLCode, E.IBErrorCode, E.Message);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CargarDetalles;
|
|
var
|
|
NumeroCampo : Integer;
|
|
begin
|
|
with TablaDetallesMem do
|
|
begin
|
|
if TablaDetallesPresupuestos.IsEmpty then
|
|
Exit;
|
|
DisableControls;
|
|
TablaDetallesPresupuestos.First;
|
|
while not TablaDetallesPresupuestos.EOF do
|
|
begin
|
|
Append;
|
|
for NumeroCampo := 0 to TablaDetallesPresupuestos.FieldCount-1 do
|
|
Fields[NumeroCampo].AsString := TablaDetallesPresupuestos.Fields[NumeroCampo].AsString;
|
|
Post;
|
|
TablaDetallesPresupuestos.Next;
|
|
end;
|
|
First;
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CargarPropiedades;
|
|
var
|
|
NumeroCampo : Integer;
|
|
begin
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
if TablaPropiedadesPresupuestos.IsEmpty then
|
|
Exit;
|
|
DisableControls;
|
|
TablaPropiedadesPresupuestos.First;
|
|
while not TablaPropiedadesPresupuestos.EOF do
|
|
begin
|
|
Append;
|
|
for NumeroCampo := 0 to TablaPropiedadesPresupuestos.FieldCount-1 do
|
|
Fields[NumeroCampo].AsString := TablaPropiedadesPresupuestos.Fields[NumeroCampo].AsString;
|
|
Post;
|
|
TablaPropiedadesPresupuestos.Next;
|
|
end;
|
|
First;
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.DetalleAfterDelete(DataSet: TDataSet);
|
|
begin
|
|
AsignarNumConceptoDetalles;
|
|
CalcularTotalPresupuesto;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actAnadirDetalleExecute(Sender: TObject);
|
|
begin
|
|
try
|
|
with TablaDetallesMem do
|
|
begin
|
|
Next;
|
|
if EOF then
|
|
Append
|
|
else begin
|
|
Prior;
|
|
Insert;
|
|
end;
|
|
end;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actEliminarDetalleExecute(Sender: TObject);
|
|
begin
|
|
if (VerMensajePregunta(msgDeseaBorrar) <> IDYES) then
|
|
Exit;
|
|
if TablaDetallesMem.RecordCount = 0 then begin
|
|
{ Hacemos un cancel de la tabla por si el registro actual estuviera
|
|
recien creado }
|
|
TablaDetallesMem.Cancel;
|
|
Exit
|
|
end;
|
|
try
|
|
BorrarPropiedadesConcepto(TablaDetallesMem.FieldByName('NUMCONCEPTO').AsVariant);
|
|
TablaDetallesMem.Delete;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
CalcularTotalPresupuesto;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ProvinciaSetText(Sender: TField;
|
|
const Text: String);
|
|
begin
|
|
FCodigoProvincia := dmTablaProvincias.DarCodigoProvincia(Text);
|
|
Sender.AsString := Text;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actEliminarTodoDetalleExecute(Sender: TObject);
|
|
begin
|
|
if (VerMensajePregunta(msgDeseaBorrarTodo) <> IDYES) then
|
|
Exit;
|
|
BorrarTabla(TablaDetallesMem);
|
|
BorrarTabla(TablaPropiedadesMem);
|
|
CalcularTotalPresupuesto;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.DtoSetText(Sender: TField;
|
|
const Text: String);
|
|
begin
|
|
if EsCadenaVacia(Text) then
|
|
Sender.AsString := '0'
|
|
else begin
|
|
ValidarDto(Text);
|
|
Sender.AsString := Text;
|
|
end;
|
|
CalcularTotalPresupuesto;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.IVASetText(Sender: TField;
|
|
const Text: String);
|
|
begin
|
|
if EsCadenaVacia(Text) then
|
|
Sender.AsString := '0'
|
|
else begin
|
|
ValidarIVA(Text);
|
|
Sender.AsString := Text;
|
|
end;
|
|
CalcularTotalPresupuesto;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.DetallesAfterInsert(DataSet: TDataSet);
|
|
begin
|
|
with DataSet do
|
|
begin
|
|
Edit;
|
|
FieldByName('CODIGOPRESUPUESTO').AsString := Codigo.DataBinding.Field.AsString;
|
|
FieldByName('NUMCONCEPTO').AsInteger := RecNo;
|
|
FieldByName('DESCRIPCION').AsString := '';
|
|
if EsCadenaVacia(FieldByName('CANTIDAD').AsString) then
|
|
FieldByName('CANTIDAD').AsString := '1';
|
|
if (Entidad in [entPresupuestoCliente, entPresupuestoVarios, entPresupuestoElectro]) then
|
|
FieldByName('TIPOCONCEPTO').AsVariant := ''
|
|
else
|
|
FieldByName('TIPOCONCEPTO').AsVariant := 'PRECIO';
|
|
Post;
|
|
AsignarNumConceptoDetalles;
|
|
Edit;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.VendedorPropertiesButtonClick(
|
|
Sender: TObject; AButtonIndex: Integer);
|
|
begin
|
|
CaptionModal := 'Lista de vendedores';
|
|
ContenidoModal := TfrVendedores.Create(Self);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.SetCodigoVendedor(Value: Variant);
|
|
var
|
|
DatosVendedor : TDatosVendedor;
|
|
begin
|
|
if EsCadenaVacia(Value) then
|
|
exit;
|
|
DatosVendedor := TDatosVendedor.Create;
|
|
DatosVendedor.Codigo := Value;
|
|
try
|
|
if dmTablaVendedores.DarDatosVendedor(DatosVendedor) then
|
|
begin
|
|
with TablaPresupuestos do
|
|
begin
|
|
Edit;
|
|
FieldByName('VENDEDOR').AsString := DatosVendedor.Nombre;
|
|
end;
|
|
FCodigoVendedor := Value;
|
|
end
|
|
else
|
|
raise Exception.CreateFmt(msgDatosCodVendNoExiste, [Value]);
|
|
finally
|
|
DatosVendedor.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CodClientePropertiesButtonClick(
|
|
Sender: TObject; AButtonIndex: Integer);
|
|
begin
|
|
ContenidoModal := TfrClientes.Create(Self);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ProvinciaPropertiesButtonClick(
|
|
Sender: TObject; AButtonIndex: Integer);
|
|
begin
|
|
CaptionModal := msgListaProvincias;
|
|
WidthModal := 280;
|
|
HeightModal := 460;
|
|
ContenidoModal := TfrProvincias.Create(Self);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.PoblacionPropertiesButtonClick(
|
|
Sender: TObject; AButtonIndex: Integer);
|
|
begin
|
|
if EsCadenaVacia(CodigoProvincia) then
|
|
begin
|
|
VerMensaje(msgSinProvincia);
|
|
Paginas.ActivePageIndex := 0;
|
|
Provincia.SetFocus;
|
|
Exit;
|
|
end;
|
|
CaptionModal := Format(msgListaPoblaciones, [dmTablaProvincias.darNombreProvincia(CodigoProvincia)]);
|
|
WidthModal := 280;
|
|
HeightModal := 460;
|
|
ContenidoModal := TfrPoblaciones.Create(Self);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.GridBotonCodigoArticuloClick(
|
|
Sender: TObject; AButtonIndex: Integer);
|
|
begin
|
|
TablaDetallesMem.Edit;
|
|
ContenidoModal := TfrArticulos.Create(Self);
|
|
gridDetalles.SetFocus;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.InsertarPropiedades(NumConcepto : Integer; Seccion : String);
|
|
var
|
|
DatosDocumento : TDocumento;
|
|
Contador : Integer;
|
|
FPropiedad : TDatosPropiedad;
|
|
FNumPropiedad : Integer;
|
|
begin
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
DisableControls;
|
|
DatosDocumento := TDocumento.Create(TablaPresupuestos.FieldByName('CODIGODOCUMENTO').AsString);
|
|
try
|
|
BorrarPropiedadesConcepto(NumConcepto);
|
|
FNumPropiedad := 0;
|
|
First;
|
|
for Contador := 0 to (DatosDocumento.ListaPropiedades.Count - 1) do
|
|
begin
|
|
FPropiedad := DatosDocumento.ListaPropiedades.Items[Contador];
|
|
if (not EsCadenaVacia(Seccion)) and (FPropiedad.Seccion <> Seccion) then
|
|
Continue
|
|
else begin
|
|
Append;
|
|
FieldByName('CODIGOPRESUPUESTO').AsString := CodigoPresupuesto;
|
|
FieldByName('NUMCONCEPTO').AsInteger := NumConcepto;
|
|
FieldByName('NUMPROPIEDAD').AsInteger := FNumPropiedad;
|
|
FieldByName('CODIGOPROPIEDAD').AsInteger := FPropiedad.CodigoPropiedad;
|
|
FieldByName('VALOR').AsString := FPropiedad.Valor;
|
|
Post;
|
|
FNumPropiedad := FNumPropiedad + 1;
|
|
end;
|
|
end;
|
|
First;
|
|
finally
|
|
DatosDocumento.Free;
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.SalvarPropiedades;
|
|
var
|
|
NumeroCampo : Integer;
|
|
begin
|
|
try
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
DisableControls;
|
|
Filtered := False;
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
if not EsCadenaVacia(FieldByName('CODIGOPROPIEDAD').AsVariant) then
|
|
begin
|
|
TablaPropiedadesPresupuestos.Append;
|
|
for NumeroCampo := 0 to FieldCount-1 do
|
|
begin
|
|
if Fields[NumeroCampo].FieldName = 'CODIGOPRESUPUESTO' then
|
|
TablaPropiedadesPresupuestos.Fields[NumeroCampo].AsString := Codigo.DataBinding.Field.AsString
|
|
else
|
|
TablaPropiedadesPresupuestos.Fields[NumeroCampo].AsVariant := Fields[NumeroCampo].AsVariant;
|
|
end;
|
|
TablaPropiedadesPresupuestos.Post;
|
|
end;
|
|
Next;
|
|
end;
|
|
EnableControls;
|
|
end
|
|
except
|
|
on E : EIBError do begin
|
|
if E.IBErrorCode = isc_unique_key_violation then
|
|
begin
|
|
TablaPropiedadesPresupuestos.Delete;
|
|
TablaPropiedadesMem.EnableControls;
|
|
end;
|
|
raise EIBError.Create(E.SQLCode, E.IBErrorCode, E.Message);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.BorrarPropiedadesConcepto(
|
|
NumConcepto: Integer);
|
|
begin
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
if IsEmpty then
|
|
Exit;
|
|
DisableControls;
|
|
try
|
|
Last;
|
|
while not BOF do begin
|
|
if FieldByName('NUMCONCEPTO').AsInteger = NumConcepto then
|
|
Delete;
|
|
Prior;
|
|
end;
|
|
if FieldByName('NUMCONCEPTO').AsInteger = NumConcepto then
|
|
Delete;
|
|
finally
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.AsignarNumConceptoDetalles;
|
|
var
|
|
FDetallesBookmark : string;
|
|
NumConAnt,
|
|
NumConNue : Integer;
|
|
begin
|
|
with TablaDetallesMem do
|
|
begin
|
|
DisableControls;
|
|
FDetallesBookmark := Bookmark;
|
|
try
|
|
Last;
|
|
while not BOF do
|
|
begin
|
|
Edit;
|
|
NumConAnt := FieldByName('NUMCONCEPTO').AsInteger;
|
|
NumConNue := RecNo;
|
|
FieldByName('NUMCONCEPTO').AsInteger := NumConNue;
|
|
Post;
|
|
ReasignarNumConceptoPropiedades(NumConAnt, NumConNue);
|
|
Prior;
|
|
end;
|
|
finally
|
|
EnableControls;
|
|
Bookmark := FDetallesBookmark;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ReasignarNumConceptoPropiedades(NumConAnt,
|
|
NumConNue: Integer);
|
|
begin
|
|
if NumConAnt = NumConNue then
|
|
exit;
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
DisableControls;
|
|
try
|
|
First;
|
|
while not EOF do begin
|
|
if FieldByName('NUMCONCEPTO').AsInteger = NumConAnt then
|
|
begin
|
|
Edit;
|
|
FieldByName('NUMCONCEPTO').AsInteger := NumConNue;
|
|
Post;
|
|
end;
|
|
Next;
|
|
end;
|
|
finally
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.PropiedadesAfterInsert(DataSet: TDataSet);
|
|
begin
|
|
with DataSet do
|
|
begin
|
|
FieldByName('CODIGOPRESUPUESTO').AsString := TablaDetallesMem.FieldByName('CODIGOPRESUPUESTO').AsString;
|
|
|
|
if Entidad in [entPresupuestoCocina, entPresupuestoBano] then
|
|
FieldByName('NUMCONCEPTO').AsInteger := 0
|
|
else begin
|
|
if Entidad = entPresupuestoArmarios then
|
|
FieldByName('NUMCONCEPTO').AsInteger := Seccion.ItemIndex
|
|
else
|
|
FieldByName('NUMCONCEPTO').AsInteger := TablaDetallesMem.FieldByName('NUMCONCEPTO').AsInteger;
|
|
end;
|
|
|
|
Post;
|
|
AsignarNumPropiedad;
|
|
Edit;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CodigoPropertiesButtonClick(
|
|
Sender: TObject; AButtonIndex: Integer);
|
|
begin
|
|
if (TratarCambios = IDCANCEL) then
|
|
exit;
|
|
{ Esto es porque en modo 'Modificar' hacemos un cambio y pulsamos
|
|
este botón se cierra la tabla y si en el frame hijo (el del grid) damos
|
|
a cancelar, FCodigoCliente es NULL y da error al activar modo porque
|
|
no se inicializa los parámetros de la sql. Lo hace BuscarCliente. }
|
|
{ if not TablaPresupuestos.Active then
|
|
BuscarPresupuesto;}
|
|
ContenidoModal := TfrPresupuestosClientes.Create(Self);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.DesactivarEventosCampos;
|
|
begin
|
|
with TablaPresupuestos do
|
|
begin
|
|
if FindField('CODIGOCLIENTE') <> NIL then
|
|
FieldByName('CODIGOCLIENTE').OnSetText := NIL;
|
|
if FindField('IVA') <> NIL then
|
|
FieldByName('IVA').OnSetText := NIL;
|
|
if FindField('DESCUENTO') <> NIL then
|
|
FieldByName('DESCUENTO').OnSetText := NIL;
|
|
end;
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
if FindField('CODIGOARTICULO') <> NIL then
|
|
FieldByName('CODIGOARTICULO').OnSetText := NIL;
|
|
if FindField('REFERENCIA') <> NIL then
|
|
FieldByName('REFERENCIA').OnSetText := NIL;
|
|
if FindField('CANTIDAD') <> NIL then
|
|
FieldByName('CANTIDAD').OnSetText := NIL;
|
|
if FindField('IMPORTEUNIDAD') <> NIL then
|
|
FieldByName('IMPORTEUNIDAD').OnSetText := NIL;
|
|
AfterDelete := NIL;
|
|
AfterInsert := NIL;
|
|
end;
|
|
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
AfterInsert := NIL;
|
|
end;
|
|
|
|
with VistaDetalles do
|
|
begin
|
|
if GetColumnByFieldName('CODIGOARTICULO') <> NIL then
|
|
TcxButtonEditProperties(GetColumnByFieldName('CODIGOARTICULO').Properties).OnButtonClick := NIL;
|
|
if GetColumnByFieldName('REFERENCIA') <> NIL then
|
|
TcxButtonEditProperties(GetColumnByFieldName('REFERENCIA').Properties).OnButtonClick := NIL;
|
|
end;
|
|
|
|
cbxSituacion.Properties.OnChange := NIL;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.cbxSituacionPropertiesChange(
|
|
Sender: TObject);
|
|
begin
|
|
{ if (cbxSituacion.EditValue = 'PENDIENTE') then
|
|
begin
|
|
FechaDecision.Enabled := False;
|
|
FechaDecision.DataBinding.Field.Value := NULL;
|
|
end
|
|
else
|
|
FechaDecision.Enabled := True;}
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CodCliSetText(Sender: TField;
|
|
const Text: String);
|
|
begin
|
|
Sender.AsString := Text;
|
|
CodigoCliente := Text;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actEliminarDetalleUpdate(Sender: TObject);
|
|
begin
|
|
if not (Modo in [Anadir, Modificar]) then
|
|
(Sender as TAction).Enabled := False
|
|
else
|
|
(Sender as TAction).Enabled := not (TablaDetallesMem.RecordCount = 0);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actEliminarTodoDetalleUpdate(Sender: TObject);
|
|
begin
|
|
if not (Modo in [Anadir, Modificar]) then
|
|
(Sender as TAction).Enabled := False
|
|
else
|
|
(Sender as TAction).Enabled := not (TablaDetallesMem.RecordCount = 0);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CargarPropiedadesArticulo(
|
|
NumConcepto: Integer; DatosArticulo: TDatosArticulo);
|
|
var
|
|
FPropiedad : TDatosPropiedad;
|
|
FBookmark : string;
|
|
begin
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
FBookmark := Bookmark;
|
|
DisableControls;
|
|
try
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
if FieldByName('NUMCONCEPTO').AsInteger = NumConcepto then
|
|
begin
|
|
FPropiedad := TDatosPropiedad.Create;
|
|
FPropiedad.CodigoPropiedad := FieldByName('CODIGOPROPIEDAD').AsInteger;
|
|
FPropiedad.Valor := FieldByName('VALOR').AsString;
|
|
DatosArticulo.ListaPropiedades.Add(FPropiedad);
|
|
end;
|
|
Next;
|
|
end;
|
|
finally
|
|
Bookmark := FBookmark;
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.cbXDocumentoPropertiesValidate(
|
|
Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
|
|
var Error: Boolean);
|
|
begin
|
|
if VerMensajePreguntaFmt(msgCliCambiarTipoPre, [cbxDocumento.Text]) = mrYES then
|
|
CargarDatosDocumento(TablaDocumentos.FieldByName('CODIGO').AsString)
|
|
else begin
|
|
ErrorText := '';
|
|
Error := True;
|
|
cbxDocumento.Undo; // Restaurar el valor anterior
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actEditarPropiedadesUpdate(
|
|
Sender: TObject);
|
|
begin
|
|
if not (Modo in [Anadir, Modificar]) then
|
|
(Sender as TAction).Enabled := False
|
|
else
|
|
(Sender as TAction).Enabled := not (TablaDetallesMem.RecordCount = 0);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actAnadirDetalleUpdate(Sender: TObject);
|
|
begin
|
|
if not (Modo in [Anadir, Modificar]) then
|
|
(Sender as TAction).Enabled := False
|
|
else
|
|
(Sender as TAction).Enabled := True;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.ArticuloConPropiedades(
|
|
NumConcepto: Integer): Boolean;
|
|
begin
|
|
Result := False;
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
DisableControls;
|
|
try
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
if FieldByName('NUMCONCEPTO').AsInteger = NumConcepto then
|
|
begin
|
|
Result := True;
|
|
Break;
|
|
end;
|
|
Next;
|
|
end;
|
|
finally
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.TablaDetallesNewRecord(DataSet: TDataSet);
|
|
begin
|
|
//
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CargarDatosDocumento(CodigoDocumento : String);
|
|
var
|
|
DocAux : TDocumento;
|
|
begin
|
|
DocAux := TDocumento.Create(CodigoDocumento);
|
|
Entidad := dmTablaDocumentos.DarEntidadDocumento(entPresupuestoCliente, DocAux.Codigo);
|
|
try
|
|
Nota.EditingText := DocAux.Notas;
|
|
TablaPresupuestos.FieldByName('OBSERVACIONES').AsString := DocAux.Notas;
|
|
FormasPago.EditingText := DocAux.FormaPago;
|
|
TablaPresupuestos.FieldByName('FORMAPAGO').AsString := DocAux.FormaPago;
|
|
PlazosEntrega.EditingText := DocAux.PlazoEntrega;
|
|
TablaPresupuestos.FieldByName('PLAZOENTREGA').AsString := DocAux.PlazoEntrega;
|
|
finally
|
|
DocAux.Free;
|
|
DocAux := NIL;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.FechaPresupuestoPropertiesEditValueChanged(
|
|
Sender: TObject);
|
|
begin
|
|
if TablaPresupuestos.State in dsEditModes then
|
|
Vigencia.DataBinding.Field.AsDateTime := IncMonth(FechaPresupuesto.DataBinding.Field.AsDateTime, EmpresaActiva.ValidezDefecto)
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.VALORGetProperties(
|
|
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
|
|
var AProperties: TcxCustomEditProperties);
|
|
begin
|
|
if not ARecord.Focused then
|
|
Exit
|
|
else begin
|
|
with TablaValores do
|
|
begin
|
|
try
|
|
DisableControls;
|
|
Close;
|
|
// ¿Tiene 'copia'?
|
|
if TablaPropiedades.FieldByName('COPIA').AsVariant <> NULL then
|
|
ParamByName('CODIGOPROPIEDAD').AsInteger := TablaPropiedades.FieldByName('COPIA').AsInteger
|
|
else // No tiene 'copia'
|
|
ParamByName('CODIGOPROPIEDAD').AsInteger := TablaPropiedadesMem.FieldByName('CODIGOPROPIEDAD').AsInteger;
|
|
Prepare;
|
|
Open;
|
|
|
|
if RecordCount = 0 then
|
|
AProperties := dmConfiguracion.cxEditRepository1TextItem1.Properties
|
|
else begin
|
|
AProperties := dmConfiguracion.cxEditRepository1ExtLookupComboBoxItem1.Properties;
|
|
with TcxExtLookupComboBoxProperties(AProperties) do
|
|
begin
|
|
DropDownListStyle := lsEditList;
|
|
ImmediatePost := True;
|
|
KeyFieldNames := 'DESCRIPCION';
|
|
ListFieldItem := VistaComboDBDescripcion;
|
|
VistaComboDBImagen.Width := CTE_ALT_IMG;
|
|
VistaCombo.OptionsView.DataRowHeight := CTE_ALT_IMG;
|
|
View := VistaCombo;
|
|
end;
|
|
end;
|
|
|
|
finally
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ConfigurarPantallaDocumento;
|
|
begin
|
|
if (Entidad in [entPresupuestoCocina, entPresupuestoArmarios]) then
|
|
begin
|
|
pagDocumentos.TabVisible := True;
|
|
pagPlanos.TabVisible := True;
|
|
end
|
|
else
|
|
begin
|
|
pagDocumentos.TabVisible := False;
|
|
pagPlanos.TabVisible := False;
|
|
end;
|
|
|
|
if (Entidad = entPresupuestoCocina) then
|
|
begin
|
|
pagContenido.TabVisible := False;
|
|
pagDesgloses.TabVisible := True;
|
|
pagAumento.TabVisible := True;
|
|
end
|
|
else
|
|
begin
|
|
pagContenido.TabVisible := True;
|
|
pagDesgloses.TabVisible := False;
|
|
pagAumento.TabVisible := False;
|
|
end;
|
|
|
|
case Entidad of
|
|
entPresupuestoCocina,
|
|
entPresupuestoBano,
|
|
entPresupuestoArmarios : begin
|
|
pagPrecios.TabVisible := True;
|
|
gridDetallesLevel1.GridView := VistaPropiedades;
|
|
pnlObservaciones.Visible := True;
|
|
if Modo in [Anadir, Modificar] then
|
|
begin
|
|
pnlBarraContenido.Visible := False;
|
|
pnlBarraPropiedades.Visible := True;
|
|
pnlBarraPrecio.Visible := True;
|
|
Observaciones.Properties.ReadOnly := False;
|
|
end
|
|
else begin
|
|
pnlBarraContenido.Visible := False;
|
|
pnlBarraPropiedades.Visible := True;
|
|
pnlBarraPrecio.Visible := False;
|
|
Observaciones.Properties.ReadOnly := True;
|
|
end;
|
|
|
|
if Entidad = entPresupuestoArmarios then
|
|
begin
|
|
eSeccion.Visible := True;
|
|
Seccion.Visible := True;
|
|
Seccion.ItemIndex := 0;
|
|
end
|
|
else begin
|
|
eSeccion.Visible := False;
|
|
Seccion.Visible := False;
|
|
end
|
|
end
|
|
else begin
|
|
pagPrecios.TabVisible := False;
|
|
gridDetallesLevel1.GridView := VistaDetalles;
|
|
pnlObservaciones.Visible := False;
|
|
if Modo in [Anadir, Modificar] then
|
|
begin
|
|
pnlBarraContenido.Visible := True;
|
|
pnlBarraPropiedades.Visible := False;
|
|
pnlBarraPrecio.Visible := False;
|
|
end
|
|
else begin
|
|
pnlBarraContenido.Visible := False;
|
|
pnlBarraPropiedades.Visible := False;
|
|
pnlBarraPrecio.Visible := False;
|
|
end
|
|
end
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.InsertarDetallesDefecto;
|
|
begin
|
|
Observaciones.Lines.Clear;
|
|
case Entidad of
|
|
entPresupuestoCocina,
|
|
entPresupuestoBano :
|
|
begin
|
|
with TablaDetallesMem do
|
|
begin
|
|
Append;
|
|
FieldByName('NUMCONCEPTO').AsInteger := 0;
|
|
FieldByName('TIPOCONCEPTO').AsString := dmTablaDocumentos.DarCodigoDocumento(Entidad);
|
|
FieldByName('CANTIDAD').AsInteger := 1;
|
|
Post;
|
|
InsertarPropiedades(FieldByName('NUMCONCEPTO').AsInteger);
|
|
CargarPreciosDocumento(cbxDocumento.DataBinding.Field.AsString, 1);
|
|
First;
|
|
end;
|
|
end;
|
|
|
|
entPresupuestoArmarios:
|
|
begin
|
|
with TablaDetallesMem do
|
|
begin
|
|
Append;
|
|
FieldByName('NUMCONCEPTO').AsInteger := 0;
|
|
FieldByName('TIPOCONCEPTO').AsString := 'FRENTE';
|
|
FieldByName('CANTIDAD').AsInteger := 1;
|
|
Post;
|
|
InsertarPropiedades(FieldByName('NUMCONCEPTO').AsInteger, FieldByName('TIPOCONCEPTO').AsString);
|
|
|
|
Append;
|
|
FieldByName('NUMCONCEPTO').AsInteger := 1;
|
|
FieldByName('TIPOCONCEPTO').AsString := 'INTERIOR';
|
|
FieldByName('CANTIDAD').AsInteger := 1;
|
|
Post;
|
|
InsertarPropiedades(FieldByName('NUMCONCEPTO').AsInteger, FieldByName('TIPOCONCEPTO').AsString);
|
|
CargarPreciosDocumento(cbxDocumento.DataBinding.Field.AsString, 2);
|
|
First;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.CargarPreciosDocumento(
|
|
CodigoDocumento: String; NumConcepto: Integer);
|
|
var
|
|
DocAux : TDocumento;
|
|
Contador : Integer;
|
|
begin
|
|
DocAux := TDocumento.Create(CodigoDocumento);
|
|
try
|
|
with TablaDetallesMem do
|
|
begin
|
|
if State in dsEditModes then
|
|
Cancel;
|
|
for Contador := 0 to DocAux.ListaPrecios.Count-1 do
|
|
begin
|
|
Append;
|
|
FieldByName('NUMCONCEPTO').AsInteger := NumConcepto + Contador;
|
|
FieldByName('TIPOCONCEPTO').AsString := 'PRECIO';
|
|
FieldByName('DESCRIPCION').AsString := DocAux.ListaPrecios.Strings[Contador];
|
|
FieldByName('CANTIDAD').AsInteger := 1;
|
|
Post;
|
|
end;
|
|
end;
|
|
finally
|
|
DocAux.Free;
|
|
DocAux := NIL;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.TablaMemDetallesFilterRecord(DataSet: TDataSet;
|
|
var Accept: Boolean);
|
|
begin
|
|
Accept := (DataSet.FieldByName('TIPOCONCEPTO').AsString = 'PRECIO');
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actAnadirPropiedadExecute(Sender: TObject);
|
|
begin
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
Next;
|
|
if EOF then
|
|
Append
|
|
else begin
|
|
Prior;
|
|
Insert;
|
|
end;
|
|
gridDetalles.SetFocus;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actAnadirPropiedadUpdate(Sender: TObject);
|
|
begin
|
|
(Sender as TAction).Enabled := (Modo in [Anadir, Modificar]);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actEliminarPropiedadExecute(
|
|
Sender: TObject);
|
|
begin
|
|
if TablaPropiedadesMem.RecordCount = 0 then begin
|
|
{ Hacemos un cancel de la tabla por si el registro actual estuviera
|
|
recien creado }
|
|
TablaPropiedadesMem.Cancel;
|
|
Exit;
|
|
end;
|
|
if (VerMensajePregunta(msgDatosBorrarPropiedad) <> IDYES) then
|
|
Exit;
|
|
TablaPropiedadesMem.Delete;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actEliminarPropiedadUpdate(
|
|
Sender: TObject);
|
|
begin
|
|
(Sender as TAction).Enabled := (Modo in [Anadir, Modificar]);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.AsignarNumPropiedad;
|
|
var
|
|
FDetallesBookmark : string;
|
|
Contador : Integer;
|
|
begin
|
|
with TablaPropiedadesMem do
|
|
begin
|
|
DisableControls;
|
|
FDetallesBookmark := Bookmark;
|
|
try
|
|
Contador := 0;
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
Edit;
|
|
FieldByName('NUMPROPIEDAD').AsInteger := Contador;
|
|
Post;
|
|
Contador := Contador + 1;
|
|
Next;
|
|
end;
|
|
finally
|
|
//FUltimaPropiedad := Contador - 1;
|
|
EnableControls;
|
|
Bookmark := FDetallesBookmark;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.PropiedadesAfterDelete(DataSet: TDataSet);
|
|
begin
|
|
AsignarNumPropiedad;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actSubirExecute(Sender: TObject);
|
|
var
|
|
NumPropiedad : Integer;
|
|
begin
|
|
NumPropiedad := TablaPropiedadesMem.FieldByName('NUMPROPIEDAD').AsInteger;
|
|
IntercambiarPropiedades(@TablaPropiedadesMem, NumPropiedad, NumPropiedad - 1);
|
|
VistaPropiedades.DataController.RefreshExternalData;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actSubirUpdate(Sender: TObject);
|
|
begin
|
|
with TablaPropiedadesMem do
|
|
(Sender as TAction).Enabled := (Modo in [Anadir, Modificar]) and
|
|
(FieldByName('NUMPROPIEDAD').AsInteger > 0);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actBajarExecute(Sender: TObject);
|
|
var
|
|
NumPropiedad : Integer;
|
|
begin
|
|
NumPropiedad := TablaPropiedadesMem.FieldByName('NUMPROPIEDAD').AsInteger;
|
|
IntercambiarPropiedades(@TablaPropiedadesMem, NumPropiedad, NumPropiedad + 1);
|
|
VistaPropiedades.DataController.RefreshExternalData;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actBajarUpdate(Sender: TObject);
|
|
begin
|
|
with TablaPropiedadesMem do
|
|
(Sender as TAction).Enabled := (Modo in [Anadir, Modificar]) and
|
|
(FieldByName('NUMPROPIEDAD').AsInteger < (VistaPropiedades.ViewData.CardCount - 1));
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.gridDetallesResize(Sender: TObject);
|
|
begin
|
|
if gridDetalles.ActiveView = VistaPropiedades then
|
|
VistaPropiedades.OptionsView.CardWidth := (gridDetalles.Width - 40) div 2;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.pnlPreciosResize(Sender: TObject);
|
|
begin
|
|
with gridPrecios do
|
|
begin
|
|
RowCount := pnlGrid.Height div 18;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.TablaMemPropiedadesFilterRecord(
|
|
DataSet: TDataSet; var Accept: Boolean);
|
|
begin
|
|
Accept := (DataSet.FieldByName('NUMCONCEPTO').AsInteger = Seccion.ItemIndex);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.SeccionPropertiesChange(Sender: TObject);
|
|
begin
|
|
if TablaPropiedadesMem.Active then
|
|
TablaPropiedadesMem.First;
|
|
|
|
Observaciones.Lines.Clear;
|
|
case Seccion.ItemIndex of
|
|
0 : Observaciones.Lines.Text := FObservaciones1;
|
|
1 : Observaciones.Lines.Text := FObservaciones2;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ObservacionesExit(Sender: TObject);
|
|
begin
|
|
case Seccion.ItemIndex of
|
|
0 : FObservaciones1 := Observaciones.Lines.Text;
|
|
1 : FObservaciones2 := Observaciones.Lines.Text;
|
|
else
|
|
FObservaciones1 := Observaciones.Lines.Text;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.VistaPropiedadesDBCardViewRow3CustomDrawCell(
|
|
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
|
|
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
|
|
begin
|
|
if Length(AViewInfo.DisplayValue) > 32 then
|
|
ACanvas.Font.Color := clRed;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actAnadirDocumentoExecute(Sender: TObject);
|
|
var
|
|
FicheroOrigen : String;
|
|
i : Integer;
|
|
begin
|
|
if OpenDialog1.Execute then
|
|
begin
|
|
for i:=0 to OpenDialog1.Files.Count - 1 do
|
|
begin
|
|
FicheroOrigen := OpenDialog1.Files.Strings[i];
|
|
if not esCadenaVacia(FicheroOrigen) then
|
|
if not AnadirDocumento(FicheroOrigen) then
|
|
VerMensaje(msgCliPreErrAnadirDoc);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actElliminarDocumentoExecute(Sender: TObject);
|
|
var
|
|
cadena : String;
|
|
i : Integer;
|
|
begin
|
|
if explo.InnerListView.SelCount > 1 then
|
|
cadena := '¿Desea borrar estos documentos del presupuesto?'
|
|
else
|
|
cadena := '¿Desea borrar este documento del presupuesto?';
|
|
|
|
if (VerMensajePregunta(cadena) <> IDYES) then
|
|
Exit;
|
|
|
|
for i:=0 to explo.InnerListView.Items.Count - 1 do
|
|
begin
|
|
if explo.InnerListView.Items[i].Selected then
|
|
begin
|
|
cadena := GetPidlName(explo.GetItemAbsolutePIDL(i));
|
|
if not SysUtils.DeleteFile(cadena) then
|
|
VerMensaje(msgCliPreErrEliminarDoc);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.AnadirDocumento(RutaDocumento: String): Boolean;
|
|
var
|
|
DireccionDestino: String;
|
|
begin
|
|
try
|
|
Result := False;
|
|
DireccionDestino := darRutaDocumentosPresupuesto + PathDelim + ExtractFileName(RutaDocumento);
|
|
CopiarFichero(RutaDocumento, DireccionDestino);
|
|
Result := True;
|
|
finally
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.HabilitarDocumentos;
|
|
begin
|
|
explo.Options.ShowNonFolders := True;
|
|
explo.Root.CustomPath := darRutaDocumentosPresupuesto;
|
|
JvChangeNotify1.Notifications.Clear;
|
|
with JvChangeNotify1.Notifications.Add do
|
|
begin
|
|
Actions := [caChangeFileName, caChangeDirName];
|
|
Directory := explo.Root.CustomPath;
|
|
end;
|
|
JvChangeNotify1.Active := True;
|
|
explo.Enabled := True;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.DeshabilitarDocumentos;
|
|
begin
|
|
JvChangeNotify1.Active := False;
|
|
JvChangeNotify1.Notifications.Clear;
|
|
explo.Enabled := False;
|
|
explo.Options.ShowNonFolders := False;
|
|
explo.Root.CustomPath := FRootDocumentos;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.darRutaDocumentosPresupuesto: Variant;
|
|
begin
|
|
Result := FRootDocumentos + FDirectorio;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actAnadirDocumentoUpdate(Sender: TObject);
|
|
begin
|
|
(Sender as TAction).Enabled := True;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actElliminarDocumentoUpdate(
|
|
Sender: TObject);
|
|
begin
|
|
(Sender as TAction).Enabled := explo.InnerListView.SelCount <> 0;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.pagNotasVariasResize(Sender: TObject);
|
|
var
|
|
Aux : Integer;
|
|
begin
|
|
Aux := pagNotasVarias.Height div 3;
|
|
pnlFormasPago.Height := Aux;
|
|
pnlPlazosEntrega.Height := Aux;
|
|
pnlNota.Height := Aux;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actAbrirDocumentoExecute(Sender: TObject);
|
|
var
|
|
FileHandle : Integer;
|
|
cadena : String;
|
|
begin
|
|
if explo.InnerListView.SelCount <> 0 then
|
|
begin
|
|
cadena := GetPidlName(explo.GetItemAbsolutePIDL(explo.InnerListView.ItemFocused.Index));
|
|
ShellExecute(Handle, 'open', PAnsiChar(cadena), nil, nil, SW_SHOWNORMAL);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actAbrirDocumentoUpdate(Sender: TObject);
|
|
begin
|
|
(Sender as TAction).Enabled := explo.InnerListView.SelCount <> 0;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.JvChangeNotify1ChangeNotify(
|
|
Sender: TObject; Dir: String; Actions: TJvChangeActions);
|
|
begin
|
|
Explo.Root.CustomPath := Explo.Root.CustomPath;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.CrearDirDocumentos: Boolean;
|
|
var
|
|
DireccionDestino: String;
|
|
begin
|
|
Result := False;
|
|
DeshabilitarDocumentos;
|
|
DireccionDestino := darRutaDocumentosPresupuesto;
|
|
if not DirectoryExists(DireccionDestino) then
|
|
CreateDir(DireccionDestino);
|
|
HabilitarDocumentos;
|
|
Result := True;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ComprobarEstadoDirDocumentos;
|
|
var
|
|
RutaTemp, RutaFinal: String;
|
|
begin
|
|
if (Entidad in [entPresupuestoCocina, entPresupuestoArmarios]) then
|
|
begin
|
|
DeshabilitarDocumentos;
|
|
Application.ProcessMessages;
|
|
if Modo = Anadir then
|
|
begin
|
|
//Intentamos renombrar el directorio temporal por el real (si existiera)
|
|
RutaTemp := darRutaDocumentosPresupuesto;
|
|
FDirectorio := PathDelim + StringReplace(CodigoPresupuesto,'/','',[rfReplaceAll]);
|
|
RutaFinal:= darRutaDocumentosPresupuesto;
|
|
RenameFile(RutaTemp, RutaFinal);
|
|
end;
|
|
|
|
{ Intentamos borrar el directorio de los documentos. Si está vacio se
|
|
borrar y si no se queda }
|
|
RemoveDir(darRutaDocumentosPresupuesto);
|
|
Application.ProcessMessages;
|
|
end;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.EliminarDirDocumentos: Boolean;
|
|
begin
|
|
Result := False;
|
|
DeshabilitarDocumentos;
|
|
Application.ProcessMessages;
|
|
if DirectoryExists(darRutaDocumentosPresupuesto) then
|
|
begin
|
|
SysFunc.Deltree(darRutaDocumentosPresupuesto, True);
|
|
Application.ProcessMessages;
|
|
Result := DirectoryExists(darRutaDocumentosPresupuesto);
|
|
end;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.darRutaPlanosPresupuesto: Variant;
|
|
begin
|
|
Result := FRootPlanos + FDirectorioPlanos;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.DeshabilitarPlanos;
|
|
begin
|
|
//
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.HabilitarPlanos;
|
|
begin
|
|
tvPlanos.Directory := darRutaPlanosPresupuesto;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.tvPlanosStartScanning(Sender: TObject;
|
|
Max: Integer);
|
|
begin
|
|
//
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.tvPlanosStopScanning(Sender: TObject);
|
|
begin
|
|
//
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.CrearDirPlanos: Boolean;
|
|
var
|
|
DireccionDestino: String;
|
|
begin
|
|
Result := False;
|
|
DeshabilitarPlanos;
|
|
DireccionDestino := darRutaPlanosPresupuesto;
|
|
if not DirectoryExists(DireccionDestino) then
|
|
CreateDir(DireccionDestino);
|
|
HabilitarPlanos;
|
|
Result := True;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ComprobarEstadoDirPlanos;
|
|
var
|
|
RutaTemp, RutaFinal: String;
|
|
begin
|
|
if (Entidad in [entPresupuestoCocina, entPresupuestoArmarios]) then
|
|
begin
|
|
DeshabilitarPlanos;
|
|
Application.ProcessMessages;
|
|
if Modo = Anadir then
|
|
begin
|
|
//Intentamos renombrar el directorio temporal por el real (si existiera)
|
|
RutaTemp := darRutaPlanosPresupuesto;
|
|
FDirectorioPlanos := PathDelim + StringReplace(CodigoPresupuesto,'/','',[rfReplaceAll]);
|
|
RutaFinal:= darRutaPlanosPresupuesto;
|
|
RenameFile(RutaTemp, RutaFinal);
|
|
end;
|
|
|
|
{ Intentamos borrar el directorio de los documentos. Si está vacio se
|
|
borrar y si no se queda }
|
|
RemoveDir(darRutaPlanosPresupuesto);
|
|
Application.ProcessMessages;
|
|
end;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.EliminarDirPlanos: Boolean;
|
|
begin
|
|
Result := False;
|
|
DeshabilitarPlanos;
|
|
Application.ProcessMessages;
|
|
if DirectoryExists(darRutaPlanosPresupuesto) then
|
|
begin
|
|
SysFunc.Deltree(darRutaPlanosPresupuesto, True);
|
|
Application.ProcessMessages;
|
|
Result := DirectoryExists(darRutaPlanosPresupuesto);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.tvPlanosDblClick(Sender: TObject);
|
|
begin
|
|
if ShellExecute(Handle, nil, pchar(tvPlanos.SelectedFile),
|
|
nil, nil, SW_SHOWNORMAL) <= 32 then
|
|
Application.MessageBox('No se pudo visualizar el fichero',
|
|
'Error', MB_ICONEXCLAMATION);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.JvTrackBar1Change(Sender: TObject);
|
|
begin
|
|
tvPlanos.Size := JvTrackBar1.Position;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actAnadirPlanoExecute(Sender: TObject);
|
|
var
|
|
FicheroOrigen : String;
|
|
i : Integer;
|
|
begin
|
|
OpenDialog1.Filter := tvPlanos.Filter;
|
|
try
|
|
if OpenDialog1.Execute then
|
|
begin
|
|
for i:=0 to OpenDialog1.Files.Count - 1 do
|
|
begin
|
|
FicheroOrigen := OpenDialog1.Files.Strings[i];
|
|
if not esCadenaVacia(FicheroOrigen) then
|
|
begin
|
|
if not AnadirPlano(FicheroOrigen) then
|
|
VerMensaje(msgCliPreErrAnadirDoc);
|
|
end;
|
|
end;
|
|
end;
|
|
finally
|
|
OpenDialog1.Filter := '';
|
|
end;
|
|
end;
|
|
|
|
function TfrPresupuestoCliente.AnadirPlano(RutaPlano: String): Boolean;
|
|
var
|
|
DireccionDestino: String;
|
|
begin
|
|
try
|
|
Result := False;
|
|
DireccionDestino := darRutaPlanosPresupuesto + PathDelim + ExtractFileName(RutaPlano);
|
|
CopiarFichero(RutaPlano, DireccionDestino);
|
|
tvPlanos.AddFromFile(DireccionDestino);
|
|
Result := True;
|
|
finally
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actEliminarPlanoExecute(Sender: TObject);
|
|
var
|
|
cadena : String;
|
|
i : Integer;
|
|
begin
|
|
cadena := '¿Desea borrar este plano del presupuesto?';
|
|
|
|
if (VerMensajePregunta(cadena) <> IDYES) then
|
|
Exit;
|
|
|
|
if not SysUtils.DeleteFile(tvPlanos.SelectedFile) then
|
|
VerMensaje(msgCliPreErrEliminarDoc);
|
|
tvPlanos.Delete(tvPlanos.Selected);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actEliminarPlanoUpdate(Sender: TObject);
|
|
begin
|
|
(Sender as TAction).Enabled := (Modo in [Anadir, Modificar]) and
|
|
(Length(tvPlanos.SelectedFile) > 0);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actRefrescarPlanoExecute(Sender: TObject);
|
|
begin
|
|
tvPlanos.Refresh;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actAnadirPlanoUpdate(Sender: TObject);
|
|
begin
|
|
(Sender as TAction).Enabled := (Modo in [Anadir, Modificar]);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.ReferenciaArticuloDetalleSetText(
|
|
Sender: TField; const Text: String);
|
|
var
|
|
ReferenciaAux : String;
|
|
CodigoArtAux : String;
|
|
begin
|
|
Sender.AsString := Text;
|
|
ReferenciaAux := Text;
|
|
|
|
if (dmTablaArticulos.DarCodigoArt(ReferenciaAux, CodigoArtAux)) then
|
|
CodigoArticulo := CodigoArtAux
|
|
else begin
|
|
raise Exception.CreateFmt(msgDatosRefArtNoExiste, [ReferenciaAux]);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.GridBotonReferenciaArticuloClick(
|
|
Sender: TObject; AButtonIndex: Integer);
|
|
begin
|
|
TablaDetallesMem.Edit;
|
|
ContenidoModal := TfrArticulos.Create(Self);
|
|
gridDetalles.SetFocus;
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actEliminarTodoPropiedadExecute(Sender: TObject);
|
|
begin
|
|
if (VerMensajePregunta(msgDeseaBorrarTodo) <> IDYES) then
|
|
Exit;
|
|
|
|
if Seccion.Visible then
|
|
BorrarPropiedadesConcepto(Seccion.ItemIndex)
|
|
else
|
|
BorrarTabla(TablaPropiedadesMem);
|
|
end;
|
|
|
|
procedure TfrPresupuestoCliente.actEliminarTodoPropiedadUpdate(Sender: TObject);
|
|
begin
|
|
if not (Modo in [Anadir, Modificar]) then
|
|
(Sender as TAction).Enabled := False
|
|
else
|
|
(Sender as TAction).Enabled := not (VistaPropiedades.ViewData.RecordCount = 0);
|
|
end;
|
|
|
|
end.
|
|
|