No pude hacerlo solo con Fivewin, asi que recurrí a PHP. Básicamente tengo un PRG que lee un dbf donde estan los datos de la factura, y genero un .txt con datos como cuit, tipo de comprobante, importe total, importe exento... etc.
Luego con PHP levanto esa info y completo donde corresponde...
Para que funcione hay que tener un certificado que da el afip, cuyo path esta en los archivos .php, y luego el .wsdl; el path de este ultimo tambien esta en el .php. Luego es cuestion de probar la conexión. Si cambian el wsdl (que es el del sitio de pruebas de afip) por el de producción, debería funcionar sin problemas. Para obtener el certificado hay instructivos en internet... se usa el OpenSSL-Win32. Busquen...
Despues, apra que corra php, tiene que instalarlo... se corre por linea de comandos... yo baje una herramienta integrada que se llama xampp... con el php que trae esto anda de 10... hay que poner un path y un set y listo...
Aviso... no es tan, tan fácil... pero... si yo lo pude hacer... lo puede hacer cualquiera... Abrazo a todos...!!!
Aca pego el PHP:
- Code: Select all Expand view RUN
- <?php
# Author: Gerardo Fisanotti - AFIP/SDGSIT/DiITEC/DeARIN - 4-oct-10
# Function: Show a basic functionality WSFEV1 SOAP client
#
# This program is supposed to be executed from the CLI, not under Apache control
# it should be invoked from the command line, like this:
#
# $ php wsfev1-client.php
#
# Depending of the methods invoked (see main program at the end of this file),
# this program will generate varios files in your default directory with the
# results obtained.
# If LOG_XMLS is TRUE, then, this program will log various files in the default
# directory, containing the request/response SOAP XML of each method invoked.
# In order to use this program you need a Ticket de Acceso (TA.xml) as provided
# by WSAA.
# The main program is at the end of this source, check it an uncomment/comment
# the lines that invoke the web methods.
#==============================================================================
# You may need to modify the following definitions to adjust to your local
# requirements.
define ("WSDL", "wsfev1.wsdl"); # The WSDL corresponding to WSFEX
define ("URL", "https://wswhomo.afip.gov.ar/wsfev1/service.asmx");
define ("TA", "TA.xml"); # Ticket de Acceso, from WSAA
define ("CUIT", 20265612769); # CUIT del emisor de las FC/NC/ND
define ("PROXY_HOST", "10.20.152.112"); # Proxy IP, to reach the Internet
define ("PROXY_PORT", "80"); # Proxy TCP port
define ("LOG_XMLS", TRUE); # For debugging purposes
#==============================================================================
function CheckErrors($results, $method, $client)
{
$descriptor1=fopen("c:\\tempo\\errorcae.txt", "w");
if (LOG_XMLS)
{
file_put_contents("request-".$method.".xml",$client->__getLastRequest());
file_put_contents("response-".$method.".xml",$client->__getLastResponse());
}
if (is_soap_fault($results))
{ fwrite($descriptor1,$results->faultcode."\n".$results->faultstring);
fclose($descriptor1);
printf("Fault: %s\nFaultString: %s\n",
$results->faultcode, $results->faultstring);
exit (1);
}
$Y=$method.'Result';
$X=$results->$Y;
if (isset($X->Errors))
{
foreach ($X->Errors->Err as $E)
{
fwrite($descriptor1,$E->Code."\n".$E->Msg."\n");
fclose($descriptor1);
printf("Method=%s / Code=%s / Msg=%s\n",$method, $E->Code, $E->Msg);
}
exit (1);
}
}
#==============================================================================
function FEDummy($client)
{
$results=$client->FEDummy();
CheckErrors($results, 'FEDummy', $client);
printf("Appserver: %s\nDbserver: %s\nAuthserver: %s\n",
$results->FEDummyResult->AppServer,
$results->FEDummyResult->DbServer,
$results->FEDummyResult->AuthServer);
}
#==============================================================================
function FEParamGetCotizacion ($client, $token, $sign, $CUIT, $MON)
{
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$params->MonId = $MON;
$results=$client->FEParamGetCotizacion($params);
CheckErrors($results, 'FEParamGetCotizacion', $client);
$X=$results->FEParamGetCotizacionResult->ResultGet;
printf("Id=%s / Cotiz=%f / Fecha=%s\n", $X->MonId, $X->MonCotiz,
$X->FchCotiz);
return $X->MonCotiz;
}
#==============================================================================
function FEParamGetTiposTributos ($client, $token, $sign, $CUIT)
{
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$results=$client->FEParamGetTiposTributos($params);
CheckErrors($results, 'FEParamGetTiposTributos', $client);
$X=$results->FEParamGetTiposTributosResult;
$fh=fopen("TiposTributos.txt","w");
foreach ($X->ResultGet->TributoTipo as $Y)
{
fwrite($fh,sprintf("%5s %-30s\n",$Y->Id, $Y->Desc));
}
fclose($fh);
}
#==============================================================================
function FEParamGetTiposMonedas ($client, $token, $sign, $CUIT)
{
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$results=$client->FEParamGetTiposMonedas($params);
CheckErrors($results, 'FEParamGetTiposMonedas', $client);
$X=$results->FEParamGetTiposMonedasResult;
$fh=fopen("TiposMonedas.txt","w");
foreach ($X->ResultGet->Moneda as $Y)
{
fwrite($fh,sprintf("%5s %-30s\n",$Y->Id, $Y->Desc));
}
fclose($fh);
}
#==============================================================================
function FEParamGetTiposIva ($client, $token, $sign, $CUIT)
{
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$results=$client->FEParamGetTiposIva($params);
CheckErrors($results, 'FEParamGetTiposIva', $client);
$X=$results->FEParamGetTiposIvaResult;
$fh=fopen("TiposIva.txt","w");
foreach ($X->ResultGet->IvaTipo as $Y)
{
fwrite($fh,sprintf("%5s %-30s\n",$Y->Id, $Y->Desc));
}
fclose($fh);
}
#==============================================================================
function FEParamGetTiposOpcional ($client, $token, $sign, $CUIT)
{
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$results=$client->FEParamGetTiposOpcional($params);
CheckErrors($results, 'FEParamGetTiposOpcional', $client);
$X=$results->FEParamGetTiposOpcionalResult;
$fh=fopen("TiposOpcional.txt","w");
foreach ($X->ResultGet->OpcionalTipo as $Y)
{
fwrite($fh,sprintf("%5s %-30s\n",$Y->Id, $Y->Desc));
}
fclose($fh);
}
#==============================================================================
function FECompConsultar1 ($client, $token, $sign, $CUIT, $PV, $TC, $NC)
{
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$params->FeCompConsReq->CbteTipo = $TC;
$params->FeCompConsReq->CbteNro = $NC;
$params->FeCompConsReq->PtoVta = $PV;
$results=$client->FECompConsultar($params);
CheckErrors($results, 'FECompConsultar', $client);
echo "\n\nEl CAE de la factura ".$NC." es ".$results->FECompConsultarResult->ResultGet->CodAutorizacion."\n\n\n";
}
#==============================================================================
function FECompConsultar ($client, $token, $sign, $CUIT, $PV, $TC)
{
$ULT_CBTE=FECompUltimoAutorizado($client, $token, $sign, CUIT, $PV, $TC);
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$params->FeCompConsReq->CbteTipo=$TC;
$params->FeCompConsReq->CbteNro=$ULT_CBTE;
$params->FeCompConsReq->PtoVta=$PV;
$results=$client->FECompConsultar($params);
CheckErrors($results, 'FECompConsultar', $client);
}
#==============================================================================
function FEParamGetTiposConcepto ($client, $token, $sign, $CUIT)
{
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$results=$client->FEParamGetTiposConcepto($params);
CheckErrors($results, 'FEParamGetTiposConcepto', $client);
$X=$results->FEParamGetTiposConceptoResult;
$fh=fopen("TiposConcepto.txt","w");
foreach ($X->ResultGet->ConceptoTipo as $Y)
{
fwrite($fh,sprintf("%5s %-30s\n",$Y->Id, $Y->Desc));
}
fclose($fh);
}
#==============================================================================
function FEParamGetPtosVenta ($client, $token, $sign, $CUIT)
{
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$results=$client->FEParamGetPtosVenta($params);
CheckErrors($results, 'FEParamGetPtosVenta', $client);
$X=$results->FEParamGetPtosVentaResult;
$fh=fopen("PtosVenta.txt","w");
foreach ($X->ResultGet->PtoVentaTipo as $Y)
{
fwrite($fh,sprintf("%5s %-30s\n",$Y->Id, $Y->Desc));
}
fclose($fh);
}
#==============================================================================
function FEParamGetTiposCbte ($client, $token, $sign, $CUIT)
{
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$results=$client->FEParamGetTiposCbte($params);
CheckErrors($results, 'FEParamGetTiposCbte', $client);
$X=$results->FEParamGetTiposCbteResult;
$fh=fopen("TiposCbte.txt","w");
foreach ($X->ResultGet->CbteTipo as $Y)
{
fwrite($fh,sprintf("%5s %-30s\n",$Y->Id, $Y->Desc));
}
fclose($fh);
}
#==============================================================================
function FEParamGetTiposDoc ($client, $token, $sign, $CUIT)
{
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$results=$client->FEParamGetTiposDoc($params);
CheckErrors($results, 'FEParamGetTiposDoc', $client);
$X=$results->FEParamGetTiposDocResult;
$fh=fopen("TiposDoc.txt","w");
foreach ($X->ResultGet->DocTipo as $Y)
{
fwrite($fh,sprintf("%5s %-30s\n",$Y->Id, $Y->Desc));
}
fclose($fh);
}
#==============================================================================
function FECompTotXRequest ($client, $token, $sign, $CUIT)
{
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$results=$client->FECompTotXRequest($params);
CheckErrors($results, 'FECompTotXRequest', $client);
$X=$results->FECompTotXRequestResult;
return $X->RegXReq;
}
#==============================================================================
function FECompUltimoAutorizado ($client, $token, $sign, $CUIT, $PV, $TC)
{
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$params->PtoVta = $PV;
$params->CbteTipo = $TC;
$results=$client->FECompUltimoAutorizado($params);
CheckErrors($results, 'FECompUltimoAutorizado', $client);
$X=$results->FECompUltimoAutorizadoResult;
printf("PV=%s / TC=%s / Ult.Cbte=%s\n",$PV, $TC,$X->CbteNro);
return $X->CbteNro;
}
#==============================================================================
function FECAESolicitar ($client, $params)
{
$descriptor=fopen("c:\\tempo\\cae.txt", "w");
$descriptor1=fopen("c:\\tempo\\errorcae.txt", "w");
$results=$client->FECAESolicitar($params);
CheckErrors($results, 'FECAESolicitar', $client);
$C=$results->FECAESolicitarResult->FeCabResp;
$D=$results->FECAESolicitarResult->FeDetResp;
printf("Resultado Cabecera=%s\n",$C->Resultado);
foreach ($D->FECAEDetResponse as $d)
{
fwrite($descriptor,$d->CAE);
fwrite($descriptor1,$d->Resultado."\n".$d->CAE."\n".$d->CAEFchVto."\n");
printf("Resultado Cbte#%s = %s / CAE=%s / vto=%s\n",
$d->CbteDesde, $d->Resultado, $d->CAE, $d->CAEFchVto);
if (isset($d->Observaciones))
{
foreach ($d->Observaciones->Obs as $O)
{
fwrite($descriptor1,$O->Code." ***** ".$O->Msg."\n");
printf("Obs: Code=%s / Msg=%s\n",$O->Code, $O->Msg);
}
}
}
fclose($descriptor);
fclose($descriptor1);
}
#==============================================================================
function EmitirFC ($client, $token, $sign, $CUIT, $PV, $CANT)
{
$descriptor=fopen("c:\\tempo\\faelec.txt", "r");
$contenido=fread($descriptor,filesize("c:\\tempo\\faelec.txt"));
fclose($descriptor);
$nro_doc=0+substr($contenido,2,11);
$tipo_cbte=0+substr($contenido,13,1);
$punto_vta=0+substr($contenido,14,2);
$cbt_desde=0+substr($contenido,16,15);
$cbt_hasta=0+$cbt_desde;
$imp_total=0+substr($contenido,46,20);
$imp_tot_conc=0+substr($contenido,66,20);
$imp_neto=0+substr($contenido,86,20);
$impto_liq=0+substr($contenido,106,20);
$impto_liq_rni=0+substr($contenido,126,20);
$imp_op_ex=0+substr($contenido,146,20);
$fecha_cbte=substr($contenido,166,8);
$iva21=0+substr($contenido,182,20);
$iva105=0+substr($contenido,202,20);
$fecha_venc_pago=$fecha_cbte;
echo "Iva Total: ",$impto_liq."\n";
echo "Tipo de Iva 21: ",gettype($iva21)."\n";
$TC=1;
$ULT_CBTE=FECompUltimoAutorizado($client, $token, $sign, CUIT, $punto_vta, $tipo_cbte);
$params->Auth->Token = $token;
$params->Auth->Sign = $sign;
$params->Auth->Cuit = $CUIT;
$FeCabReq->CantReg = 1;
$FeCabReq->PtoVta = $punto_vta;
$FeCabReq->CbteTipo = $tipo_cbte;
$FeDetReq=array();
for ($i=0;$i<$CANT;$i++)
{
$FEDetRequest='';
$FEDetRequest->Concepto=1;
$FEDetRequest->DocTipo=80;
$FEDetRequest->DocNro=$nro_doc;
$FEDetRequest->CbteDesde=$cbt_desde;
$FEDetRequest->CbteHasta=$cbt_desde;
$FEDetRequest->CbteFch=$fecha_cbte;
$FEDetRequest->ImpTotal=$imp_total;
$FEDetRequest->ImpTotConc=0;
$FEDetRequest->ImpNeto=$imp_neto;
$FEDetRequest->ImpOpEx=$imp_op_ex;
$FEDetRequest->ImpTrib=0;
$FEDetRequest->ImpIVA=$impto_liq;
$FEDetRequest->FchVtoPago=" ";
$FEDetRequest->MonId='PES';
$FEDetRequest->MonCotiz=1;
$FEDetRequest->FchServDesde=" ";
$FEDetRequest->FchServHasta=" ";
if ($iva21 > 0 && $iva105 == 0) {
# echo "Iva 21: ",$iva21."\n";
# echo "Tipo de Iva 21: ",gettype($iva21)."\n";
$FEDetRequest->Iva->AlicIva->Id=5;
$FEDetRequest->Iva->AlicIva->BaseImp=$iva21*100/21;
$FEDetRequest->Iva->AlicIva->Importe=$iva21;
}
if ($iva21 == 0 && $iva105 > 0) {
$FEDetRequest->Iva->AlicIva->Id=4;
$FEDetRequest->Iva->AlicIva->BaseImp=$iva105*100/10.5;
$FEDetRequest->Iva->AlicIva->Importe=$iva105;
}
if ($iva105 == 0 && $iva21 == 0) {
$FEDetRequest->Iva->AlicIva->Id=3;
$FEDetRequest->Iva->AlicIva->BaseImp=$imp_op_ex;
$FEDetRequest->Iva->AlicIva->Importe=0;
}
if ($iva21 > 0 && $iva105 > 0) {
echo "2 alicuotas de IVA\n";
$aAlicIva=array();
$aAlicIva[0]->Id=5;
$aAlicIva[0]->BaseImp=$iva21*100/21;
$aAlicIva[0]->Importe=$iva21;
$aAlicIva[1]->Id=4;
$aAlicIva[1]->BaseImp=$iva105*100/10.5;
$aAlicIva[1]->Importe=$iva105;
$FEDetRequest->Iva->AlicIva=$aAlicIva;
echo "\n\n\n".$FEDetRequest->Iva->AlicIva[1]->Id."\n\n\n";
}
$FeDetReq[$i]=$FEDetRequest;
}
$params->FeCAEReq->FeCabReq = $FeCabReq;
$params->FeCAEReq->FeDetReq = $FeDetReq;
$result=FECAESolicitar($client, $params);
# $FEDetRequest->Iva->AlicIva->Id=5;
# $FEDetRequest->Iva->AlicIva->BaseImp=$iva21*100/21;
# $FEDetRequest->Iva->AlicIva->Importe=$iva21;
# $FEDetRequest->FchVtoPago=date('Ymd',date('U'));
# $FEDetRequest->FchServDesde=date('Ymd',date('U'));
# $FEDetRequest->FchServHasta=date('Ymd',date('U'));
}
#==============================================================================
ini_set("soap.wsdl_cache_enabled", "0");
if (!file_exists(WSDL)) {exit("Failed to open ".WSDL."\n");}
if (!file_exists(TA)) {exit("Failed to open ".TA."\n");}
$client=new soapClient(WSDL,
array('soap_version' => SOAP_1_2,
'location' => URL,
# 'proxy_host' => PROXY_HOST,
# 'proxy_port' => PROXY_PORT,
'exceptions' => 0,
'encoding' => 'ISO-8859-1',
'features' => SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS,
'trace' => 1)); # needed by getLastRequestHeaders and others
$TA=simplexml_load_file(TA);
$token=$TA->credentials->token;
$sign=$TA->credentials->sign;
file_put_contents("functions.txt",print_r($client->__getFunctions(),TRUE));
file_put_contents("types.txt",print_r($client->__getTypes(),TRUE));
#
# Uncomment any of the following lines to invoke the corresponding web method.
#
#FEDummy($client);
#FEParamGetTiposTributos($client, $token, $sign, CUIT);
#FEParamGetTiposMonedas($client, $token, $sign, CUIT);
#FEParamGetTiposIva($client, $token, $sign, CUIT);
#FEParamGetTiposOpcional($client, $token, $sign, CUIT);
#FEParamGetTiposConcepto($client, $token, $sign, CUIT);
#FEParamGetPtosVenta($client, $token, $sign, CUIT);
#FEParamGetTiposCbte($client, $token, $sign, CUIT);
#FEParamGetTiposDoc($client, $token, $sign, CUIT);
#FEParamGetCotizacion($client, $token, $sign, CUIT, "DOL");
#FECompConsultar1($client, $token, $sign, CUIT, 1, 1, 19);
$MAX_CBTE=FECompTotXRequest($client, $token, $sign, CUIT);
printf("Max Cbte por request=%s\n",$MAX_CBTE);
$PV=1;
$CANT=1;
EmitirFC($client, $token, $sign, CUIT, $PV, $CANT);
FECompConsultar($client, $token, $sign, CUIT, $PV, 1);
?>
pego el .bat con los sets y path...
CLS
PATH=%PATH%;C:\XAMPP\PHP
SET PHPRC=C:\XAMPP\PHP
PHP WSAA-SAROS.PHP wsfe
PHP WSFEV1-SAROS.PHP
y finalmente el prg, que es medio complejo, pero traten de limpiarlo e interpretarlo un poco... cualquier cosa pregunten...
Ah... hay que bajar la fuente BAR25i
Si no la tienen me avisan y la subo por ahí...
//FACTURA SAROS, IMPRESORA LASER
#include "FiveWin.ch"
#include "Report.ch"
MEMVAR EMPRE, NROCAE, VNCCAE
function main
SET DATE ITALIAN
SET DELE ON
SET CENT ON
impre()
CLOSE ALL
SET RESOURCES TO
return nil
// ----------------------------------------------------------------
FUNCTION IMPRE()
LOCAL oPrn, oFont0, oFont, oFont1, oFontBold, oPen, oPen1,oFont2, OFONT3
LOCAL nRS, nCS, nRow, n
LOCAL NIMP, XATTE, XPAGO, XFECHA, XNUMERO, XIT, XOBSERV, XNOMBRE, XFIRMA, XREFERENCIA
LOCAL XITEMS, XPAGINA, XPAGINAS, XIT1, XTOTPAG, XDESCUENTO
LOCAL XTOTAL, XIVA, XPIVA, XTIPIVA, XREMITO, XLEYENDA, XCUIT, XDIRECCION, XCOPIAS, XCOPIA, XCODCOM1
LOCAL AMODELOS
LOCAL GTOTAL, XDES, XPRESINDES, XNITEMS, XITEM, XDTOGRAL, xnacional
LOCAL XLOCALIDAD, XPROVINCIA, XCLI_CODIG, XORDENCP, IVA_1, IVA_2
//EL RECURSO COMPARTIDO ES COLOR
IF !FILE("C:\TEMPO\INI.DBF")
MSGSTOP("FALTA EL ARCHIVO INI DEL C:\TEMPO","ERROR")
CLOSE ALL
QUIT
ELSE
SELE 99
USE C:\TEMPO\INI SHARED
LOCA FOR INI->PARAMETRO="PHP"
IF !EOF() .AND. LEN(ALLTRIM(INI->VALOR))<>0
XDIRPHP=ALLTRIM(INI->VALOR)
SELE 99
USE
NOME_ARQ := FCREATE("C:\TEMPO\WS.BAT")
NREGISTRO := "CLS"
FWRITE( NOME_ARQ, NREGISTRO+chr(13)+chr(10) )
NREGISTRO := "PATH=%PATH%;"+XDIRPHP
FWRITE( NOME_ARQ, NREGISTRO+chr(13)+chr(10) )
NREGISTRO := "SET PHPRC="+XDIRPHP
FWRITE( NOME_ARQ, NREGISTRO+chr(13)+chr(10) )
NREGISTRO := "PHP WSAA-SAROS.PHP wsfe"
FWRITE( NOME_ARQ, NREGISTRO+chr(13)+chr(10) )
NREGISTRO := "PHP WSFEV1-SAROS.PHP"
FWRITE( NOME_ARQ, NREGISTRO+chr(13)+chr(10) )
FCLOSE( NOME_ARQ )
ELSE
MSGSTOP("FALTA DEFINIR EL DIRECTORIO DE PHP EN ARCHIVO INI","ERROR")
ENDIF
ENDIF
SELE 99
USE C:\TEMPO\FAC1CLI SHARED
COPY TO C:\TEMPO\IMPCOT
USE C:\TEMPO\IMPCOT ALIAS FAC1
EMPRE:=ALLTRIM(FAC1->CODEMP)
SELE 77
USE &EMPRE\MOV_C_IV.SX SHARED
LOCA FOR MOV_C_IV->CODCOM=FAC1->CODCOM .AND. MOV_C_IV->NUMERO=FAC1->NUMERO
IF !EOF()
IF LEN(ALLTRIM(MOV_C_IV->CAE))=0
SELE 77
USE &EMPRE\FAELEC.SX SHARED
COPY STRU TO C:\TEMPO\FAELEC
SELE 78
USE C:\TEMPO\FAELEC ALIAS ELEC
SELE 99
GO TOP
SUM (FAC1->TOTAL) TO XTOTAL
SUM (FAC1->XIVA_1+FAC1->XIVA_2+FAC1->XIVA_3) TO XIVA
SUM FAC1->XIVA_1 TO XIVA21
SUM FAC1->XIVA_2 TO XIVA105
SUM (FAC1->TOTAL) TO XTOTALEXE FOR FAC1->XIVA_1=0 .AND. FAC1->XIVA_2=0 .AND. FAC1->XIVA_3=0
go top
if left(fac1->codcom,2)="CA"
xtotal:=xtotal*-1
xiva:=xiva*-1
xiva21:=xiva21*-1
xiva105:=xiva105*-1
xtotalexe:=xtotalexe*-1
endif
GO TOP
DO CASE
CASE FAC1->CODCOM="FAELE"
SELE 78
APPE BLANK
REPL ELEC->TIPODOC WITH "80"
REPL ELEC->NRODOC WITH LEFT(FAC1->CUIT,2)+SUBSTR(FAC1->CUIT,4,8)+RIGHT(ALLTRIM(FAC1->CUIT),1)
REPL ELEC->TIPOCBTE WITH "1"
REPL ELEC->PUNTOVTA WITH ALLTRIM(STR(VAL(LEFT(FAC1->NRO_COMP,4))))
REPL ELEC->CBTDESDE WITH ALLTRIM(STR(FAC1->NUMERO,15,0))
REPL ELEC->CBTHASTA WITH ALLTRIM(STR(FAC1->NUMERO,15,0))
REPL ELEC->IMPTOTAL WITH ALLTRIM(STR(XTOTAL+XIVA,15,2))
REPL ELEC->IMPTOTCO WITH "0.00"
REPL ELEC->IMPNETO WITH ALLTRIM(STR(XTOTAL-XTOTALEXE,15,2))
REPL ELEC->IMPTOLIQ WITH ALLTRIM(STR(XIVA,15,2))
REPL ELEC->IVA21 WITH ALLTRIM(STR(XIVA21,15,2))
REPL ELEC->IVA105 WITH ALLTRIM(STR(XIVA105,15,2))
REPL ELEC->IMPTONRI WITH "0.00"
REPL ELEC->IMPOPEXE WITH ALLTRIM(STR(XTOTALEXE,15,2))
REPL ELEC->FECHACBT WITH PADL(YEAR(FAC1->FECHA),4,"0")+PADL(MONTH(FAC1->FECHA),2,"0")+PADL(DAY(FAC1->FECHA),2,"0")
REPL ELEC->FECHAVTO WITH PADL(YEAR(FAC1->FECHA),4,"0")+PADL(MONTH(FAC1->FECHA),2,"0")+PADL(DAY(FAC1->FECHA),2,"0")
CASE FAC1->CODCOM="CAELE"
SELE 78
APPE BLANK
REPL ELEC->TIPODOC WITH "80"
REPL ELEC->NRODOC WITH LEFT(FAC1->CUIT,2)+SUBSTR(FAC1->CUIT,4,8)+RIGHT(ALLTRIM(FAC1->CUIT),1)
REPL ELEC->TIPOCBTE WITH "3"
REPL ELEC->PUNTOVTA WITH ALLTRIM(STR(VAL(LEFT(FAC1->NRO_COMP,4))))
REPL ELEC->CBTDESDE WITH ALLTRIM(STR(FAC1->NUMERO,15,0))
REPL ELEC->CBTHASTA WITH ALLTRIM(STR(FAC1->NUMERO,15,0))
REPL ELEC->IMPTOTAL WITH ALLTRIM(STR(XTOTAL+XIVA,15,2))
REPL ELEC->IMPTOTCO WITH "0.00"
REPL ELEC->IMPNETO WITH ALLTRIM(STR(XTOTAL,15,2))
REPL ELEC->IMPTOLIQ WITH ALLTRIM(STR(XIVA,15,2))
REPL ELEC->IVA21 WITH ALLTRIM(STR(XIVA21,15,2))
REPL ELEC->IVA105 WITH ALLTRIM(STR(XIVA105,15,2))
REPL ELEC->IMPTONRI WITH "0.00"
REPL ELEC->IMPOPEXE WITH ALLTRIM(STR(XTOTALEXE,15,2))
REPL ELEC->FECHACBT WITH PADL(YEAR(FAC1->FECHA),4,"0")+PADL(MONTH(FAC1->FECHA),2,"0")+PADL(DAY(FAC1->FECHA),2,"0")
REPL ELEC->FECHAVTO WITH PADL(YEAR(FAC1->FECHA),4,"0")+PADL(MONTH(FAC1->FECHA),2,"0")+PADL(DAY(FAC1->FECHA),2,"0")
CASE FAC1->CODCOM="DAELE"
SELE 78
APPE BLANK
REPL ELEC->TIPODOC WITH "80"
REPL ELEC->NRODOC WITH LEFT(FAC1->CUIT,2)+SUBSTR(FAC1->CUIT,4,8)+RIGHT(ALLTRIM(FAC1->CUIT),1)
REPL ELEC->TIPOCBTE WITH "2"
REPL ELEC->PUNTOVTA WITH ALLTRIM(STR(VAL(LEFT(FAC1->NRO_COMP,4))))
REPL ELEC->CBTDESDE WITH ALLTRIM(STR(FAC1->NUMERO,15,0))
REPL ELEC->CBTHASTA WITH ALLTRIM(STR(FAC1->NUMERO,15,0))
REPL ELEC->IMPTOTAL WITH ALLTRIM(STR(XTOTAL+XIVA,15,2))
REPL ELEC->IMPTOTCO WITH "0.00"
REPL ELEC->IMPNETO WITH ALLTRIM(STR(XTOTAL,15,2))
REPL ELEC->IMPTOLIQ WITH ALLTRIM(STR(XIVA,15,2))
REPL ELEC->IVA21 WITH ALLTRIM(STR(XIVA21,15,2))
REPL ELEC->IVA105 WITH ALLTRIM(STR(XIVA105,15,2))
REPL ELEC->IMPTONRI WITH "0.00"
REPL ELEC->IMPOPEXE WITH ALLTRIM(STR(XTOTALEXE,15,2))
REPL ELEC->FECHACBT WITH PADL(YEAR(FAC1->FECHA),4,"0")+PADL(MONTH(FAC1->FECHA),2,"0")+PADL(DAY(FAC1->FECHA),2,"0")
REPL ELEC->FECHAVTO WITH PADL(YEAR(FAC1->FECHA),4,"0")+PADL(MONTH(FAC1->FECHA),2,"0")+PADL(DAY(FAC1->FECHA),2,"0")
CASE FAC1->CODCOM="FBELE"
SELE 78
APPE BLANK
REPL ELEC->TIPODOC WITH "80"
REPL ELEC->NRODOC WITH LEFT(FAC1->CUIT,2)+SUBSTR(FAC1->CUIT,4,8)+RIGHT(ALLTRIM(FAC1->CUIT),1)
REPL ELEC->TIPOCBTE WITH "6"
REPL ELEC->PUNTOVTA WITH ALLTRIM(STR(VAL(LEFT(FAC1->NRO_COMP,4))))
REPL ELEC->CBTDESDE WITH ALLTRIM(STR(FAC1->NUMERO,15,0))
REPL ELEC->CBTHASTA WITH ALLTRIM(STR(FAC1->NUMERO,15,0))
REPL ELEC->IMPTOTAL WITH ALLTRIM(STR(XTOTAL+XIVA,15,2))
REPL ELEC->IMPTOTCO WITH "0.00"
REPL ELEC->IMPNETO WITH ALLTRIM(STR(XTOTAL,15,2))
REPL ELEC->IMPTOLIQ WITH ALLTRIM(STR(XIVA,15,2))
REPL ELEC->IVA21 WITH ALLTRIM(STR(XIVA21,15,2))
REPL ELEC->IVA105 WITH ALLTRIM(STR(XIVA105,15,2))
REPL ELEC->IMPTONRI WITH "0.00"
REPL ELEC->IMPOPEXE WITH ALLTRIM(STR(XTOTALEXE,15,2))
REPL ELEC->FECHACBT WITH PADL(YEAR(FAC1->FECHA),4,"0")+PADL(MONTH(FAC1->FECHA),2,"0")+PADL(DAY(FAC1->FECHA),2,"0")
REPL ELEC->FECHAVTO WITH PADL(YEAR(FAC1->FECHA),4,"0")+PADL(MONTH(FAC1->FECHA),2,"0")+PADL(DAY(FAC1->FECHA),2,"0")
CASE FAC1->CODCOM="CBELE"
SELE 78
APPE BLANK
REPL ELEC->TIPODOC WITH "80"
REPL ELEC->NRODOC WITH LEFT(FAC1->CUIT,2)+SUBSTR(FAC1->CUIT,4,8)+RIGHT(ALLTRIM(FAC1->CUIT),1)
REPL ELEC->TIPOCBTE WITH "8"
REPL ELEC->PUNTOVTA WITH ALLTRIM(STR(VAL(LEFT(FAC1->NRO_COMP,4))))
REPL ELEC->CBTDESDE WITH ALLTRIM(STR(FAC1->NUMERO,15,0))
REPL ELEC->CBTHASTA WITH ALLTRIM(STR(FAC1->NUMERO,15,0))
REPL ELEC->IMPTOTAL WITH ALLTRIM(STR(XTOTAL+XIVA,15,2))
REPL ELEC->IMPTOTCO WITH "0.00"
REPL ELEC->IMPNETO WITH ALLTRIM(STR(XTOTAL,15,2))
REPL ELEC->IMPTOLIQ WITH ALLTRIM(STR(XIVA,15,2))
REPL ELEC->IVA21 WITH ALLTRIM(STR(XIVA21,15,2))
REPL ELEC->IVA105 WITH ALLTRIM(STR(XIVA105,15,2))
REPL ELEC->IMPTONRI WITH "0.00"
REPL ELEC->IMPOPEXE WITH ALLTRIM(STR(XTOTALEXE,15,2))
REPL ELEC->FECHACBT WITH PADL(YEAR(FAC1->FECHA),4,"0")+PADL(MONTH(FAC1->FECHA),2,"0")+PADL(DAY(FAC1->FECHA),2,"0")
REPL ELEC->FECHAVTO WITH PADL(YEAR(FAC1->FECHA),4,"0")+PADL(MONTH(FAC1->FECHA),2,"0")+PADL(DAY(FAC1->FECHA),2,"0")
CASE FAC1->CODCOM="DBELE"
SELE 78
APPE BLANK
REPL ELEC->TIPODOC WITH "80"
REPL ELEC->NRODOC WITH LEFT(FAC1->CUIT,2)+SUBSTR(FAC1->CUIT,4,8)+RIGHT(ALLTRIM(FAC1->CUIT),1)
REPL ELEC->TIPOCBTE WITH "7"
REPL ELEC->PUNTOVTA WITH ALLTRIM(STR(VAL(LEFT(FAC1->NRO_COMP,4))))
REPL ELEC->CBTDESDE WITH ALLTRIM(STR(FAC1->NUMERO,15,0))
REPL ELEC->CBTHASTA WITH ALLTRIM(STR(FAC1->NUMERO,15,0))
REPL ELEC->IMPTOTAL WITH ALLTRIM(STR(XTOTAL+XIVA,15,2))
REPL ELEC->IMPTOTCO WITH "0.00"
REPL ELEC->IMPNETO WITH ALLTRIM(STR(XTOTAL,15,2))
REPL ELEC->IMPTOLIQ WITH ALLTRIM(STR(XIVA,15,2))
REPL ELEC->IVA21 WITH ALLTRIM(STR(XIVA21,15,2))
REPL ELEC->IVA105 WITH ALLTRIM(STR(XIVA105,15,2))
REPL ELEC->IMPTONRI WITH "0.00"
REPL ELEC->IMPOPEXE WITH ALLTRIM(STR(XTOTALEXE,15,2))
REPL ELEC->FECHACBT WITH PADL(YEAR(FAC1->FECHA),4,"0")+PADL(MONTH(FAC1->FECHA),2,"0")+PADL(DAY(FAC1->FECHA),2,"0")
REPL ELEC->FECHAVTO WITH PADL(YEAR(FAC1->FECHA),4,"0")+PADL(MONTH(FAC1->FECHA),2,"0")+PADL(DAY(FAC1->FECHA),2,"0")
OTHERWISE
MSGSTOP("ERROR CON EL TIPO DE COMPROBANTE ELECTRONICO","ERROR")
CLOSE ALL
RETURN NIL
ENDCASE
SELE 78
COPY TO C:\TEMPO\FAELEC.TXT SDF
IF FILE("C:\TEMPO\CAE.TXT")
RUN("DEL C:\TEMPO\CAE.TXT")
ENDIF
RUN("C:\TEMPO\WS.BAT")
IF !FILE("C:\TEMPO\CAE.TXT")
MSGSTOP("ERROR GENERACION DE CAE."+CRLF+"INGRESE AL SIMBOLO DE SISTEMA Y EJECUTE C:\TEMPO\WS.BAT"+CRLF+"PARA MAYOR DETALLE", "ERROR")
CLOSE ALL
QUIT
ENDIF
SELE 78
APPE FROM C:\TEMPO\CAE.TXT SDF
IF UPPER(ELEC->TIPODOC)="NU"
MSGSTOP("PROBLEMAS CON EL NUMERO DE CAE","ERROR")
CLOSE ALL
QUIT
ELSE
NROCAE=ELEC->TIPODOC+ELEC->NRODOC+ELEC->TIPOCBTE
VNCCAE=DATE()+10
SELE 78
USE
SELE 78
USE &EMPRE\MOV_C_IV.SX SHARED
LOCA FOR MOV_C_IV->CODCOM=FAC1->CODCOM .AND. MOV_C_IV->NUMERO=FAC1->NUMERO
IF !EOF()
DO WHILE !RLOCK()
ENDDO
REPL MOV_C_IV->CAE WITH NROCAE
REPL MOV_C_IV->VNCCAE WITH VNCCAE
UNLOCK
ENDIF
SELE 78
USE
SELE 77
APPE FROM C:\TEMPO\FAELEC
SELE 77
USE
ENDIF
ELSE
NROCAE=MOV_C_IV->CAE
VNCCAE=MOV_C_IV->VNCCAE
SELE 77
USE
ENDIF
ELSE
MSGSTOP("NO SE ENCUENTRA EL COMPROBANTE EN LA BASE CABECERA VENTAS","ERROR")
CLOSE ALL
QUIT
ENDIF
SELE 99
COUNT TO XITEMS FOR fac1->art_codig<>space(16)
GO TOP
XCAE:=CAE(FAC1->NRO_COMP,NROCAE,VNCCAE,fac1->codcom)
XCODCOM1:=fac1->CODCOM
XTIPIVA:=ALLTRIM(FAC1->TIPIVA)
XCUIT:=FAC1->CUIT
if upper(alltrim(fac1->moneda))<>"PE"
xnacional:=.f.
else
xnacionaL:=.t.
endif
XATTE:=FAC1->ATTE
XPAGO:=FAC1->PAGO
XFECHA:=FAC1->FECHA
XDTOGRAL:=fac1->DESCTO
XORDENCP:=FAC1->ORDENCP
XCLI_CODIG:=FAC1->CLI_CODIG
XNUMERO:=FAC1->NUMERO
XOBSERV:=FAC1->OBSERV
XCOPIAS:=FAC1->COPIAS
XNOMBRE:=ansitooem(FAC1->NOMBRE)
// XDIRECCIONA:=ansitooem(UPPER(ALLTRIM(FAC1->DOMICI)))
XDIRECCION:=oemTOANSI(UPPER(ALLTRIM(FAC1->DOMICI)))
// XDIRECCION:=UPPER(ALLTRIM(FAC1->DOMICI))
XLOCALIDAD:=UPPER(ALLTRIM(FAC1->LOCALI))+" ("+UPPER(ALLTRIM(FAC1->CODPOS))+")"
XPROVINCIA:=UPPER(ALLTRIM(FAC1->PROVIN))+" ,"+UPPER(ALLTRIM(FAC1->PAIS))
XLEYENDA:=ALLTRIM(FAC1->LEYENDA) //COND. VENTA
XREFERENCIA:=ALLTRIM(FAC1->ORDENCP)
IF FAC1->NROREM<>0
XREMITO:=LEFT(FAC1->NRO_COMP,5)+PADL(FAC1->NROREM,8,"0")
ELSE
XREMITO:=" "
ENDIF
DO CASE
CASE FAC1->USR='HECORT'
XFIRMA:="HECTOR PEREIRO"+SPACE(20)
CASE FAC1->USR='GABRIEL'
XFIRMA:="GABRIEL DAMIANO"+SPACE(20)
OTHERWISE
XFIRMA:="HECTOR PEREIRO"+SPACE(20)
ENDCASE
// XFIRMA:=TITULO(XFIRMA)
//IF XITEMS-20<21
IF FILE("C:\TEMPO\INI.DBF")
SELE 98
USE C:\TEMPO\INI SHARED
GO TOP
LOCA FOR INI->PARAMETRO="IMPFAC"
IF INI->VALOR<>SPACE(40) .and. !eof()
AMODELOS:= {ALLTRIM(INI->VALOR),'IMPRESORA'}
ELSE
USE &EMPRE\COMPROB.SX SHARED
LOCA FOR COMPROB->CODCOM=XCODCOM1 .AND. COMPROB->MODULO="CL" .AND. LEN(XCODCOM1)=LEN(COMPROB->CODCOM)
IF !EOF()
AMODELOS:= {ALLTRIM(COMPROB->IMPRESORA),'IMPRESORA'}
ELSE
AMODELOS:= {'\\PCPOL1\HP Business Inkjet 1200 Series','IMPRESORA COLOR'}
ENDIF
ENDIF
USE
ELSE
SELE 98
USE &EMPRE\COMPROB.SX SHARED
LOCA FOR COMPROB->CODCOM=XCODCOM1 .AND. COMPROB->MODULO="CL" .AND. LEN(XCODCOM1)=LEN(COMPROB->CODCOM)
IF !EOF()
AMODELOS:= {ALLTRIM(COMPROB->IMPRESORA),'IMPRESORA'}
ELSE
AMODELOS:= {'\\PCPOL1\HP Business Inkjet 1200 Series','IMPRESORA COLOR'}
ENDIF
USE
ENDIF
iva_1:=0
iva_2:=0
gtotal:=0
xnitems:=0
xpresindes:=0
xdes:=0
SELE 99
GO TOP
do while !eof()
xnitems:=xnitems+1
gtotal:=gtotal+fac1->total
iva_1:=iva_1+fac1->xiva_1
iva_2:=iva_2+fac1->xiva_2
xpresindes:=FAC1->presindes-(FAC1->presindes*FAC1->deslin/100)
xpresindes:=round(FAC1->cantidadf*xpresindes,2)
xdes:=xdes+xpresindes
skip
enddo
xpresindes:=xdes
xdes:=(gtotal-xpresindes)
XCOPIA:=0
XCOPIAS:=1
GO TOP
DO WHILE XCOPIA<XCOPIAS
XCOPIA:=XCOPIA+1
DO CASE
CASE LEFT(XCODCOM1,1)="F"
PRINT oPrn NAME "FACTURA" TO ALLTRIM(AMODELOS[1]) PREVIEW
CASE LEFT(XCODCOM1,1)="C"
PRINT oPrn NAME "NOTA DE CREDITO" TO ALLTRIM(AMODELOS[1]) PREVIEW
CASE LEFT(XCODCOM1,1)="D"
PRINT oPrn NAME "NOTA DE DEBITO" TO ALLTRIM(AMODELOS[1]) PREVIEW
OTHERWISE
PRINT oPrn NAME "FACTURA" TO ALLTRIM(AMODELOS[1]) PREVIEW
ENDCASE
oPrn:Setup()
DEFINE FONT oFontCae NAME "Bar 25i e HR" SIZE 0, -22 OF oPrn
DEFINE FONT oFont NAME "Ms Sans Serif" SIZE 0, -10 OF oPrn
DEFINE FONT oFont0 NAME "Ms Sans Serif" SIZE 0, -9 OF oPrn
DEFINE FONT oFontBold NAME "Ms Sans Serif" SIZE 0, -10 OF oPrn BOLD
DEFINE FONT oFont1 NAME "Ms Sans Serif" SIZE 0, -9 OF oPrn BOLD
DEFINE FONT oFont2 NAME "Ms Sans Serif" SIZE 0, -7 of oPrn
DEFINE FONT oFont3 NAME "Ms Sans Serif" SIZE 0, -16 OF oPrn BOLD
DEFINE PEN oPen1 WIDTH 5 OF oPRN
DEFINE PEN oPen WIDTH 4 OF oPRN
nRS := oPrn:nVertRes() / 60 // We want 60 rows
nCS := oPrn:nHorzRes() / 80 // We want 80 cols
PAGE
//oPrn : box(nRs*1,nCs*1,nRs*59,nCs*79,open1)
// oPrn : say(nRs*10.5,nCs*2,"Inclan 3281 Capital Federal - CP C1258AAT - Bs. As.",oFont0)
if xcodcom1="CA"
oPrn : say(nRs*1.7,nCs*45,"XXXXXXXXXXXXXXXXXXX Nota de Credito",oFont1)
endif
if xcodcom1="NA"
oPrn : say(nRs*1.7,nCs*45,"XXXXXXXXXXXXXXXXXXX Nota de Debito",oFont1)
endif
oPrn : say(nRs*5,nCs*53,DTOC(XFECHA),oFont1)
// oPrn : say(nRs*1,nCs*10,XDIRECCIONA,oFont0)
// oPrn : say(nRs*3,nCs*10,XDIRECCIONO,oFont0)
// oPrn : say(nRs*5,nCs*10,XDIRECCION,oFont0)
oPrn : say(nRs*11,nCs*10,XNOMBRE,oFont0)
oPrn : say(nRs*12.5,nCs*10,XDIRECCION,oFont0)
oPrn : say(nRs*12.5,nCs*43,XLOCALIDAD,oFont0)
DO CASE
CASE FAC1->TIPIVA="INSCR"
oPrn : say(nRs*14,nCs*12.5,"RESPONSABLE INSCRIPTO",oFont0)
CASE FAC1->TIPIVA="MONOT"
oPrn : say(nRs*14,nCs*12.5,"RESPONSABLE MONOTRIBUTO",oFont0)
CASE FAC1->TIPIVA="EXEN" .or. FAC1->TIPIVA="TFUEG"
oPrn : say(nRs*14,nCs*12.5,"EXENTO",oFont0)
CASE FAC1->TIPIVA="CF"
oPrn : say(nRs*14,nCs*12.5,"CONSUMIDOR FINAL",oFont0)
OTHERWISE
oPrn : say(nRs*14,nCs*12.5,"CONSUMIDOR FINAL",oFont0)
ENDCASE
oPrn : say(nRs*16.7,nCs*50,XCUIT,oFont0)
oPrn : say(nRs*16.9,nCs*18,XLEYENDA,oFont0)
XITEM:=1
N:=21.3
XIT:=1
go top
do while fac1->art_codig<>space(16) .AND. XIT<26
XDESCUENTO = 100 - (100*FAC1->DESLIN/100)
XDESCUENTO = XDESCUENTO - (XDESCUENTO*FAC1->DESCTO/100)
XDESCUENTO = 100 - XDESCUENTO
if FAC1->CANTIDAD=0
oPrn : say(nRs*N,nCs*25,ansiTOOEM(LEFT(FAC1->ART_DESCR,48)),oFont1)
else
//oPrn : say(nRs*N,nCs*3,STR(XITEM,5),oFont1)
XITEM:=XITEM+1
oPrn : say(nRs*N,nCs*3,STR(FAC1->CANTIDAD,10,2),oFont1)
oPrn : say(nRs*N,nCs*10,LEFT(FAC1->ART_CODIG,16),oFont1)
oPrn : say(nRs*N,nCs*25,ansiTOOEM(LEFT(FAC1->ART_DESCR,48)),oFont1)
IF XCODCOM1='FB'
oPrn : say(nRs*N,nCs*60,STR(FAC1->PRECIO+(FAC1->PRECIO*FAC1->ART_IVA/100),10,2),oFont1)
if xnacional=.t.
oPrn : say(nRs*N,nCs*67,STR(FAC1->TOTAL+(FAC1->TOTAL*FAC1->ART_IVA/100),15,2),oFont1)
else
oPrn : say(nRs*N,nCs*67,STR(FAC1->TOTALUSS+(FAC1->TOTALUSS*FAC1->ART_IVA/100),15,2),oFont1)
endif
ELSE
oPrn : say(nRs*N,nCs*60,STR(FAC1->PRECIO,10,2),oFont1)
IF XNACIONAL=.T.
oPrn : say(nRs*N,nCs*67,STR(FAC1->TOTAL,15,2),oFont1)
ELSE
oPrn : say(nRs*N,nCs*67,STR(FAC1->TOTALUSS,15,2),oFont1)
ENDIF
ENDIF
endif
N:=N+1
XIT:=XIT+1
skip
enddo
/*
SELE 99
GO TOP
XPIVA:=FAC1->ART_IVA
SUM (FAC1->TOTAL) TO XTOTAL
SUM (FAC1->XIVA_1+FAC1->XIVA_2+FAC1->XIVA_3) TO XIVA
oPrn : say(nRs*55,nCs*67,STR(XTOTAL+XIVA,15,2),oFont1)
*/
SELE 99
GO TOP
XPIVA:=FAC1->ART_IVA
IF XNACIONAL=.T.
SUM (FAC1->TOTAL) TO XTOTAL
SUM (FAC1->XIVA_1+FAC1->XIVA_2+FAC1->XIVA_3) TO XIVA
if substr(xcodcom1,2,1)="A"
oPrn : say(nRs*52,nCs*5,"$ "+STR(XTOTAL,15,2),oFont1)
oPrn : say(nRs*52,nCs*52,"$ "+STR(XIVA,15,2),oFont1)
endif
oPrn : say(nRs*52,nCs*67,"$ "+STR(XTOTAL+XIVA,15,2),oFont1)
ELSE
SUM (FAC1->TOTALUSS) TO XTOTAL
SUM (FAC1->XIVA_1USS+FAC1->XIVA_2USS) TO XIVA
if substr(xcodcom1,2,1)="A"
oPrn : say(nRs*52,nCs*5,"U$S "+STR(XTOTAL,15,2),oFont1)
oPrn : say(nRs*52,nCs*52,"U$S "+STR(XIVA,15,2),oFont1)
endif
oPrn : say(nRs*52,nCs*67,"U$S "+STR(XTOTAL+XIVA,15,2),oFont1)
ENDIF
oPrn : say(nRs*53,nCs*3,LEFT(XOBSERV,40),oFont1)
oPrn : say(nRs*54,nCs*3,"Nro. CAE: "+ NROcae +". Fecha de vencimiento del CAE: "+dtoc(vnccae),oFont1)
oPrn : say(nRs*55,nCs*3,STOBARCODE(xcae),oFontCae)
ENDPAGE
ENDPRINT
oFont:end()
oFont0:end()
oFont1:end()
oFont2:end()
oPen :end()
oPen1 :end()
ENDDO
CLOSE ALL
Return nil
// -------------------------------------------------
FUNCTION TITULO(XTITULO)
LOCAL OBT1, OTITULO, ODLG
DEFINE DIALOG oDlg RESOURCE "titulo" TITLE "FIRMA LA COTIZACION"
REDEFINE GET otitulo VAR xtitulo ID 101 of odlg
REDEFINE BUTTON oBt1 ACTION ( odlg:end() ) ID 1 of oDlg
ACTIVATE DIALOG oDlg centered
RETURN XTITULO
// -------------------------------------------------
FUNCTION CAE(XNRO_COMP,XCAE,XVNC,xcodcom)
LOCAL ODIAS, ODLG, OBTNEND
//local xCAE:=SPACE(100)
//LOCAL XVNC:=DATE()+10
/*
DEFINE DIALOG oDlg FROM 3, 3 TO 15, 60 TITLE "INGRESE CAE"
@ 1, 1 SAY "CAE:" ;
@ 1, 5 GET ODIAS VAR XCAE ;
SIZE 80, 12 OF oDlg // PICTURE "9999"
@ 3, 1 SAY "VENCIMIENTO:" ;
@ 3, 5 GET ODIAS VAR XVNC ;
SIZE 80, 12 OF oDlg // PICTURE "9999"
@ 5, 10.9 BUTTON ObtnEnd PROMPT "&Aceptar" OF oDlg SIZE 40, 12
ObtnEnd:bAction = { || oDlg:End() }
ACTIVATE DIALOG oDlg
*/
XFECHA:=PADL(YEAR(XVNC),4,"0")+PADL(MONTH(XVNC),2,"0")+PADL(DAY(XVNC),2,"0")
do case
case left(xcodcom,2)="FA"
XCAE:="2026561276901"+LEFT(XNRO_COMP,4)+ALLTRIM(XCAE)+XFECHA
case left(xcodcom,2)="FB"
XCAE:="2026561276906"+LEFT(XNRO_COMP,4)+ALLTRIM(XCAE)+XFECHA
case left(xcodcom,2)="CA"
XCAE:="2026561276903"+LEFT(XNRO_COMP,4)+ALLTRIM(XCAE)+XFECHA
case left(xcodcom,2)="CB"
XCAE:="2026561276908"+LEFT(XNRO_COMP,4)+ALLTRIM(XCAE)+XFECHA
case left(xcodcom,2)="DA"
XCAE:="2026561276902"+LEFT(XNRO_COMP,4)+ALLTRIM(XCAE)+XFECHA
case left(xcodcom,2)="DB"
XCAE:="2026561276907"+LEFT(XNRO_COMP,4)+ALLTRIM(XCAE)+XFECHA
otherwise
XCAE:="2026561276901"+LEFT(XNRO_COMP,4)+ALLTRIM(XCAE)+XFECHA
endcase
XDV:=DV(XCAE)
XCAE:=XCAE+ALLTRIM(STR(XDV))
return XCAE
// -----------------------------------------------------
FUNCTION DV(SNUMERO)
If Len(sNumero) <> 39
MsgSTOP ("El Numero debe contener 39 digitos", "ERROR")
? SNUMERO
CLOSE ALL
QUIT
Else
Sum1 = 0
Sum2 = 0
X:=1
DO WHILE X<=39
//k = Mid(sNumero, x, 1)
k = VAL(SUBSTR(sNumero, x, 1))
If x / 2 = Int(x / 2)
Sum1 = Sum1 + k
Else
Sum2 = Sum2 + k
EndIf
X:=X+1
ENDDO
SumaTotal = (Sum2 * 3) + Sum1
X:=0
WHILE X<=9
sDigito = SumaTotal + x
If sDigito / 10 = Int(sDigito / 10)
XDV = x
X:=190
EndIf
X:=X+1
ENDDO
EndIf
RETURN XDV
// -------------------------------------------------
FUNCTION STOBARCODE(xcae)
xrta:=""
IF LEN(ALLTRIM(xcae))<>40
msgstop("Error al crear codigo de barras. Largo del cae incorrecto","Error")
quit
else
SELE 15
use tabla.sx share
x:=1
do while x<=40
xnumero:=val(substr(xcae,x,2))
sele 15
loca for tabla->numero=xnumero
if !eof()
IF XNUMERO>89
xrta:=xrta+alltrim(OEMTOANSI(tabla->codigo))
ELSE
xrta:=xrta+alltrim(tabla->codigo)
ENDIF
else
msgstop("ERROR","ERROR")
quit
endif
x:=x+2
enddo
xrta:="{"+xrta+"}"
SELE 15
USE
endif
return xrta