Fix: Error on page when going from some link

This commit is contained in:
Laurent Destailleur 2010-08-13 17:42:10 +00:00
parent 5ab7a296e2
commit ff6916a5a3

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2010 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-2010 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* *
@ -28,16 +28,16 @@
*/ */
require("../main.inc.php"); require("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/expedition/expedition.class.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/class/expedition.class.php");
require_once(DOL_DOCUMENT_ROOT."/includes/modules/expedition/pdf/ModelePdfExpedition.class.php"); require_once(DOL_DOCUMENT_ROOT."/includes/modules/expedition/pdf/ModelePdfExpedition.class.php");
require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
require_once(DOL_DOCUMENT_ROOT."/product/html.formproduct.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php");
require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/sendings.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/sendings.lib.php");
if ($conf->produit->enabled || $conf->service->enabled) require_once(DOL_DOCUMENT_ROOT."/product/product.class.php"); if ($conf->product->enabled || $conf->service->enabled) require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/comm/propal/propal.class.php"); if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/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/class/commande.class.php");
if ($conf->stock->enabled) require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php"); if ($conf->stock->enabled) require_once(DOL_DOCUMENT_ROOT."/product/stock/class/entrepot.class.php");
$langs->load("sendings"); $langs->load("sendings");
$langs->load("companies"); $langs->load("companies");
@ -48,12 +48,12 @@ $langs->load('stocks');
$langs->load('other'); $langs->load('other');
$langs->load('propal'); $langs->load('propal');
$origin = "expedition";
$origin_id = isset($_GET["id"])?$_GET["id"]:'';
$id = $origin_id;
$origin = $_GET["origin"]?$_GET["origin"]:$_POST["origin"]; // Example: commande, propal $origin = $_GET["origin"]?$_GET["origin"]:$_POST["origin"]; // Example: commande, propal
$origin_id = $_GET["origin_id"]?$_GET["origin_id"]:$_POST["origin_id"]; // Id of order or propal $origin_id = isset($_REQUEST["id"])?$_REQUEST["id"]:'';
if (empty($origin_id)) $origin_id = $_GET["origin_id"]?$_GET["origin_id"]:$_POST["origin_id"]; // Id of order or propal
if (empty($origin_id)) $origin_id = $_GET["object_id"]?$_GET["object_id"]:$_POST["object_id"]; // Id of order or propal
$id = $origin_id;
// Security check // Security check
@ -72,7 +72,6 @@ if ($_POST["action"] == 'add')
// Creation de l'objet expedition // Creation de l'objet expedition
$expedition = new Expedition($db); $expedition = new Expedition($db);
$expedition->date_expedition = time();
$expedition->note = $_POST["note"]; $expedition->note = $_POST["note"];
$expedition->origin = $origin; $expedition->origin = $origin;
$expedition->origin_id = $origin_id; $expedition->origin_id = $origin_id;
@ -83,8 +82,8 @@ if ($_POST["action"] == 'add')
$expedition->size_units = $_POST["size_units"]; $expedition->size_units = $_POST["size_units"];
$expedition->weight_units = $_POST["weight_units"]; $expedition->weight_units = $_POST["weight_units"];
// On boucle sur chaque ligne du document d'origine pour completer objet expedition // On va boucler sur chaque ligne du document d'origine pour completer objet expedition
// avec qte a livrer // avec info diverses + qte a livrer
$classname = ucfirst($expedition->origin); $classname = ucfirst($expedition->origin);
$object = new $classname($db); $object = new $classname($db);
$object->fetch($expedition->origin_id); $object->fetch($expedition->origin_id);
@ -92,19 +91,21 @@ if ($_POST["action"] == 'add')
$expedition->socid = $object->socid; $expedition->socid = $object->socid;
$expedition->ref_customer = $object->ref_client; $expedition->ref_customer = $object->ref_client;
$expedition->date_delivery = $object->date_livraison; $expedition->date_delivery = $object->date_livraison; // Date delivery planed
$expedition->fk_delivery_address = $object->fk_delivery_address; $expedition->fk_delivery_address = $object->fk_delivery_address;
$expedition->expedition_method_id = $_POST["expedition_method_id"]; $expedition->expedition_method_id = $_POST["expedition_method_id"];
$expedition->tracking_number = $_POST["tracking_number"]; $expedition->tracking_number = $_POST["tracking_number"];
//var_dump($_POST);exit;
for ($i = 0 ; $i < sizeof($object->lignes) ; $i++) for ($i = 0 ; $i < sizeof($object->lignes) ; $i++)
{ {
$ent = "entl".$i;
$idl = "idl".$i;
$qty = "qtyl".$i; $qty = "qtyl".$i;
$entrepot_id = $_POST[$ent]?$_POST[$ent]:$_POST["entrepot_id"];
if ($_POST[$qty] > 0) if ($_POST[$qty] > 0)
{ {
$ent = "entl".$i;
$idl = "idl".$i;
$entrepot_id = isset($_POST[$ent])?$_POST[$ent]:$_POST["entrepot_id"];
$expedition->addline($entrepot_id,$_POST[$idl],$_POST[$qty]); $expedition->addline($entrepot_id,$_POST[$idl],$_POST[$qty]);
} }
} }
@ -126,7 +127,7 @@ if ($_POST["action"] == 'add')
} }
/* /*
* Genere un bon de livraison * Build a receiving receipt
*/ */
if ($_GET["action"] == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer) if ($_GET["action"] == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)
{ {
@ -189,6 +190,72 @@ if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes')
} }
} }
if ($_REQUEST["action"] == 'open')
{
if ($user->rights->expedition->valider )
{
$expedition = new Expedition($db);
$expedition->fetch($_GET["id"]);
$result = $expedition->setStatut(0);
if ($result < 0)
{
$mesg = $expedition->error;
}
}
}
if ($_POST['action'] == 'setdate_livraison' && $user->rights->expedition->creer)
{
//print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
$datelivraison=dol_mktime(0, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']);
$shipping = new Expedition($db);
$shipping->fetch($_GET['id']);
$result=$shipping->set_date_livraison($user,$datelivraison);
if ($result < 0)
{
$mesg='<div class="error">'.$shipping->error.'</div>';
}
}
// Action update description of emailing
if ($_REQUEST["action"] == 'settrackingnumber' || $_REQUEST["action"] == 'settrackingurl'
|| $_REQUEST["action"] == 'settrueWeight'
|| $_REQUEST["action"] == 'settrueWidth'
|| $_REQUEST["action"] == 'settrueHeight'
|| $_REQUEST["action"] == 'settrueDepth'
|| $_REQUEST["action"] == 'setexpedition_method_id')
{
$error=0;
$shipping = new Expedition($db);
$result=$shipping->fetch($_REQUEST['id']);
if ($result < 0) dol_print_error($db,$shipping->error);
if ($_REQUEST["action"] == 'settrackingnumber') $shipping->tracking_number = trim($_REQUEST["trackingnumber"]);
if ($_REQUEST["action"] == 'settrackingurl') $shipping->tracking_url = trim($_REQUEST["trackingurl"]);
if ($_REQUEST["action"] == 'settrueWeight') $shipping->trueWeight = trim($_REQUEST["trueWeight"]);
if ($_REQUEST["action"] == 'settrueWidth') $shipping->trueWidth = trim($_REQUEST["trueWidth"]);
if ($_REQUEST["action"] == 'settrueHeight') $shipping->trueHeight = trim($_REQUEST["trueHeight"]);
if ($_REQUEST["action"] == 'settrueDepth') $shipping->trueDepth = trim($_REQUEST["trueDepth"]);
if ($_REQUEST["action"] == 'setexpedition_method_id') $shipping->expedition_method_id = trim($_REQUEST["expedition_method_id"]);
if (! $error)
{
if ($shipping->update($user) >= 0)
{
Header("Location: fiche.php?id=".$shipping->id);
exit;
}
$mesg=$shipping->error;
}
$mesg='<div class="error">'.$mesg.'</div>';
$_GET["action"]="";
$_GET["id"]=$_REQUEST["id"];
}
/* /*
* Build doc * Build doc
*/ */
@ -242,7 +309,6 @@ $formproduct = new FormProduct($db);
*********************************************************************/ *********************************************************************/
if ($_GET["action"] == 'create') if ($_GET["action"] == 'create')
{ {
$expe = new Expedition($db); $expe = new Expedition($db);
print_fiche_titre($langs->trans("CreateASending")); print_fiche_titre($langs->trans("CreateASending"));
@ -262,21 +328,22 @@ if ($_GET["action"] == 'create')
$object = new $classname($db); $object = new $classname($db);
if ($object->fetch($origin_id)) if ($object->fetch($origin_id)) // This include the fetch_lines
{ {
//var_dump($object);
$soc = new Societe($db); $soc = new Societe($db);
$soc->fetch($object->socid); $soc->fetch($object->socid);
$author = new User($db); $author = new User($db);
$author->id = $object->user_author_id; $author->fetch($object->user_author_id);
$author->fetch();
if ($conf->stock->enabled) $entrepot = new Entrepot($db); if ($conf->stock->enabled) $entrepot = new Entrepot($db);
/* /*
* Document source * Document source
*/ */
print '<form action="fiche.php" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="origin" value="'.$origin.'">'; print '<input type="hidden" name="origin" value="'.$origin.'">';
@ -290,13 +357,13 @@ if ($_GET["action"] == 'create')
// Ref // Ref
print '<tr><td width="30%">'; print '<tr><td width="30%">';
if ($conf->commande->enabled) if ($origin == 'commande' && $conf->commande->enabled)
{ {
print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$object->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$object->ref; print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$object->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$object->ref;
} }
else if ($origin == 'propal' && $conf->propal->enabled)
{ {
print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/fiche.php?propalid='.$object->id.'">'.img_object($langs->trans("ShowProposal"),'propal').' '.$object->ref; print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/fiche.php?id='.$object->id.'">'.img_object($langs->trans("ShowProposal"),'propal').' '.$object->ref;
} }
print '</a></td>'; print '</a></td>';
print "</tr>\n"; print "</tr>\n";
@ -313,13 +380,12 @@ if ($_GET["action"] == 'create')
print '<td colspan="3">'.$soc->getNomUrl(1).'</td>'; print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
print '</tr>'; print '</tr>';
// Date
print "<tr><td>".$langs->trans("Date")."</td>";
print '<td colspan="3">'.dol_print_date($object->date,"day")."</td></tr>\n";
// Date delivery planned // Date delivery planned
print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>'; print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
print '<td colspan="3">'.dol_print_date($object->date_livraison,'day')."</td>\n"; print '<td colspan="3">';
print dol_print_date($object->date_livraison,"day");
//$html->select_date($object->date_livraison,'date_delivery');
print "</td>\n";
print '</tr>'; print '</tr>';
// Delivery address // Delivery address
@ -330,53 +396,44 @@ if ($_GET["action"] == 'create')
print '<td colspan="3">'; print '<td colspan="3">';
if (!empty($object->fk_delivery_address)) if (!empty($object->fk_delivery_address))
{ {
$html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$_GET['socid'],'none','commande',$object->id); $html->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$_GET['socid'],'none','commande',$object->id);
} }
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
// Warehouse (id forced)
if ($conf->stock->enabled && $_GET["entrepot_id"])
{
print '<tr><td>'.$langs->trans("Warehouse").'</td>';
print '<td colspan="3">';
$ents = $entrepot->list_array();
print '<a href="'.DOL_URL_ROOT.'/product/stock/fiche.php?id='.$_GET["entrepot_id"].'">'.img_object($langs->trans("ShowWarehouse"),'stock').' '.$ents[$_GET["entrepot_id"]].'</a>';
print '</td></tr>';
}
if ($object->note && ! $user->societe_id) if ($object->note && ! $user->societe_id)
{ {
print '<tr><td colspan="3">'.$langs->trans("NotePrivate").': '.nl2br($object->note)."</td></tr>"; print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
print '<td colspan="3">'.nl2br($object->note)."</td></tr>";
} }
print '<tr><td>'; print '<tr><td>';
print $langs->trans("Weight"); print $langs->trans("Weight");
print '</td><td><input name="weight" size="4" value=""></td><td>'; print '</td><td><input name="weight" size="4" value="'.$_POST["weight"].'"></td><td>';
print $formproduct->select_measuring_units("weight_units","weight"); print $formproduct->select_measuring_units("weight_units","weight",$_POST["weight_units"]);
print '</td></tr><tr><td>'; print '</td></tr><tr><td>';
print $langs->trans("Width"); print $langs->trans("Width");
print ' </td><td><input name="sizeW" size="4" value=""></td>'; print ' </td><td><input name="sizeW" size="4" value="'.$_POST["sizeW"].'"></td><td rowspan="3">';
print '<td>&nbsp;</td></tr><tr><td>';
print $langs->trans("Height");
print '</td><td><input name="sizeH" size="4" value=""></td><td>';
print $formproduct->select_measuring_units("size_units","size"); print $formproduct->select_measuring_units("size_units","size");
print '</td></tr><tr><td>'; print '</td></tr><tr><td>';
print $langs->trans("Height");
print '</td><td><input name="sizeH" size="4" value="'.$_POST["sizeH"].'"></td>';
print '</tr><tr><td>';
print $langs->trans("Depth"); print $langs->trans("Depth");
print '</td><td><input name="sizeS" size="4" value=""></td>'; print '</td><td><input name="sizeS" size="4" value="'.$_POST["sizeS"].'"></td>';
print '<td>&nbsp;</td></tr>'; print '</tr>';
// Delivery method // Delivery method
print "<tr><td>".$langs->trans("DeliveryMethod")."</td>"; print "<tr><td>".$langs->trans("DeliveryMethod")."</td>";
print '<td colspan="3">'; print '<td colspan="3">';
$expe->fetch_delivery_methods(); $expe->fetch_delivery_methods();
$html->select_array("expedition_method_id",$expe->meths,'',1,0,0,0,"",1); $html->select_array("expedition_method_id",$expe->meths,$_POST["expedition_method_id"],1,0,0,0,"",1);
print "</td></tr>\n"; print "</td></tr>\n";
// Tracking number // Tracking number
print "<tr><td>".$langs->trans("TrackingNumber")."</td>"; print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
print '<td colspan="3">'; print '<td colspan="3">';
print '<input name="tracking_number" size="20">'; print '<input name="tracking_number" size="20" value="'.$_POST["tracking_number"].'">';
print "</td></tr>\n"; print "</td></tr>\n";
print "</table>"; print "</table>";
@ -399,21 +456,16 @@ if ($_GET["action"] == 'create')
print '<td>'.$langs->trans("Description").'</td>'; print '<td>'.$langs->trans("Description").'</td>';
print '<td align="center">'.$langs->trans("QtyOrdered").'</td>'; print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
print '<td align="center">'.$langs->trans("QtyShipped").'</td>'; print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
print '<td align="center">'.$langs->trans("QtyToShip").'</td>'; print '<td align="left">'.$langs->trans("QtyToShip").'</td>';
if ($conf->stock->enabled) if ($conf->stock->enabled)
{ {
if ($_GET["entrepot_id"]) print '<td align="left">'.$langs->trans("Warehouse").' / '.$langs->trans("Stock").'</td>';
{
print '<td align="right">'.$langs->trans("Stock").'</td>';
}
else
{
print '<td align="left">'.$langs->trans("Warehouse").'</td>';
}
} }
print "</tr>\n"; print "</tr>\n";
} }
$product_static = new Product($db);
$var=true; $var=true;
$indiceAsked = 0; $indiceAsked = 0;
while ($indiceAsked < $numAsked) while ($indiceAsked < $numAsked)
@ -422,37 +474,63 @@ if ($_GET["action"] == 'create')
$line = $object->lines[$indiceAsked]; $line = $object->lines[$indiceAsked];
$var=!$var; $var=!$var;
// Show product and description
$type=$line->product_type?$line->product_type:$line->fk_product_type;
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
if (! empty($line->date_start)) $type=1;
if (! empty($line->date_end)) $type=1;
print "<tr ".$bc[$var].">\n"; print "<tr ".$bc[$var].">\n";
// Desc // Product label
if ($line->fk_product > 0) if ($line->fk_product > 0)
{ {
$product->fetch($line->fk_product); $product->fetch($line->fk_product);
$product->load_stock();
print '<td>'; print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$line->fk_product.'">'; print '<a name="'.$line->rowid.'"></a>'; // ancre pour retourner sur la ligne
if ($line->product_type == 1)
// Show product and description
$product_static->type=$line->fk_product_type;
$product_static->id=$line->fk_product;
$product_static->ref=$line->ref;
$product_static->libelle=$line->product_label;
$text=$product_static->getNomUrl(1);
$text.= ' - '.$line->product_label;
$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->desc));
print $html->textwithtooltip($text,$description,3,'','',$i);
// Show range
print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
// Add description in form
if ($conf->global->PRODUIT_DESC_IN_FORM)
{ {
print img_object($langs->trans("ShowService"),"service"); print ($line->desc && $line->desc!=$line->product_label)?'<br>'.dol_htmlentitiesbr($line->desc):'';
} }
else
{
print img_object($langs->trans("ShowProduct"),"product");
}
print ' '.$product->ref.'</a> - '.$product->libelle;
if ($line->desc) print '<br>'.dol_nl2br(dol_htmlcleanlastbr($line->desc),1);
print '</td>'; print '</td>';
} }
else else
{ //var_dump($ligne); {
print "<td>".nl2br($line->desc)."</td>\n"; print "<td>";
if ($type==1) $text = img_object($langs->trans('Service'),'service');
else $text = img_object($langs->trans('Product'),'product');
print $text.' '.nl2br($line->desc);
// Show range
print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
print "</td>\n";
} }
// Qty // Qty
print '<td align="center">'.$line->qty.'</td>'; print '<td align="center">'.$line->qty.'</td>';
$qtyProdCom=$line->qty; $qtyProdCom=$line->qty;
// Sendings // Qty already sent
print '<td align="center">'; print '<td align="center">';
$quantityDelivered = $object->expeditions[$line->id]; $quantityDelivered = $object->expeditions[$line->id];
print $quantityDelivered; print $quantityDelivered;
@ -461,81 +539,63 @@ if ($_GET["action"] == 'create')
$quantityAsked = $line->qty; $quantityAsked = $line->qty;
$quantityToBeDelivered = $quantityAsked - $quantityDelivered; $quantityToBeDelivered = $quantityAsked - $quantityDelivered;
if ($conf->stock->enabled && $line->product_type == 0) $defaultqty=0;
if ($_REQUEST["entrepot_id"])
{ {
$defaultqty=0; //var_dump($product);
if ($_GET["entrepot_id"]) $stock = $product->stock_warehouse[$_REQUEST["entrepot_id"]]->real;
{ $stock+=0; // Convertit en numerique
$stock = $product->stock_entrepot[$_GET["entrepot_id"]]; $defaultqty=min($quantityToBeDelivered, $stock);
$stock+=0; // Convertit en numerique if (($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES)) || $defaultqty < 0) $defaultqty=0;
$defaultqty=min($quantityToBeDelivered, $stock); }
if ($defaultqty < 0) $defaultqty=0;
}
// Quantity // Quantity to send
print '<td align="center">'; print '<td align="left">';
if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
{
print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">'; print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
print '<input name="qtyl'.$indiceAsked.'" type="text" size="6" value="'.$defaultqty.'">'; print '<input name="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$defaultqty.'">';
print '</td>'; }
else print '0';
print '</td>';
// Stock // Stock
if ($_GET["entrepot_id"]) if ($conf->stock->enabled)
{
print '<td align="left">';
if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
{ {
print '<td align="right">'; // Show warehous
print $stock; if ($_REQUEST["entrepot_id"])
if ($stock < $quantityToBeDelivered)
{ {
print ' '.img_warning($langs->trans("StockTooLow")); $formproduct->selectWarehouses($_REQUEST["entrepot_id"],'entl'.$indiceAsked,'',1,0,$line->fk_product);
} //print $stock.' '.$quantityToBeDelivered;
print '</td>'; //if ($stock >= 0 && $stock < $quantityToBeDelivered)
} if ($stock < $quantityToBeDelivered)
else
{
$array=array();
$sql = "SELECT e.rowid, e.label, ps.reel";
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
$sql.= ", ".MAIN_DB_PREFIX."entrepot as e";
$sql.= " WHERE ps.fk_entrepot = e.rowid";
$sql.= " AND fk_product = '".$product->id."'";
$result = $db->query($sql) ;
if ($result)
{
$num = $db->num_rows($result);
$i=0;
if ($num > 0)
{ {
while ($i < $num) print ' '.img_warning($langs->trans("StockTooLow"));
{
$obj = $db->fetch_object($result);
$array[$obj->rowid] = $obj->label.' ('.$obj->reel.')';
$i++;
}
} }
$db->free($result);
} }
else else
{ {
$this->error=$db->error(); $formproduct->selectWarehouses('','entl'.$indiceAsked,'',1,0,$line->fk_product);
return -1;
} }
print '<td align="left">';
$html->select_array('entl'.$i,$array,'',1,0,0);
print '</td>';
} }
else
{
print $langs->trans("Service");
}
print '</td>';
} }
else /*else
{ {
// Quantity // Quantity
print '<td align="center" '.$colspan.'>'; print '<td align="center" '.$colspan.'>';
print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">'; print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
print '<input name="qtyl'.$indiceAsked.'" type="text" size="6" value="'.$quantityToBeDelivered.'">'; print '<input name="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$quantityToBeDelivered.'">';
print '</td>'; print '</td>';
if ($line->product_type == 1) print '<td>&nbsp;</td>'; if ($line->product_type == 1) print '<td>&nbsp;</td>';
} }*/
print "</tr>\n"; print "</tr>\n";
@ -582,10 +642,10 @@ else
/* */ /* */
/* *************************************************************************** */ /* *************************************************************************** */
{ {
if ($_GET["id"] > 0) if (! empty($_REQUEST["id"]) || ! empty($_REQUEST["ref"]))
{ {
$expedition = new Expedition($db); $expedition = new Expedition($db);
$result = $expedition->fetch($_GET["id"]); $result = $expedition->fetch($_REQUEST["id"],$_REQUEST["ref"]);
if ($result < 0) if ($result < 0)
{ {
dol_print_error($db,$expedition->error); dol_print_error($db,$expedition->error);
@ -673,7 +733,9 @@ else
// Ref // Ref
print '<tr><td width="20%">'.$langs->trans("Ref").'</td>'; print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
print '<td colspan="3">'.$expedition->ref.'</td></tr>'; print '<td colspan="3">';
print $html->showrefnav($expedition,'ref','',1,'ref','ref');
print '</td></tr>';
// Customer // Customer
print '<tr><td width="20%">'.$langs->trans("Customer").'</td>'; print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
@ -709,14 +771,34 @@ else
print '<td colspan="3">'.$expedition->ref_customer."</a></td>\n"; print '<td colspan="3">'.$expedition->ref_customer."</a></td>\n";
print '</tr>'; print '</tr>';
// Date // Date creation
print '<tr><td>'.$langs->trans("Date").'</td>'; print '<tr><td>'.$langs->trans("DateCreation").'</td>';
print '<td colspan="3">'.dol_print_date($expedition->date,"daytext")."</td>\n"; print '<td colspan="3">'.dol_print_date($expedition->date_creation,"daytext")."</td>\n";
print '</tr>'; print '</tr>';
// Date delivery planned // Delivery date planed
print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>'; print '<tr><td height="10">';
print '<td colspan="3">'.dol_print_date($expedition->date_delivery,'daytext')."</td>\n"; print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('DateDeliveryPlanned');
print '</td>';
if ($_GET['action'] != 'editdate_livraison') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$expedition->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editdate_livraison')
{
print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$expedition->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="setdate_livraison">';
$html->select_date($expedition->date_delivery?$expedition->date_delivery:-1,'liv_','','','',"setdate_livraison");
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
}
else
{
print $expedition->date_delivery ? dol_print_date($expedition->date_delivery,'daytext') : '&nbsp;';
}
print '</td>';
print '</tr>'; print '</tr>';
// Delivery address // Delivery address
@ -727,30 +809,19 @@ else
print '<td colspan="3">'; print '<td colspan="3">';
if (!empty($expedition->fk_delivery_address)) if (!empty($expedition->fk_delivery_address))
{ {
$html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$expedition->id,$expedition->fk_delivery_address,$expedition->deliveryaddress->socid,'none','shipment',$expedition->id); $html->form_address($_SERVER['PHP_SELF'].'?id='.$expedition->id,$expedition->fk_delivery_address,$expedition->deliveryaddress->socid,'none','shipment',$expedition->id);
} }
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
// Weight // Weight
print '<tr><td>'.$langs->trans("TotalWeight").'</td>'; print '<tr><td>'.$html->editfieldkey("Weight",'trueWeight',$expedition->trueWeight,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print '<td colspan="3">'; print $html->editfieldval("Weight",'trueWeight',$expedition->trueWeight,'id',$expedition->id,$user->rights->expedition->creer);
if ($expedition->trueWeight) print $expedition->weight_units?measuring_units_string($expedition->weight_units,"weight"):'';
{
// If sending weigth defined
print $expedition->trueWeight.' '.measuring_units_string($expedition->weight_units,"weight");
}
else
{
// If sending Weight not defined we use sum of products
// TODO Show in best unit
if ($totalWeight > 0) print $totalWeight.' '.measuring_units_string(0,"weight");
else print '&nbsp;';
}
print '</td></tr>'; print '</td></tr>';
// Volume Total // Volume Total
print '<tr><td>'.$langs->trans("TotalVolume").'</td>'; print '<tr><td>'.$langs->trans("Volume").'</td>';
print '<td colspan="3">'; print '<td colspan="3">';
if ($expedition->trueVolume) if ($expedition->trueVolume)
{ {
@ -767,17 +838,23 @@ else
print "</td>\n"; print "</td>\n";
print '</tr>'; print '</tr>';
// Taille // Width
print '<tr><td>'.$langs->trans("Size").'</td>'; print '<tr><td>'.$html->editfieldkey("Width",'trueWidth',$expedition->trueWidth,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print '<td colspan="3">'; print $html->editfieldval("Width",'trueWidth',$expedition->trueWidth,'id',$expedition->id,$user->rights->expedition->creer);
if ($expedition->trueWidth || $expedition->trueHeight || $expedition->trueDepth) print $expedition->trueWidth?measuring_units_string($expedition->width_units,"size"):'';
{ print '</td></tr>';
// If sending size defined
print $expedition->trueSize.' '.measuring_units_string($expedition->size_units,"size"); // Height
} print '<tr><td>'.$html->editfieldkey("Height",'trueHeight',$expedition->trueHeight,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">';
else print '&nbsp;'; print $html->editfieldval("Height",'trueHeight',$expedition->trueHeight,'id',$expedition->id,$user->rights->expedition->creer);
print "</td>\n"; print $expedition->trueHeight?measuring_units_string($expedition->height_units,"size"):'';
print '</tr>'; print '</td></tr>';
// Depth
print '<tr><td>'.$html->editfieldkey("Depth",'trueDepth',$expedition->trueDepth,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print $html->editfieldval("Depth",'trueDepth',$expedition->trueDepth,'id',$expedition->id,$user->rights->expedition->creer);
print $expedition->trueDepth?measuring_units_string($expedition->depth_units,"size"):'';
print '</td></tr>';
// Status // Status
print '<tr><td>'.$langs->trans("Status").'</td>'; print '<tr><td>'.$langs->trans("Status").'</td>';
@ -785,26 +862,47 @@ else
print '</tr>'; print '</tr>';
// Sending method // Sending method
print '<tr><td>'.$langs->trans("SendingMethod").'</td>'; print '<tr><td height="10">';
print '<td colspan="3">'; print '<table class="nobordernopadding" width="100%"><tr><td>';
if ($expedition->expedition_method_id > 0) print $langs->trans('SendingMethod');
print '</td>';
if ($_GET['action'] != 'editexpedition_method_id') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editexpedition_method_id&amp;id='.$expedition->id.'">'.img_edit($langs->trans('SetSendingMethod'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editexpedition_method_id')
{ {
// Get code using getLabelFromKey print '<form name="setexpedition_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$expedition->id.'" method="post">';
$code=$langs->getLabelFromKey($db,$expedition->expedition_method_id,'expedition_methode','rowid','code'); print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print $langs->trans("SendingMethod".strtoupper($code)); print '<input type="hidden" name="action" value="setexpedition_method_id">';
$expedition->fetch_delivery_methods();
$html->select_array("expedition_method_id",$expedition->meths,$expedition->expedition_method_id,1,0,0,0,"",1);
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
}
else
{
if ($expedition->expedition_method_id > 0)
{
// Get code using getLabelFromKey
$code=$langs->getLabelFromKey($db,$expedition->expedition_method_id,'expedition_methode','rowid','code');
print $langs->trans("SendingMethod".strtoupper($code));
}
} }
else print '&nbsp;';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Tracking Number // Tracking Number
print '<tr><td>'.$langs->trans("TrackingNumber").'</td>'; print '<tr><td>'.$html->editfieldkey("TrackingNumber",'trackingnumber',$expedition->tracking_number,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print '<td>'.$expedition->tracking_number.'</td>'; print $html->editfieldval("TrackingNumber",'trackingnumber',$expedition->tracking_number,'id',$expedition->id,$user->rights->expedition->creer);
print '</td></tr>';
if ($expedition->tracking_url) if ($expedition->tracking_url)
{ {
print '<td colspan="2">'.$expedition->tracking_url."</td>\n"; print '<tr><td>'.$html->editfieldkey("TrackingUrl",'trackingurl',$expedition->tracking_url,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print $html->editfieldval("TrackingUrl",'trackingurl',$expedition->tracking_url,'id',$expedition->id,$user->rights->expedition->creer);
print '</td></tr>';
} }
print '</tr>';
print "</table>\n"; print "</table>\n";
@ -824,8 +922,9 @@ else
print '<td align="center">'.$langs->trans("QtyShipped").'</td>'; print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
} }
print '<td align="center">'.$langs->trans("Weight").'</td>'; print '<td align="center">'.$langs->trans("CalculatedWeight").'</td>';
print '<td align="center">'.$langs->trans("Volume").'</td>'; print '<td align="center">'.$langs->trans("CalculatedVolume").'</td>';
//print '<td align="center">'.$langs->trans("Size").'</td>';
if ($conf->stock->enabled) if ($conf->stock->enabled)
{ {
@ -839,6 +938,7 @@ else
{ {
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
// Predefined product or service
if ($lignes[$i]->fk_product > 0) if ($lignes[$i]->fk_product > 0)
{ {
print '<td>'; print '<td>';
@ -874,18 +974,32 @@ else
// Qte a expedier ou expedier // Qte a expedier ou expedier
print '<td align="center">'.$lignes[$i]->qty_shipped.'</td>'; print '<td align="center">'.$lignes[$i]->qty_shipped.'</td>';
// Poids // Weight
print '<td align="center">'.$lignes[$i]->weight*$lignes[$i]->qty_shipped.' '.measuring_units_string($lignes[$i]->weight_units,"weight").'</td>'; print '<td align="center">';
if ($lignes[$i]->fk_product_type == 0) print $lignes[$i]->weight*$lignes[$i]->qty_shipped.' '.measuring_units_string($lignes[$i]->weight_units,"weight");
else print '&nbsp;';
print '</td>';
// Volume // Volume
print '<td align="center">'.$lignes[$i]->volume*$lignes[$i]->qty_shipped.' '.measuring_units_string($lignes[$i]->volume_units,"volume").'</td>'; print '<td align="center">';
if ($lignes[$i]->fk_product_type == 0) print $lignes[$i]->volume*$lignes[$i]->qty_shipped.' '.measuring_units_string($lignes[$i]->volume_units,"volume");
else print '&nbsp;';
print '</td>';
// Size
//print '<td align="center">'.$lignes[$i]->volume*$lignes[$i]->qty_shipped.' '.measuring_units_string($lignes[$i]->volume_units,"volume").'</td>';
// Entrepot source // Entrepot source
if ($conf->stock->enabled) if ($conf->stock->enabled)
{ {
$entrepot = new Entrepot($db); print '<td align="left">';
$entrepot->fetch($lignes[$i]->entrepot_id); if ($lignes[$i]->entrepot_id > 0)
print '<td align="left">'.$entrepot->getNomUrl(1).'</td>'; {
$entrepot = new Entrepot($db);
$entrepot->fetch($lignes[$i]->entrepot_id);
print $entrepot->getNomUrl(1);
}
print '</td>';
} }
@ -908,6 +1022,11 @@ else
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
/*if ($expedition->statut > 0 && $user->rights->expedition->valider)
{
print '<a class="butAction" href="fiche.php?id='.$expedition->id.'&amp;action=open">'.$langs->trans("Modify").'</a>';
}*/
if ($expedition->statut == 0 && $num_prod > 0) if ($expedition->statut == 0 && $num_prod > 0)
{ {
if ($user->rights->expedition->valider) if ($user->rights->expedition->valider)