Merge pull request #5586 from atm-florian/dev_NEW_ClassOrderDeliverStatusOnStockVentil

NEW : Add workflow to calculated supplier order status on stock dispatch
This commit is contained in:
Laurent Destailleur 2016-08-05 18:15:04 +02:00 committed by GitHub
commit 126d9ae6bf
6 changed files with 793 additions and 659 deletions

View File

@ -73,12 +73,22 @@ if($action)
|| $action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER' || $action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER'
|| $action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') || $action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')
{ {
//Use variable cause empty(GETPOST()) do not work with php version < 5.4
$valdispatch=GETPOST('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER','alpha');
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", '','chaine',0,'',$conf->entity); $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", '','chaine',0,'',$conf->entity);
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", '','chaine',0,'',$conf->entity); $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", '','chaine',0,'',$conf->entity);
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", '','chaine',0,'',$conf->entity); $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", '','chaine',0,'',$conf->entity);
if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_BILL','alpha'),'chaine',0,'',$conf->entity); if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_BILL','alpha'),'chaine',0,'',$conf->entity);
if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER','alpha'),'chaine',0,'',$conf->entity); if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER','alpha'),'chaine',0,'',$conf->entity);
if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER','alpha'),'chaine',0,'',$conf->entity); if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", $valdispatch,'chaine',0,'',$conf->entity);
if (empty($valdispatch)) {
$res=dolibarr_set_const($db, "SUPPLIER_ORDER_USE_DISPATCH_STATUS", '','chaine',0,'',$conf->entity);
}
}
if($action == 'SUPPLIER_ORDER_USE_DISPATCH_STATUS') {
$res = dolibarr_set_const($db, "SUPPLIER_ORDER_USE_DISPATCH_STATUS", GETPOST('SUPPLIER_ORDER_USE_DISPATCH_STATUS','alpha'),'chaine',0,'',$conf->entity);
} }
if($action == 'STOCK_USE_VIRTUAL_STOCK') { if($action == 'STOCK_USE_VIRTUAL_STOCK') {
@ -311,6 +321,27 @@ else
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")); print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
} }
print "</td>\n</tr>\n"; print "</td>\n</tr>\n";
if (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
$var=!$var;
print "<tr ".$bc[$var].">";
print '<td width="60%">'.$langs->trans("UseDispatchStatus").'</td>';
print '<td width="160" align="right">';
if (! empty($conf->fournisseur->enabled))
{
print "<form method=\"post\" action=\"stock.php\">";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print "<input type=\"hidden\" name=\"action\" value=\"SUPPLIER_ORDER_USE_DISPATCH_STATUS\">";
print $form->selectyesno("SUPPLIER_ORDER_USE_DISPATCH_STATUS",$conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS,1,$disabled);
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"'.$disabled.'>';
print "</form>\n";
}
else
{
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
}
print "</td>\n</tr>\n";
}
$found++; $found++;
/*if (! $found) /*if (! $found)

View File

@ -2686,6 +2686,63 @@ class CommandeFournisseur extends CommonOrder
return $text; return $text;
} }
/**
* Calc status regarding dispatch stock
*
* @param User $user User action
* @return int <0 si ko, >0 si ok
*/
public function calcAndSetStatusDispatch(User $user) {
global $conf;
if (! empty($conf->commande->enabled) && ! empty($conf->fournisseur->enabled))
{
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
$qtydelivered=array();
$qtywished=array();
$supplierorderdispatch = new CommandeFournisseurDispatch($this->db);
$filter=array('t.fk_commande'=>$this->id);
if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
$filter['t.status']=1;
}
$ret=$supplierorderdispatch->fetchAll('','',0,0,$filter);
if ($ret<0) {
$this->error=$supplierorderdispatch->error; $this->errors=$supplierorderdispatch->errors;
return $ret;
} else {
if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines)>0) {
//Build array with quantity deliverd by product
foreach($supplierorderdispatch->lines as $line) {
$qtydelivered[$line->fk_product]+=$line->qty;
}
foreach($this->lines as $line) {
$qtywished[$line->fk_product]+=$line->qty;
}
//Compare array
$diff_array=array_diff_assoc($qtydelivered,$qtywished);
if (count($diff_array)==0) {
//No diff => mean everythings is received
$ret=$this->setStatus($user,5);
if ($ret<0) {
$this->error=$object->error; $this->errors=$object->errors;
}
} else {
//Diff => received partially
$ret=$this->setStatus($user,4);
if ($ret<0) {
$this->error=$object->error; $this->errors=$object->errors;
}
}
}
}
return 1;
}
}
} }

View File

@ -34,27 +34,28 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
*/ */
class CommandeFournisseurDispatch extends CommonObject class CommandeFournisseurDispatch extends CommonObject
{ {
var $db; //!< To store db handler public $db; //!< To store db handler
var $error; //!< To return error code (or message) public $error; //!< To return error code (or message)
var $errors=array(); //!< To return several error codes (or messages) public $errors=array(); //!< To return several error codes (or messages)
var $element='commandefournisseurdispatch'; //!< Id that identify managed objects public $element='commandefournisseurdispatch'; //!< Id that identify managed objects
var $table_element='commande_fournisseur_dispatch'; //!< Name of table without prefix where object is stored public $table_element='commande_fournisseur_dispatch'; //!< Name of table without prefix where object is stored
public $lines=array();
var $id; public $id;
var $fk_commande; public $fk_commande;
var $fk_product; public $fk_product;
var $fk_commandefourndet; public $fk_commandefourndet;
var $qty; public $qty;
var $fk_entrepot; public $fk_entrepot;
var $fk_user; public $fk_user;
var $datec=''; public $datec='';
var $comment; public $comment;
var $status; public $status;
var $tms=''; public $tms='';
var $batch; public $batch;
var $eatby=''; public $eatby='';
var $sellby=''; public $sellby='';
@ -539,4 +540,100 @@ class CommandeFournisseurDispatch extends CommonObject
} }
/**
* Load object in memory from the database
*
* @param string $sortorder Sort Order
* @param string $sortfield Sort field
* @param int $limit offset limit
* @param int $offset offset limit
* @param array $filter filter array
* @param string $filtermode filter mode (AND or OR)
*
* @return int <0 if KO, >0 if OK
*/
public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
{
dol_syslog(__METHOD__, LOG_DEBUG);
$sql = "SELECT";
$sql.= " t.rowid,";
$sql.= " t.fk_commande,";
$sql.= " t.fk_product,";
$sql.= " t.fk_commandefourndet,";
$sql.= " t.qty,";
$sql.= " t.fk_entrepot,";
$sql.= " t.fk_user,";
$sql.= " t.datec,";
$sql.= " t.comment,";
$sql.= " t.status,";
$sql.= " t.tms,";
$sql.= " t.batch,";
$sql.= " t.eatby,";
$sql.= " t.sellby";
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
if ($key=='t.comment') {
$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
} elseif ($key=='t.datec' || $key=='t.tms' || $key=='t.eatby' || $key=='t.sellby' || $key=='t.batch') {
$sqlwhere [] = $key . ' = \'' . $this->db->escape($value) . '\'';
} else {
$sqlwhere [] = $key . ' = ' . $this->db->escape($value);
}
}
}
if (count($sqlwhere) > 0) {
$sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere);
}
if (!empty($sortfield)) {
$sql .= $this->db->order($sortfield,$sortorder);
}
if (!empty($limit)) {
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
}
$this->lines = array();
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
while ($obj = $this->db->fetch_object($resql)) {
$line = new self($this->db);
$line->id = $obj->rowid;
$line->fk_commande = $obj->fk_commande;
$line->fk_product = $obj->fk_product;
$line->fk_commandefourndet = $obj->fk_commandefourndet;
$line->qty = $obj->qty;
$line->fk_entrepot = $obj->fk_entrepot;
$line->fk_user = $obj->fk_user;
$line->datec = $this->db->jdate($obj->datec);
$line->comment = $obj->comment;
$line->status = $obj->status;
$line->tms = $this->db->jdate($obj->tms);
$line->batch = $obj->batch;
$line->eatby = $this->db->jdate($obj->eatby);
$line->sellby = $this->db->jdate($obj->sellby);
$this->lines[$line->id] = $line;
}
$this->db->free($resql);
return $num;
} else {
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
return - 1;
}
}
} }

View File

@ -5,6 +5,7 @@
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014 Cedric Gross <c.gross@kreiz-it.fr> * Copyright (C) 2014 Cedric Gross <c.gross@kreiz-it.fr>
* Copyright (C) 2016 Florian Henry <florian.henry@atm-consulting.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -26,7 +27,6 @@
* \ingroup commande * \ingroup commande
* \brief Page to dispatch receiving * \brief Page to dispatch receiving
*/ */
require '../../main.inc.php'; require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_order/modules_commandefournisseur.php'; require_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_order/modules_commandefournisseur.php';
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php'; require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
@ -34,7 +34,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php'; require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.dispatch.class.php'; require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.dispatch.class.php';
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; if (! empty($conf->projet->enabled))
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
$langs->load('orders'); $langs->load('orders');
$langs->load('sendings'); $langs->load('sendings');
@ -43,96 +44,112 @@ $langs->load('bills');
$langs->load('deliveries'); $langs->load('deliveries');
$langs->load('products'); $langs->load('products');
$langs->load('stocks'); $langs->load('stocks');
if (! empty($conf->productbatch->enabled)) $langs->load('productbatch'); if (! empty($conf->productbatch->enabled))
$langs->load('productbatch');
// Security check // Security check
$id = GETPOST("id", 'int'); $id = GETPOST("id", 'int');
$ref = GETPOST('ref');
$lineid = GETPOST('lineid', 'int'); $lineid = GETPOST('lineid', 'int');
$action = GETPOST('action'); $action = GETPOST('action');
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id)
$socid = $user->societe_id;
$result = restrictedArea($user, 'fournisseur', $id, '', 'commande'); $result = restrictedArea($user, 'fournisseur', $id, '', 'commande');
if (empty($conf->stock->enabled)) if (empty($conf->stock->enabled)) {
{
accessforbidden(); accessforbidden();
} }
// Recuperation de l'id de projet // Recuperation de l'id de projet
$projectid = 0; $projectid = 0;
if ($_GET["projectid"]) $projectid = GETPOST("projectid",'int'); if ($_GET["projectid"])
$projectid = GETPOST("projectid", 'int');
$mesg='';
$commande = new CommandeFournisseur($db);
if ($id > 0 || ! empty($ref)) {
$result = $commande->fetch($id, $ref);
if ($result < 0) {
setEventMessages($commande->error, $commande->errors, 'errors');
}
$result = $commande->fetch_thirdparty();
if ($result < 0) {
setEventMessages($commande->error, $commande->errors, 'errors');
}
}
/* /*
* Actions * Actions
*/ */
if ($action == 'checkdispatchline' && if ($action == 'checkdispatchline' && ! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))) {
! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))
)
{
$supplierorderdispatch = new CommandeFournisseurDispatch($db); $supplierorderdispatch = new CommandeFournisseurDispatch($db);
$result = $supplierorderdispatch->fetch($lineid); $result = $supplierorderdispatch->fetch($lineid);
if (! $result) dol_print_error($db); if (! $result)
dol_print_error($db);
$result = $supplierorderdispatch->setStatut(1); $result = $supplierorderdispatch->setStatut(1);
if ($result < 0) if ($result < 0) {
{
setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors'); setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
$error ++; $error ++;
$action = ''; $action = '';
} else {
$result = $commande->calcAndSetStatusDispatch($user);
if ($result < 0) {
setEventMessages($commande->error, $commande->errors, 'errors');
$error ++;
$action = '';
}
} }
} }
if ($action == 'uncheckdispatchline' && if ($action == 'uncheckdispatchline' && ! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))) {
! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))
)
{
$supplierorderdispatch = new CommandeFournisseurDispatch($db); $supplierorderdispatch = new CommandeFournisseurDispatch($db);
$result = $supplierorderdispatch->fetch($lineid); $result = $supplierorderdispatch->fetch($lineid);
if (! $result) dol_print_error($db); if (! $result)
dol_print_error($db);
$result = $supplierorderdispatch->setStatut(0); $result = $supplierorderdispatch->setStatut(0);
if ($result < 0) if ($result < 0) {
{
setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors'); setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
$error ++; $error ++;
$action = ''; $action = '';
} else {
$result = $commande->calcAndSetStatusDispatch($user);
if ($result < 0) {
setEventMessages($commande->error, $commande->errors, 'errors');
$error ++;
$action = '';
}
} }
} }
if ($action == 'denydispatchline' && if ($action == 'denydispatchline' && ! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))) {
! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))
)
{
$supplierorderdispatch = new CommandeFournisseurDispatch($db); $supplierorderdispatch = new CommandeFournisseurDispatch($db);
$result = $supplierorderdispatch->fetch($lineid); $result = $supplierorderdispatch->fetch($lineid);
if (! $result) dol_print_error($db); if (! $result)
dol_print_error($db);
$result = $supplierorderdispatch->setStatut(2); $result = $supplierorderdispatch->setStatut(2);
if ($result < 0) if ($result < 0) {
{
setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors'); setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
$error ++; $error ++;
$action = ''; $action = '';
} else {
$result = $commande->calcAndSetStatusDispatch($user);
if ($result < 0) {
setEventMessages($commande->error, $commande->errors, 'errors');
$error ++;
$action = '';
}
} }
} }
if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner) if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner) {
{
$commande = new CommandeFournisseur($db);
$commande->fetch($id);
$error = 0; $error = 0;
$db->begin(); $db->begin();
$pos = 0; $pos = 0;
foreach($_POST as $key => $value) foreach ( $_POST as $key => $value ) {
{ // without batch module enabled
if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) // without batch module enabled if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
{
$pos ++; $pos ++;
// $numline=$reg[2] + 1; // line of product // $numline=$reg[2] + 1; // line of product
@ -143,29 +160,26 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
$pu = "pu_" . $reg[1] . '_' . $reg[2]; // This is unit price including discount $pu = "pu_" . $reg[1] . '_' . $reg[2]; // This is unit price including discount
$fk_commandefourndet = "fk_commandefourndet_" . $reg[1] . '_' . $reg[2]; $fk_commandefourndet = "fk_commandefourndet_" . $reg[1] . '_' . $reg[2];
if (GETPOST($qty) > 0) // We ask to move a qty // We ask to move a qty
{ if (GETPOST($qty) > 0) {
if (! (GETPOST($ent,'int') > 0)) if (! (GETPOST($ent, 'int') > 0)) {
{
dol_syslog('No dispatch for line ' . $key . ' as no warehouse choosed'); dol_syslog('No dispatch for line ' . $key . ' as no warehouse choosed');
$text = $langs->transnoentities('Warehouse') . ', ' . $langs->transnoentities('Line') . ' ' . ($numline); $text = $langs->transnoentities('Warehouse') . ', ' . $langs->transnoentities('Line') . ' ' . ($numline);
setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors'); setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors');
$error ++; $error ++;
} }
if (! $error) if (! $error) {
{ $result = $commande->dispatchProduct($user, GETPOST($prod, 'int'), GETPOST($qty), GETPOST($ent, 'int'), GETPOST($pu), GETPOST('comment'), '', '', '', GETPOST($fk_commandefourndet, 'int'), $notrigger);
$result = $commande->DispatchProduct($user, GETPOST($prod,'int'), GETPOST($qty), GETPOST($ent,'int'), GETPOST($pu), GETPOST('comment'), '', '', '', GETPOST($fk_commandefourndet, 'int'), $notrigger); if ($result < 0) {
if ($result < 0)
{
setEventMessages($commande->error, $commande->errors, 'errors'); setEventMessages($commande->error, $commande->errors, 'errors');
$error ++; $error ++;
} }
} }
} }
} }
if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) // with batch module enabled // with batch module enabled
{ if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
$pos ++; $pos ++;
// eat-by date dispatch // eat-by date dispatch
@ -182,29 +196,25 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
$fk_commandefourndet = 'fk_commandefourndet_' . $reg[1] . '_' . $reg[2]; $fk_commandefourndet = 'fk_commandefourndet_' . $reg[1] . '_' . $reg[2];
if (GETPOST($qty) > 0) // We ask to move a qty // We ask to move a qty
{ if (GETPOST($qty) > 0) {
if (! (GETPOST($ent,'int') > 0)) if (! (GETPOST($ent, 'int') > 0)) {
{
dol_syslog('No dispatch for line ' . $key . ' as no warehouse choosed'); dol_syslog('No dispatch for line ' . $key . ' as no warehouse choosed');
$text = $langs->transnoentities('Warehouse') . ', ' . $langs->transnoentities('Line') . ' ' . ($numline) . '-' . ($reg[1] + 1); $text = $langs->transnoentities('Warehouse') . ', ' . $langs->transnoentities('Line') . ' ' . ($numline) . '-' . ($reg[1] + 1);
setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors'); setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors');
$error ++; $error ++;
} }
if (! (GETPOST($lot, 'alpha') || $dDLUO || $dDLC)) if (! (GETPOST($lot, 'alpha') || $dDLUO || $dDLC)) {
{
dol_syslog('No dispatch for line ' . $key . ' as serial/eat-by/sellby date are not set'); dol_syslog('No dispatch for line ' . $key . ' as serial/eat-by/sellby date are not set');
$text = $langs->transnoentities('atleast1batchfield') . ', ' . $langs->transnoentities('Line') . ' ' . ($numline) . '-' . ($reg[1] + 1); $text = $langs->transnoentities('atleast1batchfield') . ', ' . $langs->transnoentities('Line') . ' ' . ($numline) . '-' . ($reg[1] + 1);
setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors'); setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors');
$error ++; $error ++;
} }
if (! $error) if (! $error) {
{
$result = $commande->dispatchProduct($user, GETPOST($prod, 'int'), GETPOST($qty), GETPOST($ent, 'int'), GETPOST($pu), GETPOST('comment'), $dDLC, $dDLUO, GETPOST($lot, 'alpha'), GETPOST($fk_commandefourndet, 'int'), $notrigger); $result = $commande->dispatchProduct($user, GETPOST($prod, 'int'), GETPOST($qty), GETPOST($ent, 'int'), GETPOST($pu), GETPOST('comment'), $dDLC, $dDLUO, GETPOST($lot, 'alpha'), GETPOST($fk_commandefourndet, 'int'), $notrigger);
if ($result < 0) if ($result < 0) {
{
setEventMessages($commande->error, $commande->errors, 'errors'); setEventMessages($commande->error, $commande->errors, 'errors');
$error ++; $error ++;
} }
@ -213,34 +223,37 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
} }
} }
if (! $notrigger && ! $error) if (! $error) {
{ $result = $commande->calcAndSetStatusDispatch($user);
if ($result < 0) {
setEventMessages($commande->error, $commande->errors, 'errors');
$error ++;
}
}
if (! $notrigger && ! $error) {
global $conf, $langs, $user; global $conf, $langs, $user;
// Call trigger // Call trigger
$result = $commande->call_trigger('ORDER_SUPPLIER_DISPATCH', $user); $result = $commande->call_trigger('ORDER_SUPPLIER_DISPATCH', $user);
// End call triggers // End call triggers
if ($result < 0) if ($result < 0) {
{
setEventMessages($commande->error, $commande->errors, 'errors'); setEventMessages($commande->error, $commande->errors, 'errors');
$error ++; $error ++;
} }
} }
if ($result >= 0 && ! $error) if ($result >= 0 && ! $error) {
{
$db->commit(); $db->commit();
header("Location: dispatch.php?id=" . $id); header("Location: dispatch.php?id=" . $id);
exit; exit();
} } else {
else
{
$db->rollback(); $db->rollback();
} }
} }
/* /*
* View * View
*/ */
@ -250,23 +263,14 @@ $formproduct = new FormProduct($db);
$warehouse_static = new Entrepot($db); $warehouse_static = new Entrepot($db);
$supplierorderdispatch = new CommandeFournisseurDispatch($db); $supplierorderdispatch = new CommandeFournisseurDispatch($db);
$help_url = 'EN:CommandeFournisseur'; $help_url = 'EN:CommandeFournisseur';
llxHeader('',$langs->trans("OrderCard"),$help_url,'',0,0,array('/fourn/js/lib_dispatch.js')); llxHeader('', $langs->trans("OrderCard"), $help_url, '', 0, 0, array(
'/fourn/js/lib_dispatch.js'
));
$now = dol_now(); $now = dol_now();
$id = GETPOST('id','int'); if ($id > 0 || ! empty($ref)) {
$ref= GETPOST('ref');
if ($id > 0 || ! empty($ref))
{
//if ($mesg) print $mesg.'<br>';
$commande = new CommandeFournisseur($db);
$result=$commande->fetch($id,$ref);
if ($result >= 0)
{
$soc = new Societe($db); $soc = new Societe($db);
$soc->fetch($commande->socid); $soc->fetch($commande->socid);
@ -303,17 +307,14 @@ if ($id > 0 || ! empty($ref))
print "</td></tr>"; print "</td></tr>";
// Date // Date
if ($commande->methode_commande_id > 0) if ($commande->methode_commande_id > 0) {
{
print '<tr><td>' . $langs->trans("Date") . '</td><td colspan="2">'; print '<tr><td>' . $langs->trans("Date") . '</td><td colspan="2">';
if ($commande->date_commande) if ($commande->date_commande) {
{
print dol_print_date($commande->date_commande, "dayhourtext") . "\n"; print dol_print_date($commande->date_commande, "dayhourtext") . "\n";
} }
print "</td></tr>"; print "</td></tr>";
if ($commande->methode_commande) if ($commande->methode_commande) {
{
print '<tr><td>' . $langs->trans("Method") . '</td><td colspan="2">' . $commande->methode_commande . '</td></tr>'; print '<tr><td>' . $langs->trans("Method") . '</td><td colspan="2">' . $commande->methode_commande . '</td></tr>';
} }
} }
@ -328,20 +329,18 @@ if ($id > 0 || ! empty($ref))
// if ($mesg) print $mesg; // if ($mesg) print $mesg;
print '<br>'; print '<br>';
$disabled = 1; $disabled = 1;
if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) $disabled=0; if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER))
$disabled = 0;
/* /*
* Lignes de commandes * Lignes de commandes
*/ */
if ($commande->statut <= 2 || $commande->statut >= 6) if ($commande->statut <= 2 || $commande->statut >= 6) {
{
print $langs->trans("OrderStatusNotReadyToDispatch"); print $langs->trans("OrderStatusNotReadyToDispatch");
} }
if ($commande->statut == 3 || $commande->statut == 4 || $commande->statut == 5) if ($commande->statut == 3 || $commande->statut == 4 || $commande->statut == 5) {
{
$entrepot = new Entrepot($db); $entrepot = new Entrepot($db);
$listwarehouses = $entrepot->list_array(1); $listwarehouses = $entrepot->list_array(1);
@ -359,15 +358,12 @@ if ($id > 0 || ! empty($ref))
$sql .= " GROUP BY l.rowid, cfd.fk_product"; $sql .= " GROUP BY l.rowid, cfd.fk_product";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
if ($num) if ($num) {
{ while ( $i < $num ) {
while ($i < $num)
{
$objd = $db->fetch_object($resql); $objd = $db->fetch_object($resql);
$products_dispatched[$objd->rowid] = price2num($objd->qty, 5); $products_dispatched[$objd->rowid] = price2num($objd->qty, 5);
$i ++; $i ++;
@ -381,18 +377,17 @@ if ($id > 0 || ! empty($ref))
$sql .= " FROM " . MAIN_DB_PREFIX . "commande_fournisseurdet as l"; $sql .= " FROM " . MAIN_DB_PREFIX . "commande_fournisseurdet as l";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON l.fk_product=p.rowid"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON l.fk_product=p.rowid";
$sql .= " WHERE l.fk_commande = " . $commande->id; $sql .= " WHERE l.fk_commande = " . $commande->id;
if(empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql.= " AND l.product_type = 0"; if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
$sql .= " AND l.product_type = 0";
$sql .= " GROUP BY p.ref, p.label, p.tobatch, l.rowid, l.fk_product, l.subprice, l.remise_percent"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product $sql .= " GROUP BY p.ref, p.label, p.tobatch, l.rowid, l.fk_product, l.subprice, l.remise_percent"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product
$sql .= " ORDER BY p.ref, p.label"; $sql .= " ORDER BY p.ref, p.label";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
if ($num) if ($num) {
{
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>' . $langs->trans("Description") . '</td>'; print '<td>' . $langs->trans("Description") . '</td>';
@ -405,8 +400,7 @@ if ($id > 0 || ! empty($ref))
print '<td align="right">' . $langs->trans("Warehouse") . '</td>'; print '<td align="right">' . $langs->trans("Warehouse") . '</td>';
print "</tr>\n"; print "</tr>\n";
if (! empty($conf->productbatch->enabled)) if (! empty($conf->productbatch->enabled)) {
{
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td></td>'; print '<td></td>';
print '<td>' . $langs->trans("batch_number") . '</td>'; print '<td>' . $langs->trans("batch_number") . '</td>';
@ -415,29 +409,24 @@ if ($id > 0 || ! empty($ref))
print '<td colspan="4">&nbsp;</td>'; print '<td colspan="4">&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
} }
} }
$nbfreeproduct = 0; $nbfreeproduct = 0;
$nbproduct = 0; $nbproduct = 0;
$var = false; $var = false;
while ($i < $num) while ( $i < $num ) {
{
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
// On n'affiche pas les produits personnalises // On n'affiche pas les produits personnalises
if (! $objp->fk_product > 0) if (! $objp->fk_product > 0) {
{
$nbfreeproduct ++; $nbfreeproduct ++;
} } else {
else
{
$remaintodispatch = price2num($objp->qty - (( float ) $products_dispatched[$objp->rowid]), 5); // Calculation of dispatched $remaintodispatch = price2num($objp->qty - (( float ) $products_dispatched[$objp->rowid]), 5); // Calculation of dispatched
if ($remaintodispatch < 0) $remaintodispatch=0; if ($remaintodispatch < 0)
$remaintodispatch = 0;
if ($remaintodispatch || empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) if ($remaintodispatch || empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) {
{
$nbproduct ++; $nbproduct ++;
$var = ! $var; $var = ! $var;
@ -454,16 +443,12 @@ if ($id > 0 || ! empty($ref))
$linktoprod = '<a href="' . DOL_URL_ROOT . '/product/fournisseurs.php?id=' . $objp->fk_product . '">' . img_object($langs->trans("ShowProduct"), 'product') . ' ' . $objp->ref . '</a>'; $linktoprod = '<a href="' . DOL_URL_ROOT . '/product/fournisseurs.php?id=' . $objp->fk_product . '">' . img_object($langs->trans("ShowProduct"), 'product') . ' ' . $objp->ref . '</a>';
$linktoprod .= ' - ' . $objp->label . "\n"; $linktoprod .= ' - ' . $objp->label . "\n";
if (! empty($conf->productbatch->enabled)) if (! empty($conf->productbatch->enabled)) {
{ if ($objp->tobatch) {
if ($objp->tobatch)
{
print '<td colspan="4">'; print '<td colspan="4">';
print $linktoprod; print $linktoprod;
print "</td>"; print "</td>";
} } else {
else
{
print '<td>'; print '<td>';
print $linktoprod; print $linktoprod;
print "</td>"; print "</td>";
@ -471,9 +456,7 @@ if ($id > 0 || ! empty($ref))
print $langs->trans("ProductDoesNotUseBatchSerial"); print $langs->trans("ProductDoesNotUseBatchSerial");
print '</td>'; print '</td>';
} }
} } else {
else
{
print '<td colspan="4">'; print '<td colspan="4">';
print $linktoprod; print $linktoprod;
print "</td>"; print "</td>";
@ -481,7 +464,8 @@ if ($id > 0 || ! empty($ref))
$var = ! $var; $var = ! $var;
$up_ht_disc = $objp->subprice; $up_ht_disc = $objp->subprice;
if (! empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU'); if (! empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP))
$up_ht_disc = price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU');
// Qty ordered // Qty ordered
print '<td align="right">' . $objp->qty . '</td>'; print '<td align="right">' . $objp->qty . '</td>';
@ -489,8 +473,7 @@ if ($id > 0 || ! empty($ref))
// Already dispatched // Already dispatched
print '<td align="right">' . $products_dispatched[$objp->rowid] . '</td>'; print '<td align="right">' . $products_dispatched[$objp->rowid] . '</td>';
if (! empty($conf->productbatch->enabled) && $objp->tobatch==1) if (! empty($conf->productbatch->enabled) && $objp->tobatch == 1) {
{
$type = 'batch'; $type = 'batch';
print '<td align="right">' . img_picto($langs->trans('AddDispatchBatchLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"') . '</td>'; // Dispatch column print '<td align="right">' . img_picto($langs->trans('AddDispatchBatchLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"') . '</td>'; // Dispatch column
print '<td></td>'; // Warehouse column print '<td></td>'; // Warehouse column
@ -518,9 +501,7 @@ if ($id > 0 || ! empty($ref))
$form->select_date($dluodatesuffix, 'dluo' . $suffix, '', '', 1, ""); $form->select_date($dluodatesuffix, 'dluo' . $suffix, '', '', 1, "");
print '</td>'; print '</td>';
print '<td colspan="2">&nbsp</td>'; // Qty ordered + qty already dispatached print '<td colspan="2">&nbsp</td>'; // Qty ordered + qty already dispatached
} } else {
else
{
$type = 'dispatch'; $type = 'dispatch';
print '<td align="right">' . img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"') . '</td>'; // Dispatch column print '<td align="right">' . img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"') . '</td>'; // Dispatch column
print '<td></td>'; print '<td></td>';
@ -542,16 +523,11 @@ if ($id > 0 || ! empty($ref))
// Warehouse // Warehouse
print '<td align="right">'; print '<td align="right">';
if (count($listwarehouses)>1) if (count($listwarehouses) > 1) {
{
print $formproduct->selectWarehouses(GETPOST("entrepot" . $suffix), "entrepot" . $suffix, '', 1, 0, $objp->fk_product); print $formproduct->selectWarehouses(GETPOST("entrepot" . $suffix), "entrepot" . $suffix, '', 1, 0, $objp->fk_product);
} } elseif (count($listwarehouses) == 1) {
elseif (count($listwarehouses)==1)
{
print $formproduct->selectWarehouses(GETPOST("entrepot" . $suffix), "entrepot" . $suffix, '', 0, 0, $objp->fk_product); print $formproduct->selectWarehouses(GETPOST("entrepot" . $suffix), "entrepot" . $suffix, '', 0, 0, $objp->fk_product);
} } else {
else
{
print $langs->trans("NoWarehouseDefined"); print $langs->trans("NoWarehouseDefined");
} }
print "</td>\n"; print "</td>\n";
@ -562,17 +538,14 @@ if ($id > 0 || ! empty($ref))
$i ++; $i ++;
} }
$db->free($resql); $db->free($resql);
} } else {
else
{
dol_print_error($db); dol_print_error($db);
} }
print "</table>\n"; print "</table>\n";
print "<br/>\n"; print "<br/>\n";
if ($nbproduct) if ($nbproduct) {
{
print $langs->trans("Comment") . ' : '; print $langs->trans("Comment") . ' : ';
print '<input type="text" size="60" maxlength="128" name="comment" value="'; print '<input type="text" size="60" maxlength="128" name="comment" value="';
print $_POST["comment"] ? GETPOST("comment") : $langs->trans("DispatchSupplierOrder", $commande->ref); print $_POST["comment"] ? GETPOST("comment") : $langs->trans("DispatchSupplierOrder", $commande->ref);
@ -581,12 +554,12 @@ if ($id > 0 || ! empty($ref))
// print '<div class="center">'; // print '<div class="center">';
print '<input type="submit" class="button" value="' . $langs->trans("DispatchVerb") . '"'; print '<input type="submit" class="button" value="' . $langs->trans("DispatchVerb") . '"';
if (count($listwarehouses) <= 0) print ' disabled'; if (count($listwarehouses) <= 0)
print ' disabled';
print '>'; print '>';
// print '</div>'; // print '</div>';
} }
if (! $nbproduct && $nbfreeproduct) if (! $nbproduct && $nbfreeproduct) {
{
print $langs->trans("NoPredefinedProductToDispatch"); print $langs->trans("NoPredefinedProductToDispatch");
} }
@ -595,7 +568,6 @@ if ($id > 0 || ! empty($ref))
dol_fiche_end(); dol_fiche_end();
// List of lines already dispatched // List of lines already dispatched
$sql = "SELECT p.ref, p.label,"; $sql = "SELECT p.ref, p.label,";
$sql .= " e.rowid as warehouse_id, e.label as entrepot,"; $sql .= " e.rowid as warehouse_id, e.label as entrepot,";
@ -608,13 +580,11 @@ if ($id > 0 || ! empty($ref))
$sql .= " ORDER BY cfd.rowid ASC"; $sql .= " ORDER BY cfd.rowid ASC";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
if ($num > 0) if ($num > 0) {
{
print "<br/>\n"; print "<br/>\n";
print load_fiche_titre($langs->trans("ReceivingForSameOrder")); print load_fiche_titre($langs->trans("ReceivingForSameOrder"));
@ -623,8 +593,7 @@ if ($id > 0 || ! empty($ref))
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>' . $langs->trans("Description") . '</td>'; print '<td>' . $langs->trans("Description") . '</td>';
if (! empty($conf->productbatch->enabled)) if (! empty($conf->productbatch->enabled)) {
{
print '<td>' . $langs->trans("batch_number") . '</td>'; print '<td>' . $langs->trans("batch_number") . '</td>';
print '<td>' . $langs->trans("l_eatby") . '</td>'; print '<td>' . $langs->trans("l_eatby") . '</td>';
print '<td>' . $langs->trans("l_sellby") . '</td>'; print '<td>' . $langs->trans("l_sellby") . '</td>';
@ -633,13 +602,13 @@ if ($id > 0 || ! empty($ref))
print '<td></td>'; print '<td></td>';
print '<td>' . $langs->trans("Warehouse") . '</td>'; print '<td>' . $langs->trans("Warehouse") . '</td>';
print '<td>' . $langs->trans("Comment") . '</td>'; print '<td>' . $langs->trans("Comment") . '</td>';
if (! empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) print '<td align="center" colspan="2">'.$langs->trans("Status").'</td>'; if (! empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS))
print '<td align="center" colspan="2">' . $langs->trans("Status") . '</td>';
print "</tr>\n"; print "</tr>\n";
$var = false; $var = false;
while ($i < $num) while ( $i < $num ) {
{
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
print "<tr " . $bc[$var] . ">"; print "<tr " . $bc[$var] . ">";
@ -648,8 +617,7 @@ if ($id > 0 || ! empty($ref))
print ' - ' . $objp->label; print ' - ' . $objp->label;
print "</td>\n"; print "</td>\n";
if (! empty($conf->productbatch->enabled)) if (! empty($conf->productbatch->enabled)) {
{
print '<td>' . $objp->batch . '</td>'; print '<td>' . $objp->batch . '</td>';
print '<td>' . dol_print_date($db->jdate($objp->eatby), 'day') . '</td>'; print '<td>' . dol_print_date($db->jdate($objp->eatby), 'day') . '</td>';
print '<td>' . dol_print_date($db->jdate($objp->sellby), 'day') . '</td>'; print '<td>' . dol_print_date($db->jdate($objp->sellby), 'day') . '</td>';
@ -670,8 +638,7 @@ if ($id > 0 || ! empty($ref))
print '<td>' . dol_trunc($objp->comment) . '</td>'; print '<td>' . dol_trunc($objp->comment) . '</td>';
// Status // Status
if (! empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) if (! empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
{
print '<td align="right">'; print '<td align="right">';
$supplierorderdispatch->status = (empty($objp->status) ? 0 : $objp->status); $supplierorderdispatch->status = (empty($objp->status) ? 0 : $objp->status);
// print $supplierorderdispatch->status; // print $supplierorderdispatch->status;
@ -680,37 +647,27 @@ if ($id > 0 || ! empty($ref))
// Add button to check/uncheck disaptching // Add button to check/uncheck disaptching
print '<td align="center">'; print '<td align="center">';
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))) {
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)) if (empty($objp->status)) {
)
{
if (empty($objp->status))
{
print '<a class="button buttonRefused" href="#">' . $langs->trans("Approve") . '</a>'; print '<a class="button buttonRefused" href="#">' . $langs->trans("Approve") . '</a>';
print '<a class="button buttonRefused" href="#">' . $langs->trans("Deny") . '</a>'; print '<a class="button buttonRefused" href="#">' . $langs->trans("Deny") . '</a>';
} } else {
else
{
print '<a class="button buttonRefused" href="#">' . $langs->trans("Disapprove") . '</a>'; print '<a class="button buttonRefused" href="#">' . $langs->trans("Disapprove") . '</a>';
print '<a class="button buttonRefused" href="#">' . $langs->trans("Deny") . '</a>'; print '<a class="button buttonRefused" href="#">' . $langs->trans("Deny") . '</a>';
} }
} } else {
else
{
$disabled = ''; $disabled = '';
if ($commande->statut == 5) $disabled=1; if ($commande->statut == 5)
if (empty($objp->status)) $disabled = 1;
{ if (empty($objp->status)) {
print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=checkdispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Approve") . '</a>'; print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=checkdispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Approve") . '</a>';
print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=denydispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Deny") . '</a>'; print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=denydispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Deny") . '</a>';
} }
if ($objp->status == 1) if ($objp->status == 1) {
{
print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=uncheckdispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Reinit") . '</a>'; print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=uncheckdispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Reinit") . '</a>';
print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=denydispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Deny") . '</a>'; print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=denydispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Deny") . '</a>';
} }
if ($objp->status == 2) if ($objp->status == 2) {
{
print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=uncheckdispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Reinit") . '</a>'; print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=uncheckdispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Reinit") . '</a>';
print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=checkdispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Approve") . '</a>'; print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=checkdispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Approve") . '</a>';
} }
@ -727,19 +684,10 @@ if ($id > 0 || ! empty($ref))
print "</table>\n"; print "</table>\n";
} }
} } else {
else
{
dol_print_error($db); dol_print_error($db);
} }
} }
else
{
// Commande non trouvee
dol_print_error($db);
}
}
llxFooter(); llxFooter();

View File

@ -132,3 +132,4 @@ OpenAll=Open for all actions
OpenInternal=Open for internal actions OpenInternal=Open for internal actions
OpenShipping=Open for shippings OpenShipping=Open for shippings
OpenDispatch=Open for dispatch OpenDispatch=Open for dispatch
UseDispatchStatus=Use dispatch status (aprouve/refuse)