This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
LuisLeon_FactuGES2/Source/Modulos/Pedidos de cliente/Views/uViewDatosYSeleccionClientePedido.pas

449 lines
14 KiB
ObjectPascal
Raw Blame History

unit uViewDatosYSeleccionClientePedido;
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, uBizPedidosCliente, uBizDireccionesContacto,
uDireccionesContactoController, Menus, cxLookAndFeelPainters, cxButtons,
cxMemo;
type
IViewDatosYSeleccionClientePedido = interface(IViewBase)
['{AE9395DA-3D41-49D3-AEC8-D751BB543724}']
function GetPedido: IBizPedidoCliente;
procedure SetPedido(const Value: IBizPedidoCliente);
property Pedido: IBizPedidoCliente read GetPedido write SetPedido;
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;
TfrViewDatosYSeleccionClientePedido = class(TfrViewBase, IViewDatosYSeleccionClientePedido)
dsCliente: TDADataSource;
ActionList1: TActionList;
actElegirContacto: TAction;
actAnadirContacto: TAction;
actVerContacto: TAction;
dxLayoutControl1Group_Root: TdxLayoutGroup;
dxLayoutControl1: TdxLayoutControl;
dxLayoutControl1Item1: TdxLayoutItem;
edtlNombre: TcxDBTextEdit;
dxLayoutControl1Item2: TdxLayoutItem;
edtNIF_CIF: TcxDBTextEdit;
dsPedido: TDADataSource;
actElegirDireccion: TAction;
actElegirPersonaContacto: TAction;
dxLayoutControl1Item3: TdxLayoutItem;
edtPersonaContacto: TcxDBTextEdit;
dxLayoutControl1Group4: TdxLayoutGroup;
dxLayoutControl1Item4: TdxLayoutItem;
edtDireccion: TcxMemo;
Button4: TButton;
dxLayoutControl1Item5: TdxLayoutItem;
dxLayoutControl1Group3: TdxLayoutGroup;
dxLayoutControl1Item6: TdxLayoutItem;
Button5: TButton;
dxLayoutControl1Group5: TdxLayoutGroup;
dxLayoutControl1Item9: TdxLayoutItem;
Button3: TBitBtn;
dxLayoutControl1Group2: TdxLayoutGroup;
dxLayoutControl1Item7: TdxLayoutItem;
Button1: TBitBtn;
dxLayoutControl1Item10: TdxLayoutItem;
BitBtn1: TBitBtn;
dxLayoutControl1Group1: TdxLayoutGroup;
PngImageList: TPngImageList;
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;
FPedido : IBizPedidoCliente;
FCliente : IBizCliente;
FDireccion : IBizDireccionesContacto;
FDireccionEntrega : 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 GetPedido: IBizPedidoCliente;
procedure SetPedido(const Value: IBizPedidoCliente);
procedure EscribirTextoDireccion;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ElegirPersonaContacto;
procedure ElegirDireccionCliente;
procedure ElegirCliente;
procedure VerFichaCliente;
procedure AnadirNuevoCliente;
procedure RefrescarDireccion;
property Pedido: IBizPedidoCliente read GetPedido write SetPedido;
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 TfrViewDatosYSeleccionClientePedido.actElegirContactoExecute(Sender: TObject);
begin
ElegirCliente;
end;
procedure TfrViewDatosYSeleccionClientePedido.actElegirDireccionExecute(
Sender: TObject);
begin
inherited;
ElegirDireccionCliente;
end;
procedure TfrViewDatosYSeleccionClientePedido.actElegirDireccionUpdate(
Sender: TObject);
begin
inherited;
(Sender as TAction).Enabled := not ReadOnly and Assigned(FCliente.Direcciones) and
(FCliente.Direcciones.Active) and (FCliente.Direcciones.RecordCount > 0);
end;
procedure TfrViewDatosYSeleccionClientePedido.actElegirPersonaContactoExecute(
Sender: TObject);
begin
inherited;
ElegirPersonaContacto;
end;
procedure TfrViewDatosYSeleccionClientePedido.actElegirPersonaContactoUpdate(
Sender: TObject);
begin
inherited;
(Sender as TAction).Enabled := not ReadOnly and Assigned(FCliente.Personal) and
(FCliente.Personal.Active) and (FCliente.Personal.RecordCount > 0);
end;
procedure TfrViewDatosYSeleccionClientePedido.actAnadirContactoExecute(
Sender: TObject);
begin
AnadirNuevoCliente;
end;
procedure TfrViewDatosYSeleccionClientePedido.actVerContactoExecute(
Sender: TObject);
begin
inherited;
VerFichaCliente;
end;
procedure TfrViewDatosYSeleccionClientePedido.actVerContactoUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Enabled := (Length(edtlNombre.Text) > 0);
end;
procedure TfrViewDatosYSeleccionClientePedido.AnadirNuevoCliente;
var
ACliente : IBizCliente;
begin
inherited;
ACliente := (FClientesController.Nuevo as IBizCliente);
FClientesController.Ver(ACliente);
Self.Cliente := ACliente;
end;
constructor TfrViewDatosYSeleccionClientePedido.Create(AOwner: TComponent);
begin
inherited;
FMsgElegirCliente := 'Elija el proveedor al que se le realizar<61> el pedido.';
FClientesController := TClientesController.Create;
FDireccionesController := TDireccionesContactoController.Create;
edtlNombre.Enabled := False;
edtNIF_CIF.Enabled := False;
edtDireccion.Enabled := False;
edtPersonaContacto.Enabled := False;
end;
destructor TfrViewDatosYSeleccionClientePedido.Destroy;
begin
FClientesController := NIL;
FDireccionesController := NIL;
inherited;
end;
procedure TfrViewDatosYSeleccionClientePedido.edtDireccionPropertiesButtonClick(
Sender: TObject; AButtonIndex: Integer);
begin
inherited;
ElegirDireccionCliente;
end;
procedure TfrViewDatosYSeleccionClientePedido.edtPersonaContactoPropertiesButtonClick(
Sender: TObject; AButtonIndex: Integer);
begin
inherited;
ElegirPersonaContacto;
end;
procedure TfrViewDatosYSeleccionClientePedido.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 TfrViewDatosYSeleccionClientePedido.ElegirDireccionCliente;
var
ADireccion : IBizDireccionesContacto;
begin
inherited;
FDireccionesController.CopiarDireccionFiscal(FCliente, FDireccion);
if (FCliente.Direcciones.RecordCount > 1) then
ADireccion := FClientesController.ElegirDireccionEntrega(FCliente, 'Seleccione la direcci<63>n del cliente que quiere utilizar como direcci<63>n de envio de este pedido.')
else
ADireccion := FCliente.Direcciones;
if Assigned(ADireccion) then
begin
FDireccionEntrega := ADireccion;
FPedido.Edit;
if FDireccionEntrega.IDIsNull then
begin
FPedido.ClearField('ID_DIRECCION');
FPedido.ClearField('IMPORTE_PORTE');
FPedido.ClearField('CALLE');
FPedido.ClearField('POBLACION');
FPedido.ClearField('PROVINCIA');
FPedido.ClearField('CODIGO_POSTAL');
FPedido.ClearField('TELEFONO');
FPedido.ClearField('PERSONA_CONTACTO');
end
else begin
FPedido.ID_DIRECCION := FDireccionEntrega.ID;
FPedido.CALLE := FDireccionEntrega.CALLE;
FPedido.POBLACION := FDireccionEntrega.POBLACION;
FPedido.PROVINCIA := FDireccionEntrega.PROVINCIA;
FPedido.CODIGO_POSTAL := FDireccionEntrega.CODIGO_POSTAL;
FPedido.TELEFONO := FDireccionEntrega.TELEFONO;
FPedido.PERSONA_CONTACTO := FDireccionEntrega.PERSONA_CONTACTO;
FPedido.IMPORTE_PORTE := FDireccionEntrega.PORTE;
end;
EscribirTextoDireccion;
end;
end;
procedure TfrViewDatosYSeleccionClientePedido.ElegirPersonaContacto;
var
APersona : IBizContactoPersonal;
begin
inherited;
APersona := FClientesController.ElegirPersonaContacto(FCliente.Personal,
'El proveedor dispone de personas de contacto dadas de alta en su ficha. Seleccione la que quiere utilizar.');
if Assigned(APersona) then
begin
FPedido.Edit;
// FPedido.PERSONA_CONTACTO_PROV := APersona.NOMBRE;
end;
end;
procedure TfrViewDatosYSeleccionClientePedido.EscribirTextoDireccion;
var
ACadena : String;
begin
ACadena := '';
if Assigned(FDireccion) then
begin
ACadena := Format('%s %s %s %s',
[FDireccion.CALLE, FDireccion.POBLACION,
FDireccion.CODIGO_POSTAL, FDireccion.PROVINCIA]);
if (not FDireccion.TELEFONOIsNull) and (FDireccion.TELEFONO <> '') then
ACadena := ACadena + #13#10 + 'Tel<65>fono: ' + FDireccion.TELEFONO;
if (not FDireccion.FAXIsNull) and (FDireccion.FAX <> '') then
ACadena := ACadena + #13#10 + 'Fax: ' + FDireccion.FAX;
end;
edtDireccion.Text := ACadena;
end;
function TfrViewDatosYSeleccionClientePedido.GetCliente: IBizCliente;
begin
Result := FCliente;
end;
function TfrViewDatosYSeleccionClientePedido.GetID_Cliente: integer;
begin
Result := -1;
if Assigned(FCliente) then
Result := FCliente.ID;
end;
procedure TfrViewDatosYSeleccionClientePedido.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;
//Solo podremos establecer persona de contacto si se ha asignado un proveedor
if FCliente.ID > 0 then
edtPersonaContacto.Enabled := True;
ElegirDireccionCliente
end
else begin
dsCliente.DataTable := NIL;
FCliente := NIL;
FDireccion := NIL;
edtPersonaContacto.Enabled := False;
end;
if Assigned(FOnClienteChanged) then
FOnClienteChanged(Self);
end;
procedure TfrViewDatosYSeleccionClientePedido.SetID_Cliente(const Value: integer);
begin
Self.Cliente := IBizCliente(FClientesController.Buscar(Value));
end;
function TfrViewDatosYSeleccionClientePedido.GetOnClienteChanged: TNotifyEvent;
begin
Result := FOnClienteChanged;
end;
function TfrViewDatosYSeleccionClientePedido.GetPedido: IBizPedidoCliente;
begin
Result := FPedido;
end;
procedure TfrViewDatosYSeleccionClientePedido.RefrescarDireccion;
begin
FDireccion := FDireccionesController.Nuevo;
if (not FPedido.ID_DIRECCIONIsNull) and
(FDireccionesController.Localizar(FCliente.Direcciones, FPedido.ID_DIRECCION)) then
FDireccionesController.CopiarDireccion(FCliente.Direcciones, FDireccion)
else
FDireccionesController.CopiarDireccionFiscal(FCliente, FDireccion);
EscribirTextoDireccion;
end;
procedure TfrViewDatosYSeleccionClientePedido.SetOnClienteChanged(
const Value: TNotifyEvent);
begin
FOnClienteChanged := Value;
end;
procedure TfrViewDatosYSeleccionClientePedido.SetPedido(
const Value: IBizPedidoCliente);
begin
FPedido := Value;
if Assigned(FPedido) then
begin
dsPedido.DataTable := FPedido.DataTable;
FCliente := FPedido.Cliente;
dsCliente.DataTable := FCliente.DataTable;
if not FCliente.DataTable.Active then
FCliente.DataTable.Active := True;
//Solo podremos establecer persona de contacto si se ha asignado un proveedor
if FCliente.ID > 0 then
edtPersonaContacto.Enabled := True;
RefrescarDireccion;
end
else begin
dsPedido.DataTable := NIL;
FCliente := NIL;
FDireccion := NIL;
end;
end;
procedure TfrViewDatosYSeleccionClientePedido.SetReadOnly(Value: Boolean);
begin
inherited;
if (csLoading in Self.ComponentState) then
Exit;
actAnadirContacto.Enabled := not ReadOnly;
actElegirContacto.Enabled := not ReadOnly;
edtPersonaContacto.Enabled := not ReadOnly;
end;
procedure TfrViewDatosYSeleccionClientePedido.VerFichaCliente;
begin
if not Assigned(Cliente) then
ShowErrorMessage('No se ha indicado un proveedor', 'El pedido no tiene ning<6E>n proveedor asociado a mostrar.')
else begin
FClientesController.Ver(Cliente);
end;
end;
end.