margin.php 8.5 KB

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