Beispiel #1
0
        public void AtualizarFaturamentoDoSegmentoCanal(int ano, int trimestre)
        {
            List <MetadaUnidade> lstMetadaUnidade = RepositoryService.MetadaUnidade.ListarMetas(ano);

            if (lstMetadaUnidade.Count == 0)
            {
                return;
            }

            DataTable dtMetaCanalSegmento = RepositoryService.MetadoCanalporSegmento.ListarMetaCanalSegmentoDW(ano, trimestre, lstMetadaUnidade);

            foreach (DataRow item in dtMetaCanalSegmento.Rows)
            {
                UnidadeNegocio mUnidadeNegocio = RepositoryService.UnidadeNegocio.ObterPorChaveIntegracao(item["CD_Unidade_Negocio"].ToString());
                Conta          mConta          = RepositoryService.Conta.ObterCanal(item["CD_Emitente"].ToString());
                Segmento       mSegmento       = RepositoryService.Segmento.ObterPor(item["cd_segmento"].ToString());

                if (mUnidadeNegocio != null && mConta != null && mSegmento != null)
                {
                    MetadoCanalporSegmento mMetadoCanalporSegmento = RepositoryService.MetadoCanalporSegmento.Obter(mUnidadeNegocio.ID.Value, mConta.ID.Value, ano, trimestre, mSegmento.ID.Value, "itbc_metadocanalporsegmentoid");
                    if (mMetadoCanalporSegmento != null)
                    {
                        mMetadoCanalporSegmento.MetaRealizada = item.Field <decimal>("vlr");
                        RepositoryService.MetadoCanalporSegmento.Update(mMetadoCanalporSegmento);
                    }
                }
            }
        }
Beispiel #2
0
        public void Criar(MetadoCanalporSegmento mMetadoCanalporSegmento, List <Model.OrcamentoDetalhado> lstOrcamentoDetalhado)
        {
            MetadoCanalporFamilia mMetadoCanalporFamilia;
            var lstorcamentoporsegfamilia = (from x in lstOrcamentoDetalhado
                                             group x by string.Format("{0}/{1}", x.Familia.Id, x.Segmento.Id));

            foreach (var OrcaSegFamilia in lstorcamentoporsegfamilia)
            {
                //mMetadoCanalporFamilia = RepositoryService.MetadoCanalporFamilia.Obterpor(OrcaSegFamilia.First().Canal.Id, mMetadoCanalporSegmento.ID.Value, OrcaSegFamilia.First().Segmento.Id, OrcaSegFamilia.First().Familia.Id, mMetadoCanalporSegmento.Trimestre.Value);
                mMetadoCanalporFamilia = RepositoryService.MetadoCanalporFamilia.Obterpor(OrcaSegFamilia.First().UnidadeNegocio.Id, OrcaSegFamilia.First().Canal.Id, mMetadoCanalporSegmento.Ano.Value, mMetadoCanalporSegmento.Trimestre.Value, OrcaSegFamilia.First().Segmento.Id, OrcaSegFamilia.First().Familia.Id);
                if (mMetadoCanalporFamilia == null)
                {
                    mMetadoCanalporFamilia                        = new MetadoCanalporFamilia(RepositoryService.NomeDaOrganizacao, RepositoryService.IsOffline, RepositoryService.Provider);
                    mMetadoCanalporFamilia.ID                     = Guid.NewGuid();
                    mMetadoCanalporFamilia.Canal                  = new Lookup(OrcaSegFamilia.First().Canal.Id, SDKore.Crm.Util.Utility.GetEntityName <Model.Conta>());
                    mMetadoCanalporFamilia.UnidadedeNegocio       = mMetadoCanalporSegmento.UnidadedeNegocio;
                    mMetadoCanalporFamilia.Ano                    = mMetadoCanalporSegmento.Ano;
                    mMetadoCanalporFamilia.Trimestre              = mMetadoCanalporSegmento.Trimestre;
                    mMetadoCanalporFamilia.Segmento               = new Lookup(OrcaSegFamilia.First().Segmento.Id, SDKore.Crm.Util.Utility.GetEntityName <Model.Segmento>());
                    mMetadoCanalporFamilia.Familia                = new Lookup(OrcaSegFamilia.First().Familia.Id, SDKore.Crm.Util.Utility.GetEntityName <Model.FamiliaProduto>());
                    mMetadoCanalporFamilia.MetadoCanalporSegmento = new Lookup(mMetadoCanalporSegmento.ID.Value, SDKore.Crm.Util.Utility.GetEntityName <Model.OrcamentodoCanalporSegmento>());

                    mMetadoCanalporFamilia.Nome = (mMetadoCanalporSegmento.Nome + " - " + OrcaSegFamilia.First().Familia.Name).ToString().Length > 99 ?
                                                  (mMetadoCanalporSegmento.Nome + " - " + OrcaSegFamilia.First().Familia.Name).Substring(1, 99)
                        : (mMetadoCanalporSegmento.Nome + " - " + OrcaSegFamilia.First().Familia.Name);

                    RepositoryService.MetadoCanalporFamilia.Create(mMetadoCanalporFamilia);
                }
                ServiceMetadoCanalporSubFamilia.Criar(mMetadoCanalporFamilia, lstOrcamentoDetalhado);
            }
        }
Beispiel #3
0
        public void Criar(Model.MetadaUnidadeporTrimestre mMetadaUnidadeporTrimestre, MetadoCanal mMetadoCanal, List <Model.OrcamentoDetalhado> lstOrcamentoDetalhado)
        {
            MetadoCanalporSegmento mMetadoCanalporSegmento;
            var lstOrcamentoporSegmento = (from x in lstOrcamentoDetalhado
                                           group x by string.Format("{0}", x.Segmento.Id));

            foreach (var OrcaSegmento in lstOrcamentoporSegmento)
            {
                //mMetadoCanalporSegmento = RepositoryService.MetadoCanalporSegmento.Obter(mMetadaUnidadeporTrimestre.MetadaUnidade.Id, OrcaSegmento.First().Canal.Id, mMetadaUnidadeporTrimestre.Trimestre.Value, OrcaSegmento.First().Segmento.Id);
                mMetadoCanalporSegmento = RepositoryService.MetadoCanalporSegmento.Obter(mMetadaUnidadeporTrimestre.UnidadedeNegocio.Id, OrcaSegmento.First().Canal.Id, mMetadaUnidadeporTrimestre.Ano.Value, mMetadaUnidadeporTrimestre.Trimestre.Value, OrcaSegmento.First().Segmento.Id);
                if (mMetadoCanalporSegmento == null)
                {
                    mMetadoCanalporSegmento                  = new MetadoCanalporSegmento(RepositoryService.NomeDaOrganizacao, RepositoryService.IsOffline, RepositoryService.Provider);
                    mMetadoCanalporSegmento.ID               = Guid.NewGuid();
                    mMetadoCanalporSegmento.Nome             = mMetadaUnidadeporTrimestre.Nome + " - " + OrcaSegmento.First().Segmento.Name;
                    mMetadoCanalporSegmento.UnidadedeNegocio = mMetadaUnidadeporTrimestre.UnidadedeNegocio;
                    mMetadoCanalporSegmento.Ano              = mMetadaUnidadeporTrimestre.Ano;// mOrcamentodaUnidade.Ano;
                    mMetadoCanalporSegmento.Canal            = new Lookup(OrcaSegmento.First().Canal.Id, SDKore.Crm.Util.Utility.GetEntityName <Model.Conta>());
                    mMetadoCanalporSegmento.Trimestre        = mMetadaUnidadeporTrimestre.Trimestre;
                    mMetadoCanalporSegmento.Segmento         = new Lookup(OrcaSegmento.First().Segmento.Id, SDKore.Crm.Util.Utility.GetEntityName <Model.Segmento>());
                    //mMetadoCanalporSegmento.MetadoTrimestreCanal = new Lookup(mMetadoCanal.ID.Value, SDKore.Crm.Util.Utility.GetEntityName<Model.MetadoCanal>());

                    RepositoryService.MetadoCanalporSegmento.Create(mMetadoCanalporSegmento);
                }

                ServiceMetadoCanalporFamilia.Criar(mMetadoCanalporSegmento, lstOrcamentoDetalhado);
            }
        }
        public List <MetadoCanalporSegmento> ListarValoresPorUnidadeNegocio(Guid unidadeNegocioId, int ano, Domain.Enum.OrcamentodaUnidade.Trimestres trimeste)
        {
            var lista = new List <MetadoCanalporSegmento>();

            string fetch = @"<fetch aggregate='true' no-lock='true' >
                              <entity name='itbc_metadocanalporfamilia' >
                                <attribute name='itbc_metarealizada' alias='valor_realizado' aggregate='sum' />
                                <attribute name='itbc_metaplanejada' alias='valor_planejado' aggregate='sum' />
                                <link-entity name='itbc_metadocanalporsegmento' from='itbc_metadocanalporsegmentoid' to='itbc_metadocanalporsegmentoid' >
                                  <attribute name='itbc_metadocanalporsegmentoid' alias='id' groupby='true' />
                                  <filter type='and' >
                                    <condition attribute='itbc_ano' operator='eq' value='{0}' />
                                    <condition attribute='itbc_unidadedenegocioid' operator='eq' value='{1}' />
                                    <condition attribute='itbc_trimestre' operator='eq' value='{2}' />
                                  </filter>
                                </link-entity>
                              </entity>
                            </fetch>";


            fetch = string.Format(fetch, ano, unidadeNegocioId, (int)trimeste);

            var retrieveMultiple = new RetrieveMultipleRequest()
            {
                Query = new FetchExpression(fetch)
            };

            EntityCollection collection = ((RetrieveMultipleResponse)this.Execute(retrieveMultiple)).EntityCollection;

            foreach (var item in collection.Entities)
            {
                var meta = new MetadoCanalporSegmento(OrganizationName, IsOffline, Provider)
                {
                    ID            = (Guid)((AliasedValue)(item.Attributes["id"])).Value,
                    MetaPlanejada = ((Money)((AliasedValue)item.Attributes["valor_planejado"]).Value).Value,
                    MetaRealizada = ((Money)((AliasedValue)item.Attributes["valor_realizado"]).Value).Value
                };

                lista.Add(meta);
            }

            return(lista);
        }