dolibarr  16.0.5
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 <https://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, null, $head, $h, 'margesadmin');
48 
49  complete_head_from_modules($conf, $langs, null, $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  complete_head_from_modules($conf, $langs, null, $head, $h, 'margins', 'remove');
100  complete_head_from_modules($conf, $langs, null, $head, $h, 'margins');
101 
102  return $head;
103 }
104 
117 function getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht)
118 {
119  global $db, $conf;
120 
121  $marge_tx_ret = '';
122  $marque_tx_ret = '';
123 
124  if ($fk_pa > 0 && empty($paht)) {
125  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
126  $product = new ProductFournisseur($db);
127  if ($product->fetch_product_fournisseur_price($fk_pa)) {
128  $paht_ret = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100);
129  } else {
130  $paht_ret = $paht;
131  }
132  } else {
133  $paht_ret = $paht;
134  }
135 
136  // Calculate selling unit price including line discount
137  // 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.
138  // Also we must not apply rounding on non decimal rule defined by option MAIN_ROUNDING_RULE_TOT
139  $pu_ht_remise = $pvht * (1 - ($remise_percent / 100));
140  $pu_ht_remise = price2num($pu_ht_remise, 'MU');
141 
142  // calcul marge
143  if ($pu_ht_remise < 0) {
144  $marge = -1 * (abs($pu_ht_remise) - $paht_ret);
145  } else {
146  $marge = $pu_ht_remise - $paht_ret;
147  }
148 
149  // calcul taux marge
150  if ($paht_ret != 0) {
151  $marge_tx_ret = (100 * $marge) / $paht_ret;
152  }
153  // calcul taux marque
154  if ($pu_ht_remise != 0) {
155  $marque_tx_ret = (100 * $marge) / $pu_ht_remise;
156  }
157 
158  return array($paht_ret, $marge_tx_ret, $marque_tx_ret);
159 }
ProductFournisseur
Class to manage predefined suppliers products.
Definition: fournisseur.product.class.php:41
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
marges_prepare_head
marges_prepare_head()
Return array of tabs to used on pages for third parties cards.
Definition: margins.lib.php:59
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
marges_admin_prepare_head
marges_admin_prepare_head()
Define head array for tabs of marges tools setup pages.
Definition: margins.lib.php:31
getMarginInfos
getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht)
Return an array with margins information of a line.
Definition: margins.lib.php:117