{
===============================================================================
  Copyright (©) 2002. Rodax Software.
===============================================================================
  Los contenidos de este fichero son propiedad de Rodax Software titular del
  copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
  en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
  acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
  bajo el que se suministra.
  -----------------------------------------------------------------------------
  Web:  www.rodax-software.com
===============================================================================
  Fecha primera versión: 04-12-2002
  Versión actual: 1.0.0
  Fecha versión actual: 04-12-2002
===============================================================================
  Modificaciones:

    Fecha         Comentarios
    ---------------------------------------------------------------------------
===============================================================================
}

unit TablaFormasPago;

interface

uses
  //Generales
  SysUtils, Classes, Controls, IBSQL, cxGridDBTableView, cxCustomData, DB,
  //Particulares

  //Aplicacion
  Framework, StrFunc, Entidades, Constantes, BaseDatos;

type
  TdmTablaFormasPago = class(TDataModule)
  private
    procedure IniciarSQL;
  public
    sqlInsertar : TStrings;
    sqlModificar : TStrings;
    sqlConsultar : TStrings;
    sqlEliminar : TStrings;
    constructor Create (AOwner : TComponent); override;
    destructor Destroy; override;
    procedure InicializarGridFormasPago(var vGrid: TcxGridDBTableView);
    function darFormasPago : TStrings;
  end;

var
  dmTablaFormasPago: TdmTablaFormasPago;

implementation

{$R *.DFM}

{ TdmTablaFormasPago }

constructor TdmTablaFormasPago.Create(AOwner: TComponent);
begin
  inherited;
  sqlInsertar := TStringList.Create;
  sqlModificar := TStringList.Create;
  sqlConsultar := TStringList.Create;
  sqlEliminar := TStringList.Create;
  IniciarSQL;
end;

destructor TdmTablaFormasPago.Destroy;
begin
  sqlInsertar.Free;
  sqlModificar.Free;
  sqlConsultar.Free;
  sqlEliminar.Free;
  inherited;
end;

function TdmTablaFormasPago.darFormasPago: TStrings;
var
  oSQL : TIBSQL;
  Lista : TStringList;
begin
  oSQL := TIBSQL.Create(Self);
  Lista := TStringList.Create;

  with oSQL do
  begin
    Database := dmBaseDatos.BD;
    Transaction := dmBaseDatos.Transaccion;
    SQL.Add('select DESCRIPCION from FORMASPAGO');
    SQL.Add('order by DESCRIPCION');

  try
    Prepare;
    ExecQuery;
    Lista.Append('');
    while not EOF do begin
      Lista.Append(Fields[0].AsString);
      Next;
    end;
    result := Lista;
  finally
    Close;
    Transaction := NIL;
    Free;
  end;
  end;
end;

procedure TdmTablaFormasPago.InicializarGridFormasPago(var vGrid: TcxGridDBTableView);
var
  Columna : TcxGridDBColumn;
begin
  with vGrid do begin
    ClearItems;
    OptionsView.Footer := True;
    {Columna DESCRIPCION}
    Columna := CreateColumn;
    Columna.DataBinding.FieldName := 'DESCRIPCION';
    Columna.Caption := 'Formas de pago';
    Columna.Options.Filtering := False;
    Columna.SortOrder := soAscending;
    with TcxGridDBTableSummaryItem(DataController.Summary.FooterSummaryItems.Add) do
    try
      try
        BeginUpdate;
        Column := Columna;
        FieldName := Columna.DataBinding.FieldName;
        Format := 'Total: 0 formas de pago';
        Kind := skCount;
      finally
        EndUpdate;
      end;
    except
      DataController.Summary.FooterSummaryItems.Delete(DataController.Summary.FooterSummaryItems.Count-1);
    end;
  end;
end;

procedure TdmTablaFormasPago.IniciarSQL;
begin
  with sqlInsertar do
  begin
    Add('insert into FORMASPAGO (DESCRIPCION) ');
    Add('values (UPPER(:DESCRIPCION))');
  end;

  with sqlModificar do
  begin
    Add('update FORMASPAGO set ');
    Add('DESCRIPCION = UPPER(:DESCRIPCION) ');
    Add('where RDB$DB_KEY = :DB_KEY');
  end;

  with sqlEliminar do
  begin
    Add('delete from FORMASPAGO ');
    Add('where DESCRIPCION = :DESCRIPCION');
  end;

  with sqlConsultar do
  begin
    Add('select RDB$DB_KEY, DESCRIPCION ');
    Add('from FORMASPAGO ');
    Add('order by DESCRIPCION');
  end;
end;

end.
