PageRenderTime 62ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/margin/admin/margin.php

https://bitbucket.org/speedealing/speedealing
PHP | 291 lines | 224 code | 36 blank | 31 comment | 35 complexity | eb8c112c9992a7d4a5a9284f999f04ce MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file /htdocs/margin/admin/margin.php
  19. * \ingroup margin
  20. * \brief Page to setup margin module
  21. */
  22. include '../../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  25. require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
  26. require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
  27. $langs->load("admin");
  28. $langs->load("bills");
  29. $langs->load("margins");
  30. if (! $user->admin) accessforbidden();
  31. $action=GETPOST('action','alpha');
  32. /*
  33. * Action
  34. */
  35. if (preg_match('/set_(.*)/',$action,$reg))
  36. {
  37. $code=$reg[1];
  38. if (dolibarr_set_const($db, $code, 1, 'yesno', 0, '', $conf->entity) > 0)
  39. {
  40. header("Location: ".$_SERVER["PHP_SELF"]);
  41. exit;
  42. }
  43. else
  44. {
  45. dol_print_error($db);
  46. }
  47. }
  48. if (preg_match('/del_(.*)/',$action,$reg))
  49. {
  50. $code=$reg[1];
  51. if (dolibarr_del_const($db, $code, $conf->entity) > 0)
  52. {
  53. header("Location: ".$_SERVER["PHP_SELF"]);
  54. exit;
  55. }
  56. else
  57. {
  58. dol_print_error($db);
  59. }
  60. }
  61. if ($action == 'remises')
  62. {
  63. if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', $_POST['MARGIN_METHODE_FOR_DISCOUNT'], 'chaine', 0, '', $conf->entity) > 0)
  64. {
  65. $conf->global->MARGIN_METHODE_FOR_DISCOUNT = $_POST['MARGIN_METHODE_FOR_DISCOUNT'];
  66. setEventMessage($langs->trans("RecordModifiedSuccessfully"));
  67. }
  68. else
  69. {
  70. dol_print_error($db);
  71. }
  72. }
  73. if ($action == 'typemarges')
  74. {
  75. if (dolibarr_set_const($db, 'MARGIN_TYPE', $_POST['MARGIN_TYPE'], 'chaine', 0, '', $conf->entity) > 0)
  76. {
  77. $conf->global->MARGIN_METHODE_FOR_DISCOUNT = $_POST['MARGIN_TYPE'];
  78. setEventMessage($langs->trans("RecordModifiedSuccessfully"));
  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. $conf->global->AGENT_CONTACT_TYPE = $_POST['AGENT_CONTACT_TYPE'];
  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_fiche_titre($langs->trans("margesSetup"),$linkback,'setup');
  102. $head = marges_admin_prepare_head();
  103. dol_fiche_head($head, 'parameters', $langs->trans("Margins"), 0, 'margin');
  104. print_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("Details").'</td>'."\n";
  110. print '</tr>';
  111. $var=true;
  112. $form = new Form($db);
  113. // GLOBAL DISCOUNT MANAGEMENT
  114. $var=!$var;
  115. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  116. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  117. print "<input type=\"hidden\" name=\"action\" value=\"typemarges\">";
  118. print '<tr '.$bc[$var].'>';
  119. print '<td>'.$langs->trans("MARGIN_TYPE").'</td>';
  120. print '<td align="right">'.$langs->trans('MargeBrute');
  121. print ' <input type="radio" name="MARGIN_TYPE" value="1" ';
  122. if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1')
  123. print 'checked ';
  124. print '/><br/>'.$langs->trans('MargeNette');
  125. print ' <input type="radio" name="MARGIN_TYPE" value="2" ';
  126. if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '2')
  127. print 'checked ';
  128. print '/>';
  129. print '</td>';
  130. print '<td>';
  131. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'" class="button">';
  132. print '</td>';
  133. print '<td>'.$langs->trans('MARGIN_TYPE_DETAILS').'</td>';
  134. print '</tr>';
  135. print '</form>';
  136. // DISPLAY MARGIN RATES
  137. $var=!$var;
  138. print '<tr '.$bc[$var].'>';
  139. print '<td>'.$langs->trans("DisplayMarginRates").'</td>';
  140. print '<td colspan="2" align="center">';
  141. if (! empty($conf->use_javascript_ajax))
  142. {
  143. print ajax_constantonoff('DISPLAY_MARGIN_RATES');
  144. }
  145. else
  146. {
  147. if (empty($conf->global->DISPLAY_MARGIN_RATES))
  148. {
  149. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  150. }
  151. else
  152. {
  153. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
  154. }
  155. }
  156. print '</td>';
  157. print '<td>'.$langs->trans('MarginRate').' = '.$langs->trans('Margin').' / '.$langs->trans('BuyingPrice').'</td>';
  158. print '</tr>';
  159. // DISPLAY MARK RATES
  160. $var=!$var;
  161. print '<tr '.$bc[$var].'>';
  162. print '<td>'.$langs->trans("DisplayMarkRates").'</td>';
  163. print '<td colspan="2" align="center">';
  164. if (! empty($conf->use_javascript_ajax))
  165. {
  166. print ajax_constantonoff('DISPLAY_MARK_RATES');
  167. }
  168. else
  169. {
  170. if (empty($conf->global->DISPLAY_MARK_RATES))
  171. {
  172. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  173. }
  174. else
  175. {
  176. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
  177. }
  178. }
  179. print '</td>';
  180. print '<td>'.$langs->trans('MarkRate').' = '.$langs->trans('Margin').' / '.$langs->trans('SellingPrice').'</td>';
  181. print '</tr>';
  182. print '<tr>';
  183. print '<td>'.$langs->trans("ForceBuyingPriceIfNull").'</td>';
  184. print '<td colspan="2" align="center">';
  185. if (! empty($conf->use_javascript_ajax))
  186. {
  187. print ajax_constantonoff('ForceBuyingPriceIfNull');
  188. }
  189. else
  190. {
  191. if (empty($conf->global->ForceBuyingPriceIfNull))
  192. {
  193. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  194. }
  195. else
  196. {
  197. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"),'on').'</a>';
  198. }
  199. }
  200. print '</td>';
  201. print '<td>'.$langs->trans('ForceBuyingPriceIfNullDetails').'</td>';
  202. print '</tr>';
  203. // GLOBAL DISCOUNT MANAGEMENT
  204. $var=!$var;
  205. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  206. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  207. print "<input type=\"hidden\" name=\"action\" value=\"remises\">";
  208. print '<tr '.$bc[$var].'>';
  209. print '<td>'.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").'</td>';
  210. print '<td align="left">';
  211. print '<select name="MARGIN_METHODE_FOR_DISCOUNT" class="flat">';
  212. print '<option value="1" ';
  213. if (isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT) && $conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1')
  214. print 'selected ';
  215. print '>'.$langs->trans('UseDiscountAsProduct').'</option>';
  216. print '<option value="2" ';
  217. if (isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT) && $conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2')
  218. print 'selected ';
  219. print '>'.$langs->trans('UseDiscountAsService').'</option>';
  220. print '<option value="3" ';
  221. if (isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT) && $conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3')
  222. print 'selected ';
  223. print '>'.$langs->trans('UseDiscountOnTotal').'</option>';
  224. print '</select>';
  225. print '</td>';
  226. print '<td>';
  227. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  228. print '</td>';
  229. print '<td>'.$langs->trans('MARGIN_METHODE_FOR_DISCOUNT_DETAILS').'</td>';
  230. print '</tr>';
  231. print '</form>';
  232. // INTERNAL CONTACT TYPE USED AS COMMERCIAL AGENT
  233. $var=!$var;
  234. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  235. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  236. print "<input type=\"hidden\" name=\"action\" value=\"contact\">";
  237. print '<tr '.$bc[$var].'>';
  238. print '<td>'.$langs->trans("AgentContactType").'</td>';
  239. print '<td align="left">';
  240. $formcompany = new FormCompany($db);
  241. $facture = new Facture($db);
  242. print $formcompany->selectTypeContact($facture, $conf->global->AGENT_CONTACT_TYPE, "AGENT_CONTACT_TYPE","internal","code",1);
  243. print '</td>';
  244. print '<td>';
  245. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  246. print '</td>';
  247. print '<td>'.$langs->trans('AgentContactTypeDetails').'</td>';
  248. print '</tr>';
  249. print '</form>';
  250. print '</table>';
  251. dol_fiche_end();
  252. print '<br>';
  253. llxFooter();
  254. $db->close();
  255. ?>