* Copyright (C) 2004-2021 Laurent Destailleur * * 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 * (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 * along with this program. If not, see . */ /** * \file htdocs/comm/remise.php * \ingroup societe * \brief Page to edit relative discount of a customer */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; // Load translation files required by the page $langs->loadLangs(array('companies', 'orders', 'bills')); $id = GETPOSTINT("id"); $socid = GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('socid'); // Security check if ($user->socid > 0) { $socid = $user->socid; } $backtopage = GETPOST('backtopage', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); $action = GETPOST('action', 'aZ09'); // Security check if ($user->socid > 0) { $id = $user->socid; } $result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0); /* * Actions */ if ($cancel) { if (!empty($backtopage)) { header("Location: ".$backtopage); exit; } else { $action = ''; } } if ($action == 'setremise' && $user->hasRight('societe', 'lire')) { $object = new Societe($db); $object->fetch($id); $discount_type = GETPOSTINT('discount_type'); if (!empty($discount_type)) { $result = $object->set_remise_supplier(price2num(GETPOST("remise")), GETPOST("note", "alphanohtml"), $user); } else { $result = $object->set_remise_client(price2num(GETPOST("remise")), GETPOST("note", "alphanohtml"), $user); } if ($result > 0) { if (!empty($backtopage)) { header("Location: ".$backtopage); exit; } else { header("Location: remise.php?id=".GETPOSTINT("id")); exit; } } else { setEventMessages($object->error, $object->errors, 'errors'); } } /* * View */ $form = new Form($db); if (! ($socid > 0)) { accessforbidden('Record not found'); } // On recupere les donnees societes par l'objet $object = new Societe($db); $object->fetch($socid); $title = $object->name; llxHeader('', $title); $head = societe_prepare_head($object); $isCustomer = ($object->client == 1 || $object->client == 3); $isSupplier = $object->fournisseur == 1; print '
'; print ''; print ''; print ''; print dol_get_fiche_head($head, 'relativediscount', $langs->trans("ThirdParty"), -1, 'company'); dol_banner_tab($object, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom'); print '
'; print '
'; if (!$isCustomer && !$isSupplier) { print '

'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'

'; print dol_get_fiche_end(); print ''; // End of page llxFooter(); $db->close(); exit; } print ''; if ($isCustomer) { // Customer discount print '"; } if ($isSupplier) { // Supplier discount print '"; } print '
'; print $langs->trans("CustomerRelativeDiscount").''.price2num($object->remise_percent)."%
'; print $langs->trans("SupplierRelativeDiscount").''.price2num($object->remise_supplier_percent)."%
'; print '
'; print load_fiche_titre($langs->trans("NewRelativeDiscount"), '', ''); print '
'; /*if (! ($isCustomer && $isSupplier)) { if ($isCustomer && ! $isSupplier) { print ''; } if (! $isCustomer && $isSupplier) { print ''; } }*/ print ''; if ($isCustomer || $isSupplier) { // Discount type print ''; } // New value print ''; // Motif/Note print ''; print "
'.$langs->trans('DiscountType').''; if ($isCustomer) { print ' '; } if ($isCustomer && $isSupplier) { print '   '; } if ($isSupplier) { print ' '; } print '
'; print $langs->trans("NewValue").'%
'; print $langs->trans("NoteReason").'
"; print '
'; print $form->buttonsSaveCancel("Modify"); print dol_get_fiche_end(); print ""; print '
'; if ($isCustomer) { if ($isSupplier) { print '
'; print '
'; print load_fiche_titre($langs->trans("CustomerDiscounts"), '', ''); } /* * 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 = ".((int) $object->id); $sql .= " AND rc.entity IN (".getEntity('discount').")"; $sql .= " AND u.rowid = rc.fk_user_author"; $sql .= " ORDER BY rc.datec DESC"; $resql = $db->query($sql); if ($resql) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; $num = $db->num_rows($resql); if ($num > 0) { $i = 0; while ($i < $num) { $obj = $db->fetch_object($resql); print ''; print ''; print ''; print ''; print ''; print ''; $i++; } } else { print ''; } $db->free($resql); print "
'.$langs->trans("Date").''.$langs->trans("CustomerRelativeDiscountShort").''.$langs->trans("NoteReason").''.$langs->trans("User").'
'.dol_print_date($db->jdate($obj->dc), "dayhour").''.price2num($obj->remise_percent).'%'.$obj->note.''.img_object($langs->trans("ShowUser"), 'user').' '.$obj->login.'
'.$langs->trans("None").'
"; } else { dol_print_error($db); } } if ($isSupplier) { if ($isCustomer) { print '
'; // class="fichehalfleft" print '
'; 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 = ".((int) $object->id); $sql .= " AND rc.entity IN (".getEntity('discount').")"; $sql .= " AND u.rowid = rc.fk_user_author"; $sql .= " ORDER BY rc.datec DESC"; $resql = $db->query($sql); if ($resql) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; $num = $db->num_rows($resql); if ($num > 0) { $i = 0; while ($i < $num) { $obj = $db->fetch_object($resql); print ''; print ''; print ''; print ''; print ''; print ''; $i++; } } else { print ''; } $db->free($resql); print "
'.$langs->trans("Date").''.$langs->trans("CustomerRelativeDiscountShort").''.$langs->trans("NoteReason").''.$langs->trans("User").'
'.dol_print_date($db->jdate($obj->dc), "dayhour").''.price2num($obj->remise_percent).'%'.$obj->note.''.img_object($langs->trans("ShowUser"), 'user').' '.$obj->login.'
'.$langs->trans("None").'
"; } else { dol_print_error($db); } if ($isCustomer) { print '
'; // class="fichehalfright" print '
'; // class="fichecenter" } } // End of page llxFooter(); $db->close();