Tecsitel_FactuGES2/Source/Modulos/Albaranes de cliente/Views/uViewAlbaranCliente.pas

497 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,
uViewDatosYSeleccionClienteBase, uViewDatosYSeleccionClienteAlbaran;
type
IViewAlbaranCliente = interface(IViewBase)
['{F4946DFE-B64C-47C8-96D6-24549E6DAC11}']
function GetAlbaran: IBizAlbaranCliente;
procedure SetAlbaran(const Value: IBizAlbaranCliente);
property Albaran: IBizAlbaranCliente read GetAlbaran write SetAlbaran;
function GetViewClienteAlbaran: IViewDatosYSeleccionClienteAlbaran;
property ViewClienteAlbaran: IViewDatosYSeleccionClienteAlbaran read GetViewClienteAlbaran;
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;
dxLayoutControl1Item8: TdxLayoutItem;
eCalle: TcxDBTextEdit;
dxLayoutControl1Item10: TdxLayoutItem;
eCodigoPostal: TcxDBTextEdit;
dxLayoutControl1Item12: TdxLayoutItem;
ePersonaContacto: TcxDBTextEdit;
dxLayoutControl1Item13: TdxLayoutItem;
eTlfTrabajo: TcxDBTextEdit;
dxLayoutControl1Group4: 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;
dxLayoutControl1Item9: TdxLayoutItem;
cbProvincia: TcxDBComboBox;
dxLayoutControl1Item11: TdxLayoutItem;
cbPoblacion: TcxDBComboBox;
dxLayoutControl1Group9: TdxLayoutGroup;
frViewDatosYSeleccionClienteAlbaran1: TfrViewDatosYSeleccionClienteAlbaran;
dxLayoutControl1Item1: 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 frViewClienteAlbaranactAnadirContactoUpdate(Sender: TObject);
procedure cbProvinciaPropertiesInitPopup(Sender: TObject);
procedure cbPoblacionPropertiesInitPopup(Sender: TObject);
protected
FAlbaran : IBizAlbaranCliente;
FAlmacenesController : IAlmacenesController;
// FPedidoAsociado : IBizPedidoCliente;
// FPedidoController : IPedidosClienteController;
FViewClienteAlbaran : IViewDatosYSeleccionClienteAlbaran;
FFormasPago : IBizFormaPago;
FFormasPagoController : IFormasPagoController;
FProvincias : TStringList;
FIDProvincia : Integer; //Almacenar<61> la provincia que hay seleccionada para no cargar las poblaciones si no es necesario
FPoblaciones : TStringList;
procedure CargarProvincias;
procedure CargarPoblaciones;
function GetAlbaran: IBizAlbaranCliente;
procedure SetAlbaran(const Value: IBizAlbaranCliente); virtual;
function GetViewClienteAlbaran: IViewDatosYSeleccionClienteAlbaran;
public
property Albaran: IBizAlbaranCliente read GetAlbaran write SetAlbaran;
property ViewClienteAlbaran: IViewDatosYSeleccionClienteAlbaran read GetViewClienteAlbaran;
end;
implementation
{$R *.dfm}
{ TfrViewAlbaranCliente }
uses
uClientesController, uBizDireccionesContacto, uAlbaranesClienteController,
schAlbaranesClienteClient_Intf, uBizAlmacenes, uDateUtils,
uDialogUtils, uProvinciasPoblacionesController, uStringsUtils;
procedure TfrViewAlbaranCliente.actElegirDireccionExecute(Sender: TObject);
var
AClientesController : IClientesController;
AAlbaranController : IAlbaranesClienteController;
ADireccion : IBizDireccionesContacto;
begin
inherited;
AClientesController := TClientesController.Create;
AAlbaranController := TAlbaranesClienteController.Create;
try
ADireccion := AClientesController.ElegirDireccionEntrega(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
ADireccion := NIL;
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.CargarPoblaciones;
var
i : integer;
begin
if (FIDProvincia <> StrToInt(FProvincias.Values[cbProvincia.Text])) then
Begin
FIDProvincia := StrToInt(FProvincias.Values[cbProvincia.Text]);
with TProvinciasPoblacionesController.Create do
try
FPoblaciones := DarListaPoblaciones(FIDProvincia);
with cbPoblacion.Properties.Items do
begin
BeginUpdate;
try
Clear;
for i := 0 to FPoblaciones.Count - 1 do
Add(FPoblaciones.Names[i]);
finally
EndUpdate;
end;
end;
finally
Free;
end;
End;
end;
procedure TfrViewAlbaranCliente.CargarProvincias;
var
i : integer;
begin
with TProvinciasPoblacionesController.Create do
try
FProvincias := DarListaProvincias;
with cbProvincia.Properties.Items do
begin
BeginUpdate;
try
Clear;
for i := 0 to FProvincias.Count - 1 do
Add(FProvincias.Names[i]);
finally
EndUpdate;
end;
end;
finally
Free;
end;
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.cbPoblacionPropertiesInitPopup(Sender: TObject);
begin
inherited;
ShowHourglassCursor;
try
FreeANDNIL(FPoblaciones);
if not Assigned(FProvincias) then
CargarProvincias;
if not EsCadenaVacia(cbProvincia.Text) and (FProvincias.IndexOfName(cbProvincia.Text) <> -1) then
CargarPoblaciones
finally
HideHourglassCursor;
end;
end;
procedure TfrViewAlbaranCliente.cbProvinciaPropertiesInitPopup(Sender: TObject);
begin
inherited;
ShowHourglassCursor;
try
if not Assigned(FProvincias) then
CargarProvincias;
finally
HideHourglassCursor;
end;
end;
procedure TfrViewAlbaranCliente.CustomViewCreate(Sender: TObject);
begin
inherited;
FIDProvincia := 0;
FProvincias := NIL;
FPoblaciones := NIL;
FFormasPago := Nil;
FFormasPagoController := TFormasPagoController.Create;
// FPedidoAsociado := NIL;
// FPedidoController := TPedidosClienteController.Create;
FViewClienteAlbaran := frViewDatosYSeleccionClienteAlbaran1;
FAlmacenesController := TAlmacenesController.Create;
end;
procedure TfrViewAlbaranCliente.CustomViewDestroy(Sender: TObject);
begin
inherited;
if Assigned(FProvincias) then
FreeANDNIL(FProvincias);
if Assigned(FPoblaciones) then
FreeANDNIL(FPoblaciones);
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;
function TfrViewAlbaranCliente.GetAlbaran: IBizAlbaranCliente;
begin
Result := FAlbaran;
end;
function TfrViewAlbaranCliente.GetViewClienteAlbaran: IViewDatosYSeleccionClienteAlbaran;
begin
Result := FViewClienteAlbaran;
end;
procedure TfrViewAlbaranCliente.SetAlbaran(const Value: IBizAlbaranCliente);
begin
FAlbaran := Value;
if Assigned(FAlbaran) then
begin
DADataSource.DataTable := FAlbaran.DataTable;
FViewClienteAlbaran.Albaran := FAlbaran;
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;
FViewClienteAlbaran.Albaran := NIL;
// FPedidoAsociado := NIL;
dsFormaPago.DataTable := NIL;
dsAlmacenes.DataTable := NIL;
end;
end;
end.