unit indices;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  StdCtrls, Forms, DBCtrls, DB, DBTables, Mask, ExtCtrls, Buttons,
  Checa, FileCtrl, Gauges,Dialogos,describe;

type
  TFormaReindexa = class(TForm)
    Panel1: TPanel;
    DataSource1: TDataSource;
    Panel2: TPanel;
    TablaAuxiliar: TTable;
    Shape1: TShape;
    Panel3: TPanel;
    Bevel20: TBevel;
    Bevel21: TBevel;
    Bevel22: TBevel;
    Label2: TLabel;
    Panel4: TPanel;
    ScrollBox: TScrollBox;
    Bevel1: TBevel;
    Avance: TGauge;
    BotonReindexa: TBitBtn;
    BitBtn3: TBitBtn;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    CheckBox7: TCheckBox;
    CheckBox8: TCheckBox;
    CheckBox9: TCheckBox;
    BotonCompacta: TBitBtn;
    BotonRecuperacion: TBitBtn;
    CheckBox10: TCheckBox;
    CheckBox11: TCheckBox;
    Bevel2: TBevel;
    CheckBox12: TCheckBox;
    CheckBox13: TCheckBox;
    CheckBox14: TCheckBox;
    CheckBox15: TCheckBox;
    CheckBox16: TCheckBox;
    GroupBox1: TGroupBox;
    FechaProceso: TEdit;
    Label1: TLabel;
    Bevel3: TBevel;
    TablaSubordinado: TTable;
    Label3: TLabel;
    CheckBox17: TCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure BotonReindexaClick(Sender: TObject);
    procedure Panel4Click(Sender: TObject);
    procedure BotonCompactaClick(Sender: TObject);
    procedure TablaAuxiliarUpdateError(DataSet: TDataSet;
      E: EDatabaseError; UpdateKind: TUpdateKind;
      var UpdateAction: TUpdateAction);
    procedure BotonReindexaMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonCompactaMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonRecuperacionMouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure BitBtn3Click(Sender: TObject);
    procedure Panel3MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TablaAuxiliarFilterRecord(DataSet: TDataSet;
      var Accept: Boolean);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  FormaReindexa: TFormaReindexa;
  fallo:boolean;

implementation

uses adminis;

{$R *.DFM}

{********procedimiento de  compactar***************}

procedure quitaindicesanteriores(archivo:string);
var
  FromF, ToF: file;
  NumRead, NumWritten:longint;
  Buf:array[1..32]of Byte;
  i,cuenta,campos:integer;
  cadena,cad:string;

begin

if FileExists(archivo) then
begin
AssignFile(FromF,archivo);
Reset(FromF,1);

     campos:=0;
     while not Eof(FromF) do
     begin
     BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
     if buf[1]=13 then break;

      if ((buf[29]=1)and(campos=0)) then
      begin
      buf[29]:=0;

      end;


      if ((buf[32]=1)and(campos>0)) then buf[32]:=0;
      begin
      Seek(FromF, FilePos(FromF)-NumRead);
      BlockWrite(FromF, Buf,NumRead,NumWritten);

      end;
campos:=campos+1;
end;
CloseFile(FromF);


end;

end;




procedure borradocumentos(base,indice:string);
var
clave:string;
arch:TextFile;
begin
With FormaReindexa do
begin

if TablaAuxiliar.State=dsBrowse then TablaAuxiliar.Close;
TablaAuxiliar.DatabaseName:=ruta(8);
TablaAuxiliar.TableName:=base;
TablaAuxiliar.IndexName:=indice;
TablaAuxiliar.Open;
TablaAuxiliar.First;

AssignFile(arch,leeruta+'\compacta.cta');
Reset(arch);

while not Eof(Arch) do
begin
Readln(arch,clave);
MuestraMensaje('borrando cuenta '+clave);
TablaAuxiliar.CancelRange;

TablaAuxiliar.SetRange([clave],[clave]);
while not TablaAuxiliar.Eof do
begin
TablaAuxiliar.Delete;
end;

end;

end;

CloseFile(arch);

end;


procedure compactabasico(archivo1,campocondicion1:String;condicion1:Currency;tipo:Char);
var
borro:boolean;
claveaux:string;
begin

{**********************}
With FormaReindexa do
begin
if TablaAuxiliar.State=dsBrowse then TablaAuxiliar.Close;
TablaAuxiliar.DatabaseName:=ruta(8);
TablaAuxiliar.TableName:=archivo1+'.dbf';

{if indice1<>'' then TablaAuxiliar.IndexName:=indice1;}
TablaAuxiliar.Open;
TablaAuxiliar.First;

{*****filtra en el caso de cxc y cxp*******}

{*******************************************}


while not TablaAuxiliar.Eof do
begin
{****caso 1 fechas******}

borro:=True;
if (campocondicion1<>'')and(tipo='n') then
begin

if TablaAuxiliar.FieldByName(campocondicion1).AsCurrency=condicion1 then
begin
TablaAuxiliar.Delete;
Borro:=False;
end
else
Borro:=True;

end;

{***termina compcatar***************************}
if borro then TablaAuxiliar.Next;
end;

{***********************}
end;
end;



{***********************************************}

procedure borrasubordinado(archivo,indice,clave:string);

begin
with FormaReindexa do
begin
mUESTRAMensaje('voy a borrar el documento '+clave);
if TablaSubordinado.State=dsBrowse then TablaSubordinado.Close;
TablaSubordinado.DatabaseName:=ruta(8);
TablaSubordinado.TableName:=archivo+'.dbf';
TablaSubordinado.IndexName:=indice;
TablaSubordinado.Open;
TablaSubordinado.First;

if TablaSubordinado.FindKey([clave]) then
begin
TablaSubordinado.SetRange([clave],[clave]);
while not TablaSubordinado.Eof do
begin
TablaSubordinado.Delete;
end;

end;

end;
end;


function fallaapertura(archivo,ruta2:string):Boolean;
begin
with FormaReindexa do
begin
try
  quitaindicesanteriores(ruta(8)+'\'+archivo+'.dbf');
  TablaAuxiliar.DataBaseName:=ruta2;
  TablaAuxiliar.TableName:=archivo+'.dbf';

  TablaAuxiliar.Exclusive:=True;
  TablaAuxiliar.Open;
  TablaAuxiliar.Close;
  fallaapertura:=True;

except
on E: Exception do
begin
MuestraMensaje('La Tabla '+Archivo+' Esta Siendo Utilizada Por Otro Usuario');
fallaapertura:=False;
end;

end;

end;

end;


{procedure quitaindicesanteriores(archivo:string);
var
  FromF, ToF: file;
  NumRead, NumWritten:longint;
  Buf:array[1..32]of Byte;
  i,cuenta,campos:integer;
  cadena,cad:string;

begin

if FileExists(archivo) then
begin
AssignFile(FromF,archivo);
Reset(FromF,1);

     campos:=0;
     while not Eof(FromF) do
     begin
     BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
     if buf[1]=13 then break;

      if ((buf[29]=1)and(campos=0)) then
      begin
      buf[29]:=0;

      end;


      if ((buf[32]=1)and(campos>0)) then buf[32]:=0;
      begin
      Seek(FromF, FilePos(FromF)-NumRead);
      BlockWrite(FromF, Buf,NumRead,NumWritten);

      end;
campos:=campos+1;
end;


CloseFile(FromF);

end;

end; }





procedure compacta(archivo1,archivo2,archivo3,indice1,indice2,indice3,clave,campofecha,fechadecorte,campocondicion1:String;condicion1:Currency;tipo:Char);
var
borro:boolean;
claveaux:string;
begin

{**********************}
With FormaReindexa do
begin
if TablaAuxiliar.State=dsBrowse then TablaAuxiliar.Close;
TablaAuxiliar.DatabaseName:=ruta(8);
TablaAuxiliar.TableName:=archivo1+'.dbf';
if indice1<>'' then TablaAuxiliar.IndexName:=indice1;
TablaAuxiliar.Open;
TablaAuxiliar.First;
{case tipo of

'c':begin
    TablaAuxiliar.Filtered:=True;
    TablaAuxiliar.Tag:=1;
    end;

'p':begin
    TablaAuxiliar.Filtered:=True;
    TablaAuxiliar.Tag:=2;
    end;

'n':begin
    TablaAuxiliar.Filtered:=False;
    TablaAuxiliar.Tag:=0;
    end;

end; }

{

while not TablaAuxiliar.Eof do
begin
borro:=False;

if (campofecha<>'')and(fechadecorte<>'')and(tipo<>'n') then
begin


if TablaAuxiliar.FieldByName(campofecha).AsDateTime<StrToDateTime(fechadecorte) then
begin
claveaux:=TablaAuxiliar.FieldByName(clave).AsString;
TablaAuxiliar.SetRange([claveaux],[claveaux]);
while not TablaAuxiliar.EOF do
begin
case tipo of
'c':begin
    if (TablaAuxiliar.FieldByName('TIMOV_CC').AsString='1')or(TablaAuxiliar.FieldByName('TIMOV_CC').AsString='2')and
       (TablaAuxiliar.FieldByName(campocondicion1).AsCurrency=condicion1) then
    begin
    break;
    borra:=True;
    end;
    end;

'p':begin

    end;

end;



end;


if TablaAuxiliar.FieldByName(campocondicion1).AsCurrency=condicion1 then
begin
claveaux:=TablaAuxiliar.FieldByName(clave).AsString;
MuestraMensaje('voy a borrar el documento '+claveaux);
if archivo2<>'' then borrasubordinado(archivo2,indice2,claveaux);
if archivo3<>'' then borrasubordinado(archivo3,indice3,claveaux);
}

{TablaAuxiliar.Filtered:=False;
TablaAuxiliar.SetRange([claveaux],[claveaux]);
TablaAuxiliar.First;
while not TablaAuxiliar.Eof do
begin
TablaAuxiliar.Delete;
end;
TablaAuxiliar.Filtered:=True;}

{end;

end
else
Borro:=True;

end;

if (campocondicion1<>'')and(tipo='n') then
begin
if TablaAuxiliar.FieldByName(campocondicion1).AsCurrency=condicion1 then
begin
TablaAuxiliar.Delete;
Borro:=False;
end
else
Borro:=True;
end;

end;
if borro then TablaAuxiliar.Next;
end;
}

end;
end;



procedure compactar;
var
porcentaje:word;
arch:TextFile;
clave:string;
begin
With FormaReindexa do
begin

if TablaAuxiliar.State=dsBrowse then
TablaAuxiliar.Close;

{***CLIENTES***}
if CheckBox1.Checked then
begin
compactabasico('CLIENTE','SALDO_C',0,'n');
Avance.Progress:=Avance.Progress+porcentaje;
end;
{****PROVEEDORES****}
if CheckBox2.Checked then
begin
compactabasico('PROVEEDO','SALDO_P',0,'n');
Avance.Progress:=Avance.Progress+porcentaje;
end;
{****VENDEDORES***}
if CheckBox3.Checked then
begin
compactabasico('VENDEDOR','',0,'n');
Avance.Progress:=Avance.Progress+porcentaje;
end;
{****COMPRAS****}
if CheckBox4.Checked then
begin
{compacta('COMPRASD','ICOMDET','','','CLDOC_OD','','');
compacta('COMPRASE','CLPRV_O','ICOMENC','','CLPRV_O','CLDOC_O','');}
Avance.Progress:=Avance.Progress+porcentaje;
end;
{***FACTURACION*****}
if CheckBox5.Checked then
begin
{compacta('FACTURAD','CLDOC_FD','','','CLDOC_FD','','');
compacta('FACTURAE','ICLIFAC','INUMENC','','CLCLI_F','CLDOC_F','');}
Avance.Progress:=Avance.Progress+porcentaje;
end;
{****INVENTAR******}
if CheckBox6.Checked then
begin
{compacta('INVENTAR','ICLPRO','','','CLPRO_I','','');}
Avance.Progress:=Avance.Progress+porcentaje;
end;
{***CXC*****}
if CheckBox7.Checked then
begin
{**************inicia compactado*******}

if TablaAuxiliar.State=dsBrowse then TablaAuxiliar.Close;
TablaAuxiliar.DatabaseName:=ruta(8);
TablaAuxiliar.TableName:='CuCobrar.dbf';
TablaAuxiliar.IndexName:='ICUECOB';
TablaAuxiliar.Open;
TablaAuxiliar.Tag:=1;
TablaAuxiliar.Filtered:=True;
TablaAuxiliar.First;
{***************************************}


AssignFile(arch,leeruta+'\compacta.cta');
Rewrite(arch);

if FechaProceso.Text<>'' then
begin
while not TablaAuxiliar.Eof do
begin

if (TablaAuxiliar.FieldByName('SALDO_CC').AsCurrency=0)and(TablaAuxiliar.FieldByName('FEAPL_CC').AsDateTime<StrToDateTime(FechaProceso.Text)) then
begin

writeln(arch,TablaAuxiliar.FieldByName('NUFAC_CC').AsString);
MuestraMensaje('cuenta '+TablaAuxiliar.FieldByName('NUFAC_CC').AsString);

end;

TablaAuxiliar.Next;

end;

end;

CloseFile(arch);

TablaAuxiliar.Filtered:=False;
MuestraMensaje('termino');
{**************************************}
borradocumentos('CuCobrar.dbf','ICUECOB');
borradocumentos('FacturaE.dbf','INUMENC');
borradocumentos('FacturaD.dbf','CLDOC_FD');
{compacta('CUCOBRAR','FACTURAE','FACTURAD','ICUECOB','INUMENC','CLDOC_FD','NUFAC_CC','FEAPL_CC',FechaProceso.Text,'saldo_cc',0,'c');}

Avance.Progress:=Avance.Progress+porcentaje;

end;

{****CXP****'}
if CheckBox8.Checked then
begin
{**************inicia compactado*******}

if TablaAuxiliar.State=dsBrowse then TablaAuxiliar.Close;
TablaAuxiliar.DatabaseName:=ruta(8);
TablaAuxiliar.TableName:='CuePagar.dbf';
TablaAuxiliar.IndexName:='NUCOM';
TablaAuxiliar.Open;
TablaAuxiliar.Tag:=2;
TablaAuxiliar.Filtered:=True;
TablaAuxiliar.First;
{***************************************}


AssignFile(arch,leeruta+'\compacta.cta');
Rewrite(arch);

if FechaProceso.Text<>'' then
begin
while not TablaAuxiliar.Eof do
begin

if (TablaAuxiliar.FieldByName('SALDO_CP').AsCurrency=0)and(TablaAuxiliar.FieldByName('FEAPL_CP').AsDateTime<StrToDateTime(FechaProceso.Text)) then
begin

writeln(arch,TablaAuxiliar.FieldByName('NUCOM_CP').AsString);
MuestraMensaje('cuenta '+TablaAuxiliar.FieldByName('NUCOM_CP').AsString);

end;

TablaAuxiliar.Next;

end;

end;

CloseFile(arch);

TablaAuxiliar.Filtered:=False;
MuestraMensaje('termino');
{**************************************}
borradocumentos('Cuepagar.dbf','NUCOM');
borradocumentos('ComprasE.dbf','ICOMENC');
borradocumentos('ComprasD.dbf','ICOMDET');

{compacta('CUEPAGAR','CLPRO_CP','NUCOM','','CLPRO_CP','NUCOM_CP','');}
Avance.Progress:=Avance.Progress+porcentaje;
end;

Avance.Progress:=100;
MuestraMensaje('Proceso Términado');
end;

end;


{*************procedimiento tipos****}


procedure quitaindices(archiv:string);
var
  FromF, ToF: file;
  NumRead, NumWritten:longint;
  Buf:array[1..32]of Byte;
  i,cuenta:integer;
  cadena,cad:string;

begin
AssignFile(FromF,archiv);
Reset(FromF,1);

BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
{ShowMessage(IntToStr(Buf[28]));}

     while not Eof(FromF) do
     begin
     BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
     if buf[1]=13 then break;

      if buf[32]=1 then buf[32]:=0;
      begin
      Seek(FromF, FilePos(FromF)-NumRead);
      BlockWrite(FromF, Buf,NumRead,NumWritten);
{      ShowMessage('Quitando el indice');}
      end;

     end;


 CloseFile(FromF);

end;




{/******************}



procedure reindexa(archivo,indice1,indice2,indice3,c1,c2,c3:string);
var
f:boolean;
begin
With FormaReindexa do
begin
{**********************}
{TablaAuxiliar.DatabaseName:=ruta(8);
Tablaauxiliar.TableName:=archivo+'.dbf';}

{************************}
{with Session do
if DatabaseCount > 0 then
begin

MuestraMensaje('numero de bases '+IntToStr(DataBaseCount));

end;}


{********************}


{Tablaauxiliar.Exclusive:=True;}
fallo:=False;
{if TablaAuxiliar.DBSession.}
{MuestraMensaje('A punto de abrir base');}
{Tablaauxiliar.Open;
TablaAuxiliar.Close;}

{if fallo then
MuestraMensaje('El Archivo '+archivo+' esta en uso no es posible crear el indice')
else
begin}



{***********************}
if fallaapertura(archivo,ruta(8)) then
begin

DeleteFile(PChar(ruta(8)+'\'+archivo+'.mdx'));

{CopyFile(PChar(leeruta+'\define\'+archivo+'.mdx'),PChar(ruta(8)+'\'+archivo+'.mdx'),f);}


{Table1.IndexDefs.Update;}
{Table1.IndexDefs.Add;}
{Table1.DeleteIndex(indice1);}
{Table1.IndexDefs.Create(Table1);
Table1.AddIndex('CLCLI_C','CLCLI_C', []);}

TablaAuxiliar.DatabaseName:=ruta(8);
Tablaauxiliar.TableName:=archivo+'.dbf';

TablaAuxiliar.IndexDefs.Update;

if indice1<>'' then
begin
TablaAuxiliar.IndexDefs.Create(TablaAuxiliar);
TablaAuxiliar.AddIndex(indice1,c1, []);
end;

if indice2<>'' then
begin
TablaAuxiliar.AddIndex(indice2,c2, []);
end;

if indice3<>'' then
begin
TablaAuxiliar.AddIndex(indice3,c3, []);
end;

end;{termina el chequeo}


end;


end;


procedure TFormaReindexa.FormCreate(Sender: TObject);
begin
{  Table1.Open;}
FormatosPais;
end;

procedure TFormaReindexa.BotonReindexaClick(Sender: TObject);
var
porcentaje:word;
begin

Avance.Progress:=0;

porcentaje:=0;
{*************}
if CheckBox1.Checked then porcentaje:=porcentaje+1;
if CheckBox2.Checked then porcentaje:=porcentaje+1;
if CheckBox3.Checked then porcentaje:=porcentaje+1;
if CheckBox4.Checked then porcentaje:=porcentaje+1;
if CheckBox5.Checked then porcentaje:=porcentaje+1;
if CheckBox6.Checked then porcentaje:=porcentaje+1;
if CheckBox7.Checked then porcentaje:=porcentaje+1;
if CheckBox8.Checked then porcentaje:=porcentaje+1;
if CheckBox9.Checked then porcentaje:=porcentaje+1;
if CheckBox10.Checked then porcentaje:=porcentaje+1;
if CheckBox11.Checked then porcentaje:=porcentaje+1;
if CheckBox12.Checked then porcentaje:=porcentaje+1;
if CheckBox13.Checked then porcentaje:=porcentaje+1;
if CheckBox14.Checked then porcentaje:=porcentaje+1;
if CheckBox15.Checked then porcentaje:=porcentaje+1;
if CheckBox16.Checked then porcentaje:=porcentaje+1;
if CheckBox17.Checked then porcentaje:=porcentaje+1;

{**************}
if porcentaje>0 then
porcentaje:=Trunc(100/porcentaje);

{***CLIENTES***}
if CheckBox1.Checked then
begin
reindexa('CLIENTE','ICLACLI','NOMBR_C','','CLCLI_C','NOMBR_C','');
Avance.Progress:=Avance.Progress+porcentaje;
end;
{****PROVEEDORES****}
if CheckBox2.Checked then
begin
reindexa('PROVEEDO','ICLAPRO','NOMBR_P','','CLAVE_P','NOMBR_P','');
Avance.Progress:=Avance.Progress+porcentaje;
end;
{****VENDEDORES***}
if CheckBox3.Checked then
begin
reindexa('VENDEDOR','ICLAVEN','NOMBR_V','','CLVEN_V','NOMBR_V','');
Avance.Progress:=Avance.Progress+porcentaje;
end;
{****RECEPCION COMPRAS****}
if CheckBox4.Checked then
begin
reindexa('COMPRASD','ICOMDET','','','CLDOC_OD','','');
reindexa('COMPRASE','CLPRV_O','ICOMENC','','CLPRV_O','CLDOC_O','');
reindexa('COMPOBS','CLDOC_CO','','','CLDOC_CO','','');
Avance.Progress:=Avance.Progress+porcentaje;
end;

{****ORDEN COMPRAS****}
if CheckBox15.Checked then
begin
reindexa('ORDENDET','ICOMDET','','','CLDOC_OD','','');
reindexa('ORDENCOM','CLPRV_O','ICOMENC','','CLPRV_O','CLDOC_O','');
Avance.Progress:=Avance.Progress+porcentaje;
end;

{****DEVOLUCION COMPRAS****}
if CheckBox16.Checked then
begin
reindexa('DEVOLDET','ICOMDET','','','CLDOC_OD','','');
reindexa('DevolCom','CLPRV_O','ICOMENC','','CLPRV_O','CLDOC_O','');
Avance.Progress:=Avance.Progress+porcentaje;
end;



{***FACTURACION*****}
if CheckBox5.Checked then
begin
reindexa('FACTURAD','CLDOC_FD','','','CLDOC_FD','','');
reindexa('FACTURAE','NOMBR_F','INUMENC','','NOMBR_F','CLDOC_F','');
reindexa('FACTUOBS','CLDOC_FO','','','CLDOC_FO','','');
Avance.Progress:=Avance.Progress+porcentaje;
end;

{***remisiones****}
if CheckBox10.Checked then
begin
reindexa('REMISIOD','CLDOC_FD','','','CLDOC_FD','','');
reindexa('REMISION','NOMBR_F','INUMENC','','NOMBR_F','CLDOC_F','');
Avance.Progress:=Avance.Progress+porcentaje;
end;
{***pedidos****}
if CheckBox11.Checked then
begin
reindexa('PEDIDOD','CLDOC_FD','','','CLDOC_FD','','');
reindexa('PEDIDO','NOMBR_F','INUMENC','','NOMBR_F','CLDOC_F','');
Avance.Progress:=Avance.Progress+porcentaje;
end;

{***cotizaciones****}
if CheckBox12.Checked then
begin
reindexa('COTIZACD','CLDOC_FD','','','CLDOC_FD','','');
reindexa('COTIZACI','NOMBR_F','INUMENC','','NOMBR_F','CLDOC_F','');
Avance.Progress:=Avance.Progress+porcentaje;
end;

{***notas de credito****}
if CheckBox13.Checked then
begin
reindexa('CREDITOD','CLDOC_FD','','','CLDOC_FD','','');
reindexa('CREDITO','NOMBR_F','INUMENC','','NOMBR_F','CLDOC_F','');
Avance.Progress:=Avance.Progress+porcentaje;
end;

{***devoluciones****}
if CheckBox14.Checked then
begin
reindexa('DEVOLUCD','CLDOC_FD','','','CLDOC_FD','','');
reindexa('DEVOLUC','NOMBR_F','INUMENC','','NOMBR_F','CLDOC_F','');
Avance.Progress:=Avance.Progress+porcentaje;
end;



{****INVENTAR******}
if CheckBox6.Checked then
begin
reindexa('INVENTAR','ICLPRO','','','CLPRO_I','','');
Avance.Progress:=Avance.Progress+porcentaje;
end;
{***CXC*****}
if CheckBox7.Checked then
begin
reindexa('CUCOBRAR','CLCLI_CC','ICUECOB','','CLCLI_CC','NUFAC_CC','');
Avance.Progress:=Avance.Progress+porcentaje;
end;
{****CXP****'}
if CheckBox8.Checked then
begin
reindexa('CUEPAGAR','CLPRO_CP','NUCOM','','CLPRO_CP','NUCOM_CP','');
Avance.Progress:=Avance.Progress+porcentaje;
end;

{ *****CATALOGOS*******}
if CheckBox9.Checked then
begin
reindexa('COMOVINV','ITIPMOV','','','NUCON_CM','','');
Avance.Progress:=Avance.Progress+porcentaje;
reindexa('CONCEPTO','NUME','','','NUMOV_MO','','');
Avance.Progress:=Avance.Progress+porcentaje;

end;


{*********************************}

if CheckBox17.Checked then
begin
reindexa('Movinven','CLPRO_MI','FEDOC_MI','IMOVINV','CLPRO_MI','FEDOC_MI','CLDOC_MI');
Avance.Progress:=Avance.Progress+porcentaje;
end;

{
i



{*********************}

Avance.Progress:=100;
MuestraMensaje('Proceso Términado');
end;


procedure TFormaReindexa.Panel4Click(Sender: TObject);
begin
Close;
end;




procedure TFormaReindexa.BotonCompactaClick(Sender: TObject);
begin

FormaAdministrador.ShowModal;
if FormaAdministrador.Tag=1 then
compactar;
 
end;

procedure TFormaReindexa.TablaAuxiliarUpdateError(DataSet: TDataSet;
  E: EDatabaseError; UpdateKind: TUpdateKind;
  var UpdateAction: TUpdateAction);
begin
fallo:=True;
end;

procedure TFormaReindexa.BotonReindexaMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaReindexa.Left+BotonReindexa.Left,FormaReindexa.Top+BotonReindexa.Top+BotonReindexa.Height,97);
end;

procedure TFormaReindexa.BotonCompactaMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaReindexa.Left+BotonCompacta.Left,FormaReindexa.Top+BotonCompacta.Top+BotonCompacta.Height,98);
end;

procedure TFormaReindexa.BotonRecuperacionMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaReindexa.Left+BotonRecuperacion.Left,FormaReindexa.Top+BotonRecuperacion.Top+BotonRecuperacion.Height,99);
end;

procedure TFormaReindexa.BitBtn3Click(Sender: TObject);

begin
Close;
end;

procedure TFormaReindexa.Panel3MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(FormaReindexa.Handle, WM_SYSCOMMAND, $F012, 0);

end;









procedure TFormaReindexa.TablaAuxiliarFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
if TablaAuxiliar.Tag=1 then
Accept:=((DataSet['TIMOV_CC']='1')or(DataSet['TIMOV_CC']='2'));

if TablaAuxiliar.Tag=2 then
Accept:=DataSet['TIMOV_CP']='51';

end;


end.
