Guest User

Untitled

a guest
Apr 27th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. class Alquiler < ActiveRecord::Base
  2.  
  3. def self.nuevo_alquiler
  4. @alquiler = new
  5.  
  6. puts "Titulo de la película: "
  7.  
  8. @alquiler.pelicula = gets.chomp
  9.  
  10. puts "Nombre del cliente: "
  11.  
  12. @alquiler.cliente = gets.chomp
  13.  
  14. puts "Precio del alquiler: "
  15.  
  16. @alquiler.precio = gets.chomp
  17.  
  18. puts "Direccion de envio: "
  19.  
  20. @alquiler.direccion = gets.chomp
  21. @alquiler.estado = "pedido"
  22. @alquiler.save
  23.  
  24. end
  25.  
  26. def self.listar_alquileres
  27. puts "\nNumero\tPelicula\tCliente\tDireccion\tPrecio\tEstado\n"
  28. Alquiler.find(:all).each do |alquiler|
  29. alquiler.imprimirme
  30. end
  31. end
  32.  
  33. def self.cambiar_estado
  34. listar_alquileres
  35. puts "Numero de alquiler a modificar: "
  36. numero = gets.chomp
  37. @alquiler = Alquiler.find(numero)
  38. @alquiler.imprimirme
  39. puts "Nuevo estado del alquiler: "
  40. estado = gets.chomp
  41. @alquiler.estado = estado
  42. @alquiler.save
  43. end
  44.  
  45. def self.reporte_para_el_jefe
  46. precio_devueltos = 0
  47. precio_entregados = 0
  48. precio_total = 0
  49. puts "---------------------------------------"
  50.  
  51. puts " REPORTE PARA EL JEFE "
  52.  
  53. puts "---------------------------------------"
  54.  
  55. puts "\nNumero\tPelicula\tCliente\tDireccion\tPrecio\tEstado\n"
  56.  
  57. puts "---------------------------------------"
  58.  
  59. alquileres = Alquiler.find(:all)
  60.  
  61. alquileres.each do |alquiler|
  62. if alquiler.estado == "devuelto"
  63.  
  64. precio_devueltos += alquiler.precio
  65.  
  66. end
  67.  
  68. if alquiler.estado.chomp=="entregado"
  69.  
  70. precio_entregados += alquiler.precio
  71.  
  72. end
  73. precio_total += alquiler.precio
  74.  
  75. alquiler.imprimirme
  76. end
  77.  
  78. porcentaje_devuelto = (precio_devueltos.to_f/precio_total.to_f * 100).to_i
  79.  
  80. porcentaje_entregados = (precio_entregados.to_f/precio_total.to_f * 100).to_i
  81.  
  82. puts "---------------------------------------"
  83.  
  84. puts "TOTAL COBRADO:" + precio_devueltos.to_s + "$" + " --- " + porcentaje_devuelto.to_s + " %"
  85.  
  86. puts "PARA COBRAR:" + precio_entregados.to_s + "$" + " --- " + porcentaje_entregados.to_s + " %"
  87.  
  88. puts "CANTIDAD DE PELICULAS ALQUILADAS:" + alquileres.size.to_s
  89.  
  90. puts "---------------------------------------"
  91.  
  92. end
  93.  
  94. def self.reporte_para_delivery
  95.  
  96. puts "---------------------------------------"
  97.  
  98. puts " REPORTE PARA EL DELIVERY "
  99.  
  100. puts "---------------------------------------"
  101. puts "\nNumero\tPelicula\tCliente\tDireccion\tPrecio\tEstado\n"
  102.  
  103. puts "---------------------------------------"
  104.  
  105. alquileres_pedidos = Alquiler.find(:all,:conditions => {:estado => "pedido"})
  106. alquileres_pedidos.each do |alquiler|
  107. alquiler.imprimirme
  108. end
  109.  
  110. puts "---------------------------------------"
  111.  
  112. puts "CANTIDAD DE PELICULAS SIN ENVIAR:" + alquileres_pedidos.size.to_s
  113.  
  114. puts "---------------------------------------"
  115.  
  116. end
  117.  
  118.  
  119.  
  120. def imprimirme
  121. puts "\n#{self.id}\t" +
  122. "#{self.pelicula}\t" +
  123. "#{self.cliente}\t" +
  124. "#{self.direccion}\t" +
  125. "#{self.precio}\t" +
  126. "#{self.estado}\n"
  127. end
  128.  
  129. end
Add Comment
Please, Sign In to add comment