2007-11-16 20:58:56 +00:00
|
|
|
|
unit uReferenciasController;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
Classes, SysUtils, uDADataTable, uControllerBase,
|
|
|
|
|
|
uIDataModuleReferencias, uBizReferencias;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
2008-08-22 12:19:25 +00:00
|
|
|
|
IReferenciasController = interface(IControllerBase)
|
2007-11-16 20:58:56 +00:00
|
|
|
|
['{832E33B0-3228-4519-A740-F551DF3004DD}']
|
|
|
|
|
|
function BuscarTodos: IBizReferencia;
|
|
|
|
|
|
procedure VerTodos(AReferencias: IBizReferencia);
|
|
|
|
|
|
function Guardar(AReferencia : IBizReferencia): Boolean;
|
|
|
|
|
|
procedure DescartarCambios(AReferencia : IBizReferencia);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2008-08-22 12:19:25 +00:00
|
|
|
|
TReferenciasController = class(TControllerBase, IReferenciasController)
|
2007-11-16 20:58:56 +00:00
|
|
|
|
protected
|
|
|
|
|
|
FDataModule : IDataModuleReferencias;
|
2008-02-07 10:13:37 +00:00
|
|
|
|
// procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override;
|
2007-11-16 20:58:56 +00:00
|
|
|
|
function CreateEditor(const AName : String; const IID: TGUID; out Intf): Boolean;
|
|
|
|
|
|
|
|
|
|
|
|
function ValidarReferencia(AReferencia: IBizReferencia): Boolean;
|
|
|
|
|
|
procedure AsignarDataModule;
|
2008-10-07 15:20:08 +00:00
|
|
|
|
procedure FiltrarEmpresa(AReferencias: IBizReferencia);
|
2007-11-16 20:58:56 +00:00
|
|
|
|
public
|
2007-11-22 19:09:07 +00:00
|
|
|
|
constructor Create; override;
|
2007-11-16 20:58:56 +00:00
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
|
|
|
|
|
|
function Guardar(AReferencia : IBizReferencia): Boolean; virtual;
|
|
|
|
|
|
procedure DescartarCambios(AReferencia : IBizReferencia); virtual;
|
|
|
|
|
|
function BuscarTodos: IBizReferencia;
|
|
|
|
|
|
procedure VerTodos(AReferencias: IBizReferencia);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
cxControls, DB, uEditorRegistryUtils, schReferenciasClient_Intf,
|
2008-10-07 15:20:08 +00:00
|
|
|
|
uIEditorReferencias, uDataModuleReferencias, uFactuGES_App,
|
2007-11-16 20:58:56 +00:00
|
|
|
|
uDAInterfaces, uDataTableUtils, uDialogUtils,
|
|
|
|
|
|
uDateUtils, uROTypes, DateUtils, Controls, Windows;
|
|
|
|
|
|
|
|
|
|
|
|
{ TReferenciasController }
|
|
|
|
|
|
|
|
|
|
|
|
procedure TReferenciasController.AsignarDataModule;
|
|
|
|
|
|
begin
|
|
|
|
|
|
FDataModule := TDataModuleReferencias.Create(Nil);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TReferenciasController.BuscarTodos: IBizReferencia;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := FDataModule.GetItems;
|
2008-10-07 15:20:08 +00:00
|
|
|
|
FiltrarEmpresa(Result);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TReferenciasController.FiltrarEmpresa(AReferencias: IBizReferencia);
|
|
|
|
|
|
var
|
|
|
|
|
|
Condicion: TDAWhereExpression;
|
2010-02-11 10:15:07 +00:00
|
|
|
|
Condicion1: TDAWhereExpression;
|
|
|
|
|
|
Condicion2: TDAWhereExpression;
|
2008-10-07 15:20:08 +00:00
|
|
|
|
begin
|
|
|
|
|
|
if AReferencias.DataTable.Active then
|
|
|
|
|
|
AReferencias.DataTable.Active := False;
|
|
|
|
|
|
|
|
|
|
|
|
// Filtrar las facturas actuales por empresa
|
|
|
|
|
|
with AReferencias.DataTable.DynamicWhere do
|
|
|
|
|
|
begin
|
2010-02-11 10:15:07 +00:00
|
|
|
|
// (ID_EMPRESA = ID)
|
|
|
|
|
|
Condicion1 := NewBinaryExpression(NewField('', fld_ReferenciasID_EMPRESA),
|
2008-10-07 15:20:08 +00:00
|
|
|
|
NewConstant(AppFactuGES.EmpresaActiva.ID, datInteger), dboEqual);
|
2010-02-11 10:15:07 +00:00
|
|
|
|
// (ID_EMPRESA = NULL)
|
|
|
|
|
|
Condicion2 := NewBinaryExpression(NewField('', 'ID_EMPRESA'), NewConstant(ID_NULO, datInteger), dboEqual);
|
|
|
|
|
|
|
|
|
|
|
|
Condicion := NewBinaryExpression(Condicion1, Condicion2, dboOr);
|
2008-10-07 15:20:08 +00:00
|
|
|
|
|
|
|
|
|
|
if IsEmpty then
|
|
|
|
|
|
Expression := Condicion
|
|
|
|
|
|
else
|
|
|
|
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
|
|
|
|
|
end;
|
2007-11-16 20:58:56 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
constructor TReferenciasController.Create;
|
|
|
|
|
|
begin
|
2007-11-22 19:09:07 +00:00
|
|
|
|
inherited;
|
2007-11-16 20:58:56 +00:00
|
|
|
|
AsignarDataModule;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TReferenciasController.CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TReferenciasController.DescartarCambios(AReferencia: IBizReferencia);
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AReferencia) then
|
|
|
|
|
|
raise Exception.Create ('Forma de pago no asignada');
|
|
|
|
|
|
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
|
|
|
|
|
if (AReferencia.State in dsEditModes) then
|
|
|
|
|
|
AReferencia.Cancel;
|
|
|
|
|
|
|
|
|
|
|
|
AReferencia.DataTable.CancelUpdates;
|
|
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TReferenciasController.Destroy;
|
|
|
|
|
|
begin
|
|
|
|
|
|
FDataModule := NIL;
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TReferenciasController.ValidarReferencia(AReferencia: IBizReferencia): Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
|
|
|
|
if not Assigned(AReferencia) then
|
|
|
|
|
|
raise Exception.Create ('Referencia no asignada');
|
|
|
|
|
|
|
|
|
|
|
|
if (AReferencia.DataTable.State in dsEditModes) then
|
|
|
|
|
|
AReferencia.DataTable.Post;
|
|
|
|
|
|
|
|
|
|
|
|
// if Length(AReferencia.VALOR) = 0 then
|
|
|
|
|
|
// raise Exception.Create('Debe indicar un c<>digo para esta referencia.');
|
|
|
|
|
|
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TReferenciasController.VerTodos(AReferencias: IBizReferencia);
|
|
|
|
|
|
var
|
|
|
|
|
|
AEditor : IEditorReferencias;
|
|
|
|
|
|
begin
|
2008-11-11 16:22:18 +00:00
|
|
|
|
CreateEditor('EditorReferencias', IEditorReferencias, AEditor);
|
|
|
|
|
|
if Assigned(AEditor) then
|
2008-11-13 13:10:32 +00:00
|
|
|
|
try
|
|
|
|
|
|
AEditor.Referencias := AReferencias;
|
|
|
|
|
|
AEditor.ShowModal;
|
|
|
|
|
|
finally
|
|
|
|
|
|
AEditor.Release;
|
|
|
|
|
|
AEditor := NIL;
|
|
|
|
|
|
end;
|
2007-11-16 20:58:56 +00:00
|
|
|
|
end;
|
2008-02-07 10:13:37 +00:00
|
|
|
|
{
|
2007-11-16 20:58:56 +00:00
|
|
|
|
procedure TReferenciasController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable);
|
|
|
|
|
|
begin
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
//
|
|
|
|
|
|
end;
|
2008-02-07 10:13:37 +00:00
|
|
|
|
}
|
2007-11-16 20:58:56 +00:00
|
|
|
|
|
|
|
|
|
|
function TReferenciasController.Guardar(AReferencia: IBizReferencia): Boolean;
|
|
|
|
|
|
var
|
|
|
|
|
|
NuevoID : Integer;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
|
|
|
|
if ValidarReferencia(AReferencia) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
|
|
|
|
|
AReferencia.DataTable.ApplyUpdates;
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
2008-02-07 10:13:37 +00:00
|
|
|
|
|
2007-11-16 20:58:56 +00:00
|
|
|
|
end.
|