diff --git a/.github/workflows/stale-issues-safe.yml b/.github/workflows/stale-issues-safe.yml
index 1682b92a7a7..4ac9fa8f5b9 100644
--- a/.github/workflows/stale-issues-safe.yml
+++ b/.github/workflows/stale-issues-safe.yml
@@ -6,9 +6,13 @@ on:
- cron: "0 21 * * *"
issue_comment:
types: [created]
+
+permissions: {} # none
jobs:
stale:
+ permissions:
+ issues: write
runs-on: ubuntu-latest
steps:
- uses: Dolibarr/stale@staleunstale
@@ -21,4 +25,4 @@ jobs:
days-before-close: 10
operations-per-run: 100
dry-run: false
-
\ No newline at end of file
+
diff --git a/htdocs/adherents/admin/website.php b/htdocs/adherents/admin/website.php
index 884c6e67be2..3c7775dc6b8 100644
--- a/htdocs/adherents/admin/website.php
+++ b/htdocs/adherents/admin/website.php
@@ -223,13 +223,13 @@ if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
$listofval = array();
$listofval['-1'] = $langs->trans('No');
$listofval['all'] = $langs->trans('Yes').' ('.$langs->trans("VisitorCanChooseItsPaymentMode").')';
- if (!empty($conf->paybox->enabled)) {
+ if (isModEnabled('paybox')) {
$listofval['paybox'] = 'Paybox';
}
- if (!empty($conf->paypal->enabled)) {
+ if (isModEnabled('paypal')) {
$listofval['paypal'] = 'PayPal';
}
- if (!empty($conf->stripe->enabled)) {
+ if (isModEnabled('stripe')) {
$listofval['stripe'] = 'Stripe';
}
print $form->selectarray("MEMBER_NEWFORM_PAYONLINE", $listofval, (!empty($conf->global->MEMBER_NEWFORM_PAYONLINE) ? $conf->global->MEMBER_NEWFORM_PAYONLINE : ''), 0);
@@ -253,7 +253,7 @@ if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
print ' ';
//print $langs->trans('FollowingLinksArePublic').' ';
print img_picto('', 'globe').' '.$langs->trans('BlankSubscriptionForm').' ';
- if (!empty($conf->multicompany->enabled)) {
+ if (isModEnabled('multicompany')) {
$entity_qr = '?entity='.$conf->entity;
} else {
$entity_qr = '';
diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php
index b40d7772e99..b6463e006a9 100644
--- a/htdocs/adherents/type.php
+++ b/htdocs/adherents/type.php
@@ -178,6 +178,7 @@ if ($action == 'update' && $user->rights->adherent->configurer) {
$object->status = (int) $status;
$object->subscription = (int) $subscription;
$object->amount = ($amount == '' ? '' : price2num($amount, 'MT'));
+ $object->caneditamount = $caneditamount;
$object->duration_value = $duration_value;
$object->duration_unit = $duration_unit;
$object->note = trim($comment);
@@ -828,6 +829,10 @@ if ($rowid > 0) {
print '">';
print '';
+ print '
';
diff --git a/htdocs/admin/security.php b/htdocs/admin/security.php
index 795a0557f16..516197b7a70 100644
--- a/htdocs/admin/security.php
+++ b/htdocs/admin/security.php
@@ -1,5 +1,5 @@
+/* Copyright (C) 2004-2022 Laurent Destailleur
* Copyright (C) 2005-2007 Regis Houssin
* Copyright (C) 2013-2015 Juanjo Menent
*
@@ -47,9 +47,6 @@ $allow_disable_encryption = true;
if ($action == 'setgeneraterule') {
if (!dolibarr_set_const($db, 'USER_PASSWORD_GENERATED', $_GET["value"], 'chaine', 0, '', $conf->entity)) {
dol_print_error($db);
- } else {
- header("Location: ".$_SERVER["PHP_SELF"]);
- exit;
}
}
@@ -94,8 +91,6 @@ if ($action == 'activate_encrypt') {
//exit;
if (!$error) {
$db->commit();
- header("Location: security.php");
- exit;
} else {
$db->rollback();
dol_print_error($db, '');
@@ -106,8 +101,6 @@ if ($action == 'activate_encrypt') {
if ($allow_disable_encryption) {
dolibarr_del_const($db, "DATABASE_PWD_ENCRYPTED", $conf->entity);
}
- header("Location: security.php");
- exit;
}
if ($action == 'activate_encryptdbpassconf') {
@@ -138,12 +131,8 @@ if ($action == 'activate_encryptdbpassconf') {
if ($action == 'activate_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
dolibarr_set_const($db, "MAIN_SECURITY_DISABLEFORGETPASSLINK", '1', 'chaine', 0, '', $conf->entity);
- header("Location: security.php");
- exit;
} elseif ($action == 'disable_MAIN_SECURITY_DISABLEFORGETPASSLINK') {
dolibarr_del_const($db, "MAIN_SECURITY_DISABLEFORGETPASSLINK", $conf->entity);
- header("Location: security.php");
- exit;
}
if ($action == 'updatepattern') {
@@ -387,9 +376,9 @@ if ($conf->global->USER_PASSWORD_GENERATED == "Perso") {
// Cryptage mot de passe
print ' ';
-print "';
// End of page
diff --git a/htdocs/admin/system/constall.php b/htdocs/admin/system/constall.php
index 9a27feb3d7a..fee82d89958 100644
--- a/htdocs/admin/system/constall.php
+++ b/htdocs/admin/system/constall.php
@@ -205,7 +205,7 @@ print '';
print '';
print ''.$langs->trans("Parameter").' ';
print ''.$langs->trans("Value").' ';
-if (empty($conf->multicompany->enabled) || !$user->entity) {
+if (!isModEnabled('multicompany') || !$user->entity) {
print ''.$langs->trans("Entity").' '; // If superadmin or multicompany disabled
}
print " \n";
@@ -218,7 +218,7 @@ $sql .= ", type";
$sql .= ", note";
$sql .= ", entity";
$sql .= " FROM ".MAIN_DB_PREFIX."const";
-if (empty($conf->multicompany->enabled)) {
+if (!isModEnabled('multicompany')) {
// If no multicompany mode, admins can see global and their constantes
$sql .= " WHERE entity IN (0,".$conf->entity.")";
} else {
@@ -239,7 +239,7 @@ if ($resql) {
print '';
print ''.$obj->name.' '."\n";
print ''.$obj->value.' '."\n";
- if (empty($conf->multicompany->enabled) || !$user->entity) {
+ if (!isModEnabled('multicompany') || !$user->entity) {
print ''.$obj->entity.' '."\n"; // If superadmin or multicompany disabled
}
print " \n";
diff --git a/htdocs/admin/system/dolibarr.php b/htdocs/admin/system/dolibarr.php
index 8a982f6e0bd..31fa647f403 100644
--- a/htdocs/admin/system/dolibarr.php
+++ b/htdocs/admin/system/dolibarr.php
@@ -382,7 +382,7 @@ foreach ($configfileparameters as $key => $value) {
$newkey = preg_replace('/^\?/', '', $key);
if (preg_match('/^\?/', $key) && empty(${$newkey})) {
- if ($newkey != 'multicompany_transverse_mode' || empty($conf->multicompany->enabled)) {
+ if ($newkey != 'multicompany_transverse_mode' || !isModEnabled('multicompany')) {
continue; // We discard parameters starting with ?
}
}
@@ -483,7 +483,7 @@ print '';
print '';
print ''.$langs->trans("Parameters").' '.$langs->trans("Database").' ';
print ''.$langs->trans("Value").' ';
-if (empty($conf->multicompany->enabled) || !$user->entity) {
+if (!isModEnabled('multicompany') || !$user->entity) {
print ''.$langs->trans("Entity").' '; // If superadmin or multicompany disabled
}
print " \n";
@@ -496,7 +496,7 @@ $sql .= ", type";
$sql .= ", note";
$sql .= ", entity";
$sql .= " FROM ".MAIN_DB_PREFIX."const";
-if (empty($conf->multicompany->enabled)) {
+if (!isModEnabled('multicompany')) {
// If no multicompany mode, admins can see global and their constantes
$sql .= " WHERE entity IN (0,".$conf->entity.")";
} else {
@@ -526,7 +526,7 @@ if ($resql) {
print dol_escape_htmltag($obj->value);
}
print ''."\n";
- if (empty($conf->multicompany->enabled) || !$user->entity) {
+ if (!isModEnabled('multicompany') || !$user->entity) {
print ''.$obj->entity.' '."\n"; // If superadmin or multicompany disabled
}
print "\n";
diff --git a/htdocs/admin/taxes.php b/htdocs/admin/taxes.php
index 646f4a7be74..fb4b2ec6d72 100644
--- a/htdocs/admin/taxes.php
+++ b/htdocs/admin/taxes.php
@@ -27,7 +27,7 @@
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
-if (!empty($conf->accounting->enabled)) {
+if (isModEnabled('accounting')) {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
}
@@ -137,7 +137,7 @@ if ($action == 'update') {
llxHeader('', $langs->trans("TaxSetup"));
$form = new Form($db);
-if (!empty($conf->accounting->enabled)) {
+if (isModEnabled('accounting')) {
$formaccounting = new FormAccounting($db);
}
@@ -282,7 +282,7 @@ echo '
';
echo '';
-if (!empty($conf->accounting->enabled)) {
+if (isModEnabled('accounting')) {
$langs->load("accountancy");
print ''.$langs->trans("AccountingAccountForSalesTaxAreDefinedInto", $langs->transnoentitiesnoconv("MenuAccountancy"), $langs->transnoentitiesnoconv("Setup")).' ';
}
diff --git a/htdocs/admin/tools/listevents.php b/htdocs/admin/tools/listevents.php
index 6d6a8edb10f..da7ae901766 100644
--- a/htdocs/admin/tools/listevents.php
+++ b/htdocs/admin/tools/listevents.php
@@ -418,7 +418,7 @@ if ($result) {
$userstatic->status = $obj->status;
print $userstatic->getLoginUrl(1);
- if (!empty($conf->multicompany->enabled) && $userstatic->admin && !$userstatic->entity) {
+ if (isModEnabled('multicompany') && $userstatic->admin && !$userstatic->entity) {
print img_picto($langs->trans("SuperAdministrator"), 'redstar', 'class="valignmiddle paddingleft"');
} elseif ($userstatic->admin) {
print img_picto($langs->trans("Administrator"), 'star', 'class="valignmiddle paddingleft"');
diff --git a/htdocs/admin/translation.php b/htdocs/admin/translation.php
index 1e667e7abb4..154ac3f5665 100644
--- a/htdocs/admin/translation.php
+++ b/htdocs/admin/translation.php
@@ -346,7 +346,7 @@ if ($mode == 'overwrite') {
print_liste_field_titre("Language_en_US_es_MX_etc", $_SERVER["PHP_SELF"], 'lang,transkey', '', $param, '', $sortfield, $sortorder);
print_liste_field_titre("Key", $_SERVER["PHP_SELF"], 'transkey', '', $param, '', $sortfield, $sortorder);
print_liste_field_titre("NewTranslationStringToShow", $_SERVER["PHP_SELF"], 'transvalue', '', $param, '', $sortfield, $sortorder);
- //if (! empty($conf->multicompany->enabled) && !$user->entity) print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'entity,transkey', '', $param, '', $sortfield, $sortorder);
+ //if (isModEnabled('multicompany') && !$user->entity) print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'entity,transkey', '', $param, '', $sortfield, $sortorder);
print ' ';
print "\n";
@@ -504,7 +504,7 @@ if ($mode == 'searchkey') {
print '';
print ' ';
// Limit to superadmin
- /*if (! empty($conf->multicompany->enabled) && !$user->entity)
+ /*if (isModEnabled('multicompany') && !$user->entity)
{
print ' ';
print ' ';
@@ -525,7 +525,7 @@ if ($mode == 'searchkey') {
print_liste_field_titre("Language_en_US_es_MX_etc", $_SERVER["PHP_SELF"], 'lang,transkey', '', $param, '', $sortfield, $sortorder);
print_liste_field_titre("Key", $_SERVER["PHP_SELF"], 'transkey', '', $param, '', $sortfield, $sortorder);
print_liste_field_titre("CurrentTranslationString", $_SERVER["PHP_SELF"], 'transvalue', '', $param, '', $sortfield, $sortorder);
- //if (! empty($conf->multicompany->enabled) && !$user->entity) print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'entity,transkey', '', $param, '', $sortfield, $sortorder);
+ //if (isModEnabled('multicompany') && !$user->entity) print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'entity,transkey', '', $param, '', $sortfield, $sortorder);
print ' ';
print "\n";
@@ -609,7 +609,7 @@ if ($mode == 'searchkey') {
$htmltext = $langs->trans("TransKeyWithoutOriginalValue", $key);
print $form->textwithpicto('', $htmltext, 1, 'warning');
}
- /*if (! empty($conf->multicompany->enabled) && !$user->entity)
+ /*if (isModEnabled('multicompany') && !$user->entity)
{
print ''.$val.' ';
}*/
diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php
index a1aa77f2e6e..0ef143d36ad 100644
--- a/htdocs/api/class/api.class.php
+++ b/htdocs/api/class/api.class.php
@@ -115,6 +115,8 @@ class DolibarrApi
// Remove linkedObjects. We should already have linkedObjectsIds that avoid huge responses
unset($object->linkedObjects);
+ unset($object->linkedObjectsFullLoaded);
+ //unset($object->lines[$i]->linked_objects); // This is the array to create linked object during create
unset($object->fields);
unset($object->oldline);
@@ -139,6 +141,7 @@ class DolibarrApi
unset($object->projet); // Should be fk_project
unset($object->project); // Should be fk_project
+ unset($object->fk_projet); // Should be fk_project
unset($object->author); // Should be fk_user_author
unset($object->timespent_old_duration);
unset($object->timespent_id);
diff --git a/htdocs/asset/class/asset.class.php b/htdocs/asset/class/asset.class.php
index 16306e73441..55d2bc07593 100644
--- a/htdocs/asset/class/asset.class.php
+++ b/htdocs/asset/class/asset.class.php
@@ -195,7 +195,7 @@ class Asset extends CommonObject
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
$this->fields['rowid']['visible'] = 0;
}
- if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
+ if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
$this->fields['entity']['enabled'] = 0;
}
diff --git a/htdocs/asset/class/assetmodel.class.php b/htdocs/asset/class/assetmodel.class.php
index 6b75702278d..fb574e6ea18 100644
--- a/htdocs/asset/class/assetmodel.class.php
+++ b/htdocs/asset/class/assetmodel.class.php
@@ -160,7 +160,7 @@ class AssetModel extends CommonObject
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
$this->fields['rowid']['visible'] = 0;
}
- if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
+ if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
$this->fields['entity']['enabled'] = 0;
}
diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php
index 50d97150d6a..576d8f5fb09 100644
--- a/htdocs/bom/class/bom.class.php
+++ b/htdocs/bom/class/bom.class.php
@@ -239,7 +239,7 @@ class BOM extends CommonObject
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
$this->fields['rowid']['visible'] = 0;
}
- if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
+ if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
$this->fields['entity']['enabled'] = 0;
}
@@ -1525,7 +1525,7 @@ class BOMLine extends CommonObjectLine
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
$this->fields['rowid']['visible'] = 0;
}
- if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
+ if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
$this->fields['entity']['enabled'] = 0;
}
diff --git a/htdocs/comm/action/class/actioncommreminder.class.php b/htdocs/comm/action/class/actioncommreminder.class.php
index ff242430b0a..eb0d464777a 100644
--- a/htdocs/comm/action/class/actioncommreminder.class.php
+++ b/htdocs/comm/action/class/actioncommreminder.class.php
@@ -149,7 +149,7 @@ class ActionCommReminder extends CommonObject
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
$this->fields['rowid']['visible'] = 0;
}
- if (empty($conf->multicompany->enabled)) {
+ if (!isModEnabled('multicompany')) {
$this->fields['entity']['enabled'] = 0;
}
}
diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php
index b30ef8f7ba9..f28a3b2f719 100644
--- a/htdocs/comm/action/peruser.php
+++ b/htdocs/comm/action/peruser.php
@@ -901,7 +901,7 @@ while ($currentdaytoshow < $lastdaytoshow) {
/* Use this list to have for all users */
$sql = "SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
- if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
+ if (isModEnabled('multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
$sql .= " WHERE ug.entity IN (".getEntity('usergroup').")";
$sql .= " AND ug.fk_user = u.rowid ";
diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php
index 748c5fabf10..eb1b50cee1b 100644
--- a/htdocs/comm/mailing/card.php
+++ b/htdocs/comm/mailing/card.php
@@ -258,7 +258,7 @@ if (empty($reshook)) {
}
}
if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
- $substitutionarray['__PUBLICLINK_NEWMEMBERFORM__'] = ''.$langs->trans('BlankSubscriptionForm'). ' ';
+ $substitutionarray['__PUBLICLINK_NEWMEMBERFORM__'] = ''.$langs->trans('BlankSubscriptionForm'). ' ';
}
/* For backward compatibility, deprecated */
if (!empty($conf->paypal->enabled) && !empty($conf->global->PAYPAL_SECURITY_TOKEN)) {
diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php
index 226e9ef6389..e02ff5d8875 100644
--- a/htdocs/comm/propal/card.php
+++ b/htdocs/comm/propal/card.php
@@ -47,7 +47,6 @@ require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
if (!empty($conf->project->enabled)) {
@@ -875,7 +874,7 @@ if (empty($reshook)) {
}
}
} elseif ($action == 'addline' && GETPOST('submitforalllines', 'alpha') && GETPOST('vatforalllines', 'alpha') !== '' && $usercancreate) {
- // Define vat_rate
+ // Define a vat_rate for all lines
$vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0);
$vat_rate = str_replace('*', '', $vat_rate);
$localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
@@ -884,7 +883,7 @@ if (empty($reshook)) {
$result = $object->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
}
} elseif ($action == 'addline' && GETPOST('submitforalllines', 'alpha') && GETPOST('remiseforalllines', 'alpha') !== '' && $usercancreate) {
- // Define vat_rate
+ // Define a discount for all lines
$remise_percent = (GETPOST('remiseforalllines') ? GETPOST('remiseforalllines') : 0);
$remise_percent = str_replace('*', '', $remise_percent);
foreach ($object->lines as $line) {
@@ -894,22 +893,36 @@ if (empty($reshook)) {
// Set if we used free entry or predefined product
$predef = '';
$product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
- $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
- $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
- $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
- $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
- $prod_entry_mode = GETPOST('prod_entry_mode');
+ $price_ht = '';
+ $price_ht_devise = '';
+ $price_ttc = '';
+ $price_ttc_devise = '';
+
+ if (GETPOST('price_ht') !== '') {
+ $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
+ }
+ if (GETPOST('multicurrency_price_ht') !== '') {
+ $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
+ }
+ if (GETPOST('price_ttc') !== '') {
+ $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
+ }
+ if (GETPOST('multicurrency_price_ttc') !== '') {
+ $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
+ }
+
+ $prod_entry_mode = GETPOST('prod_entry_mode', 'aZ09');
if ($prod_entry_mode == 'free') {
$idprod = 0;
- $tva_tx = (GETPOST('tva_tx') ? price2num(preg_replace('/\s*\(.*\)/', '', GETPOST('tva_tx'))) : 0);
+ $tva_tx = (GETPOST('tva_tx', 'alpha') ? price2num(preg_replace('/\s*\(.*\)/', '', GETPOST('tva_tx', 'alpha'))) : 0);
} else {
$idprod = GETPOST('idprod', 'int');
$tva_tx = '';
}
$qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2);
- $remise_percent = price2num(GETPOST('remise_percent'.$predef), '', 2);
+ $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
if (empty($remise_percent)) {
$remise_percent = 0;
}
@@ -930,7 +943,7 @@ if (empty($reshook)) {
$error++;
}
- if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && $price_ht === '' && $price_ht_devise === '') { // Unit price can be 0 but not ''. Also price can be negative for proposal.
+ if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && $price_ht === '' && $price_ht_devise === '' && $price_ttc === '' && $price_ttc_devise === '') { // Unit price can be 0 but not ''. Also price can be negative for proposal.
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
$error++;
}
@@ -1077,13 +1090,15 @@ if (empty($reshook)) {
$tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
$tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));
- // if price ht is forced (ie: calculated by margin rate and cost price). TODO Why this ?
+ // Set unit price to use
if (!empty($price_ht) || $price_ht === '0') {
$pu_ht = price2num($price_ht, 'MU');
$pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
+ } elseif (!empty($price_ttc) || $price_ttc === '0') {
+ $pu_ttc = price2num($price_ttc, 'MU');
+ $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
} elseif ($tmpvat != $tmpprodvat) {
- // On reevalue prix selon taux tva car taux tva transaction peut etre different
- // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
+ // Is this still used ?
if ($price_base_type != 'HT') {
$pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
} else {
@@ -1170,16 +1185,22 @@ if (empty($reshook)) {
$fk_unit = $prod->fk_unit;
} else {
$pu_ht = price2num($price_ht, 'MU');
- $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
+ $pu_ttc = price2num($price_ttc, 'MU');
$tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
+ if (empty($tva_tx)) {
+ $tva_npr = 0;
+ }
$tva_tx = str_replace('*', '', $tva_tx);
$label = (GETPOST('product_label') ? GETPOST('product_label') : '');
$desc = $product_desc;
$type = GETPOST('type');
-
$fk_unit = GETPOST('units', 'alpha');
$pu_ht_devise = price2num($price_ht_devise, 'MU');
$pu_ttc_devise = price2num($price_ttc_devise, 'MU');
+
+ if ($pu_ttc && !$pu_ht) {
+ $price_base_type = 'TTC';
+ }
}
// Margin
@@ -1298,7 +1319,7 @@ if (empty($reshook)) {
$buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
- //$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
+ $pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
$date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
$date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
@@ -1382,7 +1403,14 @@ if (empty($reshook)) {
$qty = price2num(GETPOST('qty', 'alpha'), 'MS');
- $result = $object->updateline(GETPOST('lineid', 'int'), $pu_ht, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $description, 'HT', $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options, GETPOST("units"), $pu_ht_devise);
+ $pu = $pu_ht;
+ $price_base_type = 'HT';
+ if (empty($pu) && ! empty($pu_ttc)) {
+ $pu = $pu_ttc;
+ $price_base_type = 'TTC';
+ }
+
+ $result = $object->updateline(GETPOST('lineid', 'int'), $pu, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $description, $price_base_type, $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options, GETPOST("units"), $pu_ht_devise);
if ($result >= 0) {
$db->commit();
@@ -2696,7 +2724,7 @@ if ($action == 'create') {
* Lines
*/
- // Show object lines
+ // Get object lines
$result = $object->getLinesArray();
// Add products/services form
@@ -2704,7 +2732,7 @@ if ($action == 'create') {
global $inputalsopricewithtax;
$inputalsopricewithtax = 1;
- print '