This repository has been archived on 2024-11-29. You can view files and clone it, but cannot push or open issues or pull requests.
Tecsitel_FactuGES/Empresas/Empresa.pas
2007-06-21 15:47:20 +00:00

579 lines
15 KiB
ObjectPascal

{
===============================================================================
Copyright (©) 2002. 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: 03-11-2002
Versión actual: 1.0.2
Fecha versión actual: 05-08-2004
===============================================================================
Modificaciones:
Fecha Comentarios
---------------------------------------------------------------------------
30-07-2004 p284. Se han añadido los datos de inscripción del Registro
Mercantil a la tabla de empresas.
05-08-2004 P279. Añadido el campo 'MODELOINFORME' para determinar por
empresa qué formato usarán los informes (no internos).
===============================================================================
}
unit Empresa;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
RdxBotones, StdCtrls, RdxMemo, RdxComboBox, RdxCampos, ExtCtrls,
RdxTitulos, ComCtrls, RdxCheckBox, Grids, DBGrids, RdxPaneles,
RdxBarras, Db, RdxFrame, RdxDBFrame, RdxFrameEmpresas, RXDBCtrl,
RdxPageControl, IB, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
cxEdit, cxDBData, cxGridLevel, cxClasses, cxControls, cxGridCustomView,
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid,
dxLayout, dxCntner, dxEditor, dxExEdtr, dxExGrEd, dxExELib,
cxGridCardView, cxGridDBCardView, RxMemDS, Configuracion, cxMemo,
cxDBEdit, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit, Tipos,
cxImage, cxDropDownEdit, cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox,
IBCustomDataSet, cxCalendar, cxSpinEdit, RdxEmpresaActiva, cxListBox;
type
TfrEmpresa = class(TRdxFrameEmpresas)
pnlCuerpo: TPanel;
brDoble: TRdxBarraInferior;
bGuardar: TRdxBoton;
bCancelar: TRdxBoton;
brSimple: TRdxBarraInferior;
bSalir: TRdxBoton;
pnlTitulo: TRdxPanelTituloOperacion;
dsEmpresas: TDataSource;
pnlDatos: TPanel;
eNIFCIF: TLabel;
eNombre: TLabel;
eDireccion: TLabel;
eNumero: TLabel;
eProvincia: TLabel;
ePoblacion: TLabel;
eCodigoPostal: TLabel;
eTelefono: TLabel;
eFax: TLabel;
eCorreo: TLabel;
Label1: TLabel;
NIF: TcxDBTextEdit;
Nombre: TcxDBTextEdit;
Calle: TcxDBTextEdit;
Numero: TcxDBTextEdit;
CodigoPostal: TcxDBTextEdit;
Telefono: TcxDBTextEdit;
Fax: TcxDBTextEdit;
Correo: TcxDBTextEdit;
Web: TcxDBTextEdit;
Provincia: TcxDBButtonEdit;
Poblacion: TcxDBButtonEdit;
dsLibros: TDataSource;
dsTrimestres: TDataSource;
cDatos: TRdxCabecera;
Label2: TLabel;
RegistroMercantil: TcxDBMemo;
Paginas: TRdxPagesControl;
pagLogotipo: TTabSheet;
pagInformes: TTabSheet;
bExaminar: TRdxBoton;
Logotipo: TcxDBImage;
Label3: TLabel;
cxDBTextEdit1: TcxDBTextEdit;
procedure bAceptarClick(Sender: TObject);
procedure bCancelarClick(Sender: TObject);
procedure bSalirClick(Sender: TObject);
procedure bExaminarClick(Sender: TObject);
procedure GridBotonPoblacionClick(Sender: TObject; AButtonIndex: Integer);
procedure GridBotonProvinciaClick(Sender: TObject; AButtonIndex: Integer);
private
FCodigoProvincia : Variant;
FCodigoPoblacion : Variant;
procedure ProvinciaSetText(Sender: TField; const Text: String);
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 SetCodigoProvincia (Value : Variant); virtual;
procedure SetCodigoPoblacion (Value : Variant); virtual;
procedure FreeContenido; override;
procedure BuscarEmpresa; override;
procedure CambiarModo(ModoAnterior, Modo : TRdxModo); override;
public
property CodigoProvincia : Variant read FCodigoProvincia write SetCodigoProvincia;
property CodigoPoblacion : Variant read FCodigoPoblacion write SetCodigoPoblacion;
constructor Create (AOwner : TComponent); override;
destructor Destroy; override;
published
property TablaEmpresas;
property CodigoEmpresa;
end;
var
frEmpresa: TfrEmpresa;
implementation
{$R *.DFM}
uses
TablaEmpresas, Mensajes, Provincias, Entidades,
Poblaciones, BaseDatos, RdxFrameProvincias,
RdxFramePoblaciones, TablaProvincias, StrFunc,
TablaPoblaciones, Excepciones, IBErrorCodes, dxDBTLCL,
Literales, Constantes;
constructor TfrEmpresa.Create (AOwner : TComponent);
var
i : integer;
begin
inherited Create(AOwner);
Entidad := entEmpresa;
ConfigurarFrame(Self, Self.Entidad);
FCodigoProvincia := NULL;
FCodigoPoblacion := NULL;
BaseDatos := dmBaseDatos.BD;
Transaccion := dmBaseDatos.Transaccion;
TablaEmpresas := TIBDataSet.Create(Self);
dsEmpresas.DataSet := TablaEmpresas;
with TablaEmpresas do
begin
Database := BaseDatos;
Transaction := Transaccion;
SelectSQL.Assign(dmTablaEmpresas.sqlConsultar);
InsertSQL.Assign(dmTablaEmpresas.sqlInsertar);
ModifySQL.Assign(dmTablaEmpresas.sqlModificar);
DeleteSQL.Assign(dmTablaEmpresas.sqlEliminar);
RefreshSQL.Assign(dmTablaEmpresas.sqlConsultar);
end;
bCancelar.Cancel := True;
bSalir.Cancel := True;
Paginas.ActivePageIndex := 0;
pagInformes.Visible := (dmBaseDatos.Usuario = USER_SYSDBA);
end;
procedure TfrEmpresa.bSalirClick(Sender: TObject);
begin
try
Rollback;
CloseFrame;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrEmpresa.bAceptarClick(Sender: TObject);
begin
if (RealizarOperacion) then
CloseFrame;
end;
function TfrEmpresa.AnadirDatos : boolean;
begin
Result := False;
try
TablaEmpresas.Post;
//Creamos los trimestres y libros para la nueva empresa
CodigoEmpresa := TablaEmpresas.FieldByName('CODIGO').AsString;
Commit;
TablaEmpresas.Close;
Result := True;
except
on E : EIBError do begin
if E.IBErrorCode = isc_unique_key_violation then
begin
VerMensajeFmt(msgEmpCodEmpRepetido, [CodigoEmpresa]);
TablaEmpresas.Edit;
end
else
TratarExcepcion(E);
end;
on E : Exception do
TratarExcepcion(E);
end;
end;
function TfrEmpresa.ModificarDatos : boolean;
begin
Result := False;
try
TablaEmpresas.Post;
Commit;
TablaEmpresas.Close;
//Refrescamos la empresa activa en el caso de se la empresa modificada
if (EmpresaActiva.Codigo = CodigoEmpresa) then
EmpresaActiva.Refrescar;
Result := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
function TfrEmpresa.EliminarDatos : boolean;
begin
Result := False;
if (VerMensajePregunta(msgEmpBorrarEmp) <> IDYES) then
Exit;
try
TablaEmpresas.Delete;
Commit;
TablaEmpresas.Close;
Result := True;
except
on E : EIBError do
begin
case E.IBErrorCode of
isc_lock_conflict : VerMensajeFmt(msgEmpEmpBloqueado, [Nombre.Text]);
else
TratarExcepcion(E);
end;
end;
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrEmpresa.ActivarModoAnadir;
var
CodNuevo : Variant;
begin
dsEmpresas.AutoEdit := True;
Provincia.Properties.Buttons[0].Visible := True;
Poblacion.Properties.Buttons[0].Visible := True;
try
CodNuevo := dmTablaEmpresas.DarNuevoCodigo;
with TablaEmpresas do
begin
Close;
Prepare;
Open;
FieldByName('PROVINCIA').OnSetText := ProvinciaSetText;
Insert;
FieldByName('CODIGO').AsString := CodNuevo;
FieldByName('MODELOINFORME').AsInteger := 0;
end;
Visible := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrEmpresa.ActivarModoModificar;
begin
dsEmpresas.AutoEdit := True;
Provincia.Properties.Buttons[0].Visible := True;
Poblacion.Properties.Buttons[0].Visible := True;
try
with TablaEmpresas do
begin
Prepare;
Open;
FieldByName('PROVINCIA').OnSetText := ProvinciaSetText;
if RecordCount = 0 then
begin
VerMensajeFmt(msgEmpNoExisteEmp, [CodigoEmpresa]);
CancelarModificar;
CloseFrame;
Exit;
end;
// Bloquear el Empresa
Edit;
Post;
Edit;
end;
Visible := True;
except
on E : EIBError do
begin
case E.IBErrorCode of
isc_lock_conflict : begin
VerMensajeFmt(msgEmpEmpBloqueado, [Nombre.Text]);
CancelarModificar;
CloseFrame;
Exit;
end
else
TratarExcepcion(E);
end;
end;
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrEmpresa.ActivarModoConsultar;
begin
dsEmpresas.AutoEdit := False;
Provincia.Properties.Buttons[0].Visible := False;
Poblacion.Properties.Buttons[0].Visible := False;
try
with TablaEmpresas do
begin
Prepare;
Open;
if RecordCount = 0 then
begin
VerMensajeFmt(msgEmpNoExisteEmp, [CodigoEmpresa]);
CancelarModificar;
CloseFrame;
Exit;
end;
end;
Visible := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrEmpresa.ActivarModoEliminar;
begin
dsEmpresas.AutoEdit := False;
Provincia.Properties.Buttons[0].Visible := False;
Poblacion.Properties.Buttons[0].Visible := False;
try
with TablaEmpresas do
begin
Prepare;
Open;
if RecordCount = 0 then
begin
VerMensajeFmt(msgEmpNoExisteEmp, [CodigoEmpresa]);
CancelarModificar;
CloseFrame;
Exit;
end;
end;
Visible := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrEmpresa.BuscarEmpresa;
begin
if Transaccion = NIL then
exit;
try
TablaEmpresas.Close;
// Buscar la fila a tratar si es necesario
if not esCadenaVacia(CodigoEmpresa) then
begin
TablaEmpresas.Params.ByName('CODIGO').AsString := CodigoEmpresa;
end;
TablaEmpresas.Prepare;
TablaEmpresas.Open;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
function TfrEmpresa.CancelarAnadir: Boolean;
begin
Result := False;
try
RollBack;
TablaEmpresas.Close;
Result := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
function TfrEmpresa.CancelarEliminar: Boolean;
begin
Result := False;
try
RollBack;
TablaEmpresas.Close;
Result := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
function TfrEmpresa.CancelarModificar: Boolean;
begin
Result := False;
try
RollBack;
TablaEmpresas.Close;
Result := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
destructor TfrEmpresa.Destroy;
begin
TablaEmpresas.Close;
TablaEmpresas.UnPrepare;
TablaEmpresas.Free;
inherited;
end;
procedure TfrEmpresa.FreeContenido;
begin
if (ContenidoModal is TRdxFrameEmpresas) then begin
CodigoEmpresa := (ContenidoModal as TRdxFrameEmpresas).CodigoEmpresa;
ActivarModo;
end;
if (ContenidoModal is TRdxFrameProvincias) then
CodigoProvincia := (ContenidoModal as TRdxFrameProvincias).CodigoProvincia;
if (ContenidoModal is TRdxFramePoblaciones) then begin
CodigoProvincia := (ContenidoModal as TRdxFramePoblaciones).CodigoProvincia;
CodigoPoblacion := (ContenidoModal as TRdxFramePoblaciones).CodigoPoblacion;
end;
inherited FreeContenido;
end;
procedure TfrEmpresa.SetCodigoPoblacion(Value: Variant);
begin
if (not EsCadenaVacia(Value)) then
begin
FCodigoPoblacion := Value;
Poblacion.DataBinding.Field.AsString := dmTablaPoblaciones.darNombrePoblacion(FCodigoProvincia, FCodigoPoblacion);
end;
end;
procedure TfrEmpresa.SetCodigoProvincia(Value: Variant);
begin
if (not EsCadenaVacia(Value)) then
begin
FCodigoProvincia := Value;
Provincia.DataBinding.Field.AsString := dmTablaProvincias.DarNombreProvincia(FCodigoProvincia);
end;
end;
procedure TfrEmpresa.VerModal;
begin
if (ContenidoModal is TRdxFramePoblaciones) then
(ContenidoModal as TRdxFramePoblaciones).CodigoProvincia := CodigoProvincia;
inherited;
end;
procedure TfrEmpresa.bCancelarClick(Sender: TObject);
begin
if (TratarCambios = IDOK) then
CloseFrame;
end;
procedure TfrEmpresa.GridBotonPoblacionClick(Sender: TObject; AButtonIndex: Integer);
begin
if (esCadenaVacia(CodigoProvincia)) then begin
VerMensaje(msgSinProvincia);
Provincia.setFocus;
Exit;
end;
CodigoProvincia := CodigoProvincia;
CaptionModal := Format(msgListaPoblaciones, [dmTablaProvincias.darNombreProvincia(CodigoProvincia)]);
WidthModal := 280;
HeightModal := 460;
ContenidoModal := TfrPoblaciones.Create(Self);
end;
function TfrEmpresa.ComprobarDatos: Boolean;
begin
Result := False;
if Length(Trim(Nombre.Text)) = 0 then
begin
VerMensajeFmt(msgEmpFaltaAlgo,[msgEmpNombre]);
Nombre.SetFocus;
exit;
end;
Result := True;
end;
procedure TfrEmpresa.GridBotonProvinciaClick(Sender: TObject; AButtonIndex: Integer);
begin
CaptionModal := msgListaProvincias;
WidthModal := 280;
HeightModal := 460;
ContenidoModal := TfrProvincias.Create(Self);
end;
procedure TfrEmpresa.bExaminarClick(Sender: TObject);
begin
Logotipo.LoadFromFile;
end;
procedure TfrEmpresa.ProvinciaSetText(Sender: TField;
const Text: String);
begin
FCodigoProvincia := dmTablaProvincias.DarCodigoProvincia(Text);
Sender.AsString := Text;
end;
procedure TfrEmpresa.CambiarModo(ModoAnterior, Modo: TRdxModo);
begin
inherited;
end;
end.