New: Add option SUPPLIER_ORDER_AUTOADD_USER_CONTACT to automatically set

user approving as contact following supplier order.
This commit is contained in:
Laurent Destailleur 2015-02-17 19:49:17 +01:00
parent bc88917b81
commit 1e1543403b
4 changed files with 72 additions and 44 deletions

View File

@ -137,8 +137,10 @@ if (empty($reshook))
} }
// Reopen a closed order // Reopen a closed order
else if ($action == 'reopen' && $user->rights->commande->creer) { else if ($action == 'reopen' && $user->rights->commande->creer)
if ($object->statut == 3) { {
if ($object->statut == 3)
{
$result = $object->set_reopen($user); $result = $object->set_reopen($user);
if ($result > 0) if ($result > 0)
{ {
@ -153,21 +155,26 @@ if (empty($reshook))
} }
// Suppression de la commande // Suppression de la commande
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->commande->supprimer) { else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->commande->supprimer)
{
$result = $object->delete($user); $result = $object->delete($user);
if ($result > 0) { if ($result > 0)
{
header('Location: index.php'); header('Location: index.php');
exit; exit;
} }
else { else
{
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
// Remove a product line // Remove a product line
else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->commande->creer) { else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->commande->creer)
{
$result = $object->deleteline($lineid); $result = $object->deleteline($lineid);
if ($result > 0) { if ($result > 0)
{
// Define output language // Define output language
$outputlangs = $langs; $outputlangs = $langs;
$newlang = ''; $newlang = '';
@ -194,12 +201,14 @@ if (empty($reshook))
} }
// Categorisation dans projet // Categorisation dans projet
else if ($action == 'classin' && $user->rights->commande->creer) { else if ($action == 'classin' && $user->rights->commande->creer)
{
$object->setProject(GETPOST('projectid')); $object->setProject(GETPOST('projectid'));
} }
// Add order // Add order
else if ($action == 'add' && $user->rights->commande->creer) { else if ($action == 'add' && $user->rights->commande->creer)
{
$datecommande = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $datecommande = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
$datelivraison = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year')); $datelivraison = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
@ -239,7 +248,8 @@ if (empty($reshook))
$object->contactid = GETPOST('contactid'); $object->contactid = GETPOST('contactid');
// If creation from another object of another module (Example: origin=propal, originid=1) // If creation from another object of another module (Example: origin=propal, originid=1)
if (! empty($origin) && ! empty($originid)) { if (! empty($origin) && ! empty($originid))
{
// Parse element/subelement (ex: project_task) // Parse element/subelement (ex: project_task)
$element = $subelement = $origin; $element = $subelement = $origin;
if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) { if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
@ -385,8 +395,10 @@ if (empty($reshook))
} }
// Insert default contacts if defined // Insert default contacts if defined
if ($object_id > 0) { if ($object_id > 0)
if (GETPOST('contactid')) { {
if (GETPOST('contactid'))
{
$result = $object->add_contact(GETPOST('contactid'), 'CUSTOMER', 'external'); $result = $object->add_contact(GETPOST('contactid'), 'CUSTOMER', 'external');
if ($result < 0) { if ($result < 0) {
setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors'); setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors');
@ -399,7 +411,8 @@ if (empty($reshook))
} }
// End of object creation, we show it // End of object creation, we show it
if ($object_id > 0 && ! $error) { if ($object_id > 0 && ! $error)
{
$db->commit(); $db->commit();
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object_id); header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object_id);
exit(); exit();
@ -1594,7 +1607,8 @@ if ($action == 'create' && $user->rights->commande->creer)
/* /*
* Confirmation de la validation * Confirmation de la validation
*/ */
if ($action == 'validate') { if ($action == 'validate')
{
// on verifie si l'objet est en numerotation provisoire // on verifie si l'objet est en numerotation provisoire
$ref = substr($object->ref, 1, 4); $ref = substr($object->ref, 1, 4);
if ($ref == 'PROV') { if ($ref == 'PROV') {
@ -1604,7 +1618,8 @@ if ($action == 'create' && $user->rights->commande->creer)
} }
$text = $langs->trans('ConfirmValidateOrder', $numref); $text = $langs->trans('ConfirmValidateOrder', $numref);
if (! empty($conf->notification->enabled)) { if (! empty($conf->notification->enabled))
{
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
$notify = new Notify($db); $notify = new Notify($db);
$text .= '<br>'; $text .= '<br>';

View File

@ -175,8 +175,8 @@ abstract class CommonObject
/** /**
* Add a link between element $this->element and a contact * Add a link between element $this->element and a contact
* *
* @param int $fk_socpeople Id of contact to link * @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link
* @param int $type_contact Type of contact (code or id). For example: SALESREPFOLL * @param int $type_contact Type of contact (code or id). Must be if or code found into table llx_c_type_contact. For example: SALESREPFOLL
* @param int $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user) * @param int $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user)
* @param int $notrigger Disable all triggers * @param int $notrigger Disable all triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK

View File

@ -613,7 +613,7 @@ class CommandeFournisseur extends CommonOrder
} }
/** /**
* Accept an order * Approve a supplier order
* *
* @param User $user Object user * @param User $user Object user
* @param int $idwarehouse Id of warhouse for stock change * @param int $idwarehouse Id of warhouse for stock change
@ -659,6 +659,15 @@ class CommandeFournisseur extends CommonOrder
{ {
$this->log($user, 2, time()); // Statut 2 $this->log($user, 2, time()); // Statut 2
if (! empty($conf->global->SUPPLIER_ORDER_AUTOADD_USER_CONTACT))
{
$result=$this->add_contact($user->id, 'SALESREPFOLL', 'internal', 1);
if ($result < 0)
{
$error++;
}
}
// If stock is incremented on validate order, we must increment it // If stock is incremented on validate order, we must increment it
if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)) if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER))
{ {
@ -967,8 +976,8 @@ class CommandeFournisseur extends CommonOrder
dol_syslog(get_class($this)."::create", LOG_DEBUG); dol_syslog(get_class($this)."::create", LOG_DEBUG);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
// On logue creation pour historique // Add entry into log
$this->log($user, 0, time()); $this->log($user, 0, $now);
if (! $error) if (! $error)
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2004-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2004-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
@ -2232,8 +2232,12 @@ elseif (! empty($object->id))
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->commande->creer)) if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->commande->creer))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->supplier_order_advance->validate))) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->supplier_order_advance->validate)))
{ {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid"'; $tmpbuttonlabel=$langs->trans('Validate');
print '>'.$langs->trans('Validate').'</a>'; if ($user->rights->fournisseur->commande->approuver) $tmpbuttonlabel = $langs->trans("ValidateAndApprove");
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid">';
print $tmpbuttonlabel;
print '</a>';
} }
} }