Example #1
0
        /// <inheritdoc />
        public ConsultaSessaoResposta(string retorno, Encoding encoding) : base(retorno, encoding)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (CodigoDeRetorno)
            {
            case 6000:
                if (RetornoLst.Count < 6)
                {
                    return;
                }

                using (var stream = new MemoryStream(Convert.FromBase64String(RetornoLst[6])))
                    Venda = CFe.Load(stream, encoding);

                QRCode = $"{RetornoLst[8].OnlyNumbers()}|{RetornoLst[7]}|{RetornoLst[9]}|{RetornoLst[10]}|{RetornoLst[11]}";
                break;

            case 7000:
                if (RetornoLst.Count < 6)
                {
                    return;
                }

                using (var stream = new MemoryStream(Convert.FromBase64String(RetornoLst[6])))
                    Cancelamento = CFeCanc.Load(stream, encoding);

                QRCode = $"{RetornoLst[8].OnlyNumbers()}|{RetornoLst[7]}|{RetornoLst[9]}|{RetornoLst[10]}|{RetornoLst[11]}";
                break;
            }
        }
Example #2
0
        public void ImprimirCancelamento(string xmlContent)
        {
            base.Imprimir(xmlContent);

            _CFeCanc = CFeCanc.Load(new MemoryStream(Encoding.UTF8.GetBytes(xmlContent)), Encoding.UTF8);

            #region Logotipo
            if (Logotipo != null)
            {
                if (TipoPapel == TipoPapel.Tp80mm)
                {
                    _Printer.AlignCenter();
                }

                _Printer.Image(Logotipo);
            }
            #endregion

            #region Dados do Emitente
            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.AlignCenter();
            }

            _Printer.BoldMode(PrinterModeState.On);
            _Printer.WriteLine((_CFeCanc.InfCFe.Emit.XFant.IsNotNull() ? _CFeCanc.InfCFe.Emit.XFant : _CFeCanc.InfCFe.Emit.XNome).LimitarString(ColunasNormal).RemoveAccent());

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.AlignLeft();
            }

            _Printer.BoldMode(PrinterModeState.Off);
            _Printer.WriteLine(_CFeCanc.InfCFe.Emit.XNome.LimitarString(ColunasNormal).RemoveAccent());

            _Printer.CondensedMode(PrinterModeState.On);
            _Printer.WriteLine(GereneHelpers.TextoEsquerda_Direita($"Cnpj: {_CFeCanc.InfCFe.Emit.CNPJ.FormatoCpfCnpj()}", $"I.E.: {_CFeCanc.InfCFe.Emit.IE}", ColunasCondensadas));

            _Printer.Write("End.: ");
            _Printer.WriteLine($"{_CFeCanc.InfCFe.Emit.EnderEmit.XLgr.RemoveAccent()},{_CFeCanc.InfCFe.Emit.EnderEmit.Nro.RemoveAccent()} {_CFeCanc.InfCFe.Emit.EnderEmit.XCpl.RemoveAccent()}");

            _Printer.Write("Bairro: ");
            _Printer.WriteLine($"{_CFeCanc.InfCFe.Emit.EnderEmit.XBairro.RemoveAccent()} - {_CFeCanc.InfCFe.Emit.EnderEmit.XMun.RemoveAccent()} - {_CFeCanc.InfCFe.Emit.EnderEmit.CEP.FormatoCep()}");

            _Printer.CondensedMode(PrinterModeState.Off);
            _Printer.CondensedMode(string.Empty.PadLeft(ColunasCondensadas, '-'));
            #endregion

            #region Número do extrato
            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.AlignCenter();
            }

            _Printer.BoldMode(PrinterModeState.On);
            _Printer.WriteLine($"Extrato No. {_CFeCanc.InfCFe.Ide.NCFe:D6}");
            _Printer.WriteLine($"CUPOM FISCAL ELETRONICO SAT");
            _Printer.WriteLine($"CANCELAMENTO");
            _Printer.BoldMode(PrinterModeState.Off);
            #endregion

            #region Homologação

            /*
             * if (_CFeCanc.InfCFe.Ide.TpAmb == ACBr.Net.DFe.Core.Common.DFeTipoAmbiente.Homologacao)
             * {
             *  _Printer.CondensedMode(string.Empty.PadLeft(ColunasCondensadas, '-'));
             *
             *  if (TipoPapel == TipoPapel.Tp80mm)
             *      _Printer.AlignCenter();
             *
             *  _Printer.BoldMode(PrinterModeState.On);
             *  _Printer.WriteLine("AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL");
             *  _Printer.BoldMode(PrinterModeState.Off);
             *  _Printer.CondensedMode(string.Empty.PadLeft(ColunasCondensadas, '-'));
             * }
             */
            #endregion

            #region Dados do cupom cancelado
            _Printer.CondensedMode(string.Empty.PadLeft(ColunasCondensadas, '-'));

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.AlignLeft();
            }

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.BoldMode("DADOS DO CUPOM FISCAL ELETRONICO CANCELADO");
            }
            else
            {
                _Printer.BoldMode("DADOS DO CUPOM FISCAL");
                _Printer.BoldMode("ELETRONICO CANCELADO");
            }

            _Printer.CondensedMode(PrinterModeState.On);

            _Printer.Write("CPF/CNPJ do Consumidor: ");
            _Printer.WriteLine(_CFeCanc.InfCFe.Dest?.CPF.IsNotNull() == true ? _CFeCanc.InfCFe.Dest.CPF.FormatoCpfCnpj() :
                               _CFeCanc.InfCFe.Dest?.CNPJ.IsNotNull() == true ? _CFeCanc.InfCFe.Dest.CNPJ.FormatoCpfCnpj() :
                               "000.000.000-00");
            _Printer.BoldMode(GereneHelpers.TextoEsquerda_Direita("Valor total:", _CFeCanc.InfCFe.Total.VCFe.ToString("C2", Cultura), ColunasCondensadas));

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.NewLine();
            }

            _Printer.CondensedMode(PrinterModeState.Off);

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.AlignCenter();
            }

            _Printer.WriteLine($"SAT No. {_CFeCanc.InfCFe.Ide.NSerieSAT:D9}");
            _Printer.WriteLine($"Data e Hora {_CFeCanc.InfCFe.Ide.DEmi:dd/MM/yyyy} {_CFeCanc.InfCFe.Ide.HEmi:HH:mm:ss}");

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.AlignLeft();
            }

            _Printer.CondensedMode(PrinterModeState.On);
            #region Chave de Acesso
            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.NewLine();
            }

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.AlignCenter();
            }

            string chave = Regex.Replace(_CFeCanc.InfCFe.ChCanc.OnlyNumber(), ".{4}", "$0 ");

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.BoldMode(chave);
            }
            else
            {
                _Printer.BoldMode(chave.Substring(0, 24).Trim());
                _Printer.BoldMode(chave.Substring(24).Trim());
            }

            _Printer.Code128(_CFeCanc.InfCFe.ChCanc.OnlyNumber().Substring(0, 24));
            _Printer.Code128(_CFeCanc.InfCFe.ChCanc.OnlyNumber().Substring(24));

            _Printer.NewLine();
            #endregion

            _Printer.CondensedMode(PrinterModeState.Off);

            #region QrCode
            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.AlignCenter();
            }

            string _qrCode = $"{_CFeCanc.InfCFe.ChCanc.OnlyNumber()}|" +
                             $"{_CFeCanc.InfCFe.Ide.DhEmissao:yyyyMMddHHmmss}|" +
                             $"{_CFeCanc.InfCFe.Ide.DhEmissao:0.00}|" +
                             $"{(_CFeCanc.InfCFe.Dest?.CNPJ.IsNotNull() == true ? _CFeCanc.InfCFe.Dest.CNPJ : _CFeCanc.InfCFe.Dest.CPF)}|" +
                             $"{_CFeCanc.InfCFe.Ide.AssinaturaQrcode}";

            _Printer.QrCode(_qrCode, TipoPapel == TipoPapel.Tp80mm ? QrCodeSize.Size1 : QrCodeSize.Size0);

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.NewLine();
            }
            #endregion

            #endregion

            #region Dados do cupom cancelado
            _Printer.CondensedMode(string.Empty.PadLeft(ColunasCondensadas, '-'));

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.AlignLeft();
            }

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.BoldMode("DADOS DO CUPOM FISCAL ELETRONICO DE CANCELAMENTO");
            }
            else
            {
                _Printer.BoldMode("DADOS DO CUPOM FISCAL");
                _Printer.BoldMode("ELETRONICO DE CANCELAMENTO");
            }

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.AlignCenter();
            }

            _Printer.WriteLine($"SAT No. {_CFeCanc.InfCFe.Ide.NSerieSAT:D9}");
            _Printer.WriteLine($"Data e Hora {_CFeCanc.InfCFe.Ide.DEmi:dd/MM/yyyy} {_CFeCanc.InfCFe.Ide.HEmi:HH:mm:ss}");

            #region Chave de Acesso
            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.AlignCenter();
            }

            _Printer.CondensedMode(PrinterModeState.On);

            string chave2 = Regex.Replace(_CFeCanc.InfCFe.Id.OnlyNumber(), ".{4}", "$0 ");

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.BoldMode(chave2);
            }
            else
            {
                _Printer.BoldMode(chave2.Substring(0, 24).Trim());
                _Printer.BoldMode(chave2.Substring(24).Trim());
            }

            _Printer.Code128(_CFeCanc.InfCFe.Id.OnlyNumber().Substring(0, 24));
            _Printer.Code128(_CFeCanc.InfCFe.Id.OnlyNumber().Substring(24));

            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.NewLine();
            }
            #endregion

            _Printer.CondensedMode(PrinterModeState.Off);

            #region QrCode
            if (TipoPapel == TipoPapel.Tp80mm)
            {
                _Printer.AlignCenter();
            }

            string _qrCodeCancel = $"{_CFeCanc.InfCFe.Id.OnlyNumber()}|" +
                                   $"{_CFeCanc.InfCFe.Ide.DhEmissao:yyyyMMddHHmmss}|" +
                                   $"{_CFeCanc.InfCFe.Total.VCFe:0.00}|" +
                                   $"{(_CFeCanc.InfCFe.Dest?.CNPJ.IsNotNull() == true ? _CFeCanc.InfCFe.Dest.CNPJ : _CFeCanc.InfCFe.Dest.CPF)}|" +
                                   $"{_CFeCanc.InfCFe.Ide.AssinaturaQrcode}";

            _Printer.QrCode(_qrCodeCancel, TipoPapel == TipoPapel.Tp80mm ? QrCodeSize.Size1 : QrCodeSize.Size0);

            _Printer.NewLine();
            #endregion

            #endregion

            _Printer.CondensedMode(string.Empty.PadLeft(ColunasCondensadas, '-'));

            #region Desenvolvedor
            if (Desenvolvedor.IsNotNull())
            {
                if (TipoPapel == TipoPapel.Tp80mm)
                {
                    _Printer.AlignRight();
                }

                _Printer.CondensedMode(PrinterModeState.On);
                _Printer.CondensedMode(Desenvolvedor);
                _Printer.CondensedMode(PrinterModeState.Off);
            }
            #endregion

            if (CortarPapel)
            {
                _Printer.PartialPaperCut();
            }

            _Printer.PrintDocument();
        }
Example #3
0
        /// <summary>
        ///     Inicializar uma nova instancida da classe <see cref="CancelamentoSatResposta" />.
        /// </summary>
        public CancelamentoSatResposta(string retorno, Encoding encoding) : base(retorno, encoding)
        {
            if (CodigoDeRetorno != 7000 || RetornoLst.Count < 6)
            {
                return;
            }

            using (var stream = new MemoryStream(Convert.FromBase64String(RetornoLst[6]))) Cancelamento = CFeCanc.Load(stream, encoding);

            QRCode = $"{RetornoLst[8].OnlyNumbers()}|{RetornoLst[7]}|{RetornoLst[9]}|{RetornoLst[10]}|{RetornoLst[11]}";
        }
Example #4
0
        public void ImprimirCancelamento(string xmlContent)
        {
            _CFeCanc = CFeCanc.Load(new MemoryStream(Encoding.UTF8.GetBytes(xmlContent)), Encoding.UTF8);

            _Printer = new Printer(NomeImpressora, TipoImpressora);

            #region Logotipo
            if (Logotipo != null)
            {
                //Impressão do logotipo ainda não implementada
            }
            #endregion

            #region Dados do Emitente
            _Printer.AlignCenter();
            _Printer.BoldMode(PrinterModeState.On);
            _Printer.Append((_CFeCanc.InfCFe.Emit.XFant.IsNotNull() ? _CFeCanc.InfCFe.Emit.XFant : _CFeCanc.InfCFe.Emit.XNome).LimitarString(_Printer.ColsNomal).RemoveAccent());

            _Printer.AlignLeft();
            _Printer.BoldMode(PrinterModeState.Off);
            _Printer.Append(_CFeCanc.InfCFe.Emit.XNome.LimitarString(_Printer.ColsNomal).RemoveAccent());

            _Printer.CondensedMode(PrinterModeState.On);
            _Printer.Append(GereneHelpers.TextoEsquerda_Direita($"Cnpj: {_CFeCanc.InfCFe.Emit.CNPJ.FormatoCpfCnpj()}", $"I.E.: {_CFeCanc.InfCFe.Emit.IE}", _Printer.ColsCondensed));

            _Printer.AppendWithoutLf("End.: ");
            _Printer.Append($"{_CFeCanc.InfCFe.Emit.EnderEmit.XLgr.RemoveAccent()},{_CFeCanc.InfCFe.Emit.EnderEmit.Nro.RemoveAccent()} {_CFeCanc.InfCFe.Emit.EnderEmit.XCpl.RemoveAccent()}");

            _Printer.AppendWithoutLf("Bairro: ");
            _Printer.Append($"{_CFeCanc.InfCFe.Emit.EnderEmit.XBairro.RemoveAccent()} - {_CFeCanc.InfCFe.Emit.EnderEmit.XMun.RemoveAccent()} - {_CFeCanc.InfCFe.Emit.EnderEmit.CEP.FormatoCep()}");

            _Printer.CondensedMode(PrinterModeState.Off);
            _Printer.Separator();
            #endregion

            #region Número do extrato
            _Printer.AlignCenter();
            _Printer.BoldMode(PrinterModeState.On);
            _Printer.Append($"Extrato No. {_CFeCanc.InfCFe.Ide.NCFe:D6}");
            _Printer.Append($"CUPOM FISCAL ELETRONICO SAT");
            _Printer.Append($"CANCELAMENTO");
            _Printer.BoldMode(PrinterModeState.Off);
            #endregion

            #region Homologação

            /*
             * if (_CFeCanc.InfCFe.Ide.TpAmb == ACBr.Net.DFe.Core.Common.DFeTipoAmbiente.Homologacao)
             * {
             *  _Printer.Separator();
             *  _Printer.AlignCenter();
             *  _Printer.BoldMode(PrinterModeState.On);
             *  _Printer.Append("AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL");
             *  _Printer.BoldMode(PrinterModeState.Off);
             *  _Printer.Separator();
             * }
             */
            #endregion

            #region Dados do cupom cancelado
            _Printer.Separator();

            _Printer.AlignLeft();
            _Printer.BoldMode("DADOS DO CUPOM FISCAL ELETRONICO CANCELADO");

            _Printer.CondensedMode(PrinterModeState.On);

            _Printer.AppendWithoutLf("CPF/CNPJ do Consumidor: ");
            _Printer.Append(_CFeCanc.InfCFe.Dest?.CPF.IsNotNull() == true ? _CFeCanc.InfCFe.Dest.CPF.FormatoCpfCnpj() :
                            _CFeCanc.InfCFe.Dest?.CNPJ.IsNotNull() == true ? _CFeCanc.InfCFe.Dest.CNPJ.FormatoCpfCnpj() :
                            "000.000.000-00");
            _Printer.BoldMode(GereneHelpers.TextoEsquerda_Direita("Valor total:", _CFeCanc.InfCFe.Total.VCFe.ToString("C2", _Cultura), _Printer.ColsCondensed));

            _Printer.NewLine();

            _Printer.CondensedMode(PrinterModeState.Off);

            _Printer.AlignCenter();
            _Printer.Append($"SAT No. {_CFeCanc.InfCFe.Ide.NSerieSAT:D9}");
            _Printer.Append($"Data e Hora {_CFeCanc.InfCFe.Ide.DEmi:dd/MM/yyyy} {_CFeCanc.InfCFe.Ide.HEmi:HH:mm:ss}");
            _Printer.AlignLeft();

            _Printer.CondensedMode(PrinterModeState.On);
            #region Chave de Acesso
            _Printer.NewLine();
            _Printer.AlignCenter();
            _Printer.BoldMode(Regex.Replace(_CFeCanc.InfCFe.ChCanc.OnlyNumber(), ".{4}", "$0 "));

            _Printer.Code128(_CFeCanc.InfCFe.ChCanc.OnlyNumber().Substring(0, 22));
            _Printer.Code128(_CFeCanc.InfCFe.ChCanc.OnlyNumber().Substring(22));

            _Printer.NewLine();
            #endregion

            _Printer.CondensedMode(PrinterModeState.Off);

            #region QrCode
            _Printer.AlignCenter();
            string _qrCode = $"{_CFeCanc.InfCFe.ChCanc.OnlyNumber()}|" +
                             $"{_CFeCanc.InfCFe.Ide.DhEmissao:yyyyMMddHHmmss}|" +
                             $"{_CFeCanc.InfCFe.Ide.DhEmissao:0.00}|" +
                             $"{(_CFeCanc.InfCFe.Dest?.CNPJ.IsNotNull() == true ? _CFeCanc.InfCFe.Dest.CNPJ : _CFeCanc.InfCFe.Dest.CPF)}|" +
                             $"{_CFeCanc.InfCFe.Ide.AssinaturaQrcode}";

            _Printer.QrCode(_qrCode, QrCodeSize.Size1);

            _Printer.NewLine();
            #endregion

            #endregion

            #region Dados do cupom cancelado
            _Printer.Separator();

            _Printer.AlignLeft();
            _Printer.BoldMode("DADOS DO CUPOM FISCAL ELETRONICO DE CANCELAMENTO");

            _Printer.AlignCenter();
            _Printer.Append($"SAT No. {_CFeCanc.InfCFe.Ide.NSerieSAT:D9}");
            _Printer.Append($"Data e Hora {_CFeCanc.InfCFe.Ide.DEmi:dd/MM/yyyy} {_CFeCanc.InfCFe.Ide.HEmi:HH:mm:ss}");

            #region Chave de Acesso
            _Printer.AlignCenter();
            _Printer.CondensedMode(PrinterModeState.On);
            _Printer.BoldMode(Regex.Replace(_CFeCanc.InfCFe.Id.OnlyNumber(), ".{4}", "$0 "));

            _Printer.Code128(_CFeCanc.InfCFe.Id.OnlyNumber().Substring(0, 22));
            _Printer.Code128(_CFeCanc.InfCFe.Id.OnlyNumber().Substring(22));

            _Printer.NewLine();
            #endregion

            _Printer.CondensedMode(PrinterModeState.Off);

            #region QrCode
            _Printer.AlignCenter();
            string _qrCodeCancel = $"{_CFeCanc.InfCFe.Id.OnlyNumber()}|" +
                                   $"{_CFeCanc.InfCFe.Ide.DhEmissao:yyyyMMddHHmmss}|" +
                                   $"{_CFeCanc.InfCFe.Total.VCFe:0.00}|" +
                                   $"{(_CFeCanc.InfCFe.Dest?.CNPJ.IsNotNull() == true ? _CFeCanc.InfCFe.Dest.CNPJ : _CFeCanc.InfCFe.Dest.CPF)}|" +
                                   $"{_CFeCanc.InfCFe.Ide.AssinaturaQrcode}";

            _Printer.QrCode(_qrCode, QrCodeSize.Size1);

            _Printer.NewLine();
            #endregion

            #endregion

            _Printer.Separator();
            #endregion

            if (CortarPapel)
            {
                _Printer.PartialPaperCut();
            }

            _Printer.PrintDocument();
        }