<% '-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# ' Loja Exemplo Locaweb ' Versão: 6.4 ' Data: 12/09/06 ' Arquivo: ADM_fedex_gera_conhecimento.asp ' Versão do arquivo: 0.0 ' Data da ultima atualização: 29/01/08 ' '----------------------------------------------------------------------------- ' Licença Código Livre: http://comercio.Locaweb.com.br/gpl/gpl.txt '-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# %> <% 'Carrega a configuração dos caminhos a serem usuados na Loja Call identifica_caminhos() varLang = Application("varLang") varSkin = "default" 'Assume a string dos idiomas configurados checkIdioma = Application("idiomasconfigurados") veIdiomas = Split(checkIdioma, ",") ' Esta página só pode ser acessada se o visitante já se autenticou checa_senha() 'Verifica se o perfil de usuário permite acesso a esta página Call checa_perfil_admin(""&ADMPed&"") 'Abre o banco de dados Call abre_conexao(conexao) ' Consulta a tabela 'Pedidos' Set RS_Fedex = Server.CreateObject("ADODB.Recordset") RS_Fedex.CursorLocation = 3 RS_Fedex.CursorType = 0 RS_Fedex.LockType = 3 RS_Fedex.Open "SELECT codigo_pedido, fdx_awbnumber, fdx_date, fdx_type, fdx_netcharge, fdx_surcharge, fdx_grosscharge, fdx_discount, fdx_weight, fdx_weightunit, fdx_awbgif FROM Transacao_Fedex WHERE codigo_pedido = " & Request("codigo_pedido"), Conexao If RS_Fedex.EOF Then ' Consulta a tabela 'Pedidos' Set RS_Pedidos = Server.CreateObject("ADODB.Recordset") RS_Pedidos.CursorLocation = 3 RS_Pedidos.CursorType = 0 RS_Pedidos.LockType = 3 RS_Pedidos.Open "SELECT codigo_pedido, data_pedido_inicio, data_pedido, user_ID, sessionID, ip_cliente, razaosocial_cobranca, cnpj_cobranca, nome_cobranca, cpf_cobranca, rg_cobranca, data_nascimento_cobranca, logradouro_cobranca, numero_cobranca, complemento_cobranca, bairro_cobranca, cidade_cobranca, estado_cobranca, cep_cobranca, pais_cobranca, ddd_cobranca, telefone_cobranca, razaosocial_entrega, cnpj_entrega, nome_entrega, cpf_entrega, rg_entrega, data_nascimento_entrega, logradouro_entrega, numero_entrega, complemento_entrega, bairro_entrega, cidade_entrega, estado_entrega, cep_entrega, pais_entrega, ddd_entrega, telefone_entrega, email_entrega, subtotal, taxa_envio, total, tipo_frete, codigo_frete, peso_total, forma_pagamento, cartao_encrypt, tipo_cartao, instrucoes, atendido, pago, falha, cancelado, devolvido, fraude, num_remessa, boleto_emitido, boleto_tipo, sigla_idioma, sigla_moeda, valor_moeda FROM Pedidos WHERE codigo_pedido = " & Request("codigo_pedido"), Conexao 'Prepara a transacao de envio internacional e transmite para a FedEx 'TS = transacao a ser enviada para a FedEx com os dados para o envio internacional var_date = "" & Year(Date) If Month(Date) < 10 Then var_date = var_date & "0" & Month(Date) Else var_date = var_date & Month(Date) End If If Day(Date) < 10 Then var_date = var_date & "0" & Day(Date) Else var_date = var_date & Day(Date) End If 'inicio da string de transacao FedEx TS = "0,""021""" TS = TS & "24,""" & var_date & """" TS = TS & "25,""REFERENCIA PARA FATURA""" 'Dados do Remetente TS = TS & "4,""" & Application("nomeloja") & """" TS = TS & "32,""" & Application("razaosocial") & """" TS = TS & "5,""" & Application("enderecoloja") & """" TS = TS & "6,""" & Application("bairroloja") & """" TS = TS & "7,""" & Application("cidadeloja") & """" TS = TS & "8,""" & Application("estadoloja") & """" TS = TS & "9,""" & Replace(Application("ceploja"),"-","") & """" TS = TS & "183,""" & Application("foneloja") & """" TS = TS & "117,""" & Application("paisloja") & """" 'email do remetente TS = TS & "1201,""" & Application("mailloja") & """" 'Conta FedEx - teste 152589085 TS = TS & "10,""" & Application("FedExConta") & """" 'Código controle do sistema FedEx - teste 1114115 TS = TS & "498,""" & Application("FedExMeter") & """" 'Dados do destinatario TS = TS & "11,""FEDEX""" TS = TS & "12,""" & RS_Pedidos("nome_entrega") & """" TS = TS & "13,""" & RS_Pedidos("numero_entrega") & "," & RS_Pedidos("logradouro_entrega") & """" TS = TS & "14,""" & RS_Pedidos("complemento_entrega") & """" TS = TS & "15,""" & RS_Pedidos("cidade_entrega") & """" TS = TS & "16,""" & RS_Pedidos("estado_entrega") & """" TS = TS & "17,""" & RS_Pedidos("cep_entrega") & """" TS = TS & "18,""" & RS_Pedidos("ddd_entrega") & RS_Pedidos("telefone_entrega") & """" TS = TS & "50,""" & Cria_Combo_Paises(RS_Pedidos("pais_entrega"),"codifica","") & """" 'email do destinatario TS = TS & "1202,""" & RS_Pedidos("email_entrega") & """" 'tipo de pacote FedEx TS = TS & "1273,""01""" 'tipo de servico FedEx TS = TS & "1274,""01""" 'informacoes adicionais TS = TS & "1116,""C""" TS = TS & "414,""CM""" TS = TS & "1368,""2""" TS = TS & "1369,""1""" TS = TS & "1370,""5""" TS = TS & "23,""1""" TS = TS & "70,""2""" TS = TS & "82-1,""1""" TS = TS & "116,""1""" 'Dados da remessa TS = TS & "79-1,""Produtos""" PesoTotal = Replace(FormatNumber(RS_Pedidos("peso_total"),1),",",".") TS = TS & "1400,""" & PesoTotal & """" TS = TS & "1401,""" & PesoTotal & """" TS = TS & "1407-1,""" & PesoTotal & """" TS = TS & "75,""KGS""" ValorTotal_esp = FormatNumber(Cdbl(RS_Pedidos("total") / 100),6) ValorTotal = FormatNumber(RS_Pedidos("total"),2) TS = TS & "1408-1,""" & Replace(ValorTotal_esp,",",".") & """" TS = TS & "1411,""" & Replace(ValorTotal,",",".") & """" TS = TS & "1415,""" & Replace(ValorTotal,",",".") & """" 'moeda do valor TS = TS & "68,""USD""" 'pais de fabricacao e origem TS = TS & "80-1,""BR""" 'TextoAdicional = "Aqui segue um texto a ser colocado na mensagem de notificacao de envio..." 'TS = TS & "1331,""on""" 'TS = TS & "1203,""" & TextoAdicional & """" TS = TS & "1553,""Y""" TS = TS & "1554,""N""" TS = TS & "1556,""Y""" TS = TS & "1557,""N""" TS = TS & "3025,""FDXE""" TS = TS & "99,""""" RS_Pedidos.Close Set RS_Pedidos = Nothing dim xmlhttp set xmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1") If Application("FedExGateway") = "TESTE" Then hostFEDEX = Application("URLTESTEFEDEX") Else hostFEDEX = Application("URLPRODFEDEX") End If urlFEDEX = "https://" & hostFEDEX & "/GatewayDC" xmlhttp.Open "POST",urlFEDEX,"false" xmlhttp.setRequestHeader "Referer","FedEx" xmlhttp.setRequestHeader "Host", hostFEDEX xmlhttp.setRequestHeader "Accept","image/gif, image/jpeg, image/pjpeg,text/plain, text/html, */*" xmlhttp.setRequestHeader "Content-Type","image/gif" xmlhttp.setRequestHeader "Content-Length", cStr(len(TS)) xmlhttp.send TS ResultBytes= xmlhttp.responseBody ' If you use xmlhttp.responseText here you will not be able to get a label image status = xmlhttp.status statustext = xmlhttp.statusText ' Mask it if you use ResponseText ' Convert the ByteArray response to a String for index = 1 To UBound( ResultBytes ) + 1 ResStr = ResStr & Chr(AscB(MidB( ResultBytes, index, 1 ))) Next ' UnMask if you use ResponseBody Set xmlhttp = nothing '-------------------------------------------------- 'captura o gif '-------------------------------------------------- inputstring = ResStr inputLen = Len(inputstring) startPos = InStr(inputstring, "188,") nPos = startPos + 5 'variavel de teste auxiliar auxString = Mid(inputstring, nPos) outputString = "" Do While nPos <= inputLen bufData = Mid(inputstring, nPos, 1) If bufData = Null Then bufData = Chr(0) End If If bufData = "%" Then bufData = Mid(inputstring, nPos, 3) nPos = nPos + 2 If bufData = "%00" Then bufData = Chr(0) ElseIf bufData = "%22" Then bufData = Chr(34) ElseIf bufData = "%25" Then bufData = Chr(37) End If End If outputString = outputString & bufData nPos = nPos + 1 Loop '-------------------------------------------------- 'create an array with the transaction fields by number '-------------------------------------------------- var_cnt = 0 sName = "" sValue = "" alen = Len(ResStr) first = True Campo = 0 Dim varName(100) Dim varVal(100) For I = 1 To alen If Campo > 0 Then If Campo = 1 Then Campo = Campo + 1 Else If Mid(ResStr, I, 1) = Chr(34) Then Campo = 0 varname(var_cnt) = sName varval(var_cnt) = sValue sName = "" sValue = "" var_cnt = var_cnt + 1 Else sValue = sValue + Mid(ResStr, I, 1) End If End If Else If Mid(ResStr, I, 1) = "," Then first = False Campo = 1 sValue = "" Else '// 188, GIF start If sName = Space(20) Or sName = "188" Then Exit For End If If first And Mid(ResStr, I, 1) = Chr(34) Then first = False sName = "" Else sName = sName + Mid(ResStr, I, 1) End If End If End If Next errorCode = "" For I = 0 To var_cnt - 1 If eval(varname(I)) = 2 Then EMessage = "Erro no Envio FedEx: " & varval(I) & "
" errorCode = varval(I) ElseIf eval(varname(I)) = 3 Then EMessage = EMessage + varval(I) ElseIf eval(varname(I)) = 1416 Then var_grosscharge = varval(I) '* 10 ElseIf eval(varname(I)) = 0 Then var_type = varval(I) '* 10 ElseIf eval(varname(I)) = 1402 Then var_weight = varval(I) '* 10 ElseIf eval(varname(I)) = 1376 Then var_weightunit = varval(I) '* 10 ElseIf eval(varname(I)) = 1416 Then var_grosscharge = varval(I) '* 10 ElseIf eval(varname(I)) = 1417 Then var_surcharge = varval(I) '* 10 ElseIf eval(varname(I)) = 1418 Then var_discount = varval(I) '* 10 ElseIf eval(varname(I)) = 1419 Then var_netcharge = varval(I) '* 10 ElseIf eval(varname(I)) = 29 Then AWBNumber = Trim(varval(I)) ElseIf eval(varname(I)) = 1012 Then pkStationID = Trim(varval(I)) ElseIf eval(varname(I)) = 1013 Then pkMessage = Trim(varval(I)) ElseIf eval(varname(I)) = 1011 Then pkNumber = Trim(varval(I)) ElseIf eval(varname(I)) = 1123 Then var_masterawb = Trim(varval(I)) ElseIf eval(varname(I)) = 1124 Then var_pkgnumber = Trim(varval(I)) End If Next '-------------------------------------------------- If Len(EMessage) > 0 Then FedEx_Erro = EMessage Else ETQ_FEDEX = Application("DiretorioImagensConteudo") & "\ETQ_FEDEX\" IMG_FEDEX = ETQ_FEDEX & AWBNumber & ".gif" Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 'Checa se o diretório ETQ_FEDEX existe If objFSO.FolderExists(Application("DiretorioImagensConteudo") & "\ETQ_FEDEX") = false then 'Cria o diretório ETQ_FEDEX objFSO.CreateFolder(Application("DiretorioImagensConteudo") & "\ETQ_FEDEX") End If Set objFSO = Nothing 'Salva a etiqueta como uma imagem em um arquivo GIF '-------------------------------------------------- Set objFSO=Server.CreateObject("Scripting.FileSystemObject") If NOT objFSO.FolderExists(ETQ_FEDEX) Then Set CreateFolder = objFSO.CreateFolder(ETQ_FEDEX) Set CreateFolder = nothing End If Set CreateImage = objFSO.OpenTextFile(IMG_FEDEX, 2, True) CreateImage.writeline outputstring CreateImage.Close Set CreateImage = Nothing Set objFSO = Nothing '-------------------------------------------------- 'Salva a informacao do envio no banco de dados '-------------------------------------------------- fdx_type = var_type fdx_date = mid(var_date,7,2) & "/" & mid(var_date,5,2) & "/" & mid(var_date,1,4) fdx_awbnumber = AWBNumber fdx_netcharge = var_netcharge fdx_surcharge = var_surcharge fdx_grosscharge = var_grosscharge fdx_discount = var_discount fdx_weight = var_weight fdx_weightunit = var_weightunit fdx_awbgif = outputstring RS_Fedex.Addnew RS_Fedex("codigo_pedido") = Request("codigo_pedido") RS_Fedex("fdx_type") = fdx_type RS_Fedex("fdx_date") = fdx_date RS_Fedex("fdx_awbnumber") = fdx_awbnumber RS_Fedex("fdx_netcharge") = fdx_netcharge RS_Fedex("fdx_surcharge") = fdx_surcharge RS_Fedex("fdx_grosscharge") = fdx_grosscharge RS_Fedex("fdx_discount") = fdx_discount RS_Fedex("fdx_weight") = fdx_weight RS_Fedex("fdx_weightunit") = fdx_weightunit RS_Fedex("fdx_awbgif") = fdx_awbgif RS_Fedex.Update '-------------------------------------------------- End If Else fdx_type = RS_Fedex("fdx_type") fdx_date = RS_Fedex("fdx_date") fdx_awbnumber = RS_Fedex("fdx_awbnumber") fdx_netcharge = RS_Fedex("fdx_netcharge") fdx_surcharge = RS_Fedex("fdx_surcharge") fdx_grosscharge = RS_Fedex("fdx_grosscharge") fdx_discount = RS_Fedex("fdx_discount") fdx_weight = RS_Fedex("fdx_weight") fdx_weightunit = RS_Fedex("fdx_weightunit") End If RS_Fedex.close Set RS_Fedex = nothing %> <%=Application("NomeLoja")%>
Fedex - Conhecimento Áereo    
<% If FedEx_Erro <> "" Then %> <% Else %> <% End If %>
ERRO NO PROCESSAMENTO DO ENVIO: <%= FedEx_Erro %>
Código de identificação (awbnumber): <%= fdx_awbnumber %>
Tipo: <%= fdx_type %>
Data: <%= fdx_date %>
Valor líquido: <%= fdx_netcharge %>
Taxa adicional: <%= fdx_surcharge %>
Valor bruto: <%= fdx_grosscharge %>
Desconto: <%= fdx_discount %>
Peso total: <%= fdx_weight %>
Unidade do peso: <%= fdx_weightunit %>