dolibarr  7.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-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 $langs->load("companies");
30 $langs->load("orders");
31 $langs->load("bills");
32 
33 $id=GETPOST("id",'int');
34 
35 $socid = GETPOST('id','int');
36 // Security check
37 if ($user->societe_id > 0)
38 {
39  $socid = $user->societe_id;
40 }
41 
42 $backtopage = GETPOST('backtopage','alpha');
43 
44 
45 /*
46  * Actions
47  */
48 
49 if (GETPOST('cancel','alpha') && ! empty($backtopage))
50 {
51  header("Location: ".$backtopage);
52  exit;
53 }
54 
55 if (GETPOST('action','aZ09') == 'setremise')
56 {
57  $object = new Societe($db);
58  $object->fetch($id);
59  $result=$object->set_remise_client(price2num(GETPOST("remise")),GETPOST("note"),$user);
60 
61  if ($result > 0)
62  {
63  if (! empty($backtopage))
64  {
65  header("Location: ".$backtopage);
66  exit;
67  }
68  else
69  {
70  header("Location: remise.php?id=".$_GET["id"]);
71  exit;
72  }
73  }
74  else
75  {
76  setEventMessages($object->error, $object->errors, 'errors');
77  }
78 }
79 
80 
81 /*
82  * View
83  */
84 
85 $form=new Form($db);
86 
87 llxHeader();
88 
89 
90 /*********************************************************************************
91  *
92  * Mode fiche
93  *
94  *********************************************************************************/
95 if ($socid > 0)
96 {
97  // On recupere les donnees societes par l'objet
98  $object = new Societe($db);
99  $object->fetch($socid);
100 
101  $head = societe_prepare_head($object);
102 
103 
104 
105  print '<form method="POST" action="remise.php?id='.$object->id.'">';
106  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
107  print '<input type="hidden" name="action" value="setremise">';
108  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
109 
110  dol_fiche_head($head, 'relativediscount', $langs->trans("ThirdParty"), 0, 'company');
111 
112  dol_banner_tab($object, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom');
113 
114  print '<div class="fichecenter">';
115 
116  print '<div class="underbanner clearboth"></div>';
117  print '<table class="border centpercent">';
118 
119  // Discount
120  print '<tr><td class="titlefield">';
121  print $langs->trans("CustomerRelativeDiscount").'</td><td>'.price2num($object->remise_percent)."%</td></tr>";
122  print '</table>';
123  print '<br>';
124 
125  print load_fiche_titre($langs->trans("NewRelativeDiscount"),'','');
126 
127  print '<div class="underbanner clearboth"></div>';
128 
129  print '<table class="border centpercent">';
130 
131  // New value
132  print '<tr><td class="titlefield fieldrequired">';
133  print $langs->trans("NewValue").'</td><td><input type="text" size="5" name="remise" value="'.dol_escape_htmltag(GETPOST("remise")).'">%</td></tr>';
134 
135  // Motif/Note
136  print '<tr><td class="fieldrequired">';
137  print $langs->trans("NoteReason").'</td><td><input type="text" size="60" name="note" value="'.dol_escape_htmltag(GETPOST("note")).'"></td></tr>';
138 
139  print "</table>";
140 
141  print '</div>';
142 
143  dol_fiche_end();
144 
145  print '<div class="center">';
146  print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
147  if (! empty($backtopage))
148  {
149  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
150  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
151  }
152  print '</div>';
153 
154  print "</form>";
155 
156  print '<br>';
157 
158 
159  /*
160  * List log of all percent discounts
161  */
162  $sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,";
163  $sql.= " u.login, u.rowid as user_id";
164  $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
165  $sql.= " WHERE rc.fk_soc = " . $object->id;
166  $sql.= " AND rc.entity = " . $conf->entity;
167  $sql.= " AND u.rowid = rc.fk_user_author";
168  $sql.= " ORDER BY rc.datec DESC";
169 
170  $resql=$db->query($sql);
171  if ($resql)
172  {
173  print '<table class="noborder" width="100%">';
174  $tag = !$tag;
175  print '<tr class="liste_titre">';
176  print '<td width="160">'.$langs->trans("Date").'</td>';
177  print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
178  print '<td align="left">'.$langs->trans("NoteReason").'</td>';
179  print '<td align="center">'.$langs->trans("User").'</td>';
180  print '</tr>';
181  $num = $db->num_rows($resql);
182  if ($num > 0)
183  {
184  $i = 0;
185  while ($i < $num)
186  {
187  $obj = $db->fetch_object($resql);
188  print '<tr class="oddeven">';
189  print '<td>'.dol_print_date($db->jdate($obj->dc),"dayhour").'</td>';
190  print '<td align="center">'.price2num($obj->remise_percent).'%</td>';
191  print '<td align="left">'.$obj->note.'</td>';
192  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>';
193  print '</tr>';
194  $i++;
195  }
196  }
197  else
198  {
199  print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
200  }
201  $db->free($resql);
202  print "</table>";
203  }
204  else
205  {
206  dol_print_error($db);
207  }
208 
209 }
210 
211 llxFooter();
212 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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...
if(empty($reshook)) $form
View.
Definition: perms.php:103
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...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:40
print
Draft customers invoices.
Definition: index.php:91
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:1013
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...