2 using System.Collections.Generic;
6 using System.Xml.Serialization;
10 using System.ComponentModel;
16 #region CLASE_VALIDARIVA 17 public class ValidarIVA: Validaciones
27 public string valorCSV_col =
string.Empty;
32 public string mensaje =
string.Empty;
34 #endregion PROPIEDADES 50 codigoGuia = lcCodigoGuia;
53 #endregion CONSTRUCTORES 55 #region METODOS PUBLICOS 73 dataRowEnImportacion = drEnImportacion;
74 valorCSV_col = valorColumna;
98 bool lbExcepcion =
false;
100 if (valorCSV_col.Contains(
"%"))
101 valorCSV_col = valorCSV_col.Replace(
"%",
"");
103 if (valorCSV_col.Contains(
","))
104 valorCSV_col = valorCSV_col.Replace(
",",
".");
106 if (dyValidar.Keys.Contains(valorCSV_col))
108 lcResult = dyValidar.Where(p => p.Key == valorCSV_col).FirstOrDefault().Value;
113 string codigoS50 = ObtenerCodigoIvaS50();
115 if (!
string.IsNullOrEmpty(codigoS50))
117 lcResult =
new ValidationResult(lbOk, mensaje);
118 dyValidar.Add(valorCSV_col, lcResult);
123 bool incluirRecargo = IncluirRecargo();
125 mensaje =
string.Empty;
127 string valorIVA = valorCSV_col;
128 if (!
string.IsNullOrEmpty(valorCSV_col.Trim()))
130 DataTable tablaIva =
new DataTable();
131 string lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"GESTION",
"TIPO_IVA");
133 if (
string.IsNullOrWhiteSpace(valorIVA))
135 lcSql +=
" WHERE IVA = 21 AND ";
137 lcSql +=
"RECARG <> 0 AND IVA_CEE != '' AND ";
139 lcSql +=
"RECARG = 0 AND ";
141 lcSql +=
"DEDUCE = 1 AND EXENTO = 0";
143 else if (Convert.ToDecimal(valorIVA) == 0)
145 lcSql +=
" WHERE IVA = 0 AND DEDUCE = 1 AND EXENTO = 0";
149 lcSql +=
" WHERE IVA = " + DB.SQLString(valorIVA) +
" AND ";
153 lcSql +=
"RECARG <> 0 AND IVA_CEE != '' AND ";
157 lcSql +=
"RECARG = 0 AND ";
161 lcSql +=
"DEDUCE = 1 AND EXENTO = 0";
166 lcSql +=
" AND CODIGO NOT IN ('11', '12', '13') AND CODIGO NOT IN (SELECT DISTINCT IVA_CEE FROM " + DB.SQLDatabase(
"GESTION",
"TIPO_IVA") +
" WHERE IVA_CEE != '') ";
168 DB.SQLExec(lcSql, ref tablaIva);
170 if (tablaIva.Rows.Count == 0)
173 mensaje =
"Existe en la tabla tipos de IVA un valor " + valorIVA +
", pero no puede ser asignado por no existir en destino exactamente este tipo de IVA";
200 lcResult =
new ValidationResult(lbOk, mensaje);
201 dyValidar.Add(valorCSV_col, lcResult);
206 #endregion METODOS PUBLICOS 208 #region METODOS PRIVADOS 209 private bool IncluirRecargo()
215 Negocio.Mantes.plinter_c loConfigCSV =
new Negocio.Mantes.plinter_c(codigoGuia);
216 CSVConfig cs = loConfigCSV._ObtenerConfiguracionCSV();
218 string lcBooleanoTrue = cs._BooleanoTrue.Trim();
219 string lcBooleanoFalse = cs._BooleanoFalse.Trim();
221 DataTable ldPlid =
new DataTable();
223 string lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"IDATOS",
"PLINTER_D") +
224 " WHERE CODIGO = " + DB.SQLString(codigoGuia);
225 DB.SQLExec(lcSql, ref ldPlid);
227 if (ldPlid != null || ldPlid.Rows.Count > 0)
229 string nombreColumnaRecargo;
231 var columna = ldPlid.Rows.OfType<DataRow>().Where(F => (Convert.ToInt32(F[
"IDCAMPO"]) == 50029 ||
232 Convert.ToInt32(F[
"IDCAMPO"]) == 50056 ||
233 Convert.ToInt32(F[
"IDCAMPO"]) == 50054) &&
234 !
string.IsNullOrWhiteSpace(F[
"columna"].ToString())).FirstOrDefault();
240 nombreColumnaRecargo = columna[
"COLUMNA"].ToString().Trim();
242 string valDefColumnaRecargo = columna[
"VAL_DEF"].ToString().Trim();
243 if (nombreColumnaRecargo != null)
245 int posicion = posicionColumna(nombreColumnaRecargo);
246 string rec = dataRowEnImportacion.ItemArray[posicion].ToString().Trim();
248 if (
string.IsNullOrEmpty(rec))
250 return valDefColumnaRecargo.ToUpper() == lcBooleanoTrue.ToUpper() || valDefColumnaRecargo.ToUpper() ==
".T.";
254 if (rec.ToUpper() == lcBooleanoTrue.ToUpper() || rec.ToUpper() ==
".T." || rec.ToUpper() == lcBooleanoFalse.ToUpper() || rec.ToUpper() ==
".F.")
256 return rec.ToUpper() == lcBooleanoTrue.ToUpper() || rec.ToUpper() ==
".T.";
273 private string ObtenerCodigoIvaS50()
275 DataTable ldPlid =
new DataTable();
277 string lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"IDATOS",
"PLINTER_D") +
278 " WHERE CODIGO = " + DB.SQLString(codigoGuia);
279 DB.SQLExec(lcSql, ref ldPlid);
281 if (ldPlid != null || ldPlid.Rows.Count > 0)
283 string nombreColumnaCodIva =
"";
284 string valorDefectoCodIva =
"";
285 var columna = ldPlid.Rows.OfType<DataRow>().Where(F => Convert.ToInt32(F[
"IDCAMPO"]) == 50030).FirstOrDefault();
288 nombreColumnaCodIva = columna[
"COLUMNA"].ToString().Trim();
289 valorDefectoCodIva = columna[
"VAL_DEF"].ToString().Trim();
294 if (nombreColumnaCodIva != null)
296 int posicion = posicionColumna(nombreColumnaCodIva);
297 string rec = dataRowEnImportacion.ItemArray[posicion].ToString();
299 if (
string.IsNullOrEmpty(rec))
306 string lcSqlComprobar =
"SELECT * FROM " + DB.SQLDatabase(
"GESTION",
"TIPO_IVA") +
" WHERE CODIGO = '" + rec +
"'";
307 DataTable tablaIvaComprobar =
new DataTable();
308 DB.SQLExec(lcSqlComprobar, ref tablaIvaComprobar);
310 if (tablaIvaComprobar.Rows.Count == 0)
315 string lcMessage =
"No se ha podido encontrar el tipo de IVA con código " + rec +
" especificado en el fichero CSV-EXCEL." + Environment.NewLine +
316 "Por favor, revisa el fichero de datos, y si el código de IVA es correcto asegurate de tenerlo creado dentro de tu " + Convert.ToString(
sage.
ew.
global.
EW_GLOBAL._GetVariable(
"wc_nameproducto"));
318 FUNCTIONS._MessageBox(lcMessage,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Stop,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
System.Windows.Forms.DialogResult.OK);
321 if (!
string.IsNullOrEmpty(valorDefectoCodIva))
322 return valorDefectoCodIva;
324 string lcSqlIvaDefecto =
"SELECT * FROM " + DB.SQLDatabase(
"GESTION",
"TIPO_IVA") +
" WHERE IVA = 21 AND RECARG <> 0 AND IVA_CEE != '' AND DEDUCE = 1 AND EXENTO = 0";
325 DataTable tablaIvaDefecto =
new DataTable();
326 DB.SQLExec(lcSqlIvaDefecto, ref tablaIvaDefecto);
328 if (tablaIvaDefecto.Rows.Count > 0)
329 return tablaIvaDefecto.Rows[0][
"CODIGO"].ToString();
347 private int posicionColumna(
string nombreColumna)
350 if (nombreColumna.Length == 1)
352 ret = Encoding.ASCII.GetBytes(nombreColumna)[0] - 65;
356 if (!
string.IsNullOrWhiteSpace(nombreColumna))
358 Int32 times = Convert.ToInt32(nombreColumna.Substring(0, 1));
359 ret = ((Encoding.ASCII.GetBytes(
"Z")[0] - 65) * times) + (Encoding.ASCII.GetBytes(nombreColumna)[1] - 65) + 1;
365 #endregion METODOS PRIVADOS 367 #endregion CLASE_VALIDARIVA
Es como el tipo de entrada asientos pero por negocio, sin formulario, pq quiero que me haga las propu...
ValidarIVA(string lcCodigoGuia)
Clase ValidationResult
Clase EW_GLOBAL para gestionar las variables públicas de Eurowin, variables de empresa, variables de anchuras de campo, variables de mascaras, etc.
override ValidationResult Validar(string valorColumna, DataRow drEnImportacion)
override ValidationResult Validar(string valorColumna, int columna)
override ValidationResult Validar()