2009-12-16 17:16:54 +00:00
unit uViewDatosYSeleccionClienteFacturaCliente;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uViewBase, StdCtrls, cxControls, cxContainer, cxEdit, cxLabel,
2010-02-01 19:24:25 +00:00
cxDBLabel, ExtCtrls, DB, uDADataTable, uBizContactos, uDMBase,
2009-12-16 17:16:54 +00:00
ComCtrls, ToolWin, ActnList, ImgList, PngImageList, cxTextEdit, cxDBEdit,
pngimage, JvExControls, JvComponent, JvButton, JvTransparentButton, Mask,
DBCtrls, uClientesController, dxLayoutControl, Buttons, uDAInterfaces,
cxMaskEdit, cxButtonEdit, uBizFacturasCliente, uBizDireccionesContacto,
2010-01-15 08:27:38 +00:00
uDireccionesContactoController, Menus, cxLookAndFeelPainters, cxButtons,
2010-02-01 15:48:29 +00:00
cxMemo, cxGraphics, cxLookAndFeels, dxLayoutcxEditAdapters;
2009-12-16 17:16:54 +00:00
type
IViewDatosYSeleccionClienteFacturaCliente = interface( IViewBase)
[ '{0336F03C-3349-4368-BF63-D03E6F741069}' ]
function GetFactura: IBizFacturaCliente;
procedure SetFactura( const Value: IBizFacturaCliente) ;
property Factura: IBizFacturaCliente read GetFactura write SetFactura;
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 ElegirDireccionCliente;
procedure ElegirCliente;
procedure VerFichaCliente;
procedure AnadirNuevoCliente;
procedure RefrescarDireccion;
end ;
TfrViewDatosYSeleccionClienteFacturaCliente = class( TfrViewBase, IViewDatosYSeleccionClienteFacturaCliente)
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;
dsFactura: TDADataSource;
actElegirDireccion: TAction;
dxLayoutControl1Group4: TdxLayoutGroup;
Button4: TButton;
dxLayoutControl1Item5: TdxLayoutItem;
dxLayoutControl1Group3: TdxLayoutGroup;
2010-01-15 08:27:38 +00:00
dxLayoutControl1Item3: TdxLayoutItem;
edtPersonaContacto: TcxDBTextEdit;
dxLayoutControl1Item6: TdxLayoutItem;
Button5: TButton;
dxLayoutControl1Group6: TdxLayoutGroup;
dxLayoutControl1Item4: TdxLayoutItem;
edtDireccion: TcxMemo;
dxLayoutControl1Group5: TdxLayoutGroup;
2009-12-16 17:16:54 +00:00
procedure actElegirContactoExecute( Sender: TObject) ;
procedure actAnadirContactoExecute( Sender: TObject) ;
procedure actVerContactoUpdate( Sender: TObject) ;
procedure edtDireccionPropertiesButtonClick( Sender: TObject;
AButtonIndex: Integer ) ;
procedure actVerContactoExecute( Sender: TObject) ;
procedure actElegirDireccionUpdate( Sender: TObject) ;
procedure actElegirDireccionExecute( Sender: TObject) ;
procedure actElegirPersonaContactoUpdate( Sender: TObject) ;
private
FOnClienteChanged : TNotifyEvent;
FMsgElegirCliente: String ;
protected
FClientesController : IClientesController;
FDireccionesController : IDireccionesContactoController;
FFactura : IBizFacturaCliente;
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 GetFactura: IBizFacturaCliente;
procedure SetFactura( const Value: IBizFacturaCliente) ;
procedure EscribirTextoDireccion;
procedure CopiarDireccionAFactura;
procedure LimpiarDireccionDeFactura;
public
constructor Create( AOwner: TComponent) ; override ;
destructor Destroy; override ;
procedure ElegirDireccionCliente;
procedure ElegirCliente;
procedure VerFichaCliente;
procedure AnadirNuevoCliente;
procedure RefrescarDireccion;
property Factura: IBizFacturaCliente read GetFactura write SetFactura;
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 TfrViewDatosYSeleccionClienteFacturaCliente. actElegirContactoExecute( Sender: TObject) ;
begin
ElegirCliente;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. actElegirDireccionExecute(
Sender: TObject) ;
begin
inherited ;
ElegirDireccionCliente;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. actElegirDireccionUpdate(
Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = Assigned( FCliente. Direcciones) and
( FCliente. Direcciones. Active) and ( FCliente. Direcciones. RecordCount > 0 ) ;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. actElegirPersonaContactoUpdate(
Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = Assigned( FCliente. Personal) and
( FCliente. Personal. Active) and ( FCliente. Personal. RecordCount > 0 ) ;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. actAnadirContactoExecute(
Sender: TObject) ;
begin
AnadirNuevoCliente;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. actVerContactoExecute(
Sender: TObject) ;
begin
inherited ;
VerFichaCliente;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. actVerContactoUpdate( Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = ( Length( edtlNombre. Text ) > 0 ) ;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. AnadirNuevoCliente;
var
ACliente : IBizCliente;
begin
inherited ;
ACliente : = ( FClientesController. Nuevo as IBizCliente) ;
FClientesController. Ver( ACliente) ;
Self. Cliente : = ACliente;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. CopiarDireccionAFactura;
begin
FFactura. Edit;
FFactura. ID_DIRECCION : = FDireccion. ID;
FFactura. CALLE : = FDireccion. CALLE;
FFactura. POBLACION : = FDireccion. POBLACION;
FFactura. CODIGO_POSTAL : = FDireccion. CODIGO_POSTAL;
FFactura. PROVINCIA : = FDireccion. PROVINCIA;
FFactura. IMPORTE_PORTE : = FDireccion. PORTE;
end ;
constructor TfrViewDatosYSeleccionClienteFacturaCliente. Create( AOwner: TComponent) ;
begin
inherited ;
FMsgElegirCliente : = 'Elija el cliente al que se le realizar<61> la factura.' ;
FClientesController : = TClientesController. Create;
FDireccionesController : = TDireccionesContactoController. Create;
edtlNombre. Enabled : = False ;
edtNIFCIF. Enabled : = False ;
edtDireccion. Enabled : = False ;
end ;
destructor TfrViewDatosYSeleccionClienteFacturaCliente. Destroy;
begin
FClientesController : = NIL ;
FDireccionesController : = NIL ;
inherited ;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. edtDireccionPropertiesButtonClick(
Sender: TObject; AButtonIndex: Integer ) ;
begin
inherited ;
ElegirDireccionCliente;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. ElegirCliente;
var
ACliente : IBizCliente;
begin
inherited ;
ACliente : = ( FClientesController. ElegirContacto( FClientesController. BuscarTodos, FMsgElegirCliente, False ) as IBizCliente) ;
if Assigned( ACliente) then
Self. Cliente : = ACliente;
ACliente : = Nil ;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. ElegirDireccionCliente;
var
ADireccion : IBizDireccionesContacto;
begin
inherited ;
ADireccion : = FClientesController. ElegirDireccionEntrega( FCliente, ' ' ) ;
if Assigned( ADireccion) then
begin
FDireccion : = ADireccion;
// if FDireccion.IDIsNull then
// LimpiarDireccionDeFactura
// else
CopiarDireccionAFactura;
EscribirTextoDireccion;
end ;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. EscribirTextoDireccion;
var
ACadena : String ;
begin
ACadena : = '' ;
if Assigned( FDireccion) then
ACadena : = Format( '%s %s %s %s' ,
2010-01-15 08:27:38 +00:00
[ FDireccion. CALLE, FDireccion. POBLACION,
FDireccion. CODIGO_POSTAL, FDireccion. PROVINCIA] ) ;
2009-12-16 17:16:54 +00:00
edtDireccion. Text : = ACadena;
end ;
function TfrViewDatosYSeleccionClienteFacturaCliente. GetCliente: IBizCliente;
begin
Result : = FCliente;
end ;
function TfrViewDatosYSeleccionClienteFacturaCliente. GetID_Cliente: integer ;
begin
Result : = - 1 ;
if Assigned( FCliente) then
Result : = FCliente. ID;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. 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 ;
2010-03-04 19:11:24 +00:00
//En noviseda un cliente solo podr<64> tener una direccion de envio que nunca se tendr<64> en cuenta para los documentos (facturas, albaranes, etc) solo para las etiquetas y se hace por el informe
// if FCliente.Direcciones.RecordCount > 0 then
// ElegirDireccionCliente
// else
// begin
2010-01-15 08:27:38 +00:00
FFactura. Edit;
FFactura. PERSONA_CONTACTO : = FCliente. PERSONA_CONTACTO;
RefrescarDireccion;
2010-03-04 19:11:24 +00:00
// end;
2009-12-16 17:16:54 +00:00
end
else begin
dsCliente. DataTable : = NIL ;
FCliente : = NIL ;
FDireccion : = NIL ;
end ;
if Assigned( FOnClienteChanged) then
FOnClienteChanged( Self) ;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. SetID_Cliente( const Value: integer ) ;
begin
Self. Cliente : = IBizCliente( FClientesController. Buscar( Value) ) ;
end ;
function TfrViewDatosYSeleccionClienteFacturaCliente. GetOnClienteChanged: TNotifyEvent;
begin
Result : = FOnClienteChanged;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. LimpiarDireccionDeFactura;
begin
FFactura. Edit;
FFactura. ClearField( 'ID_DIRECCION' ) ;
FFactura. ClearField( 'CALLE' ) ;
FFactura. ClearField( 'POBLACION' ) ;
FFactura. ClearField( 'CODIGO_POSTAL' ) ;
FFactura. ClearField( 'PROVINCIA' ) ;
FFactura. ClearField( 'IMPORTE_PORTE' ) ;
end ;
function TfrViewDatosYSeleccionClienteFacturaCliente. GetFactura: IBizFacturaCliente;
begin
Result : = FFactura;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. RefrescarDireccion;
begin
FDireccion : = FDireccionesController. Nuevo;
if ( not FFactura. ID_DIRECCIONIsNull) and
( FDireccionesController. Localizar( FCliente. Direcciones, FFactura. ID_DIRECCION) ) then
FDireccionesController. CopiarDireccion( FCliente. Direcciones, FDireccion)
else
FDireccionesController. CopiarDireccionFiscal( FCliente, FDireccion) ;
EscribirTextoDireccion;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. SetOnClienteChanged(
const Value: TNotifyEvent) ;
begin
FOnClienteChanged : = Value;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. SetFactura(
const Value: IBizFacturaCliente) ;
begin
FFactura : = Value;
if Assigned( FFactura) then
begin
dsFactura. DataTable : = FFactura. DataTable;
FCliente : = FFactura. Cliente;
dsCliente. DataTable : = FCliente. DataTable;
if not FCliente. DataTable. Active then
FCliente. DataTable. Active : = True ;
RefrescarDireccion;
end
else begin
dsFactura. DataTable : = NIL ;
FCliente : = NIL ;
FDireccion : = NIL ;
end ;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. SetReadOnly( Value: Boolean ) ;
begin
inherited ;
if ( csLoading in Self. ComponentState) then
Exit;
actAnadirContacto. Enabled : = not ReadOnly ;
actElegirContacto. Enabled : = not ReadOnly ;
end ;
procedure TfrViewDatosYSeleccionClienteFacturaCliente. VerFichaCliente;
begin
if not Assigned( Cliente) then
ShowErrorMessage( 'No se ha indicado un cliente' , 'La factura no tiene ning<6E> n cliente asociado a mostrar.' )
else begin
FClientesController. Ver( Cliente) ;
end ;
end ;
end .