unit uEditorAsiento; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uEditorDBItem, ToolWin, ComCtrls, JvExControls, JvComponent, uBizAsientos, JvNavigationPane, ActnList, uEditorBase, StdActns, TB2Dock, TB2Toolbar, TBX, ImgList, PngImageList, TB2Item, uEditorItem, DB, uDADataTable, uEditorDBBase, JvFormAutoSize, uDAScriptingProvider, uDACDSDataTable, StdCtrls, pngimage, ExtCtrls, TBXDkPanels, JvButton, AppEvnts, uCustomView, uViewBase, JvAppStorage, JvAppRegistryStorage, JvFormPlacement, JvComponentBase, uIEditorAsiento, uAsientosController, JvExComCtrls, JvStatusBar, dxLayoutLookAndFeels, uDAInterfaces, uViewDetallesGenerico, uViewApuntes, cxDropDownEdit, cxCalendar, cxDBEdit, dxLayoutControl, cxContainer, cxEdit, cxTextEdit, cxMaskEdit, cxSpinEdit, cxControls, DBCtrls, dxGDIPlusClasses, cxGraphics, cxCurrencyEdit; type TfEditorAsiento = class(TfEditorDBItem, IEditorAsiento) dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList; dxLayoutOfficeLookAndFeel1: TdxLayoutOfficeLookAndFeel; dxLayoutControl1Group_Root: TdxLayoutGroup; dxLayoutControl1: TdxLayoutControl; lcOrden: TdxLayoutItem; edtOrden: TcxDBSpinEdit; dxLayoutControl1Item2: TdxLayoutItem; edtFecha: TcxDBDateEdit; dxLayoutControl1Group2: TdxLayoutGroup; dxLayoutControl1Group3: TdxLayoutGroup; dxLayoutControl1Item1: TdxLayoutItem; frViewApuntes1: TfrViewApuntes; EntradaSalida: TTabSheet; dxLayoutControl2: TdxLayoutControl; dxLayoutGroup1: TdxLayoutGroup; dxLayoutControl2Item1: TdxLayoutItem; edtFecha2: TcxDBDateEdit; Tipo: TcxComboBox; dxLayoutControl2Item2: TdxLayoutItem; eDescripcion: TcxTextEdit; dxLayoutControl2Item3: TdxLayoutItem; dxLayoutControl2Group1: TdxLayoutGroup; dxLayoutControl2Item4: TdxLayoutItem; eImporte: TcxCurrencyEdit; procedure FormShow(Sender: TObject); procedure dsDataTableDataChange(Sender: TObject; Field: TField); procedure CustomEditorClose(Sender: TObject; var Action: TCloseAction); protected FController : IAsientosController; FAsiento: IBizAsiento; // FViewAsiento : IViewAsiento; function GetController : IAsientosController; procedure SetController (const Value : IAsientosController); virtual; function GetAsiento: IBizAsiento; virtual; procedure SetAsiento(const Value: IBizAsiento); virtual; // function GetViewAsiento: IViewAsiento; // procedure SetViewAsiento(const Value: IViewAsiento); // property ViewAsiento: IViewAsiento read GetViewAsiento write SetViewAsiento; procedure GuardarInterno; override; procedure EliminarInterno; override; procedure PonerTitulos(const ATitulo: string = ''); override; //Si queremos crear otra vista para el editor heredado solo tendriamos que //sobreescribir este metodo // procedure AsignarVista; virtual; public property Asiento: IBizAsiento read GetAsiento write SetAsiento; constructor Create(AOwner: TComponent); override; destructor Destroy; override; end; implementation {$R *.dfm} uses uCustomEditor, uDataModuleBase, uFactuGES_App, schContabilidadClient_Intf; function ShowEditorAsiento (ABizObject : TDADataTableRules): TModalResult; var AEditor: TfEditorAsiento; begin AEditor := TfEditorAsiento.Create(Application); try AEditor.Asiento := (ABizObject as IBizAsiento); Result := AEditor.ShowModal; finally AEditor.Release; end; end; { ******************************* TfEditorAsiento ******************************* } function TfEditorAsiento.GetAsiento: IBizAsiento; begin Result := FAsiento; end; function TfEditorAsiento.GetController: IAsientosController; begin Result := FController; end; { function TfEditorAsiento.GetViewAsiento: IViewAsiento; begin Result := FViewAsiento; end; } procedure TfEditorAsiento.GuardarInterno; begin inherited; if Tipo.Text = 'Entrada' then FController.AnadirApuntesEntrada(FAsiento, eDescripcion.Text, eImporte.Value) else FController.AnadirApuntesSalida(FAsiento, eDescripcion.Text, eImporte.Value); FController.Guardar(FAsiento); Modified := False; end; procedure TfEditorAsiento.PonerTitulos(const ATitulo: string); var FTitulo : String; begin if Assigned(Asiento) then begin if Asiento.EsNuevo then FTitulo := 'Nueva entrada/salida - ' + AppFactuGES.EmpresaActiva.NOMBRE // + ' - ' + AppFactuGES.EjercicioActivo.NOMBRE + ' (' + AppFactuGES.EjercicioActivo.ESTADO + ')' else FTitulo := 'Entrada/salida' + ' ' + IntToStr(Asiento.ORDEN) + ' - ' + AppFactuGES.EmpresaActiva.NOMBRE; // + ' - ' + AppFactuGES.EjercicioActivo.NOMBRE + ' (' + AppFactuGES.EjercicioActivo.ESTADO + ')'; end; inherited PonerTitulos(FTitulo); end; procedure TfEditorAsiento.SetAsiento(const Value: IBizAsiento); begin FAsiento := Value; if Assigned(FAsiento) then begin dsDataTable.DataTable := FAsiento.DataTable; frViewApuntes1.Apuntes := FAsiento.Apuntes end else begin dsDataTable.DataTable := Nil; frViewApuntes1.Apuntes := Nil; end; // if Assigned(FViewAsiento) and Assigned(Asiento) then // FViewAsiento.Asiento := Asiento; end; procedure TfEditorAsiento.SetController(const Value: IAsientosController); begin FController := Value; // if Assigned(ViewAsiento) then // ViewAsiento.Controller := FController; end; { procedure TfEditorAsiento.SetViewAsiento(const Value: IViewAsiento); begin FViewAsiento := Value; if Assigned(FViewAsiento) and Assigned(Asiento) then FViewAsiento.Asiento := Asiento; end; } procedure TfEditorAsiento.FormShow(Sender: TObject); begin inherited; // if not Assigned(FViewAsiento) then // raise Exception.Create('No hay ninguna vista asignada'); if not Assigned(Asiento) then raise Exception.Create('No hay ningún asiento asignado'); Asiento.DataTable.Active := True; if not Asiento.EsNuevo then begin Asiento.Apuntes.First; eDescripcion.Text := Asiento.Apuntes.CONCEPTO; if Asiento.Apuntes.DataTable.FieldByName(fld_ApuntesDEBE).IsNull then begin Tipo.ItemIndex := 1; eImporte.Value := Asiento.Apuntes.HABER; end else begin Tipo.ItemIndex := 0; eImporte.Value := Asiento.Apuntes.DEBE; end; end; //Al insertar el orden se asigna automaticamente en el servidor, luego se podrá modificar { if Asiento.EsNuevo then lcOrden.Visible := False else lcOrden.Visible := True; } //En el caso de tener apuntes el asiento nos posicionaremos siempre el la columna concepto del ultimo apunte // frViewApuntes1.GotoLast; end; destructor TfEditorAsiento.Destroy; begin // Utilizar mejor OnClose; inherited; end; { procedure TfEditorAsiento.AsignarVista; var AViewAsiento: TfrViewAsiento; begin AViewAsiento := TfrViewAsiento.create(Self); with AViewAsiento do begin Parent := pagGeneral; Align := alClient; // dxLayoutControlAsiento.LookAndFeel := dxLayoutOfficeLookAndFeel1; end; ViewAsiento := AViewAsiento; end; } constructor TfEditorAsiento.Create(AOwner: TComponent); begin inherited; pgPaginas.ActivePageIndex := 1; // AsignarVista; end; procedure TfEditorAsiento.CustomEditorClose(Sender: TObject; var Action: TCloseAction); begin inherited; dsDataTable.DataTable := NIL; // FViewAsiento := NIL; FAsiento := NIL; end; procedure TfEditorAsiento.dsDataTableDataChange(Sender: TObject; Field: TField); begin inherited; { if Assigned(FAsiento) and (not (FAsiento.DataTable.Fetching) or not (FAsiento.DataTable.Opening) or not (FAsiento.DataTable.Closing)) then PonerTitulos; } end; procedure TfEditorAsiento.EliminarInterno; begin if (Application.MessageBox('¿Está seguro que desea borrar este asiento?', 'Atención', MB_YESNO) = IDYES) then begin inherited; if not FController.Eliminar(FAsiento) then actRefrescar.Execute; end; end; end.