dolibarr  16.0.5
margin.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
3  * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 include '../../main.inc.php';
26 
27 require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
30 require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
31 
32 $langs->loadLangs(array("admin", "bills", "margins", "stocks"));
33 
34 if (!$user->admin) {
36 }
37 
38 $action = GETPOST('action', 'aZ09');
39 
40 
41 /*
42  * Action
43  */
44 
45 $reg = array();
46 if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
47  $code = $reg[1];
48  if (dolibarr_set_const($db, $code, 1, 'yesno', 0, '', $conf->entity) > 0) {
49  header("Location: ".$_SERVER["PHP_SELF"]);
50  exit;
51  } else {
52  dol_print_error($db);
53  }
54 }
55 
56 if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
57  $code = $reg[1];
58  if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
59  header("Location: ".$_SERVER["PHP_SELF"]);
60  exit;
61  } else {
62  dol_print_error($db);
63  }
64 }
65 
66 if ($action == 'remises') {
67  if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', GETPOST('MARGIN_METHODE_FOR_DISCOUNT'), 'chaine', 0, '', $conf->entity) > 0) {
68  setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
69  } else {
70  dol_print_error($db);
71  }
72 }
73 
74 if ($action == 'typemarges') {
75  if (dolibarr_set_const($db, 'MARGIN_TYPE', GETPOST('MARGIN_TYPE'), 'chaine', 0, '', $conf->entity) > 0) {
76  setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
77  } else {
78  dol_print_error($db);
79  }
80 }
81 
82 if ($action == 'contact') {
83  if (dolibarr_set_const($db, 'AGENT_CONTACT_TYPE', GETPOST('AGENT_CONTACT_TYPE'), 'chaine', 0, '', $conf->entity) > 0) {
84  setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
85  } else {
86  dol_print_error($db);
87  }
88 }
89 
90 /*
91  * View
92  */
93 
94 $form = new Form($db);
95 
96 llxHeader('', $langs->trans("margesSetup"));
97 
98 
99 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
100 print load_fiche_titre($langs->trans("margesSetup"), $linkback, 'title_setup');
101 
102 
103 $head = marges_admin_prepare_head();
104 
105 print dol_get_fiche_head($head, 'parameters', $langs->trans("Margins"), -1, 'margin');
106 
107 print '<table class="noborder centpercent">';
108 print '<tr class="liste_titre">';
109 print '<td width=300>'.$langs->trans("MemberMainOptions").'</td>';
110 print '<td colspan="2">'.$langs->trans("Value").'</td>'."\n";
111 print '<td class="left">'.$langs->trans("Description").'</td>'."\n";
112 print '</tr>';
113 
114 // GLOBAL DISCOUNT MANAGEMENT
115 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
116 print '<input type="hidden" name="token" value="'.newToken().'">';
117 print "<input type=\"hidden\" name=\"action\" value=\"typemarges\">";
118 print '<tr class="oddeven">';
119 print '<td>'.$langs->trans("MARGIN_TYPE").'</td>';
120 print '<td>';
121 print ' <input type="radio" name="MARGIN_TYPE" value="1" ';
122 if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1') {
123  print 'checked ';
124 }
125 print '/> ';
126 print $langs->trans('MargeType1');
127 print '<br>';
128 print ' <input type="radio" name="MARGIN_TYPE" value="pmp" ';
129 if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') {
130  print 'checked ';
131 }
132 print '/> ';
133 print $langs->trans('MargeType2');
134 print '<br>';
135 print ' <input type="radio" name="MARGIN_TYPE" value="costprice" ';
136 if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') {
137  print 'checked ';
138 }
139 print '/> ';
140 print $langs->trans('MargeType3');
141 print '</td>';
142 print '<td>';
143 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" class="button">';
144 print '</td>';
145 print '<td>'.$langs->trans('MarginTypeDesc');
146 print '</td>';
147 print '</tr>';
148 print '</form>';
149 
150 // DISPLAY MARGIN RATES
151 print '<tr class="oddeven">';
152 print '<td>'.$langs->trans("DisplayMarginRates").'</td>';
153 print '<td colspan="2">';
154 if (!empty($conf->use_javascript_ajax)) {
155  print ajax_constantonoff('DISPLAY_MARGIN_RATES');
156 } else {
157  if (empty($conf->global->DISPLAY_MARGIN_RATES)) {
158  print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
159  } else {
160  print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
161  }
162 }
163 print '</td>';
164 print '<td>'.$langs->trans('MarginRate').' = '.$langs->trans('Margin').' / '.$langs->trans('BuyingPrice').'</td>';
165 print '</tr>';
166 
167 // DISPLAY MARK RATES
168 print '<tr class="oddeven">';
169 print '<td>'.$langs->trans("DisplayMarkRates").'</td>';
170 print '<td colspan="2">';
171 if (!empty($conf->use_javascript_ajax)) {
172  print ajax_constantonoff('DISPLAY_MARK_RATES');
173 } else {
174  if (empty($conf->global->DISPLAY_MARK_RATES)) {
175  print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
176  } else {
177  print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
178  }
179 }
180 print '</td>';
181 print '<td>'.$langs->trans('MarkRate').' = '.$langs->trans('Margin').' / '.$langs->trans('SellingPrice').'</td>';
182 print '</tr>';
183 
184 
185 print '<tr class="oddeven">';
186 print '<td>'.$langs->trans("ForceBuyingPriceIfNull").'</td>';
187 print '<td colspan="2">';
188 if (!empty($conf->use_javascript_ajax)) {
189  print ajax_constantonoff('ForceBuyingPriceIfNull');
190 } else {
191  if (empty($conf->global->ForceBuyingPriceIfNull)) {
192  print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
193  } else {
194  print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
195  }
196 }
197 print '</td>';
198 print '<td>'.$langs->trans('ForceBuyingPriceIfNullDetails').'</td>';
199 print '</tr>';
200 
201 // GLOBAL DISCOUNT MANAGEMENT
202 $methods = array(
203  1 => $langs->trans('UseDiscountAsProduct'),
204  2 => $langs->trans('UseDiscountAsService'),
205  3 => $langs->trans('UseDiscountOnTotal')
206 );
207 
208 
209 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
210 print '<input type="hidden" name="token" value="'.newToken().'">';
211 print '<input type="hidden" name="action" value="remises">';
212 print '<tr class="oddeven">';
213 print '<td>'.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").'</td>';
214 print '<td class="left">';
215 print Form::selectarray('MARGIN_METHODE_FOR_DISCOUNT', $methods, getDolGlobalString('MARGIN_METHODE_FOR_DISCOUNT'));
216 print '</td>';
217 print '<td>';
218 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
219 print '</td>';
220 print '<td>'.$langs->trans('MARGIN_METHODE_FOR_DISCOUNT_DETAILS').'</td>';
221 print '</tr>';
222 print '</form>';
223 
224 // INTERNAL CONTACT TYPE USED AS COMMERCIAL AGENT
225 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
226 print '<input type="hidden" name="token" value="'.newToken().'">';
227 print '<input type="hidden" name="action" value="contact">';
228 print '<tr class="oddeven">';
229 print '<td>'.$langs->trans("AgentContactType").'</td>';
230 print '<td class="left">';
231 $formcompany = new FormCompany($db);
232 $facture = new Facture($db);
233 print $formcompany->selectTypeContact($facture, getDolGlobalString('AGENT_CONTACT_TYPE'), "AGENT_CONTACT_TYPE", "internal", "code", 1, "maxwidth250");
234 print '</td>';
235 print '<td>';
236 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
237 print '</td>';
238 print '<td>'.$langs->trans('AgentContactTypeDetails').'</td>';
239 print '</tr>';
240 print '</form>';
241 
242 print '</table>';
243 
244 print dol_get_fiche_end();
245 
246 print '<br>';
247 
248 // End of page
249 llxFooter();
250 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Facture
Class to manage invoices.
Definition: facture.class.php:60
marges_admin_prepare_head
marges_admin_prepare_head()
Define head array for tabs of marges tools setup pages.
Definition: margins.lib.php:31
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
ajax_constantonoff
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='')
On/off button for constant.
Definition: ajax.lib.php:573
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dolibarr_set_const
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:627
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
Form\selectarray
static selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=1, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
Definition: html.form.class.php:7879
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59