diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 9074ec5ff18..11cf3d6bb7f 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -22,7 +22,11 @@
* \file htdocs/core/class/commonobject.class.php
* \ingroup core
* \brief Fichier de la classe mere des classes metiers (facture, contrat, propal, commande, etc...)
+<<<<<<< commonobject.class.php
* \version $Id$
+=======
+ * \version $Id$
+>>>>>>> 1.107
*/
@@ -996,26 +1000,27 @@ class CommonObject
/**
* Update total_ht, total_ttc and total_vat for an object (sum of lines)
- * @param exclspec Exclude special product (product_type=9)
- * @return int <0 if KO, >0 if OK
+ * @param exclspec Exclude special product (product_type=9)
+ * @param roundingadjust -1=Use default method (MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND or 0), 0=Use total of rounding, 1=Use rounding of total
+ * @return int <0 if KO, >0 if OK
*/
- function update_price($exclspec=0)
+ function update_price($exclspec=0,$roundingadjust=-1)
{
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
+ if ($roundingadjust < 0 && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $roundingadjust=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND;
+ if ($roundingadjust < 0) $roundingadjust=0;
+
$err=0;
// List lines to sum
$fieldtva='total_tva';
$fieldlocaltax1='total_localtax1';
$fieldlocaltax2='total_localtax2';
+ if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='tva';
- if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier')
- {
- $fieldtva='tva';
- }
-
- $sql = 'SELECT qty, total_ht, '.$fieldtva.' as total_tva, '.$fieldlocaltax1.' as total_localtax1, '.$fieldlocaltax2.' as total_localtax2, total_ttc';
+ $sql = 'SELECT qty, total_ht, '.$fieldtva.' as total_tva, '.$fieldlocaltax1.' as total_localtax1, '.$fieldlocaltax2.' as total_localtax2, total_ttc,';
+ $sql.= ' tva_tx as vatrate';
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
if ($exclspec) $sql.= ' AND product_type <> 9';
@@ -1042,11 +1047,29 @@ class CommonObject
$this->total_localtax2 += $obj->total_localtax2;
$this->total_ttc += $obj->total_ttc;
+ // TODO Also fill array by vat rate
+ $varates[$this->vatrate][]=array('total_ht'=>$obj->total_ht,'total_tva'=>$obj->total_tva,'total_ttc'=>$obj->total_ttc,
+ 'total_localtax1'=>$obj->total_localtax1,'total_localtax2'=>$obj->total_localtax2);
$i++;
}
$this->db->free($resql);
+ // TODO
+ if ($roundingadjust)
+ {
+ // For each vatrate, calculate if two method of calculation differs
+
+
+ // If it differs
+ if (1==2)
+ {
+ // Adjust a line and update it
+
+
+ }
+ }
+
// Now update field total_ht, total_ttc and tva
$fieldht='total_ht';
$fieldtva='tva';
@@ -1122,7 +1145,12 @@ class CommonObject
}
/**
- * Load array of objects linked to current object. Links are loaded into this->linked_object array.
+ * Load array of objects linked to current object. Links are loaded into this->linked_object array.
+ * @param sourceid
+ * @param sourcetype
+ * @param targetid
+ * @param targettype
+ * @param clause
*/
function load_object_linked($sourceid='',$sourcetype='',$targetid='',$targettype='',$clause='OR')
{
@@ -1166,11 +1194,11 @@ class CommonObject
}
/**
- * \brief Set statut of an object
- * \param statut Statut to set
- * \param elementid Id of element to force (use this->id by default)
- * \param elementtype Type of element to force (use ->this->element by default)
- * \return int <0 if ko, >0 if ok
+ * Set statut of an object
+ * @param statut Statut to set
+ * @param elementid Id of element to force (use this->id by default)
+ * @param elementtype Type of element to force (use ->this->element by default)
+ * @return int <0 if ko, >0 if ok
*/
function setStatut($statut,$elementId='',$elementType='')
{
@@ -1238,7 +1266,7 @@ class CommonObject
}
else
{
- print $sql;
+ dol_print_error($db,$sql);
}
}
@@ -1309,7 +1337,9 @@ class CommonObject
$modelclassname = 'Dao'.ucfirst($module);
$this->hooks[$objModule->module_number]->object = new $modelclassname($this->db);
- dol_include_once('/'.$module.'/lib/'.$module.'.lib.php');
+ // We comment this because library must be included into file that need it,
+ // so include should be done into actions_ and/or dao file
+ // dol_include_once('/'.$module.'/lib/'.$module.'.lib.php');
}
}
}
@@ -1317,15 +1347,70 @@ class CommonObject
- // TODO: All functions here must be moved into a lib file and included into page as they are not business code
- // but only "view" code.
+ // TODO: All functions here must be redesigned and moved as they are not business functions but output functions
+ /* This is to show linked object block */
- /**
+
+ /**
+ * Show linked object block
+ * TODO Move this into html.class.php
+ * But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
+ * @param $objecttype Type of object (invoice, propal, order, invoice_supplier, order_supplier, ...)
+ * @param $objectid
+ * @param $somethingshown
+ */
+ function showLinkedObjectBlock($objecttype,$objectid,$somethingshown=0)
+ {
+ global $langs,$bc;
+
+ //print 'objecttype='.$objecttype.'
';
+
+ $this->objectid = $objectid;
+
+ $num = sizeof($this->objectid);
+ if ($num)
+ {
+ $element = $subelement = $objecttype;
+ $tplpath = $element;
+
+ if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
+ {
+ $element = $regs[1];
+ $subelement = $regs[2];
+ $tplpath = $element.'/'.$subelement;
+ }
+
+ $classpath = $element.'/class';
+ if ($objecttype == 'facture') { $tplpath = 'compta/'.$element; $classpath = $tplpath.'/class'; } // To work with non standard path
+ if ($objecttype == 'propal') { $tplpath = 'comm/'.$element; $classpath = $tplpath.'/class'; } // To work with non standard path
+ if ($objecttype == 'invoice_supplier') { $tplpath = 'fourn/facture'; $classpath = 'fourn/class'; } // To work with non standard path
+ if ($objecttype == 'order_supplier') { $tplpath = 'fourn/commande'; $classpath = 'fourn/class'; } // To work with non standard path
+
+ $classfile = strtolower($subelement); $classname = ucfirst($subelement);
+ if ($objecttype == 'invoice_supplier') { $classfile='fournisseur.facture'; $classname='FactureFournisseur'; }
+ if ($objecttype == 'order_supplier') { $classfile='fournisseur.commande'; $classname='CommandeFournisseur'; }
+ //print $classfile." - ".$classpath." - ".$tplpath;
+ if(!class_exists($classname))
+ {
+ dol_include_once("/".$classpath."/".$classfile.".class.php");
+ }
+ $this->linkedObjectBlock = new $classname($this->db);
+ dol_include_once('/'.$tplpath.'/tpl/linkedobjectblock.tpl.php');
+
+ return $num;
+ }
+ }
+
+
+ /* This is to show add lines */
+
+
+ /**
* Show add predefined products/services form
- * TODO Move this into page (into a lib.php file if mutualized. No code for output must be present into a business class).
- * But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
+ * TODO Edit templates to use global variables and include them directly in controller call
+ * But for the moment we don't know if it's possible as we keep a method available on overloaded objects.
* @param $dateSelector 1=Show also date range input fields
*/
function formAddPredefinedProduct($dateSelector,$seller,$buyer)
@@ -1339,7 +1424,7 @@ class CommonObject
/**
* Show add free products/services form
- * TODO Move this into page (into a lib.php file if mutualized. No code for output must be present into a business class).
+ * TODO Edit templates to use global variables and include them directly in controller call
* But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
* @param $dateSelector 1=Show also date range input fields
*/
@@ -1352,68 +1437,21 @@ class CommonObject
include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_create.tpl.php');
}
+
+
+ /* This is to show array of line of details */
+
+
/**
- * Show linked object block
- * TODO Move this into page (into a lib.php file if mutualized. No code for output must be present into a business class).
+ * Return HTML table for object lines
+ * TODO Move this into an output class file (htmlline.class.php)
+ * If lines are into a template, title must also be into a template
* But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
- * @param $objecttype Type of object (invoice, propal, order, invoice_supplier, order_supplier, ...)
- * @param $objectid
- * @param $somethingshown
- */
- function showLinkedObjectBlock($objecttype,$objectid,$somethingshown=0)
- {
- global $langs,$bc;
-
- //print 'objecttype='.$objecttype.'
';
-
- $this->objectid = $objectid;
-
- $num = sizeof($this->objectid);
- if ($num)
- {
- $element = $subelement = $objecttype;
- $tplpath = $element;
-
- if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
- {
- $element = $regs[1];
- $subelement = $regs[2];
- $tplpath = $element.'/'.$subelement;
- }
-
- $classpath = $element.'/class';
- if ($objecttype == 'facture') { $tplpath = 'compta/'.$element; $classpath = $tplpath.'/class'; } // To work with non standard path
- if ($objecttype == 'propal') { $tplpath = 'comm/'.$element; $classpath = $tplpath.'/class'; } // To work with non standard path
- if ($objecttype == 'invoice_supplier') { $tplpath = 'fourn/facture'; $classpath = 'fourn/class'; } // To work with non standard path
- if ($objecttype == 'order_supplier') { $tplpath = 'fourn/commande'; $classpath = 'fourn/class'; } // To work with non standard path
-
- $classfile = strtolower($subelement); $classname = ucfirst($subelement);
- if ($objecttype == 'invoice_supplier') { $classfile='fournisseur.facture'; $classname='FactureFournisseur'; }
- if ($objecttype == 'order_supplier') { $classfile='fournisseur.commande'; $classname='CommandeFournisseur'; }
- //print $classfile." - ".$classpath." - ".$tplpath;
- if(!class_exists($classname))
- {
- dol_include_once("/".$classpath."/".$classfile.".class.php");
- }
- $this->linkedObjectBlock = new $classname($this->db);
- dol_include_once('/'.$tplpath.'/tpl/linkedobjectblock.tpl.php');
-
- return $num;
- }
- }
-
- /**
- * Return HTML with object lines list.
- * Array $this->lines must be defined.
- * @param $dateSelector Show date input fields (if service)
- * @param $seller Object of seller third party
- * @param uyer Object of buyer third party
- * TODO Move this into page (into a lib.php file if mutualized. No code for output must be present into a business class).
*/
function printObjectLines($dateSelector=0,$seller,$buyer)
{
global $conf,$langs;
-
+
print '