private string ArmaLoteDocumentos(String tipoDocumento, String Compania, String tipoInventario, String fecha_inicio, String fecha_fin, String usuario, String NumLote) { string resultado = ""; string pedido = NumLote; string tDoc = ""; int pilaDocumento = 0; DataTable ListadoDocumentos = new DataTable(); if (tipoDocumento.Equals("FIN") || tipoDocumento.Equals("FOF") || tipoDocumento.Equals("FVH") || tipoDocumento.Equals("FVU") || tipoDocumento.Equals("SER"))//Todas las Facturas { tDoc = "1"; } else if (tipoDocumento.Equals("NIN") || tipoDocumento.Equals("NOF") || tipoDocumento.Equals("NVH") || tipoDocumento.Equals("NVU") || tipoDocumento.Equals("NSE"))//Todas las Notas de Credito { tDoc = "2"; } try { AccesoDatos acd = new AccesoDatos(); string Lote = ""; if (tipoDocumento.Equals("FIN") || tipoDocumento.Equals("NIN") ) { Lote = String.Format(Query.LoteDocumentos, tDoc, Compania, tipoInventario,"<>", desglosaFecha(fecha_inicio, "D"), desglosaFecha(fecha_fin, "D"), desglosaFecha(fecha_inicio, "M"), desglosaFecha(fecha_fin, "M"), desglosaFecha(fecha_inicio, "A"), desglosaFecha(fecha_fin, "A")); } if (tipoDocumento.Equals("SER") || tipoDocumento.Equals("NSE")) { Lote = String.Format(Query.LoteDocumentos, tDoc, Compania, tipoInventario, "=", desglosaFecha(fecha_inicio, "D"), desglosaFecha(fecha_fin, "D"), desglosaFecha(fecha_inicio, "M"), desglosaFecha(fecha_fin, "M"), desglosaFecha(fecha_inicio, "A"), desglosaFecha(fecha_fin, "A")); } if (tipoDocumento.Equals("FVH")) { Lote = String.Format(Query.LoteDocumentosFVH,Compania, desglosaFecha(fecha_inicio, "D"), desglosaFecha(fecha_fin, "D"), desglosaFecha(fecha_inicio, "M"), desglosaFecha(fecha_fin, "M"), desglosaFecha(fecha_inicio, "A"), desglosaFecha(fecha_fin, "A")); } if (tipoDocumento.Equals("NVH")) { Lote = String.Format(Query.LoteDocumentosNVH, Compania, desglosaFecha(fecha_inicio, "D"), desglosaFecha(fecha_fin, "D"), desglosaFecha(fecha_inicio, "M"), desglosaFecha(fecha_fin, "M"), desglosaFecha(fecha_inicio, "A"), desglosaFecha(fecha_fin, "A")); } if (tipoDocumento.Equals("NVU")) { Lote = String.Format(Query.LoteDocumentosNVU, Compania, desglosaFecha(fecha_inicio, "D"), desglosaFecha(fecha_fin, "D"), desglosaFecha(fecha_inicio, "M"), desglosaFecha(fecha_fin, "M"), desglosaFecha(fecha_inicio, "A"), desglosaFecha(fecha_fin, "A")); } if (tipoDocumento.Equals("FVU")) { string vsste=""; string serie = ""; if (Compania.Equals("CS")) { vsste = String.Format("'{0}',''", Compania); serie = "U"; } else if (Compania.Equals("RE")) { vsste = String.Format("'{0}'",Compania); serie = "C"; } Lote = String.Format(Query.LoteDocumentosFVU, desglosaFecha(fecha_inicio, "D"), desglosaFecha(fecha_fin, "D"), desglosaFecha(fecha_inicio, "M"), desglosaFecha(fecha_fin, "M"), desglosaFecha(fecha_inicio, "A"), desglosaFecha(fecha_fin, "A"),vsste,serie); } if (tipoDocumento.Equals("FOF")) { Lote = String.Format(Query.LoteDocumentosOficina,Compania,"FAC", desglosaFecha(fecha_inicio, "D"), desglosaFecha(fecha_fin, "D"), desglosaFecha(fecha_inicio, "M"), desglosaFecha(fecha_fin, "M"), desglosaFecha(fecha_inicio, "A"), desglosaFecha(fecha_fin, "A")); } if (tipoDocumento.Equals("NOF")) { Lote = String.Format(Query.LoteDocumentosOficina,Compania,"NCR", desglosaFecha(fecha_inicio, "D"), desglosaFecha(fecha_fin, "D"), desglosaFecha(fecha_inicio, "M"), desglosaFecha(fecha_fin, "M"), desglosaFecha(fecha_inicio, "A"), desglosaFecha(fecha_fin, "A")); } DataTable Todas = acd.RealizaConsulta(Lote); if (Todas.Rows.Count > 0) { DataTable NoProcesadas = new DataTable(); DataRow[] rrr = Todas.Select("procesada <> ''"); if (rrr.Length > 0) NoProcesadas = rrr.CopyToDataTable(); DataTable Procesadas = new DataTable(); DataRow[] ppp = Todas.Select("procesada = ''"); if (ppp.Length > 0) Procesadas = ppp.CopyToDataTable(); //Aca va la Logica para guardar las NoProcesadas if (NoProcesadas.Rows.Count > 0) { foreach (DataRow r in NoProcesadas.Rows) { AlmacenaFacturas_NoAceptadas(Compania, tipoDocumento, r["NO_DOC"].ToString().Trim(), "Factura aun no Procesada - Sin Detalle", "N"); } } //Fin de Logica if (Procesadas.Rows.Count > 0) { ListadoDocumentos = Procesadas.Copy(); } } int CantidadDocumentos; if (ListadoDocumentos.Rows.Count > 0) { CantidadDocumentos = ListadoDocumentos.Rows.Count; } else { CantidadDocumentos = 0; } if (CantidadDocumentos > 0) { String InitTag = @"<?xml version='1.0' encoding='ISO-8859-1' ?>"+Environment.NewLine+ "<LOTE>"+Environment.NewLine+"<PEDIDO>" + pedido + "</PEDIDO>" +Environment.NewLine+ "<TOTALDOCUMENTOS>" + CantidadDocumentos + "</TOTALDOCUMENTOS>"+Environment.NewLine+"<DOCUMENTOS>"+Environment.NewLine; String EndTag = Environment.NewLine+"</DOCUMENTOS>"+Environment.NewLine+"</LOTE>"; String Cuerpo = ""; String DocumentoLote = ""; for (int i = 0; i < ListadoDocumentos.Rows.Count; i++) { pilaDocumento = i; if (tipoDocumento.Equals("FIN"))//Facturas de Inventario { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.Factura, Compania, ListadoDocumentos.Rows[i]["ESTADO"].ToString().Trim(), tipoInventario, ListadoDocumentos.Rows[i]["NO_DOC"].ToString().Trim(), PFACW0001.ENUMS.TFactura.Repuesto, ""); string facturaTemp = xml.getXmlDocumentoElectronico(); facturaTemp = facturaTemp.Remove(0, 39); Cuerpo = Cuerpo + facturaTemp; } if (tipoDocumento.Equals("NIN"))//NotaCredito Inventario { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.NotaCredito, Compania, ListadoDocumentos.Rows[i]["ESTADO"].ToString().Trim(), tipoInventario, ListadoDocumentos.Rows[i]["NO_DOC"].ToString().Trim(), PFACW0001.ENUMS.TFactura.Repuesto, ""); string NotaCreditoTemp = xml.getXmlDocumentoElectronico(); NotaCreditoTemp = NotaCreditoTemp.Remove(0, 39); Cuerpo = Cuerpo + NotaCreditoTemp; } if (tipoDocumento.Equals("SER")) { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.Factura, Compania, ListadoDocumentos.Rows[i]["ESTADO"].ToString().Trim(), tipoInventario, ListadoDocumentos.Rows[i]["NO_DOC"].ToString().Trim(), PFACW0001.ENUMS.TFactura.Taller, ""); string facturaTempServ = xml.getXmlDocumentoElectronico(); facturaTempServ = facturaTempServ.Remove(0, 39); Cuerpo = Cuerpo + facturaTempServ; } if (tipoDocumento.Equals("NSE")) //Notas de credito de servicios { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.NotaCredito, Compania, ListadoDocumentos.Rows[i]["ESTADO"].ToString().Trim(), tipoInventario, ListadoDocumentos.Rows[i]["NO_DOC"].ToString().Trim(), PFACW0001.ENUMS.TFactura.Taller, ""); string facturaTemp = xml.getXmlDocumentoElectronico(); facturaTemp = facturaTemp.Remove(0, 39); Cuerpo = Cuerpo + facturaTemp; } if (tipoDocumento.Equals("FVH")) //Facturas vehiculos nuevos { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.Factura, Compania, ListadoDocumentos.Rows[i]["ESTADO"].ToString().Trim(), tipoInventario, ListadoDocumentos.Rows[i]["NO_DOC"].ToString().Trim(), PFACW0001.ENUMS.TFactura.VehiculoNuevo, "", ListadoDocumentos.Rows[i]["FECHA"].ToString()); string facturaTemp = xml.getXmlDocumentoElectronico(); facturaTemp = facturaTemp.Remove(0, 39); Cuerpo = Cuerpo + facturaTemp; } if (tipoDocumento.Equals("NVH")) //Notas de credito vehiculos nuevos { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.NotaCredito, Compania, ListadoDocumentos.Rows[i]["ESTADO"].ToString().Trim(), tipoInventario, ListadoDocumentos.Rows[i]["NO_DOC"].ToString().Trim(), PFACW0001.ENUMS.TFactura.Oficina, "NCR"); string facturaTemp = xml.getXmlDocumentoElectronico(); facturaTemp = facturaTemp.Remove(0, 39); Cuerpo = Cuerpo + facturaTemp; } if (tipoDocumento.Equals("FVU")) //Notas de credito vehiculos usados { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.Factura, Compania, ListadoDocumentos.Rows[i]["ESTADO"].ToString().Trim(), tipoInventario, ListadoDocumentos.Rows[i]["NO_DOC"].ToString().Trim(), PFACW0001.ENUMS.TFactura.VehiculoUsado, "", ListadoDocumentos.Rows[i]["FECHA"].ToString()); string facturaTemp = xml.getXmlDocumentoElectronico(); facturaTemp = facturaTemp.Remove(0, 39); Cuerpo = Cuerpo + facturaTemp; } if (tipoDocumento.Equals("NVU")) //Notas de credito vehiculos usados { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.NotaCredito, Compania, ListadoDocumentos.Rows[i]["ESTADO"].ToString().Trim(), tipoInventario, ListadoDocumentos.Rows[i]["NO_DOC"].ToString().Trim(), PFACW0001.ENUMS.TFactura.Oficina, "NCR"); string facturaTemp = xml.getXmlDocumentoElectronico(); facturaTemp = facturaTemp.Remove(0, 39); Cuerpo = Cuerpo + facturaTemp; } if (tipoDocumento.Equals("FOF")) //Facturas de Oficina { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.Factura, Compania, ListadoDocumentos.Rows[i]["ESTADO"].ToString().Trim(), tipoInventario, ListadoDocumentos.Rows[i]["NO_DOC"].ToString().Trim(), PFACW0001.ENUMS.TFactura.Oficina, "FAC"); string facturaTemp = xml.getXmlDocumentoElectronico(); facturaTemp = facturaTemp.Remove(0, 39); Cuerpo = Cuerpo + facturaTemp; } if (tipoDocumento.Equals("NOF")) //Notas de credito de Oficina { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.NotaCredito, Compania, ListadoDocumentos.Rows[i]["ESTADO"].ToString().Trim(), tipoInventario, ListadoDocumentos.Rows[i]["NO_DOC"].ToString().Trim(), PFACW0001.ENUMS.TFactura.Oficina, "NCR"); string facturaTemp = xml.getXmlDocumentoElectronico(); facturaTemp = facturaTemp.Remove(0, 39); Cuerpo = Cuerpo + facturaTemp; } if (tipoDocumento.Equals("3"))//NotaDebito { } } DocumentoLote = InitTag + Cuerpo + EndTag; resultado = DocumentoLote; } else { throw new Exception("No exiten documentos en la fecha indicada."); } } catch (Exception err) { if (ListadoDocumentos.Rows.Count>0) throw new Exception("PFACLOTEx - Doc. No: " + pilaDocumento.ToString() + " Documento: " + ListadoDocumentos.Rows[pilaDocumento]["NO_DOC"].ToString() +".- "+ err.Message); else throw new Exception("PFACLOTEx: " + err.Message); } return resultado; }
public RespuestaGeneral RegistraDocumento(String pCompania,String pNoDocumento, String pEstadoDocumento, String pInventario, String pTipoDocumento, String pUsuario, String pFechaDocumento) { RespuestaGeneral respuesta = new RespuestaGeneral(); DateTime inicioOperacion = DateTime.Now; DateTime finOperacion; String tDoc = ""; try { if (pTipoDocumento.Equals("FIN") || pTipoDocumento.Equals("FOF") || pTipoDocumento.Equals("FVH") || pTipoDocumento.Equals("FVU") || pTipoDocumento.Equals("SER"))//Todas las Facturas { tDoc = "1"; } else if (pTipoDocumento.Equals("NIN") || pTipoDocumento.Equals("NOF") || pTipoDocumento.Equals("NVH") || pTipoDocumento.Equals("NVU") || pTipoDocumento.Equals("NSE"))//Todas las Notas de Credito { tDoc = "2"; } //AccesoDatos acd = new AccesoDatos(); //string qry = String.Format(Query.EstadoDocumento, tDoc,pCompania,pNoDocumento); //DataTable estadoDoc = acd.RealizaConsulta(qry); //if (estadoDoc.Rows.Count > 0) //{ // pEstadoDocumento = estadoDoc.Rows[0]["estado"].ToString(); //} string xmlDoc = ""; inicioOperacion = DateTime.Now; if (pTipoDocumento.Equals("FIN")) { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.Factura, pCompania, pEstadoDocumento, pInventario, pNoDocumento, PFACW0001.ENUMS.TFactura.Repuesto, ""); xmlDoc = xml.getXmlDocumentoElectronico(); } if (pTipoDocumento.Equals("NIN")) { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.NotaCredito, pCompania, pEstadoDocumento, pInventario, pNoDocumento, PFACW0001.ENUMS.TFactura.Repuesto, ""); xmlDoc = xml.getXmlDocumentoElectronico(); } if (pTipoDocumento.Equals("SER")) { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.Factura, pCompania, pEstadoDocumento, pInventario, pNoDocumento, PFACW0001.ENUMS.TFactura.Taller, ""); xmlDoc = xml.getXmlDocumentoElectronico(); } if (pTipoDocumento.Equals("NSE")) { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.NotaCredito, pCompania, pEstadoDocumento, pInventario, pNoDocumento, PFACW0001.ENUMS.TFactura.Taller, ""); xmlDoc = xml.getXmlDocumentoElectronico(); } if (pTipoDocumento.Equals("FVH")) { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.Factura, pCompania, pEstadoDocumento, pInventario, pNoDocumento, PFACW0001.ENUMS.TFactura.VehiculoNuevo,"",pFechaDocumento); xmlDoc = xml.getXmlDocumentoElectronico(); } if (pTipoDocumento.Equals("FVU")) { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.Factura, pCompania, pEstadoDocumento, pInventario, pNoDocumento, PFACW0001.ENUMS.TFactura.VehiculoUsado, "",pFechaDocumento); xmlDoc = xml.getXmlDocumentoElectronico(); } if (pTipoDocumento.Equals("NVH") || pTipoDocumento.Equals("NVU")) { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.NotaCredito, pCompania, pEstadoDocumento, pInventario, pNoDocumento, PFACW0001.ENUMS.TFactura.Oficina, "NCR"); xmlDoc = xml.getXmlDocumentoElectronico(); } if (pTipoDocumento.Equals("FOF")) { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.Factura, pCompania, pEstadoDocumento, pInventario, pNoDocumento, PFACW0001.ENUMS.TFactura.Oficina, "FAC"); xmlDoc = xml.getXmlDocumentoElectronico(); } if (pTipoDocumento.Equals("NOF")) { GeneraXML xml = new GeneraXML(PFACW0001.ENUMS.TDocumento.NotaCredito, pCompania, pEstadoDocumento, pInventario, pNoDocumento, PFACW0001.ENUMS.TFactura.Oficina, "NCR"); xmlDoc = xml.getXmlDocumentoElectronico(); } if (String.IsNullOrEmpty(xmlDoc)) { respuesta.Resultado = false; respuesta.Respuesta = "S/D"; respuesta.Mensaje = "Error al Armar XML del Documento"; } else { RespuestaGeneral temp = new RespuestaGeneral(); temp = CargaDocumento_IFACERE_LOCAL(xmlDoc, pTipoDocumento); respuesta.Resultado = temp.Resultado; respuesta.Respuesta = temp.Respuesta; respuesta.Mensaje = temp.Mensaje; if (respuesta.Resultado) { string hora = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second; AlmacenaEnvioDocumentos(false, pCompania, pTipoDocumento, "", "", hora, pUsuario, "0", pNoDocumento); } finOperacion = DateTime.Now; respuesta.Mensaje = respuesta.Mensaje + Environment.NewLine + String.Format("DuraciĆ³n: {0}", (finOperacion - inicioOperacion).ToString().Substring(0,8)); } } catch (Exception err) { finOperacion = DateTime.Now; respuesta.Resultado = false; respuesta.Respuesta = null; respuesta.Mensaje = err.Message + Environment.NewLine + String.Format("DuraciĆ³n: {0}", (finOperacion - inicioOperacion).ToString().Substring(0, 8)); } return respuesta; }
public bool Test(string serie) { GeneraXML x = new GeneraXML(); return x.CDI_F_VerificaExistenciaSerie(serie); }