public void Duplicar(Object tabelaValorID, DateTime inicio, DateTime fim, Taxa taxa)
        {
            IList <Plano> planos = Plano.CarregaPlanosDaTabelaDeValor(tabelaValorID);

            PersistenceManager pm = new PersistenceManager();

            pm.BeginTransactionContext();

            try
            {
                TabelaValor tabela = new TabelaValor(tabelaValorID);
                pm.Load(tabela);

                TabelaValor novaTabela = new TabelaValor();
                novaTabela.ContratoID = tabela.ContratoID;
                novaTabela.Inicio     = inicio;
                novaTabela.Fim        = fim;
                pm.Save(novaTabela);

                taxa.TabelaValorID = novaTabela.ID;
                pm.Save(taxa);

                if (planos != null) //se tem planos, duplica os itens de tabela de valor para cada plano, aplicando a nova taxa
                {
                    foreach (Plano plano in planos)
                    {
                        IList <TabelaValorItem> itens = TabelaValorItem.CarregarPorTabela(tabela.ID, plano.ID, pm);
                        if (itens == null || itens.Count == 0)
                        {
                            continue;
                        }

                        foreach (TabelaValorItem item in itens)
                        {
                            item.ID       = null;
                            item.TabelaID = novaTabela.ID;
                            item.AplicaTaxa(taxa, true);
                            pm.Save(item);
                        }
                    }
                }

                pm.Commit();
            }
            catch (Exception ex)
            {
                pm.Rollback();
                throw ex;
            }
            finally
            {
                pm = null;
            }
        }
        public void RecalcularTaxaEmPlanos(Object tabelaValorID, Taxa taxa)
        {
            IList <Plano> planos = Plano.CarregaPlanosDaTabelaDeValor(tabelaValorID);

            if (planos == null)
            {
                return;
            }

            PersistenceManager pm = new PersistenceManager();

            pm.BeginTransactionContext();

            try
            {
                TabelaValor tabela = new TabelaValor(tabelaValorID);
                pm.Load(tabela);

                foreach (Plano plano in planos)
                {
                    IList <TabelaValorItem> itens = TabelaValorItem.CarregarPorTabela(tabela.ID, plano.ID, pm);
                    if (itens == null || itens.Count == 0)
                    {
                        continue;
                    }

                    foreach (TabelaValorItem item in itens)
                    {
                        item.AplicaTaxa(taxa, false);
                        pm.Save(item);
                    }
                }

                pm.Commit();
            }
            catch (Exception ex)
            {
                pm.Rollback();
                throw ex;
            }
            finally
            {
                pm = null;
            }
        }