2011-11-14 17:40:41 +00:00
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<42> o' ;
CTE_ARMARIO = 'Armarios' ;
CTE_ELECTRODOMESTICO = 'Electrodom<6F> sticos' ;
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_FORMA_PAGO_ARMARIO = 'FORMA_PAGO_ARMARIO' ;
CTE_PLAZOS_ENTREGA_ARMARIO = 'PLAZOS_ENTREGA_ARMARIO' ;
CTE_OBSERVACIONES_ARMARIO = 'OBSERVACIONES_ARMARIO' ;
CTE_CONDICIONES_ARMARIO = 'CONDICIONES_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_FORMA_PAGO_ELECTRODOMESTICO = 'FORMA_PAGO_ELECTRODOMESTICO' ;
CTE_PLAZOS_ENTREGA_ELECTRODOMESTICO = 'PLAZOS_ENTREGA_ELECTRODOMESTICO' ;
CTE_OBSERVACIONES_ELECTRODOMESTICO = 'OBSERVACIONES_ELECTRODOMESTICO' ;
CTE_CONDICIONES_ELECTRODOMESTICO = 'CONDICIONES_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' ;
2012-07-11 15:39:13 +00:00
CTE_FORMA_PAGO_OBRA = 'FORMA_PAGO_OBRA' ;
CTE_PLAZOS_ENTREGA_OBRA = 'PLAZOS_ENTREGA_OBRA' ;
CTE_OBSERVACIONES_OBRA = 'OBSERVACIONES_OBRA' ;
CTE_CONDICIONES_OBRA = 'CONDICIONES_OBRA' ;
2011-11-14 17:40:41 +00:00
type
TEnumTiposPresupuesto = ( teCocina, teArmario, teBano, teElectrodomestico, 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) ;
2013-09-25 17:13:02 +00:00
procedure ActualizarFormaDePago( APresupuesto : IBizPresupuestoCliente; ID_FORMA_PAGO: Integer ) ;
2011-11-14 17:40:41 +00:00
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 ;
2013-06-07 16:09:30 +00:00
procedure Preview( APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false ; VerLogotipo: Boolean = true ;
2019-10-13 17:03:09 +00:00
const VerImprimirPrecios: Boolean = False ; const VerImprimirTotales: Boolean = False ; const VerImprimirTotalesCapitulo: Boolean = False ;
2013-06-07 16:09:30 +00:00
const VerImprimirObservaciones: Boolean = False ; const VerImprimirIncidencias: Boolean = False ) ;
procedure Print( APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false ; VerLogotipo: Boolean = true ;
2019-10-13 17:03:09 +00:00
const VerImprimirPrecios: Boolean = False ; const VerImprimirTotales: Boolean = False ; const VerImprimirTotalesCapitulo: Boolean = False ;
2013-06-07 16:09:30 +00:00
const VerImprimirObservaciones: Boolean = False ; const VerImprimirIncidencias: Boolean = False ) ;
2011-11-14 17:40:41 +00:00
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) ;
2013-09-25 17:13:02 +00:00
procedure ActualizarFormaDePago( APresupuesto : IBizPresupuestoCliente; ID_FORMA_PAGO: Integer ) ;
2011-11-14 17:40:41 +00:00
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 ;
2013-06-07 16:09:30 +00:00
procedure Preview( APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false ; VerLogotipo: Boolean = true ;
2019-10-13 17:03:09 +00:00
const VerImprimirPrecios: Boolean = False ; const VerImprimirTotales: Boolean = False ; const VerImprimirTotalesCapitulo: Boolean = False ;
2013-06-07 16:09:30 +00:00
const VerImprimirObservaciones: Boolean = False ; const VerImprimirIncidencias: Boolean = False ) ;
procedure Print( APresupuesto : IBizPresupuestoCliente; AllItems: Boolean = false ; VerLogotipo: Boolean = true ;
2019-10-13 17:03:09 +00:00
const VerImprimirPrecios: Boolean = False ; const VerImprimirTotales: Boolean = False ; const VerImprimirTotalesCapitulo: Boolean = False ;
2013-06-07 16:09:30 +00:00
const VerImprimirObservaciones: Boolean = False ; const VerImprimirIncidencias: Boolean = False ) ;
2011-11-14 17:40:41 +00:00
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,
2015-12-04 12:18:02 +00:00
schContactosClient_Intf, uPresupuestosClienteReportController,
uFormasPagoController, uBizFormasPago, uTiposIVAController, uBizTiposIVA,
2011-11-14 17:40:41 +00:00
uSistemaFunc, uEMailUtils, uDialogElegirEMail, Dialogs, uStringsUtils;
{ TPresupuestosClienteController }
2013-09-25 17:13:02 +00:00
procedure TPresupuestosClienteController. ActualizarFormaDePago( APresupuesto: IBizPresupuestoCliente; ID_FORMA_PAGO: Integer ) ;
var
AFormasPago : IBizFormaPago;
AFormasPagoController : IFormasPagoController;
2015-12-04 12:18:02 +00:00
ATiposIVA : IBizTipoIVA;
ATiposIVAController : ITiposIVAController;
2013-10-08 16:59:28 +00:00
bEnEdicion : Boolean ;
2013-09-25 17:13:02 +00:00
begin
AFormasPagoController : = TFormasPagoController. Create;
AFormasPago : = AFormasPagoController. Buscar( ID_FORMA_PAGO) ;
AFormasPago. Open;
2015-12-04 12:18:02 +00:00
//Se cambia tambien el tipo de IVA por el de la ficha a peticion de Angelica
ATiposIVAController : = TTiposIVAController. Create;
ATiposIVA : = ATiposIVAController. Buscar( APresupuesto. Cliente. ID_TIPO_IVA) ;
ATiposIVA. Open;
2013-10-08 16:59:28 +00:00
bEnEdicion : = ( APresupuesto. DataTable. State in dsEditModes) ;
if not bEnEdicion then
APresupuesto. Edit;
2013-09-25 17:13:02 +00:00
APresupuesto. ID_FORMA_PAGO : = AFormasPago. ID;
APresupuesto. DataTable. FieldByName( fld_PresupuestosClienteFORMA_PAGO) . AsString : = AFormasPago. DESCRIPCION;
2015-12-04 12:18:02 +00:00
APresupuesto. ID_TIPO_IVA : = ATiposIva. ID;
2013-10-08 16:59:28 +00:00
if not bEnEdicion then
APresupuesto. Post;
2015-12-04 12:18:02 +00:00
2013-09-25 17:13:02 +00:00
AFormasPago : = NIL ;
AFormasPagoController : = NIL ;
2015-12-04 12:18:02 +00:00
ATiposIVA : = NIL ;
ATiposIVAController : = NIL ;
2013-09-25 17:13:02 +00:00
end ;
2011-11-14 17:40:41 +00:00
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
2021-02-11 17:48:36 +00:00
// (ID_CONTRATO = NULL)
Condicion : = NewBinaryExpression( NewField( '' , fld_PresupuestosClienteID_CONTRATO) , NewNull( ) , dboEqual) ;
2011-11-14 17:40:41 +00:00
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;
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 ;
2018-04-03 15:53:26 +00:00
function TPresupuestosClienteController. Duplicar( APresupuesto: IBizPresupuestoCliente) : IBizPresupuestoCliente;
2011-11-14 17:40:41 +00:00
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;
2012-01-23 17:02:46 +00:00
ID_TIENDA : = AppFactuGES. TiendaActiva. ID;
2011-11-14 17:40:41 +00:00
USUARIO : = AppFactuGES. UsuarioActivo. UserName;
FECHA_PRESUPUESTO : = DateOf( Now) ;
2016-02-18 17:44:43 +00:00
FECHA_VIGENCIA : = IncMonth( Date, AppFactuGES. EmpresaActiva. VALIDEZ_PRESUPUESTOS) ;
2011-11-14 17:40:41 +00:00
INCIDENCIAS_ACTIVAS : = 0 ;
INCIDENCIASIsNull : = True ;
ID_CONTRATOIsNull : = True ;
FECHA_DECISIONIsNull : = True ;
REFERENCIA : = '' ;
SITUACION : = SITUACION_PRESUPUESTO_PENDIENTE;
2018-04-03 15:53:26 +00:00
PRECIO_PUNTO : = AppFactuGES. EmpresaActiva. PRECIO_PUNTO;
2011-11-14 17:40:41 +00:00
end ;
Result . Post;
2018-04-03 15:53:26 +00:00
2011-11-14 17:40:41 +00:00
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<63> n
if Assigned( APresupuesto. Cliente) then
APresupuesto. Cliente. DataTable. Active : = True ;
if ( APresupuesto. ID_Cliente < = 0 ) then
// Si hay altas autom<6F> 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<6F> ticos" tanto
en MODIFICACI<EFBFBD> N como en INSERCI<EFBFBD> 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;
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 ;
AFicheroTMP : = DarFicheroPDFTemporal( EscapeIllegalChars( APresupuesto. REFERENCIA) ) ;
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;
AReportController : = TPresupuestosClienteReportController. Create;
try
AReportController. ExportToPDF( APresupuesto. ID, AFicheroTMP) ;
SendMailMAPI( 'Presupuesto ' + APresupuesto. REFERENCIA, '' , 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)' ) ;
2011-11-18 17:12:39 +00:00
Result : = ( APresupuesto. SITUACION = SITUACION_PRESUPUESTO_PENDIENTE) OR ( APresupuesto. SITUACION = SITUACION_PRESUPUESTO_ANULADO) ;
2011-11-14 17:40:41 +00:00
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<EFBFBD> n en la que estamos en los detalles por que
la asignaci<EFBFBD> n de valores a los campos IMPORTE_NETO e IMPORTE_PORTE
( ver m<EFBFBD> s adelante) colocan el puntero en la tabla detalle al principio.
No he encontrado la raz<EFBFBD> n por la que mueve el puntero. }
ADetallePosAct : = APresupuesto. Detalles. POSICION;
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<63> n que ten<65> 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) ;
2011-11-18 17:12:39 +00:00
var
AFormasPago : IBizFormaPago;
AFormasPagoController : IFormasPagoController;
2011-11-14 17:40:41 +00:00
begin
2011-11-18 17:12:39 +00:00
AFormasPagoController : = TFormasPagoController. Create;
2011-11-14 17:40:41 +00:00
case ATipo of
teCocina:
begin
APresupuesto. TIPO_PRESUPUESTO : = CTE_COCINA;
2013-09-25 17:13:02 +00:00
APresupuesto. ID_FORMA_PAGO : = StrToInt( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_FORMA_PAGO_COCINA, AppFactuGES. EmpresaActiva. ID) ) ;
2011-11-18 17:12:39 +00:00
AFormasPago : = AFormasPagoController. Buscar( APresupuesto. ID_FORMA_PAGO) ;
AFormasPago. Open;
APresupuesto. FORMA_PAGO. Add( AFormasPago. DESCRIPCION) ;
2013-09-25 17:13:02 +00:00
APresupuesto. PLAZO_ENTREGA. Add( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_PLAZOS_ENTREGA_COCINA, AppFactuGES. EmpresaActiva. ID) ) ;
APresupuesto. OBSERVACIONES. Add( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_OBSERVACIONES_COCINA, AppFactuGES. EmpresaActiva. ID) ) ;
2012-07-11 15:39:13 +00:00
( Self. DetallesController as IDetallesPresupuestoClienteController) . AnadirCapitulo( TIPO_CAPITULO_C, 'MUEBLES DE COCINA ' , False , APresupuesto. Detalles) ;
( Self. DetallesController as IDetallesPresupuestoClienteController) . AnadirCapitulo( TIPO_CAPITULO_V, 'ENCIMERA ' , True , APresupuesto. Detalles) ;
( Self. DetallesController as IDetallesPresupuestoClienteController) . AnadirCapitulo( TIPO_CAPITULO_V, 'ELECTRODOM<4F> STICOS ' , True , APresupuesto. Detalles) ;
( Self. DetallesController as IDetallesPresupuestoClienteController) . AnadirCapitulo( TIPO_CAPITULO_V, 'COMPLEMENTOS ' , True , APresupuesto. Detalles) ;
2011-11-14 17:40:41 +00:00
( 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;
2013-09-25 17:13:02 +00:00
APresupuesto. ID_FORMA_PAGO : = StrToInt( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_FORMA_PAGO_ARMARIO, AppFactuGES. EmpresaActiva. ID) ) ;
2011-11-18 17:12:39 +00:00
AFormasPago : = AFormasPagoController. Buscar( APresupuesto. ID_FORMA_PAGO) ;
AFormasPago. Open;
APresupuesto. FORMA_PAGO. Add( AFormasPago. DESCRIPCION) ;
2013-09-25 17:13:02 +00:00
APresupuesto. PLAZO_ENTREGA. Add( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_PLAZOS_ENTREGA_ARMARIO, AppFactuGES. EmpresaActiva. ID) ) ;
APresupuesto. OBSERVACIONES. Add( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_OBSERVACIONES_ARMARIO, AppFactuGES. EmpresaActiva. ID) ) ;
2011-11-14 17:40:41 +00:00
( 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;
2013-09-25 17:13:02 +00:00
APresupuesto. ID_FORMA_PAGO : = StrToInt( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_FORMA_PAGO_BANO, AppFactuGES. EmpresaActiva. ID) ) ;
2011-11-18 17:12:39 +00:00
AFormasPago : = AFormasPagoController. Buscar( APresupuesto. ID_FORMA_PAGO) ;
AFormasPago. Open;
APresupuesto. FORMA_PAGO. Add( AFormasPago. DESCRIPCION) ;
2013-09-25 17:13:02 +00:00
APresupuesto. PLAZO_ENTREGA. Add( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_PLAZOS_ENTREGA_BANO, AppFactuGES. EmpresaActiva. ID) ) ;
APresupuesto. OBSERVACIONES. Add( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_OBSERVACIONES_BANO, AppFactuGES. EmpresaActiva. ID) ) ;
2011-11-14 17:40:41 +00:00
( Self. DetallesController as IDetallesPresupuestoClienteController) . AnadirCapitulo( TIPO_CAPITULO_B, 'MUEBLE DE BA<42> O N<> ' , False , APresupuesto. Detalles) ;
( Self. DetallesController as IDetallesPresupuestoClienteController) . AnadirCapitulo( TIPO_CAPITULO_V, 'IMPORTES ' , True , APresupuesto. Detalles) ;
end ;
teElectrodomestico:
begin
APresupuesto. TIPO_PRESUPUESTO : = CTE_ELECTRODOMESTICO;
2013-09-25 17:13:02 +00:00
APresupuesto. ID_FORMA_PAGO : = StrToInt( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_FORMA_PAGO_ELECTRODOMESTICO, AppFactuGES. EmpresaActiva. ID) ) ;
2011-11-18 17:12:39 +00:00
AFormasPago : = AFormasPagoController. Buscar( APresupuesto. ID_FORMA_PAGO) ;
AFormasPago. Open;
APresupuesto. FORMA_PAGO. Add( AFormasPago. DESCRIPCION) ;
2013-09-25 17:13:02 +00:00
APresupuesto. PLAZO_ENTREGA. Add( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_PLAZOS_ENTREGA_ELECTRODOMESTICO, AppFactuGES. EmpresaActiva. ID) ) ;
APresupuesto. OBSERVACIONES. Add( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_OBSERVACIONES_ELECTRODOMESTICO, AppFactuGES. EmpresaActiva. ID) ) ;
2011-11-14 17:40:41 +00:00
( Self. DetallesController as IDetallesPresupuestoClienteController) . AnadirCapitulo( TIPO_CAPITULO_E, 'ELECTRODOM<4F> STICOS ' , False , APresupuesto. Detalles) ;
end ;
teVarios:
begin
APresupuesto. TIPO_PRESUPUESTO : = CTE_VARIOS;
2013-09-25 17:13:02 +00:00
APresupuesto. ID_FORMA_PAGO : = StrToInt( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_FORMA_PAGO_VARIOS, AppFactuGES. EmpresaActiva. ID) ) ;
2011-11-18 17:12:39 +00:00
AFormasPago : = AFormasPagoController. Buscar( APresupuesto. ID_FORMA_PAGO) ;
AFormasPago. Open;
APresupuesto. FORMA_PAGO. Add( AFormasPago. DESCRIPCION) ;
2013-09-25 17:13:02 +00:00
APresupuesto. PLAZO_ENTREGA. Add( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_PLAZOS_ENTREGA_VARIOS, AppFactuGES. EmpresaActiva. ID) ) ;
APresupuesto. OBSERVACIONES. Add( AppFactuGES. Configuracion. GetSettingAsString( teBD, CTE_OBSERVACIONES_VARIOS, AppFactuGES. EmpresaActiva. ID) ) ;
2014-05-08 15:04:53 +00:00
( Self. DetallesController as IDetallesPresupuestoClienteController) . AnadirCapitulo( TIPO_CAPITULO_V, 'VARIOS ' , True , APresupuesto. Detalles) ;
2011-11-14 17:40:41 +00:00
end ;
end ;
2011-11-18 17:12:39 +00:00
AFormasPago: = Nil ;
AFormasPagoController : = Nil ;
2011-11-14 17:40:41 +00:00
end ;
procedure TPresupuestosClienteController. FiltrarEmpresa( APresupuesto: IBizPresupuestoCliente) ;
var
2013-05-16 17:17:31 +00:00
i: Integer ;
Condicion, Condicion2: TDAWhereExpression;
2011-11-14 17:40:41 +00:00
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) ;
2013-05-16 17:17:31 +00:00
for i: = 0 to AppFactuGES. EmpresaActiva. EmpresasPresupuestosComunes. Count - 1 do
begin
// (ID_EMPRESA >= ID)
Condicion2 : = NewBinaryExpression( NewField( '' , fld_PresupuestosClienteID_EMPRESA) , NewConstant( AppFactuGES. EmpresaActiva. EmpresasPresupuestosComunes. Strings[ i] , datString) , dboEqual) ;
Condicion : = NewBinaryExpression( Condicion, Condicion2, dboOR) ;
end ;
2011-11-14 17:40:41 +00:00
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<73> 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 ;
2013-06-07 16:09:30 +00:00
procedure TPresupuestosClienteController. Preview( APresupuesto: IBizPresupuestoCliente; AllItems: Boolean = false ; VerLogotipo: Boolean = true ;
2019-10-13 17:03:09 +00:00
const VerImprimirPrecios: Boolean = False ; const VerImprimirTotales: Boolean = False ; const VerImprimirTotalesCapitulo: Boolean = False ;
2013-06-07 16:09:30 +00:00
const VerImprimirObservaciones: Boolean = False ; const VerImprimirIncidencias: Boolean = False ) ;
2011-11-14 17:40:41 +00:00
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) ;
2019-10-13 17:03:09 +00:00
AReportController. Preview( ID_Presupuestos, VerLogotipo, VerImprimirPrecios, VerImprimirTotales, VerImprimirTotalesCapitulo) ;
2011-11-14 17:40:41 +00:00
finally
AReportController : = NIL ;
FreeAndNil( ID_Presupuestos) ;
end ;
end ;
2013-06-07 16:09:30 +00:00
procedure TPresupuestosClienteController. Print( APresupuesto: IBizPresupuestoCliente; AllItems: Boolean = false ; VerLogotipo: Boolean = true ;
2019-10-13 17:03:09 +00:00
const VerImprimirPrecios: Boolean = False ; const VerImprimirTotales: Boolean = False ; const VerImprimirTotalesCapitulo: Boolean = False ;
2013-06-07 16:09:30 +00:00
const VerImprimirObservaciones: Boolean = False ; const VerImprimirIncidencias: Boolean = False ) ;
2011-11-14 17:40:41 +00:00
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) ;
2019-10-13 17:03:09 +00:00
AReportController. Print( ID_Presupuestos, VerLogotipo, VerImprimirPrecios, VerImprimirTotales, VerImprimirTotalesCapitulo) ;
2011-11-14 17:40:41 +00:00
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 .