dolibarr  9.0.0
margins.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
3  * Copyright (C) 2014-2015 Marcos GarcĂ­a <marcosgdf@gmail.com>
4  * Copyright (C) 2016 Florian Henry <florian.henry@open-concept.pro>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
32 {
33  global $langs, $conf;
34 
35  $h = 0;
36  $head = array();
37 
38  $head[$h][0] = DOL_URL_ROOT."/margin/admin/margin.php";
39  $head[$h][1] = $langs->trans("Parameters");
40  $head[$h][2] = 'parameters';
41  $h++;
42 
43  // Show more tabs from modules
44  // Entries must be declared in modules descriptor with line
45  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
46  // $this->tabs = array('entity:-tabname); to remove a tab
47  complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin');
48 
49  complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin','remove');
50 
51  return $head;
52 }
53 
60 {
61  global $langs, $conf, $user;
62  $langs->load("margins");
63 
64  $h = 0;
65  $head = array();
66 
67  if ($user->rights->produit->lire) {
68  $head[$h][0] = DOL_URL_ROOT."/margin/productMargins.php";
69  $head[$h][1] = $langs->trans("ProductMargins");
70  $head[$h][2] = 'productMargins';
71  $h++;
72  }
73 
74  if ($user->rights->societe->lire) {
75  $head[$h][0] = DOL_URL_ROOT."/margin/customerMargins.php";
76  $head[$h][1] = $langs->trans("CustomerMargins");
77  $head[$h][2] = 'customerMargins';
78  $h++;
79  }
80 
81  if ($user->rights->margins->read->all) {
82  $title = 'UserMargins';
83  } else {
84  $title = 'SalesRepresentativeMargins';
85  }
86 
87  $head[$h][0] = DOL_URL_ROOT."/margin/agentMargins.php";
88  $head[$h][1] = $langs->trans($title);
89  $head[$h][2] = 'agentMargins';
90 
91 
92  if ($user->rights->margins->creer) {
93  $h++;
94  $head[$h][0] = DOL_URL_ROOT."/margin/checkMargins.php";
95  $head[$h][1] = $langs->trans('CheckMargins');
96  $head[$h][2] = 'checkMargins';
97  }
98 
99  return $head;
100 }
101 
114 function getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht)
115 {
116  global $db, $conf;
117 
118  $marge_tx_ret='';
119  $marque_tx_ret='';
120 
121  if ($fk_pa > 0 && empty($paht)) {
122  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
123  $product = new ProductFournisseur($db);
124  if ($product->fetch_product_fournisseur_price($fk_pa))
125  {
126  $paht_ret = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100);
127  }
128  else
129  {
130  $paht_ret = $paht;
131  }
132  }
133  else
134  {
135  $paht_ret = $paht;
136  }
137 
138  // Calculate selling unit price including line discount
139  // We don't use calculate_price, because this function is dedicated to calculation of total with accuracy of total. We need an accuracy of a unit price.
140  // Also we must not apply rounding on non decimal rule defined by option MAIN_ROUNDING_RULE_TOT
141  $pu_ht_remise = $pvht * (1 - ($remise_percent / 100));
142  $pu_ht_remise = price2num($pu_ht_remise, 'MU');
143 
144  // calcul marge
145  if ($pu_ht_remise < 0)
146  $marge = -1 * (abs($pu_ht_remise) - $paht_ret);
147  else
148  $marge = $pu_ht_remise - $paht_ret;
149 
150  // calcul taux marge
151  if ($paht_ret != 0)
152  $marge_tx_ret = (100 * $marge) / $paht_ret;
153  // calcul taux marque
154  if ($pu_ht_remise != 0)
155  $marque_tx_ret = (100 * $marge) / $pu_ht_remise;
156 
157  return array($paht_ret, $marge_tx_ret, $marque_tx_ret);
158 }
getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht)
Return an array with margins information of a line.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
marges_prepare_head()
Return array of tabs to used on pages for third parties cards.
Definition: margins.lib.php:59
marges_admin_prepare_head()
Define head array for tabs of marges tools setup pages.
Definition: margins.lib.php:31
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage predefined suppliers products.