Outro mais interessante ainda, que precisou precaução
Totais por dia ou por mês do fiscal
Código: Selecionar todos
STATIC FUNCTION imprime()
LOCAL oPDF, nKey, m_ClaIcmVl, m_ClaIcmIs, m_ClaIcmOu, m_TotVlCon, m_TotIcmBa, m_TotIcmIs, m_TotIcmOu, m_TotIpiIs, m_TotIpiOu, m_ClaVlCon
LOCAL m_ClaIcmBa, m_ClaIpiBa, m_ClaIpiIs, m_ClaIpiOu, m_TotIpiVl, m_TotIcmVl, m_TotIpiBa, m_ClaIpiVl, m_Data
oPDF := PDFClass():New()
oPDF:SetType( nOpcPrinterType )
oPDF:Begin()
nKey = 0
oPDF:acHeader := {"","",""}
oPDF:acHeader[ 1 ] = "RESUMO DA MOVIMENTACAO, POR DATA"
IF nOpcData == 1
oPDF:acHeader[ 2 ] = " "
ELSE
oPDF:acHeader[ 2 ] = "Periodo: " + Dtoc( m_datai ) + " a " + Dtoc( m_dataf ) + iif( nOpcGrf == 1, "", " " + acTxtGrf[ nOpcGrf ] )
ENDIF
oPDF:acHeader[ 3 ] = Space(10) + "--DATA-- ---VALOR CONTABIL-- --BASE DE CALCULO-- -IMPOSTO DEB/CRED.- --ISENTOS/N.TRIBUT- -------OUTROS------"
STORE 0 to m_totvlcon, m_toticmba, m_toticmvl, ;
m_toticmis, m_toticmou
STORE 0 to m_totipiba, m_totipivl, m_totipiis, m_totipiou
SELECT jpfiscal
OrdSetFocus( "jpfiscal3" )
SEEK "2" SOFTSEEK
oPDF:PageHeader()
oPDF:DrawText( oPDF:nRow, 0, "ENTRADAS:" )
oPDF:nRow += 2
DO WHILE nKey != K_ESC .AND. ! Eof()
GrafProc()
nKey = Inkey()
IF jpfiscal->lfDatLan > m_dataf .AND. nOpcData == 2
SKIP
LOOP
ENDIF
IF jpfiscal->lfDatLan < m_datai .AND. nOpcData == 2
SKIP
LOOP
ENDIF
m_data := Substr( Dtoc( jpfiscal->lfDatLan ),iif( nOpcTotais == 1, 1, 4 ) )
STORE 0 to m_clavlcon, m_claicmba, m_claicmvl, ;
m_claicmis, m_claicmou
STORE 0 to m_claipiba, m_claipivl, m_claipiis, m_claipiou
DO WHILE nKey != K_ESC .AND. jpfiscal->lfTipLan=="2" .AND. ! Eof()
IF Substr( Dtoc( jpfiscal->lfDatLan ),iif( nOpcTotais == 1, 1, 4 ) ) != m_Data
EXIT
ENDIF
nKey = Inkey()
GrafProc()
IF jpfiscal->lfDatLan > m_dataf .AND. nOpcData == 2
SKIP
LOOP
ENDIF
IF jpfiscal->lfDatLan < m_datai .AND. nOpcData == 2
SKIP
LOOP
ENDIF
m_clavlcon = Round( m_clavlcon + jpfiscal->lfValCon, 2 )
IF jpfiscal->lfIcmVal != 0
m_claicmba = Round( m_claicmba + jpfiscal->lfIcmBas, 2 )
m_claicmvl = Round( m_claicmvl + jpfiscal->lfIcmVal, 2 )
ENDIF
IF jpfiscal->lfValCon - jpfiscal->lfIcmBas - jpfiscal->lfIcmOut > 0
m_claicmis = Round( m_claicmis + ( jpfiscal->lfValCon - jpfiscal->lfIcmBas - jpfiscal->lfIcmOut ), 2 )
ENDIF
IF jpfiscal->lfIcmOut != 0
m_claicmou = Round( m_claicmou + jpfiscal->lfIcmOut, 2 )
ENDIF
IF jpfiscal->lfIpiVal != 0
m_claipiba = Round( m_claipiba + jpfiscal->lfIpiBas, 2 )
m_claipivl = Round( m_claipivl + jpfiscal->lfIpiVal, 2 )
ENDIF
IF jpfiscal->lfValCon - jpfiscal->lfIpiBas - jpfiscal->lfIpiOut - jpfiscal->lfIpiVal > 0
m_claipiis = Round( m_claipiis + ( jpfiscal->lfValCon - jpfiscal->lfIpiBas - jpfiscal->lfIpiOut - jpfiscal->lfIpiVal ), 2 )
ENDIF
IF jpfiscal->lfIpiOut != 0
m_claipiou = Round( m_claipiou + jpfiscal->lfIpiOut, 2 )
ENDIF
SKIP
ENDDO
IF m_clavlcon != 0
oPDF:MaxRowTest()
oPDF:DrawText( oPDF:nRow, 10, m_Data )
oPDF:DrawText( oPDF:nRow, 20, m_clavlcon, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 40, m_claicmba, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 60, m_claicmvl, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 80, m_claicmis, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 100, m_claicmou, PicVal(14,2) )
m_totvlcon = Round( m_totvlcon + m_clavlcon, 2 )
m_toticmba = Round( m_toticmba + m_claicmba, 2 )
m_toticmvl = Round( m_toticmvl + m_claicmvl, 2 )
m_toticmis = Round( m_toticmis + m_claicmis, 2 )
m_toticmou = Round( m_toticmou + m_claicmou, 2 )
m_totipiba = Round( m_totipiba + m_claipiba, 2 )
m_totipivl = Round( m_totipivl + m_claipivl, 2 )
m_totipiis = Round( m_totipiis + m_claipiis, 2 )
m_totipiou = Round( m_totipiou + m_claipiou, 2 )
oPDF:nRow += 1
ENDIF
ENDDO
oPDF:MaxRowTest()
oPDF:DrawLine( oPDF:nRow, 0, oPDF:nRow, oPDF:MaxCol() )
oPDF:nRow += 1
oPDF:MaxRowTest()
oPDF:DrawText( oPDF:nRow, 0, "*** ICMS ***" )
oPDF:DrawText( oPDF:nRow, 20, m_totvlcon, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 40, m_toticmba, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 60, m_toticmvl, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 80, m_toticmis, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 100, m_toticmou, PicVal(14,2) )
oPDF:DrawLine( oPDF:nRow + 1, 0, oPDF:nRow + 1, oPDF:MaxCol() )
oPDF:nRow += 3
oPDF:MaxRowTest()
oPDF:DrawText( oPDF:nRow, 0, "SAIDAS:" )
oPDF:nRow += 2
oPDF:MaxRowTest()
STORE 0 to m_totvlcon, m_toticmba, m_toticmvl, ;
m_toticmis, m_toticmou
STORE 0 to m_totipiba, m_totipivl, m_totipiis, m_totipiou
SELECT jpfiscal
OrdSetFocus("jpfiscal3")
SEEK "1" SOFTSEEK
DO WHILE nKey != K_ESC .AND. jpfiscal->lfTipLan=="1" .AND. ! Eof()
nKey = Inkey()
GrafProc()
IF jpfiscal->lfDatLan > m_dataf .AND. nOpcData == 2
SKIP
LOOP
ENDIF
IF jpfiscal->lfDatLan < m_datai .AND. nOpcData == 2
SKIP
LOOP
ENDIF
m_data := Substr( Dtoc( jpfiscal->lfDatLan ), iif( nOpcTotais == 1, 1, 4 ) )
STORE 0 to m_clavlcon, m_claicmba, m_claicmvl, m_claicmis, m_claicmou, m_claipiba, m_claipivl, m_claipiis, m_claipiou
DO WHILE nKey != K_ESC .AND. jpfiscal->lfTipLan=="1" .AND. ! Eof()
IF Substr(Dtoc(jpfiscal->lfDatLan),iif(nOpcTotais==1,1,4)) != m_Data
EXIT
ENDIF
nKey = Inkey()
GrafProc()
IF jpfiscal->lfDatLan > m_dataf .AND. nOpcData == 2
SKIP
LOOP
ENDIF
IF jpfiscal->lfDatLan < m_datai .AND. nOpcData == 2
SKIP
LOOP
ENDIF
IF ( nOpcGrf == 2 .AND. jpfiscal->lfGRF != "S" ) .OR. ( nOpcGrf == 3 .AND. jpfiscal->lfGRF == "S" )
SKIP
LOOP
ENDIF
m_clavlcon = Round( m_clavlcon + jpfiscal->lfValCon, 2 )
IF jpfiscal->lfIcmBas != 0
m_claicmba = Round( m_claicmba + jpfiscal->lfIcmBas, 2 )
ENDIF
IF jpfiscal->lfIcmVal != 0
m_claicmvl = Round( m_claicmvl + jpfiscal->lfIcmVal, 2 )
ENDIF
IF jpfiscal->lfValCon - jpfiscal->lfIcmBas - jpfiscal->lfIcmOut > 0
m_claicmis = Round( m_claicmis + ( jpfiscal->lfValCon - jpfiscal->lfIcmBas - jpfiscal->lfIcmOut ), 2 )
ENDIF
IF jpfiscal->lfIcmOut != 0
m_claicmou = Round( m_claicmou + jpfiscal->lfIcmOut, 2 )
ENDIF
IF jpfiscal->lfIpiVal != 0
m_claipiba = Round( m_claipiba + jpfiscal->lfIpiBas, 2 )
m_claipivl = Round( m_claipivl + jpfiscal->lfIpiVal, 2 )
ENDIF
IF jpfiscal->lfValCon - jpfiscal->lfIpiBas - jpfiscal->lfIpiOut - jpfiscal->lfIpiVal > 0
m_claipiis = Round( m_claipiis + ( jpfiscal->lfValCon - jpfiscal->lfIpiBas - jpfiscal->lfIpiOut - jpfiscal->lfIpiVal ), 2 )
ENDIF
IF jpfiscal->lfIpiOut != 0
m_claipiou = Round( m_claipiou + jpfiscal->lfIpiOut, 2 )
ENDIF
SKIP
ENDDO
IF m_clavlcon != 0
oPDF:MaxRowTest()
oPDF:DrawText( oPDF:nRow, 10, m_data )
oPDF:DrawText( oPDF:nRow, 20, m_clavlcon, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 40, m_claicmba, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 60, m_claicmvl, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 80, m_claicmis, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 100, m_claicmou, PicVal(14,2) )
m_totvlcon = Round( m_totvlcon + m_clavlcon, 2 )
m_toticmba = Round( m_toticmba + m_claicmba, 2 )
m_toticmvl = Round( m_toticmvl + m_claicmvl, 2 )
m_toticmis = Round( m_toticmis + m_claicmis, 2 )
m_toticmou = Round( m_toticmou + m_claicmou, 2 )
m_totipiba = Round( m_totipiba + m_claipiba, 2 )
m_totipivl = Round( m_totipivl + m_claipivl, 2 )
m_totipiis = Round( m_totipiis + m_claipiis, 2 )
m_totipiou = Round( m_totipiou + m_claipiou, 2 )
oPDF:nRow += 1
ENDIF
ENDDO
oPDF:MaxRowTest()
oPDF:DrawLine( oPDF:nRow, 0, oPDF:nRow, oPDF:MaxCol() )
oPDF:nRow += 1
oPDF:MaxRowTest()
oPDF:DrawText( oPDF:nRow, 0, "*** ICMS ***" )
oPDF:DrawText( oPDF:nRow, 20, m_totvlcon, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 40, m_toticmba, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 60, m_toticmvl, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 80, m_toticmis, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 100, m_toticmou, PicVal(14,2) )
oPDF:End()
RETURN .T.
Código: Selecionar todos
STATIC FUNCTION imprime()
LOCAL oPDF, nKey, m_TotVlCon, m_TotIcmBa, m_TotIcmIs, m_TotIcmOu, m_TotIpiIs, m_TotIpiOu
LOCAL m_TotIpiVl, m_TotIcmVl, m_TotIpiBa, cSQLGroup
LOCAL cnSQL := ADOClass():New( AppConexao() )
oPDF := PDFClass():New()
oPDF:SetType( nOpcPrinterType )
oPDF:Begin()
nKey = 0
oPDF:acHeader := {"","",""}
oPDF:acHeader[ 1 ] = "RESUMO DA MOVIMENTACAO, POR DATA"
IF nOpcData == 1
oPDF:acHeader[ 2 ] = " "
ELSE
oPDF:acHeader[ 2 ] = "Periodo: " + Dtoc( dDataInicial ) + " a " + Dtoc( dDataFinal ) + iif( nOpcGrf == 1, "", " " + acTxtGrf[ nOpcGrf ] )
ENDIF
oPDF:acHeader[ 3 ] = Space(10) + "--DATA-- ---VALOR CONTABIL-- --BASE DE CALCULO-- -IMPOSTO DEB/CRED.- --ISENTOS/N.TRIBUT- -------OUTROS------"
oPDF:PageHeader()
oPDF:DrawText( oPDF:nRow, 0, "ENTRADAS:" )
oPDF:nRow += 2
WITH OBJECT cnSQL
cSQLGroup := "LPAD( YEAR( LFDATLAN ), 4, '0' ), LPAD( MONTH( LFDATLAN ), 2, '0' )"
IF nOpcTotais == 1
cSQLGroup += ", LPAD( Day( LFDATLAN ), 2, '0' )"
ENDIF
cSQLGroup := "CONCAT_WS( '-', " + cSQLGroup + " )"
:cSQL := "SELECT LFTIPLAN, " + cSQLGroup + " AS DATA, " + ;
" SUM( LFVALCON ) AS VALCON, SUM( IF( LFICMVAL = 0, 0, LFICMBAS ) ) AS ICMBAS," + ;
" SUM( LFICMVAL ) AS ICMVAL, SUM( LFICMOUT ) AS ICMOUT," + ;
" SUM( IF( LFVALCON - LFICMBAS - LFICMOUT > 0, LFVALCON - LFICMBAS - LFICMOUT, 0 ) ) AS ICMISE," + ;
" SUM( LFIPIVAL ) AS IPIVAL, SUM( IF( LFIPIVAL > 0, LFIPIBAS, 0 ) ) AS IPIBAS," + ;
" SUM( IF( LFVALCON - LFIPIBAS - LFIPIOUT - LFIPIVAL > 0, LFVALCON - LFIPIBAS - LFIPIOUT - LFIPIVAL, 0 ) ) AS IPIISE," + ;
" SUM( LFIPIOUT ) AS IPIOUT" + ;
" FROM JPFISCAL" + ;
" WHERE LFTIPLAN IN ( '1', '2' )"
IF nOpcData == 2
:cSQL += " AND LFDATLAN BETWEEN CAST( " + DateSQL( dDataInicial ) + " AS DATE )" + ;
" AND CAST( " + DateSQL( dDataFinal ) + " AS DATE )"
ENDIF
IF nOpcGrf <> 1
:cSQL += " AND LFGRF " + iif( nOpcGrf == 2, "=", "<>" ) + " 'S'"
ENDIF
:cSQL += " GROUP BY LFTIPLAN, " + cSQLGroup + ;
" HAVING VALCON > 0" + ;
" ORDER BY LFTIPLAN DESC, DATA"
:Execute()
STORE 0 to m_totvlcon, m_toticmba, m_toticmvl, m_toticmis, m_toticmou
STORE 0 to m_totipiba, m_totipivl, m_totipiis, m_totipiou
DO WHILE :String( "LFTIPLAN", 1 ) == "2" .AND. nKey != K_ESC .AND. ! :Eof()
GrafProc()
nKey := Inkey()
oPDF:MaxRowTest()
oPDF:DrawText( oPDF:nRow, 10, :String( "DATA" ) )
oPDF:DrawText( oPDF:nRow, 20, :Number( "VALCON" ), PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 40, :Number( "ICMBAS" ), PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 60, :Number( "ICMVAL" ), PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 80, :Number( "ICMISE" ), PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 100, :Number( "ICMOUT" ), PicVal(14,2) )
m_totvlcon += :Number( "VALCON" )
m_toticmba += :Number( "ICMBAS" )
m_toticmvl += :Number( "ICMVAL" )
m_toticmis += :Number( "ICMISE" )
m_toticmou += :Number( "ICMOUT" )
m_totipiba += :Number( "ICMBAS" )
m_totipivl += :Number( "IPIVAL" )
m_totipiis += :Number( "IPIISE" )
m_totipiou += :Number( "IPIOUT" )
oPDF:nRow += 1
:MoveNext()
ENDDO
oPDF:MaxRowTest()
oPDF:DrawLine( oPDF:nRow, 0, oPDF:nRow, oPDF:MaxCol() )
oPDF:nRow += 1
oPDF:MaxRowTest()
oPDF:DrawText( oPDF:nRow, 0, "*** ICMS ***" )
oPDF:DrawText( oPDF:nRow, 20, m_totvlcon, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 40, m_toticmba, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 60, m_toticmvl, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 80, m_toticmis, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 100, m_toticmou, PicVal(14,2) )
oPDF:DrawLine( oPDF:nRow + 1, 0, oPDF:nRow + 1, oPDF:MaxCol() )
oPDF:nRow += 3
oPDF:MaxRowTest()
oPDF:DrawText( oPDF:nRow, 0, "SAIDAS:" )
oPDF:nRow += 2
oPDF:MaxRowTest()
STORE 0 to m_totvlcon, m_toticmba, m_toticmvl, m_toticmis, m_toticmou
STORE 0 to m_totipiba, m_totipivl, m_totipiis, m_totipiou
DO WHILE :String( "LFTIPLAN", 1 ) == "1" .AND. nKey != K_ESC .AND. ! :Eof()
nKey := Inkey()
GrafProc()
oPDF:MaxRowTest()
oPDF:DrawText( oPDF:nRow, 10, :String( "DATA" ) )
oPDF:DrawText( oPDF:nRow, 20, :Number( "VALCON" ), PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 40, :Number( "ICMBAS" ), PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 60, :Number( "ICMVAL" ), PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 80, :Number( "ICMISE" ), PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 100, :Number( "ICMOUT" ), PicVal(14,2) )
m_totvlcon += :Number( "VALCON" )
m_toticmba += :Number( "ICMBAS" )
m_toticmvl += :Number( "ICMVAL" )
m_toticmis += :Number( "ICMISE" )
m_toticmou += :Number( "ICMOUT" )
m_totipiba += :Number( "IPIBAS" )
m_totipivl += :Number( "IPIVAL" )
m_totipiis += :Number( "IPIISE" )
m_totipiou += :Number( "IPIOUT" )
oPDF:nRow += 1
:MoveNext()
ENDDO
oPDF:MaxRowTest()
oPDF:DrawLine( oPDF:nRow, 0, oPDF:nRow, oPDF:MaxCol() )
oPDF:nRow += 1
oPDF:MaxRowTest()
oPDF:DrawText( oPDF:nRow, 0, "*** ICMS ***" )
oPDF:DrawText( oPDF:nRow, 20, m_totvlcon, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 40, m_toticmba, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 60, m_toticmvl, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 80, m_toticmis, PicVal(14,2) )
oPDF:DrawText( oPDF:nRow, 100, m_toticmou, PicVal(14,2) )
:CloseRecordset()
ENDWITH
oPDF:End()
RETURN .T.
Agora é uma soma só, e a precaução ficou por conta disto:
" WHERE LFTIPLAN IN ( '1', '2' )"
Porque?
Porque se tiver um '0' não imprimiria nada, porque não entraria em nenhum dos dois do while.