852 lines
26 KiB
ObjectPascal
852 lines
26 KiB
ObjectPascal
|
|
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;
|
|||
|
|
|
|||
|
|
procedure RecuperarCliente(APedido : IBizPresupuestoCliente);
|
|||
|
|
function Buscar(const ID: Integer): IBizPresupuestoCliente;
|
|||
|
|
function BuscarTodos: IBizPresupuestoCliente;
|
|||
|
|
function BuscarPendientes : IBizPresupuestoCliente;
|
|||
|
|
function BuscarPendientesPedir(const ID : Integer): IBizPresupuestoClienteArticulosPendientesPedirAProv;
|
|||
|
|
procedure Ver(APedido : IBizPresupuestoCliente);
|
|||
|
|
procedure VerTodos(APedidos: IBizPresupuestoCliente);
|
|||
|
|
procedure VerDireccionEntrega(APedido : IBizPresupuestoCliente);
|
|||
|
|
function Nuevo : IBizPresupuestoCliente;
|
|||
|
|
function Anadir(APedido : IBizPresupuestoCliente) : Boolean;
|
|||
|
|
function Eliminar(const ID : Integer): Boolean; overload;
|
|||
|
|
function Eliminar(APedido : IBizPresupuestoCliente; AllItems: Boolean = false): Boolean; overload;
|
|||
|
|
function Guardar(APedido : IBizPresupuestoCliente): Boolean;
|
|||
|
|
procedure DescartarCambios(APedido : IBizPresupuestoCliente);
|
|||
|
|
function Existe(const ID: Integer) : Boolean;
|
|||
|
|
function Duplicar(APedido: IBizPresupuestoCliente): IBizPresupuestoCliente;
|
|||
|
|
|
|||
|
|
function Localizar(APedidos: IBizPresupuestoCliente; const ID : Integer): Boolean;
|
|||
|
|
function ExtraerSeleccionados(APedido: IBizPresupuestoCliente) : IBizPresupuestoCliente;
|
|||
|
|
function ElegirPedidos(APedido: IBizPresupuestoCliente; AMensaje: String; AMultiSelect: Boolean): IBizPresupuestoCliente;
|
|||
|
|
|
|||
|
|
procedure CopiarDireccionEnvio (const ADireccionEnvio: IBizDireccionesContacto;
|
|||
|
|
APedido: IBizPresupuestoCliente);
|
|||
|
|
procedure QuitarDireccionEnvio(APedido: IBizPresupuestoCliente);
|
|||
|
|
|
|||
|
|
procedure RecalcularImportes(APedido : IBizPresupuestoCliente);
|
|||
|
|
function EsModificable(APedido : IBizPresupuestoCliente): Boolean;
|
|||
|
|
function EsEliminable(APedido : IBizPresupuestoCliente): Boolean;
|
|||
|
|
|
|||
|
|
procedure Preview(APedido : IBizPresupuestoCliente; AllItems: Boolean = false);
|
|||
|
|
procedure Print(APedido : IBizPresupuestoCliente; AllItems: Boolean = false);
|
|||
|
|
|
|||
|
|
function ArticulosPendientes(const ID : Integer): IBizPresupuestoClienteArticulosPend;
|
|||
|
|
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;
|
|||
|
|
procedure RecuperarObjetos(APedido: IBizPresupuestoCliente); virtual;
|
|||
|
|
|
|||
|
|
procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override;
|
|||
|
|
procedure AsignarID(APedido: IBizPresupuestoCliente; const IDNuevo : Integer);
|
|||
|
|
function CreateEditor(const AName : String; const IID: TGUID; out Intf): Boolean;
|
|||
|
|
procedure FiltrarEmpresa(APedido: IBizPresupuestoCliente);
|
|||
|
|
function _Vacio : IBizPresupuestoCliente;
|
|||
|
|
function ValidarPedido(APedido: IBizPresupuestoCliente): Boolean;
|
|||
|
|
public
|
|||
|
|
property ClienteController: IClientesController read GetClienteController write SetClienteController;
|
|||
|
|
property DetallesController: IDetallesPresupuestoClienteController read GetDetallesController write SetDetallesController;
|
|||
|
|
|
|||
|
|
constructor Create; virtual;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
|
|||
|
|
function Localizar(APedidos: IBizPresupuestoCliente; const ID : Integer): Boolean;
|
|||
|
|
|
|||
|
|
procedure RecuperarCliente(APedido : IBizPresupuestoCliente);
|
|||
|
|
function Eliminar(const ID : Integer): Boolean; overload;
|
|||
|
|
function Eliminar(APedido : IBizPresupuestoCliente; AllItems: Boolean = false): Boolean; overload;
|
|||
|
|
function Guardar(APedido : IBizPresupuestoCliente): Boolean;
|
|||
|
|
procedure DescartarCambios(APedido : IBizPresupuestoCliente); virtual;
|
|||
|
|
function Existe(const ID: Integer) : Boolean; virtual;
|
|||
|
|
function Anadir(APedido : IBizPresupuestoCliente) : Boolean;
|
|||
|
|
function Buscar(const ID: Integer): IBizPresupuestoCliente;
|
|||
|
|
function BuscarTodos: IBizPresupuestoCliente;
|
|||
|
|
function BuscarPendientes : IBizPresupuestoCliente;
|
|||
|
|
function BuscarPendientesPedir(const ID : Integer): IBizPresupuestoClienteArticulosPendientesPedirAProv;
|
|||
|
|
function Nuevo : IBizPresupuestoCliente;
|
|||
|
|
procedure Ver(APedido : IBizPresupuestoCliente);
|
|||
|
|
procedure VerTodos(APedidos: IBizPresupuestoCliente);
|
|||
|
|
procedure VerDireccionEntrega(APedido : IBizPresupuestoCliente);
|
|||
|
|
function Duplicar(APedido: IBizPresupuestoCliente): IBizPresupuestoCliente;
|
|||
|
|
procedure CopiarDireccionEnvio (const ADireccionEnvio: IBizDireccionesContacto;
|
|||
|
|
APedido: IBizPresupuestoCliente);
|
|||
|
|
|
|||
|
|
procedure QuitarDireccionEnvio(APedido: IBizPresupuestoCliente);
|
|||
|
|
function ExtraerSeleccionados(APedido: IBizPresupuestoCliente) : IBizPresupuestoCliente;
|
|||
|
|
function ElegirPedidos(APedido: IBizPresupuestoCliente; AMensaje: String; AMultiSelect: Boolean): IBizPresupuestoCliente;
|
|||
|
|
|
|||
|
|
procedure RecalcularImportes(APedido : IBizPresupuestoCliente);
|
|||
|
|
function EsModificable(APedido : IBizPresupuestoCliente): Boolean;
|
|||
|
|
function EsEliminable(APedido : IBizPresupuestoCliente): Boolean;
|
|||
|
|
|
|||
|
|
procedure Preview(APedido : IBizPresupuestoCliente; AllItems: Boolean = false);
|
|||
|
|
procedure Print(APedido : IBizPresupuestoCliente; AllItems: Boolean = false);
|
|||
|
|
|
|||
|
|
function ArticulosPendientes(const ID : Integer): IBizPresupuestoClienteArticulosPend;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
uROTypes, Controls, cxControls, DB, uEditorRegistryUtils, uEditorPreview, DateUtils,
|
|||
|
|
uIEditorPresupuestosCliente, uDataModulePresupuestosCliente, Variants,
|
|||
|
|
uBizContactos, uDataTableUtils, uDataModuleUsuarios, Classes,
|
|||
|
|
schPedidosClienteClient_Intf, uDAInterfaces, uDateUtils, uIEditorPresupuestoCliente,
|
|||
|
|
uIEditorElegirPresupuestosCliente, uIEditorDireccionEntregaPresupuestoCliente,
|
|||
|
|
schContactosClient_Intf, uPresupuestosClienteReportController;
|
|||
|
|
|
|||
|
|
{ TPresupuestosClienteController }
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.Anadir(APedido: IBizPresupuestoCliente): Boolean;
|
|||
|
|
begin
|
|||
|
|
if not Assigned(APedido) then
|
|||
|
|
raise Exception.Create ('Pedido no asignado (Anadir)');
|
|||
|
|
APedido.Insert;
|
|||
|
|
Result := True;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.ArticulosPendientes(
|
|||
|
|
const ID: Integer): IBizPresupuestoClienteArticulosPend;
|
|||
|
|
begin
|
|||
|
|
Result := FDataModule.GetArticulosPendientes(ID);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.AsignarDataModule;
|
|||
|
|
begin
|
|||
|
|
FDataModule := TDataModulePresupuestosCliente.Create(Nil);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.AsignarID(APedido: IBizPresupuestoCliente; const IDNuevo : Integer);
|
|||
|
|
begin
|
|||
|
|
if not Assigned(APedido) then
|
|||
|
|
raise Exception.Create ('Pedido no asignado');
|
|||
|
|
|
|||
|
|
if not Assigned(APedido.Detalles) then
|
|||
|
|
raise Exception.Create ('Detalles de pedido no asignados');
|
|||
|
|
|
|||
|
|
if not Assigned(FDetallesController) then
|
|||
|
|
raise Exception.Create ('Controller detalles no asignado');
|
|||
|
|
|
|||
|
|
{ Los detalles siempre hay que comprobarlos }
|
|||
|
|
FDetallesController.AsignarID(APedido.Detalles, IDNuevo, APedido.EsNuevo);
|
|||
|
|
|
|||
|
|
if APedido.EsNuevo then
|
|||
|
|
begin
|
|||
|
|
APedido.Edit;
|
|||
|
|
APedido.ID := IDNuevo;
|
|||
|
|
APedido.Post;
|
|||
|
|
end;
|
|||
|
|
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;
|
|||
|
|
begin
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
Result := BuscarTodos;
|
|||
|
|
with Result.DataTable.Where do
|
|||
|
|
begin
|
|||
|
|
if NotEmpty then
|
|||
|
|
AddOperator(opAND);
|
|||
|
|
OpenBraket;
|
|||
|
|
AddText(fld_PedidosClienteSITUACION + ' <> ''' + SITUACION_PEDIDO_SERVIDO + '''');
|
|||
|
|
CloseBraket;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.BuscarPendientesPedir(
|
|||
|
|
const ID: Integer): IBizPresupuestoClienteArticulosPendientesPedirAProv;
|
|||
|
|
begin
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
Result := FDataModule.GetArticulosPendientesPedirAProv(ID);
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.CopiarDireccionEnvio(
|
|||
|
|
const ADireccionEnvio: IBizDireccionesContacto; APedido: IBizPresupuestoCliente);
|
|||
|
|
var
|
|||
|
|
bEnEdicion : Boolean;
|
|||
|
|
begin
|
|||
|
|
if not Assigned(APedido) then
|
|||
|
|
raise Exception.Create ('Pedido no asignado (CopiarDireccionEnvio)');
|
|||
|
|
|
|||
|
|
if not Assigned(ADireccionEnvio) then
|
|||
|
|
raise Exception.Create ('No se ha indicado la direcci<63>n (CopiarDireccionEnvio)');
|
|||
|
|
|
|||
|
|
if APedido.DataTable.Active then
|
|||
|
|
APedido.DataTable.Active := True;
|
|||
|
|
|
|||
|
|
if ADireccionEnvio.DataTable.Active then
|
|||
|
|
ADireccionEnvio.DataTable.Active := True;
|
|||
|
|
|
|||
|
|
|
|||
|
|
bEnEdicion := (APedido.DataTable.State in dsEditModes);
|
|||
|
|
if not bEnEdicion then
|
|||
|
|
APedido.Edit;
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
APedido.Edit;
|
|||
|
|
try
|
|||
|
|
APedido.CALLE := ADireccionEnvio.CALLE;
|
|||
|
|
APedido.POBLACION := ADireccionEnvio.POBLACION;
|
|||
|
|
APedido.CODIGO_POSTAL := ADireccionEnvio.CODIGO_POSTAL;
|
|||
|
|
APedido.PROVINCIA := ADireccionEnvio.PROVINCIA;
|
|||
|
|
APedido.TELEFONO := ADireccionEnvio.TELEFONO;
|
|||
|
|
APedido.PERSONA_CONTACTO := ADireccionEnvio.PERSONA_CONTACTO;
|
|||
|
|
|
|||
|
|
if not bEnEdicion then
|
|||
|
|
APedido.Post;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
constructor TPresupuestosClienteController.Create;
|
|||
|
|
begin
|
|||
|
|
AsignarDataModule;
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.DescartarCambios(APedido: IBizPresupuestoCliente);
|
|||
|
|
begin
|
|||
|
|
if not Assigned(APedido) then
|
|||
|
|
raise Exception.Create ('Pedido no asignada');
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
if (APedido.State in dsEditModes) then
|
|||
|
|
APedido.Cancel;
|
|||
|
|
|
|||
|
|
APedido.DataTable.CancelUpdates;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TPresupuestosClienteController.Destroy;
|
|||
|
|
begin
|
|||
|
|
FDataModule := Nil;
|
|||
|
|
FClienteController := Nil;
|
|||
|
|
FDetallesController := Nil;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.Duplicar(
|
|||
|
|
APedido: IBizPresupuestoCliente): IBizPresupuestoCliente;
|
|||
|
|
begin
|
|||
|
|
Result := Self._Vacio;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
DuplicarRegistros(APedido.DataTable, Result.DataTable, mdrActual);
|
|||
|
|
DuplicarRegistros(APedido.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;
|
|||
|
|
FECHA_PEDIDO := DateOf(Now);
|
|||
|
|
FECHA_PREVISTA_ENVIO := 0;
|
|||
|
|
INCIDENCIAS_ACTIVAS := 0;
|
|||
|
|
// INCIDENCIAS := Nil;
|
|||
|
|
REFERENCIA := '';
|
|||
|
|
// SetFieldNull(DataTable, fld_PedidosClienteREF_TIENDA_WEB);
|
|||
|
|
end;
|
|||
|
|
Result.Post;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.ValidarPedido(
|
|||
|
|
APedido: IBizPresupuestoCliente): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
if not Assigned(APedido) then
|
|||
|
|
raise Exception.Create ('Pedido no asignado');
|
|||
|
|
|
|||
|
|
if (APedido.DataTable.State in dsEditModes) then
|
|||
|
|
APedido.DataTable.Post;
|
|||
|
|
|
|||
|
|
//Tambien hacemos post de sus tablas hija
|
|||
|
|
if (APedido.Detalles.DataTable.State in dsEditModes) then
|
|||
|
|
APedido.Detalles.DataTable.Post;
|
|||
|
|
|
|||
|
|
// Abrir el cliente para la validaci<63>n
|
|||
|
|
if Assigned(APedido.Cliente) then
|
|||
|
|
APedido.Cliente.DataTable.Active := True;
|
|||
|
|
|
|||
|
|
if (APedido.ID_Cliente < 0) or
|
|||
|
|
(not Assigned(APedido.Cliente)) or
|
|||
|
|
(APedido.Cliente.IsEmpty) then
|
|||
|
|
raise Exception.Create('Debe indicar el cliente de este pedido');
|
|||
|
|
|
|||
|
|
if (EsFechaVacia(APedido.FECHA_PEDIDO)) then
|
|||
|
|
raise Exception.Create('Debe indicar la fecha de este pedido');
|
|||
|
|
|
|||
|
|
if (not EsFechaVacia(APedido.FECHA_PREVISTA_ENVIO)) then
|
|||
|
|
begin
|
|||
|
|
if (APedido.FECHA_PREVISTA_ENVIO < APedido.FECHA_PEDIDO) then
|
|||
|
|
raise Exception.Create('La fecha prevista de env<6E>o no puede ser anterior a la fecha del pedido');
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if (APedido.Detalles.DataTable.RecordCount = 0) then
|
|||
|
|
raise Exception.Create('El pedido debe tener en su contenido al menos un concepto');
|
|||
|
|
|
|||
|
|
{ Asegurarse de valores en campos "autom<6F>ticos" tanto
|
|||
|
|
en MODIFICACI<EFBFBD>N como en INSERCI<EFBFBD>N. }
|
|||
|
|
APedido.Edit;
|
|||
|
|
try
|
|||
|
|
// APedido.USUARIO := dmUsuarios.LoginInfo.Usuario;
|
|||
|
|
|
|||
|
|
if Assigned(APedido.Cliente)
|
|||
|
|
and (APedido.ID_CLIENTE <> APedido.Cliente.ID) then
|
|||
|
|
APedido.ID_CLIENTE := APedido.Cliente.ID;
|
|||
|
|
|
|||
|
|
Result := True;
|
|||
|
|
finally
|
|||
|
|
APedido.Post;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.Ver(APedido: IBizPresupuestoCliente);
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorPresupuestoCliente;
|
|||
|
|
begin
|
|||
|
|
AEditor := NIL;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
RecuperarObjetos(APedido);
|
|||
|
|
CreateEditor('EditorPresupuestoCliente', IEditorPresupuestoCliente, AEditor);
|
|||
|
|
|
|||
|
|
if Assigned(AEditor) then
|
|||
|
|
with AEditor do
|
|||
|
|
begin
|
|||
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|||
|
|
Pedido := APedido;
|
|||
|
|
|
|||
|
|
//MODO CONSULTAR
|
|||
|
|
if not EsModificable(APedido) then
|
|||
|
|
begin
|
|||
|
|
SetDataTableReadOnly(APedido.DataTable, True);
|
|||
|
|
ReadOnly := True;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
ShowModal;
|
|||
|
|
|
|||
|
|
//MODO CONSULTAR (Se deja la tabla como estaba)
|
|||
|
|
if ReadOnly then
|
|||
|
|
SetDataTableReadOnly(APedido.DataTable, False);
|
|||
|
|
|
|||
|
|
AEditor.Release;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
AEditor := NIL;
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.VerDireccionEntrega(
|
|||
|
|
APedido: IBizPresupuestoCliente);
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorDireccionEntregaPresupuestoCliente;
|
|||
|
|
begin
|
|||
|
|
AEditor := NIL;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
//RecuperarObjetos(APedido); <- No descomentar. No hace falta
|
|||
|
|
CreateEditor('EditorDireccionEntregaPresupuestoCliente', IEditorDireccionEntregaPresupuestoCliente, AEditor);
|
|||
|
|
|
|||
|
|
with (AEditor as IEditorDireccionEntregaPresupuestoCliente) do
|
|||
|
|
begin
|
|||
|
|
Pedido := APedido;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if Assigned(AEditor) then
|
|||
|
|
try
|
|||
|
|
AEditor.ShowModal;
|
|||
|
|
AEditor.Release;
|
|||
|
|
finally
|
|||
|
|
AEditor := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.VerTodos(APedidos: IBizPresupuestoCliente);
|
|||
|
|
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
|
|||
|
|
Pedidos := APedidos;
|
|||
|
|
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
|
|||
|
|
APedido : IBizPresupuestoCliente;
|
|||
|
|
begin
|
|||
|
|
APedido := Buscar(ID);
|
|||
|
|
|
|||
|
|
if not Assigned(APedido) then
|
|||
|
|
raise Exception.Create(Format('No se ha encontrado el pedido con ID = %d', [ID]));
|
|||
|
|
|
|||
|
|
Result := Eliminar(APedido);
|
|||
|
|
APedido := NIL;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.ElegirPedidos(APedido: IBizPresupuestoCliente; AMensaje: String; AMultiSelect: Boolean): IBizPresupuestoCliente;
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorElegirPresupuestosCliente;
|
|||
|
|
begin
|
|||
|
|
Result := NIL;
|
|||
|
|
|
|||
|
|
CreateEditor('EditorElegirPresupuestosCliente', IEditorElegirPresupuestosCliente, AEditor);
|
|||
|
|
try
|
|||
|
|
with AEditor do
|
|||
|
|
begin
|
|||
|
|
Controller := Self;
|
|||
|
|
Pedidos := APedido;
|
|||
|
|
MultiSelect := AMultiSelect;
|
|||
|
|
Mensaje := AMensaje;
|
|||
|
|
if IsPositiveResult(ShowModal) then
|
|||
|
|
Result := PresupuestosClienteSeleccionados;
|
|||
|
|
Release;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
AEditor := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.Eliminar(APedido: IBizPresupuestoCliente; AllItems: Boolean = false): Boolean;
|
|||
|
|
//En el caso de eliminar almenos un elemento del conjunto se devuelve true
|
|||
|
|
var
|
|||
|
|
bEliminado: Boolean;
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
bEliminado := False;
|
|||
|
|
|
|||
|
|
if not Assigned(APedido) then
|
|||
|
|
raise Exception.Create ('APedido no asignado');
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
if not APedido.DataTable.Active then
|
|||
|
|
APedido.DataTable.Active := True;
|
|||
|
|
|
|||
|
|
if (APedido.State in dsEditModes) then
|
|||
|
|
APedido.Cancel;
|
|||
|
|
|
|||
|
|
//Siempre eliminaremos el seleccionado
|
|||
|
|
if EsEliminable(APedido) then
|
|||
|
|
begin
|
|||
|
|
APedido.Delete;
|
|||
|
|
bEliminado := True;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
//En el caso de querer eliminar todos los items del objeto AAlbaran
|
|||
|
|
if AllItems then
|
|||
|
|
begin
|
|||
|
|
with APedido.DataTable do
|
|||
|
|
begin
|
|||
|
|
First;
|
|||
|
|
while not EOF do
|
|||
|
|
begin
|
|||
|
|
if EsEliminable(APedido) then
|
|||
|
|
begin
|
|||
|
|
APedido.Delete;
|
|||
|
|
bEliminado := True
|
|||
|
|
end
|
|||
|
|
else Next;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if bEliminado then
|
|||
|
|
begin
|
|||
|
|
APedido.DataTable.ApplyUpdates;
|
|||
|
|
Result := True;
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.EsEliminable(APedido: IBizPresupuestoCliente): Boolean;
|
|||
|
|
begin
|
|||
|
|
if not Assigned(APedido) then
|
|||
|
|
raise Exception.Create ('Pedido no asignado: EsEliminable');
|
|||
|
|
|
|||
|
|
Result := (APedido.SITUACION = SITUACION_PEDIDO_PENDIENTE);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.EsModificable(APedido: IBizPresupuestoCliente): Boolean;
|
|||
|
|
begin
|
|||
|
|
if not Assigned(APedido) then
|
|||
|
|
raise Exception.Create ('Pedido no asignado: EsModificable');
|
|||
|
|
|
|||
|
|
Result := (APedido.SITUACION <> SITUACION_PEDIDO_SERVIDO);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.RecalcularImportes(
|
|||
|
|
APedido: IBizPresupuestoCliente);
|
|||
|
|
var
|
|||
|
|
bEnEdicion : Boolean;
|
|||
|
|
begin
|
|||
|
|
if not Assigned(APedido) then
|
|||
|
|
raise Exception.Create ('Pedido no asignado (RecalcularImportes)');
|
|||
|
|
|
|||
|
|
if APedido.DataTable.Active then
|
|||
|
|
APedido.DataTable.Active := True;
|
|||
|
|
|
|||
|
|
bEnEdicion := (APedido.DataTable.State in dsEditModes);
|
|||
|
|
if not bEnEdicion then
|
|||
|
|
APedido.Edit;
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
APedido.Edit;
|
|||
|
|
try
|
|||
|
|
APedido.IMPORTE_NETO := FDetallesController.DarTotalImporteTotal(APedido.Detalles);
|
|||
|
|
APedido.IMPORTE_PORTE := FDetallesController.DarTotalPorteTotal(APedido.Detalles);
|
|||
|
|
if not bEnEdicion then
|
|||
|
|
APedido.Post;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable);
|
|||
|
|
var
|
|||
|
|
APedido : IBizPresupuestoCliente;
|
|||
|
|
ADetalles : IBizDetallesPresupuestoCliente;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
|
|||
|
|
if Supports(ADataTable, IBizDetallesPresupuestoCliente, ADetalles) and
|
|||
|
|
Supports(ADetalles.DataTable.MasterSource.DataTable, IBizPresupuestoCliente, APedido) then
|
|||
|
|
begin
|
|||
|
|
RecalcularImportes(APedido);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.RecuperarObjetos(APedido: IBizPresupuestoCliente);
|
|||
|
|
begin
|
|||
|
|
RecuperarCliente(APedido);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.RecuperarCliente(
|
|||
|
|
APedido: IBizPresupuestoCliente);
|
|||
|
|
begin
|
|||
|
|
APedido._Cliente := (FClienteController.Buscar(APedido.ID_Cliente) as IBizCliente);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.Existe(const ID: Integer): Boolean;
|
|||
|
|
var
|
|||
|
|
APedido : IBizPresupuestoCliente;
|
|||
|
|
begin
|
|||
|
|
try
|
|||
|
|
APedido := Buscar(ID);
|
|||
|
|
Result := Assigned(APedido) and (APedido.ID = ID);
|
|||
|
|
finally
|
|||
|
|
APedido := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.ExtraerSeleccionados(APedido: IBizPresupuestoCliente): IBizPresupuestoCliente;
|
|||
|
|
var
|
|||
|
|
ASeleccionados : IBizPresupuestoCliente;
|
|||
|
|
begin
|
|||
|
|
ASeleccionados := (Self.Buscar(ID_NULO) as IBizPresupuestoCliente);
|
|||
|
|
CopyDataTable(APedido.DataTable, ASeleccionados.DataTable, True);
|
|||
|
|
Result := ASeleccionados;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.FiltrarEmpresa(
|
|||
|
|
APedido: IBizPresupuestoCliente);
|
|||
|
|
begin
|
|||
|
|
if APedido.DataTable.Active then
|
|||
|
|
APedido.DataTable.Active := False;
|
|||
|
|
|
|||
|
|
// Filtrar los presupuestos actuales por empresa
|
|||
|
|
{ with APedido.DataTable.Where do
|
|||
|
|
begin
|
|||
|
|
if NotEmpty then
|
|||
|
|
AddOperator(opAND);
|
|||
|
|
AddCondition(fld_PedidosClienteID_EMPRESA, cEqual, dmUsuarios.IDEmpresaActual);
|
|||
|
|
end;
|
|||
|
|
}
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.SetClienteController(const Value: IClientesController);
|
|||
|
|
begin
|
|||
|
|
FClienteController := Value;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.SetDetallesController(const Value: IDetallesPresupuestoClienteController);
|
|||
|
|
begin
|
|||
|
|
FDetallesController := Value;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.Guardar(APedido: IBizPresupuestoCliente): Boolean;
|
|||
|
|
var
|
|||
|
|
IDNuevo: Integer;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
if not Assigned(APedido) then
|
|||
|
|
raise Exception.Create ('Pedido no asignada');
|
|||
|
|
|
|||
|
|
if not Assigned(FDetallesController) then
|
|||
|
|
raise Exception.Create ('Controller detalles no asignado');
|
|||
|
|
|
|||
|
|
if ValidarPedido(APedido) then
|
|||
|
|
begin
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
|
|||
|
|
// Asegurarnos de que todos los importes est<73>n bien.
|
|||
|
|
RecalcularImportes(APedido);
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
if (APedido.EsNuevo) then
|
|||
|
|
IDNuevo := FDataModule.GetNextID(APedido.DataTable.LogicalName)
|
|||
|
|
else
|
|||
|
|
IDNuevo := APedido.ID;
|
|||
|
|
|
|||
|
|
AsignarID(APedido, IDNuevo);
|
|||
|
|
APedido.DataTable.ApplyUpdates;
|
|||
|
|
|
|||
|
|
Result := True;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.Localizar(APedidos: IBizPresupuestoCliente;
|
|||
|
|
const ID: Integer): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := True;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
with APedidos.DataTable do
|
|||
|
|
begin
|
|||
|
|
DisableControls;
|
|||
|
|
First;
|
|||
|
|
if not Locate(fld_PedidosClienteID, ID, []) then
|
|||
|
|
Result := False;
|
|||
|
|
EnableControls;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.Nuevo: IBizPresupuestoCliente;
|
|||
|
|
var
|
|||
|
|
APedido : IBizPresupuestoCliente;
|
|||
|
|
begin
|
|||
|
|
APedido := FDataModule.NewItem;
|
|||
|
|
FiltrarEmpresa(APedido);
|
|||
|
|
APedido.DataTable.Active := True;
|
|||
|
|
APedido.Insert;
|
|||
|
|
Result := APedido;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.QuitarDireccionEnvio(
|
|||
|
|
APedido: IBizPresupuestoCliente);
|
|||
|
|
var
|
|||
|
|
bEnEdicion : Boolean;
|
|||
|
|
begin
|
|||
|
|
if not Assigned(APedido) then
|
|||
|
|
raise Exception.Create ('Pedido no asignado (QuitarDireccionEnvio)');
|
|||
|
|
|
|||
|
|
if APedido.DataTable.Active then
|
|||
|
|
APedido.DataTable.Active := True;
|
|||
|
|
|
|||
|
|
bEnEdicion := (APedido.DataTable.State in dsEditModes);
|
|||
|
|
if not bEnEdicion then
|
|||
|
|
APedido.Edit;
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
APedido.Edit;
|
|||
|
|
try
|
|||
|
|
APedido.DataTable.FieldByName(fld_PedidosClienteCALLE).Clear;
|
|||
|
|
APedido.DataTable.FieldByName(fld_PedidosClientePOBLACION).Clear;
|
|||
|
|
APedido.DataTable.FieldByName(fld_PedidosClienteCODIGO_POSTAL).Clear;
|
|||
|
|
APedido.DataTable.FieldByName(fld_PedidosClientePROVINCIA).Clear;
|
|||
|
|
APedido.DataTable.FieldByName(fld_PedidosClienteTELEFONO).Clear;
|
|||
|
|
APedido.DataTable.FieldByName(fld_PedidosClientePERSONA_CONTACTO).Clear;
|
|||
|
|
|
|||
|
|
if not bEnEdicion then
|
|||
|
|
APedido.Post;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.Preview(APedido: IBizPresupuestoCliente; AllItems: Boolean = false);
|
|||
|
|
var
|
|||
|
|
AReportController : IPresupuestosClienteReportController;
|
|||
|
|
ID_Pedidos: TStringList;
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
AReportController := TPresupuestosClienteReportController.Create;
|
|||
|
|
try
|
|||
|
|
ID_Pedidos := TStringList.Create;
|
|||
|
|
|
|||
|
|
//Si deseamos previsualizar todos los items del objeto albaran
|
|||
|
|
if AllItems then
|
|||
|
|
begin
|
|||
|
|
with APedido.DataTable do
|
|||
|
|
begin
|
|||
|
|
First;
|
|||
|
|
while not EOF do
|
|||
|
|
begin
|
|||
|
|
ID_Pedidos.Add(IntToStr(APedido.ID));
|
|||
|
|
Next;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end
|
|||
|
|
//Solo previsualizamos el item seleccionado
|
|||
|
|
else
|
|||
|
|
ID_Pedidos.Add(IntToStr(APedido.ID));
|
|||
|
|
|
|||
|
|
AReportController.Preview(ID_Pedidos.CommaText);
|
|||
|
|
|
|||
|
|
finally
|
|||
|
|
AReportController := NIL;
|
|||
|
|
ID_Pedidos.Free;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPresupuestosClienteController.Print(APedido: IBizPresupuestoCliente; AllItems: Boolean = false);
|
|||
|
|
var
|
|||
|
|
AReportController : IPresupuestosClienteReportController;
|
|||
|
|
ID_Pedidos: TStringList;
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
AReportController := TPresupuestosClienteReportController.Create;
|
|||
|
|
try
|
|||
|
|
ID_Pedidos := TStringList.Create;
|
|||
|
|
|
|||
|
|
//Si deseamos previsualizar todos los items del objeto albaran
|
|||
|
|
if AllItems then
|
|||
|
|
begin
|
|||
|
|
with APedido.DataTable do
|
|||
|
|
begin
|
|||
|
|
First;
|
|||
|
|
while not EOF do
|
|||
|
|
begin
|
|||
|
|
ID_Pedidos.Add(IntToStr(APedido.ID));
|
|||
|
|
Next;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end
|
|||
|
|
//Solo previsualizamos el item seleccionado
|
|||
|
|
else
|
|||
|
|
ID_Pedidos.Add(IntToStr(APedido.ID));
|
|||
|
|
|
|||
|
|
AReportController.Print(ID_Pedidos.CommaText);
|
|||
|
|
|
|||
|
|
finally
|
|||
|
|
AReportController := NIL;
|
|||
|
|
ID_Pedidos.Free;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.GetClienteController: IClientesController;
|
|||
|
|
begin
|
|||
|
|
Result := FClienteController;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPresupuestosClienteController.GetDetallesController: IDetallesPresupuestoClienteController;
|
|||
|
|
begin
|
|||
|
|
Result := FDetallesController;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|