Maxi debuggage de la gestion des expeditions.

La gestion des bons de livraisons ne marche pas car la table llx_co_liv n'est pas alimentée
This commit is contained in:
Laurent Destailleur 2008-05-20 00:09:11 +00:00
parent 1ae558dce8
commit 5c10a7e4c2
14 changed files with 325 additions and 423 deletions

View File

@ -863,7 +863,7 @@ if ($_GET['propalid'] > 0)
print '</td>'; print '</td>';
if ($conf->projet->enabled) $rowspan++; if ($conf->projet->enabled) $rowspan++;
if ($conf->expedition->enabled || $conf->livraison->enabled) if ($conf->expedition_bon->enabled || $conf->livraison_bon->enabled)
{ {
if ($conf->global->PROPALE_ADD_SHIPPING_DATE || !$conf->commande->enabled) $rowspan++; if ($conf->global->PROPALE_ADD_SHIPPING_DATE || !$conf->commande->enabled) $rowspan++;
if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS || !$conf->commande->enabled) $rowspan++; if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS || !$conf->commande->enabled) $rowspan++;
@ -908,7 +908,7 @@ if ($_GET['propalid'] > 0)
// date de livraison (conditionne sur PROPALE_ADD_SHIPPING_DATE car carac a // date de livraison (conditionne sur PROPALE_ADD_SHIPPING_DATE car carac a
// gerer par les commandes et non les propales // gerer par les commandes et non les propales
if ($conf->expedition->enabled || $conf->livraison->enabled) if ($conf->expedition_bon->enabled || $conf->livraison_bon->enabled)
{ {
if ($conf->global->PROPALE_ADD_SHIPPING_DATE || !$conf->commande->enabled) if ($conf->global->PROPALE_ADD_SHIPPING_DATE || !$conf->commande->enabled)
{ {

View File

@ -210,7 +210,7 @@ class Commande extends CommonObject
return 0; return 0;
} }
if (! $this->$user->rights->commande->valider) if (! $user->rights->commande->valider)
{ {
$this->error='Autorisation insuffisante'; $this->error='Autorisation insuffisante';
return -1; return -1;

View File

@ -28,6 +28,7 @@
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php");
require_once(DOL_DOCUMENT_ROOT."/lib/order.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/order.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/sendings.lib.php");
if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/project.class.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/project.class.php");
@ -504,103 +505,7 @@ if ($_GET["id"] > 0)
print "</td></tr></table>"; print "</td></tr></table>";
/* show_list_sending_receive('commande',$commande->id);
* Liste des expéditions/livraisons
*/
if ($conf->expedition->enabled && ($conf->expedition_bon->enabled || $conf->livraison->enabled))
{
print '<br>';
$sql = "SELECT cd.fk_product, cd.rowid, cd.qty as qty_asked";
$sql .= ", ed.qty as qty_shipped, e.ref, ed.fk_expedition as expedition_id";
$sql .= ", ".$db->pdate("e.date_expedition")." as date_expedition";
if ($conf->livraison->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref";
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
if ($conf->livraison->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid";
$sql .= " WHERE cd.fk_commande = ".$commande->id;
$sql .= " AND cd.rowid = ed.fk_origin_line";
$sql .= " AND ed.fk_expedition = e.rowid";
$sql .= " ORDER BY cd.fk_product";
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
if ($num)
{
if ($somethingshown) print '<br>';
print_titre($langs->trans("SendingsAndReceivingForSameOrder"));
print '<table class="liste" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Product").'</td>';
print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
print '<td align="center">'.$langs->trans("DateSending").'</td>';
if ($conf->expedition_bon->enabled)
{
print '<td>'.$langs->trans("SendingSheet").'</td>';
}
if ($conf->livraison->enabled)
{
print '<td>'.$langs->trans("DeliveryOrder").'</td>';
}
print "</tr>\n";
$var=True;
while ($i < $num)
{
$var=!$var;
$objp = $db->fetch_object($resql);
print "<tr $bc[$var]>";
if ($objp->fk_product > 0)
{
$product = new Product($db);
$product->fetch($objp->fk_product);
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
print '</td>';
}
else
{
print "<td>".nl2br($objp->description)."</td>\n";
}
print '<td align="center">'.$objp->qty_shipped.'</td>';
print '<td align="center">'.dolibarr_print_date($objp->date_expedition).'</td>';
if ($conf->expedition_bon->enabled)
{
print '<td align="left"><a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.'<a></td>';
}
if ($conf->livraison->enabled)
{
if ($objp->livraison_id)
{
print '<td align="left"><a href="'.DOL_URL_ROOT.'/livraison/fiche.php?id='.$objp->livraison_id.'">'.img_object($langs->trans("ShowSending"),'generic').' '.$objp->livraison_ref.'<a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
}
print '</tr>';
$i++;
}
print '</table>';
}
$db->free($resql);
}
else
{
dolibarr_print_error($db);
}
}
} }
else else
{ {

View File

@ -180,14 +180,16 @@ class Conf
// Module expeditions // Module expeditions
$this->expedition->enabled=defined("MAIN_MODULE_EXPEDITION")?MAIN_MODULE_EXPEDITION:0; $this->expedition->enabled=defined("MAIN_MODULE_EXPEDITION")?MAIN_MODULE_EXPEDITION:0;
// Sous module bons d'expedition
$this->expedition_bon->enabled=defined("MAIN_SUBMODULE_EXPEDITION")?MAIN_SUBMODULE_EXPEDITION:0;
$this->expedition->dir_output=DOL_DATA_ROOT."/expedition"; $this->expedition->dir_output=DOL_DATA_ROOT."/expedition";
$this->expedition->dir_temp =DOL_DATA_ROOT."/expedition/temp"; $this->expedition->dir_temp =DOL_DATA_ROOT."/expedition/temp";
// Sous module bons d'expedition
$this->expedition_bon->enabled=defined("MAIN_SUBMODULE_EXPEDITION")?MAIN_SUBMODULE_EXPEDITION:0;
$this->expedition_bon->dir_output=DOL_DATA_ROOT."/expedition/sending";
$this->expedition_bon->dir_temp =DOL_DATA_ROOT."/expedition/sending/temp";
// Sous module bons de livraison // Sous module bons de livraison
$this->livraison->enabled=defined("MAIN_SUBMODULE_LIVRAISON")?MAIN_SUBMODULE_LIVRAISON:0; $this->livraison_bon->enabled=defined("MAIN_SUBMODULE_LIVRAISON")?MAIN_SUBMODULE_LIVRAISON:0;
$this->livraison->dir_output=DOL_DATA_ROOT."/livraison"; $this->livraison_bon->dir_output=DOL_DATA_ROOT."/expedition/receipt";
$this->livraison->dir_temp =DOL_DATA_ROOT."/livraison/temp"; $this->livraison_bon->dir_temp =DOL_DATA_ROOT."/expedition/receipt/temp";
// Module societe // Module societe
$this->societe->enabled=defined("MAIN_MODULE_SOCIETE")?MAIN_MODULE_SOCIETE:0; $this->societe->enabled=defined("MAIN_MODULE_SOCIETE")?MAIN_MODULE_SOCIETE:0;

View File

@ -33,6 +33,7 @@ require_once(DOL_DOCUMENT_ROOT."/project.class.php");
require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php");
require_once(DOL_DOCUMENT_ROOT."/lib/order.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/order.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/sendings.lib.php");
$langs->load('orders'); $langs->load('orders');
$langs->load("companies"); $langs->load("companies");
@ -406,171 +407,67 @@ if ($_GET["id"] > 0)
} }
print '<table width="100%"><tr><td width="50%" valign="top">';
/*
* Documents générés
*
*/
$comref = sanitize_string($commande->ref);
$file = $conf->commande->dir_output . '/' . $comref . '/' . $comref . '.pdf';
$relativepath = $comref.'/'.$comref.'.pdf';
$filedir = $conf->commande->dir_output . '/' . $comref;
$urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id;
$genallowed=0;
$delallowed=0;
$somethingshown=$formfile->show_documents('commande',$comref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf);
print '</td><td valign="top" width="50%">';
// Bouton expedier avec gestion des stocks // Bouton expedier avec gestion des stocks
print '<table width="100%"><tr><td width="100%" colspan="2" valign="top">';
if ($conf->stock->enabled && $reste_a_livrer_total > 0 && $commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer) if ($conf->stock->enabled && $reste_a_livrer_total > 0 && $commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer)
{ {
print_titre($langs->trans("NewSending")); print_titre($langs->trans("NewSending"));
print '<form method="GET" action="'.DOL_URL_ROOT.'/expedition/fiche.php">'; print '<form method="GET" action="'.DOL_URL_ROOT.'/expedition/fiche.php">';
print '<input type="hidden" name="action" value="create">'; print '<input type="hidden" name="action" value="create">';
print '<input type="hidden" name="id" value="'.$commande->id.'">'; print '<input type="hidden" name="id" value="'.$commande->id.'">';
print '<input type="hidden" name="origin" value="commande">'; print '<input type="hidden" name="origin" value="commande">';
print '<input type="hidden" name="object_id" value="'.$commande->id.'">'; print '<input type="hidden" name="object_id" value="'.$commande->id.'">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
$entrepot = new Entrepot($db); $entrepot = new Entrepot($db);
$langs->load("stocks"); $langs->load("stocks");
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans("Warehouse").'</td>'; print '<td>'.$langs->trans("Warehouse").'</td>';
print '<td>'; print '<td>';
if (sizeof($user->entrepots) === 1) if (sizeof($user->entrepots) === 1)
{ {
$uentrepot = array(); $uentrepot = array();
$uentrepot[$user->entrepots[0]['id']] = $user->entrepots[0]['label']; $uentrepot[$user->entrepots[0]['id']] = $user->entrepots[0]['label'];
$html->select_array("entrepot_id",$uentrepot); $html->select_array("entrepot_id",$uentrepot);
} }
else else
{ {
$html->select_array("entrepot_id",$entrepot->list_array()); $html->select_array("entrepot_id",$entrepot->list_array());
} }
if (sizeof($entrepot->list_array()) <= 0) if (sizeof($entrepot->list_array()) <= 0)
{ {
print ' &nbsp; Aucun entrepôt définit, <a href="'.DOL_URL_ROOT.'/product/stock/fiche.php?action=create">definissez en un</a>'; print ' &nbsp; Aucun entrepôt définit, <a href="'.DOL_URL_ROOT.'/product/stock/fiche.php?action=create">definissez en un</a>';
} }
print '</td></tr>'; print '</td></tr>';
/* /*
print '<tr><td width="20%">Mode d\'expédition</td>'; print '<tr><td width="20%">Mode d\'expédition</td>';
print '<td>'; print '<td>';
$html->select_array("entrepot_id",$entrepot->list_array()); $html->select_array("entrepot_id",$entrepot->list_array());
print '</td></tr>'; print '</td></tr>';
*/ */
print '<tr><td align="center" colspan="2">'; print '<tr><td align="center" colspan="2">';
print '<input type="submit" class="button" named="save" value="'.$langs->trans("NewSending").'">'; print '<input type="submit" class="button" named="save" value="'.$langs->trans("NewSending").'">';
print '</td></tr>'; print '</td></tr>';
print "</table>"; print "</table>";
print "</form>\n"; print "</form>\n";
$somethingshown=1; $somethingshown=1;
} }
print "</td></tr></table>"; print "</td></tr></table>";
/* show_list_sending_receive('commande',$commande->id);
* Liste des expéditions
*/
$sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande";
$sql .= " , ed.qty as qty_livre, e.ref, ed.fk_expedition as expedition_id";
$sql .= ",".$db->pdate("e.date_expedition")." as date_expedition";
if ($conf->livraison->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref";
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
if ($conf->livraison->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid";
$sql .= " WHERE cd.fk_commande = ".$commande->id;
$sql .= " AND cd.rowid = ed.fk_origin_line";
$sql .= " AND ed.fk_expedition = e.rowid";
$sql .= " ORDER BY cd.fk_product";
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
if ($num)
{
if ($somethingshown) print '<br>';
print_titre($langs->trans("SendingsAndReceivingForSameOrder"));
print '<table class="liste" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Product").'</td>';
print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
print '<td align="center">'.$langs->trans("DateSending").'</td>';
if ($conf->expedition->enabled)
{
print '<td>'.$langs->trans("SendingSheet").'</td>';
}
if ($conf->livraison->enabled)
{
print '<td>'.$langs->trans("DeliveryOrder").'</td>';
}
print "</tr>\n";
$var=True;
while ($i < $num)
{
$var=!$var;
$objp = $db->fetch_object($resql);
print "<tr $bc[$var]>";
if ($objp->fk_product > 0)
{
$product = new Product($db);
$product->fetch($objp->fk_product);
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
if ($objp->description) print '<br>'.nl2br($objp->description);
print '</td>';
}
else
{
print "<td>".nl2br($objp->description)."</td>\n";
}
print '<td align="center">'.$objp->qty_livre.'</td>';
print '<td align="center">'.dolibarr_print_date($objp->date_expedition).'</td>';
if ($conf->expedition->enabled)
{
print '<td align="left"><a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.'<a></td>';
}
if ($conf->livraison->enabled)
{
if ($objp->livraison_id)
{
print '<td><a href="'.DOL_URL_ROOT.'/livraison/fiche.php?id='.$objp->livraison_id.'">'.img_object($langs->trans("ShowSending"),'generic').' '.$objp->livraison_ref.'<a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
}
print '</tr>';
$i++;
}
print '</table>';
}
$db->free($resql);
}
else
{
dolibarr_print_error($db);
}
} }
else else
{ {

View File

@ -212,7 +212,7 @@ class Expedition extends CommonObject
{ {
$sql.=", pe.fk_propal as origin_id"; $sql.=", pe.fk_propal as origin_id";
} }
if ($conf->livraison->enabled) $sql.=", l.rowid as livraison_id"; if ($conf->livraison_bon->enabled) $sql.=", l.rowid as livraison_id";
$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e"; $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
if ($conf->commande->enabled) if ($conf->commande->enabled)
{ {
@ -224,7 +224,7 @@ class Expedition extends CommonObject
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."pr_exp as pe ON e.rowid = pe.fk_expedition"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."pr_exp as pe ON e.rowid = pe.fk_expedition";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."propal as p ON pe.fk_propal = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."propal as p ON pe.fk_propal = p.rowid";
} }
if ($conf->livraison->enabled) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON e.rowid = l.fk_expedition"; if ($conf->livraison_bon->enabled) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON e.rowid = l.fk_expedition";
$sql.= " WHERE e.rowid = ".$id; $sql.= " WHERE e.rowid = ".$id;
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
@ -432,7 +432,7 @@ class Expedition extends CommonObject
{ {
global $conf; global $conf;
if ($conf->livraison->enabled) if ($conf->livraison_bon->enabled)
{ {
if ($this->statut == 1) if ($this->statut == 1)
{ {
@ -440,8 +440,15 @@ class Expedition extends CommonObject
include_once(DOL_DOCUMENT_ROOT."/livraison/livraison.class.php"); include_once(DOL_DOCUMENT_ROOT."/livraison/livraison.class.php");
$livraison = new Livraison($this->db); $livraison = new Livraison($this->db);
$result=$livraison->create_from_sending($user, $this->id); $result=$livraison->create_from_sending($user, $this->id);
if ($result > 0)
return $result; {
return $result;
}
else
{
$this->error=$livraison->error;
return $result;
}
} }
else return 0; else return 0;
} }
@ -695,7 +702,7 @@ class Expedition extends CommonObject
$this->specimen=1; $this->specimen=1;
$socid = rand(1, $num_socs); $socid = rand(1, $num_socs);
$this->statut = 1; $this->statut = 1;
if ($conf->livraison->enabled) if ($conf->livraison_bon->enabled)
{ {
$this->livraison_id = 0; $this->livraison_id = 0;
} }

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com> * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
* Copyright (C) 2005-2008 Régis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2008 Régis Houssin <regis@dolibarr.fr>
* *
@ -31,6 +31,7 @@
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php");
require_once(DOL_DOCUMENT_ROOT."/expedition/mods/pdf/ModelePdfExpedition.class.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/mods/pdf/ModelePdfExpedition.class.php");
require_once(DOL_DOCUMENT_ROOT."/lib/sendings.lib.php");
if ($conf->produit->enabled) require_once(DOL_DOCUMENT_ROOT."/product.class.php"); if ($conf->produit->enabled) require_once(DOL_DOCUMENT_ROOT."/product.class.php");
if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
@ -43,7 +44,7 @@ $langs->load('orders');
$langs->load('stocks'); $langs->load('stocks');
$langs->load('other'); $langs->load('other');
if (!$user->rights->expedition->lire) if (! $user->rights->expedition->lire)
accessforbidden(); accessforbidden();
@ -114,12 +115,20 @@ if ($_POST["action"] == 'add')
/* /*
* Génère un bon de livraison * Génère un bon de livraison
*/ */
if ($_GET["action"] == 'create_delivery' && $conf->livraison->enabled && $user->rights->expedition->livraison->creer) if ($_GET["action"] == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)
{ {
$expedition = new Expedition($db); $expedition = new Expedition($db);
$expedition->fetch($_GET["id"]); $expedition->fetch($_GET["id"]);
$result = $expedition->create_delivery($user); $result = $expedition->create_delivery($user);
Header("Location: ".DOL_URL_ROOT.'/livraison/fiche.php?id='.$result); if ($result > 0)
{
Header("Location: ".DOL_URL_ROOT.'/livraison/fiche.php?id='.$result);
exit;
}
else
{
$mesg=$expedition->error;
}
} }
if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->expedition->valider) if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->expedition->valider)
@ -138,6 +147,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes')
$expedition->fetch($_GET["id"]); $expedition->fetch($_GET["id"]);
$expedition->delete(); $expedition->delete();
Header("Location: liste.php"); Header("Location: liste.php");
exit;
} }
} }
@ -314,7 +324,7 @@ if ($_GET["action"] == 'create')
{ {
$ligne = $object->lignes[$indiceAsked]; $ligne = $object->lignes[$indiceAsked];
$var=!$var; $var=!$var;
print "<tr $bc[$var]>\n"; print "<tr ".$bc[$var].">\n";
if ($ligne->fk_product > 0) if ($ligne->fk_product > 0)
{ {
$product = new Product($db); $product = new Product($db);
@ -412,7 +422,6 @@ if ($_GET["action"] == 'create')
print "</tr>\n"; print "</tr>\n";
$indiceAsked++; $indiceAsked++;
$var=!$var;
} }
/* /*
@ -457,7 +466,7 @@ else
$hselected = $h; $hselected = $h;
$h++; $h++;
if ($conf->livraison->enabled && $expedition->livraison_id) if ($conf->livraison_bon->enabled && $expedition->livraison_id)
{ {
$head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$expedition->livraison_id; $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$expedition->livraison_id;
$head[$h][1] = $langs->trans("DeliveryCard"); $head[$h][1] = $langs->trans("DeliveryCard");
@ -466,6 +475,8 @@ else
dolibarr_fiche_head($head, $hselected, $langs->trans("Sending")); dolibarr_fiche_head($head, $hselected, $langs->trans("Sending"));
if ($mesg) print $mesg;
/* /*
* Confirmation de la suppression * Confirmation de la suppression
* *
@ -585,11 +596,11 @@ else
} }
print "</tr>\n"; print "</tr>\n";
$var=true; $var=false;
for ($i = 0 ; $i < $num_prod ; $i++) for ($i = 0 ; $i < $num_prod ; $i++)
{ {
print "<tr $bc[$var]>"; print "<tr ".$bc[$var].">";
if ($lignes[$i]->fk_product > 0) if ($lignes[$i]->fk_product > 0)
{ {
print '<td>'; print '<td>';
@ -649,7 +660,7 @@ else
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>';
} }
if ($conf->livraison->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>';
} }
@ -666,99 +677,35 @@ else
print "<table width=\"100%\" cellspacing=2><tr><td width=\"50%\" valign=\"top\">"; print "<table width=\"100%\" cellspacing=2><tr><td width=\"50%\" valign=\"top\">";
/* /*
* Documents générés * Documents générés
*/ */
if ($conf->expedition_bon->enabled)
$expeditionref = sanitize_string($expedition->ref); {
$filedir = $conf->expedition->dir_output . "/" .$expeditionref; $expeditionref = sanitize_string($expedition->ref);
$filedir = $conf->expedition->dir_output . "/" .$expeditionref;
$urlsource = $_SERVER["PHP_SELF"]."?id=".$expedition->id;
$urlsource = $_SERVER["PHP_SELF"]."?id=".$expedition->id;
$genallowed=$user->rights->expedition->lire && ($expedition->statut > 0);
$delallowed=$user->rights->expedition->supprimer; $genallowed=$user->rights->expedition->lire && ($expedition->statut > 0);
//$genallowed=1; $delallowed=$user->rights->expedition->supprimer;
//$delallowed=0; //$genallowed=1;
//$delallowed=0;
$somethingshown=$formfile->show_documents('expedition',$expeditionref,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf);
if ($genallowed && ! $somethingshown) $somethingshown=1; $somethingshown=$formfile->show_documents('expedition',$expeditionref,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf);
if ($genallowed && ! $somethingshown) $somethingshown=1;
}
/*
* Autres expeditions
*/
$sql = "SELECT obj.fk_product, obj.description, obj.rowid, obj.qty as qty_asking";
$sql.= ", ed.qty as qty_shipped, ed.fk_expedition as expedition_id";
$sql.= ", e.ref, ".$db->pdate("e.date_expedition")." as date_expedition";
$sql.= " FROM ".MAIN_DB_PREFIX.$expedition->origin."det as obj";
$sql.= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
$sql.= " WHERE obj.fk_".$expedition->origin." = ".$expedition->origin_id;
$sql.= " AND e.rowid <> ".$expedition->id;
$sql.= " AND obj.rowid = ed.fk_origin_line";
$sql.= " AND ed.fk_expedition = e.rowid";
$sql.= " ORDER BY obj.fk_product";
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
if ($num)
{
if ($somethingshown) print '<br>';
print_titre($langs->trans("OtherSendingsForSameOrder"));
print '<table class="liste" width="100%">';
print '<tr class="liste_titre">';
print '<td align="left">'.$langs->trans("Ref").'</td>';
print '<td>'.$langs->trans("Description").'</td>';
print '<td align="center">'.$langs->trans("Qty").'</td>';
print '<td align="center">'.$langs->trans("Date").'</td>';
print "</tr>\n";
$var=True;
while ($i < $num)
{
$var=!$var;
$objp = $db->fetch_object($resql);
print "<tr $bc[$var]>";
print '<td align="left" nowrap="nowrap"><a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.'<a></td>';
if ($objp->fk_product > 0)
{
$product = new Product($db);
$product->fetch($objp->fk_product);
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.dolibarr_trunc($product->libelle,20);
if ($objp->description) print nl2br(dolibarr_trunc($objp->description,24));
print '</td>';
}
else
{
print "<td>".nl2br(dolibarr_trunc($objp->description,24))."</td>\n";
}
print '<td align="center">'.$objp->qty_shipped.'</td>';
print '<td align="center" nowrap="nowrap">'.dolibarr_print_date($objp->date_expedition).'</td>';
print '</tr>';
$i++;
}
print '</table>';
}
$db->free($resql);
}
else
{
dolibarr_print_error($db);
}
print '</td><td valign="top" width="50%">'; print '</td><td valign="top" width="50%">';
// Rien a droite // Rien a droite
print '</td></tr></table>'; print '</td></tr></table>';
print '<br>';
show_list_sending_receive($expedition->origin,$expedition->origin_id," AND e.rowid <> ".$expedition->id);
} }
else else
{ {

View File

@ -87,7 +87,7 @@ class Form
$htmltext=ereg_replace("\r","",$htmltext); $htmltext=ereg_replace("\r","",$htmltext);
$htmltext=ereg_replace("<br>\n","<br>",$htmltext); $htmltext=ereg_replace("<br>\n","<br>",$htmltext);
$htmltext=ereg_replace("\n","",$htmltext); $htmltext=ereg_replace("\n","",$htmltext);
if ($conf->use_javascript_ajax && $tooltipon == 4) if ($conf->use_javascript_ajax && $tooltipon == 4)
{ {
$s = '<div id="tip'.$i.'">'."\n"; $s = '<div id="tip'.$i.'">'."\n";
@ -116,34 +116,34 @@ class Form
$paramfortooltippicto.=' onmouseover="showtip(\''.$htmltext.'\')"'; $paramfortooltippicto.=' onmouseover="showtip(\''.$htmltext.'\')"';
$paramfortooltippicto.=' onMouseout="hidetip()"'; $paramfortooltippicto.=' onMouseout="hidetip()"';
} }
} }
$s=""; $s="";
$s.='<table class="nobordernopadding"><tr>'; $s.='<table class="nobordernopadding"><tr>';
if ($direction > 0) if ($direction > 0)
{
if ($text)
{ {
$s.='<td'.$paramfortooltiptext.'>'.$text; if ($text)
if ($direction) $s.='&nbsp;'; {
$s.='</td>'; $s.='<td'.$paramfortooltiptext.'>'.$text;
if ($direction) $s.='&nbsp;';
$s.='</td>';
}
if ($direction) $s.='<td'.$paramfortooltippicto.' valign="top" width="14">'.$img.'</td>';
} }
if ($direction) $s.='<td'.$paramfortooltippicto.' valign="top" width="14">'.$img.'</td>'; else
}
else
{
if ($direction) $s.='<td'.$paramfortooltippicto.' valign="top" width="14">'.$img.'</td>';
if ($text)
{ {
$s.='<td'.$paramfortooltiptext.'>'; if ($direction) $s.='<td'.$paramfortooltippicto.' valign="top" width="14">'.$img.'</td>';
if ($direction) $s.='&nbsp;'; if ($text)
$s.=$text.'</td>'; {
$s.='<td'.$paramfortooltiptext.'>';
if ($direction) $s.='&nbsp;';
$s.=$text.'</td>';
}
} }
$s.='</tr></table>';
} }
$s.='</tr></table>'; return $s;
} }
return $s;
}
/** /**
\brief Affiche un texte avec picto help qui affiche un tooltip \brief Affiche un texte avec picto help qui affiche un tooltip

View File

@ -1683,7 +1683,7 @@ function migrate_commande_expedition($db,$langs,$conf)
*/ */
function migrate_commande_livraison($db,$langs,$conf) function migrate_commande_livraison($db,$langs,$conf)
{ {
if ($conf->livraison->enabled) if ($conf->livraison_bon->enabled)
{ {
print '<tr><td colspan="4">'; print '<tr><td colspan="4">';

View File

@ -47,12 +47,12 @@ function commande_prepare_head($commande)
$h++; $h++;
} }
if (($conf->expedition->enabled && $user->rights->expedition->lire) if (($conf->expedition_bon->enabled && $user->rights->expedition->lire)
|| ($conf->livraison->enabled && $user->rights->expedition->livraison->lire)) || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire))
{ {
$head[$h][0] = DOL_URL_ROOT.'/expedition/commande.php?id='.$commande->id; $head[$h][0] = DOL_URL_ROOT.'/expedition/commande.php?id='.$commande->id;
if ($conf->expedition->enabled) $text=$langs->trans("Sendings"); if ($conf->expedition_bon->enabled) $text=$langs->trans("Sendings");
if ($conf->livraison->enabled) $text.='/'.$langs->trans("Receivings"); if ($conf->livraison_bon->enabled) $text.='/'.$langs->trans("Receivings");
$head[$h][1] = $text; $head[$h][1] = $text;
$head[$h][2] = 'shipping'; $head[$h][2] = 'shipping';
$h++; $h++;

View File

@ -43,13 +43,14 @@ function propal_prepare_head($propal)
$head[$h][2] = 'comm'; $head[$h][2] = 'comm';
$h++; $h++;
if ((!$conf->commande->enabled && (($conf->expedition->enabled && $user->rights->expedition->lire) if ((!$conf->commande->enabled &&
|| ($conf->livraison->enabled && $user->rights->expedition->livraison->lire)))) (($conf->expedition_bon->enabled && $user->rights->expedition->lire)
|| ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire))))
{ {
$langs->load("sendings"); $langs->load("sendings");
$head[$h][0] = DOL_URL_ROOT.'/expedition/propal.php?propalid='.$propal->id; $head[$h][0] = DOL_URL_ROOT.'/expedition/propal.php?propalid='.$propal->id;
if ($conf->expedition->enabled) $text=$langs->trans("Sendings"); if ($conf->expedition_bon->enabled) $text=$langs->trans("Sendings");
if ($conf->livraison->enabled) $text.='/'.$langs->trans("Receivings"); if ($conf->livraison_bon->enabled) $text.='/'.$langs->trans("Receivings");
$head[$h][1] = $text; $head[$h][1] = $text;
$head[$h][2] = 'shipping'; $head[$h][2] = 'shipping';
$h++; $h++;

134
htdocs/lib/sendings.lib.php Normal file
View File

@ -0,0 +1,134 @@
<?php
/* Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
\file htdocs/lib/sendings.lib.php
\ingroup expedition
\brief Library for expedition module
\version $Id$
*/
/**
* List sendings and receive receipts
*
* @param unknown_type $option
* @return unknown
*/
function show_list_sending_receive($origin='commande',$origin_id,$filter='')
{
global $db, $conf, $langs, $bc;
$sql = "SELECT obj.rowid, obj.fk_product, obj.description, obj.qty as qty_asking";
$sql.= ", ed.qty as qty_shipped, ed.fk_expedition as expedition_id";
$sql.= ", e.ref, ".$db->pdate("e.date_expedition")." as date_expedition";
if ($conf->livraison_bon->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref";
$sql.= " FROM ".MAIN_DB_PREFIX.$origin."det as obj";
$sql.= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid";
$sql.= " WHERE obj.fk_".$origin." = ".$origin_id;
if ($filter) $sql.=$filter;
$sql.= " AND obj.rowid = ed.fk_origin_line";
$sql.= " AND ed.fk_expedition = e.rowid";
$sql.= " ORDER BY obj.fk_product";
dolibarr_syslog("show_list_sending_receive sql=".$sql, LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
if ($num)
{
if ($somethingshown) print '<br>';
if ($filter) print_titre($langs->trans("OtherSendingsForSameOrder"));
else print_titre($langs->trans("SendingsAndReceivingForSameOrder"));
print '<table class="liste" width="100%">';
print '<tr class="liste_titre">';
print '<td align="left">'.$langs->trans("Ref").'</td>';
print '<td>'.$langs->trans("Description").'</td>';
print '<td align="center">'.$langs->trans("Qty").'</td>';
print '<td align="center">'.$langs->trans("DateSending").'</td>';
if ($conf->expedition_bon->enabled)
{
print '<td>'.$langs->trans("SendingSheet").'</td>';
}
if ($conf->livraison_bon->enabled)
{
print '<td>'.$langs->trans("DeliveryOrder").'</td>';
}
print "</tr>\n";
$var=True;
while ($i < $num)
{
$var=!$var;
$objp = $db->fetch_object($resql);
print "<tr $bc[$var]>";
print '<td align="left" nowrap="nowrap"><a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.'<a></td>';
if ($objp->fk_product > 0)
{
$product = new Product($db);
$product->fetch($objp->fk_product);
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.dolibarr_trunc($product->libelle,20);
if ($objp->description) print dol_htmlentitiesbr(dolibarr_trunc($objp->description,24));
print '</td>';
}
else
{
print "<td>".dol_htmlentitiesbr(dolibarr_trunc($objp->description,24))."</td>\n";
}
print '<td align="center">'.$objp->qty_shipped.'</td>';
print '<td align="center" nowrap="nowrap">'.dolibarr_print_date($objp->date_expedition,'dayhour').'</td>';
if ($conf->expedition_bon->enabled)
{
print '<td align="left"><a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.'<a></td>';
}
if ($conf->livraison_bon->enabled)
{
if ($objp->livraison_id)
{
print '<td><a href="'.DOL_URL_ROOT.'/livraison/fiche.php?id='.$objp->livraison_id.'">'.img_object($langs->trans("ShowSending"),'generic').' '.$objp->livraison_ref.'<a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
}
print '</tr>';
$i++;
}
print '</table>';
}
$db->free($resql);
}
else
{
dolibarr_print_error($db);
}
return 1;
}
?>

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com> * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be> * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
* Copyright (C) 2005-2008 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2008 Regis Houssin <regis@dolibarr.fr>
@ -425,13 +425,13 @@ else
if ($conf->commande->enabled) if ($conf->commande->enabled)
{ {
print '<tr><td>'.$langs->trans("RefOrder").'</td>'; print '<tr><td>'.$langs->trans("RefOrder").'</td>';
print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/expedition/commande.php?id='.$livraison->$object->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$livraison->$object->ref."</a></td>\n"; print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/expedition/commande.php?id='.$livraison->commande->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$livraison->commande->ref."</a></td>\n";
print '</tr>'; print '</tr>';
} }
else else
{ {
print '<tr><td>'.$langs->trans("RefProposal").'</td>'; print '<tr><td>'.$langs->trans("RefProposal").'</td>';
print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/expedition/propal.php?propalid='.$livraison->$object->id.'">'.img_object($langs->trans("ShowProposal"),'propal').' '.$livraison->$object->ref."</a></td>\n"; print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/expedition/propal.php?propalid='.$livraison->propal->id.'">'.img_object($langs->trans("ShowProposal"),'propal').' '.$livraison->propal->ref."</a></td>\n";
print '</tr>'; print '</tr>';
} }
@ -568,7 +568,7 @@ else
$sql.= ", cd.rowid, cd.qty as qty_commande"; $sql.= ", cd.rowid, cd.qty as qty_commande";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sql.= " , ".MAIN_DB_PREFIX."livraisondet as ld, ".MAIN_DB_PREFIX."livraison as l"; $sql.= " , ".MAIN_DB_PREFIX."livraisondet as ld, ".MAIN_DB_PREFIX."livraison as l";
$sql.= " WHERE cd.fk_commande = ".$livraison->commande_id; $sql.= " WHERE cd.fk_commande = ".$livraison->origin_id;
$sql.= " AND l.rowid <> ".$livraison->id; $sql.= " AND l.rowid <> ".$livraison->id;
$sql.= " AND cd.rowid = ld.fk_origin_line"; $sql.= " AND cd.rowid = ld.fk_origin_line";
$sql.= " AND ld.fk_livraison = l.rowid"; $sql.= " AND ld.fk_livraison = l.rowid";

View File

@ -17,21 +17,19 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/ */
/** /**
\file htdocs/livraison/livraison.class.php \file htdocs/livraison/livraison.class.php
\ingroup livraison \ingroup livraison
\brief Fichier de la classe de gestion des bons de livraison \brief Fichier de la classe de gestion des bons de livraison
\version $Revision$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php");
require_once(DOL_DOCUMENT_ROOT."/expedition/expedition.class.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/expedition.class.php");
require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
@ -47,7 +45,7 @@ class Livraison extends CommonObject
var $brouillon; var $brouillon;
var $origin; var $origin;
var $origin_id; var $origin_id;
var $socid;
/** /**
* Initialisation * Initialisation
@ -76,7 +74,7 @@ class Livraison extends CommonObject
{ {
global $conf; global $conf;
dolibarr_syslog("Livraison::create "); dolibarr_syslog("Livraison::create");
$error = 0; $error = 0;
@ -84,14 +82,16 @@ class Livraison extends CommonObject
$this->brouillon = 1; $this->brouillon = 1;
$this->user = $user; $this->user = $user;
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."livraison (date_creation, fk_user_author, fk_adresse_livraison"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraison (ref, fk_soc, date_creation, fk_user_author,";
$sql.= " fk_adresse_livraison";
if ($this->commande_id) $sql.= ", fk_commande"; if ($this->commande_id) $sql.= ", fk_commande";
if ($this->expedition_id) $sql.= ", fk_expedition"; if ($this->expedition_id) $sql.= ", fk_expedition";
$sql.= ")"; $sql.= ")";
$sql.= " VALUES (now(), $user->id, $this->adresse_livraison_id"; $sql.= " VALUES ('(PROV)', ".$this->socid.", now(), $user->id,";
$sql.= " ".($this->adresse_livraison_id > 0?$this->adresse_livraison_id:"null");
if ($this->commande_id) $sql.= ", $this->commande_id"; if ($this->commande_id) $sql.= ", $this->commande_id";
if ($this->expedition_id) $sql.= ", $this->expedition_id"; if ($this->expedition_id) $sql.= ", $this->expedition_id";
$sql.= ")"; $sql.= ")";
@ -120,7 +120,10 @@ class Livraison extends CommonObject
*/ */
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{ {
if (! $this->create_line(0, $this->lignes[$i]->commande_ligne_id, $this->lignes[$i]->qty)) $origin_id=$this->lignes[$i]->origin_ligne_id;
if (! $origin_id) $origin_id=$this->lignes[$i]->commande_ligne_id; // For backward compatibility
if (! $this->create_line(0, $origin_id, $this->lignes[$i]->qty))
{ {
$error++; $error++;
} }
@ -146,7 +149,7 @@ class Livraison extends CommonObject
else else
{ {
$error++; $error++;
$this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; $this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror;
dolibarr_syslog("Livraison::create Error -3 ".$this->error); dolibarr_syslog("Livraison::create Error -3 ".$this->error);
$this->db->rollback(); $this->db->rollback();
return -3; return -3;
@ -155,7 +158,7 @@ class Livraison extends CommonObject
else else
{ {
$error++; $error++;
$this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; $this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror;
dolibarr_syslog("Livraison::create Error -2 ".$this->error); dolibarr_syslog("Livraison::create Error -2 ".$this->error);
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
@ -164,7 +167,7 @@ class Livraison extends CommonObject
else else
{ {
$error++; $error++;
$this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; $this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror;
dolibarr_syslog("Livraison::create Error -1 ".$this->error); dolibarr_syslog("Livraison::create Error -1 ".$this->error);
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
@ -181,6 +184,7 @@ class Livraison extends CommonObject
$idprod = 0; $idprod = 0;
$j = 0; $j = 0;
// Search product id
while (($j < sizeof($this->commande->lignes)) && idprod == 0) while (($j < sizeof($this->commande->lignes)) && idprod == 0)
{ {
if ($this->commande->lignes[$j]->id == $commande_ligne_id) if ($this->commande->lignes[$j]->id == $commande_ligne_id)
@ -190,8 +194,12 @@ class Livraison extends CommonObject
$j++; $j++;
} }
$sql = "INSERT INTO ".MAIN_DB_PREFIX."livraisondet (fk_livraison, fk_commande_ligne, qty)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraisondet (fk_livraison, fk_origin_line,";
$sql .= " VALUES ($this->id,".$commande_ligne_id.",".$qty.")"; if ($idprod) $sql.=" fk_product";
$sql.= " qty)";
$sql.= " VALUES (".$this->id.",".$commande_ligne_id.",";
if ($idprod) $sql.=" ".$idprod.",";
$sql.= $qty.")";
if (! $this->db->query($sql) ) if (! $this->db->query($sql) )
{ {
@ -205,7 +213,6 @@ class Livraison extends CommonObject
} }
/** /**
*
* Lit un bon de livraison * Lit un bon de livraison
* *
*/ */
@ -234,7 +241,8 @@ class Livraison extends CommonObject
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."pr_liv as pl ON pl.fk_livraison = l.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."pr_liv as pl ON pl.fk_livraison = l.rowid";
} }
$sql.= " WHERE l.rowid = ".$id; $sql.= " WHERE l.rowid = ".$id;
dolibarr_syslog("Livraison::fetch sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
if ($result) if ($result)
{ {
@ -475,7 +483,7 @@ class Livraison extends CommonObject
$LivraisonLigne->origin_ligne_id = $expedition->lignes[$i]->origin_line_id; $LivraisonLigne->origin_ligne_id = $expedition->lignes[$i]->origin_line_id;
$LivraisonLigne->libelle = $expedition->lignes[$i]->libelle; $LivraisonLigne->libelle = $expedition->lignes[$i]->libelle;
$LivraisonLigne->description = $expedition->lignes[$i]->product_desc; $LivraisonLigne->description = $expedition->lignes[$i]->product_desc;
$LivraisonLigne->qty = $expedition->lignes[$i]->qty_expedie; $LivraisonLigne->qty = $expedition->lignes[$i]->qty_shipped;
$LivraisonLigne->fk_product = $expedition->lignes[$i]->fk_product; $LivraisonLigne->fk_product = $expedition->lignes[$i]->fk_product;
$LivraisonLigne->ref = $expedition->lignes[$i]->ref; $LivraisonLigne->ref = $expedition->lignes[$i]->ref;
$this->lignes[$i] = $LivraisonLigne; $this->lignes[$i] = $LivraisonLigne;
@ -487,7 +495,8 @@ class Livraison extends CommonObject
$this->projetid = $expedition->projetidp; $this->projetid = $expedition->projetidp;
$this->date_livraison = $expedition->date_livraison; $this->date_livraison = $expedition->date_livraison;
$this->adresse_livraison_id = $expedition->adresse_livraison_id; $this->adresse_livraison_id = $expedition->adresse_livraison_id;
$this->socid = $expedition->socid;
return $this->create($user); return $this->create($user);
} }
@ -619,16 +628,16 @@ class Livraison extends CommonObject
{ {
$this->lignes = array(); $this->lignes = array();
$sql = "SELECT p.label, p.ref"; $sql = "SELECT p.label, p.ref,";
$sql.= ", l.description, l.fk_product, l.subprice, l.total_ht, l.qty as qtyliv"; $sql.= " l.description, l.fk_product, l.subprice, l.total_ht, l.qty as qtyliv";
//$sql.= ", c.qty as qtycom"; //$sql.= ", c.qty as qtycom";
$sql .= " FROM ".MAIN_DB_PREFIX."livraisondet as l"; $sql.= " FROM ".MAIN_DB_PREFIX."livraisondet as l";
//$sql .= " , ".MAIN_DB_PREFIX."commandedet as c"; //$sql .= " , ".MAIN_DB_PREFIX."commandedet as c";
$sql .= " , ".MAIN_DB_PREFIX."product as p"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on p.rowid = l.fk_product";
$sql .= " WHERE l.fk_livraison = ".$this->id; $sql.= " WHERE l.fk_livraison = ".$this->id;
//$sql .= " AND l.fk_commande_ligne = c.rowid"; //$sql .= " AND l.fk_commande_ligne = c.rowid";
$sql .= " AND l.fk_product = p.rowid";
dolibarr_syslog("Livraison::fetch_lignes sql=".$sql);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {