public function sefazCancela($chNFe = '', $tpAmb = '2', $xJust = '', $nProt = '', &$aRetorno = array())
{
$chNFe = preg_replace('/[^0-9]/', '', $chNFe);
$nProt = preg_replace('/[^0-9]/', '', $nProt);
$xJust = Strings::cleanString($xJust);
//validação dos dados de entrada
if (strlen($chNFe) != 44) {
$msg = "Uma chave de NFe válida não foi passada como parâmetro {$chNFe}.";
throw new Exception\InvalidArgumentException($msg);
}
if ($nProt == '') {
$msg = "Não foi passado o numero do protocolo!!";
throw new Exception\InvalidArgumentException($msg);
}
if (strlen($xJust) < 15 || strlen($xJust) > 255) {
$msg = "A justificativa deve ter pelo menos 15 digitos e no máximo 255!!";
throw new Exception\InvalidArgumentException($msg);
}
$siglaUF = $this->zGetSigla(substr($chNFe, 0, 2));
//estabelece o codigo do tipo de evento CANCELAMENTO
$tpEvento = '110111';
$nSeqEvento = 1;
//monta mensagem
$tagAdic = "<nProt>{$nProt}</nProt><xJust>{$xJust}</xJust>";
$retorno = $this->zSefazEvento($siglaUF, $chNFe, $tpAmb, $tpEvento, $nSeqEvento, $tagAdic);
$aRetorno = $this->aLastRetEvent;
return $retorno;
}