2007-10-26 18:19:55 +00:00
|
|
|
|
unit uPresupuestosClienteController;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
SysUtils, uDADataTable, uEditorDBItem,
|
|
|
|
|
|
uControllerBase, uIDataModulePresupuestosCliente, uClientesController,
|
|
|
|
|
|
uDetallesPresupuestoClienteController, uBizPresupuestosCliente, uBizDireccionesContacto,
|
|
|
|
|
|
uBizDetallesPresupuestoCliente;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
IPresupuestosClienteController = interface(IObservador)
|
|
|
|
|
|
['{21ED0332-F0E0-468D-8D53-8CA362757191}']
|
|
|
|
|
|
function GetClienteController: IClientesController;
|
|
|
|
|
|
procedure SetClienteController(const Value: IClientesController);
|
|
|
|
|
|
property ClienteController: IClientesController read GetClienteController write SetClienteController;
|
|
|
|
|
|
|
|
|
|
|
|
function GetDetallesController: IDetallesPresupuestoClienteController;
|
|
|
|
|
|
procedure SetDetallesController(const Value: IDetallesPresupuestoClienteController);
|
|
|
|
|
|
property DetallesController: IDetallesPresupuestoClienteController read GetDetallesController write SetDetallesController;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure RecuperarCliente(APresupuesto : IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
function Buscar(const ID: Integer): IBizPresupuestoCliente;
|
|
|
|
|
|
function BuscarTodos: IBizPresupuestoCliente;
|
|
|
|
|
|
function BuscarPendientes : IBizPresupuestoCliente;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure Ver(APresupuesto : IBizPresupuestoCliente);
|
|
|
|
|
|
procedure VerTodos(APresupuestos: IBizPresupuestoCliente);
|
|
|
|
|
|
procedure VerDireccionEntrega(APresupuesto : IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
function Nuevo : IBizPresupuestoCliente;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function Anadir(APresupuesto : IBizPresupuestoCliente) : Boolean;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
function Eliminar(const ID : Integer): Boolean; overload;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function Eliminar(APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false): Boolean; overload;
|
|
|
|
|
|
function Guardar(APresupuesto : IBizPresupuestoCliente): Boolean;
|
|
|
|
|
|
procedure DescartarCambios(APresupuesto : IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
function Existe(const ID: Integer) : Boolean;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function Duplicar(APresupuesto: IBizPresupuestoCliente): IBizPresupuestoCliente;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function Localizar(APresupuestos: IBizPresupuestoCliente; const ID : Integer): Boolean;
|
|
|
|
|
|
function ExtraerSeleccionados(APresupuesto: IBizPresupuestoCliente) : IBizPresupuestoCliente;
|
|
|
|
|
|
function ElegirPresupuestos(APresupuesto: IBizPresupuestoCliente; AMensaje: String; AMultiSelect: Boolean): IBizPresupuestoCliente;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
procedure CopiarDireccionEnvio (const ADireccionEnvio: IBizDireccionesContacto;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto: IBizPresupuestoCliente);
|
|
|
|
|
|
procedure QuitarDireccionEnvio(APresupuesto: IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure RecalcularImportes(APresupuesto : IBizPresupuestoCliente);
|
|
|
|
|
|
function EsModificable(APresupuesto : IBizPresupuestoCliente): Boolean;
|
|
|
|
|
|
function EsEliminable(APresupuesto : IBizPresupuestoCliente): Boolean;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure Preview(APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false);
|
|
|
|
|
|
procedure Print(APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TPresupuestosClienteController = class(TObservador, IPresupuestosClienteController)
|
|
|
|
|
|
protected
|
|
|
|
|
|
FDataModule : IDataModulePresupuestosCliente;
|
|
|
|
|
|
FClienteController : IClientesController;
|
|
|
|
|
|
FDetallesController : IDetallesPresupuestoClienteController;
|
|
|
|
|
|
|
|
|
|
|
|
function GetClienteController: IClientesController;
|
|
|
|
|
|
procedure SetClienteController(const Value: IClientesController);
|
|
|
|
|
|
function GetDetallesController: IDetallesPresupuestoClienteController;
|
|
|
|
|
|
procedure SetDetallesController(const Value: IDetallesPresupuestoClienteController);
|
|
|
|
|
|
|
|
|
|
|
|
//Estos son los tres m<>todos a sobre escribir si se desea heredar toda la logica de
|
|
|
|
|
|
//este controller
|
|
|
|
|
|
procedure AsignarDataModule; virtual;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure RecuperarObjetos(APresupuesto: IBizPresupuestoCliente); virtual;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override;
|
|
|
|
|
|
function CreateEditor(const AName : String; const IID: TGUID; out Intf): Boolean;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure FiltrarEmpresa(APresupuesto: IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
function _Vacio : IBizPresupuestoCliente;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function ValidarPresupuesto(APresupuesto: IBizPresupuestoCliente): Boolean;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
public
|
|
|
|
|
|
property ClienteController: IClientesController read GetClienteController write SetClienteController;
|
|
|
|
|
|
property DetallesController: IDetallesPresupuestoClienteController read GetDetallesController write SetDetallesController;
|
|
|
|
|
|
|
2007-11-22 19:09:07 +00:00
|
|
|
|
constructor Create; override;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function Localizar(APresupuestos: IBizPresupuestoCliente; const ID : Integer): Boolean;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure RecuperarCliente(APresupuesto : IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
function Eliminar(const ID : Integer): Boolean; overload;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function Eliminar(APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false): Boolean; overload;
|
|
|
|
|
|
function Guardar(APresupuesto : IBizPresupuestoCliente): Boolean;
|
|
|
|
|
|
procedure DescartarCambios(APresupuesto : IBizPresupuestoCliente); virtual;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
function Existe(const ID: Integer) : Boolean; virtual;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function Anadir(APresupuesto : IBizPresupuestoCliente) : Boolean;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
function Buscar(const ID: Integer): IBizPresupuestoCliente;
|
|
|
|
|
|
function BuscarTodos: IBizPresupuestoCliente;
|
|
|
|
|
|
function BuscarPendientes : IBizPresupuestoCliente;
|
|
|
|
|
|
function Nuevo : IBizPresupuestoCliente;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure Ver(APresupuesto : IBizPresupuestoCliente);
|
|
|
|
|
|
procedure VerTodos(APresupuestos: IBizPresupuestoCliente);
|
|
|
|
|
|
procedure VerDireccionEntrega(APresupuesto : IBizPresupuestoCliente);
|
|
|
|
|
|
function Duplicar(APresupuesto: IBizPresupuestoCliente): IBizPresupuestoCliente;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
procedure CopiarDireccionEnvio (const ADireccionEnvio: IBizDireccionesContacto;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto: IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure QuitarDireccionEnvio(APresupuesto: IBizPresupuestoCliente);
|
|
|
|
|
|
function ExtraerSeleccionados(APresupuesto: IBizPresupuestoCliente) : IBizPresupuestoCliente;
|
|
|
|
|
|
function ElegirPresupuestos(APresupuesto: IBizPresupuestoCliente; AMensaje: String; AMultiSelect: Boolean): IBizPresupuestoCliente;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure RecalcularImportes(APresupuesto : IBizPresupuestoCliente);
|
|
|
|
|
|
function EsModificable(APresupuesto : IBizPresupuestoCliente): Boolean;
|
|
|
|
|
|
function EsEliminable(APresupuesto : IBizPresupuestoCliente): Boolean;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure Preview(APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false);
|
|
|
|
|
|
procedure Print(APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
uROTypes, Controls, cxControls, DB, uEditorRegistryUtils, uEditorPreview, DateUtils,
|
|
|
|
|
|
uIEditorPresupuestosCliente, uDataModulePresupuestosCliente, Variants,
|
2007-11-18 15:07:51 +00:00
|
|
|
|
uBizContactos, uDataTableUtils, uDataModuleUsuarios, Classes, uFactuGES_App,
|
2007-11-05 17:49:11 +00:00
|
|
|
|
schPresupuestosClienteClient_Intf, uDAInterfaces, uDateUtils, uIEditorPresupuestoCliente,
|
2007-10-26 18:19:55 +00:00
|
|
|
|
uIEditorElegirPresupuestosCliente, uIEditorDireccionEntregaPresupuestoCliente,
|
|
|
|
|
|
schContactosClient_Intf, uPresupuestosClienteReportController;
|
|
|
|
|
|
|
|
|
|
|
|
{ TPresupuestosClienteController }
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function TPresupuestosClienteController.Anadir(APresupuesto: IBizPresupuestoCliente): Boolean;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if not Assigned(APresupuesto) then
|
|
|
|
|
|
raise Exception.Create ('Presupuesto no asignado (Anadir)');
|
|
|
|
|
|
APresupuesto.Insert;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
Result := True;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TPresupuestosClienteController.AsignarDataModule;
|
|
|
|
|
|
begin
|
|
|
|
|
|
FDataModule := TDataModulePresupuestosCliente.Create(Nil);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPresupuestosClienteController.Buscar(const ID: Integer): IBizPresupuestoCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := FDataModule.GetItem(ID);
|
|
|
|
|
|
FiltrarEmpresa(Result);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPresupuestosClienteController.BuscarTodos: IBizPresupuestoCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := FDataModule.GetItems;
|
|
|
|
|
|
FiltrarEmpresa(Result);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPresupuestosClienteController.BuscarPendientes: IBizPresupuestoCliente;
|
2007-11-18 17:23:37 +00:00
|
|
|
|
var
|
|
|
|
|
|
Condicion: TDAWhereExpression;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
|
|
|
|
|
Result := BuscarTodos;
|
2007-11-18 17:23:37 +00:00
|
|
|
|
// Filtrar los presupuesto pendientes de recepcion
|
|
|
|
|
|
with Result.DataTable.DynamicWhere do
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-18 17:23:37 +00:00
|
|
|
|
// (SITUACION <> RECIBIDO)
|
|
|
|
|
|
Condicion := NewBinaryExpression(NewField('', fld_PresupuestosClienteSITUACION), NewConstant(SITUACION_PRESUPUESTO_PENDIENTE, datString), dboNotEqual);
|
|
|
|
|
|
|
|
|
|
|
|
if IsEmpty then
|
|
|
|
|
|
Expression := Condicion
|
|
|
|
|
|
else
|
|
|
|
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TPresupuestosClienteController.CopiarDireccionEnvio(
|
2007-11-05 17:49:11 +00:00
|
|
|
|
const ADireccionEnvio: IBizDireccionesContacto; APresupuesto: IBizPresupuestoCliente);
|
2008-05-20 18:50:02 +00:00
|
|
|
|
{var
|
|
|
|
|
|
bEnEdicion : Boolean;}
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
{
|
|
|
|
|
|
if not Assigned(APresupuesto) then
|
|
|
|
|
|
raise Exception.Create ('Presupuesto no asignado (CopiarDireccionEnvio)');
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
if not Assigned(ADireccionEnvio) then
|
|
|
|
|
|
raise Exception.Create ('No se ha indicado la direcci<63>n (CopiarDireccionEnvio)');
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if APresupuesto.DataTable.Active then
|
|
|
|
|
|
APresupuesto.DataTable.Active := True;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
if ADireccionEnvio.DataTable.Active then
|
|
|
|
|
|
ADireccionEnvio.DataTable.Active := True;
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
bEnEdicion := (APresupuesto.DataTable.State in dsEditModes);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
if not bEnEdicion then
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.Edit;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
ShowHourglassCursor;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.Edit;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
try
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.CALLE := ADireccionEnvio.CALLE;
|
|
|
|
|
|
APresupuesto.POBLACION := ADireccionEnvio.POBLACION;
|
|
|
|
|
|
APresupuesto.CODIGO_POSTAL := ADireccionEnvio.CODIGO_POSTAL;
|
|
|
|
|
|
APresupuesto.PROVINCIA := ADireccionEnvio.PROVINCIA;
|
|
|
|
|
|
APresupuesto.TELEFONO := ADireccionEnvio.TELEFONO;
|
|
|
|
|
|
APresupuesto.PERSONA_CONTACTO := ADireccionEnvio.PERSONA_CONTACTO;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
if not bEnEdicion then
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.Post;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
}
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
constructor TPresupuestosClienteController.Create;
|
|
|
|
|
|
begin
|
2007-11-22 19:09:07 +00:00
|
|
|
|
inherited;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
AsignarDataModule;
|
2007-11-22 19:09:07 +00:00
|
|
|
|
|
2007-10-26 18:19:55 +00:00
|
|
|
|
FClienteController := TClientesController.Create;
|
|
|
|
|
|
FDetallesController := TDetallesPresupuestoClienteController.Create;
|
|
|
|
|
|
FDetallesController.addObservador(Self);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPresupuestosClienteController.CreateEditor(const AName: String;
|
|
|
|
|
|
const IID: TGUID; out Intf): Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure TPresupuestosClienteController.DescartarCambios(APresupuesto: IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if not Assigned(APresupuesto) then
|
|
|
|
|
|
raise Exception.Create ('Presupuesto no asignada');
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if (APresupuesto.State in dsEditModes) then
|
|
|
|
|
|
APresupuesto.Cancel;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.DataTable.CancelUpdates;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TPresupuestosClienteController.Destroy;
|
|
|
|
|
|
begin
|
|
|
|
|
|
FDataModule := Nil;
|
|
|
|
|
|
FClienteController := Nil;
|
|
|
|
|
|
FDetallesController := Nil;
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPresupuestosClienteController.Duplicar(
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto: IBizPresupuestoCliente): IBizPresupuestoCliente;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
|
|
|
|
|
Result := Self._Vacio;
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
2007-11-05 17:49:11 +00:00
|
|
|
|
DuplicarRegistros(APresupuesto.DataTable, Result.DataTable, mdrActual);
|
|
|
|
|
|
DuplicarRegistros(APresupuesto.Detalles.DataTable, Result.Detalles.DataTable, mdrTodos);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
// Hay que dejar algunos campos como si fuera un presupuesto nuevo
|
|
|
|
|
|
Result.Edit;
|
|
|
|
|
|
with Result do
|
|
|
|
|
|
begin
|
2007-11-18 15:07:51 +00:00
|
|
|
|
ID_EMPRESA := AppFactuGES.EmpresaActiva.ID;
|
|
|
|
|
|
USUARIO := AppFactuGES.UsuarioActivo.UserName;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
FECHA_PRESUPUESTO := DateOf(Now);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
INCIDENCIAS_ACTIVAS := 0;
|
2008-01-08 10:31:12 +00:00
|
|
|
|
DataTable.FieldByName('INCIDENCIAS').AsVariant := Null;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
REFERENCIA := '';
|
2008-03-04 10:27:37 +00:00
|
|
|
|
SITUACION := SITUACION_PRESUPUESTO_PENDIENTE;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
Result.Post;
|
|
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function TPresupuestosClienteController.ValidarPresupuesto(
|
|
|
|
|
|
APresupuesto: IBizPresupuestoCliente): Boolean;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if not Assigned(APresupuesto) then
|
|
|
|
|
|
raise Exception.Create ('Presupuesto no asignado');
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if (APresupuesto.DataTable.State in dsEditModes) then
|
|
|
|
|
|
APresupuesto.DataTable.Post;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
//Tambien hacemos post de sus tablas hija
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if (APresupuesto.Detalles.DataTable.State in dsEditModes) then
|
|
|
|
|
|
APresupuesto.Detalles.DataTable.Post;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
// Abrir el cliente para la validaci<63>n
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if Assigned(APresupuesto.Cliente) then
|
|
|
|
|
|
APresupuesto.Cliente.DataTable.Active := True;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
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');
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if (EsFechaVacia(APresupuesto.FECHA_PRESUPUESTO)) then
|
|
|
|
|
|
raise Exception.Create('Debe indicar la fecha de este presupuesto');
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if (APresupuesto.Detalles.DataTable.RecordCount = 0) then
|
|
|
|
|
|
raise Exception.Create('El presupuesto debe tener en su contenido al menos un concepto');
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
{ Asegurarse de valores en campos "autom<6F>ticos" tanto
|
|
|
|
|
|
en MODIFICACI<EFBFBD>N como en INSERCI<EFBFBD>N. }
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.Edit;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
try
|
2007-11-18 15:07:51 +00:00
|
|
|
|
APresupuesto.USUARIO := AppFactuGES.UsuarioActivo.UserName;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if Assigned(APresupuesto.Cliente)
|
|
|
|
|
|
and (APresupuesto.ID_CLIENTE <> APresupuesto.Cliente.ID) then
|
|
|
|
|
|
APresupuesto.ID_CLIENTE := APresupuesto.Cliente.ID;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
finally
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.Post;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure TPresupuestosClienteController.Ver(APresupuesto: IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
var
|
|
|
|
|
|
AEditor : IEditorPresupuestoCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AEditor := NIL;
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
2007-11-05 17:49:11 +00:00
|
|
|
|
RecuperarObjetos(APresupuesto);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
CreateEditor('EditorPresupuestoCliente', IEditorPresupuestoCliente, AEditor);
|
|
|
|
|
|
|
|
|
|
|
|
if Assigned(AEditor) then
|
|
|
|
|
|
with AEditor do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
2007-11-05 17:49:11 +00:00
|
|
|
|
Presupuesto := APresupuesto;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
//MODO CONSULTAR
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if not EsModificable(APresupuesto) then
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
SetDataTableReadOnly(APresupuesto.DataTable, True);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
ReadOnly := True;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
ShowModal;
|
|
|
|
|
|
|
|
|
|
|
|
//MODO CONSULTAR (Se deja la tabla como estaba)
|
|
|
|
|
|
if ReadOnly then
|
2007-11-05 17:49:11 +00:00
|
|
|
|
SetDataTableReadOnly(APresupuesto.DataTable, False);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
AEditor.Release;
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
AEditor := NIL;
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TPresupuestosClienteController.VerDireccionEntrega(
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto: IBizPresupuestoCliente);
|
2008-05-20 18:50:02 +00:00
|
|
|
|
{var
|
|
|
|
|
|
AEditor : IEditorDireccionEntregaPresupuestoCliente;}
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
{
|
2007-10-26 18:19:55 +00:00
|
|
|
|
AEditor := NIL;
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
2007-11-05 17:49:11 +00:00
|
|
|
|
//RecuperarObjetos(APresupuesto); <- No descomentar. No hace falta
|
2007-10-26 18:19:55 +00:00
|
|
|
|
CreateEditor('EditorDireccionEntregaPresupuestoCliente', IEditorDireccionEntregaPresupuestoCliente, AEditor);
|
2007-11-18 18:42:04 +00:00
|
|
|
|
if Assigned(AEditor) then
|
|
|
|
|
|
with (AEditor as IEditorDireccionEntregaPresupuestoCliente) do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Presupuesto := APresupuesto;
|
|
|
|
|
|
ShowModal;
|
|
|
|
|
|
Release;
|
|
|
|
|
|
end;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
finally
|
2007-11-18 18:42:04 +00:00
|
|
|
|
AEditor := NIL;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
}
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure TPresupuestosClienteController.VerTodos(APresupuestos: IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
var
|
|
|
|
|
|
AEditor : IEditorPresupuestosCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AEditor := NIL;
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
|
|
|
|
|
CreateEditor('EditorPresupuestosCliente', IEditorPresupuestosCliente, AEditor);
|
|
|
|
|
|
if Assigned(AEditor) then
|
|
|
|
|
|
with AEditor do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
2007-11-05 17:49:11 +00:00
|
|
|
|
Presupuestos := APresupuestos;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
MultiSelect := True;
|
|
|
|
|
|
ShowEmbedded;
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
AEditor := NIL;
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPresupuestosClienteController._Vacio: IBizPresupuestoCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := Buscar(ID_NULO);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPresupuestosClienteController.Eliminar(const ID: Integer): Boolean;
|
|
|
|
|
|
var
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto : IBizPresupuestoCliente;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto := Buscar(ID);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if not Assigned(APresupuesto) then
|
|
|
|
|
|
raise Exception.Create(Format('No se ha encontrado el presupuesto con ID = %d', [ID]));
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
Result := Eliminar(APresupuesto);
|
|
|
|
|
|
APresupuesto := NIL;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function TPresupuestosClienteController.ElegirPresupuestos(APresupuesto: IBizPresupuestoCliente; AMensaje: String; AMultiSelect: Boolean): IBizPresupuestoCliente;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
var
|
|
|
|
|
|
AEditor : IEditorElegirPresupuestosCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := NIL;
|
2007-11-18 20:08:55 +00:00
|
|
|
|
ShowHourglassCursor;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
try
|
2007-11-18 20:08:55 +00:00
|
|
|
|
CreateEditor('EditorElegirPresupuestosCliente', IEditorElegirPresupuestosCliente, AEditor);
|
|
|
|
|
|
if Assigned(AEditor) then
|
|
|
|
|
|
with AEditor do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Controller := Self;
|
|
|
|
|
|
Presupuestos := APresupuesto;
|
|
|
|
|
|
MultiSelect := AMultiSelect;
|
|
|
|
|
|
Mensaje := AMensaje;
|
|
|
|
|
|
if IsPositiveResult(ShowModal) then
|
|
|
|
|
|
Result := PresupuestosClienteSeleccionados;
|
|
|
|
|
|
Release;
|
|
|
|
|
|
end;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
finally
|
|
|
|
|
|
AEditor := NIL;
|
2007-11-18 20:08:55 +00:00
|
|
|
|
HideHourglassCursor;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function TPresupuestosClienteController.Eliminar(APresupuesto: IBizPresupuestoCliente; AllItems: Boolean = false): Boolean;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
//En el caso de eliminar almenos un elemento del conjunto se devuelve true
|
|
|
|
|
|
var
|
|
|
|
|
|
bEliminado: Boolean;
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
bEliminado := False;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if not Assigned(APresupuesto) then
|
|
|
|
|
|
raise Exception.Create ('APresupuesto no asignado');
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if not APresupuesto.DataTable.Active then
|
2007-11-19 19:13:37 +00:00
|
|
|
|
APresupuesto.DataTable.Active := True;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if (APresupuesto.State in dsEditModes) then
|
|
|
|
|
|
APresupuesto.Cancel;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
//Siempre eliminaremos el seleccionado
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if EsEliminable(APresupuesto) then
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.Delete;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
bEliminado := True;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-12-20 10:06:27 +00:00
|
|
|
|
//En el caso de querer eliminar todos los items del objeto APresupuesto
|
2007-10-26 18:19:55 +00:00
|
|
|
|
if AllItems then
|
|
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
with APresupuesto.DataTable do
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
|
|
|
|
|
First;
|
|
|
|
|
|
while not EOF do
|
|
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if EsEliminable(APresupuesto) then
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.Delete;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
bEliminado := True
|
|
|
|
|
|
end
|
|
|
|
|
|
else Next;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
if bEliminado then
|
|
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.DataTable.ApplyUpdates;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
Result := True;
|
|
|
|
|
|
end
|
|
|
|
|
|
else
|
|
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function TPresupuestosClienteController.EsEliminable(APresupuesto: IBizPresupuestoCliente): Boolean;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if not Assigned(APresupuesto) then
|
|
|
|
|
|
raise Exception.Create ('Presupuesto no asignado: EsEliminable');
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
Result := (APresupuesto.SITUACION = SITUACION_PRESUPUESTO_PENDIENTE);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function TPresupuestosClienteController.EsModificable(APresupuesto: IBizPresupuestoCliente): Boolean;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if not Assigned(APresupuesto) then
|
|
|
|
|
|
raise Exception.Create ('Presupuesto no asignado: EsModificable');
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2008-02-18 14:42:55 +00:00
|
|
|
|
//Result := (APresupuesto.SITUACION = SITUACION_PRESUPUESTO_PENDIENTE);
|
|
|
|
|
|
// En Tecsitel, todos los presupuestos son modificables independientemente
|
|
|
|
|
|
// de su situaci<63>n.
|
|
|
|
|
|
Result := True;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TPresupuestosClienteController.RecalcularImportes(
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto: IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
var
|
|
|
|
|
|
bEnEdicion : Boolean;
|
2007-12-20 21:05:11 +00:00
|
|
|
|
ADetallePosAct : Integer;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if not Assigned(APresupuesto) then
|
|
|
|
|
|
raise Exception.Create ('Presupuesto no asignado (RecalcularImportes)');
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if APresupuesto.DataTable.Active then
|
|
|
|
|
|
APresupuesto.DataTable.Active := True;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-12-20 21:05:11 +00:00
|
|
|
|
{ Hay que guardar la posici<EFBFBD>n en la que estamos en los detalles por que
|
|
|
|
|
|
la asignaci<EFBFBD>n de valores a los campos IMPORTE_NETO e IMPORTE_PORTE
|
|
|
|
|
|
(ver m<EFBFBD>s adelante) colocan el puntero en la tabla detalle al principio.
|
|
|
|
|
|
No he encontrado la raz<EFBFBD>n por la que mueve el puntero. }
|
|
|
|
|
|
|
|
|
|
|
|
ADetallePosAct := APresupuesto.Detalles.POSICION;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
bEnEdicion := (APresupuesto.DataTable.State in dsEditModes);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
if not bEnEdicion then
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.Edit;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.IMPORTE_NETO := FDetallesController.DarTotalImporteTotal(APresupuesto.Detalles);
|
2007-12-20 21:05:11 +00:00
|
|
|
|
APresupuesto.IMPORTE_PORTE := FDetallesController.DarTotalPorteTotal(APresupuesto.Detalles);
|
|
|
|
|
|
|
2007-10-26 18:19:55 +00:00
|
|
|
|
if not bEnEdicion then
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.Post;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
2007-12-20 21:05:11 +00:00
|
|
|
|
// Restaurar la posici<63>n que ten<65>amos en los detalles.
|
|
|
|
|
|
FDetallesController.LocalizarPosicion(APresupuesto.Detalles, ADetallePosAct);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TPresupuestosClienteController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable);
|
|
|
|
|
|
var
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto : IBizPresupuestoCliente;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
ADetalles : IBizDetallesPresupuestoCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
|
|
|
|
if Supports(ADataTable, IBizDetallesPresupuestoCliente, ADetalles) and
|
2007-11-05 17:49:11 +00:00
|
|
|
|
Supports(ADetalles.DataTable.MasterSource.DataTable, IBizPresupuestoCliente, APresupuesto) then
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
RecalcularImportes(APresupuesto);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure TPresupuestosClienteController.RecuperarObjetos(APresupuesto: IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
RecuperarCliente(APresupuesto);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TPresupuestosClienteController.RecuperarCliente(
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto: IBizPresupuestoCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto._Cliente := (FClienteController.Buscar(APresupuesto.ID_Cliente) as IBizCliente);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPresupuestosClienteController.Existe(const ID: Integer): Boolean;
|
|
|
|
|
|
var
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto : IBizPresupuestoCliente;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
|
|
|
|
|
try
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto := Buscar(ID);
|
|
|
|
|
|
Result := Assigned(APresupuesto) and (APresupuesto.ID = ID);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
finally
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto := NIL;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function TPresupuestosClienteController.ExtraerSeleccionados(APresupuesto: IBizPresupuestoCliente): IBizPresupuestoCliente;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
var
|
|
|
|
|
|
ASeleccionados : IBizPresupuestoCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
ASeleccionados := (Self.Buscar(ID_NULO) as IBizPresupuestoCliente);
|
2008-05-21 15:15:41 +00:00
|
|
|
|
CopyDataTableDA5(APresupuesto.DataTable, ASeleccionados.DataTable, True);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
Result := ASeleccionados;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-18 17:23:37 +00:00
|
|
|
|
procedure TPresupuestosClienteController.FiltrarEmpresa(APresupuesto: IBizPresupuestoCliente);
|
|
|
|
|
|
var
|
|
|
|
|
|
Condicion: TDAWhereExpression;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if APresupuesto.DataTable.Active then
|
|
|
|
|
|
APresupuesto.DataTable.Active := False;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-18 17:23:37 +00:00
|
|
|
|
// Filtrar los presupuestos actuales por empresa
|
|
|
|
|
|
with APresupuesto.DataTable.DynamicWhere do
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-18 17:23:37 +00:00
|
|
|
|
// (ID_EMPRESA >= ID)
|
|
|
|
|
|
Condicion := NewBinaryExpression(NewField('', fld_PresupuestosClienteID_EMPRESA), NewConstant(AppFactuGES.EmpresaActiva.ID, datInteger), dboEqual);
|
|
|
|
|
|
|
|
|
|
|
|
if IsEmpty then
|
|
|
|
|
|
Expression := Condicion
|
|
|
|
|
|
else
|
|
|
|
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TPresupuestosClienteController.SetClienteController(const Value: IClientesController);
|
|
|
|
|
|
begin
|
|
|
|
|
|
FClienteController := Value;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TPresupuestosClienteController.SetDetallesController(const Value: IDetallesPresupuestoClienteController);
|
|
|
|
|
|
begin
|
|
|
|
|
|
FDetallesController := Value;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function TPresupuestosClienteController.Guardar(APresupuesto: IBizPresupuestoCliente): Boolean;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
|
|
|
|
|
Result := False;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if not Assigned(APresupuesto) then
|
|
|
|
|
|
raise Exception.Create ('Presupuesto no asignada');
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
if not Assigned(FDetallesController) then
|
|
|
|
|
|
raise Exception.Create ('Controller detalles no asignado');
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if ValidarPresupuesto(APresupuesto) then
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
|
|
|
|
|
|
// Asegurarnos de que todos los importes est<73>n bien.
|
2007-11-05 17:49:11 +00:00
|
|
|
|
RecalcularImportes(APresupuesto);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
try
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.DataTable.ApplyUpdates;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
function TPresupuestosClienteController.Localizar(APresupuestos: IBizPresupuestoCliente;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
const ID: Integer): Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
2007-11-05 17:49:11 +00:00
|
|
|
|
with APresupuestos.DataTable do
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
|
|
|
|
|
DisableControls;
|
|
|
|
|
|
First;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if not Locate(fld_PresupuestosClienteID, ID, []) then
|
2007-10-26 18:19:55 +00:00
|
|
|
|
Result := False;
|
|
|
|
|
|
EnableControls;
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPresupuestosClienteController.Nuevo: IBizPresupuestoCliente;
|
|
|
|
|
|
var
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto : IBizPresupuestoCliente;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto := FDataModule.NewItem;
|
|
|
|
|
|
FiltrarEmpresa(APresupuesto);
|
|
|
|
|
|
APresupuesto.DataTable.Active := True;
|
|
|
|
|
|
APresupuesto.Insert;
|
|
|
|
|
|
Result := APresupuesto;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TPresupuestosClienteController.QuitarDireccionEnvio(
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto: IBizPresupuestoCliente);
|
2008-05-20 18:50:02 +00:00
|
|
|
|
{var
|
|
|
|
|
|
bEnEdicion : Boolean;}
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
{
|
|
|
|
|
|
if not Assigned(APresupuesto) then
|
|
|
|
|
|
raise Exception.Create ('Presupuesto no asignado (QuitarDireccionEnvio)');
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
if APresupuesto.DataTable.Active then
|
|
|
|
|
|
APresupuesto.DataTable.Active := True;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
bEnEdicion := (APresupuesto.DataTable.State in dsEditModes);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
if not bEnEdicion then
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.Edit;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
ShowHourglassCursor;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.Edit;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
try
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.DataTable.FieldByName(fld_PresupuestosClienteCALLE).Clear;
|
|
|
|
|
|
APresupuesto.DataTable.FieldByName(fld_PresupuestosClientePOBLACION).Clear;
|
|
|
|
|
|
APresupuesto.DataTable.FieldByName(fld_PresupuestosClienteCODIGO_POSTAL).Clear;
|
|
|
|
|
|
APresupuesto.DataTable.FieldByName(fld_PresupuestosClientePROVINCIA).Clear;
|
|
|
|
|
|
APresupuesto.DataTable.FieldByName(fld_PresupuestosClienteTELEFONO).Clear;
|
|
|
|
|
|
APresupuesto.DataTable.FieldByName(fld_PresupuestosClientePERSONA_CONTACTO).Clear;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
if not bEnEdicion then
|
2007-11-05 17:49:11 +00:00
|
|
|
|
APresupuesto.Post;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
}
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure TPresupuestosClienteController.Preview(APresupuesto: IBizPresupuestoCliente; AllItems: Boolean = false);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
var
|
|
|
|
|
|
AReportController : IPresupuestosClienteReportController;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
ID_Presupuestos: TStringList;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
AReportController := TPresupuestosClienteReportController.Create;
|
|
|
|
|
|
try
|
2007-11-05 17:49:11 +00:00
|
|
|
|
ID_Presupuestos := TStringList.Create;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-13 19:36:56 +00:00
|
|
|
|
//Si deseamos previsualizar todos los items del objeto presupuesto
|
2007-10-26 18:19:55 +00:00
|
|
|
|
if AllItems then
|
|
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
with APresupuesto.DataTable do
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
|
|
|
|
|
First;
|
|
|
|
|
|
while not EOF do
|
|
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
ID_Presupuestos.Add(IntToStr(APresupuesto.ID));
|
2007-10-26 18:19:55 +00:00
|
|
|
|
Next;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end
|
|
|
|
|
|
//Solo previsualizamos el item seleccionado
|
|
|
|
|
|
else
|
2007-11-05 17:49:11 +00:00
|
|
|
|
ID_Presupuestos.Add(IntToStr(APresupuesto.ID));
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
AReportController.Preview(ID_Presupuestos.CommaText);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
finally
|
|
|
|
|
|
AReportController := NIL;
|
2007-11-13 19:36:56 +00:00
|
|
|
|
FreeAndNil(ID_Presupuestos);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure TPresupuestosClienteController.Print(APresupuesto: IBizPresupuestoCliente; AllItems: Boolean = false);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
var
|
|
|
|
|
|
AReportController : IPresupuestosClienteReportController;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
ID_Presupuestos: TStringList;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
|
|
|
|
|
AReportController := TPresupuestosClienteReportController.Create;
|
2008-05-20 18:50:02 +00:00
|
|
|
|
ID_Presupuestos := TStringList.Create;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
try
|
2008-02-06 14:28:09 +00:00
|
|
|
|
//Si deseamos imprimimos todos los items del objeto presupuesto
|
2007-10-26 18:19:55 +00:00
|
|
|
|
if AllItems then
|
|
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
with APresupuesto.DataTable do
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
|
|
|
|
|
First;
|
|
|
|
|
|
while not EOF do
|
|
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
ID_Presupuestos.Add(IntToStr(APresupuesto.ID));
|
2007-10-26 18:19:55 +00:00
|
|
|
|
Next;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end
|
2008-02-06 14:28:09 +00:00
|
|
|
|
//Solo imprimimos el item seleccionado
|
2007-10-26 18:19:55 +00:00
|
|
|
|
else
|
2007-11-05 17:49:11 +00:00
|
|
|
|
ID_Presupuestos.Add(IntToStr(APresupuesto.ID));
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-12-20 10:06:27 +00:00
|
|
|
|
AReportController.Print(ID_Presupuestos.CommaText);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
finally
|
|
|
|
|
|
AReportController := NIL;
|
2008-05-20 18:50:02 +00:00
|
|
|
|
FreeANDNIL(ID_Presupuestos);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPresupuestosClienteController.GetClienteController: IClientesController;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := FClienteController;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPresupuestosClienteController.GetDetallesController: IDetallesPresupuestoClienteController;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := FDetallesController;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end.
|
2008-05-21 15:15:41 +00:00
|
|
|
|
|