- element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines
- {
- ?>
-
info_bits & 2) != 2) && $line->special_code != 3) {
- // I comment this because it shows info even when not required
- // for example always visible on invoice but must be visible only if stock module on and stock decrease option is on invoice validation and status is not validated
- // must also not be output for most entities (proposal, intervention, ...)
- //if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." ";
- echo price($line->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formating role of function price
- } else echo ' ';
+ echo price($line->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formating role of function price
?>
\n";
- print "\n";
}
$var = true;
@@ -4045,7 +3982,7 @@ abstract class CommonObject
}
if (empty($reshook))
{
- $this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafieldsline);
+ $this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafieldsline, $defaulttpldir);
}
$i++;
@@ -4067,9 +4004,10 @@ abstract class CommonObject
* @param string $buyer Object of buyer third party
* @param int $selected Object line selected
* @param int $extrafieldsline Object of extrafield line attribute
+ * @param string $defaulttpldir Directory where to find the template
* @return void
*/
- public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafieldsline = 0)
+ public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafieldsline = 0, $defaulttpldir = '/core/tpl')
{
global $conf,$langs,$user,$object,$hookmanager;
global $form,$bc,$bcdd;
@@ -4103,7 +4041,7 @@ abstract class CommonObject
// Define output language and label
if (! empty($conf->global->MAIN_MULTILANGS))
{
- if (! is_object($this->thirdparty))
+ if (property_exists($this, 'socid') && ! is_object($this->thirdparty))
{
dol_print_error('', 'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
return;
@@ -4115,7 +4053,7 @@ abstract class CommonObject
$outputlangs = $langs;
$newlang='';
if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang=GETPOST('lang_id', 'aZ09');
- if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer
+ if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang) && is_object($this->thirdparty)) $newlang=$this->thirdparty->default_lang; // To use language of customer
if (! empty($newlang))
{
$outputlangs = new Translate("", $conf);
@@ -4137,7 +4075,7 @@ abstract class CommonObject
// Output template part (modules that overwrite templates must declare this into descriptor)
// Use global variables + $dateSelector + $seller and $buyer
- $dirtpls=array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
+ $dirtpls=array_merge($conf->modules_parts['tpl'], array($defaulttpldir));
foreach($dirtpls as $module => $reldir)
{
if (!empty($module))
@@ -4157,7 +4095,7 @@ abstract class CommonObject
}
}
- // Ligne en mode update
+ // Line in update mode
if ($this->statut == 0 && $action == 'editline' && $selected == $line->id)
{
$label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : ''));
@@ -4167,7 +4105,7 @@ abstract class CommonObject
// Output template part (modules that overwrite templates must declare this into descriptor)
// Use global variables + $dateSelector + $seller and $buyer
- $dirtpls=array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
+ $dirtpls=array_merge($conf->modules_parts['tpl'], array($defaulttpldir));
foreach($dirtpls as $module => $reldir)
{
if (!empty($module))
@@ -7370,6 +7308,56 @@ abstract class CommonObject
}
}
+ /**
+ * Load object in memory from the database
+ *
+ * @param string $morewhere More SQL filters (' AND ...')
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetchLinesCommon($morewhere = '')
+ {
+ $objectlineclassname = get_class($this).'Line';
+ if (! class_exists($objectlineclassname))
+ {
+ $this->error = 'Error, class '.$objectlineclassname.' not found during call of fetchLinesCommon';
+ return -1;
+ }
+
+ $objectline = new $objectlineclassname($this->db);
+
+ $sql = 'SELECT '.$objectline->getFieldList();
+ $sql.= ' FROM '.MAIN_DB_PREFIX.$objectline->table_element;
+ $sql.=' WHERE fk_'.$this->element.' = '.$this->id;
+ if ($morewhere) $sql.= $morewhere;
+
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num_rows = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < $num_rows)
+ {
+ $obj = $this->db->fetch_object($resql);
+ if ($obj)
+ {
+ $newline = new $objectlineclassname($this->db);
+ $newline->setVarsFromFetchObj($obj);
+
+ $this->lines[] = $newline;
+ }
+ $i++;
+ }
+
+ return 1;
+ }
+ else
+ {
+ $this->error = $this->db->lasterror();
+ $this->errors[] = $this->error;
+ return -1;
+ }
+ }
+
/**
* Update object into database
*
@@ -7541,6 +7529,66 @@ abstract class CommonObject
}
}
+ /**
+ * Delete a line of object in database
+ *
+ * @param User $user User that delete
+ * @param int $idline Id of line to delete
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int >0 if OK, <0 if KO
+ */
+ public function deleteLineCommon(User $user, $idline, $notrigger = false)
+ {
+ global $conf;
+
+ $error=0;
+
+ $tmpforobjectclass = get_class($this);
+ $tmpforobjectlineclass = ucfirst($tmpforobjectclass).'Line';
+
+ // Call trigger
+ $result=$this->call_trigger('LINE'.strtoupper($tmpforobjectclass).'_DELETE', $user);
+ if ($result < 0) return -1;
+ // End call triggers
+
+ $this->db->begin();
+
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element_line;
+ $sql.= " WHERE rowid=".$idline;
+
+ dol_syslog(get_class($this)."::deleteLineCommon", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (! $resql)
+ {
+ $this->error="Error ".$this->db->lasterror();
+ $error++;
+ }
+
+ if (empty($error)) {
+ // Remove extrafields
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+ {
+ $tmpobjectline = new $tmpforobjectlineclass($this->db);
+ $tmpobjectline->id= $idline;
+ $result=$tmpobjectline->deleteExtraFields();
+ if ($result < 0)
+ {
+ $error++;
+ $this->error="Error ".get_class($this)."::deleteLineCommon deleteExtraFields error -4 ".$tmpobjectline->error;
+ }
+ }
+ }
+
+ if (empty($error)) {
+ $this->db->commit();
+ return 1;
+ } else {
+ dol_syslog(get_class($this)."::deleteLineCommon ERROR:".$this->error, LOG_ERR);
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
/**
* Initialise object with example values
* Id must be 0 if object instance is a specimen
diff --git a/htdocs/core/tpl/objectline_title.tpl.php b/htdocs/core/tpl/objectline_title.tpl.php
new file mode 100644
index 00000000000..fd848764721
--- /dev/null
+++ b/htdocs/core/tpl/objectline_title.tpl.php
@@ -0,0 +1,131 @@
+
+ * Copyright (C) 2010-2011 Laurent Destailleur
+ * Copyright (C) 2012-2013 Christophe Battarel
+ * Copyright (C) 2012 Cédric Salvador
+ * Copyright (C) 2012-2014 Raphaël Doursenaud
+ * Copyright (C) 2013 Florian Henry
+ * Copyright (C) 2017 Juanjo Menent
+ *
+ * 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
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * Need to have following variables defined:
+ * $object (invoice, order, ...)
+ * $conf
+ * $langs
+ * $element (used to test $user->rights->$element->creer)
+ * $permtoedit (used to replace test $user->rights->$element->creer)
+ * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
+ * $outputalsopricetotalwithtax
+ * $usemargins (0 to disable all margins columns, 1 to show according to margin setup)
+ *
+ * $type, $text, $description, $line
+ */
+
+// Protection to avoid direct call of template
+if (empty($object) || ! is_object($object))
+{
+ print "Error, template page can't be called as URL";
+ exit;
+}
+?>
+
+\n";
+
+print '
';
+
+// Adds a line numbering column
+if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '