Ejemplo n.º 1
0
        private void SalvarAlteracao()
        {
            belInfNFe nota = bsNotas.Current as belInfNFe;
            try
            {
                #region IDE


                //nota.ide.Cuf = txtUF.Text;
                //nota.ide.Cnf = txtSeq.Text;
                //nota.ide.Natop = txtNatOp.Text;
                //nota.ide.Indpag = Convert.ToString(cbxIndPag.SelectedIndex).Trim();
                //nota.ide.Mod = txtMod.Text.Trim();
                //nota.ide.Serie = txtSerie.Text.Trim();
                //nota.ide.Nnf = txtNNF.Text.Trim();
                //nota.ide.Demi = Convert.ToDateTime(mtbDEmi.Text);
                //nota.ide.Dsaient = Convert.ToDateTime(mtbDSaiEnt.Text);
                //nota.ide.Tpnf = Convert.ToString(cbxTpNF.SelectedIndex);
                //nota.ide.Cmunfg = txtCMunFG.Text.Trim();
                //nota.ide.Tpimp = Convert.ToString((int)cbxtpImp.SelectedIndex + 1);
                //nota.ide.Tpemis = Convert.ToString((int)cbcxTpEmis.SelectedIndex + 1);
                //nota.ide.Cdv = txtCDV.Text.Trim();
                //nota.ide.Tpamb = Convert.ToString((int)cbxTpAmb.SelectedIndex + 1);
                nota.ide.Finnfe = Convert.ToString((int)cbxFinNFe.SelectedIndex + 1);
                //nota.ide.Procemi = txtProcEmi.Text.Trim();
                //nota.ide.Verproc = txtVerProc.Text.Trim();
                if (bsNFreferenciadas.Count > 0) // 25360
                {
                    List<belNFref> lObjNFref = new List<belNFref>();

                    for (int i = 0; i < bsNFreferenciadas.Count; i++)
                    {
                        lObjNFref.Add((belNFref)bsNFreferenciadas[i]);
                        if (lObjNFref[i].cUF != null)
                        {
                            if (!Util.IsNumeric(lObjNFref[i].cUF))
                            {
                                belUF objuf = new belUF();
                                lObjNFref[i].cUF = objuf.RetornaCUF((lObjNFref[i].cUF));
                                lObjNFref[i].CNPJ = (lObjNFref[i].CNPJ).Replace(",", "").Replace("/", "").Replace("-", "");
                                lObjNFref[i].nNF = (Convert.ToInt32(lObjNFref[i].nNF)).ToString();
                            }
                        }

                    }
                    nota.ide.belNFref = lObjNFref;
                }
                nota.ide.HSaiEnt = dtpHSaiEnt.Value;

                #endregion

                #region Emitente

                if (cbxPessoaEmit.SelectedIndex == 0)
                {
                    nota.emit.Cpf = mtbCpfCnpjEmit.Text;
                }
                else
                {
                    nota.emit.Cnpj = mtbCpfCnpjEmit.Text;
                }
                nota.emit.Xnome = txtXNomeEmit.Text.Trim();
                nota.emit.Xfant = txtXFantEmit.Text.Trim();
                nota.emit.Ie = txtIEEmit.Text.Trim();
                nota.emit.Iest = txtIESTEmit.Text.Trim();
                nota.emit.Im = txtIM.Text.Trim();
                nota.emit.Cnae = txtCNAE.Text;

                //Endereço

                nota.emit.Xlgr = txtEnderEmitXlgr.Text.Trim();
                nota.emit.Nro = txtEnderEmitNum.Text.Trim();
                if (txtEnderEmitCompl.Text != "")
                {
                    nota.emit.Xcpl = txtEnderEmitCompl.Text.Trim();
                }
                nota.emit.Xbairro = txtEnderEmitXbairro.Text.Trim();
                nota.emit.Cmun = txtEnderEmitCmun.Text.Trim();
                nota.emit.Xmun = txtEnderEmitXmun.Text.Trim();
                nota.emit.Uf = txtEnderEmitUF.Text.Trim();
                nota.emit.Cpais = txtEnderEmitCpais.Text.Trim();
                nota.emit.Xpais = txtEnderEmitXpais.Text.Trim();
                nota.emit.Cep = mtbEnderEmitCep.Text.Trim();
                nota.emit.Fone = mtbEnderEmitFone.Text.Trim();

                switch (cmbCRT.SelectedIndex) // NFe_2.0
                {
                    case 0: nota.emit.CRT = 1;
                        break;

                    case 1: nota.emit.CRT = 2;
                        break;

                    case 2: nota.emit.CRT = 3;
                        break;
                }
                #endregion

                #region Destinatário
                if (mtbCpfCnpjDest.Mask.Equals("00.000.000/0000-00") || mtbCpfCnpjDest.Text.ToString().ToUpper().Equals("EXTERIOR"))
                {
                    nota.dest.Cnpj = mtbCpfCnpjDest.Text.Trim();
                }
                else
                {
                    nota.dest.Cpf = mtbCpfCnpjDest.Text.Trim();
                }

                nota.dest.Xnome = (Acesso.TP_AMB == 2 ? "NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL"
                    : txtXnomeDest.Text.Trim());

                nota.dest.Ie = txtIEDest.Text.Trim();
                nota.dest.Isuf = txtISUFDest.Text.Trim();

                //Endereço

                nota.dest.Xlgr = txtEnderDestXlgr.Text.Trim();
                nota.dest.Nro = txtEnderDestNro.Text.Trim();
                nota.dest.Xcpl = txtEnderDestCpl.Text.Trim(); //OS_26347
                nota.dest.Xbairro = txtEnderDestXbairro.Text.Trim();
                nota.dest.Cmun = txtEnderDestCmun.Text.Trim();
                nota.dest.Xmun = txtEnderDestXmun.Text.Trim();
                nota.dest.Uf = txtEnderDestUF.Text.Trim();
                nota.dest.Cpais = txtEnderDestCpais.Text.Trim();
                nota.dest.Xpais = txtEnderDestXpais.Text.Trim();
                nota.dest.Cep = mtbEnderDestCEP.Text.Trim();
                nota.dest.Fone = mtbEnderDestFone.Text.Trim();
                nota.dest.email = txtEmaildest.Text.Trim(); // NFe_2.0
                #endregion

                #region Endereço de Entrega
                if (txtEndEntXlgr.Text != "")
                {

                    if (mtbCpfCnpjDest.Mask.Equals("00.000.000/0000-00") || mtbCpfCnpjDest.Text.ToString().ToUpper().Equals("EXTERIOR"))
                    {
                        nota.endent.Cnpj = mtbCpfCnpjDest.Text.Trim();
                    }
                    else
                    {
                        nota.endent.Cpf = mtbCpfCnpjDest.Text.Trim();
                    }
                    nota.endent.Xlgr = txtEndEntXlgr.Text.Trim();
                    nota.endent.Nro = txtEndEntNro.Text.Trim();
                    nota.endent.Cmun = txtEndEntCmun.Text.Trim();
                    nota.endent.Xmun = txtEndEntXmun.Text.Trim();
                    nota.endent.Uf = txtEndEntUF.Text.Trim();
                    nota.endent.Xbairro = txtEndEntXbairro.Text.Trim(); //0S_25185
                    nota.endent.Xcpl = txtEndEntCpl.Text.Trim();//0S_25185
                }
                #endregion

                #region Detatalhes

                #endregion

                #region Totais
                nota.total.belIcmstot.Vbc = nudVBC.Value;
                nota.total.belIcmstot.Vicms = nudVICMS.Value;
                nota.total.belIcmstot.Vbcst = nudVBCICMSST.Value;
                nota.total.belIcmstot.Vst = nudVST.Value;
                nota.total.belIcmstot.Vprod = nudVProd.Value;
                nota.total.belIcmstot.Vfrete = nudVFrete.Value;
                nota.total.belIcmstot.Vseg = nudVSEG.Value;
                nota.total.belIcmstot.Vdesc = nudVDesc.Value;
                nota.total.belIcmstot.Vii = nudVII.Value;
                nota.total.belIcmstot.Vipi = nudVIPI.Value;
                nota.total.belIcmstot.Vpis = nudVPIS.Value;
                nota.total.belIcmstot.Vcofins = nudVCOFINS.Value;
                nota.total.belIcmstot.Voutro = nudVOutro.Value;
                nota.total.belIcmstot.Vnf = nudVNF.Value;
                nota.total.belIcmstot.vTotTrib = nudvTotTrib.Value;
                //Fim - Totais

                //ISSQNtot
                if (flpISSNQ.Enabled != false)
                {
                    nota.total.belIssqntot.Vserv = nudVServ.Value;
                    nota.total.belIssqntot.Vbc = nudVBCISS.Value;
                    nota.total.belIssqntot.Viss = nudVISS.Value;
                    nota.total.belIssqntot.Vpis = nudVPISISS.Value;
                    nota.total.belIssqntot.Vcofins = nudVCOFINSISS.Value;
                }
                //Fin - ISSQNtot;

                //retTrib
                if (flpRetTrib.Enabled != false)
                {
                    belRetTrib objRetTrib = new belRetTrib();

                    objRetTrib.Vretpis = nudVPISRet.Value;
                    objRetTrib.Vretcofins = nudVCOFINSRet.Value;
                    objRetTrib.Vretcsll = nudVCSLLRet.Value;
                    objRetTrib.Vbcretprev = nudVBCIRRFRet.Value;
                    objRetTrib.Virrf = nudVIRRFRet.Value;
                    objRetTrib.Vbcirrf = nudVBCIRRFRet.Value;
                    objRetTrib.Vbcretprev = nudVBCRetPrev.Value;
                    objRetTrib.Vretprev = nudVRetPrev.Value;
                }
                //Fim - retTrib
                #endregion

                #region Transporte
                switch (cbxModFrete.SelectedIndex) //Nfe_2.0
                {
                    case 0: nota.transp.Modfrete = "0";
                        break;

                    case 1: nota.transp.Modfrete = "1";
                        break;

                    case 2: nota.transp.Modfrete = "2";
                        break;

                    case 3: nota.transp.Modfrete = "9";
                        break;
                }
                //Transportadora               
                if (cbxPessoaTranp.SelectedIndex == 1)
                {
                    if (mtbCPJCNPJTransp.Text.Trim() != "")
                    {
                        nota.transp.belTransportadora.Cnpj = mtbCPJCNPJTransp.Text.Trim();
                    }
                }
                else
                {
                    if (mtbCPJCNPJTransp.Text.Trim() != "")
                    {
                        nota.transp.belTransportadora.Cpf = mtbCPJCNPJTransp.Text.Trim();
                    }
                }

                if (txtXnomeTransp.Text.Trim() != "")
                {
                    nota.transp.belTransportadora.Xnome = txtXnomeTransp.Text.Trim();
                }
                if (txtIETransp.Text.Trim() != "")
                {
                    nota.transp.belTransportadora.Ie = txtIETransp.Text.Trim();
                }
                if (txtEnderTransp.Text.Trim() != "")
                {
                    nota.transp.belTransportadora.Xender = txtEnderTransp.Text.Trim();
                }
                if (txtUFTransp.Text.Trim() != "")
                {
                    nota.transp.belTransportadora.Uf = txtUFTransp.Text.Trim();
                }
                if (txtXmunTransp.Text.Trim() != "")
                {
                    nota.transp.belTransportadora.Xmun = txtXmunTransp.Text.Trim();
                }
                //Fim - Transportadora

                //VeicTransp
                if (!mtbPlacaVeicTransp.Text.Trim().Equals(""))
                {
                    nota.transp.belVeicTransp.Placa = mtbPlacaVeicTransp.Text.Trim();
                    nota.transp.belVeicTransp.Uf = txtUFVeicTransp.Text.Trim();
                    if (txtRNTCVeicTransp.Text.Trim() != "")
                    {
                        nota.transp.belVeicTransp.Rntc = txtRNTCVeicTransp.Text.Trim();
                    }
                }
                //Fim -  VeicTransp

                //Reboque
                if (!mtbPlacaReboque.Text.Trim().Equals(""))
                {
                    nota.transp.belReboque.Placa = mtbPlacaReboque.Text.Trim();
                    nota.transp.belReboque.Uf = txtUFReboque.Text.Trim();
                    nota.transp.belReboque.Rntc = txtRNTCReboque.Text.Trim();
                }
                //Fim - Reboque 

                //RetTransp
                if (nudVServTransp.Value > 0)
                {
                    nota.transp.belRetTransp.Vbvret = nudVBCICMSTransp.Value;
                    nota.transp.belRetTransp.Vserv = nudVServTransp.Value;
                    nota.transp.belRetTransp.Picmsret = nudPICMSTRetTransp.Value;
                    nota.transp.belRetTransp.Vicmsret = nudVICMSRet.Value;
                    nota.transp.belRetTransp.Cmunfg = txtCmunFGTransp.Text.Trim();
                    nota.transp.belRetTransp.Cfop = txtCFOPTransp.Text.Trim();
                }
                //Fim - RetTransp

                if (nudQvol.Value > 0)
                {
                    nota.transp.belVol.Esp = txtEsp.Text.Trim();
                    nota.transp.belVol.Marca = txtMarca.Text.Trim();
                    if (txtNVol.Text != "")
                    {
                        nota.transp.belVol.Nvol = txtNVol.Text;
                    }
                    nota.transp.belVol.PesoB = nudPesoB.Value;
                    nota.transp.belVol.PesoL = nudPesoL.Value;
                    nota.transp.belVol.Qvol = nudQvol.Value;
                }
                #endregion

                #region Cobrança

                if (nota.cobr.Fat != null)
                {
                    nota.cobr.Fat.Nfat = txtNFat.Text.Trim();
                    nota.cobr.Fat.Vorig = nudVOrigFat.Value;
                    nota.cobr.Fat.Vdesc = nudVDescFat.Value;
                    nota.cobr.Fat.Vliq = nudVLiqFat.Value;
                    nota.cobr.Fat.belDup = bsDuplicatas.List as List<belDup>;
                }

                //if (bsDuplicatas.Count > 0)
                //{
                //    List<belDup> lObjDup = (List<belDup>)bsDuplicatas.List;

                //    for (int i = 0; i < dgvDup.RowCount; i++)
                //    {
                //        belDup objdup = new belDup();
                //        objdup.Ndup = Convert.ToString(dgvDup[0, i].Value);
                //        objdup.Dvenc = Convert.ToDateTime(dgvDup[1, i].Value);
                //        objdup.Vdup = Convert.ToDecimal(dgvDup[2, i].Value);
                //        lObjDup.Add(objdup);
                //    }
                //    nota.cobr.Fat.belDup = lObjDup;
                //}

                #endregion

                #region Inf Adicionais
                if (txtInfAdic.Text != "")
                {
                    nota.infAdic.Infcpl = null;
                    nota.infAdic.Infcpl = txtInfAdic.Text.Replace(Environment.NewLine, "").Trim().TrimEnd();
                }
                #endregion

                #region exporta
                if (txtUFembarque.Text != "")
                {
                    nota.exporta.Ufembarq = txtUFembarque.Text;
                }
                if (txtLocalEmbarque.Text != "")
                {
                    nota.exporta.Xlocembarq = txtLocalEmbarque.Text;
                }
                #endregion

            }
            catch (Exception ex)
            {
                new HLPexception(ex);
            }

        }
Ejemplo n.º 2
0
        public belTotal xmlBuscaTotal()
        {
            belTotal objTotal = new belTotal();
            XmlDocument xTotalN = new XmlDocument();

            try
            {
                switch (xDoc.GetElementsByTagName("total")[0].FirstChild.Name)
                {
                    case "ICMSTot":
                        {
                            xTotalN.LoadXml(xDoc.GetElementsByTagName("ICMSTot")[0].OuterXml);

                            belIcmstot objIcmsTot = new belIcmstot();
                            objIcmsTot.Vbc = Convert.ToDecimal(xTotalN.GetElementsByTagName("vBC")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Vicms = Convert.ToDecimal(xTotalN.GetElementsByTagName("vICMS")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Vbcst = Convert.ToDecimal(xTotalN.GetElementsByTagName("vBCST")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Vst = Convert.ToDecimal(xTotalN.GetElementsByTagName("vST")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Vprod = Convert.ToDecimal(xTotalN.GetElementsByTagName("vProd")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Vfrete = Convert.ToDecimal(xTotalN.GetElementsByTagName("vFrete")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Vseg = Convert.ToDecimal(xTotalN.GetElementsByTagName("vSeg")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Vdesc = Convert.ToDecimal(xTotalN.GetElementsByTagName("vDesc")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Vii = Convert.ToDecimal(xTotalN.GetElementsByTagName("vII")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Vipi = Convert.ToDecimal(xTotalN.GetElementsByTagName("vIPI")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Vpis = Convert.ToDecimal(xTotalN.GetElementsByTagName("vPIS")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Vcofins = Convert.ToDecimal(xTotalN.GetElementsByTagName("vCOFINS")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Voutro = Convert.ToDecimal(xTotalN.GetElementsByTagName("vOutro")[0].InnerText.ToString().Replace(".", ","));
                            objIcmsTot.Vnf = Convert.ToDecimal(xTotalN.GetElementsByTagName("vNF")[0].InnerText.ToString().Replace(".", ","));

                            objTotal.belIcmstot = objIcmsTot;
                            break;
                        }
                    case "ISSQNTot":
                        {
                            xTotalN.LoadXml(xDoc.GetElementsByTagName("ISSQNTot")[0].OuterXml);

                            belIssqntot objIssqntot = new belIssqntot();
                            objIssqntot.Vserv = Convert.ToDecimal(xTotalN.GetElementsByTagName("vServ")[0].InnerText.ToString().Replace(".", ","));
                            objIssqntot.Vbc = Convert.ToDecimal(xTotalN.GetElementsByTagName("vBC")[0].InnerText.ToString().Replace(".", ","));
                            objIssqntot.Viss = Convert.ToDecimal(xTotalN.GetElementsByTagName("vISS")[0].InnerText.ToString().Replace(".", ","));
                            objIssqntot.Vpis = Convert.ToDecimal(xTotalN.GetElementsByTagName("vPIS")[0].InnerText.ToString().Replace(".", ","));
                            objIssqntot.Vcofins = Convert.ToDecimal(xTotalN.GetElementsByTagName("vCONFIS")[0].InnerText.ToString().Replace(".", ","));

                            objTotal.belIssqntot = objIssqntot;

                            break;
                        }
                    case "retTrib":
                        {
                            xTotalN.LoadXml(xDoc.GetElementsByTagName("retTrib")[0].OuterXml);

                            belRetTrib objRettrib = new belRetTrib();
                            objRettrib.Vretpis = Convert.ToDecimal(xTotalN.GetElementsByTagName("vRetPIS")[0].InnerText.ToString().Replace(".", ","));
                            objRettrib.Vretcofins = Convert.ToDecimal(xTotalN.GetElementsByTagName("vRetCOFINS")[0].InnerText.ToString().Replace(".", ","));
                            objRettrib.Vretcsll = Convert.ToDecimal(xTotalN.GetElementsByTagName("vRetCSLL")[0].InnerText.ToString().Replace(".", ","));
                            objRettrib.Vbcirrf = Convert.ToDecimal(xTotalN.GetElementsByTagName("vBCIRRF")[0].InnerText.ToString().Replace(".", ","));
                            objRettrib.Virrf = Convert.ToDecimal(xTotalN.GetElementsByTagName("vIRRF")[0].InnerText.ToString().Replace(".", ","));
                            objRettrib.Vbcretprev = Convert.ToDecimal(xTotalN.GetElementsByTagName("vBCRetPrev")[0].InnerText.ToString().Replace(".", ","));
                            objRettrib.Vretprev = Convert.ToDecimal(xTotalN.GetElementsByTagName("vRetPrev")[0].InnerText.ToString().Replace(".", ","));

                            objTotal.belRetTrib = objRettrib;

                            break;
                        }
                }

            }
            catch (Exception ex)
            {

                throw new Exception(string.Format("Problemas lendo a Tag Total, Erro.: {0}",
                                                  ex.Message));
            }

            return objTotal;

        }