dolibarr 21.0.0-beta
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 *
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
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30
39// Load translation files required by the page
40$langs->loadLangs(array('companies', 'orders', 'bills'));
41
42$id = GETPOSTINT("id");
43
44$socid = GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('socid');
45// Security check
46if ($user->socid > 0) {
47 $socid = $user->socid;
48}
49
50$backtopage = GETPOST('backtopage', 'alpha');
51$cancel = GETPOST('cancel', 'alpha');
52$action = GETPOST('action', 'aZ09');
53
54// Security check
55if ($user->socid > 0) {
56 $id = $user->socid;
57}
58$result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
59
60
61/*
62 * Actions
63 */
64
65if ($cancel) {
66 if (!empty($backtopage)) {
67 header("Location: ".$backtopage);
68 exit;
69 } else {
70 $action = '';
71 }
72}
73
74if ($action == 'setremise' && $user->hasRight('societe', 'lire')) {
75 $object = new Societe($db);
76 $object->fetch($id);
77
78 $discount_type = GETPOSTINT('discount_type');
79
80 if (!empty($discount_type)) {
81 $result = $object->set_remise_supplier(price2num(GETPOST("remise")), GETPOST("note", "alphanohtml"), $user);
82 } else {
83 $result = $object->set_remise_client(price2num(GETPOST("remise")), GETPOST("note", "alphanohtml"), $user);
84 }
85
86 if ($result > 0) {
87 if (!empty($backtopage)) {
88 header("Location: ".$backtopage);
89 exit;
90 } else {
91 header("Location: remise.php?id=".GETPOSTINT("id"));
92 exit;
93 }
94 } else {
95 setEventMessages($object->error, $object->errors, 'errors');
96 }
97}
98
99
100
101/*
102 * View
103 */
104
105$form = new Form($db);
106
107if (! ($socid > 0)) {
108 accessforbidden('Record not found');
109}
110
111// On recupere les donnees societes par l'objet
112$object = new Societe($db);
113$object->fetch($socid);
114
115$title = $object->name;
116llxHeader('', $title);
117
118$head = societe_prepare_head($object);
119
120$isCustomer = ($object->client == 1 || $object->client == 3);
121$isSupplier = $object->fournisseur == 1;
122
123print '<form method="POST" action="remise.php?id='.$object->id.'">';
124print '<input type="hidden" name="token" value="'.newToken().'">';
125print '<input type="hidden" name="action" value="setremise">';
126print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
127
128print dol_get_fiche_head($head, 'relativediscount', $langs->trans("ThirdParty"), -1, 'company');
129
130dol_banner_tab($object, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
131
132print '<div class="fichecenter">';
133
134print '<div class="underbanner clearboth"></div>';
135
136if (!$isCustomer && !$isSupplier) {
137 print '<p class="opacitymedium">'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'</p>';
138
139 print dol_get_fiche_end();
140
141 print '</form>';
142
143 // End of page
144 llxFooter();
145 $db->close();
146 exit;
147}
148
149print '<table class="border centpercent">';
150
151if ($isCustomer) {
152 // Customer discount
153 print '<tr><td class="titlefield">';
154 print $langs->trans("CustomerRelativeDiscount").'</td><td>'.price2num($object->remise_percent)."%</td></tr>";
155}
156
157if ($isSupplier) {
158 // Supplier discount
159 print '<tr><td class="titlefield">';
160 print $langs->trans("SupplierRelativeDiscount").'</td><td>'.price2num($object->remise_supplier_percent)."%</td></tr>";
161}
162
163print '</table>';
164print '<br>';
165
166print load_fiche_titre($langs->trans("NewRelativeDiscount"), '', '');
167
168print '<div class="underbanner clearboth"></div>';
169
170/*if (! ($isCustomer && $isSupplier))
171{
172 if ($isCustomer && ! $isSupplier) {
173 print '<input type="hidden" name="discount_type" value="0" />';
174 }
175 if (! $isCustomer && $isSupplier) {
176 print '<input type="hidden" name="discount_type" value="1" />';
177 }
178}*/
179
180print '<table class="border centpercent marginbottomonly">';
181
182if ($isCustomer || $isSupplier) {
183 // Discount type
184 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td><td>';
185 if ($isCustomer) {
186 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>';
187 }
188 if ($isCustomer && $isSupplier) {
189 print ' &nbsp; ';
190 }
191 if ($isSupplier) {
192 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>';
193 }
194 print '</td></tr>';
195}
196
197// New value
198print '<tr><td class="titlefield fieldrequired">';
199print $langs->trans("NewValue").'</td><td><input type="text" size="5" name="remise" value="'.dol_escape_htmltag(GETPOST("remise")).'">%</td></tr>';
200
201// Motif/Note
202print '<tr><td class="fieldrequired">';
203print $langs->trans("NoteReason").'</td><td><input type="text" size="60" name="note" value="'.dol_escape_htmltag(GETPOST("note", "alphanohtml")).'"></td></tr>';
204
205print "</table>";
206
207print '</div>';
208
209print $form->buttonsSaveCancel("Modify");
210
211print dol_get_fiche_end();
212
213print "</form>";
214
215
216print '<br>';
217
218
219if ($isCustomer) {
220 if ($isSupplier) {
221 print '<div class="fichecenter">';
222 print '<div class="fichehalfleft">';
223 print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
224 }
225
226 /*
227 * List log of all customer percent discounts
228 */
229 $sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,";
230 $sql .= " u.login, u.rowid as user_id";
231 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
232 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
233 $sql .= " AND rc.entity IN (".getEntity('discount').")";
234 $sql .= " AND u.rowid = rc.fk_user_author";
235 $sql .= " ORDER BY rc.datec DESC";
236
237 $resql = $db->query($sql);
238 if ($resql) {
239 print '<table class="noborder centpercent">';
240 print '<tr class="liste_titre">';
241 print '<td width="160">'.$langs->trans("Date").'</td>';
242 print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
243 print '<td class="left">'.$langs->trans("NoteReason").'</td>';
244 print '<td class="center">'.$langs->trans("User").'</td>';
245 print '</tr>';
246 $num = $db->num_rows($resql);
247 if ($num > 0) {
248 $i = 0;
249 while ($i < $num) {
250 $obj = $db->fetch_object($resql);
251 print '<tr class="oddeven">';
252 print '<td>'.dol_print_date($db->jdate($obj->dc), "dayhour").'</td>';
253 print '<td class="center">'.price2num($obj->remise_percent).'%</td>';
254 print '<td class="left">'.$obj->note.'</td>';
255 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>';
256 print '</tr>';
257 $i++;
258 }
259 } else {
260 print '<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
261 }
262 $db->free($resql);
263 print "</table>";
264 } else {
265 dol_print_error($db);
266 }
267}
268
269if ($isSupplier) {
270 if ($isCustomer) {
271 print '</div>'; // class="fichehalfleft"
272 print '<div class="fichehalfright">';
273 print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
274 }
275
276 /*
277 * List log of all supplier percent discounts
278 */
279 $sql = "SELECT rc.rowid, rc.remise_supplier as remise_percent, rc.note, rc.datec as dc,";
280 $sql .= " u.login, u.rowid as user_id";
281 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_supplier as rc, ".MAIN_DB_PREFIX."user as u";
282 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
283 $sql .= " AND rc.entity IN (".getEntity('discount').")";
284 $sql .= " AND u.rowid = rc.fk_user_author";
285 $sql .= " ORDER BY rc.datec DESC";
286
287 $resql = $db->query($sql);
288 if ($resql) {
289 print '<table class="noborder centpercent">';
290 print '<tr class="liste_titre">';
291 print '<td width="160">'.$langs->trans("Date").'</td>';
292 print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
293 print '<td class="left">'.$langs->trans("NoteReason").'</td>';
294 print '<td class="center">'.$langs->trans("User").'</td>';
295 print '</tr>';
296 $num = $db->num_rows($resql);
297 if ($num > 0) {
298 $i = 0;
299 while ($i < $num) {
300 $obj = $db->fetch_object($resql);
301 print '<tr class="oddeven">';
302 print '<td>'.dol_print_date($db->jdate($obj->dc), "dayhour").'</td>';
303 print '<td class="center">'.price2num($obj->remise_percent).'%</td>';
304 print '<td class="left">'.$obj->note.'</td>';
305 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>';
306 print '</tr>';
307 $i++;
308 }
309 } else {
310 print '<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
311 }
312 $db->free($resql);
313 print "</table>";
314 } else {
315 dol_print_error($db);
316 }
317
318 if ($isCustomer) {
319 print '</div>'; // class="fichehalfright"
320 print '</div>'; // class="fichecenter"
321 }
322}
323
324
325// End of page
326llxFooter();
327$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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 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.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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)
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.
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.