public void Criar(OrcamentodoCanalporSegmento mOrcamentodoCanalporSegmento, List <Model.OrcamentoDetalhado> lstOrcamentoDetalhado, Guid SegmentoId, Guid canalId) { OrcamentodoCanalporFamilia mOrcamentodoCanalporFamilia; var lstorcamentoporsegfamilia = (from x in lstOrcamentoDetalhado //where x.Segmento.Id == SegmentoId && x.Canal.Id == canalId group x by string.Format("{0}/{1}", x.Familia.Id, x.Segmento.Id)); foreach (var OrcaSegFamilia in lstorcamentoporsegfamilia) { mOrcamentodoCanalporFamilia = RepositoryService.OrcamentodoCanalporFamilia.ObterOrcamentoCanalFamilia(canalId, mOrcamentodoCanalporSegmento.ID.Value, OrcaSegFamilia.First().Segmento.Id, OrcaSegFamilia.First().Familia.Id, mOrcamentodoCanalporSegmento.Trimestre.Value); if (mOrcamentodoCanalporFamilia == null) { mOrcamentodoCanalporFamilia = new OrcamentodoCanalporFamilia(RepositoryService.NomeDaOrganizacao, RepositoryService.IsOffline, RepositoryService.Provider); mOrcamentodoCanalporFamilia.ID = Guid.NewGuid(); mOrcamentodoCanalporFamilia.Canal = new Lookup(canalId, SDKore.Crm.Util.Utility.GetEntityName <Model.Conta>()); mOrcamentodoCanalporFamilia.UnidadedeNegocio = mOrcamentodoCanalporSegmento.UnidadedeNegocio; mOrcamentodoCanalporFamilia.Ano = mOrcamentodoCanalporSegmento.Ano; mOrcamentodoCanalporFamilia.Trimestre = mOrcamentodoCanalporSegmento.Trimestre; mOrcamentodoCanalporFamilia.Segmento = new Lookup(OrcaSegFamilia.First().Segmento.Id, SDKore.Crm.Util.Utility.GetEntityName <Model.Segmento>()); mOrcamentodoCanalporFamilia.FamiliadeProduto = new Lookup(OrcaSegFamilia.First().Familia.Id, SDKore.Crm.Util.Utility.GetEntityName <Model.FamiliaProduto>()); mOrcamentodoCanalporFamilia.OrcamentodoCanalporSegmento = new Lookup(mOrcamentodoCanalporSegmento.ID.Value, SDKore.Crm.Util.Utility.GetEntityName <Model.OrcamentodoCanalporSegmento>()); mOrcamentodoCanalporFamilia.Nome = (mOrcamentodoCanalporSegmento.Nome + " - " + OrcaSegFamilia.First().Familia.Name).ToString().Length > 99 ? (mOrcamentodoCanalporSegmento.Nome + " - " + OrcaSegFamilia.First().Familia.Name).Substring(1, 99) : (mOrcamentodoCanalporSegmento.Nome + " - " + OrcaSegFamilia.First().Familia.Name); RepositoryService.OrcamentodoCanalporFamilia.Create(mOrcamentodoCanalporFamilia); } ServiceOrcamentodoCanalporSubFamilia.Criar(mOrcamentodoCanalporFamilia, OrcaSegFamilia.ToList(), OrcaSegFamilia.First().Familia.Id, canalId); } }
public void Criar(OrcamentoPorCanal mOrcamentodoCanal, Model.OrcamentodaUnidade mOrcamentodaUnidade, List <Model.OrcamentoDetalhado> lstOrcamentoDetalhado) { OrcamentodoCanalporSegmento mOrcamentodoCanalporSegmento; var lstOrcamentoporSegmento = (from x in lstOrcamentoDetalhado group x by string.Format("{0}", x.Segmento.Id)); foreach (var OrcaSegmento in lstOrcamentoporSegmento) { mOrcamentodoCanalporSegmento = RepositoryService.OrcamentodoCanalporSegmento.ObterPor(mOrcamentodoCanal.ID.Value, OrcaSegmento.First().Canal.Id, mOrcamentodoCanal.Trimestre.Value, OrcaSegmento.First().Segmento.Id); if (mOrcamentodoCanalporSegmento == null) { mOrcamentodoCanalporSegmento = new OrcamentodoCanalporSegmento(RepositoryService.NomeDaOrganizacao, RepositoryService.IsOffline, RepositoryService.Provider); mOrcamentodoCanalporSegmento.ID = Guid.NewGuid(); mOrcamentodoCanalporSegmento.Nome = mOrcamentodoCanal.Nome + " - " + OrcaSegmento.First().Segmento.Name; mOrcamentodoCanalporSegmento.UnidadedeNegocio = mOrcamentodoCanal.UnidadedeNegocio; mOrcamentodoCanalporSegmento.Ano = mOrcamentodaUnidade.Ano; mOrcamentodoCanalporSegmento.Canal = new Lookup(OrcaSegmento.First().Canal.Id, SDKore.Crm.Util.Utility.GetEntityName <Model.Conta>()); mOrcamentodoCanalporSegmento.Trimestre = mOrcamentodoCanal.Trimestre; mOrcamentodoCanalporSegmento.Segmento = new Lookup(OrcaSegmento.First().Segmento.Id, SDKore.Crm.Util.Utility.GetEntityName <Model.Segmento>()); mOrcamentodoCanalporSegmento.OrcamentodoCanal = new Lookup(mOrcamentodoCanal.ID.Value, SDKore.Crm.Util.Utility.GetEntityName <Model.OrcamentoPorCanal>()); RepositoryService.OrcamentodoCanalporSegmento.Create(mOrcamentodoCanalporSegmento); } ServiceOrcamentodoCanalporFamilia.Criar(mOrcamentodoCanalporSegmento, OrcaSegmento.ToList(), OrcaSegmento.First().Segmento.Id, OrcaSegmento.First().Canal.Id); } }
public void RetornoDWCanalSegmento() { List <OrcamentodaUnidade> lstOrcamentodaUnidade = RepositoryService.OrcamentodaUnidade.ListarOrcamentos(DateTime.Now.Date.Year); if (lstOrcamentodaUnidade.Count == 0) { return; } DataTable dtOrcamentoCanalSeg = RepositoryService.OrcamentodoCanalporSegmento.ListarCanalSegmentoDW(DateTime.Now.Date.Year, Helper.TrimestreAtual()[1], lstOrcamentodaUnidade); #region Atualiza Orçamentos Trimestre foreach (DataRow item in dtOrcamentoCanalSeg.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) { OrcamentodoCanalporSegmento mOrcamentodoCanalporSegmento = RepositoryService.OrcamentodoCanalporSegmento.ObterPor(mUnidadeNegocio.ID.Value, Convert.ToInt32(item["cd_ano"].ToString()), Helper.TrimestreAtual()[1], mConta.ID.Value, mSegmento.ID.Value); if (mOrcamentodoCanalporSegmento != null) { mOrcamentodoCanalporSegmento.OrcamentoRealizado = decimal.Parse(item["vlr"].ToString()); RepositoryService.OrcamentodoCanalporSegmento.Update(mOrcamentodoCanalporSegmento); } } } #endregion }
public void OldCriar(Model.OrcamentodaUnidadeporTrimestre mOrcamentodaUnidadeporTrimestre, Model.OrcamentodaUnidade mOrcamentodaUnidade, List <Model.OrcamentoDetalhado> lstOrcamentoDetalhado, Guid canalid, Guid orcamentodocanalId) { var lstOrcamentoporSegmento = (from x in lstOrcamentoDetalhado where x.Canal.Id == canalid group x by string.Format("{0}", x.Segmento.Id)); foreach (var OrcaSegmento in lstOrcamentoporSegmento) { OrcamentodoCanalporSegmento mOrcamentodoCanalporSegmento = new OrcamentodoCanalporSegmento(RepositoryService.NomeDaOrganizacao, RepositoryService.IsOffline, RepositoryService.Provider); mOrcamentodoCanalporSegmento.ID = Guid.NewGuid(); mOrcamentodoCanalporSegmento.Nome = mOrcamentodaUnidadeporTrimestre.Nome + " - " + OrcaSegmento.First().Segmento.Name; mOrcamentodoCanalporSegmento.UnidadedeNegocio = mOrcamentodaUnidadeporTrimestre.UnidadedeNegocio; mOrcamentodoCanalporSegmento.Ano = mOrcamentodaUnidade.Ano; mOrcamentodoCanalporSegmento.Canal = new Lookup(OrcaSegmento.First().Canal.Id, SDKore.Crm.Util.Utility.GetEntityName <Model.Conta>()); mOrcamentodoCanalporSegmento.Trimestre = mOrcamentodaUnidadeporTrimestre.Trimestre; mOrcamentodoCanalporSegmento.Segmento = new Lookup(OrcaSegmento.First().Segmento.Id, SDKore.Crm.Util.Utility.GetEntityName <Model.Segmento>()); mOrcamentodoCanalporSegmento.OrcamentodoCanal = new Lookup(orcamentodocanalId, SDKore.Crm.Util.Utility.GetEntityName <Model.OrcamentodaUnidadeporTrimestre>()); RepositoryService.OrcamentodoCanalporSegmento.Create(mOrcamentodoCanalporSegmento); ServiceOrcamentodoCanalporFamilia.Criar(mOrcamentodoCanalporSegmento, lstOrcamentoDetalhado, OrcaSegmento.First().Segmento.Id, OrcaSegmento.First().Canal.Id); } }