884 |
*/ |
*/ |
885 |
function select_tva($name='tauxtva', $defaulttx='', $default=0) |
function select_tva($name='tauxtva', $defaulttx='', $default=0) |
886 |
{ |
{ |
887 |
global $langs; |
global $langs,$conf; |
888 |
|
|
889 |
|
if (! $conf->global->MAIN_INFO_SOCIETE_PAYS) |
890 |
|
{ |
891 |
|
print '<font class="error">'.$langs->trans("ErrorYourCountryIsNotDefined").'</div>'; |
892 |
|
} |
893 |
|
|
894 |
$file = DOL_DOCUMENT_ROOT . "/conf/tva.local.php"; |
$sql = "SELECT t.taux,t.recuperableonly"; |
895 |
if (is_readable($file)) |
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva AS t"; |
896 |
|
$sql .= " WHERE t.fk_pays = '".$conf->global->MAIN_INFO_SOCIETE_PAYS."'"; |
897 |
|
$sql .= " AND t.active = 1"; |
898 |
|
$sql .= " ORDER BY t.taux ASC, t.recuperableonly ASC"; |
899 |
|
|
900 |
|
if ($this->db->query($sql)) |
901 |
{ |
{ |
902 |
include $file; |
$num = $this->db->num_rows(); |
903 |
|
for ($i = 0; $i < $num; $i++) |
904 |
|
{ |
905 |
|
$obj = $this->db->fetch_object(); |
906 |
|
$txtva[ $i ] = $obj->taux; |
907 |
|
$libtva[ $i ] = $obj->taux.'%'.($obj->recuperableonly ? ' *':''); |
908 |
|
} |
909 |
} |
} |
910 |
else |
else |
911 |
{ |
{ |
912 |
$txtva[0] = '19.6'; |
$txtva[0] = '19.6'; |
913 |
|
$libtva[0] = ''; |
914 |
$txtva[1] = '5.5'; |
$txtva[1] = '5.5'; |
915 |
|
$libtva[1] = ''; |
916 |
$txtva[2] = '0'; |
$txtva[2] = '0'; |
917 |
|
$libtva[2] = ''; |
918 |
} |
} |
919 |
|
|
920 |
if ($defaulttx == '') |
if ($defaulttx == '') |
921 |
{ |
{ |
922 |
$defaulttx = $txtva[0]; |
$defaulttx = $txtva[0]; |
923 |
} |
} |
924 |
|
|
925 |
$taille = sizeof($txtva); |
$taille = sizeof($txtva); |
926 |
|
|
927 |
print '<select class="flat" name="'.$name.'">'; |
print '<select class="flat" name="'.$name.'">'; |
928 |
if ($default) print '<option value="0">'.$langs->trans("Default").'</option>'; |
if ($default) print '<option value="0">'.$langs->trans("Default").'</option>'; |
929 |
|
|
930 |
for ($i = 0 ; $i < $taille ; $i++) |
for ($i = 0 ; $i < $taille ; $i++) |
931 |
{ |
{ |
932 |
print '<option value="'.$txtva[$i].'"'; |
print '<option value="'.$txtva[$i].'"'; |
933 |
if ($txtva[$i] == $defaulttx) |
if ($txtva[$i] == $defaulttx) |
934 |
{ |
{ |
935 |
print ' selected>'.$txtva[$i].'%</option>'; |
print ' selected>'.$libtva[$i].'</option>'; |
936 |
} |
} |
937 |
else |
else |
938 |
{ |
{ |
939 |
print '>'.$txtva[$i].'%</option>'; |
print '>'.$libtva[$i].'</option>'; |
940 |
} |
} |
941 |
} |
} |
942 |
print '</select>'; |
print '</select>'; |