dolibarr 22.0.5
remise.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2021 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31
40// Load translation files required by the page
41$langs->loadLangs(array('companies', 'orders', 'bills'));
42
43$id = GETPOSTINT("id");
44
45$socid = GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('socid');
46// Security check
47if ($user->socid > 0) {
48 $socid = $user->socid;
49}
50
51$backtopage = GETPOST('backtopage', 'alpha');
52$cancel = GETPOST('cancel', 'alpha');
53$action = GETPOST('action', 'aZ09');
54
55// Security check
56if ($user->socid > 0) {
57 $id = $user->socid;
58}
59$result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
60
61
62/*
63 * Actions
64 */
65
66if ($cancel) {
67 if (!empty($backtopage)) {
68 header("Location: ".$backtopage);
69 exit;
70 } else {
71 $action = '';
72 }
73}
74
75if ($action == 'setremise' && $user->hasRight('societe', 'lire')) {
76 $object = new Societe($db);
77 $object->fetch($id);
78
79 $discount_type = GETPOSTINT('discount_type');
80
81 if (!empty($discount_type)) {
82 $result = $object->set_remise_supplier((float) price2num(GETPOST("remise")), GETPOST("note", "alphanohtml"), $user);
83 } else {
84 $result = $object->set_remise_client((float) price2num(GETPOST("remise")), GETPOST("note", "alphanohtml"), $user);
85 }
86
87 if ($result > 0) {
88 if (!empty($backtopage)) {
89 header("Location: ".$backtopage);
90 exit;
91 } else {
92 header("Location: remise.php?id=".GETPOSTINT("id"));
93 exit;
94 }
95 } else {
96 setEventMessages($object->error, $object->errors, 'errors');
97 }
98}
99
100
101
102/*
103 * View
104 */
105
106$form = new Form($db);
107
108if (! ($socid > 0)) {
109 accessforbidden('Record not found');
110}
111
112// On recupere les donnees societes par l'objet
113$object = new Societe($db);
114$object->fetch($socid);
115
116$title = $object->name;
117llxHeader('', $title);
118
119$head = societe_prepare_head($object);
120
121$isCustomer = ($object->client == 1 || $object->client == 3);
122$isSupplier = $object->fournisseur == 1;
123
124print '<form method="POST" action="remise.php?id='.$object->id.'">';
125print '<input type="hidden" name="token" value="'.newToken().'">';
126print '<input type="hidden" name="action" value="setremise">';
127print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
128
129print dol_get_fiche_head($head, 'relativediscount', $langs->trans("ThirdParty"), -1, 'company');
130
131dol_banner_tab($object, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
132
133print '<div class="fichecenter">';
134
135print '<div class="underbanner clearboth"></div>';
136
137if (!$isCustomer && !$isSupplier) {
138 print '<p class="opacitymedium">'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'</p>';
139
140 print dol_get_fiche_end();
141
142 print '</form>';
143
144 // End of page
145 llxFooter();
146 $db->close();
147 exit;
148}
149
150print '<table class="border centpercent">';
151
152if ($isCustomer) {
153 // Customer discount
154 print '<tr><td class="titlefield">';
155 print $langs->trans("CustomerRelativeDiscount").'</td><td>'.price2num($object->remise_percent)."%</td></tr>";
156}
157
158if ($isSupplier) {
159 // Supplier discount
160 print '<tr><td class="titlefield">';
161 print $langs->trans("SupplierRelativeDiscount").'</td><td>'.price2num($object->remise_supplier_percent)."%</td></tr>";
162}
163
164print '</table>';
165print '<br>';
166
167print load_fiche_titre($langs->trans("NewRelativeDiscount"), '', '');
168
169print '<div class="underbanner clearboth"></div>';
170
171/*if (! ($isCustomer && $isSupplier))
172{
173 if ($isCustomer && ! $isSupplier) {
174 print '<input type="hidden" name="discount_type" value="0" />';
175 }
176 if (! $isCustomer && $isSupplier) {
177 print '<input type="hidden" name="discount_type" value="1" />';
178 }
179}*/
180
181print '<table class="border centpercent marginbottomonly">';
182
183if ($isCustomer || $isSupplier) {
184 // Discount type
185 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td><td>';
186 if ($isCustomer) {
187 print '<input type="radio" name="discount_type" id="discount_type_0" '.(GETPOSTISSET('discount_type') ? (GETPOSTINT('discount_type') == 0 ? ' checked' : '') : ' checked').' value="0"> <label for="discount_type_0">'.$langs->trans('Customer').'</label>';
188 }
189 if ($isCustomer && $isSupplier) {
190 print ' &nbsp; ';
191 }
192 if ($isSupplier) {
193 print ' <input type="radio" name="discount_type" id="discount_type_1"'.(GETPOSTISSET('discount_type') ? (GETPOSTINT('discount_type') ? ' checked' : '') : ($isCustomer ? '' : ' checked')).' value="1"> <label for="discount_type_1">'.$langs->trans('Supplier').'</label>';
194 }
195 print '</td></tr>';
196}
197
198// New value
199print '<tr><td class="titlefield fieldrequired">';
200print $langs->trans("NewValue").'</td><td><input type="text" size="5" name="remise" value="'.dol_escape_htmltag(GETPOST("remise")).'">%</td></tr>';
201
202// Motif/Note
203print '<tr><td class="fieldrequired">';
204print $langs->trans("NoteReason").'</td><td><input type="text" size="60" name="note" value="'.dol_escape_htmltag(GETPOST("note", "alphanohtml")).'"></td></tr>';
205
206print "</table>";
207
208print '</div>';
209
210print $form->buttonsSaveCancel("Modify");
211
212print dol_get_fiche_end();
213
214print "</form>";
215
216
217print '<br>';
218
219
220if ($isCustomer) {
221 if ($isSupplier) {
222 print '<div class="fichecenter">';
223 print '<div class="fichehalfleft">';
224 print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
225 }
226
227 /*
228 * List log of all customer percent discounts
229 */
230 $sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,";
231 $sql .= " u.login, u.rowid as user_id";
232 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
233 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
234 $sql .= " AND rc.entity IN (".getEntity('discount').")";
235 $sql .= " AND u.rowid = rc.fk_user_author";
236 $sql .= " ORDER BY rc.datec DESC";
237
238 $resql = $db->query($sql);
239 if ($resql) {
240 print '<table class="noborder centpercent">';
241 print '<tr class="liste_titre">';
242 print '<td width="160">'.$langs->trans("Date").'</td>';
243 print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
244 print '<td class="left">'.$langs->trans("NoteReason").'</td>';
245 print '<td class="center">'.$langs->trans("User").'</td>';
246 print '</tr>';
247 $num = $db->num_rows($resql);
248 if ($num > 0) {
249 $i = 0;
250 while ($i < $num) {
251 $obj = $db->fetch_object($resql);
252 print '<tr class="oddeven">';
253 print '<td>'.dol_print_date($db->jdate($obj->dc), "dayhour").'</td>';
254 print '<td class="center">'.price2num($obj->remise_percent).'%</td>';
255 print '<td class="left">'.$obj->note.'</td>';
256 print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"), 'user').' '.$obj->login.'</a></td>';
257 print '</tr>';
258 $i++;
259 }
260 } else {
261 print '<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
262 }
263 $db->free($resql);
264 print "</table>";
265 } else {
266 dol_print_error($db);
267 }
268}
269
270if ($isSupplier) {
271 if ($isCustomer) {
272 print '</div>'; // class="fichehalfleft"
273 print '<div class="fichehalfright">';
274 print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
275 }
276
277 /*
278 * List log of all supplier percent discounts
279 */
280 $sql = "SELECT rc.rowid, rc.remise_supplier as remise_percent, rc.note, rc.datec as dc,";
281 $sql .= " u.login, u.rowid as user_id";
282 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_supplier as rc, ".MAIN_DB_PREFIX."user as u";
283 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
284 $sql .= " AND rc.entity IN (".getEntity('discount').")";
285 $sql .= " AND u.rowid = rc.fk_user_author";
286 $sql .= " ORDER BY rc.datec DESC";
287
288 $resql = $db->query($sql);
289 if ($resql) {
290 print '<table class="noborder centpercent">';
291 print '<tr class="liste_titre">';
292 print '<td width="160">'.$langs->trans("Date").'</td>';
293 print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
294 print '<td class="left">'.$langs->trans("NoteReason").'</td>';
295 print '<td class="center">'.$langs->trans("User").'</td>';
296 print '</tr>';
297 $num = $db->num_rows($resql);
298 if ($num > 0) {
299 $i = 0;
300 while ($i < $num) {
301 $obj = $db->fetch_object($resql);
302 print '<tr class="oddeven">';
303 print '<td>'.dol_print_date($db->jdate($obj->dc), "dayhour").'</td>';
304 print '<td class="center">'.price2num($obj->remise_percent).'%</td>';
305 print '<td class="left">'.$obj->note.'</td>';
306 print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"), 'user').' '.$obj->login.'</a></td>';
307 print '</tr>';
308 $i++;
309 }
310 } else {
311 print '<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
312 }
313 $db->free($resql);
314 print "</table>";
315 } else {
316 dol_print_error($db);
317 }
318
319 if ($isCustomer) {
320 print '</div>'; // class="fichehalfright"
321 print '</div>'; // class="fichecenter"
322 }
323}
324
325
326// End of page
327llxFooter();
328$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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 generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.