Пример #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);
            }

        }
        private string GeraChaveDadosNFe(NFe_HLP objNFe)
        {
            string scUF = "";
            string stpEmis = "";
            string sCNPJ = "";
            string svNF = "";
            string sICMSp = "0";
            string sICMSs = "0";
            string sDD = "";
            string sDV = "";
            belUF objbelUF = new belUF();

            scUF = objbelUF.RetornaCUF(objNFe.enderDest_UF);
            stpEmis = objNFe.tpEmis;
            sCNPJ = objNFe.dest_CPF_CNPJ;
            svNF = objNFe.ICMSTot_vNF.Replace(",", "").PadLeft(14, '0');
            sDD = Convert.ToDateTime(objNFe.ide_dEmi).Day.ToString();


            if (objNFe.ICMSTot_vST != "0,00")
                sICMSs = "1";
            else
                sICMSs = "2";


            if (objNFe.ICMSTot_vICMS != "0,00")
                sICMSs = "1";
            else
                sICMSs = "2";

            string sDadosNfe = scUF + stpEmis + sCNPJ + svNF + sICMSp + sICMSs + sDD;
            string sDig = CalculaDig11(sDadosNfe).ToString();
            return (sDadosNfe + sDig).Trim();
        }