298 lines
7.5 KiB
ObjectPascal
298 lines
7.5 KiB
ObjectPascal
unit uAsientosController;
|
|
|
|
interface
|
|
|
|
|
|
uses
|
|
Classes, SysUtils, uDADataTable, uControllerBase,
|
|
uBizAsientos, uIDataModuleContabilidad;
|
|
type
|
|
IAsientosController = interface(IObservador)
|
|
['{94E5F2B6-64C8-4331-B9CB-3ED730478529}']
|
|
function BuscarTodos: IBizAsiento;
|
|
function Buscar(ID: Integer): IBizAsiento;
|
|
procedure VerTodos(AAsientos: IBizAsiento);
|
|
procedure Ver(AAsiento: IBizAsiento);
|
|
procedure Anadir(AAsiento : IBizAsiento);
|
|
function Eliminar(AAsiento : IBizAsiento): Boolean;
|
|
function Guardar(AAsiento : IBizAsiento): Boolean;
|
|
procedure DescartarCambios(AAsiento : IBizAsiento);
|
|
function Localizar(AAsientos: IBizAsiento; ADescripcion:String): Boolean;
|
|
function DarListaAsientos: TStringList;
|
|
end;
|
|
|
|
TAsientosController = class(TObservador, IAsientosController)
|
|
protected
|
|
FDataModule : IDataModuleContabilidad;
|
|
|
|
procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override;
|
|
function CreateEditor(const AName : String; const IID: TGUID; out Intf): Boolean;
|
|
|
|
function ValidarAsiento(AAsiento: IBizAsiento): Boolean;
|
|
procedure AsignarDataModule;
|
|
procedure FiltrarAsiento(AAsiento: IBizAsiento);
|
|
|
|
public
|
|
constructor Create; override;
|
|
destructor Destroy; override;
|
|
|
|
function Eliminar(AAsiento : IBizAsiento): Boolean;
|
|
function Guardar(AAsiento : IBizAsiento): Boolean; virtual;
|
|
procedure DescartarCambios(AAsiento : IBizAsiento); virtual;
|
|
procedure Anadir(AAsiento : IBizAsiento);
|
|
function BuscarTodos: IBizAsiento;
|
|
function Buscar(ID: Integer): IBizAsiento;
|
|
procedure VerTodos(AAsientos: IBizAsiento);
|
|
procedure Ver(AAsiento: IBizAsiento);
|
|
function Localizar(AAsientos: IBizAsiento; ADescripcion:String): Boolean;
|
|
function DarListaAsientos: TStringList;
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
cxControls, DB, uEditorRegistryUtils, schContabilidadClient_Intf,
|
|
uIEditorAsientos, uIEditorAsiento, uDataModuleContabilidad,
|
|
uDAInterfaces, uDataTableUtils, uDialogUtils, uFactuGES_App,
|
|
uDateUtils, uROTypes, DateUtils, Controls, Windows;
|
|
|
|
{ TAsientosController }
|
|
|
|
procedure TAsientosController.Anadir(AAsiento: IBizAsiento);
|
|
begin
|
|
AAsiento.Insert;
|
|
end;
|
|
|
|
procedure TAsientosController.AsignarDataModule;
|
|
begin
|
|
FDataModule := TDataModuleContabilidad.Create(Nil);
|
|
end;
|
|
|
|
function TAsientosController.Buscar(ID: Integer): IBizAsiento;
|
|
var
|
|
Condicion: TDAWhereExpression;
|
|
begin
|
|
ShowHourglassCursor;
|
|
try
|
|
Result := BuscarTodos;
|
|
|
|
with Result.DataTable.DynamicWhere do
|
|
begin
|
|
// (ID = :ID)
|
|
Condicion := NewBinaryExpression(NewField('', fld_AsientosID), NewConstant(ID, datInteger), dboEqual);
|
|
|
|
if IsEmpty then
|
|
Expression := Condicion
|
|
else
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
|
end;
|
|
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TAsientosController.BuscarTodos: IBizAsiento;
|
|
begin
|
|
Result := FDataModule.GetAsientoItems;
|
|
FiltrarAsiento(Result);
|
|
end;
|
|
|
|
constructor TAsientosController.Create;
|
|
begin
|
|
inherited;
|
|
AsignarDataModule;
|
|
end;
|
|
|
|
function TAsientosController.CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
|
|
begin
|
|
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
|
|
end;
|
|
|
|
function TAsientosController.DarListaAsientos: TStringList;
|
|
var
|
|
AAsientos: IBizAsiento;
|
|
begin
|
|
AAsientos := BuscarTodos;
|
|
AAsientos.DataTable.Active := True;
|
|
Result := TStringList.Create;
|
|
try
|
|
with Result do
|
|
begin
|
|
AAsientos.DataTable.First;
|
|
while not AAsientos.DataTable.EOF do
|
|
begin
|
|
Add(AAsientos.CONCEPTO);
|
|
AAsientos.DataTable.Next;
|
|
end;
|
|
end;
|
|
finally
|
|
AAsientos := NIL;
|
|
end;
|
|
end;
|
|
|
|
procedure TAsientosController.DescartarCambios(AAsiento: IBizAsiento);
|
|
begin
|
|
if not Assigned(AAsiento) then
|
|
raise Exception.Create ('Asiento no asignado');
|
|
|
|
ShowHourglassCursor;
|
|
try
|
|
if (AAsiento.State in dsEditModes) then
|
|
AAsiento.Cancel;
|
|
|
|
AAsiento.DataTable.CancelUpdates;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
destructor TAsientosController.Destroy;
|
|
begin
|
|
FDataModule:= NIL;
|
|
inherited;
|
|
end;
|
|
|
|
function TAsientosController.ValidarAsiento(AAsiento: IBizAsiento): Boolean;
|
|
begin
|
|
Result := False;
|
|
|
|
if not Assigned(AAsiento) then
|
|
raise Exception.Create ('Asiento no asignado');
|
|
|
|
if (AAsiento.DataTable.State in dsEditModes) then
|
|
AAsiento.DataTable.Post;
|
|
|
|
if Length(AAsiento.CONCEPTO) = 0 then
|
|
raise Exception.Create('Debe indicar un concepto para este Asiento.');
|
|
|
|
Result := True;
|
|
end;
|
|
|
|
procedure TAsientosController.Ver(AAsiento: IBizAsiento);
|
|
var
|
|
AEditor : IEditorAsiento;
|
|
begin
|
|
AEditor := NIL;
|
|
ShowHourglassCursor;
|
|
try
|
|
CreateEditor('EditorAsiento', IEditorAsiento, AEditor);
|
|
if Assigned(AEditor) then
|
|
with AEditor do
|
|
begin
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|
Asiento := AAsiento;
|
|
ShowModal;
|
|
Release;
|
|
end;
|
|
finally
|
|
AEditor := NIL;
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
procedure TAsientosController.VerTodos(AAsientos: IBizAsiento);
|
|
var
|
|
AEditor : IEditorAsientos;
|
|
begin
|
|
AEditor := NIL;
|
|
ShowHourglassCursor;
|
|
try
|
|
CreateEditor('EditorAsientos', IEditorAsientos, AEditor);
|
|
if Assigned(AEditor) then
|
|
with AEditor do
|
|
begin
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|
Asientos := AAsientos;
|
|
ShowEmbedded;
|
|
end;
|
|
finally
|
|
AEditor := NIL;
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TAsientosController.Eliminar(AAsiento: IBizAsiento): Boolean;
|
|
begin
|
|
Result := False;
|
|
|
|
if not Assigned(AAsiento) then
|
|
raise Exception.Create ('Asiento no asignado');
|
|
|
|
ShowHourglassCursor;
|
|
try
|
|
if (AAsiento.State in dsEditModes) then
|
|
AAsiento.Cancel;
|
|
|
|
AAsiento.Delete;
|
|
AAsiento.DataTable.ApplyUpdates;
|
|
HideHourglassCursor;
|
|
Result := True;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
procedure TAsientosController.FiltrarAsiento(AAsiento: IBizAsiento);
|
|
var
|
|
Condicion: TDAWhereExpression;
|
|
begin
|
|
if AAsiento.DataTable.Active then
|
|
AAsiento.DataTable.Active := False;
|
|
|
|
// Filtrar los Asientos actuales por Asiento activo
|
|
{ with AAsiento.DataTable.DynamicWhere do
|
|
begin
|
|
// (ID_Asiento = ID)
|
|
Condicion := NewBinaryExpression(NewField('', fld_AsientosID_Asiento), NewConstant(AppFactuGES.AsientoActivo.ID, datInteger), dboEqual);
|
|
|
|
if IsEmpty then
|
|
Expression := Condicion
|
|
else
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
|
end;
|
|
}
|
|
end;
|
|
|
|
procedure TAsientosController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable);
|
|
begin
|
|
inherited;
|
|
//
|
|
end;
|
|
|
|
function TAsientosController.Guardar(AAsiento: IBizAsiento): Boolean;
|
|
begin
|
|
Result := False;
|
|
|
|
if ValidarAsiento(AAsiento) then
|
|
begin
|
|
ShowHourglassCursor;
|
|
try
|
|
AAsiento.DataTable.ApplyUpdates;
|
|
Result := True;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function TAsientosController.Localizar(AAsientos: IBizAsiento; ADescripcion: String): Boolean;
|
|
begin
|
|
Result := True;
|
|
ShowHourglassCursor;
|
|
try
|
|
with AAsientos.DataTable do
|
|
begin
|
|
DisableControls;
|
|
First;
|
|
if not Locate(fld_AsientosCONCEPTO, ADescripcion, []) then
|
|
Result := False;
|
|
EnableControls;
|
|
end;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
end.
|