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