dolibarr 25.0.0-alpha
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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
26require_once '../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
37require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
38
39$langs->loadLangs(array("admin", "bills", "margins", "stocks"));
40
41if (!$user->admin) {
43}
44
45$action = GETPOST('action', 'aZ09');
46
47
48/*
49 * Action
50 */
51
52$reg = array();
53if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
54 $code = $reg[1];
55 if (dolibarr_set_const($db, $code, 1, 'yesno', 0, '', $conf->entity) > 0) {
56 header("Location: ".$_SERVER["PHP_SELF"]);
57 exit;
58 } else {
59 dol_print_error($db);
60 }
61}
62
63if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
64 $code = $reg[1];
65 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
66 header("Location: ".$_SERVER["PHP_SELF"]);
67 exit;
68 } else {
69 dol_print_error($db);
70 }
71}
72
73if ($action == 'update') {
74 $error = 0;
75 if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', GETPOST('MARGIN_METHODE_FOR_DISCOUNT'), 'chaine', 0, '', $conf->entity) <= 0) {
76 dol_print_error($db);
77 $error++;
78 }
79
80 if (dolibarr_set_const($db, 'MARGIN_TYPE', GETPOST('MARGIN_TYPE'), 'chaine', 0, '', $conf->entity) <= 0) {
81 dol_print_error($db);
82 $error++;
83 }
84
85 if (dolibarr_set_const($db, 'AGENT_CONTACT_TYPE', GETPOST('AGENT_CONTACT_TYPE'), 'chaine', 0, '', $conf->entity) <= 0) {
86 dol_print_error($db);
87 $error++;
88 }
89
90 if (!$error) {
91 setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
92 }
93}
94
95
96/*
97 * View
98 */
99
100$form = new Form($db);
101
102llxHeader('', $langs->trans("margesSetup"), '', '', 0, 0, '', '', '', 'mod-margin page-admin_margin');
103
104
105$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
106print load_fiche_titre($langs->trans("margesSetup"), $linkback, 'title_setup');
107
108
110
111print dol_get_fiche_head($head, 'parameters', $langs->trans("Margins"), -1, 'margin');
112
113print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
114print '<input type="hidden" name="token" value="'.newToken().'">';
115print '<input type="hidden" name="action" value="update">';
116
117print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
118print '<table class="noborder centpercent">';
119print '<tr class="liste_titre">';
120print '<td colspan="3">'.$langs->trans("MemberMainOptions").'</td>';
121print '</tr>';
122
123// GLOBAL DISCOUNT MANAGEMENT
124print '<tr class="oddeven">';
125print '<td>'.$langs->trans("MARGIN_TYPE").'</td>';
126print '<td class="nowraponall">';
127print ' <input type="radio" name="MARGIN_TYPE" id="MARGIN_TYPE1" value="1" ';
128if (getDolGlobalString('MARGIN_TYPE') == '1') {
129 print 'checked ';
130}
131print '/> ';
132print '<label for="MARGIN_TYPE1">'.$langs->trans('MargeType1').'</label>';
133print '<br>';
134print ' <input type="radio" name="MARGIN_TYPE" id="MARGIN_TYPE2" value="pmp" ';
135if (getDolGlobalString('MARGIN_TYPE') == 'pmp') {
136 print 'checked ';
137}
138print '/> ';
139print '<label for="MARGIN_TYPE2">'.$langs->trans('MargeType2').'</label>';
140print '<br>';
141print ' <input type="radio" name="MARGIN_TYPE" id="MARGIN_TYPE3" value="costprice" ';
142if (getDolGlobalString('MARGIN_TYPE') == 'costprice') {
143 print 'checked ';
144}
145print '/> ';
146print '<label for="MARGIN_TYPE3">'.$langs->trans('MargeType3').'</label>';
147print '</td>';
148print '<td class="minwidth200" style="max-width:50%"><span class="small opacitymedium">'.$langs->trans('MarginTypeDesc').'</span>';
149print '</td>';
150print '</tr>';
151
152// DISPLAY MARGIN RATES
153print '<tr class="oddeven">';
154print '<td>'.$langs->trans("DisplayMarginRates").'</td>';
155print '<td>';
156if (!empty($conf->use_javascript_ajax)) {
157 print ajax_constantonoff('DISPLAY_MARGIN_RATES');
158} else {
159 if (!getDolGlobalString('DISPLAY_MARGIN_RATES')) {
160 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
161 } else {
162 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
163 }
164}
165print '</td>';
166print '<td><span class="small opacitymedium">'.$langs->trans('MarginRate').' = '.$langs->trans('Margin').' / '.$langs->trans('BuyingPrice').'</span></td>';
167print '</tr>';
168
169// DISPLAY MARK RATES
170print '<tr class="oddeven">';
171print '<td>'.$langs->trans("DisplayMarkRates").'</td>';
172print '<td>';
173if (!empty($conf->use_javascript_ajax)) {
174 print ajax_constantonoff('DISPLAY_MARK_RATES');
175} else {
176 if (!getDolGlobalString('DISPLAY_MARK_RATES')) {
177 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
178 } else {
179 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
180 }
181}
182print '</td>';
183print '<td><span class="small opacitymedium">'.$langs->trans('MarkRate').' = '.$langs->trans('Margin').' / '.$langs->trans('SellingPrice').'</span></td>';
184print '</tr>';
185
186
187print '<tr class="oddeven">';
188print '<td>'.$langs->trans("ForceBuyingPriceIfNull").'</td>';
189print '<td>';
190if (!empty($conf->use_javascript_ajax)) {
191 print ajax_constantonoff('ForceBuyingPriceIfNull');
192} else {
193 if (!getDolGlobalString('ForceBuyingPriceIfNull')) {
194 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
195 } else {
196 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
197 }
198}
199print '</td>';
200print '<td><span class="small opacitymedium">'.$langs->trans('ForceBuyingPriceIfNullDetails').'</span></td>';
201print '</tr>';
202
203print '<tr class="oddeven">';
204print '<td>'.$langs->trans("MarginUpdateLinkedBuyingPrice").'</td>';
205print '<td colspan="2">'.ajax_constantonoff('MARGIN_CAN_UPDATE_BUYINGPRICE_ON_LINKED_DOCUMENTS').'</td>';
206print '</tr>';
207
208// GLOBAL DISCOUNT MANAGEMENT
209$methods = array(
210 1 => $langs->trans('UseDiscountAsProduct'),
211 2 => $langs->trans('UseDiscountAsService'),
212 3 => $langs->trans('UseDiscountOnTotal')
213);
214
215
216print '<tr class="oddeven">';
217print '<td>'.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").'</td>';
218print '<td class="left">';
219print Form::selectarray('MARGIN_METHODE_FOR_DISCOUNT', $methods, getDolGlobalString('MARGIN_METHODE_FOR_DISCOUNT'));
220print '</td>';
221print '<td><span class="small opacitymedium">'.$langs->trans('MARGIN_METHODE_FOR_DISCOUNT_DETAILS').'</span></td>';
222print '</tr>';
223
224// INTERNAL CONTACT TYPE USED AS COMMERCIAL AGENT
225/* Feature hidden. Enabling it does not match what the report say. So to avoid confusion, we hide it.
226 * Restore it is possible by adding the filter on page agentsMargin.php (page says report is by user).
227 * if combo is in this page, text explanation must also be modified so user can understand.
228 */
229/*
230print '<tr class="oddeven">';
231print '<td>'.$langs->trans("AgentContactType").'</td>';
232print '<td class="left">';
233$formcompany = new FormCompany($db);
234$facture = new Facture($db);
235print $formcompany->selectTypeContact($facture, getDolGlobalString('AGENT_CONTACT_TYPE'), "AGENT_CONTACT_TYPE", "internal", "code", 1, "maxwidth250");
236print '</td>';
237print '<td><span class="small opacitymedium">'.$langs->trans('AgentContactTypeDetails').'</span></td>';
238print '</tr>';
239*/
240
241print '</table>';
242print '</div>';
243
244print '<center><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" class="button"></center>';
245
246print '</form>';
247
248print dol_get_fiche_end();
249
250print '<br>';
251
252// End of page
253llxFooter();
254$db->close();
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage generation of HTML components Only common components must be here.
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='minwidth75', $addjscombo=1, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
marges_admin_prepare_head()
Define head array for tabs of marges tools setup pages.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.