297 lines
7.4 KiB
ObjectPascal
297 lines
7.4 KiB
ObjectPascal
unit uCuentasController;
|
|
|
|
interface
|
|
|
|
|
|
uses
|
|
Classes, SysUtils, uDADataTable, uControllerBase,
|
|
uBizCuentas, uIDataModuleContabilidad;
|
|
type
|
|
ICuentasController = interface(IObservador)
|
|
['{94E5F2B6-64C8-4331-B9CB-3ED730478529}']
|
|
function BuscarTodos: IBizCuenta;
|
|
function Buscar(ID: Integer): IBizCuenta;
|
|
procedure VerTodos(ACuentas: IBizCuenta);
|
|
procedure Ver(ACuenta: IBizCuenta);
|
|
procedure Anadir(ACuenta : IBizCuenta);
|
|
function Eliminar(ACuenta : IBizCuenta): Boolean;
|
|
function Guardar(ACuenta : IBizCuenta): Boolean;
|
|
procedure DescartarCambios(ACuenta : IBizCuenta);
|
|
function Localizar(ACuentas: IBizCuenta; ADescripcion:String): Boolean;
|
|
function DarListaCuentas: TStringList;
|
|
end;
|
|
|
|
TCuentasController = class(TObservador, ICuentasController)
|
|
protected
|
|
FDataModule : IDataModuleContabilidad;
|
|
|
|
procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override;
|
|
function CreateEditor(const AName : String; const IID: TGUID; out Intf): Boolean;
|
|
|
|
function ValidarCuenta(ACuenta: IBizCuenta): Boolean;
|
|
procedure AsignarDataModule;
|
|
procedure FiltrarEjercicio(ACuenta: IBizCuenta);
|
|
|
|
public
|
|
constructor Create; override;
|
|
destructor Destroy; override;
|
|
|
|
function Eliminar(ACuenta : IBizCuenta): Boolean;
|
|
function Guardar(ACuenta : IBizCuenta): Boolean; virtual;
|
|
procedure DescartarCambios(ACuenta : IBizCuenta); virtual;
|
|
procedure Anadir(ACuenta : IBizCuenta);
|
|
function BuscarTodos: IBizCuenta;
|
|
function Buscar(ID: Integer): IBizCuenta;
|
|
procedure VerTodos(ACuentas: IBizCuenta);
|
|
procedure Ver(ACuenta: IBizCuenta);
|
|
function Localizar(ACuentas: IBizCuenta; ADescripcion:String): Boolean;
|
|
function DarListaCuentas: TStringList;
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
cxControls, DB, uEditorRegistryUtils, schContabilidadClient_Intf,
|
|
uIEditorCuentas, uIEditorCuenta, uDataModuleContabilidad,
|
|
uDAInterfaces, uDataTableUtils, uDialogUtils, uFactuGES_App,
|
|
uDateUtils, uROTypes, DateUtils, Controls, Windows;
|
|
|
|
{ TCuentasController }
|
|
|
|
procedure TCuentasController.Anadir(ACuenta: IBizCuenta);
|
|
begin
|
|
ACuenta.Insert;
|
|
end;
|
|
|
|
procedure TCuentasController.AsignarDataModule;
|
|
begin
|
|
FDataModule := TDataModuleContabilidad.Create(Nil);
|
|
end;
|
|
|
|
function TCuentasController.Buscar(ID: Integer): IBizCuenta;
|
|
var
|
|
Condicion: TDAWhereExpression;
|
|
begin
|
|
ShowHourglassCursor;
|
|
try
|
|
Result := BuscarTodos;
|
|
|
|
with Result.DataTable.DynamicWhere do
|
|
begin
|
|
// (ID = :ID)
|
|
Condicion := NewBinaryExpression(NewField('', fld_CuentasID), NewConstant(ID, datInteger), dboEqual);
|
|
|
|
if IsEmpty then
|
|
Expression := Condicion
|
|
else
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
|
end;
|
|
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TCuentasController.BuscarTodos: IBizCuenta;
|
|
begin
|
|
Result := FDataModule.GetCuentaItems;
|
|
FiltrarEjercicio(Result);
|
|
end;
|
|
|
|
constructor TCuentasController.Create;
|
|
begin
|
|
inherited;
|
|
AsignarDataModule;
|
|
end;
|
|
|
|
function TCuentasController.CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
|
|
begin
|
|
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
|
|
end;
|
|
|
|
function TCuentasController.DarListaCuentas: TStringList;
|
|
var
|
|
ACuentas: IBizCuenta;
|
|
begin
|
|
ACuentas := BuscarTodos;
|
|
ACuentas.DataTable.Active := True;
|
|
Result := TStringList.Create;
|
|
try
|
|
with Result do
|
|
begin
|
|
ACuentas.DataTable.First;
|
|
while not ACuentas.DataTable.EOF do
|
|
begin
|
|
Add(ACuentas.DESCRIPCION);
|
|
ACuentas.DataTable.Next;
|
|
end;
|
|
end;
|
|
finally
|
|
ACuentas := NIL;
|
|
end;
|
|
end;
|
|
|
|
procedure TCuentasController.DescartarCambios(ACuenta: IBizCuenta);
|
|
begin
|
|
if not Assigned(ACuenta) then
|
|
raise Exception.Create ('Cuenta no asignado');
|
|
|
|
ShowHourglassCursor;
|
|
try
|
|
if (ACuenta.State in dsEditModes) then
|
|
ACuenta.Cancel;
|
|
|
|
ACuenta.DataTable.CancelUpdates;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
destructor TCuentasController.Destroy;
|
|
begin
|
|
FDataModule:= NIL;
|
|
inherited;
|
|
end;
|
|
|
|
function TCuentasController.ValidarCuenta(ACuenta: IBizCuenta): Boolean;
|
|
begin
|
|
Result := False;
|
|
|
|
if not Assigned(ACuenta) then
|
|
raise Exception.Create ('Cuenta no asignado');
|
|
|
|
if (ACuenta.DataTable.State in dsEditModes) then
|
|
ACuenta.DataTable.Post;
|
|
|
|
if Length(ACuenta.DESCRIPCION) = 0 then
|
|
raise Exception.Create('Debe indicar un nombre para este Cuenta.');
|
|
|
|
Result := True;
|
|
end;
|
|
|
|
procedure TCuentasController.Ver(ACuenta: IBizCuenta);
|
|
var
|
|
AEditor : IEditorCuenta;
|
|
begin
|
|
AEditor := NIL;
|
|
ShowHourglassCursor;
|
|
try
|
|
CreateEditor('EditorCuenta', IEditorCuenta, AEditor);
|
|
if Assigned(AEditor) then
|
|
with AEditor do
|
|
begin
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|
Cuenta := ACuenta;
|
|
ShowModal;
|
|
Release;
|
|
end;
|
|
finally
|
|
AEditor := NIL;
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
procedure TCuentasController.VerTodos(ACuentas: IBizCuenta);
|
|
var
|
|
AEditor : IEditorCuentas;
|
|
begin
|
|
AEditor := NIL;
|
|
ShowHourglassCursor;
|
|
try
|
|
CreateEditor('EditorCuentas', IEditorCuentas, AEditor);
|
|
if Assigned(AEditor) then
|
|
with AEditor do
|
|
begin
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|
Cuentas := ACuentas;
|
|
ShowEmbedded;
|
|
end;
|
|
finally
|
|
AEditor := NIL;
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TCuentasController.Eliminar(ACuenta: IBizCuenta): Boolean;
|
|
begin
|
|
Result := False;
|
|
|
|
if not Assigned(ACuenta) then
|
|
raise Exception.Create ('Cuenta no asignado');
|
|
|
|
ShowHourglassCursor;
|
|
try
|
|
if (ACuenta.State in dsEditModes) then
|
|
ACuenta.Cancel;
|
|
|
|
ACuenta.Delete;
|
|
ACuenta.DataTable.ApplyUpdates;
|
|
HideHourglassCursor;
|
|
Result := True;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
procedure TCuentasController.FiltrarEjercicio(ACuenta: IBizCuenta);
|
|
var
|
|
Condicion: TDAWhereExpression;
|
|
begin
|
|
if ACuenta.DataTable.Active then
|
|
ACuenta.DataTable.Active := False;
|
|
|
|
// Filtrar los Cuentas actuales por ejercicio activo
|
|
with ACuenta.DataTable.DynamicWhere do
|
|
begin
|
|
// (ID_EJERCICIO = ID)
|
|
Condicion := NewBinaryExpression(NewField('', fld_CuentasID_EJERCICIO), NewConstant(AppFactuGES.EjercicioActivo.ID, datInteger), dboEqual);
|
|
|
|
if IsEmpty then
|
|
Expression := Condicion
|
|
else
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
|
end;
|
|
end;
|
|
|
|
procedure TCuentasController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable);
|
|
begin
|
|
inherited;
|
|
//
|
|
end;
|
|
|
|
function TCuentasController.Guardar(ACuenta: IBizCuenta): Boolean;
|
|
begin
|
|
Result := False;
|
|
|
|
if ValidarCuenta(ACuenta) then
|
|
begin
|
|
ShowHourglassCursor;
|
|
try
|
|
ACuenta.DataTable.ApplyUpdates;
|
|
Result := True;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function TCuentasController.Localizar(ACuentas: IBizCuenta; ADescripcion: String): Boolean;
|
|
begin
|
|
Result := True;
|
|
ShowHourglassCursor;
|
|
try
|
|
with ACuentas.DataTable do
|
|
begin
|
|
DisableControls;
|
|
First;
|
|
if not Locate(fld_CuentasDESCRIPCION, ADescripcion, []) then
|
|
Result := False;
|
|
EnableControls;
|
|
end;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
end.
|