LimiteCredito.apl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. #include "PROTHEUS.CH"
  2. #include "RWMAKE.CH"
  3. #include "APWEBEX.CH"
  4. #include "TOPCONN.CH"
  5. #include "TBICONN.CH"
  6. /*__________________________________________________________________________
  7. ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  8. ¦¦+-----------------------------------------------------------------------+¦¦
  9. ¦¦¦Funçäo ¦ LimiteCredito ¦ Autor ¦ Lucilene Mendes ¦ Data ¦16.07.19 ¦¦¦
  10. ¦¦+----------+------------------------------------------------------------¦¦¦
  11. ¦¦¦Descriçäo ¦ Grid com lista de clientes x vendedor p consulta de credito¦¦¦
  12. ¦¦+-----------------------------------------------------------------------+¦¦
  13. ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  14. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*/
  15. User Function LimiteCredito()
  16. Local cHtml
  17. Private cColunas:= ""
  18. Private cItens := ""
  19. Private cTopo := ""
  20. Private cSite := "u_PortalLogin.apw"
  21. Private cPagina := "Clientes"
  22. Private cTitle := ""
  23. Private lTableTools:= .T.
  24. Private lSidebar:= .F.
  25. Private cCodLogin := ""
  26. Private cVendLogin:= ""
  27. Web Extended Init cHtml Start U_inSite()
  28. cVendLogin := u_GetUsrPR()
  29. cCodLogin := U_SetParPR(cVendLogin)
  30. // TODO - Pedro 20210208 - Remover???
  31. If Empty(HttpSession->CodVend)
  32. cHtml:= '<META HTTP-EQUIV="Refresh" CONTENT="0 ; URL='+cSite+'">'
  33. Return cHtml
  34. Else
  35. If !Empty(HttpSession->Superv) .and. HttpSession->Superv <> HttpSession->CodVend
  36. HttpSession->CodVend:= HttpSession->Superv
  37. Endif
  38. Endif
  39. // Pega do parâmetro com o Titulo do Portal
  40. cTitle := SuperGetMV("PS_TITLE", .T., "Portal SMS")
  41. // Define a funcao a ser chama no link
  42. cSite := "u_SMSPortal.apw?PR="+cCodLogin
  43. // Monta o cabeçalho para a pagina
  44. cHeader := U_PSHeader(cTitle, cSite)
  45. //Função que atualiza os menus
  46. cMenus := U_GetMenus(AllTrim(Upper(Procname())), cVendLogin)
  47. //Topo da janela
  48. //Botão incluir novo cliente
  49. /*
  50. cTopo:= '<div class="row form-group">'
  51. cTopo+= ' <div class="col-sm-3">'
  52. cTopo+= ' <button class="btn btn-primary" id="btAddCli" name="btAddCli" onclick="javascript: location.href= '+"'"+' u_AddCliente.apw?PR=' +cCodLogin+"'"+ ';">'
  53. cTopo+= ' <i class="fa fa-plus"></i> Cadastrar Cliente</button>'
  54. cTopo+= ' </div>'
  55. cTopo+= '</div>'
  56. */
  57. //Cabeçalho do grid
  58. cColunas+= '<th>Código</th>'
  59. cColunas+= '<th>Loja</th>'
  60. cColunas+= '<th>CNPJ</th>'
  61. cColunas+= '<th>Razão Social</th>'
  62. cColunas+= '<th>Nome Fantasia</th>'
  63. cColunas+= '<th>Endereço</th>'
  64. cColunas+= '<th>Cidade</th>'
  65. cColunas+= '<th>UF</th>'
  66. cColunas+= '<th>Telefone</th>'
  67. cColunas+= '<th>E-mail</th>'
  68. cColunas+= '<th>Primeira Compra</th>'
  69. cColunas+= '<th>Última Compra</th>'
  70. cColunas+= '<th>Dias em Atraso</th>'
  71. If HttpSession->Tipo = 'S' //Supervisor acessa todas as informações da sua equipe
  72. cColunas+= '<th>Vendedor</th>'
  73. Endif
  74. // Localiza os clientes deste vendedor
  75. cQuery := " Select SA1.R_E_C_N_O_ RECSA1, A1_COD, A1_LOJA, A1_CGC, A1_NOME, A1_NREDUZ, A1_BAIRRO, A1_END, A1_MUN, A1_EST, A1_DDD,"
  76. cQuery += " A1_TEL, A1_EMAIL, A1_COND, A1_VEND, A1_PRICOM, A1_ULTCOM, (SELECT MIN(E1_VENCTO )VENCTO FROM "+RetSqlName("SE1")+" SE1 "
  77. cQuery += " WHERE E1_CLIENTE = A1_COD AND E1_LOJA = A1_LOJA AND E1_SALDO > 0 AND E1_VENCTO < '"+dtos(dDataBase)+"' "
  78. cQuery += " AND E1_TIPO NOT IN ('NCC','RA') AND E1_TIPO NOT IN " + FormatIn(MVABATIM,"|")"
  79. cQuery += " AND SE1.D_E_L_E_T_ = ' ') AS VENCTO"
  80. cQuery += " From "+RetSqlName("SA1")+" SA1 "
  81. cQuery += " Where A1_FILIAL = '"+xFilial("SA1")+"' "
  82. If HttpSession->Tipo = 'S' //Supervisor acessa todos os clientes da sua equipe
  83. cQuery+= " AND A1_VEND in "+FormatIn(HttpSession->Equipe,"|")+" "
  84. Else
  85. cQuery+= " AND A1_VEND = '"+cVendLogin+"'" // OR A1_VEND2 = '"+cCodVend+"' OR A1_VEND3= '"+cCodVend+"' OR A1_VEND4= '"+cCodVend+"' OR A1_VEND5 = '"+cCodVend+"' ) "
  86. Endif
  87. cQuery += " And A1_MSBLQL <> '1' "
  88. //cQuery += " And A1_ULTCOM >= '"+DTOS(MonthSub(date(),6))+"' "
  89. cQuery += " And SA1.D_E_L_E_T_ = ' ' "
  90. cQuery += " Order by A1_NOME "
  91. If Select("QRY") > 0
  92. QRY->(dbCloseArea())
  93. Endif
  94. APWExOpenQuery(ChangeQuery(cQuery),'QRY',.T.)
  95. While QRY->(!Eof())
  96. cClick:= '' //' role="button" onclick="detLimite('+"'"+QRY->A1_COD+QRY->A1_LOJA+"'"+'); "'
  97. cItens+='<tr>'
  98. cItens+=' <td'+cClick+'>'+QRY->A1_COD+'</td>'
  99. cItens+=' <td'+cClick+'>'+QRY->A1_LOJA+'</td>'
  100. cItens+=' <td'+cClick+'>'+Transform(QRY->A1_CGC,PesqPict("SA2","A2_CGC"))+'</td>'
  101. cItens+=' <td'+cClick+'>'+Upper(Alltrim(QRY->A1_NOME))+'</td>'
  102. cItens+=' <td'+cClick+'>'+Upper(Alltrim(QRY->A1_NREDUZ))+'</td>'
  103. cItens+=' <td'+cClick+'>'+Upper(Alltrim(QRY->A1_END)+" - "+Alltrim(QRY->A1_BAIRRO))+'</td>'
  104. cItens+=' <td'+cClick+'>'+Alltrim(QRY->A1_MUN)+'</td>'
  105. cItens+=' <td'+cClick+'>'+Alltrim(QRY->A1_EST)+'</td>'
  106. cItens+=' <td'+cClick+'>('+Alltrim(QRY->A1_DDD)+')'+Alltrim(QRY->A1_TEL)+'</td>'
  107. cItens+=' <td'+cClick+'>'+Lower(Alltrim(QRY->A1_EMAIL))+'</td>'
  108. cItens+=' <td'+cClick+' data-order="'+(QRY->A1_PRICOM)+'">'+dtoc(stod(QRY->A1_PRICOM))+'</td>'
  109. cItens+=' <td'+cClick+' data-order="'+(QRY->A1_ULTCOM)+'">'+dtoc(stod(QRY->A1_ULTCOM))+'</td>'
  110. cItens+=' <td'+cClick+' data-order="'+(QRY->VENCTO)+'">'+Iif(Empty(QRY->VENCTO),"0",cValtochar(dDataBase - STOD(QRY->VENCTO)))+'</td>'
  111. If HttpSession->Tipo = 'S' //Supervisor acessa todas as informações da sua equipe
  112. cItens+=' <td role="button" '+cClick+'>'+QRY->A1_VEND+' - '+Posicione("SA3",1,xFilial("SA3")+QRY->A1_VEND,"A3_NREDUZ")+'</td>'
  113. Endif
  114. cItens+='</tr>'
  115. QRY->(dbSkip())
  116. End
  117. //Retorna o HTML para construção da página
  118. cHtml := H_SMSGrid()
  119. Web Extended End
  120. Return (cHTML)
  121. /*__________________________________________________________________________
  122. ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  123. ¦¦+-----------------------------------------------------------------------+¦¦
  124. ¦¦¦Funçäo ¦ ConsLmt ¦ Autor ¦ Lucilene Mendes ¦ Data ¦ 16.07.19 ¦¦¦
  125. ¦¦+----------+------------------------------------------------------------¦¦¦
  126. ¦¦¦Descriçäo ¦ Retorna o limite do cliente ¦¦¦
  127. ¦¦+-----------------------------------------------------------------------+¦¦
  128. ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  129. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*/
  130. User Function ConsLmt()
  131. Local cHtml:= ""
  132. Local cCliente := Alltrim(HttpPost->cliente)
  133. Local nLimite := 0
  134. Local nSalPed := 0
  135. Local nSaldo := 0
  136. Local nPrev := 0
  137. Local nFirme := 0
  138. Local nAtraso := 0
  139. Local nDias := 0
  140. Local nTitulos := 0
  141. Web Extended Init cHtml Start U_inSite()
  142. //Posiciona no cliente
  143. dbSelectArea("SA1")
  144. SA1->(dbSeek(xFilial("SA1")+cCliente))
  145. //Busca o limite do cliente
  146. cQry:="Select SUM(A1_LC) A1_LC, SUM(A1_SALPEDL) A1_SALPEDL "
  147. cQry+="From "+RetSqlName("SA1")+" SA1 "
  148. cQry+="Where A1_COD = '"+SA1->A1_COD+"' "
  149. cQry+="And A1_LOJA = '"+SA1->A1_LOJA+"' "
  150. cQry+="And SA1.D_E_L_E_T_ = ' ' "
  151. If Select("QRC") > 0
  152. QRC->(dbCloseArea())
  153. Endif
  154. APWExOpenQuery(cQry,'QRC',.T.)
  155. nLimite:= QRC->A1_LC
  156. nSalPed:= QRC->A1_SALPEDL
  157. //Busca valor em orçamentos
  158. cQry:= "SELECT CJ_XTPORC, SUM(CK_VALOR) VALOR FROM "+RetSqlName("SCJ")+" SCJ "
  159. cQry+= "INNER JOIN "+RetSqlName("SCK")+" SCK ON CK_FILIAL = CJ_FILIAL AND CK_CLIENTE = CJ_CLIENT AND CK_LOJA = CJ_LOJA AND CK_NUM = CJ_NUM "
  160. cQry+= " AND SCK.D_E_L_E_T_ = ' ' "
  161. cQry+= "WHERE CJ_CLIENTE = '"+SA1->A1_COD+"' AND CJ_LOJA = '"+SA1->A1_LOJA+"' "
  162. cQry+= "AND CJ_STATUS = 'A' AND SCJ.D_E_L_E_T_ = ' ' "
  163. cQry+= "GROUP BY CJ_XTPORC "
  164. If Select("QRL") > 0
  165. QRL->(dbCloseArea())
  166. Endif
  167. APWExOpenQuery(cQry,'QRL',.T.)
  168. While QRL->(!Eof())
  169. If QRL->CJ_XTPORC = '2'
  170. nPrev+= QRL->VALOR
  171. Else
  172. nFirme+= QRL->VALOR
  173. Endif
  174. QRL->(DBSkip())
  175. End
  176. //Busca saldo em títulos
  177. cQry:="SELECT SUM(E1_SALDO) SALDO "
  178. cQry+=" FROM "+RetSqlName("SE1")+" SE1 "
  179. cQry+=" WHERE E1_CLIENTE = '"+SA1->A1_COD+"' "
  180. cQry+=" AND E1_LOJA = '"+SA1->A1_LOJA+"' "
  181. cQry+=" AND E1_SALDO > 0 "
  182. cQry+=" AND E1_TIPO not in ('NCC','RA') "
  183. cQry+=" AND SE1.D_E_L_E_T_ = ' ' "
  184. If Select("QRS") > 0
  185. QRS->(dbCloseArea())
  186. Endif
  187. APWExOpenQuery(cQry,'QRS',.T.)
  188. nTitulos:= QRS->SALDO
  189. nSaldo:= nLimite - (nSalPed+nTitulos)
  190. //Busca os titulos em atraso do cliente
  191. nDias:= GetNewPar("AA_DIASATR",1)
  192. cQry:= " Select SUM(E1_SALDO) ATRASO from "+RetSqlName("SE1")+" SE1 "
  193. cQry+= " Where E1_CLIENTE = '"+SA1->A1_COD+"' "
  194. cQry+= " And E1_LOJA = '"+SA1->A1_LOJA+"' "
  195. cQry+= " And E1_SALDO > 0 "
  196. cQry+= " And E1_TIPO not in ('NCC','RA') "
  197. cQry+= " And E1_VENCREA < '"+dtos(dDataBase - nDias)+"' "
  198. cQry+= " And D_E_L_E_T_ = ' ' "
  199. If Select("QRA") > 0
  200. QRA->(dbCloseArea())
  201. Endif
  202. TcQuery cQry New Alias "QRA"
  203. If QRA->(!Eof())
  204. nAtraso:= QRA->ATRASO
  205. Endif
  206. cHtml:= Transform(nLimite,PesqPict("SA1","A1_LC"))+'|'+Transform(nSalPed,PesqPict("SA1","A1_SALPEDL"))
  207. cHtml+='|'+Transform(nTitulos,PesqPict("SA1","A1_SALDUP"))+'|'+Transform(nSaldo,PesqPict("SA1","A1_SALDUP"))
  208. cHtml+='|'+dtoc(SA1->A1_VENCLC)+'|'+SA1->A1_RISCO+'|'+Transform(nSalPed,PesqPict("SA1","A1_SALPED"))
  209. cHtml+='|'+Transform(nPrev,PesqPict("SA1","A1_SALDUP"))+'|'+Transform(nFirme,PesqPict("SA1","A1_SALDUP"))
  210. cHtml+='|'+Transform(nAtraso,PesqPict("SA1","A1_SALDUP"))+'|'+Transform(nSalPed+nTitulos,PesqPict("SA1","A1_SALDUP"))
  211. Web Extended End
  212. Return (cHTML)
  213. /*__________________________________________________________________________
  214. ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  215. ¦¦+-----------------------------------------------------------------------+¦¦
  216. ¦¦¦Funçäo ¦ EnvMsgFin ¦ Autor ¦ Lucilene Mendes ¦ Data ¦ 14.09.22 ¦¦¦
  217. ¦¦+----------+------------------------------------------------------------¦¦¦
  218. ¦¦¦Descriçäo ¦ Envia mensagem para o financeiro ¦¦¦
  219. ¦¦+-----------------------------------------------------------------------+¦¦
  220. ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  221. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*/
  222. User Function EnvMsgFin()
  223. Local cHtml:= ""
  224. Local cMsg:= ""
  225. Local cDestMail:= ""
  226. Local cDirAnexos:= '\web\PortalSMS\upload\'+dtos(dDataBase)
  227. Local cVend:= ""
  228. Local cMensag:= Alltrim(HttpPost->mensagem)
  229. Local cAnexos:= Alltrim(HttpPost->anexos)
  230. Local nRecCli:= val(Alltrim(HttpPost->cliente))
  231. Local aAnexos:= {}
  232. Local i:= 0
  233. Web Extended Init cHtml Start U_inSite()
  234. cVend := u_GetUsrPR()
  235. cCodLogin := U_SetParPR(cVend)
  236. HttpSession->codVend:= cVend
  237. cDirAnexos+= +'\'+cVend+"\"
  238. //Verifica se possui anexos
  239. If !Empty(cAnexos)
  240. aAnexos:= Separa(cAnexos,"|")
  241. For i:= 1 to Len(aAnexos)
  242. If !Empty(aAnexos[i])
  243. aAnexos[i]:= cDirAnexos+aAnexos[i]
  244. Endif
  245. Next
  246. Endif
  247. //Posiciona no cliente
  248. dbSelectArea("SA1")
  249. SA1->(dbGoto(nRecCli))
  250. //Posiciona no vendedor
  251. dbSelectArea("SA3")
  252. SA3->(dbSeek(xFilial("SA3")+cVend))
  253. cMsg:= "Mensagem enviada pelo Portal do Representante.<br><br>"
  254. cMsg+= chr(13)+chr(10)
  255. cMsg+= "Vendedor: "+SA3->A3_COD+" - "+Upper(Alltrim(SA3->A3_NOME))+'<br>'
  256. cMsg+= "Cliente: "+SA1->A1_COD+"/"+SA1->A1_LOJA+" - "+Upper(Alltrim(SA1->A1_NOME))+'<br>'
  257. cMsg+= "Mensagem: "+cMensag
  258. cDestMail:= GetNewPar("RB_MSGFIN")
  259. u_MailCM("Mensagem do Representante",{cDestMail},{},"Mensagem do Representante",cMsg,"","",aAnexos)
  260. Web Extended End
  261. Return (cHTML)