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
else if ($action == 'reopen' && $user->rights->commande->creer) {
if ($object->statut == 3) {
else if ($action == 'reopen' && $user->rights->commande->creer)
{
if ($object->statut == 3)
{
$result = $object->set_reopen($user);
if ($result > 0)
{
@ -153,21 +155,26 @@ if (empty($reshook))
}
// 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);
if ($result > 0) {
if ($result > 0)
{
header('Location: index.php');
exit;
}
else {
else
{
setEventMessage($object->error, 'errors');
}
}
// 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);
if ($result > 0) {
if ($result > 0)
{
// Define output language
$outputlangs = $langs;
$newlang = '';
@ -194,12 +201,14 @@ if (empty($reshook))
}
// Categorisation dans projet
else if ($action == 'classin' && $user->rights->commande->creer) {
else if ($action == 'classin' && $user->rights->commande->creer)
{
$object->setProject(GETPOST('projectid'));
}
// 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'));
$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');
// 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)
$element = $subelement = $origin;
if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
@ -301,37 +311,37 @@ if (empty($reshook))
for($i = 0; $i < $num; $i ++)
{
$label = (! empty($lines [$i]->label) ? $lines [$i]->label : '');
$desc = (! empty($lines [$i]->desc) ? $lines [$i]->desc : $lines [$i]->libelle);
$product_type = (! empty($lines [$i]->product_type) ? $lines [$i]->product_type : 0);
$label = (! empty($lines[$i]->label) ? $lines[$i]->label : '');
$desc = (! empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
$product_type = (! empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
// Dates
// TODO mutualiser
$date_start = $lines [$i]->date_debut_prevue;
if ($lines [$i]->date_debut_reel)
$date_start = $lines [$i]->date_debut_reel;
if ($lines [$i]->date_start)
$date_start = $lines [$i]->date_start;
$date_end = $lines [$i]->date_fin_prevue;
if ($lines [$i]->date_fin_reel)
$date_end = $lines [$i]->date_fin_reel;
if ($lines [$i]->date_end)
$date_end = $lines [$i]->date_end;
$date_start = $lines[$i]->date_debut_prevue;
if ($lines[$i]->date_debut_reel)
$date_start = $lines[$i]->date_debut_reel;
if ($lines[$i]->date_start)
$date_start = $lines[$i]->date_start;
$date_end = $lines[$i]->date_fin_prevue;
if ($lines[$i]->date_fin_reel)
$date_end = $lines[$i]->date_fin_reel;
if ($lines[$i]->date_end)
$date_end = $lines[$i]->date_end;
// Reset fk_parent_line for no child products and special product
if (($lines [$i]->product_type != 9 && empty($lines [$i]->fk_parent_line)) || $lines [$i]->product_type == 9) {
if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
$fk_parent_line = 0;
}
// Extrafields
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines [$i], 'fetch_optionals')) // For avoid conflicts if
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i], 'fetch_optionals')) // For avoid conflicts if
// trigger used
{
$lines [$i]->fetch_optionals($lines [$i]->rowid);
$array_option = $lines [$i]->array_options;
$lines[$i]->fetch_optionals($lines[$i]->rowid);
$array_option = $lines[$i]->array_options;
}
$result = $object->addline($desc, $lines [$i]->subprice, $lines [$i]->qty, $lines [$i]->tva_tx, $lines [$i]->localtax1_tx, $lines [$i]->localtax2_tx, $lines [$i]->fk_product, $lines [$i]->remise_percent, $lines [$i]->info_bits, $lines [$i]->fk_remise_except, 'HT', 0, $date_start, $date_end, $product_type, $lines [$i]->rang, $lines [$i]->special_code, $fk_parent_line, $lines [$i]->fk_fournprice, $lines [$i]->pa_ht, $label, $array_option);
$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $date_start, $date_end, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_option);
if ($result < 0) {
$error ++;
@ -339,7 +349,7 @@ if (empty($reshook))
}
// Defined the new fk_parent_line
if ($result > 0 && $lines [$i]->product_type == 9) {
if ($result > 0 && $lines[$i]->product_type == 9) {
$fk_parent_line = $result;
}
}
@ -385,8 +395,10 @@ if (empty($reshook))
}
// Insert default contacts if defined
if ($object_id > 0) {
if (GETPOST('contactid')) {
if ($object_id > 0)
{
if (GETPOST('contactid'))
{
$result = $object->add_contact(GETPOST('contactid'), 'CUSTOMER', 'external');
if ($result < 0) {
setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors');
@ -399,7 +411,8 @@ if (empty($reshook))
}
// End of object creation, we show it
if ($object_id > 0 && ! $error) {
if ($object_id > 0 && ! $error)
{
$db->commit();
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object_id);
exit();
@ -1594,7 +1607,8 @@ if ($action == 'create' && $user->rights->commande->creer)
/*
* Confirmation de la validation
*/
if ($action == 'validate') {
if ($action == 'validate')
{
// on verifie si l'objet est en numerotation provisoire
$ref = substr($object->ref, 1, 4);
if ($ref == 'PROV') {
@ -1604,7 +1618,8 @@ if ($action == 'create' && $user->rights->commande->creer)
}
$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';
$notify = new Notify($db);
$text .= '<br>';

View File

@ -175,8 +175,8 @@ abstract class CommonObject
/**
* Add a link between element $this->element and a contact
*
* @param int $fk_socpeople Id of contact to link
* @param int $type_contact Type of contact (code or id). For example: SALESREPFOLL
* @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). 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 $notrigger Disable all triggers
* @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 int $idwarehouse Id of warhouse for stock change
@ -659,6 +659,15 @@ class CommandeFournisseur extends CommonOrder
{
$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 (! $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);
if ($this->db->query($sql))
{
// On logue creation pour historique
$this->log($user, 0, time());
// Add entry into log
$this->log($user, 0, $now);
if (! $error)
{

View File

@ -1,6 +1,6 @@
<?php
/* 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-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
@ -1601,13 +1601,13 @@ elseif (! empty($object->id))
}
print '</td></tr>';
// Delai livraison jours
print '<tr>';
print '<td>'.$langs->trans('NbDaysToDelivery').'&nbsp;'.img_picto($langs->trans('DescNbDaysToDelivery'), 'info', 'style="cursor:help"').'</td>';
print '<td>'.$object->getMaxDeliveryTimeDay($langs).'</td>';
print '</tr>';
// Project
if (! empty($conf->projet->enabled))
{
@ -2232,8 +2232,12 @@ elseif (! empty($object->id))
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)))
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid"';
print '>'.$langs->trans('Validate').'</a>';
$tmpbuttonlabel=$langs->trans('Validate');
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>';
}
}