Fix: Can not validate an order if there is a discount

Qual: Uniformize code for stock decrease
This commit is contained in:
Laurent Destailleur 2009-05-07 21:38:56 +00:00
parent 81a5393e70
commit 14afe7a82f
6 changed files with 546 additions and 504 deletions

View File

@ -205,8 +205,8 @@ class Commande extends CommonObject
/** /**
* \brief Validate order * \brief Validate order
* \param user Utilisateur qui valide * \param user User making status change
* \return int <=0 si ko, >0 si ok * \return int <=0 if OK, >0 if KO
*/ */
function valid($user) function valid($user)
{ {
@ -217,12 +217,14 @@ class Commande extends CommonObject
// Protection // Protection
if ($this->statut == 1) if ($this->statut == 1)
{ {
dol_syslog("Commande::valid no draft status", LOG_WARNING);
return 0; return 0;
} }
if (! $user->rights->commande->valider) if (! $user->rights->commande->valider)
{ {
$this->error='Permission denied'; $this->error='Permission denied';
dol_syslog("Commande::valid ".$this->error, LOG_ERR);
return -1; return -1;
} }
@ -231,13 +233,12 @@ class Commande extends CommonObject
// Definition du nom de module de numerotation de commande // Definition du nom de module de numerotation de commande
$soc = new Societe($this->db); $soc = new Societe($this->db);
$soc->fetch($this->socid); $soc->fetch($this->socid);
$num=$this->getNextNumRef($soc);
// Class of company linked to order // Class of company linked to order
$result=$soc->set_as_client(); $result=$soc->set_as_client();
// check if temporary number // Define new ref
if (eregi('^\(PROV', $this->ref)) if (! $error && (eregi('^\(PROV', $this->ref) || eregi('^PROV', $this->ref)))
{ {
$num = $this->getNextNumRef($soc); $num = $this->getNextNumRef($soc);
} }
@ -246,22 +247,53 @@ class Commande extends CommonObject
$num = $this->ref; $num = $this->ref;
} }
// Validate
$sql = "UPDATE ".MAIN_DB_PREFIX."commande"; $sql = "UPDATE ".MAIN_DB_PREFIX."commande";
$sql.= " SET ref = '".$num."'"; $sql.= " SET ref = '".$num."'";
$sql.= ", fk_statut = 1"; $sql.= ", fk_statut = 1";
$sql.= ", date_valid=".$this->db->idate(mktime()); $sql.= ", date_valid=".$this->db->idate(mktime());
$sql.= ", fk_user_valid = ".$user->id; $sql.= ", fk_user_valid = ".$user->id;
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
$sql.= " AND fk_statut = 0";
dol_syslog("Commande::valid() sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if (! $resql)
{ {
// On efface le repertoire de pdf provisoire dol_syslog("Commande::valid() Echec update - 10 - sql=".$sql, LOG_ERR);
if (eregi('^\(PROV', $this->ref)) dol_print_error($this->db);
$error++;
}
if (! $error)
{
// If stock is incremented on validate order, we must increment it
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
{ {
// On renomme repertoire facture ($this->ref = ancienne ref, $numfa = nouvelle ref) require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
// afin de ne pas perdre les fichiers attach<63>s
// Loop on each line
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{
if ($this->lignes[$i]->fk_product > 0 && $this->lignes[$i]->product_type == 0)
{
$mouvP = new MouvementStock($this->db);
// We decrement stock of product (and sub-products)
$entrepot_id = "1"; // TODO ajouter possibilité de choisir l'entrepot
// TODO Add price of product in method or '' to update PMP
$result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
if ($result < 0) { $error++; }
}
}
}
}
if (! $error)
{
// Rename directory if dir was a temporary ref
if (eregi('^\(PROV', $this->ref) || eregi('^PROV', $this->ref))
{
// On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref)
// afin de ne pas perdre les fichiers attaches
$comref = dol_sanitizeFileName($this->ref); $comref = dol_sanitizeFileName($this->ref);
$snum = dol_sanitizeFileName($num); $snum = dol_sanitizeFileName($num);
$dirsource = $conf->commande->dir_output.'/'.$comref; $dirsource = $conf->commande->dir_output.'/'.$comref;
@ -278,44 +310,28 @@ class Commande extends CommonObject
} }
} }
} }
}
// Set new ref
if (! $error)
{
$this->ref = $num;
}
// If stock is incremented on validate order, we must increment it if (! $error)
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) {
{ // Appel des triggers
require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php"); include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_VALIDATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) if (! $error)
{ {
$mouvP = new MouvementStock($this->db); $this->db->commit();
// We decrement stock of product (and sub-products) return 1;
$entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot
$result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
if ($result < 0) { $error++; }
}
}
if ($error == 0)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_VALIDATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
if ($error == 0)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
return -1;
}
} }
else else
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.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
@ -77,36 +77,39 @@ print "</form></table><br>\n";
/* /*
* Commandes brouillons * Commandes brouillons
*/ */
$sql = "SELECT c.rowid, c.ref, s.nom, s.rowid as socid"; if ($conf->commande->enabled)
$sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.fk_soc = s.rowid";
$sql.= " AND c.entity = ".$conf->entity;
$sql.= " AND c.fk_statut = 0";
if ($socid) $sql.= " AND c.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ( $db->query($sql) )
{ {
$langs->load("orders"); $sql = "SELECT c.rowid, c.ref, s.nom, s.rowid as socid";
$num = $db->num_rows(); $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
if ($num) $sql.= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.fk_soc = s.rowid";
$sql.= " AND c.entity = ".$conf->entity;
$sql.= " AND c.fk_statut = 0";
if ($socid) $sql.= " AND c.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ( $db->query($sql) )
{ {
$i = 0;
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td colspan="2">'.$langs->trans("DraftOrders").'</td></tr>'; print '<td colspan="2">'.$langs->trans("DraftOrders").'</td></tr>';
$var = True; $langs->load("orders");
while ($i < $num) $num = $db->num_rows();
if ($num)
{ {
$var=!$var; $i = 0;
$obj = $db->fetch_object(); $var = True;
print "<tr $bc[$var]>"; while ($i < $num)
print '<td nowrap="nowrap">'; {
print "<a href=\"fiche.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref."</a></td>"; $var=!$var;
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($obj->nom,24).'</a></td></tr>'; $obj = $db->fetch_object();
$i++; print "<tr $bc[$var]>";
print '<td nowrap="nowrap">';
print "<a href=\"fiche.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref."</a></td>";
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($obj->nom,24).'</a></td></tr>';
$i++;
}
} }
print "</table><br>"; print "</table><br>";
} }
@ -115,128 +118,133 @@ if ( $db->query($sql) )
/* /*
* Commandes à traiter * Commandes à traiter
*/ */
$sql = "SELECT c.rowid, c.ref, s.nom, s.rowid as socid"; if ($conf->commande->enabled)
$sql.=" FROM ".MAIN_DB_PREFIX."commande as c";
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.fk_soc = s.rowid";
$sql.= " AND c.entity = ".$conf->entity;
$sql.= " AND c.fk_statut = 1";
if ($socid) $sql.= " AND c.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
$sql.= " ORDER BY c.rowid DESC";
if ( $db->query($sql) )
{ {
print '<table class="noborder" width="100%">'; $sql = "SELECT c.rowid, c.ref, s.nom, s.rowid as socid";
print '<tr class="liste_titre">'; $sql.=" FROM ".MAIN_DB_PREFIX."commande as c";
print '<td colspan="2">'.$langs->trans("OrdersToProcess").'</td></tr>'; $sql.= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.fk_soc = s.rowid";
$sql.= " AND c.entity = ".$conf->entity;
$sql.= " AND c.fk_statut = 1";
if ($socid) $sql.= " AND c.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
$sql.= " ORDER BY c.rowid DESC";
$num = $db->num_rows(); if ( $db->query($sql) )
if ($num)
{ {
$i = 0; print '<table class="noborder" width="100%">';
$var = True; print '<tr class="liste_titre">';
while ($i < $num) print '<td colspan="2">'.$langs->trans("OrdersToProcess").'</td></tr>';
$num = $db->num_rows();
if ($num)
{ {
$var=!$var; $i = 0;
$obj = $db->fetch_object(); $var = True;
print "<tr $bc[$var]>"; while ($i < $num)
print '<td nowrap="nowrap">'; {
$var=!$var;
$obj = $db->fetch_object();
print "<tr $bc[$var]>";
print '<td nowrap="nowrap">';
$commandestatic->id=$obj->rowid; $commandestatic->id=$obj->rowid;
$commandestatic->ref=$obj->ref; $commandestatic->ref=$obj->ref;
print '<table class="nobordernopadding"><tr class="nocellnopadd">'; print '<table class="nobordernopadding"><tr class="nocellnopadd">';
print '<td width="90" class="nobordernopadding" nowrap="nowrap">'; print '<td width="90" class="nobordernopadding" nowrap="nowrap">';
print $commandestatic->getNomUrl(1); print $commandestatic->getNomUrl(1);
print '</td>'; print '</td>';
print '<td width="16" class="nobordernopadding" nowrap="nowrap">'; print '<td width="16" class="nobordernopadding" nowrap="nowrap">';
print '&nbsp;'; print '&nbsp;';
print '</td>'; print '</td>';
print '<td width="16" align="right" class="nobordernopadding">'; print '<td width="16" align="right" class="nobordernopadding">';
$filename=dol_sanitizeFileName($obj->ref); $filename=dol_sanitizeFileName($obj->ref);
$filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref); $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid; $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
$formfile->show_documents('commande',$filename,$filedir,$urlsource,'','','','','',1); $formfile->show_documents('commande',$filename,$filedir,$urlsource,'','','','','',1);
print '</td></tr></table>'; print '</td></tr></table>';
print '</td>'; print '</td>';
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($obj->nom,24).'</a></td></tr>'; print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($obj->nom,24).'</a></td></tr>';
$i++; $i++;
}
} }
print "</table><br>";
} }
print "</table><br>";
} }
print '</td><td valign="top" width="70%" class="notopnoleftnoright">'; print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
/* /*
* Commandes en cours * Commandes en cours
*/ */
$sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom, s.rowid as socid"; if ($conf->commande->enabled)
$sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.fk_soc = s.rowid";
$sql.= " AND c.entity = ".$conf->entity;
$sql.= " AND c.fk_statut = 2 ";
if ($socid) $sql.= " AND c.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
$sql.= " ORDER BY c.rowid DESC";
if ( $db->query($sql) )
{ {
$num = $db->num_rows(); $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom, s.rowid as socid";
$sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.fk_soc = s.rowid";
$sql.= " AND c.entity = ".$conf->entity;
$sql.= " AND c.fk_statut = 2 ";
if ($socid) $sql.= " AND c.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
$sql.= " ORDER BY c.rowid DESC";
print '<table class="noborder" width="100%">'; if ( $db->query($sql) )
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("OnProcessOrders").' ('.$num.')</td></tr>';
if ($num)
{ {
$i = 0; $num = $db->num_rows();
$var = True;
while ($i < $num) print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("OnProcessOrders").' ('.$num.')</td></tr>';
if ($num)
{ {
$var=!$var; $i = 0;
$obj = $db->fetch_object(); $var = True;
print "<tr $bc[$var]>"; while ($i < $num)
print '<td width="20%" nowrap="nowrap">'; {
$var=!$var;
$obj = $db->fetch_object();
print "<tr $bc[$var]>";
print '<td width="20%" nowrap="nowrap">';
$commandestatic->id=$obj->rowid; $commandestatic->id=$obj->rowid;
$commandestatic->ref=$obj->ref; $commandestatic->ref=$obj->ref;
print '<table class="nobordernopadding"><tr class="nocellnopadd">'; print '<table class="nobordernopadding"><tr class="nocellnopadd">';
print '<td width="90" class="nobordernopadding" nowrap="nowrap">'; print '<td width="90" class="nobordernopadding" nowrap="nowrap">';
print $commandestatic->getNomUrl(1); print $commandestatic->getNomUrl(1);
print '</td>'; print '</td>';
print '<td width="16" class="nobordernopadding" nowrap="nowrap">'; print '<td width="16" class="nobordernopadding" nowrap="nowrap">';
print '&nbsp;'; print '&nbsp;';
print '</td>'; print '</td>';
print '<td width="16" align="right" class="nobordernopadding">'; print '<td width="16" align="right" class="nobordernopadding">';
$filename=dol_sanitizeFileName($obj->ref); $filename=dol_sanitizeFileName($obj->ref);
$filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref); $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid; $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
$formfile->show_documents('commande',$filename,$filedir,$urlsource,'','','','','',1); $formfile->show_documents('commande',$filename,$filedir,$urlsource,'','','','','',1);
print '</td></tr></table>'; print '</td></tr></table>';
print '</td>'; print '</td>';
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>'; print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
print '<td align="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>'; print '<td align="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
print '</tr>'; print '</tr>';
$i++; $i++;
}
} }
print "</table><br>";
} }
print "</table><br>";
} }
/* /*

View File

@ -138,7 +138,7 @@ class Expedition extends CommonObject
{ {
if (! $this->create_line($this->lignes[$i]->entrepot_id, $this->lignes[$i]->origin_line_id, $this->lignes[$i]->qty) > 0) if (! $this->create_line($this->lignes[$i]->entrepot_id, $this->lignes[$i]->origin_line_id, $this->lignes[$i]->qty) > 0)
{ {
$error++; $error++;
} }
} }
@ -146,32 +146,32 @@ class Expedition extends CommonObject
{ {
if ($conf->commande->enabled) if ($conf->commande->enabled)
{ {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_exp (fk_expedition, fk_commande) VALUES ('.$this->id.','.$this->origin_id.')'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_exp (fk_expedition, fk_commande) VALUES ('.$this->id.','.$this->origin_id.')';
if (!$this->db->query($sql)) if (!$this->db->query($sql))
{ {
$error++; $error++;
} }
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 2 WHERE rowid=".$this->origin_id; $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 2 WHERE rowid=".$this->origin_id;
if (! $this->db->query($sql)) if (! $this->db->query($sql))
{ {
$error++; $error++;
} }
} }
else else
{ {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'pr_exp (fk_expedition, fk_propal) VALUES ('.$this->id.','.$this->origin_id.')'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'pr_exp (fk_expedition, fk_propal) VALUES ('.$this->id.','.$this->origin_id.')';
if (!$this->db->query($sql)) if (!$this->db->query($sql))
{ {
$error++; $error++;
} }
//Todo: definir un statut //Todo: definir un statut
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 9 WHERE rowid=".$this->origin_id; $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 9 WHERE rowid=".$this->origin_id;
if (! $this->db->query($sql)) if (! $this->db->query($sql))
{ {
$error++; $error++;
} }
} }
} }
@ -340,7 +340,7 @@ class Expedition extends CommonObject
} }
/** /**
* \brief Valide l'expedition, et met a jour le stock si stock géré * \brief Validate object and update stock if option enabled
* \param user Objet de l'utilisateur qui valide * \param user Objet de l'utilisateur qui valide
* \return int * \return int
*/ */
@ -348,140 +348,143 @@ class Expedition extends CommonObject
{ {
global $conf; global $conf;
require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php";
dol_syslog("Expedition::valid"); dol_syslog("Expedition::valid");
$this->db->begin(); // Protection
if ($this->statut)
$error = 0;
$provref = $this->ref;
if ($user->rights->expedition->valider)
{ {
$this->ref = "EXP".$this->id; dol_syslog("Expedition::valid no draft status", LOG_WARNING);
return 0;
// Tester si non dejà au statut validé. Si oui, on arrete afin d'éviter
// de décrémenter 2 fois le stock.
$sql = "SELECT ref";
$sql.= " FROM ".MAIN_DB_PREFIX."expedition";
$sql.= " WHERE ref='".$this->ref."'";
$sql.= " AND entity = ".$conf->entity;
$sql.= " AND fk_statut <> '0'";
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
if ($num > 0)
{
dol_syslog("Expedition::valid already validated", LOG_WARNING);
$this->db->rollback();
return 0;
}
}
$sql = "UPDATE ".MAIN_DB_PREFIX."expedition";
$sql.= " SET ref='".$this->ref."'";
$sql.= ", fk_statut = 1";
$sql.= ", date_valid = ".$this->db->idate(mktime());
$sql.= ", fk_user_valid = ".$user->id;
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND fk_statut = 0";
dol_syslog("Expedition::valid update expedition sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
// If stock increment is done on sending (recommanded choice)
if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT)
{
/*
* Enregistrement d'un mouvement de stock pour chaque produit de l'expedition
*/
$sql = "SELECT cd.fk_product, ed.qty, ed.fk_entrepot";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sql.= ", ".MAIN_DB_PREFIX."expeditiondet as ed";
$sql.= " WHERE ed.fk_expedition = ".$this->id;
$sql.= " AND cd.rowid = ed.fk_origin_line";
dol_syslog("Expedition::valid select details sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i=0;
while($i < $num)
{
dol_syslog("Expedition::valid movment nb ".$i);
$obj = $this->db->fetch_object($resql);
$mouvS = new MouvementStock($this->db);
$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty);
if ($result < 0)
{
$this->db->rollback();
$this->error=$this->db->error()." - sql=$sql";
dol_syslog("Expedition::valid ".$this->error, LOG_ERR);
return -3;
}
$i++;
}
}
else
{
$this->db->rollback();
$this->error=$this->db->error()." - sql=$sql";
dol_syslog("Expedition::valid ".$this->error, LOG_ERR);
return -2;
}
}
// On efface le répertoire de pdf provisoire
$expeditionref = dol_sanitizeFileName($provref);
if ($conf->expedition->dir_output)
{
$dir = $conf->expedition->dir_output . "/" . $expeditionref;
$file = $dir . "/" . $expeditionref . ".pdf";
if (file_exists($file))
{
if (!dol_delete_file($file))
{
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
}
}
if (file_exists($dir))
{
if (!dol_delete_dir($dir))
{
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
}
}
}
}
else
{
$this->db->rollback();
$this->error=$this->db->error();
dol_syslog("Expedition::valid ".$this->error, LOG_ERR);
return -1;
}
} }
else
if (! $user->rights->expedition->valider)
{ {
$this->db->rollback(); $this->error='Permission denied';
$this->error="Non autorise";
dol_syslog("Expedition::valid ".$this->error, LOG_ERR); dol_syslog("Expedition::valid ".$this->error, LOG_ERR);
return -1; return -1;
} }
$this->db->commit(); $this->db->begin();
//dol_syslog("Expedition::valid commit");
return 1; // Define new ref
$num = "EXP".$this->id;
// Validate
$sql = "UPDATE ".MAIN_DB_PREFIX."expedition";
$sql.= " SET ref='".$num."'";
$sql.= ", fk_statut = 1";
$sql.= ", date_valid = ".$this->db->idate(mktime());
$sql.= ", fk_user_valid = ".$user->id;
$sql.= " WHERE rowid = ".$this->id;
dol_syslog("Expedition::valid update expedition sql=".$sql);
$resql=$this->db->query($sql);
if (! $resql)
{
dol_syslog("Expedition::valid() Echec update - 10 - sql=".$sql, LOG_ERR);
dol_print_error($this->db);
$error++;
}
if (! $error)
{
// If stock increment is done on sending (recommanded choice)
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT)
{
require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php";
// Loop on each product line to add a stock movement
$sql = "SELECT cd.fk_product, ed.qty, ed.fk_entrepot";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sql.= ", ".MAIN_DB_PREFIX."expeditiondet as ed";
$sql.= " WHERE ed.fk_expedition = ".$this->id;
$sql.= " AND cd.rowid = ed.fk_origin_line";
dol_syslog("Expedition::valid select details sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i=0;
while($i < $num)
{
dol_syslog("Expedition::valid movment index ".$i);
$obj = $this->db->fetch_object($resql);
if ($this->lignes[$i]->fk_product > 0 && $this->lignes[$i]->product_type == 0)
{
$mouvS = new MouvementStock($this->db);
// We decrement stock of product (and sub-products)
$entrepot_id = "1"; // TODO ajouter possibilité de choisir l'entrepot
// TODO Add price of product in method or '' to update PMP
$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty);
if ($result < 0) { $error++; }
}
$i++;
}
}
else
{
$this->db->rollback();
$this->error=$this->db->error()." - sql=$sql";
dol_syslog("Expedition::valid ".$this->error, LOG_ERR);
return -2;
}
}
}
if (! $error)
{
// On efface le répertoire de pdf provisoire
$expeditionref = dol_sanitizeFileName($this->ref);
if ($conf->expedition->dir_output)
{
$dir = $conf->expedition->dir_output . "/" . $expeditionref;
$file = $dir . "/" . $expeditionref . ".pdf";
if (file_exists($file))
{
if (!dol_delete_file($file))
{
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
}
}
if (file_exists($dir))
{
if (!dol_delete_dir($dir))
{
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
}
}
}
}
// Set new ref
if (! $error)
{
$this->ref = $num;
}
if (! $error)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_SHIPPING',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
return -1;
}
} }
@ -572,8 +575,8 @@ class Expedition extends CommonObject
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition WHERE rowid = ".$this->id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition WHERE rowid = ".$this->id;
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
$this->db->commit(); $this->db->commit();
// On efface le répertoire de pdf provisoire // On efface le répertoire de pdf provisoire
$expref = dol_sanitizeFileName($this->ref); $expref = dol_sanitizeFileName($this->ref);
@ -605,7 +608,7 @@ class Expedition extends CommonObject
$this->db->rollback(); $this->db->rollback();
return -3; return -3;
} }
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();

View File

@ -139,7 +139,7 @@ if ($_GET["action"] == 'create_delivery' && $conf->livraison_bon->enabled && $us
} }
} }
if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->expedition->valider) if ($_REQUEST["action"] == 'confirm_valid' && $_REQUEST["confirm"] == 'yes' && $user->rights->expedition->valider)
{ {
$expedition = new Expedition($db); $expedition = new Expedition($db);
$expedition->fetch($_GET["id"]); $expedition->fetch($_GET["id"]);
@ -147,7 +147,7 @@ if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->
//$expedition->PdfWrite(); //$expedition->PdfWrite();
} }
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes')
{ {
if ($user->rights->expedition->supprimer ) if ($user->rights->expedition->supprimer )
{ {
@ -554,7 +554,7 @@ else
*/ */
if ($_GET["action"] == 'delete') if ($_GET["action"] == 'delete')
{ {
$ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('DeleteSending'),$langs->trans("ConfirmDeleteSending",$expedition->ref),'confirm_delete'); $ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('DeleteSending'),$langs->trans("ConfirmDeleteSending",$expedition->ref),'confirm_delete','',0,1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
@ -564,7 +564,7 @@ else
*/ */
if ($_GET["action"] == 'valid') if ($_GET["action"] == 'valid')
{ {
$ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('ValidateSending'),$langs->trans("ConfirmValidateSending",$expedition->ref),'confirm_valid'); $ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('ValidateSending'),$langs->trans("ConfirmValidateSending",$expedition->ref),'confirm_valid','',0,1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
/* /*
@ -573,7 +573,7 @@ else
*/ */
if ($_GET["action"] == 'annuler') if ($_GET["action"] == 'annuler')
{ {
$ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('CancelSending'),$langs->trans("ConfirmCancelSending",$expedition->ref),'confirm_cancel'); $ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('CancelSending'),$langs->trans("ConfirmCancelSending",$expedition->ref),'confirm_cancel','',0,1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
@ -812,29 +812,26 @@ else
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
if (! eregi('^(valid|delete)',$_REQUEST["action"])) if ($expedition->statut == 0 && $num_prod > 0)
{ {
if ($expedition->statut == 0 && $num_prod > 0) if ($user->rights->expedition->valider)
{ {
if ($user->rights->expedition->valider) print '<a class="butAction" href="fiche.php?id='.$expedition->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
{
print '<a class="butAction" href="fiche.php?id='.$expedition->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
}
} }
else
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
}
}
if ($conf->livraison_bon->enabled && $expedition->statut == 1 && $user->rights->expedition->livraison->creer && !$expedition->livraison_id) if ($conf->livraison_bon->enabled && $expedition->statut == 1 && $user->rights->expedition->livraison->creer && !$expedition->livraison_id)
{ {
print '<a class="butAction" href="fiche.php?id='.$expedition->id.'&amp;action=create_delivery">'.$langs->trans("DeliveryOrder").'</a>'; print '<a class="butAction" href="fiche.php?id='.$expedition->id.'&amp;action=create_delivery">'.$langs->trans("DeliveryOrder").'</a>';
} }
if ($user->rights->expedition->supprimer) if ($user->rights->expedition->supprimer)
{ {
print '<a class="butActionDelete" href="fiche.php?id='.$expedition->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>'; print '<a class="butActionDelete" href="fiche.php?id='.$expedition->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
}
} }
print '</div>'; print '</div>';

View File

@ -1223,111 +1223,149 @@ class Facture extends CommonObject
{ {
global $conf,$langs; global $conf,$langs;
$error = 0; $error=0;
if ($this->brouillon)
// Protection
if (! $this->brouillon)
{ {
$this->db->begin(); dol_syslog("Facture::valid no draft status", LOG_WARNING);
return 0;
}
$this->fetch_client(); if (! $user->rights->commande->valider)
$this->fetch_lines(); {
$this->error='Permission denied';
dol_syslog("Expedition::valid ".$this->error, LOG_ERR);
return -1;
}
// Verification paramètres $this->db->begin();
if ($this->type == 1) // si facture de remplacement
$this->fetch_client();
$this->fetch_lines();
// Check parameters
if ($this->type == 1) // si facture de remplacement
{
// Controle que facture source connue
if ($this->fk_facture_source <= 0)
{ {
// Controle que facture source connue $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("InvoiceReplacement"));
if ($this->fk_facture_source <= 0) $this->db->rollback();
{ return -10;
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("InvoiceReplacement"));
$this->db->rollback();
return -10;
}
// Charge la facture source a remplacer
$facreplaced=new Facture($this->db);
$result=$facreplaced->fetch($this->fk_facture_source);
if ($result <= 0)
{
$this->error=$langs->trans("ErrorBadInvoice");
$this->db->rollback();
return -11;
}
// Controle que facture source non deja remplacee par une autre
$idreplacement=$facreplaced->getIdReplacingInvoice('validated');
if ($idreplacement && $idreplacement != $this->id)
{
$facreplacement=new Facture($this->db);
$facreplacement->fetch($idreplacement);
$this->error=$langs->trans("ErrorInvoiceAlreadyReplaced",$facreplaced->ref,$facreplacement->ref);
$this->db->rollback();
return -12;
}
$result=$facreplaced->set_canceled($user,'replaced','');
if ($result < 0)
{
$this->error=$facreplaced->error." sql=".$sql;
$this->db->rollback();
return -13;
}
} }
// Charge la facture source a remplacer
// on vérifie si la facture est en numérotation provisoire $facreplaced=new Facture($this->db);
$facref = substr($this->ref, 1, 4); $result=$facreplaced->fetch($this->fk_facture_source);
if ($result <= 0)
if ($force_number)
{ {
$numfa = $force_number; $this->error=$langs->trans("ErrorBadInvoice");
} $this->db->rollback();
else if ($facref == 'PROV') return -11;
{
$savdate=$this->date;
if ($conf->global->FAC_FORCE_DATE_VALIDATION) // If option enabled, we force invoice date
{
$this->date=gmmktime();
$this->date_lim_reglement=$this->calculate_date_lim_reglement();
}
$numfa = $this->getNextNumRef($this->client);
}
else
{
$numfa = $this->ref;
} }
$this->update_price(); // Controle que facture source non deja remplacee par une autre
$idreplacement=$facreplaced->getIdReplacingInvoice('validated');
if ($idreplacement && $idreplacement != $this->id)
{
$facreplacement=new Facture($this->db);
$facreplacement->fetch($idreplacement);
$this->error=$langs->trans("ErrorInvoiceAlreadyReplaced",$facreplaced->ref,$facreplacement->ref);
$this->db->rollback();
return -12;
}
// Validation de la facture $result=$facreplaced->set_canceled($user,'replaced','');
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; if ($result < 0)
$sql.= " SET facnumber='".$numfa."', fk_statut = 1, fk_user_valid = ".$user->id; {
$this->error=$facreplaced->error." sql=".$sql;
$this->db->rollback();
return -13;
}
}
// Define new ref
if ($force_number)
{
$num = $force_number;
}
else if (eregi('^\(PROV', $this->ref) || eregi('^PROV', $this->ref))
{
if ($conf->global->FAC_FORCE_DATE_VALIDATION) // If option enabled, we force invoice date if ($conf->global->FAC_FORCE_DATE_VALIDATION) // If option enabled, we force invoice date
{ {
$sql.= ', datef='.$this->db->idate($this->date); $this->date=gmmktime();
$sql.= ', date_lim_reglement='.$this->db->idate($this->date_lim_reglement); $this->date_lim_reglement=$this->calculate_date_lim_reglement();
} }
$sql.= ' WHERE rowid = '.$this->id; $num = $this->getNextNumRef($this->client);
}
else
{
$num = $this->ref;
}
dol_syslog("Facture::set_valid() sql=".$sql, LOG_DEBUG); $this->update_price();
$resql=$this->db->query($sql);
if ($resql) // Validate
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
$sql.= " SET facnumber='".$num."', fk_statut = 1, fk_user_valid = ".$user->id;
if ($conf->global->FAC_FORCE_DATE_VALIDATION) // If option enabled, we force invoice date
{
$sql.= ', datef='.$this->db->idate($this->date);
$sql.= ', date_lim_reglement='.$this->db->idate($this->date_lim_reglement);
}
$sql.= ' WHERE rowid = '.$this->id;
dol_syslog("Facture::set_valid() sql=".$sql);
$resql=$this->db->query($sql);
if (! $resql)
{
dol_syslog("Facture::set_valid() Echec update - 10 - sql=".$sql, LOG_ERR);
dol_print_error($this->db);
$error++;
}
// On vérifie si la facture était une provisoire
if (! $error && (eregi('^\(PROV', $this->ref) || eregi('^PROV', $this->ref)))
{
// La vérif qu'une remise n'est pas utilisée 2 fois est faite au moment de l'insertion de ligne
}
if (! $error)
{
// Define third party as a customer
$result=$this->client->set_as_client();
// Si activé on décrémente le produit principal et ses composants à la validation de facture
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_BILL)
{ {
$this->facnumber=$numfa; require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
}
else // Loop on each line
{ for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
dol_syslog("Facture::set_valid() Echec update - 10 - sql=".$sql, LOG_DEBUG); {
dol_print_error($this->db); if ($this->lignes[$i]->fk_product > 0 && $this->lignes[$i]->product_type == 0)
$error++; {
$mouvP = new MouvementStock($this->db);
// We decrease stock for product
$entrepot_id = "1"; // TODO ajouter possibilité de choisir l'entrepot
// TODO Add price of product in method or '' to update PMP
$result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
if ($result < 0) { $error++; }
}
}
} }
}
if (! $error)
// On vérifie si la facture était une provisoire {
if ($facref == 'PROV') // Rename directory if dir was a temporary ref
if (eregi('^\(PROV', $this->ref) || eregi('^PROV', $this->ref))
{ {
// On renomme repertoire facture ($this->ref = ancienne ref, $numfa = nouvelle ref) // On renomme repertoire facture ($this->ref = ancienne ref, $num = nouvelle ref)
// afin de ne pas perdre les fichiers attachés // afin de ne pas perdre les fichiers attachés
$facref = dol_sanitizeFileName($this->ref); $facref = dol_sanitizeFileName($this->ref);
$snumfa = dol_sanitizeFileName($numfa); $snumfa = dol_sanitizeFileName($num);
$dirsource = $conf->facture->dir_output.'/'.$facref; $dirsource = $conf->facture->dir_output.'/'.$facref;
$dirdest = $conf->facture->dir_output.'/'.$snumfa; $dirdest = $conf->facture->dir_output.'/'.$snumfa;
if (file_exists($dirsource)) if (file_exists($dirsource))
@ -1342,65 +1380,38 @@ class Facture extends CommonObject
} }
} }
} }
}
// On vérifie si la facture était une provisoire // Set new ref
if (! $error && $facref == 'PROV') if (! $error)
{ {
// La vérif qu'une remise n'est pas utilisée 2 fois est faite au moment de l'insertion de ligne $this->ref = $num;
} $this->facnumber=$num;
}
if (! $error) $this->use_webcal=($conf->global->PHPWEBCALENDAR_BILLSTATUS=='always'?1:0);
{
// Define third party as a customer
$result=$this->client->set_as_client();
// Si activé on décrémente le produit principal et ses composants à la validation de facture // Trigger calls
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_BILL) if (! $error)
{ {
require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php"); // Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('BILL_VALIDATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
// Loop on each line if (! $error)
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) {
{ $this->db->commit();
if ($this->lignes[$i]->fk_product && $this->lignes[$i]->product_type == 0) return 1;
{ }
$mouvP = new MouvementStock($this->db); else
// We decrease stock for product {
$entrepot_id = "1"; // TODO ajouter possibilité de choisir l'entrepot $this->db->rollback();
// TODO Add price of product in method or '' to update PMP $this->error=$this->db->lasterror();
$result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty); return -1;
}
}
}
$this->ref = $numfa;
$this->use_webcal=($conf->global->PHPWEBCALENDAR_BILLSTATUS=='always'?1:0);
if ($result > 0)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('BILL_VALIDATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -1;
}
}
else
{
$this->db->rollback();
return -1;
}
} }
} }

View File

@ -19,10 +19,10 @@
*/ */
/** /**
\file htdocs/product/stock/mouvement.php * \file htdocs/product/stock/mouvement.php
\ingroup stock * \ingroup stock
\brief Page liste des mouvements de stocks * \brief Page liste des mouvements de stocks
\version $Id$ * \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
@ -49,7 +49,7 @@ $form=new Form($db);
$sql = "SELECT p.rowid, p.label as produit,"; $sql = "SELECT p.rowid, p.label as produit,";
$sql.= " s.label as stock, s.rowid as entrepot_id,"; $sql.= " s.label as stock, s.rowid as entrepot_id,";
$sql.= " m.value, ".$db->pdate("m.datem")." as datem"; $sql.= " m.rowid as mid, m.value, m.datem";
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as s"; $sql.= " FROM ".MAIN_DB_PREFIX."entrepot as s";
$sql.= ", ".MAIN_DB_PREFIX."stock_mouvement as m"; $sql.= ", ".MAIN_DB_PREFIX."stock_mouvement as m";
$sql.= ", ".MAIN_DB_PREFIX."product as p"; $sql.= ", ".MAIN_DB_PREFIX."product as p";
@ -152,6 +152,7 @@ if ($resql)
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print "<tr class=\"liste_titre\">"; print "<tr class=\"liste_titre\">";
//print_liste_field_titre($langs->trans("Id"),"mouvement.php", "m.rowid","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Date"),"mouvement.php", "m.datem","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Date"),"mouvement.php", "m.datem","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Product"),"mouvement.php", "p.ref","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Product"),"mouvement.php", "p.ref","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Warehouse"),"mouvement.php", "s.label","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Warehouse"),"mouvement.php", "s.label","",$param,"",$sortfield,$sortorder);
@ -164,13 +165,19 @@ if ($resql)
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
$var=!$var; $var=!$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td>'.dol_print_date($objp->datem,'dayhour').'</td>'; // Id movement
//print '<td>'.$objp->mid.'</td>'; // This is primary not movement id
// Date
print '<td>'.dol_print_date($db->jdate($objp->datem),'dayhour').'</td>';
// Product
print "<td><a href=\"../fiche.php?id=$objp->rowid\">"; print "<td><a href=\"../fiche.php?id=$objp->rowid\">";
print img_object($langs->trans("ShowProduct"),"product").' '.$objp->produit; print img_object($langs->trans("ShowProduct"),"product").' '.$objp->produit;
print "</a></td>\n"; print "</a></td>\n";
// Warehouse
print '<td><a href="fiche.php?id='.$objp->entrepot_id.'">'; print '<td><a href="fiche.php?id='.$objp->entrepot_id.'">';
print img_object($langs->trans("ShowWarehouse"),"stock").' '.$objp->stock; print img_object($langs->trans("ShowWarehouse"),"stock").' '.$objp->stock;
print "</a></td>\n"; print "</a></td>\n";
// Value
print '<td align="right">'; print '<td align="right">';
if ($objp->value > 0) print '+'; if ($objp->value > 0) print '+';
print $objp->value.'</td>'; print $objp->value.'</td>';