2
0
forked from Wavyzz/dolibarr

Merge branch '18a3' of github.com:aspangaro/dolibarr into aspangaro-18a3

This commit is contained in:
Laurent Destailleur
2024-01-11 11:39:58 +01:00
9 changed files with 417 additions and 55 deletions

View File

@@ -214,7 +214,7 @@ $tabsql[6] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.t
$tabsql[7] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.accountancy_code as accountancy_code, c.code as country_code, c.label as country, a.fk_pays as country_id, a.active FROM ".MAIN_DB_PREFIX."c_chargesociales AS a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_pays = c.rowid and c.active = 1";
$tabsql[8] = "SELECT t.id as rowid, t.code as code, t.libelle, t.fk_country as country_id, c.code as country_code, c.label as country, t.position, t.active FROM ".MAIN_DB_PREFIX."c_typent as t LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON t.fk_country=c.rowid";
$tabsql[9] = "SELECT c.code_iso as code, c.label, c.unicode, c.active FROM ".MAIN_DB_PREFIX."c_currencies AS c";
$tabsql[10] = "SELECT t.rowid, t.entity, t.code, t.taux, t.localtax1_type, t.localtax1, t.localtax2_type, t.localtax2, c.label as country, c.code as country_code, t.fk_pays as country_id, t.recuperableonly, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays = c.rowid AND t.entity = ".getEntity($tabname[10]);
$tabsql[10] = "SELECT t.rowid, t.entity, t.type_vat, t.code, t.taux, t.localtax1_type, t.localtax1, t.localtax2_type, t.localtax2, c.label as country, c.code as country_code, t.fk_pays as country_id, t.recuperableonly, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays = c.rowid AND t.entity = ".getEntity($tabname[10]);
$tabsql[11] = "SELECT t.rowid as rowid, t.element, t.source, t.code, t.libelle, t.position, t.active FROM ".MAIN_DB_PREFIX."c_type_contact AS t";
$tabsql[12] = "SELECT c.rowid as rowid, c.code, c.libelle, c.libelle_facture, c.deposit_percent, c.nbjour, c.type_cdr, c.decalage, c.active, c.sortorder, c.entity FROM ".MAIN_DB_PREFIX."c_payment_term AS c WHERE c.entity IN (".getEntity($tabname[12]).")";
$tabsql[13] = "SELECT c.id as rowid, c.code, c.libelle, c.type, c.active, c.entity FROM ".MAIN_DB_PREFIX."c_paiement AS c WHERE c.entity IN (".getEntity($tabname[13]).")";
@@ -308,7 +308,7 @@ $tabfield[6] = "code,libelle,type,color,position";
$tabfield[7] = "code,libelle,country,accountancy_code";
$tabfield[8] = "code,libelle,country_id,country".(getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? ',position' : '');
$tabfield[9] = "code,label,unicode";
$tabfield[10] = "country_id,country,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
$tabfield[10] = "country_id,country,type_vat,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
$tabfield[11] = "element,source,code,libelle,position";
$tabfield[12] = "code,libelle,libelle_facture,deposit_percent,nbjour,type_cdr,decalage,sortorder";
$tabfield[13] = "code,libelle,type";
@@ -355,7 +355,7 @@ $tabfieldvalue[6] = "code,libelle,type,color,position";
$tabfieldvalue[7] = "code,libelle,country,accountancy_code";
$tabfieldvalue[8] = "code,libelle,country".(getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? ',position' : '');
$tabfieldvalue[9] = "code,label,unicode";
$tabfieldvalue[10] = "country,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
$tabfieldvalue[10] = "country,type_vat,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
$tabfieldvalue[11] = "element,source,code,libelle,position";
$tabfieldvalue[12] = "code,libelle,libelle_facture,deposit_percent,nbjour,type_cdr,decalage,sortorder";
$tabfieldvalue[13] = "code,libelle,type";
@@ -402,7 +402,7 @@ $tabfieldinsert[6] = "code,libelle,type,color,position";
$tabfieldinsert[7] = "code,libelle,fk_pays,accountancy_code";
$tabfieldinsert[8] = "code,libelle,fk_country".(getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? ',position' : '');
$tabfieldinsert[9] = "code_iso,label,unicode";
$tabfieldinsert[10] = "fk_pays,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note,entity";
$tabfieldinsert[10] = "fk_pays,type_vat,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note,entity";
$tabfieldinsert[11] = "element,source,code,libelle,position";
$tabfieldinsert[12] = "code,libelle,libelle_facture,deposit_percent,nbjour,type_cdr,decalage,sortorder,entity";
$tabfieldinsert[13] = "code,libelle,type,entity";
@@ -675,6 +675,13 @@ if ($id == 11) {
);
}
// Define type_vatList (used for dictionary "llx_c_tva")
$type_vatList = array(
"0" => $langs->trans("All"),
"1" => $langs->trans("Sell"),
"2" => $langs->trans("Buy")
);
// Define localtax_typeList (used for dictionary "llx_c_tva")
$localtax_typeList = array(
"0" => $langs->trans("No"),
@@ -1346,6 +1353,325 @@ if ($id > 0) {
print "<br>\n";
}
// Form to add a new line
if ($tabname[$id]) {
$withentity = null;
$fieldlist = explode(',', $tabfield[$id]);
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
// Line for title
print '<!-- line title to add new entry -->';
$tdsoffields = '<tr class="liste_titre">';
foreach ($fieldlist as $field => $value) {
if ($value == 'entity') {
$withentity = getEntity($tabname[$id]);
continue;
}
// Define field friendly name from its technical name
$valuetoshow = ucfirst($value); // Par defaut
$valuetoshow = $langs->trans($valuetoshow); // try to translate
$class = '';
if ($value == 'pos') {
$valuetoshow = $langs->trans("Position"); $class = 'right';
}
if ($value == 'source') {
$valuetoshow = $langs->trans("Contact");
}
if ($value == 'price') {
$valuetoshow = $langs->trans("PriceUHT");
}
if ($value == 'taux') {
if ($tabname[$id] != "c_revenuestamp") {
$valuetoshow = $langs->trans("Rate");
} else {
$valuetoshow = $langs->trans("Amount");
}
$class = 'center';
}
if ($value == 'type_vat') {
$valuetoshow = $langs->trans("VATType"); $class = "center"; $sortable = 0;
}
if ($value == 'localtax1_type') {
$valuetoshow = $langs->trans("UseLocalTax")." 2"; $class = "center"; $sortable = 0;
}
if ($value == 'localtax1') {
$valuetoshow = $langs->trans("RateOfTaxN", '2'); $class = "center";
}
if ($value == 'localtax2_type') {
$valuetoshow = $langs->trans("UseLocalTax")." 3"; $class = "center"; $sortable = 0;
}
if ($value == 'localtax2') {
$valuetoshow = $langs->trans("RateOfTaxN", '3'); $class = "center";
}
if ($value == 'organization') {
$valuetoshow = $langs->trans("Organization");
}
if ($value == 'lang') {
$valuetoshow = $langs->trans("Language");
}
if ($value == 'type') {
if ($tabname[$id] == "c_paiement") {
$valuetoshow = $form->textwithtooltip($langs->trans("Type"), $langs->trans("TypePaymentDesc"), 2, 1, img_help(1, ''));
} else {
$valuetoshow = $langs->trans("Type");
}
}
if ($value == 'code') {
$valuetoshow = $langs->trans("Code"); $class = 'maxwidth100';
}
if ($value == 'libelle' || $value == 'label') {
$valuetoshow = $form->textwithtooltip($langs->trans("Label"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
}
if ($value == 'libelle_facture') {
$valuetoshow = $form->textwithtooltip($langs->trans("LabelOnDocuments"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
}
if ($value == 'deposit_percent') {
$valuetoshow = $langs->trans('DepositPercent');
$class = 'right';
}
if ($value == 'country') {
if (in_array('region_id', $fieldlist)) {
print '<td>&nbsp;</td>'; continue;
} // For region page, we do not show the country input
$valuetoshow = $langs->trans("Country");
}
if ($value == 'recuperableonly') {
$valuetoshow = $langs->trans("NPR"); $class = "center";
}
if ($value == 'nbjour') {
$valuetoshow = $langs->trans("NbOfDays");
$class = 'right';
}
if ($value == 'type_cdr') {
$valuetoshow = $langs->trans("AtEndOfMonth"); $class = "center";
}
if ($value == 'decalage') {
$valuetoshow = $langs->trans("Offset");
$class = 'right';
}
if ($value == 'width' || $value == 'nx') {
$valuetoshow = $langs->trans("Width");
}
if ($value == 'height' || $value == 'ny') {
$valuetoshow = $langs->trans("Height");
}
if ($value == 'unit' || $value == 'metric') {
$valuetoshow = $langs->trans("MeasuringUnit");
}
if ($value == 'region_id' || $value == 'country_id') {
$valuetoshow = '';
}
if ($value == 'accountancy_code') {
$valuetoshow = $langs->trans("AccountancyCode");
}
if ($value == 'accountancy_code_sell') {
$valuetoshow = $langs->trans("AccountancyCodeSell");
}
if ($value == 'accountancy_code_buy') {
$valuetoshow = $langs->trans("AccountancyCodeBuy");
}
if ($value == 'pcg_version' || $value == 'fk_pcg_version') {
$valuetoshow = $langs->trans("Pcg_version");
}
if ($value == 'account_parent') {
$valuetoshow = $langs->trans("Accountparent");
}
if ($value == 'pcg_type') {
$valuetoshow = $langs->trans("Pcg_type");
}
if ($value == 'pcg_subtype') {
$valuetoshow = $langs->trans("Pcg_subtype");
}
if ($value == 'sortorder') {
$valuetoshow = $langs->trans("SortOrder");
$class = 'center';
}
if ($value == 'short_label') {
$valuetoshow = $langs->trans("ShortLabel");
}
if ($value == 'fk_parent') {
$valuetoshow = $langs->trans("ParentID"); $class = 'center';
}
if ($value == 'range_account') {
$valuetoshow = $langs->trans("Range");
}
if ($value == 'sens') {
$valuetoshow = $langs->trans("Sens");
}
if ($value == 'category_type') {
$valuetoshow = $langs->trans("Calculated");
}
if ($value == 'formula') {
$valuetoshow = $langs->trans("Formula");
}
if ($value == 'paper_size') {
$valuetoshow = $langs->trans("PaperSize");
}
if ($value == 'orientation') {
$valuetoshow = $langs->trans("Orientation");
}
if ($value == 'leftmargin') {
$valuetoshow = $langs->trans("LeftMargin");
}
if ($value == 'topmargin') {
$valuetoshow = $langs->trans("TopMargin");
}
if ($value == 'spacex') {
$valuetoshow = $langs->trans("SpaceX");
}
if ($value == 'spacey') {
$valuetoshow = $langs->trans("SpaceY");
}
if ($value == 'font_size') {
$valuetoshow = $langs->trans("FontSize");
}
if ($value == 'custom_x') {
$valuetoshow = $langs->trans("CustomX");
}
if ($value == 'custom_y') {
$valuetoshow = $langs->trans("CustomY");
}
if ($value == 'percent') {
$valuetoshow = $langs->trans("Percentage");
}
if ($value == 'affect') {
$valuetoshow = $langs->trans("WithCounter");
}
if ($value == 'delay') {
$valuetoshow = $langs->trans("NoticePeriod");
}
if ($value == 'newbymonth') {
$valuetoshow = $langs->trans("NewByMonth");
}
if ($value == 'fk_tva') {
$valuetoshow = $langs->trans("VAT");
}
if ($value == 'range_ik') {
$valuetoshow = $langs->trans("RangeIk");
}
if ($value == 'fk_c_exp_tax_cat') {
$valuetoshow = $langs->trans("CarCategory");
}
if ($value == 'revenuestamp_type') {
$valuetoshow = $langs->trans('TypeOfRevenueStamp');
}
if ($value == 'use_default') {
$valuetoshow = $langs->trans('Default'); $class = 'center';
}
if ($value == 'unit_type') {
$valuetoshow = $langs->trans('TypeOfUnit');
}
if ($value == 'public' && $tablib[$id] == 'TicketDictCategory') {
$valuetoshow = $langs->trans('TicketGroupIsPublic'); $class = 'center';
}
if ($value == 'block_if_negative') {
$valuetoshow = $langs->trans('BlockHolidayIfNegative');
}
if ($value == 'type_duration') {
$valuetoshow = $langs->trans('Unit');
}
if ($id == 2) { // Special case for state page
if ($value == 'region_id') {
$valuetoshow = '&nbsp;'; $showfield = 1;
}
if ($value == 'region') {
$valuetoshow = $langs->trans("Country").'/'.$langs->trans("Region"); $showfield = 1;
}
}
if ($valuetoshow != '') {
$tooltiphelp = (isset($tabcomplete[$tabname[$id]]['help'][$value]) ? $tabcomplete[$tabname[$id]]['help'][$value] : '');
$tdsoffields .= '<th'.($class ? ' class="'.$class.'"' : '').'>';
if ($tooltiphelp && preg_match('/^http(s*):/i', $tooltiphelp)) {
$tdsoffields .= '<a href="'.$tooltiphelp.'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
} elseif ($tooltiphelp) {
$tdsoffields .= $form->textwithpicto($valuetoshow, $tooltiphelp);
} else {
$tdsoffields .= $valuetoshow;
}
$tdsoffields .= '</th>';
}
}
if ($id == 4) {
$tdsoffields .= '<th></th>';
$tdsoffields .= '<th></th>';
}
$tdsoffields .= '<th>';
$tdsoffields .= '<input type="hidden" name="id" value="'.$id.'">';
if (!is_null($withentity)) {
$tdsoffields .= '<input type="hidden" name="entity" value="'.$withentity.'">';
}
$tdsoffields .= '</th>';
$tdsoffields .= '<th style="min-width: 26px;"></th>';
$tdsoffields .= '<th style="min-width: 26px;"></th>';
$tdsoffields .= '</tr>';
print $tdsoffields;
// Line to enter new values
print '<!-- line input to add new entry -->';
print '<tr class="oddeven nodrag nodrop nohover">';
$obj = new stdClass();
// If data was already input, we define them in obj to populate input fields.
if (GETPOST('actionadd')) {
foreach ($fieldlist as $key => $val) {
if (GETPOST($val) != '') {
$obj->$val = GETPOST($val);
}
}
}
$tmpaction = 'create';
$parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
$reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
$error = $hookmanager->error; $errors = $hookmanager->errors;
if ($id == 3) {
unset($fieldlist[2]); // Remove field ??? if dictionary Regions
}
if (empty($reshook)) {
fieldList($fieldlist, $obj, $tabname[$id], 'add');
}
if ($id == 4) {
print '<td></td>';
print '<td></td>';
}
print '<td colspan="3" class="center">';
if ($action != 'edit') {
print '<input type="submit" class="button button-add small" name="actionadd" value="'.$langs->trans("Add").'">';
} else {
print '<input type="submit" class="button button-add small disabled" name="actionadd" value="'.$langs->trans("Add").'">';
}
print '</td>';
print "</tr>";
print '</table>';
print '</div>';
}
print '</form>';
print '<br>';
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
// List of available record in database
dol_syslog("htdocs/admin/dict", LOG_DEBUG);
@@ -1837,6 +2163,9 @@ if ($id > 0) {
$cssprefix = 'center ';
}
if ($value == 'type_vat') {
$valuetoshow = $langs->trans("VATType"); $cssprefix = "center "; $sortable = 0;
}
if ($value == 'localtax1_type') {
$valuetoshow = $langs->trans("UseLocalTax")." 2";
$cssprefix = "center ";
@@ -2301,6 +2630,13 @@ if ($id > 0) {
$valuetoshow = ($obj->code && $key != 'SizeUnit'.strtolower($obj->unit) ? $key : $obj->$value);
} elseif ($value == 'localtax1' || $value == 'localtax2') {
$class = "center";
} elseif ($value == 'type_vat') {
if ($obj->type_vat != 0) {
$valuetoshow = $type_vatList[$valuetoshow];
} else {
$valuetoshow = $langs->transnoentitiesnoconv("All");
}
$class = "center";
} elseif ($value == 'localtax1_type') {
if ($obj->localtax1 != 0) {
$valuetoshow = $localtax_typeList[$valuetoshow];
@@ -2371,7 +2707,7 @@ if ($id > 0) {
if (in_array($value, array('nbjour', 'decalage', 'pos', 'position', 'deposit_percent'))) {
$class .= ' right';
}
if (in_array($value, array('localtax1_type', 'localtax2_type'))) {
if (in_array($value, array('type_vat', 'localtax1_type', 'localtax2_type'))) {
$class .= ' nowraponall';
}
if (in_array($value, array('use_default', 'fk_parent', 'sortorder'))) {
@@ -2545,7 +2881,7 @@ function fieldList($fieldlist, $obj = null, $tabname = '', $context = '')
global $conf, $langs, $db, $mysoc;
global $form;
global $region_id;
global $elementList, $sourceList, $localtax_typeList;
global $elementList, $sourceList, $localtax_typeList, $type_vatList;
$formadmin = new FormAdmin($db);
$formcompany = new FormCompany($db);
@@ -2684,6 +3020,11 @@ function fieldList($fieldlist, $obj = null, $tabname = '', $context = '')
);
print $form->selectarray('unit', $units, (!empty($obj->{$value}) ? $obj->{$value} : ''), 0, 0, 0);
print '</td>';
} elseif ($value == 'type_vat') {
// VAT type 0: all, 1: sell, 2: purchase
print '<td class="center">';
print $form->selectarray($value, $type_vatList, (!empty($obj->{$value}) ? $obj->{$value}:''));
print '</td>';
} elseif ($value == 'localtax1_type' || $value == 'localtax2_type') {
// Le type de taxe locale
print '<td class="center">';

View File

@@ -6374,10 +6374,11 @@ class Form
/**
* Load into the cache vat rates of a country
*
* @param string $country_code Country code with quotes ("'CA'", or "'CA,IN,...'")
* @return int Nb of loaded lines, 0 if already loaded, <0 if KO
* @param string $country_code Country code with quotes ("'CA'", or "'CA,IN,...'")
* @param int $type_vat 0=All type, 1=VAT rate sale, 2=VAT rate purchase
* @return int Nb of loaded lines, 0 if already loaded, <0 if KO
*/
public function load_cache_vatrates($country_code)
public function load_cache_vatrates($country_code, $type_vat = 0)
{
// phpcs:enable
global $langs, $user;
@@ -6389,10 +6390,13 @@ class Form
dol_syslog(__METHOD__, LOG_DEBUG);
$sql = "SELECT DISTINCT t.rowid, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
$sql .= " FROM " . $this->db->prefix() . "c_tva as t, " . $this->db->prefix() . "c_country as c";
$sql = "SELECT DISTINCT t.rowid, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
$sql .= " FROM ".$this->db->prefix()."c_tva as t, ".$this->db->prefix()."c_country as c";
$sql .= " WHERE t.fk_pays = c.rowid";
$sql .= " AND t.active > 0";
if ($type_vat > 0) {
$sql .= " AND t.type_vat IN (0, ".((int) $type_vat).")";
}
$sql .= " AND t.entity IN (".getEntity('c_tva').")";
$sql .= " AND c.code IN (" . $this->db->sanitize($country_code, 1) . ")";
$sql .= " ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
@@ -6403,17 +6407,18 @@ class Form
if ($num) {
for ($i = 0; $i < $num; $i++) {
$obj = $this->db->fetch_object($resql);
$this->cache_vatrates[$i]['rowid'] = $obj->rowid;
$this->cache_vatrates[$i]['code'] = $obj->code;
$this->cache_vatrates[$i]['txtva'] = $obj->taux;
$this->cache_vatrates[$i]['nprtva'] = $obj->recuperableonly;
$this->cache_vatrates[$i]['localtax1'] = $obj->localtax1;
$this->cache_vatrates[$i]['localtax1_type'] = $obj->localtax1_type;
$this->cache_vatrates[$i]['localtax2'] = $obj->localtax2;
$this->cache_vatrates[$i]['localtax2_type'] = $obj->localtax1_type;
$this->cache_vatrates[$i]['label'] = $obj->taux . '%' . ($obj->code ? ' (' . $obj->code . ')' : ''); // Label must contains only 0-9 , . % or *
$this->cache_vatrates[$i]['labelallrates'] = $obj->taux . '/' . ($obj->localtax1 ? $obj->localtax1 : '0') . '/' . ($obj->localtax2 ? $obj->localtax2 : '0') . ($obj->code ? ' (' . $obj->code . ')' : ''); // Must never be used as key, only label
$this->cache_vatrates[$i]['rowid'] = $obj->rowid;
$this->cache_vatrates[$i]['type_vat'] = $obj->type_vat;
$this->cache_vatrates[$i]['code'] = $obj->code;
$this->cache_vatrates[$i]['txtva'] = $obj->taux;
$this->cache_vatrates[$i]['nprtva'] = $obj->recuperableonly;
$this->cache_vatrates[$i]['localtax1'] = $obj->localtax1;
$this->cache_vatrates[$i]['localtax1_type'] = $obj->localtax1_type;
$this->cache_vatrates[$i]['localtax2'] = $obj->localtax2;
$this->cache_vatrates[$i]['localtax2_type'] = $obj->localtax1_type;
$this->cache_vatrates[$i]['label'] = $obj->taux . '%' . ($obj->code ? ' (' . $obj->code . ')' : ''); // Label must contains only 0-9 , . % or *
$this->cache_vatrates[$i]['labelallrates'] = $obj->taux . '/' . ($obj->localtax1 ? $obj->localtax1 : '0') . '/' . ($obj->localtax2 ? $obj->localtax2 : '0') . ($obj->code ? ' (' . $obj->code . ')' : ''); // Must never be used as key, only label
$positiverates = '';
if ($obj->taux) {
$positiverates .= ($positiverates ? '/' : '') . $obj->taux;
@@ -6456,24 +6461,25 @@ class Form
* Output an HTML select vat rate.
* The name of this function should be selectVat. We keep bad name for compatibility purpose.
*
* @param string $htmlname Name of HTML select field
* @param float|string $selectedrate Force preselected vat rate. Can be '8.5' or '8.5 (NOO)' for example. Use '' for no forcing.
* @param Societe $societe_vendeuse Thirdparty seller
* @param Societe $societe_acheteuse Thirdparty buyer
* @param int $idprod Id product. O if unknown of NA.
* @param int $info_bits Miscellaneous information on line (1 for NPR)
* @param int|string $type ''=Unknown, 0=Product, 1=Service (Used if idprod not defined)
* @param string $htmlname Name of HTML select field
* @param float|string $selectedrate Force preselected vat rate. Can be '8.5' or '8.5 (NOO)' for example. Use '' for no forcing.
* @param Societe $societe_vendeuse Thirdparty seller
* @param Societe $societe_acheteuse Thirdparty buyer
* @param int $idprod Id product. O if unknown of NA.
* @param int $info_bits Miscellaneous information on line (1 for NPR)
* @param int|string $type ''=Unknown, 0=Product, 1=Service (Used if idprod not defined)
* If seller not subject to VAT, default VAT=0. End of rule.
* If (seller country==buyer country), then default VAT=product's VAT. End of rule.
* If (seller and buyer in EU) and sold product = new means of transportation (car, boat, airplane), default VAT =0 (VAT must be paid by the buyer to his country's tax office and not the seller). End of rule.
* If (seller and buyer in EU) and buyer=private person, then default VAT=VAT of sold product. End of rule.
* If (seller and buyer in EU) and buyer=company then default VAT =0. End of rule.
* Else, default proposed VAT==0. End of rule.
* @param bool $options_only Return HTML options lines only (for ajax treatment)
* @param int $mode 0=Use vat rate as key in combo list, 1=Add VAT code after vat rate into key, -1=Use id of vat line as key
* @return string
* @param bool $options_only Return HTML options lines only (for ajax treatment)
* @param int $mode 0=Use vat rate as key in combo list, 1=Add VAT code after vat rate into key, -1=Use id of vat line as key
* @param int $type_vat 0=All type, 1=VAT rate sale, 2=VAT rate purchase
* @return string
*/
public function load_tva($htmlname = 'tauxtva', $selectedrate = '', $societe_vendeuse = null, $societe_acheteuse = null, $idprod = 0, $info_bits = 0, $type = '', $options_only = false, $mode = 0)
public function load_tva($htmlname = 'tauxtva', $selectedrate = '', $societe_vendeuse = null, $societe_acheteuse = null, $idprod = 0, $info_bits = 0, $type = '', $options_only = false, $mode = 0, $type_vat = 0)
{
// phpcs:enable
global $langs, $conf, $mysoc;
@@ -6536,7 +6542,7 @@ class Form
}
// Now we get list
$num = $this->load_cache_vatrates($code_country); // If no vat defined, return -1 with message into this->error
$num = $this->load_cache_vatrates($code_country, $type_vat); // If no vat defined, return -1 with message into this->error
if ($num > 0) {
// Definition du taux a pre-selectionner (si defaulttx non force et donc vaut -1 ou '')

View File

@@ -442,10 +442,15 @@ if ($nolinesbefore) {
}
print '<td class="nobottom linecolvat right">';
$coldisplay++;
if ($object->element == 'propal' || $object->element == 'commande' || $object->element == 'facture' || $object->element == 'facturerec') {
$type_tva = 1;
} elseif ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') {
$type_tva = 2;
}
if ($seller->tva_assuj == "0") {
echo '<input type="hidden" name="tva_tx" id="tva_tx" value="0">'.vatrate(0, true);
} else {
echo $form->load_tva('tva_tx', (GETPOSTISSET("tva_tx") ? GETPOST("tva_tx", 'alpha', 2) : -1), $seller, $buyer, 0, 0, '', false, 1);
echo $form->load_tva('tva_tx', (GETPOSTISSET("tva_tx") ? GETPOST("tva_tx", 'alpha', 2) : -1), $seller, $buyer, 0, 0, '', false, 1, $type_tva);
}
?>
</td>

View File

@@ -1,11 +1,11 @@
<?php
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2022 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2022 OpenDSI <support@open-dsi.fr>
*
* This program is free software; you can redistribute it and/or modify
@@ -205,9 +205,14 @@ $coldisplay++;
// VAT Rate
$coldisplay++;
if ($object->element == 'propal' || $object->element == 'commande' || $object->element == 'facture' || $object->element == 'facturerec') {
$type_tva = 1;
} elseif ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') {
$type_tva = 2;
}
if (!$situationinvoicelinewithparent) {
print '<td class="right">';
print $form->load_tva('tva_tx', GETPOSTISSET('tva_tx') ? GETPOST('tva_tx', 'alpha') : ($line->tva_tx.($line->vat_src_code ? (' ('.$line->vat_src_code.')') : '')), $seller, $buyer, 0, $line->info_bits, $line->product_type, false, 1);
print $form->load_tva('tva_tx', GETPOSTISSET('tva_tx') ? GETPOST('tva_tx', 'alpha') : ($line->tva_tx.($line->vat_src_code ? (' ('.$line->vat_src_code.')') : '')), $seller, $buyer, 0, $line->info_bits, $line->product_type, false, 1, $type_tva);
print '</td>';
} else {
print '<td class="right"><input size="1" type="text" class="flat right" name="tva_tx" value="'.price($line->tva_tx).'" readonly />%</td>';

View File

@@ -2,7 +2,7 @@
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2015-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2015-2023 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
*
@@ -2364,7 +2364,7 @@ if ($action == 'create') {
// VAT
$selectedvat = price2num($line->vatrate).(!empty($line->vat_src_code) ? ' ('.$line->vat_src_code.')' : '');
print '<td class="right">';
print $form->load_tva('vatrate', (GETPOSTISSET("vatrate") ? GETPOST("vatrate") : $selectedvat), $mysoc, '', 0, 0, '', false, 1);
print $form->load_tva('vatrate', (GETPOSTISSET("vatrate") ? GETPOST("vatrate") : $selectedvat), $mysoc, '', 0, 0, '', false, 1, 2);
print '</td>';
// Unit price

View File

@@ -2,6 +2,7 @@
-- Be carefull to requests order.
-- This file must be loaded by calling /install/index.php page
-- when current version is 18.0.0 or higher.
--
-- To restrict request to Mysql version x.y minimum use -- VMYSQLx.y
-- To restrict request to Pgsql version x.y minimum use -- VPGSQLx.y
@@ -32,7 +33,7 @@
-- -- VPGSQL8.2 SELECT dol_util_rebuild_sequences();
-- v17
-- Missing in v17 or lower
-- VMYSQL4.3 ALTER TABLE llx_emailcollector_emailcollector MODIFY COLUMN tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
@@ -86,6 +87,7 @@ ALTER TABLE llx_payment_salary MODIFY COLUMN datep datetime;
INSERT INTO llx_c_tva(rowid,fk_pays,code,taux,localtax1,localtax1_type,localtax2,localtax2_type,recuperableonly,note,active) values (1179, 117, 'I-28' , 28, 0, '0', 0, '0', 0, 'IGST', 1);
INSERT INTO llx_c_tva(rowid,fk_pays,code,taux,localtax1,localtax1_type,localtax2,localtax2_type,recuperableonly,note,active) values (1176, 117, 'C+S-18', 0, 9, '1', 9, '1', 0, 'CGST+SGST - Same state sales', 1);
ALTER TABLE llx_c_tva ADD COLUMN type_vat smallint NOT NULL DEFAULT '0' AFTER fk_pays;
ALTER TABLE llx_user ADD COLUMN flagdelsessionsbefore datetime DEFAULT NULL;

View File

@@ -20,20 +20,21 @@
create table llx_c_tva
(
rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
entity integer DEFAULT 1 NOT NULL,
fk_pays integer NOT NULL,
code varchar(10) DEFAULT '', -- a key to describe vat entry, for example FR20
taux double NOT NULL,
localtax1 varchar(20) NOT NULL DEFAULT '0',
localtax1_type varchar(10) NOT NULL DEFAULT '0',
localtax2 varchar(20) NOT NULL DEFAULT '0',
localtax2_type varchar(10) NOT NULL DEFAULT '0',
use_default tinyint DEFAULT 0, -- set to 1 to be the default vat when no vat defined on product
recuperableonly integer NOT NULL DEFAULT 0,
note varchar(128),
active tinyint DEFAULT 1 NOT NULL,
accountancy_code_sell varchar(32) DEFAULT NULL,
rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
entity integer DEFAULT 1 NOT NULL,
fk_pays integer NOT NULL,
type_vat smallint NOT NULL DEFAULT '0', -- 0: all, 1: sell, 2: purchase
code varchar(10) DEFAULT '', -- a key to describe vat entry, for example FR20
taux double NOT NULL,
localtax1 varchar(20) NOT NULL DEFAULT '0',
localtax1_type varchar(10) NOT NULL DEFAULT '0',
localtax2 varchar(20) NOT NULL DEFAULT '0',
localtax2_type varchar(10) NOT NULL DEFAULT '0',
use_default tinyint DEFAULT 0, -- set to 1 to be the default vat when no vat defined on product
recuperableonly integer NOT NULL DEFAULT 0,
note varchar(128),
active tinyint DEFAULT 1 NOT NULL,
accountancy_code_sell varchar(32) DEFAULT NULL,
accountancy_code_buy varchar(32) DEFAULT NULL
)ENGINE=innodb;

View File

@@ -1123,6 +1123,7 @@ VATIsUsedDesc=By default when creating prospects, invoices, orders etc. the Sale
VATIsNotUsedDesc=By default the proposed Sales tax is 0 which can be used for cases like associations, individuals or small companies.
VATIsUsedExampleFR=In France, it means companies or organizations having a real fiscal system (Simplified real or normal real). A system in which VAT is declared.
VATIsNotUsedExampleFR=In France, it means associations that are non Sales tax declared or companies, organizations or liberal professions that have chosen the micro enterprise fiscal system (Sales tax in franchise) and paid a franchise Sales tax without any Sales tax declaration. This choice will display the reference "Non applicable Sales tax - art-293B of CGI" on invoices.
VATType=VAT type
##### Local Taxes #####
TypeOfSaleTaxes=Type of sales tax
LTRate=Rate

View File

@@ -144,11 +144,12 @@ if (empty($reshook)) {
// We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in create product.
$vatratecode = $reg[1];
// Get record from code
$sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
$sql = "SELECT t.rowid, t.type_vat, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
$sql .= " AND t.code = '".$db->escape($vatratecode)."'";
$sql .= " AND t.type_vat IN (0, 1)"; // Use only VAT rates type all or i.e. the sales type VAT rates.
$sql .= " AND t.entity IN (".getEntity('c_tva').")";
$resql = $db->query($sql);
if ($resql) {