margin.php 8.5 KB

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