ResumenAmortizacion.cs
1 #region Referencias WindowsForms
2 
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Text;
7 using System.Data;
8 using System.Windows.Forms;
9 
10 #endregion Referencias WindowsForms
11 
12 #region Referencias Sage50c
13 
14 //Acceso a Base de Datos
15 //Referencia en : C:\sage50c\sage50cterm\Librerias\sage.ew.db.dll
16 using sage.ew.db;
17 
18 //Acceso a variables globales
19 //Referencia en : C:\sage50c\sage50cterm\Librerias\sage.50.exe
20 using sage.ew.global;
21 
22 //Objetos visuales (filtros y opciones)=
23 //Referencia en : C:\sage50c\sage50cterm\Librerias\sage.50.exe
24 using sage.ew.objetos;
25 
26 //Clases utiles de listados
27 //Referencia en : C:\sage50c\sage50cterm\Librerias\sage.50.exe
28 using sage.ew.listados;
29 using sage.ew.listados.Clases;
30 using sage.ew.listados.Listados;
31 using sage.ew.functions;
32 using sage.ew.ewbase;
33 
34 #endregion Referencias Sage50c
35 
36 namespace sage.addons.amortiza.Negocio.Listados
37 {
41  public class ResumenAmortizacion : sage.ew.listados.Clases.Listados
42  {
46  private readonly int _nDesplazamientoInicial = AMORTIZA._Get_Objeto_Amortiza().DesplazamientoInicial;
50  private readonly bool _lDesplazamientoInverso = AMORTIZA._Get_Objeto_Amortiza().DesplazamientoInverso;
51 
55  private readonly bool usarSecundariasFlag = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_secundar")) && (Convert.ToInt32(EW_GLOBAL._GetVariable("wn_TipoProd", 0)) > 0); //Bug Nivel de producto
56 
60  private readonly bool lbColPorcentajeVisible = Convert.ToBoolean(EW_GLOBAL._GetVariable("Wl_DistSec"));
61 
65  protected DateTime ldFechaIniPeriodo = Convert.ToDateTime(EW_GLOBAL._GetVariable("wd_periodoini"));
66 
70  private bool lIncluirDetalleAnal = false;
71 
75  private bool lResumenNivel3 = false;
76 
80  private bool lIncluirPartidasAmortizadas = false;
81 
85  private enum TipoResumen
86  {
87  Contable = 0,
88  Fiscal = 1,
89  Comparativo = 2
90  }
91  private TipoResumen tipoResumen = 0;
92 
96  private enum IncluirPardidas
97  {
98  Alta = 0,
99  Baja = 1,
100  Todas = 2
101  }
102  private IncluirPardidas incluirPardidas = 0;
103 
104  //private string cCuentaDesde = "";
105  //private string cCuentaHasta = "";
106  // private string cNomCtaDesde = "";
107  // private string cNomCtaHasta = "";
108  private string cEjercicio = "";
109 
110  private int nMesIni = 0;
111 
112  private string cNivel3 = " ";
113  private string cSecundaria = "";
114  private string cPrincipal = "";
115  private string cCodPlan = "";
116 
117  decimal nAnyBaja = 0;
118 
119  private decimal nCuentaTotalAct = 0.0M;
120  private decimal nCuentaPdteAct = 0.0M;
121  private decimal nCuentaTotalActFis = 0.0M;
122  private decimal nCuentaPdteActFis = 0.0M;
123  private decimal nCuentaTotalCont = 0.0M;
124  private decimal nCuentaPdteCont = 0.0M;
125  private decimal nCuentaImporte = 0.0M;
126  private decimal nCuentaTotalFis = 0.0M;
127  private decimal nCuentaPdteFis = 0.0M;
128 
129  private decimal nTotalTotalAct = 0.0M;
130  private decimal nTotalPdteAct = 0.0M;
131  private decimal nTotalTotalActFis = 0.0M;
132  private decimal nTotalPdteActFis = 0.0M;
133  private decimal nTotalTotalCont = 0.0M;
134  private decimal nTotalPdteCont = 0.0M;
135  private decimal nTotalImporte = 0.0M;
136  private decimal nTotalTotalFis = 0.0M;
137  private decimal nTotalPdteFis = 0.0M;
138 
139  private decimal nSecunTotalAct = 0.0M;
140  private decimal nSecunPdteAct = 0.0M;
141  private decimal nSecunTotalActFis = 0.0M;
142  private decimal nSecunPdteActFis = 0.0M;
143  private decimal nSecunTotalCont = 0.0M;
144  private decimal nSecunPdteCont = 0.0M;
145  private decimal nSecunImporte = 0.0M;
146  private decimal nSecunTotalFis = 0.0M;
147  private decimal nSecunPdteFis = 0.0M;
148 
149  private decimal nPrinTotalAct = 0.0M;
150  private decimal nPrinPdteAct = 0.0M;
151  private decimal nPrinTotalActFis = 0.0M;
152  private decimal nPrinPdteActFis = 0.0M;
153  private decimal nPrinTotalCont = 0.0M;
154  private decimal nPrinPdteCont = 0.0M;
155  private decimal nPrinImporte = 0.0M;
156  private decimal nPrinTotalFis = 0.0M;
157  private decimal nPrinPdteFis = 0.0M;
158 
162  public override String _ReportFile
163  {
164  get
165  {
166  if (tipoResumen == TipoResumen.Comparativo)
167  {
168  if (usarSecundariasFlag && lIncluirDetalleAnal)
169  {
170  return "resumenamortizacion_comparativo_secun.report";
171  }
172  else
173  {
174  return "resumenamortizacion_comparativo.report";
175  }
176  }
177  else
178  {
179  if (usarSecundariasFlag && lIncluirDetalleAnal)
180  {
181  return "resumenamortizacion_secun.report";
182  }
183  else
184  {
185  return "resumenamortizacion.report";
186  }
187 
188  }
189  }
190  }
191 
196  public override DataTable _DataTable()
197  {
198  // Incluir detalle analítico
199  lIncluirDetalleAnal = _Opcion_Logico("lIncluirdetalleanal");
200  // Presentar resumen cuentas a nivel 3
201  lResumenNivel3 = _Opcion_Logico("lPresentarresumende");
202  // Tipo de resumen
203  tipoResumen = (TipoResumen)_Opcion_Entero("nContableFiscalCom");
204  // Incluir partidas
205  incluirPardidas = (IncluirPardidas)_Opcion_Entero("nAltaBajaTodascomb");
206  // Incluir partidas ya amortizadas
207  lIncluirPartidasAmortizadas = _Opcion_Logico("lIncluirPartidasyaa");
208 
209  #region FILTROS
210  string lcFiltros = "";
211  // Cuentas
212  lcFiltros += _Filtro_String(_Filtros, _Tipo_Filtro_String.Cuenta, "p", "cuenta");
213  // Referencias
214  lcFiltros += _Filtro_String(_Filtros, _Tipo_Filtro_String.Referencia, "p", "referencia");
215  if (usarSecundariasFlag && lIncluirDetalleAnal)
216  {
217  // Secundarias
218  lcFiltros += _Filtro_String(_Filtros, _Tipo_Filtro_String.PlanAnalitico, "pi", "plancont");
219  lcFiltros += _Filtro_String(_Filtros, _Tipo_Filtro_String.AnaliticaNivel1, "pi", "secun");
220  lcFiltros += _Filtro_String(_Filtros, _Tipo_Filtro_String.AnaliticaNivel2, "pi", "secnivel2");
221  }
222  #endregion FILTROS
223 
224  nMesIni = ldFechaIniPeriodo.Month;
225 
226  DataTable dtResult = new DataTable();
227 
228  if (tipoResumen == TipoResumen.Comparativo)
229  {
230  dtResult = ResumenComparativo(lcFiltros);
231  }
232  else
233  {
234  dtResult = ResumenContableFiscal(lcFiltros);
235  }
236 
237  return dtResult;
238  }
239 
245  public override void _SetDefaultValues(Dictionary<string, object> toControlsFiltros = null, Dictionary<string, object> toControlsOpciones = null)
246  {
247  base._SetDefaultValues(toControlsFiltros, toControlsOpciones);
248 
249  string lcFiltro = " left(CODIGO, 3) in (select codigo from " + DB.SQLDatabase("GESTION", "nivel3") + " where amortiza = 1) ";
250 
251  if (toControlsFiltros.ContainsKey("txtCuentaDesdeHasta"))
252  {
253  ew.txtbox.UserControls.txtCuentaDesdeHasta loCuenta = (ew.txtbox.UserControls.txtCuentaDesdeHasta)toControlsFiltros["txtCuentaDesdeHasta"];
254  loCuenta._oFiltroDesde._Browser_Condicion = lcFiltro;
255  loCuenta._oFiltroHasta._Browser_Condicion = lcFiltro;
256  }
257 
258  if (toControlsOpciones != null && toControlsOpciones.ContainsKey("chIncluirdetalleanal"))
259  {
260  ew.objetos.ewcheckbox loCheckSecundarias = (ew.objetos.ewcheckbox)toControlsOpciones["chIncluirdetalleanal"];
261  loCheckSecundarias.Enabled = loCheckSecundarias.Visible = usarSecundariasFlag;
262  }
263 
264  if (toControlsOpciones != null && toControlsOpciones.ContainsKey("chPresentarresumende"))
265  {
266  ew.objetos.ewcheckbox loCheckCuentasNivel3 = (ew.objetos.ewcheckbox)toControlsOpciones["chPresentarresumende"];
267  loCheckCuentasNivel3.Checked = true;
268  }
269 
270  // Incluir detalle analítico
271  lIncluirDetalleAnal = _Opcion_Logico("lIncluirdetalleanal");
272  // Presentar resumen cuentas a nivel 3
273  lResumenNivel3 = _Opcion_Logico("lPresentarresumende");
274  // Tipo de resumen
275  tipoResumen = (TipoResumen)_Opcion_Entero("nContableFiscalCom");
276  // Incluir partidas
277  incluirPardidas = (IncluirPardidas)_Opcion_Entero("nAltaBajaTodascomb");
278  // Incluir partidas ya amortizadas
279  lIncluirPartidasAmortizadas = _Opcion_Logico("lIncluirPartidasyaa");
280 
281 
282  if (toControlsOpciones != null && toControlsOpciones.ContainsKey("cmbAltaBajaTodascomb"))
283  {
284  ew.objetos.ewcombobox loIncluirPartidas = (ew.objetos.ewcombobox)toControlsOpciones["cmbAltaBajaTodascomb"];
285 
286  loIncluirPartidas.SelectedIndex = (int)IncluirPardidas.Todas;
287  incluirPardidas = IncluirPardidas.Todas;
288  }
289 
290  if (toControlsOpciones != null && toControlsOpciones.ContainsKey("chIncluirpartidasyaa"))
291  {
292  ew.objetos.ewcheckbox loCheckPartidasAmortizadas = (ew.objetos.ewcheckbox)toControlsOpciones["chIncluirpartidasyaa"];
293 
294  }
295 
296 
297  }
298 
299 
304  public override bool _Valid()
305  {
306  if (diccionarioControlesFiltros.ContainsKey("txtPeriodoExtendidoDesdeHasta"))
307  {
308  ew.txtbox.UserControls.txtPeriodoExtendidoDesdeHasta loEjercicio = (ew.txtbox.UserControls.txtPeriodoExtendidoDesdeHasta)diccionarioControlesFiltros["txtPeriodoExtendidoDesdeHasta"];
309  cEjercicio = loEjercicio._Desde;
310  }
311 
312  return true;
313  }
314 
318  public override void _SetColumnMasks()
319  {
320  if (this._Resultados == null)
321  return;
322 
323 
324  foreach (DataColumn ldc in this._Resultados.Columns)
325  {
326  //PE-104822 Ordenación bloqueada
327  ldc.ExtendedProperties.Add("SortMode", DataGridViewColumnSortMode.NotSortable);
328 
329  switch (ldc.ColumnName.ToString().Trim())
330  {
331  case "bajainmo":
332  case "fecha":
333  ldc.ExtendedProperties.Add("Mascara", "dd/MM/yyyy");
334  break;
335  case "porcont":
336  case "porfis":
337  case "porcenna1":
338  case "porcenna2":
339  ldc.ExtendedProperties.Add("Mascara", this._Mascara_TPC_IVA);
340  break;
341  case "importe":
342  case "totalcont":
343  case "totalfis":
344  case "pdtecont":
345  case "pdtefis":
346  case "totalact":
347  case "totalactfis":
348  case "pdteact":
349  case "pdteactfis":
350  ldc.ExtendedProperties.Add("Mascara", this._Mascara_Importe);
351  break;
352  }
353  }
354 
355  base._SetColumnMasks();
356  }
357 
361  public override List<string> _ReportColumns
362  {
363  get
364  {
365  _dicDefEntidades = new Dictionary<string, ew.interficies.IDefEntidad>
366  {
367  { "cuenta", new DefEntidad() { _DB = "GESTION", _Tabla = "CUENTAS", _Campo = "CODIGO", _Relacion = "", _Empresa = false } },
368  { "codigo", new DefEntidad() { _DB = "GESTION", _Tabla = "NIVEL3", _Campo = "CODIGO", _Relacion = "", _Empresa = false } },
369  { "referencia", new DefEntidad() { _DB = "AMORTIZA", _Tabla = "PARTINVE", _Campo = "REFERENCIA", _Relacion = "", _Empresa = true } }
370  };
371 
372  List<string> listaCampos = new List<string>
373  {
374  "cuenta",
375  "referencia",
376  "fecha",
377  "porcont"
378  };
379 
380  if (tipoResumen == TipoResumen.Comparativo)
381  listaCampos.Add("porfis");
382 
383  listaCampos.Add("importe");
384  listaCampos.Add("totalcont");
385 
386  if (tipoResumen == TipoResumen.Comparativo)
387  listaCampos.Add("totalfis");
388 
389  listaCampos.Add("pdtecont");
390 
391  if (tipoResumen == TipoResumen.Comparativo)
392  listaCampos.Add("pdtefis");
393 
394  listaCampos.Add("totalact");
395 
396  if (tipoResumen == TipoResumen.Comparativo)
397  listaCampos.Add("totalactfis");
398 
399  listaCampos.Add("pdteact");
400 
401  if (tipoResumen == TipoResumen.Comparativo)
402  listaCampos.Add("pdteactfis");
403 
404  listaCampos.Add("concepto");
405  listaCampos.Add("bajainmo");
406 
407  if (usarSecundariasFlag && lIncluirDetalleAnal)
408  {
409  listaCampos.Add("codplan");
410  listaCampos.Add("codigona1");
411  if (lbColPorcentajeVisible)
412  listaCampos.Add("porcenna1");
413 
414  listaCampos.Add("codigona2");
415  if (lbColPorcentajeVisible)
416  listaCampos.Add("porcenna2");
417  }
418 
419  return listaCampos;
420  }
421  }
422 
426  public override void _SetColumnCaptions(Dictionary<string, string> tldTranslate = null)
427  {
428 
429  Dictionary<string, string> ldTranslate = new Dictionary<string, string>
430  {
431  { "porcont", (tipoResumen == TipoResumen.Fiscal) ? "@% Fiscal" : "@% Contable" },
432  { "porfis", "@% Fiscal" },
433  { "importe", "@Importe" },
434  { "totalcont", (tipoResumen != TipoResumen.Comparativo) ? "Amortizado" : "Amortizado contable" },
435  { "totalfis", "Amortizado fiscal" },
436  { "pdtecont", (tipoResumen != TipoResumen.Comparativo) ? "Pendiente" : "Pendiente contable" },
437  { "pdtefis", "Pendiente fiscal" },
438  { "totalact", (tipoResumen != TipoResumen.Comparativo) ? "Amortizado año" : "Amortizado año contable" },
439  { "totalactfis", "Amortizado año fiscal" },
440  { "pdteact", (tipoResumen != TipoResumen.Comparativo) ? "Pendiente año" : "Pendiente año contable" },
441  { "pdteactfis", "Pendiente año fiscal" },
442  { "concepto", "Observaciones" },
443  { "bajainmo", "Fecha baja" }
444  };
445  if (usarSecundariasFlag && lIncluirDetalleAnal)
446  {
447  ldTranslate.Add("codplan", "Plan analítico");
448  ldTranslate.Add("codigona1", "Nivel analítico 1");
449  if (lbColPorcentajeVisible)
450  ldTranslate.Add("porcenna1", "% na1");
451 
452  ldTranslate.Add("codigona2", "Nivel analítico 2");
453  if (lbColPorcentajeVisible)
454  ldTranslate.Add("porcenna2", "% na2");
455  }
456 
457  base._SetColumnCaptions(ldTranslate);
458  }
459 
463  public override void _SetColumnWidth(Dictionary<string, int> tldTranslate = null)
464  {
465  Dictionary<string, int> ldTranslate = new Dictionary<string, int>
466  {
467  { "porcont", 100 },
468  { "porfis", 100 },
469  { "importe", 100 },
470  { "totalcont", 200 },
471  { "totalfis", 200 },
472  { "pdtecont", 200 },
473  { "pdtefis", 200 },
474  { "totalact", 200 },
475  { "totalactfis", 200 },
476  { "pdteact", 200 },
477  { "pdteactfis", 200 }
478  };
479 
480  base._SetColumnWidth(ldTranslate);
481  }
482 
487  public override Dictionary<string, Dictionary<string, object>> AnalisisResultados
488  {
489  get
490  {
491  return new Dictionary<string, Dictionary<string, object>>() {
492  { "[bajainmo] is not null", new Dictionary<string, object>() {
493  { "backcolor", System.Drawing.Color.White },
494  { "forecolor", System.Drawing.Color.Red } }
495  } };
496  }
497  set
498  {
499  base.AnalisisResultados = value;
500  }
501  }
502 
506  public override Dictionary<string, string> _NavigateButtons
507  {
508  get
509  {
510  return new Dictionary<string, string>() { { "Partida", "Ver partida" } };
511  }
512  set
513  {
514  base._NavigateButtons = value;
515  }
516  }
522  public override void _Navigate(String tcKeyNavigate, DataRow trRow)
523  {
524  if (trRow == null)
525  return;
526 
527 
528  switch (tcKeyNavigate)
529  {
530  case "Partida":
531  // Empresa activa
532  string lcEmpresa = Convert.ToString(EW_GLOBAL._GetVariable("wc_empresa"));
533  string lcCuenta = Convert.ToString(trRow["cuenta"]).TrimEnd();
534  string lcReferencia = Convert.ToString(trRow["referencia"]).TrimEnd();
535  if (!string.IsNullOrWhiteSpace(lcCuenta) && !string.IsNullOrWhiteSpace(lcReferencia))
536  {
537  Mantes.Partidas loPartida = new Mantes.Partidas
538  {
539  _Empresa = lcEmpresa,
540  _Cuenta = lcCuenta,
541  _Referencia = lcReferencia
542  };
543  loPartida._Load();
544  loPartida._Show();
545  }
546  break;
547  }
548 
549  }
550 
556  private DataTable ResumenComparativo(string lcFiltros)
557  {
558  InicializarVariables();
559 
560  DataTable dtDades = new DataTable();
561  dtDades.Columns.Add("concepto", typeof(string));
562  dtDades.Columns.Add("empresa", typeof(string));
563  dtDades.Columns.Add("bajainmo", typeof(DateTime));
564  dtDades.Columns.Add("cuenta", typeof(string));
565  dtDades.Columns.Add("referencia", typeof(string));
566  dtDades.Columns.Add("totalact", typeof(decimal));
567  dtDades.Columns.Add("pdteact", typeof(decimal));
568  dtDades.Columns.Add("totalactfis", typeof(decimal));
569  dtDades.Columns.Add("pdteactfis", typeof(decimal));
570  dtDades.Columns.Add("totalcont", typeof(decimal));
571  dtDades.Columns.Add("pdtecont", typeof(decimal));
572  dtDades.Columns.Add("porcont", typeof(decimal));
573  dtDades.Columns.Add("importe", typeof(decimal));
574  dtDades.Columns.Add("fecha", typeof(DateTime));
575  dtDades.Columns.Add("totalfis", typeof(decimal));
576  dtDades.Columns.Add("pdtefis", typeof(decimal));
577  dtDades.Columns.Add("porfis", typeof(decimal));
578  dtDades.Columns.Add("codplan", typeof(string));
579  dtDades.Columns.Add("codigona1", typeof(string));
580  dtDades.Columns.Add("porcenna1", typeof(decimal));
581  dtDades.Columns.Add("codigona2", typeof(string));
582  dtDades.Columns.Add("porcenna2", typeof(decimal));
583  dtDades.Columns.Add("nivel3", typeof(string));
584  dtDades.Columns.Add("bold", typeof(Boolean));
585 
586  string lcSql = "";
587  string lcSql1 = "";
588 
589  DataTable dtTmp_d1e = new DataTable();
590  DataTable dtTmp_d1 = new DataTable();
591  DataTable dtTmp_d2e = new DataTable();
592  DataTable dtTmp_d2 = new DataTable();
593  DataTable dtTmp_d = new DataTable();
594 
595  lcSql = " SELECT SPACE(200) as concepto, p.empresa, MAX(p.bajainmo) as bajainmo, p.cuenta, p.referencia, " +
596  " 00000000.0000 as TotalAct, 00000000.00 as PdteAct, 00000000.0000 as TotalActFis, 00000000.00 as PdteActFis, " +
597  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_01 = " + DB.SQLTrue(), "t.M_01", "000000000.00"), "000000000.00") + ") +" +
598  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_02 = " + DB.SQLTrue(), "t.M_02", "000000000.00"), "000000000.00") + ") +" +
599  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_03 = " + DB.SQLTrue(), "t.M_03", "000000000.00"), "000000000.00") + ") +" +
600  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_04 = " + DB.SQLTrue(), "t.M_04", "000000000.00"), "000000000.00") + ") +" +
601  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_05 = " + DB.SQLTrue(), "t.M_05", "000000000.00"), "000000000.00") + ") +" +
602  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_06 = " + DB.SQLTrue(), "t.M_06", "000000000.00"), "000000000.00") + ") +" +
603  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_07 = " + DB.SQLTrue(), "t.M_07", "000000000.00"), "000000000.00") + ") +" +
604  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_08 = " + DB.SQLTrue(), "t.M_08", "000000000.00"), "000000000.00") + ") +" +
605  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_09 = " + DB.SQLTrue(), "t.M_09", "000000000.00"), "000000000.00") + ") +" +
606  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_10 = " + DB.SQLTrue(), "t.M_10", "000000000.00"), "000000000.00") + ") +" +
607  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_11 = " + DB.SQLTrue(), "t.M_11", "000000000.00"), "000000000.00") + ") +" +
608  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_12 = " + DB.SQLTrue(), "t.M_12", "000000000.00"), "000000000.00") + ") as TotalCont, " +
609  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_01 = " + DB.SQLFalse(), "t.M_01", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
610  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_02 = " + DB.SQLFalse(), "t.M_02", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
611  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_03 = " + DB.SQLFalse(), "t.M_03", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
612  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_04 = " + DB.SQLFalse(), "t.M_04", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
613  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_05 = " + DB.SQLFalse(), "t.M_05", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
614  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_06 = " + DB.SQLFalse(), "t.M_06", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
615  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_07 = " + DB.SQLFalse(), "t.M_07", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
616  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_08 = " + DB.SQLFalse(), "t.M_08", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
617  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_09 = " + DB.SQLFalse(), "t.M_09", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
618  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_10 = " + DB.SQLFalse(), "t.M_10", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
619  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_11 = " + DB.SQLFalse(), "t.M_11", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
620  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_12 = " + DB.SQLFalse(), "t.M_12", "000000000.00"), "000000000.00"), "000000000.00") + ") as PdteCont, " +
621  " MAX(p.porcont) as porcont, MAX(p.importe) as importe, MAX(p.fecha) as fecha, MAX(p.porfis) as PorFis, " +
622  (usarSecundariasFlag && lIncluirDetalleAnal ? (" pi.plancont as codplan, pi.secun as codigona1, 000000000.00 as porcenna1, pi.secnivel2 as codigona2, " + DB.SQLNvl("MAX(pi.porcen)", "000000000.00") + " as porcenna2, ") : (" SPACE(200) as codplan, SPACE(200) as codigona1, SPACE(30) as porcenna1, SPACE(200) as codigona2, SPACE(30) as porcenna2, ")) +
623  " MAX(LEFT(p.cuenta, 3)) as Nivel3 " +
624  " FROM " + DB.SQLDatabase("AMORTIZA", "PARTINVE") + " p " +
625  " LEFT JOIN " + DB.SQLDatabase("AMORTIZA", "TABLA_AM") + " t ON p.empresa+p.cuenta+p.referencia = t.empresa+t.cuenta+t.referencia AND t.periodo < " + DB.SQLString(cEjercicio) +
626  (usarSecundariasFlag && lIncluirDetalleAnal ? " LEFT JOIN " + DB.SQLDatabase("AMORTIZA", "PI_SECUN") + " pi ON p.empresa = pi.empresa AND p.cuenta = pi.cuenta AND p.referencia = pi.referencia " : "") +
627  " WHERE p.empresa = " + DB.SQLString(EW_GLOBAL._GetVariable("wc_empresa")) + lcFiltros +
628  (incluirPardidas == IncluirPardidas.Baja ? " AND " + DB.SQLString(cEjercicio) + " >= YEAR(p.bajainmo)" : " AND " + DB.SQLString(cEjercicio) + " >= YEAR(p.inici_amor)") +
629  " GROUP BY p.empresa, " + (usarSecundariasFlag && lIncluirDetalleAnal ? "p.cuenta, p.referencia, pi.plancont, pi.secun, pi.secnivel2 " : "p.cuenta, p.referencia") +
630  " ORDER BY p.empresa, " + (usarSecundariasFlag && lIncluirDetalleAnal ? "p.cuenta, p.referencia, pi.plancont, pi.secun, pi.secnivel2" : "p.cuenta, p.referencia");
631 
632  DB.SQLExec(lcSql, ref dtTmp_d1e);
633 
634  if (dtTmp_d1e != null && dtTmp_d1e.Rows.Count > 0)
635  {
636  dtTmp_d1 = InsertarRegistrosTabla(dtTmp_d1e);
637  }
638 
639  lcSql1 = " SELECT p.empresa, p.cuenta, p.referencia, MAX(p.bajainmo) as bajainmo, " +
640  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_01 = " + DB.SQLTrue(), "t.M_01", "000000000.00"), "000000000.00") + ") +" +
641  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_02 = " + DB.SQLTrue(), "t.M_02", "000000000.00"), "000000000.00") + ") +" +
642  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_03 = " + DB.SQLTrue(), "t.M_03", "000000000.00"), "000000000.00") + ") +" +
643  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_04 = " + DB.SQLTrue(), "t.M_04", "000000000.00"), "000000000.00") + ") +" +
644  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_05 = " + DB.SQLTrue(), "t.M_05", "000000000.00"), "000000000.00") + ") +" +
645  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_06 = " + DB.SQLTrue(), "t.M_06", "000000000.00"), "000000000.00") + ") +" +
646  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_07 = " + DB.SQLTrue(), "t.M_07", "000000000.00"), "000000000.00") + ") +" +
647  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_08 = " + DB.SQLTrue(), "t.M_08", "000000000.00"), "000000000.00") + ") +" +
648  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_09 = " + DB.SQLTrue(), "t.M_09", "000000000.00"), "000000000.00") + ") +" +
649  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_10 = " + DB.SQLTrue(), "t.M_10", "000000000.00"), "000000000.00") + ") +" +
650  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_11 = " + DB.SQLTrue(), "t.M_11", "000000000.00"), "000000000.00") + ") +" +
651  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_12 = " + DB.SQLTrue(), "t.M_12", "000000000.00"), "000000000.00") + ") as TotalFis, " +
652  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_01 = " + DB.SQLFalse(), "t.M_01", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
653  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_02 = " + DB.SQLFalse(), "t.M_02", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
654  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_03 = " + DB.SQLFalse(), "t.M_03", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
655  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_04 = " + DB.SQLFalse(), "t.M_04", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
656  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_05 = " + DB.SQLFalse(), "t.M_05", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
657  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_06 = " + DB.SQLFalse(), "t.M_06", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
658  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_07 = " + DB.SQLFalse(), "t.M_07", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
659  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_08 = " + DB.SQLFalse(), "t.M_08", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
660  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_09 = " + DB.SQLFalse(), "t.M_09", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
661  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_10 = " + DB.SQLFalse(), "t.M_10", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
662  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_11 = " + DB.SQLFalse(), "t.M_11", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
663  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_12 = " + DB.SQLFalse(), "t.M_12", "000000000.00"), "000000000.00"), "000000000.00") + ") as PdteFis, " +
664  " MAX(p.porcont) as porcont, MAX(p.importe) as importe, MAX(p.fecha) as fecha, MAX(p.porfis) as PorFis, " +
665  (usarSecundariasFlag && lIncluirDetalleAnal ? (" pi.plancont as codplan, pi.secun as codigona1, 000000000.00 as porcenna1, pi.secnivel2 as codigona2, " + DB.SQLNvl("MAX(pi.porcen)", "000000000.00") + " as porcenna2, ") : (" SPACE(200) as codplan, SPACE(200) as codigona1, SPACE(30) as porcenna1, SPACE(200) as codigona2, SPACE(30) as porcenna2, ")) +
666  " MAX(LEFT(p.cuenta, 3)) as Nivel3 " +
667  " FROM " + DB.SQLDatabase("AMORTIZA", "PARTINVE") + " p " +
668  " LEFT JOIN " + DB.SQLDatabase("AMORTIZA", "TABLA_FI") + " t ON p.empresa+p.cuenta+p.referencia = t.empresa+t.cuenta+t.referencia AND t.periodo < " + DB.SQLString(cEjercicio) +
669  (usarSecundariasFlag && lIncluirDetalleAnal ? " LEFT JOIN " + DB.SQLDatabase("AMORTIZA", "PI_SECUN") + " pi ON p.empresa = pi.empresa AND p.cuenta = pi.cuenta AND p.referencia = pi.referencia " : "") +
670  " WHERE p.empresa = " + DB.SQLString(EW_GLOBAL._GetVariable("wc_empresa")) + lcFiltros +
671  (incluirPardidas == IncluirPardidas.Baja ? " AND " + DB.SQLString(cEjercicio) + " >= YEAR(p.bajainmo)" : " AND " + DB.SQLString(cEjercicio) + " >= YEAR(p.inici_amor)") +
672  " GROUP BY p.empresa, " + (usarSecundariasFlag && lIncluirDetalleAnal ? "p.cuenta, pi.plancont, pi.secun, pi.secnivel2, p.referencia" : "p.cuenta, p.referencia") +
673  " ORDER BY p.empresa, " + (usarSecundariasFlag && lIncluirDetalleAnal ? "p.cuenta, pi.plancont, pi.secun, pi.secnivel2, p.referencia" : "p.cuenta, p.referencia");
674 
675  DB.SQLExec(lcSql1, ref dtTmp_d2e);
676 
677  if (dtTmp_d2e != null && dtTmp_d2e.Rows.Count > 0)
678  {
679  dtTmp_d2 = InsertarRegistrosTabla(dtTmp_d2e);
680  }
681 
682  if (usarSecundariasFlag && lIncluirDetalleAnal)
683  {
684  dtTmp_d = (from a in dtTmp_d1.AsEnumerable()
685  join b in dtTmp_d2.AsEnumerable()
686  on new
687  {
688  empresa = a.Field<string>("empresa"),
689  cuenta = a.Field<string>("cuenta"),
690  referencia = a.Field<string>("referencia"),
691  codplan = a.Field<string>("codplan"),
692  codigona1 = a.Field<string>("codigona1"),
693  codigona2 = a.Field<string>("codigona2")
694  }
695  equals new
696  {
697  empresa = b.Field<string>("empresa"),
698  cuenta = b.Field<string>("cuenta"),
699  referencia = b.Field<string>("referencia"),
700  codplan = b.Field<string>("codplan"),
701  codigona1 = b.Field<string>("codigona1"),
702  codigona2 = b.Field<string>("codigona2")
703  }
704  into leftJoin
705  from c in leftJoin.DefaultIfEmpty()
706  select new
707  {
708  empresa = a.Field<string>("empresa"),
709  cuenta = a.Field<string>("cuenta"),
710  referencia = a.Field<string>("referencia"),
711  concepto = a.Field<string>("concepto"),
712  bajainmo = (DateTime?)a.Field<DateTime?>("bajainmo"),
713  totalact = a.Field<decimal>("totalact"),
714  pdteact = a.Field<decimal>("pdteact"),
715  totalactfis = a.Field<decimal>("totalactfis"),
716  pdteactfis = a.Field<decimal>("pdteactfis"),
717  totalfis = (c != null ? c.Field<decimal>("totalfis") : Convert.ToDecimal(0)),
718  pdtefis = (c != null ? c.Field<decimal>("pdtefis") : Convert.ToDecimal(0)),
719  totalcont = a.Field<decimal>("totalcont"),
720  pdtecont = a.Field<decimal>("pdtecont"),
721  porcont = a.Field<decimal>("porcont"),
722  importe = a.Field<decimal>("importe"),
723  fecha = (DateTime?)a.Field<DateTime?>("fecha"),
724  porfis = a.Field<decimal>("porfis"),
725  codplan = (c != null ? c.Field<string>("codplan") : string.Empty),
726  codigona1 = (c != null ? c.Field<string>("codigona1") : string.Empty),
727  porcenna1 = (c != null ? c.Field<decimal>("porcenna1") : Convert.ToDecimal(0)),
728  codigona2 = (c != null ? c.Field<string>("codigona2") : string.Empty),
729  porcenna2 = (c != null ? c.Field<decimal>("porcenna2") : Convert.ToDecimal(0)),
730  nivel3 = a.Field<string>("nivel3")
731  }).__CopyToDataTable();
732  }
733  else
734  {
735  dtTmp_d = (from a in dtTmp_d1.AsEnumerable()
736  join b in dtTmp_d2.AsEnumerable()
737  on new
738  {
739  empresa = a.Field<string>("empresa"),
740  cuenta = a.Field<string>("cuenta"),
741  referencia = a.Field<string>("referencia"),
742  }
743  equals new
744  {
745  empresa = b.Field<string>("empresa"),
746  cuenta = b.Field<string>("cuenta"),
747  referencia = b.Field<string>("referencia"),
748  }
749  into leftJoin
750  from c in leftJoin.DefaultIfEmpty()
751  select new
752  {
753  empresa = a.Field<string>("empresa"),
754  cuenta = a.Field<string>("cuenta"),
755  referencia = a.Field<string>("referencia"),
756  concepto = a.Field<string>("concepto"),
757  bajainmo = (DateTime?)a.Field<DateTime?>("bajainmo"),
758  totalact = a.Field<decimal>("totalact"),
759  pdteact = a.Field<decimal>("pdteact"),
760  totalactfis = a.Field<decimal>("totalactfis"),
761  pdteactfis = a.Field<decimal>("pdteactfis"),
762  totalfis = (c != null ? c.Field<decimal>("totalfis") : Convert.ToDecimal(0)),
763  pdtefis = (c != null ? c.Field<decimal>("pdtefis") : Convert.ToDecimal(0)),
764  totalcont = a.Field<decimal>("totalcont"),
765  pdtecont = a.Field<decimal>("pdtecont"),
766  porcont = a.Field<decimal>("porcont"),
767  importe = a.Field<decimal>("importe"),
768  fecha = (DateTime?)a.Field<DateTime?>("fecha"),
769  porfis = a.Field<decimal>("porfis"),
770  codplan = string.Empty,
771  codigona1 = string.Empty,
772  porcenna1 = Convert.ToDecimal(0),
773  codigona2 = string.Empty,
774  porcenna2 = Convert.ToDecimal(0),
775  nivel3 = a.Field<string>("nivel3")
776  }).__CopyToDataTable();
777  }
778 
779  if (dtTmp_d != null && dtTmp_d.Rows.Count > 0)
780  {
781  if (usarSecundariasFlag && lIncluirDetalleAnal && lbColPorcentajeVisible)
782  {
783  Calcularporcentajena1(dtTmp_d);
784  }
785 
786  PintarResultados(dtDades, dtTmp_d);
787 
788  PintarTotales(dtDades);
789  }
790 
791  return dtDades;
792  }
793 
799  private DataTable ResumenContableFiscal(string lcFiltros)
800  {
801  InicializarVariables();
802 
803  DataTable dtDades = new DataTable();
804  dtDades.Columns.Add("concepto", typeof(string));
805  dtDades.Columns.Add("cuenta", typeof(string));
806  dtDades.Columns.Add("referencia", typeof(string));
807  dtDades.Columns.Add("nivel3", typeof(string));
808  dtDades.Columns.Add("totalact", typeof(decimal));
809  dtDades.Columns.Add("pdteact", typeof(decimal));
810  dtDades.Columns.Add("totalcont", typeof(decimal));
811  dtDades.Columns.Add("pdtecont", typeof(decimal));
812  dtDades.Columns.Add("porcont", typeof(decimal));
813  dtDades.Columns.Add("importe", typeof(decimal));
814  dtDades.Columns.Add("fecha", typeof(DateTime));
815  dtDades.Columns.Add("empresa", typeof(string));
816  dtDades.Columns.Add("bajainmo", typeof(DateTime));
817  dtDades.Columns.Add("porcen", typeof(string));
818  dtDades.Columns.Add("codplan", typeof(string));
819  dtDades.Columns.Add("codigona1", typeof(string));
820  dtDades.Columns.Add("porcenna1", typeof(decimal));
821  dtDades.Columns.Add("codigona2", typeof(string));
822  dtDades.Columns.Add("porcenna2", typeof(decimal));
823  dtDades.Columns.Add("bold", typeof(Boolean));
824 
825  string cTabla = "";
826  string lcSql = "";
827  string lcCondicion = "";
828 
829  if (_nDesplazamientoInicial > 0)
830  {
831  lcCondicion = "-1";
832  }
833 
834  DataTable dtTmp_e = new DataTable();
835  DataTable dtTmp_d = new DataTable();
836 
837  if (tipoResumen == TipoResumen.Contable)
838  {
839  cTabla = "TABLA_AM";
840 
841  // Trabaja con secundarias e incluir partidas
842  if (usarSecundariasFlag && lIncluirDetalleAnal)
843  {
844  #region CONTABLE, SECUNDARIA E INCLUIR DETALLE ANALITICO
845  lcSql = " SELECT p.cuenta, p.referencia, SPACE(200) as concepto, MAX(LEFT(p.cuenta,3)) as Nivel3, " +
846  " 00000000.0000 as TotalAct, 00000000.00 as PdteAct, " +
847  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_01 = " + DB.SQLTrue(), "t.M_01", "000000000.00"), "000000000.00") + ") +" +
848  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_02 = " + DB.SQLTrue(), "t.M_02", "000000000.00"), "000000000.00") + ") +" +
849  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_03 = " + DB.SQLTrue(), "t.M_03", "000000000.00"), "000000000.00") + ") +" +
850  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_04 = " + DB.SQLTrue(), "t.M_04", "000000000.00"), "000000000.00") + ") +" +
851  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_05 = " + DB.SQLTrue(), "t.M_05", "000000000.00"), "000000000.00") + ") +" +
852  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_06 = " + DB.SQLTrue(), "t.M_06", "000000000.00"), "000000000.00") + ") +" +
853  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_07 = " + DB.SQLTrue(), "t.M_07", "000000000.00"), "000000000.00") + ") +" +
854  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_08 = " + DB.SQLTrue(), "t.M_08", "000000000.00"), "000000000.00") + ") +" +
855  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_09 = " + DB.SQLTrue(), "t.M_09", "000000000.00"), "000000000.00") + ") +" +
856  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_10 = " + DB.SQLTrue(), "t.M_10", "000000000.00"), "000000000.00") + ") +" +
857  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_11 = " + DB.SQLTrue(), "t.M_11", "000000000.00"), "000000000.00") + ") +" +
858  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_12 = " + DB.SQLTrue(), "t.M_12", "000000000.00"), "000000000.00") + ") as TotalCont, " +
859  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_01 = " + DB.SQLFalse(), "t.M_01", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
860  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_02 = " + DB.SQLFalse(), "t.M_02", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
861  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_03 = " + DB.SQLFalse(), "t.M_03", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
862  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_04 = " + DB.SQLFalse(), "t.M_04", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
863  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_05 = " + DB.SQLFalse(), "t.M_05", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
864  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_06 = " + DB.SQLFalse(), "t.M_06", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
865  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_07 = " + DB.SQLFalse(), "t.M_07", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
866  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_08 = " + DB.SQLFalse(), "t.M_08", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
867  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_09 = " + DB.SQLFalse(), "t.M_09", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
868  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_10 = " + DB.SQLFalse(), "t.M_10", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
869  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_11 = " + DB.SQLFalse(), "t.M_11", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
870  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_12 = " + DB.SQLFalse(), "t.M_12", "000000000.00"), "000000000.00"), "000000000.00") + ") as PdteCont, " +
871  " MAX(p.porcont) as porcont, MAX(p.importe) as importe, MAX(p.fecha) as fecha, p.empresa, MAX(p.bajainmo) as bajainmo, " +
872  DB.SQLNvl("MAX(pi.porcen)", "000000000.00000") + "as porcen, " +
873  " MAX(pi.plancont) as codplan, MAX(pi.secun) as codigona1, SPACE(30) as porcenna1, MAX(pi.secnivel2) as codigona2, MAX(pi.porcen) as porcenna2 " +
874  " FROM " + DB.SQLDatabase("AMORTIZA", "PARTINVE") + " p " +
875  " LEFT JOIN " + DB.SQLDatabase("AMORTIZA", cTabla) + " t ON p.empresa = t.empresa AND p.cuenta = t.cuenta AND p.referencia = t.referencia AND t.periodo <= " + DB.SQLString(cEjercicio) +
876  " LEFT JOIN " + DB.SQLDatabase("AMORTIZA", "PI_SECUN") + " pi ON p.empresa = pi.empresa AND p.cuenta = pi.cuenta AND p.referencia = pi.referencia " +
877  " WHERE p.empresa = " + DB.SQLString(EW_GLOBAL._GetVariable("wc_empresa")) + lcFiltros +
878  (incluirPardidas == IncluirPardidas.Baja ? " AND " + DB.SQLString(cEjercicio) + " >= YEAR(p.bajainmo)" : " AND " + DB.SQLString(cEjercicio) + " >= YEAR(p.inici_amor)") + lcCondicion +
879  " GROUP BY p.empresa, p.cuenta, p.referencia, pi.plancont, pi.secun, pi.secnivel2 " +
880  " ORDER BY p.empresa, p.cuenta, p.referencia, pi.plancont, pi.secun, pi.secnivel2";
881 
882  #endregion CONTABLE, SECUNDARIA E INCLUIR DETALLE ANALITICOS
883  }
884  else
885  {
886  #region CONTABLE
887  lcSql = " SELECT SPACE(200) AS concepto, MAX(LEFT(p.cuenta, 3)) as Nivel3, p.cuenta, p.referencia, 00000000.0000 as TotalAct, 00000000.00 as PdteAct, " +
888  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_01 = " + DB.SQLTrue(), "t.M_01", "000000000.00"), "000000000.00") + ") +" +
889  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_02 = " + DB.SQLTrue(), "t.M_02", "000000000.00"), "000000000.00") + ") +" +
890  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_03 = " + DB.SQLTrue(), "t.M_03", "000000000.00"), "000000000.00") + ") +" +
891  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_04 = " + DB.SQLTrue(), "t.M_04", "000000000.00"), "000000000.00") + ") +" +
892  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_05 = " + DB.SQLTrue(), "t.M_05", "000000000.00"), "000000000.00") + ") +" +
893  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_06 = " + DB.SQLTrue(), "t.M_06", "000000000.00"), "000000000.00") + ") +" +
894  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_07 = " + DB.SQLTrue(), "t.M_07", "000000000.00"), "000000000.00") + ") +" +
895  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_08 = " + DB.SQLTrue(), "t.M_08", "000000000.00"), "000000000.00") + ") +" +
896  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_09 = " + DB.SQLTrue(), "t.M_09", "000000000.00"), "000000000.00") + ") +" +
897  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_10 = " + DB.SQLTrue(), "t.M_10", "000000000.00"), "000000000.00") + ") +" +
898  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_11 = " + DB.SQLTrue(), "t.M_11", "000000000.00"), "000000000.00") + ") +" +
899  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_12 = " + DB.SQLTrue(), "t.M_12", "000000000.00"), "000000000.00") + ") as TotalCont, " +
900  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_01 = " + DB.SQLFalse(), "t.M_01", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
901  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_02 = " + DB.SQLFalse(), "t.M_02", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
902  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_03 = " + DB.SQLFalse(), "t.M_03", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
903  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_04 = " + DB.SQLFalse(), "t.M_04", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
904  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_05 = " + DB.SQLFalse(), "t.M_05", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
905  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_06 = " + DB.SQLFalse(), "t.M_06", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
906  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_07 = " + DB.SQLFalse(), "t.M_07", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
907  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_08 = " + DB.SQLFalse(), "t.M_08", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
908  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_09 = " + DB.SQLFalse(), "t.M_09", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
909  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_10 = " + DB.SQLFalse(), "t.M_10", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
910  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_11 = " + DB.SQLFalse(), "t.M_11", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
911  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_12 = " + DB.SQLFalse(), "t.M_12", "000000000.00"), "000000000.00"), "000000000.00") + ") as PdteCont, " +
912  " MAX(p.porcont) as porcont, MAX(p.importe) as importe, MAX(p.fecha) as fecha, p.empresa, MAX(p.bajainmo) as bajainmo, " +
913  " SPACE(200) as codplan, SPACE(200) as codigona1, SPACE(30) as porcenna1, SPACE(200) as codigona2, SPACE(30) as porcenna2 " +
914  " FROM " + DB.SQLDatabase("AMORTIZA", "PARTINVE") + " p " +
915  " LEFT JOIN " + DB.SQLDatabase("AMORTIZA", cTabla) + " t ON p.empresa = t.empresa AND p.cuenta = t.cuenta AND p.referencia = t.referencia AND t.periodo <= " + DB.SQLString(cEjercicio) +
916  " WHERE p.empresa = " + DB.SQLString(EW_GLOBAL._GetVariable("wc_empresa")) + lcFiltros +
917  (incluirPardidas == IncluirPardidas.Baja ? " AND " + DB.SQLString(cEjercicio) + " >= YEAR(p.bajainmo)" : " AND " + DB.SQLString(cEjercicio) + " >= YEAR(p.inici_amor)") + lcCondicion +
918  " GROUP BY p.empresa, p.cuenta, p.referencia " +
919  " ORDER BY p.empresa, p.cuenta, p.referencia ";
920 
921  #endregion CONTABLE
922  }
923  }
924  else
925  {
926  cTabla = "TABLA_FI";
927 
928  // Trabaja con secundarias e incluir partidas
929  if (usarSecundariasFlag && lIncluirDetalleAnal)
930  {
931  #region FISCAL O COMPARATICO Y SECUNDARIA E INCLUIR DETALLE ANALITICO
932  lcSql = " SELECT p.cuenta, p.referencia, SPACE(200) AS concepto, MAX(LEFT(p.cuenta, 3)) as Nivel3, " +
933  " 00000000.0000 as TotalAct, 00000000.00 as PdteAct, " +
934  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_01 = " + DB.SQLTrue(), "t.M_01", "000000000.00"), "000000000.00") + ") +" +
935  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_02 = " + DB.SQLTrue(), "t.M_02", "000000000.00"), "000000000.00") + ") +" +
936  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_03 = " + DB.SQLTrue(), "t.M_03", "000000000.00"), "000000000.00") + ") +" +
937  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_04 = " + DB.SQLTrue(), "t.M_04", "000000000.00"), "000000000.00") + ") +" +
938  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_05 = " + DB.SQLTrue(), "t.M_05", "000000000.00"), "000000000.00") + ") +" +
939  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_06 = " + DB.SQLTrue(), "t.M_06", "000000000.00"), "000000000.00") + ") +" +
940  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_07 = " + DB.SQLTrue(), "t.M_07", "000000000.00"), "000000000.00") + ") +" +
941  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_08 = " + DB.SQLTrue(), "t.M_08", "000000000.00"), "000000000.00") + ") +" +
942  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_09 = " + DB.SQLTrue(), "t.M_09", "000000000.00"), "000000000.00") + ") +" +
943  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_10 = " + DB.SQLTrue(), "t.M_10", "000000000.00"), "000000000.00") + ") +" +
944  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_11 = " + DB.SQLTrue(), "t.M_11", "000000000.00"), "000000000.00") + ") +" +
945  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_12 = " + DB.SQLTrue(), "t.M_12", "000000000.00"), "000000000.00") + ") as TotalCont, " +
946  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_01 = " + DB.SQLFalse(), "t.M_01", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
947  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_02 = " + DB.SQLFalse(), "t.M_02", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
948  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_03 = " + DB.SQLFalse(), "t.M_03", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
949  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_04 = " + DB.SQLFalse(), "t.M_04", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
950  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_05 = " + DB.SQLFalse(), "t.M_05", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
951  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_06 = " + DB.SQLFalse(), "t.M_06", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
952  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_07 = " + DB.SQLFalse(), "t.M_07", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
953  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_08 = " + DB.SQLFalse(), "t.M_08", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
954  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_09 = " + DB.SQLFalse(), "t.M_09", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
955  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_10 = " + DB.SQLFalse(), "t.M_10", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
956  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_11 = " + DB.SQLFalse(), "t.M_11", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
957  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_12 = " + DB.SQLFalse(), "t.M_12", "000000000.00"), "000000000.00"), "000000000.00") + ") as PdteCont, " +
958  " MAX(p.porcont) as porcont, MAX(p.importe) as importe, MAX(p.fecha) as fecha, p.empresa, MAX(p.bajainmo) as bajainmo, " +
959  DB.SQLNvl("MAX(pi.porcen)", "000000000.00000") + "as porcen, " +
960  " MAX(pi.plancont) as codplan, MAX(pi.secun) as codigona1, SPACE(30) as porcenna1, MAX(pi.secnivel2) as codigona2, MAX(pi.porcen) as porcenna2 " +
961  " FROM " + DB.SQLDatabase("AMORTIZA", "PARTINVE") + " p " +
962  " LEFT JOIN " + DB.SQLDatabase("AMORTIZA", cTabla) + " t ON p.empresa = t.empresa AND p.cuenta = t.cuenta AND p.referencia = t.referencia AND t.periodo <= " + DB.SQLString(cEjercicio) +
963  " LEFT JOIN " + DB.SQLDatabase("AMORTIZA", "PI_SECUN") + " pi ON p.empresa = pi.empresa AND p.cuenta = pi.cuenta AND p.referencia = pi.referencia " +
964  " WHERE p.empresa = " + DB.SQLString(EW_GLOBAL._GetVariable("wc_empresa")) + lcFiltros +
965  (incluirPardidas == IncluirPardidas.Baja ? " AND " + DB.SQLString(cEjercicio) + " >= YEAR(p.bajainmo)" : " AND " + DB.SQLString(cEjercicio) + " >= YEAR(p.inici_amor)") + lcCondicion +
966  " GROUP BY p.empresa, p.cuenta, p.referencia, pi.plancont, pi.secun, pi.secnivel2 " +
967  " ORDER BY p.empresa, p.cuenta, p.referencia, pi.plancont, pi.secun, pi.secnivel2";
968 
969  #endregion FISCAL O COMPARATICO Y SECUNDARIA E INCLUIR DETALLE ANALITICO
970  }
971  else
972  {
973  #region FISCAL O COMPARATICO
974  lcSql = " SELECT SPACE(200) AS concepto, MAX(LEFT(p.cuenta, 3)) as Nivel3, p.cuenta, p.referencia, 00000000.0000 as TotalAct, 00000000.00 as PdteAct, " +
975  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_01 = " + DB.SQLTrue(), "t.M_01", "000000000.00"), "000000000.00") + ") +" +
976  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_02 = " + DB.SQLTrue(), "t.M_02", "000000000.00"), "000000000.00") + ") +" +
977  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_03 = " + DB.SQLTrue(), "t.M_03", "000000000.00"), "000000000.00") + ") +" +
978  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_04 = " + DB.SQLTrue(), "t.M_04", "000000000.00"), "000000000.00") + ") +" +
979  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_05 = " + DB.SQLTrue(), "t.M_05", "000000000.00"), "000000000.00") + ") +" +
980  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_06 = " + DB.SQLTrue(), "t.M_06", "000000000.00"), "000000000.00") + ") +" +
981  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_07 = " + DB.SQLTrue(), "t.M_07", "000000000.00"), "000000000.00") + ") +" +
982  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_08 = " + DB.SQLTrue(), "t.M_08", "000000000.00"), "000000000.00") + ") +" +
983  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_09 = " + DB.SQLTrue(), "t.M_09", "000000000.00"), "000000000.00") + ") +" +
984  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_10 = " + DB.SQLTrue(), "t.M_10", "000000000.00"), "000000000.00") + ") +" +
985  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_11 = " + DB.SQLTrue(), "t.M_11", "000000000.00"), "000000000.00") + ") +" +
986  " SUM(" + DB.SQLNvl(DB.SQLIif("t.A_12 = " + DB.SQLTrue(), "t.M_12", "000000000.00"), "000000000.00") + ") as TotalCont, " +
987  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_01 = " + DB.SQLFalse(), "t.M_01", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
988  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_02 = " + DB.SQLFalse(), "t.M_02", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
989  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_03 = " + DB.SQLFalse(), "t.M_03", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
990  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_04 = " + DB.SQLFalse(), "t.M_04", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
991  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_05 = " + DB.SQLFalse(), "t.M_05", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
992  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_06 = " + DB.SQLFalse(), "t.M_06", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
993  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_07 = " + DB.SQLFalse(), "t.M_07", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
994  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_08 = " + DB.SQLFalse(), "t.M_08", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
995  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_09 = " + DB.SQLFalse(), "t.M_09", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
996  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_10 = " + DB.SQLFalse(), "t.M_10", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
997  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_11 = " + DB.SQLFalse(), "t.M_11", "000000000.00"), "000000000.00"), "000000000.00") + ") +" +
998  " SUM(" + DB.SQLIif(("p.bajainmo is null"), DB.SQLNvl(DB.SQLIif("t.A_12 = " + DB.SQLFalse(), "t.M_12", "000000000.00"), "000000000.00"), "000000000.00") + ") as PdteCont, " +
999  " MAX(p.porfis) as porcont, MAX(p.importe) as importe, MAX(p.fecha) as fecha, p.empresa, MAX(p.bajainmo) as bajainmo, " +
1000  " SPACE(200) as codplan, SPACE(200) as codigona1, SPACE(30) as porcenna1, SPACE(200) as codigona2, SPACE(30) as porcenna2 " +
1001  " FROM " + DB.SQLDatabase("AMORTIZA", "PARTINVE") + " p " +
1002  " LEFT JOIN " + DB.SQLDatabase("AMORTIZA", cTabla) + " t ON p.empresa = t.empresa AND p.cuenta = t.cuenta AND p.referencia = t.referencia AND t.periodo <= " + DB.SQLString(cEjercicio) +
1003  " WHERE p.empresa = " + DB.SQLString(EW_GLOBAL._GetVariable("wc_empresa")) + lcFiltros +
1004  (incluirPardidas == IncluirPardidas.Baja ? " AND " + DB.SQLString(cEjercicio) + " >= YEAR(p.bajainmo)" : " AND " + DB.SQLString(cEjercicio) + " >= YEAR(p.inici_amor)") + lcCondicion +
1005  " GROUP BY p.empresa, p.cuenta, p.referencia " +
1006  " ORDER BY p.empresa, p.cuenta, p.referencia ";
1007  #endregion FISCAL O COMPARATICO
1008  }
1009  }
1010 
1011  DB.SQLExec(lcSql, ref dtTmp_e);
1012 
1013  if (dtTmp_e != null && dtTmp_e.Rows.Count > 0)
1014  {
1015  dtTmp_d = InsertarRegistrosTabla(dtTmp_e);
1016  }
1017 
1018  if (dtTmp_d != null && dtTmp_d.Rows.Count > 0)
1019  {
1020  if (usarSecundariasFlag && lIncluirDetalleAnal && lbColPorcentajeVisible)
1021  {
1022  Calcularporcentajena1(dtTmp_d);
1023  }
1024 
1025  PintarResultados(dtDades, dtTmp_d);
1026 
1027  PintarTotales(dtDades);
1028  }
1029 
1030  return dtDades;
1031  }
1032 
1033 
1038  private DataTable InsertarRegistrosTabla(DataTable dtTableValores)
1039  {
1040  DataTable dtTableResult = new DataTable();
1041  dtTableResult = dtTableValores.Clone();
1042 
1043  if (incluirPardidas != IncluirPardidas.Alta)
1044  {
1045  #region BAJAS O COMPARATIVA
1046  foreach (DataRow row1 in dtTableValores.Rows)
1047  {
1048  if (row1["bajainmo"] != DBNull.Value)
1049  {
1050  if (incluirPardidas == IncluirPardidas.Todas)
1051  {
1052  dtTableResult.ImportRow(row1);
1053  }
1054  else
1055  {
1056  if (Convert.ToDateTime(row1["bajainmo"]).Month <= nMesIni && _nDesplazamientoInicial > 0)
1057  {
1058  if (Convert.ToInt32(cEjercicio) <= Convert.ToDateTime(row1["bajainmo"]).Year - 1)
1059  {
1060  dtTableResult.ImportRow(row1);
1061  }
1062  }
1063  else
1064  {
1065  if (incluirPardidas == IncluirPardidas.Todas)
1066  {
1067  dtTableResult.ImportRow(row1);
1068  }
1069  else
1070  {
1071  if (Convert.ToDateTime(row1["bajainmo"]).Year <= Convert.ToInt32(cEjercicio))
1072  {
1073  dtTableResult.ImportRow(row1);
1074  }
1075  }
1076  }
1077  }
1078  }
1079  else
1080  {
1081  if (incluirPardidas == IncluirPardidas.Todas)
1082  {
1083  dtTableResult.ImportRow(row1);
1084  }
1085  }
1086  }
1087  #endregion BAJAS O COMPARATIVA
1088  }
1089  else
1090  {
1091  #region ALTA
1092  foreach (DataRow row1 in dtTableValores.Rows)
1093  {
1094  if (row1["bajainmo"] != DBNull.Value)
1095  {
1096  if (Convert.ToDateTime(row1["bajainmo"]).Month < nMesIni && _nDesplazamientoInicial > 0)
1097  {
1098  if (Convert.ToInt32(cEjercicio) <= Convert.ToDateTime(row1["bajainmo"]).Year - 1)
1099  {
1100  dtTableResult.ImportRow(row1);
1101  }
1102  }
1103  else
1104  {
1105  if (Convert.ToInt32(cEjercicio) < Convert.ToDateTime(row1["bajainmo"]).Year)
1106  {
1107  dtTableResult.ImportRow(row1);
1108  }
1109  }
1110  }
1111  else
1112  {
1113  dtTableResult.ImportRow(row1);
1114  }
1115  }
1116  #endregion ALTA
1117  }
1118 
1119  return dtTableResult;
1120  }
1121 
1126  private void EditarRegistrosBaja(ref DataTable dtTableResult)
1127  {
1128  foreach (DataRow row in dtTableResult.Rows)
1129  {
1130  if (row["bajainmo"] != DBNull.Value)
1131  {
1132  if (Convert.ToDateTime(row["bajainmo"]).Year <= Convert.ToInt32(cEjercicio))
1133  {
1134  DataTable dtDatos = new DataTable();
1135  string lcSql = " SELECT * FROM " + DB.SQLDatabase("AMORTIZA", "PARTINVE") +
1136  " WHERE empresa = " + DB.SQLString(row["empresa"].ToString()) + " AND cuenta = " + DB.SQLString(row["cuenta"].ToString()) +
1137  " AND referencia = " + DB.SQLString(row["referencia"].ToString());
1138 
1139  DB.SQLExec(lcSql, ref dtDatos);
1140 
1141  if (dtDatos != null && dtDatos.Rows.Count > 0)
1142  {
1143  row["totalcont"] = Convert.ToDecimal(dtDatos.Rows[0]["totalcont"]);
1144  if (dtTableResult.Columns.Contains("totalfis"))
1145  row["totalfis"] = Convert.ToDecimal(dtDatos.Rows[0]["totalfis"]);
1146  }
1147  }
1148  }
1149  }
1150  }
1151 
1155  private void InicializarVariables()
1156  {
1157  cNivel3 = " ";
1158  cSecundaria = "";
1159  cPrincipal = "";
1160  cCodPlan = "";
1161 
1162  nAnyBaja = 0;
1163 
1164  nCuentaTotalAct = 0.0M;
1165  nCuentaPdteAct = 0.0M;
1166  nCuentaTotalActFis = 0.0M;
1167  nCuentaPdteActFis = 0.0M;
1168  nCuentaTotalCont = 0.0M;
1169  nCuentaPdteCont = 0.0M;
1170  nCuentaImporte = 0.0M;
1171  nCuentaTotalFis = 0.0M;
1172  nCuentaPdteFis = 0.0M;
1173 
1174  nTotalTotalAct = 0.0M;
1175  nTotalPdteAct = 0.0M;
1176  nTotalTotalActFis = 0.0M;
1177  nTotalPdteActFis = 0.0M;
1178  nTotalTotalCont = 0.0M;
1179  nTotalPdteCont = 0.0M;
1180  nTotalImporte = 0.0M;
1181  nTotalTotalFis = 0.0M;
1182  nTotalPdteFis = 0.0M;
1183 
1184  nSecunTotalAct = 0.0M;
1185  nSecunPdteAct = 0.0M;
1186  nSecunTotalActFis = 0.0M;
1187  nSecunPdteActFis = 0.0M;
1188  nSecunTotalCont = 0.0M;
1189  nSecunPdteCont = 0.0M;
1190  nSecunImporte = 0.0M;
1191  nSecunTotalFis = 0.0M;
1192  nSecunPdteFis = 0.0M;
1193 
1194  nPrinTotalAct = 0.0M;
1195  nPrinPdteAct = 0.0M;
1196  nPrinTotalActFis = 0.0M;
1197  nPrinPdteActFis = 0.0M;
1198  nPrinTotalCont = 0.0M;
1199  nPrinPdteCont = 0.0M;
1200  nPrinImporte = 0.0M;
1201  nPrinTotalFis = 0.0M;
1202  nPrinPdteFis = 0.0M;
1203  }
1204 
1209  private void Calcularporcentajena1(DataTable dtTmp_d)
1210  {
1211  foreach (DataRow row in dtTmp_d.Rows)
1212  {
1213  if (!string.IsNullOrEmpty(row["codplan"].ToString().Trim()) && !string.IsNullOrEmpty(row["codigona1"].ToString().Trim()))
1214  {
1215  decimal nPorcenna2 = 0M;
1216  if (!string.IsNullOrEmpty(row["porcenna2"].ToString().Trim()))
1217  {
1218  nPorcenna2 = Convert.ToDecimal(row["porcenna2"]);
1219  }
1220  if (nPorcenna2 > 0M)
1221  {
1222  DataTable dtPiSecun = new DataTable();
1223  string lcSql = " SELECT * FROM " + DB.SQLDatabase("AMORTIZA", "PI_SECUN") +
1224  " WHERE empresa = " + DB.SQLString(row["empresa"].ToString()) + " AND cuenta = " + DB.SQLString(row["cuenta"].ToString()) +
1225  " AND referencia = " + DB.SQLString(row["referencia"].ToString()) + " AND plancont = " + DB.SQLString(row["codplan"].ToString()) +
1226  " AND secun = " + DB.SQLString(row["codigona1"].ToString());
1227 
1228  DB.SQLExec(lcSql, ref dtPiSecun);
1229 
1230  decimal nPorcen = 0M;
1231  if (dtPiSecun != null && dtPiSecun.Rows.Count > 0)
1232  {
1233  foreach (DataRow loRow in dtPiSecun.Rows)
1234  {
1235  nPorcen += Convert.ToDecimal(loRow["porcen"]);
1236  }
1237  }
1238  row["porcenna1"] = nPorcen;
1239  }
1240  }
1241  }
1242  }
1243 
1249  private void PintarResultados(DataTable dtDades, DataTable dtTmp_d)
1250  {
1251  EditarRegistrosBaja(ref dtTmp_d);
1252 
1253  DataRow dr;
1254 
1255  if (dtTmp_d != null && dtTmp_d.Rows.Count > 0)
1256  {
1257  cNivel3 = dtTmp_d.Rows[0]["nivel3"].ToString();
1258  cSecundaria = dtTmp_d.Rows[0]["codplan"].ToString().Trim();
1259  cPrincipal = dtTmp_d.Rows[0]["cuenta"].ToString();
1260  string cRowCta = "";
1261  string cRowRef = "";
1262  string cRowCodplan = "";
1263  string cRowCodigona1 = "";
1264  string cRowCodigona2 = "";
1265  bool lbPrimerReg = true;
1266 
1267  foreach (DataRow row in dtTmp_d.Rows)
1268  {
1269  string cPlan = "";
1270  string cNivel1 = "";
1271  string cNivel2 = "";
1272 
1273  // Trabaja con secundarias e incluir partidas
1274  if (usarSecundariasFlag && lIncluirDetalleAnal)
1275  {
1276  if (tipoResumen != TipoResumen.Comparativo)
1277  {
1278  //if (Convert.ToDecimal(row["porcen"]) != 0)
1279  //{
1280  // row["importe"] = Convert.ToDecimal(row["importe"]) * (Convert.ToDecimal(row["porcen"]) / 100);
1281  //}
1282  }
1283 
1284  bool lbIniSecun = false;
1285  if (cSecundaria != row["codplan"].ToString().Trim() && !string.IsNullOrEmpty(cSecundaria))
1286  {
1287  if (!string.IsNullOrEmpty(cSecundaria))
1288  cPlan = " - " + DB.SQLValor("PLANS", "CODIGO", cSecundaria, "NOMBRE").ToString();
1289 
1290  cPlan = "";
1291 
1292  lbIniSecun = true;
1293  }
1294  else
1295  {
1296  // lbNewSecun = true;
1297  if (string.IsNullOrEmpty(cSecundaria))
1298  lbIniSecun = true;
1299  }
1300 
1301  if (lbIniSecun)
1302  {
1303  nSecunTotalAct = 0.0M;
1304  nSecunPdteAct = 0.0M;
1305  nSecunTotalCont = 0.0M;
1306  nSecunPdteCont = 0.0M;
1307  nSecunImporte = 0.0M;
1308  cSecundaria = row["codplan"].ToString().Trim();
1309  if (tipoResumen == TipoResumen.Comparativo)
1310  {
1311  nSecunTotalActFis = 0.0M;
1312  nSecunPdteActFis = 0.0M;
1313  nSecunTotalFis = 0.0M;
1314  nSecunPdteFis = 0.0M;
1315  }
1316  }
1317  }
1318 
1319  if (cPrincipal != row["cuenta"].ToString())
1320  {
1321  dr = dtDades.NewRow();
1322  dr["cuenta"] = cPrincipal;
1323  dr["referencia"] = "";
1324  dr["totalact"] = nPrinTotalAct;
1325  dr["pdteact"] = nPrinPdteAct;
1326  dr["totalcont"] = nPrinTotalCont;
1327  dr["pdtecont"] = nPrinPdteCont;
1328  dr["importe"] = nPrinImporte;
1329  dr["concepto"] = DB.SQLValor("CUENTAS", "CODIGO", cPrincipal, "NOMBRE").ToString();
1330  dr["bold"] = true;
1331  if (tipoResumen == TipoResumen.Comparativo)
1332  {
1333  dr["totalactfis"] = nPrinTotalActFis;
1334  dr["pdteactfis"] = nPrinPdteActFis;
1335  dr["totalfis"] = nPrinTotalFis;
1336  dr["pdtefis"] = nPrinPdteFis;
1337  }
1338  dtDades.Rows.Add(dr);
1339 
1340  nPrinTotalAct = 0.0M;
1341  nPrinPdteAct = 0.0M;
1342  nPrinTotalCont = 0.0M;
1343  nPrinPdteCont = 0.0M;
1344  nPrinImporte = 0.0M;
1345  cPrincipal = row["cuenta"].ToString();
1346  cCodPlan = row["codplan"].ToString();
1347  if (tipoResumen == TipoResumen.Comparativo)
1348  {
1349  nPrinTotalActFis = 0.0M;
1350  nPrinPdteActFis = 0.0M;
1351  nPrinTotalFis = 0.0M;
1352  nPrinPdteFis = 0.0M;
1353  }
1354  }
1355 
1356  if (cNivel3 != row["nivel3"].ToString() && lResumenNivel3)
1357  {
1358  string cNivel3Digitos = cNivel3.Substring(0, 3);
1359  dr = dtDades.NewRow();
1360  dr["cuenta"] = cNivel3;
1361  dr["referencia"] = "";
1362  dr["totalact"] = nCuentaTotalAct;
1363  dr["pdteact"] = nCuentaPdteAct;
1364  dr["totalcont"] = nCuentaTotalCont;
1365  dr["pdtecont"] = nCuentaPdteCont;
1366  dr["importe"] = nCuentaImporte;
1367  dr["concepto"] = DB.SQLValor("NIVEL3", "CODIGO", cNivel3Digitos, "NOMBRE").ToString();
1368  dr["bold"] = true;
1369 
1370  if (tipoResumen == TipoResumen.Comparativo)
1371  {
1372  dr["totalactfis"] = nCuentaTotalActFis;
1373  dr["pdteactfis"] = nCuentaPdteActFis;
1374  dr["totalfis"] = nCuentaTotalFis;
1375  dr["pdtefis"] = nCuentaPdteFis;
1376  }
1377  dtDades.Rows.Add(dr);
1378 
1379  nCuentaTotalAct = 0.0M;
1380  nCuentaPdteAct = 0.0M;
1381  nCuentaTotalCont = 0.0M;
1382  nCuentaPdteCont = 0.0M;
1383  nCuentaImporte = 0.0M;
1384  cNivel3 = row["nivel3"].ToString();
1385  if (tipoResumen == TipoResumen.Comparativo)
1386  {
1387  nCuentaTotalActFis = 0.0M;
1388  nCuentaPdteActFis = 0.0M;
1389  nCuentaTotalFis = 0.0M;
1390  nCuentaPdteFis = 0.0M;
1391  }
1392  }
1393 
1394 
1395  dr = dtDades.NewRow();
1396  dr["concepto"] = row["concepto"].ToString();
1397  dr["empresa"] = row["empresa"].ToString();
1398  if (row["bajainmo"] != DBNull.Value)
1399  {
1400  dr["bajainmo"] = Convert.ToDateTime(row["bajainmo"].ToString());
1401  }
1402  else
1403  {
1404  if (row["bajainmo"].ToString() != "")
1405  dr["bajainmo"] = DBNull.Value;
1406  }
1407  dr["cuenta"] = row["cuenta"].ToString();
1408  dr["referencia"] = row["referencia"].ToString();
1409  dr["totalact"] = row["totalact"].ToString();
1410  dr["pdteact"] = row["pdteact"].ToString();
1411  dr["totalcont"] = row["totalcont"].ToString();
1412  dr["pdtecont"] = row["pdtecont"].ToString();
1413  dr["porcont"] = row["porcont"].ToString();
1414  dr["importe"] = row["importe"].ToString();
1415  dr["fecha"] = row["fecha"].ToString();
1416  if (!string.IsNullOrEmpty(row["codplan"].ToString().Trim()))
1417  cPlan = " - " + DB.SQLValor("PLANS", "CODIGO", row["codplan"].ToString(), "NOMBRE").ToString();
1418 
1419  if (!string.IsNullOrEmpty(row["codigona1"].ToString().Trim()))
1420  cNivel1 = " - " + DB.SQLValor("SECUNDAR", "CODIGO", row["codigona1"].ToString(), "NOMBRE").ToString();
1421 
1422  if (!string.IsNullOrEmpty(row["codigona2"].ToString().Trim()))
1423  cNivel2 = " - " + DB.SQLValor("SECUNDAR", "CODIGO", row["codigona2"].ToString(), "NOMBRE").ToString();
1424 
1425  dr["codplan"] = row["codplan"].ToString().Trim() + cPlan;
1426  dr["codigona1"] = row["codigona1"].ToString().Trim() + cNivel1;
1427  if (string.IsNullOrEmpty(row["porcenna1"].ToString().Trim()))
1428  {
1429  dr["porcenna1"] = 0M;
1430  }
1431  else
1432  {
1433  dr["porcenna1"] = row["porcenna1"].ToString();
1434  }
1435  dr["codigona2"] = row["codigona2"].ToString().Trim() + cNivel2;
1436  if (string.IsNullOrEmpty(row["porcenna2"].ToString().Trim()))
1437  {
1438  dr["porcenna2"] = 0M;
1439  }
1440  else
1441  {
1442  dr["porcenna2"] = row["porcenna2"].ToString();
1443  }
1444  dr["nivel3"] = row["nivel3"].ToString();
1445  if (tipoResumen == TipoResumen.Comparativo)
1446  {
1447  dr["totalactfis"] = row["totalactfis"].ToString();
1448  dr["pdteactfis"] = row["pdteactfis"].ToString();
1449  dr["totalfis"] = row["totalfis"].ToString();
1450  dr["pdtefis"] = row["pdtefis"].ToString();
1451  dr["porfis"] = row["porfis"].ToString();
1452  }
1453  else
1454  {
1455  if (tipoResumen == TipoResumen.Fiscal)
1456  {
1457  if (Convert.ToDecimal(dr["porcont"]) == 0)
1458  dr["totalcont"] = 0;
1459  }
1460  }
1461 
1462  // dtDades.Rows.Add(dr);
1463 
1464  if (row["bajainmo"] == DBNull.Value || row["bajainmo"].ToString().Trim() == "")
1465  {
1466  nAnyBaja = 20000000;
1467  }
1468  else
1469  {
1470  nAnyBaja = Convert.ToDateTime(row["bajainmo"]).Year * 100;
1471  nAnyBaja += Convert.ToDateTime(row["bajainmo"]).Month;
1472  }
1473  string[] laCampos = new string[3] { "empresa", "cuenta", "referencia" };
1474  object[] laValores = new object[3] { row["empresa"].ToString(), row["cuenta"].ToString(), row["referencia"].ToString() };
1475 
1476  dr["concepto"] = DB.SQLValor("PARTINVE", laCampos, laValores, "concepto", "AMORTIZA");
1477 
1478  if (!string.IsNullOrEmpty(dr["concepto"].ToString().Trim()))
1479  {
1480  if (dr["concepto"].ToString().Trim().Length > 200)
1481  {
1482  dr["concepto"] = dr["concepto"].ToString().Substring(0, 200);
1483  }
1484  }
1485 
1486  if (tipoResumen == TipoResumen.Comparativo || tipoResumen == TipoResumen.Contable)
1487  {
1488  DataTable dtcurPeriodo = new DataTable();
1489  string lcSql2 = " SELECT * FROM " + DB.SQLDatabase("AMORTIZA", "TABLA_AM") +
1490  " WHERE empresa = " + DB.SQLString(row["empresa"].ToString()) + " AND cuenta = " + DB.SQLString(row["cuenta"].ToString()) +
1491  " AND referencia = " + DB.SQLString(row["referencia"].ToString()) + " AND periodo = " + DB.SQLString(cEjercicio);
1492 
1493  DB.SQLExec(lcSql2, ref dtcurPeriodo);
1494 
1495  decimal nTotal = 0.0M;
1496  decimal nPendiente = 0.0M;
1497  decimal nPorcen = 0.0M;
1498 
1499  if (dtcurPeriodo != null && dtcurPeriodo.Rows.Count > 0)
1500  {
1501  decimal totalCont_ini = Convert.ToDecimal(dr["totalcont"]);
1502 
1503  foreach (DataRow loRow in dtcurPeriodo.Rows)
1504  {
1505  for (int n = 1; n <= 12; n++)
1506  {
1507  string cValor = loRow["A_" + Convert.ToString(n).PadLeft(2, '0')].ToString();
1508  string cValor2 = loRow["M_" + Convert.ToString(n).PadLeft(2, '0')].ToString();
1509  bool lbValor = Convert.ToBoolean(cValor);
1510 
1511  if ((((Convert.ToInt32(cEjercicio)) * 100) + n) <= nAnyBaja)
1512  {
1513  if (lbValor)
1514  {
1515  if ((((Convert.ToInt32(cEjercicio)) * 100) + n) == nAnyBaja)
1516  {
1517  Int32 nDias = DateTime.DaysInMonth(Convert.ToInt16(cEjercicio), n);
1518  nPorcen = ((nDias == Convert.ToDateTime(dr["bajainmo"]).Day) ? 1 : Convert.ToInt32((Convert.ToDateTime(dr["bajainmo"]).Day - 1 / nDias)));
1519  nTotal += Convert.ToDecimal(cValor2) * nPorcen;
1520  }
1521  else
1522  {
1523  nTotal += Convert.ToDecimal(cValor2);
1524  }
1525  }
1526  else
1527  {
1528  nPendiente += Convert.ToDecimal(cValor2);
1529  }
1530  }
1531  }
1532 
1533  if (tipoResumen != TipoResumen.Comparativo)
1534  {
1535  if (usarSecundariasFlag && lIncluirDetalleAnal && Convert.ToDecimal(row["porcen"]) != 0)
1536  {
1537  //nTotal = nTotal * (Convert.ToDecimal(row["porcen"]) / 100);
1538  //nPendiente = nPendiente * (Convert.ToDecimal(row["porcen"]) / 100);
1539  }
1540  }
1541 
1542  dr["totalact"] = nTotal;
1543  dr["pdteact"] = nPendiente;
1544 
1545  if (tipoResumen == TipoResumen.Comparativo)
1546  {
1547  dr["totalcont"] = Convert.ToDecimal(dr["totalcont"]) + nTotal;
1548  }
1549 
1550 
1551  if (dr["bajainmo"] != DBNull.Value)
1552  {
1553  if (Convert.ToInt32(cEjercicio) > Convert.ToDateTime(dr["bajainmo"]).Year)
1554  {
1555  dr["totalact"] = 0;
1556  }
1557  else
1558  {
1559  if (tipoResumen == TipoResumen.Comparativo)
1560  {
1561  dr["totalcont"] = totalCont_ini;
1562  }
1563 
1564  DataTable dtcurAmorti = new DataTable();
1565  string lcSql3 = " SELECT * FROM " + DB.SQLDatabase("AMORTIZA", "TABLA_AM") +
1566  " WHERE empresa = " + DB.SQLString(row["empresa"].ToString()) + " AND cuenta = " + DB.SQLString(row["cuenta"].ToString()) +
1567  " AND referencia = " + DB.SQLString(row["referencia"].ToString()) + " AND periodo < " + DB.SQLString(cEjercicio);
1568 
1569  DB.SQLExec(lcSql3, ref dtcurAmorti);
1570 
1571  decimal nAmorti = 0;
1572  foreach (DataRow rowA in dtcurAmorti.Rows)
1573  {
1574  nAmorti += Convert.ToDecimal(rowA["importe"]);
1575 
1576  }
1577  dr["totalact"] = Convert.ToDecimal(dr["totalcont"]) - nAmorti ;
1578  }
1579  }
1580 
1581  dr["pdtecont"] = Convert.ToDecimal(dr["importe"]) - Convert.ToDecimal(dr["totalcont"]); //}
1582 
1583  }
1584  }
1585  }
1586 
1587  if (tipoResumen == TipoResumen.Comparativo || tipoResumen == TipoResumen.Fiscal)
1588  {
1589  DataTable dtcurPeriodo2 = new DataTable();
1590  string lcSql3 = " SELECT * FROM " + DB.SQLDatabase("AMORTIZA", "TABLA_FI") +
1591  " WHERE empresa = " + DB.SQLString(row["empresa"].ToString()) + " AND cuenta = " + DB.SQLString(row["cuenta"].ToString()) +
1592  " AND referencia = " + DB.SQLString(row["referencia"].ToString()) + " AND periodo = " + DB.SQLString(cEjercicio);
1593 
1594  DB.SQLExec(lcSql3, ref dtcurPeriodo2);
1595 
1596  decimal nTotal2 = 0.0M;
1597  decimal nPendiente2 = 0.0M;
1598  decimal nPorcen2 = 0.0M;
1599 
1600  if (dtcurPeriodo2 != null && dtcurPeriodo2.Rows.Count > 0)
1601  {
1602  decimal totalfis_ini =(tipoResumen != TipoResumen.Comparativo ? 0 : Convert.ToDecimal(dr["totalfis"]));
1603 
1604  foreach (DataRow loRow in dtcurPeriodo2.Rows)
1605  {
1606  for (int n = 1; n <= 12; n++)
1607  {
1608  string cValor = loRow["A_" + Convert.ToString(n).PadLeft(2, '0')].ToString();
1609  string cValor2 = loRow["M_" + Convert.ToString(n).PadLeft(2, '0')].ToString();
1610  bool lbValor = Convert.ToBoolean(cValor);
1611 
1612  if ((((Convert.ToInt32(cEjercicio)) * 100) + n) <= nAnyBaja)
1613  {
1614  if (lbValor)
1615  {
1616  if ((((Convert.ToInt32(cEjercicio)) * 100) + n) == nAnyBaja)
1617  {
1618  Int32 nDias = DateTime.DaysInMonth(Convert.ToInt16(cEjercicio), n);
1619  nPorcen2 = ((nDias == Convert.ToDateTime(dr["bajainmo"]).Day) ? 1 : Convert.ToInt32((Convert.ToDateTime(dr["bajainmo"]).Day - 1 / nDias)));
1620  nTotal2 += Convert.ToDecimal(cValor2) * nPorcen2;
1621  }
1622  else
1623  {
1624  nTotal2 += Convert.ToDecimal(cValor2);
1625  }
1626  }
1627  else
1628  {
1629  nPendiente2 += Convert.ToDecimal(cValor2);
1630  }
1631  }
1632  }
1633 
1634  if (tipoResumen != TipoResumen.Comparativo)
1635  {
1636  if (usarSecundariasFlag && lIncluirDetalleAnal && Convert.ToDecimal(row["porcen"]) != 0)
1637  {
1638  // nTotal2 = nTotal2 * (Convert.ToDecimal(row["porcen"]) / 100);
1639  // nPendiente2 = nPendiente2 * (Convert.ToDecimal(row["porcen"]) / 100);
1640  }
1641  }
1642 
1643  if (tipoResumen == TipoResumen.Fiscal)
1644  {
1645  dr["totalact"] = nTotal2;
1646  dr["pdteact"] = nPendiente2;
1647  // dr["totalcont"] = Convert.ToDecimal(dr["totalcont"]) + nTotal2;
1648  dr["pdtecont"] = Convert.ToDecimal(dr["importe"]) - Convert.ToDecimal(dr["totalcont"]);
1649  }
1650  else
1651  {
1652  dr["totalfis"] = Convert.ToDecimal(dr["totalfis"]) + nTotal2;
1653  dr["pdtefis"] = Convert.ToDecimal(dr["importe"]) - Convert.ToDecimal(dr["totalfis"]);
1654  dr["totalactfis"] = nTotal2;
1655  dr["pdteactfis"] = nPendiente2;
1656  }
1657  }
1658 
1659  if (dr["bajainmo"] != DBNull.Value && dr["bajainmo"].ToString().Trim() != "")
1660  {
1661  if (Convert.ToInt32(cEjercicio) > Convert.ToDateTime(dr["bajainmo"]).Year)
1662  {
1663  if (tipoResumen == TipoResumen.Fiscal)
1664  {
1665  dr["totalact"] = 0;
1666  }
1667  else
1668  {
1669  dr["totalfis"] = 0;
1670  }
1671  }
1672  else
1673  {
1674  if (tipoResumen == TipoResumen.Comparativo)
1675  {
1676  dr["totalfis"] = totalfis_ini;
1677  }
1678 
1679  DataTable dtcurAmorti = new DataTable();
1680  string lcSql4 = " SELECT * FROM " + DB.SQLDatabase("AMORTIZA", "TABLA_FI") +
1681  " WHERE empresa = " + DB.SQLString(row["empresa"].ToString()) + " AND cuenta = " + DB.SQLString(row["cuenta"].ToString()) +
1682  " AND referencia = " + DB.SQLString(row["referencia"].ToString()) + " AND periodo < " + DB.SQLString(cEjercicio);
1683 
1684  DB.SQLExec(lcSql4, ref dtcurAmorti);
1685 
1686  decimal nAmorti = 0;
1687  foreach (DataRow rowA in dtcurAmorti.Rows)
1688  {
1689  nAmorti += Convert.ToDecimal(rowA["importe"]);
1690  }
1691  if (tipoResumen == TipoResumen.Fiscal)
1692  {
1693  dr["totalact"] = Convert.ToDecimal(dr["totalcont"]) - nAmorti;
1694  }
1695  else
1696  {
1697  dr["totalactfis"] = Convert.ToDecimal(dr["totalfis"]) - nAmorti;
1698  dr["pdtefis"] = Convert.ToDecimal(dr["importe"]) - Convert.ToDecimal(dr["totalfis"]);
1699  }
1700  }
1701  }
1702  }
1703 
1704  }
1705 
1706 
1707  if ((cRowCta == "" && cRowRef == "" ) || (cRowCta != row["cuenta"].ToString()) || (cRowCta == row["cuenta"].ToString() && cRowRef != row["referencia"].ToString()))
1708  {
1709  lbPrimerReg = true;
1710  }
1711  else
1712  {
1713  if (usarSecundariasFlag && lIncluirDetalleAnal && cRowCta != "" && cRowRef != "")
1714  {
1715  string[] preservar = null;
1716  if (row["codplan"].ToString() == cRowCodplan && row["codigona1"].ToString() == cRowCodigona1)
1717  {
1718  if (row["codigona2"].ToString() != cRowCodigona2)
1719  {
1720  preservar = new string[] { "codigona2", "porcenna2" };
1721  }
1722  else
1723  {
1724  preservar = new string[] { "codplan", "codigona1", "codigona2", "porcenna1", "porcenna2" };
1725  }
1726  }
1727  else
1728  {
1729  if (row["codplan"].ToString() == cRowCodplan)
1730  {
1731  preservar = new string[] { "codigona1", "codigona2", "porcenna1", "porcenna2" };
1732  }
1733  else
1734  {
1735  preservar = new string[] { "codplan", "codigona1", "codigona2", "porcenna1", "porcenna2" };
1736  }
1737  }
1738 
1739  for (int i = 0; i < dtTmp_d.Columns.Count; i++)
1740  {
1741  string columname = dtTmp_d.Columns[i].ColumnName;
1742  if (Array.Exists(preservar, element => element == columname))
1743  {
1744  continue;
1745  }
1746  dr[i] = DBNull.Value;
1747  }
1748  }
1749  }
1750 
1751  dtDades.Rows.Add(dr);
1752 
1753 
1754  if (lbPrimerReg)
1755  {
1756  nCuentaTotalAct = nCuentaTotalAct + Convert.ToDecimal(dr["totalact"]);
1757  nCuentaPdteAct = nCuentaPdteAct + Convert.ToDecimal(dr["pdteact"]);
1758  nCuentaTotalCont = nCuentaTotalCont + Convert.ToDecimal(dr["totalcont"]);
1759  nCuentaPdteCont = nCuentaPdteCont + (Convert.ToDecimal(dr["importe"]) - Convert.ToDecimal(dr["totalcont"]));
1760  nCuentaImporte = nCuentaImporte + Convert.ToDecimal(dr["importe"]);
1761 
1762  nTotalTotalAct = nTotalTotalAct + Convert.ToDecimal(dr["totalact"]);
1763  nTotalPdteAct = nTotalPdteAct + Convert.ToDecimal(dr["pdteact"]);
1764  nTotalTotalCont = nTotalTotalCont + Convert.ToDecimal(dr["totalcont"]);
1765  nTotalPdteCont = nTotalPdteCont + (Convert.ToDecimal(dr["importe"]) - Convert.ToDecimal(dr["totalcont"]));
1766  nTotalImporte = nTotalImporte + Convert.ToDecimal(dr["importe"]);
1767 
1768  if (tipoResumen == TipoResumen.Comparativo)
1769  {
1770  nCuentaTotalActFis = nCuentaTotalActFis + Convert.ToDecimal(dr["totalactfis"]);
1771  nCuentaPdteActFis = nCuentaPdteActFis + Convert.ToDecimal(dr["pdteactfis"]);
1772  nCuentaTotalFis = nCuentaTotalFis + Convert.ToDecimal(dr["totalfis"]);
1773  nCuentaPdteFis = nCuentaPdteFis + Convert.ToDecimal(dr["totalfis"]);
1774 
1775  nTotalTotalActFis = nTotalTotalActFis + Convert.ToDecimal(dr["totalactfis"]);
1776  nTotalPdteActFis = nTotalPdteActFis + Convert.ToDecimal(dr["pdteactfis"]);
1777  nTotalTotalFis = nTotalTotalFis + Convert.ToDecimal(dr["totalfis"]);
1778  nTotalPdteFis = nTotalPdteFis + Convert.ToDecimal(dr["totalfis"]);
1779  }
1780 
1781  if (usarSecundariasFlag && lIncluirDetalleAnal)
1782  {
1783  nSecunTotalAct = nSecunTotalAct + Convert.ToDecimal(dr["totalact"]);
1784  nSecunPdteAct = nSecunPdteAct + Convert.ToDecimal(dr["pdteact"]);
1785  nSecunTotalCont = nSecunTotalCont + Convert.ToDecimal(dr["totalcont"]);
1786  nSecunPdteCont = nSecunPdteCont + Convert.ToDecimal(dr["pdtecont"]);
1787  nSecunImporte = nSecunImporte + Convert.ToDecimal(dr["importe"]);
1788 
1789  if (tipoResumen == TipoResumen.Comparativo)
1790  {
1791  nSecunTotalActFis = nSecunTotalActFis + Convert.ToDecimal(dr["totalactfis"]);
1792  nSecunPdteActFis = nSecunPdteActFis + Convert.ToDecimal(dr["pdteactfis"]);
1793  nSecunTotalFis = nSecunTotalFis + Convert.ToDecimal(dr["totalfis"]);
1794  nSecunPdteFis = nSecunPdteFis + Convert.ToDecimal(dr["pdtefis"]);
1795  }
1796  }
1797 
1798  nPrinTotalAct = nPrinTotalAct + Convert.ToDecimal(dr["totalact"]);
1799  nPrinPdteAct = nPrinPdteAct + Convert.ToDecimal(dr["pdteact"]);
1800  nPrinTotalCont = nPrinTotalCont + Convert.ToDecimal(dr["totalcont"]);
1801  nPrinPdteCont = nPrinPdteCont + Convert.ToDecimal(dr["pdtecont"]);
1802  nPrinImporte = nPrinImporte + Convert.ToDecimal(dr["importe"]);
1803 
1804  if (tipoResumen == TipoResumen.Comparativo)
1805  {
1806  nPrinTotalActFis = nPrinTotalActFis + Convert.ToDecimal(dr["totalactfis"]);
1807  nPrinPdteActFis = nPrinPdteActFis + Convert.ToDecimal(dr["pdteactfis"]);
1808  nPrinTotalFis = nPrinTotalFis + Convert.ToDecimal(dr["totalfis"]);
1809  nPrinPdteFis = nPrinPdteFis + Convert.ToDecimal(dr["pdtefis"]);
1810  }
1811  }
1812 
1813  cRowCta = row["cuenta"].ToString();
1814  cRowRef = row["referencia"].ToString();
1815  cRowCodplan = row["codplan"].ToString();
1816  cRowCodigona1 = row["codigona1"].ToString();
1817  cRowCodigona2 = row["codigona2"].ToString();
1818  lbPrimerReg = false;
1819  }
1820  }
1821 
1822  if (dtTmp_d.Columns.Contains("porcen"))
1823  dtTmp_d.Columns.Remove("porcen");
1824 
1825  if (dtDades.Columns.Contains("porcen"))
1826  dtDades.Columns.Remove("porcen");
1827  }
1828 
1833  private void PintarTotales(DataTable dtDades)
1834  {
1835  DataRow dr;
1836 
1837  if (usarSecundariasFlag && lIncluirDetalleAnal)
1838  {
1839  string cPlan = "";
1840  if (!string.IsNullOrEmpty(cSecundaria))
1841  cPlan = " - " + DB.SQLValor("PLANS", "CODIGO", cSecundaria, "NOMBRE").ToString();
1842 
1843  }
1844 
1845  dr = dtDades.NewRow();
1846  dr["cuenta"] = cPrincipal;
1847  dr["referencia"] = "";
1848  dr["totalact"] = nPrinTotalAct;
1849  dr["pdteact"] = nPrinPdteAct;
1850  dr["totalcont"] = nPrinTotalCont;
1851  dr["pdtecont"] = nPrinPdteCont;
1852  dr["importe"] = nPrinImporte;
1853  dr["concepto"] = DB.SQLValor("CUENTAS", "CODIGO", cPrincipal, "NOMBRE").ToString();
1854  dr["bold"] = true;
1855  if (tipoResumen == TipoResumen.Comparativo)
1856  {
1857  dr["totalactfis"] = nPrinTotalActFis;
1858  dr["pdteactfis"] = nPrinPdteActFis;
1859  dr["totalfis"] = nPrinTotalFis;
1860  dr["pdtefis"] = nPrinPdteFis;
1861  }
1862  dtDades.Rows.Add(dr);
1863 
1864  if (lResumenNivel3)
1865  {
1866  string cNivel3Digitos = cNivel3.Substring(0, 3);
1867  dr = dtDades.NewRow();
1868  dr["cuenta"] = cNivel3;
1869  dr["referencia"] = "";
1870  dr["totalact"] = nCuentaTotalAct;
1871  dr["pdteact"] = nCuentaPdteAct;
1872  dr["totalcont"] = nCuentaTotalCont;
1873  dr["pdtecont"] = nCuentaPdteCont;
1874  dr["importe"] = nCuentaImporte;
1875  dr["concepto"] = DB.SQLValor("NIVEL3", "CODIGO", cNivel3Digitos, "NOMBRE").ToString();
1876  dr["bold"] = true;
1877  if (tipoResumen == TipoResumen.Comparativo)
1878  {
1879  dr["totalactfis"] = nCuentaTotalActFis;
1880  dr["pdteactfis"] = nCuentaPdteActFis;
1881  dr["totalfis"] = nCuentaTotalFis;
1882  dr["pdtefis"] = nCuentaPdteFis;
1883  }
1884  dtDades.Rows.Add(dr);
1885  }
1886 
1887  dr = dtDades.NewRow();
1888  dr["cuenta"] = "TOTAL";
1889  dr["referencia"] = "";
1890  dr["totalact"] = nTotalTotalAct;
1891  dr["pdteact"] = nTotalPdteAct;
1892  dr["totalcont"] = nTotalTotalCont;
1893  dr["pdtecont"] = nTotalPdteCont;
1894  dr["importe"] = nTotalImporte;
1895  dr["bold"] = true;
1896  if (tipoResumen == TipoResumen.Comparativo)
1897  {
1898  dr["totalactfis"] = nTotalTotalActFis;
1899  dr["pdteactfis"] = nTotalPdteActFis;
1900  dr["totalfis"] = nTotalTotalFis;
1901  dr["pdtefis"] = nTotalPdteFis;
1902  }
1903  dtDades.Rows.Add(dr);
1904  }
1905  }
1906 }
1907 
override void _SetDefaultValues(Dictionary< string, object > toControlsFiltros=null, Dictionary< string, object > toControlsOpciones=null)
Override del _SetDefaultValues para ocultar si se requiere la opción de cuentas secundarias ...
override void _SetColumnWidth(Dictionary< string, int > tldTranslate=null)
Especifica el tamaño que tendrá la columan en Pixels para que en el grid no todas las columnas tengan...
Clase parcial para listados, en esta definición se especificarán los métodos comunes para las demás c...
Definition: _clsListados.cs:61
Es como el tipo de entrada asientos pero por negocio, sin formulario, pq quiero que me haga las propu...
override void _SetColumnMasks()
Overrides _SetColumnMasks
override void _Navigate(String tcKeyNavigate, DataRow trRow)
Añadir navegación al asiento
override DataTable _DataTable()
Método de obtención de los datos específico para el listado
Entidad de relación (Columnas adicionales en listados)
Definition: DefEntidad.cs:14
override void _SetColumnCaptions(Dictionary< string, string > tldTranslate=null)
Overrides _SetColumnCaptions
_Tipo_Filtro_String
Enumeración de los posibles filtros de tipo STRING a realizar xxxDesde => Valor mínimo del filtro xxx...