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
|
2008-07-14 14:35:47 +00:00
|
|
|
|
IAsientosController = interface(IControllerBase)
|
2007-12-03 11:13:39 +00:00
|
|
|
|
['{94E5F2B6-64C8-4331-B9CB-3ED730478529}']
|
2008-05-12 16:41:52 +00:00
|
|
|
|
function BuscarAsientos(IdSubCuenta: Integer = -1): IBizDiario;
|
2007-12-12 19:48:05 +00:00
|
|
|
|
function Buscar(const ID: Integer): IBizAsiento;
|
|
|
|
|
|
procedure VerDiario(ADiario: IBizDiario);
|
2008-05-12 16:41:52 +00:00
|
|
|
|
procedure VerExtracto;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
procedure Ver(AAsiento: IBizAsiento);
|
2008-05-12 16:41:52 +00:00
|
|
|
|
function Anadir: IBizAsiento; overload;
|
|
|
|
|
|
function Anadir(IdSubcuenta:Integer): IBizAsiento; overload;
|
|
|
|
|
|
function CerrarCajaBanco(IdSubcuenta:Integer): Boolean;
|
2008-04-02 10:56:24 +00:00
|
|
|
|
function Eliminar(IDAsiento : Integer): Boolean; overload;
|
|
|
|
|
|
function Eliminar(AAsiento : IBizAsiento): Boolean; overload;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
function Guardar(AAsiento : IBizAsiento): Boolean;
|
|
|
|
|
|
procedure DescartarCambios(AAsiento : IBizAsiento);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2008-07-14 14:35:47 +00:00
|
|
|
|
TAsientosController = class(TControllerBase, IAsientosController)
|
2007-12-03 11:13:39 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
2008-05-12 16:41:52 +00:00
|
|
|
|
function BuscarAsientos(IdSubCuenta: Integer = -1): IBizDiario;
|
|
|
|
|
|
|
2008-04-02 10:56:24 +00:00
|
|
|
|
function Eliminar(IDAsiento : Integer): Boolean; overload;
|
|
|
|
|
|
function Eliminar(AAsiento : IBizAsiento): Boolean; overload;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
function Guardar(AAsiento : IBizAsiento): Boolean; virtual;
|
|
|
|
|
|
procedure DescartarCambios(AAsiento : IBizAsiento); virtual;
|
2008-05-12 16:41:52 +00:00
|
|
|
|
function Anadir: IBizAsiento; overload;
|
|
|
|
|
|
function Anadir(IdSubcuenta:Integer): IBizAsiento; overload;
|
|
|
|
|
|
function CerrarCajaBanco(IdSubcuenta:Integer): Boolean;
|
|
|
|
|
|
|
2007-12-12 19:48:05 +00:00
|
|
|
|
function Buscar(const ID: Integer): IBizAsiento;
|
|
|
|
|
|
procedure VerDiario(ADiario: IBizDiario);
|
2008-05-12 16:41:52 +00:00
|
|
|
|
procedure VerExtracto;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
procedure Ver(AAsiento: IBizAsiento);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
cxControls, DB, uEditorRegistryUtils, schContabilidadClient_Intf,
|
2008-05-12 16:41:52 +00:00
|
|
|
|
uIEditorDiario, uIEditorExtractoMovimientos, uIEditorAsiento,
|
|
|
|
|
|
uDataModuleContabilidad, uDAInterfaces, uDataTableUtils, uDialogUtils,
|
|
|
|
|
|
uFactuGES_App, uDateUtils, uROTypes, DateUtils, Controls, Windows,
|
|
|
|
|
|
uApuntesController;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
|
|
|
|
|
|
{ TAsientosController }
|
|
|
|
|
|
|
2008-05-12 16:41:52 +00:00
|
|
|
|
function TAsientosController.Anadir: 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-12 19:48:05 +00:00
|
|
|
|
Result := AAsiento;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2008-05-12 16:41:52 +00:00
|
|
|
|
function TAsientosController.Anadir(IdSubcuenta: Integer): IBizAsiento;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := Anadir;
|
|
|
|
|
|
|
|
|
|
|
|
//Creamos el primer apunte del asiento con la cuenta pasada por parametro
|
|
|
|
|
|
with TApuntesController.Create do
|
|
|
|
|
|
try
|
|
|
|
|
|
Anadir(Result.Apuntes, IdSubcuenta);
|
|
|
|
|
|
finally
|
|
|
|
|
|
Free;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-12-03 11:13:39 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
2008-05-12 16:41:52 +00:00
|
|
|
|
function TAsientosController.BuscarAsientos(IdSubCuenta: Integer = -1): IBizDiario;
|
|
|
|
|
|
var
|
|
|
|
|
|
Condicion: TDAWhereExpression;
|
|
|
|
|
|
|
2007-12-03 11:13:39 +00:00
|
|
|
|
begin
|
2008-05-12 16:41:52 +00:00
|
|
|
|
// En el caso de no definir cuenta lo que queremos es el diario
|
|
|
|
|
|
if (IdSubcuenta < 0) then
|
|
|
|
|
|
Result := FDataModule.GetAsientosDiarioItems
|
|
|
|
|
|
// En el caso de querer solo los movimientos de una cuenta lo que queremos es un extracto de movimientos
|
|
|
|
|
|
else
|
|
|
|
|
|
Result := FDataModule.GetExtractoMovimientosItems;
|
|
|
|
|
|
|
|
|
|
|
|
//Filtramos por empresa
|
2007-12-12 19:48:05 +00:00
|
|
|
|
FiltrarEjercicio(Result);
|
2008-05-12 16:41:52 +00:00
|
|
|
|
|
|
|
|
|
|
// Filtrar los asientos por la subcuenta elegida
|
|
|
|
|
|
if (IdSubcuenta > 0) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
if Result.DataTable.Active then
|
|
|
|
|
|
Result.DataTable.Active := False;
|
|
|
|
|
|
|
|
|
|
|
|
with Result.DataTable.DynamicWhere do
|
|
|
|
|
|
begin
|
|
|
|
|
|
// (ID_SUBCUENTA = IdSubcuenta)
|
|
|
|
|
|
Condicion := NewBinaryExpression(NewField('', fld_DiarioID_SUBCUENTA), NewConstant(IdSubCuenta, datInteger), dboEqual);
|
|
|
|
|
|
|
|
|
|
|
|
if IsEmpty then
|
|
|
|
|
|
Expression := Condicion
|
|
|
|
|
|
else
|
|
|
|
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TAsientosController.CerrarCajaBanco(IdSubcuenta: Integer): Boolean;
|
|
|
|
|
|
var
|
|
|
|
|
|
AAsiento: IBizAsiento;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AAsiento:= Anadir(IdSubCuenta);
|
|
|
|
|
|
try
|
|
|
|
|
|
AAsiento.TIPO := 'X'; //CIERRE DE CAJA
|
|
|
|
|
|
AAsiento.Post;
|
|
|
|
|
|
|
|
|
|
|
|
//Creamos el primer apunte del asiento con la cuenta pasada por parametro
|
|
|
|
|
|
with TApuntesController.Create do
|
|
|
|
|
|
try
|
|
|
|
|
|
AnadirCierre(AAsiento.Apuntes);
|
|
|
|
|
|
finally
|
|
|
|
|
|
Free;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
Guardar(AAsiento);
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
|
|
|
|
|
|
finally
|
|
|
|
|
|
AAsiento := Nil;
|
|
|
|
|
|
end;
|
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;
|
|
|
|
|
|
|
2008-04-02 10:56:24 +00:00
|
|
|
|
function TAsientosController.Eliminar(IDAsiento: Integer): Boolean;
|
|
|
|
|
|
var
|
|
|
|
|
|
AAsiento : IBizAsiento;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AAsiento := Buscar(IDAsiento);
|
|
|
|
|
|
AAsiento.DataTable.Active := True;
|
|
|
|
|
|
|
|
|
|
|
|
if not Assigned(AAsiento) then
|
|
|
|
|
|
raise Exception.Create(Format('No se ha encontrado el asiento con ID = %d', [IDAsiento]));
|
|
|
|
|
|
|
|
|
|
|
|
Result := Eliminar(AAsiento);
|
|
|
|
|
|
AAsiento := NIL;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-12-03 11:13:39 +00:00
|
|
|
|
function TAsientosController.ValidarAsiento(AAsiento: IBizAsiento): Boolean;
|
|
|
|
|
|
begin
|
2008-07-31 10:10:52 +00:00
|
|
|
|
Result := False;
|
|
|
|
|
|
|
2007-12-03 11:13:39 +00:00
|
|
|
|
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.');
|
|
|
|
|
|
|
2008-05-12 16:41:52 +00:00
|
|
|
|
// if AAsiento.ORDENIsNull then
|
|
|
|
|
|
// raise Exception.Create('Debe indicar un n<>mero de orden para este Asiento.');
|
2007-12-20 09:26:11 +00:00
|
|
|
|
|
2007-12-12 19:48:05 +00:00
|
|
|
|
//Tambien validamos los detalles del asiento
|
|
|
|
|
|
with TApuntesController.Create do
|
2008-05-12 16:41:52 +00:00
|
|
|
|
begin
|
|
|
|
|
|
ValidarApunte(AAsiento.Apuntes);
|
|
|
|
|
|
Free;
|
|
|
|
|
|
end;
|
2007-12-12 19:48:05 +00:00
|
|
|
|
|
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;
|
2008-11-11 18:52:28 +00:00
|
|
|
|
|
|
|
|
|
|
CreateEditor('EditorAsiento', IEditorAsiento, AEditor);
|
|
|
|
|
|
if Assigned(AEditor) then
|
|
|
|
|
|
with AEditor do
|
|
|
|
|
|
begin
|
|
|
|
|
|
try
|
|
|
|
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|
|
|
|
|
Asiento := AAsiento;
|
|
|
|
|
|
ShowModal;
|
|
|
|
|
|
finally
|
|
|
|
|
|
Release;
|
|
|
|
|
|
AEditor := NIL;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
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;
|
2008-11-11 18:52:28 +00:00
|
|
|
|
|
|
|
|
|
|
CreateEditor('EditorDiario', IEditorDiario, AEditor);
|
|
|
|
|
|
if Assigned(AEditor) then
|
|
|
|
|
|
with AEditor do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|
|
|
|
|
Diario := ADiario;
|
|
|
|
|
|
ShowEmbedded;
|
|
|
|
|
|
end;
|
2007-12-03 11:13:39 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2008-05-12 16:41:52 +00:00
|
|
|
|
procedure TAsientosController.VerExtracto;
|
|
|
|
|
|
var
|
|
|
|
|
|
AEditor : IEditorExtractoMovimientos;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AEditor := NIL;
|
2008-11-11 18:52:28 +00:00
|
|
|
|
|
|
|
|
|
|
CreateEditor('EditorExtractoMovimientos', IEditorExtractoMovimientos, AEditor);
|
|
|
|
|
|
if Assigned(AEditor) then
|
|
|
|
|
|
with AEditor do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|
|
|
|
|
//En este caso el objeto de negocio recae sobre la vista
|
|
|
|
|
|
ShowEmbedded;
|
|
|
|
|
|
end;
|
2008-05-12 16:41:52 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2007-12-03 11:13:39 +00:00
|
|
|
|
function TAsientosController.Eliminar(AAsiento: IBizAsiento): Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
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.
|