git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@777 0c75b7a4-871f-7646-8a2f-f78d34cc349f
370 lines
9.9 KiB
ObjectPascal
370 lines
9.9 KiB
ObjectPascal
unit uEmpresasController;
|
||
|
||
interface
|
||
|
||
|
||
uses
|
||
Windows, Forms, Classes, Controls, Contnrs, SysUtils,
|
||
uBizEmpresas, uIDataModuleEmpresas, uDADataTable, uControllerBase;
|
||
|
||
type
|
||
IEmpresasController = interface(IControllerBase)
|
||
['{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;
|
||
function DarListaCuentasBancarias(AEmpresa : IBizEmpresa): TStringList;
|
||
function DarListaCuentasBancariasIBAN(AEmpresa : IBizEmpresa): TStringList;
|
||
|
||
function DarListaFormasPago: TStringList;
|
||
function DarListaTiposIVA: TStringList;
|
||
Procedure AsignarIDFormaPago(AEmpresa: IBizEmpresa; const IDFormaPago: Variant);
|
||
Procedure AsignarIDTipoIVA(AEmpresa: IBizEmpresa; const IDTipoIVA: Variant);
|
||
end;
|
||
|
||
TEmpresasController = class(TControllerBase, IEmpresasController)
|
||
protected
|
||
FDataModule : IDataModuleEmpresas;
|
||
function ValidarEmpresa(AEmpresa : IBizEmpresa): Boolean; virtual;
|
||
public
|
||
constructor Create; override;
|
||
destructor Destroy; override;
|
||
|
||
function Eliminar(const ID : Integer): Boolean; overload;
|
||
function Eliminar(AEmpresa : IBizEmpresa): Boolean; overload;
|
||
function Guardar(AEmpresa : IBizEmpresa): Boolean;
|
||
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;
|
||
function DarListaCuentasBancarias(AEmpresa : IBizEmpresa): TStringList;
|
||
function DarListaCuentasBancariasIBAN(AEmpresa : IBizEmpresa): TStringList;
|
||
|
||
function DarListaFormasPago: TStringList;
|
||
function DarListaTiposIVA: TStringList;
|
||
Procedure AsignarIDFormaPago(AEmpresa: IBizEmpresa; const IDFormaPago: Variant);
|
||
Procedure AsignarIDTipoIVA(AEmpresa: IBizEmpresa; const IDTipoIVA: Variant);
|
||
end;
|
||
|
||
implementation
|
||
|
||
uses
|
||
uEditorRegistryUtils, cxControls, DB, uFactuGES_App, uStringsUtils,
|
||
uDataModuleEmpresas, uIEditorEmpresa, uBizEmpresasDatosBancarios;
|
||
|
||
{ TEmpresasController }
|
||
|
||
procedure TEmpresasController.Anadir(AEmpresa: IBizEmpresa);
|
||
begin
|
||
AEmpresa.Insert;
|
||
end;
|
||
|
||
procedure TEmpresasController.AsignarIDFormaPago(AEmpresa: IBizEmpresa;
|
||
const IDFormaPago: Variant);
|
||
begin
|
||
if Assigned(AEmpresa) then
|
||
begin
|
||
if not AEmpresa.DataTable.Editing then
|
||
AEmpresa.DataTable.Edit;
|
||
|
||
if EsCadenaVacia(IDFormaPago) then
|
||
AEmpresa.ID_FORMA_PAGOIsNull := true
|
||
else
|
||
AEmpresa.ID_FORMA_PAGO := IDFormaPago;
|
||
|
||
AEmpresa.DataTable.Post;
|
||
end;
|
||
end;
|
||
|
||
procedure TEmpresasController.AsignarIDTipoIVA(AEmpresa: IBizEmpresa;
|
||
const IDTipoIVA: Variant);
|
||
begin
|
||
if Assigned(AEmpresa) then
|
||
begin
|
||
if not AEmpresa.DataTable.Editing then
|
||
AEmpresa.DataTable.Edit;
|
||
|
||
if EsCadenaVacia(IDTipoIVA) then
|
||
AEmpresa.ID_TIPO_IVAIsNull := true
|
||
else
|
||
AEmpresa.ID_TIPO_IVA := IDTipoIVA;
|
||
|
||
AEmpresa.DataTable.Post;
|
||
end;
|
||
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
|
||
inherited;
|
||
FDataModule := TDataModuleEmpresas.Create(Nil);
|
||
end;
|
||
|
||
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;
|
||
ShowHourglassCursor;
|
||
try
|
||
with Result do
|
||
begin
|
||
ADatosBancarios.DataTable.First;
|
||
while not ADatosBancarios.DataTable.EOF do
|
||
begin
|
||
Aux := Format('N<> de cuenta: %s %s %s %s', [ADatosBancarios.ENTIDAD,
|
||
ADatosBancarios.SUCURSAL, ADatosBancarios.DC, ADatosBancarios.CUENTA]);
|
||
Add(Format('%s=%d', [Aux, ADatosBancarios.ID]));
|
||
ADatosBancarios.DataTable.Next;
|
||
end;
|
||
end;
|
||
finally
|
||
ADatosBancarios := NIL;
|
||
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
|
||
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;
|
||
ADatosBancarios.DataTable.Next;
|
||
end;
|
||
end;
|
||
finally
|
||
ADatosBancarios := NIL;
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
function TEmpresasController.DarListaFormasPago: TStringList;
|
||
begin
|
||
ShowHourglassCursor;
|
||
try
|
||
Result := FDataModule.DarListaFormasPago;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
function TEmpresasController.DarListaTiposIVA: TStringList;
|
||
begin
|
||
ShowHourglassCursor;
|
||
try
|
||
Result := FDataModule.DarListaTiposIVA;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
procedure TEmpresasController.DescartarCambios(AEmpresa: IBizEmpresa);
|
||
begin
|
||
if not Assigned(AEmpresa) then
|
||
raise Exception.Create ('Empresa no asignada (DescartarCambios)');
|
||
|
||
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"
|
||
AEmpresa.Edit;
|
||
AEmpresa.USUARIO := AppFactuGES.UsuarioActivo.UserName;
|
||
AEmpresa.Post;
|
||
|
||
Result := True;
|
||
end;
|
||
|
||
procedure TEmpresasController.Ver(AEmpresa: IBizEmpresa);
|
||
var
|
||
AEditor : IEditorEmpresa;
|
||
begin
|
||
AEditor := NIL;
|
||
CreateEditor('EditorEmpresa', IEditorEmpresa, AEditor);
|
||
if Assigned(AEditor) then
|
||
try
|
||
AEditor.Empresa := AEmpresa;
|
||
AEditor.Controller := Self;
|
||
AEditor.ShowModal;
|
||
finally
|
||
AEditor.Release;
|
||
AEditor := NIL;
|
||
end;
|
||
end;
|
||
|
||
procedure TEmpresasController.VerTodos(AEmpresas: IBizEmpresa);
|
||
{var
|
||
AEditor : IEditorEmpresas;}
|
||
begin
|
||
{
|
||
AEditor := NIL;
|
||
CreateEditor('EditorEmpresas', IEditorClientes, AEditor);
|
||
if Assigned(AEditor) then
|
||
try
|
||
AEditor.Contactos := AContactos;
|
||
AEditor.Controller := Self;
|
||
AEditor.ShowModal;
|
||
finally
|
||
AEditor.Release;
|
||
AEditor := NIL;
|
||
end;
|
||
}
|
||
end;
|
||
|
||
end.
|