Serious debug of supplier order process

This commit is contained in:
Laurent Destailleur 2010-05-28 21:52:51 +00:00
parent 38d91e99dd
commit 1083d5ca8b
6 changed files with 155 additions and 47 deletions

View File

@ -49,6 +49,10 @@ class CommandeFournisseur extends Commande
var $ref;
var $brouillon;
var $statut; // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally
// -> 7=Canceled/Never received -> 3=Process
// -> 6=Canceled -> 2=Approved
// -> 9=Refused -> 1=Validated
/** \brief Constructeur
@ -67,6 +71,7 @@ class CommandeFournisseur extends Commande
$this->statuts[4] = 'StatusOrderReceivedPartially';
$this->statuts[5] = 'StatusOrderReceivedAll';
$this->statuts[6] = 'StatusOrderCanceled';
$this->statuts[7] = 'StatusOrderCanceled';
$this->statuts[9] = 'StatusOrderRefused';
}
@ -373,7 +378,7 @@ class CommandeFournisseur extends Commande
if ($statut==3) return img_picto($langs->trans($this->statuts[$statut]),'statut3');
if ($statut==4) return img_picto($langs->trans($this->statuts[$statut]),'statut3');
if ($statut==5) return img_picto($langs->trans($this->statuts[$statut]),'statut6');
if ($statut==6) return img_picto($langs->trans($this->statuts[$statut]),'statut5');
if ($statut==6 || $statut==7) return img_picto($langs->trans($this->statuts[$statut]),'statut5');
if ($statut==9) return img_picto($langs->trans($this->statuts[$statut]),'statut5');
}
if ($mode == 4)
@ -384,7 +389,7 @@ class CommandeFournisseur extends Commande
if ($statut==3) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
if ($statut==4) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
if ($statut==5) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
if ($statut==6) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]);
if ($statut==6 || $statut==7) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]);
if ($statut==9) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]);
}
if ($mode == 5)
@ -395,7 +400,7 @@ class CommandeFournisseur extends Commande
if ($statut==3) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3');
if ($statut==4) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3');
if ($statut==5) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut6');
if ($statut==6) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5');
if ($statut==6 || $statut==7) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5');
if ($statut==9) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5');
}
}
@ -981,6 +986,7 @@ class CommandeFournisseur extends Commande
return -2;
}
}
/**
* Supprime une ligne de la commande
*
@ -1106,21 +1112,21 @@ class CommandeFournisseur extends Commande
dol_syslog("CommandeFournisseur::Livraison");
if ($user->rights->fournisseur->commande->receptionner && $date < gmmktime())
if ($user->rights->fournisseur->commande->receptionner)
{
if ($type == 'tot') $statut = 5;
if ($type == 'par') $statut = 4;
if ($type == 'nev') $statut = 6;
if ($type == 'can') $statut = 6;
if ($type == 'tot') $statut = 5;
if ($type == 'nev') $statut = 7;
if ($type == 'can') $statut = 7;
if ($statut == 4 or $statut == 5 or $statut == 6)
if ($statut == 4 or $statut == 5 or $statut == 7)
{
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
$sql.= " SET fk_statut = ".$statut;
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND fk_statut IN (3,4)";
$sql.= " AND fk_statut IN (3,4)"; // Process running or Partially received
dol_syslog("CommandeFournisseur::Livraison sql=".$sql);
$resql=$this->db->query($sql);
@ -1264,6 +1270,47 @@ class CommandeFournisseur extends Commande
}
/**
* \brief Tag order with a particular status
* \param user Object user that change status
* \return int <0 if KO, >0 if OK
*/
function setStatus($user,$status)
{
global $conf,$langs;
$error=0;
$this->db->begin();
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur';
$sql.= ' SET fk_statut='.$status;
$sql.= ' WHERE rowid = '.$this->id;
dol_syslog("CommandeFournisseur::setStatus sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
}
else
{
$error++;
$this->error=$this->db->lasterror();
dol_syslog("CommandeFournisseur::setStatus ".$this->error);
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -1;
}
}
/**
* \brief Update line
* \param rowid Id de la ligne de facture

View File

@ -522,7 +522,6 @@ class FactureFournisseur extends Facture
$this->db->begin();
dol_syslog("FactureFournisseur::set_unpaid rowid=".$this->id, LOG_DEBUG);
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn';
$sql.= ' SET paye=0, fk_statut=1, close_code=null, close_note=null';
$sql.= ' WHERE rowid = '.$this->id;
@ -543,8 +542,8 @@ class FactureFournisseur extends Facture
else
{
$error++;
$this->error=$this->db->error();
dol_print_error($this->db);
$this->error=$this->db->lasterror();
dol_syslog("FactureFournisseur::set_unpaid ".$this->error);
}
if (! $error)

View File

@ -174,6 +174,11 @@ if ($id > 0 || ! empty($ref))
/*
* Lignes de commandes
*/
if ($commande->statut <= 2 || $commande->statut >= 6)
{
print $langs->trans("OrderStatusNotReadyToDispatch");
}
if ($commande->statut == 3 || $commande->statut == 4 || $commande->statut == 5)
{
print '<form method="POST" action="dispatch.php?id='.$commande->id.'">';
@ -211,9 +216,6 @@ if ($id > 0 || ! empty($ref))
$num = $db->num_rows($resql);
$i = 0;
$remaintodispatch=$objp->qty - $products_dispatched[$objp->fk_product];
if ($remaintodispatch < 0) $remaintodispatch=0;
if ($num)
{
print '<tr class="liste_titre">';
@ -227,14 +229,26 @@ if ($id > 0 || ! empty($ref))
}
$entrepot = new Entrepot($db);
$nbfreeproduct=0;
$nbproduct=0;
$var=true;
while ($i < $num)
{
$objp = $db->fetch_object($resql);
// On n'affiche pas les produits personnalises
if ($objp->fk_product)
if (! $objp->fk_product > 0)
{
$nbfreeproduct++;
}
else
{
$nbproduct++;
$remaintodispatch=($objp->qty - $products_dispatched[$objp->fk_product]);
if ($remaintodispatch < 0) $remaintodispatch=0;
$var=!$var;
print "<tr ".$bc[$var].">";
print '<td>';
@ -278,16 +292,19 @@ if ($id > 0 || ! empty($ref))
print "</table>\n";
print "<br/>\n";
print '<center><input type="submit" class="button" value="'.$langs->trans("DispatchVerb").'"></center>';
if ($nbproduct)
{
print '<center><input type="submit" class="button" value="'.$langs->trans("DispatchVerb").'"></center>';
}
if (! $nbproduct && $nbfreeproduct)
{
print $langs->trans("NoPredefinedProductToDispatch");
}
print '</form>';
}
print "<br/>\n";
// List of already dispatching
print '<table class="noborder" width="100%">';
$sql = "SELECT p.ref, p.label, e.label as entrepot,";
$sql.= " cfd.fk_product, cfd.qty, cfd.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p,";
@ -303,50 +320,57 @@ if ($id > 0 || ! empty($ref))
$num = $db->num_rows($resql);
$i = 0;
if ($num)
if ($num > 0)
{
print "<br/>\n";
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Description").'</td>';
print '<td align="right">'.$langs->trans("QtyDispatched").'</td>';
print '<td align="right">'.$langs->trans("Warehouse").'</td>';
print "</tr>\n";
$var=false;
while ($i < $num)
{
$objp = $db->fetch_object($resql);
print "<tr $bc[$var]>";
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.'</a>';
print ' - '.$objp->label;
print "</td>\n";
print '<td align="right">'.$objp->qty.'</td>';
print '<td align="right">'.$objp->entrepot.'</td>';
print "</tr>\n";
$i++;
$var=!$var;
}
$db->free($resql);
print "</table>\n";
}
$var=false;
while ($i < $num)
{
$objp = $db->fetch_object($resql);
print "<tr $bc[$var]>";
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.'</a>';
print ' - '.$objp->label;
print "</td>\n";
print '<td align="right">'.$objp->qty.'</td>';
print '<td align="right">'.$objp->entrepot.'</td>';
print "</tr>\n";
$i++;
$var=!$var;
}
$db->free($resql);
}
else
{
dol_print_error($db);
}
print "</table>\n";
print '</div>';
dol_fiche_end();
/**
* Boutons actions
*/
if ($user->societe_id == 0 && $commande->statut < 3 && ($_GET["action"] <> 'valid' || $_GET['action'] == 'builddoc'))
{
print '<div class="tabsAction">';
//print '<div class="tabsAction">';
print "</div>";
//print "</div>";
}
}
else

View File

@ -81,6 +81,30 @@ if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->fournisseur->com
$id=$_REQUEST['id'];
}
if ($_GET['action'] == 'reopen' && $user->rights->fournisseur->commande->approuver)
{
$order = new CommandeFournisseur($db);
$result = $order->fetch($_REQUEST['id']);
if ($order->statut == 5 || $order->statut == 6 || $order->statut == 7 || $order->statut == 9)
{
if ($order->statut == 5) $newstatus=4; // Received->Received partially
if ($order->statut == 6) $newstatus=2; // Canceled->Approved
if ($order->statut == 7) $newstatus=3; // Canceled->Process running
if ($order->statut == 9) $newstatus=1; // Refused->Validated
$result = $order->setStatus($user,$newstatus);
if ($result > 0)
{
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_REQUEST['id']);
exit;
}
else
{
$mesg='<div class="error">'.$order->error.'</div>';
}
}
}
/*
* Ajout d'une ligne produit dans la commande
*/
@ -341,6 +365,7 @@ if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' &&
}
}
// Receive
if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner)
{
$commande = new CommandeFournisseur($db);
@ -1267,6 +1292,15 @@ if ($id > 0 || ! empty($ref))
}
}
// Reopen
if ($commande->statut == 5 || $commande->statut == 6 || $commande->statut == 7 || $commande->statut == 9)
{
if ($user->rights->fournisseur->commande->commander)
{
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
}
}
if ($user->rights->fournisseur->commande->supprimer)
{
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
@ -1294,7 +1328,7 @@ if ($id > 0 || ! empty($ref))
print '</td><td valign="top" width="50%">';
if ( $user->rights->fournisseur->commande->commander && ($commande->statut == 2 || $commande->statut == 6))
if ( $user->rights->fournisseur->commande->commander && $commande->statut == 2)
{
/**
* Commander (action=commande)

View File

@ -49,7 +49,9 @@ DeStockOnShipment=Decrease real stocks on shipment validation (recommended)
ReStockOnBill=Increase real stocks on invoices/credit notes validation (warning, in this version, it's only in warehouse number 1 that stock is modified)
ReStockOnValidateOrder=Increase real stocks on orders notes validation (warning, in this version, it's only in warehouse number 1 that stock is modified)
ReStockOnDispatchOrder=Increase real stocks on manual dispatching into warehouses, after order receiving
StockDiffPhysicTeoric=Reason for difference stock physical and theoretical
OrderStatusNotReadyToDispatch=Order has not yet or no more a status that allows dispatching of products in stock warehouses.
StockDiffPhysicTeoric=Reason for difference stock physical and theoretical
NoPredefinedProductToDispatch=No predefined products for this object. So no dispatching in stock is required.
DispatchVerb=Dispatch
StockLimitShort=Limit
StockLimit=Stock limit for alerts

View File

@ -49,7 +49,9 @@ DeStockOnShipment=Décrémente les stocks physiques sur validation des expéditi
ReStockOnBill=Incrémente les stocks physiques sur validation des factures/avoirs (attention, dans cette version, c'est toujours dans le premier entrepôt que se fait l'ajustement)
ReStockOnValidateOrder=Incrémente les stocks physiques sur validation des commandes (attention, dans cette version, c'est toujours dans le premier entrepôt que se fait l'ajustement)
ReStockOnDispatchOrder=Incrémente les stocks physiques sur ventilation manuelle de la réception des commandes dans les entrepots
OrderStatusNotReadyToDispatch=La commande n'a pas encore ou n'a plus un status permettant une ventilation en stock.
StockDiffPhysicTeoric=Raison écart stock physique-théorique
NoPredefinedProductToDispatch=Pas de produits prédéfinis dans cet object. Aucune ventilation en stock n'est donc à faire.
DispatchVerb=Ventiler
StockLimitShort=Seuil
StockLimit=Seuil alerte stock