dolibarr  16.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  *
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 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
28 
29 // Load translation files required by the page
30 $langs->loadLangs(array('companies', 'orders', 'bills'));
31 
32 $id = GETPOST("id", 'int');
33 
34 $socid = GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('socid', 'int');
35 // Security check
36 if ($user->socid > 0) {
37  $socid = $user->socid;
38 }
39 
40 $backtopage = GETPOST('backtopage', 'alpha');
41 $cancel = GETPOST('cancel', 'aplha');
42 $action = GETPOST('action', 'aZ09');
43 
44 // Security check
45 if ($user->socid > 0) {
46  $id = $user->socid;
47 }
48 $result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
49 
50 
51 /*
52  * Actions
53  */
54 
55 if ($cancel) {
56  if (!empty($backtopage)) {
57  header("Location: ".$backtopage);
58  exit;
59  } else {
60  $action = '';
61  }
62 }
63 
64 if ($action == 'setremise') {
65  $object = new Societe($db);
66  $object->fetch($id);
67 
68  $discount_type = GETPOST('discount_type', 'int');
69 
70  if (!empty($discount_type)) {
71  $result = $object->set_remise_supplier(price2num(GETPOST("remise")), GETPOST("note", "alphanohtml"), $user);
72  } else {
73  $result = $object->set_remise_client(price2num(GETPOST("remise")), GETPOST("note", "alphanohtml"), $user);
74  }
75 
76  if ($result > 0) {
77  if (!empty($backtopage)) {
78  header("Location: ".$backtopage);
79  exit;
80  } else {
81  header("Location: remise.php?id=".GETPOST("id", 'int'));
82  exit;
83  }
84  } else {
85  setEventMessages($object->error, $object->errors, 'errors');
86  }
87 }
88 
89 
90 
91 /*
92  * View
93  */
94 
95 $form = new Form($db);
96 
97 llxHeader();
98 
99 /*********************************************************************************
100  *
101  * Mode fiche
102  *
103  *********************************************************************************/
104 if ($socid > 0) {
105  // On recupere les donnees societes par l'objet
106  $object = new Societe($db);
107  $object->fetch($socid);
108 
109  $head = societe_prepare_head($object);
110 
111  $isCustomer = ($object->client == 1 || $object->client == 3);
112  $isSupplier = $object->fournisseur == 1;
113 
114  print '<form method="POST" action="remise.php?id='.$object->id.'">';
115  print '<input type="hidden" name="token" value="'.newToken().'">';
116  print '<input type="hidden" name="action" value="setremise">';
117  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
118 
119  print dol_get_fiche_head($head, 'relativediscount', $langs->trans("ThirdParty"), -1, 'company');
120 
121  dol_banner_tab($object, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
122 
123  print '<div class="fichecenter">';
124 
125  print '<div class="underbanner clearboth"></div>';
126 
127  if (!$isCustomer && !$isSupplier) {
128  print '<p class="opacitymedium">'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'</p>';
129 
130  print dol_get_fiche_end();
131 
132  print '</form>';
133 
134  // End of page
135  llxFooter();
136  $db->close();
137  exit;
138  }
139 
140  print '<table class="border centpercent">';
141 
142  if ($isCustomer) {
143  // Customer discount
144  print '<tr><td class="titlefield">';
145  print $langs->trans("CustomerRelativeDiscount").'</td><td>'.price2num($object->remise_percent)."%</td></tr>";
146  }
147 
148  if ($isSupplier) {
149  // Supplier discount
150  print '<tr><td class="titlefield">';
151  print $langs->trans("SupplierRelativeDiscount").'</td><td>'.price2num($object->remise_supplier_percent)."%</td></tr>";
152  }
153 
154  print '</table>';
155  print '<br>';
156 
157  print load_fiche_titre($langs->trans("NewRelativeDiscount"), '', '');
158 
159  print '<div class="underbanner clearboth"></div>';
160 
161  /*if (! ($isCustomer && $isSupplier))
162  {
163  if ($isCustomer && ! $isSupplier) {
164  print '<input type="hidden" name="discount_type" value="0" />';
165  }
166  if (! $isCustomer && $isSupplier) {
167  print '<input type="hidden" name="discount_type" value="1" />';
168  }
169  }*/
170 
171  print '<table class="border centpercent">';
172 
173  if ($isCustomer || $isSupplier) {
174  // Discount type
175  print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td><td>';
176  if ($isCustomer) {
177  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>';
178  }
179  if ($isSupplier) {
180  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>';
181  }
182  print '</td></tr>';
183  }
184 
185  // New value
186  print '<tr><td class="titlefield fieldrequired">';
187  print $langs->trans("NewValue").'</td><td><input type="text" size="5" name="remise" value="'.dol_escape_htmltag(GETPOST("remise")).'">%</td></tr>';
188 
189  // Motif/Note
190  print '<tr><td class="fieldrequired">';
191  print $langs->trans("NoteReason").'</td><td><input type="text" size="60" name="note" value="'.dol_escape_htmltag(GETPOST("note", "alphanohtml")).'"></td></tr>';
192 
193  print "</table>";
194 
195  print '</div>';
196 
197  print dol_get_fiche_end();
198 
199  print $form->buttonsSaveCancel("Modify");
200 
201  print "</form>";
202 
203  print '<br>';
204 
205  if ($isCustomer) {
206  if ($isSupplier) {
207  print '<div class="fichecenter">';
208  print '<div class="fichehalfleft">';
209  print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
210  }
211 
212  /*
213  * List log of all customer percent discounts
214  */
215  $sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,";
216  $sql .= " u.login, u.rowid as user_id";
217  $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
218  $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
219  $sql .= " AND rc.entity IN (".getEntity('discount').")";
220  $sql .= " AND u.rowid = rc.fk_user_author";
221  $sql .= " ORDER BY rc.datec DESC";
222 
223  $resql = $db->query($sql);
224  if ($resql) {
225  print '<table class="noborder centpercent">';
226  $tag = !$tag;
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" class="opacitymedium">'.$langs->trans("None").'</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  $tag = !$tag;
278  print '<tr class="liste_titre">';
279  print '<td width="160">'.$langs->trans("Date").'</td>';
280  print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
281  print '<td class="left">'.$langs->trans("NoteReason").'</td>';
282  print '<td class="center">'.$langs->trans("User").'</td>';
283  print '</tr>';
284  $num = $db->num_rows($resql);
285  if ($num > 0) {
286  $i = 0;
287  while ($i < $num) {
288  $obj = $db->fetch_object($resql);
289  print '<tr class="oddeven">';
290  print '<td>'.dol_print_date($db->jdate($obj->dc), "dayhour").'</td>';
291  print '<td class="center">'.price2num($obj->remise_percent).'%</td>';
292  print '<td class="left">'.$obj->note.'</td>';
293  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>';
294  print '</tr>';
295  $i++;
296  }
297  } else {
298  print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
299  }
300  $db->free($resql);
301  print "</table>";
302  } else {
303  dol_print_error($db);
304  }
305 
306  if ($isCustomer) {
307  print '</div>'; // class="fichehalfright"
308  print '</div>'; // class="fichecenter"
309  }
310  }
311 }
312 
313 // End of page
314 llxFooter();
315 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
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.
Definition: functions.lib.php:2046
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
societe_prepare_head
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59