2007-10-03 16:03:28 +00:00
|
|
|
|
unit uEmpresasController;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
Windows, Forms, Classes, Controls, Contnrs, SysUtils,
|
2007-10-08 07:58:40 +00:00
|
|
|
|
uBizEmpresas, uIDataModuleEmpresas, uDADataTable, uControllerBase;
|
2007-10-03 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
|
type
|
2007-10-08 07:58:40 +00:00
|
|
|
|
IEmpresasController = interface(IControllerBase)
|
2007-10-03 16:03:28 +00:00
|
|
|
|
['{2F0AB21C-4F19-446E-87C4-B9C1038850FC}']
|
|
|
|
|
|
function Buscar(const ID: Integer): IBizEmpresa;
|
|
|
|
|
|
function BuscarTodos: IBizEmpresa;
|
|
|
|
|
|
procedure Ver(AEmpresa : IBizEmpresa);
|
|
|
|
|
|
procedure VerTodos(AEmpresas: IBizEmpresa);
|
|
|
|
|
|
function Nuevo : IBizEmpresa;
|
|
|
|
|
|
procedure Anadir(AEmpresa : IBizEmpresa);
|
|
|
|
|
|
function Eliminar(const ID : Integer): Boolean; overload;
|
|
|
|
|
|
function Eliminar(AEmpresa : IBizEmpresa): Boolean; overload;
|
|
|
|
|
|
function Guardar(AEmpresa : IBizEmpresa): Boolean;
|
|
|
|
|
|
procedure DescartarCambios(AEmpresa : IBizEmpresa);
|
|
|
|
|
|
function Existe(const ID: Integer) : Boolean;
|
|
|
|
|
|
function ToStringList(AEmpresa : IBizEmpresa) : TStringList;
|
2008-06-05 18:21:13 +00:00
|
|
|
|
function DarListaCuentasBancarias(AEmpresa : IBizEmpresa): TStringList;
|
2008-06-12 17:24:02 +00:00
|
|
|
|
function DarListaCuentasBancariasIBAN(AEmpresa : IBizEmpresa): TStringList;
|
2007-10-03 16:03:28 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2007-10-08 07:58:40 +00:00
|
|
|
|
TEmpresasController = class(TControllerBase, IEmpresasController)
|
2007-10-03 16:03:28 +00:00
|
|
|
|
protected
|
|
|
|
|
|
FDataModule : IDataModuleEmpresas;
|
|
|
|
|
|
function ValidarEmpresa(AEmpresa : IBizEmpresa): Boolean; virtual;
|
|
|
|
|
|
public
|
2008-05-14 14:38:09 +00:00
|
|
|
|
constructor Create; override;
|
2007-10-03 16:03:28 +00:00
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
|
|
|
|
|
|
function Eliminar(const ID : Integer): Boolean; overload;
|
2008-06-12 17:24:02 +00:00
|
|
|
|
function Eliminar(AEmpresa : IBizEmpresa): Boolean; overload;
|
|
|
|
|
|
function Guardar(AEmpresa : IBizEmpresa): Boolean;
|
2007-10-03 16:03:28 +00:00
|
|
|
|
procedure DescartarCambios(AEmpresa : IBizEmpresa); virtual;
|
|
|
|
|
|
function Existe(const ID: Integer) : Boolean; virtual;
|
|
|
|
|
|
procedure Anadir(AEmpresa : IBizEmpresa); virtual;
|
|
|
|
|
|
|
|
|
|
|
|
function Buscar(const ID: Integer): IBizEmpresa; virtual;
|
|
|
|
|
|
function BuscarTodos: IBizEmpresa; virtual;
|
|
|
|
|
|
function Nuevo : IBizEmpresa; virtual;
|
|
|
|
|
|
procedure Ver(AEmpresa : IBizEmpresa); virtual;
|
|
|
|
|
|
procedure VerTodos(AEmpresas: IBizEmpresa); virtual;
|
|
|
|
|
|
function ToStringList(AEmpresa : IBizEmpresa) : TStringList; virtual;
|
2008-06-05 18:21:13 +00:00
|
|
|
|
function DarListaCuentasBancarias(AEmpresa : IBizEmpresa): TStringList;
|
2008-06-12 17:24:02 +00:00
|
|
|
|
function DarListaCuentasBancariasIBAN(AEmpresa : IBizEmpresa): TStringList;
|
2007-10-03 16:03:28 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
2008-09-24 17:59:34 +00:00
|
|
|
|
uEditorRegistryUtils, cxControls, DB, uFactuGES_App, uStringsUtils,
|
2008-06-05 18:21:13 +00:00
|
|
|
|
uDataModuleEmpresas, uIEditorEmpresa, uBizEmpresasDatosBancarios;
|
2007-10-03 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
|
{ TEmpresasController }
|
|
|
|
|
|
|
|
|
|
|
|
procedure TEmpresasController.Anadir(AEmpresa: IBizEmpresa);
|
|
|
|
|
|
begin
|
|
|
|
|
|
AEmpresa.Insert;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TEmpresasController.Buscar(const ID: Integer): IBizEmpresa;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := FDataModule.GetItem(ID)
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TEmpresasController.BuscarTodos: IBizEmpresa;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := FDataModule.GetItems;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
constructor TEmpresasController.Create;
|
|
|
|
|
|
begin
|
2008-11-10 19:38:27 +00:00
|
|
|
|
inherited;
|
2007-10-24 18:54:18 +00:00
|
|
|
|
FDataModule := TDataModuleEmpresas.Create(Nil);
|
2007-10-03 16:03:28 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2008-06-05 18:21:13 +00:00
|
|
|
|
function TEmpresasController.DarListaCuentasBancarias(
|
|
|
|
|
|
AEmpresa: IBizEmpresa): TStringList;
|
|
|
|
|
|
var
|
|
|
|
|
|
ADatosBancarios: IBizEmpresasDatosBancarios;
|
|
|
|
|
|
Aux : String;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AEmpresa) then
|
|
|
|
|
|
raise Exception.Create ('Empresa no asignada (DarListaCuentasBancarias)');
|
|
|
|
|
|
|
|
|
|
|
|
ADatosBancarios := AEmpresa.DatosBancarios;
|
|
|
|
|
|
ADatosBancarios.DataTable.Active := True;
|
|
|
|
|
|
|
|
|
|
|
|
Result := TStringList.Create;
|
2008-06-12 17:24:02 +00:00
|
|
|
|
ShowHourglassCursor;
|
2008-06-05 18:21:13 +00:00
|
|
|
|
try
|
|
|
|
|
|
with Result do
|
|
|
|
|
|
begin
|
|
|
|
|
|
ADatosBancarios.DataTable.First;
|
|
|
|
|
|
while not ADatosBancarios.DataTable.EOF do
|
|
|
|
|
|
begin
|
2008-06-13 14:54:06 +00:00
|
|
|
|
Aux := Format('N<> de cuenta: %s %s %s %s', [ADatosBancarios.ENTIDAD,
|
2008-06-05 18:21:13 +00:00
|
|
|
|
ADatosBancarios.SUCURSAL, ADatosBancarios.DC, ADatosBancarios.CUENTA]);
|
|
|
|
|
|
Add(Format('%s=%d', [Aux, ADatosBancarios.ID]));
|
|
|
|
|
|
ADatosBancarios.DataTable.Next;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
ADatosBancarios := NIL;
|
2008-06-12 17:24:02 +00:00
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TEmpresasController.DarListaCuentasBancariasIBAN(AEmpresa: IBizEmpresa): TStringList;
|
|
|
|
|
|
var
|
|
|
|
|
|
ADatosBancarios: IBizEmpresasDatosBancarios;
|
|
|
|
|
|
Aux : String;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AEmpresa) then
|
|
|
|
|
|
raise Exception.Create ('Empresa no asignada (DarListaCuentasBancariasIBAN)');
|
|
|
|
|
|
|
|
|
|
|
|
ADatosBancarios := AEmpresa.DatosBancarios;
|
|
|
|
|
|
ADatosBancarios.DataTable.Active := True;
|
|
|
|
|
|
|
|
|
|
|
|
Result := TStringList.Create;
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
|
|
|
|
|
with Result do
|
|
|
|
|
|
begin
|
|
|
|
|
|
ADatosBancarios.DataTable.First;
|
|
|
|
|
|
while not ADatosBancarios.DataTable.EOF do
|
|
|
|
|
|
begin
|
2008-09-24 17:59:34 +00:00
|
|
|
|
if not EsCadenaVacia(ADatosBancarios.IBAN) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
Aux := Format('IBAN: %s - SWIFT: %s', [ADatosBancarios.IBAN, ADatosBancarios.SWIFT]);
|
|
|
|
|
|
Add(Format('%s=%d', [Aux, ADatosBancarios.ID]));
|
|
|
|
|
|
end;
|
2008-06-12 17:24:02 +00:00
|
|
|
|
ADatosBancarios.DataTable.Next;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
ADatosBancarios := NIL;
|
|
|
|
|
|
HideHourglassCursor;
|
2008-06-05 18:21:13 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-10-03 16:03:28 +00:00
|
|
|
|
procedure TEmpresasController.DescartarCambios(AEmpresa: IBizEmpresa);
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AEmpresa) then
|
2008-06-05 18:21:13 +00:00
|
|
|
|
raise Exception.Create ('Empresa no asignada (DescartarCambios)');
|
2007-10-03 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
|
|
|
|
|
if (AEmpresa.State in dsEditModes) then
|
|
|
|
|
|
AEmpresa.Cancel;
|
|
|
|
|
|
|
|
|
|
|
|
AEmpresa.DataTable.CancelUpdates;
|
|
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TEmpresasController.Destroy;
|
|
|
|
|
|
begin
|
|
|
|
|
|
FDataModule := NIL;
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TEmpresasController.Eliminar(AEmpresa: IBizEmpresa): Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AEmpresa) then
|
|
|
|
|
|
raise Exception.Create ('Empresa no asignada');
|
|
|
|
|
|
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
|
|
|
|
|
if (AEmpresa.State in dsEditModes) then
|
|
|
|
|
|
AEmpresa.Cancel;
|
|
|
|
|
|
|
|
|
|
|
|
AEmpresa.Delete;
|
|
|
|
|
|
AEmpresa.DataTable.ApplyUpdates;
|
|
|
|
|
|
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TEmpresasController.Eliminar(const ID: Integer): Boolean;
|
|
|
|
|
|
var
|
|
|
|
|
|
AEmpresa : IBizEmpresa;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AEmpresa := Buscar(ID);
|
|
|
|
|
|
|
|
|
|
|
|
if not Assigned(AEmpresa) then
|
|
|
|
|
|
raise Exception.Create(Format('No se ha encontrado la empresa con ID = %d', [ID]));
|
|
|
|
|
|
|
|
|
|
|
|
Result := Eliminar(AEmpresa);
|
|
|
|
|
|
AEmpresa := NIL;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TEmpresasController.Existe(const ID: Integer): Boolean;
|
|
|
|
|
|
var
|
|
|
|
|
|
AEmpresa : IBizEmpresa;
|
|
|
|
|
|
begin
|
|
|
|
|
|
try
|
|
|
|
|
|
AEmpresa := Buscar(ID);
|
|
|
|
|
|
Result := Assigned(AEmpresa) and (AEmpresa.ID = ID);
|
|
|
|
|
|
finally
|
|
|
|
|
|
AEmpresa := NIL;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TEmpresasController.Guardar(AEmpresa: IBizEmpresa): Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
|
|
|
|
if ValidarEmpresa(AEmpresa) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
|
|
|
|
|
AEmpresa.DataTable.ApplyUpdates;
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TEmpresasController.Nuevo: IBizEmpresa;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := FDataModule.NewItem;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TEmpresasController.ToStringList(AEmpresa: IBizEmpresa): TStringList;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := TStringList.Create;
|
|
|
|
|
|
with Result do
|
|
|
|
|
|
begin
|
|
|
|
|
|
AEmpresa.DataTable.Active := True;
|
|
|
|
|
|
AEmpresa.First;
|
|
|
|
|
|
while not AEmpresa.EOF do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Add(AEmpresa.NOMBRE);
|
|
|
|
|
|
AEmpresa.Next;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TEmpresasController.ValidarEmpresa(AEmpresa: IBizEmpresa): Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AEmpresa) then
|
|
|
|
|
|
raise Exception.Create ('Empresa no asignada');
|
|
|
|
|
|
|
|
|
|
|
|
if (AEmpresa.DataTable.State in dsEditModes) then
|
|
|
|
|
|
AEmpresa.DataTable.Post;
|
|
|
|
|
|
|
|
|
|
|
|
if Length(AEmpresa.NOMBRE) = 0 then
|
|
|
|
|
|
raise Exception.Create('Debe indicar al menos el nombre de la empresa.');
|
|
|
|
|
|
|
|
|
|
|
|
// Asegurarse de valores en campos "autom<6F>ticos"
|
2007-11-18 15:06:31 +00:00
|
|
|
|
AEmpresa.Edit;
|
|
|
|
|
|
AEmpresa.USUARIO := AppFactuGES.UsuarioActivo.UserName;
|
|
|
|
|
|
AEmpresa.Post;
|
2007-10-03 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TEmpresasController.Ver(AEmpresa: IBizEmpresa);
|
|
|
|
|
|
var
|
|
|
|
|
|
AEditor : IEditorEmpresa;
|
|
|
|
|
|
begin
|
2007-11-18 20:08:55 +00:00
|
|
|
|
AEditor := NIL;
|
2007-10-03 16:03:28 +00:00
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
|
|
|
|
|
CreateEditor('EditorEmpresa', IEditorEmpresa, AEditor);
|
2007-11-18 18:42:04 +00:00
|
|
|
|
if Assigned(AEditor) then
|
|
|
|
|
|
with AEditor do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Empresa := AEmpresa;
|
|
|
|
|
|
Controller := Self;
|
|
|
|
|
|
ShowModal;
|
|
|
|
|
|
Release;
|
|
|
|
|
|
end;
|
2007-10-03 16:03:28 +00:00
|
|
|
|
finally
|
2007-11-18 18:42:04 +00:00
|
|
|
|
AEditor := NIL;
|
2007-10-03 16:03:28 +00:00
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TEmpresasController.VerTodos(AEmpresas: IBizEmpresa);
|
|
|
|
|
|
{var
|
2007-11-18 20:08:55 +00:00
|
|
|
|
AEditor : IEditorEmpresas;}
|
2007-10-03 16:03:28 +00:00
|
|
|
|
begin
|
2007-11-18 20:08:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
AEditor := NIL;
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
|
|
|
|
|
CreateEditor('EditorEmpresas', IEditorClientes, AEditor);
|
|
|
|
|
|
if Assigned(AEditor) then
|
|
|
|
|
|
with AEditor do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Contactos := AContactos;
|
|
|
|
|
|
Controller := Self;
|
|
|
|
|
|
ShowEmbedded;
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
AEditor := NIL;
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
}
|
2007-10-03 16:03:28 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end.
|