Al igual que Ricardo Aidelman, yo uso el ocx de facturaelectronicax.
Desarrollé el siguiente método para generar un libro iva ventas con la
información obtenida directamente de la AFIP:

Al ocx le puse el nombre FE


** método libroiva

Local
nUltimoDia,cMess,nPuntoVenta,nTipoComprobante,cTipoDoc,nUltimoAutorizado
Local dFecha,nNeto,nIVA,nTotal,cCUIT,cEmpresa,nIVA_ID
Local nNetoT,nIVAT,nTotalT,nNograT,nNoGra,cPuntoVenta,cNroAfip

Store 0 to nUltimoDia,nPuntoVenta,nTipoComprobante,nUltimoAutorizado
Store '' to cMess,cTipoDoc,cCUIT,cEmpresa,cPuntoVenta,cNroAfip
Store 0.00 to nNeto,nIVA,nTotal,nNoGra,nNetoT,nIVAT,nTotalT,nNograT


dFecha = {}


** tengo un método que calcula el último día del mes según el mes y año
pedidos y lo pego a un objeto de administración en la _screen

nUltimoDia = _screen.oAdm.ultimodia( Alltrim(Str(thisform.nMes)) ,
Alltrim(Str(thisform.nAnio))  )

this.dHasta = Date(thisform.nAnio,thisform.nMes,nUltimoDia)
this.dDesde = Date(thisform.nAnio,thisform.nMes,1)

cMess = 'IVA Ventas Consolidado'+Chr(13)
cMess = cMess + _screen.oAdm.aMeses(this.nMes)+' '+Transform(this.nAnio)


_VFP.AutoYield = .F.


nPuntoVenta = this.nPtoVen
cPuntoVenta = Padl(Alltrim(Str(nPuntoVenta)),4,'0')


With thisform
     .grid1.RecordSource = ''
     .lblNeto.caption    = ''
     .lblIVA.caption     = ''
     .lblNoGrav.caption  = ''
     .lblTotal.caption   = ''
EndWith

** este cursor lo creo en el load del form (la estructura se ve más abajo)

Select curIVA
Zap


nTipo = 1

do while nTipo <= 6
With thisform.FE

nTipoComprobante = ICase(nTipo = 1,1,; && FAC A
nTipo = 2,2,; && ND  A
nTipo = 3,3,; && NC  A
nTipo = 4,6,; && FAC B
nTipo = 5,7,; && ND  B
nTipo = 6,8) && NC  B

        If nTipo > 6
           Exit
        EndIf


cTipoDoc = ICase( nTipo = 1,'FAC A',;
 nTipo = 2,'NDB A',;
     nTipo = 3,'NCR A',;
     nTipo = 4,'FAC B',;
     nTipo = 5,'NDB B',;
     nTipo = 6,'NCR B')

        nUltimoAutorizado =
 .F1CompUltimoAutorizado(nPuntoVenta,nTipoComprobante)

        Do while .t.

            If nUltimoAutorizado <= 0
               nTipo = nTipo + 1
               exit
            EndIf

lOK = .F1CompConsultar(nPuntoVenta,nTipoComprobante,nUltimoAutorizado)

If lOK
cFecha = .F1DetalleCbteFch
* si la fecha es anterior al primer dia del periodo
if cFecha < dtos(thisform.dDesde)
   nTipo = nTipo + 1
exit
endif
** si la fecha es posterior al último dia del periodo
if cFecha > dtos(thisform.dHasta)
nUltimoAutorizado = nUltimoAutorizado - 1
                 Wait window nowait 'Buscando ' + cTipoDoc + ' de
'+_screen.oAdm.aMeses(this.nMes)+' '+Transform(this.nAnio) at 30,110
loop
endif
dFecha = Ctod(Right(cFecha,2)+'/'+Substr(cFecha,5,2)+'/'+Left(cFecha,4))

            nIVA_ID   = .F1DetalleIvaId

            If nIVA_ID = 3 && 0 %
               nNoGra = .F1DetalleIvaBaseImp
            endif

            nNeto  = Round(.F1DetalleImpNeto,2)
            nIVA   = Round(.F1DetalleImpIVA,2)
            nTotal = Round(.F1DetalleImpTotal,2)

            If InList(nTipo,3,6)    && si es una nota de crédito
               nNeto  = nNeto  * (-1)
               nIVA   = nIVA   * (-1)
               nTotal = nTotal * (-1)
               nNoGra = nNoGra * (-1)
            endif

                 If InList(nTipo,4,5,6)

                    nNoGra = 0.00

                 EndIf

            nUltimoAutorizado  = Cast(nUltimoAutorizado as int)

    cCUIT = Alltrim(.F1RespuestaDetalleDocNro)

    cEmpresa = this.buscar_cliente(cCUIT)

            cCUIT = Left(cCUIT,2)+'-'+Substr(cCUIT,3,8)+'-'+Right(cCUIT,1)

              Wait window nowait cTipoDoc+' '+Transform(nUltimoAutorizado)
at 30,110

                 cNroAfip = Padl(Alltrim(Str(nUltimoAutorizado)),8,'0')

Insert into curIVA(fecha,empresa,cuit,tipodoc,puntoventa,nroafip,;
    neto,iva,total,otros) ;
    values(dFecha,cEmpresa,cCUIT,cTipoDoc,cPuntoVenta,cNroAfip,;
    nNeto,nIVA,nTotal,nNoGra)

    else

       nTipo = nTipo + 1
       Exit

    endif

          nUltimoAutorizado = nUltimoAutorizado-1

    EndDo

endwith

enddo
Wait clear

Select curIVA


Scan for InList(tipodoc,'FAC B','NDB B','NCR B')

     If InList(tipodoc,'FAC B','NDB B')

    replace neto with Round(total/1.21,2),;
            iva with total - neto

     endif

     If tipodoc = 'NCR B'

    replace neto with Round(Abs(total)/1.21,2) * (-1),;
            iva with (abs(total) - Abs(neto)) * (-1),;
            total with Abs(total) * (-1)

     endif
endscan

Select curIVA

Sum all neto,iva,total,otros to nNetoT,nIVAT,nTotalT,nNograT


cPic = '99,999,999.99'

Scatter name oTotales blank

With thisform
     .lblNeto.caption   = Transform(nNetoT,cPic)
     .lblIVA.caption    = Transform(nIVAT,cPic)
     .lblNoGrav.caption = Transform(nNograT,cPic)
     .lblTotal.caption  = Transform(nTotalT,cPic)
EndWith

thisform.grid1.RecordSource = ''


Select curIVA
Index on Dtos(fecha)+tipodoc+nroafip tag fecha ascending


thisform.set_grid()          && este método configura la grid con el cursor
curIVA

thisform.btnImprimir.Enabled = .t.


Espero te sirva

Rafael Copquin

Responder a