Skip to content

Commit

Permalink
Fix: test limits with vat rates of current country
Browse files Browse the repository at this point in the history
Fix: uniform code
  • Loading branch information
hregis committed Jan 8, 2012
1 parent f3e5774 commit f7c6136
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 128 deletions.
77 changes: 42 additions & 35 deletions htdocs/admin/limits.php
@@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
/* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,11 +30,11 @@
$langs->load("products");
$langs->load("admin");

if (!$user->admin)
accessforbidden();
if (! $user->admin) accessforbidden();

$action = GETPOST('action','alpha');

if (isset($_POST["action"]) && $_POST["action"] == 'update')
if ($action == 'update')
{
$error=0;
$MAXDEC=8;
Expand Down Expand Up @@ -96,9 +96,9 @@

if ($mesg) print $mesg.'<br>';

if (isset($_GET["action"]) && $_GET["action"] == 'edit')
if ($action == 'edit')
{
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';

Expand Down Expand Up @@ -167,6 +167,27 @@
print '</div>';
}

$vat_rates=array();

// TODO move to DAO class
$sql.="SELECT taux as vat_rate";
$sql.=" FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
$sql.=" WHERE t.active=1 AND t.fk_pays = p.rowid AND p.code='".$mysoc->country_code."'";
$sql.=" ORDER BY t.taux ASC";

$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
if ($num)
{
for ($i = 0; $i < $num; $i++)
{
$obj = $db->fetch_object($resql);
$vat_rates[$i] = $obj->vat_rate;
}
}
}

// Show examples
print '<b>'.$langs->trans("ExamplesWithCurrentSetup").":</b><br>\n";
Expand All @@ -178,35 +199,21 @@
print " - ".$langs->trans("VAT").": ".$vat.'%';
print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";

$s=10/3;$qty=1;$vat=0;
$tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0);
print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
print " x ".$langs->trans("Quantity").": ".$qty;
print " - ".$langs->trans("VAT").": ".$vat.'%';
print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";

$s=10/3;$qty=2;$vat=0;
$tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0);
print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
print " x ".$langs->trans("Quantity").": ".$qty;
print " - ".$langs->trans("VAT").": ".$vat.'%';
print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";

$s=10/3;$qty=1;$vat=10;
$tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0);
print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
print " x ".$langs->trans("Quantity").": ".$qty;
print " - ".$langs->trans("VAT").": ".$vat.'%';
print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
foreach($vat_rates as $vat)
{
for ($qty=1; $qty<=2; $qty++)
{
$s=10/3;
$tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0);
print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
print " x ".$langs->trans("Quantity").": ".$qty;
print " - ".$langs->trans("VAT").": ".$vat.'%';
print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
}
}

$s=10/3;$qty=2;$vat=10;
$tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0);
print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
print " x ".$langs->trans("Quantity").": ".$qty;
print " - ".$langs->trans("VAT").": ".$vat.'%';
print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
llxFooter();

$db->close();

llxFooter();
?>

0 comments on commit f7c6136

Please sign in to comment.