remise.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/comm/remise.php
  20. * \ingroup societe
  21. * \brief Page to edit relative discount of a customer
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  26. // Load translation files required by the page
  27. $langs->loadLangs(array('companies', 'orders', 'bills'));
  28. $id = GETPOST("id", 'int');
  29. $socid = GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('socid', 'int');
  30. // Security check
  31. if ($user->socid > 0) {
  32. $socid = $user->socid;
  33. }
  34. $backtopage = GETPOST('backtopage', 'alpha');
  35. /*
  36. * Actions
  37. */
  38. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  39. header("Location: ".$backtopage);
  40. exit;
  41. }
  42. if (GETPOST('action', 'aZ09') == 'setremise') {
  43. $object = new Societe($db);
  44. $object->fetch($id);
  45. $discount_type = GETPOST('discount_type', 'int');
  46. if (!empty($discount_type)) {
  47. $result = $object->set_remise_supplier(price2num(GETPOST("remise")), GETPOST("note", "alphanohtml"), $user);
  48. } else {
  49. $result = $object->set_remise_client(price2num(GETPOST("remise")), GETPOST("note", "alphanohtml"), $user);
  50. }
  51. if ($result > 0) {
  52. if (!empty($backtopage)) {
  53. header("Location: ".$backtopage);
  54. exit;
  55. } else {
  56. header("Location: remise.php?id=".GETPOST("id", 'int'));
  57. exit;
  58. }
  59. } else {
  60. setEventMessages($object->error, $object->errors, 'errors');
  61. }
  62. }
  63. // Security check
  64. if ($user->socid > 0) {
  65. $id = $user->socid;
  66. }
  67. $result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
  68. /*
  69. * View
  70. */
  71. $form = new Form($db);
  72. llxHeader();
  73. /*********************************************************************************
  74. *
  75. * Mode fiche
  76. *
  77. *********************************************************************************/
  78. if ($socid > 0) {
  79. // On recupere les donnees societes par l'objet
  80. $object = new Societe($db);
  81. $object->fetch($socid);
  82. $head = societe_prepare_head($object);
  83. $isCustomer = ($object->client == 1 || $object->client == 3);
  84. $isSupplier = $object->fournisseur == 1;
  85. print '<form method="POST" action="remise.php?id='.$object->id.'">';
  86. print '<input type="hidden" name="token" value="'.newToken().'">';
  87. print '<input type="hidden" name="action" value="setremise">';
  88. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  89. print dol_get_fiche_head($head, 'relativediscount', $langs->trans("ThirdParty"), -1, 'company');
  90. dol_banner_tab($object, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
  91. print '<div class="fichecenter">';
  92. print '<div class="underbanner clearboth"></div>';
  93. if (!$isCustomer && !$isSupplier) {
  94. print '<p class="opacitymedium">'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'</p>';
  95. print dol_get_fiche_end();
  96. print '</form>';
  97. // End of page
  98. llxFooter();
  99. $db->close();
  100. exit;
  101. }
  102. print '<table class="border centpercent">';
  103. if ($isCustomer) {
  104. // Customer discount
  105. print '<tr><td class="titlefield">';
  106. print $langs->trans("CustomerRelativeDiscount").'</td><td>'.price2num($object->remise_percent)."%</td></tr>";
  107. }
  108. if ($isSupplier) {
  109. // Supplier discount
  110. print '<tr><td class="titlefield">';
  111. print $langs->trans("SupplierRelativeDiscount").'</td><td>'.price2num($object->remise_supplier_percent)."%</td></tr>";
  112. }
  113. print '</table>';
  114. print '<br>';
  115. print load_fiche_titre($langs->trans("NewRelativeDiscount"), '', '');
  116. print '<div class="underbanner clearboth"></div>';
  117. /*if (! ($isCustomer && $isSupplier))
  118. {
  119. if ($isCustomer && ! $isSupplier) {
  120. print '<input type="hidden" name="discount_type" value="0" />';
  121. }
  122. if (! $isCustomer && $isSupplier) {
  123. print '<input type="hidden" name="discount_type" value="1" />';
  124. }
  125. }*/
  126. print '<table class="border centpercent">';
  127. if ($isCustomer || $isSupplier) {
  128. // Discount type
  129. print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td><td>';
  130. if ($isCustomer) {
  131. 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>';
  132. }
  133. if ($isSupplier) {
  134. 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>';
  135. }
  136. print '</td></tr>';
  137. }
  138. // New value
  139. print '<tr><td class="titlefield fieldrequired">';
  140. print $langs->trans("NewValue").'</td><td><input type="text" size="5" name="remise" value="'.dol_escape_htmltag(GETPOST("remise")).'">%</td></tr>';
  141. // Motif/Note
  142. print '<tr><td class="fieldrequired">';
  143. print $langs->trans("NoteReason").'</td><td><input type="text" size="60" name="note" value="'.dol_escape_htmltag(GETPOST("note", "alphanohtml")).'"></td></tr>';
  144. print "</table>";
  145. print '</div>';
  146. print dol_get_fiche_end();
  147. print $form->buttonsSaveCancel("Modify");
  148. print "</form>";
  149. print '<br>';
  150. if ($isCustomer) {
  151. if ($isSupplier) {
  152. print '<div class="fichecenter">';
  153. print '<div class="fichehalfleft">';
  154. print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
  155. }
  156. /*
  157. * List log of all customer percent discounts
  158. */
  159. $sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,";
  160. $sql .= " u.login, u.rowid as user_id";
  161. $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
  162. $sql .= " WHERE rc.fk_soc = ".$object->id;
  163. $sql .= " AND rc.entity IN (".getEntity('discount').")";
  164. $sql .= " AND u.rowid = rc.fk_user_author";
  165. $sql .= " ORDER BY rc.datec DESC";
  166. $resql = $db->query($sql);
  167. if ($resql) {
  168. print '<table class="noborder centpercent">';
  169. $tag = !$tag;
  170. print '<tr class="liste_titre">';
  171. print '<td width="160">'.$langs->trans("Date").'</td>';
  172. print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
  173. print '<td class="left">'.$langs->trans("NoteReason").'</td>';
  174. print '<td class="center">'.$langs->trans("User").'</td>';
  175. print '</tr>';
  176. $num = $db->num_rows($resql);
  177. if ($num > 0) {
  178. $i = 0;
  179. while ($i < $num) {
  180. $obj = $db->fetch_object($resql);
  181. print '<tr class="oddeven">';
  182. print '<td>'.dol_print_date($db->jdate($obj->dc), "dayhour").'</td>';
  183. print '<td class="center">'.price2num($obj->remise_percent).'%</td>';
  184. print '<td class="left">'.$obj->note.'</td>';
  185. 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>';
  186. print '</tr>';
  187. $i++;
  188. }
  189. } else {
  190. print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  191. }
  192. $db->free($resql);
  193. print "</table>";
  194. } else {
  195. dol_print_error($db);
  196. }
  197. }
  198. if ($isSupplier) {
  199. if ($isCustomer) {
  200. print '</div>'; // class="fichehalfleft"
  201. print '<div class="fichehalfright">';
  202. print '<div class="ficheaddleft">';
  203. print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
  204. }
  205. /*
  206. * List log of all supplier percent discounts
  207. */
  208. $sql = "SELECT rc.rowid, rc.remise_supplier as remise_percent, rc.note, rc.datec as dc,";
  209. $sql .= " u.login, u.rowid as user_id";
  210. $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_supplier as rc, ".MAIN_DB_PREFIX."user as u";
  211. $sql .= " WHERE rc.fk_soc = ".$object->id;
  212. $sql .= " AND rc.entity IN (".getEntity('discount').")";
  213. $sql .= " AND u.rowid = rc.fk_user_author";
  214. $sql .= " ORDER BY rc.datec DESC";
  215. $resql = $db->query($sql);
  216. if ($resql) {
  217. print '<table class="noborder centpercent">';
  218. $tag = !$tag;
  219. print '<tr class="liste_titre">';
  220. print '<td width="160">'.$langs->trans("Date").'</td>';
  221. print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
  222. print '<td class="left">'.$langs->trans("NoteReason").'</td>';
  223. print '<td class="center">'.$langs->trans("User").'</td>';
  224. print '</tr>';
  225. $num = $db->num_rows($resql);
  226. if ($num > 0) {
  227. $i = 0;
  228. while ($i < $num) {
  229. $obj = $db->fetch_object($resql);
  230. print '<tr class="oddeven">';
  231. print '<td>'.dol_print_date($db->jdate($obj->dc), "dayhour").'</td>';
  232. print '<td class="center">'.price2num($obj->remise_percent).'%</td>';
  233. print '<td class="left">'.$obj->note.'</td>';
  234. 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>';
  235. print '</tr>';
  236. $i++;
  237. }
  238. } else {
  239. print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  240. }
  241. $db->free($resql);
  242. print "</table>";
  243. } else {
  244. dol_print_error($db);
  245. }
  246. if ($isCustomer) {
  247. print '</div>'; // class="ficheaddleft"
  248. print '</div>'; // class="fichehalfright"
  249. print '</div>'; // class="fichecenter"
  250. }
  251. }
  252. }
  253. // End of page
  254. llxFooter();
  255. $db->close();