git-svn-id: https://192.168.0.254/svn/Proyectos.AlonsoYSal_FactuGES2/trunk@24 40301925-124e-1c4e-b97d-170ad7a8785b
1193 lines
44 KiB
ObjectPascal
1193 lines
44 KiB
ObjectPascal
unit uPresupuestosClienteController;
|
|
|
|
interface
|
|
|
|
|
|
uses
|
|
Classes, uROTypes, SysUtils, uDADataTable, uEditorDBItem,
|
|
uControllerBase, uIDataModulePresupuestosCliente, uClientesController,
|
|
uDetallesPresupuestoClienteController, uGestorDocumentosController,
|
|
uBizPresupuestosCliente, uBizDireccionesContacto, uBizDetallesPresupuestoCliente,
|
|
uIntegerListUtils;
|
|
|
|
const
|
|
CTE_COCINA = 'Cocina';
|
|
CTE_BANO = 'Baño';
|
|
CTE_ARMARIO = 'Armarios';
|
|
CTE_ELECTRODOMESTICO = 'Electrodomésticos';
|
|
CTE_OBRA = 'Obra';
|
|
CTE_VARIOS = 'Varios';
|
|
|
|
|
|
CTE_FORMA_PAGO_COCINA = 'FORMA_PAGO_COCINA';
|
|
CTE_PLAZOS_ENTREGA_COCINA = 'PLAZOS_ENTREGA_COCINA';
|
|
CTE_OBSERVACIONES_COCINA = 'OBSERVACIONES_COCINA';
|
|
CTE_CONDICIONES_COCINA = 'CONDICIONES_COCINA';
|
|
CTE_CALIDADES_COCINA = 'CALIDADES_COCINA';
|
|
|
|
CTE_FORMA_PAGO_ARMARIO = 'FORMA_PAGO_ARMARIO';
|
|
CTE_PLAZOS_ENTREGA_ARMARIO = 'PLAZOS_ENTREGA_ARMARIO';
|
|
CTE_OBSERVACIONES_ARMARIO = 'OBSERVACIONES_ARMARIO';
|
|
CTE_CONDICIONES_ARMARIO = 'CONDICIONES_ARMARIO';
|
|
CTE_CALIDADES_ARMARIO = 'CALIDADES_ARMARIO';
|
|
|
|
CTE_FORMA_PAGO_BANO = 'FORMA_PAGO_BANO';
|
|
CTE_PLAZOS_ENTREGA_BANO = 'PLAZOS_ENTREGA_BANO';
|
|
CTE_OBSERVACIONES_BANO = 'OBSERVACIONES_BANO';
|
|
CTE_CONDICIONES_BANO = 'CONDICIONES_BANO';
|
|
CTE_CALIDADES_BANO = 'CALIDADES_BANO';
|
|
|
|
CTE_FORMA_PAGO_ELECTRODOMESTICO = 'FORMA_PAGO_ELECTRODOMESTICO';
|
|
CTE_PLAZOS_ENTREGA_ELECTRODOMESTICO = 'PLAZOS_ENTREGA_ELECTRODOMESTICO';
|
|
CTE_OBSERVACIONES_ELECTRODOMESTICO = 'OBSERVACIONES_ELECTRODOMESTICO';
|
|
CTE_CONDICIONES_ELECTRODOMESTICO = 'CONDICIONES_ELECTRODOMESTICO';
|
|
CTE_CALIDADES_ELECTRODOMESTICO = 'CALIDADES_ELECTRODOMESTICO';
|
|
|
|
CTE_FORMA_PAGO_VARIOS = 'FORMA_PAGO_VARIOS';
|
|
CTE_PLAZOS_ENTREGA_VARIOS = 'PLAZOS_ENTREGA_VARIOS';
|
|
CTE_OBSERVACIONES_VARIOS = 'OBSERVACIONES_VARIOS';
|
|
CTE_CONDICIONES_VARIOS = 'CONDICIONES_VARIOS';
|
|
CTE_CALIDADES_VARIOS = 'CALIDADES_VARIOS';
|
|
|
|
CTE_FORMA_PAGO_OBRA = 'FORMA_PAGO_OBRA';
|
|
CTE_PLAZOS_ENTREGA_OBRA = 'PLAZOS_ENTREGA_OBRA';
|
|
CTE_OBSERVACIONES_OBRA = 'OBSERVACIONES_OBRA';
|
|
CTE_CONDICIONES_OBRA = 'CONDICIONES_OBRA';
|
|
CTE_CALIDADES_OBRA = 'CALIDADES_OBRA';
|
|
|
|
type
|
|
TEnumTiposPresupuesto = (teCocina, teArmario, teBano, teElectrodomestico, teObra, teVarios);
|
|
|
|
IPresupuestosClienteController = interface(IControllerBase)
|
|
['{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;
|
|
|
|
//GESTION_DOCUMENTOS
|
|
function GetGestorDocumentosController: IGestorDocumentosController;
|
|
procedure SetGestorDocumentosController(const Value: IGestorDocumentosController);
|
|
property GestorDocumentosController: IGestorDocumentosController read GetGestorDocumentosController write SetGestorDocumentosController;
|
|
|
|
procedure RecuperarCliente(APresupuesto : IBizPresupuestoCliente);
|
|
function Buscar(const ID: Integer): IBizPresupuestoCliente; overload;
|
|
function Buscar(const ListaID: TIntegerList): IBizPresupuestoCliente; overload;
|
|
function BuscarTodos: IBizPresupuestoCliente; overload;
|
|
function BuscarTodos(const ID_Cliente: Integer): IBizPresupuestoCliente; overload;
|
|
function BuscarAceptados : IBizPresupuestoCliente;
|
|
function BuscarSinContrato : IBizPresupuestoCliente;
|
|
procedure Ver(APresupuesto : IBizPresupuestoCliente);
|
|
procedure VerTodos(APresupuestos: IBizPresupuestoCliente;
|
|
const AVerModal : Boolean = False; const AWindowCaption: String = '';
|
|
const AHeaderText: String = '');
|
|
procedure VerDireccionEntrega(APresupuesto : IBizPresupuestoCliente);
|
|
function Nuevo : IBizPresupuestoCliente;
|
|
function Anadir(APresupuesto : IBizPresupuestoCliente; const ATipo: TEnumTiposPresupuesto = teVarios) : Boolean;
|
|
function Eliminar(const ID : Integer): Boolean; overload;
|
|
function Eliminar(APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false): Boolean; overload;
|
|
function Guardar(APresupuesto : IBizPresupuestoCliente): Boolean;
|
|
procedure DescartarCambios(APresupuesto : IBizPresupuestoCliente);
|
|
function Existe(const ID: Integer) : Boolean;
|
|
function Duplicar(APresupuesto: IBizPresupuestoCliente): IBizPresupuestoCliente;
|
|
|
|
function Localizar(APresupuestos: IBizPresupuestoCliente; const ID : Integer): Boolean;
|
|
function ExtraerSeleccionados(APresupuesto: IBizPresupuestoCliente) : IBizPresupuestoCliente;
|
|
function ElegirPresupuestos(APresupuesto: IBizPresupuestoCliente; AMensaje: String; AMultiSelect: Boolean): IBizPresupuestoCliente;
|
|
|
|
procedure QuitarDireccionEnvio(APresupuesto: IBizPresupuestoCliente);
|
|
|
|
procedure RecalcularImportes(APresupuesto : IBizPresupuestoCliente);
|
|
function EsModificable(APresupuesto : IBizPresupuestoCliente): Boolean;
|
|
function EsEliminable(APresupuesto : IBizPresupuestoCliente): Boolean;
|
|
|
|
procedure Preview(APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false);
|
|
procedure Print(APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false);
|
|
procedure EnviarPresupuestoPorEMail(APresupuesto : IBizPresupuestoCliente);
|
|
function CambiarSituacion(APresupuesto : IBizPresupuestoCliente; Situacion: String; FechaDecision: TDateTime; AllItems: Boolean = false): Boolean;
|
|
|
|
function DarListaAnosPresupuestos: TStringList;
|
|
procedure FiltrarAno(APresupuesto: IBizPresupuestoCliente; ADynWhereDataTable: WideString; const Ano: String);
|
|
end;
|
|
|
|
TPresupuestosClienteController = class(TControllerBase, IPresupuestosClienteController)
|
|
protected
|
|
FDataModule : IDataModulePresupuestosCliente;
|
|
FClienteController : IClientesController;
|
|
FDetallesController : IDetallesPresupuestoClienteController;
|
|
FGestorDocumentosController : IGestorDocumentosController;
|
|
|
|
function GetClienteController: IClientesController;
|
|
procedure SetClienteController(const Value: IClientesController);
|
|
function GetDetallesController: IDetallesPresupuestoClienteController;
|
|
procedure SetDetallesController(const Value: IDetallesPresupuestoClienteController);
|
|
|
|
//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(APresupuesto: IBizPresupuestoCliente); virtual;
|
|
|
|
procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override;
|
|
function CreateEditor(const AName : String; const IID: TGUID; out Intf): Boolean;
|
|
procedure FiltrarEmpresa(APresupuesto: IBizPresupuestoCliente);
|
|
function _Vacio : IBizPresupuestoCliente;
|
|
function ValidarPresupuesto(APresupuesto: IBizPresupuestoCliente): Boolean;
|
|
procedure RellenarValoresDefecto(APresupuesto: IBizPresupuestoCliente; ATipo: TEnumTiposPresupuesto);
|
|
|
|
public
|
|
property ClienteController: IClientesController read GetClienteController write SetClienteController;
|
|
property DetallesController: IDetallesPresupuestoClienteController read GetDetallesController write SetDetallesController;
|
|
property GestorDocumentosController: IGestorDocumentosController read GetGestorDocumentosController write SetGestorDocumentosController;
|
|
|
|
constructor Create; override;
|
|
destructor Destroy; override;
|
|
|
|
function Localizar(APresupuestos: IBizPresupuestoCliente; const ID : Integer): Boolean;
|
|
|
|
procedure RecuperarCliente(APresupuesto : IBizPresupuestoCliente);
|
|
function Eliminar(const ID : Integer): Boolean; overload;
|
|
function Eliminar(APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false): Boolean; overload;
|
|
function Guardar(APresupuesto : IBizPresupuestoCliente): Boolean;
|
|
procedure DescartarCambios(APresupuesto : IBizPresupuestoCliente); virtual;
|
|
function Existe(const ID: Integer) : Boolean; virtual;
|
|
function Anadir(APresupuesto : IBizPresupuestoCliente; const ATipo: TEnumTiposPresupuesto = teVarios) : Boolean;
|
|
function Buscar(const ListaID: TIntegerList): IBizPresupuestoCliente; overload;
|
|
function Buscar(const ID: Integer): IBizPresupuestoCliente; overload;
|
|
function BuscarTodos: IBizPresupuestoCliente; overload;
|
|
function BuscarTodos(const ID_Cliente: Integer): IBizPresupuestoCliente; overload;
|
|
function BuscarAceptados : IBizPresupuestoCliente;
|
|
function BuscarSinContrato : IBizPresupuestoCliente;
|
|
function Nuevo : IBizPresupuestoCliente;
|
|
procedure Ver(APresupuesto : IBizPresupuestoCliente);
|
|
procedure VerTodos(APresupuestos: IBizPresupuestoCliente;
|
|
const AVerModal : Boolean = False; const AWindowCaption: String = '';
|
|
const AHeaderText: String = '');
|
|
procedure VerDireccionEntrega(APresupuesto : IBizPresupuestoCliente);
|
|
function Duplicar(APresupuesto: IBizPresupuestoCliente): IBizPresupuestoCliente;
|
|
|
|
procedure QuitarDireccionEnvio(APresupuesto: IBizPresupuestoCliente);
|
|
function ExtraerSeleccionados(APresupuesto: IBizPresupuestoCliente) : IBizPresupuestoCliente;
|
|
function ElegirPresupuestos(APresupuesto: IBizPresupuestoCliente; AMensaje: String; AMultiSelect: Boolean): IBizPresupuestoCliente;
|
|
|
|
procedure RecalcularImportes(APresupuesto : IBizPresupuestoCliente);
|
|
function EsModificable(APresupuesto : IBizPresupuestoCliente): Boolean;
|
|
function EsEliminable(APresupuesto : IBizPresupuestoCliente): Boolean;
|
|
|
|
procedure Preview(APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false);
|
|
procedure Print(APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false);
|
|
procedure EnviarPresupuestoPorEMail(APresupuesto : IBizPresupuestoCliente);
|
|
function CambiarSituacion(APresupuesto : IBizPresupuestoCliente; Situacion: String; FechaDecision: TDateTime; AllItems: Boolean = false): Boolean;
|
|
|
|
function DarListaAnosPresupuestos: TStringList;
|
|
procedure FiltrarAno(APresupuesto: IBizPresupuestoCliente; ADynWhereDataTable: WideString; const Ano: String);
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
Controls, cxControls, DB, uEditorRegistryUtils, uEditorPreview, DateUtils,
|
|
uIEditorPresupuestosCliente, uDataModulePresupuestosCliente, Variants,
|
|
uBizContactos, uDataTableUtils, uDataModuleUsuarios, uFactuGES_App, uConfiguracionController,
|
|
schPresupuestosClienteClient_Intf, uDAInterfaces, uDateUtils, uIEditorPresupuestoCliente,
|
|
uIEditorElegirPresupuestosCliente, uIEditorDireccionEntregaPresupuestoCliente,
|
|
schContactosClient_Intf, uPresupuestosClienteReportController, FactuGES_Intf,
|
|
uSistemaFunc, uEMailUtils, uDialogElegirEMail, Dialogs, uStringsUtils;
|
|
|
|
{ TPresupuestosClienteController }
|
|
|
|
function TPresupuestosClienteController.Anadir(APresupuesto: IBizPresupuestoCliente; const ATipo: TEnumTiposPresupuesto): Boolean;
|
|
begin
|
|
if not Assigned(APresupuesto) then
|
|
raise Exception.Create ('Presupuesto no asignado (Anadir)');
|
|
APresupuesto.Insert;
|
|
|
|
RellenarValoresDefecto(APresupuesto, ATipo);
|
|
|
|
Result := True;
|
|
end;
|
|
|
|
{
|
|
procedure TPresupuestosClienteController.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 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.Buscar(
|
|
const ListaID: TIntegerList): IBizPresupuestoCliente;
|
|
begin
|
|
Result := FDataModule.GetItems(ListaID);
|
|
FiltrarEmpresa(Result);
|
|
end;
|
|
|
|
function TPresupuestosClienteController.BuscarAceptados: IBizPresupuestoCliente;
|
|
var
|
|
Condicion: TDAWhereExpression;
|
|
begin
|
|
ShowHourglassCursor;
|
|
try
|
|
Result := BuscarTodos;
|
|
// Filtrar los presupuesto pendientes de recepcion
|
|
with Result.DataTable.DynamicWhere do
|
|
begin
|
|
// (SITUACION <> RECIBIDO)
|
|
Condicion := NewBinaryExpression(NewField('', fld_PresupuestosClienteSITUACION), NewConstant(SITUACION_PRESUPUESTO_ACEPTADO, datString), dboEqual);
|
|
|
|
if IsEmpty then
|
|
Expression := Condicion
|
|
else
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
|
end;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.BuscarSinContrato: IBizPresupuestoCliente;
|
|
var
|
|
Condicion: TDAWhereExpression;
|
|
begin
|
|
ShowHourglassCursor;
|
|
try
|
|
Result := BuscarAceptados;
|
|
|
|
with Result.DataTable.DynamicWhere do
|
|
begin
|
|
// (ID_FACTURA = NULL)
|
|
// Condicion := NewBinaryExpression(NewField('', fld_PresupuestosClienteID_CONTRATO), NewNull(), dboEqual);
|
|
|
|
if IsEmpty then
|
|
Expression := Condicion
|
|
else
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
|
end;
|
|
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.BuscarTodos(
|
|
const ID_Cliente: Integer): IBizPresupuestoCliente;
|
|
var
|
|
Condicion: TDAWhereExpression;
|
|
begin
|
|
ShowHourglassCursor;
|
|
try
|
|
Result := BuscarTodos;
|
|
|
|
with Result.DataTable.DynamicWhere do
|
|
begin
|
|
// ID_CLIENTE
|
|
Condicion := NewBinaryExpression(NewField('', fld_PresupuestosClienteID_CLIENTE), NewConstant(ID_Cliente, datInteger), dboEqual);
|
|
|
|
if IsEmpty then
|
|
Expression := Condicion
|
|
else
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
|
end;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.CambiarSituacion(APresupuesto: IBizPresupuestoCliente;
|
|
Situacion: String; FechaDecision: TDateTime; AllItems: Boolean): Boolean;
|
|
// En el caso de cambiar almenos un elemento del conjunto se devuelve true
|
|
begin
|
|
if not Assigned(APresupuesto) then
|
|
raise Exception.Create ('APresupuesto no asignado');
|
|
|
|
ShowHourglassCursor;
|
|
try
|
|
if not APresupuesto.DataTable.Active then
|
|
APresupuesto.DataTable.Active := True;
|
|
|
|
if (APresupuesto.State in dsEditModes) then
|
|
APresupuesto.Cancel;
|
|
|
|
//Siempre cambiaremos de situacion el seleccionado
|
|
if APresupuesto.SITUACION <> Situacion then
|
|
begin
|
|
APresupuesto.DataTable.Edit;
|
|
APresupuesto.SITUACION := Situacion;
|
|
APresupuesto.FECHA_DECISION := FechaDecision;
|
|
APresupuesto.DataTable.Post;
|
|
end;
|
|
|
|
//En el caso de querer eliminar todos los items del objeto APresupuesto
|
|
if AllItems then
|
|
begin
|
|
with APresupuesto.DataTable do
|
|
begin
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
if APresupuesto.SITUACION <> Situacion then
|
|
begin
|
|
APresupuesto.DataTable.Edit;
|
|
APresupuesto.SITUACION := Situacion;
|
|
APresupuesto.FECHA_DECISION := FechaDecision;
|
|
APresupuesto.DataTable.Post;
|
|
end;
|
|
Next;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
APresupuesto.DataTable.ApplyUpdates;
|
|
Result := True;
|
|
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
constructor TPresupuestosClienteController.Create;
|
|
begin
|
|
inherited;
|
|
AsignarDataModule;
|
|
|
|
FClienteController := TClientesController.Create;
|
|
FDetallesController := TDetallesPresupuestoClienteController.Create;
|
|
|
|
//GESTION_DOCUMENTOS
|
|
FGestorDocumentosController := TGestorDocumentosController.Create;
|
|
FGestorDocumentosController.Almacen := TRdxAlmacenes_Presupuestos;
|
|
|
|
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;
|
|
|
|
{
|
|
function TPresupuestosClienteController.DarListaDocumentos(const ID: Integer): TStringList;
|
|
begin
|
|
Result := FDataModule.DarListaDocumentos(ID);
|
|
end;
|
|
|
|
function TPresupuestosClienteController.DescargarFichero(const ID: Integer; const NombreFichero: String; const DestinoFichero: String): Boolean;
|
|
begin
|
|
Result := FDataModule.DescargarFichero(ID, NombreFichero, DestinoFichero);
|
|
end;
|
|
}
|
|
|
|
function TPresupuestosClienteController.DarListaAnosPresupuestos: TStringList;
|
|
begin
|
|
Result := FDataModule.GetAnosItems;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.DescartarCambios(APresupuesto: IBizPresupuestoCliente);
|
|
begin
|
|
if not Assigned(APresupuesto) then
|
|
raise Exception.Create ('Presupuesto no asignada');
|
|
|
|
ShowHourglassCursor;
|
|
try
|
|
if (APresupuesto.State in dsEditModes) then
|
|
APresupuesto.Cancel;
|
|
|
|
APresupuesto.DataTable.CancelUpdates;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
destructor TPresupuestosClienteController.Destroy;
|
|
begin
|
|
FDataModule := Nil;
|
|
FClienteController := Nil;
|
|
FDetallesController := Nil;
|
|
|
|
//GESTION_DOCUMENTOS
|
|
FGestorDocumentosController := Nil;
|
|
inherited;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.Duplicar(
|
|
APresupuesto: IBizPresupuestoCliente): IBizPresupuestoCliente;
|
|
begin
|
|
Result := Self._Vacio;
|
|
ShowHourglassCursor;
|
|
try
|
|
DuplicarRegistros(APresupuesto.DataTable, Result.DataTable, mdrActual);
|
|
DuplicarRegistros(APresupuesto.Detalles.DataTable, Result.Detalles.DataTable, mdrTodos);
|
|
|
|
// Hay que dejar algunos campos como si fuera un presupuesto nuevo
|
|
Result.Edit;
|
|
with Result do
|
|
begin
|
|
ID_EMPRESA := AppFactuGES.EmpresaActiva.ID;
|
|
USUARIO := AppFactuGES.UsuarioActivo.UserName;
|
|
ID_TIENDA := AppFactuGES.TiendaActiva.ID;
|
|
TIENDA := AppFactuGES.TiendaActiva.NOMBRE;
|
|
FECHA_PRESUPUESTO := DateOf(Now);
|
|
INCIDENCIAS_ACTIVAS := 0;
|
|
INCIDENCIASIsNull := True;
|
|
ID_CONTRATOIsNull := True;
|
|
FECHA_DECISIONIsNull := True;
|
|
REFERENCIA := '';
|
|
SITUACION := SITUACION_PRESUPUESTO_PENDIENTE;
|
|
end;
|
|
Result.AsignarVendedor;
|
|
Result.Post;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.ValidarPresupuesto(
|
|
APresupuesto: IBizPresupuestoCliente): Boolean;
|
|
begin
|
|
if not Assigned(APresupuesto) then
|
|
raise Exception.Create ('Presupuesto no asignado');
|
|
|
|
if (APresupuesto.DataTable.State in dsEditModes) then
|
|
APresupuesto.DataTable.Post;
|
|
|
|
//Tambien hacemos post de sus tablas hija
|
|
if (APresupuesto.Detalles.DataTable.State in dsEditModes) then
|
|
APresupuesto.Detalles.DataTable.Post;
|
|
|
|
// Abrir el cliente para la validación
|
|
if Assigned(APresupuesto.Cliente) then
|
|
APresupuesto.Cliente.DataTable.Active := True;
|
|
|
|
if (APresupuesto.ID_Cliente <= 0) then
|
|
// Si hay altas automáticas no hay objeto Cliente pero sí hay ID_CLIENTE
|
|
{ (not Assigned(APresupuesto.Cliente)) or
|
|
(APresupuesto.Cliente.IsEmpty) then}
|
|
raise Exception.Create('Debe indicar el cliente de este presupuesto');
|
|
|
|
if (EsFechaVacia(APresupuesto.FECHA_PRESUPUESTO)) then
|
|
raise Exception.Create('Debe indicar la fecha de este presupuesto');
|
|
|
|
if (APresupuesto.Detalles.DataTable.RecordCount = 0) then
|
|
raise Exception.Create('El presupuesto debe tener en su contenido al menos un concepto');
|
|
|
|
|
|
FDetallesController.ValidarDetalles(APresupuesto.Detalles);
|
|
|
|
{ Asegurarse de valores en campos "automáticos" tanto
|
|
en MODIFICACIÓN como en INSERCIÓN. }
|
|
APresupuesto.Edit;
|
|
try
|
|
APresupuesto.USUARIO := AppFactuGES.UsuarioActivo.UserName;
|
|
|
|
// Se quita temporalmente si no hay mas fallos de cambio de cliente se quita de todos los sitios
|
|
// if Assigned(APresupuesto.Cliente)
|
|
// and (APresupuesto.ID_CLIENTE <> APresupuesto.Cliente.ID) then
|
|
// APresupuesto.ID_CLIENTE := APresupuesto.Cliente.ID;
|
|
|
|
Result := True;
|
|
finally
|
|
APresupuesto.Post;
|
|
end;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.Ver(APresupuesto: IBizPresupuestoCliente);
|
|
var
|
|
AEditor : IEditorPresupuestoCliente;
|
|
begin
|
|
AEditor := NIL;
|
|
|
|
RecuperarObjetos(APresupuesto);
|
|
CreateEditor('EditorPresupuestoCliente', IEditorPresupuestoCliente, AEditor);
|
|
|
|
if Assigned(AEditor) then
|
|
try
|
|
AEditor.Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|
AEditor.Presupuesto := APresupuesto;
|
|
|
|
//MODO CONSULTAR
|
|
if not EsModificable(APresupuesto) then
|
|
begin
|
|
SetDataTableReadOnly(APresupuesto.DataTable, True);
|
|
AEditor.ReadOnly := True;
|
|
end;
|
|
|
|
AEditor.ShowModal;
|
|
|
|
//MODO CONSULTAR (Se deja la tabla como estaba)
|
|
if AEditor.ReadOnly then
|
|
SetDataTableReadOnly(APresupuesto.DataTable, False);
|
|
finally
|
|
AEditor.Release;
|
|
AEditor := NIL;
|
|
end;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.VerDireccionEntrega(
|
|
APresupuesto: IBizPresupuestoCliente);
|
|
{var
|
|
AEditor : IEditorDireccionEntregaPresupuestoCliente;}
|
|
begin
|
|
{
|
|
AEditor := NIL;
|
|
//RecuperarObjetos(APresupuesto); <- No descomentar. No hace falta
|
|
CreateEditor('EditorDireccionEntregaPresupuestoCliente', IEditorDireccionEntregaPresupuestoCliente, AEditor);
|
|
if Assigned(AEditor) then
|
|
with (AEditor as IEditorDireccionEntregaPresupuestoCliente) do
|
|
begin
|
|
try
|
|
Presupuesto := APresupuesto;
|
|
ShowModal;
|
|
finally
|
|
AEditor.Release;
|
|
AEditor := NIL;
|
|
end;
|
|
end;
|
|
}
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.VerTodos(APresupuestos: IBizPresupuestoCliente;
|
|
const AVerModal : Boolean = False; const AWindowCaption: String = '';
|
|
const AHeaderText: String = '');
|
|
var
|
|
AEditor : IEditorPresupuestosCliente;
|
|
begin
|
|
AEditor := NIL;
|
|
CreateEditor('EditorPresupuestosCliente', IEditorPresupuestosCliente, 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.Presupuestos := APresupuestos;
|
|
AEditor.MultiSelect := True;
|
|
if AVerModal then
|
|
AEditor.ShowModal
|
|
else
|
|
AEditor.ShowEmbedded;
|
|
finally
|
|
if AVerModal then
|
|
AEditor.Release;
|
|
AEditor := NIL;
|
|
end;
|
|
end;
|
|
|
|
function TPresupuestosClienteController._Vacio: IBizPresupuestoCliente;
|
|
begin
|
|
Result := Buscar(ID_NULO);
|
|
end;
|
|
|
|
function TPresupuestosClienteController.Eliminar(const ID: Integer): Boolean;
|
|
var
|
|
APresupuesto : IBizPresupuestoCliente;
|
|
begin
|
|
APresupuesto := Buscar(ID);
|
|
|
|
if not Assigned(APresupuesto) then
|
|
raise Exception.Create(Format('No se ha encontrado el presupuesto con ID = %d', [ID]));
|
|
|
|
Result := Eliminar(APresupuesto);
|
|
APresupuesto := NIL;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.ElegirPresupuestos(APresupuesto: IBizPresupuestoCliente; AMensaje: String; AMultiSelect: Boolean): IBizPresupuestoCliente;
|
|
var
|
|
AEditor : IEditorElegirPresupuestosCliente;
|
|
begin
|
|
Result := NIL;
|
|
|
|
CreateEditor('EditorElegirPresupuestosCliente', IEditorElegirPresupuestosCliente, AEditor);
|
|
if Assigned(AEditor) then
|
|
try
|
|
AEditor.Controller := Self;
|
|
AEditor.Presupuestos := APresupuesto;
|
|
AEditor.MultiSelect := AMultiSelect;
|
|
AEditor.Mensaje := AMensaje;
|
|
if IsPositiveResult(AEditor.ShowModal) then
|
|
Result := AEditor.PresupuestosClienteSeleccionados;
|
|
finally
|
|
AEditor.Release;
|
|
AEditor := NIL;
|
|
end;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.Eliminar(APresupuesto: 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(APresupuesto) then
|
|
raise Exception.Create ('APresupuesto no asignado');
|
|
|
|
ShowHourglassCursor;
|
|
try
|
|
if not APresupuesto.DataTable.Active then
|
|
APresupuesto.DataTable.Active := True;
|
|
|
|
if (APresupuesto.State in dsEditModes) then
|
|
APresupuesto.Cancel;
|
|
|
|
//Siempre eliminaremos el seleccionado
|
|
if EsEliminable(APresupuesto) then
|
|
begin
|
|
//GESTION_DOCUMENTOS
|
|
FGestorDocumentosController.EliminarDirectorio(APresupuesto.ID);
|
|
|
|
APresupuesto.Delete;
|
|
bEliminado := True;
|
|
end;
|
|
|
|
//En el caso de querer eliminar todos los items del objeto APresupuesto
|
|
if AllItems then
|
|
begin
|
|
with APresupuesto.DataTable do
|
|
begin
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
if EsEliminable(APresupuesto) then
|
|
begin
|
|
//GESTION_DOCUMENTOS
|
|
FGestorDocumentosController.EliminarDirectorio(APresupuesto.ID);
|
|
|
|
APresupuesto.Delete;
|
|
bEliminado := True
|
|
end
|
|
else Next;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
if bEliminado then
|
|
begin
|
|
APresupuesto.DataTable.ApplyUpdates;
|
|
Result := True;
|
|
end
|
|
else
|
|
Result := False;
|
|
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.EnviarPresupuestoPorEMail(
|
|
APresupuesto: IBizPresupuestoCliente);
|
|
var
|
|
AReportController : IPresupuestosClienteReportController;
|
|
AFicheroTMP : TFileName;
|
|
ATituloEnvio : String;
|
|
AEMail : String;
|
|
AListaEmail : TStringList;
|
|
begin
|
|
if not Assigned(APresupuesto) then
|
|
raise Exception.Create ('Presupuesto no asignado (EnviarPresupuestoPorEMail)');
|
|
|
|
if APresupuesto.DataTable.Active then
|
|
APresupuesto.DataTable.Active := True;
|
|
|
|
AListaEmail := TStringList.Create;
|
|
try
|
|
RecuperarCliente(APresupuesto);
|
|
APresupuesto.Cliente.DataTable.Active := True;
|
|
|
|
if not APresupuesto.Cliente.EMAIL_1IsNull then
|
|
AListaEmail.Add(APresupuesto.Cliente.EMAIL_1);
|
|
if not APresupuesto.Cliente.EMAIL_2IsNull then
|
|
AListaEmail.Add(APresupuesto.Cliente.EMAIL_2);
|
|
|
|
if not ElegirEMail(AListaEmail, AEMail) then
|
|
Exit;
|
|
finally
|
|
FreeANDNIL(AListaEmail);
|
|
end;
|
|
|
|
ShowHourglassCursor;
|
|
ATituloEnvio := 'Presupuesto ' + APresupuesto.Cliente.NOMBRE + ' - ' + APresupuesto.REFERENCIA_CLIENTE;
|
|
AFicheroTMP := DarFicheroPDFTemporal(EscapeIllegalChars(ATituloEnvio));
|
|
AReportController := TPresupuestosClienteReportController.Create;
|
|
try
|
|
AReportController.ExportToPDF(APresupuesto.ID, AFicheroTMP);
|
|
SendMailMAPI(ATituloEnvio, '', AFicheroTMP, '', '', APresupuesto.Cliente.NOMBRE, AEMail);
|
|
finally
|
|
DeleteFile(AFicheroTMP);
|
|
AReportController := NIL;
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.EsEliminable(APresupuesto: IBizPresupuestoCliente): Boolean;
|
|
begin
|
|
if not Assigned(APresupuesto) then
|
|
raise Exception.Create ('Presupuesto no asignado: EsEliminable');
|
|
|
|
Result := (APresupuesto.SITUACION = SITUACION_PRESUPUESTO_PENDIENTE);
|
|
end;
|
|
|
|
function TPresupuestosClienteController.EsModificable(APresupuesto: IBizPresupuestoCliente): Boolean;
|
|
begin
|
|
if not Assigned(APresupuesto) then
|
|
raise Exception.Create ('Presupuesto no asignado (EsModificable)');
|
|
|
|
//Result := (APresupuesto.SITUACION = SITUACION_PRESUPUESTO_PENDIENTE);
|
|
|
|
Result := True;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.RecalcularImportes(
|
|
APresupuesto: IBizPresupuestoCliente);
|
|
var
|
|
bEnEdicion : Boolean;
|
|
ADetallePosAct : Integer;
|
|
begin
|
|
if not Assigned(APresupuesto) then
|
|
raise Exception.Create ('Presupuesto no asignado (RecalcularImportes)');
|
|
|
|
if APresupuesto.DataTable.Active then
|
|
APresupuesto.DataTable.Active := True;
|
|
|
|
{ Hay que guardar la posición en la que estamos en los detalles por que
|
|
la asignació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ón por la que mueve el puntero. }
|
|
|
|
ADetallePosAct := APresupuesto.Detalles.POSICION;
|
|
|
|
bEnEdicion := (APresupuesto.DataTable.State in dsEditModes);
|
|
if not bEnEdicion then
|
|
APresupuesto.Edit;
|
|
|
|
ShowHourglassCursor;
|
|
try
|
|
APresupuesto.IMPORTE_NETO := FDetallesController.DarTotalImporteTotal(APresupuesto.Detalles);
|
|
APresupuesto.IMPORTE_PORTE := FDetallesController.DarTotalPorteTotal(APresupuesto.Detalles);
|
|
|
|
if not bEnEdicion then
|
|
APresupuesto.Post;
|
|
finally
|
|
HideHourglassCursor;
|
|
// Restaurar la posición que teníamos en los detalles.
|
|
FDetallesController.LocalizarPosicion(APresupuesto.Detalles, ADetallePosAct);
|
|
end;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable);
|
|
var
|
|
APresupuesto : IBizPresupuestoCliente;
|
|
ADetalles : IBizDetallesPresupuestoCliente;
|
|
begin
|
|
inherited;
|
|
|
|
if Supports(ADataTable, IBizDetallesPresupuestoCliente, ADetalles) and
|
|
Supports(ADetalles.DataTable.MasterSource.DataTable, IBizPresupuestoCliente, APresupuesto) then
|
|
begin
|
|
RecalcularImportes(APresupuesto);
|
|
end;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.RecuperarObjetos(APresupuesto: IBizPresupuestoCliente);
|
|
begin
|
|
RecuperarCliente(APresupuesto);
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.RecuperarCliente(
|
|
APresupuesto: IBizPresupuestoCliente);
|
|
begin
|
|
APresupuesto._Cliente := (FClienteController.Buscar(APresupuesto.ID_Cliente) as IBizCliente);
|
|
end;
|
|
|
|
function TPresupuestosClienteController.Existe(const ID: Integer): Boolean;
|
|
var
|
|
APresupuesto : IBizPresupuestoCliente;
|
|
begin
|
|
try
|
|
APresupuesto := Buscar(ID);
|
|
Result := Assigned(APresupuesto) and (APresupuesto.ID = ID);
|
|
finally
|
|
APresupuesto := NIL;
|
|
end;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.ExtraerSeleccionados(APresupuesto: IBizPresupuestoCliente): IBizPresupuestoCliente;
|
|
var
|
|
ASeleccionados : IBizPresupuestoCliente;
|
|
begin
|
|
ASeleccionados := (Self.Buscar(ID_NULO) as IBizPresupuestoCliente);
|
|
CopyDataTableDA5(APresupuesto.DataTable, ASeleccionados.DataTable, True);
|
|
Result := ASeleccionados;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.FiltrarAno(APresupuesto: IBizPresupuestoCliente; ADynWhereDataTable: WideString;const Ano: String);
|
|
var
|
|
Condicion: TDAWhereExpression;
|
|
FechaIni: String;
|
|
FechaFin: String;
|
|
|
|
begin
|
|
APresupuesto.DataTable.DynamicWhere.Clear;
|
|
APresupuesto.DataTable.DynamicWhere.Xml := ADynWhereDataTable;
|
|
|
|
if (Ano <> 'Todos') then
|
|
begin
|
|
// Filtrar las facturas actuales por empresa
|
|
FechaIni := '01/01/' + Ano;
|
|
FechaFin := '31/12/' + Ano;
|
|
with APresupuesto.DataTable.DynamicWhere do
|
|
begin
|
|
// (FECHA_INICIO between FECHA_FIN)
|
|
Condicion := NewBinaryExpression(NewField('', fld_PresupuestosClienteFECHA_PRESUPUESTO), NewConstant(FechaIni, datString), dboGreaterOrEqual);
|
|
Condicion := NewBinaryExpression(NewBinaryExpression(NewField('', fld_PresupuestosClienteFECHA_PRESUPUESTO), NewConstant(FechaFin, datString), dboLessOrEqual), Condicion, dboAnd);
|
|
|
|
if IsEmpty then
|
|
Expression := Condicion
|
|
else
|
|
Expression := NewBinaryExpression(Condicion, Expression, dboAnd);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.RellenarValoresDefecto(APresupuesto: IBizPresupuestoCliente; ATipo: TEnumTiposPresupuesto);
|
|
var
|
|
ACadena : String;
|
|
begin
|
|
case ATipo of
|
|
teCocina:
|
|
begin
|
|
APresupuesto.TIPO_PRESUPUESTO := CTE_COCINA;
|
|
APresupuesto.FORMA_PAGO.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_FORMA_PAGO_COCINA));
|
|
APresupuesto.PLAZO_ENTREGA.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_PLAZOS_ENTREGA_COCINA));
|
|
APresupuesto.OBSERVACIONES.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_OBSERVACIONES_COCINA));
|
|
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CALIDADES_COCINA);
|
|
if (ACadena <> '') then
|
|
APresupuesto.CALIDADES.Add(ACadena);
|
|
(Self.DetallesController as IDetallesPresupuestoClienteController).AnadirCapitulo(TIPO_CAPITULO_C_VACIO, 'MUEBLES DE COCINA ', False, APresupuesto.Detalles);
|
|
// (Self.DetallesController as IDetallesPresupuestoClienteController).AnadirCapitulo(TIPO_CAPITULO_V, 'IMPORTES ', True, APresupuesto.Detalles);
|
|
// (Self.DetallesController as IDetallesPresupuestoClienteController).AnadirCapitulo(TIPO_CAPITULO_V, 'AUMENTO POR ', False, APresupuesto.Detalles);
|
|
end;
|
|
teArmario:
|
|
begin
|
|
APresupuesto.TIPO_PRESUPUESTO := CTE_ARMARIO;
|
|
APresupuesto.FORMA_PAGO.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_FORMA_PAGO_ARMARIO));
|
|
APresupuesto.PLAZO_ENTREGA.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_PLAZOS_ENTREGA_ARMARIO));
|
|
APresupuesto.OBSERVACIONES.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_OBSERVACIONES_ARMARIO));
|
|
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CALIDADES_ARMARIO);
|
|
if (ACadena <> '') then
|
|
APresupuesto.CALIDADES.Add(ACadena);
|
|
(Self.DetallesController as IDetallesPresupuestoClienteController).AnadirCapitulo(TIPO_CAPITULO_AF, 'FRENTE DE ARMARIO Nº ', false, APresupuesto.Detalles);
|
|
(Self.DetallesController as IDetallesPresupuestoClienteController).AnadirCapitulo(TIPO_CAPITULO_AI, 'INTERIOR DE ARMARIO Nº ', false, APresupuesto.Detalles);
|
|
end;
|
|
teBano:
|
|
begin
|
|
APresupuesto.TIPO_PRESUPUESTO := CTE_BANO;
|
|
APresupuesto.FORMA_PAGO.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_FORMA_PAGO_BANO));
|
|
APresupuesto.PLAZO_ENTREGA.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_PLAZOS_ENTREGA_BANO));
|
|
APresupuesto.OBSERVACIONES.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_OBSERVACIONES_BANO));
|
|
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CALIDADES_BANO);
|
|
if (ACadena <> '') then
|
|
APresupuesto.CALIDADES.Add(ACadena);
|
|
(Self.DetallesController as IDetallesPresupuestoClienteController).AnadirCapitulo(TIPO_CAPITULO_B, 'MUEBLE DE BAÑO Nº ', false, APresupuesto.Detalles);
|
|
// (Self.DetallesController as IDetallesPresupuestoClienteController).AnadirCapitulo(TIPO_CAPITULO_V, 'IMPORTES ', false, APresupuesto.Detalles);
|
|
end;
|
|
teElectrodomestico:
|
|
begin
|
|
APresupuesto.TIPO_PRESUPUESTO := CTE_ELECTRODOMESTICO;
|
|
APresupuesto.FORMA_PAGO.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_FORMA_PAGO_ELECTRODOMESTICO));
|
|
APresupuesto.PLAZO_ENTREGA.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_PLAZOS_ENTREGA_ELECTRODOMESTICO));
|
|
APresupuesto.OBSERVACIONES.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_OBSERVACIONES_ELECTRODOMESTICO));
|
|
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CALIDADES_ELECTRODOMESTICO);
|
|
if (ACadena <> '') then
|
|
APresupuesto.CALIDADES.Add(ACadena);
|
|
(Self.DetallesController as IDetallesPresupuestoClienteController).AnadirCapitulo(TIPO_CAPITULO_E, 'ELECTRODOMÉSTICOS ', false, APresupuesto.Detalles);
|
|
end;
|
|
teObra:
|
|
begin
|
|
APresupuesto.TIPO_PRESUPUESTO := CTE_OBRA;
|
|
APresupuesto.FORMA_PAGO.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_FORMA_PAGO_OBRA));
|
|
APresupuesto.PLAZO_ENTREGA.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_PLAZOS_ENTREGA_OBRA));
|
|
APresupuesto.OBSERVACIONES.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_OBSERVACIONES_OBRA));
|
|
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CALIDADES_OBRA);
|
|
if (ACadena <> '') then
|
|
APresupuesto.CALIDADES.Add(ACadena);
|
|
(Self.DetallesController as IDetallesPresupuestoClienteController).AnadirCapitulo(TIPO_CAPITULO_O, 'OBRA ', false, APresupuesto.Detalles);
|
|
end;
|
|
teVarios:
|
|
begin
|
|
APresupuesto.TIPO_PRESUPUESTO := CTE_VARIOS;
|
|
APresupuesto.FORMA_PAGO.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_FORMA_PAGO_VARIOS));
|
|
APresupuesto.PLAZO_ENTREGA.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_PLAZOS_ENTREGA_VARIOS));
|
|
APresupuesto.OBSERVACIONES.Add(AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_OBSERVACIONES_VARIOS));
|
|
ACadena := AppFactuGES.Configuracion.GetSettingAsString(teBD, CTE_CALIDADES_VARIOS);
|
|
if (ACadena <> '') then
|
|
APresupuesto.CALIDADES.Add(ACadena);
|
|
(Self.DetallesController as IDetallesPresupuestoClienteController).AnadirCapitulo(TIPO_CAPITULO_V, 'VARIOS ', false, APresupuesto.Detalles);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.FiltrarEmpresa(APresupuesto: IBizPresupuestoCliente);
|
|
var
|
|
Condicion: TDAWhereExpression;
|
|
begin
|
|
if APresupuesto.DataTable.Active then
|
|
APresupuesto.DataTable.Active := False;
|
|
|
|
// Filtrar los presupuestos actuales por empresa
|
|
with APresupuesto.DataTable.DynamicWhere do
|
|
begin
|
|
// (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);
|
|
end;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.SetClienteController(const Value: IClientesController);
|
|
begin
|
|
FClienteController := Value;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.SetDetallesController(const Value: IDetallesPresupuestoClienteController);
|
|
begin
|
|
FDetallesController := Value;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.SetGestorDocumentosController(
|
|
const Value: IGestorDocumentosController);
|
|
begin
|
|
FGestorDocumentosController := Value;
|
|
end;
|
|
|
|
{
|
|
function TPresupuestosClienteController.SubirFichero(const ID: Integer; const NombreFichero: String; const Fichero: Binary): Boolean;
|
|
begin
|
|
Result := FDataModule.SubirFichero(ID, NombreFichero, Fichero);
|
|
end;
|
|
}
|
|
|
|
function TPresupuestosClienteController.Guardar(APresupuesto: IBizPresupuestoCliente): Boolean;
|
|
begin
|
|
Result := False;
|
|
|
|
if not Assigned(APresupuesto) then
|
|
raise Exception.Create ('Presupuesto no asignada');
|
|
|
|
if not Assigned(FDetallesController) then
|
|
raise Exception.Create ('Controller detalles no asignado');
|
|
|
|
if ValidarPresupuesto(APresupuesto) then
|
|
begin
|
|
ShowHourglassCursor;
|
|
|
|
// Asegurarnos de que todos los importes están bien.
|
|
RecalcularImportes(APresupuesto);
|
|
|
|
try
|
|
APresupuesto.DataTable.ApplyUpdates;
|
|
Result := True;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.Localizar(APresupuestos: IBizPresupuestoCliente;
|
|
const ID: Integer): Boolean;
|
|
begin
|
|
Result := True;
|
|
ShowHourglassCursor;
|
|
try
|
|
with APresupuestos.DataTable do
|
|
begin
|
|
DisableControls;
|
|
First;
|
|
if not Locate(fld_PresupuestosClienteID, ID, []) then
|
|
Result := False;
|
|
EnableControls;
|
|
end;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.Nuevo: IBizPresupuestoCliente;
|
|
var
|
|
APresupuesto : IBizPresupuestoCliente;
|
|
begin
|
|
APresupuesto := FDataModule.NewItem;
|
|
FiltrarEmpresa(APresupuesto);
|
|
APresupuesto.DataTable.Active := True;
|
|
APresupuesto.Insert;
|
|
Result := APresupuesto;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.QuitarDireccionEnvio(
|
|
APresupuesto: IBizPresupuestoCliente);
|
|
{var
|
|
bEnEdicion : Boolean;}
|
|
begin
|
|
{
|
|
if not Assigned(APresupuesto) then
|
|
raise Exception.Create ('Presupuesto no asignado (QuitarDireccionEnvio)');
|
|
|
|
if APresupuesto.DataTable.Active then
|
|
APresupuesto.DataTable.Active := True;
|
|
|
|
bEnEdicion := (APresupuesto.DataTable.State in dsEditModes);
|
|
if not bEnEdicion then
|
|
APresupuesto.Edit;
|
|
|
|
ShowHourglassCursor;
|
|
APresupuesto.Edit;
|
|
try
|
|
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;
|
|
|
|
if not bEnEdicion then
|
|
APresupuesto.Post;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
}
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.Preview(APresupuesto: IBizPresupuestoCliente; AllItems: Boolean = false);
|
|
var
|
|
AReportController : IPresupuestosClienteReportController;
|
|
ID_Presupuestos: TIntegerList;
|
|
begin
|
|
AReportController := TPresupuestosClienteReportController.Create;
|
|
try
|
|
ID_Presupuestos := TIntegerList.Create;
|
|
|
|
//Si deseamos previsualizar todos los items del objeto presupuesto
|
|
if AllItems then
|
|
begin
|
|
with APresupuesto.DataTable do
|
|
begin
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
ID_Presupuestos.Add(APresupuesto.ID);
|
|
Next;
|
|
end;
|
|
end;
|
|
end
|
|
//Solo previsualizamos el item seleccionado
|
|
else
|
|
ID_Presupuestos.Add(APresupuesto.ID);
|
|
|
|
AReportController.Preview(ID_Presupuestos);
|
|
finally
|
|
AReportController := NIL;
|
|
FreeAndNil(ID_Presupuestos);
|
|
end;
|
|
end;
|
|
|
|
procedure TPresupuestosClienteController.Print(APresupuesto: IBizPresupuestoCliente; AllItems: Boolean = false);
|
|
var
|
|
AReportController : IPresupuestosClienteReportController;
|
|
ID_Presupuestos: TIntegerList;
|
|
begin
|
|
AReportController := TPresupuestosClienteReportController.Create;
|
|
ID_Presupuestos := TIntegerList.Create;
|
|
try
|
|
//Si deseamos imprimimos todos los items del objeto presupuesto
|
|
if AllItems then
|
|
begin
|
|
with APresupuesto.DataTable do
|
|
begin
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
ID_Presupuestos.Add(APresupuesto.ID);
|
|
Next;
|
|
end;
|
|
end;
|
|
end
|
|
//Solo imprimimos el item seleccionado
|
|
else
|
|
ID_Presupuestos.Add(APresupuesto.ID);
|
|
|
|
AReportController.Print(ID_Presupuestos);
|
|
|
|
finally
|
|
AReportController := NIL;
|
|
FreeANDNIL(ID_Presupuestos);
|
|
end;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.GetClienteController: IClientesController;
|
|
begin
|
|
Result := FClienteController;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.GetDetallesController: IDetallesPresupuestoClienteController;
|
|
begin
|
|
Result := FDetallesController;
|
|
end;
|
|
|
|
function TPresupuestosClienteController.GetGestorDocumentosController: IGestorDocumentosController;
|
|
begin
|
|
Result := FGestorDocumentosController;
|
|
end;
|
|
|
|
end.
|