***********************************************************
* SISTEMA...............: SISMAT - SISTEMA MATERIAL
* PROGRAMA..............: SISMAT61.PRG
* INSTALACAO............: EXIT-INFORMATICA E COML LTDA
* PROGRAMACAO...........: RICARDO SALES RIBEIRO
* DATA..................: 17:57:58  4/1/2010
* REMARKS...............: Entradas On Line
***********************************************************
Save Scre To SisMat61
Quadros(02,02,20,77)
Set Colo To &C_CorTlq
@ 02,35 Say Chr(16)+'    Movimenta‡„o   : Adiciona         '+Chr(17)
Set Colo To
Use CadTab Inde CadTabCd                                     Shared alias a_CadTab New
Use CadMat Inde CadMatCd,CadMatNo,CadMatIr,CadMatSt,CadMatTp Shared alias a_CadMat New
Use CadFor Inde CadForCd,CadForNo                            Shared alias a_CadFor New
Use CadNff Inde CadNffNf                                     Shared alias a_CadNff New
Use IteNff Inde IteNffCd,IteNffDt,IteNffIt,IteNffCb,IteNffCg Shared alias a_IteNff New
Select a_CadNff
Set Orde To 1
Set Conf On
Do while .T.
   Select a_CadNff
   Set Curs On
   Inic_Var()
   wDat_Ent:=Date()
   wDoc:=Space(01)
   T_CadNff()
   Mensagem('Tecle [ESC] p/Sair...')
   Set Colo To &C_CorGet
   @ 04,04 Get wNro_Nff Pict '@!'
   Read
   Clea Gets
   If LastKey() = 27
      DbCloseAll()
      Set Conf Off
      Rest Scre From SisMat61
      Retu
   Endif
   If wNro_Nff = Space(10)
      DbCloseAll()
      Set Conf Off
      Rest Scre From SisMat61
      Retu
   Endif
   Set Colo To &C_CorGet
   Select a_CadNff
   Set Orde To 2
   wChave:=wNro_Nff+wCod_For
   DbSeek(wChave)
   If !Eof()
      Igual_Var()
      T_CadNff()
      Som()
      Mensagem('Documento j  Cadastrado! Continua [S,N] ?')
      wSn:='N'
      Set Inte Off
      Set Colo To w+/r
      @ 23,45 Get wSn Pict '@!' Valid wSn $ 'S,N'
      Read
      Clea Gets
      Set Inte On
      Set Colo To
      If wSn = 'N'
         Set Orde To 1
         Loop
      Endif
   Endif
   Set Orde To 1
   wNff_Ite:=wNro_Nff
   Set Colo To &C_CorGet
   @ 04,15 Get wDat_Emi
   @ 04,27 Get wDat_Ent
   @ 04,38 Get wTip_Est Valid wTip_Est $'1,2'
   Read
   Clea Gets
*******************************************************
*  A opcao wTip_Est e so para definir a maneira de como
*  vou dar entrada, a tela de entrada.
*******************************************************
   Mensagem('Dados Corretos ..........:')
   Set Colo To &C_CorSin
   Grava = 1
   @ 23,30 Prompt 'Sim'
   @ 23,35 Prompt 'NÆo'
   Menu To Grava
   Set Colo To
   If Grava = 1
      Select a_CadNff
      DbAppend()
      If NetErr()
         DbAppend()
         Do while NetErr()
            DbAppend()
         Enddo
      Endif
      Repl_Var()
      DbCommit()
      DbUnlock()
   Else
      If Grava = 2
         Select a_CadNff
         Loop
      Endif
   Endif
   wl:=07
   Do while .T.
      Set Curs On
      Select a_IteNff
*******************************************
* Se o Tipo for 1, a tela de entrada e uma,
* procuro o Codigo e monto a tela
*******************************************
      If wTip_Est = '1'
         Do while .T.
            wCodigo:=Space(06)
            Mensagem('Digite Codigo .: ')
            @ 23,20 Get wCodigo Pict '999999'
            Read
            Clea Gets
            If LastKey() = 27
               Set Colo To /bg
               @ 06,03 Clea To 19,76
               Set Colo To
               Exit
            Endif
            Select a_CadTab
            DbSeek(wCodigo)
            If !Eof()
               wCod_Igo:=wCodigo
               wDes_Ite:=Material
               wPcu_Ite:=wCus_Ite:=Custo
            Endif
            Do while .T.
               Mensagem('Tecle [ESC] p/Retornar')
               Set Colo To w+/bg
               @ 06,04 Say 'Qtde.'
               @ 06,10 Say 'Ird'
               @ 06,31 Say 'Sc'
               @ 06,42 Say 'Codigo'
               @ 06,49 Say 'Material'
               @ 06,71 Say 'Custo'
               Set Colo To
               wCod_Bar:=Space(20)
               wSct_Ite:=Space(12)
               wTip_Ite:=wTip_Est
               wQtd_Ite:=1
               wTot_Ite:=0
               Set Colo To &C_CorGet
               @ wl,04 Get wQtd_Ite Pict '99999'
               @ wl,10 Get wCod_Bar Pict '@!'
               @ wl,31 Get wSct_Ite Pict '@s10'
               @ wl,42 Get wCod_igo Pict '@!'
               @ wl,49 Get wDes_Ite Pict '@s18'
               @ wl,68 Get wCus_Ite Pict '@e 9,999.99'
               Clea Gets
               Set Colo To &C_CorGet
               @ wl,10 Get wCod_Bar Pict '@!'
               Read
               Clea Gets
               If LastKey() = 27
                  Set Colo To /bg
                  @ 06,03 Clea To 19,76
                  Set Colo To
                  Exit
               Endif
               wChave0:=wNff_Ite+wCod_For+wCod_Bar
               Select a_IteNff
               Set Orde To 1
               DbSeek(wChave0)
               If !Eof()
                  Som()
                  Mensagem('Item J  Cadastrado...Tecle [ENTER]')
                  Set Curs Off
                  Inkey(0)
                  Select a_IteNff
                  Loop
               Endif
               Select a_CadMat
               Set Orde To 3
               DbSeek(wCod_Bar)
               If !Eof()
                  Som()
                  Mensagem('Material j  Cadastrado...Tecle [ENTER]')
                  Set Curs Off
                  Inkey(0)
                  Set Curs On
                  Select a_IteNff
                  Loop
               Endif
               Select a_IteNff
               @ wl,31 Get wSct_Ite Pict '@s10'
               Read
               Clea Gets
               Mensagem('Confirma Item ...........:')
               Set Colo To &C_CorSin
               Grava = 1
               @ 23,30 Prompt 'Sim'
               @ 23,35 Prompt 'NÆo'
               Menu To Grava
               Set Colo To
               If Grava = 1
                  Select a_CadMat
                  Set Orde To 1
                  DbAppend()
                  If NetErr()
                     DbAppend()
                     Do while NetErr()
                        DbAppend()
                     Enddo
                  Endif
                  Repl Codigo   with wCod_Igo
                  Repl Material with wDes_Ite
                  Repl Ird      with wCod_Bar
                  Repl Sc       with wSct_Ite
                  Repl Qtde     with wQtd_Ite
                  Repl Tipo     with wTip_Ite
                  Repl Custo    with wCus_Ite
                  DbCommit()
                  DbUnlock()
                  Select a_IteNff
                  DbAppend()
                  If NetErr()
                     DbAppend()
                     Do while NetErr()
                        DbAppend()
                     Enddo
                  Endif
                  Repl Nro_Ite with wNro_Reg
                  Repl Nff_Ite with wNff_Ite
                  Repl Dat_Ite with wDat_Ent
                  Repl For_Ite with wCod_For
                  Repl Qtd_Ite with wQtd_Ite
                  Repl Cod_Ite with wCod_Igo
                  Repl Des_Ite with wDes_Ite
                  Repl Cod_Bar with wCod_Bar
                  Repl Pcu_Ite with wCus_Ite
                  Repl Tot_Ite with wCus_Ite*wQtd_Ite
                  Repl Tip_Ite with wTip_Doc
                  Repl Tip_Est with wTip_Ite
                  Repl Cod_Sct with wSct_Ite
                  DbCommit()
                  DbUnlock()
               Else
                  Loop
               Endif
               wl:=wl+1
               If wl > 19
                  Set Colo To /bg
                  @ 06,03 Clea To 19,76
                  Set Colo To
                  wl:=07
                  Loop
               Endif
            Enddo
         Enddo
      Else
*******************************************
* Se o Tipo for 2, a tela de entrada e uma,
* procuro o Codigo e monto a tela
*******************************************
         If wTip_Est = '2'
            Do while .T.
               Mensagem('Tecle [ESC] p/Retornar')
               wCod_Igo:=Space(06)
               wDes_Ite:=Space(45)
               wCod_Ite:=Space(20)
               wCod_Bar:=Space(20)
               wSct_Ite:=Space(12)
               wUnd_Ite:=Space(02)
               wTip_Ite:=wTip_Est
               wQtd_Ite:=0
               wPcu_Ite:=wTot_Ite:=wQtd_Dig:=wCus_Ite:=0
               Set Colo To w+/bg
               @ 06,04 Say 'Qtde.'
               @ 06,10 Say 'Codigo'
               @ 06,17 Say 'Material'
               @ 06,71 Say 'Custo'
               Set Colo To
               Set Colo To &C_CorGet
               @ wl,04 Get wQtd_Ite Pict '99999'
               @ wl,10 Get wCod_Igo Pict '@!'
               @ wl,17 Get wDes_Ite Pict '@!'
               @ wl,68 Get wCus_Ite Pict '@e 9,999.99'
               Clea Gets
               Set Colo To &C_CorGet
               @ wl,04 Get wQtd_Ite Pict '99999' Valid wQtd_Ite > 0 .and. wQtd_Ite < 30000
               Read
               Clea Gets
               If LastKey() = 27
                  Set Colo To /bg
                  @ 06,03 Clea To 19,76
                  Set Colo To
                  Exit
               Endif
               Set Colo To &C_CorGet
               @ wl,10 Get wCod_Igo
               Read
               Clea Gets
               Select a_CadTab
               DbSeek(wCod_Igo)
               If !Eof()
                  wDes_Ite:=Material
                  wCus_Ite:=Custo
               Else
                  Mensagem('Codigo nÆo Cadastrado...Tecle [ENTER]')
                  Set Curs Off
                  Inkey(0)
                  Set Curs On
                  Loop
               Endif
               wChave0:=wNff_Ite+wCod_For+wCod_Igo
               Select a_IteNff
               Set Orde To 5
               DbSeek(wChave0)
               If !Eof()
                  Som()
                  Mensagem('Item J  Cadastrado...Tecle [ENTER]')
                  Set Curs Off
                  Inkey(0)
                  Select a_IteNff
                  Loop
               Endif
               Select a_CadMat
               Set Orde To 1
               DbSeek(wCod_Igo)
               If Eof()
                  Som()
                  Mensagem('C¢digo Material N„o Cadastrado...Tecle [ENTER]')
                  Set Curs Off
                  Inkey(0)
                  Set Curs On
                  Select a_IteNff
                  Loop
               Endif
               Select a_IteNff
               @ wl,17 Get wDes_Ite Pict '@!'
               @ wl,68 Get wCus_Ite Pict '@e 9,999.99'
               Clea Gets
               Mensagem('Confirma Item ...........:')
               Set Colo To &C_CorSin
               Grava = 1
               @ 23,30 Prompt 'Sim'
               @ 23,35 Prompt 'NÆo'
               Menu To Grava
               Set Colo To
               If Grava = 1
                  Select a_CadMat
                  Set Orde To 1
                  DbSeek(wCod_Igo)
                  Do while !RLock()
                  Enddo
                  Repl Qtde with Qtde + wQtd_Ite
                  DbCommit()
                  DbUnlock()
                  Select a_IteNff
                  DbAppend()
                  If NetErr()
                     DbAppend()
                     Do while NetErr()
                     DbAppend()
                     Enddo
                  Endif
                  Repl Nro_Ite with wNro_Reg
                  Repl Nff_Ite with wNff_Ite
                  Repl Dat_Ite with wDat_Ent
                  Repl For_Ite with wCod_For
                  Repl Qtd_Ite with wQtd_Ite
                  Repl Cod_Ite with wCod_Igo
                  Repl Des_Ite with wDes_Ite
                  Repl Pcu_Ite with wCus_Ite
                  Repl Tot_Ite with wCus_Ite*wQtd_Ite
                  Repl Tip_Ite with wTip_Doc
                  Repl Tip_Est with wTip_Ite
                  DbCommit()
                  DbUnlock()
               Else
                  Loop
               Endif
               wl:=wl+1
               If wl > 19
                  Set Colo To /bg
                  @ 06,03 Clea To 19,76
                  Set Colo To
                  wl:=07
                  Loop
               Endif
            Enddo
         Endif
      Endif
      Exit
   Enddo
Enddo
Set Conf Off
Set Curs Off
DbCloseAll()
Rest Scre From SisMat61
Retu
