2012-08-22 23:27:53 +02:00
|
|
|
<?php
|
2008-08-12 20:20:18 +02:00
|
|
|
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2015-08-28 00:29:46 +02:00
|
|
|
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
|
2008-08-12 20:20:18 +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
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2008-08-12 20:20:18 +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
|
2011-08-03 02:45:22 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-08-12 20:20:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2009-07-08 12:10:35 +02:00
|
|
|
* \file htdocs/comm/remise.php
|
|
|
|
|
* \ingroup societe
|
2011-09-08 23:50:41 +02:00
|
|
|
* \brief Page to edit relative discount of a customer
|
2009-07-08 12:10:35 +02:00
|
|
|
*/
|
|
|
|
|
|
2012-08-22 23:24:21 +02:00
|
|
|
require '../main.inc.php';
|
2012-08-22 23:11:24 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
|
2008-08-12 20:20:18 +02:00
|
|
|
|
2018-05-26 19:03:41 +02:00
|
|
|
// Load translation files required by the page
|
|
|
|
|
$langs->loadLangs(array('companies', 'orders', 'bills'));
|
2008-08-12 20:20:18 +02:00
|
|
|
|
2016-02-08 02:49:19 +01:00
|
|
|
$id=GETPOST("id",'int');
|
|
|
|
|
|
2018-04-06 20:22:20 +02:00
|
|
|
$socid = GETPOST('id','int')?GETPOST('id','int'):GETPOST('socid','int');
|
2009-07-08 12:10:35 +02:00
|
|
|
// Security check
|
|
|
|
|
if ($user->societe_id > 0)
|
|
|
|
|
{
|
2011-09-10 19:52:21 +02:00
|
|
|
$socid = $user->societe_id;
|
2009-07-08 12:10:35 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-27 17:02:56 +01:00
|
|
|
$backtopage = GETPOST('backtopage','alpha');
|
|
|
|
|
|
2008-08-12 20:20:18 +02:00
|
|
|
|
2011-09-08 23:50:41 +02:00
|
|
|
/*
|
|
|
|
|
* Actions
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 10:50:50 +02:00
|
|
|
if (GETPOST('cancel','alpha') && ! empty($backtopage))
|
2011-09-08 23:50:41 +02:00
|
|
|
{
|
2012-08-31 05:58:38 +02:00
|
|
|
header("Location: ".$backtopage);
|
2011-09-08 23:50:41 +02:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-16 13:27:32 +02:00
|
|
|
if (GETPOST('action','aZ09') == 'setremise')
|
2008-08-12 20:20:18 +02:00
|
|
|
{
|
2015-10-13 13:06:32 +02:00
|
|
|
$object = new Societe($db);
|
2016-02-15 01:37:23 +01:00
|
|
|
$object->fetch($id);
|
2018-02-27 16:30:39 +01:00
|
|
|
|
|
|
|
|
$discount_type = GETPOST('discount_type', 'int');
|
|
|
|
|
|
|
|
|
|
if(! empty($discount_type)) {
|
|
|
|
|
$result=$object->set_remise_supplier(price2num(GETPOST("remise")),GETPOST("note"),$user);
|
|
|
|
|
} else {
|
|
|
|
|
$result=$object->set_remise_client(price2num(GETPOST("remise")),GETPOST("note"),$user);
|
|
|
|
|
}
|
2008-08-12 20:20:18 +02:00
|
|
|
|
|
|
|
|
if ($result > 0)
|
2009-07-08 12:10:35 +02:00
|
|
|
{
|
2012-02-27 17:02:56 +01:00
|
|
|
if (! empty($backtopage))
|
2011-09-10 19:52:21 +02:00
|
|
|
{
|
2012-08-31 05:58:38 +02:00
|
|
|
header("Location: ".$backtopage);
|
2011-09-10 19:52:21 +02:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-08-31 05:58:38 +02:00
|
|
|
header("Location: remise.php?id=".$_GET["id"]);
|
2011-09-10 19:52:21 +02:00
|
|
|
exit;
|
|
|
|
|
}
|
2008-08-12 20:20:18 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-10-13 13:06:32 +02:00
|
|
|
setEventMessages($object->error, $object->errors, 'errors');
|
2008-08-12 20:20:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-07-08 12:10:35 +02:00
|
|
|
/*
|
|
|
|
|
* View
|
|
|
|
|
*/
|
2008-08-12 20:20:18 +02:00
|
|
|
|
2009-07-08 12:10:35 +02:00
|
|
|
$form=new Form($db);
|
2008-08-12 20:20:18 +02:00
|
|
|
|
2009-07-08 12:10:35 +02:00
|
|
|
llxHeader();
|
2008-08-12 20:20:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* Mode fiche
|
|
|
|
|
*
|
2009-07-08 12:10:35 +02:00
|
|
|
*********************************************************************************/
|
2011-09-10 19:52:21 +02:00
|
|
|
if ($socid > 0)
|
2008-08-12 20:20:18 +02:00
|
|
|
{
|
|
|
|
|
// On recupere les donnees societes par l'objet
|
2015-10-13 13:06:32 +02:00
|
|
|
$object = new Societe($db);
|
|
|
|
|
$object->fetch($socid);
|
2009-07-08 12:10:35 +02:00
|
|
|
|
2015-10-13 13:06:32 +02:00
|
|
|
$head = societe_prepare_head($object);
|
2008-08-12 20:20:18 +02:00
|
|
|
|
2018-02-27 16:30:39 +01:00
|
|
|
$isCustomer = $object->client == 1 || $object->client == 3;
|
|
|
|
|
$isSupplier = $object->fournisseur == 1;
|
2016-07-07 12:43:02 +02:00
|
|
|
|
2015-10-13 13:06:32 +02:00
|
|
|
print '<form method="POST" action="remise.php?id='.$object->id.'">';
|
2015-08-28 00:29:46 +02:00
|
|
|
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
|
|
|
|
print '<input type="hidden" name="action" value="setremise">';
|
|
|
|
|
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
|
|
|
|
|
|
2018-02-27 22:17:42 +01:00
|
|
|
dol_fiche_head($head, 'relativediscount', $langs->trans("ThirdParty"), -1, 'company');
|
2009-07-08 12:10:35 +02:00
|
|
|
|
2015-10-13 13:06:32 +02:00
|
|
|
dol_banner_tab($object, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom');
|
2016-07-07 12:43:02 +02:00
|
|
|
|
2015-10-13 13:06:32 +02:00
|
|
|
print '<div class="fichecenter">';
|
2016-07-07 12:43:02 +02:00
|
|
|
|
2015-10-13 13:06:32 +02:00
|
|
|
print '<div class="underbanner clearboth"></div>';
|
2018-04-06 20:22:20 +02:00
|
|
|
|
2018-03-05 10:58:19 +01:00
|
|
|
if(! $isCustomer && ! $isSupplier) {
|
2018-02-27 16:30:39 +01:00
|
|
|
print '<p class="opacitymedium">'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'</p>';
|
2018-04-06 20:22:20 +02:00
|
|
|
|
2018-02-27 16:30:39 +01:00
|
|
|
dol_fiche_end();
|
2018-04-06 20:22:20 +02:00
|
|
|
|
2018-02-27 16:30:39 +01:00
|
|
|
print '</form>';
|
2018-04-06 20:22:20 +02:00
|
|
|
|
2018-02-27 16:30:39 +01:00
|
|
|
llxFooter();
|
|
|
|
|
$db->close();
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-13 13:06:32 +02:00
|
|
|
print '<table class="border centpercent">';
|
2009-07-08 12:10:35 +02:00
|
|
|
|
2018-03-05 10:58:19 +01:00
|
|
|
if($isCustomer) {
|
2018-02-27 16:30:39 +01:00
|
|
|
// Customer discount
|
|
|
|
|
print '<tr><td class="titlefield">';
|
|
|
|
|
print $langs->trans("CustomerRelativeDiscount").'</td><td>'.price2num($object->remise_percent)."%</td></tr>";
|
|
|
|
|
}
|
2018-04-06 20:22:20 +02:00
|
|
|
|
2018-03-05 10:58:19 +01:00
|
|
|
if($isSupplier) {
|
2018-02-27 16:30:39 +01:00
|
|
|
// Supplier discount
|
|
|
|
|
print '<tr><td class="titlefield">';
|
|
|
|
|
print $langs->trans("SupplierRelativeDiscount").'</td><td>'.price2num($object->remise_supplier_percent)."%</td></tr>";
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-07 02:49:43 +02:00
|
|
|
print '</table>';
|
|
|
|
|
print '<br>';
|
|
|
|
|
|
2015-09-24 18:33:48 +02:00
|
|
|
print load_fiche_titre($langs->trans("NewRelativeDiscount"),'','');
|
2009-08-07 02:49:43 +02:00
|
|
|
|
2017-03-11 02:35:01 +01:00
|
|
|
print '<div class="underbanner clearboth"></div>';
|
2018-02-27 16:30:39 +01:00
|
|
|
|
2018-03-05 10:58:19 +01:00
|
|
|
if($isCustomer && ! $isSupplier) {
|
2018-02-27 16:30:39 +01:00
|
|
|
print '<input type="hidden" name="discount_type" value="0" />';
|
|
|
|
|
}
|
2018-04-06 20:22:20 +02:00
|
|
|
|
2018-03-05 10:58:19 +01:00
|
|
|
if(! $isCustomer && $isSupplier) {
|
2018-02-27 16:30:39 +01:00
|
|
|
print '<input type="hidden" name="discount_type" value="1" />';
|
|
|
|
|
}
|
2018-04-06 20:22:20 +02:00
|
|
|
|
2015-10-13 13:06:32 +02:00
|
|
|
print '<table class="border centpercent">';
|
2009-08-07 02:49:43 +02:00
|
|
|
|
2018-03-05 10:58:19 +01:00
|
|
|
if($isCustomer && $isSupplier) {
|
2018-02-27 16:30:39 +01:00
|
|
|
// Discount type
|
|
|
|
|
print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td>';
|
|
|
|
|
print '<td><input type="radio" name="discount_type" id="discount_type_0" selected value="0"/> <label for="discount_type_0">'.$langs->trans('Customer').'</label>';
|
|
|
|
|
print ' <input type="radio" name="discount_type" id="discount_type_1" selected value="1"/> <label for="discount_type_1">'.$langs->trans('Supplier').'</label>';
|
|
|
|
|
print '</td></tr>';
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-18 13:04:24 +01:00
|
|
|
// New value
|
2017-04-09 13:12:25 +02:00
|
|
|
print '<tr><td class="titlefield fieldrequired">';
|
2016-12-18 13:04:24 +01:00
|
|
|
print $langs->trans("NewValue").'</td><td><input type="text" size="5" name="remise" value="'.dol_escape_htmltag(GETPOST("remise")).'">%</td></tr>';
|
2009-07-08 12:10:35 +02:00
|
|
|
|
|
|
|
|
// Motif/Note
|
2017-04-09 13:12:25 +02:00
|
|
|
print '<tr><td class="fieldrequired">';
|
2016-12-18 13:04:24 +01:00
|
|
|
print $langs->trans("NoteReason").'</td><td><input type="text" size="60" name="note" value="'.dol_escape_htmltag(GETPOST("note")).'"></td></tr>';
|
2009-07-08 12:10:35 +02:00
|
|
|
|
2011-09-08 22:47:19 +02:00
|
|
|
print "</table>";
|
2011-09-08 23:28:57 +02:00
|
|
|
|
2015-10-13 13:06:32 +02:00
|
|
|
print '</div>';
|
2016-07-07 12:43:02 +02:00
|
|
|
|
2015-08-28 00:29:46 +02:00
|
|
|
dol_fiche_end();
|
2016-07-07 12:43:02 +02:00
|
|
|
|
2014-11-25 20:13:43 +01:00
|
|
|
print '<div class="center">';
|
2011-09-08 23:50:41 +02:00
|
|
|
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
|
2012-02-27 17:02:56 +01:00
|
|
|
if (! empty($backtopage))
|
2011-09-08 23:50:41 +02:00
|
|
|
{
|
2014-11-25 20:13:43 +01:00
|
|
|
print ' ';
|
2011-09-08 23:50:41 +02:00
|
|
|
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
|
|
|
|
}
|
2014-11-25 20:13:43 +01:00
|
|
|
print '</div>';
|
2011-09-08 23:11:09 +02:00
|
|
|
|
2009-07-08 12:10:35 +02:00
|
|
|
print "</form>";
|
|
|
|
|
|
|
|
|
|
print '<br>';
|
|
|
|
|
|
2018-03-05 10:58:19 +01:00
|
|
|
if($isCustomer) {
|
|
|
|
|
if($isSupplier) {
|
2018-02-27 16:30:39 +01:00
|
|
|
print '<div class="fichecenter">';
|
|
|
|
|
print '<div class="fichehalfleft">';
|
|
|
|
|
print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
|
|
|
|
|
}
|
2009-07-08 12:10:35 +02:00
|
|
|
|
2018-02-27 16:30:39 +01:00
|
|
|
/*
|
|
|
|
|
* List log of all customer percent discounts
|
|
|
|
|
*/
|
|
|
|
|
$sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,";
|
|
|
|
|
$sql.= " u.login, u.rowid as user_id";
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
|
|
|
|
|
$sql.= " WHERE rc.fk_soc = " . $object->id;
|
|
|
|
|
$sql.= " AND rc.entity = " . $conf->entity;
|
|
|
|
|
$sql.= " AND u.rowid = rc.fk_user_author";
|
|
|
|
|
$sql.= " ORDER BY rc.datec DESC";
|
2018-04-06 20:22:20 +02:00
|
|
|
|
2018-02-27 16:30:39 +01:00
|
|
|
$resql=$db->query($sql);
|
|
|
|
|
if ($resql)
|
|
|
|
|
{
|
|
|
|
|
print '<table class="noborder" width="100%">';
|
|
|
|
|
$tag = !$tag;
|
|
|
|
|
print '<tr class="liste_titre">';
|
|
|
|
|
print '<td width="160">'.$langs->trans("Date").'</td>';
|
|
|
|
|
print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
|
|
|
|
|
print '<td align="left">'.$langs->trans("NoteReason").'</td>';
|
|
|
|
|
print '<td align="center">'.$langs->trans("User").'</td>';
|
|
|
|
|
print '</tr>';
|
|
|
|
|
$num = $db->num_rows($resql);
|
|
|
|
|
if ($num > 0)
|
|
|
|
|
{
|
|
|
|
|
$i = 0;
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
{
|
|
|
|
|
$obj = $db->fetch_object($resql);
|
|
|
|
|
print '<tr class="oddeven">';
|
|
|
|
|
print '<td>'.dol_print_date($db->jdate($obj->dc),"dayhour").'</td>';
|
|
|
|
|
print '<td align="center">'.price2num($obj->remise_percent).'%</td>';
|
|
|
|
|
print '<td align="left">'.$obj->note.'</td>';
|
|
|
|
|
print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a></td>';
|
|
|
|
|
print '</tr>';
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
|
2018-04-06 20:22:20 +02:00
|
|
|
}
|
2018-02-27 16:30:39 +01:00
|
|
|
$db->free($resql);
|
|
|
|
|
print "</table>";
|
2009-07-08 12:10:35 +02:00
|
|
|
}
|
2017-04-09 13:12:25 +02:00
|
|
|
else
|
|
|
|
|
{
|
2018-02-27 16:30:39 +01:00
|
|
|
dol_print_error($db);
|
|
|
|
|
}
|
2009-07-08 12:10:35 +02:00
|
|
|
}
|
2008-08-12 20:20:18 +02:00
|
|
|
|
2018-03-05 10:58:19 +01:00
|
|
|
if($isSupplier) {
|
|
|
|
|
if($isCustomer) {
|
2018-02-27 16:30:39 +01:00
|
|
|
print '</div>'; // class="fichehalfleft"
|
|
|
|
|
print '<div class="fichehalfright">';
|
|
|
|
|
print '<div class="ficheaddleft">';
|
|
|
|
|
print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* List log of all supplier percent discounts
|
|
|
|
|
*/
|
|
|
|
|
$sql = "SELECT rc.rowid, rc.remise_supplier as remise_percent, rc.note, rc.datec as dc,";
|
|
|
|
|
$sql.= " u.login, u.rowid as user_id";
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_supplier as rc, ".MAIN_DB_PREFIX."user as u";
|
|
|
|
|
$sql.= " WHERE rc.fk_soc = " . $object->id;
|
|
|
|
|
$sql.= " AND rc.entity = " . $conf->entity;
|
|
|
|
|
$sql.= " AND u.rowid = rc.fk_user_author";
|
|
|
|
|
$sql.= " ORDER BY rc.datec DESC";
|
2018-04-06 20:22:20 +02:00
|
|
|
|
2018-02-27 16:30:39 +01:00
|
|
|
$resql=$db->query($sql);
|
|
|
|
|
if ($resql)
|
|
|
|
|
{
|
|
|
|
|
print '<table class="noborder" width="100%">';
|
|
|
|
|
$tag = !$tag;
|
|
|
|
|
print '<tr class="liste_titre">';
|
|
|
|
|
print '<td width="160">'.$langs->trans("Date").'</td>';
|
|
|
|
|
print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
|
|
|
|
|
print '<td align="left">'.$langs->trans("NoteReason").'</td>';
|
|
|
|
|
print '<td align="center">'.$langs->trans("User").'</td>';
|
|
|
|
|
print '</tr>';
|
|
|
|
|
$num = $db->num_rows($resql);
|
|
|
|
|
if ($num > 0)
|
|
|
|
|
{
|
|
|
|
|
$i = 0;
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
{
|
|
|
|
|
$obj = $db->fetch_object($resql);
|
|
|
|
|
print '<tr class="oddeven">';
|
|
|
|
|
print '<td>'.dol_print_date($db->jdate($obj->dc),"dayhour").'</td>';
|
|
|
|
|
print '<td align="center">'.price2num($obj->remise_percent).'%</td>';
|
|
|
|
|
print '<td align="left">'.$obj->note.'</td>';
|
|
|
|
|
print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a></td>';
|
|
|
|
|
print '</tr>';
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
|
|
|
|
|
}
|
|
|
|
|
$db->free($resql);
|
|
|
|
|
print "</table>";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dol_print_error($db);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-05 10:58:19 +01:00
|
|
|
if($isCustomer) {
|
2018-02-27 16:30:39 +01:00
|
|
|
print '</div>'; // class="ficheaddleft"
|
|
|
|
|
print '</div>'; // class="fichehalfright"
|
|
|
|
|
print '</div>'; // class="fichecenter"
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-08-12 20:20:18 +02:00
|
|
|
}
|
|
|
|
|
|
2011-08-27 16:24:16 +02:00
|
|
|
llxFooter();
|
2015-12-11 14:19:38 +01:00
|
|
|
$db->close();
|