From 0b78a04756ca59d8c896fdaa8fc86ef100a922ab Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Sat, 19 Apr 2014 12:32:01 +0200 Subject: [PATCH 1/5] Update doc_generic_project_odt.modules.php --- .../pdf/doc_generic_project_odt.modules.php | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php b/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php index 0e7ec535ac6..c8cf919742b 100644 --- a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php +++ b/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php @@ -841,46 +841,56 @@ class doc_generic_project_odt extends ModelePDFProjects 'propal'=>array( 'title'=>"ListProposalsAssociatedProject", 'class'=>'Propal', - 'test'=>$conf->propal->enabled), + 'table'=>'propal', + 'test'=>$conf->propal->enabled && $user->rights->propale->lire), 'order'=>array( 'title'=>"ListOrdersAssociatedProject", 'class'=>'Commande', - 'test'=>$conf->commande->enabled), + 'table'=>'commande', + 'test'=>$conf->commande->enabled && $user->rights->commande->lire), 'invoice'=>array( 'title'=>"ListInvoicesAssociatedProject", 'class'=>'Facture', - 'test'=>$conf->facture->enabled), + 'table'=>'facture', + 'test'=>$conf->facture->enabled && $user->rights->facture->lire), 'invoice_predefined'=>array( 'title'=>"ListPredefinedInvoicesAssociatedProject", 'class'=>'FactureRec', - 'test'=>$conf->facture->enabled), + 'table'=>'facture_rec', + 'test'=>$conf->facture->enabled && $user->rights->facture->lire), 'order_supplier'=>array( 'title'=>"ListSupplierOrdersAssociatedProject", + 'table'=>'commande_fournisseur', 'class'=>'CommandeFournisseur', - 'test'=>$conf->fournisseur->enabled), + 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire), 'invoice_supplier'=>array( 'title'=>"ListSupplierInvoicesAssociatedProject", + 'table'=>'facture_fourn', 'class'=>'FactureFournisseur', - 'test'=>$conf->fournisseur->enabled), + 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire), 'contract'=>array( 'title'=>"ListContractAssociatedProject", 'class'=>'Contrat', - 'test'=>$conf->contrat->enabled), + 'table'=>'contrat', + 'test'=>$conf->contrat->enabled && $user->rights->contrat->lire), 'intervention'=>array( 'title'=>"ListFichinterAssociatedProject", 'class'=>'Fichinter', + 'table'=>'fichinter', 'disableamount'=>1, - 'test'=>$conf->ficheinter->enabled), + 'test'=>$conf->ficheinter->enabled && $user->rights->ficheinter->lire), 'trip'=>array( 'title'=>"ListTripAssociatedProject", 'class'=>'Deplacement', + 'table'=>'deplacement', 'disableamount'=>1, - 'test'=>$conf->deplacement->enabled), + 'test'=>$conf->deplacement->enabled && $user->rights->deplacement->lire), 'agenda'=>array( 'title'=>"ListActionsAssociatedProject", 'class'=>'ActionComm', + 'table'=>'actioncomm', 'disableamount'=>1, - 'test'=>$conf->agenda->enabled) + 'test'=>$conf->agenda->enabled && $user->rights->agenda->allactions->lire) ); //Insert reference @@ -891,11 +901,12 @@ class doc_generic_project_odt extends ModelePDFProjects foreach ($listofreferent as $keyref => $valueref) { $title=$valueref['title']; + $tablename=$valueref['table']; $classname=$valueref['class']; $qualified=$valueref['test']; if ($qualified) { - $elementarray = $object->get_element_list($keyref); + $elementarray = $object->get_element_list($keyref, $tablename); if (count($elementarray)>0 && is_array($elementarray)) { $var=true; From 09d231ad0a62ab2e124f5d121fed88120a80294e Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Sat, 19 Apr 2014 12:36:15 +0200 Subject: [PATCH 2/5] Update project.class.php --- htdocs/projet/class/project.class.php | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 46f70c7ca89..27a6c4ca0d3 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -391,31 +391,14 @@ class Project extends CommonObject * @param string $type 'propal','order','invoice','order_supplier','invoice_supplier' * @return array List of orders linked to project, <0 if error */ - function get_element_list($type) + function get_element_list($type, $tablename) { $elements = array(); - $sql = ''; - if ($type == 'propal') - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "propal WHERE fk_projet=" . $this->id; - if ($type == 'order') - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "commande WHERE fk_projet=" . $this->id; - if ($type == 'invoice') - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture WHERE fk_projet=" . $this->id; - if ($type == 'invoice_predefined') - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture_rec WHERE fk_projet=" . $this->id; - if ($type == 'order_supplier') - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "commande_fournisseur WHERE fk_projet=" . $this->id; - if ($type == 'invoice_supplier') - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture_fourn WHERE fk_projet=" . $this->id; - if ($type == 'contract') - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "contrat WHERE fk_projet=" . $this->id; - if ($type == 'intervention') - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "fichinter WHERE fk_projet=" . $this->id; - if ($type == 'trip') - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "deplacement WHERE fk_projet=" . $this->id; if ($type == 'agenda') $sql = "SELECT id as rowid FROM " . MAIN_DB_PREFIX . "actioncomm WHERE fk_project=" . $this->id; + else + $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . $tablename." WHERE fk_projet=" . $this->id; if (! $sql) return -1; //print $sql; From cebbf1607c4b3c5607f139e1bc7007cfeca2a791 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Sat, 19 Apr 2014 13:00:42 +0200 Subject: [PATCH 3/5] Update element.php --- htdocs/projet/element.php | 73 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 4266d0f745e..c6756ac6713 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -151,6 +151,7 @@ $listofreferent=array( 'invoice'=>array( 'title'=>"ListInvoicesAssociatedProject", 'class'=>'Facture', + 'margin'=>'add', 'table'=>'facture', 'test'=>$conf->facture->enabled && $user->rights->facture->lire), 'invoice_predefined'=>array( @@ -166,6 +167,7 @@ $listofreferent=array( 'invoice_supplier'=>array( 'title'=>"ListSupplierInvoicesAssociatedProject", 'class'=>'FactureFournisseur', + 'margin'=>'minus', 'table'=>'facture_fourn', 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire), 'contract'=>array( @@ -183,6 +185,7 @@ $listofreferent=array( 'title'=>"ListTripAssociatedProject", 'class'=>'Deplacement', 'table'=>'deplacement', + 'margin'=>'minus', 'disableamount'=>1, 'test'=>$conf->deplacement->enabled && $user->rights->deplacement->lire), 'agenda'=>array( @@ -237,7 +240,7 @@ foreach ($listofreferent as $key => $value) if (empty($value['disableamount'])) print ''.$langs->trans("AmountTTC").''; print ''.$langs->trans("Status").''; print ''; - $elementarray = $project->get_element_list($key); + $elementarray = $project->get_element_list($key, $tablename); if (count($elementarray)>0 && is_array($elementarray)) { $var=true; @@ -334,6 +337,74 @@ foreach ($listofreferent as $key => $value) } } +// Margin display of the project +print_titre("Margin"); +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + + +foreach ($listofreferent as $key => $value) +{ + $title=$value['title']; + $classname=$value['class']; + $tablename=$value['table']; + $qualified=$value['test']; + $margin = $value['margin']; + if (isset($margin)) + { + $elementarray = $project->get_element_list($key); + if (count($elementarray)>0 && is_array($elementarray)) + { + $var=true; + $total_ht = 0; + $total_ttc = 0; + $num=count($elementarray); + for ($i = 0; $i < $num; $i++) + { + $element = new $classname($db); + $element->fetch($elementarray[$i]); + $element->fetch_thirdparty(); + //print $classname; + + $total_ht = $total_ht + $element->total_ht; + $total_ttc = $total_ttc + $element->total_ttc; + } + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + if ($margin=="add") + { + $margin_ht+= $total_ht; + $margin_ttc+= $total_ttc; + } + else + { + $margin_ht-= $total_ht; + $margin_ttc-= $total_ttc; + } + } + + } +} +// and the margin amount total +print ''; +print ''; +print ''; +print ''; +print ''; + +print "
'.$langs->trans("Element").''.$langs->trans("Number").''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").'
'.$classname.''.$i.''.price($total_ht).''.price($total_ttc).'
'.$langs->trans("Total").''.price($margin_ht).''.price($margin_ttc).'
"; + + llxFooter(); $db->close(); From ebab7a0b624596d302bced10ddc53fb48e7e154a Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Sat, 19 Apr 2014 13:06:11 +0200 Subject: [PATCH 4/5] Update element.php --- htdocs/projet/element.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index c6756ac6713..fd36808ccdd 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -357,7 +357,7 @@ foreach ($listofreferent as $key => $value) $margin = $value['margin']; if (isset($margin)) { - $elementarray = $project->get_element_list($key); + $elementarray = $project->get_element_list($key, $tablename); if (count($elementarray)>0 && is_array($elementarray)) { $var=true; From c55e51d82520e85e41ea86184007fb2b6b89ad56 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Sat, 19 Apr 2014 14:59:42 +0200 Subject: [PATCH 5/5] Update project.class.php --- htdocs/projet/class/project.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 27a6c4ca0d3..719c7c5f034 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -389,6 +389,7 @@ class Project extends CommonObject * Return list of elements for type linked to project * * @param string $type 'propal','order','invoice','order_supplier','invoice_supplier' + * @param string $tablename name of table associated of the type * @return array List of orders linked to project, <0 if error */ function get_element_list($type, $tablename)