dolibarr 23.0.3
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="minwidth150">';
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"><span class="small">'.$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">'.$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">'.$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">'.$langs->trans('ForceBuyingPriceIfNullDetails').'</span></td>';
201print '</tr>';
202
203// GLOBAL DISCOUNT MANAGEMENT
204$methods = array(
205 1 => $langs->trans('UseDiscountAsProduct'),
206 2 => $langs->trans('UseDiscountAsService'),
207 3 => $langs->trans('UseDiscountOnTotal')
208);
209
210
211print '<tr class="oddeven">';
212print '<td>'.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").'</td>';
213print '<td class="left">';
214print Form::selectarray('MARGIN_METHODE_FOR_DISCOUNT', $methods, getDolGlobalString('MARGIN_METHODE_FOR_DISCOUNT'));
215print '</td>';
216print '<td><span class="small">'.$langs->trans('MARGIN_METHODE_FOR_DISCOUNT_DETAILS').'</span></td>';
217print '</tr>';
218
219// INTERNAL CONTACT TYPE USED AS COMMERCIAL AGENT
220print '<tr class="oddeven">';
221print '<td>'.$langs->trans("AgentContactType").'</td>';
222print '<td class="left">';
223$formcompany = new FormCompany($db);
224$facture = new Facture($db);
225print $formcompany->selectTypeContact($facture, getDolGlobalString('AGENT_CONTACT_TYPE'), "AGENT_CONTACT_TYPE", "internal", "code", 1, "maxwidth250");
226print '</td>';
227print '<td><span class="small">'.$langs->trans('AgentContactTypeDetails').'</span></td>';
228print '</tr>';
229
230print '</table>';
231print '</div>';
232
233print '<center><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" class="button"></center>';
234
235print '</form>';
236
237print dol_get_fiche_end();
238
239print '<br>';
240
241// End of page
242llxFooter();
243$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
Class to manage invoices.
Class to build HTML component for third parties management Only common components are here.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.