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