Advertisement
JoaquinFioriti

Untitled

Nov 26th, 2021 (edited)
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1.     /**
  2.      * PRE: numeroDeFactura y fechaDeSolicitud deben ser distintos de null
  3.      * El formato de la fecha ya esta validado
  4.      * Numero de factura es > 0
  5.      * <p>
  6.      * POST: El metodo retorna un importe adicional a la factura emitida, dependiendo del total facturado, de la fecha de solicitud, de la fecha de facturación, de la lista de insumos
  7.      *
  8.      * @param numeroDeFactura
  9.      * @param fechaDeSolicitud
  10.      * @param listaDeInsumos
  11.      * @return
  12.      */
  13.     public double calculoImporteAdicionales(int numeroDeFactura, GregorianCalendar fechaDeSolicitud, ArrayList<Double> listaDeInsumos) {
  14.  
  15.         Factura factura = null;
  16.         double importeParcial = 0;
  17.         double importeTotal = 0;
  18.         double respuesta = 0;
  19.         int aleatorio = Util.createRandom();
  20.         System.out.println(aleatorio);
  21.         //busco la factura
  22.         for (Factura facturaact : this.facturas) {
  23.             if (facturaact.getNroFactura() == numeroDeFactura) {            
  24.                 factura = facturaact;
  25.             }
  26.         }
  27.  
  28.         if (factura != null) {
  29.             if (Math.abs(factura.getFecha().get(Calendar.DAY_OF_YEAR) - fechaDeSolicitud.get(Calendar.DAY_OF_YEAR)) < 10) {
  30.                 importeParcial = factura.getImporteTotal() - (factura.getSubTotalImpar() * 0.7);
  31.             } else
  32.                 importeParcial = factura.getImporteTotal() * 0.3;            
  33.             if (factura.getPaciente().getRangoEtario().equalsIgnoreCase("mayor")) {
  34.                 importeTotal = importeParcial * 1.4;                
  35.             } else
  36.                 importeTotal = importeParcial * 0.85;
  37.             if (aleatorio == factura.getFecha().get(Calendar.DAY_OF_MONTH)) {              
  38.                 respuesta = importeTotal;
  39.             } else {
  40.                 double sumavalores = 0;
  41.                 if (listaDeInsumos!=null) {
  42.                     for (Double valor : listaDeInsumos)
  43.                         sumavalores += valor;
  44.                 }                
  45.                 respuesta = importeTotal + sumavalores;
  46.             }
  47.         }
  48.         return respuesta;
  49.     }
  50.  
  51. //En la clase Utils:
  52. public static int createRandom(){
  53.         Random r = new Random();
  54.         return r.nextInt(31)+1;
  55.     }
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement