unit CaptuRap;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  StdCtrls, Forms, DBCtrls, DB, DBTables, Mask, ExtCtrls, Grids, DBGrids,
  Buttons,Dialogos, Menus,Printers, ComCtrls, Tabnotbk,conver,checa,describe,tablas,
  Tabs,Apertura;

type
  TFormaCapturaRapida = class(TForm)
    FuenteTablaFacturae: TDataSource;
    TablaFacturae: TTable;
    TablaDeta: TTable;
    FuenteTablaDeta: TDataSource;
    TablaCliente: TTable;
    TablaInventario: TTable;
    TablaFacturaD: TTable;
    TablaVendedores: TTable;
    TablamovimientosInventario: TTable;
    TablaCuentasxCobrar: TTable;
    MainMenu1: TMainMenu;
    Archivo1: TMenuItem;
    Salir1: TMenuItem;
    Registro1: TMenuItem;
    Nuevo1: TMenuItem;
    Modificar1: TMenuItem;
    Guardar1: TMenuItem;
    Buscar1: TMenuItem;
    Imprimir1: TMenuItem;
    Reportes1: TMenuItem;
    Ayuda1: TMenuItem;
    Consultas1: TMenuItem;
    TablaDetaCANTIDAD: TFloatField;
    TablaDetaPRECIO: TCurrencyField;
    TablaDetaDESCUENTO: TFloatField;
    TablaDetaIMPORTE: TCurrencyField;
    Label13: TLabel;
    Concentrar1: TMenuItem;
    Panel1: TPanel;
    BotonTotales: TSpeedButton;
    BotonSalir: TSpeedButton;
    BotonPago: TSpeedButton;
    BotonBuscar: TSpeedButton;
    BotonCambios: TSpeedButton;
    Label14: TLabel;
    Navegador: TDBNavigator;
    Base: TComboBox;
    Panel2: TPanel;
    caja: TScrollBox;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label7: TLabel;
    Label9: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    IvaEtiqueta: TLabel;
    usuario: TLabel;
    EditCLDOC_F: TDBEdit;
    EditCLCLI_F: TDBEdit;
    EditBCLIM_F: TDBEdit;
    EditCLVEN_F: TDBEdit;
    EditDESFI_F: TDBEdit;
    EditCTOVE_F: TDBEdit;
    EditIMIM1_F: TDBEdit;
    EditFEDOC_F: TMaskEdit;
    Estado: TLabel;
    Comisiones1: TMenuItem;
    BotonNuevo: TSpeedButton;
    BotonGuardar: TSpeedButton;
    BotonImprimir: TSpeedButton;
    TablaDetaUNIDAD: TStringField;
    ConsecutivodeFacturas1: TMenuItem;
    Eliminar1: TMenuItem;
    TablaObservacion: TTable;
    ComisionesDetallado1: TMenuItem;
    Generar1: TMenuItem;
    Pedido1: TMenuItem;
    Remisin1: TMenuItem;
    Factura1: TMenuItem;
    TablaDetaCOSTO: TCurrencyField;
    VentasyUtilidad1: TMenuItem;
    BotonPreliminar: TSpeedButton;
    Calculadora1: TMenuItem;
    Opciones1: TMenuItem;
    Divisas1: TMenuItem;
    TotalesporDivisa1: TMenuItem;
    ImprimirDocumento1: TMenuItem;
    ImprimirRangodeDocumentos1: TMenuItem;
    Detalle: TDBGrid;
    Cancelar1: TMenuItem;
    Bevel1: TBevel;
    Bevel3: TBevel;
    Bevel8: TBevel;
    Bevel12: TBevel;
    Bevel15: TBevel;
    Bevel16: TBevel;
    Formatos: TMenuItem;
    Elegirformato1: TMenuItem;
    DisearFormato1: TMenuItem;
    FacturasFechaeImportes1: TMenuItem;
    BotonObservacion: TSpeedButton;
    Devolucin1: TMenuItem;
    NotadeCrdito1: TMenuItem;
    VentasporDa1: TMenuItem;
    VentasporMes1: TMenuItem;
    Ventasporao1: TMenuItem;
    VentasporArtculo1: TMenuItem;
    ImprimePlantilla1: TMenuItem;
    DocumentosCancelados1: TMenuItem;
    Temas1: TMenuItem;
    CancelaMovimiento1: TMenuItem;
    DesgloceporMoneda1: TMenuItem;
    TablaAuxiliar: TTable;
    TablaDetaCLAVE: TStringField;
    TablaDetaPRODUCTO: TStringField;
    Panel3: TPanel;
    Panel4: TPanel;
    uno: TLabel;
    dos: TLabel;
    Label2: TLabel;
    SuCambio: TLabel;
    CAMBIO_F: TDBEdit;
    VerFunciones1: TMenuItem;
    UtilidadporProducto1: TMenuItem;
    TabSet1: TTabSet;
    FacturadeCierre1: TMenuItem;
    CortedeCaja1: TMenuItem;
    Nombre: TLabel;
    TablaDetaIMPUESTO: TFloatField;
    TipoPago: TComboBox;
    Direccion: TLabel;
    Label8: TLabel;
    Direc2: TLabel;
    Poblacion: TLabel;
    RFC: TLabel;
    CodigoPostal: TLabel;
    RangodeDocumentos1: TMenuItem;
    Label1: TLabel;
    ConfigurarCaja1: TMenuItem;
    Label6: TLabel;
    Funciones: TLabel;
    Hora: TLabel;
    Panel5: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    EditClave: TDBEdit;
    Label10: TLabel;
    Label12: TLabel;
    SumarTotal: TLabel;
    Label22: TLabel;
    ImpuestoValor: TLabel;
    Label24: TLabel;
    TotalFact: TLabel;
    Label11: TLabel;
    EditCantidad: TDBEdit;
    Image1: TImage;
    Label15: TLabel;
    Label18: TLabel;
    SaltarEncabezado1: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure EditCLCLI_FExit(Sender: TObject);
    procedure BotonNuevoClick(Sender: TObject);
    procedure BotonGuardarClick(Sender: TObject);
    procedure NavegadorClick(Sender: TObject; Button: TNavigateBtn);
    procedure DetalleColEnter(Sender: TObject);
    procedure EditCLCLI_FKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCLVEN_FKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCLVEN_FExit(Sender: TObject);
    procedure EditFEDOC_FEnter(Sender: TObject);
    procedure DetalleKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure EditNALMA_FKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditFEDOC_FKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditIMIM1_FEnter(Sender: TObject);
    procedure EditDESFI_FEnter(Sender: TObject);
    procedure BotonSalirClick(Sender: TObject);
    procedure Consultas1Click(Sender: TObject);
    procedure EditCLDOC_FKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BotonBuscarClick(Sender: TObject);
    procedure BotonCambiosClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BotonImprimirClick(Sender: TObject);
    procedure DetalleEditButtonClick(Sender: TObject);
    procedure FolderChange(Sender: TObject; NewTab: Integer;
      var AllowChange: Boolean);
    procedure BaseChange(Sender: TObject);
    procedure EditCLDOC_FEnter(Sender: TObject);
    procedure EditCLCLI_FEnter(Sender: TObject);
    procedure EditBCLIM_FEnter(Sender: TObject);
    procedure EditCLVEN_FEnter(Sender: TObject);
    procedure EditCTOVE_FEnter(Sender: TObject);
    procedure EditCLPED_FEnter(Sender: TObject);
    procedure EditDECOT_FEnter(Sender: TObject);
    procedure Concentrar1Click(Sender: TObject);
    procedure Comisiones1Click(Sender: TObject);
    procedure EditFEDOC_FExit(Sender: TObject);
    procedure EditCLDOC_FMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditCLCLI_FMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditCLVEN_FMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditCTOVE_FMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditBCLIM_FMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditCLPED_FMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditFEDOC_FMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditIMIM1_FMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditDESFI_FMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditDECOT_FMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditNALMA_FMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditREMIS_FKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCONDI_FKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditDESTI_FKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure ConsecutivodeFacturas1Click(Sender: TObject);
    procedure Eliminar1Click(Sender: TObject);
    procedure ComisionesDetallado1Click(Sender: TObject);
    procedure Factura1Click(Sender: TObject);
    procedure Remisin1Click(Sender: TObject);
    procedure Pedido1Click(Sender: TObject);
    procedure VentasyUtilidad1Click(Sender: TObject);
    procedure BotonPreliminarClick(Sender: TObject);
    procedure Calculadora1Click(Sender: TObject);
    procedure Divisas1Click(Sender: TObject);
    procedure ImprimirRangodeDocumentos1Click(Sender: TObject);
    procedure Cancelar1Click(Sender: TObject);
    procedure BotonTotalesClick(Sender: TObject);
    procedure EditDECOT_FKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Elegirformato1Click(Sender: TObject);
    procedure DisearFormato1Click(Sender: TObject);
    procedure TablaFacturaeEditError(DataSet: TDataSet; E: EDatabaseError;
      var Action: TDataAction);
    procedure TablaFacturaePostError(DataSet: TDataSet; E: EDatabaseError;
      var Action: TDataAction);
    procedure EditCLDOC_FExit(Sender: TObject);
    procedure EditCTOVE_FExit(Sender: TObject);
    procedure EditBCLIM_FExit(Sender: TObject);
    procedure EditIMIM1_FExit(Sender: TObject);
    procedure EditDESFI_FExit(Sender: TObject);
    procedure TablaFacturaeDeleteError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    procedure TablaFacturaeUpdateError(DataSet: TDataSet;
      E: EDatabaseError; UpdateKind: TUpdateKind;
      var UpdateAction: TUpdateAction);
    procedure TablaFacturaDDeleteError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    procedure TablaFacturaDEditError(DataSet: TDataSet; E: EDatabaseError;
      var Action: TDataAction);
    procedure TablaFacturaDPostError(DataSet: TDataSet; E: EDatabaseError;
      var Action: TDataAction);
    procedure TablaFacturaDUpdateError(DataSet: TDataSet;
      E: EDatabaseError; UpdateKind: TUpdateKind;
      var UpdateAction: TUpdateAction);
    procedure TablaClienteEditError(DataSet: TDataSet; E: EDatabaseError;
      var Action: TDataAction);
    procedure TablaClienteDeleteError(DataSet: TDataSet; E: EDatabaseError;
      var Action: TDataAction);
    procedure TablaClientePostError(DataSet: TDataSet; E: EDatabaseError;
      var Action: TDataAction);
    procedure TablaClienteUpdateError(DataSet: TDataSet; E: EDatabaseError;
      UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
    procedure TablaInventarioDeleteError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    procedure TablaInventarioEditError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    procedure TablaInventarioPostError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    procedure TablaInventarioUpdateError(DataSet: TDataSet;
      E: EDatabaseError; UpdateKind: TUpdateKind;
      var UpdateAction: TUpdateAction);
    procedure TablaVendedoresDeleteError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    procedure TablaVendedoresEditError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    procedure TablaVendedoresPostError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    procedure TablaVendedoresUpdateError(DataSet: TDataSet;
      E: EDatabaseError; UpdateKind: TUpdateKind;
      var UpdateAction: TUpdateAction);
    procedure TablamovimientosInventarioDeleteError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    procedure TablamovimientosInventarioEditError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    procedure TablamovimientosInventarioPostError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    procedure TablamovimientosInventarioUpdateError(DataSet: TDataSet;
      E: EDatabaseError; UpdateKind: TUpdateKind;
      var UpdateAction: TUpdateAction);
    procedure FacturasFechaeImportes1Click(Sender: TObject);
    procedure BotonObservacionClick(Sender: TObject);
    procedure BotonCambiosMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonNuevoMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonGuardarMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonTotalesMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonPreliminarMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonObservacionMouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure BotonBuscarMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonImprimirMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonPagoMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Devolucin1Click(Sender: TObject);
    procedure VentasporDa1Click(Sender: TObject);
    procedure VentasporMes1Click(Sender: TObject);
    procedure Ventasporao1Click(Sender: TObject);
    procedure VentasporArtculo1Click(Sender: TObject);
    procedure ImprimePlantilla1Click(Sender: TObject);
    procedure DocumentosCancelados1Click(Sender: TObject);
    procedure EditDIVIS_FKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditDIVIS_FEnter(Sender: TObject);
    procedure EditDIVIS_FExit(Sender: TObject);
    procedure Temas1Click(Sender: TObject);
    procedure CancelaMovimiento1Click(Sender: TObject);
    procedure DesgloceporMoneda1Click(Sender: TObject);
    procedure EditDESFI_FKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DetalleKeyPress(Sender: TObject; var Key: Char);
    procedure DetalleEnter(Sender: TObject);
    procedure Edit1Exit(Sender: TObject);
    procedure CAMBIO_FExit(Sender: TObject);
    procedure CAMBIO_FKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure VerFunciones1Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DetalleColExit(Sender: TObject);
    procedure UtilidadporProducto1Click(Sender: TObject);
    procedure FacturadeCierre1Click(Sender: TObject);
    procedure CortedeCaja1Click(Sender: TObject);
    procedure CAMBIO_FEnter(Sender: TObject);
    procedure RangodeDocumentos1Click(Sender: TObject);
    procedure ConfigurarCaja1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DetalleDrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure EditClaveKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCantidadKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure SaltarEncabezado1Click(Sender: TObject);
  private
procedure MyOnGetText(Sender: TField; var Text: string; DisplayText: Boolean);
    { private declarations }
  public
procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
    { public declarations }
  end;



type
registroencab=record
Numero:string[10];
claveCli:string[15];
NombreCli:string[60];
direccionCli:String[60];
direccionCli2:string[60];
Poblacion:string[40];
Vendedor:string[15];
Comision:string[4];
Mostrador:string[10];
Condiciones:string[10];
Destino:string[10];
FechaDoc:string[15];
FechaEnt:string[15];
FechaVen:string[15];
Iva:String[10];
DescFina:string[10];
DescComer:string[10];
Almacen:string[10];
Pago:string[25];
end;

type
registrodeta=record
cantidad:real;
clave:string[15];
descripcion:string[40];
precio:real;
descuento:real;
costo:real;
unidad:string[3];

end;



var
  FormaCapturaRapida: TFormaCapturaRapida;
   numeromovimiento,tipomovimiento,indice:longint;
   cantidad,suma,iva1,total1,costo,saldoanterior:Currency;
   iva,desfin,desfin1:Real;
   indices,ant,sig:integer;
   meses:array[1..12] of Real;
   cliente:String;
   decimales,formatonum:Word;
   local:Boolean;
   Color1:TColor;
   nombreformato:string;
   ultimovendedor:string[10];
   CambiaPrecios:string[1];
   PrecioNumero:Word;
   Orig:String[8];
   ivatotal:Real;
   RangoDocumentos:Boolean;
   ExistenciasNegativos:string[1];
   desglosado:boolean;
   CajaLocal:String[10];
   Digitos:Word;
   Digi:string[20];
   ListaClaves,ListaCantidad:TStringList;
   SaltarEncabezado:boolean;

procedure posicionafactura(clave:string);
implementation


uses ConVen, ConInve, Acerca, consulta, buscar, ConPro, formatos,
  cerrar,formato, conclie, barras, advierte, edicion, moneda, totales,
  imprime, desgloce, Concobra, cxcd, observa, progreso, Cucobra,
  AyudaMod, Rango{, Rango};

{$R *.DFM}

function CantidadApartada(clave:string;regi:integer):real;
var
i,acumulado:real;
indi:integer;
aux:string;
begin
{   acumulado:=0;
   for i:=1 to 100 do
   begin
    if  (Apartados[i,1]=clave)and(regi<>i) then
    acumulado:=acumulado+StrToInt(Apartados[i,2])



   end;
   CantidadApartada:=acumulado;}
   acumulado:=0;
   if ListaClaves.Find(clave,indi) then
   begin
   aux:=ListaCantidad.Strings[indi];
    CantidadApartada:=StrToFloat(aux);
    //Insert(indi,FloatToStr(StrToFloat(ListaCantidad.Strings[indi])+TablaDeta.FieldByName('CANTIDAD').AsFloat));

   end
   else
   CantidadApartada:=0;

end;

procedure TFormaCapturaRapida.MyOnGetText(Sender: TField; var Text: string; DisplayText: Boolean);
var
aux:string;
i:integer;
begin
aux:=Sender.AsString;
text:=aux;
//Sender.

if aux<>'' then
Case Sender.DataType of
ftInteger:begin
//ShowMessage('entra entero'+aux);
text:=FormatFloat(Digi,StrTofloat(aux));
end;
ftFloat	:begin
//ShowMessage('entra flotante'+AUX);
text:=FormatFloat(Digi,StrTofloat(aux));
end;

ftString:begin
//ShowMessage('entra cademnae'+text);
text:=aux;
end;

end;//case




end;


procedure CalculaRangoDocumentos(TablaAnterior:string;rango:string);
var
 Tabla: TTable;
 i,j,inicio,fin:integer;
 aux:string;
 ran:Boolean;
begin
with FormaCapturaRapida do
begin
inicio:=0;
fin:=0;
aux:='';
ran:=False;
for i:=1 to length(rango) do
if rango[i]='-' then
begin
ran:=True;
end;
if ran then
rango:=rango+'-'
else
rango:=rango+',';

for j:=1 to length(rango) do
begin

if rango[j]='-' then
begin

if inicio=0 then inicio:=StrToInt(aux)
else
fin:=StrToInt(aux);
aux:='';

end//if rango
else
aux:=rango[j];

end;//for j

if TablaAuxiliar.State=dsBrowse then
TablaAuxiliar.Close;

   TablaAuxiliar.DatabaseName := ruta(8);
   TablaAuxiliar.TableName :=TablaAnterior;
   TablaAuxiliar.IndexName:='CLDOC_FD';
   TablaAuxiliar.Open;


//MuestraMensaje(IntToStr(inicio)+'   '+IntToStr(fin));
if ran then
if inicio<=fin then
for i:=fin downto inicio do
begin
TablaAuxiliar.SetRange([IntToStr(i)],[IntToStr(i)]);

{TablaFacturaD.First;}
TablaAuxiliar.Last;

while not TablaAuxiliar.Bof do
begin
if TablaAuxiliar.FieldByName('TREGI_FD').AsString<>'C' then
begin
TablaDeta.Insert;
TablaDeta.FieldByName('CANTIDAD').AsFloat:=TablaAuxiliar.FieldByName('CANTI_FD').AsFloat;
TablaDeta.FieldByName('CLAVE').AsString:=TablaAuxiliar.FieldByName('CLPRO_FD').AsString;
TablaDeta.FieldByName('PRODUCTO').AsString:=TablaAuxiliar.FieldByName('DEPRO_FD').AsString;
TablaDeta.FieldByName('UNIDAD').AsString:=TablaAuxiliar.FieldByName('UNIDA_FD').AsString;
TablaDeta.FieldByName('PRECIO').AsFloat:=TablaAuxiliar.FieldByName('PUNPR_FD').AsFloat;
TablaDeta.FieldByName('COSTO').AsFloat:=TablaAuxiliar.FieldByName('COPRO_FD').AsFloat*TablaDeta.FieldByName('CANTIDAD').AsFloat;
TablaDeta.FieldByName('DESCUENTO').AsFloat:=TablaAuxiliar.FieldByName('PDES1_FD').AsFloat;
TablaDeta.FieldByName('IMPORTE').AsFloat:=TablaDeta.FieldByName('CANTIDAD').AsFloat*TablaDeta.FieldByName('PRECIO').AsFloat-
(TablaDeta.FieldByName('CANTIDAD').AsFloat*TablaDeta.FieldByName('PRECIO').AsFloat*TablaDeta.FieldByName('DESCUENTO').AsFloat/100);
TablaDeta.FieldByName('IMPUESTO').AsFloat:=TablaAuxiliar.FieldByName('PIVA1_FD').AsFloat;

TablaDeta.Post;
end;//if
TablaAuxiliar.Prior;


end;//while


end;//for i

//**************segundo caso
aux:='';
i:=1;
if not ran then
while i<=length(rango) do
begin
if rango[i]=',' then
begin

TablaAuxiliar.SetRange([Aux],[Aux]);

{TablaFacturaD.First;}
TablaAuxiliar.Last;

while not TablaAuxiliar.Bof do
begin
if TablaAuxiliar.FieldByName('TREGI_FD').AsString<>'C' then
begin
TablaDeta.Insert;
TablaDeta.FieldByName('CANTIDAD').AsFloat:=TablaAuxiliar.FieldByName('CANTI_FD').AsFloat;
TablaDeta.FieldByName('CLAVE').AsString:=TablaAuxiliar.FieldByName('CLPRO_FD').AsString;
TablaDeta.FieldByName('PRODUCTO').AsString:=TablaAuxiliar.FieldByName('DEPRO_FD').AsString;
TablaDeta.FieldByName('UNIDAD').AsString:=TablaAuxiliar.FieldByName('UNIDA_FD').AsString;
TablaDeta.FieldByName('PRECIO').AsFloat:=TablaAuxiliar.FieldByName('PUNPR_FD').AsFloat;
TablaDeta.FieldByName('COSTO').AsFloat:=TablaAuxiliar.FieldByName('COPRO_FD').AsFloat*TablaDeta.FieldByName('CANTIDAD').AsFloat;
TablaDeta.FieldByName('DESCUENTO').AsFloat:=TablaAuxiliar.FieldByName('PDES1_FD').AsFloat;
TablaDeta.FieldByName('IMPORTE').AsFloat:=TablaDeta.FieldByName('CANTIDAD').AsFloat*TablaDeta.FieldByName('PRECIO').AsFloat-
(TablaDeta.FieldByName('CANTIDAD').AsFloat*TablaDeta.FieldByName('PRECIO').AsFloat*TablaDeta.FieldByName('DESCUENTO').AsFloat/100);
TablaDeta.FieldByName('IMPUESTO').AsFloat:=TablaAuxiliar.FieldByName('PIVA1_FD').AsFloat;

TablaDeta.Post;
end;//if
TablaAuxiliar.Prior;


end;//while
Aux:='';
end
else
begin
Aux:=Aux+rango[i];
end;
i:=i+1;
end;//for i
//*************************************


TablaAuxiliar.Close;
//Tabla.Free;

end;//width
end;


procedure ActualizaFacturaImporte(tot,iv,su:real);
begin
with FormaCapturaRapida do
begin
if TablaFacturaE.FieldByName('IMTOD_F').AsFloat<>Total1 then
begin
TablaFacturaE.Edit;
TablaFacturaE.FieldByName('SUBTO_F').AsFloat:=suma;
TablaFacturaE.FieldByName('DECOT_F').AsFloat:=desfin1;
TablaFacturaE.FieldByName('IMIM2_F').AsFloat:=iva1;
TablaFacturaE.FieldByName('IMTOD_F').AsFloat:=Total1;
TablaFacturaE.FieldByName('COSTO_F').AsFloat:=costo;
TablaFacturaE.Post;
end;//if

end;//width
end;


procedure CancelaDetalle(doc:string);
begin
with FormaCapturaRapida do
begin

TablaFacturaD.SetRange([doc],[doc]);

{TablaFacturaD.First;}
TablaFacturaD.First;

while not TablaFacturaD.Eof do
begin
TablaFacturaD.Edit;

TablaFacturaD.FieldByName('TREGI_FD').AsString:='C';

TablaFacturaD.Post;
TablaFacturaD.Next;


end;//while
end;
end;



procedure CopiaRegistro(Tabla1,Tabla2:TTable);
var
i:integer;
begin

for i:=0 to Tabla1.FieldCount-1 do
begin
Tabla2.FieldByName(Tabla1.Fields[i].FieldName).AsString:=Tabla1.FieldByName(Tabla1.Fields[i].FieldName).AsString;
end;


end;


procedure GeneraCorteDeCaja(fecha,fecha2:TDate;nombre1,nombre2,nombre3,indice:string);
var
Tabla:TTable;
campofecha,nomtab:string;
Fe1,fe2:String;
begin
with FormaCapturaRapida do
begin
Refresh;
if LowerCase(nombre3)='factauxi.dbf' then
begin
 campofecha:='FEDOC_F';
 nomtab:='enc';
end
else
begin
campofecha:='FEDOC_FD';
nomtab:='det';
end;
//MuestraMensaje(DateToStr(fecha)+'  '+DateToStr(fecha2));
if TablaAuxiliar.State=dsBrowse then
TablaAuxiliar.Close;
try

TablaAuxiliar.DatabaseName:=ruta(8);
TablaAuxiliar.TableName:=nombre3;
TablaAuxiliar.IndexName:=indice;
//'FactAuxi.dbf';
TablaAuxiliar.Open;
While not TablaAuxiliar.Eof do
begin
TablaAuxiliar.Delete;
end;

Tabla:=TTable.Create(Tabla);
Tabla.DatabaseName:=ruta(8);
//Tabla.TableName:='Remision.dbf';
Tabla.TableName:=nombre1;
Tabla.Open;
fe1:=DateToStr(fecha);
fe2:=DateToStr(fecha2);

While not Tabla.Eof do
begin
if (StrToDate(fe1)<=Tabla.FieldByName(campofecha).AsDateTime)and(StrToDate(fe2)>=Tabla.FieldByName(campofecha).AsDateTime) then
begin
//MuestraMensaje(Tabla.FieldByName('CLDOC_F').AsString);
TablaAuxiliar.Insert;
CopiaRegistro(Tabla,TablaAuxiliar);
TablaAuxiliar.Post;
end;//if

Tabla.Next;
end;//while


if Tabla.State=dsBrowse then
Tabla.Close;
Tabla.DatabaseName:=ruta(8);
Tabla.TableName:=nombre2;
//'Devoluc.dbf';
Tabla.Open;
While not Tabla.Eof do
begin
if (StrToDate(fe1)<=Tabla.FieldByName(campofecha).AsDateTime)and(StrToDate(fe2)>=Tabla.FieldByName(campofecha).AsDateTime) then
begin
TablaAuxiliar.Insert;
CopiaRegistro(Tabla,TablaAuxiliar);
if  nomtab='enc'then
begin
TablaAuxiliar.FieldByName('IMTOD_F').AsFloat:=TablaAuxiliar.FieldByName('IMTOD_F').AsFloat*(-1);
TablaAuxiliar.FieldByName('SUBTO_F').AsFloat:=TablaAuxiliar.FieldByName('SUBTO_F').AsFloat*(-1);
end
else
begin
TablaAuxiliar.FieldByName('CANTI_FD').AsFloat:=TablaAuxiliar.FieldByName('CANTI_FD').AsFloat*(-1);
//TablaAuxiliar.FieldByName('SUBTO_F').AsFloat:=TablaAuxiliar.FieldByName('SUBTO_F').AsFloat*(-1);
end;
TablaAuxiliar.Post;
end;//if

Tabla.Next;
end;//while

Tabla.Free;

except
if TablaAuxiliar.State=dsBrowse then
TablaAuxiliar.Close;

end;//try
end;
end;

procedure TFormaCapturaRapida.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
{with Form2 do
begin}
 if Msg.wParam = VK_RETURN then
 begin
 if ((Screen.ActiveControl) is TEdit)or((Screen.ActiveControl) is TDBEdit)
  or((Screen.ActiveControl) is TMaskEdit)and ((Screen.ActiveForm) is TFormaCapturaRapida) then
 Msg.wParam := VK_TAB;
 end;

{end;}
end;



{***termina procedimiento  de enter******}



{***posiciona desde catalogo****}


{****************************}




{*****activar botones}

procedure activabotones(cambios,nuevo,guardar,buscar,imprimir,navegar,cancela:boolean);
begin
with FormaCapturaRapida do
begin
BotonCambios.Enabled:=cambios;
Modificar1.Enabled:=cambios;

BotonNuevo.Enabled:=nuevo;
Nuevo1.Enabled:=nuevo;

BotonGuardar.Enabled:=guardar;
Guardar1.Enabled:=guardar;

BotonBuscar.Enabled:=buscar;

BotonImprimir.Enabled:=imprimir;

Navegador.Enabled:=navegar;

CancelaMovimiento1.Enabled:=cancela;

{*****extras******}
 Eliminar1.Enabled:=nuevo;
 Cancelar1.Enabled:=nuevo;
 CancelaMovimiento1.Enabled:=guardar;

{****************}


end;
end;

{*******************}


procedure buscaobservacion(numero:string;tipo:integer);
begin
with FormaCapturaRapida do
begin
  FormaObservaciones:=TFormaObservaciones.Create(Application);
{case tipo of
0:begin}

  FormaObservaciones.Tag:=0;
  FormaObservaciones.Observacion.Clear;
  TablaObservacion.First;

  if (TablaObservacion.FindKey([numero])) then
  begin
  FormaObservaciones.Observacion.Lines[0]:=TablaObservacion.FieldByName('OBSER_FO').AsString;
  end;
  {MuestraMensaje('No Tiene Observaciones');}
  FormaObservaciones.ShowModal;
  {  end;
  end;
1:begin
  FormaObservaciones.Observacion.Clear;
  FormaObservaciones.ShowModal;}
 {********************************}

  if FormaObservaciones.Tag=1 then
  begin
  TablaObservacion.First;
  if (TablaObservacion.FindKey([numero])) then
  TablaObservacion.Edit
  else
  TablaObservacion.Insert;

  TablaObservacion.FieldByName('CLDOC_FO').AsString:=numero;
  TablaObservacion.FieldByName('OBSER_FO').AsString:=FormaObservaciones.Observacion.Lines[0];
  TablaObservacion.Post;

  end;
{*************************************}
  FormaObservaciones.Tag:=0;
end;
FormaObservaciones.Free;
end;


procedure ponecolor(indi:integer;col1:TColor);
begin
with FormaCapturaRapida do
begin
color1:=col1;
TDBEdit(Components[indi]).Color:=ClRed;
end;
end;

procedure quitacolor(indi:integer);
begin
with FormaCapturaRapida do
begin
TDBEdit(Components[indi]).Color:=Color1;

end;
end;






{function guardadivisa:string;
type
mone=record
Nombre:string[15];
valor:string[10];
end;
var
arch:file of mone;
money:mone;
i:integer;
aux:string;
begin
aux:='';
if FileExists(ruta(8)+'\moneda.sif') then
begin
AssignFile(arch,ruta(8)+'\moneda.sif');
reset(arch);
while not Eof(arch) do
begin
Read(arch,money);
aux:=aux+money.nombre+',';
aux:=aux+money.valor+',';
end;
CloseFile(arch);
guardadivisa:=aux;
end;
end;}

function leedivisa:string;
type
mone=record
Nombre:string[15];
valor:string[10];
eti1:String[30];
eti2:String[30];
eti3:String[30];
eti4:String[30];
eti5:String[5];
end;
var
arch:file of mone;
money:mone;
i:integer;
aux:string;
begin
aux:='';
if FileExists(ruta(8)+'\moneda.sif') then
begin
AssignFile(arch,ruta(8)+'\moneda.sif');
reset(arch);
{FormaCapturaRapida.EditDIVIS_F.Items.Clear;}
while not Eof(arch) do
begin

Read(arch,money);
{FormaCapturaRapida.EditDIVIS_F.Items.Add(money.nombre);}
{aux:=aux+money.valor+',';}
end;
{FormaCapturaRapida.EditDIVIS_F.Text:=FormaCapturaRapida.EditDIVIS_F.Items[0];}
CloseFile(arch);
{guardadivisa:=aux;}
end;
end;

function valordivisa(caso:integer):Currency;
type
mone=record
Nombre:string[15];
valor:string[10];
eti1:String[30];
eti2:String[30];
eti3:String[30];
eti4:String[30];
eti5:String[5];

end;
var
arch:file of mone;
money:mone;
i:integer;
begin
if FileExists(ruta(8)+'\moneda.sif') then
begin
AssignFile(arch,ruta(8)+'\moneda.sif');
reset(arch);
for i:=0 to caso do
begin
Read(arch,money);
end;
valordivisa:=StrToCurr(money.valor);
CloseFile(arch);
{guardadivisa:=aux;}
end;
end;
{****procedimiento para leer los distintos valores de mobneda******}
function valordivisaetiqueta(moned:string;valor:word):string;
type
mone=record
Nombre:string[15];
valor:string[10];
eti1:String[30];
eti2:String[30];
eti3:String[30];
eti4:String[30];
eti5:String[5];

end;
var
arch:file of mone;
money:mone;
i:integer;
begin
if FileExists(ruta(8)+'\moneda.sif') then
begin
AssignFile(arch,ruta(8)+'\moneda.sif');
reset(arch);
money.Nombre:='';
valordivisaetiqueta:='xx';
for i:=0 to FileSize(arch)-1 do
begin
if moned=money.Nombre then
begin
if valor=1 then valordivisaetiqueta:=money.eti1;
if valor=2 then valordivisaetiqueta:=money.eti2;
if valor=3 then valordivisaetiqueta:=money.eti3;
if valor=4 then valordivisaetiqueta:=money.eti4;
break;
end;

Read(arch,money);
end;
{valordivisa:=StrToCurr(money.valor);}
CloseFile(arch);
{guardadivisa:=aux;}
end;
end;



{******************************}


procedure calculavencimiento;
var
dias,meses:integer;
a,m,d:Word;
begin
end;

Procedure borra;
begin
with FormaCapturaRapida do
begin
TablaDeta.First;
while not TablaDeta.Eof do
begin
TablaDeta.Delete;
end;
end;
end;


procedure asignatipo;
type
datos=record
archivo:String[60];
descrip:String[125];
end;
var
dat:datos;
faltan:Boolean;
arch,arch2:file of datos;
i:integer;
begin
with FormaConsulta do
begin
{MuestraMensaje(leeruta+'\report\facturae.for');}
AssignFile(arch,leeruta+'\report\facturae.for');
Reset(arch);
Archivo.Items.Clear;
Descripcion.Clear;
faltan:=True;
for i:=0 to FileSize(arch)-1 do
begin
Read(arch,dat);
if FileExists(Dat.archivo) then
Archivo.Items.Append(Dat.archivo)
else
faltan:=False;
end;
CloseFile(arch);


if faltan=False then
begin
AssignFile(arch,leeruta+'\report\facturae.for');
Reset(arch);
AssignFile(arch2,leeruta+'\report\Cliente2.for');
Rewrite(arch2);

for i:=0 to FileSize(arch)-1 do
begin
Read(arch,dat);
if FileExists(Dat.archivo) then
write(arch2,dat);
end;
CloseFile(arch);
CloseFile(arch2);
{******************}
AssignFile(arch,leeruta+'\report\facturae.for');
Rewrite(arch);
AssignFile(arch2,leeruta+'\report\Cliente2.for');
Reset(arch2);

for i:=0 to FileSize(arch2)-1 do
begin
Read(arch2,dat);
if FileExists(Dat.archivo) then
write(arch,dat);
end;
CloseFile(arch);
CloseFile(arch2);
end;


Archivo.Text:=Archivo.Items[0];
Descripcion.lines.Add(Dat.Descrip);

ReporteDe.Caption:='Reporte de Clientes';
Archi.Caption:='facturae.for';
end;

end;




procedure ejes(m:integer);
begin
end;




{%%%%%%%%%%%%%%%%%inicia traduce %%%%%%%%%%%%%%%}

{function exponente(num:longint;j:integer):longint;
var
i:integer;
begin
if j>=1 then
for i:=1 to j do
begin
num:=num*10;
end;
exponente:=num;
end;



function busca(cifra:longint;pos,ult:integer):string;
var
cadenas:array[1..200,1..2] of string;
i,num:longint;
begin
cadenas[1,1]:='1';cadenas[1,2]:='un';
cadenas[2,1]:='2';cadenas[2,2]:='dos';
cadenas[3,1]:='3';cadenas[3,2]:='tres';
cadenas[4,1]:='4';cadenas[4,2]:='cuatro';
cadenas[5,1]:='5';cadenas[5,2]:='cinco';
cadenas[6,1]:='6';cadenas[6,2]:='seis';
cadenas[7,1]:='7';cadenas[7,2]:='siete';
cadenas[8,1]:='8';cadenas[8,2]:='ocho';
cadenas[9,1]:='9';cadenas[9,2]:='nueve';
cadenas[10,1]:='10';cadenas[10,2]:='diez';
cadenas[11,1]:='11';cadenas[11,2]:='once';
cadenas[12,1]:='12';cadenas[12,2]:='doce';
cadenas[13,1]:='13';cadenas[13,2]:='trece';
cadenas[14,1]:='14';cadenas[14,2]:='catorce';
cadenas[15,1]:='15';cadenas[15,2]:='quince';
cadenas[16,1]:='16';cadenas[16,2]:='dieciseis';
cadenas[17,1]:='17';cadenas[17,2]:='diecisiete';
cadenas[18,1]:='18';cadenas[18,2]:='dieciocho';
cadenas[19,1]:='19';cadenas[19,2]:='diecinueve';
cadenas[20,1]:='20';cadenas[20,2]:='veinte';
cadenas[21,1]:='21';cadenas[21,2]:='veintiuno';
cadenas[22,1]:='22';cadenas[22,2]:='veintidos';
cadenas[23,1]:='23';cadenas[23,2]:='veintitres';
cadenas[24,1]:='24';cadenas[24,2]:='veinticuatro';
cadenas[25,1]:='25';cadenas[25,2]:='veinticinco';
cadenas[26,1]:='26';cadenas[26,2]:='veintiseis';
cadenas[27,1]:='27';cadenas[27,2]:='veintisiete';
cadenas[28,1]:='28';cadenas[28,2]:='veintiocho';
cadenas[29,1]:='29';cadenas[29,2]:='veintinueve';
cadenas[30,1]:='30';cadenas[30,2]:='treinta';
cadenas[32,1]:='40';cadenas[32,2]:='cuarenta';
cadenas[33,1]:='50';cadenas[33,2]:='cincuenta';
cadenas[34,1]:='60';cadenas[34,2]:='sesenta';
cadenas[35,1]:='70';cadenas[35,2]:='setenta';
cadenas[36,1]:='80';cadenas[36,2]:='ochenta';
cadenas[37,1]:='90';cadenas[37,2]:='noventa';
cadenas[38,1]:='100';cadenas[38,2]:='ciento';
cadenas[39,1]:='200';cadenas[39,2]:='doscientos';
cadenas[40,1]:='300';cadenas[40,2]:='trescientos';
cadenas[41,1]:='400';cadenas[41,2]:='cuatrocientos';
cadenas[42,1]:='500';cadenas[42,2]:='quinientos';
cadenas[43,1]:='600';cadenas[43,2]:='seiscientos';
cadenas[44,1]:='700';cadenas[44,2]:='setecientos';
cadenas[45,1]:='800';cadenas[45,2]:='ochocientos';
cadenas[46,1]:='900';cadenas[46,2]:='novecientos';
cadenas[47,1]:='1000';cadenas[47,2]:='mil';
cadenas[48,1]:='1000000';cadenas[48,2]:='millones';
i:=1;

while not(cadenas[i,1]=IntToStr(cifra))and(i<50) do
begin
i:=i+1;
end;


if cadenas[i,2]<>'' then
begin

if (cifra<=10)and (cifra>=1)and(ult<>1) then
cadenas[i,2]:=' y '+cadenas[i,2];


if (pos=0)then
cadenas[i,2]:=' '+cadenas[i,2];
end;

if cadenas[i,2]<>'0' then
busca:='  '+cadenas[i,2];

case pos+1 of
4:busca:='  '+cadenas[i,2] +' mil ';


end;


end;


function traduce(cantidad:Real):String;
var
aux,letra:String;
valores:array[1..10] of longint;
cifra:longint;
j,i,pos,ult:integer;
begin
aux:=intToStr(Trunc(cantidad));
j:=length(aux);

for i:=1 to length(aux) do
begin
valores[i]:=exponente(StrToInt(aux[i]),j-1);
j:=j-1;
end;

j:=0;

if length(aux)>2 then
begin
for i:=length(aux) downto 2  do
begin
j:=j+1;
if j=1 then
begin
valores[i]:=valores[i]+valores[i-1];
end;
if j=3 then j:=0;
end;

end
else
begin
valores[2]:=StrToInt(aux);
valores[1]:= (valores[2]div 10)*10   ;
end;


letra:='';
pos:=length(aux);
j:=1;



i:=length(aux);

j:=0;
pos:=0;
if i<=2 then
i:=2;
ult:=0;
while i>=1  do
begin
j:=j+1;
if i=2 then ult:=1;

if valores[i]>=1000 then
begin
valores[i]:=valores[i] div exponente(1,pos);
if i-1>0 then
valores[i-1]:=valores[i-1] div exponente(1,pos);
end;


if j=1 then
begin
if valores[i]>30 then
begin

valores[i-1]:=valores[i]-valores[i-1];
letra:=busca(valores[i-1],pos,ult)+letra;
valores[i]:=valores[i]-valores[i-1];
letra:=busca(valores[i],1,ult)+letra;

end
else
begin
letra:=busca(valores[i],pos,ult)+letra;

end;

end;


if j=3 then
begin
letra:=busca(valores[i],pos,ult)+letra;
j:=0;
end;
i:=i-1;
pos:=pos+1;


end;



letra:=letra+'  pesos '+IntToStr(Trunc(Frac(cantidad)*100))+'/100' ;

traduce:=letra;
end; }

{%%%%%%%%%%%%%%%%%termina traduce %%%%%%%%%%%%%%%}

{**** iniciaN procedimientos para formatos***************}
procedure dibujabitmap(nombre:String);
var
  mapa: TBitmap;
  rectangulo:TRect;
begin

  mapa := TBitmap.Create;
  mapa.LoadFromFile(nombre);
  rectangulo.Left:=5;
  rectangulo.Top:=5;
  rectangulo.Right:=100;
  rectangulo.Bottom:=240;
  Printer.Canvas.StretchDraw(rectangulo,mapa);
end;


procedure imprimelinea(li:string;tipo,y:integer;palabra:word);

var
l,j,i,conta,cod:integer;
aux:string;
valor:array[1..3] of string;
palabras:array[1..5]of string;
nume:Real;
begin
conta:=1;
i:=1;
palabras[1]:='';
palabras[2]:='';
palabras[3]:='';
palabras[4]:='';
palabras[5]:='';
while (i<=length(li))and (conta<=5) do
begin

if (li[i]=',')or(li[i]='(')or(li[i]=')') then
conta:=conta+1
else
begin
if (li[i]<>' ')and (li[i]<>'@') then
palabras[conta]:=palabras[conta]+li[i];
end;
i:=i+1;
end;

aux:='';

case palabra of
1:begin
  valor[1]:='';
  valor[2]:='';
  valor[3]:='';
  j:=1;
  for l:=2 to length(li) do
  begin
  if (li[l]=',') then
  begin
  valor[j]:=aux;
  j:=j+1;
  aux:='';
  end
  else
  begin
  aux:=aux+li[l];
  if (l=length(li)) then
  valor[j]:=aux;
  end;

  end;
  {*** *checa tipo de dato****}
  case tipo of
  0:begin
     val(FormaCapturaRapida.TablaFacturaE.FieldByName(valor[3]).AsString,nume,cod);
     if cod=0 then
     begin
     if palabras[4]='' then palabras[4]:='0';
     Str(FormaCapturaRapida.TablaFacturaE.FieldByName(valor[3]).AsFloat:15:StrToInt(palabras[4]),valor[3]);
     Printer.Canvas.TextOut(StrToInt(valor[1])*25,50*StrToInt(valor[2])+y*50,valor[3]);

     end
     else
     Printer.Canvas.TextOut(StrToInt(valor[1])*25,50*StrToInt(valor[2])+y*50,FormaCapturaRapida.TablaFacturaE.FieldByName(valor[3]).AsString);

    end;
  1: begin
      val(FormaCapturaRapida.TablaDeta.FieldByName(valor[3]).AsString,nume,cod);
     if cod=0 then
     begin
     if palabras[4]='' then palabras[4]:='0';
     Str(FormaCapturaRapida.TablaDeta.FieldByName(valor[3]).AsFloat:15:StrToInt(palabras[4]),valor[3]);
     Printer.Canvas.TextOut(StrToInt(valor[1])*25,50*StrToInt(valor[2])+y*50,valor[3]);
     end
     else
      Printer.Canvas.TextOut(StrToInt(valor[1])*25,50*(StrToInt(valor[2])+y),FormaCapturaRapida.TablaDeta.FieldByName(valor[3]).AsString);
     end;
  end;



  {*termina checkeo de dato****}



{  if tipo=0 then
  Printer.Canvas.TextOut(StrToInt(valor[1])*25,50*StrToInt(valor[2])+y*50,FormaCapturaRapida.TablaFacturaE.FieldByName(valor[3]).AsString);
  if tipo=1 then
  Printer.Canvas.TextOut(StrToInt(valor[1])*25,50*(StrToInt(valor[2])+y),FormaCapturaRapida.TablaDeta.FieldByName(valor[3]).AsString);}

end;

3:begin
  if palabras[2]='rojo' then
  Printer.Canvas.Font.Color:=clRed;

  if palabras[2]='azul' then
  Printer.Canvas.Font.Color:=clBlue;

  if palabras[2]='verde' then
  Printer.Canvas.Font.Color:=clGreen;

  if palabras[2]='amarillo' then
  Printer.Canvas.Font.Color:=clYellow;

  if palabras[2]='negro' then
  Printer.Canvas.Font.Color:=clBlack;
  end;

4:begin

  Printer.Canvas.TextOut(25*StrToInt(palabras[2]),50*StrToInt(palabras[3]),traduce(FormaCapturaRapida.TablaFacturaE.FieldByName('IMTOD_F').AsFloat));
  end;

5:begin
  Printer.Canvas.Rectangle(StrToInt(palabras[2]),StrToInt(palabras[3]),StrToInt(palabras[4]),StrToInt(palabras[5]));
  end;

6:begin
  Printer.Canvas.Font.Size:=StrToInt(palabras[2]);
  end;


7:begin
  Printer.Canvas.Font.Name:=Palabras[2];
  end;

8:begin
  if (palabras[1]='logo') then
  dibujabitmap(palabras[2]);

  end;
end;



{if (li[1]='@')or(li[1]='t') then
begin
j:=1;
for l:=2 to length(li) do
begin
if (li[l]=',') then
begin
valor[j]:=aux;
j:=j+1;
aux:='';
end
else
begin
aux:=aux+li[l];
if (l=length(li)) then
valor[j]:=aux;
end;
end;

if li[1]='t' then
begin
Printer.Canvas.Font.Size:=StrToInt(valor[2]);
end;

if li[1]='@' then
if tipo=0 then
Printer.Canvas.TextOut(StrToInt(valor[1])*25,50*StrToInt(valor[2])+y*50,FormaCapturaRapida.TablaFacturaE.FieldByName(valor[3]).AsString);
if tipo=1 then
Printer.Canvas.TextOut(StrToInt(valor[1])*25,50*(StrToInt(valor[2])+y*50),FormaCapturaRapida.TablaDeta.FieldByName(valor[3]).AsString);
end;
 }



end;

procedure imprimedetalle;
var arch2:TextFile;
lin:string[100];
tipo,y:integer;
begin
FormaCapturaRapida.TablaDeta.First;
y:=0;
while not FormaCapturaRapida.TablaDeta.Eof do
begin

AssignFile(arch2,leeruta+'\consulta\detatmp.tmp');
reset(arch2);

tipo:=1;
while not Eof(arch2) do
begin
readln(arch2,lin);
imprimelinea(lin,1,y,1);
end;

Closefile(arch2);
y:=y+1;
FormaCapturaRapida.TablaDeta.Next;

end;
end;

procedure imprimeformato;
var
arch,arch2:TextFile;
lin:string[100];
l:string[4];
tipo,y:integer;
palabra:word;
begin
With FormaCapturaRapida do
begin
AssignFile(arch,leeruta+'\consulta\factura.fmt');
reset(arch);
Printer.BeginDoc;


while not Eof(arch) do
begin
readln(arch,lin);
{MuestraMensaje('lineaimprimir     '+lin);}
if lin[1]='&' then
begin
AssignFile(arch2,leeruta+'\consulta\detatmp.tmp');
ReWrite(arch2);
repeat
readln(arch,lin);
if lin[1]<>'&' then
Writeln(arch2,lin);
until lin[1]='&';
CloseFile(arch2);

imprimedetalle;
end
else
begin

l:=lin;

if l[1]='@' then palabra:=1;
{if l[1]='&' then palabra:=2;}
if l='colo' then palabra:=3;
if l='trad' then palabra:=4;
if l='cuad' then palabra:=5;
if l='tama' then palabra:=6;
if l='tipo' then palabra:=7;
if l='logo' then palabra:=8;
imprimelinea(lin,0,0,palabra);

end;

end;
Printer.EndDoc;
closefile(arch);
end;
end;

{****terminan pocedimientos para formatos***************}
function borratodaslascuentas:boolean;
var
borrarcuenta:Boolean;
cuenta:integer;
begin
with FormaCapturaRapida do
begin
 TablaCuentasxCobrar.SetRange([EditCLDOC_F.Text],[EditCLDOC_F.Text]);
 TablaCuentasxCobrar.First;
 borrarcuenta:=False;
 cuenta:=0;
{ muestraMensaje(TablaCuentasxCobrar.FieldByName('NUFAC_CC').AsString);}
 while not TablaCuentasxCobrar.Eof do
 begin
 if (TablaCuentasxCobrar.FieldByName('STATU_CC').AsString='F')and (TablaCuentasxCobrar.FieldByName('IMCUE_CC').AsFloat= TablaCuentasxCobrar.FieldByName('SALDO_CC').AsFloat) then
 borrarcuenta:=True;
 TablaCuentasxCobrar.Next;
 cuenta:=cuenta+1;
 end;


 if borrarcuenta then
 begin
  TablaCuentasxCobrar.First;
  while not TablaCuentasxCobrar.Eof do
  begin
  TablaCuentasxCobrar.Delete;
  end;
 borratodaslascuentas:=True;
 end
 else
 begin
{ MuestraMensaje('La Cuenta por Cobrar no Puede ser Eliminada Poque tiene Movimientos');}
  borratodaslascuentas:=False;
 end;
 if cuenta=0 then
 borratodaslascuentas:=True;

 TablaCuentasxCobrar.CancelRange;
end;
end;

procedure actualizalacuenta;
var
borrarcuenta:Boolean;
begin
with FormaCapturaRapida do
begin
 TablaCuentasxCobrar.SetRange([EditCLDOC_F.Text],[EditCLDOC_F.Text]);
 TablaCuentasxCobrar.First;
 borrarcuenta:=False;
{ muestraMensaje(TablaCuentasxCobrar.FieldByName('NUFAC_CC').AsString);}
 while not TablaCuentasxCobrar.Eof do
 begin

 if (TablaCuentasxCobrar.FieldByName('STATU_CC').AsString='F')and (TablaCuentasxCobrar.FieldByName('IMCUE_CC').AsFloat= TablaCuentasxCobrar.FieldByName('SALDO_CC').AsFloat) then
 borrarcuenta:=True;
 TablaCuentasxCobrar.Next;
 end;


 if borrarcuenta then
 begin
  TablaCuentasxCobrar.First;
  while not TablaCuentasxCobrar.Eof do
  begin
  TablaCuentasxCobrar.Delete;
  end;
 end
 else
 MuestraMensaje('La Cuenta por Cobrar no Puede ser Eliminada Poque tiene Movimientos');


 TablaCuentasxCobrar.CancelRange;
end;

end;


procedure BorraDatosMovimientos(tipo:Char);
var
borrarcuenta:boolean;
begin
with FormaCapturaRapida do
begin


 TablamovimientosInventario.First;
if (tipo='F')or(tipo='R')then
 while not TablamovimientosInventario.Eof do
 begin
 if (TablamovimientosInventario.FieldByName('BANAF_MI').AsString='F') and (TablamovimientosInventario.FieldByName('REFMO_MI').AsString=EditCLDOC_F.Text) then
 begin
 TablamovimientosInventario.Delete;
{ MuestraMensaje('lo encontre M I');}
 end
 else
 TablamovimientosInventario.Next;

 end;

end;
end;

procedure borradatosanteriores(tipo:Char);
var
borrarcuenta:boolean;
begin
with FormaCapturaRapida do
begin

{***********************}
if BotonCambios.Tag=1 then
begin


end;

 if (tipo='F')or(tipo='R') then
 begin
{ borratodaslascuentas;}
 TablaFacturaD.First;
 TablaFacturaD.SetRange([EditCLDOC_F.Text],[EditCLDOC_F.Text]);
 while not TablaFacturaD.Eof do
 begin
 TablaFacturaD.Delete;
 end;
 end;
{********************************}
 if tipo<>'X' then
 begin

 TablaFacturaD.First;
 while not TablaFacturaD.Eof do
 begin
 if TablaFacturaD.FieldByName('CLDOC_FD').AsInteger=StrToInt(EditCLDOC_F.Text) then
 begin
 TablaFacturaD.Delete;
 end
 else
 TablaFacturaD.Next;
 end;

 end;

 end;
end;


procedure generadocumento(tipo:char);
var
arch:File of registrodeta;
arch2:File of registroencab;
datos:registrodeta;
encab:registroencab;
k:longint;
TablaAnterior:string[15];
begin
With FormaCapturaRapida do
begin
TablaAnterior:=TablaFacturaD.TableName;
{********cambia base****}

if tipo='F' then
begin
Base.Text:='Factura';
TablaFacturaE.Close;
TablaFacturaE.TableName:='Facturae.dbf';
TablaFacturaE.Open;
TablaFacturaD.Close;
TablaFacturaD.TableName:='FacturaD.dbf';
TablaFacturaD.Open;
formatonum:=14;
end;

if tipo='R' then
begin
Base.Text:='Remision';
TablaFacturaE.Close;
TablaFacturaE.TableName:='Remision.dbf';
TablaFacturaE.Open;
TablaFacturaD.Close;
TablaFacturaD.TableName:='RemisioD.dbf';
TablaFacturaD.Open;
formatonum:=15;
end;

if tipo='P' then
begin
Base.Text:='Pedido';
TablaFacturaE.Close;
TablaFacturaE.TableName:='Pedido.dbf';
TablaFacturaE.Open;
TablaFacturaD.Close;
TablaFacturaD.TableName:='PedidoD.dbf';
TablaFacturaD.Open;
formatonum:=16;
end;

{***********************}
if tipo='D' then
begin
Base.Text:='Devolución';
TablaFacturaE.Close;
TablaFacturaE.TableName:='Devoluc.dbf';
TablaFacturaE.Open;
TablaFacturaD.Close;
TablaFacturaD.TableName:='DevolucD.dbf';
TablaFacturaD.Open;
formatonum:=21;
end;

{***********************}



{****graba encabezado****}
TablaFacturaE.Last;
k:=TablaFacturaE.FieldByName('CLDOC_F').AsInteger+1;
TablaFacturaE.Insert;
AssignFile(arch2,leeruta+'\buferenc.tmp');
ReSet(arch2);
Read(arch2,encab);

EditCLDOC_F.Text:=IntToStr(k);
EditCLCLI_F.Text:=encab.claveCli;
Nombre.Caption:=encab.NombreCli;
Direccion.Caption:=encab.direccionCli;
Direc2.Caption:=encab.direccionCli2;
Poblacion.Caption:=encab.Poblacion;
EditCLVEN_F.Text:=encab.Vendedor;
EditCTOVE_F.Text:=encab.Comision;
EditBCLIM_F.Text:=encab.Mostrador;
{EditCONDI_F.Text:=encab.Condiciones;}
{EditDESTI_F.Text:=encab.Destino;}
EditFEDOC_F.Text:=encab.FechaDoc;
{EditFEENT_F.Text:=encab.FechaEnt;}
{EditFEVEN_F.Text:=encab.FechaVen;}
EditIMIM1_F.Text:=encab.Iva;
{EditDECOT_F.Text:=encab.DescFina;}
EditDESFI_F.Text:=encab.DescComer;
TipoPago.Text:=encab.Pago;
TablaFacturaE.Post;
//TablaFacturaE.ApplyUpdates;
CloseFile(arch2);

{************************}

{****datos detalle****}
borra;

if not RangoDocumentos then
begin

AssignFile(arch,leeruta+'\bufer.tmp');
ReSet(arch);
While not EoF(arch) do
begin
read(arch,datos);
TablaDeta.Insert;
TablaDeta.FieldByName('cantidad').AsFloat:=Datos.cantidad;
TablaDeta.FieldByName('clave').AsString:=Datos.clave;
TablaDeta.FieldByName('producto').AsString:=Datos.descripcion;
TablaDeta.FieldByName('precio').AsFloat:=Datos.precio;
TablaDeta.FieldByName('descuento').AsFloat:=Datos.descuento;
TablaDeta.FieldByName('costo').AsFloat:=Datos.Costo;
TablaDeta.FieldByName('unidad').AsString:=Datos.Unidad;
//TablaDeta.FieldByName('impuesto').AsFloat:=Datos.impuesto;
TablaDeta.Post;
end; //whiole

CloseFile(arch);

end
else
begin
CalculaRangoDocumentos(TablaAnterior,FormaRango.Edit1.Text);

end;
//*******************


BotonGuardar.Enabled:=True;
BotonNuevo.Enabled:=False;
BotonNuevo.tag:=1;

end;
end;

procedure regresabufercambios;
{type
registrodeta=record
cantidad:real;
clave:string[15];
descripcion:string[40];
precio:real;
descuento:real;
costo:real;
unidad:string[3];
end;}
var
arch:File of registrodeta;
datos:registrodeta;
k:integer;
begin
With FormaCapturaRapida do
begin
AssignFile(arch,leeruta+'\bufer.tmp');
Reset(arch);
for k:=0 to Filesize(arch) -1 do
begin
seek(arch,k);
read(arch,datos);

 TablaInventario.First;
 if TablaInventario.FindKey([datos.clave]) then
 begin
 TablaInventario.Edit;

 TablaInventario.FieldByName('EXIST_I').AsFloat:= TablaInventario.FieldByName('EXIST_I').AsFloat -
 datos.cantidad;
 if (TablaInventario.FieldByName('EXIST_I').AsFloat<0)and(ExistenciasNegativos='N') then
 TablaInventario.FieldByName('EXIST_I').AsFloat:=0;
 TablaInventario.Post;
// TablaInventario.ApplyUpdates;

{***********detalle*********}

 TablaFacturaD.Insert;
 TablaFacturaD.FieldByName('CLDOC_FD').AsString:= EditCLDOC_F.Text;
 TablaFacturaD.FieldByName('CLPRO_FD').AsString:= Datos.clave;
 TablaFacturaD.FieldByName('CANTI_FD').AsFloat:=Datos.cantidad;
 TablaFacturaD.FieldByName('DEPRO_FD').AsString:= Datos.descripcion;
 TablaFacturaD.FieldByName('PUNPR_FD').AsFloat:= Datos.precio;
 TablaFacturaD.FieldByName('COPRO_FD').AsFloat:= Datos.Costo;
 TablaFacturaD.FieldByName('PDES1_FD').AsFloat:=Datos.descuento;
 TablaFacturaD.FieldByName('UNIDA_FD').AsString:= Datos.Unidad;
 TablaFacturaD.Post;
// TablaFacturaD.ApplyUpdates;
{***************************}
 end;
{MuestraMensaje(FloatToStr(datos.cantidad)+(datos.clave)+(datos.descripcion)+FloatToStr(datos.precio)+
FloatToStr(datos.descuento));}
end;
CloseFile(arch);
end;
end;


procedure bufercambios(tipo:Char);

{type
registroencab=record
Numero:string[10];
claveCli:string[15];
NombreCli:string[60];
direccionCli:String[60];
direccionCli2:string[60];
Poblacion:string[40];
Vendedor:string[15];
Comision:string[4];
Mostrador:string[10];
Condiciones:string[10];
Destino:string[10];
FechaDoc:string[15];
FechaEnt:string[15];
FechaVen:string[15];
Iva:String[10];
DescFina:string[10];
DescComer:string[10];
Almacen:string[10];
end;

type
registrodeta=record
cantidad:real;
clave:string[15];
descripcion:string[40];
precio:real;
descuento:real;
costo:real;
unidad:string[3];
end; }

var
arch:File of registrodeta;
arch2:File of registroencab;
datos:registrodeta;
encab:registroencab;

k:integer;
begin
With FormaCapturaRapida do
begin
{****graba encabezado****}


AssignFile(arch2,leeruta+'\buferenc.tmp');
ReWrite(arch2);

encab.Numero:=EditCLDOC_F.Text;
encab.claveCli:=EditCLCLI_F.Text;
encab.NombreCli:=Nombre.Caption;
encab.direccionCli:=Direccion.Caption;
encab.direccionCli2:=Direc2.Caption;
encab.Poblacion:=Poblacion.Caption;
encab.Vendedor:=EditCLVEN_F.Text;
encab.Comision:=EditCTOVE_F.Text;
encab.Mostrador:=EditBCLIM_F.Text;
{encab.Condiciones:=EditCONDI_F.Text;
encab.Destino:=EditDESTI_F.Text;}
encab.FechaDoc:=EditFEDOC_F.Text;
{encab.FechaEnt:=EditFEENT_F.Text;}
{encab.FechaVen:=EditFEVEN_F.Text;}
encab.Iva:=EditIMIM1_F.Text;
{encab.DescFina:=EditDECOT_F.Text;}
encab.DescComer:=EditDESFI_F.Text;
encab.Pago:=TipoPago.Text;

write(arch2,encab);
CloseFile(arch2);

{************************}

AssignFile(arch,leeruta+'\bufer.tmp');
ReWrite(arch);

TablaDeta.First;
While not TablaDeta.EoF do
begin
Datos.cantidad:=TablaDeta.FieldByName('cantidad').AsFloat;
Datos.clave:=TablaDeta.FieldByName('clave').AsString;
Datos.descripcion:=TablaDeta.FieldByName('producto').AsString;
Datos.precio:=TablaDeta.FieldByName('precio').AsFloat;
Datos.descuento:=TablaDeta.FieldByName('descuento').AsFloat;
Datos.Costo:=TablaDeta.FieldByName('costo').AsFloat;
Datos.Unidad:=TablaDeta.FieldByName('unidad').AsString;
Write(arch,datos);
TablaDeta.Next;

end;


if tipo='F' then
begin
for k:=0 to Filesize(arch) -1 do
begin
seek(arch,k);
read(arch,datos);
 TablaInventario.First;
 if TablaInventario.FindKey([datos.clave]) then
 begin
 TablaInventario.Edit;
 TablaInventario.FieldByName('EXIST_I').AsFloat:= TablaInventario.FieldByName('EXIST_I').AsFloat +
 datos.cantidad;
 if (TablaInventario.FieldByName('EXIST_I').AsFloat<0)and(ExistenciasNegativos='N') then
 TablaInventario.FieldByName('EXIST_I').AsFloat:=0;

 TablaInventario.Post;
// Tablainventario.ApplyUpdates;
end;
end;

end;
 CloseFile(arch);
end;

end;

procedure ActualizaInventarioCambios;
begin
with FormaCapturaRapida do
begin
TablaInventario.First;
 if (TablaInventario.FindKey([TablaDeta.FieldByName('Clave').AsString]))and(TablaInventario.FieldByName('DSCPR_I').AsString<>'') then
 begin
 TablaInventario.Edit;
 TablaInventario.FieldByName('EXIST_I').AsFloat:= TablaInventario.FieldByName('EXIST_I').AsFloat-
 TablaDeta.FieldByName('cantidad').AsFloat;
 if (TablaInventario.FieldByName('EXIST_I').AsFloat<0)and(ExistenciasNegativos='N') then
 TablaInventario.FieldByName('EXIST_I').AsFloat:=0;

 TablaInventario.Post;
// TablaInventario.ApplyUpdates;
 end;
end;

end;

{function ruta(linea:integer):String;
var
arch:TextFile;
aux:string;
i:integer;

begin

AssignFile(arch,leeempresa());
Reset(arch);
for i:=1 to linea do
Readln(arch,aux);
CloseFile(arch);
ruta:=aux;

end;}


procedure rutas;
var
  j: Integer;
  cerradas:string[2];
begin
cerradas:=ruta(1);
with FormaCapturaRapida do
begin
  for j := 0 to ComponentCount -1 do
    begin
     if Components[j] is TTable  then
       begin
       TTable(Components[j]).DatabaseName:=ruta(8);
       end;
    end;

  TablaDeta.DataBaseName:=leeruta();
  for j := 0 to ComponentCount -1 do
    begin
     if Components[j] is TTable  then
       begin
//       TTable(Components[j]).Open;
AbreTablaTotal(TTable(Components[j]));
    //if UpperCase(Cerradas)='NO' then
//    TTable(Components[j]).CachedUpdates:=True;
       end;
    end;


if Usuario.Caption='0' then
EditCLDOC_F.ReadOnly:=False
else
EditCLDOC_F.ReadOnly:=True;

ExistenciasNegativos:=ruta(41);


if (Base.Text='')or(Base.Text<>'Remisión')or(Base.Text<>'Devolución')or(Base.Text<>'Caja Chica') then
Base.Text:='Remisión';


if Base.Text='Remisión' then
begin
TablaFacturaE.Close;
TablaFacturaE.TableName:='Remision.dbf';
TablaFacturaE.Open;
TablaFacturaD.Close;
TablaFacturaD.TableName:='RemisioD.dbf';
TablaFacturaD.Open;
formatonum:=15;

Pedido1.Enabled:=False;
Remisin1.Enabled:=False;
Factura1.Enabled:=True;
Devolucin1.Enabled:=True;
NotadeCrdito1.Enabled:=False;
BotonPago.Enabled:=False;
BotonObservacion.Enabled:=False;

if Usuario.Caption='0' then
EditCLDOC_F.ReadOnly:=True
else
EditCLDOC_F.ReadOnly:=False;

end;


end;

end;




procedure limpiar;
var
  j: Integer;
begin

with FormaCapturaRapida do
begin
  for j:=0 to ComponentCount -1 do
    begin
     if Components[j] is TDBEdit  then
       TDBEdit(Components[j]).Text :='';
     if Components[j] is TEdit  then
       TEdit(Components[j]).Text :='';
     if Components[j] is TMaskEdit then
       TMaskEdit(Components[j]).Text:='';

  end;
Nombre.Caption:='';
Direccion.Caption:='';
Poblacion.Caption:='';
end;
end;


procedure activa;
var
  j: Integer;
begin
with FormaCapturaRapida do
begin
Caja.Enabled:=True;
{  for j := 0 to ComponentCount -1 do
    begin
     if Components[j] is TDBEdit  then
       TDBEdit(Components[j]).Enabled :=True;
     if Components[j] is TEdit  then
       TEdit(Components[j]).Enabled :=True;
     if Components[j] is TLabel then
       TLabel(Components[j]).Enabled :=True;
     if Components[j] is TMaskEdit then
       TMaskEdit(Components[j]).Enabled:=True;
end;
Nombre.Enabled:=True;
Direccion.Enabled:=True;
Poblacion.Enabled:=True;}
Detalle.ReadOnly:=False;

end;

end;

procedure desactiva;
var
  j: Integer;
begin
with FormaCapturaRapida do
begin
{  for j := 0 to ComponentCount -1 do
    begin
     if Components[j] is TDBEdit then
       TDBEdit(Components[j]).Enabled :=False;
     if Components[j] is TEdit then
       TEdit(Components[j]).Enabled :=False;
     if Components[j] is TLabel then
       TLabel(Components[j]).Enabled :=False;
     if Components[j] is TMaskEdit then
       TMaskEdit(Components[j]).Enabled:=False;
end;
Nombre.Enabled:=False;
Direccion.Enabled:=False;
Poblacion.Enabled:=False;}
Caja.Enabled:=False;
Detalle.ReadOnly:=True;
end;
end;


procedure cursor1;
begin
With FormaCapturaRapida do
begin

if indices > 17 then indices:=1;
if indices < 1 then indices:=1;
case indices of
1:EditCLDOC_F.SetFocus;
2:EditCLCLI_F.SetFocus;
3:EditCLVEN_F.SetFocus;
4:EditCTOVE_F.SetFocus;
5:EditBCLIM_F.SetFocus;
6:EditFEDOC_F.SetFocus;
7:EditIMIM1_F.SetFocus;
8:EditDESFI_F.SetFocus;

{3:EditCLPED_F.SetFocus;
4:EditREMIS_F.SetFocus;
5:EditDIVIS_F.SetFocus;


 8:EditDESTI_F.SetFocus;
9:EditCONDI_F.SetFocus;


12:EditFEENT_F.SetFocus;
13:EditFEVEN_F.SetFocus;


16:EditDECOT_F.SetFocus;
17:EditNALMA_F.SetFocus;}
end;
end;
end;

{procedure checaexistencias;

begin
with FormaCapturaRapida do
begin
cantidad:=TablaInventario.FieldByName('Exist_I').AsFloat-TablaDeta.FieldByName('Cantidad').AsFloat;

if (cantidad<0) and (UpperCase(TablaInventario.FieldByName('LIPRO_I').AsString)<>'SERVI')and (ruta(21)='N') then
begin
MuestraMensaje('Las Compras son Superiores a las Existencias');
if (Base.Text='Factura')or(Base.Text='Remisión') then
Detalle.SelectedIndex:=0;

end;

end;
end;}

procedure checaexistencias;
var
solicitado,existente:real;
begin
with FormaCapturaRapida do
begin
//cantidad:=TablaInventario.FieldByName('Exist_I').AsFloat-TablaDeta.FieldByName('Cantidad').AsFloat;
solicitado:=(TablaDeta.FieldByName('Cantidad').AsFloat+CantidadApartada(TablaDeta.FieldByName('Clave').AsString,Detalle.DataSource.DataSet.RecNo));
existente:=TablaInventario.FieldByName('Exist_I').AsFloat;
cantidad:=existente-solicitado;

//MuestraMensaje(floattostr(cantidad));
if (cantidad<0) and (UpperCase(TablaInventario.FieldByName('LIPRO_I').AsString)<>'SERVI')and (ruta(21)='N') then
begin
MuestraMensaje('Las Compras son Superiores a las Existencias '+TablaInventario.FieldByName('Exist_I').AsString+' Solicitado '+FloatToStr(Solicitado));
if (Base.Text='Factura')or(Base.Text='Remisión') then
Detalle.SelectedIndex:=0;

end;

end;
end;


procedure actualizacliente;
begin
with FormaCapturaRapida do
begin
TablaCliente.First;
if TablaCliente.FindKey([cliente]) then
begin
TablaCliente.Edit;
suma:=suma+(suma*StrTofloat(EditIMIM1_F.Text)/100);
TablaCliente.FieldByName('FULCO_C').AsDateTime:=StrToDatetime(EditFEDOC_F.Text);
TablaCliente.FieldByName('SALDO_C').AsFloat:=TablaCliente.FieldByName('SALDO_C').AsFloat+suma-saldoanterior;
TablaCliente.FieldByName('COMPR_C').Asfloat:=TablaCliente.FieldByName('COMPR_C').AsFloat+suma-saldoanterior;
TablaCliente.Post;
//TablaCliente.ApplyUpdates;
end;
end;
end;

procedure configuracion;
var
arch:Textfile;
cadena:string;
begin
with FormaCapturaRapida do
begin
AssignFile(arch,leeempresa());
Reset(arch);
readln(arch,cadena);
readln(arch,cadena);
readln(arch,cadena);
readln(arch,cadena);
readln(arch,cadena);
iva:=StrTofloat(cadena);
readln(arch,cadena);
//desfin:=StrTofloat(cadena);
EditIMIM1_F.Text:=FloatToStr(iva);
EditDESFI_F.Text:=FloatToStr(desfin);
closefile(arch);

end;
end;

procedure pegafecha;
begin
with FormaCapturaRapida do
begin


end;

end;

{procedure sumatotal;
begin
with FormaCapturaRapida do
begin
   TablaDeta.First;
   suma:=0;
   costo:=0;
   desfin1:=0;
   if EditDESFI_F.Text='' then
   EditDESFI_F.Text:='0';
   while not TablaDeta.Eof do
   begin
   TablaDeta.Edit;
   TablaDeta.FieldByName('Importe').AsFloat:=TablaDeta.FieldByName('Cantidad').AsFloat*TablaDeta.FieldByName('Precio').AsFloat;
   TablaDeta.FieldByName('Importe').AsFloat:=TablaDeta.FieldByName('Importe').AsFloat-(TablaDeta.FieldByName('Importe').AsFloat*TablaDeta.FieldByName('Descuento').AsFloat/100);
   TablaDeta.Post;
   suma:=suma+TablaDeta.FieldByName('Importe').AsFloat;
   desfin1:=suma*(StrToFloat(EditDESFI_F.Text)/100);
   costo:=costo+TablaDeta.FieldByName('Costo').AsFloat;
   TablaDeta.Next;
   end;
   desfin1:=StrToFloat(redondear(desfin1));
   suma:=StrToFloat(redondear(suma));
   SumarTotal.Caption:=convierte('###,###,##0.00',redondear(suma),'$');

   if EditIMIM1_F.Text='' then iva1:=0
   else
   iva1:=StrToCurr(redondear(((suma-StrToCurr(redondear(desfin1)))*(StrToCurr(EditIMIM1_F.Text)/100))));
   ImpuestoValor.Caption:=convierte('###,###,##0.00',CurrToStr(iva1),'$');
   total1:=StrToCurr(redondear(suma))-StrToCurr(redondear(desfin1))+StrToCurr(redondear(iva1));
   TotalFact.Caption:=convierte('###,###,##0.00',redondear(total1),'$');
   end;

end;}



{procedure sumatotal;
var
cuenta:integer;
DCom:real;
Tabla:TTable;
begin
with FormaCapturaRapida do
begin
//   Tabladeta.Refresh;

   TablaDeta.First;
   suma:=0;
   ivatotal:=0;
   costo:=0;
   desfin1:=0;
   if EditDESFI_F.Text='' then
   EditDESFI_F.Text:='0';
   cuenta:=1;
   while not TablaDeta.Eof do
   begin
   TablaDeta.Edit;
   TablaDeta.FieldByName('IMPORTE').AsFloat:=TablaDeta.FieldByName('CANTIDAD').AsFloat*TablaDeta.FieldByName('PRECIO').AsFloat-
(TablaDeta.FieldByName('CANTIDAD').AsFloat*TablaDeta.FieldByName('PRECIO').AsFloat*TablaDeta.FieldByName('DESCUENTO').AsFloat/100);
TablaDeta.Post;

   suma:=suma+TablaDeta.FieldByName('Importe').AsFloat;

    if desglosado then
   begin
   ivatotal:=ivatotal+TablaDeta.FieldByName('Importe').AsFloat-(TablaDeta.FieldByName('Importe').AsFloat/(1+TablaDeta.FieldByName('Impuesto').AsFloat/100));
   end
   else
   ivatotal:=ivatotal+(TablaDeta.FieldByName('Importe').AsFloat*TablaDeta.FieldByName('Impuesto').AsFloat/100);

   desfin1:=suma*(StrToFloat(EditDESFI_F.Text)/100);
   costo:=costo+TablaDeta.FieldByName('Costo').AsFloat;
   //***guarda para comparar
   //Apartados[cuenta,1]:=TablaDeta.FieldByName('CLAVE').AsString;
  // Apartados[cuenta,2]:=TablaDeta.FieldByName('CANTIDAD').AsString;

   cuenta:=cuenta+1;
   TablaDeta.Next;
   end;

  if desglosado then
   begin
   suma:=suma-ivatotal;
   end;


   //**ojo EditDESFI_F tiene el descuento comercial
//   Dcom:=0;
   //suma:=suma*(StrToFloat(EditDESFI_F.Text)/100);
   suma:=StrToFloat(redondear(suma));
   //calcula desc. com
   if (EditDESFI_F.Text='') then EditDESFI_F.Text:='0';
   DCom:=suma*(StrToFloat(EditDESFI_F.Text)/100);
   DCom:=StrToFloat(redondear(DCom));

   suma:=suma-DCom;
   suma:=StrToFloat(redondear(suma));
   //calcula desc Fin
//   Dfin:=0;
//   if EditDECOT_F.Text='' then EditDECOT_F.Text:='0';
//   DFin:=suma*(StrToFloat(EditDECOT_F.Text)/100);
//   DFin:=StrToFloat(redondear(DFin));

//   suma:=suma-DFin;
  // desfin1:=StrToFloat(redondear(desfin1));
   suma:=StrToFloat(redondear(suma));
//   SumarTotal.Caption:=convierte('###,###,##0.00',redondear(suma),'$');

   if (EditIMIM1_F.Text='')or(EditIMIM1_F.Text='0') then
   begin
    iva1:=StrToCurr(redondear(ivatotal));
   end
   else
   iva1:=StrToCurr(redondear(suma*(StrToCurr(EditIMIM1_F.Text)/100)));

   ImpuestoValor.Caption:=convierte('###,###,##0.00',CurrToStr(iva1),'$');
//   total1:=StrToCurr(redondear(suma))-StrToCurr(redondear(desfin1))+StrToCurr(redondear(iva1));
   total1:=StrToCurr(redondear(suma))+StrToCurr(redondear(iva1));

   TotalFact.Caption:=convierte('###,###,##0.00',redondear(total1),'$');

//   suma:=suma;
   suma:=StrToFloat(redondear(suma));

   SumarTotal.Caption:=convierte('###,###,##0.00',redondear(suma),'$');


  ActualizaFacturaImporte(total1,iva1,suma);


   end;

end;}


{procedure sumatotal;
var
cuenta:integer;
DCom:real;
Tabla:TTable;
begin
with FormaCapturaRapida do
begin
try
//   Tabladeta.Refresh;

Tabla:=TTable.Create(Application);
Tabla.TableName:=TablaDeta.TableName;
Tabla.DatabaseName:=TablaDeta.DatabaseName;
Tabla.Open;

   Tabla.First;
   suma:=0;
   ivatotal:=0;
   costo:=0;
   desfin1:=0;
   if EditDESFI_F.Text='' then
   EditDESFI_F.Text:='0';
   cuenta:=1;
   while not Tabla.Eof do
   begin
   Tabla.Edit;
   Tabla.FieldByName('IMPORTE').AsFloat:=Tabla.FieldByName('CANTIDAD').AsFloat*Tabla.FieldByName('PRECIO').AsFloat-
(Tabla.FieldByName('CANTIDAD').AsFloat*Tabla.FieldByName('PRECIO').AsFloat*Tabla.FieldByName('DESCUENTO').AsFloat/100);
Tabla.Post;

   suma:=suma+Tabla.FieldByName('Importe').AsFloat;

    if desglosado then
   begin
   ivatotal:=ivatotal+Tabla.FieldByName('Importe').AsFloat-(Tabla.FieldByName('Importe').AsFloat/(1+Tabla.FieldByName('Impuesto').AsFloat/100));
   end
   else
   ivatotal:=ivatotal+(Tabla.FieldByName('Importe').AsFloat*Tabla.FieldByName('Impuesto').AsFloat/100);

   desfin1:=suma*(StrToFloat(EditDESFI_F.Text)/100);
   costo:=costo+Tabla.FieldByName('Costo').AsFloat;
   //***guarda para comparar
   //Apartados[cuenta,1]:=TablaDeta.FieldByName('CLAVE').AsString;
  // Apartados[cuenta,2]:=TablaDeta.FieldByName('CANTIDAD').AsString;

   cuenta:=cuenta+1;
   Tabla.Next;
   end;

  if desglosado then
   begin
   suma:=suma-ivatotal;
   end;


   //**ojo EditDESFI_F tiene el descuento comercial
//   Dcom:=0;
   //suma:=suma*(StrToFloat(EditDESFI_F.Text)/100);
   suma:=StrToFloat(redondear(suma));
   //calcula desc. com
   if (EditDESFI_F.Text='') then EditDESFI_F.Text:='0';
   DCom:=suma*(StrToFloat(EditDESFI_F.Text)/100);
   DCom:=StrToFloat(redondear(DCom));

   suma:=suma-DCom;
   suma:=StrToFloat(redondear(suma));
   //calcula desc Fin
//   Dfin:=0;
//   if EditDECOT_F.Text='' then EditDECOT_F.Text:='0';
//   DFin:=suma*(StrToFloat(EditDECOT_F.Text)/100);
//   DFin:=StrToFloat(redondear(DFin));

//   suma:=suma-DFin;
  // desfin1:=StrToFloat(redondear(desfin1));
   suma:=StrToFloat(redondear(suma));
//   SumarTotal.Caption:=convierte('###,###,##0.00',redondear(suma),'$');

   if (EditIMIM1_F.Text='')or(EditIMIM1_F.Text='0') then
   begin
    iva1:=StrToCurr(redondear(ivatotal));
   end
   else
   iva1:=StrToCurr(redondear(suma*(StrToCurr(EditIMIM1_F.Text)/100)));

   ImpuestoValor.Caption:=convierte('###,###,##0.00',CurrToStr(iva1),'$');
//   total1:=StrToCurr(redondear(suma))-StrToCurr(redondear(desfin1))+StrToCurr(redondear(iva1));
   total1:=StrToCurr(redondear(suma))+StrToCurr(redondear(iva1));

   TotalFact.Caption:=convierte('###,###,##0.00',redondear(total1),'$');

//   suma:=suma;
   suma:=StrToFloat(redondear(suma));

   SumarTotal.Caption:=convierte('###,###,##0.00',redondear(suma),'$');


  ActualizaFacturaImporte(total1,iva1,suma);
except
end;

   end;//width

end; }


procedure sumatotal;
var
cuenta:integer;
DCom:real;
Tabla:TTable;
indi:integer;
begin
with FormaCapturaRapida do
begin
try
//   Tabladeta.Refresh;
ListaCantidad.Clear;
ListaClaves.Clear;


Tabla:=TTable.Create(Application);
Tabla.TableName:=TablaDeta.TableName;
Tabla.DatabaseName:=TablaDeta.DatabaseName;
Tabla.Open;

   Tabla.First;
   suma:=0;
   ivatotal:=0;
   costo:=0;
   desfin1:=0;
   if EditDESFI_F.Text='' then
   EditDESFI_F.Text:='0';
   cuenta:=1;
   while not Tabla.Eof do
   begin
   Tabla.Edit;
   Tabla.FieldByName('IMPORTE').AsFloat:=Tabla.FieldByName('CANTIDAD').AsFloat*Tabla.FieldByName('PRECIO').AsFloat-
(Tabla.FieldByName('CANTIDAD').AsFloat*Tabla.FieldByName('PRECIO').AsFloat*Tabla.FieldByName('DESCUENTO').AsFloat/100);
Tabla.Post;

   suma:=suma+Tabla.FieldByName('Importe').AsFloat;

    if desglosado then
   begin
   ivatotal:=ivatotal+Tabla.FieldByName('Importe').AsFloat-(Tabla.FieldByName('Importe').AsFloat/(1+Tabla.FieldByName('Impuesto').AsFloat/100));
   end
   else
   ivatotal:=ivatotal+(Tabla.FieldByName('Importe').AsFloat*Tabla.FieldByName('Impuesto').AsFloat/100);

   desfin1:=suma*(StrToFloat(EditDESFI_F.Text)/100);
   costo:=costo+Tabla.FieldByName('Costo').AsFloat;
   //***guarda para comparar
   //Apartados[cuenta,1]:=TablaDeta.FieldByName('CLAVE').AsString;
  // Apartados[cuenta,2]:=TablaDeta.FieldByName('CANTIDAD').AsString;

   cuenta:=cuenta+1;


   if ListaClaves.Find(Tabla.FieldByName('CLAVE').AsString,indi) then
   begin

   ListaCantidad.Insert(indi,FloatToStr(StrToFloat(ListaCantidad.Strings[indi])+Tabla.FieldByName('CANTIDAD').AsFloat));
   ListaCantidad.Delete(indi+1);
   end
   else
   begin
   ListaCantidad.Add(Tabla.FieldByName('Cantidad').AsString);
   ListaClaves.Add(Tabla.FieldByName('Clave').AsString);
   end;



   Tabla.Next;
   end;

  if desglosado then
   begin
   suma:=suma-ivatotal;
   end;


   //**ojo EditDESFI_F tiene el descuento comercial
//   Dcom:=0;
   //suma:=suma*(StrToFloat(EditDESFI_F.Text)/100);
   suma:=StrToFloat(redondear(suma));
   //calcula desc. com
   if (EditDESFI_F.Text='') then EditDESFI_F.Text:='0';
   DCom:=suma*(StrToFloat(EditDESFI_F.Text)/100);
   DCom:=StrToFloat(redondear(DCom));

   suma:=suma-DCom;
   suma:=StrToFloat(redondear(suma));
   //calcula desc Fin
//   Dfin:=0;
//   if EditDECOT_F.Text='' then EditDECOT_F.Text:='0';
//   DFin:=suma*(StrToFloat(EditDECOT_F.Text)/100);
//   DFin:=StrToFloat(redondear(DFin));

//   suma:=suma-DFin;
  // desfin1:=StrToFloat(redondear(desfin1));
   suma:=StrToFloat(redondear(suma));
//   SumarTotal.Caption:=convierte('###,###,##0.00',redondear(suma),'$');

   if (EditIMIM1_F.Text='')or(EditIMIM1_F.Text='0') then
   begin
    iva1:=StrToCurr(redondear(ivatotal));
   end
   else
   iva1:=StrToCurr(redondear(suma*(StrToCurr(EditIMIM1_F.Text)/100)));

   ImpuestoValor.Caption:=convierte('###,###,##0.00',CurrToStr(iva1),'$');
//   total1:=StrToCurr(redondear(suma))-StrToCurr(redondear(desfin1))+StrToCurr(redondear(iva1));
   total1:=StrToCurr(redondear(suma))+StrToCurr(redondear(iva1));

   TotalFact.Caption:=convierte('###,###,##0.00',redondear(total1),'$');

//   suma:=suma;
   suma:=StrToFloat(redondear(suma));

   SumarTotal.Caption:=convierte('###,###,##0.00',redondear(suma),'$');


  ActualizaFacturaImporte(total1,iva1,suma);
except
end;

   end;//width

end;


procedure generacuentasxcobrar(tipo:char);
var
saldo:Currency;
cambio:Boolean;
begin

with FormaCapturaRapida do
begin

if tipo='N' then
begin
TablaCuentasxCobrar.Insert;
TablaCuentasxCobrar.FieldByName('CLCLI_CC').AsString:=EditCLCLI_F.Text;
TablaCuentasxCobrar.FieldByName('NOMBR_CC').AsString:=Nombre.Caption;
TablaCuentasxCobrar.FieldByName('STATU_CC').AsString:='F';
TablaCuentasxCobrar.FieldByName('TIMOV_CC').AsInteger:=1;
TablaCuentasxCobrar.FieldByName('CONCE_CC').AsString:='Factura';
TablaCuentasxCobrar.FieldByName('NUFAC_CC').AsString:=EditCLDOC_F.Text;
TablaCuentasxCobrar.FieldByName('OPERA_CC').AsString:='C';
TablaCuentasxCobrar.FieldByName('NUDOC_CC').AsInteger:=StrToInt(EditCLDOC_F.Text);
sumatotal;
TablaCuentasxCobrar.FieldByName('IMCUE_CC').AsFloat:=total1;
TablaCuentasxCobrar.FieldByName('SALDO_CC').AsFloat:=total1;
TablaCuentasxCobrar.FieldByName('CARGO_CC').AsFloat:=total1;
TablaCuentasxCobrar.FieldByName('FEAPL_CC').AsDateTime:=StrToDaTeTime(EditFEDOC_F.Text);
{TablaCuentasxCobrar.FieldByName('FEVEN_CC').AsDateTime:=StrToDateTime(EditFEVEN_F.Text);}
TablaCuentasxCobrar.Post;
//TablaCuentasxCobrar.ApplyUpdates;
end;

if tipo='C' then
begin
{TablaCuentasxCobrar.First;}
TablaCuentasxcobrar.CancelRange;
TablaCuentasxcobrar.SetRange([EditCLDOC_F.Text],[EditCLDOC_F.Text]);
TablaCuentasxcobrar.First;
cambio:=False;

while not TablaCuentasxCobrar.Eof do
begin
if (TablaCuentasxCobrar.FieldByName('STATU_CC').AsString='F') then
begin
TablaCuentasxCobrar.Edit;
TablaCuentasxCobrar.FieldByName('CLCLI_CC').AsString:=EditCLCLI_F.Text;
TablaCuentasxCobrar.FieldByName('NOMBR_CC').AsString:=Nombre.Caption;
TablaCuentasxCobrar.FieldByName('STATU_CC').AsString:='F';
TablaCuentasxCobrar.FieldByName('TIMOV_CC').AsInteger:=1;
TablaCuentasxCobrar.FieldByName('CONCE_CC').AsString:='Factura';
TablaCuentasxCobrar.FieldByName('NUFAC_CC').AsString:=EditCLDOC_F.Text;
TablaCuentasxCobrar.FieldByName('OPERA_CC').AsString:='C';
TablaCuentasxCobrar.FieldByName('NUDOC_CC').AsInteger:=StrToInt(EditCLDOC_F.Text);
sumatotal;
saldo:=TablaCuentasxCobrar.FieldByName('IMCUE_CC').AsFloat-TablaCuentasxCobrar.FieldByName('SALDO_CC').AsFloat;
TablaCuentasxCobrar.FieldByName('IMCUE_CC').AsFloat:=total1;
TablaCuentasxCobrar.FieldByName('CARGO_CC').AsFloat:=total1;
TablaCuentasxCobrar.FieldByName('SALDO_CC').AsFloat:=total1-saldo;
TablaCuentasxCobrar.FieldByName('FEAPL_CC').AsDateTime:=StrToDaTeTime(EditFEDOC_F.Text);
{TablaCuentasxCobrar.FieldByName('FEVEN_CC').AsDateTime:=StrToDateTime(EditFEVEN_F.Text);}
TablaCuentasxCobrar.Post;
//TablaCuentasxCobrar.ApplyUpdates;

cambio:=True;
Break;

end;
 TablaCuentasxCobrar.Next;
end;

if not cambio then
begin
TablaCuentasxCobrar.Insert;
TablaCuentasxCobrar.FieldByName('CLCLI_CC').AsString:=EditCLCLI_F.Text;
TablaCuentasxCobrar.FieldByName('NOMBR_CC').AsString:=Nombre.Caption;
TablaCuentasxCobrar.FieldByName('STATU_CC').AsString:='F';
TablaCuentasxCobrar.FieldByName('TIMOV_CC').AsInteger:=1;
TablaCuentasxCobrar.FieldByName('CONCE_CC').AsString:='Factura';
TablaCuentasxCobrar.FieldByName('NUFAC_CC').AsString:=EditCLDOC_F.Text;
TablaCuentasxCobrar.FieldByName('OPERA_CC').AsString:='C';
TablaCuentasxCobrar.FieldByName('NUDOC_CC').AsInteger:=StrToInt(EditCLDOC_F.Text);
sumatotal;
saldo:=TablaCuentasxCobrar.FieldByName('IMCUE_CC').AsFloat-TablaCuentasxCobrar.FieldByName('SALDO_CC').AsFloat;
TablaCuentasxCobrar.FieldByName('IMCUE_CC').AsFloat:=total1;
TablaCuentasxCobrar.FieldByName('SALDO_CC').AsFloat:=total1-saldo;
TablaCuentasxCobrar.FieldByName('FEAPL_CC').AsDateTime:=StrToDaTeTime(EditFEDOC_F.Text);
{TablaCuentasxCobrar.FieldByName('FEVEN_CC').AsDateTime:=StrToDateTime(EditFEVEN_F.Text);}
TablaCuentasxCobrar.Post;
//TablaCuentasxCobrar.ApplyUpdates;
end;

end;



end;

end;

procedure mueveteclas;
var
i,componente:integer;
begin
with FormaCapturaRapida do
begin

while indice < ComponentCount-1 do
begin

if Components[indice] is TDBEdit then
if TDBEdit(Components[indice]).TabOrder = sig then
begin
MuestraMensaje(IntToStr(TDBEdit(Components[indice]).TabOrder));
TDBEdit(Components[indice]).SetFocus;
MuestraMensaje(IntToStr(indice));
indice:=1000;
end;
indice:=indice+1;
end;

indice:=0;
sig:=sig+1;

{while not (Components[indice] is TDBEdit) do
begin

if indice < ComponentCount-1 then
indice:=indice+1;
if indice=ComponentCount-1 then
indice:=0;
end;

if Components[indice] is TDBEdit then
begin
TDBEdit(Components[indice]).SetFocus;
MuestraMensaje(IntToStr(TDBEdit(Components[indice]).TabOrder));
end;
indice:=indice+1;}
end;


end;

Procedure MovimientosInventario;
begin
with FormaCapturaRapida do
begin

{ TablamovimientosInventario.Last;

 TablamovimientosInventario.Post;
 TablamovimientosInventario.Edit;}

 TablamovimientosInventario.Insert;
 TablamovimientosInventario.FieldByName('CLDOC_MI').AsInteger:= numeromovimiento;
 TablamovimientosInventario.FieldByName('CLPRO_MI').AsString:= TablaDeta.FieldByName('CLAVE').AsString;
 TablamovimientosInventario.FieldByName('DESCR_MI').AsString:= TablaDeta.FieldByName('PRODUCTO').AsString;
 TablamovimientosInventario.FieldByName('TIMOV_MI').AsInteger:= tipomovimiento;
 TablamovimientosInventario.FieldByName('FEDOC_MI').AsString:= EditFEDOC_F.Text;
 TablamovimientosInventario.FieldByName('REFMO_MI').AsString:= EditCLDOC_F.Text;
 TablamovimientosInventario.FieldByName('CLCOP_MI').AsString:= EditCLCLI_F.Text;
 TablamovimientosInventario.FieldByName('CLVEN_MI').AsString:= EditCLVEN_F.Text;
 TablamovimientosInventario.FieldByName('CANTI_MI').AsFloat:= TablaDeta.FieldByName('CANTIDAD').AsFloat;
 TablamovimientosInventario.FieldByName('PUNIT_MI').AsFloat:= TablaDeta.FieldByName('PRECIO').AsFloat;
{ TablamovimientosInventario.FieldByName('NALMA_MI').AsString:=EditNALMA_F.Text;}
 TablamovimientosInventario.FieldByName('BANAF_MI').AsString:='F';

 TablamovimientosInventario.Post;
// TablamovimientosInventario.ApplyUpdates;
 end;

end;

procedure devolucionproductos;
var
monto,cantidad:Real;

begin
With FormaCapturaRapida do
begin
TablaDeta.First;

while not TablaDeta.Eof do
begin
 TablaInventario.First;
 if TablaInventario.FindKey([TablaDeta.FieldByName('clave').AsString]) then
 begin
 TablaInventario.Edit;

 TablaInventario.FieldByName('EXIST_I').AsFloat:= TablaInventario.FieldByName('EXIST_I').AsFloat +
 TablaDeta.FieldByName('cantidad').AsFloat;
 if (TablaInventario.FieldByName('EXIST_I').AsFloat<0)and(ExistenciasNegativos='N') then
 TablaInventario.FieldByName('EXIST_I').AsFloat:=0;

 TablaInventario.FieldByName('VANMO_I').AsFloat:= TablaInventario.FieldByName('VANMO_I').AsFloat -
 TablaDeta.FieldByName('IMPORTE').AsFloat;

 TablaInventario.FieldByName('VANCA_I').AsFloat:= TablaInventario.FieldByName('VANCA_I').AsFloat -
 TablaDeta.FieldByName('CANTIDAD').AsFloat;

 TablaInventario.Post;
// TablaInventario.ApplyUpdates;

 end;
{MuestraMensaje(FloatToStr(datos.cantidad)+(datos.clave)+(datos.descripcion)+FloatToStr(datos.precio)+
FloatToStr(datos.descuento));}
TablaDeta.Next;
end;
movimientosinventario;
end;
end;


procedure fechas(pos:integer;letra:char);
var cad:string[2];
     fecha:String[12];
    num,code:integer;
begin

end;


function revisafactura(cad:string):boolean;
begin
With FormaCapturaRapida do
begin
if EditCLCLI_F.Text='' then
begin
MuestraMensaje('No se puede Guardar la Factura faltan datos del Cliente');
revisafactura:=false;
end
else  revisafactura:=true;
end;
end;

procedure borradatoscliente;
begin

 FormaCapturaRapida.Nombre.Caption:='';
 FormaCapturaRapida.Direccion.Caption:='';
 FormaCapturaRapida.Direc2.Caption:='';
 FormaCapturaRapida.Poblacion.Caption:='';
 FormaCapturaRapida.CodigoPostal.Caption:='';
 FormaCapturaRapida.RFC.Caption:='';

 FormaCapturaRapida.EditFEDOC_F.Text:='';
{ FormaCapturaRapida.EditFEENT_F.Text:='';}
{ FormaCapturaRapida.EditFEVEN_F.Text:='';}

end;


procedure ActualizaInventario;
begin
with FormaCapturaRapida do
begin
TablaInventario.First;
 if (TablaInventario.FindKey([TablaDeta.FieldByName('Clave').AsString]))and(TablaInventario.FieldByName('DSCPR_I').AsString<>'') then
 begin
 TablaInventario.Edit;
 TablaInventario.FieldByName('EXIST_I').AsFloat:= TablaInventario.FieldByName('EXIST_I').AsFloat-
 TablaDeta.FieldByName('cantidad').AsFloat;
 if (TablaInventario.FieldByName('EXIST_I').AsFloat<0)and(ExistenciasNegativos='N') then
 TablaInventario.FieldByName('EXIST_I').AsFloat:=0;

 TablaInventario.FieldByName('VANCA_I').AsFloat:= TablaInventario.FieldByName('VANCA_I').AsFloat+TablaDeta.FieldByName('cantidad').AsFloat;
 TablaInventario.FieldByName('VANMO_I').AsFloat:= TablaInventario.FieldByName('VANMO_I').AsFloat+TablaDeta.FieldByName('cantidad').AsFloat*TablaDeta.FieldByName('precio').AsFloat;
 TablaInventario.Post;
//  TablaInventario.ApplyUpdates;
 end;
end;

end;


procedure LeeDetalle;
begin

with FormaCapturaRapida do

begin

Borra;
TablaFacturaD.SetRange([TablaFacturaE.FieldByName('CLDOC_F').AsString],[TablaFacturaE.FieldByName('CLDOC_F').AsString]);

{TablaFacturaD.First;}
TablaFacturaD.Last;

while not TablaFacturaD.Bof do
begin
TablaDeta.Insert;

TablaDeta.FieldByName('CANTIDAD').AsFloat:=TablaFacturaD.FieldByName('CANTI_FD').AsFloat;
TablaDeta.FieldByName('CLAVE').AsString:=TablaFacturaD.FieldByName('CLPRO_FD').AsString;
TablaDeta.FieldByName('PRODUCTO').AsString:=TablaFacturaD.FieldByName('DEPRO_FD').AsString;
TablaDeta.FieldByName('UNIDAD').AsString:=TablaFacturaD.FieldByName('UNIDA_FD').AsString;
TablaDeta.FieldByName('PRECIO').AsFloat:=TablaFacturaD.FieldByName('PUNPR_FD').AsFloat;
TablaDeta.FieldByName('COSTO').AsFloat:=TablaFacturaD.FieldByName('COPRO_FD').AsFloat;
//*TablaDeta.FieldByName('CANTIDAD').AsFloat;
TablaDeta.FieldByName('DESCUENTO').AsFloat:=TablaFacturaD.FieldByName('PDES1_FD').AsFloat;
TablaDeta.FieldByName('IMPORTE').AsFloat:=TablaDeta.FieldByName('CANTIDAD').AsFloat*TablaDeta.FieldByName('PRECIO').AsFloat-
(TablaDeta.FieldByName('CANTIDAD').AsFloat*TablaDeta.FieldByName('PRECIO').AsFloat*TablaDeta.FieldByName('DESCUENTO').AsFloat/100);
TablaDeta.FieldByName('IMPUESTO').AsFloat:=TablaFacturaD.FieldByName('PIVA1_FD').AsFloat;


TablaDeta.Post;
//TablaDeta.ApplyUpdates;
TablaFacturaD.Prior;
begin

end;


end;

end;
end;


procedure LeeDetalleCierre(inicio,fin,fecha:string);
var
ExistiaFacturaCierre:Boolean;
begin

with FormaCapturaRapida do

begin

Borra;
TablaFacturaD.SetRange([inicio],[fin]);
MuestraMensaje('Ventas del Documento '+inicio+'  al  '+fin);
{TablaFacturaD.First;}
TablaFacturaD.First;
ExistiaFacturaCierre:=False;

while not TablaFacturaD.Eof do
begin
if (TablaFacturaD.FieldByName('TREGI_FD').AsString<>'F') then
begin
if(TablaFacturaD.FieldByName('TREGI_FD').AsString<>'C') then
begin
TablaDeta.Insert;

TablaDeta.FieldByName('CANTIDAD').AsFloat:=TablaFacturaD.FieldByName('CANTI_FD').AsFloat;
TablaDeta.FieldByName('CLAVE').AsString:=TablaFacturaD.FieldByName('CLPRO_FD').AsString;
TablaDeta.FieldByName('PRODUCTO').AsString:=TablaFacturaD.FieldByName('DEPRO_FD').AsString;
TablaDeta.FieldByName('UNIDAD').AsString:=TablaFacturaD.FieldByName('UNIDA_FD').AsString;
TablaDeta.FieldByName('PRECIO').AsFloat:=TablaFacturaD.FieldByName('PUNPR_FD').AsFloat;
TablaDeta.FieldByName('COSTO').AsFloat:=TablaFacturaD.FieldByName('COPRO_FD').AsFloat;
//*TablaDeta.FieldByName('CANTIDAD').AsFloat;
TablaDeta.FieldByName('DESCUENTO').AsFloat:=TablaFacturaD.FieldByName('PDES1_FD').AsFloat;
TablaDeta.FieldByName('IMPORTE').AsFloat:=TablaDeta.FieldByName('CANTIDAD').AsFloat*TablaDeta.FieldByName('PRECIO').AsFloat-
(TablaDeta.FieldByName('CANTIDAD').AsFloat*TablaDeta.FieldByName('PRECIO').AsFloat*TablaDeta.FieldByName('DESCUENTO').AsFloat/100);

TablaDeta.Post;
end;//if cancelado
//TablaDeta.ApplyUpdates;

end
else
begin
ExistiaFacturaCierre:=True;
end;

TablaFacturaD.Next;
end;//while

if ExistiaFacturaCierre then
MuestraMensaje('Existe una Factura de Cierre para esta Fecha...');

end;
end;





function ChecaRepeticion(ulti:LongInt):LongInt;
var
actual,anterior,siguiente,ultimo:longint;
claves,clavesaux:array[1..15] of LongInt;
j,su,k:integer;
begin
With FormaCapturaRapida do
begin
{*************** checa si no se repite ******}
{TablaFacturaE.MoveBy(-7);}
j:=0;
anterior:=ulti;
{MuestraMensaje(InttoStr(ulti));}
while (j<15)and (not TablaFacturaE.Bof) do
begin
TablaFacturaE.Prior;
anterior:=TablaFacturaE.FieldByName('CLDOC_F').AsInteger;
{MuestraMensaje('fin');}
j:=j+1;

if (anterior<ulti)then
break;

end;

{MuestraMensaje('fin');}
TablaFacturaE.MoveBy(j);
ChecaRepeticion:=ulti+j-1;
end;
{su:=0;
ultimo:=claves[1];

for j:=1 to 7 do
begin
su:=su+(claves[j]-ultimo);
if ultimo<claves[j] then
ultimo:=claves[j];
end;

TablaFacturaE.Next;
claves[8]:=TablaFacturaE.FieldByName('CLDOC_F').AsInteger;
ChecaRepeticion:=claves[8]+(7-su);
MuestraMensaje(IntToStr(claves[8]+(7-su)));
end;
}
{****termina ***************}


{if (BotonNuevo.Tag=1)and(TablaFacturaE.RecordCount>1) then
begin

TablaFacturaE.Prior;
anterior:=TablaFacturaE.FieldByName('CLDOC_F').AsInteger;
TablaFacturaE.Next;
actual:=TablaFacturaE.FieldByName('CLDOC_F').AsInteger;

if not TablaFacturaE.Eof then
begin
TablaFacturaE.Next;
siguiente:=TablaFacturaE.FieldByName('CLDOC_F').AsInteger;
TablaFacturaE.Prior;
end;
if actual=anterior then
begin
actual:=actual+1;
if actual=siguiente then
actual:=siguiente+1;
end;

end
else
actual:=TablaFacturaE.FieldByName('CLDOC_F').AsInteger;}
{****************************************}
end;


procedure actualizafactura(tipo:Char);
var
ultimo:LongInt;
begin
With FormaCapturaRapida do
begin
BotonNuevo.Enabled:=True;
BotonGuardar.Enabled:=False;
BotonImprimir.Enabled:=True;

{******guarda encabezado****************}
sumatotal;
ultimo:=TablaFacturaE.FieldByName('CLDOC_F').AsInteger;
if (BotonNuevo.Tag=1) then
begin
ultimo:=ChecaRepeticion(ultimo);
end;
{MuestraMensaje(IntToStr(TablaFacturaE.RecNo));}
TablaFacturaE.Edit;
TablaFacturaE.FieldByName('CLDOC_F').AsInteger:=ultimo;
TablaFacturaE.FieldByName('NOMBR_F').AsString:=Nombre.Caption;
TablaFacturaE.FieldByName('DIREC_F').AsString:=Direccion.Caption;
TablaFacturaE.FieldByName('DIRE2_F').AsString:=Direc2.Caption;
TablaFacturaE.FieldByName('POBLA_F').AsString:=Poblacion.Caption;
TablaFacturaE.FieldByName('RFCXX_F').AsString:=RFC.Caption;
TablaFacturaE.FieldByName('CPXXX_F').AsString:=CodigoPostal.Caption;

TablaFacturaE.FieldByName('FEDOC_F').AsDateTime:=StrToDateTime(EditFEDOC_F.Text);
TablaFacturaE.FieldByName('FEENT_F').AsDateTime:=StrToDateTime(EditFEDOC_F.Text);
TablaFacturaE.FieldByName('FEVEN_F').AsDateTime:=StrToDateTime(EditFEDOC_F.Text);
TablaFacturaE.FieldByName('SUBTO_F').AsFloat:=suma;
TablaFacturaE.FieldByName('DECOT_F').AsFloat:=desfin1;
TablaFacturaE.FieldByName('IMIM2_F').AsFloat:=iva1;
TablaFacturaE.FieldByName('IMTOD_F').AsFloat:=Total1;
TablaFacturaE.FieldByName('COSTO_F').AsFloat:=costo;

TablaFacturaE.FieldByName('HORAX_F').AsString:= TimeToStr(Time);
TablaFacturaE.FieldByName('PAGOX_F').AsString:=TipoPago.Text;
{TablaFacturaE.FieldByName('NOMDI_F').AsString:=EditDIVIS_F.Text;
TablaFacturaE.FieldByName('DIVIS_F').AsString:=EditVALDI_F.Text;
if Tipo='D' then
TablaFacturaE.FieldByName('STATU_F').AsString:='P';}

TablaFacturaE.Post;
//TablaFacturaE.ApplyUpdates;

{*******termina encabezado***********}

TablaDeta.First;
while not TablaDeta.eof do
begin
{MuestraMensaje('guardando deta');}

if (TablaDeta.FieldByName('Cantidad').AsFloat>0)and(TablaDeta.FieldByName('Clave').AsString<>'')and(TablaDeta.FieldByName('Producto').AsString<>'') then
begin

if (tipo='F')or(tipo='R') then
begin
ActualizaInventario;
MovimientosInventario;
end;
TablaFacturaD.Insert;
TablaFacturaD.FieldByName('CLDOC_FD').AsString:= EditCLDOC_F.Text;
TablaFacturaD.FieldByName('CLPRO_FD').AsString:= TablaDeta.FieldByName('Clave').AsString;
TablaFacturaD.FieldByName('CANTI_FD').AsFloat:= TablaDeta.FieldByName('Cantidad').AsFloat;
TablaFacturaD.FieldByName('DEPRO_FD').AsString:= TablaDeta.FieldByName('Producto').AsString;
TablaFacturaD.FieldByName('PUNPR_FD').AsFloat:= TablaDeta.FieldByName('Precio').AsFloat;
TablaFacturaD.FieldByName('COPRO_FD').AsFloat:= TablaDeta.FieldByName('Costo').AsFloat;
TablaFacturaD.FieldByName('PDES1_FD').AsFloat:= TablaDeta.FieldByName('Descuento').AsFloat;
TablaFacturaD.FieldByName('UNIDA_FD').AsString:= TablaDeta.FieldByName('Unidad').AsString;
TablaFacturaD.FieldByName('FEDOC_FD').AsString:= EditFEDOC_F.Text;
TablaFacturaD.FieldByName('PIVA1_FD').AsFloat:= TablaDeta.FieldByName('Impuesto').AsFloat;
TablaFacturaD.FieldByName('IMPOR_FD').AsFloat:= TablaDeta.FieldByName('Importe').AsFloat;
TablaFacturaD.Post;
//TablaFacturaD.ApplyUpdates;

end;
TablaDeta.Next;
end;
{borra;}
end;


end;


procedure guardatodo(tipo:Char);
begin
With FormaCapturaRapida do
begin
cliente:=EditCLCLI_F.Text;
if BotonNuevo.tag=1 then
begin
{MuestraMensaje(IntTostr(numeromovimiento));}
if revisafactura(EditCLCLI_F.Text) then
begin
case tipo of
'Z':begin
generacuentasxcobrar('N');
actualizafactura(tipo);
actualizacliente;
end;

'F':begin
TablaMovimientosInventario.Last;
numeromovimiento:=TablaMovimientosInventario.FieldByName('CLDOC_MI').AsInteger+1;
tipomovimiento:=1;
TablaMovimientosInventario.Insert;
TablaMovimientosInventario.FieldByName('CLDOC_MI').AsInteger:=numeromovimiento;
TablaMovimientosInventario.Post;
//TablaMovimientosInventario.ApplyUpdates;
actualizafactura(tipo);
generacuentasxcobrar('N');
actualizacliente;
end;

'R':begin
TablaMovimientosInventario.Last;
numeromovimiento:=TablaMovimientosInventario.FieldByName('CLDOC_MI').AsInteger+1;
tipomovimiento:=3;
TablaMovimientosInventario.Insert;
TablaMovimientosInventario.FieldByName('CLDOC_MI').AsInteger:=numeromovimiento;
TablaMovimientosInventario.Post;
//TablaMovimientosInventario.ApplyUpdates;
actualizafactura(tipo);
{actualizacliente;}
end;

'C':begin
actualizafactura('C');

end;

'P':begin
actualizafactura(tipo);
end;

'X':begin
actualizafactura(tipo);
end;

'N':begin
actualizafactura(tipo);

end;

'D':begin
TablaMovimientosInventario.Last;
numeromovimiento:=TablaMovimientosInventario.FieldByName('CLDOC_MI').AsInteger+1;
tipomovimiento:=52;
devolucionproductos;
TablaMovimientosInventario.Insert;
TablaMovimientosInventario.FieldByName('CLDOC_MI').AsInteger:=numeromovimiento;
TablaMovimientosInventario.Post;
//TablaMovimientosInventario.ApplyUpdates;
actualizafactura(tipo);


end;



end;{case}


end;
BotonNuevo.Tag:=0;
end;
{*********cambios*******}
if BotonCambios.tag=1 then
begin

case tipo of
'F':begin
borradatosanteriores('F');
TablaMovimientosInventario.Last;
numeromovimiento:=TablaMovimientosInventario.FieldByName('CLDOC_MI').AsInteger+1;
generacuentasxcobrar('C');
actualizafactura(tipo);
actualizacliente;
end;

'R':begin
TablaMovimientosInventario.Last;
numeromovimiento:=TablaMovimientosInventario.FieldByName('CLDOC_MI').AsInteger+1;
actualizafactura(tipo);
end;

'C':begin
    actualizafactura(tipo);
    end;

'P':begin
    actualizafactura(tipo);
    end;
end;
{****case termina cambios*****}



BotonCambios.Tag:=0;
end;



{limpiar;}
desactiva;

end;
end;

procedure ponedatos;
begin

With FormaCapturaRapida do
begin
{if TablaFacturaE.FieldByName('NOMBR_F').AsString<>'' then
 begin}
 Nombre.Caption:=TablaFacturaE.FieldByName('NOMBR_F').AsString;
 TipoPago.Text:=TablaFacturaE.FieldByName('PAGOX_F').AsString;


 Direccion.Caption:=TablaFacturaE.FieldByName('DIREC_F').AsString;
 Direc2.Caption:=TablaFacturaE.FieldByName('DIRE2_F').AsString;
 Poblacion.Caption:=TablaFacturaE.FieldByName('POBLA_F').AsString;
 RFC.Caption:=TablaFacturaE.FieldByName('RFCXX_F').AsString;
 CodigoPostal.Caption:=TablaFacturaE.FieldByName('CPXXX_F').AsString;
 FormaCapturaRapida.EditFEDOC_F.Text:=TablaFacturaE.FieldByName('FEDOC_F').AsString;

 Hora.Caption:=TablaFacturaE.FieldByName('HORAX_F').AsString;

 if TablaFacturaE.FieldByName('STATU_F').AsString='C' then
 Estado.Caption:='Cancelada'
 else
 begin
 if TablaFacturaE.FieldByName('STATU_F').AsString='D' then
 Estado.Caption:='Dev. Total';
 if TablaFacturaE.FieldByName('STATU_F').AsString='P' then
 Estado.Caption:='Dev. Parcial';
 if TablaFacturaE.FieldByName('STATU_F').AsString='' then
 Estado.Caption:='Activa';
 end;

{ if TablaFacturaE.FieldByName('STATU_F').AsString='C' then
 Estado.Caption:='Cancelada'
 else
 Estado.Caption:='Activa';}


LeeDetalle;
sumatotal;



end;
end;

{xxx*********}
procedure posicionafactura(clave:string);
begin
with FormaCapturaRapida do
begin
if FormaCapturaRapida.Tag=0 then
begin
{if FileExists(leetapiz(3)) then
Fondo.Picture.LoadFromFile(leetapiz(3));}
{Fondo.Visible:=True;}
rutas;
desactiva;
Pedido1.Enabled:=False;
Remisin1.Enabled:=False;
//Factura1.Enabled:=False;
BotonCambios.Enabled:=True;
BotonNuevo.Enabled:=true;
BotonGuardar.Enabled:=false;
Guardar1.enabled:=False;
{BotonImprimir.Enabled:=false;}
indices:=1;
decimales:=2;
{ponedatos;}
end;

FormaCapturaRapida.Tag:=1;
TablafacturaE.FindKey([clave]);
end;
ponedatos;
end;

{************}


procedure TFormaCapturaRapida.FormCreate(Sender: TObject);
var
i:integer;
arch:TextFile;
linea:string;
begin

try
Assignfile(arch,leeruta+'\encabeza.cnf');
Reset(arch);
Readln(arch,linea);
CloseFile(arch);
if linea='S' then
begin
SaltarEncabezado:=True;
SaltarEncabezado1.Checked:=True;
end
else
begin
SaltarEncabezado:=False;
SaltarEncabezado1.Checked:=False;
end;
except
end;

  FormatosPais;
  formatonum:=14;
  nombreformato:=leeruta+'\consulta\'+ruta(formatonum);
  ultimovendedor:='';
  orig:='';
  desglosado:=True;
  Digitos:=2;

//  MuestraMensaje(ruta(42));
  Digitos:=StrToInt(ruta(42));
if digitos>0 then
begin
  Digi:='';
for i:=1 to Digitos do
Digi:=Digi+'0';
Digi:='##,##0.'+digi;
//MuestraMensaje(Digi);
end;

Funciones.Caption:='F2 -> Buscar Producto'+char(13)+
                   'F3 -> Repite el último Movimiento'+char(13)+
                   'F4 -> Salta a Cantidad'+char(13)+
                   'F5 -> Ingresar Efectivo'+char(13);
  ListaClaves:=TStringList.Create;
  ListaCantidad:=TStringList.Create;


  end;

procedure TFormaCapturaRapida.EditCLCLI_FExit(Sender: TObject);
var
trunca:string[60];
begin

quitacolor(EditCLCLI_F.ComponentIndex);
TablaCliente.First;
if Tablacliente.FindKey([EditCLCLI_F.Text]) then
begin
Nombre.Caption:=TablaCliente.FieldByName('NOMBR_C').AsString;
Direccion.Caption:=TablaCliente.FieldByName('DIREC_C').AsString;
Direc2.Caption:=TablaCliente.FieldByName('DIRE2_C').AsString;
Poblacion.Caption:=TablaCliente.FieldByName('POBLA_C').AsString;
RFC.Caption:=TablaCliente.FieldByName('RFCXX_C').AsString;
CodigoPostal.Caption:=TablaCliente.FieldByname('CPXXX_C').AsString;
//EditCONDI_F.Text:=TablaCliente.FieldByname('DCRED_C').AsString;

PrecioNumero:=Tablacliente.FieldByName('PREPR_C').AsInteger;
if PrecioNumero<1 then
Precionumero:=1;

end;
{end;}

end;

procedure TFormaCapturaRapida.BotonNuevoClick(Sender: TObject);
var
Ultimo:Integer;
begin

if caso(StrToInt(usuario.Caption),20) then
begin

PrecioNumero:=1;
Hora.Caption:=TimeToStr(Time);
{*********}
{TablaFacturaE.LockTable(ltReadLock);
TablaFacturaE.LockTable(ltWriteLock);}
TablaFacturaE.Last;
{TablaUltimo.LockTable(ltReadLock);}

Ultimo:=TablaFacturaE.FieldByName('CLDOC_F').AsInteger;
{TablaFacturaE.UnLockTable(ltWriteLock);}
{TablaUltimo.UnLockTable(ltReadLock);}
TablaFacturae.Insert;
EditBCLIM_F.Text:=CajaLocal;
SuCambio.Caption:='';
{***********************}

if TablaFacturaE.State=dsInsert then
begin

TablaFacturae.FieldByName('CLDOC_F').AsInteger:=Ultimo+1;
TablaFacturae.FieldByName('CLVEN_F').AsString:=ultimovendedor;
TablaFacturae.Post;

//TablaFacturaE.ApplyUpdates;
{TablaFacturaE.UnLockTable(ltReadLock);}
{TablaUltimo.UnLockTable(ltReadLock);}
saldoanterior:=0;
borradatoscliente;
borra;
{BotonImprimir.Enabled:=false;}
BotonNuevo.Tag:=1;
BotonCambios.Tag:=0;
Caja.Enabled:=True;
local:=True;
TablaFacturae.Edit;
EditCLCLI_F.Visible:=True;
activa;
EditFEDOC_F.Text:=DateToStr(Date);
configuracion;
indice:=0;
sig:=1;
{****totales****}
SumarTotal.Caption:=convierte('###,###,##0.00','0','$');
ImpuestoValor.Caption:=convierte('###,###,##0.00','0','$');
TotalFact.Caption:=convierte('###,###,##0.00','0','$');
{**************}
activabotones(False,False,True,False,False,False,True);

{indices:=1;}
EditCLDOC_F.SetFocus;
EditCLCLI_F.Text:='1';
if SaltarEncabezado then
begin
Tabladeta.Edit;
EditCantidad.SetFocus;
EditCantidad.Text:='1';
EditClave.SetFocus;
end;
end
else
MuestraMensaje('No Pueden Guardarse los Datos ha Ocurrido un Error');
end;
Navegador.Enabled:=False;
end;


procedure TFormaCapturaRapida.BotonGuardarClick(Sender: TObject);
var
ulti:string[20];
begin

Hora.Caption:=TimeToStr(Time);

if ((BotonNuevo.Tag=1)or(BotonCambios.Tag=1)) and (revisafactura(EditCLCLI_F.Text)) then
begin

if BotonCambios.Tag=1 then
BorraDatosMovimientos('F');

if EditCLDOC_F.Text<>'' then
begin
if (Base.Text='Factura')and (Base.Tag=1) then
guardatodo('Z');
if Base.Text='Factura' then
guardatodo('F');
if Base.Text='Remisión' then
guardatodo('R');
if Base.Text='Pedido' then
guardatodo('P');
if Base.Text='Cotización' then
guardatodo('C');
if Base.Text='Devolución' then
guardatodo('D');
if Base.Text='Nota de Crédito' then
guardatodo('N');
if Base.Text='Caja Chica' then
guardatodo('C');


{configuracion;}

if ruta(1)='NO' then
begin
ulti:=EditCLDOC_F.Text;
//MuestraMensaje('guarda permanete');
GuardaPendientes(TablaMovimientosInventario);
GuardaPendientes(TablaFacturaE);
GuardaPendientes(TablaFacturaD);
GuardaPendientes(TablaInventario);

GuardaPendientes(TablaCuentasxCobrar);
GuardaPendientes(TablaCliente);
if TablaFacturaE.FindKey([ulti]) then
ponedatos;
end;
ultimovendedor:=EditCLVEN_F.Text;
Navegador.Enabled:=True;
Base.Tag:=0;
activabotones(True,True,False,True,True,True,False);
BotonPago.Enabled:=True;
//Base.SetFocus;
//Detalle.SelectedIndex:=2;
//Detalle.SelectedIndex:=0;

end
else
begin
MuestraMensaje('Falta el Numero de Documento');
EditCLDOC_F.SetFocus;
end;
end
else
MuestraMensaje('No Pueden Guardarse los Datos ha Ocurrido un Error');


end;


procedure TFormaCapturaRapida.NavegadorClick(Sender: TObject; Button: TNavigateBtn);
begin
ponedatos;
end;

procedure TFormaCapturaRapida.DetalleColEnter(Sender: TObject);
var valor:Real;
    code:integer;
    cadena:string;
begin

if (Detalle.Enabled=True)and((BotonCambios.Tag=1)or(BotonNuevo.Tag=1))  then
begin
case Detalle.SelectedIndex of

0:begin
//   Facturable:=False;
   sumatotal;
 {  TablaDeta.First;
   suma:=0;
   costo:=0;
   while not TablaDeta.Eof do
   begin
   suma:=suma+TablaDeta.FieldByName('Importe').AsFloat;
   costo:=costo+TablaDeta.FieldByName('Costo').AsFloat;
   TablaDeta.Next;
   end;
   TablaDeta.Last;}
   Str(suma:12:3,cadena);
   SumarTotal.Caption:=convierte('###,###,##0.00',cadena,'$');
{   TablaDeta.Insert;}

 end;


1:begin
if TablaDeta.FieldByName('Cantidad').AsString='' then
  Detalle.SelectedIndex:=Detalle.SelectedIndex-1
  else
  begin
  Val(TablaDeta.FieldByName('Cantidad').AsString,valor,code);
  if code<>0 then
  TablaDeta.FieldByName('Cantidad').AsString:='0';
  TablaDeta.Edit;
  end;
  end;

2:begin
if TablaDeta.FieldByName('Cantidad').AsString='' then
  Detalle.SelectedIndex:=Detalle.SelectedIndex-1
  else
  if (TablaInventario.FindKey([TablaDeta.FieldByName('Clave').AsString]))and(TablaDeta.FieldByName('CLAVE').AsString<>'COMENTARIO') then
  begin
  checaexistencias;
  TablaDeta.Edit;

  if (cantidad>=0) or ((UpperCase(TablaInventario.FieldByName('LIPRO_I').AsString)='SERVI')or (ruta(21)<>'N')) or
  ((Base.Text='Pedido')or(Base.Text='Cotización')or(Base.Text='Nota de Crédito')or(Base.Text='Devolución'))then
  begin
  TablaDeta.Edit;
  TablaDeta.FieldByName('Producto').AsString:=TablaInventario.FieldByName('DSCPR_I').AsString;
  case PrecioNumero of

  1:TablaDeta.FieldByName('PRECIO').AsFloat:= TablaInventario.FieldByName('PPUBL_I').AsFloat;
//  TablaInventario.FieldByName('PPUBL_I').AsFloat/(1+(TablaInventario.FieldByName('PIVA1_I').AsFloat/100));
  //redondear(TablaDeta.FieldByName('PRECIO').AsFloat);
//  -(TablaInventario.FieldByName('PIVA1_I').AsFloat*TablaInventario.FieldByName('PPUBL_I').AsFloat/100);
  2:TablaDeta.FieldByName('PRECIO').AsString:=  TablaInventario.FieldByName('PLIS2_I').AsString;
  3:TablaDeta.FieldByName('PRECIO').AsString:=  TablaInventario.FieldByName('PLIS3_I').AsString;
  4:TablaDeta.FieldByName('PRECIO').AsString:=  TablaInventario.FieldByName('PLIS4_I').AsString;
  5:TablaDeta.FieldByName('PRECIO').AsString:=  TablaInventario.FieldByName('PMINI_I').AsString;
  end;

  TablaDeta.FieldByName('Unidad').AsString:=TablaInventario.FieldByName('UMEDI_I').AsString;
  TablaDeta.FieldByName('Costo').AsString:=TablaInventario.FieldByName('CPROM_I').AsString;
  TablaDeta.FieldByName('importe').AsFloat:=  TablaDeta.FieldByName('cantidad').AsFloat*
  TablaDeta.FieldByName('Precio').AsFloat-(TablaDeta.FieldByName('cantidad').AsFloat*TablaDeta.FieldByName('Precio').AsFloat*
  TablaDeta.FieldByName('DESCUENTO').AsFloat/100)+0.000;
  TablaDeta.FieldByName('Impuesto').AsString:=TablaInventario.FieldByName('PIVA1_I').AsString;
  TablaDeta.Post;
  sumatotal;
//  TablaDeta.ApplyUpdates;
  TablaDeta.Append;
  TablaDeta.FieldByName('Cantidad').AsString:='1';
    Detalle.SelectedIndex:=1;
{   TablaDeta.FieldByName('Costo').AsFloat:=}


  Str(TablaDeta.FieldByName('importe').AsFloat:12:4,cadena);
  FormatFloat( CADENA,3);
  TablaDeta.FieldByName('importe').AsString:=cadena;

{******quitamos lo siguiente para EID se agrega parar los demás solo se quita el comentario*****}
{  Detalle.SelectedIndex:=3;}
  end;



  end
  else
  begin

  if (TablaDeta.FieldByName('CLAVE').AsString<>'COMENTARIO') then
  begin
  Detalle.SelectedIndex:=Detalle.SelectedIndex-1;
  MuestraMensaje('El Producto No Se encuenta');
  Detalle.SetFocus;
  EditClave.SetFocus;
  end;

  end;

  end;

4:begin
//if CambiaPrecios='s' then
//begin
//MuestraMensaje(CambiaPrecios);
//TablaDetaPRECIO.ReadOnly:=False

//end
//else
//TablaDetaPRECIO.ReadOnly:=True;


  Detalle.Columns[4].PickList.Clear;
  Detalle.Columns[4].PickList.Add(  TablaInventario.FieldByName('PLIS2_I').AsString);
  Detalle.Columns[4].PickList.Add(  TablaInventario.FieldByName('PLIS3_I').AsString);
  Detalle.Columns[4].PickList.Add(  TablaInventario.FieldByName('PLIS4_I').AsString);
  Detalle.Columns[4].PickList.Add(  TablaInventario.FieldByName('PMINI_I').AsString);

  end;


 5:begin
   TablaDeta.Edit;
   TablaDeta.FieldByName('importe').AsFloat:=  TablaDeta.FieldByName('cantidad').AsFloat*
   TablaDeta.FieldByName('Precio').AsFloat-(TablaDeta.FieldByName('cantidad').AsFloat*TablaDeta.FieldByName('Precio').AsFloat*
   TablaDeta.FieldByName('DESCUENTO').AsFloat/100);
   TablaDeta.FieldByName('Costo').AsFloat:=  TablaDeta.FieldByName('Costo').AsFloat;
   //*TablaDeta.FieldByName('cantidad').AsFloat;

   Str(TablaDeta.FieldByName('importe').AsFloat:12:3,cadena);
   TablaDeta.FieldByName('importe').AsString:=cadena;
  end;
end;
end;//if pricipal
end;

procedure TFormaCapturaRapida.EditCLCLI_FKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
{mueveteclas;}
if (Ord(Char(Key))=13) or (Ord(Char(Key))=40) then
begin
indices:=indices+1;
cursor1;
end;
if Ord(Char(Key))=38 then
begin
indices:=indices-1;
cursor1;
end;
if Ord(Char(Key))=113 then
begin
EditCLCLI_F.Text:=BuscaclaveCliente(EditCLCLI_F.Text);
EditCLCLI_F.SetFocus;
end;

end;

procedure TFormaCapturaRapida.EditCLVEN_FKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
TablaVendedores.FindNearest([EditCLVEN_F.Text]);
if Ord(Char(Key))=113 then
begin
FormaCapturaRapida.Tag:=2;
FormaConVendedores.ShowModal;
EditCLVEN_F.SetFocus;
end;
if (Ord(Char(Key))=13) or (Ord(Char(Key))=40) then
begin
indices:=indices+1;
cursor1;
end;
if Ord(Char(Key))=38 then
begin
indices:=indices-1;
cursor1;
end;
end;

procedure TFormaCapturaRapida.EditCLVEN_FExit(Sender: TObject);
begin
quitacolor(EditCLVEN_F.ComponentIndex);
if (TablaVendedores.FindKey([EditCLVEN_F.Text]))and(TablaFacturaE.State=dsEdit) then
TablaFacturaE.FieldByName('CTOVE_F').AsFloat:=TablaVendedores.FieldByName('COMIS_V').AsFloat;
end;

procedure TFormaCapturaRapida.EditFEDOC_FEnter(Sender: TObject);
begin
ponecolor(EditFEDOC_F.ComponentIndex,EditFEDOC_F.Color);
indices:=6;
EditFEDOC_F.Text:=DateToStr(Date);
Uno.Caption:=comenta(13,'factu.des');
Dos.Caption:=comenta(14,'factu.des');
end;

procedure TFormaCapturaRapida.DetalleKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
clave,cantidad:string;
begin
if (Detalle.Enabled=True)and((BotonCambios.Tag=1)or(BotonNuevo.Tag=1))  then
begin

Case key of

113:
begin
Detalle.Tag:=3;
TablaDeta.Edit;
TablaDeta.Post;
TablaDeta.Edit;

FormaCapturaRapida.TablaDeta.FieldByName('clave').AsString:=BuscaClave(FormaCapturaRapida.TablaDeta.FieldByName('clave').AsString,1);

//FormaConProduct.ShowModal;
Detalle.SetFocus;
end;

{118:  //f7
begin
Detalle.SelectedIndex:=0;
BotonImprimir.Enabled:=true;
end;}

13:
begin
Detalle.SelectedIndex:=Detalle.SelectedIndex+1;
if  (Detalle.SelectedIndex =5) then
Detalle.SelectedIndex:=0;

end;

{115:      //f4
begin
if (TablaDeta.State=dsInsert)or(TablaDeta.State=dsEdit) then
begin
TablaDeta.FieldByName('CLAVE').AsString:='COMENTARIO';
TablaDeta.FieldByName('CANTIDAD').AsString:='1';
end;
end;}

//if key=117 then
//begin
//if (TablaDeta.State=dsInsert)or(TablaDeta.State=dsEdit) then
//begin
//TablaDeta.FieldByName('CLAVE').AsString:='DEVOLUCION';
//TablaDeta.FieldByName('CANTIDAD').AsString:='1';
//end;
//end;


116://f5 para dar cambio
begin
CAMBIO_F.SetFocus;

end;

114://f3 para repetir el ulltimo dato
begin
if (TablaDeta.FieldByName('CLAVE').AsString='')and(TablaDeta.FieldByName('CANTIDAD').AsFloat>0) then
TablaDeta.Delete;
clave:=TablaDeta.FieldByName('CLAVE').AsString;
cantidad:=TablaDeta.FieldByName('CANTIDAD').AsString;
TablaDeta.Append;
TablaDeta.FieldByName('CLAVE').AsString:=clave;
TablaDeta.FieldByName('CANTIDAD').AsString:=cantidad;
Detalle.SelectedIndex:=1;
Detalle.SelectedIndex:=2;
end;

115://f4 ir a cantidad
begin
Detalle.SelectedIndex:=0;
end;


118://f7 ir a cantidad
begin
try
TablaDeta.Delete;
sumatotal;
except
end;
end;


123:
begin
TablaDeta.Insert;
if TablaDeta.FieldByName('Cantidad').AsString='' then
TablaDeta.FieldByName('Cantidad').AsInteger:=1;
Detalle.SelectedIndex:=0;
end;

end;//case
end;//if

end;

procedure TFormaCapturaRapida.FormActivate(Sender: TObject);
begin
if FormaCapturaRapida.Tag=0 then
begin
{if FileExists(leetapiz(3)) then
Fondo.Picture.LoadFromFile(leetapiz(3));}
{Fondo.Visible:=True;}
rutas;
desactiva;
Pedido1.Enabled:=False;
Remisin1.Enabled:=False;
//Factura1.Enabled:=False;
BotonCambios.Enabled:=True;
BotonNuevo.Enabled:=true;
BotonGuardar.Enabled:=false;
Guardar1.enabled:=False;
{BotonImprimir.Enabled:=false;}
indices:=1;
decimales:=2;
TablafacturaE.Last;
ponedatos;
CambiaPrecios:=casoLetra(StrToInt(usuario.Caption),44);
end;
FormaCapturaRapida.Tag:=1;
end;

procedure TFormaCapturaRapida.EditNALMA_FKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Ord(Char(Key))=13 then
Detalle.SetFocus;
if Ord(Char(Key))=38 then
{EditDECOT_F.SetFocus;}
end;

procedure TFormaCapturaRapida.EditFEDOC_FKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

//if Key=114 then
//EditFEDOC_F.Text:=DateTimeToStr(Date);
if (Key=13) or (Key=40) then
begin
quitacolor(EditFEDOC_F.ComponentIndex);
if not fechavalida(EditFedoc_F.Text) then
EditFedoc_F.Text:=DateTimeToStr(Date);

indices:=indices+1;
cursor1;
end;

if Key=38 then
begin
indices:=indices-1;
cursor1;
end;

end;

procedure TFormaCapturaRapida.EditIMIM1_FEnter(Sender: TObject);
begin
ponecolor(EditIMIM1_F.ComponentIndex,EditIMIM1_F.Color);
indices:=7;
EditIMIM1_F.Text:=FloatToStr(iva);
Uno.Caption:=comenta(19,'factu.des');
Dos.Caption:=comenta(20,'factu.des');
end;

procedure TFormaCapturaRapida.EditDESFI_FEnter(Sender: TObject);
begin
ponecolor(EditDESFI_F.ComponentIndex,EditDESFI_F.Color);
indices:=8;
//EditDESFI_F.Text:=FloatToStr(desfin);
Uno.Caption:=comenta(21,'factu.des');
Dos.Caption:=comenta(22,'factu.des');
end;




procedure TFormaCapturaRapida.BotonSalirClick(Sender: TObject);
begin
Close;
end;

procedure TFormaCapturaRapida.Consultas1Click(Sender: TObject);
begin
FormaConsulta.TablaConsulta.DataBaseName:=ruta(8);
FormaConsulta.TablaConsulta.IndexName:='INUMENC';
FormaConsulta.TablaConsulta.TableName:='facturae.dbf';
FormaConsulta.TablaConsulta.Open;
FormaConsulta.TablaConsulta.First;
//FormaConsulta.De.Text:=FormaConsulta.TablaConsulta.Fields[0].AsString;
FormaConsulta.TablaConsulta.Last;
//FormaConsulta.Hasta.Text:=FormaConsulta.TablaConsulta.Fields[0].AsString;
FormaConsulta.TablaConsulta.First;
FormaConsulta.NumCampo.Caption:='0';
asignatipo;
leearchivocampos(74,101);
FormaConsulta.ShowModal;

end;

procedure TFormaCapturaRapida.EditCLDOC_FKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Ord(Char(Key))=13) or (Ord(Char(Key))=40) then
begin
indices:=indices+1;
cursor1;

end;
if Ord(Char(Key))=38 then
begin
indices:=indices-1;
cursor1;
end;
end;

procedure TFormaCapturaRapida.BotonBuscarClick(Sender: TObject);
var siguiente:LongInt;
begin
FormaBusqueda:=TFormaBusqueda.Create(Application);
FormaBusqueda.ShowModal;
TablaFacturae.FindNearest([FormaBusqueda.CajaBuscar.Text]);
ponedatos;
FormaBusqueda.Free;
end;

procedure TFormaCapturaRapida.BotonCambiosClick(Sender: TObject);

begin

if caso(StrToInt(usuario.Caption),22) then
begin
local:=False;
TablaFacturae.Edit;
if TablaFacturaE.State=dsEdit then
begin
bufercambios('F');
saldoanterior:=TablaFacturaE.FieldByName('IMTOD_F').AsFloat;

TablaDeta.Edit;
EditCLCLI_F.Visible:=True;
activa;
indice:=0;
sig:=1;
indices:=1;
borradatosanteriores('F');

activabotones(False,False,True,False,False,False,True);
BotonCambios.Tag:=1;
BotonNuevo.Tag:=0;

EditCLDOC_F.SetFocus;
end
else
MuestraMensaje('No se Pueden Realizar Cambios');
end;


Navegador.Enabled:=False;

end;




procedure TFormaCapturaRapida.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
if (BotonCambios.Tag=1)or (BotonNuevo.Tag=1) then
begin
FormaCerrar:=TFormaCerrar.Create(Application);
{FormaCapturaRapida.Tag:=1;}
FormaCerrar.ShowModal;
{MuestraMensaje(IntToStr(FormaCerrar.Tag));}
if FormaCerrar.Tag=1 then
begin
{MuestraMensaje('voy a guardar');}

if Base.Text='Factura' then
guardatodo('F');
if Base.Text='Remisión' then
guardatodo('R');
if Base.Text='Pedido' then
guardatodo('P');
if Base.Text='Cotización' then
guardatodo('C');


activabotones(True,True,False,True,True,True,False);
desactiva;
BotonCambios.Tag:=0;
BotonNuevo.Tag:=0;
end;

if FormaCerrar.Tag=2 then
begin
if BotonCambios.Tag=1 then
regresabufercambios;

if BotonCambios.Tag<>1 then
TablaFacturae.Delete;
TablaFacturad.Cancel;



{FormaCapturaRapida.Close;}


activabotones(True,True,False,True,True,True,False);
desactiva;
BotonCambios.Tag:=0;
BotonNuevo.Tag:=0;

end;

if FormaCerrar.Tag=3 then
Action:=caNone;
FormaCerrar.Tag:=0;
{FormaCapturaRapida.Tag:=0;}
FormaCerrar.Free;
end;
Navegador.Enabled:=True;
BotonSalir.Tag:=1000;
end;

procedure TFormaCapturaRapida.BotonImprimirClick(Sender: TObject);
begin
if ImpresoraLista then
begin
if FileExists(nombreformato) then
begin
LeeEtiquetasMoneda(valordivisaetiqueta('M.N.',1),valordivisaetiqueta('M.N.',2),valordivisaetiqueta('M.N.',3),valordivisaetiqueta('M.N.',4));
forma(FormaCapturaRapida.TablaFacturaE,FormaCapturaRapida.TablaDeta,nombreformato,'i');
end
else
MuestraMensaje('El Formato '+nombreformato+'No Existe');
end
else
MuestraMensaje('La Impresora No Se Encuentra Lista...');
end;

procedure TFormaCapturaRapida.DetalleEditButtonClick(Sender: TObject);
begin
{MuestraMensaje('Mostrar precios');}
end;

procedure TFormaCapturaRapida.FolderChange(Sender: TObject; NewTab: Integer;
  var AllowChange: Boolean);
var
ventas:integer;
begin
{TablaFacturaE.Open;
TablaFacturaE.SetRange([TablaCliente.FieldByName('CLCLI_C').AsString],[TablaCliente.FieldByName('CLCLI_C').AsString]);}
end;

procedure TFormaCapturaRapida.BaseChange(Sender: TObject);
begin
if (Base.Text='')or(Base.Text<>'Remisión')or(Base.Text<>'Devolución')or(Base.Text<>'Caja Chica') then
Base.Text:='Remisión';


if Base.Text='Remisión' then
begin
TablaFacturaE.Close;
TablaFacturaE.TableName:='Remision.dbf';
TablaFacturaE.Open;
TablaFacturaD.Close;
TablaFacturaD.TableName:='RemisioD.dbf';
TablaFacturaD.Open;
formatonum:=15;

Pedido1.Enabled:=False;
Remisin1.Enabled:=False;
Factura1.Enabled:=True;
Devolucin1.Enabled:=True;
NotadeCrdito1.Enabled:=False;
BotonPago.Enabled:=False;
BotonObservacion.Enabled:=False;
if Usuario.Caption='0' then
EditCLDOC_F.ReadOnly:=True
else
EditCLDOC_F.ReadOnly:=False;
end;


if Base.Text='Caja Chica' then
begin
TablaFacturaE.Close;
TablaFacturaE.TableName:='CajaChic.dbf';
TablaFacturaE.Open;
TablaFacturaD.Close;
TablaFacturaD.TableName:='CajaChiD.dbf';
TablaFacturaD.Open;
formatonum:=17;

Pedido1.Enabled:=False;
Remisin1.Enabled:=False;
Factura1.Enabled:=False;
Devolucin1.Enabled:=False;
NotadeCrdito1.Enabled:=False;
BotonPago.Enabled:=False;
BotonObservacion.Enabled:=False;
end;




nombreformato:=leeruta+'\consulta\'+ruta(formatonum);
ponedatos;

end;

procedure TFormaCapturaRapida.EditCLDOC_FEnter(Sender: TObject);
begin
ponecolor(EditCLDOC_F.ComponentIndex,EditCLDOC_F.Color);
indices:=1;
Uno.Caption:=comenta(1,'factu.des');
Dos.Caption:=comenta(2,'factu.des');
end;

procedure TFormaCapturaRapida.EditCLCLI_FEnter(Sender: TObject);
begin

EditCLClI_F.Text:='1';
EditCLClI_F.SelectAll;
ponecolor(EditCLCLI_F.ComponentIndex,EditCLCLI_F.Color);
indices:=2;

Uno.Caption:=comenta(3,'factu.des');
Dos.Caption:=comenta(4,'factu.des');

end;

procedure TFormaCapturaRapida.EditBCLIM_FEnter(Sender: TObject);
begin
ponecolor(EditBCLIM_F.ComponentIndex,EditBCLIM_F.Color);
indices:=5;
Uno.Caption:=comenta(9,'factu.des');
Dos.Caption:=comenta(10,'factu.des');
EditBCLIM_F.Text:=CajaLocal;
end;

procedure TFormaCapturaRapida.EditCLVEN_FEnter(Sender: TObject);
begin
ponecolor(EditCLVEN_F.ComponentIndex,EditCLVEN_F.Color);
indices:=3;
Uno.Caption:=comenta(5,'factu.des');
Dos.Caption:=comenta(6,'factu.des');
end;

procedure TFormaCapturaRapida.EditCTOVE_FEnter(Sender: TObject);
begin
ponecolor(EditCTOVE_F.ComponentIndex,EditCTOVE_F.Color);
indices:=4;
Uno.Caption:=comenta(7,'factu.des');
Dos.Caption:=comenta(8,'factu.des');
end;

procedure TFormaCapturaRapida.EditCLPED_FEnter(Sender: TObject);
begin
{ponecolor(EditCLPED_F.ComponentIndex,EditCLPED_F.Color);}
indices:=3;
Uno.Caption:=comenta(11,'factu.des');
Dos.Caption:=comenta(12,'factu.des');
end;

procedure TFormaCapturaRapida.EditDECOT_FEnter(Sender: TObject);
begin
{ponecolor(EditDECOT_F.ComponentIndex,EditDECOT_F.Color);}
indices:=16;
Uno.Caption:=comenta(23,'factu.des');
Dos.Caption:=comenta(24,'factu.des');
end;

procedure TFormaCapturaRapida.Concentrar1Click(Sender: TObject);
var
desde,hastavalor:string;
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturae.dbf');

TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
//valoresiniciales('','',desde,hastavalor);
valoresiniciales('','','','');

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaE.TableName,'devoluc.dbf','FactAuxi.dbf','INUMENC');
Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLCLI_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM1_F','IMIM2_F','','','','','STATU_F','!','C','D');
end
else
Concentrar(TablaFacturaE,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLCLI_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM1_F','IMIM2_F','','','','','STATU_F','!','C','D');

poneetiquetas('Cliente','Nombre','Total del Documento','SubTotal','IVA','% IVA','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica de Facturas, Importe e Iva'+Base.Text+' Documentos, Subtotal, I.V.A., Total','Número de Documento','Total por Documento',3);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;

FormaBarras.Concentrado.Clear;
FormaBarras.Caption:='Reporte de Facturas, Importe e Iva';
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;

end;


procedure TFormaCapturaRapida.Comisiones1Click(Sender: TObject);
var
desde,hastavalor:string;
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturae.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaE.TableName,'devoluc.dbf','FactAuxi.dbf','INUMENC');
//Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLCLI_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM1_F','IMIM2_F','','','','','STATU_F','!','C','D');
Concentrar(TablaAuxiliar,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLVEN_F','FEDOC_F','SUBTO_F','&%SUBTO_F&*&%CTOVE_F&*&0.01&','IMTOD_F','&%IMTOD_F&*&%CTOVE_F&*&0.01&','','','','','STATU_F','!','C','C');
end
else
Concentrar(TablaFacturaE,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLVEN_F','FEDOC_F','SUBTO_F','&%SUBTO_F&*&%CTOVE_F&*&0.01&','IMTOD_F','&%IMTOD_F&*&%CTOVE_F&*&0.01&','','','','','STATU_F','!','C','C');
poneetiquetas('Vendedor','Fecha','SubTotal del Documento','Comisión Sobre SubTotal','Total del Documento','Comisión sobre Total','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica de Comisiones de Vendedor'+Base.Text+' , Subtotal, I.V.A., Total','Número de Documento','Total por Documento',1);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;
FormaBarras.Concentrado.Clear;
FormaBarras.Caption:='Reporte de Comisiones de Vendedor';
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;

FormaFormatos.Free;
FormaBarras.Free;

end;

procedure TFormaCapturaRapida.EditFEDOC_FExit(Sender: TObject);
begin
quitacolor(EditFEDOC_F.ComponentIndex);
if not fechavalida(EditFedoc_F.Text) then
EditFedoc_F.Text:=DateTimeToStr(Date);

end;

procedure TFormaCapturaRapida.EditCLDOC_FMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(1,'factu.des');
Dos.Caption:=comenta(2,'factu.des');
end;

procedure TFormaCapturaRapida.EditCLCLI_FMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(3,'factu.des');
Dos.Caption:=comenta(4,'factu.des');
end;

procedure TFormaCapturaRapida.EditCLVEN_FMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(5,'factu.des');
Dos.Caption:=comenta(6,'factu.des');
end;

procedure TFormaCapturaRapida.EditCTOVE_FMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(7,'factu.des');
Dos.Caption:=comenta(8,'factu.des');
end;

procedure TFormaCapturaRapida.EditBCLIM_FMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(9,'factu.des');
Dos.Caption:=comenta(10,'factu.des');
end;

procedure TFormaCapturaRapida.EditCLPED_FMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(11,'factu.des');
Dos.Caption:=comenta(12,'factu.des');
end;

procedure TFormaCapturaRapida.EditFEDOC_FMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(13,'factu.des');
Dos.Caption:=comenta(14,'factu.des');
end;

procedure TFormaCapturaRapida.EditIMIM1_FMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(19,'factu.des');
Dos.Caption:=comenta(20,'factu.des');
end;

procedure TFormaCapturaRapida.EditDESFI_FMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(21,'factu.des');
Dos.Caption:=comenta(22,'factu.des');
end;

procedure TFormaCapturaRapida.EditDECOT_FMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(23,'factu.des');
Dos.Caption:=comenta(24,'factu.des');
end;

procedure TFormaCapturaRapida.EditNALMA_FMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(25,'factu.des');
Dos.Caption:=comenta(26,'factu.des');
end;

procedure TFormaCapturaRapida.EditREMIS_FKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Ord(Char(Key))=13) or (Ord(Char(Key))=40) then
begin
indices:=indices+1;
cursor1;
{indice:=0;
mueveteclas;}

end;

if Ord(Char(Key))=38 then
begin
indices:=indices-1;
cursor1;
end;
end;

procedure TFormaCapturaRapida.EditCONDI_FKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Ord(Char(Key))=13) or (Ord(Char(Key))=40) then
begin
indices:=indices+1;
cursor1;
{indice:=0;
mueveteclas;}

end;

if Ord(Char(Key))=38 then
begin
indices:=indices-1;
cursor1;
end;
end;

procedure TFormaCapturaRapida.EditDESTI_FKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Ord(Char(Key))=13) or (Ord(Char(Key))=40) then
begin
indices:=indices+1;
cursor1;
{indice:=0;
mueveteclas;}

end;

if Ord(Char(Key))=38 then
begin
indices:=indices-1;
cursor1;
end;
end;

procedure TFormaCapturaRapida.ConsecutivodeFacturas1Click(Sender: TObject);
var
dia:string[12];
desde,hastavalor:string;
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturae.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
//valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaE.TableName,'devoluc.dbf','FactAuxi.dbf','INUMENC');
Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLDOC_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM2_F','','','','','','STATU_F','!','C','D');
end
else
Concentrar(TablaFacturaE,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLDOC_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM2_F','','','','','','STATU_F','!','C','D');

//Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLCLI_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM1_F','IMIM2_F','','','','','STATU_F','!','C','D');

dia:=DateToStr(FormaFormatos.Inicial.Date);
//

poneetiquetas('Documento','Nombre','Total del Documento','SubTotal','IVA','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica de Consecutivo de Documentos','Número de Documento','Total por Documento',1);

FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;

FormaBarras.Concentrado.Clear;
FormaBarras.Caption:='Reporte de Documentos Del Día '+dia;
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;

end;


procedure TFormaCapturaRapida.Eliminar1Click(Sender: TObject);
begin
if caso(StrToInt(usuario.Caption),22) then
begin
FormaAdvertencia:=TFormaAdvertencia.Create(Application);
FormaAdvertencia.ShowModal;
if FormaAdvertencia.Tag=1 then
begin
{***********}
if Base.Text='Factura' then
begin
if borratodaslascuentas then
begin
bufercambios('F');
BorraDatosMovimientos('F');
borradatosanteriores('F');
TablaFacturaE.Delete;
end
else
MuestraMensaje('El documento No Puede Eliminarse Posee Movimientos');
end
else
begin
if Base.Text='Remisión' then
begin

bufercambios('F');
BorraDatosMovimientos('R');
borradatosanteriores('R');
TablaFacturaE.Delete;
end;//if remision
end;
ponedatos;
end;
FormaAdvertencia.Tag:=0;
FormaAdvertencia.Free;
end;
end;

procedure TFormaCapturaRapida.ComisionesDetallado1Click(Sender: TObject);
var
desde,hastavalor:string;
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturae.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaE.TableName,'devoluc.dbf','FactAuxi.dbf','INUMENC');
//Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLCLI_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM1_F','IMIM2_F','','','','','STATU_F','!','C','D');
Concentrar(TablaAuxiliar,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLVEN_F','FEDOC_F','IMTOD_F','&%IMTOD_F&*&%CTOVE_F&*&0.01&','','','','','','','STATU_F','!','C','DC');
end
else
Concentrar(TablaFacturaE,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLVEN_F','FEDOC_F','IMTOD_F','&%IMTOD_F&*&%CTOVE_F&*&0.01&','','','','','','','STATU_F','!','C','DC');
poneetiquetas('Vendedor','Fecha','Total','Comisión','','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica de Comisiones Detallado','Número de Documento','Total por Documento',1);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;

FormaBarras.Concentrado.Clear;
FormaBarras.Caption:='Reporte de Comisiones Detallado';
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=1;
FormaFormatos.Free;
FormaBarras.Free;

end;

procedure TFormaCapturaRapida.Factura1Click(Sender: TObject);
var
Aux:string[1];
begin
Aux:=Base.Text;
Orig:=Aux+EditCLDOC_F.Text;
RangoDocumentos:=False;

Base.Tag:=1;
while not TablaFacturaD.EOF do
begin
TablaFacturaD.Edit;
TablaFacturaD.FieldByName('TREGI_FD').AsString:='F';
TablaFacturaD.Post;
TablaFacturaD.Next;
end;

bufercambios('C');
generadocumento('F');
TablaFacturaD.First;
activa;
EditCLDOC_F.SetFocus;
local:=True;
TablaFacturaE.Edit;


if (TablaCliente.FindKey([EditCLCLI_F.Text]))and(TablaFacturaE.State=dsEdit) then
begin
Nombre.Caption:=TablaCliente.FieldByName('NOMBR_C').AsString;
Direccion.Caption:=TablaCliente.FieldByName('DIREC_C').AsString;
Direc2.Caption:=TablaCliente.FieldByName('DIRE2_C').AsString;
Poblacion.Caption:=TablaCliente.FieldByName('POBLA_C').AsString;
RFC.Caption:=TablaCliente.FieldByName('RFCXX_C').AsString;
CodigoPostal.Caption:=TablaCliente.FieldByname('CPXXX_C').AsString;
end


end;

procedure TFormaCapturaRapida.Remisin1Click(Sender: TObject);
var
Aux:string[1];
begin
Aux:=Base.Text;
Orig:=Aux+EditCLDOC_F.Text;
bufercambios('C');
generadocumento('R');
activa;
EditCLDOC_F.SetFocus;
local:=True;
TablaFacturaE.Edit;
end;

procedure TFormaCapturaRapida.Pedido1Click(Sender: TObject);
var
Aux:string[1];
begin
Aux:=Base.Text;
Orig:=Aux+EditCLDOC_F.Text;
bufercambios('C');
generadocumento('P');
activa;
EditCLDOC_F.SetFocus;
local:=True;
TablaFacturaE.Edit;
end;

procedure TFormaCapturaRapida.VentasyUtilidad1Click(Sender: TObject);
var
desde,hastavalor:string;
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturae.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaE.TableName,'devoluc.dbf','FactAuxi.dbf','INUMENC');
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
//Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLCLI_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM1_F','IMIM2_F','','','','','STATU_F','!','C','D');
Concentrar(TablaAuxiliar,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLDOC_F','NOMBR_F','COSTO_F','IMTOD_F','&%IMTOD_F&-&%COSTO_F&*&1.0&','','','','','','STATU_F','!','C','D');
end
else
Concentrar(TablaFacturaE,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLDOC_F','NOMBR_F','COSTO_F','SUBTO_F','&%SUBTO_F&-&%COSTO_F&*&1.0&','','','','','','STATU_F','!','C','D');
poneetiquetas('Documento','Nombre','Costo','Total','Utilidad','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica de Ventas y Utilidades','Número de Documento','Total por Documento',2);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;

FormaBarras.Concentrado.Clear;
FormaBarras.Caption:='Reporte de Ventas y Utilidades';
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;

end;

procedure TFormaCapturaRapida.BotonPreliminarClick(Sender: TObject);
begin
if FileExists(nombreformato) then
begin
FormaEdicion:=TFormaEdicion.Create(Application);
LeeEtiquetasMoneda(valordivisaetiqueta('M.N.',1),valordivisaetiqueta('M.N.',2),valordivisaetiqueta('M.N.',3),valordivisaetiqueta('M.N.',4));
forma(FormaCapturaRapida.TablaFacturaE,FormaCapturaRapida.TablaDeta,nombreformato,'p');
end
else
MuestraMensaje('El Formato '+nombreformato+'No Existe');
FormaEdicion.Hoja.Tag:=0;
FormaEdicion.ShowModal;
FormaEdicion.Free;
end;


procedure TFormaCapturaRapida.Calculadora1Click(Sender: TObject);
begin
{if FileExists('calc.exe') then}
WinExec('calc.exe',SW_SHOWNORMAL);

end;

procedure TFormaCapturaRapida.Divisas1Click(Sender: TObject);
begin
FormaDivisa:=TFormaDivisa.Create(Application);
FormaDivisa.ShowModal;
FormaDivisa.Free;
end;

procedure TFormaCapturaRapida.ImprimirRangodeDocumentos1Click(Sender: TObject);
var
i:integer;
begin
DialogoImprimir:=TDialogoImprimir.Create(Application);
DialogoImprimir.Tag:=0;
DialogoImprimir.PrimeraPagina.Text:='0';
DialogoImprimir.UltimaPagina.Text:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
DialogoImprimir.ShowModal;

if DialogoImprimir.Tag=1 then
begin
TablaFacturaE.First;
for i:=StrToInt(DialogoImprimir.PrimeraPagina.Text) to StrToInt(DialogoImprimir.UltimaPagina.Text) do
begin
if TablaFacturaE.FindKey([IntToStr(i)]) then
begin
ponedatos;
if FileExists(nombreformato) then
forma(FormaCapturaRapida.TablaFacturaE,FormaCapturaRapida.TablaDeta,nombreformato,'i')
else
MuestraMensaje('El Formato '+nombreformato+'No Existe');
end;
end;
ponedatos;
end;
DialogoImprimir.Free;

end;


procedure TFormaCapturaRapida.Cancelar1Click(Sender: TObject);
begin

if caso(StrToInt(usuario.Caption),22) then
begin
FormaAdvertencia:=TFormaAdvertencia.Create(Application);
FormaAdvertencia.Label1.Caption:='Esta Seguro que Desea CANCELAR este Documento ?';
FormaAdvertencia.ShowModal;
FormaAdvertencia.Label1.Caption:='Esta Seguro que Desea ELIMINAR este Documento ?';
if FormaAdvertencia.Tag=1 then
begin

if TablaFacturaE.FieldByName('STATU_F').AsString<>'C' then
begin

   bufercambios('F');
   saldoanterior:=TablaFacturaE.FieldByName('IMTOD_F').AsFloat;
   borradatosanteriores('X');
   BorraDatosMovimientos('R');
   TablaMovimientosInventario.Last;
   numeromovimiento:=TablaMovimientosInventario.FieldByName('CLDOC_MI').AsInteger+1;

  {generacuentasxcobrar;}
  {actualizafactura(tipo);}

if TablaCliente.FindKey([EditCLCLI_F.Text]) then
begin
TablaCliente.Edit;
TablaCliente.FieldByName('SALDO_C').AsFloat:=TablaCliente.FieldByName('SALDO_C').AsFloat-saldoanterior;
TablaCliente.FieldByName('COMPR_C').Asfloat:=TablaCliente.FieldByName('COMPR_C').AsFloat-saldoanterior;
TablaCliente.Post;
end;
   {*********};
{guardatodo('X');}
local:=False;
TablaFacturaE.Edit;
TablaFacturaE.FieldByName('STATU_F').AsString:='C';
TablaFacturaE.Post;
CancelaDetalle(EditCLDOC_F.Text);
Estado.Caption:='Cancelada';
end
else
MuestraMensaje('La Factura Ya Fue Cancelada');
indice:=0;
sig:=1;
indices:=1;

end;
FormaAdvertencia.Tag:=0;
FormaAdvertencia:=TFormaAdvertencia.Create(Application);
end;

end;

procedure TFormaCapturaRapida.BotonTotalesClick(Sender: TObject);
var
cantiletra:string;
begin
sumatotal;
FormaDesglosaTotal:=TFormaDesglosaTotal.Create(Application);
FormaDesglosaTotal.SubTotal.Caption:=SumarTotal.Caption;
FormaDesglosaTotal.Descuento.Caption:=convierte('###,###,##0.00',redondear(desfin1),'$');
FormaDesglosaTotal.Iva.Caption:=ImpuestoValor.Caption;
FormaDesglosaTotal.Total.Caption:=TotalFact.Caption;
{*****************}
cantiletra:=Traduce(Total1);
FormaDesglosaTotal.Letra2.Caption:='';
FormaDesglosaTotal.Letra1.Caption:=cantiletra;
{*****************}
FormaDesglosaTotal.ShowModal;
FormaDesglosaTotal.Free;
end;

procedure TFormaCapturaRapida.EditDECOT_FKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Ord(Char(Key))=13) or (Ord(Char(Key))=40) then
begin
indices:=indices+1;
cursor1;
end;
if Ord(Char(Key))=38 then
begin
indices:=indices-1;
cursor1;
end;

end;

















procedure TFormaCapturaRapida.Elegirformato1Click(Sender: TObject);
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Tag:=3;
FormaFormatos.Rangos.Visible:=False;
FormaFormatos.Formatos.Visible:=True;
FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
if FileExists(Formaformatos.Rutas.Text) then
begin
nombreformato:=Formaformatos.Rutas.Text;
{forma(TablaFacturaE,TablaFacturaE,Formaformatos.Rutas.Text,'i')}

end
else
MuestraMensaje('El Formato '+Formaformatos.Rutas.Text+' No Existe');
end;
FormaFormatos.Tag:=1;
FormaFormatos.Free;
FormaBarras.Free;

end;

procedure TFormaCapturaRapida.DisearFormato1Click(Sender: TObject);
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=False;
FormaFormatos.Formatos.Visible:=True;
FormaFormatos.ShowModal;

FormaFormatos.Free;
FormaBarras.Free;

end;

procedure TFormaCapturaRapida.TablaFacturaeEditError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
if local then Action:=daRetry
else
DatabaseError('No se Pueden Editar los Datos ha Ocurrido un Error');
end;

procedure TFormaCapturaRapida.TablaFacturaePostError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
{DatabaseError('No se Pueden Guardar los Datos ha Ocurrido un Error');}
end;

procedure TFormaCapturaRapida.EditCLDOC_FExit(Sender: TObject);
begin
quitacolor(EditCLDOC_F.ComponentIndex);
end;

procedure TFormaCapturaRapida.EditCTOVE_FExit(Sender: TObject);
begin
quitacolor(EditCTOVE_F.ComponentIndex);

end;

procedure TFormaCapturaRapida.EditBCLIM_FExit(Sender: TObject);
begin
quitacolor(EditBCLIM_F.ComponentIndex);
end;

procedure TFormaCapturaRapida.EditIMIM1_FExit(Sender: TObject);
begin
quitacolor(EditIMIM1_F.ComponentIndex);
end;

procedure TFormaCapturaRapida.EditDESFI_FExit(Sender: TObject);
begin
quitacolor(EditDESFI_F.ComponentIndex);
end;

procedure TFormaCapturaRapida.TablaFacturaeDeleteError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaFacturaeUpdateError(DataSet: TDataSet;
  E: EDatabaseError; UpdateKind: TUpdateKind;
  var UpdateAction: TUpdateAction);
begin
UpdateAction:=uaRetry;
end;

procedure TFormaCapturaRapida.TablaFacturaDDeleteError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaFacturaDEditError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaFacturaDPostError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaFacturaDUpdateError(DataSet: TDataSet;
  E: EDatabaseError; UpdateKind: TUpdateKind;
  var UpdateAction: TUpdateAction);
begin
UpdateAction:=uaRetry	;
end;

procedure TFormaCapturaRapida.TablaClienteEditError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaClienteDeleteError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaClientePostError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaClienteUpdateError(DataSet: TDataSet;
  E: EDatabaseError; UpdateKind: TUpdateKind;
  var UpdateAction: TUpdateAction);
begin
UpdateAction:=uaRetry	;
end;

procedure TFormaCapturaRapida.TablaInventarioDeleteError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaInventarioEditError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaInventarioPostError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaInventarioUpdateError(DataSet: TDataSet;
  E: EDatabaseError; UpdateKind: TUpdateKind;
  var UpdateAction: TUpdateAction);
begin
UpdateAction:=uaRetry	;
end;

procedure TFormaCapturaRapida.TablaVendedoresDeleteError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaVendedoresEditError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaVendedoresPostError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablaVendedoresUpdateError(DataSet: TDataSet;
  E: EDatabaseError; UpdateKind: TUpdateKind;
  var UpdateAction: TUpdateAction);
begin
UpdateAction:=uaRetry	;
end;

procedure TFormaCapturaRapida.TablamovimientosInventarioDeleteError(
  DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablamovimientosInventarioEditError(
  DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablamovimientosInventarioPostError(
  DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction);
begin
Action:=daRetry	;
end;

procedure TFormaCapturaRapida.TablamovimientosInventarioUpdateError(
  DataSet: TDataSet; E: EDatabaseError; UpdateKind: TUpdateKind;
  var UpdateAction: TUpdateAction);
begin
UpdateAction:=uaRetry	;
end;


procedure TFormaCapturaRapida.FacturasFechaeImportes1Click(Sender: TObject);
var
desde,hastavalor:string;
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturae.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);

TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaE.TableName,'devoluc.dbf','FactAuxi.dbf','INUMENC');
//Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLCLI_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM1_F','IMIM2_F','','','','','STATU_F','!','C','D');
Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLCLI_F','FEDOC_F','IMTOD_F','SUBTO_F','IMIM2_F','','','','','','STATU_F','!','C','D');
end
else
Concentrar(TablaFacturaE,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLCLI_F','FEDOC_F','IMTOD_F','SUBTO_F','IMIM2_F','','','','','','STATU_F','!','C','D');
poneetiquetas('Cliente','Fecha','Total del Documento','SubTotal','IVA','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica de Facturas, Fechas e Importes','Número de Documento','Total por Documento',1);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;

FormaBarras.Concentrado.Clear;
FormaBarras.Caption:='Reporte de Facturas, Fechas e Importes';
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;

end;



procedure TFormaCapturaRapida.BotonObservacionClick(Sender: TObject);
begin
try
buscaobservacion(EditCLDOC_F.Text,BotonNuevo.Tag);
except
end;
end;

procedure TFormaCapturaRapida.BotonCambiosMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaCapturaRapida.Left+BotonCambios.Left,FormaCapturaRapida.Top+BotonCambios.Top+BotonCambios.Height,15);
end;

procedure TFormaCapturaRapida.BotonNuevoMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaCapturaRapida.Left+BotonNuevo.Left,FormaCapturaRapida.Top+BotonNuevo.Top+BotonNuevo.Height,16);
end;

procedure TFormaCapturaRapida.BotonGuardarMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaCapturaRapida.Left+BotonGuardar.Left,FormaCapturaRapida.Top+BotonGuardar.Top+BotonGuardar.Height,17);
end;

procedure TFormaCapturaRapida.BotonTotalesMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaCapturaRapida.Left+BotonTotales.Left,FormaCapturaRapida.Top+BotonTotales.Top+BotonTotales.Height,18);
end;

procedure TFormaCapturaRapida.BotonPreliminarMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaCapturaRapida.Left+BotonPreliminar.Left,FormaCapturaRapida.Top+BotonPreliminar.Top+BotonPreliminar.Height,19);
end;

procedure TFormaCapturaRapida.BotonObservacionMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaCapturaRapida.Left+BotonObservacion.Left,FormaCapturaRapida.Top+BotonObservacion.Top+BotonObservacion.Height,20);
end;

procedure TFormaCapturaRapida.BotonBuscarMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaCapturaRapida.Left+BotonBuscar.Left,FormaCapturaRapida.Top+BotonBuscar.Top+BotonBuscar.Height,21);
end;

procedure TFormaCapturaRapida.BotonImprimirMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaCapturaRapida.Left+BotonImprimir.Left,FormaCapturaRapida.Top+BotonImprimir.Top+BotonImprimir.Height,22);
end;

procedure TFormaCapturaRapida.BotonPagoMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaCapturaRapida.Left+BotonPago.Left,FormaCapturaRapida.Top+BotonPago.Top+BotonPago.Height,23);
end;

procedure TFormaCapturaRapida.Devolucin1Click(Sender: TObject);
var
Aux:string[1];
begin
RangoDocumentos:=False;
Aux:=Base.Text;
Orig:=Aux+EditCLDOC_F.Text;

bufercambios('C');
generadocumento('D');
activa;
EditCLDOC_F.SetFocus;
local:=True;
TablaFacturaE.Edit;

end;

procedure TFormaCapturaRapida.VentasporDa1Click(Sender: TObject);
var
desde,hastavalor:string;
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturae.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaE.TableName,'devoluc.dbf','FactAuxi.dbf','INUMENC');
Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'FEDOC_F','','IMTOD_F','CTOVE_F','&%IMTOD_F&*&%CTOVE_F&*&0.01&','','','','','','STATU_F','!','C','C');
end
else
Concentrar(TablaFacturaE,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'FEDOC_F','','IMTOD_F','CTOVE_F','&%IMTOD_F&*&%CTOVE_F&*&0.01&','','','','','','STATU_F','!','C','C');
poneetiquetas('Fecha','','Importe','- % Comis. Vend.','Comisión','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
FormaBarras.Caption:='Reporte de Ventas por Día';
parametrosgrafica('Gráfica de Ventas por Día','Día','Total por Día',1);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;

end;

procedure TFormaCapturaRapida.VentasporMes1Click(Sender: TObject);
var
desde,hastavalor:string;
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturae.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaE.TableName,'devoluc.dbf','FactAuxi.dbf','INUMENC');
Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'FEDOC_F','','IMTOD_F','CTOVE_F','&%IMTOD_F&*&%CTOVE_F&*&0.01&','','','','','','STATU_F','!','C','C');
end
else
Concentrar(TablaFacturaE,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'FEDOC_F','','IMTOD_F','CTOVE_F','&%IMTOD_F&*&%CTOVE_F&*&0.01&','','','','','','STATU_F','!','C','C');
poneetiquetas('Fecha','','Importe','- % Comis. Vend.','Comisión','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
pormes;
FormaBarras.Caption:='Reporte de Ventas por Mes';
parametrosgrafica('Gráfica de Ventas por Mes','Mes','Total por Mes',1);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;

end;

procedure TFormaCapturaRapida.Ventasporao1Click(Sender: TObject);
var
desde,hastavalor:string;
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturae.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaE.TableName,'devoluc.dbf','FactAuxi.dbf','INUMENC');
Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'FEDOC_F','','IMTOD_F','CTOVE_F','&%IMTOD_F&*&%CTOVE_F&*&0.01&','','','','','','STATU_F','!','C','C');
end
else
Concentrar(TablaFacturaE,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'FEDOC_F','','IMTOD_F','CTOVE_F','&%IMTOD_F&*&%CTOVE_F&*&0.01&','','','','','','STATU_F','!','C','C');
poneetiquetas('Fecha','','Importe','- % Comis. Vend.','Comisión','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
FormaBarras.Caption:='Reporte de Ventas por Año';
parametrosgrafica('Gráfica de Ventas por Año','Año','Total por Año',1);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;
porano;
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;

FormaFormatos.Free;
FormaBarras.Free;

end;

procedure TFormaCapturaRapida.VentasporArtculo1Click(Sender: TObject);
var
desde,hastavalor:string;
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturad.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaD.TableName,'devolucd.dbf','FactAuxiD.dbf',TablaFacturaD.IndexName);
Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_FD',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLPRO_FD','DEPRO_FD','CANTI_FD','PUNPR_FD','&%IMPOR_FD&+&%IMPOR_FD&*&0.5000&','','','','','','TREGI_FD','!','C','C');
end
else
Concentrar(TablaFacturaD,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_FD',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLPRO_FD','DEPRO_FD','CANTI_FD','PUNPR_FD','&%IMPOR_FD&+&%IMPOR_FD&*&0.5000&','','','','','','TREGI_FD','!','C','C');


poneetiquetas('Articulo','Descripción','-Cantidad','-Precio','Importe','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
FormaBarras.Caption:='Reporte de Ventas por Artículo';
parametrosgrafica('Gráfica de Ventas por Artículo','Artículo','Total por Artículo',1);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;

end;

procedure TFormaCapturaRapida.ImprimePlantilla1Click(Sender: TObject);
begin
FormaCapturaRapida.Print;
end;

procedure TFormaCapturaRapida.DocumentosCancelados1Click(Sender: TObject);
var
desde,hastavalor:string;
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturae.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
{poneetiquetas('Num. Documento','Nombre','Subtotal','Iva','Total','','','','','','');}

{Concentrar(TablaFacturaE,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',FormaFormatos.Inicial.Text,FormaFormatos.Final.Text,'CLDOC_F','NOMBR_F','IMTOD_F','CTOVE_F','&%IMTOD_F&*&%CTOVE_F&*&0.01&','','','','','','','X','','D');}
{dia:=Formaformatos.Inicial.Text;}
Concentrar(TablaFacturaE,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLDOC_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM2_F','','','','','','STATU_F','=','C','D');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
poneetiquetas('Documento','Nombre','Total del Documento','SubTotal','IVA','','','','','','');

parametrosgrafica('Gráfica de Documentos Cancelados','Número de Documento','Total por Documento',1);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;

FormaBarras.Concentrado.Clear;
FormaBarras.Caption:='Reporte de Documentos Cancelados';{+dia;}
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;

FormaFormatos.Free;
FormaBarras.Free;

end;

procedure TFormaCapturaRapida.EditDIVIS_FKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Ord(Char(Key))=13) or (Ord(Char(Key))=40) then
begin
indices:=indices+1;
cursor1;
{indice:=0;
mueveteclas;}

end;

if Ord(Char(Key))=38 then
begin
indices:=indices-1;
cursor1;
end;

end;

procedure TFormaCapturaRapida.EditDIVIS_FEnter(Sender: TObject);
begin
leedivisa;
indices:=5;

end;

procedure TFormaCapturaRapida.EditDIVIS_FExit(Sender: TObject);
begin
{if Editdivis_F.Text='M.N.' then
EditVALDI_F.Text:='1.00';}
end;

procedure TFormaCapturaRapida.Temas1Click(Sender: TObject);
begin
PoneAyuda(leeruta+'\ayuda\factura.rtf',0);
end;

procedure TFormaCapturaRapida.CancelaMovimiento1Click(Sender: TObject);
begin

if (BotonNuevo.Tag=1) then
begin
TablaFacturaE.Delete;
borra;
ponedatos;
desactiva;
end;

if BotonCambios.Tag=1 then
begin
regresabufercambios;
TablaFacturaE.Cancel;
desactiva;
end;

activabotones(True,True,False,True,True,True,False);
BotonNuevo.Tag:=0;
BotonCambios.Tag:=0;
end;

procedure TFormaCapturaRapida.DesgloceporMoneda1Click(Sender: TObject);
var
dia:string[12];
desde,hastavalor:string;
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturae.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaE.TableName,'devoluc.dbf','FactAuxi.dbf','INUMENC');
//Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLCLI_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM1_F','IMIM2_F','','','','','STATU_F','!','C','D');
Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLDOC_F','NOMDI_F','DIVIS_F','SUBTO_F','IMTOD_F','&%SUBTO_F&*&%DIVIS_F&*&1.00&','&%IMTOD_F&*&%DIVIS_F&*&1.00&','','','','STATU_F','!','C','D');
end
else
Concentrar(TablaFacturaE,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLDOC_F','NOMDI_F','DIVIS_F','SUBTO_F','IMTOD_F','&%SUBTO_F&*&%DIVIS_F&*&1.00&','&%IMTOD_F&*&%DIVIS_F&*&1.00&','','','','STATU_F','!','C','D');
dia:=DateToStr(FormaFormatos.Inicial.Date);

poneetiquetas('Documento','Nombre','Valor Div.','SubTotal Divisa','Total Divisa','Subtotal M.N.','Total M.N.','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica Desgloce por Moneda','Número de Documento','Total por Moneda',3);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;

FormaBarras.Concentrado.Clear;
FormaBarras.Caption:='Reporte Desgloce por monedas';
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;

end;

procedure TFormaCapturaRapida.EditDESFI_FKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (key=13) then
Detalle.SetFocus;
end;

procedure TFormaCapturaRapida.DetalleKeyPress(Sender: TObject; var Key: Char);
begin
key:=CambiaLetras(key);
end;

procedure TFormaCapturaRapida.DetalleEnter(Sender: TObject);
begin
//Facturable:=False;
try
Detalle.SelectedIndex:=0;

if TablaDeta.FieldByName('Cantidad').AsFloat<=0 then
begin
if  TablaDeta.RecordCount=0 then
begin
TablaDeta.Append;
TablaDeta.FieldByName('Cantidad').AsFloat:=1;
Detalle.SelectedIndex:=1;
EditClave.SetFocus;
end;
end;

except

end;

end;



procedure TFormaCapturaRapida.Edit1Exit(Sender: TObject);
var
camb:real;
begin
camb:=0;
if CAMBIO_F.Text<>'' then
begin
camb:=StrTofloat(CAMBIO_F.Text)-total1;

SuCambio.Caption:='Cambio '+Convierte('###,##0.00',FloatToStr(camb),'$');

end;
end;


procedure TFormaCapturaRapida.CAMBIO_FExit(Sender: TObject);
var
camb:real;
begin
camb:=0;
if CAMBIO_F.Text<>'' then
begin
camb:=StrTofloat(CAMBIO_F.Text)-total1;

SuCambio.Caption:='Camb.'+Convierte('###,##0.00',FloatToStr(camb),'$');

end;
end;


procedure TFormaCapturaRapida.CAMBIO_FKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
camb:real;
begin
if key=117 then
begin

camb:=0;
if CAMBIO_F.Text<>'' then
begin
camb:=StrTofloat(CAMBIO_F.Text)-total1;

SuCambio.Caption:='Cambio '+Convierte('###,##0.00',FloatToStr(camb),'$');

end;
end;//if f6

if key=13 then
CAMBIO_FExit(Sender);

end;

procedure TFormaCapturaRapida.VerFunciones1Click(Sender: TObject);
begin
MuestraMensaje('Ctrl+F1    Ver Funciones'+Char(13)+
               'Ctrl+F4    Inserta Comentario'+Char(13)+
               'Ctrl+N     Nuevo Documento'+Char(13)+
               'Ctrl+G     Guarda Documento'+Char(13)+
               'Ctrl+F5    Introducir Efectivo'+Char(13)+
               'Ctrl+F6    Calcular Cambio'+Char(13)+
               'Ctrl+F7    Inicia Captura de Partidas'+Char(13)+
               'Ctrl+B     Buscar'+Char(13)+
               'Ctrl+I     Imprimir'+Char(13)

               );

end;

procedure TFormaCapturaRapida.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
try

if key=33 then
TablaDeta.Prior;

if key=34 then
TablaDeta.Next;


if key=115 then
EditCantidad.SetFocus;


if key=118 then
Detalle.SetFocus;


if key=117 then
CAMBIO_FExit(Sender);

if key=119 then
TipoPago.SetFocus;

{if key=120 then
begin
  BotonNuevoClick(Sender);

end;

if key=121 then
begin
BotonGuardarClick(Sender);
Detalle.SetFocus;
end;}

except
end;
end;

procedure TFormaCapturaRapida.DetalleColExit(Sender: TObject);
begin
   if Detalle.SelectedIndex=3 then
   begin
   TablaDeta.Edit;
   TablaDeta.FieldByName('Importe').AsFloat:=TablaDeta.FieldByName('Cantidad').AsFloat*TablaDeta.FieldByName('Precio').AsFloat;
   TablaDeta.FieldByName('Importe').AsFloat:=TablaDeta.FieldByName('Importe').AsFloat-(TablaDeta.FieldByName('Importe').AsFloat*TablaDeta.FieldByName('Descuento').AsFloat/100);
   TablaDeta.Post;
   end;

end;

procedure TFormaCapturaRapida.UtilidadporProducto1Click(Sender: TObject);
var
desde,hastavalor:string;
begin
{FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturad.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);
//valoresiniciales('','','','');
FormaFormatos.ShowModal;

if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaD.TableName,'devolucd.dbf','FactAuxiD.dbf',TablaFacturaD.IndexName);
//Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLCLI_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM1_F','IMIM2_F','','','','','STATU_F','!','C','D');
Concentrar(TablaAuxiliar,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_FD',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLDOC_FD','CLPRO_FD','CANTI_FD','&%CANTI_FD&*&%COPRO_FD&*1.00&','&%IMPOR_FD&+&%IMPOR_FD&*&0.4347826086957&','','','','','','TREGI_FD','!','C','D');
end
else
Concentrar(TablaFacturaD,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_FD',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLDOC_FD','CLPRO_FD','CANTI_FD','&%CANTI_FD&*&%COPRO_FD&*1.00&','&%IMPOR_FD&+&%IMPOR_FD&*&0.4347826086957&','','','','','','TREGI_FD','!','C','D');

poneetiquetas('Documento','Clave','-Cantidad','CostoxCantidad','PrecioxCantidad','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica de Ventas y Utilidades','Número de Documento','Total por Documento',2);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;

FormaBarras.Concentrado.Clear;
FormaBarras.Caption:='Reporte de Ventas y Utilidades';
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;}


FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturad.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','',desde,hastavalor);
//valoresiniciales('','','','');
FormaFormatos.ShowModal;

if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
if FormaFormatos.IncluirDevoluciones.Checked then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaD.TableName,'devolucd.dbf','FactAuxiD.dbf',TablaFacturaD.IndexName);
//Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLCLI_F','NOMBR_F','IMTOD_F','SUBTO_F','IMIM1_F','IMIM2_F','','','','','STATU_F','!','C','D');
Concentrar(TablaAuxiliar,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_FD',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLDOC_FD','CLPRO_FD','CANTI_FD','&%CANTI_FD&*&%COPRO_FD&*1.00&','&%IMPOR_FD&+&%IMPOR_FD&*&0.4347826086957&','','','','','','TREGI_FD','!','C','D');
end
else
Concentrar(TablaFacturaD,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_FD',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLDOC_FD','CLPRO_FD','CANTI_FD','&%CANTI_FD&*&%COPRO_FD&*1.00&','IMPOR_FD','&%IMPOR_FD&-&%IMPOR_FD&*&0.4347826086957&','','','','','TREGI_FD','!','C','D');

poneetiquetas('Documento','Clave','-Cantidad','CostoxCantidad','PrecioxCantidad','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica de Ventas y Utilidades','Número de Documento','Total por Documento',2);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;

FormaBarras.Concentrado.Clear;
FormaBarras.Caption:='Reporte de Ventas y Utilidades';
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;

end;


procedure TFormaCapturaRapida.FacturadeCierre1Click(Sender: TObject);
var
inicio,fin,ultimo:integer;
Aux:string[1];
begin
DialogoImprimir:=TDialogoImprimir.Create(Application);
inicio:=0;
fin:=0;
RangoDocumentos:=False;
DialogoImprimir.Tag:=0;
DialogoImprimir.PrimeraPagina.Text:=DatetoStr(date);
DialogoImprimir.UltimaPagina.Text:=DatetoStr(date);
DialogoImprimir.ShowModal;

if DialogoImprimir.Tag=1 then
begin

Aux:=Base.Text;
Orig:=Aux+EditCLDOC_F.Text;


TablaFacturaE.Last;
fin:=TablaFacturaE.FieldByName('CLDOC_F').AsInteger;
while not TablaFacturaE.BOF do
begin
if TablaFacturaE.FieldByName('FEDOC_F').AsDateTime>=StrToDate(DialogoImprimir.PrimeraPagina.Text)then
inicio:=TablaFacturaE.FieldByName('CLDOC_F').AsInteger
else
break;;

TablaFacturaE.Prior;
end;//while
if inicio<>0 then
begin
LeeDetallecierre(IntToStr(inicio),IntTostr(fin),DialogoImprimir.PrimeraPagina.Text);


//***************************************
PrecioNumero:=1;
Hora.Caption:=TimeToStr(Time);
{*********}
TablaFacturaE.Last;
Ultimo:=TablaFacturaE.FieldByName('CLDOC_F').AsInteger;
TablaFacturae.Insert;

{***********************}

if TablaFacturaE.State=dsInsert then
begin

TablaFacturae.FieldByName('CLDOC_F').AsInteger:=Ultimo+1;
TablaFacturae.FieldByName('CLVEN_F').AsString:=ultimovendedor;
TablaFacturae.Post;
saldoanterior:=0;
borradatoscliente;
//borra;
BotonNuevo.Tag:=1;
BotonCambios.Tag:=0;
Caja.Enabled:=True;
local:=True;
TablaFacturae.Edit;
EditCLCLI_F.Visible:=True;
activa;
EditFEDOC_F.Text:=DateToStr(Date);
configuracion;
indice:=0;
sig:=1;
{****totales****}
SumarTotal.Caption:=convierte('###,###,##0.00','0','$');
ImpuestoValor.Caption:=convierte('###,###,##0.00','0','$');
TotalFact.Caption:=convierte('###,###,##0.00','0','$');
{**************}
activabotones(False,False,True,False,False,False,True);

EditCLDOC_F.SetFocus;
EditCLCLI_F.Text:='1';
TablaFacturaE.FieldByName('CLCLI_F').AsString:='100';
TablaFacturaE.FieldByName('FEDOC_F').AsString:=DialogoImprimir.PrimeraPagina.Text;
TablaFacturaE.FieldByName('IMIM1_F').AsString:=EditIMIM1_F.Text;
TablaFacturaE.FieldByName('DESFI_F').AsString:=EditDESFI_F.Text;

end;//if insert

//******************************



//***********manda los datos a la factura
Base.Tag:=1;
{while not TablaFacturaD.EOF do
begin
TablaFacturaD.Edit;
TablaFacturaD.FieldByName('TREGI_FD').AsString:='F';
TablaFacturaD.Post;
TablaFacturaD.Next;
end;}

bufercambios('C');
TablaFacturaE.Delete;
generadocumento('F');
TablaFacturaD.First;
activa;
EditCLDOC_F.SetFocus;
local:=True;
TablaFacturaE.Edit;
end;//if iicio<>0

end;//if dialogoimprimir

DialogoImprimir.Free;
end;

procedure TFormaCapturaRapida.CortedeCaja1Click(Sender: TObject);
var
dia:string[12];
desde,hastavalor:string;

begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,true,False,true,true,true,true,'facturae.dbf');
TablaFacturaE.First;
desde:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
TablaFacturaE.Last;
hastavalor:=TablaFacturaE.FieldByName('CLDOC_F').AsString;
valoresiniciales('','','','');

FormaFormatos.ShowModal;

if FormaFormatos.Tag=1 then
begin
GeneraCorteDeCaja(FormaFormatos.Inicial.Date,FormaFormatos.Final.Date,TablaFacturaE.TableName,'devoluc.dbf','FactAuxi.dbf',TablaFacturaE.IndexName);

condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,'Y');
{poneetiquetas('Num. Documento','Nombre','Subtotal','Iva','Total','','','','','','');}
{Concentrar(TablaFacturaE,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',FormaFormatos.Inicial.Text,FormaFormatos.Final.Text,'CLDOC_F','NOMBR_F','IMTOD_F','CTOVE_F','&%IMTOD_F&*&%CTOVE_F&*&0.01&','','','','','','','X','','D');}
dia:=DateToStr(FormaFormatos.Inicial.Date);
Concentrar(TablaAuxiliar,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'FEDOC_F',DateToStr(FormaFormatos.Inicial.Date),DateToStr(FormaFormatos.Final.Date),'CLDOC_F','NOMBR_F','IMTOD_F','SUBTO_F','','','','','','','STATU_F','!','C','D');
poneetiquetas('Documento','Nombre','Total del Documento','SubTotal','','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica de Consecutivo de Documentos','Número de Documento','Total por Documento',1);

FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;

FormaBarras.Concentrado.Clear;
FormaBarras.Caption:='Reporte de Documentos por Periodo ';
FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;

end;

procedure TFormaCapturaRapida.CAMBIO_FEnter(Sender: TObject);
begin
sumatotal;
end;

procedure TFormaCapturaRapida.RangodeDocumentos1Click(Sender: TObject);
var
aux:string[1];
op:char;
begin
FormaRango:=TFormaRango.Create(Application);
if Base.Text='Cotización' then
begin
FormaRango.Factura.Enabled:=True;
FormaRango.Remision.Enabled:=True;
FormaRango.Pedido.Enabled:=True;
end;

if Base.Text='Pedido' then
begin
FormaRango.Factura.Enabled:=True;
FormaRango.Remision.Enabled:=True;
FormaRango.Pedido.Enabled:=False;
end;

if Base.Text='Remisión' then
begin
FormaRango.Factura.Enabled:=True;
FormaRango.Remision.Enabled:=False;
FormaRango.Pedido.Enabled:=False;
end;

FormaRango.Tag:=0;
FormaRango.ShowModal;


if FormaRango.Factura.Checked=True then
Aux:=FormaRango.Factura.Caption;

if FormaRango.Remision.Checked=True then
Aux:=FormaRango.Remision.Caption;

if FormaRango.Pedido.Checked=True then
Aux:=FormaRango.Pedido.Caption;

if FormaRango.Tag =1 then
begin
//Aux:=Base.Text;
Orig:=Aux+EditCLDOC_F.Text;
RangoDocumentos:=True;
Base.Tag:=1;
bufercambios('C');
op:=Aux[1];
generadocumento(op);
activa;
EditCLDOC_F.SetFocus;
local:=True;
TablaFacturaE.Edit;
activabotones(False,False,True,False,False,False,True);
end;

FormaRango.Free;
end;

procedure TFormaCapturaRapida.ConfigurarCaja1Click(Sender: TObject);
var
arch:TextFile;
begin
Assignfile(arch,leeruta+'\caja.cnf');
ReWrite(arch);
Writeln(arch,EditBCLIM_F.Text);

CloseFile(arch);

end;

procedure TFormaCapturaRapida.FormShow(Sender: TObject);
var
arch:TextFile;
linea:string;
begin
CajaLocal:='';
if FileExists(leeruta+'\caja.cnf') then
begin
Assignfile(arch,leeruta+'\caja.cnf');
Reset(arch);
Readln(arch,LINEA);
CajaLocal:=linea;
CloseFile(arch);
end;//if

end;

procedure TFormaCapturaRapida.DetalleDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
if Digitos>0 then
Detalle.Fields[DataCol].OnGetText:=MyOnGetText;
end;













procedure TFormaCapturaRapida.EditClaveKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
case key of
13:
begin
 if (TablaDeta.State=dsEdit)or(TablaDeta.State=dsInsert) then
 begin
 TablaDeta.Post;
 TablaDeta.Edit;
 end;
 Detalle.SelectedIndex:=2;

end;


113:
begin
Detalle.Tag:=3;
TablaDeta.Edit;
TablaDeta.Post;
TablaDeta.Edit;
FormaCapturaRapida.TablaDeta.FieldByName('clave').AsString:=BuscaClave(FormaCapturaRapida.TablaDeta.FieldByName('clave').AsString,1);
EditClave.SetFocus;
end;

end;//case

end;



procedure TFormaCapturaRapida.EditCantidadKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
if key=13 then
EditClave.SetFocus;
end;



procedure TFormaCapturaRapida.SaltarEncabezado1Click(Sender: TObject);
var
arch:TextFile;
begin
   SaltarEncabezado1.Checked:=not SaltarEncabezado1.Checked;
if SaltarEncabezado1.Checked then
begin
Assignfile(arch,leeruta+'\encabeza.cnf');
ReWrite(arch);
Writeln(arch,'S');
Writeln(arch,'S');
CloseFile(arch);
end
else
begin
Assignfile(arch,leeruta+'\encabeza.cnf');
ReWrite(arch);
Writeln(arch,'N');
Writeln(arch,'N');

CloseFile(arch);


end;

end;

end.

