unit uViewFacturaCliente; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uViewBase, DB, uDADataTable, uCustomView, uBizFacturasCliente, cxControls, cxContainer, cxEdit, cxTextEdit, cxDBEdit, dxLayoutControl, cxMemo, cxMaskEdit, cxDropDownEdit, cxCalendar, cxSpinEdit, StdCtrls, Mask, DBCtrls, cxGraphics, dxLayoutLookAndFeels, cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, uFormasPagoController, uDAInterfaces, uBizFormasPago, ActnList, uViewDatosYSeleccionClienteFacturaCliente, uFacturasClienteController, cxCheckBox; type IViewFacturaCliente = interface(IViewBase) ['{3A95930C-20B3-41E9-93CB-21138ADB5B70}'] function GetFactura: IBizFacturaCliente; procedure SetFactura(const Value: IBizFacturaCliente); property Factura: IBizFacturaCliente read GetFactura write SetFactura; function GetController : IFacturasClienteController; procedure SetController (const Value : IFacturasClienteController); property Controller : IFacturasClienteController read GetController write SetController; function GetViewClienteFactura: IViewDatosYSeleccionClienteFacturaCliente; property ViewClienteFactura: IViewDatosYSeleccionClienteFacturaCliente read GetViewClienteFactura; end; TfrViewFacturaCliente = class(TfrViewBase, IViewFacturaCliente) DADataSource: TDADataSource; dxLayoutControl1Group_Root: TdxLayoutGroup; dxLayoutControl1: TdxLayoutControl; dxLayoutControl1Item1: TdxLayoutItem; eReferencia: TcxDBTextEdit; dxLayoutControl1Item2: TdxLayoutItem; edtFecha: TcxDBDateEdit; dxLayoutControl1Group1: TdxLayoutGroup; dxLayoutControl1Group2: TdxLayoutGroup; dxLayoutControl1Item5: TdxLayoutItem; memObservaciones: TcxDBMemo; dxLayoutControl1Group5: TdxLayoutGroup; dxLayoutControl1Item6: TdxLayoutItem; dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList; dxLayoutOfficeLookAndFeel1: TdxLayoutOfficeLookAndFeel; dsFormaPago: TDADataSource; dxLayoutControl1Item4: TdxLayoutItem; cbFormaPago: TcxDBLookupComboBox; dxLayoutControl1Item10: TdxLayoutItem; bFormasPago: TButton; dxLayoutControl1Item3: TdxLayoutItem; cbCuentaBancaria: TcxDBComboBox; dxLayoutControl1Item7: TdxLayoutItem; Label1: TLabel; dxLayoutControl1Item8: TdxLayoutItem; cbClienteFinal: TcxDBTextEdit; dxLayoutControl1Item9: TdxLayoutItem; bElegirClienteFinal: TButton; dxLayoutControl1Group7: TdxLayoutGroup; dxLayoutControl1Group8: TdxLayoutGroup; ActionList1: TActionList; actElegirClienteFinal: TAction; frViewDatosYSeleccionClienteFacturaCliente1: TfrViewDatosYSeleccionClienteFacturaCliente; dxLayoutControl1Group9: TdxLayoutGroup; dxLayoutControl1Group6: TdxLayoutGroup; dxLayoutControl1Group4: TdxLayoutGroup; ledtFechaVencimiento: TdxLayoutItem; edtFechaVemcimiento: TcxDBDateEdit; dxLayoutControl1Group3: TdxLayoutGroup; dxLayoutControl1Item11: TdxLayoutItem; eCertificadoISO: TcxDBCheckBox; procedure bFormasPagoClick(Sender: TObject); procedure CustomViewDestroy(Sender: TObject); procedure CustomViewCreate(Sender: TObject); procedure actElegirClienteFinalExecute(Sender: TObject); procedure actElegirClienteFinalUpdate(Sender: TObject); procedure edtFechaVemcimientoPropertiesEditValueChanged(Sender: TObject); protected FFactura : IBizFacturaCliente; FController : IFacturasClienteController; FFormasPago : IBizFormaPago; FFormasPagoController : IFormasPagoController; FViewClienteFactura : IViewDatosYSeleccionClienteFacturaCliente; function GetFactura: IBizFacturaCliente; procedure SetFactura(const Value: IBizFacturaCliente); function GetController : IFacturasClienteController; procedure SetController (const Value : IFacturasClienteController); procedure RellenarCuentasBancarias; function GetViewClienteFactura: IViewDatosYSeleccionClienteFacturaCliente; public property Factura: IBizFacturaCliente read GetFactura write SetFactura; property Controller : IFacturasClienteController read GetController write SetController; property ViewClienteFactura: IViewDatosYSeleccionClienteFacturaCliente read GetViewClienteFactura; end; implementation uses uDataModuleContactos, schFacturasClienteClient_Intf, uFactuGES_App, uEmpresasController, uClientesController, uBizContactos, uBizDireccionesContacto; {$R *.dfm} { TfrViewFacturaCliente } procedure TfrViewFacturaCliente.actElegirClienteFinalExecute(Sender: TObject); var ACliente : IBizCliente; AClienteController : IClientesController; begin inherited; AClienteController := TClientesController.Create; try ACliente := (AClienteController.ElegirContacto(AClienteController.BuscarTodos, 'Elija el cliente final de esta factura', False) as IBizCliente); if Assigned(ACliente) then begin ShowHourglassCursor; try FFactura.Edit; FFactura.CLIENTE_FINAL := ACliente.NOMBRE; finally HideHourglassCursor; end; end; finally ACliente := NIL; AClienteController := NIL; end; end; procedure TfrViewFacturaCliente.actElegirClienteFinalUpdate(Sender: TObject); begin inherited; (Sender as TAction).Enabled := (not ReadOnly); end; procedure TfrViewFacturaCliente.bFormasPagoClick(Sender: TObject); begin inherited; if Assigned(FFormasPago) then FFormasPagoController.VerTodos(FFormasPago); end; procedure TfrViewFacturaCliente.CustomViewCreate(Sender: TObject); begin inherited; FFormasPago := Nil; FFormasPagoController := TFormasPagoController.Create; FViewClienteFactura := frViewDatosYSeleccionClienteFacturaCliente1; end; procedure TfrViewFacturaCliente.CustomViewDestroy(Sender: TObject); begin inherited; FFormasPago := Nil; FFormasPagoController := NIL; FViewClienteFactura := NIL; end; procedure TfrViewFacturaCliente.edtFechaVemcimientoPropertiesEditValueChanged( Sender: TObject); begin if Assigned(FFormasPago) then if (FFormasPago.Plazos.RecordCount = 0) then ledtFechaVencimiento.Enabled := True else ledtFechaVencimiento.Enabled := False; end; function TfrViewFacturaCliente.GetController: IFacturasClienteController; begin Result := FController; end; function TfrViewFacturaCliente.GetFactura: IBizFacturaCliente; begin Result := FFactura; end; function TfrViewFacturaCliente.GetViewClienteFactura: IViewDatosYSeleccionClienteFacturaCliente; begin Result := FViewClienteFactura; end; procedure TfrViewFacturaCliente.RellenarCuentasBancarias; var AController : IEmpresasController; ALista : TStringList; AListaIBAN : TStringList; AListaCliente: TStringList; i : integer; begin AController := TEmpresasController.Create; try ALista := AController.DarListaCuentasBancarias(AppFactuGES.EmpresaActiva); AListaIBAN := AController.DarListaCuentasBancariasIBAN(AppFactuGES.EmpresaActiva); AListaCliente := Controller.ClienteController.DarListaCuentasBancarias(FFactura.ID_CLIENTE); try with cbCuentaBancaria.Properties.Items do begin BeginUpdate; try Clear; Add(''); for i := 0 to ALista.Count - 1 do Add(ALista.Names[i]); if AListaIBAN.Count > 0 then begin Add('--------------'); for i := 0 to AListaIBAN.Count - 1 do Add(AListaIBAN.Names[i]); end; if AListaCliente.Count > 0 then begin Add('--------------'); for i := 0 to AListaCliente.Count - 1 do Add(AListaCliente.Names[i]); end; finally EndUpdate; end; end; finally FreeANDNIL(ALista); FreeANDNIL(AListaIBAN); end; finally AController := NIL; end; end; procedure TfrViewFacturaCliente.SetController(const Value: IFacturasClienteController); begin FController := Value; end; procedure TfrViewFacturaCliente.SetFactura(const Value: IBizFacturaCliente); var ACadena : String; begin FFactura := Value; RellenarCuentasBancarias; if Assigned(FFactura) then begin DADataSource.DataTable := FFactura.DataTable; FViewClienteFactura.Factura := FFactura; FFormasPago := FFormasPagoController.BuscarTodos; dsFormaPago.DataTable := FFormasPago.DataTable; dsFormaPago.DataTable.Active := True; //Posicionamos la tabla en la forma de pago que tiene la factura ya que no lo hace el componente por si solo FFormasPago.DataTable.Locate(fld_FacturasClienteID, FFactura.ID_FORMA_PAGO, []); if (FFormasPago.Plazos.RecordCount = 0) then ledtFechaVencimiento.Enabled := True else ledtFechaVencimiento.Enabled := False; if FFactura.TIPO = CTE_TIPO_ABONO then begin dxLayoutControl1Group1.Caption := 'Datos del abono:'; dxLayoutControl1Item2.Caption := 'Fecha del abono:'; ACadena := 'Elija el cliente al que se le realizará el abono.'; end else ACadena := 'Elija el cliente al que se le realizará la factura.'; //ViewDatosYSeleccionClienteFacturaCliente1.MsgElegirCliente := ACadena; end else begin DADataSource.DataTable := NIL; dsFormaPago.DataTable := NIL; FViewClienteFactura.Factura := NIL; end; end; end.