dolibarr  9.0.0
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-2015 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 <http://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->societe_id > 0)
37 {
38  $socid = $user->societe_id;
39 }
40 
41 $backtopage = GETPOST('backtopage','alpha');
42 
43 
44 /*
45  * Actions
46  */
47 
48 if (GETPOST('cancel','alpha') && ! empty($backtopage))
49 {
50  header("Location: ".$backtopage);
51  exit;
52 }
53 
54 if (GETPOST('action','aZ09') == 'setremise')
55 {
56  $object = new Societe($db);
57  $object->fetch($id);
58 
59  $discount_type = GETPOST('discount_type', 'int');
60 
61  if(! empty($discount_type)) {
62  $result=$object->set_remise_supplier(price2num(GETPOST("remise")),GETPOST("note"),$user);
63  } else {
64  $result=$object->set_remise_client(price2num(GETPOST("remise")),GETPOST("note"),$user);
65  }
66 
67  if ($result > 0)
68  {
69  if (! empty($backtopage))
70  {
71  header("Location: ".$backtopage);
72  exit;
73  }
74  else
75  {
76  header("Location: remise.php?id=".$_GET["id"]);
77  exit;
78  }
79  }
80  else
81  {
82  setEventMessages($object->error, $object->errors, 'errors');
83  }
84 }
85 
86 
87 /*
88  * View
89  */
90 
91 $form=new Form($db);
92 
93 llxHeader();
94 
95 
96 /*********************************************************************************
97  *
98  * Mode fiche
99  *
100  *********************************************************************************/
101 if ($socid > 0)
102 {
103  // On recupere les donnees societes par l'objet
104  $object = new Societe($db);
105  $object->fetch($socid);
106 
107  $head = societe_prepare_head($object);
108 
109  $isCustomer = $object->client == 1 || $object->client == 3;
110  $isSupplier = $object->fournisseur == 1;
111 
112  print '<form method="POST" action="remise.php?id='.$object->id.'">';
113  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
114  print '<input type="hidden" name="action" value="setremise">';
115  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
116 
117  dol_fiche_head($head, 'relativediscount', $langs->trans("ThirdParty"), -1, 'company');
118 
119  dol_banner_tab($object, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom');
120 
121  print '<div class="fichecenter">';
122 
123  print '<div class="underbanner clearboth"></div>';
124 
125  if(! $isCustomer && ! $isSupplier) {
126  print '<p class="opacitymedium">'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'</p>';
127 
128  dol_fiche_end();
129 
130  print '</form>';
131 
132  // End of page
133  llxFooter();
134  $db->close();
135  exit;
136  }
137 
138  print '<table class="border centpercent">';
139 
140  if($isCustomer) {
141  // Customer discount
142  print '<tr><td class="titlefield">';
143  print $langs->trans("CustomerRelativeDiscount").'</td><td>'.price2num($object->remise_percent)."%</td></tr>";
144  }
145 
146  if($isSupplier) {
147  // Supplier discount
148  print '<tr><td class="titlefield">';
149  print $langs->trans("SupplierRelativeDiscount").'</td><td>'.price2num($object->remise_supplier_percent)."%</td></tr>";
150  }
151 
152  print '</table>';
153  print '<br>';
154 
155  print load_fiche_titre($langs->trans("NewRelativeDiscount"),'','');
156 
157  print '<div class="underbanner clearboth"></div>';
158 
159  if($isCustomer && ! $isSupplier) {
160  print '<input type="hidden" name="discount_type" value="0" />';
161  }
162 
163  if(! $isCustomer && $isSupplier) {
164  print '<input type="hidden" name="discount_type" value="1" />';
165  }
166 
167  print '<table class="border centpercent">';
168 
169  if($isCustomer && $isSupplier) {
170  // Discount type
171  print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td>';
172  print '<td><input type="radio" name="discount_type" id="discount_type_0" selected value="0"/> <label for="discount_type_0">'.$langs->trans('Customer').'</label>';
173  print ' <input type="radio" name="discount_type" id="discount_type_1" selected value="1"/> <label for="discount_type_1">'.$langs->trans('Supplier').'</label>';
174  print '</td></tr>';
175  }
176 
177  // New value
178  print '<tr><td class="titlefield fieldrequired">';
179  print $langs->trans("NewValue").'</td><td><input type="text" size="5" name="remise" value="'.dol_escape_htmltag(GETPOST("remise")).'">%</td></tr>';
180 
181  // Motif/Note
182  print '<tr><td class="fieldrequired">';
183  print $langs->trans("NoteReason").'</td><td><input type="text" size="60" name="note" value="'.dol_escape_htmltag(GETPOST("note")).'"></td></tr>';
184 
185  print "</table>";
186 
187  print '</div>';
188 
189  dol_fiche_end();
190 
191  print '<div class="center">';
192  print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
193  if (! empty($backtopage))
194  {
195  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
196  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
197  }
198  print '</div>';
199 
200  print "</form>";
201 
202  print '<br>';
203 
204  if($isCustomer) {
205  if($isSupplier) {
206  print '<div class="fichecenter">';
207  print '<div class="fichehalfleft">';
208  print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
209  }
210 
211  /*
212  * List log of all customer percent discounts
213  */
214  $sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,";
215  $sql.= " u.login, u.rowid as user_id";
216  $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
217  $sql.= " WHERE rc.fk_soc = " . $object->id;
218  $sql.= " AND rc.entity = " . $conf->entity;
219  $sql.= " AND u.rowid = rc.fk_user_author";
220  $sql.= " ORDER BY rc.datec DESC";
221 
222  $resql=$db->query($sql);
223  if ($resql)
224  {
225  print '<table class="noborder" width="100%">';
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 align="left">'.$langs->trans("NoteReason").'</td>';
231  print '<td align="center">'.$langs->trans("User").'</td>';
232  print '</tr>';
233  $num = $db->num_rows($resql);
234  if ($num > 0)
235  {
236  $i = 0;
237  while ($i < $num)
238  {
239  $obj = $db->fetch_object($resql);
240  print '<tr class="oddeven">';
241  print '<td>'.dol_print_date($db->jdate($obj->dc),"dayhour").'</td>';
242  print '<td align="center">'.price2num($obj->remise_percent).'%</td>';
243  print '<td align="left">'.$obj->note.'</td>';
244  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>';
245  print '</tr>';
246  $i++;
247  }
248  }
249  else
250  {
251  print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
252  }
253  $db->free($resql);
254  print "</table>";
255  }
256  else
257  {
258  dol_print_error($db);
259  }
260  }
261 
262  if($isSupplier) {
263  if($isCustomer) {
264  print '</div>'; // class="fichehalfleft"
265  print '<div class="fichehalfright">';
266  print '<div class="ficheaddleft">';
267  print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
268  }
269 
270  /*
271  * List log of all supplier percent discounts
272  */
273  $sql = "SELECT rc.rowid, rc.remise_supplier as remise_percent, rc.note, rc.datec as dc,";
274  $sql.= " u.login, u.rowid as user_id";
275  $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_supplier as rc, ".MAIN_DB_PREFIX."user as u";
276  $sql.= " WHERE rc.fk_soc = " . $object->id;
277  $sql.= " AND rc.entity = " . $conf->entity;
278  $sql.= " AND u.rowid = rc.fk_user_author";
279  $sql.= " ORDER BY rc.datec DESC";
280 
281  $resql=$db->query($sql);
282  if ($resql)
283  {
284  print '<table class="noborder" width="100%">';
285  $tag = !$tag;
286  print '<tr class="liste_titre">';
287  print '<td width="160">'.$langs->trans("Date").'</td>';
288  print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
289  print '<td align="left">'.$langs->trans("NoteReason").'</td>';
290  print '<td align="center">'.$langs->trans("User").'</td>';
291  print '</tr>';
292  $num = $db->num_rows($resql);
293  if ($num > 0)
294  {
295  $i = 0;
296  while ($i < $num)
297  {
298  $obj = $db->fetch_object($resql);
299  print '<tr class="oddeven">';
300  print '<td>'.dol_print_date($db->jdate($obj->dc),"dayhour").'</td>';
301  print '<td align="center">'.price2num($obj->remise_percent).'%</td>';
302  print '<td align="left">'.$obj->note.'</td>';
303  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>';
304  print '</tr>';
305  $i++;
306  }
307  }
308  else
309  {
310  print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
311  }
312  $db->free($resql);
313  print "</table>";
314  }
315  else
316  {
317  dol_print_error($db);
318  }
319 
320  if($isCustomer) {
321  print '</div>'; // class="ficheaddleft"
322  print '</div>'; // class="fichehalfright"
323  print '</div>'; // class="fichecenter"
324  }
325  }
326 }
327 
328 // End of page
329 llxFooter();
330 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
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.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)