Cargando...
Buscando...
Nada coincide
DatosAdicionalesFacturaDA.cs
1using sage.ew.db;
6using System;
7using System.Collections.Generic;
8using System.Data;
9using System.Linq;
10
12{
17 {
26 public bool TieneTipoIvaConfiguradoEnModelo(string empresa, string tipoIva, string tipoConfiguracion, List<string> listaTipoModelos = null)
27 {
28 bool existe = false;
29
30 if (string.IsNullOrEmpty(tipoIva) || string.IsNullOrEmpty(tipoConfiguracion))
31 {
32 return existe;
33 }
34
35 List<DB.QueryParams> parametros = new List<DB.QueryParams>
36 {
37 new DB.QueryParams("@empresa", Convert.ToString(empresa), SqlDbType.Char),
38 new DB.QueryParams("@tipoIva", Convert.ToString(tipoIva), SqlDbType.Char),
39 new DB.QueryParams("@tipoConf", Convert.ToString(tipoConfiguracion), SqlDbType.Char)
40 };
41
42 string query = $@"SELECT tipo_iva FROM {DB.SQLDatabase("MODTIPO")}
43 WHERE empresa = @empresa AND tipo_iva = @tipoIva AND tipo = @tipoConf";
44
45 if (listaTipoModelos != null && listaTipoModelos.Count() > 0)
46 {
47 string modelos = "";
48
49 foreach (string modelo in listaTipoModelos)
50 {
51 modelos += (string.IsNullOrWhiteSpace(modelos) ? " AND (modelo = " : " OR modelo = ") + DB.SQLString(modelo);
52 }
53 modelos += ")";
54 query += modelos;
55 }
56
57 DataTable tabla = new DataTable();
58
59 DB.SQLExecParams(query, ref tabla, parametros);
60
61 if (tabla != null && tabla.Rows.Count > 0)
62 {
63 string tipo = tabla.Rows[0][0].ToString().Trim();
64 existe = !string.IsNullOrWhiteSpace(tipo);
65 }
66 FUNCTIONS._DisposeDatatable(ref tabla);
67
68 return existe;
69 }
70
77 /// <returns></returns>
78 public Dictionary<string, object> GetRegistrosIvaReper(string empresa, string numFra, List<string> tiposIva)
79 {
80 if (string.IsNullOrWhiteSpace(numFra))
81 return null;
82
83 DataTable tabla = new DataTable();
84 try
85 {
86 // Construimos la consulta parametrizada
87 string sql = $"SELECT * FROM {SQLDatabase("GESTION", "IVAREPER")} WHERE NUMFRA = @numFra AND EMPRESA = @empresa";
88
89 var parametros = new List<DB.QueryParams>
90 {
91 new DB.QueryParams("@numFra", numFra, SqlDbType.Char),
92 new DB.QueryParams("@empresa", empresa, SqlDbType.Char),
93 };
94
95 // Ejecutamos la consulta
96 bool ok = DB.SQLExecParams(sql, ref tabla, parametros);
97
98 if (ok && tabla.Rows.Count > 0)
99 {
100 List<string> lstCampos = new List<string> { "BIMPO", "PORCEN_IVA", "IVA", "RECARGO", "BIMPODIV", "IVADIV", "RECDIV" };
101 var sumaDict = new Dictionary<string, object>();
102 int registrosSumados = 0;
103
104 foreach (DataRow row in tabla.Rows)
105 {
106 if (tiposIva == null || tiposIva.Count == 0 ||
107 (row.Table.Columns.Contains("TIPO_IVA") && row["TIPO_IVA"] != null && !tiposIva.Contains(row["TIPO_IVA"].ToString())))
108 {
109 foreach (string campo in lstCampos)
110 {
111 if (!row.Table.Columns.Contains(campo)) continue;
112 var valor = row[campo];
113 if (valor == DBNull.Value) continue;
114
115 // Cambiar la clave "PORCEN_IVA" por "TPCIVA" en el diccionario
116 string claveDict = campo == "PORCEN_IVA" ? "TPCIVA" : campo;
117
118 decimal suma = sumaDict.ContainsKey(claveDict) ? Convert.ToDecimal(sumaDict[claveDict]) : 0m;
119 suma += Convert.ToDecimal(valor);
120 sumaDict[claveDict] = suma;
121 }
122 registrosSumados++;
123 }
124 }
125
126 if (registrosSumados > 0)
127 return sumaDict;
128
129 return null;
130 }
131 }
132 catch (Exception ex)
133 {
134 Registrar_Error(ex);
135 }
136 finally
137 {
138 FUNCTIONS._DisposeDatatable(ref tabla);
139 }
140 return null;
141 }
142
151 /// <returns>Diccionario con claves: baseiva, impiva, imprec</returns>
152 public DataTable ObtenerRegistrosIvareper(ref DataTable dtDatos, string empresa, string numFra, string divisa, string divisaEmpresa)
153 {
154 string campos;
155
156 if (divisa == divisaEmpresa)
157 {
158 campos = "BIMPO AS BASEIVA, IVA AS IMPIVA, RECARGO AS IMPREC";
159 }
160 else
161 {
162 campos = "BIMPODIV AS BIMPO, IVADIV AS IVA, RECDIV AS RECARGO";
163 }
164
165 string sql = $"SELECT EMPRESA, NUMFRA, TIPO_IVA AS CODIGO, {campos} " +
166 $"FROM {DB.SQLDatabase("GESTION", "IVAREPER")} " +
167 $"WHERE EMPRESA = @empresa AND NUMFRA = @numFra AND DIVISA = @divisa";
168
169 var parametros = new List<DB.QueryParams>
170 {
171 new DB.QueryParams("@empresa", empresa, System.Data.SqlDbType.Char),
172 new DB.QueryParams("@numFra", numFra, System.Data.SqlDbType.Char),
173 new DB.QueryParams("@divisa", divisa, System.Data.SqlDbType.Char)
174 };
175
176 try
177 {
178 if (DB.SQLExecParams(sql, ref dtDatos, parametros) && dtDatos.Rows.Count > 0)
179 {
180 return dtDatos;
181 }
182 }
183 catch (Exception ex)
184 {
185 Registrar_Error(ex);
186 }
187
188 return dtDatos;
189 }
190 }
191}
Dictionary< string, object > GetRegistrosIvaReper(string empresa, string numFra, List< string > tiposIva)
bool TieneTipoIvaConfiguradoEnModelo(string empresa, string tipoIva, string tipoConfiguracion, List< string > listaTipoModelos=null)
Verifica si un tipo de IVA "tipoIva" tiene una configuración específica "tipoConfiguracion" en algún modelo "l...
DataTable ObtenerRegistrosIvareper(ref DataTable dtDatos, string empresa, string numFra, string divisa, string divisaEmpresa)
Obtiene los totales de base, iva y recargo de IVAREPER para una empresa y factura,...
Clase base de acceso a datos.
Definition BaseDA.cs:19
void Registrar_Error(Exception toEx)
Registra error.
Definition BaseDA.cs:33