by jnavas » Wed Apr 27, 2022 9:57 am
Saludos
Publico el codigo que utilizo con bematech
#include "..\INCLUDE\DPXBASE.CH"
MEMVAR oDp
/*
// Inicializa la Impresora
*/
FUNCTION BEMA_INI()
LOCAL nRet,cError:="",I
LOCAL cWinDir :=GetWinDir()+"\System32\"
LOCAL cFileDll:=cWinDir+"bemafi32.dll"
LOCAL aDlls:={}
DEFAULT oDp:lBema_Demo :=.T.,;
oDp:aBema_Tasas:={}
IF !File(cFileDll)
AADD(aDlls,"bemafi32.dll")
AADD(aDlls,"bemafi32.ini")
FOR I := 1 TO len(aDlls)
IF !File(cWinDir+aDlls[I])
__COPYFILE("BEMATECH\"+aDlls[I],cWinDir+aDlls[I])
ENDIF
NEXT
ENDIF
DEFAULT oDp:nBemaDll:=LoadLibrary("bemafi32.dll")
nRet:=BmPrintLig()
cError:=BEMA_ERROR(nRet,.F.)
RETURN cError
/*
// Mensajes de Error
*/
FUNCTION BEMA_ERROR(nRet,lShow)
LOCAL cError:=""
DEFAULT lShow:=.T.
IF nRet=1
RETURN ""
ENDIF
DO CASE
CASE nRet= -1
cError:="Parámetro inválido"
CASE nRet= -2
cError:="Parámetro Inválido"
CASE nRet=-3
cError:="Aliquota no programada"
CASE nRet=-4
cError:="Archivo BemaFI32.INI no encontrado, copielo en c:\windows\system32"
CASE nRet=-5
cError:="Error en Apertura, Posiblemente ya está Abierto el Puerto"
CASE nRet=-6
cError:="Ninguna Impresora fué Encontrada, Verifique si está Encendida o Conectada al Cable Serial"
CASE nRet = -8
cError:="Error al Crear o Grabar en el Archivo status.txt o retorno.txt "
ENDCASE
cError:="Error:"+LSTR(nRet)+", "+cError
IF lShow
MensajeErr(cError,"Error Impresora Bematech")
ENDIF
RETURN cError
/*
// Finaliza la Impresora
*/
FUNCTION BEMA_END()
IF oDp:nBemaDll<>NIL
FreeLibrary(oDp:nBemaDll)
oDp:nBemaDll:=NIL
ENDIF
RETURN .T.
PROCE XBEMA()
LOCAL nRet ,cRif:=PADR("Nombre del Cliente",41)+PADR("RIF",18)
LOCAL nNumImp:=0,I,uBuf,cTasas:=SPACE(79)
/*
SET DATE FREN
SET CENTU OFF
oDp:nBemaDLL = LoadLibrary("bemafi32.dll")
IF xDll=0
MsgAlert("bemafi32.dll","No existe")
RETURN
ENDIF
aTasas:={}
lDemo:=.T.
nRet:=BmPrintLig()
IF nRet=-4
? "Archivo BemaFI32.INI no encontrado, copielo en c:\windows\system32"
return
Endif
IF nRet=-5
? "Error en Apertura, Posiblemente ya está Abierto el Puerto"
RETURN
ENDIF
if nRet=-6
? "Ninguna Impresora fué Encontrada, Verifique si está Encendida o Conectada al Cable Serial"
return
Endif
? "Impresora existentes",nRet
IF !lDemo // Solo lo Devuelve el Modo Fiscal
? "Detectando Caja"
nNumImp:=BmNumeroCx()
? nNumImp
ENDIF
*/
// ? nNumImp,"Numero de Impresora"
uBuf := 0
nRet := BmFlagFiscal(@uBuf)
// nNumImp:=BmNumeroCx() Numero de Caja Solo en Modo Fiscal, de lo Contrario genera Error
//
// ? nRet,uBuf
// CambiarTasas()
// BemaTechZ()
// ? BemaProgAlicuota( "1200"),"Grabando Tasa 1200"
BemaLeerAlicuota(@cTasas)
// AADD(aTasas,{1,12.00}) // Tasas según Lectura de la Impresora
// ? cTasas,"cTasas"
// ? "AHORA ABRIMOS EL CUPO",LEN(cRif)
//FOR I=1 TO 59 //LEN(cRif)
// cRif:=REPLI("A",I)
nRet := BmAbreCup(cRif)
// ? nRet,cRif,I
//NEXT
// ? nRet,"BmAbreCup",cRif
// nRet := BmFechaCup(uPar[1],uPar[2],uPar[3],uPar[4],uPar[5],uPar[6])
// RETURN .T.
FUNCTION CAMBIARTASAS()
? "Es necesario Emitir Reporte Z"
IF MsgYesNo("Cambiar Tasas ")
BematechZ()
BemaProgAlicuota( "1400")
ENDIF
RETURN .T.
FUNCTION BemaTechZ()
LOCAL cFecha:=DTOC(DATE())
LOCAL cHora :=TIME()
// MsgAlert(cFecha)
// MsgAlert(cHora)
? BemaReporteZeta(cFecha,cHora),"REPORTEZ"
RETURN .T.
FUNCTION ISWINXP()
RETURN .T.
//Faz abertura do dia
// DLL32 FUNCTION LECTURA ( cPort AS LPSTR ) AS LONG PASCAL ;
// FROM "IniPuertaStr" LIB oDp:nBemaDLL
//DLL32 FUNCTION LECTURA( cPort AS STRING ) AS LONG PASCAL FROM "IniPuertaStr";
// LIB "oDp:nBemaDLL."
DLL32 FUNCTION BmPrintLig( ) AS LONG PASCAL ;
FROM "Bematech_FI_VerificaImpressoraLigada" LIB oDp:nBemaDLL
//Ler número do caixa
DLL32 FUNCTION BmNumeroCx( NumeroCaixa AS LPSTR ) AS LONG PASCAL ;
FROM "Bematech_FI_NumeroCaja" LIB oDp:nBemaDLL
DLL32 FUNCTION BmAbreCup ( cData AS LPSTR ) AS LONG PASCAL ;
FROM "Bematech_FI_AbreComprobanteDeVenta" LIB oDp:nBemaDLL
DLL32 FUNCTION BmFlagFiscal( @FlagFiscal AS PTR ) AS LONG PASCAL ;
FROM "Bematech_FI_FlagsFiscales" LIB oDp:nBemaDLL
DLL32 FUNCTION BmFechaCup( FormaPgto AS STRING,;
Acrescimo AS STRING,;
TipoAcresc AS STRING,;
ValorAcresc AS STRING,;
ValorPago AS STRING,;
Mensagem AS STRING ) AS LONG PASCAL ;
FROM "Bematech_FI_CierraCupon" LIB oDp:nBemaDLL
// Juan Navas
DLL32 FUNCTION BemaLeerAlicuota( @cTasas AS LPSTR) AS LONG PASCAL ;
FROM "Bematech_FI_RetornoAlicuotas" LIB oDp:nBemaDLL
/*
// Antes de Asignar las Tasas es necesario Emitir el Reporte Z
*/
DLL32 FUNCTION BemaProgAlicuota( cTasas AS LPSTR) AS LONG PASCAL ;
FROM "Bematech_FI_ProgramaAlicuota" LIB oDp:nBemaDLL
//Emite redução Z
DLL32 FUNCTION BemaReporteZeta( Dt AS LPSTR, Hs AS LPSTR ) AS LONG PASCAL ;
FROM "Bematech_FI_ReduccionZ" LIB oDp:nBemaDLL
// Kleyber (Brasil)
DLL32 FUNCTION BmSubTotal( SubTotal AS LPSTR ) AS LONG PASCAL ;
FROM "Bematech_FI_SubTotal" LIB oDp:nBemaDLL
//Ler número do caixa
//DLL32 FUNCTION BmNumeroCx( NumeroCaixa AS LPSTR ) AS LONG PASCAL ;
// FROM "Bematech_FI_NumeroCaja" LIB oDp:nBemaDLL
//Ler configuração arredondamento/truncamento
DLL32 FUNCTION BmVerArred( Arredonda AS LPSTR ) AS LONG PASCAL ;
FROM "Bematech_FI_VerificaTruncamiento" LIB oDp:nBemaDLL
//Ativa arredondamento
DLL32 FUNCTION BmLigArred( ) AS LONG PASCAL ;
FROM "Bematech_FI_ProgramaRedondeo" LIB oDp:nBemaDLL
//Ler data do movimento
DLL32 FUNCTION BmDtMovto ( DtMovto AS LPSTR ) AS LONG PASCAL ;
FROM "Bematech_FI_FechaMovimiento" LIB oDp:nBemaDLL
//Ler flag fiscal da impressora
DLL32 FUNCTION BmFlagFisc( @FlagFiscal AS PTR ) AS LONG PASCAL ;
FROM "Bematech_FI_FlagsFiscales" LIB oDp:nBemaDLL
//Emite leitura X
DLL32 FUNCTION BmLeituraX( ) AS LONG PASCAL ;
FROM "Bematech_FI_LecturaX" LIB oDp:nBemaDLL
//Emite redução Z
DLL32 FUNCTION BmReducaoZ( Dt AS LPSTR, Hs AS LPSTR ) AS LONG PASCAL ;
FROM "Bematech_FI_ReduccionZ" LIB oDp:nBemaDLL
//Ler data e hora da impressora
DLL32 FUNCTION BmDtHora ( Dt AS LPSTR, Hs AS LPSTR ) AS LONG PASCAL ;
FROM "Bematech_FI_FechaHoraImpresora" LIB oDp:nBemaDLL
//Faz abertura do dia
DLL32 FUNCTION BmAbreDia ( Vl AS LPSTR, Fr AS LPSTR ) AS LONG PASCAL ;
FROM "Bematech_FI_AberturaDoDia" LIB oDp:nBemaDLL
//Abre cupom fiscal
//DLL32 FUNCTION BmAbreCup ( Cgc AS LPSTR ) AS LONG PASCAL ;
// FROM "Bematech_FI_AbreComprobanteDeVenta" LIB oDp:nBemaDLL
//Verifica se tem papel
DLL32 FUNCTION BmVerPapel( @Linhas AS PTR ) AS LONG PASCAL ;
FROM "Bematech_FI_MonitoramentoPapel" LIB oDp:nBemaDLL
//Verifica se tem impressora ligada
//DLL32 FUNCTION BmPrintLig( ) AS LONG PASCAL ;
// FROM "Bematech_FI_VerificaImpressoraLigada" LIB oDp:nBemaDLL
//Cancela cupom fiscal
DLL32 FUNCTION BmCanCupom( ) AS LONG PASCAL ;
FROM "Bematech_FI_CierraCupon" LIB oDp:nBemaDLL
//Cancela último ítem do cupom
DLL32 FUNCTION BmCancItem( ) AS LONG PASCAL ;
FROM "Bematech_FI_AnulaArticuloAnterior" LIB oDp:nBemaDLL
//Abre a gaveta
DLL32 FUNCTION BmAbreGav ( ) AS LONG PASCAL ;
FROM "Bematech_FI_AccionaGaveta" LIB oDp:nBemaDLL
//Ler número do cupom
DLL32 FUNCTION BmNumCupom( @cCupon AS LPSTR ) AS LONG PASCAL ;
FROM "Bematech_FI_NumeroCupon" LIB oDp:nBemaDLL
//Emite leitura da memória fiscal por data
DLL32 FUNCTION BmMemFiscD( In AS LPSTR, Fi AS LPSTR ) AS LONG PASCAL ;
FROM "Bematech_FI_LecturaMemoriaFiscalFecha" LIB oDp:nBemaDLL
//Emite leitura da memória fiscal por reduções
DLL32 FUNCTION BmMemFiscR( In AS LPSTR, Fi AS LPSTR ) AS LONG PASCAL ;
FROM "Bematech_FI_LecturaMemoriaFiscalReduccion" LIB oDp:nBemaDLL
//Emite cupom gerencial
DLL32 FUNCTION BmCpGerAbr( Texto AS STRING ) AS LONG PASCAL ;
FROM "Bematech_FI_CierraInformeGerencial" LIB oDp:nBemaDLL
//Fecha cupom gerencial
DLL32 FUNCTION BmCpGerFec( ) AS LONG PASCAL ;
FROM "Bematech_FI_CierraInformeGerencial" LIB oDp:nBemaDLL
//Verifica status da gaveta
DLL32 FUNCTION BmStGaveta( @nStatus AS PTR ) AS LONG PASCAL ;
FROM "Bematech_FI_VerificaEstadoGaveta" LIB oDp:nBemaDLL
//Abre cupom adicional
DLL32 FUNCTION BmCupAdAbr( FormaPgto AS STRING,;
Valor AS STRING,;
Cupom AS STRING ) AS LONG PASCAL ;
FROM "Bematech_FI_AbreComprobanteNoFiscalVinculado" LIB oDp:nBemaDLL
//Imprime cupom não fiscal vinculado
DLL32 FUNCTION BmCupAdUsa( Texto AS STRING ) AS LONG PASCAL ;
FROM "Bematech_FI_ImprimeComprobanteNoFiscalVinculado" LIB oDp:nBemaDLL
//Fecha cupom não fiscal
DLL32 FUNCTION BmCupAdFec( ) AS LONG PASCAL ;
FROM "Bematech_FI_CierraComprobanteNoFiscalVinculado" LIB oDp:nBemaDLL
//Vende ítem
DLL32 FUNCTION BmVendItem( Codigo AS STRING,;
Descricao AS STRING,;
Aliquota AS STRING,;
TpQte AS STRING,;
Quantid AS STRING,;
Decimal AS 7 ,;
ValUnit AS STRING,;
TpDesc AS STRING,;
ValDesc AS STRING ) AS LONG PASCAL ;
FROM "Bematech_FI_VendeArticulo" LIB oDp:nBemaDLL
//Efetua Formas de Pagamento
DLL32 FUNCTION BmFormasPag( FormaPgto AS STRING,;
ValorPago AS STRING ) AS LONG PASCAL ;
FROM "Bematech_FI_EfectuaFormaPago" LIB oDp:nBemaDLL
//Inicia Fechamento cupom
DLL32 FUNCTION BmIniFecCup( Acrescimo AS STRING,;
TipoAcresc AS STRING,;
ValorAcresc AS STRING ) AS LONG PASCAL ;
FROM "Bematech_FI_IniciaCierreCupon" LIB oDp:nBemaDLL
//Termina Fechamento cupom
DLL32 FUNCTION BmTerFecCup( Mensagem AS STRING ) AS LONG PASCAL ;
FROM "Bematech_FI_FinalizarCierreCupon" LIB oDp:nBemaDLL
//Fecha cupom com uma forma de pagamento somente
//DLL32 FUNCTION BmFechaCup( FormaPgto AS STRING,;
// Acrescimo AS STRING,;
// TipoAcresc AS STRING,;
// ValorAcresc AS STRING,;
// ValorPago AS STRING,;
// Mensagem AS STRING ) AS LONG PASCAL ;
// FROM "Bematech_FI_CierraCupon" LIB oDp:nBemaDLL
//Verifica status do gerenciador padrão
DLL32 FUNCTION BmTfStatus( Operacao AS LPSTR ) AS LONG PASCAL;
FROM "Bematech_FITEF_Status" LIB oDp:nBemaDLL
DLL32 FUNCTION BmSimboloMoneda( cMoneda AS LPSTR ) AS LONG PASCAL;
FROM "Bematech_FI_CambiaSimboloMoneda" LIB oDp:nBemaDLL
DLL32 FUNCTION BmAbreNotaDeCredito( cNombre AS LPSTR,; // Nombre del Cliente
cSerie AS LPSTR,; // Serie de la Impresora
cRif AS LPSTR,; // Rif
cDias AS LPSTR,; // Dia
cMes AS LPSTR,; // Mes
cAno AS LPSTR,; // Año
cHora AS LPSTR,; // Hora
cMin AS LPSTR,; // Min
cSeg AS LPSTR,; // Seg
cCupon AS LPSTR ) AS LONG PASCAL;
FROM "Bematech_FI_AbreNotaDeCredito" LIB oDp:nBemaDLL
/*
Bematech_FI_AbreNotaDeCredito(
char * Nome, char * Serie, char * Rif,
char * Dia, char * Mes, char * Ano,
char * Hora, char * Minuto, char * Segundo,
char * COO);
*/
DLL32 FUNCTION BmLecturaX() AS LONG PASCAL;
FROM "Bematech_FI_LecturaX" LIB oDp:nBemaDLL