remise.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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 '<div class="center">';
  148. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  149. if (!empty($backtopage)) {
  150. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  151. print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  152. }
  153. print '</div>';
  154. print "</form>";
  155. print '<br>';
  156. if ($isCustomer) {
  157. if ($isSupplier) {
  158. print '<div class="fichecenter">';
  159. print '<div class="fichehalfleft">';
  160. print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
  161. }
  162. /*
  163. * List log of all customer percent discounts
  164. */
  165. $sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,";
  166. $sql .= " u.login, u.rowid as user_id";
  167. $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
  168. $sql .= " WHERE rc.fk_soc = ".$object->id;
  169. $sql .= " AND rc.entity IN (".getEntity('discount').")";
  170. $sql .= " AND u.rowid = rc.fk_user_author";
  171. $sql .= " ORDER BY rc.datec DESC";
  172. $resql = $db->query($sql);
  173. if ($resql) {
  174. print '<table class="noborder centpercent">';
  175. $tag = !$tag;
  176. print '<tr class="liste_titre">';
  177. print '<td width="160">'.$langs->trans("Date").'</td>';
  178. print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
  179. print '<td class="left">'.$langs->trans("NoteReason").'</td>';
  180. print '<td class="center">'.$langs->trans("User").'</td>';
  181. print '</tr>';
  182. $num = $db->num_rows($resql);
  183. if ($num > 0) {
  184. $i = 0;
  185. while ($i < $num) {
  186. $obj = $db->fetch_object($resql);
  187. print '<tr class="oddeven">';
  188. print '<td>'.dol_print_date($db->jdate($obj->dc), "dayhour").'</td>';
  189. print '<td class="center">'.price2num($obj->remise_percent).'%</td>';
  190. print '<td class="left">'.$obj->note.'</td>';
  191. 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>';
  192. print '</tr>';
  193. $i++;
  194. }
  195. } else {
  196. print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  197. }
  198. $db->free($resql);
  199. print "</table>";
  200. } else {
  201. dol_print_error($db);
  202. }
  203. }
  204. if ($isSupplier) {
  205. if ($isCustomer) {
  206. print '</div>'; // class="fichehalfleft"
  207. print '<div class="fichehalfright">';
  208. print '<div class="ficheaddleft">';
  209. print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
  210. }
  211. /*
  212. * List log of all supplier percent discounts
  213. */
  214. $sql = "SELECT rc.rowid, rc.remise_supplier 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_supplier as rc, ".MAIN_DB_PREFIX."user as u";
  217. $sql .= " WHERE rc.fk_soc = ".$object->id;
  218. $sql .= " AND rc.entity IN (".getEntity('discount').")";
  219. $sql .= " AND u.rowid = rc.fk_user_author";
  220. $sql .= " ORDER BY rc.datec DESC";
  221. $resql = $db->query($sql);
  222. if ($resql) {
  223. print '<table class="noborder centpercent">';
  224. $tag = !$tag;
  225. print '<tr class="liste_titre">';
  226. print '<td width="160">'.$langs->trans("Date").'</td>';
  227. print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
  228. print '<td class="left">'.$langs->trans("NoteReason").'</td>';
  229. print '<td class="center">'.$langs->trans("User").'</td>';
  230. print '</tr>';
  231. $num = $db->num_rows($resql);
  232. if ($num > 0) {
  233. $i = 0;
  234. while ($i < $num) {
  235. $obj = $db->fetch_object($resql);
  236. print '<tr class="oddeven">';
  237. print '<td>'.dol_print_date($db->jdate($obj->dc), "dayhour").'</td>';
  238. print '<td class="center">'.price2num($obj->remise_percent).'%</td>';
  239. print '<td class="left">'.$obj->note.'</td>';
  240. 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>';
  241. print '</tr>';
  242. $i++;
  243. }
  244. } else {
  245. print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  246. }
  247. $db->free($resql);
  248. print "</table>";
  249. } else {
  250. dol_print_error($db);
  251. }
  252. if ($isCustomer) {
  253. print '</div>'; // class="ficheaddleft"
  254. print '</div>'; // class="fichehalfright"
  255. print '</div>'; // class="fichecenter"
  256. }
  257. }
  258. }
  259. // End of page
  260. llxFooter();
  261. $db->close();