public IActionResult ObterProd([FromBody] Dictionary <string, string> dados)
        {
            CamadaNegocio.ProdIndustCamadaNegocio pcn = new CamadaNegocio.ProdIndustCamadaNegocio();
            string cod_ref = dados["cod_ref"];

            Models.ProdutoIndust prodemp = pcn.ObterProd(cod_ref);
            return(Json(new
            {
                prodemp
            }));
        }
Example #2
0
        private (bool, string, int, string) ProcessImport(XmlDocument xmlDoc)
        {
            CamadaNegocio.ProdIndustCamadaNegocio picn = new CamadaNegocio.ProdIndustCamadaNegocio();
            List <Models.ProdutoIndust>           pi   = new List <Models.ProdutoIndust>();

            CamadaNegocio.NotaCamadaNegocio ncn = new CamadaNegocio.NotaCamadaNegocio();
            Models.NotaFiscal notamodelo        = new Models.NotaFiscal();

            CamadaNegocio.ItemNotaCamadaNegocio incn = new CamadaNegocio.ItemNotaCamadaNegocio();
            Models.ItemNota itemnota;

            //dados para rastreamento
            List <int>    rastroCod  = new List <int>();
            List <string> rastroLote = new List <string>();

            XmlNodeList xnList, xnList2;

            bool operacao, entrou;

            entrou = operacao = false;
            string msg      = "Produtos sem Cadastro - Códigos: ";
            string cnpjdist = "";

            xnList          = xmlDoc.GetElementsByTagName("prod");
            notamodelo.Tipo = HttpContext.User.Claims.ToList()[1].Value;
            for (int i = 0; i < xnList.Count; i++)
            {
                string id_prod = xnList[i]["cProd"].InnerText;

                pi.Add(picn.ObterProd(id_prod));
                if (pi[i] == null)
                {
                    entrou = true;
                    msg   += id_prod + ", ";
                }
            }
            msg  = msg.Remove(msg.Length - 2);
            msg += ".";

            //todos produtos cadastrados
            if (!entrou)
            {
                //dados nota fiscal
                notamodelo.Cod_indust = Convert.ToInt32(HttpContext.User.Claims.ToList()[3].Value);

                xnList           = xmlDoc.GetElementsByTagName("infProt");
                notamodelo.Chave = xnList[0]["chNFe"].InnerText;

                xnList            = xmlDoc.GetElementsByTagName("ide");
                notamodelo.Serie  = Convert.ToInt32(xnList[0]["serie"].InnerText);
                notamodelo.Numero = Convert.ToInt32(xnList[0]["nNF"].InnerText);
                notamodelo.Data   = Convert.ToDateTime(xnList[0]["dhEmi"].InnerText);

                xnList = xmlDoc.GetElementsByTagName("fat");
                notamodelo.Valor_nf = GetDouble(xnList[0]["vLiq"].InnerText, 0d);

                operacao = ncn.Criar(notamodelo);

                if (operacao)
                {
                    xnList  = xmlDoc.GetElementsByTagName("prod");
                    xnList2 = xmlDoc.GetElementsByTagName("rastro");

                    for (int i = 0; i < xnList.Count; i++)
                    {
                        itemnota         = new Models.ItemNota();
                        itemnota.Id_nota = notamodelo.Id;
                        itemnota.Id_prod = pi[i].Id;
                        itemnota.Lote    = xnList2[i]["nLote"].InnerText;
                        string qtdeaux = xnList[i]["qTrib"].InnerText;
                        string qtde    = "";
                        for (int j = 0; qtdeaux[j] != '.'; j++)
                        {
                            qtde += qtdeaux[j];
                        }

                        itemnota.Qtde = Convert.ToInt32(qtde);

                        itemnota.Valor_unit = GetDouble(xnList[i]["vUnTrib"].InnerText, 0d);

                        rastroCod.Add(itemnota.Id_prod);
                        rastroLote.Add(itemnota.Lote);
                        operacao = incn.Criar(itemnota);
                    }
                }
                else
                {
                    return(operacao, "Problemas com os dados da Nota Fiscal!", notamodelo.Id, cnpjdist);
                }
            }
            if (!entrou)
            {
                xnList   = xmlDoc.GetElementsByTagName("dest");
                cnpjdist = xnList[0]["CNPJ"].InnerText;

                //salvar o rastreio
                CamadaNegocio.RastroCamadaNegocio rcn = new CamadaNegocio.RastroCamadaNegocio();
                rcn.Criar(rastroCod, rastroLote, cnpjdist, notamodelo.Cod_indust);

                return(operacao, "Dados Importados!", notamodelo.Id, cnpjdist);
            }
            else
            {
                return(false, msg, 0, cnpjdist);
            }
        }