multiprix.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/comm/multiprix.php
  21. * \ingroup societe
  22. * \brief Tab to set the price level of a thirdparty
  23. */
  24. // Load Dolibarr environment
  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. // Load translation files required by the page
  29. $langs->loadLangs(array('orders', 'companies'));
  30. $action = GETPOST('action', 'alpha');
  31. $cancel = GETPOST('cancel', 'alpha');
  32. $id = GETPOST('id', 'int');
  33. $_socid = GETPOST("id", 'int');
  34. // Security check
  35. if ($user->socid > 0) {
  36. $_socid = $user->socid;
  37. }
  38. // Security check
  39. $socid = GETPOST("socid", 'int');
  40. if ($user->socid > 0) {
  41. $action = '';
  42. $id = $user->socid;
  43. }
  44. $result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
  45. /*
  46. * Actions
  47. */
  48. if ($action == 'setpricelevel' && $user->hasRight('societe', 'creer')) {
  49. $soc = new Societe($db);
  50. $soc->fetch($id);
  51. $soc->setPriceLevel(GETPOST("price_level"), $user);
  52. header("Location: multiprix.php?id=".$id);
  53. exit;
  54. }
  55. /*
  56. * View
  57. */
  58. llxHeader();
  59. $userstatic = new User($db);
  60. if ($_socid > 0) {
  61. // We load data of thirdparty
  62. $objsoc = new Societe($db);
  63. $objsoc->id = $_socid;
  64. $objsoc->fetch($_socid);
  65. $head = societe_prepare_head($objsoc);
  66. $tabchoice = '';
  67. if ($objsoc->client == 1) {
  68. $tabchoice = 'customer';
  69. }
  70. if ($objsoc->client == 2) {
  71. $tabchoice = 'prospect';
  72. }
  73. print '<form method="POST" action="multiprix.php?id='.$objsoc->id.'">';
  74. print '<input type="hidden" name="token" value="'.newToken().'">';
  75. print '<input type="hidden" name="action" value="setpricelevel">';
  76. print dol_get_fiche_head($head, $tabchoice, $langs->trans("ThirdParty"), 0, 'company');
  77. print '<table class="border centpercent tableforfield">';
  78. print '<tr><td class="titlefieldcreate">';
  79. print $langs->trans("PriceLevel").'</td><td>'.$objsoc->price_level."</td></tr>";
  80. print '<tr><td>';
  81. print $langs->trans("NewValue").'</td><td>';
  82. print '<select name="price_level" class="flat">';
  83. for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
  84. print '<option value="'.$i.'"';
  85. if ($i == $objsoc->price_level) {
  86. print 'selected';
  87. }
  88. print '>'.$i;
  89. $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$i;
  90. if (getDolGlobalString($keyforlabel)) {
  91. print ' - '.$langs->trans(getDolGlobalString($keyforlabel));
  92. }
  93. print '</option>';
  94. }
  95. print '</select>';
  96. print '</td></tr>';
  97. print "</table>";
  98. print dol_get_fiche_end();
  99. print $form->buttonsSaveCancel("Save", '');
  100. print "</form>";
  101. print '<br><br>';
  102. /*
  103. * List historic of multiprices
  104. */
  105. $sql = "SELECT rc.rowid,rc.price_level, rc.datec as dc, u.rowid as uid, u.login";
  106. $sql .= " FROM ".MAIN_DB_PREFIX."societe_prices as rc, ".MAIN_DB_PREFIX."user as u";
  107. $sql .= " WHERE rc.fk_soc = ".((int) $objsoc->id);
  108. $sql .= " AND u.rowid = rc.fk_user_author";
  109. $sql .= " ORDER BY rc.datec DESC";
  110. $resql = $db->query($sql);
  111. if ($resql) {
  112. print '<table class="noborder centpercent">';
  113. print '<tr class="liste_titre">';
  114. print '<td>'.$langs->trans("Date").'</td>';
  115. print '<td>'.$langs->trans("PriceLevel").'</td>';
  116. print '<td class="right">'.$langs->trans("User").'</td>';
  117. print '</tr>';
  118. $i = 0;
  119. $num = $db->num_rows($resql);
  120. while ($i < $num) {
  121. $obj = $db->fetch_object($resql);
  122. print '<tr class="oddeven">';
  123. print '<td>'.dol_print_date($db->jdate($obj->dc), "dayhour").'</td>';
  124. print '<td>'.$obj->price_level.' </td>';
  125. $userstatic->id = $obj->uid;
  126. $userstatic->lastname = $obj->login;
  127. print '<td class="right">'.$userstatic->getNomUrl(1).'</td>';
  128. print '</tr>';
  129. $i++;
  130. }
  131. $db->free($resql);
  132. print "</table>";
  133. } else {
  134. dol_print_error($db);
  135. }
  136. }
  137. // End of page
  138. llxFooter();
  139. $db->close();