betoesquivel

Impuestos php

Mar 27th, 2015
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2.     $edo=$_GET['edo'];
  3.     $nhijos=$_GET['nhijos'];
  4.     $salario=$_GET['salario'];
  5.  
  6.     if($edo=='casado') {
  7.     $npartes=2+$nhijos/2;
  8.     } else {
  9.     $npartes=1+$nhijos/2;
  10.     }
  11.  
  12.     if($nhijos>2){
  13.     $npartes+=0.5;
  14.     }
  15.  
  16.     $grabable=$salario*0.72;
  17.     $cociente=$grabable/$npartes;
  18.  
  19.     try {
  20.         $DBH = new PDO("mysql:host=127.0.0.1;dbname=impuestos", "root","");
  21.     } catch (PDOException $e) {
  22.  
  23.     echo $e->getMessage();
  24.     exit();
  25.     }
  26.  
  27.     $tasa=0;
  28.     $deduccion=0;
  29.  
  30.     $query="SELECT * FROM tabla";
  31.     $result=$DBH->query($query);
  32.  
  33.     while($row=$result->fetch(PDO::FETCH_ASSOC)) {
  34.     $tasa1=$row['tasa'];
  35.     $deduccion1=$row['deduccion'];
  36.     $cociente1=$row['cociente'];
  37.  
  38.     if($cociente1 > $cociente) {
  39.     break;
  40.     }
  41.  
  42.     $tasa=$tasa1;
  43.     $deduccion=$deduccion1;
  44.     }
  45.  
  46.     $impuesto=($grabable*$tasa)-($npartes*$deduccion);
  47.  
  48.     echo $impuesto;
  49.  
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment