git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@351 0c75b7a4-871f-7646-8a2f-f78d34cc349f
348 lines
9.6 KiB
ObjectPascal
348 lines
9.6 KiB
ObjectPascal
unit uProveedoresController;
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, uCustomEditor, uContactosController, uBizContactos, uBizDireccionesContacto, uDireccionesContactoController,
|
|
uIEditorProveedores, uIEditorProveedor, uIDataModuleContactos, uIDataModuleProveedores;
|
|
|
|
type
|
|
IProveedoresController = interface(IContactosController)
|
|
['{50F10D01-5120-470D-A61D-99FE8A76DF93}']
|
|
function BuscarSubcontratas: IBizProveedor;
|
|
function BuscarTodosTiendaWeb: IBizProveedor;
|
|
function ElegirDireccionEntrega(ADirecciones: IBizDireccionesContacto; AMensaje: String): IBizDireccionesContacto;
|
|
function EsEliminable(AProveedor: IBizContacto): Boolean;
|
|
function Eliminar(AProveedor: IBizContacto; AllItems: Boolean = false): Boolean; overload;
|
|
procedure Preview(AProveedor : IBizProveedor; AllItems: Boolean = false);
|
|
procedure Print(AProveedor : IBizProveedor; AllItems: Boolean = false);
|
|
function DarListaDescripcionesProveedores: TStringList;
|
|
end;
|
|
|
|
TProveedoresController = class(TContactosController, IProveedoresController)
|
|
protected
|
|
FDireccionesController : IDireccionesContactoController;
|
|
|
|
public
|
|
constructor Create; override;
|
|
destructor Destroy; override;
|
|
|
|
function Buscar(const ID: Integer): IBizContacto; override;
|
|
function BuscarTodos: IBizContacto; override;
|
|
function BuscarTodosTiendaWeb: IBizProveedor;
|
|
function BuscarSubcontratas: IBizProveedor;
|
|
function Nuevo : IBizContacto; override;
|
|
procedure Ver(AContacto : IBizContacto); override;
|
|
procedure VerTodos(AContactos: IBizContacto); override;
|
|
function ElegirContacto(AContactos : IBizContacto;
|
|
AMensaje: String; AMultiSelect: Boolean): IBizContacto; override;
|
|
function ElegirDireccionEntrega(ADirecciones: IBizDireccionesContacto;
|
|
AMensaje: String): IBizDireccionesContacto;
|
|
function EsEliminable(AProveedor: IBizContacto): Boolean;
|
|
function Eliminar(AProveedor: IBizContacto; AllItems: Boolean = false): Boolean; overload;
|
|
procedure Preview(AProveedor : IBizProveedor; AllItems: Boolean = false);
|
|
procedure Print(AProveedor : IBizProveedor; AllItems: Boolean = false);
|
|
function DarListaDescripcionesProveedores: TStringList;
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
SysUtils, cxControls, Dialogs, uDataModuleProveedores, uEditorRegistryUtils,
|
|
uDataTableUtils, uDADataTable, DB, schContactosClient_Intf, uEtiquetasContactosReportController,
|
|
uIEditorElegirProveedores, Controls, uIEditorElegirDireccionEntrega,
|
|
uEditorGridBase, uDAInterfaces;
|
|
|
|
{ TProveedoresController }
|
|
|
|
function TProveedoresController.Buscar(const ID: Integer): IBizContacto;
|
|
begin
|
|
Result := (FDataModule as IDataModuleProveedores).GetItem(ID);
|
|
FiltrarEmpresa(Result);
|
|
end;
|
|
|
|
function TProveedoresController.BuscarSubcontratas: IBizProveedor;
|
|
var
|
|
Condicion: TDAWhereExpression;
|
|
begin
|
|
Result := BuscarTodos as IBizProveedor;
|
|
with Result.DataTable.DynamicWhere do
|
|
begin
|
|
Condicion := NewBinaryExpression(NewField('', fld_ProveedoresSUBCONTRATA), NewConstant(1, datInteger), dboEqual);
|
|
Clear;
|
|
Expression := Condicion
|
|
end;
|
|
end;
|
|
|
|
function TProveedoresController.BuscarTodos: IBizContacto;
|
|
begin
|
|
Result := (FDataModule as IDataModuleProveedores).GetItems;
|
|
FiltrarEmpresa(Result);
|
|
end;
|
|
|
|
function TProveedoresController.BuscarTodosTiendaWeb: IBizProveedor;
|
|
begin
|
|
Result := (FDataModule as IDataModuleProveedores).GetItemsTiendaWeb;
|
|
FiltrarEmpresa(Result);
|
|
end;
|
|
|
|
constructor TProveedoresController.Create;
|
|
begin
|
|
inherited;
|
|
FDataModule := TDataModuleProveedores.Create(Nil);
|
|
FDireccionesController := TDireccionesContactoController.Create;
|
|
end;
|
|
|
|
function TProveedoresController.DarListaDescripcionesProveedores: TStringList;
|
|
begin
|
|
Result := (FDataModule as IDataModuleProveedores).DarListaDescripcionesProveedores;
|
|
end;
|
|
|
|
destructor TProveedoresController.Destroy;
|
|
begin
|
|
FDireccionesController := NIL;
|
|
inherited;
|
|
end;
|
|
|
|
function TProveedoresController.ElegirContacto(AContactos: IBizContacto;
|
|
AMensaje: String; AMultiSelect: Boolean): IBizContacto;
|
|
var
|
|
AEditor : IEditorElegirProveedores;
|
|
begin
|
|
Result := NIL;
|
|
ShowHourglassCursor;
|
|
try
|
|
CreateEditor('EditorElegirProveedores', IEditorElegirProveedores, AEditor);
|
|
if Assigned(AEditor) then
|
|
with AEditor do
|
|
begin
|
|
Contactos := AContactos;
|
|
Controller := Self;
|
|
MultiSelect := AMultiSelect;
|
|
Mensaje := AMensaje;
|
|
if IsPositiveResult(ShowModal) then
|
|
Result := ContactosSeleccionados;
|
|
Release;
|
|
end;
|
|
finally
|
|
AEditor := NIL;
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TProveedoresController.ElegirDireccionEntrega(ADirecciones: IBizDireccionesContacto;
|
|
AMensaje: String): IBizDireccionesContacto;
|
|
var
|
|
AEditor : IEditorElegirDireccionEntrega;
|
|
begin
|
|
Result := NIL;
|
|
ShowHourglassCursor;
|
|
try
|
|
CreateEditor('EditorElegirDireccionEntrega', IEditorElegirDireccionEntrega, AEditor);
|
|
if Assigned(AEditor) then
|
|
with AEditor do
|
|
begin
|
|
Direccion := ADirecciones;
|
|
Mensaje := AMensaje;
|
|
if IsPositiveResult(ShowModal) then
|
|
Result := DireccionSeleccionada;
|
|
Release;
|
|
end;
|
|
finally
|
|
AEditor := NIL;
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TProveedoresController.Eliminar(AProveedor: IBizContacto; AllItems: Boolean): Boolean;
|
|
//En el caso de eliminar almenos un elemento del conjunto se devuelve true
|
|
var
|
|
bEliminado: Boolean;
|
|
|
|
begin
|
|
Result := False;
|
|
|
|
if not Assigned(AProveedor) then
|
|
raise Exception.Create ('Contacto no asignado');
|
|
|
|
ShowHourglassCursor;
|
|
try
|
|
if not AProveedor.DataTable.Active then
|
|
AProveedor.DataTable.Active := True;
|
|
|
|
if (AProveedor.State in dsEditModes) then
|
|
AProveedor.Cancel;
|
|
|
|
//Siempre eliminaremos el seleccionado
|
|
if EsEliminable(AProveedor) then
|
|
begin
|
|
AProveedor.Delete;
|
|
bEliminado := True;
|
|
end;
|
|
|
|
//En el caso de querer eliminar todos los items del objeto AProveedor
|
|
if AllItems then
|
|
begin
|
|
with AProveedor.DataTable do
|
|
begin
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
if EsEliminable(AProveedor) then
|
|
begin
|
|
AProveedor.Delete;
|
|
bEliminado := True
|
|
end
|
|
else Next;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
if bEliminado then
|
|
begin
|
|
AProveedor.DataTable.ApplyUpdates;
|
|
Result := True;
|
|
end
|
|
else
|
|
Result := False;
|
|
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TProveedoresController.EsEliminable(AProveedor: IBizContacto): Boolean;
|
|
begin
|
|
if not Assigned(AProveedor) then
|
|
raise Exception.Create ('Contacto no asignado: EsEliminable');
|
|
|
|
Result := True;
|
|
end;
|
|
|
|
function TProveedoresController.Nuevo: IBizContacto;
|
|
var
|
|
AContacto : IBizProveedor;
|
|
begin
|
|
AContacto := (FDataModule as IDataModuleProveedores).NewItem;
|
|
FiltrarEmpresa(AContacto);
|
|
AContacto.DataTable.Active := True;
|
|
AContacto.Insert;
|
|
Result := AContacto;
|
|
end;
|
|
|
|
procedure TProveedoresController.Preview(AProveedor: IBizProveedor; AllItems: Boolean);
|
|
var
|
|
AReportController : IEtiquetasContactosReportController;
|
|
ListaID: TStringList;
|
|
|
|
begin
|
|
AReportController := TEtiquetasContactosReportController.Create;
|
|
try
|
|
ListaID := TStringList.Create;
|
|
|
|
//Si deseamos previsualizar todos los items del objeto albaran
|
|
if AllItems then
|
|
begin
|
|
with AProveedor.DataTable do
|
|
begin
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
ListaID.Add(IntToStr(AProveedor.ID));
|
|
Next;
|
|
end;
|
|
end;
|
|
end
|
|
//Solo previsualizamos el item seleccionado
|
|
else
|
|
ListaID.Add(IntToStr(AProveedor.ID));
|
|
|
|
AReportController.Preview(ListaID.CommaText);
|
|
|
|
finally
|
|
AReportController := NIL;
|
|
ListaID.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TProveedoresController.Print(AProveedor: IBizProveedor; AllItems: Boolean);
|
|
var
|
|
AReportController : IEtiquetasContactosReportController;
|
|
ListaID: TStringList;
|
|
|
|
begin
|
|
AReportController := TEtiquetasContactosReportController.Create;
|
|
try
|
|
ListaID := TStringList.Create;
|
|
|
|
//Si deseamos previsualizar todos los items del objeto albaran
|
|
if AllItems then
|
|
begin
|
|
with AProveedor.DataTable do
|
|
begin
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
ListaID.Add(IntToStr(AProveedor.ID));
|
|
Next;
|
|
end;
|
|
end;
|
|
end
|
|
//Solo previsualizamos el item seleccionado
|
|
else
|
|
ListaID.Add(IntToStr(AProveedor.ID));
|
|
|
|
AReportController.Print(ListaID.CommaText);
|
|
|
|
finally
|
|
AReportController := NIL;
|
|
ListaID.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TProveedoresController.Ver(AContacto: IBizContacto);
|
|
var
|
|
AEditor : IEditorProveedor;
|
|
begin
|
|
AEditor := NIL;
|
|
ShowHourglassCursor;
|
|
try
|
|
CreateEditor('EditorProveedor', IEditorProveedor, AEditor);
|
|
if Assigned(AEditor) then
|
|
with AEditor do
|
|
begin
|
|
Contacto := AContacto;
|
|
Controller := Self;
|
|
ShowModal;
|
|
Release;
|
|
end;
|
|
finally
|
|
AEditor := NIL;
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
procedure TProveedoresController.VerTodos(AContactos: IBizContacto);
|
|
var
|
|
AEditor : IEditorProveedores;
|
|
begin
|
|
AEditor := NIL;
|
|
ShowHourglassCursor;
|
|
try
|
|
CreateEditor('EditorProveedores', IEditorProveedores, AEditor);
|
|
if Assigned(AEditor) then
|
|
with AEditor do
|
|
begin
|
|
Contactos := AContactos;
|
|
Controller := Self;
|
|
MultiSelect := True;
|
|
ShowEmbedded;
|
|
end;
|
|
finally
|
|
AEditor := NIL;
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
end.
|