Example #1
0
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute schedule_faturamento ");

            /// USER [ execute ]

            T_Empresa emp   = new T_Empresa(this);
            DateTime  dtFat = DateTime.Now.AddDays(-1);

            #region - ## Busca todas as empresas -

            if (emp.selectAll())
            {
                // ## Busco todos os registros

                while (emp.fetch())
                {
                    // ## Se dia é hoje

                    if (emp.get_int_nu_periodoFat() == dtFat.Day &&
                        emp.get_tg_isentoFat() == Context.FALSE)
                    {
                        T_Faturamento fat     = new T_Faturamento(this);
                        T_Faturamento fat_upd = new T_Faturamento(this);

                        DateTime aux = dtFat;

                        // ## Para casos onde o mês deve ser o próximo

                        if (emp.get_int_nu_diaVenc() < dtFat.Day)
                        {
                            aux = dtFat.AddMonths(1);
                        }

                        DateTime dtVenc = new DateTime(aux.Year,
                                                       aux.Month,
                                                       (int)emp.get_int_nu_diaVenc());

                        fat.set_dt_vencimento(GetDataBaseTime(dtVenc));
                        fat.set_fk_empresa(emp.get_identity());
                        fat.set_tg_situacao(TipoSitFat.Pendente);

                        // ## Crio registro

                        fat.create_T_Faturamento();

                        long vr_total_fat = 0;

                        // ## Crio registro detalhe

                        #region - 1 - mensalidade -

                        {
                            T_FaturamentoDetalhes fat_det = new T_FaturamentoDetalhes(this);

                            fat_det.set_fk_fatura(fat.get_identity());
                            fat_det.set_vr_cobranca(emp.get_vr_mensalidade());
                            fat_det.set_tg_tipoFat(TipoFat.TBM);
                            fat_det.set_tg_desconto(Context.FALSE);
                            fat_det.set_fk_empresa(emp.get_identity());
                            fat_det.set_fk_loja(Context.FALSE);

                            vr_total_fat += fat_det.get_int_vr_cobranca();

                            fat_det.create_T_FaturamentoDetalhes();
                        }

                        #endregion

                        #region - 2 - valor por transações -

                        if (emp.get_int_vr_transacao() > 0)
                        {
                            LOG_Transacoes l_tr = new LOG_Transacoes(this);

                            l_tr.SetCountMode();

                            l_tr.select_rows_dt_emp(GetDataBaseTime(dtFat.AddMonths(-1)),
                                                    GetDataBaseTime(dtFat),
                                                    emp.get_identity());

                            long trans = l_tr.GetCount() - emp.get_int_nu_franquia();

                            if (trans > 0)
                            {
                                T_FaturamentoDetalhes fat_det = new T_FaturamentoDetalhes(this);

                                fat_det.set_fk_fatura(fat.get_identity());
                                fat_det.set_vr_cobranca((trans * emp.get_int_vr_transacao()).ToString());
                                fat_det.set_tg_tipoFat(TipoFat.FixoTrans);
                                fat_det.set_nu_quantidade(l_tr.GetCount().ToString());
                                fat_det.set_tg_desconto(Context.FALSE);
                                fat_det.set_fk_empresa(emp.get_identity());
                                fat_det.set_fk_loja(Context.FALSE);

                                vr_total_fat += fat_det.get_int_vr_cobranca();

                                fat_det.create_T_FaturamentoDetalhes();
                            }
                        }

                        #endregion

                        #region - 3 - valor percentual por transações -

                        if (emp.get_int_nu_pctValor() > 0)
                        {
                            LOG_Transacoes l_tr = new LOG_Transacoes(this);

                            // ## Busca por período e empresa

                            if (l_tr.select_rows_dt_emp(GetDataBaseTime(dtFat.AddMonths(-1)),
                                                        GetDataBaseTime(dtFat),
                                                        emp.get_identity()))
                            {
                                long vr_trans = 0;

                                while (l_tr.fetch())
                                {
                                    if (l_tr.get_tg_confirmada() == TipoConfirmacao.Confirmada)
                                    {
                                        vr_trans += l_tr.get_int_vr_total();
                                    }
                                }

                                if (vr_trans > 0)
                                {
                                    vr_trans = vr_trans * emp.get_int_nu_pctValor() / 10000;

                                    T_FaturamentoDetalhes fat_det = new T_FaturamentoDetalhes(this);

                                    fat_det.set_fk_fatura(fat.get_identity());
                                    fat_det.set_vr_cobranca(vr_trans.ToString());
                                    fat_det.set_tg_tipoFat(TipoFat.Percent);
                                    fat_det.set_tg_desconto(Context.FALSE);
                                    fat_det.set_fk_empresa(emp.get_identity());
                                    fat_det.set_fk_loja(Context.FALSE);

                                    vr_total_fat += fat_det.get_int_vr_cobranca();

                                    fat_det.create_T_FaturamentoDetalhes();
                                }
                            }
                        }

                        #endregion

                        #region - 4 - valor cartão ativo -

                        if (emp.get_int_vr_cartaoAtivo() > 0)
                        {
                            T_Cartao cart = new T_Cartao(this);

                            // ## Busca por período e empresa

                            if (cart.select_rows_empresa(emp.get_st_empresa()))
                            {
                                T_FaturamentoDetalhes fat_det = new T_FaturamentoDetalhes(this);

                                fat_det.set_fk_fatura(fat.get_identity());
                                fat_det.set_vr_cobranca((cart.RowCount() * emp.get_int_vr_cartaoAtivo()).ToString());
                                fat_det.set_tg_tipoFat(TipoFat.CartaoAtiv);
                                fat_det.set_tg_desconto(Context.FALSE);
                                fat_det.set_fk_empresa(emp.get_identity());
                                fat_det.set_fk_loja(Context.FALSE);

                                vr_total_fat += fat_det.get_int_vr_cobranca();

                                fat_det.create_T_FaturamentoDetalhes();
                            }
                        }

                        #endregion

                        #region - 5 - valores extras -

                        T_FaturamentoDetalhes fat_extras = new T_FaturamentoDetalhes(this);

                        if (fat_extras.select_rows_emp(emp.get_identity(), TipoFat.Extras))
                        {
                            while (fat_extras.fetch())
                            {
                                vr_total_fat += fat_extras.get_int_vr_cobranca();

                                T_FaturamentoDetalhes fat_extras_upd = new T_FaturamentoDetalhes(this);

                                fat_extras_upd.ExclusiveAccess();

                                fat_extras_upd.selectIdentity(fat_extras.get_identity());
                                fat_extras_upd.set_fk_fatura(fat.get_identity());

                                fat_extras_upd.synchronize_T_FaturamentoDetalhes();
                                fat_extras_upd.ReleaseExclusive();
                            }
                        }

                        #endregion

                        if (emp.get_int_vr_minimo() > vr_total_fat)
                        {
                            vr_total_fat = emp.get_int_vr_minimo();
                        }

                        fat_upd.ExclusiveAccess();
                        fat_upd.selectIdentity(fat.get_identity());

                        fat_upd.set_vr_cobranca(vr_total_fat.ToString());

                        fat_upd.synchronize_T_Faturamento();
                        fat_upd.ReleaseExclusive();
                    }
                }
            }

            #endregion

            T_Loja loj = new T_Loja(this);

            // ## Busca todas as lojas

            if (loj.selectAll())
            {
                // ## Busco todos os registros

                while (loj.fetch())
                {
                    // ## Se dia é hoje

                    Trace("Loja: " + loj.get_st_nome());

                    if (loj.get_tg_cancel() == Context.TRUE)
                    {
                        continue;
                    }

                    Trace("Loja ok ");

                    if (loj.get_int_nu_periodoFat() == dtFat.Day &&
                        loj.get_tg_isentoFat() == Context.FALSE)
                    {
                        Trace("[A]");

                        T_Faturamento fat     = new T_Faturamento(this);
                        T_Faturamento fat_upd = new T_Faturamento(this);

                        DateTime aux = dtFat;

                        // ## Para casos onde o mês deve ser o próximo

                        if (loj.get_int_nu_diavenc() < dtFat.Day)
                        {
                            Trace("[B]");
                            aux = dtFat.AddMonths(1);
                        }

                        Trace("[C]");

                        int zday = Convert.ToInt32(loj.get_int_nu_diavenc());

                        Trace("[C] 1 " + aux.Year.ToString());
                        Trace("[C] 2 " + aux.Month.ToString());
                        Trace("[C] 3 " + zday.ToString());

                        DateTime dtVenc = new DateTime(aux.Year, aux.Month, zday);

                        Trace("[D]");

                        fat.set_dt_vencimento(GetDataBaseTime(dtVenc));
                        fat.set_fk_loja(loj.get_identity());
                        fat.set_tg_situacao(TipoSitFat.Pendente);

                        // ## Crio registro

                        fat.create_T_Faturamento();

                        long vr_total_fat = 0;

                        // ## Crio registro detalhe

                        #region - 1 - mensalidade -

                        {
                            Trace("[E]");

                            T_FaturamentoDetalhes fat_det = new T_FaturamentoDetalhes(this);

                            fat_det.set_fk_fatura(fat.get_identity());
                            fat_det.set_vr_cobranca(loj.get_vr_mensalidade());
                            fat_det.set_tg_tipoFat(TipoFat.TBM);
                            fat_det.set_tg_desconto(Context.FALSE);
                            fat_det.set_fk_empresa(Context.FALSE);
                            fat_det.set_fk_loja(loj.get_identity());

                            vr_total_fat += fat_det.get_int_vr_cobranca();

                            fat_det.create_T_FaturamentoDetalhes();
                        }

                        #endregion

                        #region - 2 - valor por transações -

                        if (loj.get_int_vr_transacao() > 0)
                        {
                            Trace("[F]");

                            LOG_Transacoes l_tr = new LOG_Transacoes(this);

                            l_tr.SetCountMode();

                            l_tr.select_rows_dt_loj(GetDataBaseTime(dtFat.AddMonths(-1)),
                                                    GetDataBaseTime(dtFat),
                                                    loj.get_identity());

                            long trans = l_tr.GetCount() - loj.get_int_nu_franquia();

                            if (trans > 0)
                            {
                                Trace("[G]");

                                T_FaturamentoDetalhes fat_det = new T_FaturamentoDetalhes(this);

                                fat_det.set_fk_fatura(fat.get_identity());
                                fat_det.set_vr_cobranca((trans * loj.get_int_vr_transacao()).ToString());
                                fat_det.set_tg_tipoFat(TipoFat.FixoTrans);
                                fat_det.set_nu_quantidade(l_tr.GetCount().ToString());
                                fat_det.set_tg_desconto(Context.FALSE);
                                fat_det.set_fk_empresa(Context.FALSE);
                                fat_det.set_fk_loja(loj.get_identity());

                                vr_total_fat += fat_det.get_int_vr_cobranca();

                                fat_det.create_T_FaturamentoDetalhes();
                            }
                        }

                        #endregion

                        #region - 3 - valor percentual por transações -

                        if (loj.get_int_nu_pctValor() > 0)
                        {
                            Trace("[H]");

                            LOG_Transacoes l_tr = new LOG_Transacoes(this);

                            // ## Busca por período e empresa

                            if (l_tr.select_rows_dt_loj(GetDataBaseTime(dtFat.AddMonths(-1)),
                                                        GetDataBaseTime(dtFat),
                                                        loj.get_identity()))
                            {
                                Trace("[I]");

                                long vr_trans = 0;

                                while (l_tr.fetch())
                                {
                                    if (l_tr.get_tg_confirmada() == TipoConfirmacao.Confirmada)
                                    {
                                        vr_trans += l_tr.get_int_vr_total();
                                    }
                                }

                                if (vr_trans > 0)
                                {
                                    Trace("[J]");

                                    vr_trans = vr_trans * loj.get_int_nu_pctValor() / 10000;

                                    T_FaturamentoDetalhes fat_det = new T_FaturamentoDetalhes(this);

                                    fat_det.set_fk_fatura(fat.get_identity());
                                    fat_det.set_vr_cobranca(vr_trans.ToString());
                                    fat_det.set_tg_tipoFat(TipoFat.Percent);
                                    fat_det.set_tg_desconto(Context.FALSE);
                                    fat_det.set_fk_empresa(Context.FALSE);
                                    fat_det.set_fk_loja(loj.get_identity());

                                    vr_total_fat += fat_det.get_int_vr_cobranca();

                                    fat_det.create_T_FaturamentoDetalhes();
                                }
                            }
                        }

                        #endregion

                        #region - 4 - valores extras -

                        T_FaturamentoDetalhes fat_extras = new T_FaturamentoDetalhes(this);

                        if (fat_extras.select_rows_emp(loj.get_identity(), TipoFat.Extras))
                        {
                            Trace("[K]");

                            while (fat_extras.fetch())
                            {
                                Trace("[L]");

                                vr_total_fat += fat_extras.get_int_vr_cobranca();

                                T_FaturamentoDetalhes fat_extras_upd = new T_FaturamentoDetalhes(this);

                                fat_extras_upd.ExclusiveAccess();

                                fat_extras_upd.selectIdentity(fat_extras.get_identity());
                                fat_extras_upd.set_fk_fatura(fat.get_identity());

                                fat_extras_upd.synchronize_T_FaturamentoDetalhes();
                                fat_extras_upd.ReleaseExclusive();
                            }
                        }

                        #endregion

                        if (vr_total_fat < loj.get_int_vr_minimo())
                        {
                            vr_total_fat = loj.get_int_vr_minimo();
                        }

                        fat_upd.ExclusiveAccess();
                        fat_upd.selectIdentity(fat.get_identity());

                        fat_upd.set_vr_cobranca(vr_total_fat.ToString());

                        fat_upd.synchronize_T_Faturamento();
                        fat_upd.ReleaseExclusive();

                        Trace("[M]");
                    }
                }
            }

            /// USER [ execute ] END

            Registry("execute done schedule_faturamento ");

            return(true);
        }
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute fetch_dadosLoja ");

            /// USER [ execute ]

            // ## Copia para saida

            output_cont_dl.set_st_loja(loj.get_st_loja());
            output_cont_dl.set_nu_CNPJ(loj.get_nu_CNPJ());
            output_cont_dl.set_st_nome(loj.get_st_nome());
            output_cont_dl.set_st_social(loj.get_st_social());
            output_cont_dl.set_st_endereco(loj.get_st_endereco());
            output_cont_dl.set_st_enderecoInst(loj.get_st_enderecoInst());
            output_cont_dl.set_nu_inscEst(loj.get_nu_inscEst());

            output_cont_dl.set_st_cidade(loj.get_st_cidade());
            output_cont_dl.set_st_estado(loj.get_st_estado());
            output_cont_dl.set_nu_CEP(loj.get_nu_CEP());
            output_cont_dl.set_nu_telefone(loj.get_nu_telefone());
            output_cont_dl.set_nu_fax(loj.get_nu_fax());
            output_cont_dl.set_st_contato(loj.get_st_contato());
            output_cont_dl.set_vr_mensalidade(loj.get_vr_mensalidade());
            output_cont_dl.set_nu_contaDeb(loj.get_nu_contaDeb());
            output_cont_dl.set_st_obs(loj.get_st_obs());

            output_cont_dl.set_nu_pctValor(loj.get_nu_pctValor());
            output_cont_dl.set_vr_transacao(loj.get_vr_transacao());
            output_cont_dl.set_vr_minimo(loj.get_vr_minimo());
            output_cont_dl.set_nu_franquia(loj.get_nu_franquia());
            output_cont_dl.set_nu_periodoFat(loj.get_nu_periodoFat());
            output_cont_dl.set_nu_diavenc(loj.get_nu_diavenc());
            output_cont_dl.set_nu_bancoFat(loj.get_nu_bancoFat());
            output_cont_dl.set_tg_tipoCobranca(loj.get_tg_tipoCobranca());
            output_cont_dl.set_tg_blocked(loj.get_tg_blocked());
            output_cont_dl.set_tg_cancel(loj.get_tg_cancel());
            output_cont_dl.set_tg_isento(loj.get_tg_isentoFat());
            output_cont_dl.set_st_senhaWeb(loj.get_st_senha());

            LINK_LojaEmpresa loj_emp = new LINK_LojaEmpresa(this);
            T_Empresa        emp     = new T_Empresa(this);

            string convs = "";

            if (loj_emp.select_fk_loja(loj.get_identity()))
            {
                while (loj_emp.fetch())
                {
                    emp.selectIdentity(loj_emp.get_fk_empresa());

                    convs += emp.get_st_empresa().TrimStart('0') + ",";
                }
            }

            output_cont_dl.set_st_convenios(convs.TrimEnd(','));

            /// USER [ execute ] END

            Registry("execute done fetch_dadosLoja ");

            return(true);
        }
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute fetch_rel_tarifas ");

            /// USER [ execute ]

            StringBuilder sb_emp     = new StringBuilder();
            StringBuilder sb_content = new StringBuilder();

            money mon_help = new money();

            T_Empresa emp = new T_Empresa(this);

            emp.select_rows_tarifas();

            while (emp.fetch())
            {
                DadosEmpresa de = new DadosEmpresa();

                de.set_st_fantasia("(E) " + emp.get_st_empresa() + " " + emp.get_st_fantasia());

                DataPortable tmp = de as DataPortable;

                sb_emp.Append(MemorySave(ref tmp));
                sb_emp.Append(",");

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(de.get_st_fantasia());
                    //rt.set_st_desc ( "Empresa" );
                    rt.set_st_val(emp.get_st_fantasia());

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(de.get_st_fantasia());
                    //rt.set_st_desc ( "Mensalidade" );
                    rt.set_st_val(mon_help.formatToMoney(emp.get_vr_mensalidade()));

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(de.get_st_fantasia());
                    //rt.set_st_desc ( "Percentual sobre transação" );

                    string pct = emp.get_nu_pctValor().PadLeft(3, '0');

                    pct = pct.Insert(pct.Length - 2, ",") + "%";

                    rt.set_st_val(pct);

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(de.get_st_fantasia());
                    //rt.set_st_desc ( "Valor transação" );
                    rt.set_st_val(mon_help.formatToMoney(emp.get_vr_transacao()));

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(de.get_st_fantasia());
                    //rt.set_st_desc ( "Valor mínimo" );
                    rt.set_st_val(mon_help.formatToMoney(emp.get_vr_minimo()));

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(de.get_st_fantasia());
                    //rt.set_st_desc ( "Franquia de transações" );
                    rt.set_st_val(emp.get_nu_franquia());

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(de.get_st_fantasia());
                    //rt.set_st_desc ( "Valor por cartão ativo" );
                    rt.set_st_val(mon_help.formatToMoney(emp.get_vr_cartaoAtivo()));

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(de.get_st_fantasia());
                    //rt.set_st_desc ( "Isento de Fatura" );

                    if (emp.get_tg_isentoFat() == Context.TRUE)
                    {
                        rt.set_st_val("SIM");
                    }
                    else
                    {
                        rt.set_st_val("NÃO");
                    }

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(de.get_st_fantasia());
                    //rt.set_st_desc ( "Situação" );

                    if (emp.get_tg_blocked() == Context.TRUE)
                    {
                        rt.set_st_val("Bloq.");
                    }
                    else
                    {
                        rt.set_st_val("Ativo");
                    }

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }
            }

            T_Loja loj = new T_Loja(this);

            loj.select_rows_tarifas();

            while (loj.fetch())
            {
                DadosEmpresa de = new DadosEmpresa();

                string id = "(" + loj.get_st_loja() + ") CNPJ: " + loj.get_nu_CNPJ() + " " + loj.get_st_nome() + " - " + loj.get_st_social();

                de.set_st_fantasia(id);

                DataPortable tmp = de as DataPortable;

                sb_emp.Append(MemorySave(ref tmp));
                sb_emp.Append(",");

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(de.get_st_fantasia());
                    //rt.set_st_desc ( "Empresa" );
                    rt.set_st_val(id);

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(id);
                    //rt.set_st_desc ( "Mensalidade" );
                    rt.set_st_val(mon_help.formatToMoney(loj.get_vr_mensalidade()));

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(id);
                    //rt.set_st_desc ( "Percentual sobre transação" );

                    string pct = loj.get_nu_pctValor().PadLeft(3, '0');

                    pct = pct.Insert(pct.Length - 2, ",") + "%";

                    rt.set_st_val(pct);

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(id);
                    //rt.set_st_desc ( "Valor transação" );
                    rt.set_st_val(mon_help.formatToMoney(loj.get_vr_transacao()));

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(id);
                    //rt.set_st_desc ( "Valor mínimo" );
                    rt.set_st_val(mon_help.formatToMoney(loj.get_vr_minimo()));

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(id);
                    //rt.set_st_desc ( "Franquia de transações" );
                    rt.set_st_val(loj.get_nu_franquia());

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(de.get_st_fantasia());
                    //rt.set_st_desc ( "Valor por cartão ativo" );
                    rt.set_st_val("0");

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(id);
                    //rt.set_st_desc ( "Isento de Fatura" );

                    if (loj.get_tg_isentoFat() == Context.TRUE)
                    {
                        rt.set_st_val("SIM");
                    }
                    else
                    {
                        rt.set_st_val("NÃO");
                    }

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }

                {
                    Rel_Tarifas rt = new Rel_Tarifas();

                    rt.set_st_emp(de.get_st_fantasia());
                    //rt.set_st_desc ( "Situação" );

                    if (loj.get_tg_blocked() == Context.TRUE)
                    {
                        rt.set_st_val("Bloq.");
                    }
                    else
                    {
                        rt.set_st_val("Ativo");
                    }

                    if (loj.get_tg_cancel() == Context.TRUE)
                    {
                        rt.set_st_val("Cancel.");
                    }

                    DataPortable port_rt = rt as DataPortable;

                    sb_content.Append(MemorySave(ref port_rt));
                    sb_content.Append(",");
                }
            }

            // content
            {
                string list_ids = sb_content.ToString().TrimEnd(',');

                DataPortable dp = new DataPortable();

                dp.setValue("ids", list_ids);

                output_st_csv = MemorySave(ref dp);
            }

            // entidades
            {
                string list_ids = sb_emp.ToString().TrimEnd(',');

                DataPortable dp = new DataPortable();

                dp.setValue("ids", list_ids);

                output_st_csv_emp = MemorySave(ref dp);
            }

            /// USER [ execute ] END

            Registry("execute done fetch_rel_tarifas ");

            return(true);
        }
Example #4
0
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute fetch_relFat ");

            /// USER [ execute ]

            T_Faturamento fat = new T_Faturamento(this);

            if (!fat.select_rows_dt_venc(input_st_dt_ini,
                                         input_st_dt_fim,
                                         input_tg_type))
            {
                PublishError("Nenhum registro encontrado");
                return(false);
            }

            T_Empresa     emp     = new T_Empresa(this);
            T_Loja        loj     = new T_Loja(this);
            T_RetCobranca ret_cob = new T_RetCobranca(this);

            string nome      = "";
            long   total_cob = 0;

            StringBuilder sb_content = new StringBuilder();

            while (fat.fetch())
            {
                if (input_tg_type == TipoSitFat.PagoDoc ||
                    input_tg_type == TipoSitFat.PagoCC)
                {
                    if (fat.get_tg_retBanco() == "0")
                    {
                        continue;
                    }
                }

                Rel_FatCompleto rel = new Rel_FatCompleto();



                if (fat.get_fk_empresa() != Context.FALSE)
                {
                    if (!emp.selectIdentity(fat.get_fk_empresa()))
                    {
                        return(false);
                    }

                    if (emp.get_tg_isentoFat() == Context.TRUE)
                    {
                        continue;
                    }

                    nome = "(E) " + emp.get_st_social();

                    ret_cob.select_rows_cod(emp.get_nu_bancoFat(),
                                            fat.get_tg_retBanco(),
                                            emp.get_tg_tipoCobranca());

                    total_cob += fat.get_int_vr_cobranca();
                }
                else
                {
                    if (!loj.selectIdentity(fat.get_fk_loja()))
                    {
                        return(false);
                    }

                    nome = "(L) [" + loj.get_st_loja() + "] " + loj.get_st_social() + " - " + loj.get_st_nome();

                    if (loj.get_tg_isentoFat() == Context.TRUE)
                    {
                        nome = "(ISENTO) " + nome;
                    }
                    else
                    {
                        total_cob += fat.get_int_vr_cobranca();
                    }

                    ret_cob.select_rows_cod(loj.get_nu_bancoFat(),
                                            fat.get_tg_retBanco(),
                                            loj.get_tg_tipoCobranca());
                }

                ret_cob.fetch();

                rel.set_st_nome(nome);
                rel.set_vr_cobranca(fat.get_vr_cobranca());
                rel.set_dt_vencimento(fat.get_dt_vencimento());

                if (fat.get_tg_situacao() != TipoSitFat.EmCobrança)
                {
                    rel.set_dt_baixa(fat.get_dt_baixa());
                    rel.set_cod_retBanco(fat.get_tg_retBanco());
                    rel.set_st_msgBanco(ret_cob.get_st_codMsg());
                }

                DataPortable port = rel as DataPortable;

                sb_content.Append(MemorySave(ref port));
                sb_content.Append(",");
            }

            output_st_total = total_cob.ToString();

            // content
            {
                string list_ids = sb_content.ToString().TrimEnd(',');

                if (list_ids == "")
                {
                    PublishError("Nenhum registro encontrado");
                    return(false);
                }
                else
                {
                    DataPortable dp = new DataPortable();

                    dp.setValue("ids", list_ids);

                    output_st_content_block = MemorySave(ref dp);
                }
            }

            /// USER [ execute ] END

            Registry("execute done fetch_relFat ");

            return(true);
        }
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute fetch_rel_6_fat ");

            /// USER [ execute ]

            T_Faturamento fat = new T_Faturamento(this);

            if (!fat.select_rows_dt_venc(input_st_dt_ini,
                                         input_st_dt_fim,
                                         TipoSitFat.Pendente))
            {
                PublishError("Nenhum registro encontrado");
                return(false);
            }

            T_Empresa             emp     = new T_Empresa(this);
            T_Loja                loj     = new T_Loja(this);
            T_FaturamentoDetalhes fat_det = new T_FaturamentoDetalhes(this);

            StringBuilder sb_content = new StringBuilder();
            StringBuilder sb_entity  = new StringBuilder();

            long total          = 0,
                 total_desconto = 0,
                 CartaoAtiv     = 0,
                 Extras         = 0,
                 FixoTrans      = 0,
                 Percent        = 0,
                 TBM            = 0;

            while (fat.fetch())
            {
                Entidade ent = new Entidade();

                ent.set_fk_fatura(fat.get_identity());

                long desconto = 0;

                if (fat.get_fk_empresa() != Context.NONE)
                {
                    if (!emp.selectIdentity(fat.get_fk_empresa()))
                    {
                        return(false);
                    }

                    if (emp.get_tg_isentoFat() == Context.TRUE)
                    {
                        continue;
                    }

                    ent.set_st_nome("Associação (" + emp.get_st_empresa() + ") " + emp.get_st_fantasia() + " - CNPJ: " + emp.get_nu_CNPJ());
                }
                else
                {
                    if (!loj.selectIdentity(fat.get_fk_loja()))
                    {
                        return(false);
                    }

                    if (loj.get_tg_isentoFat() == Context.TRUE)
                    {
                        continue;
                    }

                    ent.set_st_nome("Loja (" + loj.get_st_loja() + ") " + loj.get_st_nome() + " - CNPJ: " + loj.get_nu_CNPJ());
                }

                DataPortable tmp = ent as DataPortable;

                sb_entity.Append(MemorySave(ref tmp));
                sb_entity.Append(",");

                fat_det.Reset();

                if (fat_det.select_fk_fat(fat.get_identity()))
                {
                    while (fat_det.fetch())
                    {
                        Rel_FAT r_f = new Rel_FAT();

                        if (fat_det.get_tg_desconto() == Context.TRUE)
                        {
                            desconto += fat_det.get_int_vr_cobranca();
                        }

                        r_f.set_st_extra(fat_det.get_st_extras());
                        r_f.set_vr_cob(fat_det.get_vr_cobranca());
                        r_f.set_tg_tipoFat(fat_det.get_tg_tipoFat());
                        r_f.set_tg_desconto(fat_det.get_tg_desconto());

                        switch (fat_det.get_tg_tipoFat())
                        {
                        case TipoFat.CartaoAtiv:        CartaoAtiv += fat_det.get_int_vr_cobranca();    break;

                        case TipoFat.Extras:            Extras += fat_det.get_int_vr_cobranca();    break;

                        case TipoFat.FixoTrans:         FixoTrans += fat_det.get_int_vr_cobranca();    break;

                        case TipoFat.Percent:           Percent += fat_det.get_int_vr_cobranca();    break;

                        case TipoFat.TBM:                       TBM += fat_det.get_int_vr_cobranca();    break;
                        }

                        r_f.set_fk_fatura(fat_det.get_fk_fatura());

                        DataPortable tmp2 = r_f as DataPortable;

                        sb_content.Append(MemorySave(ref tmp2));
                        sb_content.Append(",");
                    }
                }

                total          += fat.get_int_vr_cobranca();
                total_desconto += desconto;

                output_st_csv_subtotal          += fat.get_vr_cobranca() + ",";
                output_st_csv_subtotal_desconto += desconto.ToString() + ",";
            }

            // content
            {
                string list_ids = sb_content.ToString().TrimEnd(',');

                DataPortable dp = new DataPortable();

                dp.setValue("ids", list_ids);

                output_st_content_block = MemorySave(ref dp);
            }

            // entidades
            {
                string list_ids = sb_entity.ToString().TrimEnd(',');

                DataPortable dp = new DataPortable();

                dp.setValue("ids", list_ids);

                output_st_emp_loj_block = MemorySave(ref dp);
            }

            output_st_csv_subtotal          = output_st_csv_subtotal.TrimEnd(',');
            output_st_csv_subtotal_desconto = output_st_csv_subtotal_desconto.TrimEnd(',');

            output_st_total          = total.ToString();
            output_st_total_desconto = total_desconto.ToString();
            output_CartaoAtiv        = CartaoAtiv.ToString();
            output_Extras            = Extras.ToString();
            output_FixoTrans         = FixoTrans.ToString();
            output_Percent           = Percent.ToString();
            output_TBM = TBM.ToString();

            /// USER [ execute ] END

            Registry("execute done fetch_rel_6_fat ");

            return(true);
        }