@param array $detalhe

@return bool
@throws \Exception
543514
protected function processarDetalhe(array $detalhe)
    {
        $d = $this->detalheAtual();

        if ($this->getSegmentType($detalhe) == 'T') {
            $d->setOcorrencia($this->rem(16, 17, $detalhe))
                ->setOcorrenciaDescricao(array_get($this->ocorrencias, $this->detalheAtual()->getOcorrencia(), 'Desconhecida'))
                ->setNossoNumero($this->rem(41, 48, $detalhe))
                ->setCarteira($this->rem(38, 40, $detalhe))
                ->setNumeroDocumento($this->rem(59, 68, $detalhe))
                ->setDataVencimento($this->rem(74, 81, $detalhe))
                ->setValor(Util::nFloat($this->rem(82, 96, $detalhe)/100, 2, false))
                ->setNumeroControle($this->rem(106, 130, $detalhe))
                ->setPagador([
                    'nome' => $this->rem(149, 188, $detalhe),
                    'documento' => $this->rem(134, 148, $detalhe),
                ])
                ->setValorTarifa(Util::nFloat($this->rem(199, 213, $detalhe)/100, 2, false));

            /**
             * ocorrencias
            */
            $msgAdicional = str_split(sprintf('%08s', $this->rem(214, 221, $detalhe)), 2) + array_fill(0, 5, '');
            if ($d->hasOcorrencia('06', '08', '10')) {
                $this->totais['liquidados']++;
                $d->setOcorrenciaTipo($d::OCORRENCIA_LIQUIDADA);
            } elseif ($d->hasOcorrencia('02')) {
                $this->totais['entradas']++;
                if(array_search('a4', array_map('strtolower', $msgAdicional)) !== false) {
                    $d->getPagador()->setDda(true);
                }
                $d->setOcorrenciaTipo($d::OCORRENCIA_ENTRADA);
            } elseif ($d->hasOcorrencia('09')) {
                $this->totais['baixados']++;
                $d->setOcorrenciaTipo($d::OCORRENCIA_BAIXADA);
            } elseif ($d->hasOcorrencia('32')) {
                $this->totais['protestados']++;
                $d->setOcorrenciaTipo($d::OCORRENCIA_PROTESTADA);
            } elseif ($d->hasOcorrencia('04')) {
                $this->totais['alterados']++;
                $d->setOcorrenciaTipo($d::OCORRENCIA_ALTERACAO);
            } elseif ($d->hasOcorrencia('03', '15', '16', '17', '18')) {
                $this->totais['erros']++;
                $error = Util::appendStrings(
                    array_get($this->rejeicoes, $msgAdicional[0], ''),
                    array_get($this->rejeicoes, $msgAdicional[1], ''),
                    array_get($this->rejeicoes, $msgAdicional[2], ''),
                    array_get($this->rejeicoes, $msgAdicional[3], '')
                );
                $d->setError($error);
            } else {
                $d->setOcorrenciaTipo($d::OCORRENCIA_OUTROS);
            }
        }

        if ($this->getSegmentType($detalhe) == 'U') {
            $d->setValorMulta(Util::nFloat($this->rem(18, 32, $detalhe)/100, 2, false))
                ->setValorDesconto(Util::nFloat($this->rem(33, 47, $detalhe)/100, 2, false))
                ->setValorAbatimento(Util::nFloat($this->rem(48, 62, $detalhe)/100, 2, false))
                ->setValorIOF(Util::nFloat($this->rem(63, 77, $detalhe)/100, 2, false))
                ->setValorRecebido(Util::nFloat($this->rem(78, 92, $detalhe)/100, 2, false))
                ->setValorTarifa($d->getValorRecebido() - Util::nFloat($this->rem(93, 107, $detalhe)/100, 2, false))
                ->setDataOcorrencia($this->rem(138, 145, $detalhe))
                ->setDataCredito($this->rem(146, 153, $detalhe));
        }

        return true;
    }
697220
public function delete($deleteReference = false)
    {
        $returnValue = (bool) false;
        $returnValue = $this->getImplementation()->delete($this, $deleteReference);
        return (bool) $returnValue;
    }
258632
public function order(array $args = array()) {
        $args = $this->getOrder()->parameters($this->merge($args))->text();
        if ($args['return_code'] != 'SUCCESS') {
            throw new Exception($args['return_msg']);
        }
        if ($args['result_code'] != 'SUCCESS') {
            throw new Exception($args['err_code_des']);
        }
        if (!$this->verify($args)) {
            throw new Exception('数据验签失败！');
        }
        $this->set($args);
        return $args;
    }
455165
public function exec($query, $args = array(), $removeCache = null)
    {
        if ($this->connection) {
            if ($this->getCache() && $removeCache) {
                $this->getCache()->remove($removeCache);
            }
            return $this->connection->select($query, $args, false);
        }
        throw new \Exception('Database connection is not open!');
    }
57540
public function supportedLocale($sValue)
    {
        /** @var Locale $oLocale */
        $oLocale           = Factory::service('Locale');
        $aSupportedLocales = $oLocale->getSupportedLocales();
        if (!in_array($sValue, $aSupportedLocales)) {
            $this->set_message('supportedLocale', 'This is not a supported locale');
            return false;
        }

        return true;
    }
266038
public function isRemove($newValue = null)
    {
        if (null !== $newValue) {
            $this->isRemove = (bool) $newValue;
        }
        return $this->isRemove;
    }
708893
public function id($disallowNull = false)
        {
            $id = $this->get($this->_getIdColumnName());

            if ($disallowNull) {
                if (Arrays::is($id)) {
                    foreach ($id as $id_part) {
                        if ($id_part === null) {
                            throw new Exception('Primary key ID contains null value(s)');
                        }
                    }
                } else if ($id === null) {
                    throw new Exception('Primary key ID missing from row or is null');
                }
            }

            return $id;
        }
443640
public function command(array $query)
    {
        // Create command from query
        $command = $this->getCommand($query);

        try {
            $cursor = $this->getInstance()->executeCommand(
                $this->getParam('database'),
                $command
            );
            $response = $cursor->toArray();

        } catch (MongoException $e) {
            new Exception('Unable to execute command');
        }

        return $response ?? false;
    }
1303401
public function get($property) {
		if ($this->isProperty($property)) {
			return $this->properties[$property]->value();
		} else {
      throw new Exception("la propriété '".$property."' est invalide pour l'objet '".get_class($this)."'", '00010004');
		}
	}
1322443
public function handleException($exception, array $error = null)
    {
        if (null === $error) {
            self::$exitCode = 255;
        }
        if (!$exception instanceof \Exception) {
            $exception = new FatalThrowableError($exception);
        }
        $type = $exception instanceof FatalErrorException ? $exception->getSeverity() : E_ERROR;
        $handlerException = null;

        if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) {
            if (false !== strpos($message = $exception->getMessage(), "class@anonymous\0")) {
                $message = (new FlattenException())->setMessage($message)->getMessage();
            }
            if ($exception instanceof FatalErrorException) {
                if ($exception instanceof FatalThrowableError) {
                    $error = [
                        'type' => $type,
                        'message' => $message,
                        'file' => $exception->getFile(),
                        'line' => $exception->getLine(),
                    ];
                } else {
                    $message = 'Fatal '.$message;
                }
            } elseif ($exception instanceof \ErrorException) {
                $message = 'Uncaught '.$message;
            } else {
                $message = 'Uncaught Exception: '.$message;
            }
        }
        if ($this->loggedErrors & $type) {
            try {
                $this->loggers[$type][0]->log($this->loggers[$type][1], $message, ['exception' => $exception]);
            } catch (\Throwable $handlerException) {
            }
        }
        if ($exception instanceof FatalErrorException && !$exception instanceof OutOfMemoryException && $error) {
            foreach ($this->getFatalErrorHandlers() as $handler) {
                if ($e = $handler->handleError($error, $exception)) {
                    $exception = $e;
                    break;
                }
            }
        }
        $exceptionHandler = $this->exceptionHandler;
        $this->exceptionHandler = null;
        try {
            if (null !== $exceptionHandler) {
                return $exceptionHandler($exception);
            }
            $handlerException = $handlerException ?: $exception;
        } catch (\Throwable $handlerException) {
        }
        if ($exception === $handlerException) {
            self::$reservedMemory = null; // Disable the fatal error handler
            throw $exception; // Give back $exception to the native handler
        }
        $this->handleException($handlerException);
    }
96036
public function execute($code, $throwExceptions = false)
    {
        $this->setCode($code, true);
        $closure = new ExecutionClosure($this);

        if ($throwExceptions) {
            return $closure->execute();
        }

        try {
            return $closure->execute();
        } catch (\TypeError $_e) {
            $this->writeException(TypeErrorException::fromTypeError($_e));
        } catch (\Error $_e) {
            $this->writeException(ErrorException::fromError($_e));
        } catch (\Exception $_e) {
            $this->writeException($_e);
        }
    }
155305
private function _checkJoinArray()
	{
		$defaultJoinArray = array('way' => null, 'tables' => null, 'conditionType' => null, 'condition' => null);
		if($this->joinArray === $defaultJoinArray)
		{
			throw new \Exception('one of the methods: inner(), natural(), left[Outer](), right[Outer] must called before!');
		}
	}
14609
public function execute($request)
    {
        $result = $request->authHeaders()->send();

        if ($result->status === self::API_STATUS_FAIL) {
            throw new Exception('Error: '.$result->error);
        }

        return $result;
    }
1191004
private function normalizarDetalle(array &$detalle)
    {
        // agregar nodos (esto para mantener orden del XML)
        $detalle = array_merge([
            'TpoDoc' => false,
            'Emisor' => false,
            'IndFactCompra' => false,
            'NroDoc' => false,
            'Anulado' => false,
            'Operacion' => false,
            'TpoImp' => 1,
            'TasaImp' => false,
            'NumInt' => false,
            'IndServicio' => false,
            'IndSinCosto' => false,
            'FchDoc' => false,
            'CdgSIISucur' => false,
            'RUTDoc' => false,
            'RznSoc' => false,
            'Extranjero' => false,
            'TpoDocRef' => false,
            'FolioDocRef' => false,
            'MntExe' => false,
            'MntNeto' => false,
            'MntIVA' => false,
            'MntActivoFijo' => false,
            'MntIVAActivoFijo' => false,
            'IVANoRec' => false,
            'IVAUsoComun' => false,
            'IVAFueraPlazo' => false,
            'IVAPropio' => false,
            'IVATerceros' => false,
            'Ley18211' => false,
            'OtrosImp' => false,
            'MntSinCred' => false,
            'IVARetTotal' => false,
            'IVARetParcial' => false,
            'CredEC' => false,
            'DepEnvase' => false,
            'Liquidaciones' => false,
            'MntTotal' => false,
            'IVANoRetenido' => false,
            'MntNoFact' => false,
            'MntPeriodo' => false,
            'PsjNac' => false,
            'PsjInt' => false,
            'TabPuros' => false,
            'TabCigarrillos' => false,
            'TabElaborado' => false,
            'ImpVehiculo' => false,
        ], $detalle);
        // si el caso está anulado se genera sólo lo mínimo pedido por el SII
        if (!empty($detalle['Anulado']) and $detalle['Anulado']=='A') {
            $detalle = [
                'TpoDoc' => $detalle['TpoDoc'],
                'NroDoc' => $detalle['NroDoc'],
                'Anulado' => $detalle['Anulado']
            ];
            return;
        }
        // largo campos
        if ($detalle['RznSoc']) {
            $detalle['RznSoc'] = mb_substr($detalle['RznSoc'], 0, 50);
        }
        // calcular valores que no se hayan entregado
        if (isset($detalle['FctProp'])) {
            if ($detalle['IVAUsoComun']===false)
                $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100));
        } else if (!$detalle['MntIVA'] and !is_array($detalle['IVANoRec']) and $detalle['TasaImp'] and $detalle['MntNeto']) {
            $detalle['MntIVA'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100));
        }
        // si el monto total es 0 pero no se asigno neto ni exento se coloca
        if ($detalle['MntExe']===false and $detalle['MntNeto']===false and $detalle['MntTotal']===0) {
            $detalle['MntNeto'] = 0;
        }
        // colocar montos que falten en 0 si es solo exento y no neto
        if ($detalle['MntNeto']===false and $detalle['MntExe']) {
            $detalle['TasaImp'] = \sasco\LibreDTE\Sii::getIVA();
            $detalle['MntNeto'] = 0;
            $detalle['MntIVA'] = 0;
        }
        // normalizar IVA no recuperable
        if (!empty($detalle['IVANoRec'])) {
            if (!isset($detalle['IVANoRec'][0]))
                $detalle['IVANoRec'] = [$detalle['IVANoRec']];
            // si son múltiples iva no recuperable se arma arreglo real
            if (strpos($detalle['IVANoRec'][0]['CodIVANoRec'], ',')) {
                $CodIVANoRec = explode(',', $detalle['IVANoRec'][0]['CodIVANoRec']);
                $MntIVANoRec = explode(',', $detalle['IVANoRec'][0]['MntIVANoRec']);
                $detalle['IVANoRec'] = [];
                $n_inr = count($CodIVANoRec);
                for ($i=0; $i<$n_inr; $i++) {
                    $detalle['IVANoRec'][] = [
                        'CodIVANoRec' => $CodIVANoRec[$i],
                        'MntIVANoRec' => $MntIVANoRec[$i],
                    ];
                }
            }
        }
        // normalizar otros impuestos
        if (!empty($detalle['OtrosImp'])) {
            if (!isset($detalle['OtrosImp'][0]))
                $detalle['OtrosImp'] = [$detalle['OtrosImp']];
            // si son múltiples impuestos se arma arreglo real
            if (strpos($detalle['OtrosImp'][0]['CodImp'], ',')) {
                $CodImp = explode(',', $detalle['OtrosImp'][0]['CodImp']);
                $TasaImp = explode(',', $detalle['OtrosImp'][0]['TasaImp']);
                $MntImp = explode(',', $detalle['OtrosImp'][0]['MntImp']);
                $detalle['OtrosImp'] = [];
                $n_impuestos = count($CodImp);
                for ($i=0; $i<$n_impuestos; $i++) {
                    $detalle['OtrosImp'][] = [
                        'CodImp' => $CodImp[$i],
                        'TasaImp' => !empty($TasaImp[$i]) ? $TasaImp[$i] : false,
                        'MntImp' => $MntImp[$i],
                    ];
                }
            }
            // calcular y agregar IVA no retenido si corresponde
            $retenido = ImpuestosAdicionales::getRetenido($detalle['OtrosImp']);
            if ($retenido) {
                // si el iva retenido es total
                if ($retenido == $detalle['MntIVA']) {
                    $detalle['IVARetTotal'] = $retenido;
                }
                // si el iva retenido es parcial
                else {
                    $detalle['IVARetParcial'] = $retenido;
                    $detalle['IVANoRetenido'] = $detalle['MntIVA'] - $retenido;
                }
            }
        }
        // calcular monto total si no se especificó
        if ($detalle['MntTotal']===false) {
            // calcular monto total inicial
            $detalle['MntTotal'] = $detalle['MntExe'] + $detalle['MntNeto'] + (int)$detalle['MntIVA'];
            // agregar iva no recuperable al monto total
            if (!empty($detalle['IVANoRec'])) {
                foreach ($detalle['IVANoRec'] as $IVANoRec) {
                    $detalle['MntTotal'] += $IVANoRec['MntIVANoRec'];
                }
            }
            // agregar iva de uso común al monto total
            if (isset($detalle['FctProp'])) {
                $detalle['MntTotal'] += $detalle['IVAUsoComun'];
            }
            // descontar del total la retención total de IVA
            if (!empty($detalle['OtrosImp'])) {
                foreach ($detalle['OtrosImp'] as $OtrosImp) {
                    if (ImpuestosAdicionales::getTipo($OtrosImp['CodImp'])=='R') {
                        $detalle['MntTotal'] -= $OtrosImp['MntImp'];
                    }
                }
            }
            // agregar otro montos e impuestos al total
            $detalle['MntTotal'] += (int)$detalle['MntSinCred'] + (int)$detalle['TabPuros'] + (int)$detalle['TabCigarrillos'] + (int)$detalle['TabElaborado'] + (int)$detalle['ImpVehiculo'];
        }
        // si no hay no hay monto neto, no se crean campos para IVA
        if ($detalle['MntNeto']===false) {
            $detalle['MntNeto'] = $detalle['TasaImp'] = $detalle['MntIVA'] = false;
        }
        // si el código de sucursal no existe se pone a falso, esto básicamente
        // porque algunos sistemas podrían usar 0 cuando no hay CdgSIISucur
        if (!$detalle['CdgSIISucur']) {
            $detalle['CdgSIISucur'] = false;
        }
    }
1145039
public static function _matchException($actual, $exception)
    {
        if (!$actual) {
            return false;
        }
        if ($exception instanceof AnyException) {
            $code = $exception->getCode() ? $actual->getCode() : $exception->getCode();
            $class = get_class($actual);
        } else {
            $code = $actual->getCode();
            $class = get_class($exception);
        }

        if (get_class($actual) !== $class) {
            return false;
        }

        $sameCode = $code === $exception->getCode();
        $sameMessage = static::_sameMessage($actual->getMessage(), $exception->getMessage());
        return $sameCode && $sameMessage;
    }
793194
public function setFetchDepth($fetchDepth = null)
    {
        if (!$this->useFetchDepth) {
            return 0;
        }

        $oldFetchDepth = $this->session->getSessionOption($this->useFetchDepth);

        if (isset($fetchDepth)) {
            $this->session->setSessionOption($this->useFetchDepth, $fetchDepth);
        }

        return $oldFetchDepth;
    }
212698
public static function getLastElement(array &$inputArray, $removeElement=false)
    {
        if (count($inputArray) > 0)
        {
            if (!$removeElement)
            {
                $element = end($inputArray);
            }
            else
            {
                $element = array_pop($inputArray);
            }
        }
        else
        {
            throw new \Exception('inputArray has no elements');
        }
        
        return $element;
    }