Exemplo n.º 1
0
        public void GetSaldoDisponivel(ref T_Cartao cart, ref long dispMensal, ref long dispTotal)
        {
            Transaction tr = cart.var_Transaction;

            bool changed = false;

            if (tr.SQL_LOGGING_ENABLE == true)
            {
                tr.SQL_LOGGING_ENABLE = false;
                changed = true;
            }

            ArrayList lstCartoes = new ArrayList();

            T_Cartao c_t = new T_Cartao(tr);

            c_t.select_rows_empresa_matricula(cart.get_st_empresa(), cart.get_st_matricula());

            while (c_t.fetch())
            {
                lstCartoes.Add(c_t.get_identity());
            }

            if (cart.get_tg_tipoCartao() == TipoCartao.empresarial)
            {
                tr.Trace("Empresarial!");

                LOG_Transacoes ltr  = new LOG_Transacoes(tr);
                T_Parcelas     parc = new T_Parcelas(tr);

                // Verifica disponivel mensal nas parcelas
                if (parc.select_rows_cartao_mensal(ref lstCartoes, "1"))                      // este mês
                {
                    while (parc.fetch())
                    {
                        if (ltr.selectIdentity(parc.get_fk_log_transacoes()))                              // busca transação
                        {
                            if (ltr.get_tg_confirmada() == TipoConfirmacao.Confirmada ||
                                ltr.get_tg_confirmada() == TipoConfirmacao.Pendente)
                            {
                                dispMensal -= parc.get_int_vr_valor();
                            }
                        }
                    }
                }

                parc.Reset();

                // Verifica disponivel total nas parcelas
                if (parc.select_rows_cartao(ref lstCartoes, "1"))                       // nu_parcela >= 1 (ou seja, no futuro)
                {
                    while (parc.fetch())
                    {
                        if (ltr.selectIdentity(parc.get_fk_log_transacoes()))                              // busca transação
                        {
                            if (ltr.get_tg_confirmada() == TipoConfirmacao.Confirmada ||
                                ltr.get_tg_confirmada() == TipoConfirmacao.Pendente)
                            {
                                dispTotal -= parc.get_int_vr_valor();
                            }
                        }
                    }
                }

                if (dispMensal < 0)
                {
                    dispMensal = 0;
                }

                if (dispTotal < 0)
                {
                    dispTotal = 0;
                }
            }
            else if (cart.get_tg_tipoCartao() == TipoCartao.educacional)
            {
                dispMensal = cart.get_int_vr_disp_educacional();
                dispTotal  = cart.get_int_vr_disp_educacional();
            }

            if (changed)
            {
                tr.SQL_LOGGING_ENABLE = true;
            }
        }