Ponto de Entrada A010TOK Produtos Protheus

Pontos de Entrada Protheus

Ponto de Entrada A010TOK Protheus é uma User Function criada para interagir com uma rotina padrão do ERP TOTVS Protheus. Dependendo do momento em que é acionado durante um processamento, ele pode:

  • Aprimorar validações feitas pela aplicação;
  • Executar ações que dependem das informações atuais do ambiente;
  • Substituir um processamento padrão por uma regra específica do cliente.

Descrição: A010TOK – Validação para inclusão ou alteração do Produto.
Programa/Rotina Padrão: MATA010.PRX – Cadastro de Produto
Localizado em: Function A010TudoOK – Função de Validação para inclusão ou alteração do Produto.
Em que ponto: No início das validações após a confirmação da inclusão ou alteração, antes da gravação do Produto; deve ser utilizado para validações adicionais para a INCLUSÃO ou ALTERAÇÃO do Produto..

Sintaxe: A010TOK – Validação para inclusão ou alteração do Produto ( ) –> lExecuta

Referência TDN: https://tdn.totvs.com/pages/releaseview.action?pageId=235596878

Academia Protheus
Sua academia para uma carreira de Sucesso!

Treinamento que Recomendo 👇


Pensando no Mercado de Trabalho com Totvs Protheus, especialmente para ser um Consultor de Negócios e Implantações ? Aqui está o Treinamento que você precisa: https://go.hotmart.com/Q88839526S

Aproveite e inscreva-se em nosso canal do Youtube: https://bit.ly/36keSmP

Exemplo:

#include "totvs.ch"
#include "topconn.ch"
#include "tbiconn.ch"
#DEFINE cEOF Chr(13)+Chr(10)

/*-------------------------------------------------------------------------------------------*
    {Protheus.doc} User Function A010TOK()   
    @type:      User Function
    @author:    Jose Moura
    @site:      https://academiaprotheus.com.br
    @desc.:     Ponto de entrada mata010 - (Cadastro de produto)
                Por boas práticas eu salvo o arquivo como: PE_A010TOK.prw (.tlpp)
 *-------------------------------------------------------------------------------------------*/

User Function A010TOK()
Local _lRet  	:= .T.
Local aArea  	:= GetArea()
Local cCodPrd	:= M->B1_COD
Local cDesPrd	:= M->B1_DESC
Local cBloqn 	:= M->B1_MSBLQL
Local cUsuID 	:= __cUserId
Local cUsuari 	:= cUserName
Local cMailUsr	:= ""

If .NOT. "SERVICO" $ M->B1_DESC
	If Empty(M->B1_POSIPI)
		FWAlertWarning("Produto : " + M->B1_COD + " - NÃO tem NCM cadastrado!!! Favor corrigir ...","Atenção!")
		_lRet	:= .F.
	Endif
Endif
If cEmpAnt <> "30"
	RestArea(aArea)
	Return(_lRet)
Else
	If ! _lRet
		Return (_lRet)
	Else
		If Inclui
			lIncPrd := .T.
			If ! __cUserId $ "000001*000005"
				Replace SB1->B1_XUSUAA With "I"+__cUserId 
			Else
				PswOrder(1)
				If PswSeek( Substr(M->B1_XUSUAA,2,6), .T. )  
				   cMailUsr := PswRet(1)[1][14] 
				EndIf
			Endif
		Else
			lIncPrd := .F.
			If ! __cUserId $ "000001*000005"
				Replace SB1->B1_XUSUAA With "A"+__cUserId
			Else
				PswOrder(1)
				If PswSeek( Substr(M->B1_XUSUAA,2,6), .T. ) 
				   cMailUsr := PswRet(1)[1][14] 
				EndIf

			Endif
		Endif
		If cBloqn <> '1' .And. ! __cUserId $ "000001*000005"
			Return(.T.)
		Else
			ENVMAIL(lIncPrd,cUsuID,cUsuari,cCodPrd,cDesPrd,cBloqn,cMailUsr)
		Endif
	Endif
Endif
RestArea(aArea)

Return (_lRet)

/*
ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
±±ÉÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍÍ»±±
±±ºPrograma  ³ENVMAIL   ºAutor  ³Jose Moura          º Data ³  07/06/2019 º±±
±±ÌÍÍÍÍÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍ͹±±
±±ºDesc.     ³Ponto de entrada A010TOK -> rotina ENVMAIL ref. inclusao    º±±
±±º          ³ou alteracao no cadastro de produto                         º±±
±±ÌÍÍÍÍÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹±±
±±ºUso       ³Academia Protheus                                           º±±
±±ÈÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±±
±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
*/

Static Function ENVMAIL(lIncPrd,cUsuID,cUsuari,cCodPrd,cDesPrd,cBloqn,cMailUsr)

Local lResul 		:= .T.
Local lResulSend 	:= .T.
Local cError 		:= ""

Private cTitulo  := "Cadastro de Produto - Workflow"
Private cServer  := GetMv("MV_RELSERV",,"")
Private cEmail   := GetMv("MV_RELACNT",,"")
Private cPass    := GetMv("MV_RELPSW",,"")
Private lAuth    := GetMv("MV_RELAUTH",,.T.)
Private cMailAut   := Left(cEMail, At("@", cEMail)-1)

Private cDe      := "fulanocompras@uol.com.br" //cEmail
Private cPara    := Trim(GetMV("MV_MAILCON"))// e-mail do contabil (fulanocontabil@academiaprotheus.com.br)
Private cMailFis := Trim(GetMV("MV_MAILFIS"))// e-mail do Fiscal, responsavel por liberar (desbloquear) o produto
Private cMailCC  := Trim(GetMV("MV_MAILCCC"))// usuarios que incluem ou alteram (cadastro de produto)
Private cBCC  	 := "moura@academiaprotheus.com.br" //copia oculta
Private cAssunto := "O Produto : "+ cCodPrd +"-"+ Substr(cDesPrd,1,15) +"... - " + " foi " + Iif(lIncPrd,"Incluido","Alterado")
Private cAnexo   := Space(200)
Private cMsg     := "O Produto : "+ cCodPrd +"-"+ Substr(cDesPrd,1,15) +"... - " + " foi " + Iif(lIncPrd,"Incluido","Alterado")

cHtml := '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
cHtml += '<html><head>'
cHtml += '  <title>Workflow Academia Protheus</title>'
cHtml += '  <meta content="text/html; charset=windows-1252" http-equiv="Content-Type">'
cHtml += '  <style>'
cHtml += 'BODY {'
cHtml += '	FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;'
cHtml += '	FONT-SIZE: 10pt;'
cHtml += '}'
cHtml += '}'
cHtml += 'DIV {'
cHtml += '	FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;'
cHtml += '	FONT-SIZE: 10pt;'
cHtml += '}'
cHtml += 'TABLE {'
cHtml += '	FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;'
cHtml += '	FONT-SIZE: 10pt;'
cHtml += '}'
cHtml += 'TD {'
cHtml += '	FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;'
cHtml += '	FONT-SIZE: 10pt;'
cHtml += '}'
cHtml += 'FORM {'
cHtml += '	MARGIN: 0px;'
cHtml += '}'
cHtml += 'A:link {'
cHtml += '	COLOR: #2d2dcb;'
cHtml += '}'
cHtml += 'A:visited {'
cHtml += '	COLOR: #2d2dcb;'
cHtml += '}'
cHtml += 'A:active {'
cHtml += '	COLOR: #2d2dcb;'
cHtml += '}'
cHtml += 'A:hover {'
cHtml += '	COLOR: #2d2dcb;'
cHtml += '}'
cHtml += 'INPUT {'
cHtml += '	FONT-FAMILY: Courier;'
cHtml += '	FONT-SIZE: 12px;'
cHtml += '}'
cHtml += '.TableRowSalmonFormMini {'
cHtml += '	BACKGROUND-COLOR: #E4E4E4;'
cHtml += '	COLOR: #000000;'
cHtml += '	FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;'
cHtml += '	FONT-SIZE: 10px;'
cHtml += '}'
cHtml += '.TableRowWhiteMini2 {'
cHtml += '	COLOR: #000000;'
cHtml += '	FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;'
cHtml += '	FONT-SIZE: 10px;'
cHtml += '	VERTICAL-ALIGN: top;'
cHtml += '}'
cHtml += '.auto-style27 {'
cHtml += '	background-color: #626262;'
cHtml += '}'
cHtml += '.auto-style29 {'
cHtml += '	text-align: center;'
cHtml += '	font-family: Arial, Helvetica, sans-serif;'
cHtml += '	font-size: 16pt;'
cHtml += '	color: #FFFFFF;'
cHtml += '}'
cHtml += '.auto-style31 {'
cHtml += '	font-family: Arial, Helvetica, sans-serif;'
cHtml += '	font-size: xx-small;'
cHtml += '	color: #FFFFFF;'
cHtml += '	margin-top: 0;'
cHtml += '	margin-bottom: 0;'
cHtml += '}'
cHtml += '.auto-style37 {'
cHtml += '	text-align: left;'
cHtml += '}'
cHtml += '.auto-style49 {'
cHtml += '	margin-top: 5px;'
cHtml += '	margin-bottom: 5px;'
cHtml += '}'
cHtml += '.auto-style44 {'
cHtml += '	color: #000080;'
cHtml += '}'
cHtml += '.auto-style45 {'
cHtml += '	text-align: left;'
cHtml += '}'
cHtml += '.auto-style46 {'
cHtml += '	font-size: small;'
cHtml += '}'
cHtml += '.auto-style41 {'
cHtml += '	font-size: small;'
cHtml += '	font-family: Arial, Helvetica, sans-serif;'
cHtml += '}'
cHtml += '.auto-style48 {'
cHtml += '	font-family: Arial, Helvetica, sans-serif;'
cHtml += '	font-size: small;'
cHtml += '	background-color: #E5E5E1;'
cHtml += '	text-align: left;'
cHtml += '}'
cHtml += '.auto-style47 {'
cHtml += '	font-family: Arial, Helvetica, sans-serif;'
cHtml += '	font-size: small;'
cHtml += '	background-color: #FFFFFF;'
cHtml += '	text-align: left;'
cHtml += '}'
cHtml += '.auto-style50 {'
cHtml += '	text-align: left;'
cHtml += '	font-size: small;'
cHtml += '}'
cHtml += '.auto-style52 {'
cHtml += '	font-size: medium;'
cHtml += '}'
cHtml += '.auto-style55 {'
cHtml += '	font-family: Arial, Helvetica, sans-serif;'
cHtml += '	font-size: small;'
cHtml += '	background-color: #E5E5E1;'
cHtml += '}'
cHtml += '.auto-style56 {'
cHtml += '	font-family: Arial, Helvetica, sans-serif;'
cHtml += '	font-size: medium;'
cHtml += '	background-color: #FFFFFF;'
cHtml += '	text-align: left;'
cHtml += '}'
cHtml += '.auto-style57 {'
cHtml += '	color: #000080;'
cHtml += '	font-size: medium;'
cHtml += '}'
cHtml += '  </style>'
cHtml += '  <meta content="MSHTML 6.00.3790.4237" name="GENERATOR">'
cHtml += '</head><body topmargin="8" leftmargin="8">'
cHtml += '<div align="center">'
cHtml += '<div align="center">'
cHtml += '<table border="0" width="100%">'
cHtml += '  <tbody>'
cHtml += '    <tr>'
cHtml += '      <td style="font-size: 8pt; width: 93px;"><img src="\\10.91.1.208\totvs12\Protheus_prd\protheus_data\system\lgrl60.bmp"  height="49" width="97"></td>'
cHtml += '      <td bgcolor="#626262" style="font-size: 6pt; color: rgb(214, 214, 214); " width="92%"><align="center"><font color="#ffffff" face="Arial" size="1">'
cHtml += '      <align="center"><font color="#ffffff" face="Arial" size="1"> </font></align="center"></font></align="center">'
cHtml += '      <font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"> </font></font></font>'
cHtml += '      <p style="margin-top: 0pt; margin-bottom: 0pt;" align="right"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1">&amp;amp;nbsp;</font></font></font></p>'
cHtml += '      <font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"> </font></font></font>'
cHtml += '      <div align="center"><font color="#ffffff" face="Arial" size="3"><font color="#ffffff" face="Arial" size="3"><font color="#ffffff" face="Arial" size="3"> &amp;amp;nbsp;<strong>CADASTRO DE PRODUTO</strong></font></font></font></div>'
cHtml += '      <align="center"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"> </font></font></font></font></align="center">'
cHtml += '      <font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"> </font></font></font></font>'
cHtml += '      <p align="right"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1">Academia Protheus - Workflow</font></font></font></font></p>'
cHtml += '      <font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"><font color="#ffffff" face="Arial" size="1"> </font></font></font></font></td>'
cHtml += '    </tr>'
cHtml += '  </tbody>'
cHtml += '</table>'
cHtml += '<p style="margin-top: 0pt; margin-bottom: 0pt;" align="left">&amp;amp;nbsp;</p>'
cHtml += '<font size="4">'
cHtml += '<table style="width: 100%;">'
cHtml += '  <tbody>'
cHtml += '    <tr>'
cHtml += '      <td style="width: 380px; height: 23px;" class="auto-style52"> <font class="auto-style52" face="Arial" size="2">Produto: '+'<span class="auto-style44"> <strong>'+cCodPrd+"-"+cDesPrd+'</strong></span></font></td>'
cHtml += '      <td class="auto-style45" style="height: 23px;"> <font size="4"> <font class="auto-style46" face="Arial" size="2">Data: <strong>'+ALLTRIM(DTOC(DATE()))+'</strong></font></font></td>'
cHtml += '    </tr>'
cHtml += '  </tbody>'
cHtml += '</table>'
cHtml += '<p class="auto-style49" style="height: 0px;">&amp;amp;nbsp;</p>'
cHtml += '<font size="2">'
cHtml += '<table style="width: 100%;">'
cHtml += '  <tbody>'
cHtml += '    <tr>'
cHtml += '      <td bgcolor="#E5E5E1" style="width: 202px;">Login:</td>'
cHtml += '      <td class="auto-style41"><strong>'+cUsuID + "-" +cUsuari + '</strong></td>'
cHtml += '    </tr>'
cHtml += '  </tbody>'
cHtml += '</table>'
cHtml += '<table style="width: 100%;">'
cHtml += '  <tbody>'
cHtml += '    <tr>'
cHtml += '      <td bgcolor="#E5E5E1" style="width: 202px;">Status:</td>'
cHtml += '      <td class="auto-style41"><strong>' + Iif(lIncPrd,"Inclusão","Alteração")+'</strong></td>'
cHtml += '    </tr>'
cHtml += '  </tbody>'
cHtml += '</table>'
cHtml += '<p style="margin-top: 0pt; margin-bottom: 5px;" align="left">&amp;amp;nbsp;</p>'
cHtml += '</font> <font size="2">'
cHtml += '</font> </font> <br>'
cHtml += '<br>'
cHtml += '<br>'
cHtml += '<p>&amp;amp;nbsp;</p>'
cHtml += '</div>'
cHtml += '</div>'
cHtml += '<div align="center">'
cHtml += '<table border="0" cellpadding="0" cellspacing="0" width="100%">'
cHtml += '  <tbody>'
If __cUserId $ '000186'
	cHtml += '    <tr>'
	cHtml += '      <td><font face="Arial" size="2">O Produto acima foi '+Iif(lIncPrd,"Incluido","Alterado")+' e requer sua validação e Liberação!</font></td>'
	cHtml += '    </tr>'
Elseif __cUserId $ '000135*000168'
	cHtml += '    <tr>'
	cHtml += '      <td><font face="Arial" size="2">O Produto acima foi '+Iif(lIncPrd,"Incluido","Alterado")+', revisado e já está Liberado!</font></td>'
	cHtml += '    </tr>'
Else
	If lIncPrd
		cHtml += '    <tr>'
		cHtml += '      <td><font face="Arial" size="2">O Produto acima foi '+Iif(lIncPrd,"Incluido","Alterado")+' e requer sua validação!</font></td>'
		cHtml += '    </tr>'
	Endif
Endif
cHtml += '    <tr>'
cHtml += '      <td align="center" bgcolor="#e4e4e4"> <img src="pic_invis.gif" height="1" width="1"></td>'
cHtml += '    </tr>'
cHtml += '  </tbody>'
cHtml += '</table>'
cHtml += '</div>'
cHtml += '<font size="4"><i><font face="Arial" size="1">E-mail automático enviado pelo processo de workflow, Favor não respondê-lo.</font></i></font>'
cHtml += '</body></html>'

If !Empty(cServer) .And. !Empty(cEmail) .And. !Empty(cPass)
	// Envia e-mail com os dados necessarios
	CONNECT SMTP SERVER cServer ACCOUNT cEmail PASSWORD cPass RESULT lResult
	// Autenticacao da conta de e-mail
	If lResult
		If lAuth
			lResult := MailAuth(cEMail,cPass)
		EndIf
		
		If !lResult
			lResult := MailAuth(cMailAut,cPass)
		EndIf
		
		If lResult
			If !__cUserId $ '000001*000005'
				SEND MAIL  			;
				FROM 		cEMail	;
				TO 			Iif( lIncPrd, cPara, cMailFis );
				BCC 		cBCC	;
				SUBJECT	 	cAssunto;
				BODY	 	cHtml	;
				RESULT		lResult
			Else
				SEND MAIL  			;
				FROM 		cEMail	;
				TO 			Iif( lIncPrd, cPara, cMailUsr );
				BCC 		cBCC	;
				SUBJECT	 	cAssunto;
				BODY	 	cHtml	;
				RESULT		lResult
				
			Endif
			//			ATTACHMENT cPathRel+cArqRel	;
			
			If !lResult
				//Erro no Envio do E-Mail.
				GET MAIL ERROR cError
				ConOut(cError)
			EndIf
		Else
			//Erro na autenticacao da conta
			GET MAIL ERROR cError
			ConOut(cError)
		Endif
	Else
		//Erro na conexao com o SMTP Server
		GET MAIL ERROR cError
		ConOut(cError)
	Endif
Endif

DISCONNECT SMTP SERVER

RETURN()

One thought on “Ponto de Entrada A010TOK Produtos Protheus

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *