587 lines
18 KiB
ObjectPascal
587 lines
18 KiB
ObjectPascal
|
|
unit uPresupuestosController;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Classes, SysUtils, uDADataTable,
|
|||
|
|
uControllerBase, uIDataModulePresupuestos, uClientesController,
|
|||
|
|
uDetallesPresupuestoController, uBizPresupuestos;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
IPresupuestosController = interface(IObservador)
|
|||
|
|
['{051B0128-B234-4B80-B1F0-056CD61F9E3A}']
|
|||
|
|
function GetClienteController: IClientesController;
|
|||
|
|
procedure SetClienteController(const Value: IClientesController);
|
|||
|
|
property ClienteController: IClientesController read GetClienteController write SetClienteController;
|
|||
|
|
|
|||
|
|
function GetDetallesController: IDetallesPresupuestoController;
|
|||
|
|
procedure SetDetallesController(const Value: IDetallesPresupuestoController);
|
|||
|
|
property DetallesController: IDetallesPresupuestoController read GetDetallesController write SetDetallesController;
|
|||
|
|
|
|||
|
|
function Buscar(const ID: Integer): IBizPresupuesto;
|
|||
|
|
function BuscarTodos: IBizPresupuesto;
|
|||
|
|
procedure Ver(APresupuesto : IBizPresupuesto);
|
|||
|
|
procedure VerTodos(APresupuestos: IBizPresupuesto);
|
|||
|
|
function Nuevo : IBizPresupuesto;
|
|||
|
|
procedure Anadir(APresupuesto : IBizPresupuesto);
|
|||
|
|
procedure Eliminar(const ID : Integer); overload;
|
|||
|
|
procedure Eliminar(APresupuesto : IBizPresupuesto); overload;
|
|||
|
|
procedure Guardar(APresupuesto : IBizPresupuesto);
|
|||
|
|
procedure DescartarCambios(APresupuesto : IBizPresupuesto);
|
|||
|
|
function Existe(const ID: Integer) : Boolean;
|
|||
|
|
procedure RecuperarCliente(APresupuesto: IBizPresupuesto);
|
|||
|
|
function Duplicar(APresupuesto: IBizPresupuesto): IBizPresupuesto;
|
|||
|
|
function CambiarSituacion(APresupuesto: IBizPresupuesto; ASituacion : String; AFechaDecision: TDateTime = 0; DoPost: Boolean = True): Boolean; overload;
|
|||
|
|
function CambiarSituacion(APresupuesto: IBizPresupuesto): Boolean; overload;
|
|||
|
|
procedure Preview(APresupuesto : IBizPresupuesto);
|
|||
|
|
procedure Print(APresupuesto : IBizPresupuesto);
|
|||
|
|
|
|||
|
|
function ElegirPresupuesto(APresupuestos : IBizPresupuesto; AMensaje: String; AMultiSelect: Boolean): IBizPresupuesto;
|
|||
|
|
function ExtraerSeleccionados(APresupuestos: IBizPresupuesto) : IBizPresupuesto;
|
|||
|
|
|
|||
|
|
function BuscarSinMontaje: IBizPresupuesto;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
TPresupuestosController = class(TObservador, IPresupuestosController)
|
|||
|
|
private
|
|||
|
|
FDataModule : IDataModulePresupuestos;
|
|||
|
|
FClienteController : IClientesController;
|
|||
|
|
FDetallesController : IDetallesPresupuestoController;
|
|||
|
|
|
|||
|
|
function GetClienteController: IClientesController;
|
|||
|
|
procedure SetClienteController(const Value: IClientesController);
|
|||
|
|
|
|||
|
|
function GetDetallesController: IDetallesPresupuestoController;
|
|||
|
|
procedure SetDetallesController(const Value: IDetallesPresupuestoController);
|
|||
|
|
|
|||
|
|
procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override;
|
|||
|
|
procedure AsignarID(APresupuesto: IBizPresupuesto; const NuevoID:Integer);
|
|||
|
|
function CreateEditor(const AName : String; const IID: TGUID; out Intf): Boolean;
|
|||
|
|
procedure FiltrarEmpresa(APresupuestos: IBizPresupuesto);
|
|||
|
|
|
|||
|
|
function ValidarPresupuesto(APresupuesto: IBizPresupuesto): Boolean;
|
|||
|
|
function ValidarSituacion(ASituacion: String; AFechaPresupuesto: TDateTime;
|
|||
|
|
var AFechaDecision: TDateTime): Boolean;
|
|||
|
|
function _Vacio : IBizPresupuesto;
|
|||
|
|
public
|
|||
|
|
property ClienteController: IClientesController read GetClienteController write SetClienteController;
|
|||
|
|
property DetallesController: IDetallesPresupuestoController read GetDetallesController write SetDetallesController;
|
|||
|
|
|
|||
|
|
constructor Create;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
|
|||
|
|
procedure Eliminar(const ID : Integer); overload;
|
|||
|
|
procedure Eliminar(APresupuesto : IBizPresupuesto); overload;
|
|||
|
|
procedure Guardar(APresupuesto : IBizPresupuesto);
|
|||
|
|
procedure DescartarCambios(APresupuesto : IBizPresupuesto);
|
|||
|
|
function Existe(const ID: Integer) : Boolean;
|
|||
|
|
procedure Anadir(APresupuesto : IBizPresupuesto);
|
|||
|
|
function Buscar(const ID: Integer): IBizPresupuesto;
|
|||
|
|
function BuscarTodos: IBizPresupuesto;
|
|||
|
|
function Nuevo : IBizPresupuesto;
|
|||
|
|
procedure Ver(APresupuesto : IBizPresupuesto);
|
|||
|
|
procedure VerTodos(APresupuestos: IBizPresupuesto);
|
|||
|
|
procedure RecuperarCliente(APresupuesto: IBizPresupuesto);
|
|||
|
|
function Duplicar(APresupuesto: IBizPresupuesto): IBizPresupuesto;
|
|||
|
|
function CambiarSituacion(APresupuesto: IBizPresupuesto; ASituacion : String; AFechaDecision: TDateTime = 0; DoPost: Boolean = True): Boolean; overload;
|
|||
|
|
function CambiarSituacion(APresupuesto: IBizPresupuesto): Boolean; overload;
|
|||
|
|
procedure Preview(APresupuesto : IBizPresupuesto);
|
|||
|
|
procedure Print(APresupuesto : IBizPresupuesto);
|
|||
|
|
|
|||
|
|
function ElegirPresupuesto(APresupuestos : IBizPresupuesto; AMensaje: String; AMultiSelect: Boolean): IBizPresupuesto;
|
|||
|
|
function ExtraerSeleccionados(APresupuestos: IBizPresupuesto) : IBizPresupuesto;
|
|||
|
|
|
|||
|
|
function BuscarSinMontaje: IBizPresupuesto;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Controls, cxControls, DB, uEditorRegistryUtils, schPresupuestosClient_Intf,
|
|||
|
|
uDataModulePresupuestos, uIEditorPresupuestos, uIEditorPresupuesto,
|
|||
|
|
uDAInterfaces, uDataTableUtils, Dialogs, uDataModuleUsuarios, Variants,
|
|||
|
|
uBizDetallesPresupuesto, uControllerDetallesBase, uBizContactos, DateUtils,
|
|||
|
|
uIEditorSituacionPresupuesto, uDateUtils, uPresupuestosReportController,
|
|||
|
|
uIEditorElegirPresupuestos;
|
|||
|
|
|
|||
|
|
{ TPresupuestosController }
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.Anadir(APresupuesto: IBizPresupuesto);
|
|||
|
|
begin
|
|||
|
|
APresupuesto.Insert;
|
|||
|
|
APresupuesto.Cliente := (FClienteController.Nuevo as IBizCliente);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.AsignarID(APresupuesto: IBizPresupuesto; const NuevoID:Integer);
|
|||
|
|
begin
|
|||
|
|
if not Assigned(APresupuesto) then
|
|||
|
|
raise Exception.Create ('Presupuesto no asignado');
|
|||
|
|
|
|||
|
|
if not Assigned(FDetallesController) then
|
|||
|
|
raise Exception.Create ('Controller detalles no asignado');
|
|||
|
|
|
|||
|
|
{ <EFBFBD><EFBFBD><EFBFBD> OJO !!!
|
|||
|
|
Primero cambiamos el ID de las tablas detalles
|
|||
|
|
porque si cambiamos antes el ID de la cabecera
|
|||
|
|
deja de funcionar la relacion M/D y no
|
|||
|
|
encontrar<EFBFBD>amos las filas detalle.
|
|||
|
|
|
|||
|
|
--> MASTER.ID = DETAIL.ID_PRESUPUESTO <--
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
FDetallesController.AsignarID(APresupuesto.Detalles, NuevoID, APresupuesto.EsNuevo);
|
|||
|
|
|
|||
|
|
if APresupuesto.EsNuevo then
|
|||
|
|
begin
|
|||
|
|
APresupuesto.Edit;
|
|||
|
|
APresupuesto.ID := NuevoID;
|
|||
|
|
APresupuesto.Post;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.Buscar(const ID: Integer): IBizPresupuesto;
|
|||
|
|
begin
|
|||
|
|
Result := (FDataModule as IDataModulePresupuestos).GetItem(ID);
|
|||
|
|
FiltrarEmpresa(Result);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.BuscarSinMontaje: IBizPresupuesto;
|
|||
|
|
begin
|
|||
|
|
Result := BuscarTodos;
|
|||
|
|
|
|||
|
|
// Filtrar los presupuestos que ya tienen montaje asociado
|
|||
|
|
with Result.DataTable.Where do
|
|||
|
|
begin
|
|||
|
|
if NotEmpty then
|
|||
|
|
AddOperator(opAND);
|
|||
|
|
OpenBraket;
|
|||
|
|
AddText('MONTAJES.ID is null');
|
|||
|
|
CloseBraket;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.BuscarTodos: IBizPresupuesto;
|
|||
|
|
begin
|
|||
|
|
Result := FDataModule.GetItems;
|
|||
|
|
FiltrarEmpresa(Result);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.CambiarSituacion(APresupuesto: IBizPresupuesto): Boolean;
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorSituacionPresupuesto;
|
|||
|
|
begin
|
|||
|
|
AEditor := NIL;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
RecuperarCliente(APresupuesto);
|
|||
|
|
CreateEditor('EditorSituacionPresupuesto', IEditorSituacionPresupuesto, AEditor);
|
|||
|
|
with AEditor do
|
|||
|
|
begin
|
|||
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|||
|
|
Presupuesto := APresupuesto;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if Assigned(AEditor) then
|
|||
|
|
AEditor.ShowModal;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.CambiarSituacion(APresupuesto: IBizPresupuesto;
|
|||
|
|
ASituacion: String; AFechaDecision: TDateTime; DoPost: Boolean): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
// Validar la situaci<63>n del presupuesto
|
|||
|
|
if ValidarSituacion(ASituacion, APresupuesto.FECHA_PRESUPUESTO, AFechaDecision) then
|
|||
|
|
begin
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
APresupuesto.DataTable.DisableControls;
|
|||
|
|
try
|
|||
|
|
APresupuesto.Edit;
|
|||
|
|
APresupuesto.SITUACION := ASituacion;
|
|||
|
|
if AFechaDecision <> APresupuesto.FECHA_DECISION then
|
|||
|
|
APresupuesto.FECHA_DECISION := AFechaDecision;
|
|||
|
|
APresupuesto.Post;
|
|||
|
|
if DoPost then
|
|||
|
|
Guardar(APresupuesto);
|
|||
|
|
Result := True;
|
|||
|
|
finally
|
|||
|
|
APresupuesto.DataTable.EnableControls;
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
constructor TPresupuestosController.Create;
|
|||
|
|
begin
|
|||
|
|
FDataModule := TDataModulePresupuestos.Create(Nil);
|
|||
|
|
FClienteController := TClientesController.Create;
|
|||
|
|
FDetallesController := TDetallesPresupuestoController.Create;
|
|||
|
|
FDetallesController.addObservador(Self);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.CreateEditor(const AName: String;
|
|||
|
|
const IID: TGUID; out Intf): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.DescartarCambios(APresupuesto: IBizPresupuesto);
|
|||
|
|
begin
|
|||
|
|
if not Assigned(APresupuesto) then
|
|||
|
|
raise Exception.Create ('Presupuesto no asignado');
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
if (APresupuesto.State in dsEditModes) then
|
|||
|
|
APresupuesto.Cancel;
|
|||
|
|
|
|||
|
|
APresupuesto.DataTable.CancelUpdates;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TPresupuestosController.Destroy;
|
|||
|
|
begin
|
|||
|
|
FDataModule := Nil;
|
|||
|
|
FClienteController := Nil;
|
|||
|
|
FDetallesController := Nil;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.Duplicar(
|
|||
|
|
APresupuesto: IBizPresupuesto): IBizPresupuesto;
|
|||
|
|
begin
|
|||
|
|
Result := Self._Vacio;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
DuplicarRegistros(APresupuesto.DataTable, Result.DataTable, mdrActual);
|
|||
|
|
DuplicarRegistros(APresupuesto.Detalles.DataTable, Result.Detalles.DataTable, mdrTodos);
|
|||
|
|
|
|||
|
|
// Hay que dejar algunos campos como si fuera un presupuesto nuevo
|
|||
|
|
Result.Edit;
|
|||
|
|
with Result do
|
|||
|
|
begin
|
|||
|
|
ID_EMPRESA := dmUsuarios.IDEmpresaActual;
|
|||
|
|
USUARIO := dmUsuarios.LoginInfo.Usuario;
|
|||
|
|
REFERENCIA := ''; //Para que se le asigne una nueva
|
|||
|
|
FECHA_PRESUPUESTO := DateOf(Now);
|
|||
|
|
SITUACION := SITUACION_PENDIENTE;
|
|||
|
|
FECHA_DECISION := 0;
|
|||
|
|
end;
|
|||
|
|
Result.Post;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
|
|||
|
|
function TPresupuestosController.ValidarPresupuesto(APresupuesto: IBizPresupuesto): Boolean;
|
|||
|
|
var
|
|||
|
|
AFechaDecision : TDateTime;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
if not Assigned(APresupuesto) then
|
|||
|
|
raise Exception.Create ('Presupuesto no asignado');
|
|||
|
|
|
|||
|
|
if not Assigned(FDetallesController) then
|
|||
|
|
raise Exception.Create ('Controller detalles no asignado');
|
|||
|
|
|
|||
|
|
if (APresupuesto.DataTable.State in dsEditModes) then
|
|||
|
|
APresupuesto.DataTable.Post;
|
|||
|
|
|
|||
|
|
//Tambien hacemos post de sus tablas hija
|
|||
|
|
if (APresupuesto.Detalles.DataTable.State in dsEditModes) then
|
|||
|
|
APresupuesto.Detalles.DataTable.Post;
|
|||
|
|
|
|||
|
|
//VALIDACION
|
|||
|
|
if (APresupuesto.ID_CLIENTE < 0) or
|
|||
|
|
(not Assigned(APresupuesto.Cliente)) or
|
|||
|
|
(APresupuesto.Cliente.IsEmpty) then
|
|||
|
|
raise Exception.Create('Debe indicar el cliente de este presupuesto');
|
|||
|
|
|
|||
|
|
if (EsFechaVacia(APresupuesto.FECHA_PRESUPUESTO)) then
|
|||
|
|
raise Exception.Create('Debe indicar la fecha de este presupuesto');
|
|||
|
|
|
|||
|
|
// Validar la situaci<63>n del presupuesto
|
|||
|
|
AFechaDecision := APresupuesto.FECHA_DECISION;
|
|||
|
|
if not ValidarSituacion(APresupuesto.SITUACION, APresupuesto.FECHA_PRESUPUESTO, AFechaDecision) then
|
|||
|
|
Exit;
|
|||
|
|
|
|||
|
|
// Asegurarse de valores en campos "autom<6F>ticos"
|
|||
|
|
APresupuesto.Edit;
|
|||
|
|
try
|
|||
|
|
if AFechaDecision <> APresupuesto.FECHA_DECISION then
|
|||
|
|
APresupuesto.FECHA_DECISION := AFechaDecision;
|
|||
|
|
|
|||
|
|
APresupuesto.USUARIO := dmUsuarios.LoginInfo.Usuario;
|
|||
|
|
|
|||
|
|
if Assigned(APresupuesto.Cliente) then
|
|||
|
|
APresupuesto.ID_CLIENTE := APresupuesto.Cliente.ID;
|
|||
|
|
|
|||
|
|
Result := True;
|
|||
|
|
finally
|
|||
|
|
APresupuesto.Post;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.ValidarSituacion(ASituacion: String;
|
|||
|
|
AFechaPresupuesto: TDateTime; var AFechaDecision: TDateTime): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
if ASituacion = SITUACION_PENDIENTE then
|
|||
|
|
AFechaDecision := 0
|
|||
|
|
else begin
|
|||
|
|
if (EsFechaVacia(AFechaDecision)) then
|
|||
|
|
raise Exception.Create('Hay que indicar una fecha de decisi<73>n')
|
|||
|
|
else if (AFechaDecision < AFechaPresupuesto) then
|
|||
|
|
raise Exception.Create('La fecha de decisici<63>n debe ser posterior a la fecha del presupuesto');
|
|||
|
|
end;
|
|||
|
|
Result := True;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.Ver(APresupuesto: IBizPresupuesto);
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorPresupuesto;
|
|||
|
|
begin
|
|||
|
|
AEditor := NIL;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
RecuperarCliente(APresupuesto);
|
|||
|
|
CreateEditor('EditorPresupuesto', IEditorPresupuesto, AEditor);
|
|||
|
|
with AEditor do
|
|||
|
|
begin
|
|||
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|||
|
|
Presupuesto := APresupuesto;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if Assigned(AEditor) then
|
|||
|
|
AEditor.ShowModal;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.VerTodos(APresupuestos: IBizPresupuesto);
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorPresupuestos;
|
|||
|
|
begin
|
|||
|
|
AEditor := NIL;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
CreateEditor('EditorPresupuestos', IEditorPresupuestos, AEditor);
|
|||
|
|
with AEditor do
|
|||
|
|
begin
|
|||
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|||
|
|
Presupuestos := APresupuestos;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if Assigned(AEditor) then
|
|||
|
|
AEditor.ShowEmbedded;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController._Vacio: IBizPresupuesto;
|
|||
|
|
begin
|
|||
|
|
Result := Buscar(ID_NULO);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.Eliminar(const ID: Integer);
|
|||
|
|
var
|
|||
|
|
APresupuesto : IBizPresupuesto;
|
|||
|
|
begin
|
|||
|
|
APresupuesto := Buscar(ID);
|
|||
|
|
|
|||
|
|
if not Assigned(APresupuesto) then
|
|||
|
|
raise Exception.Create(Format('No se ha encontrado el presupuesto con ID = %d', [ID]));
|
|||
|
|
|
|||
|
|
Eliminar(APresupuesto);
|
|||
|
|
APresupuesto := NIL;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.ElegirPresupuesto(APresupuestos: IBizPresupuesto; AMensaje: String;
|
|||
|
|
AMultiSelect: Boolean): IBizPresupuesto;
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorElegirPresupuestos;
|
|||
|
|
begin
|
|||
|
|
Result := NIL;
|
|||
|
|
|
|||
|
|
CreateEditor('EditorElegirPresupuestos', IEditorElegirPresupuestos, AEditor);
|
|||
|
|
try
|
|||
|
|
with AEditor do
|
|||
|
|
begin
|
|||
|
|
Presupuestos := APresupuestos;
|
|||
|
|
Controller := Self;
|
|||
|
|
MultiSelect := AMultiSelect;
|
|||
|
|
if IsPositiveResult(ShowModal) then
|
|||
|
|
Result := PresupuestosSeleccionados;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
AEditor := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.Eliminar(APresupuesto: IBizPresupuesto);
|
|||
|
|
begin
|
|||
|
|
if not Assigned(APresupuesto) then
|
|||
|
|
raise Exception.Create ('Presupuesto no asignado');
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
if (APresupuesto.State in dsEditModes) then
|
|||
|
|
APresupuesto.Cancel;
|
|||
|
|
|
|||
|
|
APresupuesto.Delete;
|
|||
|
|
APresupuesto.DataTable.ApplyUpdates;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable);
|
|||
|
|
var
|
|||
|
|
APresupuesto : IBizPresupuesto;
|
|||
|
|
ADetallesPresupuesto : IBizDetallesPresupuesto;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
|
|||
|
|
if Supports(ADataTable, IBizDetallesPresupuesto, ADetallesPresupuesto) and
|
|||
|
|
Supports(ADetallesPresupuesto.DataTable.MasterSource.DataTable, IBizPresupuesto, APresupuesto) then
|
|||
|
|
begin
|
|||
|
|
APresupuesto.Edit;
|
|||
|
|
try
|
|||
|
|
APresupuesto.BASE_IMPONIBLE := FDetallesController.DarTotalImporteTotal(ADetallesPresupuesto);
|
|||
|
|
finally
|
|||
|
|
APresupuesto.Post;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.RecuperarCliente(
|
|||
|
|
APresupuesto: IBizPresupuesto);
|
|||
|
|
begin
|
|||
|
|
APresupuesto.Cliente := (FClienteController.Buscar(APresupuesto.ID_CLIENTE) as IBizCliente);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.Existe(const ID: Integer): Boolean;
|
|||
|
|
var
|
|||
|
|
APresupuesto : IBizPresupuesto;
|
|||
|
|
begin
|
|||
|
|
try
|
|||
|
|
APresupuesto := Buscar(ID);
|
|||
|
|
Result := Assigned(APresupuesto) and (APresupuesto.ID = ID);
|
|||
|
|
finally
|
|||
|
|
APresupuesto := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.ExtraerSeleccionados(APresupuestos: IBizPresupuesto): IBizPresupuesto;
|
|||
|
|
var
|
|||
|
|
ASeleccionados : IBizPresupuesto;
|
|||
|
|
begin
|
|||
|
|
ASeleccionados := Self.Buscar(ID_NULO);
|
|||
|
|
CopyDataTable(APresupuestos.DataTable, ASeleccionados.DataTable, True);
|
|||
|
|
Result := ASeleccionados;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.FiltrarEmpresa(APresupuestos: IBizPresupuesto);
|
|||
|
|
begin
|
|||
|
|
if APresupuestos.DataTable.Active then
|
|||
|
|
APresupuestos.DataTable.Active := False;
|
|||
|
|
|
|||
|
|
// Filtrar los presupuestos actuales por empresa
|
|||
|
|
with APresupuestos.DataTable.Where do
|
|||
|
|
begin
|
|||
|
|
if NotEmpty then
|
|||
|
|
AddOperator(opAND);
|
|||
|
|
AddCondition(fld_PresupuestosID_EMPRESA, cEqual, dmUsuarios.IDEmpresaActual);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.SetClienteController(const Value: IClientesController);
|
|||
|
|
begin
|
|||
|
|
FClienteController := Value;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.SetDetallesController(const Value: IDetallesPresupuestoController);
|
|||
|
|
begin
|
|||
|
|
FDetallesController := Value;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.Guardar(APresupuesto: IBizPresupuesto);
|
|||
|
|
var
|
|||
|
|
NuevoID: Integer;
|
|||
|
|
begin
|
|||
|
|
if ValidarPresupuesto(APresupuesto) then
|
|||
|
|
begin
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
if APresupuesto.EsNuevo then
|
|||
|
|
NuevoID := FDataModule.GetNextID(APresupuesto.DataTable.LogicalName)
|
|||
|
|
else
|
|||
|
|
NuevoID := APresupuesto.ID;
|
|||
|
|
|
|||
|
|
AsignarID(APresupuesto, NuevoID);
|
|||
|
|
APresupuesto.DataTable.ApplyUpdates;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.Nuevo: IBizPresupuesto;
|
|||
|
|
var
|
|||
|
|
APresupuesto : IBizPresupuesto;
|
|||
|
|
begin
|
|||
|
|
APresupuesto := FDataModule.NewItem;
|
|||
|
|
FiltrarEmpresa(APresupuesto);
|
|||
|
|
APresupuesto.DataTable.Active := True;
|
|||
|
|
APresupuesto.Insert;
|
|||
|
|
APresupuesto.Cliente := (FClienteController.Nuevo as IBizCliente);
|
|||
|
|
Result := APresupuesto;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.Preview(APresupuesto: IBizPresupuesto);
|
|||
|
|
var
|
|||
|
|
AReportController : IPresupuestosReportController;
|
|||
|
|
begin
|
|||
|
|
AReportController := TPresupuestosReportController.Create;
|
|||
|
|
try
|
|||
|
|
AReportController.Preview(APresupuesto.ID);
|
|||
|
|
finally
|
|||
|
|
AReportController := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosController.Print(APresupuesto: IBizPresupuesto);
|
|||
|
|
var
|
|||
|
|
AReportController : IPresupuestosReportController;
|
|||
|
|
begin
|
|||
|
|
AReportController := TPresupuestosReportController.Create;
|
|||
|
|
try
|
|||
|
|
AReportController.Print(APresupuesto.ID);
|
|||
|
|
finally
|
|||
|
|
AReportController := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
|
|||
|
|
function TPresupuestosController.GetClienteController: IClientesController;
|
|||
|
|
begin
|
|||
|
|
Result := FClienteController;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosController.GetDetallesController: IDetallesPresupuestoController;
|
|||
|
|
begin
|
|||
|
|
Result := FDetallesController;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|