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, cxDBLookupComboBox, uFormasPagoController, uAlmacenesController; 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: 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; procedure CustomViewCreate(Sender: TObject); procedure CustomViewDestroy(Sender: TObject); procedure actElegirDireccionExecute(Sender: TObject); procedure actElegirDireccionUpdate(Sender: TObject); procedure actVerPedidoCliUpdate(Sender: TObject); procedure actVerPedidoCliExecute(Sender: TObject); procedure frViewClienteAlbaranactElegirContactoUpdate(Sender: TObject); procedure frViewClienteAlbaranactAnadirContactoUpdate(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); protected FAlbaran : IBizAlbaranCliente; FAlmacenesController : IAlmacenesController; FPedidoAsociado : IBizPedidoCliente; FPedidoController : IPedidosClienteController; FViewClienteAlbaran : TfrViewDatosYSeleccionCliente; FFormasPagoController : IFormasPagoController; function GetAlbaran: IBizAlbaranCliente; procedure SetAlbaran(const Value: IBizAlbaranCliente); virtual; function GetViewClienteAlbaran: TfrViewDatosYSeleccionCliente; procedure SetViewClienteAlbaran(const Value: TfrViewDatosYSeleccionCliente); public property Albaran: IBizAlbaranCliente read GetAlbaran write SetAlbaran; property ViewClienteAlbaran: TfrViewDatosYSeleccionCliente read GetViewClienteAlbaran; end; implementation {$R *.dfm} { TfrViewAlbaranCliente } uses uClientesController, uBizDireccionesContacto, uAlbaranesClienteController, schAlbaranesClienteClient_Intf, uBizFormasPago, uBizAlmacenes, uDateUtils, uDialogUtils; 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.Direcciones, 'Seleccione la dirección del cliente que quiere utilizar como direcció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; (Sender as TAction).Enabled := 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; (Sender as TAction).Enabled := Assigned(FPedidoAsociado) end; procedure TfrViewAlbaranCliente.bFormasPagoClick(Sender: TObject); begin inherited; FFormasPagoController.VerTodos((dsFormaPago.DataTable) as IBizFormaPago); end; procedure TfrViewAlbaranCliente.cbConAlmacenClick(Sender: TObject); begin inherited; 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); begin inherited; FFormasPagoController := TFormasPagoController.Create; FPedidoAsociado := NIL; FPedidoController := TPedidosClienteController.Create; FViewClienteAlbaran := frViewClienteAlbaran; FViewClienteAlbaran.MsgElegirCliente := 'Elija el cliente al que se le realizará el Albaran.'; FAlmacenesController := TAlmacenesController.Create; end; procedure TfrViewAlbaranCliente.CustomViewDestroy(Sender: TObject); begin inherited; FViewClienteAlbaran := Nil; FPedidoController := NIL; FFormasPagoController := 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án tambien las fechas de envio y recepción en caso de tenerlas. ¿Desea continuar?', '') = IDYES) then begin eFechaRecepcion.Clear; eFechaRecepcion.Enabled := false; end else DisplayValue := DateToStr(eFechaEnvio.Date); end else begin if (eFechaEnvio.Date >= eFechaPrevista.Date) then eFechaRecepcion.Enabled := true else begin ShowWarningMessage('La fecha de envio debe ser posterior a la fecha prevista de envio'); eFechaEnvio.SetFocus; end; end; 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án tambien las fechas de envio y recepción en caso de tenerlas. ¿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ón debe ser posterior a la fecha de envio'); eFechaRecepcion.SetFocus; end; end; end; procedure TfrViewAlbaranCliente.frViewClienteAlbaranactAnadirContactoUpdate( Sender: TObject); begin if Assigned(FPedidoAsociado) then (Sender as TAction).Enabled := False else inherited; end; procedure TfrViewAlbaranCliente.frViewClienteAlbaranactElegirContactoUpdate( Sender: TObject); begin if Assigned(FPedidoAsociado) then (Sender as TAction).Enabled := False else inherited; end; function TfrViewAlbaranCliente.GetAlbaran: IBizAlbaranCliente; begin Result := FAlbaran; 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; frViewClienteAlbaran.Cliente := FAlbaran.Cliente; dsFormaPago.DataTable := FFormasPagoController.BuscarTodos.DataTable; dsFormaPago.DataTable.Active := True; dsAlmacenes.DataTable := (FAlmacenesController.BuscarTodos).DataTable; dsAlmacenes.DataTable.Active := True; 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; 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.SetViewClienteAlbaran(const Value: TfrViewDatosYSeleccionCliente); begin FViewClienteAlbaran := Value; end; end.