git-svn-id: https://192.168.0.254/svn/Proyectos.AlonsoYSal_FactuGES2/trunk@25 40301925-124e-1c4e-b97d-170ad7a8785b
1200 lines
42 KiB
ObjectPascal
1200 lines
42 KiB
ObjectPascal
unit uContratosClienteController;
|
||
|
||
interface
|
||
|
||
|
||
uses
|
||
Classes, uROTypes, SysUtils, uDADataTable, uEditorDBItem,
|
||
uControllerBase, uIDataModuleContratosCliente, uClientesController,
|
||
uDetallesContratoClienteController, uGestorDocumentosController,
|
||
uBizContratosCliente, uBizDireccionesContacto, uBizDetallesContratoCliente,
|
||
uIntegerListUtils;
|
||
|
||
type
|
||
TEnumTiposContrato = (teCocina, teArmario, teBano, teElectrodomestico, teObra, teVarios);
|
||
|
||
IContratosClienteController = interface(IControllerBase)
|
||
['{D6544299-A233-4FF0-BDA4-328DA06DCFD8}']
|
||
function GetClienteController: IClientesController;
|
||
procedure SetClienteController(const Value: IClientesController);
|
||
property ClienteController: IClientesController read GetClienteController write SetClienteController;
|
||
|
||
function GetDetallesController: IDetallesContratoClienteController;
|
||
procedure SetDetallesController(const Value: IDetallesContratoClienteController);
|
||
property DetallesController: IDetallesContratoClienteController read GetDetallesController write SetDetallesController;
|
||
|
||
//GESTION_DOCUMENTOS
|
||
function GetGestorDocumentosController: IGestorDocumentosController;
|
||
procedure SetGestorDocumentosController(const Value: IGestorDocumentosController);
|
||
property GestorDocumentosController: IGestorDocumentosController read GetGestorDocumentosController write SetGestorDocumentosController;
|
||
|
||
procedure RecuperarCliente(AContrato : IBizContratoCliente);
|
||
function Buscar(const ID: Integer): IBizContratoCliente; overload;
|
||
function Buscar(const ListaID: TIntegerList): IBizContratoCliente; overload;
|
||
function BuscarTodos: IBizContratoCliente; overload;
|
||
function BuscarTodos(const ID_Cliente: Integer): IBizContratoCliente; overload;
|
||
procedure Ver(AContrato : IBizContratoCliente); overload;
|
||
procedure Ver(const ID: Integer); overload;
|
||
procedure VerTodos(AContratos: IBizContratoCliente;
|
||
const AVerModal : Boolean = False; const AWindowCaption: String = '';
|
||
const AHeaderText: String = '');
|
||
function Nuevo : IBizContratoCliente;
|
||
function Anadir(AContrato : IBizContratoCliente; const ATipo: TEnumTiposContrato = teVarios) : Boolean;
|
||
function Eliminar(const ID : Integer): Boolean; overload;
|
||
function Eliminar(AContrato : IBizContratoCliente; AllItems: Boolean = false): Boolean; overload;
|
||
function Guardar(AContrato : IBizContratoCliente): Boolean;
|
||
procedure DescartarCambios(AContrato : IBizContratoCliente);
|
||
function Existe(const ID: Integer) : Boolean;
|
||
function Duplicar(AContrato: IBizContratoCliente): IBizContratoCliente;
|
||
|
||
function Localizar(AContratos: IBizContratoCliente; const ID : Integer): Boolean;
|
||
function ExtraerSeleccionados(AContrato: IBizContratoCliente) : IBizContratoCliente;
|
||
function ElegirContratos(AContrato: IBizContratoCliente; AMensaje: String; AMultiSelect: Boolean): IBizContratoCliente;
|
||
|
||
procedure RecalcularImportes(AContrato : IBizContratoCliente);
|
||
function EsModificable(AContrato : IBizContratoCliente): Boolean;
|
||
function EsEliminable(AContrato : IBizContratoCliente): Boolean;
|
||
|
||
procedure Preview(AContrato : IBizContratoCliente; AllItems: Boolean = false; AVerCondiciones: Boolean = false);
|
||
procedure Print(AContrato : IBizContratoCliente; AllItems: Boolean = false; AVerCondiciones: Boolean = false);
|
||
procedure EnviarContratoPorEMail(AContrato : IBizContratoCliente);
|
||
function CambiarSituacion(AContrato : IBizContratoCliente; Situacion: String; FechaDecision: TDateTime; AllItems: Boolean = false): Boolean;
|
||
function AsignarLOPD(AContratos: IBizContratoCliente): Boolean;
|
||
|
||
function DarListaAnosContratos: TStringList;
|
||
procedure FiltrarAno(AContrato: IBizContratoCliente; ADynWhereDataTable: WideString; const Ano: String);
|
||
procedure VerListadoBeneficios;
|
||
procedure VerPedidosProveedor(AContrato : IBizContratoCliente);
|
||
procedure VerFacturasProveedor(AContrato : IBizContratoCliente);
|
||
|
||
procedure CopiarDireccion (const ADireccion: IBizDireccionesContacto; AContrato: IBizContratoCliente);
|
||
end;
|
||
|
||
TContratosClienteController = class(TControllerBase, IContratosClienteController)
|
||
protected
|
||
FDataModule : IDataModuleContratosCliente;
|
||
FClienteController : IClientesController;
|
||
FDetallesController : IDetallesContratoClienteController;
|
||
FGestorDocumentosController : IGestorDocumentosController;
|
||
|
||
function GetClienteController: IClientesController;
|
||
procedure SetClienteController(const Value: IClientesController);
|
||
function GetDetallesController: IDetallesContratoClienteController;
|
||
procedure SetDetallesController(const Value: IDetallesContratoClienteController);
|
||
|
||
//GESTION_DOCUMENTOS
|
||
function GetGestorDocumentosController: IGestorDocumentosController;
|
||
procedure SetGestorDocumentosController(const Value: IGestorDocumentosController);
|
||
|
||
//Estos son los tres m<>todos a sobre escribir si se desea heredar toda la logica de
|
||
//este controller
|
||
procedure AsignarDataModule; virtual;
|
||
procedure RecuperarObjetos(AContrato: IBizContratoCliente); virtual;
|
||
|
||
procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override;
|
||
function CreateEditor(const AName : String; const IID: TGUID; out Intf): Boolean;
|
||
procedure FiltrarEmpresa(AContrato: IBizContratoCliente);
|
||
function _Vacio : IBizContratoCliente;
|
||
function ValidarContrato(AContrato: IBizContratoCliente): Boolean;
|
||
procedure RellenarValoresDefecto(AContrato: IBizContratoCliente; ATipo: TEnumTiposContrato);
|
||
public
|
||
property ClienteController: IClientesController read GetClienteController write SetClienteController;
|
||
property DetallesController: IDetallesContratoClienteController read GetDetallesController write SetDetallesController;
|
||
property GestorDocumentosController: IGestorDocumentosController read GetGestorDocumentosController write SetGestorDocumentosController;
|
||
|
||
constructor Create; override;
|
||
destructor Destroy; override;
|
||
|
||
function Localizar(AContratos: IBizContratoCliente; const ID : Integer): Boolean;
|
||
|
||
procedure RecuperarCliente(AContrato : IBizContratoCliente);
|
||
function Eliminar(const ID : Integer): Boolean; overload;
|
||
function Eliminar(AContrato : IBizContratoCliente; AllItems: Boolean = false): Boolean; overload;
|
||
function Guardar(AContrato : IBizContratoCliente): Boolean;
|
||
procedure DescartarCambios(AContrato : IBizContratoCliente); virtual;
|
||
function Existe(const ID: Integer) : Boolean; virtual;
|
||
function Anadir(AContrato : IBizContratoCliente; const ATipo: TEnumTiposContrato = teVarios) : Boolean;
|
||
function Buscar(const ListaID: TIntegerList): IBizContratoCliente; overload;
|
||
function Buscar(const ID: Integer): IBizContratoCliente; overload;
|
||
function BuscarTodos: IBizContratoCliente; overload;
|
||
function BuscarTodos(const ID_Cliente: Integer): IBizContratoCliente; overload;
|
||
function Nuevo : IBizContratoCliente;
|
||
procedure Ver(AContrato : IBizContratoCliente); overload;
|
||
procedure Ver(const ID: Integer); overload;
|
||
procedure VerTodos(AContratos: IBizContratoCliente;
|
||
const AVerModal : Boolean = False; const AWindowCaption: String = '';
|
||
const AHeaderText: String = '');
|
||
function Duplicar(AContrato: IBizContratoCliente): IBizContratoCliente;
|
||
|
||
function ExtraerSeleccionados(AContrato: IBizContratoCliente) : IBizContratoCliente;
|
||
function ElegirContratos(AContrato: IBizContratoCliente; AMensaje: String; AMultiSelect: Boolean): IBizContratoCliente;
|
||
|
||
procedure RecalcularImportes(AContrato : IBizContratoCliente);
|
||
function EsModificable(AContrato : IBizContratoCliente): Boolean;
|
||
function EsEliminable(AContrato : IBizContratoCliente): Boolean;
|
||
|
||
procedure Preview(AContrato : IBizContratoCliente; AllItems: Boolean = false; AVerCondiciones: Boolean = false);
|
||
procedure Print(AContrato : IBizContratoCliente; AllItems: Boolean = false; AVerCondiciones: Boolean = false);
|
||
procedure EnviarContratoPorEMail(AContrato : IBizContratoCliente);
|
||
function CambiarSituacion(AContrato : IBizContratoCliente; Situacion: String; FechaDecision: TDateTime; AllItems: Boolean = false): Boolean;
|
||
function AsignarLOPD(AContratos: IBizContratoCliente): Boolean;
|
||
|
||
function DarListaAnosContratos: TStringList;
|
||
procedure FiltrarAno(AContrato: IBizContratoCliente; ADynWhereDataTable: WideString; const Ano: String);
|
||
procedure VerListadoBeneficios;
|
||
procedure VerPedidosProveedor(AContrato : IBizContratoCliente);
|
||
procedure VerFacturasProveedor(AContrato : IBizContratoCliente);
|
||
|
||
procedure CopiarDireccion (const ADireccion: IBizDireccionesContacto; AContrato: IBizContratoCliente);
|
||
end;
|
||
|
||
implementation
|
||
|
||
uses
|
||
Controls, cxControls, DB, uEditorRegistryUtils, uEditorPreview, DateUtils,
|
||
uIEditorContratosCliente, uDataModuleContratosCliente, Variants,
|
||
uBizContactos, uDataTableUtils, uDataModuleUsuarios, uFactuGES_App,
|
||
schContratosClienteClient_Intf, uDAInterfaces, uDateUtils, uIEditorContratoCliente,
|
||
uIEditorElegirContratosCliente, uIEditorDireccionEntregaContratoCliente,
|
||
schContactosClient_Intf, uContratosClienteReportController, FactuGES_Intf,
|
||
uSistemaFunc, uEMailUtils, uDialogElegirEMail, Dialogs, uStringsUtils,
|
||
uIEditorContratosClienteBeneficios, uPresupuestosClienteController,
|
||
uConfiguracionController, uBizDetallesPresupuestoCliente, uModuleController, uPlugins_Intf;
|
||
|
||
{ TContratosClienteController }
|
||
|
||
function TContratosClienteController.Anadir(AContrato : IBizContratoCliente;
|
||
const ATipo: TEnumTiposContrato = teVarios) : Boolean;
|
||
begin
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create ('Contrato no asignado (Anadir)');
|
||
AContrato.Insert;
|
||
RellenarValoresDefecto(AContrato, ATipo);
|
||
Result := True;
|
||
end;
|
||
|
||
{
|
||
procedure TContratosClienteController.SincronizarDocumentos(const ID: Integer; FListaDocumentos: TStringList; Directorio: String);
|
||
var
|
||
ListaDocumentosServidor: TStringList;
|
||
ANombreFichero: String;
|
||
AFichero: Binary;
|
||
i, j: Integer;
|
||
begin
|
||
//Eliminamos todos los documentos del servidor que ya no existan en el cliente.
|
||
ListaDocumentosServidor := DarListaDocumentos(ID);
|
||
for i:= 0 to ListaDocumentosServidor.Count - 1 do
|
||
if not FListaDocumentos.Find(ListaDocumentosServidor.Strings[i], j) then
|
||
if not FDataModule.EliminarFichero(ID, ListaDocumentosServidor.Strings[i]) then
|
||
showmessage('Error al borrar fichero' + ListaDocumentosServidor.Strings[i]);
|
||
|
||
//Subimos todos los ficheros que halla al servidor (de momento no se miran fechas)
|
||
for i := 0 to FListaDocumentos.Count - 1 do
|
||
begin
|
||
ANombreFichero := Directorio + FListaDocumentos.Strings[i];
|
||
if FileExists(ANombreFichero) then
|
||
begin
|
||
AFichero := Binary.Create;
|
||
AFichero.LoadFromFile(ANombreFichero);
|
||
SubirFichero(ID, ExtractFileName(ANombreFichero), AFichero);
|
||
end;
|
||
end;
|
||
end;
|
||
}
|
||
|
||
procedure TContratosClienteController.AsignarDataModule;
|
||
begin
|
||
FDataModule := TDataModuleContratosCliente.Create(Nil);
|
||
end;
|
||
|
||
function TContratosClienteController.AsignarLOPD(AContratos: IBizContratoCliente): Boolean;
|
||
var
|
||
ACliente : IBizCliente;
|
||
AResultado : Boolean;
|
||
begin
|
||
Result := false;
|
||
if Assigned(AContratos) then
|
||
begin
|
||
with AContratos.DataTable do
|
||
begin
|
||
First;
|
||
while not EOF do
|
||
begin
|
||
ACliente := (FClienteController.Buscar(AContratos.ID_Cliente) as IBizCliente);
|
||
AResultado := FClienteController.AsignarLOPD(ACliente);
|
||
if not Result then
|
||
Result := AResultado;
|
||
Next;
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
function TContratosClienteController.Buscar(const ID: Integer): IBizContratoCliente;
|
||
begin
|
||
Result := FDataModule.GetItem(ID);
|
||
FiltrarEmpresa(Result);
|
||
end;
|
||
|
||
function TContratosClienteController.BuscarTodos: IBizContratoCliente;
|
||
begin
|
||
Result := FDataModule.GetItems;
|
||
FiltrarEmpresa(Result);
|
||
end;
|
||
|
||
function TContratosClienteController.Buscar(
|
||
const ListaID: TIntegerList): IBizContratoCliente;
|
||
begin
|
||
Result := FDataModule.GetItems(ListaID);
|
||
FiltrarEmpresa(Result);
|
||
end;
|
||
|
||
function TContratosClienteController.BuscarTodos(
|
||
const ID_Cliente: Integer): IBizContratoCliente;
|
||
var
|
||
Condicion: TDAWhereExpression;
|
||
begin
|
||
ShowHourglassCursor;
|
||
try
|
||
Result := BuscarTodos;
|
||
|
||
with Result.DataTable.DynamicWhere do
|
||
begin
|
||
// ID_CLIENTE
|
||
Condicion := NewBinaryExpression(NewField('', fld_ContratosClienteID_CLIENTE), NewConstant(ID_Cliente, datInteger), dboEqual);
|
||
|
||
if IsEmpty then
|
||
Expression := Condicion
|
||
else
|
||
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
||
end;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
function TContratosClienteController.CambiarSituacion(AContrato: IBizContratoCliente;
|
||
Situacion: String; FechaDecision: TDateTime; AllItems: Boolean): Boolean;
|
||
// En el caso de cambiar almenos un elemento del conjunto se devuelve true
|
||
begin
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create ('AContrato no asignado');
|
||
|
||
ShowHourglassCursor;
|
||
try
|
||
if not AContrato.DataTable.Active then
|
||
AContrato.DataTable.Active := True;
|
||
|
||
if (AContrato.State in dsEditModes) then
|
||
AContrato.Cancel;
|
||
|
||
//Siempre cambiaremos de situacion el seleccionado
|
||
if AContrato.SITUACION <> Situacion then
|
||
begin
|
||
AContrato.DataTable.Edit;
|
||
AContrato.SITUACION := Situacion;
|
||
AContrato.FECHA_DECISION := FechaDecision;
|
||
AContrato.DataTable.Post;
|
||
end;
|
||
|
||
//En el caso de querer eliminar todos los items del objeto AContrato
|
||
if AllItems then
|
||
begin
|
||
with AContrato.DataTable do
|
||
begin
|
||
First;
|
||
while not EOF do
|
||
begin
|
||
if AContrato.SITUACION <> Situacion then
|
||
begin
|
||
AContrato.DataTable.Edit;
|
||
AContrato.SITUACION := Situacion;
|
||
AContrato.FECHA_DECISION := FechaDecision;
|
||
AContrato.DataTable.Post;
|
||
end;
|
||
Next;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
AContrato.DataTable.ApplyUpdates;
|
||
Result := True;
|
||
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.CopiarDireccion(
|
||
const ADireccion: IBizDireccionesContacto;
|
||
AContrato: IBizContratoCliente);
|
||
var
|
||
bEnEdicion : Boolean;
|
||
begin
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create ('Contrato no asignado (CopiarDireccion)');
|
||
|
||
if not Assigned(ADireccion) then
|
||
raise Exception.Create ('No se ha indicado la direcci<63>n (CopiarDireccion)');
|
||
|
||
if AContrato.DataTable.Active then
|
||
AContrato.DataTable.Active := True;
|
||
|
||
if ADireccion.DataTable.Active then
|
||
ADireccion.DataTable.Active := True;
|
||
|
||
bEnEdicion := (AContrato.DataTable.State in dsEditModes);
|
||
if not bEnEdicion then
|
||
AContrato.Edit;
|
||
|
||
ShowHourglassCursor;
|
||
AContrato.Edit;
|
||
try
|
||
AContrato.CALLE := ADireccion.CALLE;
|
||
AContrato.POBLACION := ADireccion.POBLACION;
|
||
AContrato.CODIGO_POSTAL := ADireccion.CODIGO_POSTAL;
|
||
AContrato.PROVINCIA := ADireccion.PROVINCIA;
|
||
AContrato.NIF_CIF := ADireccion.NIF_CIF;
|
||
AContrato.NOMBRE := ADireccion.NOMBRE;
|
||
|
||
if not bEnEdicion then
|
||
AContrato.Post;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
constructor TContratosClienteController.Create;
|
||
begin
|
||
inherited;
|
||
AsignarDataModule;
|
||
|
||
FClienteController := TClientesController.Create;
|
||
FDetallesController := TDetallesContratoClienteController.Create;
|
||
|
||
//GESTION_DOCUMENTOS
|
||
FGestorDocumentosController := TGestorDocumentosController.Create;
|
||
FGestorDocumentosController.Almacen := TRdxAlmacenes_Presupuestos;
|
||
|
||
FDetallesController.addObservador(Self);
|
||
end;
|
||
|
||
function TContratosClienteController.CreateEditor(const AName: String;
|
||
const IID: TGUID; out Intf): Boolean;
|
||
begin
|
||
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
|
||
end;
|
||
|
||
{
|
||
function TContratosClienteController.DarListaDocumentos(const ID: Integer): TStringList;
|
||
begin
|
||
Result := FDataModule.DarListaDocumentos(ID);
|
||
end;
|
||
|
||
function TContratosClienteController.DescargarFichero(const ID: Integer; const NombreFichero: String; const DestinoFichero: String): Boolean;
|
||
begin
|
||
Result := FDataModule.DescargarFichero(ID, NombreFichero, DestinoFichero);
|
||
end;
|
||
}
|
||
|
||
function TContratosClienteController.DarListaAnosContratos: TStringList;
|
||
begin
|
||
Result := FDataModule.GetAnosItems;
|
||
end;
|
||
|
||
procedure TContratosClienteController.DescartarCambios(AContrato: IBizContratoCliente);
|
||
begin
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create ('Contrato no asignada');
|
||
|
||
ShowHourglassCursor;
|
||
try
|
||
if (AContrato.State in dsEditModes) then
|
||
AContrato.Cancel;
|
||
|
||
AContrato.DataTable.CancelUpdates;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
destructor TContratosClienteController.Destroy;
|
||
begin
|
||
FDataModule := Nil;
|
||
FClienteController := Nil;
|
||
FDetallesController := Nil;
|
||
|
||
//GESTION_DOCUMENTOS
|
||
FGestorDocumentosController := Nil;
|
||
inherited;
|
||
end;
|
||
|
||
function TContratosClienteController.Duplicar(
|
||
AContrato: IBizContratoCliente): IBizContratoCliente;
|
||
begin
|
||
Result := Self._Vacio;
|
||
ShowHourglassCursor;
|
||
try
|
||
DuplicarRegistros(AContrato.DataTable, Result.DataTable, mdrActual);
|
||
DuplicarRegistros(AContrato.Detalles.DataTable, Result.Detalles.DataTable, mdrTodos);
|
||
|
||
// Hay que dejar algunos campos como si fuera un contrato nuevo
|
||
Result.Edit;
|
||
with Result do
|
||
begin
|
||
ID_EMPRESA := AppFactuGES.EmpresaActiva.ID;
|
||
USUARIO := AppFactuGES.UsuarioActivo.UserName;
|
||
ID_TIENDA := AppFactuGES.TiendaActiva.ID;
|
||
TIENDA := AppFactuGES.TiendaActiva.NOMBRE;
|
||
FECHA_CONTRATO := DateOf(Now);
|
||
INCIDENCIAS_ACTIVAS := 0;
|
||
INCIDENCIASIsNull := True;
|
||
// ID_FACTURAIsNull := True;
|
||
REFERENCIA := '';
|
||
SITUACION := SITUACION_CONTRATO_PENDIENTE;
|
||
end;
|
||
Result.AsignarVendedor;
|
||
Result.Post;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
function TContratosClienteController.ValidarContrato(
|
||
AContrato: IBizContratoCliente): Boolean;
|
||
begin
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create ('Contrato no asignado');
|
||
|
||
if (AContrato.DataTable.State in dsEditModes) then
|
||
AContrato.DataTable.Post;
|
||
|
||
//Tambien hacemos post de sus tablas hija
|
||
if (AContrato.Detalles.DataTable.State in dsEditModes) then
|
||
AContrato.Detalles.DataTable.Post;
|
||
|
||
// Abrir el cliente para la validaci<63>n
|
||
if Assigned(AContrato.Cliente) then
|
||
AContrato.Cliente.DataTable.Active := True;
|
||
|
||
if (AContrato.ID_Cliente <= 0) then
|
||
// Si hay altas autom<6F>ticas no hay objeto Cliente pero s<> hay ID_CLIENTE
|
||
{ (not Assigned(AContrato.Cliente)) or
|
||
(AContrato.Cliente.IsEmpty) then}
|
||
raise Exception.Create('Debe indicar el cliente de este contrato');
|
||
|
||
if (EsFechaVacia(AContrato.FECHA_CONTRATO)) then
|
||
raise Exception.Create('Debe indicar la fecha de este contrato');
|
||
|
||
if (AContrato.Detalles.DataTable.RecordCount = 0) then
|
||
raise Exception.Create('El contrato debe tener en su contenido al menos un concepto');
|
||
|
||
|
||
FDetallesController.ValidarDetalles(AContrato.Detalles);
|
||
|
||
{ Asegurarse de valores en campos "autom<6F>ticos" tanto
|
||
en MODIFICACI<43>N como en INSERCI<43>N. }
|
||
AContrato.Edit;
|
||
try
|
||
AContrato.USUARIO := AppFactuGES.UsuarioActivo.UserName;
|
||
|
||
if Assigned(AContrato.Cliente)
|
||
and (AContrato.ID_CLIENTE <> AContrato.Cliente.ID) then
|
||
AContrato.ID_CLIENTE := AContrato.Cliente.ID;
|
||
|
||
Result := True;
|
||
finally
|
||
AContrato.Post;
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.Ver(AContrato: IBizContratoCliente);
|
||
var
|
||
AEditor : IEditorContratoCliente;
|
||
begin
|
||
AEditor := NIL;
|
||
|
||
RecuperarObjetos(AContrato);
|
||
CreateEditor('EditorContratoCliente', IEditorContratoCliente, AEditor);
|
||
|
||
if Assigned(AEditor) then
|
||
try
|
||
AEditor.Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
||
AEditor.Contrato := AContrato;
|
||
|
||
//MODO CONSULTAR
|
||
if not EsModificable(AContrato) then
|
||
begin
|
||
SetDataTableReadOnly(AContrato.DataTable, True);
|
||
AEditor.ReadOnly := True;
|
||
end;
|
||
|
||
AEditor.ShowModal;
|
||
|
||
//MODO CONSULTAR (Se deja la tabla como estaba)
|
||
if AEditor.ReadOnly then
|
||
SetDataTableReadOnly(AContrato.DataTable, False);
|
||
finally
|
||
AEditor.Release;
|
||
AEditor := NIL;
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.Ver(const ID: Integer);
|
||
var
|
||
AContrato : IBizContratoCliente;
|
||
begin
|
||
AContrato := Self.Buscar(ID);
|
||
if Assigned(AContrato) then
|
||
try
|
||
Self.Ver(AContrato);
|
||
finally
|
||
FreeAndNil(AContrato);
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.VerFacturasProveedor(AContrato: IBizContratoCliente);
|
||
var
|
||
AModule : TModuleController;
|
||
APlugin : IMCFacturasProveedor;
|
||
begin
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create ('Contrato no asignado (VerFacturasProveedor)');
|
||
|
||
if not AContrato.DataTable.Active then
|
||
AContrato.DataTable.Active := True;
|
||
|
||
AModule := AppFactuGES.GetModule(MODULENAME_FACTURAS_PROVEEDOR);
|
||
if Assigned(AModule) then
|
||
try
|
||
if Supports(AModule, IMCFacturasProveedor, APlugin) then
|
||
APlugin.VerFacturasContrato(AContrato.ID, AContrato.REFERENCIA, AContrato.NOMBRE);
|
||
finally
|
||
APlugin := NIL;
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.VerListadoBeneficios;
|
||
var
|
||
AContratosClienteBeneficios: IBizContratosClienteBeneficios;
|
||
AEditor : IEditorContratosClienteBeneficios;
|
||
begin
|
||
AEditor := NIL;
|
||
|
||
AContratosClienteBeneficios := FDataModule.GetContratosClienteBeneficios;
|
||
CreateEditor('EditorContratosClienteBeneficios', IEditorContratosClienteBeneficios, AEditor);
|
||
|
||
if Assigned(AEditor) then
|
||
try
|
||
// AEditor.Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
||
|
||
AEditor.Contratos := AContratosClienteBeneficios;
|
||
AEditor.ShowModal;
|
||
|
||
finally
|
||
AEditor.Release;
|
||
AEditor := NIL;
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.VerPedidosProveedor(AContrato: IBizContratoCliente);
|
||
var
|
||
AModule : TModuleController;
|
||
APlugin : IMCPedidosProveedor;
|
||
begin
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create ('Contrato no asignado (VerPedidosProveedor)');
|
||
|
||
if not AContrato.DataTable.Active then
|
||
AContrato.DataTable.Active := True;
|
||
|
||
AModule := AppFactuGES.GetModule(MODULENAME_PEDIDOS_PROVEEDOR);
|
||
if Assigned(AModule) then
|
||
try
|
||
if Supports(AModule, IMCPedidosProveedor, APlugin) then
|
||
APlugin.VerPedidos(AContrato.ID, AContrato.REFERENCIA, AContrato.NOMBRE);
|
||
finally
|
||
APlugin := NIL;
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.VerTodos(AContratos: IBizContratoCliente;
|
||
const AVerModal : Boolean = False; const AWindowCaption: String = '';
|
||
const AHeaderText: String = '');
|
||
var
|
||
AEditor : IEditorContratosCliente;
|
||
begin
|
||
AEditor := NIL;
|
||
CreateEditor('EditorContratosCliente', IEditorContratosCliente, AEditor);
|
||
if Assigned(AEditor) then
|
||
try
|
||
// if not EsCadenaVacia(AWindowCaption) then
|
||
// AEditor.WindowCaption := AWindowCaption;
|
||
|
||
// if not EsCadenaVacia(AHeaderText) then
|
||
// AEditor.HeaderText := AHeaderText;
|
||
|
||
AEditor.Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
||
AEditor.Contratos := AContratos;
|
||
AEditor.MultiSelect := True;
|
||
if AVerModal then
|
||
AEditor.ShowModal
|
||
else
|
||
AEditor.ShowEmbedded;
|
||
finally
|
||
if AVerModal then
|
||
AEditor.Release;
|
||
AEditor := NIL;
|
||
end;
|
||
end;
|
||
|
||
function TContratosClienteController._Vacio: IBizContratoCliente;
|
||
begin
|
||
Result := Buscar(ID_NULO);
|
||
end;
|
||
|
||
function TContratosClienteController.Eliminar(const ID: Integer): Boolean;
|
||
var
|
||
AContrato : IBizContratoCliente;
|
||
begin
|
||
AContrato := Buscar(ID);
|
||
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create(Format('No se ha encontrado el contrato con ID = %d', [ID]));
|
||
|
||
Result := Eliminar(AContrato);
|
||
AContrato := NIL;
|
||
end;
|
||
|
||
function TContratosClienteController.ElegirContratos(AContrato: IBizContratoCliente; AMensaje: String; AMultiSelect: Boolean): IBizContratoCliente;
|
||
var
|
||
AEditor : IEditorElegirContratosCliente;
|
||
begin
|
||
Result := NIL;
|
||
|
||
CreateEditor('EditorElegirContratosCliente', IEditorElegirContratosCliente, AEditor);
|
||
if Assigned(AEditor) then
|
||
try
|
||
AEditor.Controller := Self;
|
||
AEditor.Contratos := AContrato;
|
||
AEditor.MultiSelect := AMultiSelect;
|
||
AEditor.Mensaje := AMensaje;
|
||
if IsPositiveResult(AEditor.ShowModal) then
|
||
Result := AEditor.ContratosClienteSeleccionados;
|
||
finally
|
||
AEditor.Release;
|
||
AEditor := NIL;
|
||
end;
|
||
end;
|
||
|
||
function TContratosClienteController.Eliminar(AContrato: IBizContratoCliente; 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(AContrato) then
|
||
raise Exception.Create ('AContrato no asignado');
|
||
|
||
ShowHourglassCursor;
|
||
try
|
||
if not AContrato.DataTable.Active then
|
||
AContrato.DataTable.Active := True;
|
||
|
||
if (AContrato.State in dsEditModes) then
|
||
AContrato.Cancel;
|
||
|
||
//Siempre eliminaremos el seleccionado
|
||
if EsEliminable(AContrato) then
|
||
begin
|
||
//GESTION_DOCUMENTOS
|
||
FGestorDocumentosController.EliminarDirectorio(AContrato.ID);
|
||
|
||
AContrato.Delete;
|
||
bEliminado := True;
|
||
end;
|
||
|
||
//En el caso de querer eliminar todos los items del objeto AContrato
|
||
if AllItems then
|
||
begin
|
||
with AContrato.DataTable do
|
||
begin
|
||
First;
|
||
while not EOF do
|
||
begin
|
||
if EsEliminable(AContrato) then
|
||
begin
|
||
//GESTION_DOCUMENTOS
|
||
FGestorDocumentosController.EliminarDirectorio(AContrato.ID);
|
||
|
||
AContrato.Delete;
|
||
bEliminado := True
|
||
end
|
||
else Next;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
if bEliminado then
|
||
begin
|
||
AContrato.DataTable.ApplyUpdates;
|
||
Result := True;
|
||
end
|
||
else
|
||
Result := False;
|
||
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.EnviarContratoPorEMail(
|
||
AContrato: IBizContratoCliente);
|
||
var
|
||
AReportController : IContratosClienteReportController;
|
||
AFicheroTMP : TFileName;
|
||
ATituloEnvio : String;
|
||
AEMail : String;
|
||
AListaEmail : TStringList;
|
||
begin
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create ('Contrato no asignado (EnviarContratoPorEMail)');
|
||
|
||
if AContrato.DataTable.Active then
|
||
AContrato.DataTable.Active := True;
|
||
|
||
AListaEmail := TStringList.Create;
|
||
try
|
||
RecuperarCliente(AContrato);
|
||
AContrato.Cliente.DataTable.Active := True;
|
||
|
||
if not AContrato.Cliente.EMAIL_1IsNull then
|
||
AListaEmail.Add(AContrato.Cliente.EMAIL_1);
|
||
if not AContrato.Cliente.EMAIL_2IsNull then
|
||
AListaEmail.Add(AContrato.Cliente.EMAIL_2);
|
||
|
||
if not ElegirEMail(AListaEmail, AEMail) then
|
||
Exit;
|
||
finally
|
||
FreeANDNIL(AListaEmail);
|
||
end;
|
||
|
||
ShowHourglassCursor;
|
||
ATituloEnvio := 'Presupuesto ' + AContrato.Cliente.NOMBRE + ' - ' + AContrato.REFERENCIA_CLIENTE;
|
||
AFicheroTMP := DarFicheroPDFTemporal(EscapeIllegalChars(ATituloEnvio));
|
||
AReportController := TContratosClienteReportController.Create;
|
||
try
|
||
AReportController.ExportToPDF(AContrato.ID, AFicheroTMP);
|
||
SendMailMAPI(ATituloEnvio, '', AFicheroTMP, '', '', AContrato.Cliente.NOMBRE, AEMail);
|
||
finally
|
||
DeleteFile(AFicheroTMP);
|
||
AReportController := NIL;
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
function TContratosClienteController.EsEliminable(AContrato: IBizContratoCliente): Boolean;
|
||
begin
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create ('Contrato no asignado: EsEliminable');
|
||
|
||
Result := True;
|
||
end;
|
||
|
||
function TContratosClienteController.EsModificable(AContrato: IBizContratoCliente): Boolean;
|
||
begin
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create ('Contrato no asignado (EsModificable)');
|
||
|
||
Result := True;
|
||
end;
|
||
|
||
procedure TContratosClienteController.RecalcularImportes(
|
||
AContrato: IBizContratoCliente);
|
||
var
|
||
bEnEdicion : Boolean;
|
||
ADetallePosAct : Integer;
|
||
begin
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create ('Contrato no asignado (RecalcularImportes)');
|
||
|
||
if AContrato.DataTable.Active then
|
||
AContrato.DataTable.Active := True;
|
||
|
||
{ Hay que guardar la posici<63>n en la que estamos en los detalles por que
|
||
la asignaci<63>n de valores a los campos IMPORTE_NETO e IMPORTE_PORTE
|
||
(ver m<>s adelante) colocan el puntero en la tabla detalle al principio.
|
||
No he encontrado la raz<61>n por la que mueve el puntero. }
|
||
|
||
ADetallePosAct := AContrato.Detalles.POSICION;
|
||
|
||
bEnEdicion := (AContrato.DataTable.State in dsEditModes);
|
||
if not bEnEdicion then
|
||
AContrato.Edit;
|
||
|
||
ShowHourglassCursor;
|
||
try
|
||
AContrato.IMPORTE_NETO := FDetallesController.DarTotalImporteTotal(AContrato.Detalles);
|
||
AContrato.IMPORTE_PORTE := FDetallesController.DarTotalPorteTotal(AContrato.Detalles);
|
||
|
||
if not bEnEdicion then
|
||
AContrato.Post;
|
||
finally
|
||
HideHourglassCursor;
|
||
// Restaurar la posici<63>n que ten<65>amos en los detalles.
|
||
FDetallesController.LocalizarPosicion(AContrato.Detalles, ADetallePosAct);
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable);
|
||
var
|
||
AContrato : IBizContratoCliente;
|
||
ADetalles : IBizDetallesContratoCliente;
|
||
begin
|
||
inherited;
|
||
|
||
if Supports(ADataTable, IBizDetallesContratoCliente, ADetalles) and
|
||
Supports(ADetalles.DataTable.MasterSource.DataTable, IBizContratoCliente, AContrato) then
|
||
begin
|
||
RecalcularImportes(AContrato);
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.RecuperarObjetos(AContrato: IBizContratoCliente);
|
||
begin
|
||
RecuperarCliente(AContrato);
|
||
end;
|
||
|
||
procedure TContratosClienteController.RellenarValoresDefecto(AContrato: IBizContratoCliente; ATipo: TEnumTiposContrato);
|
||
var
|
||
ACadena : String;
|
||
begin
|
||
case ATipo of
|
||
teCocina:
|
||
begin
|
||
AContrato.TIPO_CONTRATO := CTE_COCINA;
|
||
AContrato.FORMA_PAGO.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_FORMA_PAGO_COCINA));
|
||
AContrato.PLAZO_ENTREGA.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_PLAZOS_ENTREGA_COCINA));
|
||
AContrato.OBSERVACIONES.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_OBSERVACIONES_COCINA));
|
||
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CONDICIONES_COCINA);
|
||
if (ACadena <> '') then
|
||
AContrato.CONDICIONES.Add(ACadena);
|
||
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CALIDADES_COCINA);
|
||
if (ACadena <> '') then
|
||
AContrato.CALIDADES.Add(ACadena);
|
||
(Self.DetallesController as IDetallesContratoClienteController).AnadirCapitulo(TIPO_CAPITULO_C, 'MUEBLES DE COCINA ', false, AContrato.Detalles);
|
||
end;
|
||
teArmario:
|
||
begin
|
||
AContrato.TIPO_CONTRATO := CTE_ARMARIO;
|
||
AContrato.FORMA_PAGO.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_FORMA_PAGO_ARMARIO));
|
||
AContrato.PLAZO_ENTREGA.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_PLAZOS_ENTREGA_ARMARIO));
|
||
AContrato.OBSERVACIONES.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_OBSERVACIONES_ARMARIO));
|
||
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CONDICIONES_ARMARIO);
|
||
if (ACadena <> '') then
|
||
AContrato.CONDICIONES.Add(ACadena);
|
||
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CALIDADES_ARMARIO);
|
||
if (ACadena <> '') then
|
||
AContrato.CALIDADES.Add(ACadena);
|
||
(Self.DetallesController as IDetallesContratoClienteController).AnadirCapitulo(TIPO_CAPITULO_AF, 'FRENTE DE ARMARIO N<> ', false, AContrato.Detalles);
|
||
(Self.DetallesController as IDetallesContratoClienteController).AnadirCapitulo(TIPO_CAPITULO_AI, 'INTERIOR DE ARMARIO N<> ', false, AContrato.Detalles);
|
||
end;
|
||
teBano:
|
||
begin
|
||
AContrato.TIPO_CONTRATO := CTE_BANO;
|
||
AContrato.FORMA_PAGO.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_FORMA_PAGO_BANO));
|
||
AContrato.PLAZO_ENTREGA.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_PLAZOS_ENTREGA_BANO));
|
||
AContrato.OBSERVACIONES.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_OBSERVACIONES_BANO));
|
||
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CONDICIONES_BANO);
|
||
if (ACadena <> '') then
|
||
AContrato.CONDICIONES.Add(ACadena);
|
||
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CALIDADES_BANO);
|
||
if (ACadena <> '') then
|
||
AContrato.CALIDADES.Add(ACadena);
|
||
(Self.DetallesController as IDetallesContratoClienteController).AnadirCapitulo(TIPO_CAPITULO_B, 'MUEBLE DE BA<42>O N<> ', false, AContrato.Detalles);
|
||
end;
|
||
teElectrodomestico:
|
||
begin
|
||
AContrato.TIPO_CONTRATO := CTE_ELECTRODOMESTICO;
|
||
AContrato.FORMA_PAGO.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_FORMA_PAGO_ELECTRODOMESTICO));
|
||
AContrato.PLAZO_ENTREGA.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_PLAZOS_ENTREGA_ELECTRODOMESTICO));
|
||
AContrato.OBSERVACIONES.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_OBSERVACIONES_ELECTRODOMESTICO));
|
||
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CONDICIONES_ELECTRODOMESTICO);
|
||
if (ACadena <> '') then
|
||
AContrato.CONDICIONES.Add(ACadena);
|
||
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CALIDADES_ELECTRODOMESTICO);
|
||
if (ACadena <> '') then
|
||
AContrato.CALIDADES.Add(ACadena);
|
||
(Self.DetallesController as IDetallesContratoClienteController).AnadirCapitulo(TIPO_CAPITULO_E, 'ELECTRODOM<4F>STICOS ', false, AContrato.Detalles);
|
||
end;
|
||
teObra:
|
||
begin
|
||
AContrato.TIPO_CONTRATO := CTE_OBRA;
|
||
AContrato.FORMA_PAGO.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_FORMA_PAGO_OBRA));
|
||
AContrato.PLAZO_ENTREGA.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_PLAZOS_ENTREGA_OBRA));
|
||
AContrato.OBSERVACIONES.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_OBSERVACIONES_OBRA));
|
||
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CONDICIONES_OBRA);
|
||
if (ACadena <> '') then
|
||
AContrato.CONDICIONES.Add(ACadena);
|
||
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CALIDADES_OBRA);
|
||
if (ACadena <> '') then
|
||
AContrato.CALIDADES.Add(ACadena);
|
||
(Self.DetallesController as IDetallesContratoClienteController).AnadirCapitulo(TIPO_CAPITULO_O, 'OBRA ', false, AContrato.Detalles);
|
||
end;
|
||
teVarios:
|
||
begin
|
||
AContrato.TIPO_CONTRATO := CTE_VARIOS;
|
||
AContrato.FORMA_PAGO.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_FORMA_PAGO_VARIOS));
|
||
AContrato.PLAZO_ENTREGA.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_PLAZOS_ENTREGA_VARIOS));
|
||
AContrato.OBSERVACIONES.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_OBSERVACIONES_VARIOS));
|
||
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CONDICIONES_VARIOS);
|
||
if (ACadena <> '') then
|
||
AContrato.CONDICIONES.Add(ACadena);
|
||
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CALIDADES_VARIOS);
|
||
if (ACadena <> '') then
|
||
AContrato.CALIDADES.Add(ACadena);
|
||
(Self.DetallesController as IDetallesContratoClienteController).AnadirCapitulo(TIPO_CAPITULO_V, 'VARIOS ', false, AContrato.Detalles);
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.RecuperarCliente(
|
||
AContrato: IBizContratoCliente);
|
||
begin
|
||
AContrato._Cliente := (FClienteController.Buscar(AContrato.ID_Cliente) as IBizCliente);
|
||
end;
|
||
|
||
function TContratosClienteController.Existe(const ID: Integer): Boolean;
|
||
var
|
||
AContrato : IBizContratoCliente;
|
||
begin
|
||
try
|
||
AContrato := Buscar(ID);
|
||
Result := Assigned(AContrato) and (AContrato.ID = ID);
|
||
finally
|
||
AContrato := NIL;
|
||
end;
|
||
end;
|
||
|
||
function TContratosClienteController.ExtraerSeleccionados(AContrato: IBizContratoCliente): IBizContratoCliente;
|
||
var
|
||
ASeleccionados : IBizContratoCliente;
|
||
begin
|
||
ASeleccionados := (Self.Buscar(ID_NULO) as IBizContratoCliente);
|
||
CopyDataTableDA5(AContrato.DataTable, ASeleccionados.DataTable, True);
|
||
Result := ASeleccionados;
|
||
end;
|
||
|
||
procedure TContratosClienteController.FiltrarAno(AContrato: IBizContratoCliente; ADynWhereDataTable: WideString;const Ano: String);
|
||
var
|
||
Condicion: TDAWhereExpression;
|
||
FechaIni: String;
|
||
FechaFin: String;
|
||
|
||
begin
|
||
AContrato.DataTable.DynamicWhere.Clear;
|
||
AContrato.DataTable.DynamicWhere.Xml := ADynWhereDataTable;
|
||
|
||
if (Ano <> 'Todos') then
|
||
begin
|
||
// Filtrar las facturas actuales por empresa
|
||
FechaIni := '01/01/' + Ano;
|
||
FechaFin := '31/12/' + Ano;
|
||
with AContrato.DataTable.DynamicWhere do
|
||
begin
|
||
// (FECHA_INICIO between FECHA_FIN)
|
||
Condicion := NewBinaryExpression(NewField('', fld_ContratosClienteFECHA_CONTRATO), NewConstant(FechaIni, datString), dboGreaterOrEqual);
|
||
Condicion := NewBinaryExpression(NewBinaryExpression(NewField('', fld_ContratosClienteFECHA_CONTRATO), NewConstant(FechaFin, datString), dboLessOrEqual), Condicion, dboAnd);
|
||
|
||
if IsEmpty then
|
||
Expression := Condicion
|
||
else
|
||
Expression := NewBinaryExpression(Condicion, Expression, dboAnd);
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.FiltrarEmpresa(AContrato: IBizContratoCliente);
|
||
var
|
||
Condicion: TDAWhereExpression;
|
||
begin
|
||
if AContrato.DataTable.Active then
|
||
AContrato.DataTable.Active := False;
|
||
|
||
// Filtrar los contratos actuales por empresa
|
||
with AContrato.DataTable.DynamicWhere do
|
||
begin
|
||
// (ID_EMPRESA >= ID)
|
||
Condicion := NewBinaryExpression(NewField('', fld_ContratosClienteID_EMPRESA), NewConstant(AppFactuGES.EmpresaActiva.ID, datInteger), dboEqual);
|
||
|
||
if IsEmpty then
|
||
Expression := Condicion
|
||
else
|
||
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.SetClienteController(const Value: IClientesController);
|
||
begin
|
||
FClienteController := Value;
|
||
end;
|
||
|
||
procedure TContratosClienteController.SetDetallesController(const Value: IDetallesContratoClienteController);
|
||
begin
|
||
FDetallesController := Value;
|
||
end;
|
||
|
||
procedure TContratosClienteController.SetGestorDocumentosController(
|
||
const Value: IGestorDocumentosController);
|
||
begin
|
||
FGestorDocumentosController := Value;
|
||
end;
|
||
|
||
{
|
||
function TContratosClienteController.SubirFichero(const ID: Integer; const NombreFichero: String; const Fichero: Binary): Boolean;
|
||
begin
|
||
Result := FDataModule.SubirFichero(ID, NombreFichero, Fichero);
|
||
end;
|
||
}
|
||
|
||
function TContratosClienteController.Guardar(AContrato: IBizContratoCliente): Boolean;
|
||
begin
|
||
Result := False;
|
||
|
||
if not Assigned(AContrato) then
|
||
raise Exception.Create ('Contrato no asignada');
|
||
|
||
if not Assigned(FDetallesController) then
|
||
raise Exception.Create ('Controller detalles no asignado');
|
||
|
||
if ValidarContrato(AContrato) then
|
||
begin
|
||
ShowHourglassCursor;
|
||
|
||
// Asegurarnos de que todos los importes est<73>n bien.
|
||
RecalcularImportes(AContrato);
|
||
|
||
try
|
||
AContrato.DataTable.ApplyUpdates;
|
||
Result := True;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
function TContratosClienteController.Localizar(AContratos: IBizContratoCliente;
|
||
const ID: Integer): Boolean;
|
||
begin
|
||
Result := True;
|
||
ShowHourglassCursor;
|
||
try
|
||
with AContratos.DataTable do
|
||
begin
|
||
DisableControls;
|
||
First;
|
||
if not Locate(fld_ContratosClienteID, ID, []) then
|
||
Result := False;
|
||
EnableControls;
|
||
end;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
function TContratosClienteController.Nuevo: IBizContratoCliente;
|
||
var
|
||
AContrato : IBizContratoCliente;
|
||
begin
|
||
AContrato := FDataModule.NewItem;
|
||
FiltrarEmpresa(AContrato);
|
||
AContrato.DataTable.Active := True;
|
||
AContrato.Insert;
|
||
Result := AContrato;
|
||
end;
|
||
|
||
procedure TContratosClienteController.Preview(AContrato: IBizContratoCliente; AllItems: Boolean = false; AVerCondiciones: Boolean = false);
|
||
var
|
||
AReportController : IContratosClienteReportController;
|
||
ID_Contratos: TIntegerList;
|
||
begin
|
||
AReportController := TContratosClienteReportController.Create;
|
||
try
|
||
ID_Contratos := TIntegerList.Create;
|
||
|
||
//Si deseamos previsualizar todos los items del objeto contrato
|
||
if AllItems then
|
||
begin
|
||
with AContrato.DataTable do
|
||
begin
|
||
First;
|
||
while not EOF do
|
||
begin
|
||
ID_Contratos.Add(AContrato.ID);
|
||
Next;
|
||
end;
|
||
end;
|
||
end
|
||
//Solo previsualizamos el item seleccionado
|
||
else
|
||
ID_Contratos.Add(AContrato.ID);
|
||
|
||
AReportController.Preview(ID_Contratos, AVerCondiciones);
|
||
finally
|
||
AReportController := NIL;
|
||
FreeAndNil(ID_Contratos);
|
||
end;
|
||
end;
|
||
|
||
procedure TContratosClienteController.Print(AContrato: IBizContratoCliente; AllItems: Boolean = false; AVerCondiciones: Boolean = false);
|
||
var
|
||
AReportController : IContratosClienteReportController;
|
||
ID_Contratos: TIntegerList;
|
||
begin
|
||
AReportController := TContratosClienteReportController.Create;
|
||
ID_Contratos := TIntegerList.Create;
|
||
try
|
||
//Si deseamos imprimimos todos los items del objeto contrato
|
||
if AllItems then
|
||
begin
|
||
with AContrato.DataTable do
|
||
begin
|
||
First;
|
||
while not EOF do
|
||
begin
|
||
ID_Contratos.Add(AContrato.ID);
|
||
Next;
|
||
end;
|
||
end;
|
||
end
|
||
//Solo imprimimos el item seleccionado
|
||
else
|
||
ID_Contratos.Add(AContrato.ID);
|
||
|
||
AReportController.Print(ID_Contratos, AVerCondiciones);
|
||
|
||
finally
|
||
AReportController := NIL;
|
||
FreeANDNIL(ID_Contratos);
|
||
end;
|
||
end;
|
||
|
||
function TContratosClienteController.GetClienteController: IClientesController;
|
||
begin
|
||
Result := FClienteController;
|
||
end;
|
||
|
||
function TContratosClienteController.GetDetallesController: IDetallesContratoClienteController;
|
||
begin
|
||
Result := FDetallesController;
|
||
end;
|
||
|
||
function TContratosClienteController.GetGestorDocumentosController: IGestorDocumentosController;
|
||
begin
|
||
Result := FGestorDocumentosController;
|
||
end;
|
||
|
||
end.
|