2007-12-03 11:13:39 +00:00
|
|
|
|
unit uAsientosController;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
Classes, SysUtils, uDADataTable, uControllerBase,
|
2007-12-12 19:48:05 +00:00
|
|
|
|
uBizAsientos, uBizDiario, uIDataModuleContabilidad;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
type
|
|
|
|
|
|
IAsientosController = interface(IObservador)
|
|
|
|
|
|
['{94E5F2B6-64C8-4331-B9CB-3ED730478529}']
|
2007-12-12 19:48:05 +00:00
|
|
|
|
function BuscarDiario: IBizDiario;
|
|
|
|
|
|
function Buscar(const ID: Integer): IBizAsiento;
|
|
|
|
|
|
procedure VerDiario(ADiario: IBizDiario);
|
2007-12-03 11:13:39 +00:00
|
|
|
|
procedure Ver(AAsiento: IBizAsiento);
|
2007-12-27 10:33:45 +00:00
|
|
|
|
function Anadir(NumOrden:Integer): IBizAsiento;
|
2007-12-10 18:42:52 +00:00
|
|
|
|
function Eliminar(AAsiento : IBizAsiento): Boolean;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
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;
|
2007-12-12 19:48:05 +00:00
|
|
|
|
procedure FiltrarEjercicio(ADiario: IBizDiario);
|
2007-12-03 11:13:39 +00:00
|
|
|
|
|
|
|
|
|
|
public
|
|
|
|
|
|
constructor Create; override;
|
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
|
|
|
|
|
|
function Eliminar(AAsiento : IBizAsiento): Boolean;
|
|
|
|
|
|
function Guardar(AAsiento : IBizAsiento): Boolean; virtual;
|
|
|
|
|
|
procedure DescartarCambios(AAsiento : IBizAsiento); virtual;
|
2007-12-27 10:33:45 +00:00
|
|
|
|
function Anadir(NumOrden:Integer): IBizAsiento;
|
2007-12-12 19:48:05 +00:00
|
|
|
|
function BuscarDiario: IBizDiario;
|
|
|
|
|
|
function Buscar(const ID: Integer): IBizAsiento;
|
|
|
|
|
|
procedure VerDiario(ADiario: IBizDiario);
|
2007-12-03 11:13:39 +00:00
|
|
|
|
procedure Ver(AAsiento: IBizAsiento);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
cxControls, DB, uEditorRegistryUtils, schContabilidadClient_Intf,
|
2007-12-12 19:48:05 +00:00
|
|
|
|
uIEditorDiario, uIEditorAsiento, uDataModuleContabilidad,
|
2007-12-03 11:13:39 +00:00
|
|
|
|
uDAInterfaces, uDataTableUtils, uDialogUtils, uFactuGES_App,
|
2007-12-12 19:48:05 +00:00
|
|
|
|
uDateUtils, uROTypes, DateUtils, Controls, Windows, uApuntesController;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
|
|
|
|
|
|
{ TAsientosController }
|
|
|
|
|
|
|
2007-12-27 10:33:45 +00:00
|
|
|
|
function TAsientosController.Anadir(NumOrden:Integer): IBizAsiento;
|
2007-12-12 19:48:05 +00:00
|
|
|
|
var
|
|
|
|
|
|
AAsiento : IBizAsiento;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
begin
|
2007-12-12 19:48:05 +00:00
|
|
|
|
AAsiento := FDataModule.GetAsientoItem(ID_NULO);
|
|
|
|
|
|
AAsiento.DataTable.Active := True;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
AAsiento.Insert;
|
2007-12-27 10:33:45 +00:00
|
|
|
|
AAsiento.ORDEN := NumOrden;
|
2007-12-12 19:48:05 +00:00
|
|
|
|
Result := AAsiento;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TAsientosController.AsignarDataModule;
|
|
|
|
|
|
begin
|
|
|
|
|
|
FDataModule := TDataModuleContabilidad.Create(Nil);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-12-12 19:48:05 +00:00
|
|
|
|
function TAsientosController.Buscar(const ID: Integer): IBizAsiento;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
begin
|
2007-12-12 19:48:05 +00:00
|
|
|
|
Result := FDataModule.GetAsientoItem(ID);
|
2007-12-03 11:13:39 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2007-12-12 19:48:05 +00:00
|
|
|
|
function TAsientosController.BuscarDiario: IBizDiario;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
begin
|
2007-12-12 19:48:05 +00:00
|
|
|
|
Result := FDataModule.GetDiarioItems;
|
|
|
|
|
|
FiltrarEjercicio(Result);
|
2007-12-03 11:13:39 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
2007-12-20 09:26:11 +00:00
|
|
|
|
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.');
|
|
|
|
|
|
|
2007-12-12 19:48:05 +00:00
|
|
|
|
//Tambien validamos los detalles del asiento
|
|
|
|
|
|
with TApuntesController.Create do
|
|
|
|
|
|
ValidarApunte(AAsiento.Apuntes);
|
|
|
|
|
|
|
2007-12-10 18:42:52 +00:00
|
|
|
|
// if Length(AAsiento.CONCEPTO) = 0 then
|
|
|
|
|
|
// raise Exception.Create('Debe indicar un concepto para este Asiento.');
|
2007-12-03 11:13:39 +00:00
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
2007-12-12 19:48:05 +00:00
|
|
|
|
procedure TAsientosController.VerDiario(ADiario: IBizDiario);
|
2007-12-03 11:13:39 +00:00
|
|
|
|
var
|
2007-12-12 19:48:05 +00:00
|
|
|
|
AEditor : IEditorDiario;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
begin
|
|
|
|
|
|
AEditor := NIL;
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
2007-12-12 19:48:05 +00:00
|
|
|
|
CreateEditor('EditorDiario', IEditorDiario, AEditor);
|
2007-12-03 11:13:39 +00:00
|
|
|
|
if Assigned(AEditor) then
|
|
|
|
|
|
with AEditor do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
2007-12-12 19:48:05 +00:00
|
|
|
|
Diario := ADiario;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
2007-12-12 19:48:05 +00:00
|
|
|
|
procedure TAsientosController.FiltrarEjercicio(ADiario: IBizDiario);
|
2007-12-03 11:13:39 +00:00
|
|
|
|
var
|
|
|
|
|
|
Condicion: TDAWhereExpression;
|
|
|
|
|
|
begin
|
2007-12-12 19:48:05 +00:00
|
|
|
|
if ADiario.DataTable.Active then
|
|
|
|
|
|
ADiario.DataTable.Active := False;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
|
2008-01-28 08:43:23 +00:00
|
|
|
|
if not Assigned(AppFactuGES.EjercicioActivo) then
|
|
|
|
|
|
raise Exception.Create('No se ha definido ning<6E>n ejercicio activo');
|
|
|
|
|
|
|
2007-12-12 19:48:05 +00:00
|
|
|
|
// Filtrar los asientos por la empresa activa
|
|
|
|
|
|
with ADiario.DataTable.DynamicWhere do
|
2007-12-03 11:13:39 +00:00
|
|
|
|
begin
|
2007-12-12 19:48:05 +00:00
|
|
|
|
// (ID_EJERCICIO = ID)
|
|
|
|
|
|
Condicion := NewBinaryExpression(NewField('', fld_DiarioID_EJERCICIO), NewConstant(AppFactuGES.EjercicioActivo.ID, datInteger), dboEqual);
|
2007-12-03 11:13:39 +00:00
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
2007-12-12 19:48:05 +00:00
|
|
|
|
if not Assigned(AAsiento) then
|
|
|
|
|
|
raise Exception.Create ('Factura no asignada');
|
|
|
|
|
|
|
2007-12-03 11:13:39 +00:00
|
|
|
|
if ValidarAsiento(AAsiento) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
ShowHourglassCursor;
|
2007-12-12 19:48:05 +00:00
|
|
|
|
|
|
|
|
|
|
// Asegurarnos de que todos los importes est<73>n bien.
|
|
|
|
|
|
// RecalcularImportes(AFactura);
|
|
|
|
|
|
|
2007-12-03 11:13:39 +00:00
|
|
|
|
try
|
|
|
|
|
|
AAsiento.DataTable.ApplyUpdates;
|
2007-12-12 19:48:05 +00:00
|
|
|
|
|
2007-12-03 11:13:39 +00:00
|
|
|
|
Result := True;
|
|
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end.
|