dolibarr 21.0.0-beta
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
26include '../../main.inc.php';
27
28require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
31require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
32
41$langs->loadLangs(array("admin", "bills", "margins", "stocks"));
42
43if (!$user->admin) {
45}
46
47$action = GETPOST('action', 'aZ09');
48
49
50/*
51 * Action
52 */
53
54$reg = array();
55if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
56 $code = $reg[1];
57 if (dolibarr_set_const($db, $code, 1, 'yesno', 0, '', $conf->entity) > 0) {
58 header("Location: ".$_SERVER["PHP_SELF"]);
59 exit;
60 } else {
61 dol_print_error($db);
62 }
63}
64
65if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
66 $code = $reg[1];
67 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
68 header("Location: ".$_SERVER["PHP_SELF"]);
69 exit;
70 } else {
71 dol_print_error($db);
72 }
73}
74
75if ($action == 'remises') {
76 if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', GETPOST('MARGIN_METHODE_FOR_DISCOUNT'), 'chaine', 0, '', $conf->entity) > 0) {
77 setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
78 } else {
79 dol_print_error($db);
80 }
81}
82
83if ($action == 'typemarges') {
84 if (dolibarr_set_const($db, 'MARGIN_TYPE', GETPOST('MARGIN_TYPE'), 'chaine', 0, '', $conf->entity) > 0) {
85 setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
86 } else {
87 dol_print_error($db);
88 }
89}
90
91if ($action == 'contact') {
92 if (dolibarr_set_const($db, 'AGENT_CONTACT_TYPE', GETPOST('AGENT_CONTACT_TYPE'), 'chaine', 0, '', $conf->entity) > 0) {
93 setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
94 } else {
95 dol_print_error($db);
96 }
97}
98
99/*
100 * View
101 */
102
103$form = new Form($db);
104
105llxHeader('', $langs->trans("margesSetup"), '', '', 0, 0, '', '', '', 'mod-margin page-admin_margin');
106
107
108$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
109print load_fiche_titre($langs->trans("margesSetup"), $linkback, 'title_setup');
110
111
113
114print dol_get_fiche_head($head, 'parameters', $langs->trans("Margins"), -1, 'margin');
115
116print '<table class="noborder centpercent">';
117print '<tr class="liste_titre">';
118print '<td width=300>'.$langs->trans("MemberMainOptions").'</td>';
119print '<td colspan="2">'.$langs->trans("Value").'</td>'."\n";
120print '<td class="left">'.$langs->trans("Description").'</td>'."\n";
121print '</tr>';
122
123// GLOBAL DISCOUNT MANAGEMENT
124print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
125print '<input type="hidden" name="token" value="'.newToken().'">';
126print "<input type=\"hidden\" name=\"action\" value=\"typemarges\">";
127print '<tr class="oddeven">';
128print '<td>'.$langs->trans("MARGIN_TYPE").'</td>';
129print '<td>';
130print ' <input type="radio" name="MARGIN_TYPE" value="1" ';
131if (getDolGlobalString('MARGIN_TYPE') == '1') {
132 print 'checked ';
133}
134print '/> ';
135print $langs->trans('MargeType1');
136print '<br>';
137print ' <input type="radio" name="MARGIN_TYPE" value="pmp" ';
138if (getDolGlobalString('MARGIN_TYPE') == 'pmp') {
139 print 'checked ';
140}
141print '/> ';
142print $langs->trans('MargeType2');
143print '<br>';
144print ' <input type="radio" name="MARGIN_TYPE" value="costprice" ';
145if (getDolGlobalString('MARGIN_TYPE') == 'costprice') {
146 print 'checked ';
147}
148print '/> ';
149print $langs->trans('MargeType3');
150print '</td>';
151print '<td>';
152print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" class="button">';
153print '</td>';
154print '<td>'.$langs->trans('MarginTypeDesc');
155print '</td>';
156print '</tr>';
157print '</form>';
158
159// DISPLAY MARGIN RATES
160print '<tr class="oddeven">';
161print '<td>'.$langs->trans("DisplayMarginRates").'</td>';
162print '<td colspan="2">';
163if (!empty($conf->use_javascript_ajax)) {
164 print ajax_constantonoff('DISPLAY_MARGIN_RATES');
165} else {
166 if (!getDolGlobalString('DISPLAY_MARGIN_RATES')) {
167 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
168 } else {
169 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
170 }
171}
172print '</td>';
173print '<td>'.$langs->trans('MarginRate').' = '.$langs->trans('Margin').' / '.$langs->trans('BuyingPrice').'</td>';
174print '</tr>';
175
176// DISPLAY MARK RATES
177print '<tr class="oddeven">';
178print '<td>'.$langs->trans("DisplayMarkRates").'</td>';
179print '<td colspan="2">';
180if (!empty($conf->use_javascript_ajax)) {
181 print ajax_constantonoff('DISPLAY_MARK_RATES');
182} else {
183 if (!getDolGlobalString('DISPLAY_MARK_RATES')) {
184 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
185 } else {
186 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
187 }
188}
189print '</td>';
190print '<td>'.$langs->trans('MarkRate').' = '.$langs->trans('Margin').' / '.$langs->trans('SellingPrice').'</td>';
191print '</tr>';
192
193
194print '<tr class="oddeven">';
195print '<td>'.$langs->trans("ForceBuyingPriceIfNull").'</td>';
196print '<td colspan="2">';
197if (!empty($conf->use_javascript_ajax)) {
198 print ajax_constantonoff('ForceBuyingPriceIfNull');
199} else {
200 if (!getDolGlobalString('ForceBuyingPriceIfNull')) {
201 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
202 } else {
203 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
204 }
205}
206print '</td>';
207print '<td>'.$langs->trans('ForceBuyingPriceIfNullDetails').'</td>';
208print '</tr>';
209
210// GLOBAL DISCOUNT MANAGEMENT
211$methods = array(
212 1 => $langs->trans('UseDiscountAsProduct'),
213 2 => $langs->trans('UseDiscountAsService'),
214 3 => $langs->trans('UseDiscountOnTotal')
215);
216
217
218print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
219print '<input type="hidden" name="token" value="'.newToken().'">';
220print '<input type="hidden" name="action" value="remises">';
221print '<tr class="oddeven">';
222print '<td>'.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").'</td>';
223print '<td class="left">';
224print Form::selectarray('MARGIN_METHODE_FOR_DISCOUNT', $methods, getDolGlobalString('MARGIN_METHODE_FOR_DISCOUNT'));
225print '</td>';
226print '<td>';
227print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
228print '</td>';
229print '<td>'.$langs->trans('MARGIN_METHODE_FOR_DISCOUNT_DETAILS').'</td>';
230print '</tr>';
231print '</form>';
232
233// INTERNAL CONTACT TYPE USED AS COMMERCIAL AGENT
234print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
235print '<input type="hidden" name="token" value="'.newToken().'">';
236print '<input type="hidden" name="action" value="contact">';
237print '<tr class="oddeven">';
238print '<td>'.$langs->trans("AgentContactType").'</td>';
239print '<td class="left">';
240$formcompany = new FormCompany($db);
241$facture = new Facture($db);
242print $formcompany->selectTypeContact($facture, getDolGlobalString('AGENT_CONTACT_TYPE'), "AGENT_CONTACT_TYPE", "internal", "code", 1, "maxwidth250");
243print '</td>';
244print '<td>';
245print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
246print '</td>';
247print '<td>'.$langs->trans('AgentContactTypeDetails').'</td>';
248print '</tr>';
249print '</form>';
250
251print '</table>';
252
253print dol_get_fiche_end();
254
255print '<br>';
256
257// End of page
258llxFooter();
259$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.
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:71
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.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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)
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)
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
marges_admin_prepare_head()
Define head array for tabs of marges tools setup pages.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.