Skip to content

Instantly share code, notes, and snippets.

@birkir
Created June 21, 2011 12:50
Show Gist options
  • Save birkir/1037790 to your computer and use it in GitHub Desktop.
Save birkir/1037790 to your computer and use it in GitHub Desktop.
Okai
<?php
$gengi = array();
$xml = file_get_contents('http://vefafgreidsla.tollur.is/tollalina/gengi/Innflutningur.aspx');
$xml = new SimpleXMLElement(str_replace('xmlns="tollalinan/WS/Schema/DSGengi.xsd"', NULL, $xml));
foreach ($xml->DSGengi->MyntOgGengi as $item)
{
$gengi[strtolower($item->Mynt)] = (double) $item->Gengi;
}
$fake = isset($_GET['f']) ? intval($_GET['f']) : 0;
$base = isset($_GET['a']) ? intval($_GET['a']) : 0;
$curr = (isset($_GET['c']) AND in_array($_GET['c'], array_keys($gengi))) ? $_GET['c'] : 'isk';
echo "<form method='get'>
Upphæð: <input type='text' name='a' value='$base' /><br />
Fake upphæð: <input type='text' name='f' value='$fake' /><br />
Gjaldmiðill: <input type='text' name='c' value='$curr' /><br /><input type='submit' value='reikna' /></form>";
if ($fake > 0){
$f = $fake;
$fake = $base;
$base = $f;
}
echo "<pre>";
echo "\t\t".$base." ".strtoupper($curr)."\t\t@".$gengi[$curr]." ISK\n";
$base1 = $base*$gengi[$curr];
echo "\t\t=\t\t".isk($base1)."\n\n";
$toll1 = 0.075 * $base1;
echo "7.5%:\t\t".isk($toll1)."\t\t".isk($toll1+$base1)."\n";
$toll2 = 0.1 * ($base1 + $toll1);
echo "10%:\t\t".isk($toll2)."\t\t".isk($toll1+$toll2+$base1)."\n";
$vsk = 0.255 * ($base1 + $toll1 + $toll2);
echo "25.5%:\t\t".isk($vsk)."\t".isk($toll1+$toll2+$vsk+$base1)."\n";
echo "\t\t".isk(550)."\t\t".isk($toll1+$toll2+$vsk+$base1+550)."\n";
$total = $toll1+$toll2+$vsk+$base1+550;
if (isset($f) AND $f > 0){
echo "Rest of $fake\$ \t".isk(($fake - $f)*$gengi[$curr])."\t".isk($toll1+$toll2+$vsk+$base1+550+(($fake - $f)*$gengi[$curr]))."\n";
$total = $toll1+$toll2+$vsk+$base1+550+(($fake-$f)*$gengi[$curr]);
}
echo "\n\nTotal: ".isk($total)."</pre>";
function isk($num = 0)
{
return number_format($num, 0, '', '.').' ISK';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment