/** * Converte para Objetos RPS * @param string $txt lote de RPS em TXT formatado ou path para o arquivo * @return array * @throws InvalidArgumentException */ public static function toRps($txt = '') { if (empty($txt)) { throw new InvalidArgumentException('Algum dado deve ser passado para converter.'); } $aRps = array(); if (is_file($txt)) { //extrai cada linha do arquivo em um campo de matriz $aDados = file($txt, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES | FILE_TEXT); } elseif (is_array($txt)) { //carrega a matriz $aDados = $txt; } else { if (strlen($txt) > 0) { //carrega a matriz com as linha do arquivo $aDados = explode("\n", $txt); } else { return $aRps; } } $total = count($aDados); for ($x = 0; $x < $total; $x++) { $aDados[$x] = str_replace("\r", '', $aDados[$x]); $aDados[$x] = Strings::cleanString($aDados[$x]); $tipo = substr($aDados[$x], 0, 1); self::$contTipos[$tipo] += 1; } self::validTipos(); //o numero de notas criadas será a quantidade de tipo 2 ou 3 ou 6 self::$numRps = self::$contTipos['2'] + self::$contTipos['3'] + self::$contTipos['6']; for ($x = 0; $x < self::$numRps; $x++) { self::$aRps[] = new Rps(); } self::zArray2Rps($aDados); self::loadRPS(); return self::$aRps; }
/** * Clear the string of unwanted characters * Will remove all duplicated spaces and if wanted * replace all accented characters by their originals * and all the special ones * @param string $field string to be cleaned */ private function clearFieldString(&$field) { $field = trim(preg_replace('/\\s+/', ' ', $field)); if ($this->limparString) { $field = Strings::cleanString($field); } }
/** * sefazManifesta * Solicita o registro da manifestação de destinatário * @param string $chNFe * @param string $tpAmb * @param string $xJust * @param string $tpEvento * @param array $aRetorno * @return string * @throws Exception\InvalidArgumentException */ public function sefazManifesta($chNFe = '', $tpAmb = '2', $xJust = '', $tpEvento = '', &$aRetorno = array()) { $chNFe = preg_replace('/[^0-9]/', '', $chNFe); $tpEvento = preg_replace('/[^0-9]/', '', $tpEvento); $tagAdic = ''; switch ($tpEvento) { case '210200': //210200 – Confirmação da Operação break; case '210210': //210210 – Ciência da Operação break; case '210220': //210220 – Desconhecimento da Operação break; case '210240': //210240 – Operação não Realizada if (strlen($xJust) < 15 || strlen($xJust) > 255) { $msg = "É obrigatória uma justificativa com 15 até 255 caracteres!!"; throw new Exception\InvalidArgumentException($msg); } $xJust = Strings::cleanString($xJust); $tagAdic = "<xJust>{$xJust}</xJust>"; break; default: $msg = "Esse código de tipo de evento não consta!! {$tpEvento}"; throw new Exception\InvalidArgumentException($msg); } $siglaUF = 'AN'; $nSeqEvento = '1'; $retorno = $this->zSefazEvento($siglaUF, $chNFe, $tpAmb, $tpEvento, $nSeqEvento, $tagAdic); $aRetorno = $this->aLastRetEvent; return $retorno; }
/** * zClean * Efetua limpeza dos campos * * @param array $aCampos * @return array */ protected function zClean($aCampos = array()) { foreach ($aCampos as $campo) { $campo = trim(preg_replace('/\\s+/', ' ', $campo)); if ($this->limparString) { $campo = Strings::cleanString($campo); } } return $aCampos; }
/** * sefazCancela * @param string $chave * @param string $tpAmb * @param string $xJust * @param string $nProt * @param array $aRetorno * @return string * @throws Exception\InvalidArgumentException */ public function sefazCancela($chave = '', $tpAmb = '2', $nSeqEvento = '1', $nProt = '', $xJust = '', &$aRetorno = array()) { if ($tpAmb == '') { $tpAmb = $this->aConfig['tpAmb']; } $chMDFe = preg_replace('/[^0-9]/', '', $chave); $nProt = preg_replace('/[^0-9]/', '', $nProt); $xJust = Strings::cleanString($xJust); if (strlen($chMDFe) != 44) { $msg = "Uma chave de MDFe válida não foi passada como parâmetro {$chMDFe}."; 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 = self::zGetSigla(substr($chMDFe, 0, 2)); //estabelece o codigo do tipo de evento CANCELAMENTO $tpEvento = '110111'; if ($nSeqEvento == '') { $nSeqEvento = '1'; } $tagAdic = "<evCancMDFe><descEvento>Cancelamento</descEvento>" . "<nProt>{$nProt}</nProt><xJust>{$xJust}</xJust></evCancMDFe>"; $retorno = $this->zSefazEvento($siglaUF, $chMDFe, $tpAmb, $tpEvento, $nSeqEvento, $tagAdic); $aRetorno = $this->aLastRetEvent; return $retorno; }
/** * Carga tributária total estimada * Dados normalmente obtidos no IBPT * @param float $valor * @param float $percentual * @param string $fonte */ public function cargaTributaria($valor, $percentual, $fonte) { $this->valorCargaTributariaRPS = number_format($valor, 2, '.', ''); $this->percentualCargaTributariaRPS = number_format($percentual, 4, '.', ''); $this->fonteCargaTributariaRPS = substr(Strings::cleanString($fonte), 0, 10); }
public function cancelamento($motivo) { $this->motCancelamento = Strings::cleanString($motivo); }