2 using System.Collections.Generic;
9 namespace sage.ew.contabilidad
16 #region Variables privadas 21 protected bool llDivisaConta = Convert.ToBoolean(EW_GLOBAL._GetVariable(
"wl_divisaconta"));
26 protected string lcEmpresa = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_empresa"));
31 protected string lcMoneda = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_moneda"));
36 protected string lcIva = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_iva"));
42 protected int lnDigito3 = Convert.ToInt32(EW_GLOBAL._GetVariable(
"wn_digito3"));
47 protected int lnDigito4 = Convert.ToInt32(EW_GLOBAL._GetVariable(
"wn_digito4"));
52 protected bool _lTodacuen = (Convert.ToBoolean(EW_GLOBAL._GetVariable(
"wl_todacuen")));
57 protected DateTime dtFechaDesde = DateTime.MinValue;
62 protected DateTime dtFechaHasta = DateTime.MaxValue;
67 protected bool lbAsientosDescuadrados =
false;
72 protected bool lbAsientosSinCtaContable =
false;
77 protected bool lbAsientosVerificarCuentas =
false;
82 protected bool lbImporteInferiorPlanesAnaliticos =
false;
87 protected bool lbImporteSuperiorPlanesAnaliticos =
false;
92 protected bool lbAsientosVerificarPlanesAnaliticos =
false;
97 protected bool lbAsientosSinIVA =
false;
102 protected bool lbCuentaDeIVADiferenteAsiento =
false;
107 protected bool lbImporteDeIVADiferente =
false;
112 protected bool lbRetencionNoAnotada =
false;
119 protected bool lbAsientosVerificarRetencion =
false;
124 protected bool lbAsientosVerificarFechaPeriodo =
false;
129 protected bool lbImporteDeRecargoDiferente =
false;
134 protected bool trabajaConSecundarias = Convert.ToBoolean(EW_GLOBAL._GetVariable(
"wl_secundar"));
139 protected DataTable dtResultadoRevision = null;
144 protected DataTable lDtAsientos = null;
146 #endregion Variables privadas 148 #region Constructores 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));
161 lDtAsientos =
new DataTable();
164 #endregion Constructores 171 public override String _ReportFile
175 return "revisionasientos.report";
185 dtResultadoRevision.Clear();
186 _ActivarMarcas(
false);
188 lDtAsientos = _AsientosDivisa();
191 String lsQueryAsientos =
"SELECT numero, MAX(fecha) as fecha, divisa" +
192 " FROM " + DB.SQLDatabase(
"Gestion",
"Asientos") +
193 " WHERE empresa= " + DB.SQLString(lcEmpresa);
195 lsQueryAsientos +=
" GROUP BY numero, divisa";
196 DB.SQLExec(lsQueryAsientos, ref lDtAsientos);
198 if (_DeterminarQueRevisionesLanzar())
201 if (lbAsientosDescuadrados)
203 _AsientosDescuadrados();
206 if (lbAsientosSinCtaContable)
208 _AsientosSinCuentaContable();
211 if (lbAsientosVerificarCuentas)
213 _AsientosVerificarCuentas();
218 if (lbImporteInferiorPlanesAnaliticos ||
219 lbImporteSuperiorPlanesAnaliticos ||
220 lbAsientosVerificarPlanesAnaliticos)
222 _AsientosVerificarPlanesAnaliticos(lbImporteSuperiorPlanesAnaliticos, lbImporteInferiorPlanesAnaliticos, lbAsientosVerificarPlanesAnaliticos);
225 if (lbAsientosSinIVA)
231 if (lbCuentaDeIVADiferenteAsiento ||
232 lbImporteDeIVADiferente)
234 _AsientosVerificarIvaRepercutido(lbCuentaDeIVADiferenteAsiento, lbImporteDeIVADiferente);
235 _AsientosVerificarIvaSoportado(lbCuentaDeIVADiferenteAsiento, lbImporteDeIVADiferente);
239 if (lbRetencionNoAnotada ||
240 lbAsientosVerificarRetencion)
242 _AsientosVerificarRetencion(lbRetencionNoAnotada, lbAsientosVerificarRetencion);
245 if (lbAsientosVerificarFechaPeriodo)
247 _AsientosVerificarFechaPeriodo();
250 if (lbImporteDeRecargoDiferente)
252 _AsientosVerificarRecargoRepercutido(lbImporteDeRecargoDiferente);
253 _AsientosVerificarRecargoSoportado(lbImporteDeRecargoDiferente);
257 return dtResultadoRevision;
263 public override List<string> _ReportColumns
267 _dicDefEntidades =
new Dictionary<string, ew.interficies.IDefEntidad>();
268 _dicDefEntidades.Add(
"asiento",
new DefEntidad() { _DB =
"GESTION", _Tabla =
"ASIENTOS", _Campo =
"NUMERO", _Relacion =
"", _Empresa =
true });
270 return new List<string>() {
"asiento",
"fecha",
"descripcion" };
280 Dictionary<string, string> ldTranslate =
new Dictionary<string, string>();
282 ldTranslate.Add(
"asiento",
"Asiento");
283 ldTranslate.Add(
"fecha",
"Fecha");
284 ldTranslate.Add(
"descripcion",
"Descripción");
286 base._SetColumnCaptions(ldTranslate);
295 Dictionary<string, int> ldTranslate =
new Dictionary<string, int>();
298 ldTranslate.Add(
"descripcion", 2000);
300 base._SetColumnWidth(ldTranslate);
306 public override Dictionary<string, string> _NavigateButtons
310 return new Dictionary<string, string>() { {
"Asiento",
"Ver asiento" } };
314 base._NavigateButtons = value;
323 public override void _Navigate(String tcKeyNavigate, DataRow trRow)
328 switch (tcKeyNavigate)
331 string lcAsiento = Convert.ToString(trRow[
"asiento"]);
333 if (!
string.IsNullOrWhiteSpace(lcAsiento))
343 #region Métodos privados 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")));
358 DB.SQLExec(lsQueryAsientosDescuadrados, ref lDtTempAsientosDescuadrados);
359 if (lDtTempAsientosDescuadrados != null && lDtTempAsientosDescuadrados.Rows.Count > 0)
361 foreach (DataRow r
in lDtTempAsientosDescuadrados.Rows)
363 dtResultadoRevision.Rows.Add(r[
"numero"], r[
"fecha"],
"Asiento descuadrado");
366 lDtTempAsientosDescuadrados.Clear();
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")));
379 DB.SQLExec(lsQueryAsientosDescuadrados, ref lDtTempAsientosDescuadrados);
380 if (lDtTempAsientosDescuadrados != null && lDtTempAsientosDescuadrados.Rows.Count > 0)
382 foreach (DataRow r
in lDtTempAsientosDescuadrados.Rows)
384 if (!_AsientoMultidivisa(r))
385 dtResultadoRevision.Rows.Add(r[
"numero"], r[
"fecha"],
"Asiento descuadrado en multidivisa");
388 lDtTempAsientosDescuadrados.Clear();
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");
404 DB.SQLExec(lsQueryAsientosSinCuentaContable, ref lDtAsientosSinCuentaContable);
405 if (lDtAsientosSinCuentaContable != null && lDtAsientosSinCuentaContable.Rows.Count > 0)
407 foreach (DataRow r
in lDtAsientosSinCuentaContable.Rows)
409 dtResultadoRevision.Rows.Add(r[
"numero"], r[
"fecha"],
"Apunte sin cuenta contable");
412 lDtAsientosSinCuentaContable.Clear();
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 ";
428 lsQueryAsientosVerificarCuentas += _Filtro_Fecha(_Filtros,
_Tipo_Filtro_Fecha.Fecha,
"a",
"fecha");
430 DB.SQLExec(lsQueryAsientosVerificarCuentas, ref lDtAsientosVerificarCuentas);
431 if (lDtAsientosVerificarCuentas != null && lDtAsientosVerificarCuentas.Rows.Count > 0)
433 foreach (DataRow r
in lDtAsientosVerificarCuentas.Rows)
436 if (r[
"cuenta"] != null && !String.IsNullOrWhiteSpace(r[
"cuenta"].ToString()))
438 dtResultadoRevision.Rows.Add(
441 String.Format(
"Cuenta {0} inexistente.", r[
"cuenta"]));
445 lDtAsientosVerificarCuentas.Clear();
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);
463 DB.SQLExec(lsQueryCurContInex, ref lDtCurContInex);
464 lDtCurContInex.TableName =
"CurContInex";
466 if (lDtCurContInex != null && lDtCurContInex.Rows.Count > 0)
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";
478 if (importeInferior || importeSuperior)
481 var results = (from table1 in lDtCurContInex.AsEnumerable()
482 join table2 in lDtCurOtrasien.AsEnumerable() on (String)table1[
"ASI"] equals (String)table2[
"ASI"]
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();
498 foreach (DataRow r
in results.Rows)
500 if (!_lTodacuen || (_lTodacuen && Convert.ToDecimal(r[
"tot"]) != 0))
503 if (importeSuperior && (Convert.ToDecimal(r[
"tot"]) > (Convert.ToDecimal(r[
"debe"]) + Convert.ToDecimal(r[
"haber"]))))
505 dtResultadoRevision.Rows.Add(
508 "Importe en planes analíticos superior que el valor de la cuenta " + r[
"cuenta"].ToString());
511 else if (importeInferior && (Convert.ToDecimal(r[
"tot"]) < (Convert.ToDecimal(r[
"debe"]) + Convert.ToDecimal(r[
"haber"]))))
513 dtResultadoRevision.Rows.Add(
516 "Importe en planes analíticos inferior que el valor de la cuenta " + r[
"cuenta"].ToString());
520 if (llDivisaConta && !_AsientoMultidivisa(r) && (!_lTodacuen || (_lTodacuen && Convert.ToDecimal(r[
"totdiv"]) != 0)))
523 if (importeSuperior && (Convert.ToDecimal(r[
"totdiv"]) > (Convert.ToDecimal(r[
"debediv"]) + Convert.ToDecimal(r[
"haberdiv"]))))
525 dtResultadoRevision.Rows.Add(
528 "Importe en divisa en planes analíticos superior que el valor de la cuenta " + r[
"cuenta"].ToString());
531 else if (importeInferior && (Convert.ToDecimal(r[
"totdiv"]) < (Convert.ToDecimal(r[
"debediv"]) + Convert.ToDecimal(r[
"haberdiv"]))))
533 dtResultadoRevision.Rows.Add(
536 "Importe en divisa en planes analíticos inferior que el valor de la cuenta " + r[
"cuenta"].ToString());
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 ";
554 DB.SQLExec(lsQueryCurOtrasienNivel1, ref lDtCurOtrasienNivel1);
555 lDtCurOtrasien.TableName =
"CurOtrasienNivel1";
558 if (importeInferior || importeSuperior)
561 var results = (from table1 in lDtCurContInex.AsEnumerable()
562 join table2 in lDtCurOtrasienNivel1.AsEnumerable() on (String)table1[
"ASI"] equals (String)table2[
"ASI"]
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();
578 foreach (DataRow r
in results.Rows)
581 if (importeSuperior && (Convert.ToDecimal(r[
"totaln1"]) > Convert.ToDecimal(r[
"totaln2"])))
583 dtResultadoRevision.Rows.Add(
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()));
589 else if (importeInferior && (Convert.ToDecimal(r[
"totaln1"]) > Convert.ToDecimal(r[
"totaln2"])))
591 dtResultadoRevision.Rows.Add(
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()));
597 if (llDivisaConta && !_AsientoMultidivisa(r))
600 if (importeSuperior && (Convert.ToDecimal(r[
"totaln1div"]) > Convert.ToDecimal(r[
"totaln2div"])))
602 dtResultadoRevision.Rows.Add(
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()));
608 else if (importeInferior && (Convert.ToDecimal(r[
"totaln1div"]) < Convert.ToDecimal(r[
"totaln2div"])))
610 dtResultadoRevision.Rows.Add(
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()));
621 if (sinSecundaria && !_lTodacuen)
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()
628 asi = table1.Field<
string>(
"ASI")
632 asi = table2.Field<
string>(
"ASI")
635 from c in leftJoin.DefaultIfEmpty()
636 where (c != null ?
false :
true)
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();
648 foreach (DataRow r
in results.Rows)
650 dtResultadoRevision.Rows.Add(
653 String.Format(
"Cuenta {0} sin planes analíticos.", r[
"cuenta"].ToString()));
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()
664 asi = table1.Field<
string>(
"ASI")
668 asi = table2.Field<
string>(
"ASI")
671 from c in leftJoin.DefaultIfEmpty()
672 where (c != null ?
false :
true)
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();
682 if (resultsdiv != null)
684 foreach (DataRow r
in results.Rows)
686 dtResultadoRevision.Rows.Add(
689 String.Format(
"Cuenta {0} sin planes analíticos.", r[
"cuenta"].ToString()));
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(
"")) +
" ) ";
705 DB.SQLExec(lsQueryCurAnalitica, ref lDtCurAnalitica);
706 lDtCurOtrasien.TableName =
"CurAnalitica";
709 var lDtAnalitica = (from a in lDtCurContInex.AsEnumerable()
710 join b in lDtCurAnalitica.AsEnumerable()
713 asi = a.Field<
string>(
"asi")
717 asi = b.Field<
string>(
"asi")
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();
730 if (lDtAnalitica != null)
732 foreach (DataRow r
in lDtAnalitica.Rows)
734 dtResultadoRevision.Rows.Add(
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"]));
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);
748 DB.SQLExec(lsQueryCurAnalitica, ref lDtCurAnalitica);
749 lDtCurOtrasien.TableName =
"CurAnalitica";
752 var lDtAnalitica2 = (from a in lDtCurContInex.AsEnumerable()
753 join b in lDtCurAnalitica.AsEnumerable()
756 asi = a.Field<
string>(
"asi")
760 asi = b.Field<
string>(
"asi")
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();
773 if (lDtAnalitica2 != null)
775 foreach (DataRow r
in lDtAnalitica2.Rows)
777 if (
string.IsNullOrWhiteSpace(Convert.ToString(r[
"codcuen2"])))
779 dtResultadoRevision.Rows.Add(
782 String.Format(
"Cuenta {0} inexistente definida en niveles analíticos.", r[
"codcuen"]));
784 else if (Convert.ToString(r[
"codcuen"]) != Convert.ToString(r[
"cuenta"]))
786 dtResultadoRevision.Rows.Add(
789 String.Format(
"Cuenta {0} no coincide con la cuenta {1} definida en niveles analíticos.", r[
"cuenta"], r[
"codcuen"]));
801 DataTable lDtAsientosSinIva =
new DataTable();
802 string lsAsientos = DB.SQLDatabase(
"Gestion",
"Asientos");
805 String lsDigito3IvaRepercutido = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_IvaRep"));
807 lsDigito3IvaRepercutido = lsDigito3IvaRepercutido.Substring(0, lnDigito3);
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 +=
") ";
833 DB.SQLExec(lsQueryAsientosSinIva, ref lDtAsientosSinIva);
834 if (lDtAsientosSinIva != null && lDtAsientosSinIva.Rows.Count > 0)
836 foreach(DataRow r
in lDtAsientosSinIva.Rows)
838 dtResultadoRevision.Rows.Add(
841 String.Format(
"Cuenta de {0} {1}, no anotada en el libro registro de {2} REPERCUTIDO.", lcIva, r[
"cuenta"], lcIva));
844 lDtAsientosSinIva.Clear();
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 +=
")" ;
870 DB.SQLExec(lsQueryAsientosSinIva, ref lDtAsientosSinIva);
871 if (lDtAsientosSinIva != null && lDtAsientosSinIva.Rows.Count > 0)
873 foreach (DataRow r
in lDtAsientosSinIva.Rows)
875 dtResultadoRevision.Rows.Add(
878 String.Format(
"Cuenta de {0} {1}, no anotada en el libro registro de {2} SOPORTADO.", lcIva, r[
"cuenta"], lcIva));
881 lDtAsientosSinIva.Clear();
891 DataTable lDtAsientosIvaRepercutido =
new DataTable();
893 String lsDigito3IvaRepercutido = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_IvaRep"));
894 lsDigito3IvaRepercutido = lsDigito3IvaRepercutido.Substring(0, lnDigito3);
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");
907 DB.SQLExec(lsQueryAsientosIvaRepercutido, ref lDtAsientosIvaRepercutido);
908 if (lDtAsientosIvaRepercutido != null && lDtAsientosIvaRepercutido.Rows.Count > 0)
910 DataTable lDtCtaDiferente =
new DataTable();
911 DB.SQLExec(
"SELECT NUMERO, FECHA, CUENTA FROM " + DB.SQLDatabase(
"Gestion",
"Asientos"), ref lDtCtaDiferente);
913 String lsCuentaIva =
string.Empty;
914 bool lbDiferImpIva =
false;
915 bool lbDiferImpIvaDiv =
false;
917 string lcCondicion =
string.Empty;
919 foreach (DataRow r
in lDtAsientosIvaRepercutido.Rows)
921 lbDiferImpIva =
false;
922 lbDiferImpIvaDiv =
false;
924 lsCuentaIva = r[
"CUENTA"].ToString();
926 if (Convert.ToDecimal(r[
"IVA"]) != ( Convert.ToDecimal(r[
"HABER"]) - Convert.ToDecimal(r[
"DEBE"])))
928 lbDiferImpIva =
true;
931 if (llDivisaConta && !_AsientoMultidivisa(r) && Convert.ToDecimal(r[
"IVADIV"]) != (Convert.ToDecimal(r[
"HABERDIV"]) - Convert.ToDecimal(r[
"DEBEDIV"])))
933 lbDiferImpIvaDiv =
true;
937 if (cuentaDiferente )
940 lcCondicion =
"NUMERO = " + DB.SQLString(r[
"NUMERO"]) +
" AND CUENTA = " + DB.SQLString(lsCuentaIva);
941 ldrItems = lDtCtaDiferente.Select(lcCondicion);
943 if (ldrItems != null && ldrItems.Length == 0)
945 dtResultadoRevision.Rows.Add(
948 String.Format(
"Cuenta del registro de {0} REPERCUTIDO diferente de la del asiento.", lcIva));
953 if (importeDiferente && lbDiferImpIva)
955 String lsTxtDiferencia =
"Diferencias en importes: el importe de la cuenta " + Convert.ToString(r[
"cuentaiva"]) +
" es diferente al registro de IVA repercutido";
957 dtResultadoRevision.Rows.Add(
964 if (llDivisaConta && importeDiferente && lbDiferImpIvaDiv)
966 String lsTxtDiferencia =
"Diferencias en importes: el importe en divisa de la cuenta " + Convert.ToString(r[
"cuentaiva"]) +
" es diferente al registro de IVA repercutido";
968 dtResultadoRevision.Rows.Add(
974 lDtCtaDiferente.Clear();
975 lDtAsientosIvaRepercutido.Clear();
986 DataTable lDtAsientosIvaSoportado =
new DataTable();
988 String lsDigito3IvaSoportado = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_IvaSop"));
989 lsDigito3IvaSoportado = lsDigito3IvaSoportado.Substring(0, lnDigito3);
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");
1002 DB.SQLExec(lsQueryAsientosIvaSoportado, ref lDtAsientosIvaSoportado);
1003 if (lDtAsientosIvaSoportado != null && lDtAsientosIvaSoportado.Rows.Count > 0)
1005 DataTable lDtCtaDiferente =
new DataTable();
1006 DB.SQLExec(
"SELECT NUMERO, FECHA, CUENTA FROM " + DB.SQLDatabase(
"Gestion",
"Asientos"), ref lDtCtaDiferente);
1008 String lsCuentaIva =
string.Empty;
1009 bool lbDiferImpIva =
false;
1010 bool lbDiferImpIvaDiv =
false;
1012 string lcCondicion =
string.Empty;
1014 foreach (DataRow r
in lDtAsientosIvaSoportado.Rows)
1016 lbDiferImpIva =
false;
1017 lbDiferImpIvaDiv =
false;
1019 lsCuentaIva = r[
"CUENTA"].ToString();
1021 if (Convert.ToDecimal(r[
"IVA"]) != (Convert.ToDecimal(r[
"DEBE"]) - Convert.ToDecimal(r[
"HABER"])))
1023 lbDiferImpIva =
true;
1026 if (llDivisaConta && Convert.ToDecimal(r[
"IVADIV"]) != (Convert.ToDecimal(r[
"DEBEDIV"]) - Convert.ToDecimal(r[
"HABERDIV"])))
1028 lbDiferImpIvaDiv =
true;
1032 if (cuentaDiferente)
1034 lcCondicion =
"NUMERO = " + DB.SQLString(r[
"NUMERO"]) +
" AND CUENTA = " + DB.SQLString(lsCuentaIva);
1035 ldrItems = lDtCtaDiferente.Select(lcCondicion);
1037 if (ldrItems != null && ldrItems.Length == 0)
1039 dtResultadoRevision.Rows.Add(
1042 String.Format(
"Cuenta del registro de {0} SOPORTADO diferente de la del asiento.", lcIva));
1047 if (importeDiferente && lbDiferImpIva)
1049 String lsTxtDiferencia =
"Diferencias en importes: el importe de la cuenta " + Convert.ToString(r[
"cuentaiva"]) +
" es diferente al registro de IVA soportado";
1051 dtResultadoRevision.Rows.Add(
1058 if (llDivisaConta && importeDiferente && lbDiferImpIvaDiv)
1060 String lsTxtDiferencia =
"Diferencias en importes: el importe en divisa de la cuenta " + Convert.ToString(r[
"cuentaiva"]) +
" es diferente al registro de IVA soportado";
1062 dtResultadoRevision.Rows.Add(
1069 lDtCtaDiferente.Clear();
1070 lDtAsientosIvaSoportado.Clear();
1081 DataTable lDtAsientosVerificarRetencion =
new DataTable();
1083 String lsRetReper = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_RetReper"));
1084 String lsRetSopor = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_RetSopor"));
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");
1092 DB.SQLExec(lsQueryAsientosVerificarRetencion, ref lDtAsientosVerificarRetencion);
1093 if (lDtAsientosVerificarRetencion != null && lDtAsientosVerificarRetencion.Rows.Count > 0)
1095 String lsNombreTablaRetencion = String.Empty;
1096 bool lbIncidenciaRet =
false;
1098 bool lbDiferenciaRet =
false;
1099 bool lbDiferenciaRetDivisa =
false;
1101 string lcCondicion =
string.Empty;
1103 foreach (DataRow r
in lDtAsientosVerificarRetencion.Rows)
1105 lbIncidenciaRet =
false;
1107 lbDiferenciaRet =
false;
1108 lbDiferenciaRetDivisa =
false;
1111 (r[
"cuenta"].ToString().Substring(0, lnDigito4) == lsRetReper.Substring(0, lnDigito4)) ||
1112 (r[
"cuenta"].ToString().Substring(0, lnDigito4) == lsRetSopor.Substring(0, lnDigito4))
1115 if (r[
"cuenta"].ToString().Substring(0, lnDigito4) == lsRetReper.Substring(0, lnDigito4))
1117 lcCondicion =
"CTA_RE_REP = " + DB.SQLString(r[
"cuenta"]);
1118 lsNombreTablaRetencion =
"RETREPER";
1122 lcCondicion =
"CTA_RE_SOP = " + DB.SQLString(r[
"cuenta"]);
1123 lsNombreTablaRetencion =
"RETSOPOR";
1128 String lsQueryExisteRetencion =
"SELECT ASI, RETENCIO, RETDIV" +
1129 " FROM " + DB.SQLDatabase(
"Gestion", lsNombreTablaRetencion) +
1130 " WHERE empresa= " + DB.SQLString(lcEmpresa) +
1131 " AND ASI='" + r[
"ASI"] +
"' ";
1133 DataTable lDtExisteRetencion =
new DataTable();
1134 DB.SQLExec(lsQueryExisteRetencion, ref lDtExisteRetencion);
1135 if (lDtExisteRetencion != null && lDtExisteRetencion.Rows.Count > 0)
1137 if (lsNombreTablaRetencion.CompareTo(
"RETREPER") == 0)
1139 if (Convert.ToDecimal(lDtExisteRetencion.Rows[0][
"RETENCIO"]) != Convert.ToDecimal(r[
"haber"]) - (Convert.ToDecimal(r[
"debe"])))
1141 lbDiferenciaRet =
true;
1146 if (Convert.ToDecimal(lDtExisteRetencion.Rows[0][
"RETENCIO"]) != (Convert.ToDecimal(r[
"debe"]) - Convert.ToDecimal(r[
"haber"])))
1148 lbDiferenciaRet =
true;
1153 if (lsNombreTablaRetencion.CompareTo(
"RETREPER") == 0)
1155 if (llDivisaConta && !_AsientoMultidivisa(r) && Convert.ToDecimal(lDtExisteRetencion.Rows[0][
"RETDIV"]) != Convert.ToDecimal(r[
"haberdiv"]) - (Convert.ToDecimal(r[
"debediv"])))
1157 lbDiferenciaRetDivisa =
true;
1162 if (llDivisaConta && !_AsientoMultidivisa(r) && Convert.ToDecimal(lDtExisteRetencion.Rows[0][
"RETDIV"]) != (Convert.ToDecimal(r[
"debediv"]) - Convert.ToDecimal(r[
"haberdiv"])))
1164 lbDiferenciaRetDivisa =
true;
1170 lbIncidenciaRet =
true;
1172 lDtExisteRetencion.Clear();
1175 if (retencionNoAnotada && lbIncidenciaRet)
1177 dtResultadoRevision.Rows.Add(
1180 String.Format(
"Cuenta de Retención {0}, no anotada en el libro registro de Retenciones.", r[
"cuenta"]));
1183 if (importeRetencion && lbDiferenciaRet)
1185 dtResultadoRevision.Rows.Add(
1188 "Importe del registro de Retenciones, diferente al del asiento.");
1191 if (llDivisaConta && importeRetencion && lbDiferenciaRetDivisa)
1193 dtResultadoRevision.Rows.Add(
1196 "Importe en divisa del registro de Retenciones, diferente al del asiento.");
1201 lDtAsientosVerificarRetencion.Clear();
1209 DataTable lDtAsientosVerificarFechaPeriodo =
new DataTable();
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")));
1216 DB.SQLExec(lsQueryAsientosVerificarFechaPeriodo, ref lDtAsientosVerificarFechaPeriodo);
1217 if (lDtAsientosVerificarFechaPeriodo != null && lDtAsientosVerificarFechaPeriodo.Rows.Count > 0)
1219 foreach (DataRow r
in lDtAsientosVerificarFechaPeriodo.Rows)
1221 dtResultadoRevision.Rows.Add(
1224 "Asiento con fecha fuera del período del ejercicio actual.");
1227 lDtAsientosVerificarFechaPeriodo.Clear();
1236 DataTable lDtAsientosIvaRepercutido =
new DataTable();
1237 DataTable lDtAsientosRecargoRepercutido =
new DataTable();
1239 String lsDigito3IvaRepercutido = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_IvaRep"));
1240 lsDigito3IvaRepercutido = lsDigito3IvaRepercutido.Substring(0, lnDigito3);
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");
1254 DB.SQLExec(lsQueryAsientosIvaRepercutido, ref lDtAsientosIvaRepercutido);
1255 if (lDtAsientosIvaRepercutido != null && lDtAsientosIvaRepercutido.Rows.Count > 0)
1257 DataTable dtMergeAsi = AgruparAsientosReper(lDtAsientosIvaRepercutido);
1259 foreach (DataRow r
in lDtAsientosIvaRepercutido.Rows)
1261 if (!
string.IsNullOrEmpty(r[
"CTA_RE_REP"].ToString().Trim()) && (Convert.ToDecimal(r[
"RECARGO"]) != 0 || Convert.ToDecimal(r[
"RECDIV"]) != 0))
1263 string lsCuentaRecargoRepercutido = r[
"CTA_RE_REP"].ToString();
1264 string lcNumero = r[
"NUMERO"].ToString();
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 +
"' ";
1272 lsQueryAsientosRecargoRepercutido += _Filtro_Fecha(_Filtros,
_Tipo_Filtro_Fecha.Fecha,
"",
"fecha");
1274 DB.SQLExec(lsQueryAsientosRecargoRepercutido, ref lDtAsientosRecargoRepercutido);
1276 if (lDtAsientosRecargoRepercutido != null)
1278 if (lDtAsientosRecargoRepercutido.Rows.Count == 1)
1280 ComprobacionRegistroUnico(lDtAsientosRecargoRepercutido, importeDiferente, r,
false);
1284 if (lDtAsientosRecargoRepercutido.Rows.Count == 0)
1286 ComprobacionIncidencias(
true,
true,
true, r,
false);
1290 ComprobacionRegistrosVarios(lDtAsientosRecargoRepercutido, importeDiferente, dtMergeAsi, r,
false);
1296 lDtAsientosIvaRepercutido.Clear();
1309 foreach (DataRow rec
in ldtAsientosRecargo.Rows)
1311 bool lbDiferImpRecargo =
false;
1312 bool lbDiferImpRecargoDiv =
false;
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"]));
1320 if (Convert.ToDecimal(r[
"RECARGO"]) != nValorRecargo)
1322 lbDiferImpRecargo =
true;
1325 if (llDivisaConta && !_AsientoMultidivisa(rec) && Convert.ToDecimal(r[
"RECDIV"]) != nValorRecargoDiv)
1327 lbDiferImpRecargoDiv =
true;
1330 ComprobacionIncidencias(importeDiferente, lbDiferImpRecargo, lbDiferImpRecargoDiv, r, lbRegistroSopor);
1332 ldtAsientosRecargo.Clear();
1343 protected void ComprobacionRegistrosVarios(DataTable ldtAsientosRecargo,
bool importeDiferente, DataTable dtMergeAsi, DataRow r,
bool lbRegistroSopor)
1345 bool lbDiferImpRecargo =
false;
1346 bool lbDiferImpRecargoDiv =
false;
1348 DataTable dtMergeRecargo = AgruparRecargo(ldtAsientosRecargo);
1350 Int32 lcNumero = Convert.ToInt32(r[
"numero"].ToString());
1351 decimal nRecargo = Convert.ToDecimal(r[
"RECARGO"].ToString());
1352 decimal nRecargoDiv = Convert.ToDecimal(r[
"RECDIV"].ToString());
1354 string lcCampo1 = (lbRegistroSopor ?
"DEBE" :
"HABER");
1355 string lcCampo2 = (lbRegistroSopor ?
"HABER" :
"DEBE");
1356 string lcCampoDiv1 = (lbRegistroSopor ?
"DEBEDIV" :
"HABERDIV");
1357 string lcCampoDiv2 = (lbRegistroSopor ?
"HABERDIV" :
"DEBEDIV");
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>();
1364 lstRegistros = ldtAsientosRecargo.AsEnumerable().Where(g => g.Field<decimal>(lcCampo1) - g.Field<decimal>(lcCampo2) == nRecargo).Select(g => g.Field<
string>(
"CUENTA_RECARGO") ).ToList();
1366 lstRegistrosDiv = ldtAsientosRecargo.AsEnumerable().Where(g => g.Field<decimal>(lcCampoDiv1) - g.Field<decimal>(lcCampoDiv2) == nRecargoDiv).Select(g => g.Field<
string>(
"CUENTA_RECARGO")).ToList();
1368 lstAsientos = dtMergeAsi.AsEnumerable().Where(g => g.Field<Int32>(
"NUMERO") == lcNumero).Select(g => g.Field<decimal>(
"RECARGO")).Distinct().ToList();
1370 lstAsientosDiv = dtMergeAsi.AsEnumerable().Where(g => g.Field<Int32>(
"NUMERO") == lcNumero).Select(g => g.Field<decimal>(
"RECDIV")).Distinct().ToList();
1372 if (lstRegistros.Count != 1)
1374 if (lstRegistros.Count == 0)
1376 if (lstAsientos.Count > 0)
1378 nRecargo = Convert.ToDecimal(lstAsientos[0]);
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();
1383 if (lstRegistros.Count != 1)
1385 lbDiferImpRecargo =
true;
1391 lbDiferImpRecargo =
true;
1395 if (llDivisaConta && !_AsientoMultidivisa(r) && lstRegistrosDiv.Count != 1)
1397 if (lstRegistrosDiv.Count == 0)
1399 if (lstAsientosDiv.Count > 0)
1401 nRecargoDiv = Convert.ToDecimal(lstAsientosDiv[0]);
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();
1406 if (lstRegistrosDiv.Count != 1)
1408 lbDiferImpRecargoDiv =
true;
1414 lbDiferImpRecargoDiv =
true;
1418 ComprobacionIncidencias(importeDiferente, lbDiferImpRecargo, lbDiferImpRecargoDiv, r, lbRegistroSopor);
1427 DataTable lDtAsientosIvaSoportado =
new DataTable();
1428 DataTable lDtAsientosRecargoSoportado =
new DataTable();
1431 String lsDigito3IvaSoportado = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_IvaSop"));
1432 lsDigito3IvaSoportado = lsDigito3IvaSoportado.Substring(0, lnDigito3);
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 ";
1444 lsQueryAsientosIvaSoportado += _Filtro_Fecha(_Filtros,
_Tipo_Filtro_Fecha.Fecha,
"A",
"fecha");
1446 DB.SQLExec(lsQueryAsientosIvaSoportado, ref lDtAsientosIvaSoportado);
1447 if (lDtAsientosIvaSoportado != null && lDtAsientosIvaSoportado.Rows.Count > 0)
1449 DataTable dtMergeAsi = AgruparAsientosSopor(lDtAsientosIvaSoportado);
1451 foreach (DataRow r
in lDtAsientosIvaSoportado.Rows)
1453 if (!
string.IsNullOrEmpty(r[
"CTA_RE_SOP"].ToString().Trim()) && (Convert.ToDecimal(r[
"RECARGO"]) != 0 || Convert.ToDecimal(r[
"RECDIV"]) != 0))
1455 string lsCuentaRecargoRepercutido = r[
"CTA_RE_SOP"].ToString();
1456 string lcNumero = r[
"NUMERO"].ToString();
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 +
"' ";
1464 lsQueryAsientosRecargoSoportado += _Filtro_Fecha(_Filtros,
_Tipo_Filtro_Fecha.Fecha,
"",
"fecha");
1466 DB.SQLExec(lsQueryAsientosRecargoSoportado, ref lDtAsientosRecargoSoportado);
1468 if (lDtAsientosRecargoSoportado != null)
1470 if (lDtAsientosRecargoSoportado.Rows.Count == 1)
1472 ComprobacionRegistroUnico(lDtAsientosRecargoSoportado, importeDiferente, r,
true);
1476 if (lDtAsientosRecargoSoportado.Rows.Count == 0)
1478 ComprobacionIncidencias(
true,
true,
true, r,
true);
1482 ComprobacionRegistrosVarios(lDtAsientosRecargoSoportado, importeDiferente, dtMergeAsi, r,
true);
1488 lDtAsientosIvaSoportado.Clear();
1500 const string TIPO_REVISION =
"TipoRevision";
1502 bool lbResult =
false;
1503 object loParametro = null;
1504 List<string> loLista = null;
1505 String lsTipoRevisionDesde =
string.Empty;
1506 String lsTipoRevisionHasta =
string.Empty;
1508 if (this._Filtros != null && this._Filtros.Count > 0)
1510 this._Filtros.TryGetValue(TIPO_REVISION +
"Lista", out loParametro);
1511 if (loParametro != null)
1514 if (loParametro is
string)
1516 loLista =
new List<String>(loParametro.ToString().Split(
','));
1520 loLista = (List<string>)loParametro;
1523 if (loLista != null && loLista.Count > 0)
1525 this._ActivarMarcas(loLista);
1532 this._Filtros.TryGetValue(TIPO_REVISION +
"Desde", out loParametro);
1533 if (loParametro != null)
1535 lsTipoRevisionDesde = Convert.ToString(loParametro);
1539 this._Filtros.TryGetValue(TIPO_REVISION +
"Hasta", out loParametro);
1540 if (loParametro != null)
1542 lsTipoRevisionHasta = Convert.ToString(loParametro);
1545 if (!String.IsNullOrWhiteSpace(lsTipoRevisionDesde) && !String.IsNullOrWhiteSpace(lsTipoRevisionHasta))
1547 int desde = Convert.ToInt32(lsTipoRevisionDesde);
1548 int hasta = Convert.ToInt32(lsTipoRevisionHasta);
1550 List<String> loListaAux =
new List<string>();
1551 for (
int i = desde; i <= hasta; i++)
1553 loListaAux.Add(i.ToString(
"00"));
1555 this._ActivarMarcas(loListaAux);
1561 this._Filtros.TryGetValue(TIPO_REVISION +
"Unico", out loParametro);
1562 if (loParametro != null)
1564 List<String> loListaAux =
new List<string>();
1565 loListaAux.Add(String.Format(
"{00:0}", loParametro));
1566 this._ActivarMarcas(loListaAux);
1573 this._ActivarMarcas(
true);
1583 this._ActivarMarcas(
true);
1596 if (tiposRevisionSeleccionados != null && tiposRevisionSeleccionados.Count > 0)
1598 foreach (String s
in tiposRevisionSeleccionados)
1604 this.lbAsientosDescuadrados =
true;
1608 this.lbAsientosSinCtaContable =
true;
1612 this.lbAsientosVerificarCuentas =
true;
1616 this.lbImporteInferiorPlanesAnaliticos = this.trabajaConSecundarias;
1620 this.lbImporteSuperiorPlanesAnaliticos = this.trabajaConSecundarias;
1624 this.lbAsientosVerificarPlanesAnaliticos = this.trabajaConSecundarias;
1628 this.lbAsientosSinIVA =
true;
1632 this.lbCuentaDeIVADiferenteAsiento =
true;
1636 this.lbImporteDeIVADiferente =
true;
1640 this.lbRetencionNoAnotada =
true;
1644 this.lbAsientosVerificarRetencion =
true;
1648 this.lbAsientosVerificarFechaPeriodo =
true;
1652 this.lbImporteDeRecargoDiferente =
true;
1666 this.lbAsientosDescuadrados = valor;
1668 this.lbAsientosSinCtaContable = valor;
1670 this.lbAsientosVerificarCuentas = valor;
1672 this.lbImporteInferiorPlanesAnaliticos = valor ? this.trabajaConSecundarias : valor;
1674 this.lbImporteSuperiorPlanesAnaliticos = valor ? this.trabajaConSecundarias : valor;
1676 this.lbAsientosVerificarPlanesAnaliticos = valor ? this.trabajaConSecundarias : valor;
1678 this.lbAsientosSinIVA = valor;
1680 this.lbCuentaDeIVADiferenteAsiento = valor;
1682 this.lbImporteDeIVADiferente = valor;
1684 this.lbRetencionNoAnotada = valor;
1686 this.lbAsientosVerificarRetencion = valor;
1688 this.lbAsientosVerificarFechaPeriodo = valor;
1690 this.lbImporteDeRecargoDiferente = valor;
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();
1706 if (lstAsientos.Count == 1)
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);
1722 lsQueryAsientos +=
" GROUP BY numero, divisa";
1723 DB.SQLExec(lsQueryAsientos, ref lDtAsientos);
1735 var ldtAgrupado = (from item in dt.AsEnumerable()
1738 numero = item.Field<Int32>(
"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();
1775 var ldtAgrupado = (from item in dt.AsEnumerable()
1778 numero = item.Field<Int32>(
"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();
1806 var ldtAgrupado = (from item in dt.AsEnumerable()
1809 numero = item.Field<Int32>(
"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();
1847 protected void ComprobacionIncidencias(
bool importeDiferente,
bool lbDiferImpRecargo,
bool lbDiferImpRecargoDiv, DataRow r,
bool lbRegistroSopor)
1849 string lcCuenta = (lbRegistroSopor ? Convert.ToString(r[
"CTA_RE_SOP"]) : Convert.ToString(r[
"CTA_RE_REP"]));
1850 string lcVariable = (lbRegistroSopor ?
"soportado" :
"repercutido");
1853 if (importeDiferente && lbDiferImpRecargo)
1855 string lsTxtDiferencia =
"Diferencias en importes: el importe de la cuenta " + lcCuenta +
" es diferente al registro de recargo " + lcVariable.ToString();
1857 dtResultadoRevision.Rows.Add(
1864 if (llDivisaConta && importeDiferente && lbDiferImpRecargoDiv)
1866 string lsTxtDiferencia =
"Diferencias en importes: el importe en divisa de la cuenta " + lcCuenta +
" es diferente al registro de recargo " + lcVariable.ToString();
1868 dtResultadoRevision.Rows.Add(
1875 #endregion Métodos privados 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...
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 AgruparRecargo(DataTable dt)
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)
Clase de negocio para el listado de revisión de asientos contables
bool _AsientoMultidivisa(DataRow r)
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
Pantalla
Tipos de pantalla
void _AsientosSinCuentaContable()
Revisa los apuntes sin cuenta contable.
void ComprobacionRegistrosVarios(DataTable ldtAsientosRecargo, bool importeDiferente, DataTable dtMergeAsi, DataRow r, bool lbRegistroSopor)