SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard Pedro Monteiro's Avatar
    Join Date
    Sep 2002
    Location
    Lisbon
    Posts
    1,393
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with Calculations

    I'm have having difficulty understanding why this tax simulator isn't applying the correct math to the end result.

    The objective is simple, the sale price of the item, hte comission he want's to get out of it, and the script simply performs the calculations and returns the sale price of the item with all of the TAX factors included.

    The problem is that it's just retuning the value from the first line of the code that is:
    $totalcomercialprice = ($aquisitionprice * $comission);

    It seems to ignore everything else.

    Any idea why this is happening?

    PHP Code:
    <?php 
    // do not change under mention code
    extract($_GET);
    // end of sandip code
    // Will get the total sale price with the comission but witout the taxes
    $totalcomercialprice = ($aquisitionprice $comission);
    // Getting the tax for the car Celindrada
    if ($celindrada <= 1250)  { 
     
    $totalcelindrada == ($celindrada *  1.96 1350);
    } else { 
     
    $totalcelindrada == ($celindrada *  7.16 7850);
    }
     
    // Getting the Celindrada Tax for Gasoline Cars
    if ($vgasolina <= 120)  { 
     
    $totalvgasolina = ($vgasolina 0.95);
    } elseif( 
    $vgasolina <= 121 $vgasolina >= 180 ) { 
     
    $totalvgasolina = ($vgasolina 18.50) - 2.106 ;
    } elseif (
    $vgasolina <= 181 $vgasolina >= 210) { 
     
    $totalvgasolina = ($vgasolina 53.00) - 8.316;
    } elseif (
    $vgasolina 210 ) { 
     
    $totalvgasolina = ($vgasolina 60.00 9.786);


    // Getting the Gasoleo Tax for Gasoline Cars
    if ($vgasoleo <= 100) { 
     
    $totalvgasoleo = ($vgasoleo 2.60);
    } elseif (
    $vgasoleo <= 101 $vgasoleo >= 150 )  { 
     
    $totalvgasoleo = ($vgasoleo 2700) - 2.44000;
    } elseif (
    $vgasoleo <= 151 $vgasoleo >= 180 ) { 
     
    $totalvgasoleo = ($vgasoleo 85.00) - 11.140;
    } elseif (
    $vgasoleo 180) { 
     
    $totalvgasoleo = ($vgasoleo 105.00) - 14.740;

    $impostos = ($totalvgasoleo $totalvgasolina $totalcelindrada);
    $valortotal  = ($impostos $vusadosclassicos) + $totalcomercialprice;
    // do not change under mention code
    echo $valortotal;
    exit();
    ?>

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Where is $aquisitionprice and $comission comming from? And why are you using extract($_GET);? Do you not care about security?
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Wizard Pedro Monteiro's Avatar
    Join Date
    Sep 2002
    Location
    Lisbon
    Posts
    1,393
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    logic_earth, security isn't really an issue here, as this is going to run on our local apache and it's for personal use only.

    The form:
    PHP Code:
    <form id="taxcalculation" name="form1" method="post" action="imposto-code.php" >
    <
    h1>Tax Generator</h1><h2>Dados Comerciais</h2><label>Pre&#231;o de Aquisição<br />
    <input name="aquisitionprice" id="aquisitionprice" type="text" size="12"/>

    </
    label><br /><br />Comiss&#227;o a aplicar:
    <select name="comission" id="comission" ><option value="1.5">5&#37;</option>
    <option value="1.6">6%</option>
    <
    option value="1.7">7%</option>
    <
    option value="1.8">8%</option>
    <
    option value="1.9">9%</option>
    <
    option value="1.10">10%</option>
    <
    option value="1.11">11%</option>
    <
    option value="1.12">12%</option>
    <
    option value="1.13">13%</option>
    <
    option value="1.14">14%</option>
    <
    option value="1.15">15%</option>
    <
    option value="1.16">16%</option>
    <
    option value="1.17">17%</option>
    <
    option value="1.18">18%</option>
    <
    option value="1.19">19%</option>
    <
    option value="1.20">20%</option>
    </
    select>
    </
    label>
    <
    h2>Tabela para ve&#237;culos ligeiros de passageiros e mistos</h2>Componente Cilindrada<br />
    <label>
    <
    input name="celindrada" id="celindrada" type="text" size="12" />
    </
    label>
    <
    br /><br /><h3>Componente Ambiental</h3>Ve&#237;culos a Gasolina<br />
    <input name="vgasolina" id="vgasolina" type="text" size="12" />
    <
    br /><br />Ve&#237;culos a Gasóleo<br />
    <input name="vgasoleo" id="vgasoleo" type="text" size="12" />
    <
    br />
     
    <
    br /><h2>Ve&#237;culos Usados e Clássicos</h2> 
    <p>
    <
    select name="vusadosclassicos" id="vusadosclassicos">
    <
    option value="1.10">De 6 meses a 1 ano</option>
    <
    option value="1.20">Mais de 1 a 2 anos</option>
    <
    option value="1.28">Mais de 2 a 3 anos</option>
    <
    option value="1.35">Mais de 3 a 4 anos</option>
    <
    option value="1.43">Mais de 4 a 5 anos</option>
    <
    option value="1.52">Mais de 5 a 6 anos</option>
    <
    option value="1.60">Mais de 6 a 7 anos</option>
    <
    option value="1.65">Mais de 7 a 8 anos</option>
    <
    option value="1.70">Mais de 8 a 9 anos</option>
    <
    option value="1.75">Mais de 9 a 10 anos</option>
    <
    option value="1.80">Mais de 10 anos</option>
    </
    select>
    </
    p>
    <
    label>
    <
    input type="submit" name="Submit" value="Gerar Preço de Venda" onclick="return calculation(); " />
    </
    label>
    </
    form

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    No security is always important the last thing you expect is a rouge employee but they do exist.

    change: $totalcomercialprice = ($aquisitionprice * $comission);
    to: $totalcomercialprice = ((int)$aquisitionprice * (int)$comission);

    The form sends them as strings.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,196
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    They need to be set as float not int, though php would autocast them to float before calculating the amounts. However if you cast them manually it will speed up the script.

    Do $valortotal contain the value of $totalcomercialprice? I.e. that the other variables are not set?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •