| @@ 75-150 (lines=76) @@ | ||
| 72 | * @param string $fonteDANFE Nome da fonte alternativa do DAnfe |
|
| 73 | * @param number $mododebug 0-Não 1-Sim e 2-nada (2 default) |
|
| 74 | */ |
|
| 75 | public function __construct( |
|
| 76 | $docXML = '', |
|
| 77 | $sOrientacao = '', |
|
| 78 | $sPapel = '', |
|
| 79 | $sPathLogo = '', |
|
| 80 | $sDestino = 'I', |
|
| 81 | $aEnd = '', |
|
| 82 | $sDirPDF = '', |
|
| 83 | $fontePDF = '', |
|
| 84 | $mododebug = 0 |
|
| 85 | ) { |
|
| 86 | if (is_numeric($mododebug)) { |
|
| 87 | $this->debugMode = (int) $mododebug; |
|
| 88 | } |
|
| 89 | if ($this->debugMode === 1) { |
|
| 90 | // ativar modo debug |
|
| 91 | error_reporting(E_ALL); |
|
| 92 | ini_set('display_errors', 'On'); |
|
| 93 | } elseif ($this->debugMode === 0) { |
|
| 94 | // desativar modo debug |
|
| 95 | error_reporting(0); |
|
| 96 | ini_set('display_errors', 'Off'); |
|
| 97 | } |
|
| 98 | if (is_array($aEnd)) { |
|
| 99 | $this->aEnd = $aEnd; |
|
| 100 | } |
|
| 101 | $this->orientacao = $sOrientacao; |
|
| 102 | $this->papel = $sPapel; |
|
| 103 | $this->pdf = ''; |
|
| 104 | $this->xml = $docXML; |
|
| 105 | $this->logomarca = $sPathLogo; |
|
| 106 | $this->destino = $sDestino; |
|
| 107 | $this->pdfDir = $sDirPDF; |
|
| 108 | // verifica se foi passa a fonte a ser usada |
|
| 109 | if (empty($fontePDF)) { |
|
| 110 | $this->fontePadrao = 'Times'; |
|
| 111 | } else { |
|
| 112 | $this->fontePadrao = $fontePDF; |
|
| 113 | } |
|
| 114 | // se for passado o xml |
|
| 115 | if (!empty($this->xml)) { |
|
| 116 | if (is_file($this->xml)) { |
|
| 117 | $this->xml = file_get_contents($this->xml); |
|
| 118 | } |
|
| 119 | $this->dom = new Dom(); |
|
| 120 | $this->dom->loadXML($this->xml); |
|
| 121 | $this->procEventoCTe = $this->dom->getElementsByTagName("procEventoCTe")->item(0); |
|
| 122 | $this->eventoCTe = $this->procEventoCTe->getElementsByTagName("eventoCTe")->item(0); |
|
| 123 | $this->retEventoCTe = $this->procEventoCTe->getElementsByTagName("retEventoCTe")->item(0); |
|
| 124 | $this->infEvento = $this->eventoCTe->getElementsByTagName("infEvento")->item(0); |
|
| 125 | $this->retInfEvento = $this->retEventoCTe->getElementsByTagName("infEvento")->item(0); |
|
| 126 | $tpEvento = $this->infEvento->getElementsByTagName("tpEvento")->item(0)->nodeValue; |
|
| 127 | if ($tpEvento != '110110') { |
|
| 128 | $this->errMsg = 'Um evento de CC-e deve ser passado.'; |
|
| 129 | $this->errStatus = true; |
|
| 130 | throw new Exception($this->errMsg); |
|
| 131 | } |
|
| 132 | $this->id = str_replace('ID', '', $this->infEvento->getAttribute("Id")); |
|
| 133 | $this->chCTe = $this->infEvento->getElementsByTagName("chCTe")->item(0)->nodeValue; |
|
| 134 | $this->tpAmb = $this->infEvento->getElementsByTagName("tpAmb")->item(0)->nodeValue; |
|
| 135 | $this->cOrgao = $this->infEvento->getElementsByTagName("cOrgao")->item(0)->nodeValue; |
|
| 136 | $this->infCorrecao = $this->infEvento->getElementsByTagName("infCorrecao"); |
|
| 137 | $this->xCondUso = $this->infEvento->getElementsByTagName("xCondUso")->item(0)->nodeValue; |
|
| 138 | $this->dhEvento = $this->infEvento->getElementsByTagName("dhEvento")->item(0)->nodeValue; |
|
| 139 | $this->cStat = $this->retInfEvento->getElementsByTagName("cStat")->item(0)->nodeValue; |
|
| 140 | $this->xMotivo = $this->retInfEvento->getElementsByTagName("xMotivo")->item(0)->nodeValue; |
|
| 141 | $this->CNPJDest = !empty($this->retInfEvento->getElementsByTagName("CNPJDest")->item(0)->nodeValue) |
|
| 142 | ? $this->retInfEvento->getElementsByTagName("CNPJDest")->item(0)->nodeValue |
|
| 143 | : ''; |
|
| 144 | $this->CPFDest = !empty($this->retInfEvento->getElementsByTagName("CPFDest")->item(0)->nodeValue) |
|
| 145 | ? $this->retInfEvento->getElementsByTagName("CPFDest")->item(0)->nodeValue |
|
| 146 | : ''; |
|
| 147 | $this->dhRegEvento = $this->retInfEvento->getElementsByTagName("dhRegEvento")->item(0)->nodeValue; |
|
| 148 | $this->nProt = $this->retInfEvento->getElementsByTagName("nProt")->item(0)->nodeValue; |
|
| 149 | } |
|
| 150 | } |
|
| 151 | ||
| 152 | /** |
|
| 153 | * monta |
|
| @@ 77-152 (lines=76) @@ | ||
| 74 | * @param string $fonteDANFE Nome da fonte alternativa do DAnfe |
|
| 75 | * @param number $mododebug 0-Não 1-Sim e 2-nada (2 default) |
|
| 76 | */ |
|
| 77 | public function __construct( |
|
| 78 | $docXML = '', |
|
| 79 | $sOrientacao = '', |
|
| 80 | $sPapel = '', |
|
| 81 | $sPathLogo = '', |
|
| 82 | $sDestino = 'I', |
|
| 83 | $aEnd = '', |
|
| 84 | $sDirPDF = '', |
|
| 85 | $fontePDF = '', |
|
| 86 | $mododebug = 0 |
|
| 87 | ) { |
|
| 88 | if (is_numeric($mododebug)) { |
|
| 89 | $this->debugMode = (int) $mododebug; |
|
| 90 | } |
|
| 91 | if ($this->debugMode === 1) { |
|
| 92 | // ativar modo debug |
|
| 93 | error_reporting(E_ALL); |
|
| 94 | ini_set('display_errors', 'On'); |
|
| 95 | } elseif ($this->debugMode === 0) { |
|
| 96 | // desativar modo debug |
|
| 97 | error_reporting(0); |
|
| 98 | ini_set('display_errors', 'Off'); |
|
| 99 | } |
|
| 100 | if (is_array($aEnd)) { |
|
| 101 | $this->aEnd = $aEnd; |
|
| 102 | } |
|
| 103 | $this->orientacao = $sOrientacao; |
|
| 104 | $this->papel = $sPapel; |
|
| 105 | $this->pdf = ''; |
|
| 106 | $this->xml = $docXML; |
|
| 107 | $this->logomarca = $sPathLogo; |
|
| 108 | $this->destino = $sDestino; |
|
| 109 | $this->pdfDir = $sDirPDF; |
|
| 110 | // verifica se foi passa a fonte a ser usada |
|
| 111 | if (empty($fontePDF)) { |
|
| 112 | $this->fontePadrao = 'Times'; |
|
| 113 | } else { |
|
| 114 | $this->fontePadrao = $fontePDF; |
|
| 115 | } |
|
| 116 | // se for passado o xml |
|
| 117 | if (!empty($this->xml)) { |
|
| 118 | if (is_file($this->xml)) { |
|
| 119 | $this->xml = file_get_contents($this->xml); |
|
| 120 | } |
|
| 121 | $this->dom = new Dom(); |
|
| 122 | $this->dom->loadXML($this->xml); |
|
| 123 | $this->procEventoNFe = $this->dom->getElementsByTagName("procEventoNFe")->item(0); |
|
| 124 | $this->evento = $this->procEventoNFe->getElementsByTagName("evento")->item(0); |
|
| 125 | $this->retEvento = $this->procEventoNFe->getElementsByTagName("retEvento")->item(0); |
|
| 126 | $this->infEvento = $this->evento->getElementsByTagName("infEvento")->item(0); |
|
| 127 | $this->retInfEvento = $this->retEvento->getElementsByTagName("infEvento")->item(0); |
|
| 128 | $tpEvento = $this->infEvento->getElementsByTagName("tpEvento")->item(0)->nodeValue; |
|
| 129 | if ($tpEvento != '110110') { |
|
| 130 | $this->errMsg = 'Um evento de CC-e deve ser passado.'; |
|
| 131 | $this->errStatus = true; |
|
| 132 | throw new Exception($this->errMsg); |
|
| 133 | } |
|
| 134 | $this->id = str_replace('ID', '', $this->infEvento->getAttribute("Id")); |
|
| 135 | $this->chNFe = $this->infEvento->getElementsByTagName("chNFe")->item(0)->nodeValue; |
|
| 136 | $this->tpAmb = $this->infEvento->getElementsByTagName("tpAmb")->item(0)->nodeValue; |
|
| 137 | $this->cOrgao = $this->infEvento->getElementsByTagName("cOrgao")->item(0)->nodeValue; |
|
| 138 | $this->xCorrecao = $this->infEvento->getElementsByTagName("xCorrecao")->item(0)->nodeValue; |
|
| 139 | $this->xCondUso = $this->infEvento->getElementsByTagName("xCondUso")->item(0)->nodeValue; |
|
| 140 | $this->dhEvento = $this->infEvento->getElementsByTagName("dhEvento")->item(0)->nodeValue; |
|
| 141 | $this->cStat = $this->retInfEvento->getElementsByTagName("cStat")->item(0)->nodeValue; |
|
| 142 | $this->xMotivo = $this->retInfEvento->getElementsByTagName("xMotivo")->item(0)->nodeValue; |
|
| 143 | $this->CNPJDest = !empty($this->retInfEvento->getElementsByTagName("CNPJDest")->item(0)->nodeValue) |
|
| 144 | ? $this->retInfEvento->getElementsByTagName("CNPJDest")->item(0)->nodeValue |
|
| 145 | : ''; |
|
| 146 | $this->CPFDest = !empty($this->retInfEvento->getElementsByTagName("CPFDest")->item(0)->nodeValue) |
|
| 147 | ? $this->retInfEvento->getElementsByTagName("CPFDest")->item(0)->nodeValue |
|
| 148 | : ''; |
|
| 149 | $this->dhRegEvento = $this->retInfEvento->getElementsByTagName("dhRegEvento")->item(0)->nodeValue; |
|
| 150 | $this->nProt = $this->retInfEvento->getElementsByTagName("nProt")->item(0)->nodeValue; |
|
| 151 | } |
|
| 152 | } |
|
| 153 | ||
| 154 | /** |
|
| 155 | * monta |
|