Detalhamento de Troco

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

frazato
Usuário Nível 3
Usuário Nível 3
Mensagens: 219
Registrado em: 08 Jul 2004 07:45

Detalhamento de Troco

Mensagem por frazato »

Fiz uma rotina para calculo de troco detalhado para uso em meu PDV estou testando caso alguem tenha interesse estou postando, me parece que o projeto ACBR tem uma função que faz isso mais não consegui usa-la.


Frazato

Código: Selecionar todos

/* Joao Frazato
   sistema_jaf@hotmail.com

   Mostrar detalhamento de Troco para uso em PDV JAF
   19/11/2011

*/
#include "Fileio.Ch"
#include "inkey.ch"

SETBLINK(.F.)

Clear

nCompra := 18.25
nTroco  := 0
nPago   := 258.00
wNotas  := {}
                Aadd(wNotas ,{ 100,1,0 })
                Aadd(wNotas ,{  50,2,0 })
                Aadd(wNotas ,{  20,3,0 })
                Aadd(wNotas ,{  10,2,0 })
                Aadd(wNotas ,{   5,1,0 })
                Aadd(wNotas ,{   2,3,0 })
                Aadd(wNotas ,{   1,15,0 })



Do while .t.

Clear
@ 00,00 say Padc('JAF DESENVOLVIMENTOS  - Joao Frazato',MaxCol()) Color('WW/R+')
@ 01,10 say 'Total Compra :' Get nCompra Pict "@E 9999,999.99"
@ 02,10 say 'Total Pago   :' Get nPago Pict "@E 9999,999.99"
Read

If LastKey()==27
   Exit
Endif
nTroco := nPago - nCompra

If nTroco <= 0
   Alert('Sem troco')
Endif

nTroco := Int(nTroco)  // Nao pego os centavos no caso as moedas
@ 03,10 say 'Valor troco :' +Str(nTroco,11,2)

nSeqNota := 1

Do While ( nTroco > 0)
   If nSeqNota > Len(wNotas)
      Alert('erro nas notas')
      Exit
   Endif
   If nTroco >= wNotas[nSeqNota,1]
      If wNotas[nSeqNota,2] > wNotas[nSeqNota,3] 
         ? ' Nota de '+Str(wNotas[nSeqNota,1],7,2)
         nTroco -= wNotas[nSeqNota,1]
         wNotas[nSeqNota,3]++
       Else
          nSeqNota++
      Endif
   Else
      nSeqNota++
   Endif
Enddo
Alert('Olha as notas ..rs..')

// Edicao das notas [wNotas]
private n:= 1, ntot:=len(wNotas)

@ 05,20 to 23,MaxCol()-1
brw:=TBrowseNew(06,21,22,MaxCol()-2)
brw:colorspec := "W/B,n/GR"
brw:headsep   :='___'
brw:colsep    :="   "
brw:gotopblock({|| n:= 1})
brw:gobottomblock({|| n:=ntot})
brw:skipblock({|_1| (n:= n + _1, iif(n < 1, _1:= _1 - n + (n:= ;
   1), iif(n > ntot, _1:= _1 - (n - (n:= ;
   ntot)), Nil)), _1)})


brw:addcolumn(tbcolumnnew("Notas Disponivel",{|| wNotas[n,2] } ))
brw:addcolumn(tbcolumnnew("Valor Nota R$",{|| TRANS(wNotas[n,1],"@E 99,999.99")}))
brw:addcolumn(tbcolumnnew("Notas Usadas ",{|| wNotas[n,3] } ))

volta_db=.t.
st_pesq:=""
idx=1
DO WHILE volta_db
   SETCOLOR("W+/B")
   SET CURSO OFF
   e=1
   DO WHILE !brw:stabilize() .AND. NEXTKEY()=0
   ENDD
   READINSERT(.f.)
   x_ = COL() ; y_ = ROW()
   tecl_p=INKEY(0)
   SET CURSO ON
   brw:dehilite()
   DO CASE

         CASE tecl_p = K_ENTER

              If Brw:ColPos == 3
                 nValor := wNotas[n,3]
                 @ Row(),Col() Get nValor Pict "@E 999999999"
                 Read
                 If LastKey()#27
                    wNotas[n,3] := nValor
                 Endif
                 Brw:Refreshall()
              Endif

              If Brw:ColPos == 1
                 nValor := wNotas[n,2]
                 @ Row(),Col() Get nValor Pict "@E 999999999"
                 Read
                 If LastKey()#27
                    wNotas[n,2] := nValor
                 Endif
                 Brw:Refreshall()
              Endif

         CASE tecl_p = K_ESC
            volta_db=.f.
         CASE tecl_p = K_UP
              brw:up()
         CASE tecl_p = K_DOWN
            brw:down()
         CASE tecl_p = K_RIGHT
            brw:right()
         CASE tecl_p = K_LEFT
            brw:left()
         CASE tecl_p = K_HOME   
            brw:home()
         CASE tecl_p = K_END   
            brw:end()
         CASE tecl_p = K_PGUP   
            brw:pageup()
         CASE tecl_p = K_PGDN   
            brw:pagedown()
         CASE tecl_p = K_CTRL_PGDN
            brw:gobottom()
         CASE tecl_p = K_CTRL_PGUP
            brw:gotop()
         CASE tecl_p = K_CTRL_END   
            brw:panend()
         CASE tecl_p = K_CTRL_HOME   
            brw:panhome()
         CASE tecl_p = K_CTRL_LEFT   
            brw:panleft()
         CASE tecl_p = K_CTRL_RIGHT   
            brw:panright()
   ENDC
   st_pesq=""
ENDD
SET CURSO ON
Enddo
Return Nil


Responder