2008-09-19 10:11:52 +00:00
unit uViewDatosYSeleccionClientePresupuesto;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uViewBase, StdCtrls, cxControls, cxContainer, cxEdit, cxLabel,
cxDBLabel, ExtCtrls, DB, uDADataTable, uBizContactos,
ComCtrls, ToolWin, ActnList, ImgList, PngImageList, cxTextEdit, cxDBEdit,
pngimage, JvExControls, JvComponent, JvButton, JvTransparentButton, Mask,
DBCtrls, uClientesController, dxLayoutControl, Buttons, uDAInterfaces,
cxMaskEdit, cxButtonEdit, uBizPresupuestosCliente, uBizDireccionesContacto,
uDireccionesContactoController, Menus, cxLookAndFeelPainters, cxButtons;
type
IViewDatosYSeleccionClientePresupuesto = interface( IViewBase)
[ '{0BD8B1D7-A992-448A-A9EE-ECE8CBA30A24}' ]
function GetPresupuesto: IBizPresupuestoCliente;
procedure SetPresupuesto( const Value: IBizPresupuestoCliente) ;
property Presupuesto: IBizPresupuestoCliente read GetPresupuesto write SetPresupuesto;
function GetCliente: IBizCliente;
procedure SetCliente( Value: IBizCliente) ;
property Cliente: IBizCliente read GetCliente write SetCliente;
function GetID_Cliente: integer ;
procedure SetID_Cliente( const Value: integer ) ;
property ID_Cliente: integer read GetID_Cliente write SetID_Cliente;
function GetOnClienteChanged : TNotifyEvent;
procedure SetOnClienteChanged ( const Value : TNotifyEvent) ;
property OnClienteChanged : TNotifyEvent read GetOnClienteChanged
write SetOnClienteChanged;
procedure ElegirPersonaContacto;
procedure ElegirDireccionCliente;
procedure ElegirCliente;
procedure VerFichaCliente;
procedure AnadirNuevoCliente;
procedure RefrescarDireccion;
end ;
TfrViewDatosYSeleccionClientePresupuesto = class( TfrViewBase, IViewDatosYSeleccionClientePresupuesto)
dsCliente: TDADataSource;
ActionList1: TActionList;
actElegirContacto: TAction;
actAnadirContacto: TAction;
actVerContacto: TAction;
PngImageList: TPngImageList;
dxLayoutControl1Group_Root: TdxLayoutGroup;
dxLayoutControl1: TdxLayoutControl;
dxLayoutControl1Item1: TdxLayoutItem;
edtlNombre: TcxDBTextEdit;
dxLayoutControl1Item2: TdxLayoutItem;
edtNIFCIF: TcxDBTextEdit;
Button1: TBitBtn;
dxLayoutControl1Item7: TdxLayoutItem;
Button2: TBitBtn;
dxLayoutControl1Item8: TdxLayoutItem;
Button3: TBitBtn;
dxLayoutControl1Item9: TdxLayoutItem;
dxLayoutControl1Group1: TdxLayoutGroup;
dxLayoutControl1Group2: TdxLayoutGroup;
dsPresupuesto: TDADataSource;
actElegirDireccion: TAction;
actElegirPersonaContacto: TAction;
dxLayoutControl1Item3: TdxLayoutItem;
edtPersonaContacto: TcxDBTextEdit;
dxLayoutControl1Group4: TdxLayoutGroup;
dxLayoutControl1Item4: TdxLayoutItem;
edtDireccion: TcxTextEdit;
Button4: TButton;
dxLayoutControl1Item5: TdxLayoutItem;
dxLayoutControl1Group3: TdxLayoutGroup;
dxLayoutControl1Item6: TdxLayoutItem;
Button5: TButton;
dxLayoutControl1Group5: TdxLayoutGroup;
procedure actElegirContactoExecute( Sender: TObject) ;
procedure actAnadirContactoExecute( Sender: TObject) ;
procedure actVerContactoUpdate( Sender: TObject) ;
procedure edtPersonaContactoPropertiesButtonClick( Sender: TObject;
AButtonIndex: Integer ) ;
procedure edtDireccionPropertiesButtonClick( Sender: TObject;
AButtonIndex: Integer ) ;
procedure actVerContactoExecute( Sender: TObject) ;
procedure actElegirDireccionUpdate( Sender: TObject) ;
procedure actElegirDireccionExecute( Sender: TObject) ;
procedure actElegirPersonaContactoExecute( Sender: TObject) ;
procedure actElegirPersonaContactoUpdate( Sender: TObject) ;
private
FOnClienteChanged : TNotifyEvent;
FMsgElegirCliente: String ;
protected
FClientesController : IClientesController;
FDireccionesController : IDireccionesContactoController;
FPresupuesto : IBizPresupuestoCliente;
FCliente : IBizCliente;
FDireccion : IBizDireccionesContacto;
function GetCliente: IBizCliente; virtual ;
procedure SetCliente( Value: IBizCliente) ; virtual ;
function GetOnClienteChanged : TNotifyEvent;
procedure SetOnClienteChanged ( const Value : TNotifyEvent) ;
procedure SetReadOnly( Value: Boolean ) ; override ;
function GetID_Cliente: integer ; virtual ;
procedure SetID_Cliente( const Value: integer ) ; virtual ;
function GetPresupuesto: IBizPresupuestoCliente;
procedure SetPresupuesto( const Value: IBizPresupuestoCliente) ;
procedure EscribirTextoDireccion;
public
constructor Create( AOwner: TComponent) ; override ;
destructor Destroy; override ;
procedure ElegirPersonaContacto;
procedure ElegirDireccionCliente;
procedure ElegirCliente;
procedure VerFichaCliente;
procedure AnadirNuevoCliente;
procedure RefrescarDireccion;
property Presupuesto: IBizPresupuestoCliente read GetPresupuesto write SetPresupuesto;
property Cliente: IBizCliente read GetCliente write SetCliente;
property OnClienteChanged : TNotifyEvent read GetOnClienteChanged write SetOnClienteChanged;
property ID_Cliente: integer read GetID_Cliente write SetID_Cliente;
end ;
implementation
{$R *.dfm}
uses
uDataModuleClientes, Math, uCustomView, uBizContactosPersonal, uDialogUtils;
procedure TfrViewDatosYSeleccionClientePresupuesto. actElegirContactoExecute( Sender: TObject) ;
begin
ElegirCliente;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. actElegirDireccionExecute(
Sender: TObject) ;
begin
inherited ;
ElegirDireccionCliente;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. actElegirDireccionUpdate(
Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = Assigned( FCliente. Direcciones) and
( FCliente. Direcciones. Active) and ( FCliente. Direcciones. RecordCount > 0 ) ;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. actElegirPersonaContactoExecute(
Sender: TObject) ;
begin
inherited ;
ElegirPersonaContacto;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. actElegirPersonaContactoUpdate(
Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = Assigned( FCliente. Personal) and
( FCliente. Personal. Active) and ( FCliente. Personal. RecordCount > 0 ) ;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. actAnadirContactoExecute(
Sender: TObject) ;
begin
AnadirNuevoCliente;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. actVerContactoExecute(
Sender: TObject) ;
begin
inherited ;
VerFichaCliente;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. actVerContactoUpdate( Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = ( Length( edtlNombre. Text ) > 0 ) ;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. AnadirNuevoCliente;
var
ACliente : IBizCliente;
begin
inherited ;
ACliente : = ( FClientesController. Nuevo as IBizCliente) ;
FClientesController. Ver( ACliente) ;
Self. Cliente : = ACliente;
end ;
constructor TfrViewDatosYSeleccionClientePresupuesto. Create( AOwner: TComponent) ;
begin
inherited ;
FMsgElegirCliente : = 'Elija el cliente al que se le realizar<61> el presupuesto.' ;
FClientesController : = TClientesController. Create;
FDireccionesController : = TDireccionesContactoController. Create;
edtlNombre. Enabled : = False ;
edtNIFCIF. Enabled : = False ;
edtDireccion. Enabled : = False ;
2008-11-27 16:14:51 +00:00
edtPersonaContacto. Enabled : = False ;
2008-09-19 10:11:52 +00:00
end ;
destructor TfrViewDatosYSeleccionClientePresupuesto. Destroy;
begin
FClientesController : = NIL ;
FDireccionesController : = NIL ;
inherited ;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. edtDireccionPropertiesButtonClick(
Sender: TObject; AButtonIndex: Integer ) ;
begin
inherited ;
ElegirDireccionCliente;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. edtPersonaContactoPropertiesButtonClick(
Sender: TObject; AButtonIndex: Integer ) ;
begin
inherited ;
ElegirPersonaContacto;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. ElegirCliente;
var
ACliente : IBizCliente;
begin
inherited ;
2008-11-11 18:55:52 +00:00
2008-09-19 10:11:52 +00:00
ACliente : = ( FClientesController. ElegirContacto( FClientesController. BuscarTodos, FMsgElegirCliente, False ) as IBizCliente) ;
if Assigned( ACliente) then
Self. Cliente : = ACliente;
ACliente : = Nil ;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. ElegirDireccionCliente;
var
ADireccion : IBizDireccionesContacto;
begin
inherited ;
2008-11-06 11:19:46 +00:00
ADireccion : = FClientesController. ElegirDireccionEntrega( FCliente, ' ' ) ;
2008-09-19 10:11:52 +00:00
if Assigned( ADireccion) then
begin
FDireccion : = ADireccion;
FPresupuesto. Edit;
if FDireccion. IDIsNull then
begin
FPresupuesto. ClearField( 'ID_DIRECCION' ) ;
FPresupuesto. ClearField( 'IMPORTE_PORTE' ) ;
end
else begin
FPresupuesto. ID_DIRECCION : = FDireccion. ID;
FPresupuesto. IMPORTE_PORTE : = FDireccion. PORTE;
end ;
2009-06-29 16:22:34 +00:00
//Siempre asignaremos la persona de contacto ya sea de las direcciones del contacto o la ID_Direccion=0 que es la principal de la ficha
FPresupuesto. PERSONA_CONTACTO : = FDireccion. PERSONA_CONTACTO;
2008-09-19 10:11:52 +00:00
EscribirTextoDireccion;
end ;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. ElegirPersonaContacto;
var
APersona : IBizContactoPersonal;
begin
inherited ;
APersona : = FClientesController. ElegirPersonaContacto( FCliente. Personal, 'El cliente dispone de personas de contacto dadas de alta en su ficha. Seleccione la que quiere utilizar.' ) ;
if Assigned( APersona) then
begin
FPresupuesto. Edit;
FPresupuesto. PERSONA_CONTACTO : = APersona. NOMBRE;
end ;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. EscribirTextoDireccion;
var
ACadena : String ;
begin
ACadena : = '' ;
if Assigned( FDireccion) then
ACadena : = Format( '%s %s %s %s' ,
[ FDireccion. CALLE, FDireccion. POBLACION,
FDireccion. CODIGO_POSTAL, FDireccion. PROVINCIA] ) ;
edtDireccion. Text : = ACadena;
end ;
function TfrViewDatosYSeleccionClientePresupuesto. GetCliente: IBizCliente;
begin
Result : = FCliente;
end ;
function TfrViewDatosYSeleccionClientePresupuesto. GetID_Cliente: integer ;
begin
Result : = - 1 ;
if Assigned( FCliente) then
Result : = FCliente. ID;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. SetCliente( Value: IBizCliente) ;
begin
FCliente : = Value;
if Assigned( FCliente) then
begin
dsCliente. DataTable : = FCliente. DataTable;
if not FCliente. DataTable. Active then
FCliente. DataTable. Active : = True ;
2009-08-04 14:58:06 +00:00
//Solo podremos establecer persona de contacto si se ha asignado un cliente
if FCliente. ID > 0 then
edtPersonaContacto. Enabled : = True ;
2008-12-04 17:24:29 +00:00
if FCliente. Direcciones. RecordCount > 0 then
ElegirDireccionCliente
else begin
FPresupuesto. Edit;
FPresupuesto. PERSONA_CONTACTO : = FCliente. PERSONA_CONTACTO;
2011-03-31 11:07:06 +00:00
FPresupuesto. ID_DIRECCIONIsNull : = True ; //Limpiamos la direccion que pudiera tener el anterior cliente del documento si lo tuviere.
2008-12-04 17:24:29 +00:00
RefrescarDireccion;
end ;
2008-09-19 10:11:52 +00:00
end
else begin
dsCliente. DataTable : = NIL ;
FCliente : = NIL ;
FDireccion : = NIL ;
2008-11-27 16:14:51 +00:00
edtPersonaContacto. Enabled : = False ;
2008-09-19 10:11:52 +00:00
end ;
if Assigned( FOnClienteChanged) then
FOnClienteChanged( Self) ;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. SetID_Cliente( const Value: integer ) ;
begin
Self. Cliente : = IBizCliente( FClientesController. Buscar( Value) ) ;
end ;
function TfrViewDatosYSeleccionClientePresupuesto. GetOnClienteChanged: TNotifyEvent;
begin
Result : = FOnClienteChanged;
end ;
function TfrViewDatosYSeleccionClientePresupuesto. GetPresupuesto: IBizPresupuestoCliente;
begin
Result : = FPresupuesto;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. RefrescarDireccion;
begin
FDireccion : = FDireccionesController. Nuevo;
if ( not FPresupuesto. ID_DIRECCIONIsNull) and
( FDireccionesController. Localizar( FCliente. Direcciones, FPresupuesto. ID_DIRECCION) ) then
FDireccionesController. CopiarDireccion( FCliente. Direcciones, FDireccion)
else
FDireccionesController. CopiarDireccionFiscal( FCliente, FDireccion) ;
EscribirTextoDireccion;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. SetOnClienteChanged(
const Value: TNotifyEvent) ;
begin
FOnClienteChanged : = Value;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. SetPresupuesto(
const Value: IBizPresupuestoCliente) ;
begin
FPresupuesto : = Value;
if Assigned( FPresupuesto) then
begin
dsPresupuesto. DataTable : = FPresupuesto. DataTable;
FCliente : = FPresupuesto. Cliente;
dsCliente. DataTable : = FCliente. DataTable;
if not FCliente. DataTable. Active then
FCliente. DataTable. Active : = True ;
2009-08-04 14:58:06 +00:00
//Solo podremos establecer persona de contacto si se ha asignado un cliente
if FCliente. ID > 0 then
edtPersonaContacto. Enabled : = True ;
2008-09-19 10:11:52 +00:00
RefrescarDireccion;
end
else begin
dsPresupuesto. DataTable : = NIL ;
FCliente : = NIL ;
FDireccion : = NIL ;
end ;
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. SetReadOnly( Value: Boolean ) ;
begin
inherited ;
2008-09-23 15:28:46 +00:00
if ( csLoading in Self. ComponentState) then
Exit;
actAnadirContacto. Enabled : = not ReadOnly ;
actElegirContacto. Enabled : = not ReadOnly ;
2008-09-19 10:11:52 +00:00
end ;
procedure TfrViewDatosYSeleccionClientePresupuesto. VerFichaCliente;
begin
if not Assigned( Cliente) then
ShowErrorMessage( 'No se ha indicado un cliente' , 'El presupuesto no tiene ning<6E> n cliente asociado a mostrar.' )
else begin
FClientesController. Ver( Cliente) ;
end ;
end ;
end .