EliminarDocumentosIncompletos.cs
1 using sage.ew.db;
4 using sage.ew.ewbase.Clases;
5 using sage.ew.formul.Forms;
6 using sage.ew.global;
7 using System;
8 using System.Collections.Generic;
9 using System.Data;
10 using System.Linq;
11 using System.Text;
12 using System.Windows.Forms;
13 
14 namespace sage.ew.Diagnostico
15 {
21  {
22 
23  private List<TipoDocumento> _oDocumentos = null;
24 
28  protected override List<TipoDocumento> _Documentos
29  {
30  get
31  {
32  if (_oDocumentos == null) _oDocumentos = new List<TipoDocumento>() { new TipoDocumentoPresupuestoVenta(), new TipoDocumentoDepositoVenta(), new TipoDocumentoPedidoVenta(), new TipoDocumentoAlbaranVenta(), new TipoDocumentoFacturaVenta(), new TipoDocumentoTicketVenta() };
33  return _oDocumentos;
34  }
35  }
36 
42  protected override DataTable CreateDataTable(List<TipoDocumento> toDocumentos)
43  {
44  string lcTipo;
45  DataRow loRow;
46  DataTable loDt = new DataTable();
47 
48  loDt.Columns.Add("sel", typeof(bool));
49  loDt.Columns.Add("tipo", typeof(string)).Caption = "Tipo documento";
50  loDt.Columns.Add("tabla", typeof(string));
51  loDt.Columns.Add("documento", typeof(string));
52  loDt.Columns.Add("key", typeof(string)).ExtendedProperties.Add("NoVisible", true);
53 
54  toDocumentos.ForEach(f =>
55  {
56  lcTipo = $"{f.ToString().Substring(0, 1).ToUpper()}{f.ToString().Substring(1)}";
57 
58  f._Data.AsEnumerable().ToList().ForEach(z =>
59  {
60  loRow = loDt.NewRow();
61  loRow["tipo"] = lcTipo;
62  loRow["tabla"] = z["TABLA"];
63  loRow["documento"] = $"{z["LETRA"]}{z["NUMERO"]}";
64  z["KEY"] = loRow["key"] = Guid.NewGuid();
65 
66  loDt.Rows.Add(loRow);
67  });
68  });
69 
70  return loDt;
71  }
72 
77  : base(TipoCategoriaPruebaDiagnostica.Ventas, "Eliminar cabeceras sin líneas y líneas sin cabeceras a nivel de documentos de ventas (pedidos, presupuestos, albarán, depósitos y facturas).")
78  {
79 
80  }
81 
82  }
83 
89  {
90  private List<TipoDocumento> _oDocumentos = null;
91 
95  protected override List<TipoDocumento> _Documentos
96  {
97  get
98  {
99  if (_oDocumentos == null) _oDocumentos = new List<TipoDocumento>() { new TipoDocumentoPropuestaCompra(), new TipoDocumentoDepositoCompra(), new TipoDocumentoPedidoCompra(), new TipoDocumentoAlbaranCompra(), new TipoDocumentoFacturaCompra() };
100  return _oDocumentos;
101  }
102  }
103 
109  protected override DataTable CreateDataTable(List<TipoDocumento> toDocumentos)
110  {
111  string lcTipo;
112  DataRow loRow;
113  DataTable loDt = new DataTable();
114 
115  loDt.Columns.Add("sel", typeof(bool));
116  loDt.Columns.Add("tipo", typeof(string)).Caption = "Tipo documento";
117  loDt.Columns.Add("tabla", typeof(string));
118  loDt.Columns.Add("documento", typeof(string));
119  loDt.Columns.Add("proveedor", typeof(string));
120  loDt.Columns.Add("key", typeof(string)).ExtendedProperties.Add("NoVisible", true);
121 
122  toDocumentos.ForEach(f =>
123  {
124  lcTipo = $"{f.ToString().Substring(0, 1).ToUpper()}{f.ToString().Substring(1)}";
125 
126  f._Data.AsEnumerable().ToList().ForEach(z =>
127  {
128  loRow = loDt.NewRow();
129  loRow["sel"] = true;
130  loRow["tipo"] = lcTipo;
131  loRow["tabla"] = z["TABLA"];
132  loRow["documento"] = z["NUMERO"];
133  loRow["proveedor"] = z["PROVEEDOR"];
134  z["KEY"] = loRow["key"] = Guid.NewGuid();
135 
136  loDt.Rows.Add(loRow);
137  });
138  });
139 
140  return loDt;
141  }
146  : base(TipoCategoriaPruebaDiagnostica.Compras, "Eliminar cabeceras sin líneas y líneas sin cabeceras a nivel de documentos de compras (pedidos, presupuestos, albarán, depósitos y facturas).")
147  {
148 
149  }
150 
151  }
152 
153  #region TIPO DOCUMENTOS COMPRAS
154 
160  {
165  : base("C_ALBCOM", "D_ALBCOM", EnUso.TiposEnUso.FACTUCOM.ToString(), "factura")
166  {
167 
168  }
169 
174  protected override string _GetSQLByDocument()
175  {
176  string lcCampo, lcSQL, lcClave;
177 
178  lcCampo = "c.NUMERO, c.PROVEEDOR";
179  lcClave = $"'{Convert.ToString(EW_GLOBAL._GetVariable("wc_any"))}' + c.EMPRESA + {DB.SQLIif("LEN(RTRIM(LTRIM(c.FACTURA))) < 10 ", "SUBSTRING(c.FACTURA, LEN(c.FACTURA) - 9, 10)", "RTRIM(LTRIM(c.FACTURA))")} + c.PROVEEDOR";
180 
181  lcSQL = $@"SELECT '{_Tipo}' as TIPO, '{_Tabla}' as TABLA, {lcCampo}, 0 as LINIA, u.CLAVE FROM {DB.SQLDatabase("GESTION", _Tabla)} c {Environment.NewLine}" +
182  $@"LEFT JOIN {DB.SQLDatabase("GESTION", _TablaLineas)} l ON c.NUMERO = l.NUMERO AND l.PROVEEDOR = c.PROVEEDOR AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
183  $@"LEFT JOIN {DB.SQLDatabase("COMUNES", "EN_USO")} u on u.tipo = '{_Tipo}' AND u.CLAVE = {lcClave} {Environment.NewLine}" +
184  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND l.NUMERO is null AND RTRIM(LTRIM(c.FACTURA)) <> '' AND ( u.CLAVE is null OR u.CREATED < {DB.SQLString(DateTime.Now.AddDays(-2))}) {Environment.NewLine} ";
185 
186  return lcSQL;
187  }
188  }
189 
195  {
200  : base("C_ALBCOM", "D_ALBCOM", EnUso.TiposEnUso.ALBCOM.ToString(), "albaran")
201  {
202 
203  }
204 
209  protected override string _GetSQLByDocument()
210  {
211  string lcCampo, lcSQL, lcClave;
212 
213  lcCampo = "c.NUMERO, c.PROVEEDOR";
214  lcClave = $"'{Convert.ToString(EW_GLOBAL._GetVariable("wc_any"))}' + c.EMPRESA + {DB.SQLIif("LEN(RTRIM(LTRIM(c.NUMERO))) < 10 ", "SUBSTRING(c.NUMERO, LEN(c.NUMERO) - 9, 10)", "RTRIM(LTRIM(c.NUMERO))")} + c.PROVEEDOR";
215 
216  lcSQL = $@"SELECT '{_Tipo}' as TIPO, '{_Tabla}' as TABLA, {lcCampo}, 0 as LINIA, u.CLAVE FROM {DB.SQLDatabase("GESTION", _Tabla)} c {Environment.NewLine}" +
217  $@"LEFT JOIN {DB.SQLDatabase("GESTION", _TablaLineas)} l ON c.NUMERO = l.NUMERO AND l.PROVEEDOR = c.PROVEEDOR AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
218  $@"LEFT JOIN {DB.SQLDatabase("COMUNES", "EN_USO")} u on u.tipo = '{_Tipo}' AND u.CLAVE = {lcClave} {Environment.NewLine}" +
219  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND l.NUMERO is null AND RTRIM(LTRIM(FACTURA)) = '' AND ( u.CLAVE is null OR u.CREATED < {DB.SQLString(DateTime.Now.AddDays(-2))}) {Environment.NewLine} " +
220  $@"UNION {Environment.NewLine}" +
221  $@"SELECT '{_Tipo}' as TIPO, '{_TablaLineas}' as TABLA, {lcCampo}, LINIA, '' as CLAVE FROM {DB.SQLDatabase("GESTION", _TablaLineas)} c {Environment.NewLine}" +
222  $@"LEFT JOIN {DB.SQLDatabase("GESTION", _Tabla)} l ON c.NUMERO = l.NUMERO AND l.PROVEEDOR = c.PROVEEDOR AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
223  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND l.NUMERO is null ";
224 
225  return lcSQL;
226  }
227  }
228 
234  {
239  : base("C_PEDICO", "D_PEDICO", EnUso.TiposEnUso.PEDICOM.ToString(), "pedido")
240  {
241 
242  }
243  }
244 
250  {
255  : base("C_DEPCOM", "D_DEPCOM", EnUso.TiposEnUso.DEPOCOM.ToString(), "depósito")
256  {
257 
258  }
259  }
260 
266  {
271  : base("C_PRECOM", "D_PRECOM", EnUso.TiposEnUso.PRECOM.ToString(), "propuesta")
272  {
273 
274  }
275  }
276 
277  #endregion TIPO DOCUMENTOS COMPRAS
278 
279  #region TIPO DOCUMENTOS VENTAS
280 
286  {
290  protected internal bool _FactSer = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_Factser"));
294  protected internal bool _SerFact = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_Serfact"));
295 
300  : base("C_ALBVEN", "D_ALBVEN", "C_ALBVEN", "ticket")
301  {
302 
303  }
304 
309  protected override string _GetSQLByDocument()
310  {
311  string lcCampo, lcSQL, lcClave, lcClaveF, lcAny;
312 
313  lcCampo = "c.LETRA, c.NUMERO, c.EJERCICIO";
314  lcAny = Convert.ToString(EW_GLOBAL._GetVariable("wc_any"));
315  lcClave = $"'{lcAny}' + c.EMPRESA + c.NUMERO + c.LETRA ";
316  lcClaveF = _FactSer && _SerFact ? $"'{Convert.ToString(EW_GLOBAL._GetVariable("wc_any"))}' + c.EMPRESA + SUBSTRING(ISNULL(g.FACTURA, c.NUMERO), 3, 8) + SUBSTRING(ISNULL(g.FACTURA, c.NUMERO), 0, 3) " : $"'{Convert.ToString(EW_GLOBAL._GetVariable("wc_any"))}' + c.EMPRESA + ISNULL(g.FACTURA, c.NUMERO) ";
317 
318  lcSQL = $@"SELECT '{_Tipo}' as TIPO, '{_Tabla}' as TABLA, {lcCampo}, 0 as LINEA, u.CLAVE, c.TIPO_DOC FROM {DB.SQLDatabase("TPV", _Tabla)} c {Environment.NewLine}" +
319  $@"LEFT JOIN {DB.SQLDatabase("TPV", _TablaLineas)} l ON c.EJERCICIO = l.EJERCICIO AND c.NUMERO = l.NUMERO AND c.LETRA = l.LETRA AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
320  $@"LEFT JOIN {DB.SQLDatabase("COMUNES", "EN_USO")} u on u.tipo = '{_Tipo}' AND u.CLAVE = {lcClave} {Environment.NewLine}" +
321  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND c.TIPO_DOC <> 3 AND l.NUMERO is null AND c.EJERCICIO = {DB.SQLString(lcAny)} AND ( u.CLAVE is null OR u.CREATED < {DB.SQLString(DateTime.Now.AddDays(-2))}) {Environment.NewLine}" +
322  $@"UNION {Environment.NewLine}" +
323  $@"SELECT 'FACTUVEN' as TIPO, '{_Tabla}' as TABLA, {lcCampo}, 0 as LINEA, u.CLAVE, c.TIPO_DOC FROM {DB.SQLDatabase("TPV", _Tabla)} c {Environment.NewLine}" +
324  $@"LEFT JOIN {DB.SQLDatabase("GESTION", "C_ALBVEN")} g ON c.EJERCICIO = '{lcAny}' AND c.NUMERO = g.NUMERO AND c.LETRA = g.LETRA AND c.EMPRESA = g.EMPRESA AND RTRIM(LTRIM(g.FACTURA)) <> '' {Environment.NewLine}" +
325  $@"LEFT JOIN {DB.SQLDatabase("TPV", _TablaLineas)} l ON c.EJERCICIO = l.EJERCICIO AND c.NUMERO = l.NUMERO AND c.LETRA = l.LETRA AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
326  $@"LEFT JOIN {DB.SQLDatabase("COMUNES", "EN_USO")} u on u.tipo = 'FACTUVEN' AND u.CLAVE = {lcClaveF} {Environment.NewLine}" +
327  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND c.TIPO_DOC = 3 AND l.NUMERO is null AND c.EJERCICIO = {DB.SQLString(lcAny)} AND ( u.CLAVE is null OR u.CREATED < {DB.SQLString(DateTime.Now.AddDays(-2))}) {Environment.NewLine}" +
328  $@"UNION {Environment.NewLine}" +
329  $@"SELECT '{_Tipo}' as TIPO, '{_TablaLineas}' as TABLA, {lcCampo}, LINEA, '' as CLAVE, 0 as TIPO_DOC FROM {DB.SQLDatabase("TPV", _TablaLineas)} c {Environment.NewLine}" +
330  $@"LEFT JOIN {DB.SQLDatabase("TPV", _Tabla)} l ON c.EJERCICIO = l.EJERCICIO AND c.NUMERO = l.NUMERO AND c.LETRA = l.LETRA AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
331  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND l.NUMERO is null AND c.EJERCICIO = {DB.SQLString(lcAny)} ";
332 
333  return lcSQL;
334 
335  }
336 
341  protected override string _GetSQLDeleteCabeceraByDocument()
342  {
343  List<DataRow> loList;
344  StringBuilder loSQL = new StringBuilder();
345 
346  loList = GetDataByTabla(_Tabla);
347  loList.ForEach(f => loSQL.AppendLine($"DELETE FROM {DB.SQLDatabase("TPV", _Tabla)} WHERE EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND NUMERO = {DB.SQLString(f["NUMERO"])} AND LETRA = {DB.SQLString(f["LETRA"])} AND EJERCICIO = {DB.SQLString(f["EJERCICIO"])} AND TIPO_DOC = {DB.SQLString(f["TIPO_DOC"])}; "));
348 
349  return loSQL.ToString();
350  }
351 
356  protected override string _GetSQLDeleteLineasByDocument()
357  {
358  List<DataRow> loList;
359  StringBuilder loSQL = new StringBuilder();
360 
361  loList = GetDataByTabla(_TablaLineas);
362  loList.ForEach(f => loSQL.AppendLine($"DELETE FROM {DB.SQLDatabase("TPV", _TablaLineas)} WHERE EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND NUMERO = {DB.SQLString(f["NUMERO"])} AND LETRA = {DB.SQLString(f["LETRA"])} AND EJERCICIO = {DB.SQLString(f["EJERCICIO"])} AND LINEA = {DB.SQLString(f["LINEA"])}; "));
363 
364  return loSQL.ToString();
365  }
366  }
367 
373  {
377  protected internal bool _FactSer = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_Factser"));
381  protected internal bool _SerFact = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_Serfact"));
382 
387  : base("C_ALBVEN", "D_ALBVEN", EnUso.TiposEnUso.FACTUVEN.ToString(), "factura")
388  {
389 
390  }
391 
396  protected override string _GetSQLByDocument()
397  {
398  string lcCampo, lcSQL, lcClave;
399 
400  lcCampo = "c.LETRA, c.NUMERO";
401  lcClave = _FactSer && _SerFact ? $"'{Convert.ToString(EW_GLOBAL._GetVariable("wc_any"))}' + c.EMPRESA + SUBSTRING(c.FACTURA, 3, 8) + SUBSTRING(c.FACTURA, 0, 3) " : $"'{Convert.ToString(EW_GLOBAL._GetVariable("wc_any"))}' + c.EMPRESA + c.FACTURA";
402 
403  lcSQL = $@"SELECT '{_Tipo}' as TIPO, '{_Tabla}' as TABLA, {lcCampo}, 0 as LINIA, u.CLAVE FROM {DB.SQLDatabase("GESTION", _Tabla)} c {Environment.NewLine}" +
404  $@"LEFT JOIN {DB.SQLDatabase("GESTION", _TablaLineas)} l ON c.NUMERO = l.NUMERO AND c.LETRA = l.LETRA AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
405  $@"LEFT JOIN {DB.SQLDatabase("COMUNES", "EN_USO")} u on u.tipo = '{_Tipo}' AND u.CLAVE = {lcClave} {Environment.NewLine}" +
406  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND l.NUMERO is null AND RTRIM(LTRIM(FACTURA)) <> '' AND ( u.CLAVE is null OR u.CREATED < {DB.SQLString(DateTime.Now.AddDays(-2))}) {Environment.NewLine}";
407 
408  return lcSQL;
409  }
410 
415  protected override string _GetSQLDeleteLineasByDocument()
416  {
417  return "";
418  }
419  }
420 
426  {
431  : base("C_ALBVEN", "D_ALBVEN", "C_ALBVEN", "albaran")
432  {
433 
434  }
435 
440  protected override string _GetSQLByDocument()
441  {
442  string lcCampo, lcSQL, lcClave;
443 
444  lcCampo = "c.LETRA, c.NUMERO";
445  lcClave = $"'{Convert.ToString(EW_GLOBAL._GetVariable("wc_any"))}' + c.EMPRESA + c.NUMERO + c.LETRA ";
446 
447  lcSQL = $@"SELECT '{_Tipo}' as TIPO, '{_Tabla}' as TABLA, {lcCampo}, 0 as LINIA, u.CLAVE FROM {DB.SQLDatabase("GESTION", _Tabla)} c {Environment.NewLine}" +
448  $@"LEFT JOIN {DB.SQLDatabase("GESTION", _TablaLineas)} l ON c.NUMERO = l.NUMERO AND c.LETRA = l.LETRA AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
449  $@"LEFT JOIN {DB.SQLDatabase("COMUNES", "EN_USO")} u on u.tipo = '{_Tipo}' AND u.CLAVE = {lcClave} {Environment.NewLine}" +
450  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND l.NUMERO is null AND RTRIM(LTRIM(FACTURA)) = '' AND ( u.CLAVE is null OR u.CREATED < {DB.SQLString(DateTime.Now.AddDays(-2))}) {Environment.NewLine}" +
451  $@"UNION {Environment.NewLine}" +
452  $@"SELECT '{_Tipo}' as TIPO, '{_TablaLineas}' as TABLA, {lcCampo}, LINIA, '' as CLAVE FROM {DB.SQLDatabase("GESTION", _TablaLineas)} c {Environment.NewLine}" +
453  $@"LEFT JOIN {DB.SQLDatabase("GESTION", _Tabla)} l ON c.NUMERO = l.NUMERO AND c.LETRA = l.LETRA AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
454  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND l.NUMERO is null ";
455 
456  return lcSQL;
457  }
458  }
459 
465  {
470  : base("C_PEDIVE", "D_PEDIVE", EnUso.TiposEnUso.PEDIVEN.ToString(), "pedido")
471  {
472 
473  }
474  }
475 
481  {
486  : base("C_ALBDEP", "D_ALBDEP", EnUso.TiposEnUso.DEPOVEN.ToString(), "depósito")
487  {
488 
489  }
490  }
491 
497  {
502  : base("C_PRESUV", "D_PRESUV", EnUso.TiposEnUso.PRESUVEN.ToString(), "presupuesto")
503  {
504 
505  }
506  }
507 
508  #endregion TIPO DOCUMENTOS VENTAS
509 
510  #region ABSTRACT CLASS
511 
515  public abstract class EliminarDocumentosIncompletos
517  {
521  protected abstract List<TipoDocumento> _Documentos { get; }
522 
528  protected abstract DataTable CreateDataTable(List<TipoDocumento> toDocumentos);
529 
534  public override IEnumerable<IResultadoPruebaDiagnostica> Ejecutar()
535  {
536  Seleccionar loForm;
537  List<string> loKeys;
538  IResultadoPruebaDiagnostica loResDefecte;
539  List<TipoDocumento> loDocumentos = new List<TipoDocumento>();
540  List<IResultadoPruebaDiagnostica> loRes = new List<IResultadoPruebaDiagnostica>();
541 
542  _Documentos.ForEach(f => f.Clear());
543 
544  loResDefecte = GetResultadoPreconfigurado();
545 
546  loDocumentos = _Documentos.Where(f => f._Data.Rows.Count > 0).ToList();
547 
548  if (loDocumentos.Count > 0)
549  {
550  loForm = new Seleccionar();
551  loForm._DataTable = CreateDataTable(loDocumentos);
552  loForm._CampoSeleccion = "sel";
553  loForm._MostrarColumnaSeleccion = true;
554  loForm._ValorSeleccionarTodosDefecto = true;
555  loForm._ShowDialog();
556 
557  if (loForm.DialogResult == DialogResult.OK)
558  {
559  loKeys = loForm._DataTable.AsEnumerable().Where(f => Convert.ToBoolean(f["sel"])).Select(f => Convert.ToString(f["Key"])).ToList();
560 
561  if (loKeys.Count > 0)
562  {
563  loDocumentos.ForEach(f =>
564  {
565  f._Keys = loKeys;
566  loResDefecte = GetResultadoPreconfigurado();
567  loResDefecte = f._GetResultCabeceraByDocument(loResDefecte);
568  if (loResDefecte is IResultadoPruebaDiagnostica) loRes.Add(loResDefecte);
569  loResDefecte = GetResultadoPreconfigurado();
570  loResDefecte = f._GetResultLineasByDocument(loResDefecte);
571  if (loResDefecte is IResultadoPruebaDiagnostica) loRes.Add(loResDefecte);
572  });
573 
574  //Eliminamos los registros en la tabla EN_USO de comunes
575  DeleteEnUso(loDocumentos);
576  }
577  else
578  {
579  loResDefecte.Resultado = TipoResultadoPruebaDiagnostica.Warning;
580  loResDefecte.Descripcion = "No se han seleccionado registros para eliminar.";
581  loRes.Add(loResDefecte);
582  }
583  }
584  else
585  {
586  loResDefecte.Resultado = TipoResultadoPruebaDiagnostica.Warning;
587  loResDefecte.Descripcion = "Eliminación cancelada por el usuario.";
588  loRes.Add(loResDefecte);
589  }
590  }
591  else
592  {
593  loResDefecte.Resultado = TipoResultadoPruebaDiagnostica.Correcto;
594  loResDefecte.Descripcion = "No se han encontrado documentos sin líneas o líneas sin cabeceras. ";
595  loRes.Add(loResDefecte);
596  }
597 
598  _Documentos.ForEach(f => f.Clear());
599 
600  return loRes;
601  }
602 
603  private void DeleteEnUso(List<TipoDocumento> toDocumentos)
604  {
605  StringBuilder loSQL = new StringBuilder();
606 
607  toDocumentos.ForEach(f => f._Data.AsEnumerable().ToList().Where(z => !string.IsNullOrEmpty(Convert.ToString(z["CLAVE"]).Trim())).ToList().ForEach(z => loSQL.AppendLine($"DELETE FROM {DB.SQLDatabase("COMUNES", "EN_USO")} WHERE TIPO = {DB.SQLString(z["TIPO"])} AND CLAVE = {DB.SQLString(z["CLAVE"])};")));
608 
609  if (loSQL.Length > 0) DB.SQLExec(loSQL.ToString());
610  }
611 
617  public EliminarDocumentosIncompletos(TipoCategoriaPruebaDiagnostica teCategoria, string tcDescripcion)
618  : base(teCategoria, $"Eliminación de cabeceras y líneas incompletas", tcDescripcion)
619  {
620 
621  }
622  }
623 
627  public abstract class TipoDocumentoVenta
628  : TipoDocumento
629  {
637  public TipoDocumentoVenta(string tcTabla, string tcTablaLin, string tcTipo, string tcNombre)
638  : base(tcTabla, tcTablaLin, tcTipo, tcNombre)
639  {
640  }
641 
646  protected override string _GetSQLByDocument()
647  {
648  string lcCampo, lcSQL, lcClave;
649 
650  lcCampo = "c.LETRA, c.NUMERO";
651  lcClave = $"'{Convert.ToString(EW_GLOBAL._GetVariable("wc_any"))}' + c.EMPRESA + c.NUMERO + c.LETRA ";
652 
653  lcSQL = $@"SELECT '{_Tipo}' as TIPO, '{_Tabla}' as TABLA, {lcCampo}, 0 as LINIA, u.CLAVE FROM {DB.SQLDatabase("GESTION", _Tabla)} c {Environment.NewLine}" +
654  $@"LEFT JOIN {DB.SQLDatabase("GESTION", _TablaLineas)} l ON c.NUMERO = l.NUMERO AND c.LETRA = l.LETRA AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
655  $@"LEFT JOIN {DB.SQLDatabase("COMUNES", "EN_USO")} u on u.tipo = '{_Tipo}' AND u.CLAVE = {lcClave} {Environment.NewLine}" +
656  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND l.NUMERO is null AND ( u.CLAVE is null OR u.CREATED < {DB.SQLString(DateTime.Now.AddDays(-2))}) {Environment.NewLine}" +
657  $@"UNION {Environment.NewLine}" +
658  $@"SELECT '{_Tipo}' as TIPO, '{_TablaLineas}' as TABLA, {lcCampo}, LINIA, '' as CLAVE FROM {DB.SQLDatabase("GESTION", _TablaLineas)} c {Environment.NewLine}" +
659  $@"LEFT JOIN {DB.SQLDatabase("GESTION", _Tabla)} l ON c.NUMERO = l.NUMERO AND c.LETRA = l.LETRA AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
660  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND l.NUMERO is null ";
661 
662  return lcSQL;
663  }
664 
669  protected override string _GetSQLDeleteCabeceraByDocument()
670  {
671  List<DataRow> loList;
672  StringBuilder loSQL = new StringBuilder();
673 
674  loList = GetDataByTabla(_Tabla);
675  loList.ForEach(f => loSQL.AppendLine($"DELETE FROM {DB.SQLDatabase("GESTION", _Tabla)} WHERE EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND NUMERO = {DB.SQLString(f["NUMERO"])} AND LETRA = {DB.SQLString(f["LETRA"])}; "));
676 
677  return loSQL.ToString();
678  }
679 
684  protected override string _GetSQLDeleteLineasByDocument()
685  {
686  List<DataRow> loList;
687  StringBuilder loSQL = new StringBuilder();
688 
689  loList = GetDataByTabla(_TablaLineas);
690  loList.ForEach(f => loSQL.AppendLine($"DELETE FROM {DB.SQLDatabase("GESTION", _TablaLineas)} WHERE EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND NUMERO = {DB.SQLString(f["NUMERO"])} AND LETRA = {DB.SQLString(f["LETRA"])} AND LINIA = {DB.SQLString(f["LINIA"])} ; "));
691 
692  return loSQL.ToString();
693  }
694  }
695 
699  public abstract class TipoDocumentoCompra
700  : TipoDocumento
701  {
709  public TipoDocumentoCompra(string tcTabla, string tcTablaLin, string tcTipo, string tcNombre)
710  : base(tcTabla, tcTablaLin, tcTipo, tcNombre)
711  {
712  }
713 
718  protected override string _GetSQLDeleteCabeceraByDocument()
719  {
720  List<DataRow> loList;
721  StringBuilder loSQL = new StringBuilder();
722 
723  loList = GetDataByTabla(_Tabla);
724  loList.ForEach(f => loSQL.AppendLine($"DELETE FROM {DB.SQLDatabase("GESTION", _Tabla)} WHERE EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND NUMERO = {DB.SQLString(f["NUMERO"])} AND PROVEEDOR = {DB.SQLString(f["PROVEEDOR"])}; "));
725 
726  return loSQL.ToString();
727  }
728 
733  protected override string _GetSQLDeleteLineasByDocument()
734  {
735  List<DataRow> loList;
736  StringBuilder loSQL = new StringBuilder();
737 
738  loList = GetDataByTabla(_TablaLineas);
739  loList.ForEach(f => loSQL.AppendLine($"DELETE FROM {DB.SQLDatabase("GESTION", _TablaLineas)} WHERE EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND NUMERO = {DB.SQLString(f["NUMERO"])};"));
740 
741  return loSQL.ToString();
742  }
743 
748  protected override string _GetSQLByDocument()
749  {
750  string lcCampo, lcSQL, lcClave;
751 
752  lcCampo = "c.NUMERO, c.PROVEEDOR";
753  lcClave = $"'{Convert.ToString(EW_GLOBAL._GetVariable("wc_any"))}' + c.EMPRESA + {DB.SQLIif("LEN(RTRIM(LTRIM(c.NUMERO))) < 10 ", "SUBSTRING(c.NUMERO, LEN(c.NUMERO) - 9, 10)", "RTRIM(LTRIM(c.NUMERO))")}";
754 
755  lcSQL = $@"SELECT '{_Tipo}' as TIPO, '{_Tabla}' as TABLA, {lcCampo}, 0 as LINIA, u.CLAVE FROM {DB.SQLDatabase("GESTION", _Tabla)} c {Environment.NewLine}" +
756  $@"LEFT JOIN {DB.SQLDatabase("GESTION", _TablaLineas)} l ON c.NUMERO = l.NUMERO AND l.PROVEEDOR = c.PROVEEDOR AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
757  $@"LEFT JOIN {DB.SQLDatabase("COMUNES", "EN_USO")} u on u.tipo = '{_Tipo}' AND u.CLAVE = {lcClave} {Environment.NewLine}" +
758  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND l.NUMERO is null AND ( u.CLAVE is null OR u.CREATED < {DB.SQLString(DateTime.Now.AddDays(-2))}) {Environment.NewLine}" +
759  $@"UNION {Environment.NewLine}" +
760  $@"SELECT '{_Tipo}' as TIPO, '{_TablaLineas}' as TABLA, {lcCampo}, LINIA, '' as CLAVE FROM {DB.SQLDatabase("GESTION", _TablaLineas)} c {Environment.NewLine}" +
761  $@"LEFT JOIN {DB.SQLDatabase("GESTION", _Tabla)} l ON c.NUMERO = l.NUMERO AND l.PROVEEDOR = c.PROVEEDOR AND c.EMPRESA = l.EMPRESA {Environment.NewLine}" +
762  $@"WHERE c.EMPRESA = {DB.SQLString(EW_GLOBAL._Empresa._Codigo)} AND l.NUMERO is null ";
763 
764  return lcSQL;
765  }
766 
767  }
768 
772  public abstract class TipoDocumento
773  {
774  private DataTable _oData = null;
775 
779  public List<string> _Keys { get; set; }
780 
784  protected string _Tabla { get; private set; }
785 
789  protected string _TablaLineas { get; private set; }
790 
794  protected string _Tipo { get; private set; }
795 
799  protected string _Nombre { get; private set; }
800 
804  public DataTable _Data
805  {
806  get
807  {
808  if (_oData == null) _oData = _GetData();
809  return _oData;
810  }
811  }
812 
818  protected List<DataRow> GetDataByTabla(string tcTabla)
819  {
820  return _Data.AsEnumerable().Where(f => Convert.ToString(f["TABLA"]) == tcTabla && _Keys.Contains(Convert.ToString(f["KEY"]))).ToList();
821  }
822 
826  private DataTable _GetData()
827  {
828  DataTable loDt = new DataTable();
829  DB.SQLExec(_GetSQLByDocument(), ref loDt);
830 
831  loDt.Columns.Add("Key", typeof(string));
832 
833  return loDt;
834  }
835 
840  protected abstract string _GetSQLByDocument();
841 
846  protected abstract string _GetSQLDeleteCabeceraByDocument();
847 
852  protected abstract string _GetSQLDeleteLineasByDocument();
853 
859  protected virtual string GetDescripcionOK(bool tbCabecera)
860  {
861  int lnCount;
862 
863  lnCount = GetDataByTabla(tbCabecera ? _Tabla : _TablaLineas).Count();
864 
865  return $"Se ha{(lnCount > 1 ? "n" : "")} eliminado {lnCount} {(tbCabecera ? $"cabecera{(lnCount > 1 ? "s" : "")} sin líneas" : $"línea{(lnCount > 1 ? "s" : "")} sin cabecera")} de {_Nombre}";
866  }
867 
873  protected virtual string GetError(bool tbCabecera)
874  {
875  int lnCount;
876 
877  lnCount = GetDataByTabla(tbCabecera ? _Tabla : _TablaLineas).Count();
878 
879  return $"No se ha{(lnCount > 1 ? "n" : "")} podido eliminar {lnCount} {(tbCabecera ? $"cabecera{(lnCount > 1 ? "s" : "")}" : $"línea{(lnCount > 1 ? "s" : "")}")} de {_Nombre}";
880  }
881 
888  {
889  return _GetResultByDocument(_GetSQLDeleteCabeceraByDocument(), toResDefecte, true);
890  }
891 
898  {
899  return _GetResultByDocument(_GetSQLDeleteLineasByDocument(), toResDefecte, false);
900  }
901 
902 
903 
904  private IResultadoPruebaDiagnostica _GetResultByDocument(string tcSQL, IResultadoPruebaDiagnostica toResDefecte, bool tbCabecera)
905  {
906  if (!string.IsNullOrEmpty(tcSQL))
907  {
908  if (DB.SQLExec(tcSQL))
909  {
910  toResDefecte.Resultado = TipoResultadoPruebaDiagnostica.Correcto;
911  toResDefecte.Descripcion = GetDescripcionOK(tbCabecera);
912  }
913  else
914  {
915  toResDefecte.Resultado = TipoResultadoPruebaDiagnostica.Error;
916  toResDefecte.Descripcion = GetError(tbCabecera);
917  }
918  }
919  else
920  {
921  toResDefecte = null;
922  }
923 
924  return toResDefecte;
925  }
926 
930  public void Clear()
931  {
932  _oData = null;
933  }
934 
939  public override string ToString()
940  {
941  return _Nombre;
942  }
943 
951  public TipoDocumento(string tcTabla, string tcTablaLin, string tcTipo, string tcNombre)
952  {
953  _Tabla = tcTabla;
954  _TablaLineas = tcTablaLin;
955  _Tipo = tcTipo;
956  _Nombre = tcNombre;
957  }
958  }
959 
960  #endregion ABSTRACT CLASS
961 }
virtual string GetDescripcionOK(bool tbCabecera)
Retorna la cadena descriptiva del proceso realizado
override string _GetSQLDeleteLineasByDocument()
Obtener la SQL para eliminar las lineas por documento
Clase para la definición del tipo de documento depósito de venta
override string _GetSQLDeleteLineasByDocument()
Obtener la SQL para eliminar las lineas por documento
override DataTable CreateDataTable(List< TipoDocumento > toDocumentos)
Crear la tabla para mostrar los resistros de ventas para su eliminación
override IEnumerable< IResultadoPruebaDiagnostica > Ejecutar()
Comprobación para ver los asientos con cuentas de diferencias de cambio y moneda diferente a la de em...
Clase para la definición del tipo de documento factura de compra
virtual void _ShowDialog()
PE92638 Fa el ShowDialog però abans comprova l&#39;accès al formulari
Definition: clsFormul.cs:4664
Clase para la definición del tipo de documento depósito de compra
override string _GetSQLDeleteCabeceraByDocument()
Obtener la SQL para eliminar por documento
Clase para la definición del tipo de documento albaran de venta
override string _GetSQLDeleteLineasByDocument()
Obtener la SQL para eliminar las lineas por documento
override DataTable CreateDataTable(List< TipoDocumento > toDocumentos)
Crear la tabla para mostrar los registros de compras para su eliminación
TipoCategoriaPruebaDiagnostica
Enumerado de categorias de pruebas diagnósticas
Clase para la definición del tipo de documento pedido de compra
Clase de prueba diagnostico para eliminar cabeceras sin líneas y líneas sin cabeceras (Compras) ...
override string _GetSQLByDocument()
Obtener SQL para comporbar documentos sin lineas y lineas sin cabecera
override string _GetSQLByDocument()
Obtener SQL para comporbar documentos sin lineas y lineas sin cabecera
override string _GetSQLDeleteLineasByDocument()
Obtener la SQL para eliminar las líneas por documento
TipoResultadoPruebaDiagnostica
Tipos de resultado que pueden tener las pruebas diagnósticas
virtual IResultadoPruebaDiagnostica _GetResultLineasByDocument(IResultadoPruebaDiagnostica toResDefecte)
Comprueba los registros, eliminado las cabeceras y lineas sin documentos
string _CampoSeleccion
PE-99360 Campo a seleccionar
Definition: Seleccionar.cs:263
virtual IResultadoPruebaDiagnostica _GetResultCabeceraByDocument(IResultadoPruebaDiagnostica toResDefecte)
Comprueba los registros, eliminado las cabeceras y lineas sin documentos
override string _GetSQLByDocument()
Obtener SQL para comporbar documentos sin lineas y lineas sin cabecera
override string _GetSQLByDocument()
Obtener SQL para comporbar documentos sin lineas y lineas sin cabecera
override string _GetSQLByDocument()
Obtener SQL para comporbar documentos sin lineas y lineas sin cabecera
virtual string GetError(bool tbCabecera)
Retorna el error
Clase de prueba diagnostico para eliminar cabeceras sin líneas y líneas sin cabeceras (Ventas) ...
override string _GetSQLByDocument()
Obtener SQL para comporbar documentos sin lineas y lineas sin cabecera
override string _GetSQLDeleteCabeceraByDocument()
Obtener la SQL para eliminar las cabeceras por documento
Clase para la definición del tipo de documento propuesta de compra
override string ToString()
Tipo de documento
override string _GetSQLByDocument()
Obtener SQL para comporbar documentos sin lineas y lineas sin cabecera
DataTable _DataTable
Datatable que se mostrará en el grid.
Definition: Seleccionar.cs:281
override string _GetSQLDeleteCabeceraByDocument()
Obtener la SQL para eliminar las cabeceras por documento
Clase interna para el diagnóstico automático de la instalación Esta clase actua como contenedor de pr...
Definition: Diagnostico.cs:285
Clase para la definición del tipo de documento albaran de venta
bool _ValorSeleccionarTodosDefecto
Valor por defecto del check de seleccionar todo
Definition: Seleccionar.cs:88
EliminarDocumentosIncompletos(TipoCategoriaPruebaDiagnostica teCategoria, string tcDescripcion)
Constructor
TipoDocumentoCompra(string tcTabla, string tcTablaLin, string tcTipo, string tcNombre)
Contructor
Clase para la definición del tipo de documento
List< DataRow > GetDataByTabla(string tcTabla)
Obtener los registros por tabla
Clase para la definición del tipo de documento albaran de venta
Clase para la definición del tipo de documento presupuesto de venta
Formulario multipropuesta SELECCIONAR
Definition: Seleccionar.cs:24
Clase para la definición del tipo de documento albaran de compra
bool _MostrarColumnaSeleccion
Mostrar la columna de selección con checkbox en el header Incompatible con MostrarCheckTodos ...
Definition: Seleccionar.cs:75
TipoDocumentoVenta(string tcTabla, string tcTablaLin, string tcTipo, string tcNombre)
Contructor
Clase base de prueba diagnostico para eliminar cabeceras sin lineas y lineas sin cabeceras ...
TipoDocumento(string tcTabla, string tcTablaLin, string tcTipo, string tcNombre)
Constructor
Clase para la definición del tipo de documento pedido de venta
Interfície para el resultado de pruebas de diagnóstico
Clase EnUso. PE-103176 Centralización de código para la gestión del KeyCopy de las clases que lo requ...
Definition: EnUso.cs:18