multiprix.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array('orders', 'companies'));
  29. $action = GETPOST('action', 'alpha');
  30. $cancel = GETPOST('cancel', 'alpha');
  31. $id = GETPOST('id', 'int');
  32. $_socid = GETPOST("id", 'int');
  33. // Security check
  34. if ($user->socid > 0) {
  35. $_socid = $user->socid;
  36. }
  37. // Security check
  38. $socid = GETPOST("socid", 'int');
  39. if ($user->socid > 0) {
  40. $action = '';
  41. $id = $user->socid;
  42. }
  43. $result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
  44. /*
  45. * Actions
  46. */
  47. if ($action == 'setpricelevel' && $user->rights->societe->creer) {
  48. $soc = new Societe($db);
  49. $soc->fetch($id);
  50. $soc->setPriceLevel(GETPOST("price_level"), $user);
  51. header("Location: multiprix.php?id=".$id);
  52. exit;
  53. }
  54. /*
  55. * View
  56. */
  57. llxHeader();
  58. $userstatic = new User($db);
  59. if ($_socid > 0) {
  60. // We load data of thirdparty
  61. $objsoc = new Societe($db);
  62. $objsoc->id = $_socid;
  63. $objsoc->fetch($_socid);
  64. $head = societe_prepare_head($objsoc);
  65. $tabchoice = '';
  66. if ($objsoc->client == 1) {
  67. $tabchoice = 'customer';
  68. }
  69. if ($objsoc->client == 2) {
  70. $tabchoice = 'prospect';
  71. }
  72. print '<form method="POST" action="multiprix.php?id='.$objsoc->id.'">';
  73. print '<input type="hidden" name="token" value="'.newToken().'">';
  74. print '<input type="hidden" name="action" value="setpricelevel">';
  75. print dol_get_fiche_head($head, $tabchoice, $langs->trans("ThirdParty"), 0, 'company');
  76. print '<table class="border centpercent tableforfield">';
  77. print '<tr><td class="titlefieldcreate">';
  78. print $langs->trans("PriceLevel").'</td><td>'.$objsoc->price_level."</td></tr>";
  79. print '<tr><td>';
  80. print $langs->trans("NewValue").'</td><td>';
  81. print '<select name="price_level" class="flat">';
  82. for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
  83. print '<option value="'.$i.'"';
  84. if ($i == $objsoc->price_level) {
  85. print 'selected';
  86. }
  87. print '>'.$i;
  88. $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$i;
  89. if (!empty($conf->global->$keyforlabel)) {
  90. print ' - '.$langs->trans($conf->global->$keyforlabel);
  91. }
  92. print '</option>';
  93. }
  94. print '</select>';
  95. print '</td></tr>';
  96. print "</table>";
  97. print dol_get_fiche_end();
  98. print $form->buttonsSaveCancel("Save", '');
  99. print "</form>";
  100. print '<br><br>';
  101. /*
  102. * List historic of multiprices
  103. */
  104. $sql = "SELECT rc.rowid,rc.price_level, rc.datec as dc, u.rowid as uid, u.login";
  105. $sql .= " FROM ".MAIN_DB_PREFIX."societe_prices as rc, ".MAIN_DB_PREFIX."user as u";
  106. $sql .= " WHERE rc.fk_soc = ".((int) $objsoc->id);
  107. $sql .= " AND u.rowid = rc.fk_user_author";
  108. $sql .= " ORDER BY rc.datec DESC";
  109. $resql = $db->query($sql);
  110. if ($resql) {
  111. print '<table class="noborder centpercent">';
  112. print '<tr class="liste_titre">';
  113. print '<td>'.$langs->trans("Date").'</td>';
  114. print '<td>'.$langs->trans("PriceLevel").'</td>';
  115. print '<td class="right">'.$langs->trans("User").'</td>';
  116. print '</tr>';
  117. $i = 0;
  118. $num = $db->num_rows($resql);
  119. while ($i < $num) {
  120. $obj = $db->fetch_object($resql);
  121. print '<tr class="oddeven">';
  122. print '<td>'.dol_print_date($db->jdate($obj->dc), "dayhour").'</td>';
  123. print '<td>'.$obj->price_level.' </td>';
  124. $userstatic->id = $obj->uid;
  125. $userstatic->lastname = $obj->login;
  126. print '<td class="right">'.$userstatic->getNomUrl(1).'</td>';
  127. print '</tr>';
  128. $i++;
  129. }
  130. $db->free($resql);
  131. print "</table>";
  132. } else {
  133. dol_print_error($db);
  134. }
  135. }
  136. // End of page
  137. llxFooter();
  138. $db->close();