FactuGES2/Source/Modulos/Albaranes de cliente/Views/uViewAlbaranCliente.pas
david d7b65d47a3 - Actualización a DevExpress? x.38 sin el módulo de skins.
- Limpieza de código para NO usar skins de DevExpress?. 

git-svn-id: https://192.168.0.254/svn/Proyectos.Acana_FactuGES2/trunk@313 f4e31baf-9722-1c47-927c-6f952f962d4b
2008-10-03 18:43:45 +00:00

482 lines
16 KiB
ObjectPascal
Raw Blame History

unit uViewAlbaranCliente;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uViewBase, uBizAlbaranesCliente, DB, uDADataTable, uCustomView,
AppEvnts, StdCtrls, Mask, DBCtrls,
uViewObservaciones, uViewDatosYSeleccionCliente,
cxGraphics, cxDropDownEdit, cxImageComboBox, cxDBEdit, cxContainer, cxEdit,
cxTextEdit, cxMaskEdit, cxCalendar, dxLayoutControl, cxControls, cxMemo,
uViewDireccionEntregaAlbaranCliente, Buttons, ActnList,
// uBizPedidosCliente, uPedidosClienteController,
ExtCtrls, cxLookupEdit, cxDBLookupEdit, uBizFormasPago,
cxDBLookupComboBox, uFormasPagoController, uAlmacenesController, uDAInterfaces,
uViewTienda, uAlbaranesClienteController;
type
IViewAlbaranCliente = interface(IViewBase)
['{F4946DFE-B64C-47C8-96D6-24549E6DAC11}']
function GetController : IAlbaranesClienteController;
procedure SetController (const Value : IAlbaranesClienteController);
property Controller : IAlbaranesClienteController read GetController write SetController;
function GetAlbaran: IBizAlbaranCliente;
procedure SetAlbaran(const Value: IBizAlbaranCliente);
property Albaran: IBizAlbaranCliente read GetAlbaran write SetAlbaran;
function GetViewClienteAlbaran: TfrViewDatosYSeleccionCliente;
procedure SetViewClienteAlbaran(const Value: TfrViewDatosYSeleccionCliente);
property ViewClienteAlbaran: TfrViewDatosYSeleccionCliente read GetViewClienteAlbaran write SetViewClienteAlbaran;
end;
TfrViewAlbaranCliente = class(TfrViewBase, IViewAlbaranCliente)
DADataSource: TDADataSource;
dxLayoutControl1Group_Root: TdxLayoutGroup;
dxLayoutControl1: TdxLayoutControl;
dxLayoutControl1Item2: TdxLayoutItem;
edtFechaAlbaran: TcxDBDateEdit;
dxLayoutControl1Group1: TdxLayoutGroup;
dxLayoutControl1Group2: TdxLayoutGroup;
dxLayoutControl1Item6: TdxLayoutItem;
memObservaciones: TcxDBMemo;
dxLayoutControl1Item3: TdxLayoutItem;
eReferencia: TcxDBTextEdit;
dxLayoutControl1Group6: TdxLayoutGroup;
dxLayoutControl1Group7: TdxLayoutGroup;
dxLayoutControl1Group8: TdxLayoutGroup;
dxLayoutControl1Group3: TdxLayoutGroup;
dxLayoutControl1Item1: TdxLayoutItem;
frViewClienteAlbaran: TfrViewDatosYSeleccionCliente;
dxLayoutControl1Item8: TdxLayoutItem;
eCalle: TcxDBTextEdit;
dxLayoutControl1Item9: TdxLayoutItem;
ePoblacion: TcxDBTextEdit;
dxLayoutControl1Item10: TdxLayoutItem;
eCodigoPostal: TcxDBTextEdit;
dxLayoutControl1Item11: TdxLayoutItem;
eProvincia: TcxDBTextEdit;
dxLayoutControl1Item12: TdxLayoutItem;
ePersonaContacto: TcxDBTextEdit;
dxLayoutControl1Item13: TdxLayoutItem;
eTlfTrabajo: TcxDBTextEdit;
dxLayoutControl1Group4: TdxLayoutGroup;
dxLayoutControl1Group9: TdxLayoutGroup;
dxLayoutControl1Item14: TdxLayoutItem;
bElegirDireccion: TBitBtn;
ActionList1: TActionList;
actElegirDireccion: TAction;
Button1: TButton;
dxLayoutControl1Item5: TdxLayoutItem;
actVerPedidoCli: TAction;
eReferenciaPedidoCli: TcxTextEdit;
dxLayoutControl1Item7: TdxLayoutItem;
dxLayoutControl1Group5: TdxLayoutGroup;
dxLayoutControl1Item4: TdxLayoutItem;
cbFormaPago: TcxDBLookupComboBox;
dxLayoutControl1Item15: TdxLayoutItem;
bFormasPago: TButton;
dsFormaPago: TDADataSource;
dxLayoutControl1Group13: TdxLayoutGroup;
dxLayoutControl1Group14: TdxLayoutGroup;
dxLayoutControl1Item16: TdxLayoutItem;
eFechaRecepcion: TcxDBDateEdit;
dxLayoutControl1Group11: TdxLayoutGroup;
dxLayoutControl1Item19: TdxLayoutItem;
cbConAlmacen: TCheckBox;
dxLayoutControl1Item20: TdxLayoutItem;
cbAlmacen: TcxDBLookupComboBox;
dsAlmacenes: TDADataSource;
dxLayoutControl1Item18: TdxLayoutItem;
Label1: TLabel;
dxLayoutControl1Group12: TdxLayoutGroup;
dxLayoutControl1Group10: TdxLayoutGroup;
dxLayoutControl1Item22: TdxLayoutItem;
eRefFacturaCli: TcxDBTextEdit;
dxLayoutControl1Group15: TdxLayoutGroup;
dxLayoutControl1Item24: TdxLayoutItem;
eFechaPrevista: TcxDBDateEdit;
dxLayoutControl1Item23: TdxLayoutItem;
eRefCliente: TcxDBTextEdit;
dxLayoutControl1Item21: TdxLayoutItem;
eFechaEnvio: TcxDBDateEdit;
dxLayoutControl1Group16: TdxLayoutGroup;
dxLayoutControl1Group17: TdxLayoutGroup;
frViewTienda1: TfrViewTienda;
dxLayoutControl1Item17: TdxLayoutItem;
procedure CustomViewCreate(Sender: TObject);
procedure CustomViewDestroy(Sender: TObject);
procedure actElegirDireccionExecute(Sender: TObject);
procedure actVerPedidoCliExecute(Sender: TObject);
procedure bFormasPagoClick(Sender: TObject);
procedure cbConAlmacenClick(Sender: TObject);
procedure eFechaPrevistaPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
procedure eFechaEnvioPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
procedure eFechaRecepcionPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
procedure frViewClienteAlbaranactElegirContactoUpdate(Sender: TObject);
procedure actElegirDireccionUpdate(Sender: TObject);
procedure actVerPedidoCliUpdate(Sender: TObject);
procedure frViewClienteAlbaranButton1Click(Sender: TObject);
procedure frViewClienteAlbaranButton2Click(Sender: TObject);
procedure frViewClienteAlbaranactAnadirContactoUpdate(Sender: TObject);
protected
FAlbaran : IBizAlbaranCliente;
FController : IAlbaranesClienteController;
FAlmacenesController : IAlmacenesController;
// FPedidoAsociado : IBizPedidoCliente;
// FPedidoController : IPedidosClienteController;
FViewClienteAlbaran : TfrViewDatosYSeleccionCliente;
FFormasPago : IBizFormaPago;
FFormasPagoController : IFormasPagoController;
function GetAlbaran: IBizAlbaranCliente;
procedure SetAlbaran(const Value: IBizAlbaranCliente); virtual;
function GetController : IAlbaranesClienteController;
procedure SetController (const Value : IAlbaranesClienteController);
function GetViewClienteAlbaran: TfrViewDatosYSeleccionCliente;
procedure SetViewClienteAlbaran(const Value: TfrViewDatosYSeleccionCliente);
public
property Albaran: IBizAlbaranCliente read GetAlbaran write SetAlbaran;
property Controller : IAlbaranesClienteController read GetController write SetController;
property ViewClienteAlbaran: TfrViewDatosYSeleccionCliente read GetViewClienteAlbaran;
end;
implementation
{$R *.dfm}
{ TfrViewAlbaranCliente }
uses
uClientesController, uBizDireccionesContacto,
schAlbaranesClienteClient_Intf, uBizAlmacenes, uDateUtils,
uDialogUtils, uFactuGES_App;
procedure TfrViewAlbaranCliente.actElegirDireccionExecute(Sender: TObject);
var
AClientesController : IClientesController;
AAlbaranController : IAlbaranesClienteController;
ADireccion : IBizDireccionesContacto;
begin
inherited;
{
try
case FFactura.Cliente.Direcciones.RecordCount of
0 : //No hay direcciones secundarias asociadas
else ADireccion := AClientesController.ElegirDireccion(FFactura.Cliente, 'Seleccione la direcci<63>n del proveedor que quiere utilizar como direcci<63>n fiscal de esta factura.');
end;
// Si hay direcci<63>n de envio, copiarla al albar<61>n y poner el coste del porte
if Assigned(ADireccion) then
begin
try
FFactura.Edit;
FFactura.IMPORTE_PORTE := ADireccion.PORTE;
FController.CopiarDireccion(ADireccion, FFactura);
finally
ADireccion := NIL;
end;
end
finally
AClientesController := Nil;
end;
}
{
AClientesController := TClientesController.Create;
AAlbaranController := TAlbaranesClienteController.Create;
try
ADireccion := AClientesController.ElegirDireccion(FAlbaran.Cliente, 'Seleccione la direcci<63>n del cliente que quiere utilizar como direcci<63>n de envio de este albaran.');
if Assigned(ADireccion) then
begin
AAlbaranController.CopiarDireccionEnvio(ADireccion, FAlbaran);
FAlbaran.Edit;
FAlbaran.IMPORTE_PORTE := ADireccion.PORTE;
end;
finally
AClientesController := NIL;
AAlbaranController := NIL;
end;
}
end;
procedure TfrViewAlbaranCliente.actElegirDireccionUpdate(Sender: TObject);
begin
inherited;
if (Sender as TAction).Enabled then
(Sender as TAction).Enabled := (not ReadOnly) and
Assigned(FAlbaran) and
Assigned(FViewClienteAlbaran) and
FAlbaran.DataTable.Active and
Assigned(FAlbaran.Cliente) and
Assigned(FAlbaran.Cliente) and
Assigned(FAlbaran.Cliente.Direcciones) and
FAlbaran.Cliente.Direcciones.DataTable.Active and
(FAlbaran.Cliente.Direcciones.DataTable.RecordCount > 0);
end;
procedure TfrViewAlbaranCliente.actVerPedidoCliExecute(Sender: TObject);
begin
inherited;
// FPedidoController.Ver(FPedidoAsociado);
end;
procedure TfrViewAlbaranCliente.actVerPedidoCliUpdate(Sender: TObject);
begin
inherited;
if (Sender as TAction).Enabled then
(Sender as TAction).Enabled := (Albaran.REF_PEDIDO <> '')
end;
procedure TfrViewAlbaranCliente.bFormasPagoClick(Sender: TObject);
begin
inherited;
if Assigned(FFormasPago) then
FFormasPagoController.VerTodos(FFormasPago);
end;
procedure TfrViewAlbaranCliente.cbConAlmacenClick(Sender: TObject);
begin
inherited;
//Para que no me cambie el estilo del campo
if ReadOnly then Exit;
if cbConAlmacen.Checked then
begin
cbAlmacen.Enabled := True;
cbAlmacen.DroppedDown := True;
end
else begin
cbAlmacen.Enabled := False;
FAlbaran.Edit;
FAlbaran.ID_ALMACEN := 0;
end;
end;
procedure TfrViewAlbaranCliente.CustomViewCreate(Sender: TObject);
var
i : integer;
begin
inherited;
FFormasPago := Nil;
FFormasPagoController := TFormasPagoController.Create;
// FPedidoAsociado := NIL;
// FPedidoController := TPedidosClienteController.Create;
FViewClienteAlbaran := frViewClienteAlbaran;
FViewClienteAlbaran.MsgElegirCliente := 'Elija el cliente al que se le realizar<61> el Albaran.';
FAlmacenesController := TAlmacenesController.Create;
end;
procedure TfrViewAlbaranCliente.CustomViewDestroy(Sender: TObject);
begin
inherited;
FFormasPago := Nil;
FFormasPagoController := NIL;
FViewClienteAlbaran := Nil;
// FPedidoController := NIL;
// FPedidoAsociado := NIL;
FAlmacenesController := NIL;
end;
procedure TfrViewAlbaranCliente.eFechaEnvioPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
inherited;
if VarIsNull(DisplayValue) or (DisplayValue = '') then
begin
if (ShowConfirmMessage('Si elimina la fecha prevista de envio, se eliminar<61>n tambien las fechas de envio y recepci<63>n en caso de tenerlas. <20>Desea continuar?', '') = IDYES) then
begin
eFechaRecepcion.Clear;
eFechaRecepcion.Enabled := false;
end
else
DisplayValue := DateToStr(eFechaEnvio.Date);
end
else
eFechaRecepcion.Enabled := true;
end;
procedure TfrViewAlbaranCliente.eFechaPrevistaPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
var Error: Boolean);
begin
inherited;
if VarIsNull(DisplayValue) or (DisplayValue = '') then
begin
if (ShowConfirmMessage('Si elimina la fecha prevista de envio, se eliminar<61>n tambien las fechas de envio y recepci<63>n en caso de tenerlas. <20>Desea continuar?', '') = IDYES) then
begin
eFechaEnvio.Clear;
eFechaEnvio.Enabled := false;
eFechaRecepcion.Clear;
eFechaRecepcion.Enabled := false;
end
else
DisplayValue := DateToStr(eFechaPrevista.Date);
end
else
eFechaEnvio.Enabled := true;
end;
procedure TfrViewAlbaranCliente.eFechaRecepcionPropertiesValidate(
Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
var Error: Boolean);
begin
inherited;
if not (VarIsNull(DisplayValue) or (DisplayValue = '')) then
begin
if (eFechaRecepcion.Date < eFechaEnvio.Date) then
begin
ShowWarningMessage('La fecha de recepci<63>n debe ser posterior a la fecha de envio');
eFechaRecepcion.SetFocus;
end;
end;
end;
procedure TfrViewAlbaranCliente.frViewClienteAlbaranactAnadirContactoUpdate(Sender: TObject);
begin
{
if (Sender as TAction).Enabled then
(Sender as TAction).Enabled := not Assigned(FPedidoAsociado);
}
end;
procedure TfrViewAlbaranCliente.frViewClienteAlbaranactElegirContactoUpdate(Sender: TObject);
begin
{
if (Sender as TAction).Enabled then
(Sender as TAction).Enabled := not Assigned(FPedidoAsociado);
}
end;
procedure TfrViewAlbaranCliente.frViewClienteAlbaranButton1Click(Sender: TObject);
begin
if Assigned(Albaran) and Assigned(Albaran.Cliente) and
Assigned (Albaran.Detalles) and (Albaran.Detalles.RecordCount > 0) then
begin
if (Application.MessageBox('Los descuentos de los art<72>culos del albar<61>n ser<65>n actualizados con los del nuevo cliente seleccionado, <20>Desea continuar?', 'Atenci<63>n', MB_YESNO) = IDNO) then
Exit;
end;
frViewClienteAlbaran.actElegirContacto.Execute;
end;
procedure TfrViewAlbaranCliente.frViewClienteAlbaranButton2Click(Sender: TObject);
begin
if Assigned(Albaran) and Assigned(Albaran.Cliente) and
Assigned (Albaran.Detalles) and (Albaran.Detalles.RecordCount > 0) then
begin
if (Application.MessageBox('Los descuentos de los art<72>culos del albar<61>n ser<65>n actualizados con los del nuevo cliente seleccionado, <20>Desea continuar?', 'Atenci<63>n', MB_YESNO) = IDNO) then
Exit;
end;
frViewClienteAlbaran.actAnadirContacto.Execute;
end;
function TfrViewAlbaranCliente.GetAlbaran: IBizAlbaranCliente;
begin
Result := FAlbaran;
end;
function TfrViewAlbaranCliente.GetController: IAlbaranesClienteController;
begin
Result := FController;
end;
function TfrViewAlbaranCliente.GetViewClienteAlbaran: TfrViewDatosYSeleccionCliente;
begin
Result := FViewClienteAlbaran;
end;
procedure TfrViewAlbaranCliente.SetAlbaran(const Value: IBizAlbaranCliente);
begin
FAlbaran := Value;
if Assigned(FAlbaran) then
begin
DADataSource.DataTable := FAlbaran.DataTable;
frViewTienda1.DataItem := FAlbaran.DataTable;
frViewClienteAlbaran.Cliente := FAlbaran.Cliente;
FFormasPago := FFormasPagoController.BuscarTodos;
dsFormaPago.DataTable := FFormasPago.DataTable;
dsFormaPago.DataTable.Active := True;
dsAlmacenes.DataTable := (FAlmacenesController.BuscarTodos).DataTable;
dsAlmacenes.DataTable.Active := True;
//Para que no me cambie el estilo del campo
if not ReadOnly then
begin
cbConAlmacen.Checked := (FAlbaran.ID_ALMACEN > 0);
cbAlmacen.Enabled := cbConAlmacen.Checked;
eReferenciaPedidoCli.Enabled := False;
eRefFacturaCli.Enabled := False;
if EsFechaVacia(FAlbaran.FECHA_PREVISTA_ENVIO) then
begin
eFechaEnvio.Enabled := false;
eFechaRecepcion.Enabled := false;
end
else
begin
eFechaEnvio.Enabled := true;
if EsFechaVacia(FAlbaran.FECHA_ENVIO) then
eFechaRecepcion.Enabled := false
else
eFechaRecepcion.Enabled := true;
end;
end;
{
FPedidoAsociado := NIL;
if (FAlbaran.ID_PEDIDO > 0) then
begin
FPedidoAsociado := FPedidoController.Buscar(FAlbaran.ID_PEDIDO);
if Assigned(FPedidoAsociado) then
begin
FPedidoAsociado.DataTable.Active := True;
eReferenciaPedidoCli.Text := FPedidoAsociado.REFERENCIA
end
else
eReferenciaPedidoCli.Text := '';
end
else
eReferenciaPedidoCli.Text := 'No hay pedido asociado';
}
end
else begin
DADataSource.DataTable := NIL;
frViewClienteAlbaran.Cliente := nil;
// FPedidoAsociado := NIL;
dsFormaPago.DataTable := NIL;
dsAlmacenes.DataTable := NIL;
end;
end;
procedure TfrViewAlbaranCliente.SetController(const Value: IAlbaranesClienteController);
begin
FController := Value;
if Assigned(FController)
and Assigned(ViewClienteAlbaran) then
ViewClienteAlbaran.Controller := FController.ClienteController;
end;
procedure TfrViewAlbaranCliente.SetViewClienteAlbaran(const Value: TfrViewDatosYSeleccionCliente);
begin
FViewClienteAlbaran := Value;
end;
end.