DatosFacturaCertificaVeriFactu.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using sage.ew.interficies;
10 using sage.ew.global;
11 using sage.ew.ewbase;
13 using sage.ew.objetos;
14 using sage.ew.functions;
15 using sage.ew.formul;
16 using sage.ew.docsven;
17 using sage.ew.docventatpv;
18 using sage.ew.db;
19 using sage.ew.images.Properties;
22 using System.Reflection;
23 using Sage.Reporting.Model;
24 using System.IO;
25 using Sage.ES.S50.Modelos.Forms;
26 
27 namespace sage.addons.factucert.Visual.UserControls
28 {
32  public partial class _oDatosFacturaCertificaVeriFactu : sage.ew.ewbase.UserControlConfig
33  {
34  #region PROPIEDADES PRIVADAS
35 
36  private string _QRVeriFac = string.Empty;
37 
38  #endregion PROPIEDADES PRIVADAS
39 
40 
41  #region PROPIEDADES PROTECTED
42  #endregion PROPIEDADES PROTECTED
43 
44 
45  #region PROPIEDADES INTERFICIE IUserControlFacturarAlbaranVenta
46 
50  public string _TituloPagina
51  {
52  get { return _cTituloPagina; }
53  set { _cTituloPagina = value; }
54  }
55  private string _cTituloPagina = "";
56 
60  public dynamic _Documento
61  {
62  get { return _oDocumento; }
63  set { _oDocumento = value; }
64  }
65  private dynamic _oDocumento = null;
66 
70  public DatosAdicionalesBase _DatosAdicionales
71  {
72  get { return loDatos; }
73  }
74  private DatosAdicionalesBase loDatos = null;
75 
76  #endregion PROPIEDADES INTERFICIE IUserControlFacturarAlbaranVenta
77 
78 
79  #region PROPIEDADES PUBLICAS
80 
84  public virtual bool _ReadOnly
85  {
86  get { return _lReadOnly; }
87  set { _lReadOnly = value; }
88  }
89  private bool _lReadOnly = false;
90 
91  #endregion PROPIEDADES PUBLICAS
92 
93 
94  #region CONSTRUCTORES
95 
100  {
101  InitializeComponent();
102  }
103 
104  #endregion CONSTRUCTORES
105 
106 
107  #region METODOS PRIVADOS
108 
112  private void ConfigurarControles()
113  {
114  ewcomboboxSistema.__SetEnumSource(typeof(SistemasFacturacionCertificada));
115  ewcomboboxTerritorio.__SetEnumSource(typeof(TerritoriosFactuCert));
116  btVerDocumento.Image = Resources.icon_eye16;
117 
118  DefinirTextos();
119  }
120 
121  private void DefinirTextos()
122  {
123  if (_Documento._TipoDocumento == eTipoDocumento.Ticket)
124  {
125  ewPanelTituloInformacionFactura._Titulo = "Información del ticket";
126  ewlabelFactura.Text = "Ticket:";
127  }
128  else if (_Documento is ewDocVentaFraAnulada)
129  {
130  ewPanelTituloInformacionFactura._Titulo = "Información de la factura modificada";
131  ewlabelFactura.Text = "Factura modificada:";
132  }
133  else
134  {
135  ewPanelTituloInformacionFactura._Titulo = "Información de la factura";
136  ewlabelFactura.Text = "Factura:";
137  }
138  }
139 
140 
144  private void EstadoControles()
145  {
146  txtFactura._ReadOnly = _lReadOnly;
147  ewtextboxFechaExpedicion.ReadOnly = _lReadOnly;
148  txtTerminal.ReadOnly = _lReadOnly;
149  txtCodigoSeguro.ReadOnly = _lReadOnly;
150  txtFichero.ReadOnly = _lReadOnly;
151 
152  ewcomboboxSistema.Enabled = !_lReadOnly;
153  ewcomboboxTerritorio.Enabled = !_lReadOnly;
154  }
155 
156 
157  private string GetEnumDescription(Enum value)
158  {
159  // Get the Description attribute value for the enum value
160  FieldInfo fi = value.GetType().GetField(value.ToString());
161  DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
162 
163  if (attributes.Length > 0)
164  return attributes[0].Description;
165  else
166  return value.ToString();
167  }
168 
169  private Image GenerarImagenQr(string tcText)
170  {
171  sage.ew.ewbase.Clases.GenCodigoBarras loGen = new ew.ewbase.Clases.GenCodigoBarras();
172  loGen._TipoCodigo = Sage.Reporting.Model.BarcodeSymbology.QR;
173  loGen._Texto = tcText;
174 
175  return loGen._Generar();
176  }
177 
178  private void lnkAccesoAEAT_Click(object sender, EventArgs e)
179  {
180  if (!string.IsNullOrWhiteSpace(_QRVeriFac))
181  System.Diagnostics.Process.Start(_QRVeriFac);
182 
183  }
184 
190  private void btVerDocumento_Click(object sender, EventArgs e)
191  {
192  string lcFile = txtFichero.Text;
193  if (string.IsNullOrWhiteSpace(txtFichero.Text))
194  {
195  FUNCTIONS._MessageBox("No existe fichero.", "Datos certificación", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
196  return;
197  }
198 
199  lcFile = Path.Combine(factucert.GetRutaXmlVeriFactu(), lcFile);
200  if (!File.Exists(lcFile))
201  {
202  FUNCTIONS._MessageBox("No se ha encontrado el fichero.", "Datos certificación", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
203  return;
204  }
205 
206  using (FormXMLRespuesta frmRespuesta = new FormXMLRespuesta())
207  {
208  frmRespuesta._FicheroXML = lcFile;
209  frmRespuesta.ShowDialog();
210  }
211  }
212 
213  #endregion METODOS PRIVADOS
214 
215 
216  #region METODOS PROTECTED
217 
221  protected override void OnCreateControl()
222  {
223  if (!IsDisposed && !Disposing && !this.Visible)
224  return;
225 
226  if (this.DesignMode)
227  return;
228 
229  base.OnCreateControl();
230 
231  this.ConfigurarControles();
232  this.EstadoControles();
233  }
234 
235  #endregion METODOS PROTECTED
236 
237 
238  #region METODOS PUBLICOS
239 
243  public override void _Binding()
244  {
245  loDatos = null;
246 
247  if (_Documento._TipoDocumento == eTipoDocumento.Factura && _oDocumento is ewDocVentaTPV)
248  {
249  loDatos = ((dynamic)_Documento._Addons["FACTUCERT"])._DatosAdicionalesFactura;
250  }
251  else
252  {
253  loDatos = ((dynamic)_Documento._Addons["FACTUCERT"])._DatosAdicionales;
254  }
255 
256  if (_Documento._TipoDocumento == eTipoDocumento.Ticket && _oDocumento is ewDocVentaTPV)
257  {
258  txtFactura._Numero = loDatos._Numero;
259  txtFactura._Letra = loDatos._Letra;
260  }
261  else
262  {
263  txtFactura.__BindearControl("_Factura", loDatos, "_Numero");
264  }
265 
266  ewtextboxFechaExpedicion.Text = loDatos._Hora != null ? loDatos._Hora + " " + loDatos._HusoHora : "";
267 
268  txtTerminal.DataBindings.Clear();
269  txtTerminal.__BindearControl("Text", loDatos, "_Terminal");
270 
271  txtCodigoSeguro.DataBindings.Clear();
272  txtCodigoSeguro.__BindearControl("Text", loDatos, "_CSV");
273 
274  txtFichero.DataBindings.Clear();
275  txtFichero.__BindearControl("Text", loDatos, "_FicheroXML");
276 
277  _QRVeriFac = loDatos._QRVERIFAC;
278 
279  //ewlabelIdentificativoTBai.DataBindings.Clear();
280  //ewlabelIdentificativoTBai.__BindearControl("Text", loDatos, "_TBAI");
281 
282  ewcomboboxSistema.DataBindings.Clear();
283  ewcomboboxSistema.__BindearControl("SelectedValue", loDatos, "_Sistema");
284 
285  ewcomboboxTerritorio.DataBindings.Clear();
286  ewcomboboxTerritorio.__BindearControl("SelectedValue", loDatos, "_Territorio");
287 
288  ewlblEstadoFactura.Text = $@"{(loDatos._Anulado == 0 ? "Certificada" : "Anulada")}\{GetEnumDescription((EstadoFactuCert)loDatos._Estado)}";
289 
290  // Task 188453: si territorio Guipuzcoa mostramos el entorno al que se ha enviado, el resto de Territorios Alava y Vizcaya envian a PROD
291  // incondicionalmente (salvo las excepciones obvias de modo debug y entradas al config.ini)
292  //
293  if (FACTUCERT._FactuCertConfig._Territorio == Convert.ToInt32(TerritoriosFactuCert.Guipuzcoa) ||
294  FACTUCERT._FactuCertConfig._Territorio == Convert.ToInt32(TerritoriosFactuCert.Alava))
295  {
296  this.ewlblEntornoEnvio.Visible = false;
297  if (loDatos._TipoCert == TipoDocCrearFactura.Certificada)
298  {
299  // Mostramos el entorno ya en el caso de que la factura esté certificada, aunque no esté enviada todavía.
300  // Recordar que cuando se certifica, en el XML que se genera se incluye información relacionada con el entorno para el que
301  // se va a enviar la factura, por tanto, si la factura está certificada se ha de mostrar la etiqueta de entorno de envío
302  // pues esa factura está certificada para ser enviada a ese entorno y no otro. No esperaremos a que la factura se envíe
303  // para mostrar esa información del entorno, solo que la factura esté certificada ya mostraremos el entorno.
304  //
305  // La etiqueta de entorno de envío solo se muestra para Guipuzcoa y Alava que son los territorios en los que se puede
306  // configurar el entorno de envío.
307  //
308  // Para Vizcaya no se puede configurar el entorno de envío, siempre será PROD y ya no se muestra, si la factura está
309  // certificada ya se sobreentiende que el entorno es PROD.
310 
311  // Para prevenir que en el campo TIPOENVIO haya algun valor que no se corresponda con los enumerados, p.e., 0.
312  //
313  int minEntorno = Convert.ToInt32(Enum.GetValues(typeof(TipoEnvio)).Cast<TipoEnvio>().First());
314  int maxEntorno = Convert.ToInt32(Enum.GetValues(typeof(TipoEnvio)).Cast<TipoEnvio>().Last());
315  if (loDatos._TipoEnvio >= minEntorno && loDatos._TipoEnvio <= maxEntorno)
316  {
317  this.ewlblEntornoEnvio.Visible = true;
318  ewlblEntornoEnvio.Text = $@"{GetEnumDescription((TipoEnvio)loDatos._TipoEnvio)}";
319  }
320  }
321  }
322  else
323  {
324  this.ewlblEntornoEnvio.Visible = false;
325  }
326 
327  ewImagenQR.Image = GenerarImagenQr(loDatos._QRVERIFAC);
328  ewImagenQR.SizeMode = PictureBoxSizeMode.StretchImage;
329 
330  }
331 
332 
333 
334 
335  #endregion METODOS PUBLICOS
336 
337  }
338 
339 
340 }
SistemasFacturacionCertificada
SistemasFacturacionCertificada
Definition: Enums.cs:44
Este es el espacio de nombres de su módulo. Puede encontrar más información y ayuda en el fichero rea...
int _TipoEnvio
Entorno de envio (0-No enviado aún, 1-Enviado a PRE, 2-Enviado a PRO)
TipoDocCrearFactura _TipoCert
TIPO_CERT de tipo entero, valor por defecto 0. Guardará el tipo de factura y los posibles valores ser...
Clase documento de venta TPV
Definition: DocVentaTpv.cs:47
Formulario gennérico para mostrar información
static System.Drawing.Bitmap icon_eye16
Busca un recurso adaptado de tipo System.Drawing.Bitmap.
TipoDocCrearFactura
Enumeración para la creación de las facturas
Definition: Enums.cs:163
Clase de recurso fuertemente tipado, para buscar cadenas traducidas, etc.
Clase para generar códigos de barras/QR a partir de SageReports
TipoEnvio
Entorno de envío PRE/PRO
Definition: Enums.cs:710
eTipoDocumento
Detalle los tipos de documento posibles de ventas y compras
Definition: docsvenenum.cs:32
Clase que se utilizará como base para "DatosAdicionalesFacturarAlbaran" y "DatosAdicionalesTicket" qu...
Usercontrol para los datos de certificación de factura para VeriFactu
DateTime _Hora
HORA, guardará la hora en la que se ha certificado la factura o ticket. Mientras no se certifique ha ...
Clase UserControlConfig
Definition: Modulo.cs:1734
string _QRVERIFAC
QR_VERIFAC de tipo text. Guardará el valor que se usará para imprimir código QR en el documento cuand...