dolibarr  13.0.2
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) accessforbidden();
35 
36 $action = GETPOST('action', 'aZ09');
37 
38 
39 /*
40  * Action
41  */
42 
43 if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg))
44 {
45  $code = $reg[1];
46  if (dolibarr_set_const($db, $code, 1, 'yesno', 0, '', $conf->entity) > 0)
47  {
48  header("Location: ".$_SERVER["PHP_SELF"]);
49  exit;
50  } else {
51  dol_print_error($db);
52  }
53 }
54 
55 if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg))
56 {
57  $code = $reg[1];
58  if (dolibarr_del_const($db, $code, $conf->entity) > 0)
59  {
60  header("Location: ".$_SERVER["PHP_SELF"]);
61  exit;
62  } else {
63  dol_print_error($db);
64  }
65 }
66 
67 if ($action == 'remises')
68 {
69  if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', $_POST['MARGIN_METHODE_FOR_DISCOUNT'], 'chaine', 0, '', $conf->entity) > 0)
70  {
71  setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
72  } else {
73  dol_print_error($db);
74  }
75 }
76 
77 if ($action == 'typemarges')
78 {
79  if (dolibarr_set_const($db, 'MARGIN_TYPE', $_POST['MARGIN_TYPE'], 'chaine', 0, '', $conf->entity) > 0)
80  {
81  setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
82  } else {
83  dol_print_error($db);
84  }
85 }
86 
87 if ($action == 'contact')
88 {
89  if (dolibarr_set_const($db, 'AGENT_CONTACT_TYPE', $_POST['AGENT_CONTACT_TYPE'], 'chaine', 0, '', $conf->entity) > 0)
90  {
91  setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
92  } else {
93  dol_print_error($db);
94  }
95 }
96 
97 /*
98  * View
99  */
100 
101 $form = new Form($db);
102 
103 llxHeader('', $langs->trans("margesSetup"));
104 
105 
106 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
107 print load_fiche_titre($langs->trans("margesSetup"), $linkback, 'title_setup');
108 
109 
110 $head = marges_admin_prepare_head();
111 
112 print dol_get_fiche_head($head, 'parameters', $langs->trans("Margins"), -1, 'margin');
113 
114 print '<table class="noborder centpercent">';
115 print '<tr class="liste_titre">';
116 print '<td width=300>'.$langs->trans("MemberMainOptions").'</td>';
117 print '<td colspan="2">'.$langs->trans("Value").'</td>'."\n";
118 print '<td class="left">'.$langs->trans("Description").'</td>'."\n";
119 print '</tr>';
120 
121 // GLOBAL DISCOUNT MANAGEMENT
122 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
123 print '<input type="hidden" name="token" value="'.newToken().'">';
124 print "<input type=\"hidden\" name=\"action\" value=\"typemarges\">";
125 print '<tr class="oddeven">';
126 print '<td>'.$langs->trans("MARGIN_TYPE").'</td>';
127 print '<td>';
128 print ' <input type="radio" name="MARGIN_TYPE" value="1" ';
129 if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1')
130  print 'checked ';
131 print '/> ';
132 print $langs->trans('MargeType1');
133 print '<br>';
134 print ' <input type="radio" name="MARGIN_TYPE" value="pmp" ';
135 if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') print 'checked ';
136 print '/> ';
137 print $langs->trans('MargeType2');
138 print '<br>';
139 print ' <input type="radio" name="MARGIN_TYPE" value="costprice" ';
140 if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') print 'checked ';
141 print '/> ';
142 print $langs->trans('MargeType3');
143 print '</td>';
144 print '<td>';
145 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'" class="button">';
146 print '</td>';
147 print '<td>'.$langs->trans('MarginTypeDesc');
148 print '</td>';
149 print '</tr>';
150 print '</form>';
151 
152 // DISPLAY MARGIN RATES
153 print '<tr class="oddeven">';
154 print '<td>'.$langs->trans("DisplayMarginRates").'</td>';
155 print '<td colspan="2">';
156 if (!empty($conf->use_javascript_ajax))
157 {
158  print ajax_constantonoff('DISPLAY_MARGIN_RATES');
159 } else {
160  if (empty($conf->global->DISPLAY_MARGIN_RATES))
161  {
162  print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES&amp;token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
163  } else {
164  print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES&amp;token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
165  }
166 }
167 print '</td>';
168 print '<td>'.$langs->trans('MarginRate').' = '.$langs->trans('Margin').' / '.$langs->trans('BuyingPrice').'</td>';
169 print '</tr>';
170 
171 // DISPLAY MARK RATES
172 print '<tr class="oddeven">';
173 print '<td>'.$langs->trans("DisplayMarkRates").'</td>';
174 print '<td colspan="2">';
175 if (!empty($conf->use_javascript_ajax))
176 {
177  print ajax_constantonoff('DISPLAY_MARK_RATES');
178 } else {
179  if (empty($conf->global->DISPLAY_MARK_RATES))
180  {
181  print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
182  } else {
183  print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
184  }
185 }
186 print '</td>';
187 print '<td>'.$langs->trans('MarkRate').' = '.$langs->trans('Margin').' / '.$langs->trans('SellingPrice').'</td>';
188 print '</tr>';
189 
190 
191 print '<tr class="oddeven">';
192 print '<td>'.$langs->trans("ForceBuyingPriceIfNull").'</td>';
193 print '<td colspan="2">';
194 if (!empty($conf->use_javascript_ajax))
195 {
196  print ajax_constantonoff('ForceBuyingPriceIfNull');
197 } else {
198  if (empty($conf->global->ForceBuyingPriceIfNull))
199  {
200  print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull&amp;token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
201  } else {
202  print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull&amp;token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
203  }
204 }
205 print '</td>';
206 print '<td>'.$langs->trans('ForceBuyingPriceIfNullDetails').'</td>';
207 print '</tr>';
208 
209 // GLOBAL DISCOUNT MANAGEMENT
210 $methods = array(
211  1 => $langs->trans('UseDiscountAsProduct'),
212  2 => $langs->trans('UseDiscountAsService'),
213  3 => $langs->trans('UseDiscountOnTotal')
214 );
215 
216 
217 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
218 print '<input type="hidden" name="token" value="'.newToken().'">';
219 print "<input type=\"hidden\" name=\"action\" value=\"remises\">";
220 print '<tr class="oddeven">';
221 print '<td>'.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").'</td>';
222 print '<td class="left">';
223 print Form::selectarray('MARGIN_METHODE_FOR_DISCOUNT', $methods, $conf->global->MARGIN_METHODE_FOR_DISCOUNT);
224 print '</td>';
225 print '<td>';
226 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
227 print '</td>';
228 print '<td>'.$langs->trans('MARGIN_METHODE_FOR_DISCOUNT_DETAILS').'</td>';
229 print '</tr>';
230 print '</form>';
231 
232 // INTERNAL CONTACT TYPE USED AS COMMERCIAL AGENT
233 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
234 print '<input type="hidden" name="token" value="'.newToken().'">';
235 print "<input type=\"hidden\" name=\"action\" value=\"contact\">";
236 print '<tr class="oddeven">';
237 print '<td>'.$langs->trans("AgentContactType").'</td>';
238 print '<td class="left">';
239 $formcompany = new FormCompany($db);
240 $facture = new Facture($db);
241 print $formcompany->selectTypeContact($facture, $conf->global->AGENT_CONTACT_TYPE, "AGENT_CONTACT_TYPE", "internal", "code", 1);
242 print '</td>';
243 print '<td>';
244 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
245 print '</td>';
246 print '<td>'.$langs->trans('AgentContactTypeDetails').'</td>';
247 print '</tr>';
248 print '</form>';
249 
250 print '</table>';
251 
252 print dol_get_fiche_end();
253 
254 print '<br>';
255 
256 // End of page
257 llxFooter();
258 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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=0, $moreparamonempty= '', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
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:575
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:499
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0)
On/off button for constant.
Definition: ajax.lib.php:503
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage invoices.
marges_admin_prepare_head()
Define head array for tabs of marges tools setup pages.
Definition: margins.lib.php:31
llxFooter()
Empty footer.
Definition: wrapper.php:59