margin.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?php
  2. /* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  3. * Copyright (C) 2016 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/margin/admin/margin.php
  20. * \ingroup margin
  21. * \brief Page to setup margin module
  22. */
  23. include '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  27. require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
  28. $langs->loadLangs(array("admin", "bills", "margins", "stocks"));
  29. if (!$user->admin) {
  30. accessforbidden();
  31. }
  32. $action = GETPOST('action', 'aZ09');
  33. /*
  34. * Action
  35. */
  36. $reg = array();
  37. if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
  38. $code = $reg[1];
  39. if (dolibarr_set_const($db, $code, 1, 'yesno', 0, '', $conf->entity) > 0) {
  40. header("Location: ".$_SERVER["PHP_SELF"]);
  41. exit;
  42. } else {
  43. dol_print_error($db);
  44. }
  45. }
  46. if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
  47. $code = $reg[1];
  48. if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
  49. header("Location: ".$_SERVER["PHP_SELF"]);
  50. exit;
  51. } else {
  52. dol_print_error($db);
  53. }
  54. }
  55. if ($action == 'remises') {
  56. if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', GETPOST('MARGIN_METHODE_FOR_DISCOUNT'), 'chaine', 0, '', $conf->entity) > 0) {
  57. setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
  58. } else {
  59. dol_print_error($db);
  60. }
  61. }
  62. if ($action == 'typemarges') {
  63. if (dolibarr_set_const($db, 'MARGIN_TYPE', GETPOST('MARGIN_TYPE'), 'chaine', 0, '', $conf->entity) > 0) {
  64. setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
  65. } else {
  66. dol_print_error($db);
  67. }
  68. }
  69. if ($action == 'contact') {
  70. if (dolibarr_set_const($db, 'AGENT_CONTACT_TYPE', GETPOST('AGENT_CONTACT_TYPE'), 'chaine', 0, '', $conf->entity) > 0) {
  71. setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
  72. } else {
  73. dol_print_error($db);
  74. }
  75. }
  76. /*
  77. * View
  78. */
  79. $form = new Form($db);
  80. llxHeader('', $langs->trans("margesSetup"));
  81. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  82. print load_fiche_titre($langs->trans("margesSetup"), $linkback, 'title_setup');
  83. $head = marges_admin_prepare_head();
  84. print dol_get_fiche_head($head, 'parameters', $langs->trans("Margins"), -1, 'margin');
  85. print '<table class="noborder centpercent">';
  86. print '<tr class="liste_titre">';
  87. print '<td width=300>'.$langs->trans("MemberMainOptions").'</td>';
  88. print '<td colspan="2">'.$langs->trans("Value").'</td>'."\n";
  89. print '<td class="left">'.$langs->trans("Description").'</td>'."\n";
  90. print '</tr>';
  91. // GLOBAL DISCOUNT MANAGEMENT
  92. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  93. print '<input type="hidden" name="token" value="'.newToken().'">';
  94. print "<input type=\"hidden\" name=\"action\" value=\"typemarges\">";
  95. print '<tr class="oddeven">';
  96. print '<td>'.$langs->trans("MARGIN_TYPE").'</td>';
  97. print '<td>';
  98. print ' <input type="radio" name="MARGIN_TYPE" value="1" ';
  99. if (getDolGlobalString('MARGIN_TYPE') == '1') {
  100. print 'checked ';
  101. }
  102. print '/> ';
  103. print $langs->trans('MargeType1');
  104. print '<br>';
  105. print ' <input type="radio" name="MARGIN_TYPE" value="pmp" ';
  106. if (getDolGlobalString('MARGIN_TYPE') == 'pmp') {
  107. print 'checked ';
  108. }
  109. print '/> ';
  110. print $langs->trans('MargeType2');
  111. print '<br>';
  112. print ' <input type="radio" name="MARGIN_TYPE" value="costprice" ';
  113. if (getDolGlobalString('MARGIN_TYPE') == 'costprice') {
  114. print 'checked ';
  115. }
  116. print '/> ';
  117. print $langs->trans('MargeType3');
  118. print '</td>';
  119. print '<td>';
  120. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" class="button">';
  121. print '</td>';
  122. print '<td>'.$langs->trans('MarginTypeDesc');
  123. print '</td>';
  124. print '</tr>';
  125. print '</form>';
  126. // DISPLAY MARGIN RATES
  127. print '<tr class="oddeven">';
  128. print '<td>'.$langs->trans("DisplayMarginRates").'</td>';
  129. print '<td colspan="2">';
  130. if (!empty($conf->use_javascript_ajax)) {
  131. print ajax_constantonoff('DISPLAY_MARGIN_RATES');
  132. } else {
  133. if (empty($conf->global->DISPLAY_MARGIN_RATES)) {
  134. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  135. } else {
  136. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
  137. }
  138. }
  139. print '</td>';
  140. print '<td>'.$langs->trans('MarginRate').' = '.$langs->trans('Margin').' / '.$langs->trans('BuyingPrice').'</td>';
  141. print '</tr>';
  142. // DISPLAY MARK RATES
  143. print '<tr class="oddeven">';
  144. print '<td>'.$langs->trans("DisplayMarkRates").'</td>';
  145. print '<td colspan="2">';
  146. if (!empty($conf->use_javascript_ajax)) {
  147. print ajax_constantonoff('DISPLAY_MARK_RATES');
  148. } else {
  149. if (empty($conf->global->DISPLAY_MARK_RATES)) {
  150. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  151. } else {
  152. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
  153. }
  154. }
  155. print '</td>';
  156. print '<td>'.$langs->trans('MarkRate').' = '.$langs->trans('Margin').' / '.$langs->trans('SellingPrice').'</td>';
  157. print '</tr>';
  158. print '<tr class="oddeven">';
  159. print '<td>'.$langs->trans("ForceBuyingPriceIfNull").'</td>';
  160. print '<td colspan="2">';
  161. if (!empty($conf->use_javascript_ajax)) {
  162. print ajax_constantonoff('ForceBuyingPriceIfNull');
  163. } else {
  164. if (empty($conf->global->ForceBuyingPriceIfNull)) {
  165. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  166. } else {
  167. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
  168. }
  169. }
  170. print '</td>';
  171. print '<td>'.$langs->trans('ForceBuyingPriceIfNullDetails').'</td>';
  172. print '</tr>';
  173. // GLOBAL DISCOUNT MANAGEMENT
  174. $methods = array(
  175. 1 => $langs->trans('UseDiscountAsProduct'),
  176. 2 => $langs->trans('UseDiscountAsService'),
  177. 3 => $langs->trans('UseDiscountOnTotal')
  178. );
  179. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  180. print '<input type="hidden" name="token" value="'.newToken().'">';
  181. print '<input type="hidden" name="action" value="remises">';
  182. print '<tr class="oddeven">';
  183. print '<td>'.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").'</td>';
  184. print '<td class="left">';
  185. print Form::selectarray('MARGIN_METHODE_FOR_DISCOUNT', $methods, getDolGlobalString('MARGIN_METHODE_FOR_DISCOUNT'));
  186. print '</td>';
  187. print '<td>';
  188. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
  189. print '</td>';
  190. print '<td>'.$langs->trans('MARGIN_METHODE_FOR_DISCOUNT_DETAILS').'</td>';
  191. print '</tr>';
  192. print '</form>';
  193. // INTERNAL CONTACT TYPE USED AS COMMERCIAL AGENT
  194. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  195. print '<input type="hidden" name="token" value="'.newToken().'">';
  196. print '<input type="hidden" name="action" value="contact">';
  197. print '<tr class="oddeven">';
  198. print '<td>'.$langs->trans("AgentContactType").'</td>';
  199. print '<td class="left">';
  200. $formcompany = new FormCompany($db);
  201. $facture = new Facture($db);
  202. print $formcompany->selectTypeContact($facture, getDolGlobalString('AGENT_CONTACT_TYPE'), "AGENT_CONTACT_TYPE", "internal", "code", 1, "maxwidth250");
  203. print '</td>';
  204. print '<td>';
  205. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
  206. print '</td>';
  207. print '<td>'.$langs->trans('AgentContactTypeDetails').'</td>';
  208. print '</tr>';
  209. print '</form>';
  210. print '</table>';
  211. print dol_get_fiche_end();
  212. print '<br>';
  213. // End of page
  214. llxFooter();
  215. $db->close();