' === Pratica Obrigatoria 1 (ATIVO) ===
Option Explicit

Sub ProcessarDespachoCompleto()
    Dim ws As Worksheet
    Dim strCategoria As String
    Dim curValor As Currency
    Dim strTemMOPP As String
    Dim strExigencia As String
    Dim curTaxaRisco As Currency
    Dim blnBloqueado As Boolean
    Dim strMotivo As String
    
    Set ws = ThisWorkbook.Worksheets(1)
    
    strCategoria = UCase(Trim(ws.Range("B2").Value))
    curValor = CCur(ws.Range("C2").Value)
    strTemMOPP = UCase(Trim(ws.Range("D2").Value))
    
    curTaxaRisco = 0
    blnBloqueado = False
    
    ' 1. Select Case para Requisitos e Taxas
    Select Case strCategoria
        Case "QUIMICA", "COMBUSTIVEL"
            strExigencia = "MOPP + Vistoria IBAMA"
            curTaxaRisco = 1200
            
        Case "PERECIVEL", "FARMACEUTICA"
            strExigencia = "Termógrafo Calibrado"
            curTaxaRisco = 450
            
        Case "ELETRONICOS"
            If curValor > 300000 Then
                strExigencia = "Escolta Armada + Isca"
                curTaxaRisco = 1800
            Else
                strExigencia = "Rastreador Híbrido"
                curTaxaRisco = 750
            End If
            
        Case "CARGA SECA"
            strExigencia = "Inspeção Padrão"
            curTaxaRisco = 0
            
        Case Else
            strExigencia = "NÃO HOMOLOGADA"
            blnBloqueado = True
            strMotivo = "Categoria inválida."
    End Select
    
    ' 2. Regra de Bloqueio MOPP
    If (strCategoria = "QUIMICA" Or strCategoria = "COMBUSTIVEL") And strTemMOPP <> "SIM" Then
        blnBloqueado = True
        strMotivo = strMotivo & " Falta MOPP."
    End If
    
    ' 3. Gravação de Resultados
    ws.Range("E2").Value = strExigencia
    ws.Range("G2").Value = curTaxaRisco
    ws.Range("G2").NumberFormat = "R$ #,##0.00"
    
    If blnBloqueado Then
        With ws.Range("F2")
            .Value = "BLOQUEADO: " & Trim(strMotivo)
            .Font.Bold = True
            .Font.Color = RGB(255, 255, 255)
            .Interior.Color = RGB(192, 57, 43)
        End With
    Else
        With ws.Range("F2")
            .Value = "LIBERADO"
            .Font.Bold = True
            .Font.Color = RGB(255, 255, 255)
            .Interior.Color = RGB(39, 174, 96)
        End With
    End If
    
    ws.Columns("A:G").AutoFit
End Sub

