protected void Generar_Planilla(string numero, string tipo) { string plantilla = ""; string nlchar = "`", redChar = "^"; int anchoTiquete = Tiquetes.anchoTiquete; try { string strLinea = ""; StreamReader strArchivo; strArchivo = File.OpenText(ConfigurationManager.AppSettings["PathToPapeleria"] + "\\PlantillaPlanillaGemela.txt"); strLinea = strArchivo.ReadLine(); //La primera linea puede contener el ancho del tiquete try { anchoTiquete = Int16.Parse(strLinea); strLinea = strArchivo.ReadLine(); } catch {} while (strLinea != null) { plantilla += strLinea + nlchar; strLinea = strArchivo.ReadLine(); } strArchivo.Close(); } catch { Utils.MostrarAlerta(Response, "No se ha creado la plantilla de planillas, no se pudo imprimir."); return; } plantilla = plantilla.Replace("<RED>", redChar); txtPlanilla = ""; DataSet dsPlanilla = new DataSet(); DataSet dsViaje = new DataSet(); DataSet dsInfoTiquete = new DataSet(); int SecuenciaRuta1, SecuenciaRutaT; //Info general DBFunctions.Request(dsInfoTiquete, IncludeSchema.NO, "select * from dbxschema.ccampos_tiquete;"); //Planilla DBFunctions.Request(dsPlanilla, IncludeSchema.NO, "SELECT * FROM DBXSCHEMA.MPLANILLAVIAJE WHERE MPLA_CODIGO=" + numero + ";"); if (dsPlanilla.Tables[0].Rows.Count == 0) { return; } string agencia = dsPlanilla.Tables[0].Rows[0]["MAG_CODIGO"].ToString(); string rutaP = dsPlanilla.Tables[0].Rows[0]["MRUT_CODIGO"].ToString(); string viaje = dsPlanilla.Tables[0].Rows[0]["MVIAJE_NUMERO"].ToString(); double ValorTiquete, TotalIngresos, TotalEgresos, Pasajeros, TotalTiquetes, PorcentajeRuta1, ValorEncomienda; //Gemelas if (!DBFunctions.RecordExist("SELECT MPLA_CODIGO FROM DBXSCHEMA.MPLANILLA_VIAJE_GEMELA WHERE MPLA_CODIGO=" + numero + ";")) { return; } string rutaG = "", origenG, destinoG, rutaI, CodigoRuta1, DestinoRuta1; DataSet dsGemela = new DataSet(); DBFunctions.Request(dsGemela, IncludeSchema.NO, "SELECT MRUT_CODIGO,MRUT_CODIGO1,MRUT_CODIGO2,CODIGO_INTERNO1,CODIGO_INTERNO2,PORCENTAJE_RUTA1 FROM DBXSCHEMA.MRUTAS_DOBLE_PLANILLA WHERE MRUT_CODIGO='" + rutaP + "';"); CodigoRuta1 = dsGemela.Tables[0].Rows[0]["MRUT_CODIGO1"].ToString(); SecuenciaRuta1 = Convert.ToInt32(DBFunctions.SingleData(" Select MRUTA_SECUENCIA from DBXSCHEMA.MRUTA_INTERMEDIA WHERE MRUTA_PRINCIPAL = '" + rutaP + "' AND MRUTA_SECUNDARIA = '" + CodigoRuta1 + "';")); PorcentajeRuta1 = Convert.ToDouble(dsGemela.Tables[0].Rows[0]["PORCENTAJE_RUTA1"]); if (dsGemela.Tables[0].Rows.Count > 0) { if (tipo == "1") { rutaG = dsGemela.Tables[0].Rows[0]["MRUT_CODIGO1"].ToString(); rutaI = dsGemela.Tables[0].Rows[0]["CODIGO_INTERNO1"].ToString(); } else if (tipo == "2") { rutaG = dsGemela.Tables[0].Rows[0]["MRUT_CODIGO2"].ToString(); rutaI = dsGemela.Tables[0].Rows[0]["CODIGO_INTERNO2"].ToString(); } else { return; } } else { return; } origenG = DBFunctions.SingleData("SELECT PC.PCIU_NOMBRE FROM DBXSCHEMA.MRUTAS MR, DBXSCHEMA.PCIUDAD PC WHERE PC.PCIU_CODIGO=MR.PCIU_COD AND MR.MRUT_CODIGO='" + rutaG + "';"); destinoG = DBFunctions.SingleData("SELECT PC.PCIU_NOMBRE FROM DBXSCHEMA.MRUTAS MR, DBXSCHEMA.PCIUDAD PC WHERE PC.PCIU_CODIGO=MR.PCIU_CODDES AND MR.MRUT_CODIGO='" + rutaG + "';"); plantilla = plantilla.Replace("<ORIGEN_GEMELA>", origenG); plantilla = plantilla.Replace("<DESTINO_GEMELA>", destinoG); plantilla = plantilla.Replace("<RUTA_INTERNA>", rutaI); DBFunctions.Request(dsViaje, IncludeSchema.NO, "SELECT * FROM DBXSCHEMA.MVIAJE WHERE MRUT_CODIGO='" + rutaP + "' AND MVIAJE_NUMERO=" + viaje + ";"); if (dsViaje.Tables[0].Rows.Count == 0) { return; } int hora = Convert.ToInt32(dsViaje.Tables[0].Rows[0]["HORA_SALIDA"]); string placa = dsViaje.Tables[0].Rows[0]["MCAT_PLACA"].ToString(); string numVehiculo = DBFunctions.SingleData("SELECT MBUS_NUMERO FROM DBXSCHEMA.MBUSAFILIADO WHERE MCAT_PLACA='"+ placa + "';"); //txtPlanilla+="Número: "+dsPlanilla.Tables[0].Rows[0]["MPLA_CODIGO"].ToString()+nlchar; plantilla = plantilla.Replace("<NUMERO>", dsPlanilla.Tables[0].Rows[0]["MPLA_CODIGO"].ToString()); //txtPlanilla+="Fecha: "+DateTime.Now.ToString("yyyy-MM-dd HH:mm")+nlchar; plantilla = plantilla.Replace("<FECHA>", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //txtPlanilla+="Bus: "+numVehiculo+" ("+placa+")"+nlchar; plantilla = plantilla.Replace("<BUS_NUMERO>", numVehiculo); plantilla = plantilla.Replace("<BUS_PLACA>", placa); //txtPlanilla+="Origen : "+DBFunctions.SingleData("SELECT PC.PCIU_NOMBRE FROM DBXSCHEMA.MAGENCIA MA, DBXSCHEMA.PCIUDAD PC WHERE PC.PCIU_CODIGO=MA.PCIU_CODIGO AND MA.MAG_CODIGO="+agencia+";")+nlchar; //plantilla=plantilla.Replace("<ORIGEN>",DBFunctions.SingleData("SELECT PC.PCIU_NOMBRE FROM DBXSCHEMA.MAGENCIA MA, DBXSCHEMA.PCIUDAD PC WHERE PC.PCIU_CODIGO=MA.PCIU_CODIGO AND MA.MAG_CODIGO="+agencia+";")); //txtPlanilla+="Destino: "+DBFunctions.SingleData("SELECT PC.PCIU_NOMBRE FROM DBXSCHEMA.MRUTAS MR, DBXSCHEMA.PCIUDAD PC WHERE PC.PCIU_CODIGO=MR.PCIU_CODDES AND MR.MRUT_CODIGO='"+rutaP+"';")+nlchar; //plantilla=plantilla.Replace("<DESTINO>",DBFunctions.SingleData("SELECT PC.PCIU_NOMBRE FROM DBXSCHEMA.MRUTAS MR, DBXSCHEMA.PCIUDAD PC WHERE PC.PCIU_CODIGO=MR.PCIU_CODDES AND MR.MRUT_CODIGO='"+rutaP+"';")); //txtPlanilla+="Agencia: "+DBFunctions.SingleData("SELECT MAGE_NOMBRE FROM DBXSCHEMA.MAGENCIA WHERE MAG_CODIGO="+agencia+";")+nlchar; //plantilla=plantilla.Replace("<AGENCIA>",DBFunctions.SingleData("SELECT MAGE_NOMBRE FROM DBXSCHEMA.MAGENCIA WHERE MAG_CODIGO="+agencia+";")); plantilla = plantilla.Replace("<AGENCIA>", agencia); //txtPlanilla+="Salida: "+Convert.ToDateTime(dsViaje.Tables[0].Rows[0]["FECHA_SALIDA"]).ToString("yyyy-MM-dd")+" "+Math.Round((double)hora/60,0).ToString("00")+":"+(hora%60).ToString("00")+nlchar; plantilla = plantilla.Replace("<FECHA_SALIDA>", Convert.ToDateTime(dsViaje.Tables[0].Rows[0]["FECHA_SALIDA"]).ToString("yyyy-MM-dd") + " " + Math.Round((double)hora / 60, 0).ToString("00") + ":" + (hora % 60).ToString("00")); //txtPlanilla+=Tiquetes.CortarTexto("Conductor: "+DBFunctions.SingleData("select mnit_nombres concat ' ' concat mnit_apellidos FROM DBXSCHEMA.MNIT WHERE MNIT_NIT='"+dsViaje.Tables[0].Rows[0]["MNIT_CONDUCTOR"]+"';"))+nlchar; plantilla = plantilla.Replace("<CONDUCTOR_NOMBRE>", DBFunctions.SingleData("select mnit_nombres concat ' ' concat mnit_apellidos FROM DBXSCHEMA.MNIT WHERE MNIT_NIT='" + dsViaje.Tables[0].Rows[0]["MNIT_CONDUCTOR"] + "';")); //txtPlanilla+=Tiquetes.CortarTexto("Relevador: "+DBFunctions.SingleData("select mnit_nombres concat ' ' concat mnit_apellidos FROM DBXSCHEMA.MNIT WHERE MNIT_NIT='"+dsViaje.Tables[0].Rows[0]["MNIT_RELEVADOR1"]+"';"))+nlchar; plantilla = plantilla.Replace("<RELEVADOR_NOMBRE>", DBFunctions.SingleData("select mnit_nombres concat ' ' concat mnit_apellidos FROM DBXSCHEMA.MNIT WHERE MNIT_NIT='" + dsViaje.Tables[0].Rows[0]["MNIT_RELEVADOR1"] + "';")); string espacio = " "; string num = ""; string Pasajes = ""; //Tiquetes DataSet dsTiquetes = new DataSet(); DBFunctions.Request(dsTiquetes, IncludeSchema.NO, "Select cast(right(rtrim(char(MV.NUM_DOCUMENTO))," + AMS.Comercial.Tiquetes.lenTiquete + ") as integer) AS NUM_DOCUMENTO,PC.PCIU_NOMBRE AS DESTINO,MV.MRUT_CODIGO AS CODIGO_RUTA,MV.NUMERO_PUESTOS,MV.VALOR_PASAJE,MV.VALOR_TOTAL " + "FROM DBXSCHEMA.MTIQUETE_VIAJE MV,DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MRUTAS MR " + "WHERE MR.MRUT_CODIGO=MV.MRUT_CODIGO AND PC.PCIU_CODIGO=MR.PCIU_CODDES AND MV.TEST_CODIGO='V' AND MV.MPLA_CODIGO=" + numero + ";"); txtPlanilla = ""; TotalIngresos = 0; TotalEgresos = 0; Pasajeros = 0; if (dsTiquetes.Tables[0].Rows.Count > 0) { txtPlanilla += nlchar; txtPlanilla += "TIQUETES" + nlchar; txtPlanilla += redChar + "--------" + nlchar; } double TotalPasajes = 0; foreach (DataRow dr in dsTiquetes.Tables[0].Rows) { SecuenciaRutaT = Convert.ToInt32(DBFunctions.SingleData(" Select MRUTA_SECUENCIA from DBXSCHEMA.MRUTA_INTERMEDIA WHERE MRUTA_PRINCIPAL = '" + rutaP + "' AND MRUTA_SECUNDARIA = '" + dr["CODIGO_RUTA"].ToString() + "';")); // Condicion para saber si lista el tiquete de acuerdo a la planilla 1 o 2 if (tipo == "1" || (tipo == "2" && SecuenciaRutaT > SecuenciaRuta1)) { num = dr["NUM_DOCUMENTO"].ToString().Trim(); if (num.Length > Tiquetes.lenTiquete) { num = Convert.ToInt32(num.Substring(num.Length - Tiquetes.lenTiquete)).ToString(); } num = new string('0', Tiquetes.lenTiquete - num.Length) + num; Pasajes = dr["NUMERO_PUESTOS"].ToString(); Pasajes = new string(' ', Tiquetes.lenTiquete - num.Length) + Pasajes; if (tipo == "1") { if (SecuenciaRutaT > SecuenciaRuta1) { DestinoRuta1 = DBFunctions.SingleData("Select PC.PCIU_NOMBRE AS DESTINO FROM DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MRUTAS MR " + "WHERE MR.MRUT_CODIGO='" + CodigoRuta1 + "' AND PC.PCIU_CODIGO=MR.PCIU_CODDES;"); txtPlanilla += "No." + num + espacio + Pasajes + espacio + DestinoRuta1 + nlchar; ValorTiquete = Math.Round((Convert.ToDouble(dr["VALOR_PASAJE"].ToString()) * PorcentajeRuta1 / 100), 0); } else { ValorTiquete = Convert.ToDouble(dr["VALOR_PASAJE"].ToString()); txtPlanilla += "No. " + num + espacio + dr["DESTINO"].ToString() + nlchar; } } else { ValorTiquete = Convert.ToDouble(dr["VALOR_PASAJE"].ToString()) - Math.Round((Convert.ToDouble(dr["VALOR_PASAJE"].ToString()) * PorcentajeRuta1 / 100), 0); txtPlanilla += "No. " + num + espacio + dr["DESTINO"].ToString() + nlchar; } TotalTiquetes = ValorTiquete * Convert.ToInt32(dr["NUMERO_PUESTOS"].ToString()); txtPlanilla += "Vr. " + num + espacio + ValorTiquete.ToString() + nlchar; txtPlanilla += "Tot. " + new string(' ', Tiquetes.lenTiquete) + espacio + TotalTiquetes.ToString() + nlchar; TotalIngresos += TotalTiquetes; TotalPasajes += TotalTiquetes; Pasajeros += Convert.ToInt32(dr["NUMERO_PUESTOS"].ToString()); } } txtPlanilla += "" + nlchar; txtPlanilla += "Total Pasajes: " + TotalPasajes.ToString("###,###,##0") + nlchar; //Tiquetes Prepago DataSet dsTiquetesPre = new DataSet(); DBFunctions.Request(dsTiquetesPre, IncludeSchema.NO, "Select cast(right(rtrim(char(MV.NUM_DOCUMENTO))," + AMS.Comercial.Tiquetes.lenTiquete + ") as integer) AS NUM_DOCUMENTO,PC.PCIU_NOMBRE AS DESTINO,MV.MRUT_CODIGO AS CODIGO_RUTA,MV.VALOR_PASAJE,MV.VALOR_TOTAL " + "FROM DBXSCHEMA.MTIQUETE_VIAJE_PREPAGO MV,DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MRUTAS MR " + "WHERE MR.MRUT_CODIGO=MV.MRUT_CODIGO AND PC.PCIU_CODIGO=MR.PCIU_CODDES AND MV.MPLA_CODIGO=" + numero + ";"); if (dsTiquetesPre.Tables[0].Rows.Count > 0) { txtPlanilla += "" + nlchar; txtPlanilla += "TIQUETES PREPAGO" + nlchar; txtPlanilla += redChar + "-------- -------" + nlchar; } foreach (DataRow dr in dsTiquetesPre.Tables[0].Rows) { SecuenciaRutaT = Convert.ToInt32(DBFunctions.SingleData(" Select MRUTA_SECUENCIA from DBXSCHEMA.MRUTA_INTERMEDIA WHERE MRUTA_PRINCIPAL = '" + rutaP + "' AND MRUTA_SECUNDARIA = '" + dr["CODIGO_RUTA"].ToString() + "';")); // Condicion para saber si lista el tiquete de acuerdo a la planilla if (tipo == "1" || (tipo == "2" && SecuenciaRutaT > SecuenciaRuta1)) { num = dr["NUM_DOCUMENTO"].ToString().Trim(); if (num.Length > Tiquetes.lenTiquete) { num = Convert.ToInt32(num.Substring(num.Length - Tiquetes.lenTiquete)).ToString(); } num = new string('0', Tiquetes.lenTiquete - num.Length) + num; if (tipo == "1") { if (SecuenciaRutaT > SecuenciaRuta1) { DestinoRuta1 = DBFunctions.SingleData("Select PC.PCIU_NOMBRE AS DESTINO FROM DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MRUTAS MR " + "WHERE MR.MRUT_CODIGO='" + CodigoRuta1 + "' AND PC.PCIU_CODIGO=MR.PCIU_CODDES;"); txtPlanilla += "No. " + num + espacio + DestinoRuta1 + nlchar; ValorTiquete = Math.Round((Convert.ToDouble(dr["VALOR_PASAJE"].ToString()) * PorcentajeRuta1 / 100), 0); } else { ValorTiquete = Convert.ToDouble(dr["VALOR_PASAJE"].ToString()); txtPlanilla += "No. " + num + espacio + dr["DESTINO"].ToString() + nlchar; } } else { ValorTiquete = Convert.ToDouble(dr["VALOR_PASAJE"].ToString()) - Math.Round((Convert.ToDouble(dr["VALOR_PASAJE"].ToString()) * PorcentajeRuta1 / 100), 0); txtPlanilla += "No. " + num + espacio + dr["DESTINO"].ToString() + nlchar; } txtPlanilla += "Vr. " + num + espacio + ValorTiquete.ToString() + nlchar; txtPlanilla += "Tot. " + num + espacio + ValorTiquete.ToString() + nlchar; TotalIngresos += ValorTiquete; Pasajeros += 1; } } //Encomiendas DataSet dsEncomiendas = new DataSet(); DBFunctions.Request(dsEncomiendas, IncludeSchema.NO, "Select MV.NUM_DOCUMENTO,PC.PCIU_NOMBRE AS DESTINO,MV.MRUT_CODIGO AS CODIGO_RUTA,MV.COSTO_ENCOMIENDA,MV.VALOR_TOTAL,MV.DESCRIPCION_CONTENIDO " + "FROM DBXSCHEMA.MENCOMIENDAS MV,DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MRUTAS MR " + "WHERE MR.MRUT_CODIGO=MV.MRUT_CODIGO AND PC.PCIU_CODIGO=MR.PCIU_CODDES AND MV.MPLA_CODIGO=" + numero + ";"); if (dsEncomiendas.Tables[0].Rows.Count > 0) { txtPlanilla += "" + nlchar; txtPlanilla += "ENCOMIENDAS" + nlchar; txtPlanilla += redChar + "-----------" + nlchar; } foreach (DataRow dr in dsEncomiendas.Tables[0].Rows) { SecuenciaRutaT = Convert.ToInt32(DBFunctions.SingleData(" Select coalesce(MRUTA_SECUENCIA,0) from DBXSCHEMA.MRUTA_INTERMEDIA WHERE MRUTA_PRINCIPAL = '" + rutaP + "' AND MRUTA_SECUNDARIA = '" + dr["CODIGO_RUTA"].ToString() + "';")); // Condicion para saber si lista el tiquete de acuerdo a la planilla if (tipo == "1" || (tipo == "2" && SecuenciaRutaT > SecuenciaRuta1)) { num = dr["NUM_DOCUMENTO"].ToString().Trim(); if (num.Length > Tiquetes.lenTiquete) { num = Convert.ToInt32(num.Substring(num.Length - Tiquetes.lenTiquete)).ToString(); } num = new string('0', Tiquetes.lenTiquete - num.Length) + num; if (tipo == "1") { if (SecuenciaRutaT > SecuenciaRuta1) { DestinoRuta1 = DBFunctions.SingleData("Select PC.PCIU_NOMBRE AS DESTINO FROM DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MRUTAS MR " + "WHERE MR.MRUT_CODIGO='" + CodigoRuta1 + "' AND PC.PCIU_CODIGO=MR.PCIU_CODDE;"); txtPlanilla += "No. " + num + espacio + DestinoRuta1 + nlchar; ValorEncomienda = Math.Round((Convert.ToDouble(dr["COSTO_ENCOMIENDA"].ToString()) * PorcentajeRuta1 / 100), 0); } else { ValorEncomienda = Convert.ToDouble(dr["COSTO_ENCOMIENDA"].ToString()); txtPlanilla += "No. " + num + espacio + dr["DESTINO"].ToString() + nlchar; } } else { ValorEncomienda = Convert.ToDouble(dr["COSTO_ENCOMIENDA"].ToString()) - Math.Round((Convert.ToDouble(dr["COSTO_ENCOMIENDA"].ToString()) * PorcentajeRuta1 / 100), 0); txtPlanilla += "No. " + num + espacio + dr["DESTINO"].ToString() + nlchar; } txtPlanilla += "Vr. " + num + espacio + ValorEncomienda.ToString() + nlchar; txtPlanilla += "Tot. " + num + espacio + ValorEncomienda.ToString() + nlchar; txtPlanilla += Tiquetes.CortarTexto(espacio + dr["DESCRIPCION_CONTENIDO"].ToString()) + nlchar; TotalIngresos += ValorEncomienda; } } //Giros if (tipo == "1") { DataSet dsGiros = new DataSet(); DBFunctions.Request(dsGiros, IncludeSchema.NO, "Select MV.NUM_DOCUMENTO,PC.PCIU_NOMBRE AS DESTINO,MV.COSTO_GIRO,MV.VALOR_GIRO " + "FROM DBXSCHEMA.MGIROS MV,DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MAGENCIA MA " + "WHERE MA.MAG_CODIGO=MV.MAG_AGENCIA_DESTINO AND PC.PCIU_CODIGO=MA.PCIU_CODIGO AND MV.MPLA_CODIGO=" + numero + ";"); if (dsGiros.Tables[0].Rows.Count > 0) { txtPlanilla += "" + nlchar; txtPlanilla += "GIROS" + nlchar; txtPlanilla += redChar + "-----" + nlchar; } foreach (DataRow dr in dsGiros.Tables[0].Rows) { num = dr["NUM_DOCUMENTO"].ToString().Trim(); if (num.Length > Tiquetes.lenTiquete) { num = Convert.ToInt32(num.Substring(num.Length - Tiquetes.lenTiquete)).ToString(); } num = new string('0', Tiquetes.lenTiquete - num.Length) + num; txtPlanilla += "No. " + num + espacio + dr["DESTINO"].ToString() + nlchar; num = new string(' ', Tiquetes.lenTiquete); txtPlanilla += "Cst. " + num + espacio + dr["COSTO_GIRO"].ToString() + nlchar; txtPlanilla += "Vr. " + num + espacio + dr["VALOR_GIRO"].ToString() + nlchar; TotalIngresos += Convert.ToDouble(dr["COSTO_GIRO"].ToString()); } } //Anticipos if (tipo == "1") { DataSet dsAnticipos = new DataSet(); DBFunctions.Request(dsAnticipos, IncludeSchema.NO, "Select MV.NUM_DOCUMENTO,TG.NOMBRE AS CONCEPTO,MV.VALOR_TOTAL_AUTORIZADO " + "FROM DBXSCHEMA.MGASTOS_TRANSPORTES MV, DBXSCHEMA.TCONCEPTOS_TRANSPORTES TG " + "WHERE MV.TCON_CODIGO=TG.TCON_CODIGO AND MV.MPLA_CODIGO=" + numero + ";"); if (dsAnticipos.Tables[0].Rows.Count > 0) { txtPlanilla += "" + nlchar; txtPlanilla += "ANTICIPOS-INGRESOS-EGRESOS" + nlchar; txtPlanilla += redChar + "---------" + nlchar; } foreach (DataRow dr in dsAnticipos.Tables[0].Rows) { num = dr["NUM_DOCUMENTO"].ToString().Trim(); if (num.Length > Tiquetes.lenTiquete) { num = Convert.ToInt32(num.Substring(num.Length - Tiquetes.lenTiquete)).ToString(); } num = new string('0', Tiquetes.lenTiquete - num.Length) + num; txtPlanilla += "No. " + dr["CONCEPTO"].ToString() + nlchar; num = new string(' ', Tiquetes.lenTiquete); txtPlanilla += "Vr. " + num + espacio + dr["VALOR_TOTAL_AUTORIZADO"].ToString() + nlchar; TotalEgresos += Convert.ToDouble(dr["VALOR_TOTAL_AUTORIZADO"].ToString()); } } plantilla = plantilla.Replace("<CONTENIDO>", txtPlanilla); //txtPlanilla+=redChar+"INGRESOS: "+Convert.ToDouble(DBFunctions.SingleData("SELECT coalesce(VALOR_INGRESOS,0) FROM DBXSCHEMA.MPLANILLAVIAJE WHERE MPLA_CODIGO="+numero)).ToString("###,###,###")+nlchar; plantilla = plantilla.Replace("<INGRESOS>", Convert.ToDouble(TotalIngresos).ToString("###,###,##0")); //txtPlanilla+=redChar+"EGRESOS: "+Convert.ToDouble(DBFunctions.SingleData("SELECT coalesce(VALOR_EGRESOS,0) FROM DBXSCHEMA.MPLANILLAVIAJE WHERE MPLA_CODIGO="+numero)).ToString("###,###,###")+nlchar; plantilla = plantilla.Replace("<EGRESOS>", Convert.ToDouble(TotalEgresos).ToString("###,###,##0")); /*txtPlanilla+=redChar+"TOTAL PASAJEROS: "+DBFunctions.SingleData("Select sum(MV.NUMERO_PUESTOS) "+ * "FROM DBXSCHEMA.MTIQUETE_VIAJE MV,DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MRUTAS MR "+ * "WHERE MR.MRUT_CODIGO=MV.MRUT_CODIGO AND PC.PCIU_CODIGO=MR.PCIU_CODDES AND MV.TEST_CODIGO='V' AND MV.MPLA_CODIGO="+numero+";")+nlchar;*/ plantilla = plantilla.Replace("<PASAJEROS>", Convert.ToDouble(Pasajeros).ToString()); txtPlanilla = plantilla; }
//Planillar private void btnPlanillar_Click(object sender, System.EventArgs e) { #region Validaciones Generales ArrayList sqlUpd = new ArrayList(); string errores = ""; string viaje; string agencia = ddlAgencia.SelectedValue.Trim().Replace("|", ""); string placa = txtPlaca.Text.Trim(); long numDocumento = 0; DateTime fecha = Convert.ToDateTime(txtFecha.Text); string conductor = txtConductor.Text.Trim(); string relevador = txtRelevador.Text.Trim(); relevador = (relevador.Length == 0)?"NULL":"'" + relevador + "'"; string rutaP = ddlRutaPrincipal.SelectedValue; string nitPlanillaManual = DBFunctions.SingleData("select mnit_nit from dbxschema.mnit where mnit_nombres='Planilla Manual';"); //Responsable string nitResponsable = DBFunctions.SingleData("select mnit_nit from DBXSCHEMA.susuario where susu_login='******';"); if (nitResponsable.Length == 0) { Response.Write("<script language='javascript'>alert('El usuario (responsable) no tiene un NIT asignado.');</script>"); return; } //Hora int hora = (int.Parse(ddlHora.SelectedValue) * 60) + int.Parse(ddlMinuto.SelectedValue); //Afiliado string afiliado = DBFunctions.SingleData("SELECT MNIT_ASOCIADO FROM DBXSCHEMA.MBUSAFILIADO WHERE MCAT_PLACA='" + placa + "'"); afiliado = (afiliado.Length == 0)?"NULL":"'" + afiliado + "'"; //Configuracion string configBus = DBFunctions.SingleData("Select MCON_COD from DBXSCHEMA.MBUSAFILIADO WHERE MCAT_PLACA='" + placa + "';"); if (configBus.Length == 0) { configBus = "NULL"; } string planilla = Planillas.TraerSiguientePlanillaVirtual(); viaje = Viajes.TraerSiguienteViaje(rutaP); //Insertar viaje sqlUpd.Add("INSERT INTO dbxschema.MVIAJE values('" + rutaP + "'," + viaje + ",'" + fecha.ToString("yyyy-MM-dd") + "'," + hora + ",NULL," + agencia + ",'" + placa + "'," + configBus + ",'" + conductor + "'," + relevador + ",NULL," + afiliado + ",'" + nitResponsable + "'," + hora + ",NULL,NULL,NULL,NULL,NULL,'A',NULL);"); //Insertar papeleria sqlUpd.Add("INSERT INTO DBXSCHEMA.MCONTROL_PAPELERIA VALUES('PLA'," + planilla + ",'V',0,'" + DateTime.Now.ToString("yyyy-MM-dd") + "',0," + agencia + ",'" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + nitResponsable + "',0,'" + DateTime.Now.ToString("yyyy-MM-dd") + "',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'" + DateTime.Now.ToString("yyyy-MM-dd") + "');"); //Insertar planilla sqlUpd.Add("insert into dbxschema.mplanillaviaje values(" + planilla + ",'" + rutaP + "'," + viaje + "," + agencia + ",'" + nitResponsable + "','" + fecha.ToString("yyyy-MM-dd") + "',NULL,NULL,NULL,0,0,NULL);"); #endregion //Fila real y actual int fila = 1, linea = 1; //Totales double totalTiquetes = 0, valorSeguro; //Seguro try { valorSeguro = Convert.ToDouble(DBFunctions.SingleData("SELECT VALOR_SEGURO FROM DBXSCHEMA.CTRANSPORTES;")); } catch { valorSeguro = 0; } #region Tiquetes int prefijo = 0, totalPasajeros = 0; //Prefijo tiquetes if (ddlAgencia.SelectedValue.EndsWith("|")) { prefijo = Convert.ToInt16(agencia); } numDocumento = Convert.ToInt64(Tiquetes.TraerSiguienteTiqueteVirtual()); foreach (DataGridItem dgrI in dgrTiquetes.Items) { bool errLin = false; DropDownList ddlDestino = (DropDownList)dgrI.FindControl("ddlDestinoTiquete"); TextBox txtCantidadTiquete = (TextBox)dgrI.FindControl("txtCantidadTiquete"); TextBox txtValorTiquete = (TextBox)dgrI.FindControl("txtValorTiquete"); TextBox txtTotalTiquete = (TextBox)dgrI.FindControl("txtTotalTiquete"); CheckBox chkAnula = (CheckBox)dgrI.FindControl("chkAnlulado"); DropDownList ddlConceptoAnulacion = (DropDownList)dgrI.FindControl("ddlConceptoAnulacion"); if ((ddlDestino.SelectedValue.Length > 0 || txtCantidadTiquete.Text.Trim().Length > 0 || txtValorTiquete.Text.Trim().Length > 0)) { int cantidad = 0; double precio = 0; bool anula = false; string ruta = ddlDestino.SelectedValue; //Ruta if (ruta.Length == 0) { errores += "Destino de tiquete no válido en la línea " + fila + ". "; errLin = true; } //Cantidad try{ cantidad = int.Parse(txtCantidadTiquete.Text.Replace(",", "").Trim()); } catch { errores += "Cantidad de tiquetes no válida en la línea " + fila + ". "; errLin = true; } //Precio try{ precio = double.Parse(txtValorTiquete.Text.Replace(",", "").Trim()); if (precio <= 0) { throw(new Exception()); } } catch { errores += "Precio de tiquete no válido en la línea " + fila + ". "; errLin = true; } //Anulado? if (!errLin && chkAnula.Checked) { if (ddlConceptoAnulacion.SelectedValue.Length == 0) { errores += "Debe seleccionar la causa de la anulacion en la línea " + fila + ". "; errLin = true; } else { anula = true; } } //Verificar rango precio if (!errLin) { if (!DBFunctions.RecordExist("SELECT MRUT_VALSUG FROM DBXSCHEMA.MRUTAS WHERE MRUT_VALMAX>=" + precio + " AND MRUT_VALMIN<=" + precio + " AND MRUT_CODIGO='" + ruta + "';")) { txtValorTiquete.Text = Convert.ToDouble(DBFunctions.SingleData("SELECT MRUT_VALMAX FROM DBXSCHEMA.MRUTAS WHERE MRUT_CODIGO='" + ruta + "';")).ToString("###,###,##0.##"); errores += "Precio de tiquete fuera del rango válido en la línea " + fila + ", el precio ha sido remplazado. "; strActScript += "totalTicketes('" + txtCantidadTiquete.ClientID + "','" + txtValorTiquete.ClientID + "','" + txtTotalTiquete.ClientID + "',1);"; errLin = true; } } //Insertar tiquete if (!errLin) { sqlUpd.Add("INSERT INTO DBXSCHEMA.MCONTROL_PAPELERIA VALUES('TIQ'," + numDocumento + ",'V',0,'" + DateTime.Now.ToString("yyyy-MM-dd") + "',0," + agencia + ",'" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + nitResponsable + "',0,'" + DateTime.Now.ToString("yyyy-MM-dd") + "',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'" + DateTime.Now.ToString("yyyy-MM-dd") + "');"); if (anula) { //ANULAR sqlUpd.Add("INSERT INTO dbxschema.mtiquete_viaje values('TIQ'," + numDocumento + "," + planilla + "," + linea + ",'" + ruta + "','" + nitResponsable + "'," + cantidad + ",'" + nitPlanillaManual + "'," + valorSeguro.ToString("0") + "," + precio + "," + precio * cantidad + ",'" + fecha.ToString("yyyy-MM-dd") + "','A');"); sqlUpd.Add("INSERT INTO dbxschema.MTIQUETE_VIAJE_ANULADO values('TIQ'," + numDocumento + "," + ddlConceptoAnulacion.SelectedValue + ",'" + fecha.ToString("yyyy-MM-dd") + "','" + nitResponsable + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "');"); sqlUpd.Add("UPDATE DBXSCHEMA.MCONTROL_PAPELERIA SET NUM_ANULACION=0, COD_ANULACION=" + ddlConceptoAnulacion.SelectedValue + ",MNIT_ANULACION='" + nitResponsable + "', FECHA_ANULACION='" + DateTime.Now.ToString("yyyy-MM-dd") + "' WHERE TDOC_CODIGO='TIQ' AND NUM_DOCUMENTO=" + numDocumento + ";"); } else { sqlUpd.Add("INSERT INTO dbxschema.mtiquete_viaje values('TIQ'," + numDocumento + "," + planilla + "," + linea + ",'" + ruta + "','" + nitResponsable + "'," + cantidad + ",'" + nitPlanillaManual + "'," + valorSeguro.ToString("0") + "," + precio + "," + precio * cantidad + ",'" + fecha.ToString("yyyy-MM-dd") + "','V');"); totalTiquetes += cantidad * precio; totalPasajeros += cantidad; } //Modificar papeleria(usada) sqlUpd.Add("UPDATE DBXSCHEMA.MCONTROL_PAPELERIA SET FECHA_USO='" + DateTime.Now.ToString("yyyy-MM-dd") + "',MPLA_CODIGO=" + planilla + " WHERE TDOC_CODIGO='TIQ' AND NUM_DOCUMENTO=" + numDocumento + ";"); dgrI.Cells[0].BackColor = dgrI.Cells[1].BackColor; linea++; } else { dgrI.Cells[0].BackColor = System.Drawing.Color.DarkSalmon; if (errores.Length > 0) { errores += "\\r\\n"; } } numDocumento++; } else { dgrI.Cells[0].BackColor = dgrI.Cells[1].BackColor; } fila++; } #endregion if (errores.Length == 0) { //Actualizar VIAJE sqlUpd.Add("UPDATE dbxschema.MVIAJE SET VALOR_INGRESOS=" + (totalTiquetes) + ", VALOR_EGRESOS=0, ESTADO_VIAJE='T', FECHA_LIQUIDACION='" + fecha.ToString("yyyy-MM-dd") + "' WHERE MRUT_CODIGO='" + rutaP + "' AND MVIAJE_NUMERO=" + viaje + ";"); //Actualizar PLANILLA: NO. LINEAS, FECHA LIQUID, INGRESOS, EGRESOS, NO. LINEAS sqlUpd.Add("UPDATE dbxschema.MPLANILLAVIAJE SET VALOR_INGRESOS=" + (totalTiquetes) + ", VALOR_EGRESOS=0, NUMERO_LINEAS=" + linea + ", FECHA_LIQUIDACION='" + fecha.ToString("yyyy-MM-dd") + "' WHERE MPLA_CODIGO=" + planilla + ";"); //Actualizar PAPELERIA PLANILLA sqlUpd.Add("UPDATE DBXSCHEMA.MCONTROL_PAPELERIA SET FECHA_USO='" + DateTime.Now.ToString("yyyy-MM-dd") + "' WHERE TDOC_CODIGO='PLA' AND NUM_DOCUMENTO=" + planilla + ";"); if (DBFunctions.Transaction(sqlUpd)) { Response.Redirect(indexPage + "?process=Comercial.PlanillaBus&path=" + Request.QueryString["path"] + "&pln=" + planilla); } else { lblError.Text = DBFunctions.exceptions; } } else { strActScript += "alert('" + errores + "');"; } }
protected void Generar_Encomienda(string numero) { string agenciaO, ruta, fecha, entregaNit, entregaCel, placa, numBus, entregaNombre, recibeNit, recibeCel, recibeNombre, descripcion, unidades, peso, volumen, valDeclarado, costo, iva, total, responsableNit, responsableNombre; string plantilla = ""; string nlchar = "`", redChar = "^"; int anchoTiquete = Tiquetes.anchoTiquete; try { string strLinea = ""; StreamReader strArchivo; strArchivo = File.OpenText(ConfigurationManager.AppSettings["PathToPapeleria"] + "\\PlantillaEncomienda.txt"); strLinea = strArchivo.ReadLine(); //La primera linea puede contener el ancho del tiquete try { anchoTiquete = Int16.Parse(strLinea); strLinea = strArchivo.ReadLine(); } catch {} while (strLinea != null) { plantilla += strLinea + nlchar; strLinea = strArchivo.ReadLine(); } strArchivo.Close(); } catch { Utils.MostrarAlerta(Response, "No se ha creado la plantilla de Encomiendas, no se pudo imprimir."); return; } plantilla = plantilla.Replace("<RED>", redChar); DataSet dsEncomienda = new DataSet(); DBFunctions.Request(dsEncomienda, IncludeSchema.NO, "SELECT * FROM DBXSCHEMA.MENCOMIENDAS WHERE NUM_DOCUMENTO=" + numero + ";"); if (dsEncomienda.Tables[0].Rows.Count == 0) { plantilla = "NO EXISTE LA ENCOMIENDA"; return; } agenciaO = DBFunctions.SingleData("SELECT MAGE_NOMBRE FROM DBXSCHEMA.MAGENCIA WHERE MAG_CODIGO=" + dsEncomienda.Tables[0].Rows[0]["MAG_RECIBE"].ToString() + ";"); ruta = DBFunctions.SingleData("SELECT MRUT_DESCRIPCION FROM DBXSCHEMA.MRUTAS WHERE MRUT_CODIGO='" + dsEncomienda.Tables[0].Rows[0]["MRUT_CODIGO"].ToString() + "';"); fecha = Convert.ToDateTime(dsEncomienda.Tables[0].Rows[0]["FECHA_RECIBE"]).ToString("yyyy/MM/dd"); placa = dsEncomienda.Tables[0].Rows[0]["MCAT_PLACA"].ToString(); numBus = DBFunctions.SingleData("SELECT MBUS_NUMERO FROM DBXSCHEMA.MBUSAFILIADO WHERE MCAT_PLACA='" + placa + "';"); entregaNit = dsEncomienda.Tables[0].Rows[0]["MNIT_EMISOR"].ToString(); entregaNombre = DBFunctions.SingleData("SELECT MPAS_NOMBRES CONCAT ' ' CONCAT MPAS_APELLIDOS FROM DBXSCHEMA.MPASAJERO where MPAS_NIT='" + entregaNit + "';"); entregaCel = DBFunctions.SingleData("SELECT MPAS_TELEFONO FROM DBXSCHEMA.MPASAJERO where MPAS_NIT='" + entregaNit + "';"); recibeNit = dsEncomienda.Tables[0].Rows[0]["MNIT_DESTINATARIO"].ToString(); recibeNombre = DBFunctions.SingleData("SELECT MPAS_NOMBRES CONCAT ' ' CONCAT MPAS_APELLIDOS FROM DBXSCHEMA.MPASAJERO where MPAS_NIT='" + recibeNit + "';"); recibeCel = DBFunctions.SingleData("SELECT MPAS_TELEFONO FROM DBXSCHEMA.MPASAJERO where MPAS_NIT='" + recibeNit + "';"); responsableNit = dsEncomienda.Tables[0].Rows[0]["MNIT_RESPONSABLE_RECIBE"].ToString(); responsableNombre = DBFunctions.SingleData("SELECT MNIT_NOMBRES CONCAT ' ' CONCAT MNIT_APELLIDOS FROM DBXSCHEMA.MNIT where MNIT_NIT='" + responsableNit + "';"); unidades = Convert.ToDouble(dsEncomienda.Tables[0].Rows[0]["UNIDADES"]).ToString("###,###,##0"); peso = Convert.ToDouble(dsEncomienda.Tables[0].Rows[0]["PESO"]).ToString("###,###,##0"); volumen = Convert.ToDouble(dsEncomienda.Tables[0].Rows[0]["VOLUMEN"]).ToString("###,###,##0"); valDeclarado = Convert.ToDouble(dsEncomienda.Tables[0].Rows[0]["VALOR_AVALUO"]).ToString("###,###,##0"); costo = Convert.ToDouble(dsEncomienda.Tables[0].Rows[0]["COSTO_ENCOMIENDA"]).ToString("###,###,##0"); iva = Convert.ToDouble(dsEncomienda.Tables[0].Rows[0]["VALOR_IVA"]).ToString("###,###,##0"); total = Convert.ToDouble(dsEncomienda.Tables[0].Rows[0]["VALOR_TOTAL"]).ToString("###,###,##0"); plantilla = plantilla.Replace("<NUMERO>", numero); plantilla = plantilla.Replace("<FECHA>", fecha); plantilla = plantilla.Replace("<PLANILLA>", dsEncomienda.Tables[0].Rows[0]["MPLA_CODIGO"].ToString()); plantilla = plantilla.Replace("<DOCUMENTO>", dsEncomienda.Tables[0].Rows[0]["NUM_DOC_REFERENCIA"].ToString()); plantilla = plantilla.Replace("<AGENCIA>", agenciaO); plantilla = plantilla.Replace("<RUTA>", ruta); plantilla = plantilla.Replace("<BUS_NUMERO>", numBus); plantilla = plantilla.Replace("<BUS_PLACA>", placa); plantilla = plantilla.Replace("<ENTREGA_NOMBRE>", entregaNombre); plantilla = plantilla.Replace("<ENTREGA_NIT>", entregaNit); plantilla = plantilla.Replace("<ENTREGA_CEL>", entregaCel); plantilla = plantilla.Replace("<RECIBE_NOMBRE>", recibeNombre); plantilla = plantilla.Replace("<RECIBE_NIT>", recibeNit); plantilla = plantilla.Replace("<RECIBE_CEL>", recibeCel); //descripcion=Tiquetes.CortarTexto(dsEncomienda.Tables[0].Rows[0]["DESCRIPCION_CONTENIDO"].ToString(),anchoTiquete); descripcion = dsEncomienda.Tables[0].Rows[0]["DESCRIPCION_CONTENIDO"].ToString(); int longitud = descripcion.Length; int lineas = longitud / Tiquetes.anchoTiquete; string txtDescripcion = ""; int subindice = 0; for (int i = 1; i <= lineas; i++) { txtDescripcion += Tiquetes.ReemplazarTexto(descripcion.Substring(subindice, Tiquetes.anchoTiquete).ToString()) + nlchar; subindice += Tiquetes.anchoTiquete; } if (subindice < longitud) { txtDescripcion += Tiquetes.ReemplazarTexto(descripcion.Substring(subindice, longitud - subindice).ToString()) + nlchar; } plantilla = plantilla.Replace("<DESCRIPCION>", txtDescripcion); //plantilla=plantilla.Replace("<DESCRIPCION>",descripcion); plantilla = plantilla.Replace("<UNIDADES>", unidades); plantilla = plantilla.Replace("<PESO>", peso); plantilla = plantilla.Replace("<VOLUMEN>", volumen); plantilla = plantilla.Replace("<VALOR_DECLARADO>", valDeclarado); plantilla = plantilla.Replace("<COSTO_ENCOMIENDA>", costo); plantilla = plantilla.Replace("<IVA_ENCOMIENDA>", iva); plantilla = plantilla.Replace("<TOTAL_ENCOMIENDA>", total); plantilla = plantilla.Replace("<NITRESPONSABLE>", responsableNit); plantilla = plantilla.Replace("<RESPONSABLE>", responsableNombre); txtEncomienda = plantilla; }
protected void Generar_Giro(string numero) { string agenciaO, agenciaD, fecha, entregaNit, entregaNombre, recibeNit, recibeNombre, ResponsableNombre, valor, costo, iva, total; string plantilla = ""; string nlchar = "`", redChar = "^"; int anchoTiquete = Tiquetes.anchoTiquete; try { string strLinea = ""; StreamReader strArchivo; strArchivo = File.OpenText(ConfigurationManager.AppSettings["PathToPapeleria"] + "\\PlantillaGiro.txt"); strLinea = strArchivo.ReadLine(); //La primera linea puede contener el ancho del tiquete try { anchoTiquete = Int16.Parse(strLinea); strLinea = strArchivo.ReadLine(); } catch {} while (strLinea != null) { plantilla += strLinea + nlchar; strLinea = strArchivo.ReadLine(); } strArchivo.Close(); } catch { Utils.MostrarAlerta(Response, "No se ha creado la plantilla de Giros, no se pudo imprimir."); return; } plantilla = plantilla.Replace("<RED>", redChar); DataSet dsGiro = new DataSet(); DBFunctions.Request(dsGiro, IncludeSchema.NO, "SELECT * FROM DBXSCHEMA.MGIROS WHERE NUM_DOCUMENTO=" + numero + ";"); if (dsGiro.Tables[0].Rows.Count == 0) { plantilla = "NO EXISTE EL GIRO"; return; } //Validar responsable string nitResponsable = DBFunctions.SingleData("select mnit_nit from DBXSCHEMA.susuario where susu_login='******';"); if (nitResponsable.Length == 0) { Utils.MostrarAlerta(Response, "NO TIENE NIT EL USUARIO--> CREELO EN NITS"); return; } agenciaO = DBFunctions.SingleData("SELECT MAGE_NOMBRE FROM DBXSCHEMA.MAGENCIA WHERE MAG_CODIGO=" + dsGiro.Tables[0].Rows[0]["MAG_AGENCIA_ORIGEN"].ToString() + ";"); agenciaD = DBFunctions.SingleData("SELECT MAGE_NOMBRE FROM DBXSCHEMA.MAGENCIA WHERE MAG_CODIGO=" + dsGiro.Tables[0].Rows[0]["MAG_AGENCIA_DESTINO"].ToString() + ";"); fecha = Convert.ToDateTime(dsGiro.Tables[0].Rows[0]["FECHA_RECIBE"]).ToString("yyyy/MM/dd"); entregaNit = dsGiro.Tables[0].Rows[0]["MNIT_EMISOR"].ToString(); entregaNombre = DBFunctions.SingleData("SELECT MNIT_NOMBRES CONCAT ' ' CONCAT MNIT_APELLIDOS FROM DBXSCHEMA.MNIT where MNIT_NIT='" + entregaNit + "';"); ResponsableNombre = DBFunctions.SingleData("SELECT MNIT_NOMBRES CONCAT ' ' CONCAT MNIT_APELLIDOS FROM DBXSCHEMA.MNIT where MNIT_NIT='" + nitResponsable + "';"); recibeNit = dsGiro.Tables[0].Rows[0]["MNIT_DESTINATARIO"].ToString(); recibeNombre = DBFunctions.SingleData("SELECT MNIT_NOMBRES CONCAT ' ' CONCAT MNIT_APELLIDOS FROM DBXSCHEMA.MNIT where MNIT_NIT='" + recibeNit + "';"); valor = Convert.ToDouble(dsGiro.Tables[0].Rows[0]["VALOR_GIRO"]).ToString("###,###,##0"); costo = Convert.ToDouble(dsGiro.Tables[0].Rows[0]["COSTO_GIRO"]).ToString("###,###,##0"); iva = Convert.ToDouble(dsGiro.Tables[0].Rows[0]["VALOR_IVA"]).ToString("###,###,##0"); total = (Convert.ToDouble(dsGiro.Tables[0].Rows[0]["VALOR_GIRO"]) + Convert.ToDouble(dsGiro.Tables[0].Rows[0]["COSTO_GIRO"]) + Convert.ToDouble(dsGiro.Tables[0].Rows[0]["VALOR_IVA"])).ToString("###,###,##0"); plantilla = plantilla.Replace("<NUMERO>", numero); plantilla = plantilla.Replace("<FECHA>", fecha); plantilla = plantilla.Replace("<AGENCIA_ORIGEN>", agenciaO); plantilla = plantilla.Replace("<AGENCIA_DESTINO>", agenciaD); plantilla = plantilla.Replace("<ENTREGA_NOMBRE>", entregaNombre); plantilla = plantilla.Replace("<ENTREGA_NIT>", entregaNit); plantilla = plantilla.Replace("<RECIBE_NOMBRE>", recibeNombre); plantilla = plantilla.Replace("<RECIBE_NIT>", recibeNit); plantilla = plantilla.Replace("<VALOR_GIRO>", valor); plantilla = plantilla.Replace("<COSTO_GIRO>", costo); plantilla = plantilla.Replace("<IVA_GIRO>", iva); plantilla = plantilla.Replace("<TOTAL_GIRO>", total); int longitud = ResponsableNombre.Length; int lineas = longitud / Tiquetes.anchoTiquete; string txtNombre = ""; int subindice = 0; for (int i = 1; i <= lineas; i++) { txtNombre += Tiquetes.ReemplazarTexto(ResponsableNombre.Substring(subindice, Tiquetes.anchoTiquete).ToString()) + nlchar; subindice += Tiquetes.anchoTiquete; } if (subindice < longitud) { txtNombre += Tiquetes.ReemplazarTexto(ResponsableNombre.Substring(subindice, longitud - subindice).ToString()) + nlchar; } plantilla = plantilla.Replace("<RESPONSABLE>", txtNombre); txtGiro = plantilla; }
//Generar el anticipo a partir de su plantilla public static string GenerarAnticipo(string numero, string plantilla, string nlchar, string redChar, int anchoTiquete) { string agencia, fecha, busNumero, busPlaca, planilla, concepto, entregaNit, entregaNombre, recibeNit, recibeNombre, descripcion, cantidad, valorU, valorT; plantilla = plantilla.Replace("<RED>", redChar); DataSet dsAnticipo = new DataSet(); DBFunctions.Request(dsAnticipo, IncludeSchema.NO, "SELECT * FROM DBXSCHEMA.MGASTOS_TRANSPORTES WHERE NUM_DOCUMENTO=" + numero + ";"); if (dsAnticipo.Tables[0].Rows.Count == 0) { return("NO EXISTE EL ANTICIPO"); } agencia = DBFunctions.SingleData("SELECT MAGE_NOMBRE FROM DBXSCHEMA.MAGENCIA WHERE MAG_CODIGO=" + dsAnticipo.Tables[0].Rows[0]["MAG_CODIGO"].ToString() + ";"); busPlaca = dsAnticipo.Tables[0].Rows[0]["MCAT_PLACA"].ToString(); busNumero = DBFunctions.SingleData("SELECT MBUS_NUMERO FROM DBXSCHEMA.MBUSAFILIADO WHERE MCAT_PLACA='"+ busPlaca + "';"); planilla = dsAnticipo.Tables[0].Rows[0]["MPLA_CODIGO"].ToString(); concepto = DBFunctions.SingleData("SELECT NOMBRE from DBXSCHEMA.TCONCEPTOS_TRANSPORTES WHERE TCON_CODIGO=" + dsAnticipo.Tables[0].Rows[0]["TCON_CODIGO"].ToString() + ";"); entregaNit = dsAnticipo.Tables[0].Rows[0]["MNIT_RESPONSABLE_ENTREGA"].ToString(); entregaNombre = DBFunctions.SingleData("SELECT MNIT_NOMBRES CONCAT ' ' CONCAT MNIT_APELLIDOS FROM DBXSCHEMA.MNIT where MNIT_NIT='" + entregaNit + "';"); recibeNit = dsAnticipo.Tables[0].Rows[0]["MNIT_RESPONSABLE_RECIBE"].ToString(); recibeNombre = DBFunctions.SingleData("SELECT MNIT_NOMBRES CONCAT ' ' CONCAT MNIT_APELLIDOS FROM DBXSCHEMA.MNIT where MNIT_NIT='" + recibeNit + "';"); //descripcion=Tiquetes.CortarTexto(dsAnticipo.Tables[0].Rows[0]["DESCRIPCION"].ToString(),anchoTiquete); cantidad = Convert.ToDouble(dsAnticipo.Tables[0].Rows[0]["CANTIDAD_CONSUMO"]).ToString("##0"); valorU = Convert.ToDouble(dsAnticipo.Tables[0].Rows[0]["VALOR_UNIDAD"]).ToString("###,###,##0"); valorT = Convert.ToDouble(dsAnticipo.Tables[0].Rows[0]["VALOR_TOTAL_AUTORIZADO"]).ToString("###,###,##0"); fecha = Convert.ToDateTime(dsAnticipo.Tables[0].Rows[0]["FECHA_DOCUMENTO"]).ToString("yyyy/MM/dd"); plantilla = plantilla.Replace("<FECHA_IMPRESION>", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt")); plantilla = plantilla.Replace("<NUMERO>", numero); plantilla = plantilla.Replace("<AGENCIA>", agencia); plantilla = plantilla.Replace("<BUS_NUMERO>", busNumero); plantilla = plantilla.Replace("<BUS_PLACA>", busPlaca); plantilla = plantilla.Replace("<PLANILLA>", planilla); plantilla = plantilla.Replace("<CONCEPTO>", concepto); plantilla = plantilla.Replace("<ENTREGA_NOMBRE>", entregaNombre); plantilla = plantilla.Replace("<ENTREGA_NIT>", entregaNit); plantilla = plantilla.Replace("<RECIBE_NOMBRE>", recibeNombre); plantilla = plantilla.Replace("<RECIBE_NIT>", recibeNit); descripcion = dsAnticipo.Tables[0].Rows[0]["DESCRIPCION"].ToString(); int longitud = descripcion.Length; int lineas = longitud / Tiquetes.anchoTiquete; string txtDescripcion = ""; int subindice = 0; for (int i = 1; i <= lineas; i++) { txtDescripcion += Tiquetes.ReemplazarTexto(descripcion.Substring(subindice, Tiquetes.anchoTiquete).ToString()) + nlchar; subindice += Tiquetes.anchoTiquete; } if (subindice < longitud) { txtDescripcion += Tiquetes.ReemplazarTexto(descripcion.Substring(subindice, longitud - subindice).ToString()) + nlchar; } plantilla = plantilla.Replace("<DESCRIPCION>", txtDescripcion); //plantilla=plantilla.Replace("<DESCRIPCION>",descripcion); plantilla = plantilla.Replace("<CANTIDAD>", cantidad); plantilla = plantilla.Replace("<VALOR_UNIDAD>", valorU); plantilla = plantilla.Replace("<VALOR_TOTAL>", valorT); return(plantilla.Replace("<FECHA>", fecha)); }
//Generar la planilla a pertir de su plantilla public static string GenerarPlanilla(string numero, string plantilla, string nlchar, string redChar, int anchoTiquete) { DataSet dsPlanilla = new DataSet(); DataSet dsViaje = new DataSet(); DataSet dsInfoTiquete = new DataSet(); //Info general DBFunctions.Request(dsInfoTiquete, IncludeSchema.NO, "select * from dbxschema.ccampos_tiquete;"); //Planilla DBFunctions.Request(dsPlanilla, IncludeSchema.NO, "SELECT * FROM DBXSCHEMA.MPLANILLAVIAJE WHERE MPLA_CODIGO=" + numero + ";"); if (dsPlanilla.Tables[0].Rows.Count == 0) { return("NO HAY DATOS DE LA PLANILLA"); } string agencia = dsPlanilla.Tables[0].Rows[0]["MAG_CODIGO"].ToString(); string rutaP = dsPlanilla.Tables[0].Rows[0]["MRUT_CODIGO"].ToString(); string viaje = dsPlanilla.Tables[0].Rows[0]["MVIAJE_NUMERO"].ToString(); DBFunctions.Request(dsViaje, IncludeSchema.NO, "SELECT * FROM DBXSCHEMA.MVIAJE WHERE MRUT_CODIGO='" + rutaP + "' AND MVIAJE_NUMERO=" + viaje + ";"); if (dsViaje.Tables[0].Rows.Count == 0) { return("NO HAY DATOS DEL VIAJE"); } int hora = Convert.ToInt32(dsViaje.Tables[0].Rows[0]["HORA_SALIDA"]); int horaDespacho = Convert.ToInt32(dsViaje.Tables[0].Rows[0]["HORA_DESPACHO"]); string placa = dsViaje.Tables[0].Rows[0]["MCAT_PLACA"].ToString(); string numVehiculo = DBFunctions.SingleData("SELECT MBUS_NUMERO FROM DBXSCHEMA.MBUSAFILIADO WHERE MCAT_PLACA='"+ placa + "';"); /*txtPlanilla+=redChar+new String('-',anchoTiquete)+nlchar; * if(dsInfoTiquete.Tables[0].Rows.Count>0) * { * txtPlanilla+=Tiquetes.CentrarTexto(dsInfoTiquete.Tables[0].Rows[0]["NOMBRE_EMPRESA"].ToString(),' ')+nlchar; * txtPlanilla+=Tiquetes.CentrarTexto("NIT. "+dsInfoTiquete.Tables[0].Rows[0]["NIT_EMPRESA"].ToString(),' ')+nlchar;} * txtPlanilla+=redChar+new String('-',anchoTiquete)+nlchar; * txtPlanilla+=""+nlchar;*/ //txtPlanilla+="Número: "+dsPlanilla.Tables[0].Rows[0]["MPLA_CODIGO"].ToString()+nlchar; plantilla = plantilla.Replace("<NUMERO>", dsPlanilla.Tables[0].Rows[0]["MPLA_CODIGO"].ToString()); //txtPlanilla+="Fecha: "+DateTime.Now.ToString("yyyy-MM-dd HH:mm")+nlchar; plantilla = plantilla.Replace("<FECHA>", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //txtPlanilla+="Bus: "+numVehiculo+" ("+placa+")"+nlchar; plantilla = plantilla.Replace("<BUS_NUMERO>", numVehiculo); plantilla = plantilla.Replace("<BUS_PLACA>", placa); //txtPlanilla+="Origen : "+DBFunctions.SingleData("SELECT PC.PCIU_NOMBRE FROM DBXSCHEMA.MAGENCIA MA, DBXSCHEMA.PCIUDAD PC WHERE PC.PCIU_CODIGO=MA.PCIU_CODIGO AND MA.MAG_CODIGO="+agencia+";")+nlchar; plantilla = plantilla.Replace("<ORIGEN>", DBFunctions.SingleData("SELECT PC.PCIU_NOMBRE FROM DBXSCHEMA.MAGENCIA MA, DBXSCHEMA.PCIUDAD PC WHERE PC.PCIU_CODIGO=MA.PCIU_CODIGO AND MA.MAG_CODIGO=" + agencia + ";")); //txtPlanilla+="Destino: "+DBFunctions.SingleData("SELECT PC.PCIU_NOMBRE FROM DBXSCHEMA.MRUTAS MR, DBXSCHEMA.PCIUDAD PC WHERE PC.PCIU_CODIGO=MR.PCIU_CODDES AND MR.MRUT_CODIGO='"+rutaP+"';")+nlchar; plantilla = plantilla.Replace("<DESTINO>", DBFunctions.SingleData("SELECT PC.PCIU_NOMBRE FROM DBXSCHEMA.MRUTAS MR, DBXSCHEMA.PCIUDAD PC WHERE PC.PCIU_CODIGO=MR.PCIU_CODDES AND MR.MRUT_CODIGO='" + rutaP + "';")); plantilla = plantilla.Replace("<NUMERO_VIAJE>", viaje); //txtPlanilla+="Agencia: "+DBFunctions.SingleData("SELECT MAGE_NOMBRE FROM DBXSCHEMA.MAGENCIA WHERE MAG_CODIGO="+agencia+";")+nlchar; plantilla = plantilla.Replace("<AGENCIA>", DBFunctions.SingleData("SELECT MAGE_NOMBRE FROM DBXSCHEMA.MAGENCIA WHERE MAG_CODIGO=" + agencia + ";")); //txtPlanilla+="Salida: "+Convert.ToDateTime(dsViaje.Tables[0].Rows[0]["FECHA_SALIDA"]).ToString("yyyy-MM-dd")+" "+Math.Round((double)hora/60,0).ToString("00")+":"+(hora%60).ToString("00")+nlchar; plantilla = plantilla.Replace("<FECHA_SALIDA>", Convert.ToDateTime(dsViaje.Tables[0].Rows[0]["FECHA_SALIDA"]).ToString("yyyy-MM-dd") + " " + (hora / 60).ToString("00") + ":" + (hora % 60).ToString("00")); plantilla = plantilla.Replace("<HORA_DESPACHO>", ((int)horaDespacho / 60).ToString("00") + ":" + (horaDespacho % 60).ToString("00")); //txtPlanilla+=Tiquetes.CortarTexto("Conductor: "+DBFunctions.SingleData("select mnit_nombres concat ' ' concat mnit_apellidos FROM DBXSCHEMA.MNIT WHERE MNIT_NIT='"+dsViaje.Tables[0].Rows[0]["MNIT_CONDUCTOR"]+"';"))+nlchar; plantilla = plantilla.Replace("<CONDUCTOR_NOMBRE>", DBFunctions.SingleData("select mnit_nombres concat ' ' concat mnit_apellidos FROM DBXSCHEMA.MNIT WHERE MNIT_NIT='" + dsViaje.Tables[0].Rows[0]["MNIT_CONDUCTOR"] + "';")); //txtPlanilla+=Tiquetes.CortarTexto("Relevador: "+DBFunctions.SingleData("select mnit_nombres concat ' ' concat mnit_apellidos FROM DBXSCHEMA.MNIT WHERE MNIT_NIT='"+dsViaje.Tables[0].Rows[0]["MNIT_RELEVADOR1"]+"';"))+nlchar; plantilla = plantilla.Replace("<RELEVADOR_NOMBRE>", DBFunctions.SingleData("select mnit_nombres concat ' ' concat mnit_apellidos FROM DBXSCHEMA.MNIT WHERE MNIT_NIT='" + dsViaje.Tables[0].Rows[0]["MNIT_RELEVADOR1"] + "';")); string espacio = " "; string num = ""; //Tiquetes DataSet dsTiquetes = new DataSet(); DBFunctions.Request(dsTiquetes, IncludeSchema.NO, "Select cast(right(rtrim(char(MV.NUM_DOCUMENTO))," + AMS.Comercial.Tiquetes.lenTiquete + ") as integer) AS NUM_DOCUMENTO,PC.PCIU_NOMBRE AS DESTINO,MV.NUMERO_PUESTOS,MV.VALOR_PASAJE,MV.VALOR_TOTAL " + "FROM DBXSCHEMA.MTIQUETE_VIAJE MV,DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MRUTAS MR " + "WHERE MR.MRUT_CODIGO=MV.MRUT_CODIGO AND PC.PCIU_CODIGO=MR.PCIU_CODDES AND MV.TEST_CODIGO='V' AND MV.MPLA_CODIGO=" + numero + ";"); string txtPlanilla = ""; if (dsTiquetes.Tables[0].Rows.Count > 0) { txtPlanilla += nlchar; txtPlanilla += "TIQUETES" + nlchar; txtPlanilla += redChar + "--------" + nlchar; } double TotalPasajes = 0; double TotalPasajeros = 0; double TotalGiros = 0; double TotalIngresos = 0; double TotalEgresos = 0; double TotalPlanilla = 0; foreach (DataRow dr in dsTiquetes.Tables[0].Rows) { num = dr["NUM_DOCUMENTO"].ToString().Trim(); if (num.Length > Tiquetes.lenTiquete) { num = Convert.ToInt32(num.Substring(num.Length - Tiquetes.lenTiquete)).ToString(); } num = new string('0', Tiquetes.lenTiquete - num.Length) + num; txtPlanilla += "No. " + num + espacio + dr["DESTINO"].ToString() + nlchar; num = dr["NUMERO_PUESTOS"].ToString(); num = new string(' ', Tiquetes.lenTiquete - num.Length) + num; txtPlanilla += "Vr. " + num + espacio + dr["VALOR_PASAJE"].ToString() + nlchar; txtPlanilla += "Tot. " + new string(' ', Tiquetes.lenTiquete) + espacio + dr["VALOR_TOTAL"].ToString() + nlchar; TotalPasajes += Convert.ToDouble(dr["VALOR_TOTAL"].ToString()); TotalPasajeros += Convert.ToDouble(dr["NUMERO_PUESTOS"].ToString()); TotalIngresos += Convert.ToDouble(dr["VALOR_TOTAL"].ToString()); } txtPlanilla += "" + nlchar; txtPlanilla += "Total Pasajes: " + TotalPasajes.ToString("###,###,##0") + nlchar; //Tiquetes Prepago DataSet dsTiquetesPre = new DataSet(); DBFunctions.Request(dsTiquetesPre, IncludeSchema.NO, "Select cast(right(rtrim(char(MV.NUM_DOCUMENTO))," + AMS.Comercial.Tiquetes.lenTiquete + ") as integer) AS NUM_DOCUMENTO,PC.PCIU_NOMBRE AS DESTINO,MV.VALOR_PASAJE,MV.VALOR_TOTAL " + "FROM DBXSCHEMA.MTIQUETE_VIAJE_PREPAGO MV,DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MRUTAS MR " + "WHERE MR.MRUT_CODIGO=MV.MRUT_CODIGO AND PC.PCIU_CODIGO=MR.PCIU_CODDES AND MV.MPLA_CODIGO=" + numero + ";"); if (dsTiquetesPre.Tables[0].Rows.Count > 0) { txtPlanilla += "" + nlchar; txtPlanilla += "TIQUETES PREPAGO" + nlchar; txtPlanilla += redChar + "-------- -------" + nlchar; } foreach (DataRow dr in dsTiquetesPre.Tables[0].Rows) { num = dr["NUM_DOCUMENTO"].ToString().Trim(); if (num.Length > Tiquetes.lenTiquete) { num = Convert.ToInt32(num.Substring(num.Length - Tiquetes.lenTiquete)).ToString(); } num = new string('0', Tiquetes.lenTiquete - num.Length) + num; txtPlanilla += "No. " + num + espacio + dr["DESTINO"].ToString() + nlchar; num = new string(' ', Tiquetes.lenTiquete); txtPlanilla += "Vr. " + num + espacio + dr["VALOR_PASAJE"].ToString() + nlchar; txtPlanilla += "Tot. " + num + espacio + dr["VALOR_TOTAL"].ToString() + nlchar; TotalPasajeros += 1; } //Encomiendas DataSet dsEncomiendas = new DataSet(); DBFunctions.Request(dsEncomiendas, IncludeSchema.NO, "Select MV.NUM_DOCUMENTO,PC.PCIU_NOMBRE AS DESTINO,MV.COSTO_ENCOMIENDA,MV.VALOR_TOTAL,MV.DESCRIPCION_CONTENIDO " + "FROM DBXSCHEMA.MENCOMIENDAS MV,DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MRUTAS MR " + "WHERE MR.MRUT_CODIGO=MV.MRUT_CODIGO AND PC.PCIU_CODIGO=MR.PCIU_CODDES AND MV.MPLA_CODIGO=" + numero + ";"); if (dsEncomiendas.Tables[0].Rows.Count > 0) { txtPlanilla += "" + nlchar; txtPlanilla += "ENCOMIENDAS" + nlchar; txtPlanilla += redChar + "-----------" + nlchar; } foreach (DataRow dr in dsEncomiendas.Tables[0].Rows) { num = dr["NUM_DOCUMENTO"].ToString().Trim(); if (num.Length > Tiquetes.lenTiquete) { num = Convert.ToInt32(num.Substring(num.Length - Tiquetes.lenTiquete)).ToString(); } num = new string('0', Tiquetes.lenTiquete - num.Length) + num; txtPlanilla += "No. " + num + espacio + dr["DESTINO"].ToString() + nlchar; num = new string(' ', Tiquetes.lenTiquete); txtPlanilla += "Vr. " + num + espacio + dr["COSTO_ENCOMIENDA"].ToString() + nlchar; TotalIngresos += Convert.ToDouble(dr["COSTO_ENCOMIENDA"].ToString()); txtPlanilla += "Tot. " + num + espacio + dr["VALOR_TOTAL"].ToString() + nlchar; txtPlanilla += Tiquetes.CortarTexto(espacio + dr["DESCRIPCION_CONTENIDO"].ToString()) + nlchar; } //Giros DataSet dsGiros = new DataSet(); DBFunctions.Request(dsGiros, IncludeSchema.NO, "Select MV.NUM_DOCUMENTO,PC.PCIU_NOMBRE AS DESTINO,MV.COSTO_GIRO,MV.VALOR_GIRO " + "FROM DBXSCHEMA.MGIROS MV,DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MAGENCIA MA " + "WHERE MA.MAG_CODIGO=MV.MAG_AGENCIA_DESTINO AND PC.PCIU_CODIGO=MA.PCIU_CODIGO AND MV.MPLA_CODIGO=" + numero + ";"); if (dsGiros.Tables[0].Rows.Count > 0) { txtPlanilla += "" + nlchar; txtPlanilla += "GIROS" + nlchar; txtPlanilla += redChar + "-----" + nlchar; } foreach (DataRow dr in dsGiros.Tables[0].Rows) { num = dr["NUM_DOCUMENTO"].ToString().Trim(); if (num.Length > Tiquetes.lenTiquete) { num = Convert.ToInt32(num.Substring(num.Length - Tiquetes.lenTiquete)).ToString(); } num = new string('0', Tiquetes.lenTiquete - num.Length) + num; txtPlanilla += "No. " + num + espacio + dr["DESTINO"].ToString() + nlchar; num = new string(' ', Tiquetes.lenTiquete); txtPlanilla += "Cst. " + num + espacio + dr["COSTO_GIRO"].ToString() + nlchar; txtPlanilla += "Vr. " + num + espacio + dr["VALOR_GIRO"].ToString() + nlchar; TotalIngresos += Convert.ToDouble(dr["COSTO_GIRO"].ToString()); TotalGiros += Convert.ToDouble(dr["VALOR_GIRO"].ToString()); } //Anticipos DataSet dsAnticipos = new DataSet(); DBFunctions.Request(dsAnticipos, IncludeSchema.NO, "Select MV.NUM_DOCUMENTO,TG.NOMBRE AS CONCEPTO,IMPUTACION_CONTABLE,VALOR_TOTAL_AUTORIZADO " + "FROM DBXSCHEMA.MGASTOS_TRANSPORTES MV, DBXSCHEMA.TCONCEPTOS_TRANSPORTES TG " + "WHERE MV.TCON_CODIGO=TG.TCON_CODIGO AND MV.MPLA_CODIGO=" + numero + ";"); if (dsAnticipos.Tables[0].Rows.Count > 0) { txtPlanilla += "" + nlchar; txtPlanilla += "ANTICIPOS-OTROSINGRESOS-EGRESOS" + nlchar; txtPlanilla += redChar + "---------" + nlchar; } foreach (DataRow dr in dsAnticipos.Tables[0].Rows) { num = dr["NUM_DOCUMENTO"].ToString().Trim(); if (num.Length > Tiquetes.lenTiquete) { num = Convert.ToInt32(num.Substring(num.Length - Tiquetes.lenTiquete)).ToString(); } num = new string('0', Tiquetes.lenTiquete - num.Length) + num; txtPlanilla += "No. " + dr["CONCEPTO"].ToString() + nlchar; num = new string(' ', Tiquetes.lenTiquete); txtPlanilla += "Vr. " + num + espacio + dr["VALOR_TOTAL_AUTORIZADO"].ToString() + nlchar; if (dr["IMPUTACION_CONTABLE"].ToString() == "D") { TotalIngresos += Convert.ToDouble(dr["VALOR_TOTAL_AUTORIZADO"].ToString()); } else { TotalEgresos += Convert.ToDouble(dr["VALOR_TOTAL_AUTORIZADO"].ToString()); } } plantilla = plantilla.Replace("<CONTENIDO>", txtPlanilla); //txtPlanilla+=redChar+"INGRESOS: "+Convert.ToDouble(DBFunctions.SingleData("SELECT coalesce(VALOR_INGRESOS,0) FROM DBXSCHEMA.MPLANILLAVIAJE WHERE MPLA_CODIGO="+numero)).ToString("###,###,###")+nlchar; plantilla = plantilla.Replace("<INGRESOS>", TotalIngresos.ToString("###,###,##0")); //txtPlanilla+=redChar+"EGRESOS: "+Convert.ToDouble(DBFunctions.SingleData("SELECT coalesce(VALOR_EGRESOS,0) FROM DBXSCHEMA.MPLANILLAVIAJE WHERE MPLA_CODIGO="+numero)).ToString("###,###,###")+nlchar; plantilla = plantilla.Replace("<EGRESOS>", TotalEgresos.ToString("###,###,##0")); TotalPlanilla = TotalIngresos - TotalEgresos; plantilla = plantilla.Replace("<TOTAL_PLANILLA>", TotalPlanilla.ToString("###,###,##0")); /*txtPlanilla+=redChar+"TOTAL PASAJEROS: "+DBFunctions.SingleData("Select sum(MV.NUMERO_PUESTOS) "+ * "FROM DBXSCHEMA.MTIQUETE_VIAJE MV,DBXSCHEMA.PCIUDAD PC,DBXSCHEMA.MRUTAS MR "+ * "WHERE MR.MRUT_CODIGO=MV.MRUT_CODIGO AND PC.PCIU_CODIGO=MR.PCIU_CODDES AND MV.TEST_CODIGO='V' AND MV.MPLA_CODIGO="+numero+";")+nlchar;*/ plantilla = plantilla.Replace("<PASAJEROS>", TotalPasajeros.ToString()); plantilla = plantilla.Replace("<VALOR_GIROS>", TotalGiros.ToString("###,###,##0")); string ObservacionPlanilla = DBFunctions.SingleData("select OBSERVACION_PLANILLA from dbxschema.mplanilla_observacion where mpla_codigo=" + numero + ";"); int longitud = ObservacionPlanilla.Length; int lineas = longitud / Tiquetes.anchoTiquete; txtPlanilla = ""; int subindice = 0; for (int i = 1; i <= lineas; i++) { txtPlanilla += Tiquetes.ReemplazarTexto(ObservacionPlanilla.Substring(subindice, Tiquetes.anchoTiquete).ToString()) + nlchar; subindice += Tiquetes.anchoTiquete; } if (subindice < longitud) { txtPlanilla += Tiquetes.ReemplazarTexto(ObservacionPlanilla.Substring(subindice, longitud - subindice).ToString()) + nlchar; } plantilla = plantilla.Replace("<OBSERVACIONES>", txtPlanilla); return(plantilla); }
// Generar el tiquete a partir de la plantilla public static string GenerarTiquete(string numero, string plantilla, string nlChar, string nitResponsable, int anchoTiquete) { DataSet dsTiquete = new DataSet(); DataSet dsInfoTiquete = new DataSet(); DataSet dsViaje = new DataSet(); DataSet dsRuta = new DataSet(); DataSet dsPuestos = new DataSet(); int precio = 0; string ruta, rutaPrincipal, agencia, strPlanilla; string strNumero = numero; //if(strNumero.Length>Tiquetes.lenTiquete) // strNumero=Convert.ToInt32(strNumero.Substring(strNumero.Length-Tiquetes.lenTiquete)).ToString(); //strNumero=new string('0',Tiquetes.lenTiquete-strNumero.Length)+strNumero; //Info general DBFunctions.Request(dsInfoTiquete, IncludeSchema.NO, "select * from dbxschema.ccampos_tiquete;"); //Consultar tiquete string nitPlanillaManual = DBFunctions.SingleData("select mpas_nit from dbxschema.mpasajero where mpas_nombres='Planilla Manual';"); DBFunctions.Request(dsTiquete, IncludeSchema.NO, "SELECT MV.MPLA_CODIGO, MV.MRUT_CODIGO, MV.VALOR_PASAJE, MV.MNIT_COMPRADOR AS MNIT_COMPRADOR, " + "COALESCE(MN.MPAS_NOMBRES CONCAT ' ' CONCAT MN.MPAS_APELLIDOS, '') AS COMPRADOR, " + "COALESCE(MNV.MPAS_NOMBRES CONCAT ' ' CONCAT MNV.MPAS_APELLIDOS, '') AS VENDEDOR , MN.MPAS_TELEFONO " + "FROM DBXSCHEMA.MTIQUETE_VIAJE MV " + "LEFT JOIN DBXSCHEMA.MPASAJERO MN ON MN.MPAS_NIT=MV.MNIT_COMPRADOR " + "LEFT JOIN DBXSCHEMA.MPASAJERO MNV ON MNV.MPAS_NIT=MV.MNIT_RESPONSABLE " + "WHERE MV.TDOC_CODIGO='TIQ' AND MV.NUM_DOCUMENTO=" + numero + " AND MV.MNIT_RESPONSABLE='" + nitResponsable + "';"); if (dsTiquete.Tables[0].Rows.Count == 0) { return("NO EXISTE EL TIQUETE"); } strPlanilla = dsTiquete.Tables[0].Rows[0]["MPLA_CODIGO"].ToString(); ruta = dsTiquete.Tables[0].Rows[0]["MRUT_CODIGO"].ToString(); //Consultar ruta DBFunctions.Request(dsRuta, IncludeSchema.NO, "SELECT po.PCIU_NOMBRE AS ORIGEN, pd.PCIU_NOMBRE AS DESTINO " + "FROM DBXSCHEMA.PCIUDAD po, DBXSCHEMA.PCIUDAD pd, DBXSCHEMA.MRUTAS mr " + "WHERE po.PCIU_CODIGO=mr.PCIU_COD AND pd.PCIU_CODIGO=mr.PCIU_CODDES AND mr.MRUT_CODIGO='" + ruta + "';"); if (dsRuta.Tables[0].Rows.Count == 0) { return("NO EXISTE LA RUTA"); } //Consultar planilla, viaje DBFunctions.Request(dsViaje, IncludeSchema.NO, "SELECT coalesce(mv.MCAT_PLACA,'******') as PLACA, mn.MPAS_NOMBRES concat ' ' concat mn.MPAS_APELLIDOS AS CONDUCTOR , " + "coalesce(mb.MBUS_NUMERO,0) AS NUMERO, mp.MRUT_CODIGO AS RUTAP, mp.MAG_CODIGO as AGENCIA, mv.TPROG_TIPOPROG as PROGRAMACION, " + "mv.FECHA_SALIDA as FECHA_SALIDA, mv.HORA_SALIDA AS HORA_SALIDA, mv.mviaje_padre as viaje_padre " + "FROM DBXSCHEMA.MPLANILLAVIAJE mp " + "left join DBXSCHEMA.MVIAJE mv on mp.MRUT_CODIGO=mv.MRUT_CODIGO and mp.MVIAJE_NUMERO=mv.MVIAJE_NUMERO " + "left join DBXSCHEMA.MPASAJERO mn on mn.MPAS_NIT=mv.MNIT_CONDUCTOR " + "left join DBXSCHEMA.MBUSAFILIADO mb on mb.MCAT_PLACA=mv.MCAT_PLACA " + "WHERE mp.MPLA_CODIGO=" + strPlanilla + ";"); if (dsViaje.Tables[0].Rows.Count == 0) { return("NO EXISTE EL VIAJE"); } //Consultar puestos string strPuestos = ""; DBFunctions.Request(dsPuestos, IncludeSchema.NO, "SELECT MELE_NUMEPUES FROM DBXSCHEMA.MCONFIGURACIONPUESTO WHERE TDOC_CODIGO='TIQ' AND NUM_DOCUMENTO=" + numero + " ORDER BY MELE_NUMEPUES;"); if (dsPuestos.Tables[0].Rows.Count == 0) { return("NO HAY PUESTOS REGISTRADOS"); } //Agencia de paso? No tener en cuenta el puesto agencia = dsViaje.Tables[0].Rows[0]["AGENCIA"].ToString(); rutaPrincipal = dsViaje.Tables[0].Rows[0]["RUTAP"].ToString(); if (dsViaje.Tables[0].Rows[0]["VIAJE_PADRE"].ToString().Length == 0 && !DBFunctions.RecordExist( "select * from dbxschema.magencia ma, dbxschema.mrutas mr " + "where ma.pciu_codigo=mr.pciu_cod and mr.mrut_codigo='" + rutaPrincipal + "' and ma.mag_codigo=" + agencia)) { strPuestos = "***"; } else { for (int c = 0; c < dsPuestos.Tables[0].Rows.Count; c++) { strPuestos += dsPuestos.Tables[0].Rows[c]["MELE_NUMEPUES"].ToString() + ", "; } if (strPuestos.EndsWith(", ")) { strPuestos = strPuestos.Substring(0, strPuestos.Length - 2); } } precio = Convert.ToInt32(dsTiquete.Tables[0].Rows[0]["VALOR_PASAJE"]); /*txtTiquete+=redChar+new String('-',anchoTiquete)+nlchar; * if(dsInfoTiquete.Tables[0].Rows.Count>0){ * txtTiquete+=Tiquetes.CentrarTexto(dsInfoTiquete.Tables[0].Rows[0]["NOMBRE_EMPRESA"].ToString(),' ')+nlchar; * txtTiquete+=Tiquetes.CentrarTexto("NIT. "+dsInfoTiquete.Tables[0].Rows[0]["NIT_EMPRESA"].ToString(),' ')+nlchar; * txtTiquete+=Tiquetes.CentrarTexto(dsInfoTiquete.Tables[0].Rows[0]["TEXTO1"].ToString(),' ')+nlchar; * txtTiquete+=Tiquetes.CentrarTexto(dsInfoTiquete.Tables[0].Rows[0]["TEXTO2"].ToString(),' ')+nlchar; * txtTiquete+=Tiquetes.CentrarTexto(dsInfoTiquete.Tables[0].Rows[0]["TELEFONO_EMPRESA"].ToString(),' ')+nlchar; * txtTiquete+=Tiquetes.CentrarTexto(dsInfoTiquete.Tables[0].Rows[0]["TEXTO3"].ToString(),' ')+nlchar;} * txtTiquete+=redChar+new String('-',anchoTiquete)+nlchar; * txtTiquete+="Factura cambiaria de transporte"+nlchar;*/ //txtTiquete+="número : "+strNumero+nlchar; plantilla = plantilla.Replace("<FECHA_IMPRESION>", DateTime.Now.ToString("dd/MM/yyyy hh:mm")); plantilla = plantilla.Replace("<NUMERO>", strNumero); if (!dsTiquete.Tables[0].Rows[0]["MNIT_COMPRADOR"].ToString().Equals(nitPlanillaManual)) { plantilla = plantilla.Replace("<CLIENTE_NOMBRE>", Tiquetes.CortarTexto(dsTiquete.Tables[0].Rows[0]["COMPRADOR"].ToString(), anchoTiquete - 10)); plantilla = plantilla.Replace("<CLIENTE_NIT>", Tiquetes.CortarTexto(dsTiquete.Tables[0].Rows[0]["MNIT_COMPRADOR"].ToString(), anchoTiquete - 10)); plantilla = plantilla.Replace("<MPAS_TELEFONO>", Tiquetes.CortarTexto(dsTiquete.Tables[0].Rows[0]["MPAS_TELEFONO"].ToString(), anchoTiquete - 10)); //txtTiquete+=Tiquetes.CortarTexto("Nombre : "+Tiquetes.CortarTexto(dsTiquete.Tables[0].Rows[0]["COMPRADOR"].ToString()))+nlchar; //txtTiquete+=Tiquetes.CortarTexto(" "+Tiquetes.CortarTexto(dsTiquete.Tables[0].Rows[0]["MNIT_COMPRADOR"].ToString()))+nlchar; } else { plantilla = plantilla.Replace("<CLIENTE_NOMBRE>", ""); plantilla = plantilla.Replace("<CLIENTE_NIT>", ""); } int Minutos = Convert.ToInt16((dsViaje.Tables[0].Rows[0]["HORA_SALIDA"].ToString())); int Horas = Minutos / 60; int HoraMinuto = Minutos % 60; plantilla = plantilla.Replace("<FECHA_VIAJE>", Convert.ToDateTime(dsViaje.Tables[0].Rows[0]["FECHA_SALIDA"]).ToString("yyyy-MM-dd")); plantilla = plantilla.Replace("<HORA>", Horas.ToString()); plantilla = plantilla.Replace("<MINUTO>", HoraMinuto.ToString()); /* * if(dsViaje.Tables[0].Rows[0]["PROGRAMACION"].ToString().Length>0) * plantilla=plantilla.Replace("<FECHA_VIAJE>",DateTime.Now.ToString("dd/MM/yyyy hh:mm")); * //txtTiquete+="Fecha : "+DateTime.Now.ToString("dd/MM/yyyy hh:mm")+nlchar; * else * plantilla=plantilla.Replace("<FECHA_VIAJE>",DateTime.Now.ToString("dd/MM/yyyy")); */ //txtTiquete+="Fecha : "+DateTime.Now.ToString("dd/MM/yyyy ")+nlc har; //txtTiquete+="Bus : "+dsViaje.Tables[0].Rows[0]["NUMERO"].ToString()+" ("+dsViaje.Tables[0].Rows[0]["PLACA"].ToString()+")"+nlchar; plantilla = plantilla.Replace("<BUS_NUMERO>", dsViaje.Tables[0].Rows[0]["NUMERO"].ToString()); plantilla = plantilla.Replace("<BUS_PLACA>", dsViaje.Tables[0].Rows[0]["PLACA"].ToString()); //txtTiquete+=Tiquetes.AjustarTexto("Puesto : "+strPuestos)+nlchar; plantilla = plantilla = plantilla = plantilla.Replace("<PUESTOS>", strPuestos); //txtTiquete+="Origen : "+dsRuta.Tables[0].Rows[0]["ORIGEN"].ToString()+nlchar; plantilla = plantilla.Replace("<ORIGEN>", dsRuta.Tables[0].Rows[0]["ORIGEN"].ToString()); //txtTiquete+="Destino : "+dsRuta.Tables[0].Rows[0]["DESTINO"]+nlchar; plantilla = plantilla.Replace("<DESTINO>", dsRuta.Tables[0].Rows[0]["DESTINO"].ToString()); //txtTiquete+="Pasajes : "+dsPuestos.Tables[0].Rows.Count.ToString()+nlchar; plantilla = plantilla.Replace("<CANTIDAD>", dsPuestos.Tables[0].Rows.Count.ToString()); //txtTiquete+="Valor : "+precio.ToString("#,###")+nlchar; plantilla = plantilla.Replace("<VALOR_UNIDAD>", precio.ToString("#,###")); //txtTiquete+="Total : "+(dsPuestos.Tables[0].Rows.Count*precio).ToString("#,###")+nlchar; plantilla = plantilla.Replace("<VALOR_TOTAL>", (dsPuestos.Tables[0].Rows.Count * precio).ToString("#,###")); plantilla = plantilla.Replace("<VENDEDOR>", Tiquetes.CortarTexto(dsTiquete.Tables[0].Rows[0]["VENDEDOR"].ToString(), anchoTiquete - 10)); //txtTiquete+="Vendedor: "+Tiquetes.CortarTexto(dsTiquete.Tables[0].Rows[0]["VENDEDOR"].ToString())+nlchar; //txtTiquete+="Planilla: "+strPlanilla+nlchar+nlchar; plantilla = plantilla.Replace("<PLANILLA>", strPlanilla); return(plantilla); }