public static EmpresaCollection GetEmpresas() { DBEngine.SQLEngine sqlEngine = new DBEngine.SQLEngine(); EmpresaCollection oEmpresaColl = new EmpresaCollection(); DataTable dt = sqlEngine.GetItems("Empresas", "EmpresaID", "Activo = 'True'", 0); foreach (DataRow dr in dt.Rows) { Empresa oEmpresa = new Empresa(dr["EmpresaID"].ToString()); oEmpresaColl.Add(oEmpresa); } return oEmpresaColl; }
public Settings(string EmpresaID) { DBEngine.SQLEngine sqlEngine = new DBEngine.SQLEngine(); parametros = sqlEngine.GetGeneralSettings(EmpresaID); }
public void SaveDocumentInDB(ReporteBase reporte, TipoDocumento strType) { try { var oSettings = new Settings(UnReporte.oEmpresa.EmpresaID); string pathName = oSettings.PathImpresion + @"\TEMP_SITEDOWNLOADS\"; string fileName = pathName + UnReporte.CbteID; try { //Si no existe el path, intento crearlo. if (!System.IO.Directory.Exists(pathName)) System.IO.Directory.CreateDirectory(pathName); } catch (Exception ex) { throw new Exception("No se pudo crear el Path: " + pathName, ex); } //El componente genera el archivo pdf. reporte.ExportToPdf(fileName); //Abro el Pdf creado por el componente, lo convierto en bytes, y lo guardo en la DB. using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { byte[] archivoPdf = new byte[fs.Length]; fs.Read(archivoPdf, 0, archivoPdf.Length); var sqlEngine = new DBEngine.SQLEngine(); if (sqlEngine.Open()) { sqlEngine.SavePdfInDB(archivoPdf, UnReporte.CbteID, UnReporte.TipoDeCopia.ToString()); sqlEngine.Close(); } } //Si se creo el archivo, lo elimino. if (System.IO.File.Exists(fileName)) System.IO.File.Delete(fileName); } catch (Exception) { throw; } }
public Empresa(string EmpresaID) { DBEngine.SQLEngine sqlEngine = new DBEngine.SQLEngine(); parametros = sqlEngine.GetEmpresa(EmpresaID); }
/// <summary> /// Preparo el objeto 'pdf' que luego servirá para llenar todos los campos del reporte. /// </summary> /// <param name="CbteCodigo"></param> /// <param name="CbteCopia"></param> /// <param name="sqlEngine"></param> /// <param name="oEmpresa"></param> /// <param name="oSettings"></param> /// <param name="dtHeader"></param> public void LlenarPropiedades(string CbteCodigo, TipoDeCopia tipoDeCopia, Empresa oEmpresa, Settings oSettings, DataTable dtHeader) { DBEngine.SQLEngine sqlEngine = new DBEngine.SQLEngine(); UnReporte.oEmpresa = oEmpresa; UnReporte.TipoDeCopia = tipoDeCopia; UnReporte.CbteID = dtHeader.Rows[0]["CbteID"].ToString().Trim(); UnReporte.NroCbte = Utils.Utils.FillWithCeros(dtHeader.Rows[0]["PuntoVenta"].ToString().Trim(),4) + "-" + Utils.Utils.FillWithCeros(dtHeader.Rows[0]["NroComprobanteDesde"].ToString(), 8); UnReporte.NombreEmpresa = dtHeader.Rows[0]["CompradorRazonSocial"].ToString(); //------------------------------------------------------------- //Armo la dirección... string direccion = ""; direccion += dtHeader.Rows[0]["CompradorDireccion"].ToString(); //El código postal va siempre. if (dtHeader.Rows[0]["CompradorCodigoPostal"].ToString() != string.Empty && dtHeader.Rows[0]["CompradorCodigoPostal"].ToString() != "0") direccion += " - (" + dtHeader.Rows[0]["CompradorCodigoPostal"].ToString() + ")"; //Solo muestro la Localidad, cuando la PROVINCIA es distinta de 0 (no es Capital Federal). if (Convert.ToString(dtHeader.Rows[0]["CompradorProvincia"]).Trim() != "0") { if (dtHeader.Rows[0]["CompradorLocalidad"].ToString() != string.Empty && dtHeader.Rows[0]["CompradorLocalidad"].ToString() != "0") direccion += " - " + dtHeader.Rows[0]["CompradorLocalidad"].ToString(); } //La provincia se muestra siempre. string provinciaConvertida = FacturaElectronica.WSPrint.Common.GetDescripcionProvincia(Convert.ToString(dtHeader.Rows[0]["CompradorProvincia"])); if (provinciaConvertida.Trim() != string.Empty) direccion += " - " + provinciaConvertida; if (sqlEngine.Open()) { string paisConvertido = sqlEngine.ObtenerEquivalencia("EquivAFIPPais", oSettings.EmpresaID, dtHeader.Rows[0]["CompradorPais"].ToString()); paisConvertido = WSPrint.Common.GetDescripcionPais(paisConvertido); if (paisConvertido != string.Empty && paisConvertido.Trim() != "0") direccion += " - " + paisConvertido; sqlEngine.Close(); } UnReporte.Domicilio = direccion; //------------------------------------------------------------- UnReporte.TipoIva = dtHeader.Rows[0]["CompradorTipoResponsableDescripcion"].ToString(); UnReporte.CondicionDeVenta = dtHeader.Rows[0]["FormaPagoDescripcion"].ToString(); UnReporte.CondicionDePago = dtHeader.Rows[0]["CondicionPago"].ToString(); UnReporte.NumCuit = dtHeader.Rows[0]["CompradorNroDocumento"].ToString(); UnReporte.NumRemito = dtHeader.Rows[0]["NroRemito"].ToString(); UnReporte.NumIIBB = dtHeader.Rows[0]["CompradorNroIIBB"].ToString(); // UnReporte.NumCodIIBB = dtHeader.Rows[0]["CodigoJurisdiccionIIBB"].ToString(); UnReporte.Son = dtHeader.Rows[0]["ImporteEscrito"].ToString(); UnReporte.RefCliente = dtHeader.Rows[0]["CompradorNroReferencia"].ToString(); UnReporte.RefInterna = dtHeader.Rows[0]["NroInternoERP"].ToString(); UnReporte.AlicuotaIVA = dtHeader.Rows[0]["AlicuotaIVA"].ToString(); UnReporte.EmisorDireccion = dtHeader.Rows[0]["EmisorDireccion"].ToString(); UnReporte.EmisorCalle = dtHeader.Rows[0]["EmisorCalle"].ToString(); UnReporte.EmisorCP = dtHeader.Rows[0]["EmisorCP"].ToString(); UnReporte.EmisorLocalidad = dtHeader.Rows[0]["EmisorLocalidad"].ToString(); UnReporte.EmisorProvincia = dtHeader.Rows[0]["EmisorProvincia"].ToString(); UnReporte.EmisorPais = dtHeader.Rows[0]["EmisorPais"].ToString(); UnReporte.EmisorTelefonos = dtHeader.Rows[0]["EmisorTelefonos"].ToString(); UnReporte.EmisorEMail = dtHeader.Rows[0]["EmisorEMail"].ToString(); UnReporte.DAGRUF =Convert.ToString(dtHeader.Rows[0]["DAGRUF"]); UnReporte.OPER = Convert.ToString(dtHeader.Rows[0]["OPER"]); UnReporte.NOPER = Convert.ToString(dtHeader.Rows[0]["NOPER"]); UnReporte.FECPG1_FORMATEADO = Convert.ToString(dtHeader.Rows[0]["FECPG1_FORMATEADO"]); UnReporte.FECPG2_FORMATEADO = Convert.ToString(dtHeader.Rows[0]["FECPG2_FORMATEADO"]); UnReporte.FACTORI_FORMATEADO = Convert.ToString(dtHeader.Rows[0]["FACTORI_FORMATEADO"]); //Convert.ToString(dtHeader.Rows[0]["FACTORI"]); UnReporte.USUARIO = Convert.ToString(dtHeader.Rows[0]["USUARIO"]); UnReporte.CODCLIENTECOMPRADOR = Convert.ToString(dtHeader.Rows[0]["CompradorCodigoCliente"]); UnReporte.OBSERVACIONRAPIPAGO = Convert.ToString(dtHeader.Rows[0]["ObservacionRapipago"]); UnReporte.ERRORCODIGO = GetErrorCodigo(UnReporte.CbteID); UnReporte.TasaIIBB = Convert.ToString(dtHeader.Rows[0]["TasaIIBB"]); if (dtHeader.Rows[0]["LetraComprobante"].ToString() != "B") { if (dtHeader.Rows[0]["ImporteImpuestoLiquidadoMonedaFacturacion"].ToString() != string.Empty) UnReporte.TotalIva = String.Format(FORMATO_NRO, Convert.ToDecimal(dtHeader.Rows[0]["ImporteImpuestoLiquidadoMonedaFacturacion"].ToString())); } else { UnReporte.TotalIva = "0,00"; } decimal subtotal = 0; if (dtHeader.Rows[0]["ImporteMonedaFacturacion"].ToString() != string.Empty) subtotal = Convert.ToDecimal(dtHeader.Rows[0]["ImporteMonedaFacturacion"].ToString()); if (dtHeader.Rows[0]["ImportePercepcionIIBBMonedaFacturacion"].ToString() != string.Empty) subtotal -= Convert.ToDecimal(dtHeader.Rows[0]["ImportePercepcionIIBBMonedaFacturacion"].ToString()); UnReporte.SubTotal = String.Format(FORMATO_NRO, subtotal); decimal subtotalB = 0; if (dtHeader.Rows[0]["ImporteMonedaFacturacionComprobanteB"].ToString() != string.Empty) subtotalB = Convert.ToDecimal(dtHeader.Rows[0]["ImporteMonedaFacturacionComprobanteB"].ToString()); UnReporte.SubTotalComprobanteB = String.Format(FORMATO_NRO, subtotalB); decimal subtotalgravado = 0; if (dtHeader.Rows[0]["ImporteGravadoMonedaFacturacion"].ToString() != string.Empty) subtotalgravado -= Convert.ToDecimal(dtHeader.Rows[0]["ImporteGravadoMonedaFacturacion"].ToString()); UnReporte.SubTotalGravadoMonedaFacturacion = String.Format(FORMATO_NRO, subtotal); decimal totalpercep = 0; if (dtHeader.Rows[0]["ImportePercepcionIIBBMonedaFacturacion"].ToString() != string.Empty) totalpercep = Convert.ToDecimal(dtHeader.Rows[0]["ImportePercepcionIIBBMonedaFacturacion"].ToString()); UnReporte.TotalPercepcionIIBB = String.Format(FORMATO_NRO, totalpercep); if (dtHeader.Rows[0]["ImporteMonedaFacturacion"].ToString() != string.Empty) UnReporte.Total = String.Format(FORMATO_NRO, Convert.ToDecimal(dtHeader.Rows[0]["ImporteMonedaFacturacion"].ToString())); if (dtHeader.Rows[0]["ImporteMonedaFacturacionComprobanteB"].ToString() != string.Empty) UnReporte.TotalComprobanteB = String.Format(FORMATO_NRO, Convert.ToDecimal(dtHeader.Rows[0]["ImporteMonedaFacturacionComprobanteB"].ToString())); if (dtHeader.Rows[0]["ImporteGravadoMonedaFacturacion"].ToString() != string.Empty) UnReporte.TotalGravadoMonedaFacturacion = String.Format(FORMATO_NRO, Convert.ToDecimal(dtHeader.Rows[0]["ImporteGravadoMonedaFacturacion"].ToString())); UnReporte.LetraCbte = dtHeader.Rows[0]["LetraComprobante"].ToString(); UnReporte.TipoCbte = tipoDeCopia.ToString(); UnReporte.NumCodigo = "Código N° " + Utils.Utils.FillWithCeros(CbteCodigo, 2); string strTime = WSPrint.Common.GetDateStringValue(dtHeader.Rows[0]["FechaComprobante"].ToString()); UnReporte.DayCbte = (strTime.Split('/')[0].Length > 1) ? strTime.Split('/')[0] : "0" + strTime.Split('/')[0]; UnReporte.MonthCbte = (strTime.Split('/')[1].Length > 1) ? strTime.Split('/')[1] : "0" + strTime.Split('/')[1]; UnReporte.YearCbte = strTime.Split('/')[2].ToString(); UnReporte.FechaCbte = UnReporte.DayCbte + "/" + UnReporte.MonthCbte + "/" + UnReporte.YearCbte; DateTime dVencimiento; if (DateTime.TryParse(Convert.ToString(dtHeader.Rows[0]["FechaVencimiento"]), out dVencimiento)) UnReporte.FechaVto = dVencimiento.ToString("dd/MM/yyyy"); UnReporte.ObservacionesCabecera = dtHeader.Rows[0]["Observaciones1"].ToString().Replace("|", "\n"); UnReporte.ObservacionesCuerpo = dtHeader.Rows[0]["Observaciones2"].ToString().Replace("|", "\n"); UnReporte.ObservacionesPie = dtHeader.Rows[0]["Observaciones3"].ToString().Replace("|", "\n"); string monedaConvertida = sqlEngine.ObtenerEquivalencia("EquivAFIPMoneda", oSettings.EmpresaID, dtHeader.Rows[0]["CodigoMoneda"].ToString().Trim()); UnReporte.Moneda = WSPrint.Common.GetDescripcionMoneda(monedaConvertida); UnReporte.CAE = dtHeader.Rows[0]["CAE"].ToString(); string strtimeVto = UnReporte.FechaVto; if (dtHeader.Rows[0]["RapiPago"] != null) UnReporte.Rapipago = dtHeader.Rows[0]["RapiPago"].ToString(); if (dtHeader.Rows[0]["PagoFacil"] != null) UnReporte.Pagofacil = dtHeader.Rows[0]["PagoFacil"].ToString(); UnReporte.BarCodeCbte = WSPrint.Common.GetBarCode(oEmpresa.NroDocumento, Utils.Utils.FillWithCeros(CbteCodigo, 2), dtHeader.Rows[0]["PuntoVenta"].ToString(), UnReporte.CAE, strtimeVto.Split('/')[2] + ((strtimeVto.Split('/')[1].Length == 1) ? "0" + strtimeVto.Split('/')[1] : strtimeVto.Split('/')[1]) + ((strtimeVto.Split('/')[0].Length == 1) ? "0" + strtimeVto.Split('/')[0] : strtimeVto.Split('/')[0])); /**************************************************************************************/ decimal ImporteGravado = 0; if (dtHeader.Rows[0]["ImporteGravado"].ToString() != string.Empty) ImporteGravado = Convert.ToDecimal(dtHeader.Rows[0]["ImporteGravado"].ToString()); UnReporte.ImpuestoSubGrav = String.Format(FORMATO_NRO, ImporteGravado); decimal ImporteNoGravado = 0; if (dtHeader.Rows[0]["ImporteNoGravado"].ToString() != string.Empty) ImporteNoGravado = Convert.ToDecimal(dtHeader.Rows[0]["ImporteNoGravado"].ToString()); UnReporte.ImporteSubNoGrav = String.Format(FORMATO_NRO, ImporteNoGravado); if (dtHeader.Rows[0]["LetraComprobante"].ToString() == "A") { decimal ImporteSubTotal = ImporteGravado + ImporteNoGravado; UnReporte.ImporteSubTotal = String.Format(FORMATO_NRO, ImporteSubTotal); } if (dtHeader.Rows[0]["LetraComprobante"].ToString() == "B") { decimal ImporteImpuestoLiquidado = 0; if (dtHeader.Rows[0]["ImporteImpuestoLiquidado"].ToString() != string.Empty) ImporteImpuestoLiquidado = Convert.ToDecimal(dtHeader.Rows[0]["ImporteImpuestoLiquidado"].ToString()); decimal ImporteSubTotal = ImporteGravado + ImporteNoGravado + ImporteImpuestoLiquidado; UnReporte.ImporteSubTotal = String.Format(FORMATO_NRO, ImporteSubTotal); } /**************************************************************************************/ /* decimal CUOTAIVA21 = 0; if (dtHeader.Rows[0]["CUOTAIVA21"].ToString() != string.Empty) CUOTAIVA21 = Convert.ToDecimal(dtHeader.Rows[0]["CUOTAIVA21"].ToString()); UnReporte.CUOTAIVA21 = String.Format(FORMATO_NRO, CUOTAIVA21); decimal CUOTAIVA105 = 0; if (dtHeader.Rows[0]["CUOTAIVA105"].ToString() != string.Empty) CUOTAIVA105 = Convert.ToDecimal(dtHeader.Rows[0]["CUOTAIVA105"].ToString()); UnReporte.CUOTAIVA105 = String.Format(FORMATO_NRO, CUOTAIVA105); */ }