RevisionAsientos.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Data;
4 using System.Linq;
5 using sage.ew.db;
6 using sage.ew.global;
7 using sage.ew.listados.Clases;
8 
9 namespace sage.ew.contabilidad
10 {
14  public class RevisionAsientos : sage.ew.listados.Clases.Listados
15  {
16  #region Variables privadas
17 
21  protected bool llDivisaConta = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_divisaconta"));
22 
26  protected string lcEmpresa = Convert.ToString(EW_GLOBAL._GetVariable("wc_empresa"));
27 
31  protected string lcMoneda = Convert.ToString(EW_GLOBAL._GetVariable("wc_moneda"));
32 
36  protected string lcIva = Convert.ToString(EW_GLOBAL._GetVariable("wc_iva"));
37 
38 
42  protected int lnDigito3 = Convert.ToInt32(EW_GLOBAL._GetVariable("wn_digito3"));
43 
47  protected int lnDigito4 = Convert.ToInt32(EW_GLOBAL._GetVariable("wn_digito4"));
48 
52  protected bool _lTodacuen = (Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_todacuen")));
53 
57  protected DateTime dtFechaDesde = DateTime.MinValue;
58 
62  protected DateTime dtFechaHasta = DateTime.MaxValue;
63 
67  protected bool lbAsientosDescuadrados = false;
68 
72  protected bool lbAsientosSinCtaContable = false;
73 
77  protected bool lbAsientosVerificarCuentas = false;
78 
82  protected bool lbImporteInferiorPlanesAnaliticos = false;
83 
87  protected bool lbImporteSuperiorPlanesAnaliticos = false;
88 
92  protected bool lbAsientosVerificarPlanesAnaliticos = false;
93 
97  protected bool lbAsientosSinIVA = false;
98 
102  protected bool lbCuentaDeIVADiferenteAsiento = false;
103 
107  protected bool lbImporteDeIVADiferente = false;
108 
112  protected bool lbRetencionNoAnotada = false;
113 
119  protected bool lbAsientosVerificarRetencion = false;
120 
124  protected bool lbAsientosVerificarFechaPeriodo = false;
125 
129  protected bool lbImporteDeRecargoDiferente = false;
130 
134  protected bool trabajaConSecundarias = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_secundar"));
135 
139  protected DataTable dtResultadoRevision = null;
140 
144  protected DataTable lDtAsientos = null;
145 
146  #endregion Variables privadas
147 
148  #region Constructores
149 
154  : base()
155  {
156  dtResultadoRevision = new DataTable();
157  dtResultadoRevision.Columns.Add("asiento", typeof(System.Int32));
158  dtResultadoRevision.Columns.Add("fecha", typeof(System.DateTime));
159  dtResultadoRevision.Columns.Add("descripcion", typeof(System.String));
160 
161  lDtAsientos = new DataTable();
162  }
163 
164  #endregion Constructores
165 
166  #region Overrides
167 
171  public override String _ReportFile
172  {
173  get
174  {
175  return "revisionasientos.report";
176  }
177  }
178 
183  public override DataTable _DataTable()
184  {
185  dtResultadoRevision.Clear();
186  _ActivarMarcas(false);
187 
188  lDtAsientos = _AsientosDivisa();
189 
190  new DataTable();
191  String lsQueryAsientos = "SELECT numero, MAX(fecha) as fecha, divisa" +
192  " FROM " + DB.SQLDatabase("Gestion", "Asientos") +
193  " WHERE empresa= " + DB.SQLString(lcEmpresa);
194  lsQueryAsientos += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "", "fecha");
195  lsQueryAsientos += " GROUP BY numero, divisa";
196  DB.SQLExec(lsQueryAsientos, ref lDtAsientos);
197 
198  if (_DeterminarQueRevisionesLanzar())
199  {
200  // Asiento descuadrado
201  if (lbAsientosDescuadrados)
202  {
203  _AsientosDescuadrados();
204  }
205  // Apunte sin cuenta contable
206  if (lbAsientosSinCtaContable)
207  {
208  _AsientosSinCuentaContable();
209  }
210  // cuenta contable inexistente
211  if (lbAsientosVerificarCuentas)
212  {
213  _AsientosVerificarCuentas();
214  }
215  // Importe superior en cuentas secundarias
216  // Importe inferior en cuentas secundarias
217  // Asientos sin cuentas secundarias
218  if (lbImporteInferiorPlanesAnaliticos ||
219  lbImporteSuperiorPlanesAnaliticos ||
220  lbAsientosVerificarPlanesAnaliticos)
221  {
222  _AsientosVerificarPlanesAnaliticos(lbImporteSuperiorPlanesAnaliticos, lbImporteInferiorPlanesAnaliticos, lbAsientosVerificarPlanesAnaliticos);
223  }
224  // Apunte de IVA no registrado
225  if (lbAsientosSinIVA)
226  {
227  _AsientosSinIva();
228  }
229  // Cuenta de IVA diferente de asiento
230  // Importe de IVA diferente
231  if (lbCuentaDeIVADiferenteAsiento ||
232  lbImporteDeIVADiferente)
233  {
234  _AsientosVerificarIvaRepercutido(lbCuentaDeIVADiferenteAsiento, lbImporteDeIVADiferente);
235  _AsientosVerificarIvaSoportado(lbCuentaDeIVADiferenteAsiento, lbImporteDeIVADiferente);
236  }
237  // Retención no anotada
238  // Importe de retención diferente
239  if (lbRetencionNoAnotada ||
240  lbAsientosVerificarRetencion)
241  {
242  _AsientosVerificarRetencion(lbRetencionNoAnotada, lbAsientosVerificarRetencion);
243  }
244  // Asientos con fecha fuera del período del ejercicio actual
245  if (lbAsientosVerificarFechaPeriodo)
246  {
247  _AsientosVerificarFechaPeriodo();
248  }
249  // Importe de recargo diferente
250  if (lbImporteDeRecargoDiferente)
251  {
252  _AsientosVerificarRecargoRepercutido(lbImporteDeRecargoDiferente);
253  _AsientosVerificarRecargoSoportado(lbImporteDeRecargoDiferente);
254  }
255  }
256 
257  return dtResultadoRevision;
258  }
259 
263  public override List<string> _ReportColumns
264  {
265  get
266  {
267  _dicDefEntidades = new Dictionary<string, ew.interficies.IDefEntidad>();
268  _dicDefEntidades.Add("asiento", new DefEntidad() { _DB = "GESTION", _Tabla = "ASIENTOS", _Campo = "NUMERO", _Relacion = "", _Empresa = true });
269 
270  return new List<string>() { "asiento", "fecha", "descripcion" };
271  }
272  }
273 
278  public override void _SetColumnCaptions(Dictionary<string, string> tldTranslate = null)
279  {
280  Dictionary<string, string> ldTranslate = new Dictionary<string, string>();
281 
282  ldTranslate.Add("asiento", "Asiento");
283  ldTranslate.Add("fecha", "Fecha");
284  ldTranslate.Add("descripcion", "Descripción");
285 
286  base._SetColumnCaptions(ldTranslate);
287  }
288 
293  public override void _SetColumnWidth(Dictionary<string, int> tldTranslate = null)
294  {
295  Dictionary<string, int> ldTranslate = new Dictionary<string, int>();
296 
297 
298  ldTranslate.Add("descripcion", 2000);
299 
300  base._SetColumnWidth(ldTranslate);
301  }
302 
306  public override Dictionary<string, string> _NavigateButtons
307  {
308  get
309  {
310  return new Dictionary<string, string>() { { "Asiento", "Ver asiento" } };
311  }
312  set
313  {
314  base._NavigateButtons = value;
315  }
316  }
317 
323  public override void _Navigate(String tcKeyNavigate, DataRow trRow)
324  {
325  if (trRow == null)
326  return;
327 
328  switch (tcKeyNavigate)
329  {
330  case "Asiento":
331  string lcAsiento = Convert.ToString(trRow["asiento"]);
332 
333  if (!string.IsNullOrWhiteSpace(lcAsiento))
334  {
335  _Navegar(sage.ew.listados.Clases.Listados.Pantalla.Asientos, new List<string>() { lcEmpresa, lcAsiento });
336  }
337  break;
338  }
339  }
340 
341  #endregion Overrides
342 
343  #region Métodos privados
344 
348  protected void _AsientosDescuadrados()
349  {
350  DataTable lDtTempAsientosDescuadrados = new DataTable();
351  String lsQueryAsientosDescuadrados = "SELECT numero, MAX(fecha) as fecha, ABS(SUM(DEBE)-SUM(HABER)) as saldo" +
352  " FROM " + DB.SQLDatabase("Gestion", "Asientos") +
353  " WHERE empresa= " + DB.SQLString(lcEmpresa);
354  lsQueryAsientosDescuadrados += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "", "fecha");
355  lsQueryAsientosDescuadrados += " GROUP BY numero";
356  lsQueryAsientosDescuadrados += string.Format(" HAVING ROUND( ABS(SUM(DEBE)-SUM(HABER)), {0}) > 0.00", Convert.ToInt32(EW_GLOBAL._GetVariable("wn_decimales")));
357 
358  DB.SQLExec(lsQueryAsientosDescuadrados, ref lDtTempAsientosDescuadrados);
359  if (lDtTempAsientosDescuadrados != null && lDtTempAsientosDescuadrados.Rows.Count > 0)
360  {
361  foreach (DataRow r in lDtTempAsientosDescuadrados.Rows)
362  {
363  dtResultadoRevision.Rows.Add(r["numero"], r["fecha"], "Asiento descuadrado");
364  }
365  }
366  lDtTempAsientosDescuadrados.Clear();
367 
368  // Revisión en multidivisa
369  if (llDivisaConta)
370  {
371  lsQueryAsientosDescuadrados = "SELECT numero, MAX(fecha) as fecha, ABS(SUM(DEBEDIV)-SUM(HABERDIV)) as saldo" +
372  " FROM " + DB.SQLDatabase("Gestion", "Asientos") +
373  " WHERE empresa= " + DB.SQLString(lcEmpresa);
374  lsQueryAsientosDescuadrados += " AND divisa != " + DB.SQLString(lcMoneda);
375  lsQueryAsientosDescuadrados += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "", "fecha");
376  lsQueryAsientosDescuadrados += " GROUP BY numero";
377  lsQueryAsientosDescuadrados += string.Format(" HAVING ROUND( ABS(SUM(DEBEDIV)-SUM(HABERDIV)), {0}) > 0.00", Convert.ToInt32(EW_GLOBAL._GetVariable("wn_decimales")));
378 
379  DB.SQLExec(lsQueryAsientosDescuadrados, ref lDtTempAsientosDescuadrados);
380  if (lDtTempAsientosDescuadrados != null && lDtTempAsientosDescuadrados.Rows.Count > 0)
381  {
382  foreach (DataRow r in lDtTempAsientosDescuadrados.Rows)
383  {
384  if (!_AsientoMultidivisa(r))
385  dtResultadoRevision.Rows.Add(r["numero"], r["fecha"], "Asiento descuadrado en multidivisa");
386  }
387  }
388  lDtTempAsientosDescuadrados.Clear();
389  }
390  }
391 
395  protected void _AsientosSinCuentaContable()
396  {
397  DataTable lDtAsientosSinCuentaContable = new DataTable();
398  String lsQueryAsientosSinCuentaContable = "SELECT distinct(numero) AS numero, fecha" +
399  " FROM " + DB.SQLDatabase("Gestion", "Asientos") +
400  " WHERE empresa= " + DB.SQLString(lcEmpresa) +
401  " AND cuenta = " + DB.SQLString(new String(' ', lnDigito3)) + " ";
402  lsQueryAsientosSinCuentaContable += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "", "fecha");
403 
404  DB.SQLExec(lsQueryAsientosSinCuentaContable, ref lDtAsientosSinCuentaContable);
405  if (lDtAsientosSinCuentaContable != null && lDtAsientosSinCuentaContable.Rows.Count > 0)
406  {
407  foreach (DataRow r in lDtAsientosSinCuentaContable.Rows)
408  {
409  dtResultadoRevision.Rows.Add(r["numero"], r["fecha"], "Apunte sin cuenta contable");
410  }
411  }
412  lDtAsientosSinCuentaContable.Clear();
413  }
414 
418  protected void _AsientosVerificarCuentas()
419  {
420  DataTable lDtAsientosVerificarCuentas = new DataTable();
421  String lsQueryAsientosVerificarCuentas = "SELECT a.numero, a.fecha, a.cuenta" +
422  " FROM " + DB.SQLDatabase("Gestion", "Asientos") + " a " +
423  " LEFT JOIN " + DB.SQLDatabase("Gestion", "Cuentas") + " b ON a.CUENTA = b.CODIGO " +
424  " WHERE a.empresa= " + DB.SQLString(lcEmpresa) +
425  " AND a.cuenta != " + DB.SQLString(new String(' ', lnDigito3)) + " " +
426  " and b.CODIGO IS NULL ";
427 
428  lsQueryAsientosVerificarCuentas += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "a", "fecha");
429 
430  DB.SQLExec(lsQueryAsientosVerificarCuentas, ref lDtAsientosVerificarCuentas);
431  if (lDtAsientosVerificarCuentas != null && lDtAsientosVerificarCuentas.Rows.Count > 0)
432  {
433  foreach (DataRow r in lDtAsientosVerificarCuentas.Rows)
434  {
435  // PE-105203
436  if (r["cuenta"] != null && !String.IsNullOrWhiteSpace(r["cuenta"].ToString()))
437  {
438  dtResultadoRevision.Rows.Add(
439  r["numero"],
440  r["fecha"],
441  String.Format("Cuenta {0} inexistente.", r["cuenta"]));
442  }
443  }
444  }
445  lDtAsientosVerificarCuentas.Clear();
446  }
447 
454  protected void _AsientosVerificarPlanesAnaliticos(bool importeSuperior, bool importeInferior, bool sinSecundaria)
455  {
456  DataTable lDtCurContInex = new DataTable("CurContInex");
457  String lsQueryCurContInex = "SELECT a.NUMERO, a.CUENTA, a.FECHA, a.DEBE, a.HABER, a.DEBEDIV, a.HABERDIV, a.ASI " +
458  " FROM " + DB.SQLDatabase("Gestion", "Asientos") + " a " +
459  " INNER JOIN " + DB.SQLDatabase("Gestion", "Cuentas") + " c ON a.cuenta = c.codigo AND secundaria<>'' AND secundaria<>'N' " +
460  " WHERE empresa= " + DB.SQLString(lcEmpresa);
461 
462  lsQueryCurContInex += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "", "fecha");
463  DB.SQLExec(lsQueryCurContInex, ref lDtCurContInex);
464  lDtCurContInex.TableName = "CurContInex";
465 
466  if (lDtCurContInex != null && lDtCurContInex.Rows.Count > 0)
467  {
468  // verificar que el total de las cuentas secundarias coincida con el total del DEBE+HABER
469  DataTable lDtCurOtrasien = new DataTable("CurOtrasien");
470  String lsQueryCurOtrasien = "SELECT ASI,SUM(DEBE+HABER) AS TOT,SUM(DEBEDIV+HABERDIV) AS TOTDIV " +
471  " FROM " + DB.SQLDatabase("Gestion", "Otrasien") +
472  " WHERE empresa= " + DB.SQLString(lcEmpresa) +
473  " GROUP BY ASI,PLANCONT ";
474  DB.SQLExec(lsQueryCurOtrasien, ref lDtCurOtrasien);
475  lDtCurOtrasien.TableName = "CurOtrasien";
476 
477  // Verificando los importes menor y mayor
478  if (importeInferior || importeSuperior)
479  {
480  // Hacemos el join con linq sobre las dos datatables anteriores.
481  var results = (from table1 in lDtCurContInex.AsEnumerable()
482  join table2 in lDtCurOtrasien.AsEnumerable() on (String)table1["ASI"] equals (String)table2["ASI"]
483  select new
484  {
485  numero = Convert.ToInt32(table1["NUMERO"]),
486  cuenta = table1["CUENTA"].ToString(),
487  fecha = Convert.ToDateTime(table1["FECHA"]),
488  debe = Convert.ToDecimal(table1["DEBE"]),
489  haber = Convert.ToDecimal(table1["HABER"]),
490  tot = Convert.ToDecimal(table2["TOT"]),
491  debediv = Convert.ToDecimal(table1["DEBEDIV"]),
492  haberdiv = Convert.ToDecimal(table1["HABERDIV"]),
493  totdiv = Convert.ToDecimal(table2["TOTDIV"])
494  }).__CopyToDataTable();
495 
496  if (results != null)
497  {
498  foreach (DataRow r in results.Rows)
499  {
500  if (!_lTodacuen || (_lTodacuen && Convert.ToDecimal(r["tot"]) != 0)) // Si tenemos activado la opción de todas la cuentas pero hay importe en la secundaria avisamos =mente...
501  {
502  // Importe superior en cuentas secundarias
503  if (importeSuperior && (Convert.ToDecimal(r["tot"]) > (Convert.ToDecimal(r["debe"]) + Convert.ToDecimal(r["haber"]))))
504  {
505  dtResultadoRevision.Rows.Add(
506  r["numero"],
507  r["fecha"],
508  "Importe en planes analíticos superior que el valor de la cuenta " + r["cuenta"].ToString());
509  }
510  // Importe inferior en cuentas secundarias
511  else if (importeInferior && (Convert.ToDecimal(r["tot"]) < (Convert.ToDecimal(r["debe"]) + Convert.ToDecimal(r["haber"]))))
512  {
513  dtResultadoRevision.Rows.Add(
514  r["numero"],
515  r["fecha"],
516  "Importe en planes analíticos inferior que el valor de la cuenta " + r["cuenta"].ToString());
517  }
518  }
519 
520  if (llDivisaConta && !_AsientoMultidivisa(r) && (!_lTodacuen || (_lTodacuen && Convert.ToDecimal(r["totdiv"]) != 0))) // Si tenemos activado la opción de todas la cuentas pero hay importe en la secundaria avisamos =mente...
521  {
522  // Importe superior en cuentas secundarias
523  if (importeSuperior && (Convert.ToDecimal(r["totdiv"]) > (Convert.ToDecimal(r["debediv"]) + Convert.ToDecimal(r["haberdiv"]))))
524  {
525  dtResultadoRevision.Rows.Add(
526  r["numero"],
527  r["fecha"],
528  "Importe en divisa en planes analíticos superior que el valor de la cuenta " + r["cuenta"].ToString());
529  }
530  // Importe inferior en cuentas secundarias
531  else if (importeInferior && (Convert.ToDecimal(r["totdiv"]) < (Convert.ToDecimal(r["debediv"]) + Convert.ToDecimal(r["haberdiv"]))))
532  {
533  dtResultadoRevision.Rows.Add(
534  r["numero"],
535  r["fecha"],
536  "Importe en divisa en planes analíticos inferior que el valor de la cuenta " + r["cuenta"].ToString());
537  }
538  }
539  }
540  }
541 
542  }
543 
544 
545  // verificar que el total de la cuenta secundaria de nivel 2 sume el total del nivel 1
546  DataTable lDtCurOtrasienNivel1 = new DataTable("CurOtrasien");
547  String lsQueryCurOtrasienNivel1 = "SELECT PLANCONT, SECUNDAR, ASI, " +
548  " SUM(DEBE+HABER) AS TOTALN2, MAX(DEBEAGRUP+HABERAGRUP) AS TOTALN1, " +
549  " SUM(DEBEDIV+HABERDIV) AS TOTALN2DIV, MAX(DEBEAGRUPDIV+HABERAGRUPDIV) AS TOTALN1DIV " +
550  " FROM " + DB.SQLDatabase("Gestion", "Otrasien") +
551  " WHERE empresa= " + DB.SQLString(lcEmpresa) +
552  " GROUP BY ASI,PLANCONT,SECUNDAR ";
553 
554  DB.SQLExec(lsQueryCurOtrasienNivel1, ref lDtCurOtrasienNivel1);
555  lDtCurOtrasien.TableName = "CurOtrasienNivel1";
556 
557  // Verificando los importes menor y mayor
558  if (importeInferior || importeSuperior)
559  {
560  // Hacemos el join con linq sobre las dos datatables anteriores.
561  var results = (from table1 in lDtCurContInex.AsEnumerable()
562  join table2 in lDtCurOtrasienNivel1.AsEnumerable() on (String)table1["ASI"] equals (String)table2["ASI"]
563  select new
564  {
565  numero = Convert.ToInt32(table1["NUMERO"]),
566  cuenta = table1["CUENTA"].ToString(),
567  fecha = Convert.ToDateTime(table1["FECHA"]),
568  plancont = Convert.ToString(table2["PLANCONT"]),
569  secundar = Convert.ToString(table2["SECUNDAR"]),
570  totaln1 = Convert.ToDecimal(table2["TOTALN1"]),
571  totaln2 = Convert.ToDecimal(table2["TOTALN2"]),
572  totaln1div = Convert.ToDecimal(table2["TOTALN1DIV"]),
573  totaln2div = Convert.ToDecimal(table2["TOTALN2DIV"])
574  }).__CopyToDataTable();
575 
576  if (results != null)
577  {
578  foreach (DataRow r in results.Rows)
579  {
580  // Importe superior en cuentas secundarias
581  if (importeSuperior && (Convert.ToDecimal(r["totaln1"]) > Convert.ToDecimal(r["totaln2"])))
582  {
583  dtResultadoRevision.Rows.Add(
584  r["numero"],
585  r["fecha"],
586  String.Format("Importe en plan analítico {0} de N1 {1} inferior que el valor de N2 para la cuenta {2} ", r["plancont"].ToString(), r["secundar"].ToString(), r["cuenta"].ToString()));
587  }
588  // Importe inferior en cuentas secundarias
589  else if (importeInferior && (Convert.ToDecimal(r["totaln1"]) > Convert.ToDecimal(r["totaln2"])))
590  {
591  dtResultadoRevision.Rows.Add(
592  r["numero"],
593  r["fecha"],
594  String.Format("Importe en plan analítico {0} de N1 {1} superior que el valor de N2 para la cuenta {2} ", r["plancont"].ToString(), r["secundar"].ToString(), r["cuenta"].ToString()));
595  }
596 
597  if (llDivisaConta && !_AsientoMultidivisa(r))
598  {
599  // Importe superior en cuentas secundarias
600  if (importeSuperior && (Convert.ToDecimal(r["totaln1div"]) > Convert.ToDecimal(r["totaln2div"])))
601  {
602  dtResultadoRevision.Rows.Add(
603  r["numero"],
604  r["fecha"],
605  String.Format("Importe en divisa en plan analítico {0} de N1 {1} inferior que el valor de N2 para la cuenta {2} ", r["plancont"].ToString(), r["secundar"].ToString(), r["cuenta"].ToString()));
606  }
607  // Importe inferior en cuentas secundarias
608  else if (importeInferior && (Convert.ToDecimal(r["totaln1div"]) < Convert.ToDecimal(r["totaln2div"])))
609  {
610  dtResultadoRevision.Rows.Add(
611  r["numero"],
612  r["fecha"],
613  String.Format("Importe en divisa en plan analítico {0} de N1 {1} superior que el valor de N2 para la cuenta {2} ", r["plancont"].ToString(), r["secundar"].ToString(), r["cuenta"].ToString()));
614  }
615  }
616  }
617  }
618 
619  }
620  // Verificando apuntes sin cuentas secundarias
621  if (sinSecundaria && !_lTodacuen)
622  {
623  var results = (from table1 in lDtCurContInex.AsEnumerable()
624  where (Convert.ToInt32(table1["DEBE"]) != 0) || (Convert.ToInt32(table1["HABER"]) != 0)
625  join table2 in lDtCurOtrasien.AsEnumerable()
626  on new
627  {
628  asi = table1.Field<string>("ASI")
629  }
630  equals new
631  {
632  asi = table2.Field<string>("ASI")
633  }
634  into leftJoin
635  from c in leftJoin.DefaultIfEmpty()
636  where (c != null ? false : true)
637  select new
638  {
639  numero = Convert.ToInt32(table1["NUMERO"]),
640  cuenta = table1["CUENTA"].ToString(),
641  fecha = Convert.ToDateTime(table1["FECHA"]),
642  debe = Convert.ToDecimal(table1["DEBE"]),
643  haber = Convert.ToDecimal(table1["HABER"])
644  }).__CopyToDataTable();
645 
646  if (results != null)
647  {
648  foreach (DataRow r in results.Rows)
649  {
650  dtResultadoRevision.Rows.Add(
651  r["numero"],
652  r["fecha"],
653  String.Format("Cuenta {0} sin planes analíticos.", r["cuenta"].ToString()));
654  }
655  }
656 
657  if (llDivisaConta)
658  {
659  var resultsdiv = (from table1 in lDtCurContInex.AsEnumerable()
660  where (Convert.ToInt32(table1["DEBEDIV"]) != 0) || (Convert.ToInt32(table1["HABERDIV"]) != 0)
661  join table2 in lDtCurOtrasien.AsEnumerable()
662  on new
663  {
664  asi = table1.Field<string>("ASI")
665  }
666  equals new
667  {
668  asi = table2.Field<string>("ASI")
669  }
670  into leftJoin
671  from c in leftJoin.DefaultIfEmpty()
672  where (c != null ? false : true)
673  select new
674  {
675  numero = Convert.ToInt32(table1["NUMERO"]),
676  cuenta = table1["CUENTA"].ToString(),
677  fecha = Convert.ToDateTime(table1["FECHA"]),
678  debe = Convert.ToDecimal(table1["DEBEDIV"]),
679  haber = Convert.ToDecimal(table1["HABERDIV"])
680  }).__CopyToDataTable();
681 
682  if (resultsdiv != null)
683  {
684  foreach (DataRow r in results.Rows)
685  {
686  dtResultadoRevision.Rows.Add(
687  r["numero"],
688  r["fecha"],
689  String.Format("Cuenta {0} sin planes analíticos.", r["cuenta"].ToString()));
690  }
691  }
692  }
693  }
694 
695  // Revisar secundarias en OTRASIEN
696  DataTable lDtCurAnalitica = new DataTable("CurAnalitica");
697  String lsQueryCurAnalitica = "SELECT A.ASI,A.PLANCONT,A.SECUNDAR,A.SECNIVEL2 " +
698  " FROM " + DB.SQLDatabase("Gestion", "Otrasien") + " A " +
699  " LEFT JOIN " + DB.SQLDatabase("Gestion", "Secundar") + " AS S1 ON A.SECUNDAR = S1.CODIGO AND S1.NIVEL = 1 " +
700  " LEFT JOIN " + DB.SQLDatabase("Gestion", "Secundar") + " AS S2 ON A.SECNIVEL2 = S2.CODIGO AND S2.NIVEL = 2 " +
701  " WHERE A.empresa= " + DB.SQLString(lcEmpresa) +
702  " AND (A.SECUNDAR != " + DB.SQLNvl("S1.CODIGO", DB.SQLString("")) +
703  " OR A.SECNIVEL2 != " + DB.SQLNvl("S2.CODIGO", DB.SQLString("")) + " ) ";
704 
705  DB.SQLExec(lsQueryCurAnalitica, ref lDtCurAnalitica);
706  lDtCurOtrasien.TableName = "CurAnalitica";
707 
708  // verificar que la cuenta asignada en OTRASIEN exista
709  var lDtAnalitica = (from a in lDtCurContInex.AsEnumerable()
710  join b in lDtCurAnalitica.AsEnumerable()
711  on new
712  {
713  asi = a.Field<string>("asi")
714  }
715  equals new
716  {
717  asi = b.Field<string>("asi")
718  }
719 
720  select new
721  {
722  numero = a.Field<int>("numero"),
723  cuenta = a.Field<string>("cuenta"),
724  fecha = a.Field<DateTime>("fecha"),
725  secundar = b.Field<string>("secundar"),
726  secnivel2 = b.Field<string>("secnivel2")
727  }).__CopyToDataTable();
728 
729 
730  if (lDtAnalitica != null)
731  {
732  foreach (DataRow r in lDtAnalitica.Rows)
733  {
734  dtResultadoRevision.Rows.Add(
735  r["numero"],
736  r["fecha"],
737  String.Format("Cuenta {0} tiene definido el nivel analítico {1} que no existe.", r["cuenta"], string.IsNullOrWhiteSpace(r["secnivel2"].ToString()) ? r["secundar"] : r["secnivel2"]));
738  }
739  }
740 
741  // Revisar las cuentas contables en OTRASIEN
742  lDtCurAnalitica = new DataTable("CurAnalitica");
743  lsQueryCurAnalitica = "SELECT A.ASI,A.CODCUEN, " + DB.SQLNvl("C.CODIGO", DB.SQLString("")) + " as CODCUEN2 " +
744  " FROM " + DB.SQLDatabase("Gestion", "Otrasien") + " A " +
745  " LEFT JOIN " + DB.SQLDatabase("Gestion", "Cuentas") + " AS C ON A.CODCUEN = C.CODIGO " +
746  " WHERE A.empresa= " + DB.SQLString(lcEmpresa);
747 
748  DB.SQLExec(lsQueryCurAnalitica, ref lDtCurAnalitica);
749  lDtCurOtrasien.TableName = "CurAnalitica";
750 
751  // verificar que la cuenta asignada en OTRASIEN exista
752  var lDtAnalitica2 = (from a in lDtCurContInex.AsEnumerable()
753  join b in lDtCurAnalitica.AsEnumerable()
754  on new
755  {
756  asi = a.Field<string>("asi")
757  }
758  equals new
759  {
760  asi = b.Field<string>("asi")
761  }
762 
763  select new
764  {
765  numero = a.Field<int>("numero"),
766  cuenta = a.Field<string>("cuenta"),
767  fecha = a.Field<DateTime>("fecha"),
768  codcuen = b.Field<string>("codcuen"),
769  codcuen2 = b.Field<string>("codcuen2")
770  }).__CopyToDataTable();
771 
772 
773  if (lDtAnalitica2 != null)
774  {
775  foreach (DataRow r in lDtAnalitica2.Rows)
776  {
777  if (string.IsNullOrWhiteSpace(Convert.ToString(r["codcuen2"])))
778  {
779  dtResultadoRevision.Rows.Add(
780  r["numero"],
781  r["fecha"],
782  String.Format("Cuenta {0} inexistente definida en niveles analíticos.", r["codcuen"]));
783  }
784  else if (Convert.ToString(r["codcuen"]) != Convert.ToString(r["cuenta"]))
785  {
786  dtResultadoRevision.Rows.Add(
787  r["numero"],
788  r["fecha"],
789  String.Format("Cuenta {0} no coincide con la cuenta {1} definida en niveles analíticos.", r["cuenta"], r["codcuen"]));
790  }
791  }
792  }
793  }
794  }
795 
799  protected void _AsientosSinIva()
800  {
801  DataTable lDtAsientosSinIva = new DataTable();
802  string lsAsientos = DB.SQLDatabase("Gestion","Asientos");
803 
804  // IVA Repercutido
805  String lsDigito3IvaRepercutido = Convert.ToString(EW_GLOBAL._GetVariable("wc_IvaRep"));
806 
807  lsDigito3IvaRepercutido = lsDigito3IvaRepercutido.Substring(0, lnDigito3);
808 
809  String lsQueryAsientosSinIva = "SELECT a.numero,a.cuenta,a.fecha" +
810  " FROM " + DB.SQLDatabase("Gestion","Asientos") + " A INNER JOIN " + DB.SQLDatabase("Gestion","Tipo_iva") + " B ON A.CUENTA=B.CTA_IV_REP " +
811  " WHERE A.empresa= " + DB.SQLString(lcEmpresa) +
812  " AND LEFT(A.cuenta, " + lnDigito3 + ")='" + lsDigito3IvaRepercutido + "' " +
813  " AND A.tipo = '0' " +
814  " AND A.PROVEEDOR<>'LIQUIDAR' " +
815  " AND A.TIPO_MOV <> 8 " +
816  " AND A.TIPO_MOV <> 29 ";
817  lsQueryAsientosSinIva += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "A", "fecha");
818  lsQueryAsientosSinIva += " AND A.ASI NOT IN(";
819  lsQueryAsientosSinIva += " SELECT i.asi ";
820  lsQueryAsientosSinIva += " FROM " + DB.SQLDatabase("Gestion", "Ivareper") + " i ";
821  lsQueryAsientosSinIva += ") ";
822 
823  // Customer Change Request 170452:En un asiento con una cuenta de IVA, no informamos del desglose de ese IVA los datos de la factura. Se realizamos una revisión de asientos o de IVA no detecta ese error.
824  // Comentado con Jordi Salamó no vemos para que es la parte de abajo comentada. Con la primera select salen los registros que no están en ivareper y abajo ivasopor
825 
826  //string lsDigito2Iva = lsDigito3IvaRepercutido.Substring(0,2);
827 
828  //lsQueryAsientosSinIva += " AND A.NUMERO NOT IN( SELECT P1.NUMERO FROM " + lsAsientos + " P1 WHERE empresa= " + DB.SQLString(lcEmpresa) + " AND LEFT(CUENTA, 2 )='" + lsDigito2Iva +"' GROUP BY P1.NUMERO " +
829  // "HAVING COUNT (*) = ( SELECT COUNT(*) FROM " + lsAsientos +
830  // " WHERE empresa= " + DB.SQLString(lcEmpresa) + " AND NUMERO = P1.NUMERO AND LEFT(CUENTA, 2 )='" + lsDigito2Iva + "' AND TRIM(FACTURA) = ''))"; // = ''
831 
832 
833  DB.SQLExec(lsQueryAsientosSinIva, ref lDtAsientosSinIva);
834  if (lDtAsientosSinIva != null && lDtAsientosSinIva.Rows.Count > 0)
835  {
836  foreach(DataRow r in lDtAsientosSinIva.Rows)
837  {
838  dtResultadoRevision.Rows.Add(
839  r["numero"],
840  r["fecha"],
841  String.Format("Cuenta de {0} {1}, no anotada en el libro registro de {2} REPERCUTIDO.", lcIva, r["cuenta"], lcIva));
842  }
843  }
844  lDtAsientosSinIva.Clear();
845 
846  // IVA Soportado
847  String lsDigito3IvaSoportado = Convert.ToString(EW_GLOBAL._GetVariable("wc_IvaSop"));
848  lsDigito3IvaSoportado = lsDigito3IvaSoportado.Substring(0, lnDigito3);
849  lsQueryAsientosSinIva = "SELECT a.numero,a.cuenta,a.fecha" +
850  " FROM " + DB.SQLDatabase("Gestion","Asientos") + " A INNER JOIN " + DB.SQLDatabase("Gestion", "Tipo_iva") + " B ON A.CUENTA=B.CTA_IV_SOP " +
851  " WHERE A.empresa= " + DB.SQLString(lcEmpresa) +
852  " AND LEFT(A.cuenta, " + lnDigito3 + ")='" + lsDigito3IvaSoportado + "' " +
853  " AND A.tipo = '0' " +
854  " AND A.PROVEEDOR<>'LIQUIDAR' " +
855  " AND A.TIPO_MOV <> 9 " +
856  " AND A.TIPO_MOV <> 29 ";
857  lsQueryAsientosSinIva += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "A", "fecha");
858  lsQueryAsientosSinIva += " AND A.ASI NOT IN(";
859  lsQueryAsientosSinIva += " SELECT i.asi ";
860  lsQueryAsientosSinIva += " FROM " + DB.SQLDatabase("Gestion","Ivasopor") + " i ";
861  lsQueryAsientosSinIva += ")" ;
862 
863  // Customer Change Request 170452:En un asiento con una cuenta de IVA, no informamos del desglose de ese IVA los datos de la factura. Se realizamos una revisión de asientos o de IVA no detecta ese error.
864  // Comentado con Jordi Salamó no vemos para que es la parte de abajo comentada. Con la primera select salen los registros que no están en ivareper y abajo ivasopor
865 
866  //lsQueryAsientosSinIva += " AND A.NUMERO NOT IN( SELECT P1.NUMERO FROM " + lsAsientos + " P1 WHERE empresa= " + DB.SQLString(lcEmpresa) + " AND LEFT(CUENTA, 2 )='" + lsDigito2Iva + "' GROUP BY P1.NUMERO " +
867  // "HAVING COUNT (*) = ( SELECT COUNT(*) FROM " + lsAsientos +
868  // " WHERE empresa= " + DB.SQLString(lcEmpresa) + " AND NUMERO = P1.NUMERO AND LEFT(CUENTA, 2 )='" + lsDigito2Iva + "' AND TRIM(FACTURA) = ''))"; // = ''
869 
870  DB.SQLExec(lsQueryAsientosSinIva, ref lDtAsientosSinIva);
871  if (lDtAsientosSinIva != null && lDtAsientosSinIva.Rows.Count > 0)
872  {
873  foreach (DataRow r in lDtAsientosSinIva.Rows)
874  {
875  dtResultadoRevision.Rows.Add(
876  r["numero"],
877  r["fecha"],
878  String.Format("Cuenta de {0} {1}, no anotada en el libro registro de {2} SOPORTADO.", lcIva, r["cuenta"], lcIva));
879  }
880  }
881  lDtAsientosSinIva.Clear();
882  }
883 
889  protected void _AsientosVerificarIvaRepercutido(bool cuentaDiferente, bool importeDiferente)
890  {
891  DataTable lDtAsientosIvaRepercutido = new DataTable();
892 
893  String lsDigito3IvaRepercutido = Convert.ToString(EW_GLOBAL._GetVariable("wc_IvaRep"));
894  lsDigito3IvaRepercutido = lsDigito3IvaRepercutido.Substring(0, lnDigito3);
895 
896  String lsQueryAsientosIvaRepercutido = "SELECT A.NUMERO,A.FECHA,A.DEBE,A.HABER,A.DEBEDIV,A.HABERDIV,C.CUENTA,C.ASI,C.IVA,C.BIMPO,C.IVADIV,C.BIMPODIV,C.PORCEN_IVA, a.cuenta as cuentaiva " +
897  " FROM (( " + DB.SQLDatabase("Gestion", "Asientos") + " A " +
898  " INNER JOIN " + DB.SQLDatabase("Gestion", "Tipo_iva") + " B ON A.CUENTA =B.CTA_IV_REP ) " +
899  " INNER JOIN " + DB.SQLDatabase("Gestion", "Ivareper") + " C ON A.EMPRESA=C.EMPRESA AND A.ASI=C.ASI) " +
900  " WHERE A.empresa= " + DB.SQLString(lcEmpresa) +
901  " AND LEFT(A.cuenta, " + lnDigito3 + ")='" + lsDigito3IvaRepercutido + "' " +
902  " AND A.tipo = '0' " +
903  " AND A.PROVEEDOR<>'LIQUIDAR' " +
904  " AND A.TIPO_MOV <> 29 ";
905  lsQueryAsientosIvaRepercutido += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "A", "fecha");
906 
907  DB.SQLExec(lsQueryAsientosIvaRepercutido, ref lDtAsientosIvaRepercutido);
908  if (lDtAsientosIvaRepercutido != null && lDtAsientosIvaRepercutido.Rows.Count > 0)
909  {
910  DataTable lDtCtaDiferente = new DataTable();
911  DB.SQLExec("SELECT NUMERO, FECHA, CUENTA FROM " + DB.SQLDatabase("Gestion", "Asientos"), ref lDtCtaDiferente);
912 
913  String lsCuentaIva = string.Empty;
914  bool lbDiferImpIva = false;
915  bool lbDiferImpIvaDiv = false;
916  DataRow[] ldrItems;
917  string lcCondicion = string.Empty;
918 
919  foreach (DataRow r in lDtAsientosIvaRepercutido.Rows)
920  {
921  lbDiferImpIva = false;
922  lbDiferImpIvaDiv = false;
923 
924  lsCuentaIva = r["CUENTA"].ToString();
925 
926  if (Convert.ToDecimal(r["IVA"]) != ( Convert.ToDecimal(r["HABER"]) - Convert.ToDecimal(r["DEBE"])))
927  {
928  lbDiferImpIva = true;
929  }
930 
931  if (llDivisaConta && !_AsientoMultidivisa(r) && Convert.ToDecimal(r["IVADIV"]) != (Convert.ToDecimal(r["HABERDIV"]) - Convert.ToDecimal(r["DEBEDIV"])))
932  {
933  lbDiferImpIvaDiv = true;
934  }
935 
936  // Cuenta de IVA diferente de asiento.
937  if (cuentaDiferente )
938  {
939 
940  lcCondicion = "NUMERO = " + DB.SQLString(r["NUMERO"]) + " AND CUENTA = " + DB.SQLString(lsCuentaIva);
941  ldrItems = lDtCtaDiferente.Select(lcCondicion);
942 
943  if (ldrItems != null && ldrItems.Length == 0)
944  {
945  dtResultadoRevision.Rows.Add(
946  r["NUMERO"],
947  r["FECHA"],
948  String.Format("Cuenta del registro de {0} REPERCUTIDO diferente de la del asiento.", lcIva));
949  }
950  }
951 
952  // Importe de IVA diferente
953  if (importeDiferente && lbDiferImpIva)
954  {
955  String lsTxtDiferencia = "Diferencias en importes: el importe de la cuenta " + Convert.ToString(r["cuentaiva"]) + " es diferente al registro de IVA repercutido";
956 
957  dtResultadoRevision.Rows.Add(
958  r["NUMERO"],
959  r["FECHA"],
960  lsTxtDiferencia);
961  }
962 
963  // Importe Divisa de IVA diferente
964  if (llDivisaConta && importeDiferente && lbDiferImpIvaDiv)
965  {
966  String lsTxtDiferencia = "Diferencias en importes: el importe en divisa de la cuenta " + Convert.ToString(r["cuentaiva"]) + " es diferente al registro de IVA repercutido";
967 
968  dtResultadoRevision.Rows.Add(
969  r["NUMERO"],
970  r["FECHA"],
971  lsTxtDiferencia);
972  }
973  }
974  lDtCtaDiferente.Clear();
975  lDtAsientosIvaRepercutido.Clear();
976  }
977  }
978 
984  protected void _AsientosVerificarIvaSoportado(bool cuentaDiferente, bool importeDiferente)
985  {
986  DataTable lDtAsientosIvaSoportado = new DataTable();
987 
988  String lsDigito3IvaSoportado = Convert.ToString(EW_GLOBAL._GetVariable("wc_IvaSop"));
989  lsDigito3IvaSoportado = lsDigito3IvaSoportado.Substring(0, lnDigito3);
990 
991  String lsQueryAsientosIvaSoportado = "SELECT A.NUMERO,A.FECHA,A.DEBE,A.HABER,A.DEBEDIV,A.HABERDIV,C.CUENTA,C.ASI,C.IVA,C.BIMPO,C.IVADIV,C.BASEDIV,C.PORCEN_IVA, a.cuenta as cuentaiva " +
992  " FROM (( " + DB.SQLDatabase("Gestion", "Asientos") + " A INNER JOIN " + DB.SQLDatabase("Gestion", "Tipo_iva") + " B ON A.CUENTA=B.CTA_IV_SOP) " +
993  " INNER JOIN " + DB.SQLDatabase("Gestion", "Ivasopor") + " C ON A.EMPRESA=C.EMPRESA AND A.ASI=C.ASI) " +
994  " WHERE A.empresa= " + DB.SQLString(lcEmpresa) +
995  " AND LEFT(A.cuenta, " + lnDigito3 + ")='" + lsDigito3IvaSoportado + "' " +
996  " AND A.tipo = '0' " +
997  " AND A.OPERACION != 9 " +
998  " AND A.PROVEEDOR<>'LIQUIDAR' " +
999  " AND A.TIPO_MOV <> 29 ";
1000  lsQueryAsientosIvaSoportado += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "A", "fecha");
1001 
1002  DB.SQLExec(lsQueryAsientosIvaSoportado, ref lDtAsientosIvaSoportado);
1003  if (lDtAsientosIvaSoportado != null && lDtAsientosIvaSoportado.Rows.Count > 0)
1004  {
1005  DataTable lDtCtaDiferente = new DataTable();
1006  DB.SQLExec("SELECT NUMERO, FECHA, CUENTA FROM " + DB.SQLDatabase("Gestion", "Asientos"), ref lDtCtaDiferente);
1007 
1008  String lsCuentaIva = string.Empty;
1009  bool lbDiferImpIva = false;
1010  bool lbDiferImpIvaDiv = false;
1011  DataRow[] ldrItems;
1012  string lcCondicion = string.Empty;
1013 
1014  foreach (DataRow r in lDtAsientosIvaSoportado.Rows)
1015  {
1016  lbDiferImpIva = false;
1017  lbDiferImpIvaDiv = false;
1018 
1019  lsCuentaIva = r["CUENTA"].ToString();
1020 
1021  if (Convert.ToDecimal(r["IVA"]) != (Convert.ToDecimal(r["DEBE"]) - Convert.ToDecimal(r["HABER"])))
1022  {
1023  lbDiferImpIva = true;
1024  }
1025 
1026  if (llDivisaConta && Convert.ToDecimal(r["IVADIV"]) != (Convert.ToDecimal(r["DEBEDIV"]) - Convert.ToDecimal(r["HABERDIV"])))
1027  {
1028  lbDiferImpIvaDiv = true;
1029  }
1030 
1031  // Cuenta de IVA diferente de asiento.
1032  if (cuentaDiferente)
1033  {
1034  lcCondicion = "NUMERO = " + DB.SQLString(r["NUMERO"]) + " AND CUENTA = " + DB.SQLString(lsCuentaIva);
1035  ldrItems = lDtCtaDiferente.Select(lcCondicion);
1036 
1037  if (ldrItems != null && ldrItems.Length == 0)
1038  {
1039  dtResultadoRevision.Rows.Add(
1040  r["NUMERO"],
1041  r["FECHA"],
1042  String.Format("Cuenta del registro de {0} SOPORTADO diferente de la del asiento.", lcIva));
1043  }
1044  }
1045 
1046  // Importe de IVA diferente
1047  if (importeDiferente && lbDiferImpIva)
1048  {
1049  String lsTxtDiferencia = "Diferencias en importes: el importe de la cuenta " + Convert.ToString(r["cuentaiva"]) + " es diferente al registro de IVA soportado";
1050 
1051  dtResultadoRevision.Rows.Add(
1052  r["NUMERO"],
1053  r["FECHA"],
1054  lsTxtDiferencia);
1055  }
1056 
1057  // Importe Divisa de IVA diferente
1058  if (llDivisaConta && importeDiferente && lbDiferImpIvaDiv)
1059  {
1060  String lsTxtDiferencia = "Diferencias en importes: el importe en divisa de la cuenta " + Convert.ToString(r["cuentaiva"]) + " es diferente al registro de IVA soportado";
1061 
1062  dtResultadoRevision.Rows.Add(
1063  r["NUMERO"],
1064  r["FECHA"],
1065  lsTxtDiferencia);
1066  }
1067  }
1068 
1069  lDtCtaDiferente.Clear();
1070  lDtAsientosIvaSoportado.Clear();
1071  }
1072  }
1073 
1079  protected void _AsientosVerificarRetencion(bool retencionNoAnotada, bool importeRetencion)
1080  {
1081  DataTable lDtAsientosVerificarRetencion = new DataTable();
1082 
1083  String lsRetReper = Convert.ToString(EW_GLOBAL._GetVariable("wc_RetReper"));
1084  String lsRetSopor = Convert.ToString(EW_GLOBAL._GetVariable("wc_RetSopor"));
1085 
1086  String lsQueryAsientosVerificarRetencion = "SELECT numero, cuenta, fecha, debe, haber, debediv, haberdiv, factura, asi" +
1087  " FROM " + DB.SQLDatabase("Gestion", "Asientos") +
1088  " WHERE tipo='0' AND tipo_mov = 0 " +
1089  " AND empresa= " + DB.SQLString(lcEmpresa);
1090  lsQueryAsientosVerificarRetencion += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "", "fecha");
1091 
1092  DB.SQLExec(lsQueryAsientosVerificarRetencion, ref lDtAsientosVerificarRetencion);
1093  if (lDtAsientosVerificarRetencion != null && lDtAsientosVerificarRetencion.Rows.Count > 0)
1094  {
1095  String lsNombreTablaRetencion = String.Empty;
1096  bool lbIncidenciaRet = false;
1097 
1098  bool lbDiferenciaRet = false;
1099  bool lbDiferenciaRetDivisa = false;
1100  //DataRow[] ldrItems;
1101  string lcCondicion = string.Empty;
1102 
1103  foreach (DataRow r in lDtAsientosVerificarRetencion.Rows)
1104  {
1105  lbIncidenciaRet = false;
1106 
1107  lbDiferenciaRet = false;
1108  lbDiferenciaRetDivisa = false;
1109 
1110  if (
1111  (r["cuenta"].ToString().Substring(0, lnDigito4) == lsRetReper.Substring(0, lnDigito4)) ||
1112  (r["cuenta"].ToString().Substring(0, lnDigito4) == lsRetSopor.Substring(0, lnDigito4))
1113  )
1114  {
1115  if (r["cuenta"].ToString().Substring(0, lnDigito4) == lsRetReper.Substring(0, lnDigito4))
1116  {
1117  lcCondicion = "CTA_RE_REP = " + DB.SQLString(r["cuenta"]);
1118  lsNombreTablaRetencion = "RETREPER";
1119  }
1120  else
1121  {
1122  lcCondicion = "CTA_RE_SOP = " + DB.SQLString(r["cuenta"]);
1123  lsNombreTablaRetencion = "RETSOPOR";
1124  }
1125 
1126 
1127 
1128  String lsQueryExisteRetencion = "SELECT ASI, RETENCIO, RETDIV" +
1129  " FROM " + DB.SQLDatabase("Gestion", lsNombreTablaRetencion) +
1130  " WHERE empresa= " + DB.SQLString(lcEmpresa) +
1131  " AND ASI='" + r["ASI"] + "' ";
1132 
1133  DataTable lDtExisteRetencion = new DataTable();
1134  DB.SQLExec(lsQueryExisteRetencion, ref lDtExisteRetencion);
1135  if (lDtExisteRetencion != null && lDtExisteRetencion.Rows.Count > 0)
1136  {
1137  if (lsNombreTablaRetencion.CompareTo("RETREPER") == 0)
1138  {
1139  if (Convert.ToDecimal(lDtExisteRetencion.Rows[0]["RETENCIO"]) != Convert.ToDecimal(r["haber"]) - (Convert.ToDecimal(r["debe"])))
1140  {
1141  lbDiferenciaRet = true;
1142  }
1143  }
1144  else
1145  {
1146  if (Convert.ToDecimal(lDtExisteRetencion.Rows[0]["RETENCIO"]) != (Convert.ToDecimal(r["debe"]) - Convert.ToDecimal(r["haber"])))
1147  {
1148  lbDiferenciaRet = true;
1149  }
1150  }
1151 
1152 
1153  if (lsNombreTablaRetencion.CompareTo("RETREPER") == 0)
1154  {
1155  if (llDivisaConta && !_AsientoMultidivisa(r) && Convert.ToDecimal(lDtExisteRetencion.Rows[0]["RETDIV"]) != Convert.ToDecimal(r["haberdiv"]) - (Convert.ToDecimal(r["debediv"])))
1156  {
1157  lbDiferenciaRetDivisa = true;
1158  }
1159  }
1160  else
1161  {
1162  if (llDivisaConta && !_AsientoMultidivisa(r) && Convert.ToDecimal(lDtExisteRetencion.Rows[0]["RETDIV"]) != (Convert.ToDecimal(r["debediv"]) - Convert.ToDecimal(r["haberdiv"])))
1163  {
1164  lbDiferenciaRetDivisa = true;
1165  }
1166  }
1167  }
1168  else
1169  {
1170  lbIncidenciaRet = true;
1171  }
1172  lDtExisteRetencion.Clear();
1173 
1174 
1175  if (retencionNoAnotada && lbIncidenciaRet)
1176  {
1177  dtResultadoRevision.Rows.Add(
1178  r["NUMERO"],
1179  r["FECHA"],
1180  String.Format("Cuenta de Retención {0}, no anotada en el libro registro de Retenciones.", r["cuenta"]));
1181  }
1182 
1183  if (importeRetencion && lbDiferenciaRet)
1184  {
1185  dtResultadoRevision.Rows.Add(
1186  r["NUMERO"],
1187  r["FECHA"],
1188  "Importe del registro de Retenciones, diferente al del asiento.");
1189  }
1190 
1191  if (llDivisaConta && importeRetencion && lbDiferenciaRetDivisa)
1192  {
1193  dtResultadoRevision.Rows.Add(
1194  r["NUMERO"],
1195  r["FECHA"],
1196  "Importe en divisa del registro de Retenciones, diferente al del asiento.");
1197  }
1198  }
1199  }
1200  }
1201  lDtAsientosVerificarRetencion.Clear();
1202  }
1203 
1208  {
1209  DataTable lDtAsientosVerificarFechaPeriodo = new DataTable();
1210 
1211  String lsQueryAsientosVerificarFechaPeriodo = "SELECT DISTINCT numero,fecha " +
1212  " FROM " + DB.SQLDatabase("Gestion", "Asientos") +
1213  " WHERE empresa= " + DB.SQLString(lcEmpresa) +
1214  String.Format(" AND (fecha<'{0:dd/MM/yyyy}' OR fecha>'{1:dd/MM/yyy}') ", Convert.ToDateTime(EW_GLOBAL._GetVariable("wd_periodoini")), Convert.ToDateTime(EW_GLOBAL._GetVariable("wd_periodoFin")));
1215 
1216  DB.SQLExec(lsQueryAsientosVerificarFechaPeriodo, ref lDtAsientosVerificarFechaPeriodo);
1217  if (lDtAsientosVerificarFechaPeriodo != null && lDtAsientosVerificarFechaPeriodo.Rows.Count > 0)
1218  {
1219  foreach (DataRow r in lDtAsientosVerificarFechaPeriodo.Rows)
1220  {
1221  dtResultadoRevision.Rows.Add(
1222  r["NUMERO"],
1223  r["FECHA"],
1224  "Asiento con fecha fuera del período del ejercicio actual.");
1225  }
1226  }
1227  lDtAsientosVerificarFechaPeriodo.Clear();
1228  }
1229 
1234  protected void _AsientosVerificarRecargoRepercutido(bool importeDiferente)
1235  {
1236  DataTable lDtAsientosIvaRepercutido = new DataTable();
1237  DataTable lDtAsientosRecargoRepercutido = new DataTable();
1238 
1239  String lsDigito3IvaRepercutido = Convert.ToString(EW_GLOBAL._GetVariable("wc_IvaRep"));
1240  lsDigito3IvaRepercutido = lsDigito3IvaRepercutido.Substring(0, lnDigito3);
1241 
1242  String lsQueryAsientosIvaRepercutido = "SELECT A.NUMERO,A.FECHA,A.DEBE,A.HABER,A.DEBEDIV,A.HABERDIV,C.CUENTA,C.ASI,C.IVA,C.BIMPO,C.IVADIV,C.BIMPODIV,C.PORCEN_IVA, a.cuenta as cuentaiva, " +
1243  " C.TIPO_IVA, B.CTA_RE_REP, C.RECARGO, C.RECDIV " +
1244  " FROM (( " + DB.SQLDatabase("Gestion", "Asientos") + " A " +
1245  " INNER JOIN " + DB.SQLDatabase("Gestion", "Tipo_iva") + " B ON A.CUENTA =B.CTA_IV_REP ) " +
1246  " INNER JOIN " + DB.SQLDatabase("Gestion", "Ivareper") + " C ON A.EMPRESA=C.EMPRESA AND A.ASI=C.ASI) " +
1247  " WHERE A.empresa= " + DB.SQLString(lcEmpresa) +
1248  " AND LEFT(A.cuenta, " + lnDigito3 + ")='" + lsDigito3IvaRepercutido + "' " +
1249  " AND A.tipo = '0' " +
1250  " AND A.PROVEEDOR<>'LIQUIDAR' " +
1251  " AND A.TIPO_MOV <> 29 ";
1252  lsQueryAsientosIvaRepercutido += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "A", "fecha");
1253 
1254  DB.SQLExec(lsQueryAsientosIvaRepercutido, ref lDtAsientosIvaRepercutido);
1255  if (lDtAsientosIvaRepercutido != null && lDtAsientosIvaRepercutido.Rows.Count > 0)
1256  {
1257  DataTable dtMergeAsi = AgruparAsientosReper(lDtAsientosIvaRepercutido);
1258 
1259  foreach (DataRow r in lDtAsientosIvaRepercutido.Rows)
1260  {
1261  if (!string.IsNullOrEmpty(r["CTA_RE_REP"].ToString().Trim()) && (Convert.ToDecimal(r["RECARGO"]) != 0 || Convert.ToDecimal(r["RECDIV"]) != 0))
1262  {
1263  string lsCuentaRecargoRepercutido = r["CTA_RE_REP"].ToString();
1264  string lcNumero = r["NUMERO"].ToString();
1265 
1266  String lsQueryAsientosRecargoRepercutido = "SELECT NUMERO, FECHA, DEBE, HABER, DEBEDIV, HABERDIV, CUENTA as cuenta_recargo, ASI " +
1267  " FROM " + DB.SQLDatabase("Gestion", "Asientos") +
1268  " WHERE empresa= " + DB.SQLString(lcEmpresa) +
1269  " AND numero= " + DB.SQLString(lcNumero) +
1270  " AND cuenta='" + lsCuentaRecargoRepercutido + "' ";
1271 
1272  lsQueryAsientosRecargoRepercutido += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "", "fecha");
1273 
1274  DB.SQLExec(lsQueryAsientosRecargoRepercutido, ref lDtAsientosRecargoRepercutido);
1275 
1276  if (lDtAsientosRecargoRepercutido != null)
1277  {
1278  if (lDtAsientosRecargoRepercutido.Rows.Count == 1)
1279  {
1280  ComprobacionRegistroUnico(lDtAsientosRecargoRepercutido, importeDiferente, r, false);
1281  }
1282  else
1283  {
1284  if (lDtAsientosRecargoRepercutido.Rows.Count == 0)
1285  {
1286  ComprobacionIncidencias(true, true, true, r, false);
1287  }
1288  else
1289  {
1290  ComprobacionRegistrosVarios(lDtAsientosRecargoRepercutido, importeDiferente, dtMergeAsi, r, false);
1291  }
1292  }
1293  }
1294  }
1295  }
1296  lDtAsientosIvaRepercutido.Clear();
1297  }
1298  }
1299 
1307  protected void ComprobacionRegistroUnico(DataTable ldtAsientosRecargo, bool importeDiferente, DataRow r, bool lbRegistroSopor)
1308  {
1309  foreach (DataRow rec in ldtAsientosRecargo.Rows)
1310  {
1311  bool lbDiferImpRecargo = false;
1312  bool lbDiferImpRecargoDiv = false;
1313 
1314  decimal nValorRecargo = (lbRegistroSopor ? Convert.ToDecimal(rec["DEBE"]) - Convert.ToDecimal(rec["HABER"])
1315  : Convert.ToDecimal(rec["HABER"]) - Convert.ToDecimal(rec["DEBE"]));
1316  decimal nValorRecargoDiv = (lbRegistroSopor ? Convert.ToDecimal(rec["DEBEDIV"]) - Convert.ToDecimal(rec["HABERDIV"])
1317  : Convert.ToDecimal(rec["HABERDIV"]) - Convert.ToDecimal(rec["DEBEDIV"]));
1318 
1319 
1320  if (Convert.ToDecimal(r["RECARGO"]) != nValorRecargo)
1321  {
1322  lbDiferImpRecargo = true;
1323  }
1324 
1325  if (llDivisaConta && !_AsientoMultidivisa(rec) && Convert.ToDecimal(r["RECDIV"]) != nValorRecargoDiv)
1326  {
1327  lbDiferImpRecargoDiv = true;
1328  }
1329 
1330  ComprobacionIncidencias(importeDiferente, lbDiferImpRecargo, lbDiferImpRecargoDiv, r, lbRegistroSopor);
1331  }
1332  ldtAsientosRecargo.Clear();
1333  }
1334 
1343  protected void ComprobacionRegistrosVarios(DataTable ldtAsientosRecargo, bool importeDiferente, DataTable dtMergeAsi, DataRow r, bool lbRegistroSopor)
1344  {
1345  bool lbDiferImpRecargo = false;
1346  bool lbDiferImpRecargoDiv = false;
1347 
1348  DataTable dtMergeRecargo = AgruparRecargo(ldtAsientosRecargo);
1349 
1350  Int32 lcNumero = Convert.ToInt32(r["numero"].ToString());
1351  decimal nRecargo = Convert.ToDecimal(r["RECARGO"].ToString());
1352  decimal nRecargoDiv = Convert.ToDecimal(r["RECDIV"].ToString());
1353 
1354  string lcCampo1 = (lbRegistroSopor ? "DEBE" : "HABER");
1355  string lcCampo2 = (lbRegistroSopor ? "HABER" : "DEBE");
1356  string lcCampoDiv1 = (lbRegistroSopor ? "DEBEDIV" : "HABERDIV");
1357  string lcCampoDiv2 = (lbRegistroSopor ? "HABERDIV" : "DEBEDIV");
1358 
1359  List<string> lstRegistros = new List<string>();
1360  List<string> lstRegistrosDiv = new List<string>();
1361  List<decimal> lstAsientos = new List<decimal>();
1362  List<decimal> lstAsientosDiv = new List<decimal>();
1363 
1364  lstRegistros = ldtAsientosRecargo.AsEnumerable().Where(g => g.Field<decimal>(lcCampo1) - g.Field<decimal>(lcCampo2) == nRecargo).Select(g => g.Field<string>("CUENTA_RECARGO") ).ToList();
1365 
1366  lstRegistrosDiv = ldtAsientosRecargo.AsEnumerable().Where(g => g.Field<decimal>(lcCampoDiv1) - g.Field<decimal>(lcCampoDiv2) == nRecargoDiv).Select(g => g.Field<string>("CUENTA_RECARGO")).ToList();
1367 
1368  lstAsientos = dtMergeAsi.AsEnumerable().Where(g => g.Field<Int32>("NUMERO") == lcNumero).Select(g => g.Field<decimal>("RECARGO")).Distinct().ToList();
1369 
1370  lstAsientosDiv = dtMergeAsi.AsEnumerable().Where(g => g.Field<Int32>("NUMERO") == lcNumero).Select(g => g.Field<decimal>("RECDIV")).Distinct().ToList();
1371 
1372  if (lstRegistros.Count != 1)
1373  {
1374  if (lstRegistros.Count == 0)
1375  {
1376  if (lstAsientos.Count > 0)
1377  {
1378  nRecargo = Convert.ToDecimal(lstAsientos[0]);
1379 
1380  lstRegistros.Clear();
1381  lstRegistros = dtMergeRecargo.AsEnumerable().Where(g => g.Field<decimal>(lcCampo1) - g.Field<decimal>(lcCampo2) == nRecargo).Select(g => g.Field<string>("CUENTA_RECARGO")).ToList();
1382 
1383  if (lstRegistros.Count != 1)
1384  {
1385  lbDiferImpRecargo = true;
1386  }
1387  }
1388  }
1389  else
1390  {
1391  lbDiferImpRecargo = true;
1392  }
1393  }
1394 
1395  if (llDivisaConta && !_AsientoMultidivisa(r) && lstRegistrosDiv.Count != 1)
1396  {
1397  if (lstRegistrosDiv.Count == 0)
1398  {
1399  if (lstAsientosDiv.Count > 0)
1400  {
1401  nRecargoDiv = Convert.ToDecimal(lstAsientosDiv[0]);
1402 
1403  lstRegistrosDiv.Clear();
1404  lstRegistrosDiv = dtMergeRecargo.AsEnumerable().Where(g => g.Field<decimal>(lcCampoDiv1) - g.Field<decimal>(lcCampoDiv2) == nRecargoDiv).Select(g => g.Field<string>("CUENTA_RECARGO")).ToList();
1405 
1406  if (lstRegistrosDiv.Count != 1)
1407  {
1408  lbDiferImpRecargoDiv = true;
1409  }
1410  }
1411  }
1412  else
1413  {
1414  lbDiferImpRecargoDiv = true;
1415  }
1416  }
1417 
1418  ComprobacionIncidencias(importeDiferente, lbDiferImpRecargo, lbDiferImpRecargoDiv, r, lbRegistroSopor);
1419  }
1420 
1425  protected void _AsientosVerificarRecargoSoportado(bool importeDiferente)
1426  {
1427  DataTable lDtAsientosIvaSoportado = new DataTable();
1428  DataTable lDtAsientosRecargoSoportado = new DataTable();
1429 
1430 
1431  String lsDigito3IvaSoportado = Convert.ToString(EW_GLOBAL._GetVariable("wc_IvaSop"));
1432  lsDigito3IvaSoportado = lsDigito3IvaSoportado.Substring(0, lnDigito3);
1433 
1434  String lsQueryAsientosIvaSoportado = "SELECT A.NUMERO,A.FECHA,A.DEBE,A.HABER,A.DEBEDIV,A.HABERDIV,C.CUENTA,C.ASI,C.IVA,C.BIMPO,C.IVADIV,C.BASEDIV,C.PORCEN_IVA, a.cuenta as cuentaiva, " +
1435  " C.TIPO_IVA, B.CTA_RE_SOP, C.RECARGO, C.RECDIV " +
1436  " FROM (( " + DB.SQLDatabase("Gestion", "Asientos") + " A INNER JOIN " + DB.SQLDatabase("Gestion", "Tipo_iva") + " B ON A.CUENTA=B.CTA_IV_SOP) " +
1437  " INNER JOIN " + DB.SQLDatabase("Gestion", "Ivasopor") + " C ON A.EMPRESA=C.EMPRESA AND A.ASI=C.ASI) " +
1438  " WHERE A.empresa= " + DB.SQLString(lcEmpresa) +
1439  " AND LEFT(A.cuenta, " + lnDigito3 + ")='" + lsDigito3IvaSoportado + "' " +
1440  " AND A.tipo = '0' " +
1441  " AND A.PROVEEDOR<>'LIQUIDAR' " +
1442  " AND A.TIPO_MOV <> 29 ";
1443 
1444  lsQueryAsientosIvaSoportado += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "A", "fecha");
1445 
1446  DB.SQLExec(lsQueryAsientosIvaSoportado, ref lDtAsientosIvaSoportado);
1447  if (lDtAsientosIvaSoportado != null && lDtAsientosIvaSoportado.Rows.Count > 0)
1448  {
1449  DataTable dtMergeAsi = AgruparAsientosSopor(lDtAsientosIvaSoportado);
1450 
1451  foreach (DataRow r in lDtAsientosIvaSoportado.Rows)
1452  {
1453  if (!string.IsNullOrEmpty(r["CTA_RE_SOP"].ToString().Trim()) && (Convert.ToDecimal(r["RECARGO"]) != 0 || Convert.ToDecimal(r["RECDIV"]) != 0))
1454  {
1455  string lsCuentaRecargoRepercutido = r["CTA_RE_SOP"].ToString();
1456  string lcNumero = r["NUMERO"].ToString();
1457 
1458  String lsQueryAsientosRecargoSoportado = "SELECT NUMERO, FECHA, DEBE, HABER, DEBEDIV, HABERDIV, CUENTA as cuenta_recargo " +
1459  " FROM " + DB.SQLDatabase("Gestion", "Asientos") +
1460  " WHERE empresa= " + DB.SQLString(lcEmpresa) +
1461  " AND numero= " + DB.SQLString(lcNumero) +
1462  " AND cuenta='" + lsCuentaRecargoRepercutido + "' ";
1463 
1464  lsQueryAsientosRecargoSoportado += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "", "fecha");
1465 
1466  DB.SQLExec(lsQueryAsientosRecargoSoportado, ref lDtAsientosRecargoSoportado);
1467 
1468  if (lDtAsientosRecargoSoportado != null)
1469  {
1470  if (lDtAsientosRecargoSoportado.Rows.Count == 1)
1471  {
1472  ComprobacionRegistroUnico(lDtAsientosRecargoSoportado, importeDiferente, r, true);
1473  }
1474  else
1475  {
1476  if (lDtAsientosRecargoSoportado.Rows.Count == 0)
1477  {
1478  ComprobacionIncidencias(true, true, true, r, true);
1479  }
1480  else
1481  {
1482  ComprobacionRegistrosVarios(lDtAsientosRecargoSoportado, importeDiferente, dtMergeAsi, r, true);
1483  }
1484  }
1485  }
1486  }
1487  }
1488  lDtAsientosIvaSoportado.Clear();
1489  }
1490  }
1491 
1499  {
1500  const string TIPO_REVISION = "TipoRevision";
1501 
1502  bool lbResult = false;
1503  object loParametro = null;
1504  List<string> loLista = null;
1505  String lsTipoRevisionDesde = string.Empty;
1506  String lsTipoRevisionHasta = string.Empty;
1507 
1508  if (this._Filtros != null && this._Filtros.Count > 0)
1509  {
1510  this._Filtros.TryGetValue(TIPO_REVISION + "Lista", out loParametro);
1511  if (loParametro != null)
1512  {
1513  // Es una lista.
1514  if (loParametro is string)
1515  {
1516  loLista = new List<String>(loParametro.ToString().Split(','));
1517  }
1518  else
1519  {
1520  loLista = (List<string>)loParametro;
1521  }
1522 
1523  if (loLista != null && loLista.Count > 0)
1524  {
1525  this._ActivarMarcas(loLista);
1526  lbResult = true;
1527  }
1528  }
1529  else
1530  {
1531  // Desde / hasta.
1532  this._Filtros.TryGetValue(TIPO_REVISION + "Desde", out loParametro);
1533  if (loParametro != null)
1534  {
1535  lsTipoRevisionDesde = Convert.ToString(loParametro);
1536  }
1537  loParametro = null;
1538 
1539  this._Filtros.TryGetValue(TIPO_REVISION + "Hasta", out loParametro);
1540  if (loParametro != null)
1541  {
1542  lsTipoRevisionHasta = Convert.ToString(loParametro);
1543  }
1544 
1545  if (!String.IsNullOrWhiteSpace(lsTipoRevisionDesde) && !String.IsNullOrWhiteSpace(lsTipoRevisionHasta))
1546  {
1547  int desde = Convert.ToInt32(lsTipoRevisionDesde);
1548  int hasta = Convert.ToInt32(lsTipoRevisionHasta);
1549 
1550  List<String> loListaAux = new List<string>();
1551  for (int i = desde; i <= hasta; i++)
1552  {
1553  loListaAux.Add(i.ToString("00"));
1554  }
1555  this._ActivarMarcas(loListaAux);
1556  lbResult = true;
1557  }
1558  else
1559  {
1560  // Unico
1561  this._Filtros.TryGetValue(TIPO_REVISION + "Unico", out loParametro);
1562  if (loParametro != null)
1563  {
1564  List<String> loListaAux = new List<string>();
1565  loListaAux.Add(String.Format("{00:0}", loParametro));
1566  this._ActivarMarcas(loListaAux);
1567  lbResult = true;
1568  }
1569  else
1570  {
1571  // Si no llegan filtros no sabemos si está marcado o no el check de todos.
1572  // Según lo hablado con Joan se lanzan todas las revisiones.
1573  this._ActivarMarcas(true);
1574  lbResult = true;
1575  }
1576  }
1577  }
1578  }
1579  else
1580  {
1581  // Si no llegan filtros no sabemos si está marcado o no el check de todos.
1582  // Según lo hablado con Joan se lanzan todas las revisiones.
1583  this._ActivarMarcas(true);
1584  lbResult = true;
1585  }
1586 
1587  return lbResult;
1588  }
1589 
1594  protected void _ActivarMarcas(List<String> tiposRevisionSeleccionados )
1595  {
1596  if (tiposRevisionSeleccionados != null && tiposRevisionSeleccionados.Count > 0)
1597  {
1598  foreach (String s in tiposRevisionSeleccionados)
1599  {
1600  switch (s)
1601  {
1602  case "01":
1603  // Asiento descuadrado
1604  this.lbAsientosDescuadrados = true;
1605  break;
1606  case "02":
1607  // Apunte sin cuenta contable
1608  this.lbAsientosSinCtaContable = true;
1609  break;
1610  case "03":
1611  // cuenta contable inexistente
1612  this.lbAsientosVerificarCuentas = true;
1613  break;
1614  case "04":
1615  // Importe inferior en cuentas secundarias
1616  this.lbImporteInferiorPlanesAnaliticos = this.trabajaConSecundarias;
1617  break;
1618  case "05":
1619  // Importe superior en cuentas secundarias
1620  this.lbImporteSuperiorPlanesAnaliticos = this.trabajaConSecundarias;
1621  break;
1622  case "06":
1623  // Asientos sin cuentas secundarias
1624  this.lbAsientosVerificarPlanesAnaliticos = this.trabajaConSecundarias;
1625  break;
1626  case "07":
1627  // Apunte de IVA no registrado
1628  this.lbAsientosSinIVA = true;
1629  break;
1630  case "08":
1631  // Cuenta de IVA diferente de asiento
1632  this.lbCuentaDeIVADiferenteAsiento = true;
1633  break;
1634  case "09":
1635  // Importe de IVA diferente
1636  this.lbImporteDeIVADiferente = true;
1637  break;
1638  case "10":
1639  // Retención no anotada
1640  this.lbRetencionNoAnotada = true;
1641  break;
1642  case "11":
1643  // Importe de retención diferente
1644  this.lbAsientosVerificarRetencion = true;
1645  break;
1646  case "12":
1647  // Asientos con fecha fuera del período del ejercicio actual
1648  this.lbAsientosVerificarFechaPeriodo = true;
1649  break;
1650  case "13":
1651  // Importe de recargo diferente
1652  this.lbImporteDeRecargoDiferente = true;
1653  break;
1654  }
1655  }
1656  }
1657  }
1658 
1663  protected void _ActivarMarcas(bool valor)
1664  {
1665  // Asiento descuadrado
1666  this.lbAsientosDescuadrados = valor;
1667  // Apunte sin cuenta contable
1668  this.lbAsientosSinCtaContable = valor;
1669  // cuenta contable inexistente
1670  this.lbAsientosVerificarCuentas = valor;
1671  // Importe inferior en cuentas secundarias
1672  this.lbImporteInferiorPlanesAnaliticos = valor ? this.trabajaConSecundarias : valor;
1673  // Importe superior en cuentas secundarias
1674  this.lbImporteSuperiorPlanesAnaliticos = valor ? this.trabajaConSecundarias : valor;
1675  // Asientos sin cuentas secundarias
1676  this.lbAsientosVerificarPlanesAnaliticos = valor ? this.trabajaConSecundarias : valor;
1677  // Apunte de IVA no registrado
1678  this.lbAsientosSinIVA = valor;
1679  // Cuenta de IVA diferente de asiento
1680  this.lbCuentaDeIVADiferenteAsiento = valor;
1681  // Importe de IVA diferente
1682  this.lbImporteDeIVADiferente = valor;
1683  // Retención no anotada
1684  this.lbRetencionNoAnotada = valor;
1685  // Importe de retención diferente
1686  this.lbAsientosVerificarRetencion = valor;
1687  // Asientos con fecha fuera del período del ejercicio actual
1688  this.lbAsientosVerificarFechaPeriodo = valor;
1689  // Importe de recargo diferente
1690  this.lbImporteDeRecargoDiferente = valor;
1691  }
1692 
1698  protected bool _AsientoMultidivisa(DataRow r)
1699  {
1700  bool lbOk = true;
1701 
1702  Int32 lcNumero = Convert.ToInt32(r["numero"].ToString());
1703  List<string> lstAsientos = new List<string>();
1704  lstAsientos = lDtAsientos.AsEnumerable().Where(g => g.Field<Int32>("numero") == lcNumero).Select(g => g.Field<string>("divisa")).Distinct().ToList();
1705 
1706  if (lstAsientos.Count == 1)
1707  lbOk = false;
1708 
1709  return lbOk;
1710  }
1711 
1715  protected DataTable _AsientosDivisa()
1716  {
1717  DataTable lDtAsientos = new DataTable();
1718  String lsQueryAsientos = "SELECT numero, MAX(fecha) as fecha, divisa" +
1719  " FROM " + DB.SQLDatabase("Gestion", "Asientos") +
1720  " WHERE empresa= " + DB.SQLString(lcEmpresa);
1721  lsQueryAsientos += _Filtro_Fecha(_Filtros, _Tipo_Filtro_Fecha.Fecha, "", "fecha");
1722  lsQueryAsientos += " GROUP BY numero, divisa";
1723  DB.SQLExec(lsQueryAsientos, ref lDtAsientos);
1724 
1725  return lDtAsientos;
1726  }
1727 
1733  protected DataTable AgruparAsientosReper(DataTable dt)
1734  {
1735  var ldtAgrupado = (from item in dt.AsEnumerable()
1736  group item by new
1737  {
1738  numero = item.Field<Int32>("numero")
1739  }
1740  into g
1741  select new
1742  {
1743  g.Key.numero,
1744  fecha = g.Max(y => y.Field<DateTime>("fecha")),
1745  debe = g.Sum(y => y.Field<decimal>("debe")),
1746  haber = g.Sum(y => y.Field<decimal>("haber")),
1747  debediv = g.Sum(y => y.Field<decimal>("debediv")),
1748  haberdiv = g.Sum(y => y.Field<decimal>("haberdiv")),
1749  cuenta = g.Max(y => y.Field<string>("cuenta")),
1750  asi = g.Max(y => y.Field<string>("asi")),
1751  iva = g.Sum(y => y.Field<decimal>("iva")),
1752  bimpo = g.Sum(y => y.Field<decimal>("bimpo")),
1753  ivadiv = g.Sum(y => y.Field<decimal>("ivadiv")),
1754  bimpodiv = g.Sum(y => y.Field<decimal>("bimpodiv")),
1755  porcen_iva = g.Max(y => y.Field<decimal>("porcen_iva")),
1756  cuentaiva = g.Max(y => y.Field<string>("cuentaiva")),
1757  tipo_iva = g.Max(y => y.Field<string>("tipo_iva")),
1758  cta_re_rep = g.Max(y => y.Field<string>("cta_re_rep")),
1759  recargo = g.Sum(y => y.Field<decimal>("recargo")),
1760  recdiv = g.Sum(y => y.Field<decimal>("recdiv"))
1761  }).__CopyToDataTable();
1762 
1763  dt = ldtAgrupado;
1764 
1765  return dt;
1766  }
1767 
1773  protected DataTable AgruparRecargo(DataTable dt)
1774  {
1775  var ldtAgrupado = (from item in dt.AsEnumerable()
1776  group item by new
1777  {
1778  numero = item.Field<Int32>("numero")
1779  }
1780  into g
1781  select new
1782  {
1783  g.Key.numero,
1784  fecha = g.Max(y => y.Field<DateTime>("fecha")),
1785  debe = g.Sum(y => y.Field<decimal>("debe")),
1786  haber = g.Sum(y => y.Field<decimal>("haber")),
1787  debediv = g.Sum(y => y.Field<decimal>("debediv")),
1788  haberdiv = g.Sum(y => y.Field<decimal>("haberdiv")),
1789  cuenta_recargo = g.Max(y => y.Field<string>("cuenta_recargo")),
1790  asi = g.Max(y => y.Field<string>("asi"))
1791  }).__CopyToDataTable();
1792 
1793 
1794  dt = ldtAgrupado;
1795 
1796  return dt;
1797  }
1798 
1804  protected DataTable AgruparAsientosSopor(DataTable dt)
1805  {
1806  var ldtAgrupado = (from item in dt.AsEnumerable()
1807  group item by new
1808  {
1809  numero = item.Field<Int32>("numero")
1810  }
1811  into g
1812  select new
1813  {
1814  g.Key.numero,
1815  fecha = g.Max(y => y.Field<DateTime>("fecha")),
1816  debe = g.Sum(y => y.Field<decimal>("debe")),
1817  haber = g.Sum(y => y.Field<decimal>("haber")),
1818  debediv = g.Sum(y => y.Field<decimal>("debediv")),
1819  haberdiv = g.Sum(y => y.Field<decimal>("haberdiv")),
1820  cuenta = g.Max(y => y.Field<string>("cuenta")),
1821  asi = g.Max(y => y.Field<string>("asi")),
1822  iva = g.Sum(y => y.Field<decimal>("iva")),
1823  bimpo = g.Sum(y => y.Field<decimal>("bimpo")),
1824  ivadiv = g.Sum(y => y.Field<decimal>("ivadiv")),
1825  bimpodiv = g.Sum(y => y.Field<decimal>("basediv")),
1826  porcen_iva = g.Max(y => y.Field<decimal>("porcen_iva")),
1827  cuentaiva = g.Max(y => y.Field<string>("cuentaiva")),
1828  tipo_iva = g.Max(y => y.Field<string>("tipo_iva")),
1829  cta_re_sop = g.Max(y => y.Field<string>("cta_re_sop")),
1830  recargo = g.Sum(y => y.Field<decimal>("recargo")),
1831  recdiv = g.Sum(y => y.Field<decimal>("recdiv"))
1832  }).__CopyToDataTable();
1833 
1834  dt = ldtAgrupado;
1835 
1836  return dt;
1837  }
1838 
1847  protected void ComprobacionIncidencias(bool importeDiferente, bool lbDiferImpRecargo, bool lbDiferImpRecargoDiv, DataRow r, bool lbRegistroSopor)
1848  {
1849  string lcCuenta = (lbRegistroSopor ? Convert.ToString(r["CTA_RE_SOP"]) : Convert.ToString(r["CTA_RE_REP"]));
1850  string lcVariable = (lbRegistroSopor ? "soportado" : "repercutido");
1851 
1852  // Importe de IVA diferente
1853  if (importeDiferente && lbDiferImpRecargo)
1854  {
1855  string lsTxtDiferencia = "Diferencias en importes: el importe de la cuenta " + lcCuenta + " es diferente al registro de recargo " + lcVariable.ToString();
1856 
1857  dtResultadoRevision.Rows.Add(
1858  r["NUMERO"],
1859  r["FECHA"],
1860  lsTxtDiferencia);
1861  }
1862 
1863  // Importe Divisa de IVA diferente
1864  if (llDivisaConta && importeDiferente && lbDiferImpRecargoDiv)
1865  {
1866  string lsTxtDiferencia = "Diferencias en importes: el importe en divisa de la cuenta " + lcCuenta + " es diferente al registro de recargo " + lcVariable.ToString();
1867 
1868  dtResultadoRevision.Rows.Add(
1869  r["NUMERO"],
1870  r["FECHA"],
1871  lsTxtDiferencia);
1872  }
1873  }
1874 
1875  #endregion Métodos privados
1876  }
1877 }
void _ActivarMarcas(bool valor)
Activar/Desactivar TODAS las marcas para lanzar/no lanzar TODOS los procesos de revision.
DataTable AgruparAsientosSopor(DataTable dt)
void _AsientosVerificarCuentas()
Revisa los apuntes con cuenta contable inexistente
void _ActivarMarcas(List< String > tiposRevisionSeleccionados)
Activar los marcas para lanzar los procesos de revisión seleccionados.
override void _SetColumnWidth(Dictionary< string, int > tldTranslate=null)
Definir ancho de columnas
Clase parcial para listados, en esta definición se especificarán los métodos comunes para las demás c...
Definition: _clsListados.cs:61
bool _DeterminarQueRevisionesLanzar()
Determinar las revisiones a lanzar. Este filtro no es el típico filtro para construir una cláusula w...
void _AsientosVerificarRetencion(bool retencionNoAnotada, bool importeRetencion)
Revisa:
void _AsientosVerificarIvaSoportado(bool cuentaDiferente, bool importeDiferente)
Revisa:
void _AsientosVerificarRecargoRepercutido(bool importeDiferente)
Revisa:
override void _Navigate(String tcKeyNavigate, DataRow trRow)
Navegación al asiento
DataTable AgruparAsientosReper(DataTable dt)
void _AsientosVerificarPlanesAnaliticos(bool importeSuperior, bool importeInferior, bool sinSecundaria)
Revisa:
override DataTable _DataTable()
Método de obtención de los datos específico para el listado
void ComprobacionIncidencias(bool importeDiferente, bool lbDiferImpRecargo, bool lbDiferImpRecargoDiv, DataRow r, bool lbRegistroSopor)
DataTable _AsientosDivisa()
Consultamos Asientos
void _AsientosDescuadrados()
Revisa los asientos descuadrados.
_Tipo_Filtro_Fecha
Enumeración de los posibles filtros fecha a realizar
void _AsientosVerificarIvaRepercutido(bool cuentaDiferente, bool importeDiferente)
Revisa:
void ComprobacionRegistroUnico(DataTable ldtAsientosRecargo, bool importeDiferente, DataRow r, bool lbRegistroSopor)
RevisionAsientos()
Inicializa una nueva instancia de la clase
Entidad de relación (Columnas adicionales en listados)
Definition: DefEntidad.cs:14
Clase de negocio para el listado de revisión de asientos contables
void _AsientosVerificarRecargoSoportado(bool importeDiferente)
Revisa:
void _AsientosSinIva()
Revisa apuntes de Iva no registrado.
override void _SetColumnCaptions(Dictionary< string, string > tldTranslate=null)
Títulos de las columnas
void _AsientosVerificarFechaPeriodo()
Revisa asientos con fecha fuera del período del ejercicio actual
void _AsientosSinCuentaContable()
Revisa los apuntes sin cuenta contable.
void ComprobacionRegistrosVarios(DataTable ldtAsientosRecargo, bool importeDiferente, DataTable dtMergeAsi, DataRow r, bool lbRegistroSopor)