dolibarr 18.0.6
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
25include '../../main.inc.php';
26
27require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
30require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
31
32$langs->loadLangs(array("admin", "bills", "margins", "stocks"));
33
34if (!$user->admin) {
36}
37
38$action = GETPOST('action', 'aZ09');
39
40
41/*
42 * Action
43 */
44
45$reg = array();
46if (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
56if (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
66if ($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
74if ($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
82if ($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
96llxHeader('', $langs->trans("margesSetup"));
97
98
99$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
100print load_fiche_titre($langs->trans("margesSetup"), $linkback, 'title_setup');
101
102
104
105print dol_get_fiche_head($head, 'parameters', $langs->trans("Margins"), -1, 'margin');
106
107print '<table class="noborder centpercent">';
108print '<tr class="liste_titre">';
109print '<td width=300>'.$langs->trans("MemberMainOptions").'</td>';
110print '<td colspan="2">'.$langs->trans("Value").'</td>'."\n";
111print '<td class="left">'.$langs->trans("Description").'</td>'."\n";
112print '</tr>';
113
114// GLOBAL DISCOUNT MANAGEMENT
115print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
116print '<input type="hidden" name="token" value="'.newToken().'">';
117print "<input type=\"hidden\" name=\"action\" value=\"typemarges\">";
118print '<tr class="oddeven">';
119print '<td>'.$langs->trans("MARGIN_TYPE").'</td>';
120print '<td>';
121print ' <input type="radio" name="MARGIN_TYPE" value="1" ';
122if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1') {
123 print 'checked ';
124}
125print '/> ';
126print $langs->trans('MargeType1');
127print '<br>';
128print ' <input type="radio" name="MARGIN_TYPE" value="pmp" ';
129if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') {
130 print 'checked ';
131}
132print '/> ';
133print $langs->trans('MargeType2');
134print '<br>';
135print ' <input type="radio" name="MARGIN_TYPE" value="costprice" ';
136if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') {
137 print 'checked ';
138}
139print '/> ';
140print $langs->trans('MargeType3');
141print '</td>';
142print '<td>';
143print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" class="button">';
144print '</td>';
145print '<td>'.$langs->trans('MarginTypeDesc');
146print '</td>';
147print '</tr>';
148print '</form>';
149
150// DISPLAY MARGIN RATES
151print '<tr class="oddeven">';
152print '<td>'.$langs->trans("DisplayMarginRates").'</td>';
153print '<td colspan="2">';
154if (!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}
163print '</td>';
164print '<td>'.$langs->trans('MarginRate').' = '.$langs->trans('Margin').' / '.$langs->trans('BuyingPrice').'</td>';
165print '</tr>';
166
167// DISPLAY MARK RATES
168print '<tr class="oddeven">';
169print '<td>'.$langs->trans("DisplayMarkRates").'</td>';
170print '<td colspan="2">';
171if (!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}
180print '</td>';
181print '<td>'.$langs->trans('MarkRate').' = '.$langs->trans('Margin').' / '.$langs->trans('SellingPrice').'</td>';
182print '</tr>';
183
184
185print '<tr class="oddeven">';
186print '<td>'.$langs->trans("ForceBuyingPriceIfNull").'</td>';
187print '<td colspan="2">';
188if (!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}
197print '</td>';
198print '<td>'.$langs->trans('ForceBuyingPriceIfNullDetails').'</td>';
199print '</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
209print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
210print '<input type="hidden" name="token" value="'.newToken().'">';
211print '<input type="hidden" name="action" value="remises">';
212print '<tr class="oddeven">';
213print '<td>'.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").'</td>';
214print '<td class="left">';
215print Form::selectarray('MARGIN_METHODE_FOR_DISCOUNT', $methods, getDolGlobalString('MARGIN_METHODE_FOR_DISCOUNT'));
216print '</td>';
217print '<td>';
218print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
219print '</td>';
220print '<td>'.$langs->trans('MARGIN_METHODE_FOR_DISCOUNT_DETAILS').'</td>';
221print '</tr>';
222print '</form>';
223
224// INTERNAL CONTACT TYPE USED AS COMMERCIAL AGENT
225print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
226print '<input type="hidden" name="token" value="'.newToken().'">';
227print '<input type="hidden" name="action" value="contact">';
228print '<tr class="oddeven">';
229print '<td>'.$langs->trans("AgentContactType").'</td>';
230print '<td class="left">';
231$formcompany = new FormCompany($db);
232$facture = new Facture($db);
233print $formcompany->selectTypeContact($facture, getDolGlobalString('AGENT_CONTACT_TYPE'), "AGENT_CONTACT_TYPE", "internal", "code", 1, "maxwidth250");
234print '</td>';
235print '<td>';
236print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
237print '</td>';
238print '<td>'.$langs->trans('AgentContactTypeDetails').'</td>';
239print '</tr>';
240print '</form>';
241
242print '</table>';
243
244print dol_get_fiche_end();
245
246print '<br>';
247
248// End of page
249llxFooter();
250$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()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return 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.