Пример #1
0
        public void AtualizaPorNcm(params string[] ncm)
        {
            if (ncm == null || ncm.Length == 0)
            {
                return;
            }

            lock (syncRoot)
            {
                List <string> naoBuscar = ExecuteMultipleScalar <string>("select ncm from imposto_ncm where ncm in ('" +
                                                                         String.Join("','", ncm) + "')");

                List <string> buscar = new List <string>(ncm);
                foreach (string nao in naoBuscar)
                {
                    buscar.Remove(nao);
                }

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

                var retorno = new WebGlass.WebService.ImpostoTotal.ImpostoTotal().ObtemTabelaDados(buscar.ToArray());

                foreach (var item in retorno)
                {
                    Insert(new ImpostoNcm()
                    {
                        Ncm = item.Ncm,
                        AliquotaNacional   = item.AliquotaNacional,
                        AliquotaImportacao = item.AliquotaImportacao
                    });
                }
            }
        }
Пример #2
0
        public void AtualizaPorNcm(params string[] ncm)
        {
            if (ncm == null || ncm.Length == 0)
            {
                return;
            }

            lock (syncRoot)
            {
                var naoBuscar = new GDA.Sql.Query(string.Format("ncm in ('{0}')", String.Join("','", ncm))).ToList <ImpostoNcmUF>();

                var buscar = new List <string>(ncm);
                foreach (string nao in naoBuscar.Select(f => f.Ncm))
                {
                    buscar.Remove(nao);
                }

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

                try
                {
                    var instancia = new WebGlass.WebService.ImpostoTotal.ImpostoTotal();

                    //var naoBuscar = ExecuteMultipleScalar<string>("select ncm from imposto_ncm where ncm in ('" +
                    //    String.Join("','", ncm) + "')");

                    var ncmAtualizar = naoBuscar.Where(f => f.VigenciaFim.GetValueOrDefault() < DateTime.Now);

                    var versao = instancia.ObtemVersaoNCM(Glass.Data.Helper.UserInfo.GetUserInfo.UfLoja).Versao;

                    var retorno = new WebGlass.WebService.ImpostoTotal.ImpostoTotal()
                                  .ObtemTabelaDadosNCMUf(buscar.ToArray(), Glass.Data.Helper.UserInfo.GetUserInfo.UfLoja);

                    foreach (var item in retorno)
                    {
                        Insert
                            (new ImpostoNcmUF()
                        {
                            Ncm = item.Ncm,
                            AliquotaNacional   = item.AliquotaNacional,
                            AliquotaImportacao = item.AliquotaImportacao,
                            AliquotaEstadual   = item.AliquotaEstadual,
                            AliquotaMunicipal  = item.AliquotaMunicipal,
                            Versao             = versao,
                            VigenciaInicio     = item.VigenciaInicio,
                            VigenciaFim        = item.VigenciaFim,
                            UF    = item.UF,
                            Fonte = item.Fonte
                        });
                    }

                    foreach (var item in ncmAtualizar)
                    {
                        item.Versao = versao;
                        ImpostoNcmUFDAO.Instance.Update(item);
                    }
                }
                catch
                {
                    // ignored
                }
            }
        }