dolibarr/htdocs/margin/admin/margin.php

299 lines
9.1 KiB
PHP
Raw Permalink Normal View History

2012-07-18 15:52:15 +02:00
<?php
2012-07-20 09:57:50 +02:00
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
2012-07-18 15:52:15 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2012-07-18 15:52:15 +02:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2012-07-20 09:57:50 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2012-07-18 15:52:15 +02:00
*/
/**
2012-07-23 16:10:54 +02:00
* \file /htdocs/margin/admin/margin.php
2012-07-20 09:57:50 +02:00
* \ingroup margin
* \brief Page to setup margin module
2012-07-18 15:52:15 +02:00
*/
include '../../main.inc.php';
2012-07-18 15:52:15 +02:00
require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
2012-07-18 15:52:15 +02:00
$langs->load("admin");
$langs->load("bills");
2012-07-20 09:57:50 +02:00
$langs->load("margins");
2015-07-16 13:28:40 +02:00
$langs->load("stocks");
2012-07-18 15:52:15 +02:00
2012-07-20 09:57:50 +02:00
if (! $user->admin) accessforbidden();
$action=GETPOST('action','alpha');
2012-07-18 15:52:15 +02:00
/*
* Action
*/
if (preg_match('/set_(.*)/',$action,$reg))
{
$code=$reg[1];
if (dolibarr_set_const($db, $code, 1, 'yesno', 0, '', $conf->entity) > 0)
{
2012-08-31 05:58:38 +02:00
header("Location: ".$_SERVER["PHP_SELF"]);
2012-07-18 15:52:15 +02:00
exit;
}
else
{
dol_print_error($db);
}
}
if (preg_match('/del_(.*)/',$action,$reg))
{
$code=$reg[1];
if (dolibarr_del_const($db, $code, $conf->entity) > 0)
{
2012-08-31 05:58:38 +02:00
header("Location: ".$_SERVER["PHP_SELF"]);
2012-07-18 15:52:15 +02:00
exit;
}
else
{
dol_print_error($db);
}
}
2012-07-20 09:57:50 +02:00
if ($action == 'remises')
2012-07-18 15:52:15 +02:00
{
if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', $_POST['MARGIN_METHODE_FOR_DISCOUNT'], 'chaine', 0, '', $conf->entity) > 0)
{
2015-12-12 10:59:02 +01:00
setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
2012-07-18 15:52:15 +02:00
}
else
{
dol_print_error($db);
}
}
2012-07-20 09:57:50 +02:00
if ($action == 'typemarges')
2012-07-18 15:52:15 +02:00
{
if (dolibarr_set_const($db, 'MARGIN_TYPE', $_POST['MARGIN_TYPE'], 'chaine', 0, '', $conf->entity) > 0)
{
2015-12-12 10:59:02 +01:00
setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
2012-07-18 15:52:15 +02:00
}
else
{
dol_print_error($db);
}
}
if ($action == 'contact')
{
if (dolibarr_set_const($db, 'AGENT_CONTACT_TYPE', $_POST['AGENT_CONTACT_TYPE'], 'chaine', 0, '', $conf->entity) > 0)
{
2015-12-12 10:59:02 +01:00
setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
}
else
{
dol_print_error($db);
}
}
2012-07-18 15:52:15 +02:00
/*
* View
*/
llxHeader('',$langs->trans("margesSetup"));
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans("margesSetup"),$linkback,'title_setup');
2012-07-18 15:52:15 +02:00
2012-07-20 09:57:50 +02:00
$head = marges_admin_prepare_head();
2012-07-18 15:52:15 +02:00
dol_fiche_head($head, 'parameters', $langs->trans("Margins"), 0, 'margin');
2012-07-18 15:52:15 +02:00
print load_fiche_titre($langs->trans("MemberMainOptions"),'','');
2012-07-18 15:52:15 +02:00
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td width=300>'.$langs->trans("Description").'</td>';
print '<td colspan="2" align="center">'.$langs->trans("Value").'</td>'."\n";
print '<td align="left">'.$langs->trans("Description").'</td>'."\n";
2012-07-18 15:52:15 +02:00
print '</tr>';
$var=true;
$form = new Form($db);
2012-07-20 09:57:50 +02:00
2012-07-18 15:52:15 +02:00
// GLOBAL DISCOUNT MANAGEMENT
$var=!$var;
2012-07-23 16:10:54 +02:00
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
2012-07-18 15:52:15 +02:00
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print "<input type=\"hidden\" name=\"action\" value=\"typemarges\">";
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("MARGIN_TYPE").'</td>';
2015-07-16 13:28:40 +02:00
print '<td>';
2012-07-18 15:52:15 +02:00
print ' <input type="radio" name="MARGIN_TYPE" value="1" ';
2012-07-20 09:57:50 +02:00
if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1')
2012-07-18 15:52:15 +02:00
print 'checked ';
2015-07-16 13:28:40 +02:00
print '/> ';
print $langs->trans('MargeType1');
print '<br>';
/*print $langs->trans('MargeNette');
2012-07-18 15:52:15 +02:00
print ' <input type="radio" name="MARGIN_TYPE" value="2" ';
2012-07-20 09:57:50 +02:00
if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '2')
2012-07-18 15:52:15 +02:00
print 'checked ';
print '/>';*/
// TODO Check that PMP is available when stock module is not enabled. If not, make this choice greyed when stock module disabled.
//if (! empty($conf->stock->enabled))
//{
print ' <input type="radio" name="MARGIN_TYPE" value="pmp" ';
if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp')
print 'checked ';
2015-07-16 13:28:40 +02:00
print '/> ';
print $langs->trans('MargeType2');
//}
2012-07-18 15:52:15 +02:00
print '</td>';
print '<td>';
2012-09-12 20:45:01 +02:00
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'" class="button">';
2012-07-18 15:52:15 +02:00
print '</td>';
2015-07-16 13:28:40 +02:00
print '<td>'.$langs->trans('MarginTypeDesc');
print '</td>';
2012-07-18 15:52:15 +02:00
print '</tr>';
print '</form>';
// DISPLAY MARGIN RATES
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("DisplayMarginRates").'</td>';
print '<td colspan="2" align="center">';
2012-07-20 09:57:50 +02:00
if (! empty($conf->use_javascript_ajax))
2012-07-18 15:52:15 +02:00
{
print ajax_constantonoff('DISPLAY_MARGIN_RATES');
}
else
{
2012-07-20 09:57:50 +02:00
if (empty($conf->global->DISPLAY_MARGIN_RATES))
2012-07-18 15:52:15 +02:00
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
2012-07-20 09:57:50 +02:00
else
2012-07-18 15:52:15 +02:00
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
}
}
print '</td>';
print '<td>'.$langs->trans('MarginRate').' = '.$langs->trans('Margin').' / '.$langs->trans('BuyingPrice').'</td>';
print '</tr>';
// DISPLAY MARK RATES
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("DisplayMarkRates").'</td>';
print '<td colspan="2" align="center">';
2012-07-20 09:57:50 +02:00
if (! empty($conf->use_javascript_ajax))
2012-07-18 15:52:15 +02:00
{
print ajax_constantonoff('DISPLAY_MARK_RATES');
}
else
{
2012-07-20 09:57:50 +02:00
if (empty($conf->global->DISPLAY_MARK_RATES))
2012-07-18 15:52:15 +02:00
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
2012-07-20 09:57:50 +02:00
else
2012-07-18 15:52:15 +02:00
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
}
}
print '</td>';
print '<td>'.$langs->trans('MarkRate').' = '.$langs->trans('Margin').' / '.$langs->trans('SellingPrice').'</td>';
print '</tr>';
2012-12-08 14:24:57 +01:00
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("ForceBuyingPriceIfNull").'</td>';
2012-07-18 15:52:15 +02:00
print '<td colspan="2" align="center">';
2012-07-20 09:57:50 +02:00
if (! empty($conf->use_javascript_ajax))
2012-07-18 15:52:15 +02:00
{
print ajax_constantonoff('ForceBuyingPriceIfNull');
}
else
{
2012-07-20 09:57:50 +02:00
if (empty($conf->global->ForceBuyingPriceIfNull))
2012-07-18 15:52:15 +02:00
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
2012-07-20 09:57:50 +02:00
else
2012-07-18 15:52:15 +02:00
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"),'on').'</a>';
}
}
print '</td>';
print '<td>'.$langs->trans('ForceBuyingPriceIfNullDetails').'</td>';
print '</tr>';
// GLOBAL DISCOUNT MANAGEMENT
$var=!$var;
2012-07-23 16:10:54 +02:00
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
2012-07-18 15:52:15 +02:00
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print "<input type=\"hidden\" name=\"action\" value=\"remises\">";
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").'</td>';
print '<td align="left">';
2012-09-12 20:45:01 +02:00
print '<select name="MARGIN_METHODE_FOR_DISCOUNT" class="flat">';
2012-07-18 15:52:15 +02:00
print '<option value="1" ';
2012-07-20 09:57:50 +02:00
if (isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT) && $conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1')
2012-07-18 15:52:15 +02:00
print 'selected ';
print '>'.$langs->trans('UseDiscountAsProduct').'</option>';
print '<option value="2" ';
2012-07-20 09:57:50 +02:00
if (isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT) && $conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2')
2012-07-18 15:52:15 +02:00
print 'selected ';
print '>'.$langs->trans('UseDiscountAsService').'</option>';
print '<option value="3" ';
2012-07-20 09:57:50 +02:00
if (isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT) && $conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3')
2012-07-18 15:52:15 +02:00
print 'selected ';
print '>'.$langs->trans('UseDiscountOnTotal').'</option>';
print '</select>';
print '</td>';
print '<td>';
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print '</td>';
print '<td>'.$langs->trans('MARGIN_METHODE_FOR_DISCOUNT_DETAILS').'</td>';
print '</tr>';
print '</form>';
// INTERNAL CONTACT TYPE USED AS COMMERCIAL AGENT
$var=!$var;
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print "<input type=\"hidden\" name=\"action\" value=\"contact\">";
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("AgentContactType").'</td>';
print '<td align="left">';
$formcompany = new FormCompany($db);
$facture = new Facture($db);
print $formcompany->selectTypeContact($facture, $conf->global->AGENT_CONTACT_TYPE, "AGENT_CONTACT_TYPE","internal","code",1);
print '</td>';
print '<td>';
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print '</td>';
print '<td>'.$langs->trans('AgentContactTypeDetails').'</td>';
print '</tr>';
print '</form>';
2012-07-18 15:52:15 +02:00
print '</table>';
2012-09-15 09:02:20 +02:00
dol_fiche_end();
2012-09-12 20:45:01 +02:00
print '<br>';
2012-07-18 15:52:15 +02:00
2012-07-20 09:57:50 +02:00
llxFooter();
2012-07-18 15:52:15 +02:00
$db->close();