diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php
index 902b49a8231..49f351be4c3 100644
--- a/htdocs/comm/card.php
+++ b/htdocs/comm/card.php
@@ -773,7 +773,7 @@ if ($object->id > 0)
}
/*
- * Last sendings
+ * Last shipments
*/
if (! empty($conf->expedition->enabled) && $user->rights->expedition->lire) {
$sendingstatic = new Expedition($db);
diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php
index 7ed5e3097bf..c261f9e7c90 100644
--- a/htdocs/commande/class/api_orders.class.php
+++ b/htdocs/commande/class/api_orders.class.php
@@ -153,6 +153,7 @@ class Orders extends DolibarrApi
{
$num = $db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
+ $i=0;
while ($i < $min)
{
$obj = $db->fetch_object($result);
@@ -276,7 +277,7 @@ class Orders extends DolibarrApi
$request_data->product_type,
$request_data->rang,
$request_data->special_code,
- $fk_parent_line,
+ $request_data->fk_parent_line,
$request_data->fk_fournprice,
$request_data->pa_ht,
$request_data->label,
diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php
index e691d497194..c1f8774095a 100644
--- a/htdocs/compta/facture/class/api_invoices.class.php
+++ b/htdocs/compta/facture/class/api_invoices.class.php
@@ -60,30 +60,30 @@ class Invoices extends DolibarrApi
*
* @throws RestException
*/
- function get($id)
- {
+ function get($id)
+ {
if(! DolibarrApiAccess::$user->rights->facture->lire) {
throw new RestException(401);
}
- $result = $this->invoice->fetch($id);
- if( ! $result ) {
- throw new RestException(404, 'Invoice not found');
- }
+ $result = $this->invoice->fetch($id);
+ if (! $result) {
+ throw new RestException(404, 'Invoice not found');
+ }
- // Get payment details
- $this->invoice->totalpaye = $this->invoice->getSommePaiement();
- $this->invoice->totalcreditnotes = $this->invoice->getSumCreditNotesUsed();
- $this->invoice->totaldeposits = $this->invoice->getSumDepositsUsed();
- $this->invoice->resteapayer = price2num($this->invoice->total_ttc - $this->invoice->totalpaye - $this->invoice->totalcreditnotes - $this->invoice->totaldeposits, 'MT');
+ // Get payment details
+ $this->invoice->totalpaye = $this->invoice->getSommePaiement();
+ $this->invoice->totalcreditnotes = $this->invoice->getSumCreditNotesUsed();
+ $this->invoice->totaldeposits = $this->invoice->getSumDepositsUsed();
+ $this->invoice->resteapayer = price2num($this->invoice->total_ttc - $this->invoice->totalpaye - $this->invoice->totalcreditnotes - $this->invoice->totaldeposits, 'MT');
- if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
+ if (! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->invoice->fetchObjectLinked();
return $this->_cleanObjectDatas($this->invoice);
- }
+ }
/**
* List invoices
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 8eed645edc4..35ab14454ef 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -1163,9 +1163,9 @@ class Facture extends CommonInvoice
$label.= '
' . $langs->trans('AmountHT') . ': ' . price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
if (! empty($this->total_tva))
$label.= '
' . $langs->trans('VAT') . ': ' . price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
- if (! empty($this->total_tva))
+ if (! empty($this->total_localtax1))
$label.= '
' . $langs->trans('LT1') . ': ' . price($this->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency);
- if (! empty($this->total_tva))
+ if (! empty($this->total_localtax2))
$label.= '
' . $langs->trans('LT2') . ': ' . price($this->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency);
if (! empty($this->total_ttc))
$label.= '
' . $langs->trans('AmountTTC') . ': ' . price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 7ebd32b30b3..2df6dfc82b7 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -78,7 +78,7 @@ abstract class CommonObject
*/
public $array_options=array();
/**
- * @var int[] Array of linked objects ids. Loaded by ->fetchObjectLinked
+ * @var int[][] Array of linked objects ids. Loaded by ->fetchObjectLinked
*/
public $linkedObjectsIds;
/**
@@ -4391,7 +4391,7 @@ abstract class CommonObject
* @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters.
* @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded
*/
- function fetch_optionals($rowid=null,$optionsArray=null)
+ function fetch_optionals($rowid=null, $optionsArray=null)
{
if (empty($rowid)) $rowid=$this->id;
@@ -4536,16 +4536,30 @@ abstract class CommonObject
foreach($new_array_options as $key => $value)
{
- $attributeKey = substr($key,8); // Remove 'options_' prefix
- $attributeType = $extrafields->attribute_type[$attributeKey];
- $attributeLabel = $extrafields->attribute_label[$attributeKey];
- $attributeParam = $extrafields->attribute_param[$attributeKey];
+ $attributeKey = substr($key,8); // Remove 'options_' prefix
+ $attributeType = $extrafields->attribute_type[$attributeKey];
+ $attributeLabel = $extrafields->attribute_label[$attributeKey];
+ $attributeParam = $extrafields->attribute_param[$attributeKey];
+ $attributeRequired = $extrafields->attribute_required[$attributeKey];
+
+ if ($attributeRequired)
+ {
+ $mandatorypb=false;
+ if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true;
+ if ($this->array_options[$key] === '') $mandatorypb=true;
+ if ($mandatorypb)
+ {
+ $this->errors[]=$langs->trans('ErrorFieldRequired', $attributeLabel);
+ return -1;
+ }
+ }
+
switch ($attributeType)
{
case 'int':
if (!is_numeric($value) && $value!='')
{
- $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel);
+ $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
return -1;
}
elseif ($value=='')
@@ -4569,23 +4583,27 @@ abstract class CommonObject
$new_array_options[$key] = $this->db->idate($this->array_options[$key]);
break;
case 'link':
- $param_list=array_keys($attributeParam ['options']);
+ $param_list=array_keys($attributeParam['options']);
// 0 : ObjectName
// 1 : classPath
$InfoFieldList = explode(":", $param_list[0]);
dol_include_once($InfoFieldList[1]);
if ($InfoFieldList[0] && class_exists($InfoFieldList[0]))
{
- $object = new $InfoFieldList[0]($this->db);
- if ($value)
+ if ($value == '-1') // -1 is key for no defined in combo list of objects
{
+ $new_array_options[$key]='';
+ }
+ elseif ($value)
+ {
+ $object = new $InfoFieldList[0]($this->db);
if (is_numeric($value)) $res=$object->fetch($value);
else $res=$object->fetch('',$value);
if ($res > 0) $new_array_options[$key]=$object->id;
else
{
- $this->error="Ref '".$value."' for object '".$object->element."' not found";
+ $this->error="Id/Ref '".$value."' for object '".$object->element."' not found";
$this->db->rollback();
return -1;
}
@@ -4598,6 +4616,7 @@ abstract class CommonObject
break;
}
}
+
$this->db->begin();
$table_element = $this->table_element;
@@ -4730,9 +4749,9 @@ abstract class CommonObject
// 1 : classPath
$InfoFieldList = explode(":", $param_list[0]);
dol_include_once($InfoFieldList[1]);
- $object = new $InfoFieldList[0]($this->db);
if ($value)
{
+ $object = new $InfoFieldList[0]($this->db);
$object->fetch(0,$value);
$this->array_options["options_".$key]=$object->id;
}
@@ -6254,12 +6273,14 @@ abstract class CommonObject
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
}
+ // Create extrafields
if (! $error)
{
$result=$this->insertExtraFields();
if ($result < 0) $error++;
}
+ // Triggers
if (! $error && ! $notrigger)
{
// Call triggers
@@ -6321,13 +6342,13 @@ abstract class CommonObject
/**
* Update object into database
*
- * @param User $user User that modifies
- * @param bool $notrigger false=launch triggers after, true=disable triggers
- * @return int <0 if KO, >0 if OK
+ * @param User $user User that modifies
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
*/
public function updateCommon(User $user, $notrigger = false)
{
- global $langs;
+ global $conf, $langs;
$error = 0;
@@ -6375,7 +6396,22 @@ abstract class CommonObject
}
}
- if (! $error && ! $notrigger) {
+ // Update extrafield
+ if (! $error)
+ {
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+ {
+ $result=$this->insertExtraFields();
+ if ($result < 0)
+ {
+ $error++;
+ }
+ }
+ }
+
+ // Triggers
+ if (! $error && ! $notrigger)
+ {
// Call triggers
$result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user);
if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail
@@ -6414,6 +6450,19 @@ abstract class CommonObject
}
}
+ if (! $error)
+ {
+ $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element."_extrafields";
+ $sql.= " WHERE fk_object=" . $this->id;
+
+ $resql = $this->db->query($sql);
+ if (! $resql)
+ {
+ $this->errors[] = $this->db->lasterror();
+ $error++;
+ }
+ }
+
if (! $error)
{
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id;
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index 51a95d3d32e..1161fb8abd8 100644
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -1621,8 +1621,8 @@ class ExtraFields
{
$out='';
- // only if something to display (perf)
- if ($value)
+ // Only if something to display (perf)
+ if ($value) // If we have -1 here, pb is into sert, not into ouptu
{
$param_list=array_keys($param['options']); // $param_list='ObjectName:classPath'
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 2dafb56e178..a736f3c139a 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -550,7 +550,7 @@ function GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NU
if (! is_array($out) || empty($out)) $out=array();
break;
case 'nohtml':
- $out=dol_string_nohtmltag($out);
+ $out=dol_string_nohtmltag($out, 0);
break;
case 'alphanohtml': // Recommended for search params
if (! is_array($out))
diff --git a/htdocs/core/tpl/extrafields_view.tpl.php b/htdocs/core/tpl/extrafields_view.tpl.php
index e01848e458d..9d638426bc3 100644
--- a/htdocs/core/tpl/extrafields_view.tpl.php
+++ b/htdocs/core/tpl/extrafields_view.tpl.php
@@ -131,7 +131,7 @@ if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element][
}
else
{
- print $extrafields->showOutputField($key, $value);
+ print $extrafields->showOutputField($key, $value, '', (empty($extrafieldsobjectkey)?'':$extrafieldsobjectkey));
}
print '' . "\n";
diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index 2d6178ed79b..0bccdd61e79 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -131,7 +131,7 @@ if ($nolinesbefore) {
if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
$coldisplay=2;
?>
-