git-svn-id: https://192.168.0.254/svn/Proyectos.Acana_FactuGES2/trunk@72 f4e31baf-9722-1c47-927c-6f952f962d4b
258 lines
6.7 KiB
ObjectPascal
258 lines
6.7 KiB
ObjectPascal
unit uAsientosController;
|
||
|
||
interface
|
||
|
||
|
||
uses
|
||
Classes, SysUtils, uDADataTable, uControllerBase,
|
||
uBizAsientos, uBizDiario, uIDataModuleContabilidad;
|
||
type
|
||
IAsientosController = interface(IObservador)
|
||
['{94E5F2B6-64C8-4331-B9CB-3ED730478529}']
|
||
function BuscarDiario: IBizDiario;
|
||
function Buscar(const ID: Integer): IBizAsiento;
|
||
procedure VerDiario(ADiario: IBizDiario);
|
||
procedure Ver(AAsiento: IBizAsiento);
|
||
function Anadir(NumOrden:Integer): IBizAsiento;
|
||
function Eliminar(AAsiento : IBizAsiento): Boolean;
|
||
function Guardar(AAsiento : IBizAsiento): Boolean;
|
||
procedure DescartarCambios(AAsiento : IBizAsiento);
|
||
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 FiltrarEjercicio(ADiario: IBizDiario);
|
||
|
||
public
|
||
constructor Create; override;
|
||
destructor Destroy; override;
|
||
|
||
function Eliminar(AAsiento : IBizAsiento): Boolean;
|
||
function Guardar(AAsiento : IBizAsiento): Boolean; virtual;
|
||
procedure DescartarCambios(AAsiento : IBizAsiento); virtual;
|
||
function Anadir(NumOrden:Integer): IBizAsiento;
|
||
function BuscarDiario: IBizDiario;
|
||
function Buscar(const ID: Integer): IBizAsiento;
|
||
procedure VerDiario(ADiario: IBizDiario);
|
||
procedure Ver(AAsiento: IBizAsiento);
|
||
end;
|
||
|
||
implementation
|
||
|
||
uses
|
||
cxControls, DB, uEditorRegistryUtils, schContabilidadClient_Intf,
|
||
uIEditorDiario, uIEditorAsiento, uDataModuleContabilidad,
|
||
uDAInterfaces, uDataTableUtils, uDialogUtils, uFactuGES_App,
|
||
uDateUtils, uROTypes, DateUtils, Controls, Windows, uApuntesController;
|
||
|
||
{ TAsientosController }
|
||
|
||
function TAsientosController.Anadir(NumOrden:Integer): IBizAsiento;
|
||
var
|
||
AAsiento : IBizAsiento;
|
||
begin
|
||
AAsiento := FDataModule.GetAsientoItem(ID_NULO);
|
||
AAsiento.DataTable.Active := True;
|
||
AAsiento.Insert;
|
||
AAsiento.ORDEN := NumOrden;
|
||
Result := AAsiento;
|
||
end;
|
||
|
||
procedure TAsientosController.AsignarDataModule;
|
||
begin
|
||
FDataModule := TDataModuleContabilidad.Create(Nil);
|
||
end;
|
||
|
||
function TAsientosController.Buscar(const ID: Integer): IBizAsiento;
|
||
begin
|
||
Result := FDataModule.GetAsientoItem(ID);
|
||
end;
|
||
|
||
function TAsientosController.BuscarDiario: IBizDiario;
|
||
begin
|
||
Result := FDataModule.GetDiarioItems;
|
||
FiltrarEjercicio(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;
|
||
|
||
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 AAsiento.FECHA_ASIENTOIsNull then
|
||
raise Exception.Create('Debe indicar una fecha para este Asiento.');
|
||
|
||
if AAsiento.ORDENIsNull then
|
||
raise Exception.Create('Debe indicar un n<>mero de orden para este Asiento.');
|
||
|
||
//Tambien validamos los detalles del asiento
|
||
with TApuntesController.Create do
|
||
ValidarApunte(AAsiento.Apuntes);
|
||
|
||
// 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.VerDiario(ADiario: IBizDiario);
|
||
var
|
||
AEditor : IEditorDiario;
|
||
begin
|
||
AEditor := NIL;
|
||
ShowHourglassCursor;
|
||
try
|
||
CreateEditor('EditorDiario', IEditorDiario, AEditor);
|
||
if Assigned(AEditor) then
|
||
with AEditor do
|
||
begin
|
||
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
||
Diario := ADiario;
|
||
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.FiltrarEjercicio(ADiario: IBizDiario);
|
||
var
|
||
Condicion: TDAWhereExpression;
|
||
begin
|
||
if ADiario.DataTable.Active then
|
||
ADiario.DataTable.Active := False;
|
||
|
||
// Filtrar los asientos por la empresa activa
|
||
with ADiario.DataTable.DynamicWhere do
|
||
begin
|
||
// (ID_EJERCICIO = ID)
|
||
Condicion := NewBinaryExpression(NewField('', fld_DiarioID_EJERCICIO), NewConstant(AppFactuGES.EjercicioActivo.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 not Assigned(AAsiento) then
|
||
raise Exception.Create ('Factura no asignada');
|
||
|
||
if ValidarAsiento(AAsiento) then
|
||
begin
|
||
ShowHourglassCursor;
|
||
|
||
// Asegurarnos de que todos los importes est<73>n bien.
|
||
// RecalcularImportes(AFactura);
|
||
|
||
try
|
||
AAsiento.DataTable.ApplyUpdates;
|
||
|
||
Result := True;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
end.
|