protected function pGeraChaveAdicionalDeContingencia()
{
//cUF tpEmis CNPJ vNF ICMSp ICMSs DD DV
// Quantidade de caracteres 02 01 14 14 01 01 02 01
$forma = "%02d%d%s%014d%01d%01d%02d";
$cUF = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
$CNPJ = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
$CNPJ = substr($CNPJ, -14);
$vNF = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
$vICMS = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
if ($vICMS > 0) {
$vICMS = 1;
}
$icmss = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
if ($icmss > 0) {
$icmss = 1;
}
$dEmi = !empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ? $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
if ($dEmi == '') {
$dEmi = !empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ? $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
$aDemi = explode('T', $dEmi);
$dEmi = $aDemi[0];
}
$dd = $dEmi;
$rpos = strrpos($dd, '-');
$dd = substr($dd, $rpos + 1);
$chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
$chave = $chave . $this->pModulo11($chave);
return $chave;
}