<?php
    include_once "conexao.php";

error_reporting(E_ALL ^ E_NOTICE);

class MovimentacoesClass
{
    private $con;
    private $pdo;

    private $id;
    private $cliId;
    private $origem;
    private $servico;
    private $documento;
    private $referencia_externa;
    private $situacao;
    private $recusa_descricao;
    private $codigo_retorno;
    private $codigo_adquirente;
    private $codigo_mcc;
    private $softDescriptor;
    private $autorizacao;
    private $moeda;
    private $nsu_tef;
    private $nsu;
    private $valor;
    private $valorOriginal;
    private $valorTotal;
    private $parcelas;
    private $cartao_portador;
    private $cartao_dig_ini;
    private $cartao_dig_fim;
    private $banderia;
    private $forma_pagamento;
    private $forma_captura;
    private $numero_serie;
    private $data;
    private $enviado_sinpag;
    private $id_sinpag;
    private $urlSinPag;
    private $enviado_movingpay;
    private $idMovingPay;
    private $veiculo_quitado;
    private $boleto_quitado;
    private $pix_enviado;

    private $emiteNota;
    private $novosDados;

    private $notaNome;
    private $notaTelefone;
    private $notaEmail;
    private $notaDocumento;
    private $notaCep;
    private $notaRua;
    private $notaNumero;
    private $notaComplemento;
    private $notaBairro;
    private $notaCidade;
    private $notaEstado;

    private $numeroEc;
    private $numeroCv;

    private $urlNotification;

    private $retornoJson;
    private $tabelaUtilizada;

    private $calcCliente;
    private $calcAdquirente;
    private $calcCdx;
    private $calcPolo;
    private $calcRepresentante;
    private $dataRepasse;

    private $idEstorno;

    private $codCliMovingPay;

    private $permiteEstorno;

    private $retorno;
    private $mensagemRetorno;

    public function __construct()
    {
        $this->con = new Conexao();
        $this->pdo = $this->con->getConexao();
    }

    public function getListaParaEnvioPagtoMovingPay()
    {
        $sql = "select mov.* from movimentacoes mov
                where mov.data_pagamento_ec is not null and mov.data_envio_movingpay is null
                order by mov.codcli_movingpay
                ";
        $resultado = $this->pdo->prepare($sql);
        $resultado->execute();

        return $resultado;
    }

    public function getListaTodos()
    {
        $sql = "select mov.*, cli.cli_nomerazao from movimentacoes mov, cliente cli
                where mov.documento = cli.cli_cpfcnpj and mov.cli_id <> 0
                union
                select mov.*, mov.nota_nome as cli_nomerazao from movimentacoes mov
                where mov.cli_id = 0
                order by 1 desc";
        $resultado = $this->pdo->prepare($sql);
        $resultado->execute();

        return $resultado;
    }

    public function getListaTodosSemEstorno()
    {
        $sql = "select mov.*, cli.cli_nomerazao, cli.cli_fantasia, polo.cli_nomerazao as nome_polo
                from movimentacoes mov 
                left join cliente cli on mov.documento = cli.cli_cpfcnpj
                left outer join cliente polo on cli.cli_idresponsavel = polo.cli_id
                where mov.cli_id <> 0 and mov.servico <> 'Estorno' and mov.data >= CURDATE() - INTERVAL 1 DAY
                union
                select mov.*, mov.nota_nome as cli_nomerazao, '' as cli_fantasia, '' as nome_polo
                from movimentacoes mov
                where mov.cli_id = 0 and mov.servico <> 'Estorno' and mov.data >= CURDATE() - INTERVAL 1 DAY
                order by 1 desc
                LIMIT 300";
        $resultado = $this->pdo->prepare($sql);
        $resultado->execute();

        return $resultado;
    }

    public function getListaTodosSemEstornoPIX()
    {
        $sql = "select mov.*, cli.cli_nomerazao, cli.cli_fantasia, polo.cli_nomerazao as nome_polo,
                mpx.nome as nome_pix, mpx.documento as documento_pix
                from movimentacoes mov 
                left join cliente cli on mov.documento = cli.cli_cpfcnpj
                left outer join cliente polo on cli.cli_idresponsavel = polo.cli_id
                left join movimentacoes_pix mpx on mov.id = mpx.id_movimentacoes
                where mov.cli_id <> 0 and mov.servico <> 'Estorno' and mov.data >= CURDATE() - INTERVAL 1 DAY
                union
                select mov.*, mov.nota_nome as cli_nomerazao, '' as cli_fantasia, '' as nome_polo,
                mpx.nome as nome_pix, mpx.documento as documento_pix
                from movimentacoes mov
                left join movimentacoes_pix mpx on mov.id = mpx.id_movimentacoes
                where mov.cli_id = 0 and mov.servico <> 'Estorno' and mov.data >= CURDATE() - INTERVAL 1 DAY
                order by 1 desc
                LIMIT 300";
        $resultado = $this->pdo->prepare($sql);
        $resultado->execute();

        return $resultado;
    }

    public function getListaTodosSemEstornoConciliacao()
    {
        $sql = "select distinct mov.*, cli.cli_nomerazao, cli.cli_fantasia,
                v.valor_comissao_venda, a.data_credito_antecipacao, o.taxa_ao_mes_operacao as taxa_antecipacao,
                v.valor_da_parcela, v.data_pagamento, v.numero_parcela_relacionada_ao_cv, d.mdr
                from cdx.movimentacoes mov
                left join cdx.cliente cli on mov.documento = cli.cli_cpfcnpj
                left outer join getnet_conciliation.edi_comprovante_venda v on v.data_transacao = date(mov.data) and v.nsu = mov.nsu and v.codigo_estabelecimento_comercial = cast(mov.numero_ec as UNSIGNED)
                left outer join getnet_conciliation.edi_antecipacao a on v.numero_rv = a.numero_rv and v.numero_parcelas = a.qtde_parcelas and v.numero_parcela_relacionada_ao_cv = a.numero_parcela
                left outer join getnet_conciliation.edi_operacao_antecipacao o on a.numero_operacao_antecipacao = o.numero_operacao_antecipacao and a.codigo_estabelecimento_comercial_centralizador = o.codigo_estabelecimento_comercial
                left outer join getnet_conciliation.mcc m on v.codigo_estabelecimento_comercial = m.num_logico
                left outer join getnet_conciliation.mcc_mdr d on m.codigo_mcc = d.codigo_mcc and d.bandeira = mov.banderia and d.tipo_get = mov.forma_pagamento and d.parcela = v.numero_parcelas
                where mov.id > 0 and mov.servico <> 'Estorno' and mov.data >= CURDATE() - INTERVAL 1 DAY
                order by 1 desc
                LIMIT 300";
        $resultado = $this->pdo->prepare($sql);
        $resultado->execute();

        return $resultado;
    }

    public function getListaTodosPendentesLiberacao()
    {
        $sql = "select mov.*, cli.cli_nomerazao, cli.cli_fantasia, polo.cli_nomerazao as nome_polo
                from movimentacoes mov 
                left join cliente cli on mov.documento = cli.cli_cpfcnpj
                left outer join cliente polo on cli.cli_idresponsavel = polo.cli_id
                where mov.cli_id <> 0 and mov.servico <> 'Estorno' and mov.data >= CURDATE() - INTERVAL 1 DAY
                and mov.situacao in('APPR','paid','APROVADA', 'APPROVED') and mov.id_estorno = 0 and mov.repasse_efetuado = 0
                union
                select mov.*, mov.nota_nome as cli_nomerazao, '' as cli_fantasia, '' as nome_polo
                from movimentacoes mov
                where mov.cli_id = 0 and mov.servico <> 'Estorno' and mov.data >= CURDATE() - INTERVAL 1 DAY
                and mov.situacao in('APPR','paid','APROVADA', 'APPROVED') and mov.id_estorno = 0 and mov.repasse_efetuado = 0
                order by 1 desc
                LIMIT 300";
        $resultado = $this->pdo->prepare($sql);
        $resultado->execute();

        return $resultado;
    }

    public function getPesquisaSemEstorno($cliente, $dataIni, $dataFim, $status)
    {
        $origem = $this->getOrigem().'%';
        $servico = $this->getServico().'%';
        $documento = $this->getDocumento().'%';
        $autorizacao = $this->getAutorizacao().'%';

        $cli = $cliente.'%';

        $filtro = "";
        $limit = "";

        if(!empty($dataIni)){
            if(!empty($dataFim)){
                $filtro = " and mov.data between '".date('Y-m-d',strtotime($dataIni)).
                    " 00:00:00' and '".date('Y-m-d',strtotime($dataFim))." 23:59:59' ";
            }else{
                //$filtro = " and mov.data = '".date('Y-m-d',strtotime($dataIni))."' ";
                $filtro = " and mov.data between '".date('Y-m-d',strtotime($dataIni)).
                    " 00:00:00' and '".date('Y-m-d',strtotime($dataIni))." 23:59:59' ";
            }
        }else{
            $limit = " LIMIT 3000 ";
        }

        if($status == "APROVADAS"){
            $filtro .= " and mov.situacao in('APPR','paid','APROVADA', 'APPROVED') and mov.id_estorno = 0 ";
        }

        if($status == "AGUARDANDO"){
            $filtro .= " and mov.situacao in('AGUARDANDO','processing') ";
        }

        if($status == "CANCELADAS"){
            $filtro .= " and (mov.situacao in('CANCELED','CANCELADA','CANCELADO') or mov.id_estorno > 0) ";
        }

        if($status == "REPROVADA"){
            $filtro .= " and mov.situacao in('REPROVADA') ";
        }

        $sql = "select mov.*, cli.cli_nomerazao, cli.cli_fantasia, polo.cli_nomerazao as nome_polo
                from movimentacoes mov
                left join cliente cli on mov.documento = cli.cli_cpfcnpj
                left outer join cliente polo on cli.cli_idresponsavel = polo.cli_id
                where mov.cli_id <> 0 and mov.servico <> 'Estorno' and 
                mov.origem like :origem and mov.servico like :servico and mov.documento like :documento and
                mov.autorizacao like :autorizacao and
                cli.cli_nomerazao like :nome ".$filtro."
                union
                select mov.*, mov.nota_nome as cli_nomerazao, '' as cli_fantasia, '' as nome_polo
                from movimentacoes mov
                where mov.cli_id = 0 and mov.servico <> 'Estorno' and
                mov.autorizacao like :autorizacao and
                mov.origem like :origem and mov.servico like :servico and mov.documento like :documento ".
                $filtro."
                order by 1 desc" .$limit;
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":origem", $origem, PDO::PARAM_STR);
        $resultado->bindParam(":servico", $servico, PDO::PARAM_STR);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->bindParam(":nome", $cli, PDO::PARAM_STR);
        $resultado->bindParam(":autorizacao", $autorizacao, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getPesquisaSemEstornoPIX($cliente, $dataIni, $dataFim, $status)
    {
        $origem = $this->getOrigem().'%';
        $servico = $this->getServico().'%';
        $documento = $this->getDocumento().'%';
        $autorizacao = $this->getAutorizacao().'%';

        $cli = $cliente.'%';

        $filtro = "";

        if(!empty($dataIni)){
            if(!empty($dataFim)){
                $filtro = " and mov.data between '".date('Y-m-d',strtotime($dataIni)).
                    " 00:00:00' and '".date('Y-m-d',strtotime($dataFim))." 23:59:59' ";
            }else{
                //$filtro = " and mov.data = '".date('Y-m-d',strtotime($dataIni))."' ";
                $filtro = " and mov.data between '".date('Y-m-d',strtotime($dataIni)).
                    " 00:00:00' and '".date('Y-m-d',strtotime($dataIni))." 23:59:59' ";
            }
        }else{
            $limit = " LIMIT 3000 ";
        }

        if($status == "APROVADAS"){
            $filtro .= " and mov.situacao in('APPR','paid','APROVADA', 'APPROVED') and mov.id_estorno = 0 ";
        }

        if($status == "AGUARDANDO"){
            $filtro .= " and mov.situacao in('AGUARDANDO','processing') ";
        }

        if($status == "CANCELADAS"){
            $filtro .= " and (mov.situacao in('CANCELED') or mov.id_estorno > 0) ";
        }

        if($status == "REPROVADA"){
            $filtro .= " and mov.situacao in('REPROVADA') ";
        }

        $sql = "select mov.*, cli.cli_nomerazao, cli.cli_fantasia, polo.cli_nomerazao as nome_polo,
                mpx.nome as nome_pix, mpx.documento as documento_pix
                from movimentacoes mov
                left join cliente cli on mov.documento = cli.cli_cpfcnpj
                left outer join cliente polo on cli.cli_idresponsavel = polo.cli_id
                left join movimentacoes_pix mpx on mov.id = mpx.id_movimentacoes
                where mov.cli_id <> 0 and mov.servico <> 'Estorno' and 
                mov.origem like :origem and mov.servico like :servico and mov.documento like :documento and
                mov.autorizacao like :autorizacao and
                cli.cli_nomerazao like :nome ".$filtro."
                union
                select mov.*, mov.nota_nome as cli_nomerazao, '' as cli_fantasia, '' as nome_polo,
                mpx.nome as nome_pix, mpx.documento as documento_pix
                from movimentacoes mov
                left join movimentacoes_pix mpx on mov.id = mpx.id_movimentacoes
                where mov.cli_id = 0 and mov.servico <> 'Estorno' and
                mov.autorizacao like :autorizacao and
                mov.origem like :origem and mov.servico like :servico and mov.documento like :documento ".
            $filtro."
                order by 1 desc".$limit;
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":origem", $origem, PDO::PARAM_STR);
        $resultado->bindParam(":servico", $servico, PDO::PARAM_STR);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->bindParam(":nome", $cli, PDO::PARAM_STR);
        $resultado->bindParam(":autorizacao", $autorizacao, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getPesquisaSemEstornoConciliacao($cliente, $dataIni, $dataFim, $status)
    {
        $origem = $this->getOrigem().'%';
        $servico = $this->getServico().'%';
        $documento = $this->getDocumento().'%';
        $autorizacao = $this->getAutorizacao().'%';

        $cli = $cliente.'%';

        $filtro = "";

        if(!empty($dataIni)){
            if(!empty($dataFim)){
                $filtro = " and mov.data between '".date('Y-m-d',strtotime($dataIni)).
                    " 00:00:00' and '".date('Y-m-d',strtotime($dataFim))." 23:59:59' ";
            }else{
                //$filtro = " and DATE(mov.data) = '".date('Y-m-d',strtotime($dataIni))."' ";
                $filtro = " and mov.data between '".date('Y-m-d',strtotime($dataIni)).
                    " 00:00:00' and '".date('Y-m-d',strtotime($dataIni))." 23:59:59' ";
            }
        }

        if($status == "APROVADAS"){
            $filtro .= " and mov.situacao in('APPR','paid','APROVADA', 'APPROVED') and mov.id_estorno = 0 ";
        }

        if($status == "AGUARDANDO"){
            $filtro .= " and mov.situacao in('AGUARDANDO','processing') ";
        }

        if($status == "CANCELADAS"){
            $filtro .= " and (mov.situacao in('CANCELED') or mov.id_estorno > 0) ";
        }

        $sql = "select distinct mov.*, cli.cli_nomerazao, cli.cli_fantasia,
                v.valor_comissao_venda, a.data_credito_antecipacao, o.taxa_ao_mes_operacao as taxa_antecipacao,
                v.valor_da_parcela, v.data_pagamento, v.numero_parcela_relacionada_ao_cv, d.mdr
                from cdx.movimentacoes mov
                left join cdx.cliente cli on mov.documento = cli.cli_cpfcnpj
                left outer join getnet_conciliation.edi_comprovante_venda v on v.data_transacao = date(mov.data) and v.autorizacao_correta = mov.autorizacao and v.numero_parcelas = mov.parcelas
                left outer join getnet_conciliation.edi_antecipacao a on v.numero_rv = a.numero_rv and v.numero_parcelas = a.qtde_parcelas and v.numero_parcela_relacionada_ao_cv = a.numero_parcela
                left outer join getnet_conciliation.edi_operacao_antecipacao o on a.numero_operacao_antecipacao = o.numero_operacao_antecipacao and a.codigo_estabelecimento_comercial_centralizador = o.codigo_estabelecimento_comercial
                left outer join getnet_conciliation.mcc m on v.codigo_estabelecimento_comercial = m.num_logico
                left outer join getnet_conciliation.mcc_mdr d on m.codigo_mcc = d.codigo_mcc and d.bandeira = mov.banderia and d.tipo_get = mov.forma_pagamento and d.parcela = v.numero_parcelas
                where mov.servico <> 'Estorno' and 
                mov.origem like :origem and mov.servico like :servico and mov.documento like :documento and
                mov.autorizacao like :autorizacao and
                cli.cli_nomerazao like :nome ".$filtro."
                order by 1 desc";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":origem", $origem, PDO::PARAM_STR);
        $resultado->bindParam(":servico", $servico, PDO::PARAM_STR);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->bindParam(":nome", $cli, PDO::PARAM_STR);
        $resultado->bindParam(":autorizacao", $autorizacao, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getPesquisaPendentesLiberacao($cliente, $dataIni, $dataFim, $tipoData)
    {
        $origem = $this->getOrigem().'%';
        $servico = $this->getServico().'%';
        $documento = $this->getDocumento().'%';
        $autorizacao = $this->getAutorizacao().'%';

        $cli = $cliente.'%';

        $filtro = "";

        if($tipoData == "DATA VENDA"){
            if(!empty($dataIni)){
                if(!empty($dataFim)){
                    $filtro = " and mov.data between '".date('Y-m-d',strtotime($dataIni)).
                        " 00:00:00' and '".date('Y-m-d',strtotime($dataFim))." 23:59:59' ";
                }else{
                    //$filtro = " and mov.data = '".date('Y-m-d',strtotime($dataIni))."' ";
                    $filtro = " and mov.data between '".date('Y-m-d',strtotime($dataIni)).
                        " 00:00:00' and '".date('Y-m-d',strtotime($dataIni))." 23:59:59' ";
                }
            }
        }else{
            if(!empty($dataIni)){
                if(!empty($dataFim)){
                    $filtro = " and mov.data_repasse between '".date('Y-m-d',strtotime($dataIni)).
                        "' and '".date('Y-m-d',strtotime($dataFim))."' ";
                }else{
                    //$filtro = " and mov.data = '".date('Y-m-d',strtotime($dataIni))."' ";
                    $filtro = " and mov.data_repasse between '".date('Y-m-d',strtotime($dataIni)).
                        "' and '".date('Y-m-d',strtotime($dataIni))."' ";
                }
            }
        }


        $sql = "select mov.*, cli.cli_nomerazao, cli.cli_fantasia, polo.cli_nomerazao as nome_polo
                from movimentacoes mov
                left join cliente cli on mov.documento = cli.cli_cpfcnpj
                left outer join cliente polo on cli.cli_idresponsavel = polo.cli_id
                where mov.cli_id <> 0 and mov.servico not in ('Estorno','VendasEDI') and 
                mov.origem like :origem and mov.servico like :servico and mov.documento like :documento and
                mov.repasse_efetuado = 0 and mov.origem in('POS', 'TOTEM', 'WEB') and
                mov.autorizacao like :autorizacao and mov.situacao in('APPR','paid','APROVADA', 'APPROVED') and mov.id_estorno = 0 and
                cli.cli_nomerazao like :nome ".$filtro."
                union
                select mov.*, mov.nota_nome as cli_nomerazao, '' as cli_fantasia, '' as nome_polo
                from movimentacoes mov
                where mov.cli_id = 0 and mov.servico not in ('Estorno','VendasEDI') and
                mov.repasse_efetuado = 0 and mov.origem in('POS', 'TOTEM', 'WEB') and
                mov.autorizacao like :autorizacao and mov.situacao in('APPR','paid','APROVADA', 'APPROVED') and mov.id_estorno = 0 and
                mov.origem like :origem and mov.servico like :servico and mov.documento like :documento ".
            $filtro."
                order by 1 desc";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":origem", $origem, PDO::PARAM_STR);
        $resultado->bindParam(":servico", $servico, PDO::PARAM_STR);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->bindParam(":nome", $cli, PDO::PARAM_STR);
        $resultado->bindParam(":autorizacao", $autorizacao, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getPesquisaSemEstornoPorAdmId($admId,$cliente, $dataIni, $dataFim, $status)
    {
        $origem = $this->getOrigem().'%';
        if($admId == 77){
            $servico = 'Crédito PIX';
        }else{
            $servico = $this->getServico().'%';
        }

        $documento = $this->getDocumento().'%';
        $autorizacao = $this->getAutorizacao().'%';
        $cli = $cliente.'%';

        $filtro = "";

        if(!empty($dataIni)){
            if(!empty($dataFim)){
                $filtro = " and DATE(mov.data) between '".date('Y-m-d',strtotime($dataIni)).
                    "' and '".date('Y-m-d',strtotime($dataFim))."' ";
            }else{
                $filtro = " and DATE(mov.data) = '".date('Y-m-d',strtotime($dataIni))."' ";
            }
        }

        if($status == "APROVADAS"){
            $filtro .= " and mov.situacao in('APPR','paid','APROVADA', 'APPROVED') and mov.id_estorno = 0 ";
        }

        if($status == "AGUARDANDO"){
            $filtro .= " and mov.situacao in('AGUARDANDO','processing') ";
        }

        if($status == "CANCELADAS"){
            $filtro .= " and (mov.situacao in('CANCELED','CANCELADA','CANCELADO') or mov.id_estorno > 0) ";
        }

        if($status == "REPROVADA"){
            $filtro .= " and mov.situacao in('REPROVADA')  ";
        }

        $sql = "select distinct mov.*, cli.cli_nomerazao, cli.cli_fantasia, 
                cli2.cli_nomerazao as nome2, cli2.cli_fantasia as fantasia2
                from movimentacoes mov, cliente cli, administrador_cliente adm, cliente cli2
                where mov.documento = cli.cli_cpfcnpj and cli2.cli_id = mov.cli_id and mov.cli_id <> 0 and mov.servico <> 'Estorno' and 
                mov.origem like :origem and mov.servico like :servico and mov.documento like :documento and
                ((mov.cli_id = adm.cli_id) or (cli.cli_idresponsavel = adm.cli_id)) and adm.adm_id = :admId and
                mov.autorizacao like :autorizacao and
                cli.cli_nomerazao like :nome ".$filtro."
                order by 1 desc";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":origem", $origem, PDO::PARAM_STR);
        $resultado->bindParam(":servico", $servico, PDO::PARAM_STR);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->bindParam(":nome", $cli, PDO::PARAM_STR);
        $resultado->bindParam(":admId", $admId, PDO::PARAM_INT);
        $resultado->bindParam(":autorizacao", $autorizacao, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getPesquisaSemEstornoPorAdmIdPIX($admId,$cliente, $dataIni, $dataFim, $status)
    {
        $origem = $this->getOrigem().'%';
        if($admId == 77){
            $servico = 'Crédito PIX';
        }else{
            $servico = $this->getServico().'%';
        }

        $documento = $this->getDocumento().'%';
        $autorizacao = $this->getAutorizacao().'%';
        $cli = $cliente.'%';

        $filtro = "";

        if(!empty($dataIni)){
            if(!empty($dataFim)){
                $filtro = " and DATE(mov.data) between '".date('Y-m-d',strtotime($dataIni)).
                    "' and '".date('Y-m-d',strtotime($dataFim))."' ";
            }else{
                $filtro = " and DATE(mov.data) = '".date('Y-m-d',strtotime($dataIni))."' ";
            }
        }

        if($status == "APROVADAS"){
            $filtro .= " and mov.situacao in('APPR','paid','APROVADA', 'APPROVED') and mov.id_estorno = 0 ";
        }

        if($status == "AGUARDANDO"){
            $filtro .= " and mov.situacao in('AGUARDANDO','processing') ";
        }

        if($status == "CANCELADAS"){
            $filtro .= " and (mov.situacao in('CANCELED') or mov.id_estorno > 0) ";
        }

        if($status == "REPROVADA"){
            $filtro .= " and mov.situacao in('REPROVADA')  ";
        }

        $sql = "select distinct mov.*, cli.cli_nomerazao, cli.cli_fantasia, 
                cli2.cli_nomerazao as nome2, cli2.cli_fantasia as fantasia2, 
                mpx.nome as nome_pix, mpx.documento as documento_pix
                from movimentacoes mov, cliente cli, administrador_cliente adm, cliente cli2,
                movimentacoes_pix mpx
                where mov.documento = cli.cli_cpfcnpj and cli2.cli_id = mov.cli_id and mov.id = mpx.id_movimentacoes and
                mov.cli_id <> 0 and mov.servico <> 'Estorno' and 
                mov.origem like :origem and mov.servico like :servico and mov.documento like :documento and
                ((mov.cli_id = adm.cli_id) or (cli.cli_idresponsavel = adm.cli_id)) and adm.adm_id = :admId and
                mov.autorizacao like :autorizacao and
                cli.cli_nomerazao like :nome ".$filtro."
                order by 1 desc";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":origem", $origem, PDO::PARAM_STR);
        $resultado->bindParam(":servico", $servico, PDO::PARAM_STR);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->bindParam(":nome", $cli, PDO::PARAM_STR);
        $resultado->bindParam(":admId", $admId, PDO::PARAM_INT);
        $resultado->bindParam(":autorizacao", $autorizacao, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getListaTodosSemEstornoPorAdmId($admId)
    {
        if($admId == 77){
            $sql = "select distinct mov.*, cli.cli_nomerazao, cli.cli_fantasia, 
                cli2.cli_nomerazao as nome2, cli2.cli_fantasia as fantasia2
                from movimentacoes mov, cliente cli, administrador_cliente adm, cliente cli2
                where mov.documento = cli.cli_cpfcnpj and cli2.cli_id = mov.cli_id and mov.cli_id <> 0 and mov.servico = 'Crédito PIX' and
                ((mov.cli_id = adm.cli_id) or (cli.cli_idresponsavel = adm.cli_id)) and adm.adm_id = :admId and mov.data >= CURDATE() - INTERVAL 1 DAY
                order by 1 desc
                LIMIT 300";
        }else{
            $sql = "select distinct mov.*, cli.cli_nomerazao, cli.cli_fantasia, 
                cli2.cli_nomerazao as nome2, cli2.cli_fantasia as fantasia2
                from movimentacoes mov, cliente cli, administrador_cliente adm, cliente cli2
                where mov.documento = cli.cli_cpfcnpj and cli2.cli_id = mov.cli_id and mov.cli_id <> 0 and mov.servico <> 'Estorno' and
                ((mov.cli_id = adm.cli_id) or (cli.cli_idresponsavel = adm.cli_id)) and adm.adm_id = :admId and mov.data >= CURDATE() - INTERVAL 1 DAY
                order by 1 desc
                LIMIT 300";
        }

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":admId", $admId, PDO::PARAM_INT);
        $resultado->execute();

        return $resultado;
    }

    public function getListaTodosSemEstornoPorAdmIdPIX($admId)
    {
        if($admId == 77){
            $sql = "select distinct mov.*, cli.cli_nomerazao, cli.cli_fantasia, 
                cli2.cli_nomerazao as nome2, cli2.cli_fantasia as fantasia2,
                mpx.nome as nome_pix, mpx.documento as documento_pix
                from movimentacoes mov, cliente cli, administrador_cliente adm, cliente cli2,
                movimentacoes_pix mpx
                where mov.documento = cli.cli_cpfcnpj and cli2.cli_id = mov.cli_id and mov.cli_id <> 0 and mov.id = mpx.id_movimentacoes and
                mov.servico = 'Crédito PIX' and
                ((mov.cli_id = adm.cli_id) or (cli.cli_idresponsavel = adm.cli_id)) and adm.adm_id = :admId and mov.data >= CURDATE() - INTERVAL 1 DAY
                order by 1 desc
                LIMIT 300";
        }else{
            $sql = "select distinct mov.*, cli.cli_nomerazao, cli.cli_fantasia, 
                cli2.cli_nomerazao as nome2, cli2.cli_fantasia as fantasia2,
                mpx.nome as nome_pix, mpx.documento as documento_pix
                from movimentacoes mov, cliente cli, administrador_cliente adm, cliente cli2,
                movimentacoes_pix mpx
                where mov.documento = cli.cli_cpfcnpj and cli2.cli_id = mov.cli_id and mov.cli_id <> 0 and mov.id = mpx.id_movimentacoes and
                mov.servico <> 'Estorno' and
                ((mov.cli_id = adm.cli_id) or (cli.cli_idresponsavel = adm.cli_id)) and adm.adm_id = :admId and mov.data >= CURDATE() - INTERVAL 1 DAY
                order by 1 desc
                LIMIT 300";
        }

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":admId", $admId, PDO::PARAM_INT);
        $resultado->execute();

        return $resultado;
    }

    public function getTotalVendasSemEstornoPorAdmIdData($admId, $data)
    {
        $sql = "select sum(mov.valor * mov.parcelas) as total
                from movimentacoes mov, cliente cli, administrador_cliente adm
                where mov.documento = cli.cli_cpfcnpj and mov.cli_id <> 0 and mov.servico <> 'Estorno' and
                ((mov.cli_id = adm.cli_id) or (cli.cli_idresponsavel = adm.cli_id)) and adm.adm_id =:admId and date(mov.data) =:dat and 
                mov.situacao in ('APPR','paid','APROVADA','APPROVED')
                ";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":admId", $admId, PDO::PARAM_INT);
        $resultado->bindParam(":dat", $data);
        $resultado->execute();

        return $resultado;
    }

    public function getTotalVendasSemEstornoPorData($data)
    {
        $sql = "select sum(mov.valor * mov.parcelas) as total
                from movimentacoes mov
                where mov.servico <> 'Estorno' and
                date(mov.data) =:dat and 
                mov.situacao in ('APPR','paid','APROVADA','APPROVED')
                ";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":dat", $data);
        $resultado->execute();

        return $resultado;
    }

    public function getMovimentacoesPorId()
    {
        $id = $this->getId();

        $sql = "select * from movimentacoes 
                where id =:id";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $id, PDO::PARAM_INT);
        $resultado->execute();

        return $resultado;
    }

    public function getMovimentacoesPorDataECAutorizacaoNSU()
    {
        $data = $this->getData();
        $ec = $this->getNumeroEc();
        $autorizacao = $this->getAutorizacao();
        $nsu = $this->getNsu();

        $sql = "select mov.* from movimentacoes mov 
                where date(mov.data) =:dat and mov.numero_ec =:ec and mov.autorizacao =:autorizacao and mov.nsu =:nsu";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":dat", $data);
        $resultado->bindParam(":ec", $ec, PDO::PARAM_STR);
        $resultado->bindParam(":autorizacao", $autorizacao, PDO::PARAM_STR);
        $resultado->bindParam(":nsu", $nsu, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getMovimentacoesPorDataECAutorizacaoNumeroSerie()
    {
        $data = $this->getData();
        $ec = $this->getNumeroEc();
        $autorizacao = $this->getAutorizacao();
        $num = $this->getNumeroSerie();

        $sql = "select mov.* from movimentacoes mov 
                where date(mov.data) =:dat and mov.numero_ec =:ec and mov.autorizacao =:autorizacao and mov.numero_serie =:num";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":dat", $data);
        $resultado->bindParam(":ec", $ec, PDO::PARAM_STR);
        $resultado->bindParam(":autorizacao", $autorizacao, PDO::PARAM_STR);
        $resultado->bindParam(":num", $num, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getUltimasMovimentacoesPorDocumento()
    {
        $documento = $this->getDocumento();

        $sql = "select mov.* from movimentacoes mov
                where mov.documento =:documento
                order by mov.data desc
                LIMIT 100";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getUltimasMovimentacoesPorDocumentoVendas()
    {
        $documento = $this->getDocumento();

        $sql = "select mov.* from movimentacoes mov
                where mov.documento =:documento and mov.servico in('Vendas', 'VendasSoftwareExpress')
                order by mov.data desc
                LIMIT 100";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getUltimasMovimentacoesPorDocumentoProdutosCDX()
    {
        $documento = $this->getDocumento();

        $sql = "select mov.* from movimentacoes mov
                where mov.documento =:documento and mov.servico not in('Vendas', 'VendasSoftwareExpress')
                order by mov.data desc
                LIMIT 100";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getListaSaldoBloqueadoPorDocumento()
    {
        $documento = $this->getDocumento();

        //$sql = "select mov.* from movimentacoes mov
        //        where mov.documento =:documento and CURRENT_DATE > DATE(mov.data) AND CURRENT_DATE < DATE(mov.data_repasse)
        //        order by mov.data desc
        //        ";

        $sql = "select mov.* from movimentacoes mov
                where mov.documento =:documento and 
                mov.repasse_efetuado = 0 and
                DATE(mov.data) >= '2023-05-01' and mov.data_repasse is not null
                order by mov.data desc
                ";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function buscaTotalPorDataRepasse($dataIni, $dataFIm)
    {
        //$data = $this->getDataRepasse();

        $sql = "select mov.documento, cli.cli_nomerazao, cli.cli_fantasia, sum(mov.calc_cliente) as valor_cliente, sum(mov.calc_adquirente) as valor_adquirente,
                sum(mov.calc_cdx) as valor_cdx, sum(mov.calc_polo) as valor_polo, sum(mov.calc_representante) as valor_representante,
                mov.repasse_efetuado, sum(mov.valor_total) as valor_total
                from movimentacoes mov, cliente cli
                where mov.documento = cli.cli_cpfcnpj and  mov.servico NOT IN('Sorte Online', 'Debito Veicular','Boleto Parcelado') and
                DATE(mov.data_repasse) between :dataRepasseIni and :dataRepasseFim and mov.origem in ('POS','WEB') and
                mov.id_estorno = 0 and mov.situacao IN('APPR','paid','APROVADA','APPROVED')
                group by mov.documento, cli.cli_nomerazao, cli.cli_fantasia, mov.repasse_efetuado
                order by cli.cli_nomerazao
                ";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":dataRepasseIni", $dataIni);
        $resultado->bindParam(":dataRepasseFim", $dataFIm);
        $resultado->execute();

        return $resultado;
    }

    public function buscaLiberacoesPorDocumentoPorDataRepasse($dataIni, $dataFIm)
    {
        $doc = $this->getDocumento();

        $sql = "select cli.cli_id, cli.cli_nomerazao, mov.*, cli.cli_idresponsavel
                from movimentacoes mov, cliente cli
                where mov.documento = cli.cli_cpfcnpj and mov.servico NOT IN('Sorte Online','Debito Veicular','Boleto Parcelado') and
                DATE(mov.data_repasse) between :dataRepasseIni and :dataRepasseFim and mov.documento =:doc and mov.origem in ('POS','WEB') and
                mov.id_estorno = 0 and mov.situacao IN('APPR','paid','APROVADA','APPROVED')
                order by cli.cli_nomerazao, mov.data
                ";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":dataRepasseIni", $dataIni);
        $resultado->bindParam(":dataRepasseFim", $dataFIm);
        $resultado->bindParam(":doc", $doc, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function buscaTotalPorDataVenda($dataIni, $dataFIm)
    {
        //$data = $this->getDataRepasse();

        $sql = "select mov.documento, cli.cli_nomerazao, cli.cli_fantasia, sum(mov.calc_cliente) as valor_cliente, sum(mov.calc_adquirente) as valor_adquirente,
                sum(mov.calc_cdx) as valor_cdx, sum(mov.calc_polo) as valor_polo, sum(mov.calc_representante) as valor_representante,
                mov.repasse_efetuado, sum(mov.valor_total) as valor_total
                from movimentacoes mov, cliente cli
                where mov.documento = cli.cli_cpfcnpj and mov.servico NOT IN('Sorte Online','Debito Veicular','Boleto Parcelado') and
                DATE(mov.data) between :dataVendaIni and :dataVendaFim and mov.origem in ('POS','WEB') and mov.valor >0 and
                mov.id_estorno = 0 and mov.situacao IN('APPR','paid','APROVADA','APPROVED')
                group by mov.documento, cli.cli_nomerazao, cli.cli_fantasia, mov.repasse_efetuado
                order by cli.cli_nomerazao
                ";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":dataVendaIni", $dataIni);
        $resultado->bindParam(":dataVendaFim", $dataFIm);
        $resultado->execute();

        return $resultado;
    }

    public function buscaLiberacoesPorDocumentoPorDataVenda($dataIni, $dataFIm)
    {
        //$data = $this->getDataRepasse();
        $doc = $this->getDocumento();

        $sql = "select cli.cli_id, cli.cli_nomerazao, mov.*, cli.cli_idresponsavel
                from movimentacoes mov, cliente cli
                where mov.documento = cli.cli_cpfcnpj and mov.servico NOT IN('Sorte Online','Debito Veicular','Boleto Parcelado') and
                DATE(mov.data) between :dataVendaIni and :dataVendaFim and mov.documento =:doc and mov.origem in ('POS','WEB') and
                mov.id_estorno = 0 and mov.situacao IN('APPR','paid','APROVADA','APPROVED')
                order by cli.cli_nomerazao, mov.data
                ";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":dataVendaIni", $dataIni);
        $resultado->bindParam(":dataVendaFim", $dataFIm);
        $resultado->bindParam(":doc", $doc, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getMovimentacoesPorDocumentoNumeroSerieDoDia()
    {
        $documento = $this->getDocumento();
        $serie = $this->getNumeroSerie();

        $sql = "select mov.data, mov.situacao, mov.recusa_descricao, mov.autorizacao, mov.numero_cv,
                mov.nsu, IF(mov.id_estorno > 0, -mov.valor, mov.valor) as valor, mov.valor_original, mov.parcelas, mov.cartao_dig_ini, mov.cartao_dig_fim,
                mov.banderia, mov.retorno_json
                from movimentacoes mov
                where mov.documento =:documento and mov.numero_serie =:serie and DATE(mov.data) = CURRENT_DATE 
                order by mov.data desc
                ";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->bindParam(":serie", $serie, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getMovimentacoesPorDocumentoNumeroSerieParaEstorno()
    {
        $documento = $this->getDocumento();
        $serie = $this->getNumeroSerie();
        $dataHoje = date('Y-m-d');

        $sql = "select mov.data, mov.situacao, mov.recusa_descricao, mov.autorizacao, mov.numero_cv,
                mov.nsu, mov.nsu_tef, mov.valor, mov.valor_original, mov.parcelas, mov.cartao_dig_ini, mov.cartao_dig_fim,
                mov.banderia, mov.retorno_json, mov.referencia_externa
                from movimentacoes mov
                where mov.documento =:documento and mov.numero_serie =:serie and DATE(mov.data) =:dataHoje and 
                mov.servico = 'Vendas' and mov.banderia is not null and mov.id_estorno = 0
                union
                select mov.data, mov.situacao, mov.recusa_descricao, mov.autorizacao, mov.numero_cv,
                mov.nsu, mov.nsu_tef, mov.valor, mov.valor_original, mov.parcelas, mov.cartao_dig_ini, mov.cartao_dig_fim,
                mov.banderia, mov.retorno_json, mov.referencia_externa
                from movimentacoes mov
                where mov.documento =:documento and mov.numero_serie =:serie and DATE(mov.data) =:dataHoje and 
                mov.servico <> 'Vendas' and mov.banderia is not null and mov.id_estorno = 0 and mov.permite_estorno = 1
                order by 1 desc
                ";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->bindParam(":serie", $serie, PDO::PARAM_STR);
        $resultado->bindParam(":dataHoje", $dataHoje);
        $resultado->execute();

        return $resultado;
    }

    public function getMovimentacoesPorDocumentoNumeroSeriePeriodo($dataIni, $dataFim)
    {
        $documento = $this->getDocumento();
        $serie = $this->getNumeroSerie();

        $sql = "select mov.data, mov.situacao, mov.recusa_descricao, mov.autorizacao, mov.numero_cv,
                mov.nsu, IF(mov.id_estorno > 0, -mov.valor, mov.valor) as valor,  IF(mov.id_estorno > 0, -mov.valor_original, mov.valor_original) as valor_original, mov.parcelas, mov.cartao_dig_ini, mov.cartao_dig_fim,
                mov.banderia, mov.retorno_json
                from movimentacoes mov
                where mov.documento =:documento and mov.numero_serie =:serie and DATE(mov.data) >= :dataIni and 
                DATE(mov.data) <= :dataFim
                order by mov.data desc
                ";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":documento", $documento, PDO::PARAM_STR);
        $resultado->bindParam(":serie", $serie, PDO::PARAM_STR);
        $resultado->bindParam(":dataIni", $dataIni);
        $resultado->bindParam(":dataFim", $dataFim);
        $resultado->execute();

        return $resultado;
    }

    public function getMovimentacoesParaMovingPay($dataIni, $dataFim, $cpf_cnpj, $nsu)
    {
        //antes do colocar todos os servicos
        //mov.servico in('Link Pay Debito Veicular','Link Pay Boleto','Link MPago Debito Veicular','Pos Browser Boleto','Pos Browser Debito Veicular')
        //mov.origem = 'POS'
        if(!empty($dataIni) && !empty($dataFim)){
            $sql = "select mov.data, mov.situacao, mov.recusa_descricao, mov.autorizacao, mov.numero_cv,
                mov.nsu, mov.valor, mov.valor_original, mov.parcelas, mov.cartao_dig_ini, mov.cartao_dig_fim,
                mov.banderia, mov.retorno_json, mov.moeda, mov.referencia_externa,mov.documento, mov.codigo_adquirente,
                mov.codigo_retorno, mov.nsu_tef, mov.calc_adquirente, mov.cartao_portador, mov.forma_pagamento,
                mov.forma_captura, mov.numero_serie, mov.id, mov.codcli_movingpay, mov.codigo_mcc, '' as nsu_cancelamento
                from movimentacoes mov
                where mov.data between :dataIni and :dataFim and mov.situacao IN('APPR','paid','APROVADA','APPROVED') and
                mov.banderia is not null and mov.id_estorno = 0
                and mov.servico in('VendasSoftwareExpress','Rercarga Celular','Vendas','Operacao Leilao','Pos Presencial Cartorio','Pos Presencial Debito Veicular','Pos Browser Cartorio','Pos Presencial Boleto','Operacao Boleto','Operacao Debito Veicular','Link Pay Debito Veicular','Link Pay Boleto','Link MPago Debito Veicular','Pos Browser Boleto','Pos Browser Debito Veicular')
                and mov.codcli_movingpay is not null
                union
                select movEstorno.data, 'DEVOL' as situacao, mov.recusa_descricao, mov.autorizacao, mov.numero_cv,
                mov.nsu, mov.valor, mov.valor_original, mov.parcelas, mov.cartao_dig_ini, mov.cartao_dig_fim,
                mov.banderia, mov.retorno_json, mov.moeda, mov.referencia_externa,mov.documento, mov.codigo_adquirente,
                mov.codigo_retorno, mov.nsu_tef, mov.calc_adquirente, mov.cartao_portador, mov.forma_pagamento,
                mov.forma_captura, mov.numero_serie, mov.id, mov.codcli_movingpay, mov.codigo_mcc, movEstorno.nsu as nsu_cancelamento
                from movimentacoes movEstorno
                left join movimentacoes mov on movEstorno.id = mov.id_estorno
                where movEstorno.data between :dataIni and :dataFim and mov.situacao IN('APPR','paid','APROVADA','APPROVED') and
                mov.banderia is not null and mov.id_estorno > 0
                and movEstorno.servico in('Estorno')
                and mov.codcli_movingpay is not null
                ";

            if(!empty($cpf_cnpj)){
                $sql .= " and mov.documento =:documento ";
            }

            if(!empty($nsu)){
                $sql .= " and mov.nsu =:nsu ";
            }
            $sql .= " order by 1 desc";
            $resultado = $this->pdo->prepare($sql);
            $resultado->bindParam(":dataIni", $dataIni);
            $resultado->bindParam(":dataFim", $dataFim);
            if(!empty($cpf_cnpj)){
                $resultado->bindParam(":documento", $cpf_cnpj);
            }
            if(!empty($nsu)){
                $resultado->bindParam(":nsu", $nsu);
            }
        }else{
            //$dataHoje = date('Y-m-d', strtotime("-2 days"));
            //$dataHoje = '2022-11-10';
            //mov.servico in('Vendas','Link Pay Debito Veicular','Link Pay Boleto','Link MPago Debito Veicular','Pos Browser Boleto','Pos Browser Debito Veicular')
            $dataHoje = date('Y-m-d');

            $sql = "select mov.data, mov.situacao, mov.recusa_descricao, mov.autorizacao, mov.numero_cv,
                mov.nsu, mov.valor, mov.valor_original, mov.parcelas, mov.cartao_dig_ini, mov.cartao_dig_fim,
                mov.banderia, mov.retorno_json, mov.moeda, mov.referencia_externa,mov.documento, mov.codigo_adquirente,
                mov.codigo_retorno, mov.nsu_tef, mov.calc_adquirente, mov.cartao_portador, mov.forma_pagamento,
                mov.forma_captura, mov.numero_serie, mov.id, mov.codcli_movingpay, mov.codigo_mcc
                from movimentacoes mov
                where DATE(mov.data) =:dataHoje and mov.situacao = 'APPR' and
                mov.servico in('Rercarga Celular','Vendas','Operacao Leilao','Pos Presencial Cartorio','Pos Presencial Debito Veicular','Pos Browser Cartorio','Pos Presencial Boleto','Operacao Boleto','Operacao Debito Veicular','Link Pay Debito Veicular','Link Pay Boleto','Link MPago Debito Veicular','Pos Browser Boleto','Pos Browser Debito Veicular') and 
                mov.banderia is not null and mov.id_estorno = 0 and mov.codcli_movingpay is not null
                union
                select movEstorno.data, 'DEVOL' as situacao, mov.recusa_descricao, mov.autorizacao, mov.numero_cv,
                mov.nsu, mov.valor, mov.valor_original, mov.parcelas, mov.cartao_dig_ini, mov.cartao_dig_fim,
                mov.banderia, mov.retorno_json, mov.moeda, mov.referencia_externa,mov.documento, mov.codigo_adquirente,
                mov.codigo_retorno, mov.nsu_tef, mov.calc_adquirente, mov.cartao_portador, mov.forma_pagamento,
                mov.forma_captura, mov.numero_serie, mov.id, mov.codcli_movingpay, mov.codigo_mcc
                from movimentacoes movEstorno
                left join movimentacoes mov on movEstorno.id = mov.id_estorno
                where DATE(movEstorno.data) =:dataHoje and mov.situacao IN('APPR','paid','APROVADA','APPROVED') and
                mov.banderia is not null and mov.id_estorno > 0
                and movEstorno.servico in('Estorno')
                and mov.codcli_movingpay is not null
                ";

            if(!empty($cpf_cnpj)){
                $sql .= " and mov.documento =:documento ";
            }

            if(!empty($nsu)){
                $sql .= " and mov.nsu =:nsu ";
            }
            $sql .= " order by 1 desc";
            $resultado = $this->pdo->prepare($sql);
            $resultado->bindParam(":dataHoje", $dataHoje);
            if(!empty($cpf_cnpj)){
                $resultado->bindParam(":documento", $cpf_cnpj);
            }
            if(!empty($nsu)){
                $resultado->bindParam(":nsu", $nsu);
            }
        }


        $resultado->execute();

        return $resultado;
    }

    public function getMovimentacoesPorRefExterna()
    {
        $id = $this->getReferenciaExterna();

        $sql = "select * from movimentacoes 
                where referencia_externa =:id";
        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $id, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function getTotalAprovadas()
    {
        $sql = "select sum(valor * parcelas) as total, servico from movimentacoes
                where situacao = 'APPR'
                group by servico";
        $resultado = $this->pdo->prepare($sql);
        $resultado->execute();

        return $resultado;
    }

    public function inserir()
    {
        $dataRepasse = null;
        if (!empty($this->getDataRepasse()))
        {
            $dataRepasse = date('Y-m-d', strtotime($this->getDataRepasse()));
        }


            $sql = "insert into movimentacoes (cli_id, origem, servico, numero_ec, documento, referencia_externa, situacao, recusa_descricao,
                    codigo_retorno, codigo_adquirente, codigo_mcc, soft_descriptor, autorizacao, numero_cv, moeda, nsu_tef,
                    nsu, valor, valor_original, valor_total, parcelas, cartao_portador, cartao_dig_ini, cartao_dig_fim, banderia, forma_pagamento,
                    forma_captura, numero_serie, data,
                    emite_nota, nota_novos_dados, nota_nome, nota_telefone, nota_email, nota_documento, nota_cep,
                    nota_rua, nota_numero, nota_complemento, nota_bairro, nota_cidade,
                    nota_estado, url_notification, retorno_json,
                    calc_cliente, calc_adquirente, calc_cdx, calc_polo, calc_representante, data_repasse, tabela_utilizada, codcli_movingpay)
                    values(:cli_id, :origem, :servico, :numero_ec, :documento, :referencia_externa, :situacao, :recusa_descricao,
                    :codigo_retorno, :codigo_adquirente, :codigo_mcc, :soft_descriptor, :autorizacao, :numero_cv, :moeda, :nsu_tef,
                    :nsu, :valor, :valor_original, :valor_total, :parcelas, :cartao_portador, :cartao_dig_ini, :cartao_dig_fim, :banderia, :forma_pagamento,
                    :forma_captura, :numero_serie, :movData,
                    :emite_nota, :nota_novos_dados, :nota_nome, :nota_telefone, :nota_email, :nota_documento, :nota_cep,
                    :nota_rua, :nota_numero, :nota_complemento, :nota_bairro, :nota_cidade,
                    :nota_estado, :url_notification, :retorno_json,
                    :calc_cliente, :calc_adquirente, :calc_cdx, :calc_polo, :calc_representante, :data_repasse, :tabela_utilizada, :codcli_movingpay) ";
            $resultado = $this->pdo->prepare($sql);
            $resultado->bindParam(":cli_id", $this->getCliId(), PDO::PARAM_INT);
            $resultado->bindParam(":origem", $this->getOrigem(), PDO::PARAM_STR);
            $resultado->bindParam(":servico", $this->getServico(), PDO::PARAM_STR);
            $resultado->bindParam(":numero_ec", $this->getNumeroEc(), PDO::PARAM_STR);
            $resultado->bindParam(":documento", $this->getDocumento(), PDO::PARAM_STR);
            $resultado->bindParam(":referencia_externa", $this->getReferenciaExterna(), PDO::PARAM_STR);
            $resultado->bindParam(":situacao", $this->getSituacao(), PDO::PARAM_STR);
            $resultado->bindParam(":recusa_descricao", $this->getRecusaDescricao(), PDO::PARAM_STR);
            $resultado->bindParam(":codigo_retorno", $this->getCodigoRetorno(), PDO::PARAM_STR);
            $resultado->bindParam(":codigo_adquirente", $this->getCodigoAdquirente(), PDO::PARAM_STR);
            $resultado->bindParam(":codigo_mcc", $this->getCodigoMcc(), PDO::PARAM_STR);
            $resultado->bindParam(":soft_descriptor", $this->getSoftDescriptor(), PDO::PARAM_STR);
            $resultado->bindParam(":autorizacao", $this->getAutorizacao(), PDO::PARAM_STR);
            $resultado->bindParam(":numero_cv", $this->getNumeroCv(), PDO::PARAM_STR);
            $resultado->bindParam(":moeda", $this->getMoeda(), PDO::PARAM_STR);
            $resultado->bindParam(":nsu_tef", $this->getNsuTef(), PDO::PARAM_STR);
            $resultado->bindParam(":nsu", $this->getNsu(), PDO::PARAM_STR);
            $resultado->bindParam(":valor", $this->getValor());
            $resultado->bindParam(":valor_original", $this->getValorOriginal());
            $resultado->bindParam(":valor_total", $this->getValorTotal());
            $resultado->bindParam(":parcelas", $this->getParcelas(), PDO::PARAM_INT);
            $resultado->bindParam(":cartao_portador", $this->getCartaoPortador(), PDO::PARAM_STR);
            $resultado->bindParam(":cartao_dig_ini", $this->getCartaoDigIni(), PDO::PARAM_STR);
            $resultado->bindParam(":cartao_dig_fim", $this->getCartaoDigFim(), PDO::PARAM_STR);
            $resultado->bindParam(":banderia", $this->getBanderia(), PDO::PARAM_STR);
            $resultado->bindParam(":forma_pagamento", $this->getFormaPagamento(), PDO::PARAM_STR);
            $resultado->bindParam(":forma_captura", $this->getFormaCaptura(), PDO::PARAM_STR);

            $resultado->bindParam(":numero_serie", $this->getNumeroSerie(), PDO::PARAM_STR);
            $resultado->bindParam(":movData", $this->getData(), PDO::PARAM_STR);

            $resultado->bindParam(":emite_nota", $this->getEmiteNota(), PDO::PARAM_INT);
            $resultado->bindParam(":nota_novos_dados", $this->getNovosDados(), PDO::PARAM_INT);
            $resultado->bindParam(":nota_nome", $this->getNotaNome(), PDO::PARAM_STR);
            $resultado->bindParam(":nota_telefone", $this->getNotaTelefone(), PDO::PARAM_STR);
            $resultado->bindParam(":nota_email", $this->getNotaEmail(), PDO::PARAM_STR);
            $resultado->bindParam(":nota_documento", $this->getNotaDocumento(), PDO::PARAM_STR);
            $resultado->bindParam(":nota_cep", $this->getNotaCep(), PDO::PARAM_STR);
            $resultado->bindParam(":nota_rua", $this->getNotaRua(), PDO::PARAM_STR);
            $resultado->bindParam(":nota_numero", $this->getNotaNumero(), PDO::PARAM_STR);
            $resultado->bindParam(":nota_complemento", $this->getNotaComplemento(), PDO::PARAM_STR);
            $resultado->bindParam(":nota_bairro", $this->getNotaBairro(), PDO::PARAM_STR);
            $resultado->bindParam(":nota_cidade", $this->getNotaCidade(), PDO::PARAM_STR);
            $resultado->bindParam(":nota_estado", $this->getNotaEstado(), PDO::PARAM_STR);
            $resultado->bindParam(":url_notification", $this->getUrlNotification(), PDO::PARAM_STR);
            $resultado->bindParam(":retorno_json", $this->getRetornoJson());

            $resultado->bindParam(":calc_cliente", $this->getCalcCliente());
            $resultado->bindParam(":calc_adquirente", $this->getCalcAdquirente());
            $resultado->bindParam(":calc_cdx", $this->getCalcCdx());
            $resultado->bindParam(":calc_polo", $this->getCalcPolo());
            $resultado->bindParam(":calc_representante", $this->getCalcRepresentante());
            $resultado->bindParam(":data_repasse", $dataRepasse);
            $resultado->bindParam(":tabela_utilizada", $this->getTabelaUtilizada(), PDO::PARAM_STR);

            $resultado->bindParam(":codcli_movingpay", $this->getCodCliMovingPay(), PDO::PARAM_STR);

        $resultado->execute();


        if ($resultado){
            $this->setId($this->pdo->lastInsertId());
            $this->setRetorno("OK");
            $this->setMensagemRetorno("");
        }else{
            $this->setRetorno("ERRO");
            $this->setMensagemRetorno("Ocorreu um erro durante a inserção de dados.");
        }

        return $resultado;
    }

    public function alterarMovimentacao()
    {
        $id = $this->getId();
        $situacao = $this->getSituacao();
        $dataRepasse = $this->getDataRepasse();
        $estorno = $this->getPermiteEstorno();

        $sql = "update movimentacoes 
                set situacao =:situacao, data_repasse =:data_repasse, permite_estorno =:estorno
                where id =:id";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $id, PDO::PARAM_INT);
        $resultado->bindParam(":situacao", $situacao, PDO::PARAM_STR);
        $resultado->bindParam(":data_repasse", $dataRepasse);
        $resultado->bindParam(":estorno", $estorno, PDO::PARAM_INT);
        $resultado->execute();

        return $resultado;
    }

    public function alterarRebatesPorIdMovimentacao()
    {
        $id = $this->getId();
        $calcCli = $this->getCalcCliente();
        $calcAdq = $this->getCalcAdquirente();
        $calcPolo = $this->getCalcPolo();
        $calcRepre = $this->getCalcRepresentante();

        $sql = "update movimentacoes set calc_cliente =:calc_cliente, calc_adquirente =:calc_adquirente,
                calc_polo =:calc_polo, calc_representante =:calc_representante
                where id =:id";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $id, PDO::PARAM_INT);
        $resultado->bindParam(":calc_cliente", $calcCli);
        $resultado->bindParam(":calc_adquirente", $calcAdq);
        $resultado->bindParam(":calc_polo", $calcPolo);
        $resultado->bindParam(":calc_representante", $calcRepre);
        $resultado->execute();

        return $resultado;
    }

    public function gravaDataRepassePorIdMovimento()
    {
        $id = $this->getId();

        $sql = "update movimentacoes set repasse_efetuado = 1, repasse_datapagamento = CURRENT_TIMESTAMP 
                where id =:id";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $id, PDO::PARAM_INT);
        $resultado->execute();

        return $resultado;
    }

    public function atualizaSituacaoPorRefExterna()
    {
        $sql = "update movimentacoes set situacao =:situacao where referencia_externa =:referencia";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":referencia", $this->getReferenciaExterna(), PDO::PARAM_STR);
        $resultado->bindParam(":situacao", $this->getSituacao(), PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function atualizaSituacaoPorIdMovimento()
    {
        $id = $this->getId();
        $situacao = $this->getSituacao();

        $sql = "update movimentacoes set situacao =:situacao where id =:id";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $id, PDO::PARAM_INT);
        $resultado->bindParam(":situacao", $situacao, PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function atualizaAgenciaIdMovimento()
    {
        $id = $this->getId();
        $codCliente = $this->getCliId();
        $doc = $this->getDocumento();
        $codCliMoving = $this->getCodCliMovingPay();

        $sql = "update movimentacoes set cli_id =:cli_id, documento =:documento, codcli_movingpay =:codcli_movingpay
                where id =:id";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $id, PDO::PARAM_INT);
        $resultado->bindParam(":cli_id", $codCliente, PDO::PARAM_INT);
        $resultado->bindParam(":documento", $doc, PDO::PARAM_STR);
        $resultado->bindParam(":codcli_movingpay", $codCliMoving, PDO::PARAM_INT);
        $resultado->execute();

        return $resultado;
    }

    public function gravaEnvioSinPag()
    {
        $sql = "update movimentacoes set enviado_sinpag = 1, id_sinpag =:idSin, url_sinpag =:url
                where id =:id";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $this->getId(), PDO::PARAM_INT);
        $resultado->bindParam(":idSin", $this->getIdSinpag(), PDO::PARAM_STR);
        $resultado->bindParam(":url", $this->getUrlSinPag(), PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function gravaEnvioMovingPay()
    {
        $sql = "update movimentacoes set enviado_movingpay = 1, id_movingpay =:codigo
                where id =:id";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $this->getId(), PDO::PARAM_INT);
        $resultado->bindParam(":codigo", $this->getIdMovingPay(), PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function gravaVeiculoQuitado()
    {
        $sql = "update movimentacoes set veiculo_quitado = 1 where id =:id";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $this->getId(), PDO::PARAM_INT);
        $resultado->execute();

        return $resultado;
    }

    public function gravaBoletoQuitado()
    {
        $sql = "update movimentacoes set boleto_quitado = 1 where id =:id";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $this->getId(), PDO::PARAM_INT);
        $resultado->execute();

        return $resultado;
    }

    public function gravaPixEnviado()
    {
        $sql = "update movimentacoes set pix_enviado = 1 where id =:id";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $this->getId(), PDO::PARAM_INT);
        $resultado->execute();

        return $resultado;
    }

    public function gravaEstorno()
    {
        $sql = "update movimentacoes set id_estorno =:estorno where id =:id";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $this->getId(), PDO::PARAM_INT);
        $resultado->bindParam(":estorno", $this->getIdEstorno(), PDO::PARAM_INT);
        $resultado->execute();

        return $resultado;
    }

    public function gravaPagamentoCartao()
    {
        $sql = "update movimentacoes mov set mov.referencia_externa =:referencia_externa, mov.situacao =:situacao,
                mov.recusa_descricao =:recusa_descricao, mov.autorizacao =:autorizacao, mov.nsu =:nsu, mov.cartao_portador =:cartao_portador,
                mov.cartao_dig_ini =:cartao_dig_ini, mov.cartao_dig_fim =:cartao_dig_fim, mov.banderia =:banderia, mov.data = current_timestamp 
                where mov.id =:id";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $this->getId(), PDO::PARAM_INT);
        $resultado->bindParam(":referencia_externa", $this->getReferenciaExterna(), PDO::PARAM_STR);
        $resultado->bindParam(":situacao", $this->getSituacao(), PDO::PARAM_STR);
        $resultado->bindParam(":recusa_descricao", $this->getRecusaDescricao(), PDO::PARAM_STR);
        $resultado->bindParam(":autorizacao", $this->getAutorizacao(), PDO::PARAM_STR);
        $resultado->bindParam(":nsu", $this->getNsu(), PDO::PARAM_STR);
        $resultado->bindParam(":cartao_portador", $this->getCartaoPortador(), PDO::PARAM_STR);
        $resultado->bindParam(":cartao_dig_ini", $this->getCartaoDigIni(), PDO::PARAM_STR);
        $resultado->bindParam(":cartao_dig_fim", $this->getCartaoDigFim(), PDO::PARAM_STR);
        $resultado->bindParam(":banderia", $this->getBanderia(), PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function gravaErroPagamentoCartao()
    {
        $sql = "update movimentacoes set situacao =:situacao,
                recusa_descricao =:recusa_descricao
                where id =:id and situacao <> 'APPROVED'";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $this->getId(), PDO::PARAM_INT);
        $resultado->bindParam(":situacao", $this->getSituacao(), PDO::PARAM_STR);
        $resultado->bindParam(":recusa_descricao", $this->getRecusaDescricao(), PDO::PARAM_STR);
        $resultado->execute();

        return $resultado;
    }

    public function gravaDataPagamentoEC()
    {
        $codCli = $this->getCliId();

        $sql = "update movimentacoes set data_pagamento_ec = CURRENT_TIMESTAMP 
                where cli_id =:id and data_pagamento_ec is null and id_estorno = 0 and repasse_efetuado = 1";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $codCli, PDO::PARAM_INT);
        $resultado->execute();

        return $resultado;
    }

    public function gravaDataEnvioMovingPayPorId()
    {
        $id = $this->getId();

        $sql = "update movimentacoes set data_envio_movingpay = CURRENT_TIMESTAMP 
                where id =:id and data_envio_movingpay is null";

        $resultado = $this->pdo->prepare($sql);
        $resultado->bindParam(":id", $id, PDO::PARAM_INT);
        $resultado->execute();

        return $resultado;
    }

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param mixed $id
     */
    public function setId($id): void
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getOrigem()
    {
        return $this->origem;
    }

    /**
     * @param mixed $origem
     */
    public function setOrigem($origem): void
    {
        $this->origem = $origem;
    }

    /**
     * @return mixed
     */
    public function getServico()
    {
        return $this->servico;
    }

    /**
     * @param mixed $servico
     */
    public function setServico($servico): void
    {
        $this->servico = $servico;
    }

    /**
     * @return mixed
     */
    public function getDocumento()
    {
        return $this->documento;
    }

    /**
     * @param mixed $documento
     */
    public function setDocumento($documento): void
    {
        $this->documento = $documento;
    }

    /**
     * @return mixed
     */
    public function getReferenciaExterna()
    {
        return $this->referencia_externa;
    }

    /**
     * @param mixed $referencia_externa
     */
    public function setReferenciaExterna($referencia_externa): void
    {
        $this->referencia_externa = $referencia_externa;
    }

    /**
     * @return mixed
     */
    public function getSituacao()
    {
        return $this->situacao;
    }

    /**
     * @param mixed $situacao
     */
    public function setSituacao($situacao): void
    {
        $this->situacao = $situacao;
    }

    /**
     * @return mixed
     */
    public function getRecusaDescricao()
    {
        return $this->recusa_descricao;
    }

    /**
     * @param mixed $recusa_descricao
     */
    public function setRecusaDescricao($recusa_descricao): void
    {
        $this->recusa_descricao = $recusa_descricao;
    }

    /**
     * @return mixed
     */
    public function getCodigoRetorno()
    {
        return $this->codigo_retorno;
    }

    /**
     * @param mixed $codigo_retorno
     */
    public function setCodigoRetorno($codigo_retorno): void
    {
        $this->codigo_retorno = $codigo_retorno;
    }

    /**
     * @return mixed
     */
    public function getCodigoAdquirente()
    {
        return $this->codigo_adquirente;
    }

    /**
     * @param mixed $codigo_adquirente
     */
    public function setCodigoAdquirente($codigo_adquirente): void
    {
        $this->codigo_adquirente = $codigo_adquirente;
    }

    /**
     * @return mixed
     */
    public function getCodigoMcc()
    {
        return $this->codigo_mcc;
    }

    /**
     * @param mixed $codigo_mcc
     */
    public function setCodigoMcc($codigo_mcc): void
    {
        $this->codigo_mcc = $codigo_mcc;
    }

    /**
     * @return mixed
     */
    public function getAutorizacao()
    {
        return $this->autorizacao;
    }

    /**
     * @param mixed $autorizacao
     */
    public function setAutorizacao($autorizacao): void
    {
        $this->autorizacao = $autorizacao;
    }

    /**
     * @return mixed
     */
    public function getMoeda()
    {
        return $this->moeda;
    }

    /**
     * @param mixed $moeda
     */
    public function setMoeda($moeda): void
    {
        $this->moeda = $moeda;
    }

    /**
     * @return mixed
     */
    public function getNsuTef()
    {
        return $this->nsu_tef;
    }

    /**
     * @param mixed $nsu_tef
     */
    public function setNsuTef($nsu_tef): void
    {
        $this->nsu_tef = $nsu_tef;
    }

    /**
     * @return mixed
     */
    public function getNsu()
    {
        return $this->nsu;
    }

    /**
     * @param mixed $nsu
     */
    public function setNsu($nsu): void
    {
        $this->nsu = $nsu;
    }

    /**
     * @return mixed
     */
    public function getValor()
    {
        return $this->valor;
    }

    /**
     * @param mixed $valor
     */
    public function setValor($valor): void
    {
        $this->valor = $valor;
    }

    /**
     * @return mixed
     */
    public function getParcelas()
    {
        return $this->parcelas;
    }

    /**
     * @param mixed $parcelas
     */
    public function setParcelas($parcelas): void
    {
        $this->parcelas = $parcelas;
    }

    /**
     * @return mixed
     */
    public function getCartaoPortador()
    {
        return $this->cartao_portador;
    }

    /**
     * @param mixed $cartao_portador
     */
    public function setCartaoPortador($cartao_portador): void
    {
        $this->cartao_portador = $cartao_portador;
    }

    /**
     * @return mixed
     */
    public function getCartaoDigIni()
    {
        return $this->cartao_dig_ini;
    }

    /**
     * @param mixed $cartao_dig_ini
     */
    public function setCartaoDigIni($cartao_dig_ini): void
    {
        $this->cartao_dig_ini = $cartao_dig_ini;
    }

    /**
     * @return mixed
     */
    public function getCartaoDigFim()
    {
        return $this->cartao_dig_fim;
    }

    /**
     * @param mixed $cartao_dig_fim
     */
    public function setCartaoDigFim($cartao_dig_fim): void
    {
        $this->cartao_dig_fim = $cartao_dig_fim;
    }

    /**
     * @return mixed
     */
    public function getBanderia()
    {
        return $this->banderia;
    }

    /**
     * @param mixed $banderia
     */
    public function setBanderia($banderia): void
    {
        $this->banderia = $banderia;
    }

    /**
     * @return mixed
     */
    public function getFormaPagamento()
    {
        return $this->forma_pagamento;
    }

    /**
     * @param mixed $forma_pagamento
     */
    public function setFormaPagamento($forma_pagamento): void
    {
        $this->forma_pagamento = $forma_pagamento;
    }

    /**
     * @return mixed
     */
    public function getFormaCaptura()
    {
        return $this->forma_captura;
    }

    /**
     * @param mixed $forma_captura
     */
    public function setFormaCaptura($forma_captura): void
    {
        $this->forma_captura = $forma_captura;
    }

    /**
     * @return mixed
     */
    public function getNumeroSerie()
    {
        return $this->numero_serie;
    }

    /**
     * @param mixed $numero_serie
     */
    public function setNumeroSerie($numero_serie): void
    {
        $this->numero_serie = $numero_serie;
    }

    /**
     * @return mixed
     */
    public function getData()
    {
        return $this->data;
    }

    /**
     * @param mixed $data
     */
    public function setData($data): void
    {
        $this->data = $data;
    }

    /**
     * @return mixed
     */
    public function getEnviadoMovingpay()
    {
        return $this->enviado_movingpay;
    }

    /**
     * @param mixed $enviado_movingpay
     */
    public function setEnviadoMovingpay($enviado_movingpay): void
    {
        $this->enviado_movingpay = $enviado_movingpay;
    }

    /**
     * @return mixed
     */
    public function getVeiculoQuitado()
    {
        return $this->veiculo_quitado;
    }

    /**
     * @param mixed $veiculo_quitado
     */
    public function setVeiculoQuitado($veiculo_quitado): void
    {
        $this->veiculo_quitado = $veiculo_quitado;
    }

    /**
     * @return mixed
     */
    public function getBoletoQuitado()
    {
        return $this->boleto_quitado;
    }

    /**
     * @param mixed $boleto_quitado
     */
    public function setBoletoQuitado($boleto_quitado): void
    {
        $this->boleto_quitado = $boleto_quitado;
    }

    /**
     * @return mixed
     */
    public function getPixEnviado()
    {
        return $this->pix_enviado;
    }

    /**
     * @param mixed $pix_enviado
     */
    public function setPixEnviado($pix_enviado): void
    {
        $this->pix_enviado = $pix_enviado;
    }

    /**
     * @return mixed
     */
    public function getRetorno()
    {
        return $this->retorno;
    }

    /**
     * @param mixed $retorno
     */
    public function setRetorno($retorno): void
    {
        $this->retorno = $retorno;
    }

    /**
     * @return mixed
     */
    public function getMensagemRetorno()
    {
        return $this->mensagemRetorno;
    }

    /**
     * @param mixed $mensagemRetorno
     */
    public function setMensagemRetorno($mensagemRetorno): void
    {
        $this->mensagemRetorno = $mensagemRetorno;
    }

    /**
     * @return mixed
     */
    public function getValorOriginal()
    {
        return $this->valorOriginal;
    }

    /**
     * @param mixed $valorOriginal
     */
    public function setValorOriginal($valorOriginal)
    {
        $this->valorOriginal = $valorOriginal;
    }

    /**
     * @return mixed
     */
    public function getEmiteNota()
    {
        return $this->emiteNota;
    }

    /**
     * @param mixed $emiteNota
     */
    public function setEmiteNota($emiteNota)
    {
        $this->emiteNota = $emiteNota;
    }

    /**
     * @return mixed
     */
    public function getNovosDados()
    {
        return $this->novosDados;
    }

    /**
     * @param mixed $novosDados
     */
    public function setNovosDados($novosDados)
    {
        $this->novosDados = $novosDados;
    }

    /**
     * @return mixed
     */
    public function getNotaNome()
    {
        return $this->notaNome;
    }

    /**
     * @param mixed $notaNome
     */
    public function setNotaNome($notaNome)
    {
        $this->notaNome = $notaNome;
    }

    /**
     * @return mixed
     */
    public function getNotaDocumento()
    {
        return $this->notaDocumento;
    }

    /**
     * @param mixed $notaDocumento
     */
    public function setNotaDocumento($notaDocumento)
    {
        $this->notaDocumento = $notaDocumento;
    }

    /**
     * @return mixed
     */
    public function getNotaCep()
    {
        return $this->notaCep;
    }

    /**
     * @param mixed $notaCep
     */
    public function setNotaCep($notaCep)
    {
        $this->notaCep = $notaCep;
    }

    /**
     * @return mixed
     */
    public function getNotaRua()
    {
        return $this->notaRua;
    }

    /**
     * @param mixed $notaRua
     */
    public function setNotaRua($notaRua)
    {
        $this->notaRua = $notaRua;
    }

    /**
     * @return mixed
     */
    public function getNotaNumero()
    {
        return $this->notaNumero;
    }

    /**
     * @param mixed $notaNumero
     */
    public function setNotaNumero($notaNumero)
    {
        $this->notaNumero = $notaNumero;
    }

    /**
     * @return mixed
     */
    public function getNotaComplemento()
    {
        return $this->notaComplemento;
    }

    /**
     * @param mixed $notaComplemento
     */
    public function setNotaComplemento($notaComplemento)
    {
        $this->notaComplemento = $notaComplemento;
    }

    /**
     * @return mixed
     */
    public function getNotaBairro()
    {
        return $this->notaBairro;
    }

    /**
     * @param mixed $notaBairro
     */
    public function setNotaBairro($notaBairro)
    {
        $this->notaBairro = $notaBairro;
    }

    /**
     * @return mixed
     */
    public function getNotaCidade()
    {
        return $this->notaCidade;
    }

    /**
     * @param mixed $notaCidade
     */
    public function setNotaCidade($notaCidade)
    {
        $this->notaCidade = $notaCidade;
    }

    /**
     * @return mixed
     */
    public function getNotaEstado()
    {
        return $this->notaEstado;
    }

    /**
     * @param mixed $notaEstado
     */
    public function setNotaEstado($notaEstado)
    {
        $this->notaEstado = $notaEstado;
    }

    /**
     * @return mixed
     */
    public function getEnviadoSinpag()
    {
        return $this->enviado_sinpag;
    }

    /**
     * @param mixed $enviado_sinpag
     */
    public function setEnviadoSinpag($enviado_sinpag)
    {
        $this->enviado_sinpag = $enviado_sinpag;
    }

    /**
     * @return mixed
     */
    public function getIdSinpag()
    {
        return $this->id_sinpag;
    }

    /**
     * @param mixed $id_sinpag
     */
    public function setIdSinpag($id_sinpag)
    {
        $this->id_sinpag = $id_sinpag;
    }

    /**
     * @return mixed
     */
    public function getNotaTelefone()
    {
        return $this->notaTelefone;
    }

    /**
     * @param mixed $notaTelefone
     */
    public function setNotaTelefone($notaTelefone)
    {
        $this->notaTelefone = $notaTelefone;
    }

    /**
     * @return mixed
     */
    public function getNotaEmail()
    {
        return $this->notaEmail;
    }

    /**
     * @param mixed $notaEmail
     */
    public function setNotaEmail($notaEmail)
    {
        $this->notaEmail = $notaEmail;
    }

    /**
     * @return mixed
     */
    public function getNumeroEc()
    {
        return $this->numeroEc;
    }

    /**
     * @param mixed $numeroEc
     */
    public function setNumeroEc($numeroEc): void
    {
        $this->numeroEc = $numeroEc;
    }

    /**
     * @return mixed
     */
    public function getNumeroCv()
    {
        return $this->numeroCv;
    }

    /**
     * @param mixed $numeroCv
     */
    public function setNumeroCv($numeroCv): void
    {
        $this->numeroCv = $numeroCv;
    }

    /**
     * @return mixed
     */
    public function getCliId()
    {
        return $this->cliId;
    }

    /**
     * @param mixed $cliId
     */
    public function setCliId($cliId): void
    {
        $this->cliId = $cliId;
    }

    /**
     * @return mixed
     */
    public function getUrlNotification()
    {
        return $this->urlNotification;
    }

    /**
     * @param mixed $urlNotification
     */
    public function setUrlNotification($urlNotification): void
    {
        $this->urlNotification = $urlNotification;
    }

    /**
     * @return mixed
     */
    public function getRetornoJson()
    {
        return $this->retornoJson;
    }

    /**
     * @param mixed $retornoJson
     */
    public function setRetornoJson($retornoJson): void
    {
        $this->retornoJson = $retornoJson;
    }

    /**
     * @return mixed
     */
    public function getCalcCliente()
    {
        return $this->calcCliente;
    }

    /**
     * @param mixed $calcCliente
     */
    public function setCalcCliente($calcCliente): void
    {
        $this->calcCliente = $calcCliente;
    }

    /**
     * @return mixed
     */
    public function getCalcAdquirente()
    {
        return $this->calcAdquirente;
    }

    /**
     * @param mixed $calcAdquirente
     */
    public function setCalcAdquirente($calcAdquirente): void
    {
        $this->calcAdquirente = $calcAdquirente;
    }

    /**
     * @return mixed
     */
    public function getCalcCdx()
    {
        return $this->calcCdx;
    }

    /**
     * @param mixed $calcCdx
     */
    public function setCalcCdx($calcCdx): void
    {
        $this->calcCdx = $calcCdx;
    }

    /**
     * @return mixed
     */
    public function getCalcPolo()
    {
        return $this->calcPolo;
    }

    /**
     * @param mixed $calcPolo
     */
    public function setCalcPolo($calcPolo): void
    {
        $this->calcPolo = $calcPolo;
    }

    /**
     * @return mixed
     */
    public function getCalcRepresentante()
    {
        return $this->calcRepresentante;
    }

    /**
     * @param mixed $calcRepresentante
     */
    public function setCalcRepresentante($calcRepresentante): void
    {
        $this->calcRepresentante = $calcRepresentante;
    }

    /**
     * @return mixed
     */
    public function getDataRepasse()
    {
        return $this->dataRepasse;
    }

    /**
     * @param mixed $dataRepasse
     */
    public function setDataRepasse($dataRepasse): void
    {
        $this->dataRepasse = $dataRepasse;
    }

    /**
     * @return mixed
     */
    public function getTabelaUtilizada()
    {
        return $this->tabelaUtilizada;
    }

    /**
     * @param mixed $tabelaUtilizada
     */
    public function setTabelaUtilizada($tabelaUtilizada): void
    {
        $this->tabelaUtilizada = $tabelaUtilizada;
    }

    /**
     * @return mixed
     */
    public function getUrlSinPag()
    {
        return $this->urlSinPag;
    }

    /**
     * @param mixed $urlSinPag
     */
    public function setUrlSinPag($urlSinPag): void
    {
        $this->urlSinPag = $urlSinPag;
    }

    /**
     * @return mixed
     */
    public function getIdMovingPay()
    {
        return $this->idMovingPay;
    }

    /**
     * @param mixed $idMovingPay
     */
    public function setIdMovingPay($idMovingPay): void
    {
        $this->idMovingPay = $idMovingPay;
    }

    /**
     * @return mixed
     */
    public function getIdEstorno()
    {
        return $this->idEstorno;
    }

    /**
     * @param mixed $idEstorno
     */
    public function setIdEstorno($idEstorno): void
    {
        $this->idEstorno = $idEstorno;
    }

    /**
     * @return mixed
     */
    public function getSoftDescriptor()
    {
        return $this->softDescriptor;
    }

    /**
     * @param mixed $softDescriptor
     */
    public function setSoftDescriptor($softDescriptor): void
    {
        $this->softDescriptor = $softDescriptor;
    }

    /**
     * @return mixed
     */
    public function getCodCliMovingPay()
    {
        return $this->codCliMovingPay;
    }

    /**
     * @param mixed $codCliMovingPay
     */
    public function setCodCliMovingPay($codCliMovingPay): void
    {
        $this->codCliMovingPay = $codCliMovingPay;
    }

    /**
     * @return mixed
     */
    public function getValorTotal()
    {
        return $this->valorTotal;
    }

    /**
     * @param mixed $valorTotal
     */
    public function setValorTotal($valorTotal): void
    {
        $this->valorTotal = $valorTotal;
    }

    /**
     * @return mixed
     */
    public function getPermiteEstorno()
    {
        return $this->permiteEstorno;
    }

    /**
     * @param mixed $permiteEstorno
     */
    public function setPermiteEstorno($permiteEstorno): void
    {
        $this->permiteEstorno = $permiteEstorno;
    }


}