Fix: uniformize code

This commit is contained in:
Regis Houssin 2011-05-26 15:33:33 +00:00
parent 621f42374c
commit 2b5f7aac4e
2 changed files with 173 additions and 156 deletions

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-2010 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be> * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
@ -46,6 +46,8 @@ class Expedition extends CommonObject
var $id; var $id;
var $socid; var $socid;
var $ref_customer; var $ref_customer;
var $ref_ext;
var $ref_int;
var $brouillon; var $brouillon;
var $entrepot_id; var $entrepot_id;
var $modelpdf; var $modelpdf;
@ -155,8 +157,9 @@ class Expedition extends CommonObject
$sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition (";
$sql.= "ref"; $sql.= "ref";
$sql.= ", ref_customer";
$sql.= ", entity"; $sql.= ", entity";
$sql.= ", ref_customer";
$sql.= ", ref_int";
$sql.= ", date_creation"; $sql.= ", date_creation";
$sql.= ", fk_user_author"; $sql.= ", fk_user_author";
$sql.= ", date_expedition"; $sql.= ", date_expedition";
@ -173,8 +176,9 @@ class Expedition extends CommonObject
$sql.= ", size_units"; $sql.= ", size_units";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= "'(PROV)'"; $sql.= "'(PROV)'";
$sql.= ", '".$this->ref_customer."'";
$sql.= ", ".$conf->entity; $sql.= ", ".$conf->entity;
$sql.= ", ".($this->ref_customer?"'".$this->ref_customer."'":"null");
$sql.= ", ".($this->ref_int?"'".$this->ref_int."'":"null");
$sql.= ", '".$this->db->idate(gmmktime())."'"; $sql.= ", '".$this->db->idate(gmmktime())."'";
$sql.= ", ".$user->id; $sql.= ", ".$user->id;
$sql.= ", ".($this->date_expedition>0?"'".$this->db->idate($this->date_expedition)."'":"null"); $sql.= ", ".($this->date_expedition>0?"'".$this->db->idate($this->date_expedition)."'":"null");
@ -288,25 +292,32 @@ class Expedition extends CommonObject
} }
/** /**
* \brief Lit une expedition * Get object and lines from database
* \param id Id of object * @param id Id of object to load
* \param ref Ref of object * @param ref Ref of object
* @param ref_ext External reference of object
* @param ref_int Internal reference of other object
* @return int >0 if OK, <0 if KO
*/ */
function fetch($id,$ref='') function fetch($id, $ref='', $ref_ext='', $ref_int='')
{ {
global $conf; global $conf;
if (empty($id) && empty($ref)) return -1; // Check parameters
if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1;
$sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_customer, e.fk_user_author, e.fk_statut"; $sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_customer, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut";
$sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height"; $sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
$sql.= ", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery"; $sql.= ", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
$sql.= ", e.fk_expedition_methode, e.tracking_number"; $sql.= ", e.fk_expedition_methode, e.tracking_number";
$sql.= ", el.fk_source as origin_id, el.sourcetype as origin"; $sql.= ", el.fk_source as origin_id, el.sourcetype as origin";
$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e"; $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->element."'"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->element."'";
if ($id) $sql.= " WHERE e.rowid = ".$id; $sql.= " WHERE e.entity = ".$conf->entity;
if ($ref) $sql.= " WHERE e.ref = '".$ref."'"; if ($id) $sql.= " AND e.rowid=".$id;
if ($ref) $sql.= " AND e.ref='".$this->db->escape($ref)."'";
if ($ref_ext) $sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
if ($ref_int) $sql.= " AND e.ref_int='".$this->db->escape($ref_int)."'";
dol_syslog("Expedition::fetch sql=".$sql); dol_syslog("Expedition::fetch sql=".$sql);
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
@ -320,6 +331,8 @@ class Expedition extends CommonObject
$this->ref = $obj->ref; $this->ref = $obj->ref;
$this->socid = $obj->socid; $this->socid = $obj->socid;
$this->ref_customer = $obj->ref_customer; $this->ref_customer = $obj->ref_customer;
$this->ref_ext = $obj->ref_ext;
$this->ref_int = $obj->ref_int;
$this->statut = $obj->fk_statut; $this->statut = $obj->fk_statut;
$this->user_author_id = $obj->fk_user_author; $this->user_author_id = $obj->fk_user_author;
$this->date_creation = $this->db->jdate($obj->date_creation); $this->date_creation = $this->db->jdate($obj->date_creation);
@ -863,23 +876,25 @@ class Expedition extends CommonObject
* \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul * \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
* \return string Chaine avec URL * \return string Chaine avec URL
*/ */
function getNomUrl($withpicto=0) function getNomUrl($withpicto=0,$option=0,$max=0,$short=0)
{ {
global $langs; global $langs;
$result=''; $result='';
$urlOption='';
$url = DOL_URL_ROOT.'/expedition/fiche.php?id='.$this->id;
$lien = '<a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$this->id.'">'; if ($short) return $url;
$lienfin='</a>';
$linkstart = '<a href="'.$url.'">';
$linkend='</a>';
$picto='sending'; $picto='sending';
$label=$langs->trans("ShowSending").': '.$this->ref; $label=$langs->trans("ShowSending").': '.$this->ref;
if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); if ($withpicto) $result.=($linkstart.img_object($label,$picto).$linkend);
if ($withpicto && $withpicto != 2) $result.=' '; if ($withpicto && $withpicto != 2) $result.=' ';
$result.=$lien.$this->ref.$lienfin; $result.=$linkstart.$this->ref.$linkend;
return $result; return $result;
} }
@ -909,13 +924,18 @@ class Expedition extends CommonObject
} }
if ($mode==1) if ($mode==1)
{ {
if ($statut==0) return $langs->trans($this->statuts[$statut]); if ($statut==0) return $langs->trans('StatusSendingDraftShort');
if ($statut==1) return $langs->trans($this->statuts[$statut]); if ($statut==1) return $langs->trans('StatusSendingValidatedShort');
}
if ($mode == 3)
{
if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4');
} }
if ($mode == 4) if ($mode == 4)
{ {
if ($statut==0) return img_picto($this->statuts[$statut],'statut0').' '.$langs->trans($this->statuts[$statut]); if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
if ($statut==1) return img_picto($this->statuts[$statut],'statut4').' '.$langs->trans($this->statuts[$statut]); if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
} }
if ($mode == 5) if ($mode == 5)
{ {

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2010 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-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -49,57 +49,58 @@ $langs->load('stocks');
$langs->load('other'); $langs->load('other');
$langs->load('propal'); $langs->load('propal');
$origin = GETPOST("origin")?GETPOST("origin"):'expedition'; // Example: commande, 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;
$action = GETPOST("action");
$origin = GETPOST("origin")?GETPOST("origin"):'expedition'; // Example: commande, propal
$origin_id = GETPOST("id")?GETPOST("id"):'';
if (empty($origin_id)) $origin_id = GETPOST("origin_id"); // Id of order or propal
if (empty($origin_id)) $origin_id = GETPOST("object_id"); // Id of order or propal
$id = $origin_id;
// Security check // Security check
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$result=restrictedArea($user,$origin,$origin_id,''); $result=restrictedArea($user,$origin,$origin_id);
$object = new Expedition($db);
/* /*
* Actions * Actions
*/ */
if ($_POST["action"] == 'add') if ($action == 'add')
{ {
$db->begin(); $db->begin();
// Creation de l'objet expedition $object->note = $_POST["note"];
$expedition = new Expedition($db); $object->origin = $origin;
$object->origin_id = $origin_id;
$expedition->note = $_POST["note"]; $object->weight = $_POST["weight"]==""?"NULL":$_POST["weight"];
$expedition->origin = $origin; $object->sizeH = $_POST["sizeH"]==""?"NULL":$_POST["sizeH"];
$expedition->origin_id = $origin_id; $object->sizeW = $_POST["sizeW"]==""?"NULL":$_POST["sizeW"];
$expedition->weight = $_POST["weight"]==""?"NULL":$_POST["weight"]; $object->sizeS = $_POST["sizeS"]==""?"NULL":$_POST["sizeS"];
$expedition->sizeH = $_POST["sizeH"]==""?"NULL":$_POST["sizeH"]; $object->size_units = $_POST["size_units"];
$expedition->sizeW = $_POST["sizeW"]==""?"NULL":$_POST["sizeW"]; $object->weight_units = $_POST["weight_units"];
$expedition->sizeS = $_POST["sizeS"]==""?"NULL":$_POST["sizeS"];
$expedition->size_units = $_POST["size_units"];
$expedition->weight_units = $_POST["weight_units"];
$date_delivery = dol_mktime($_POST["date_deliveryhour"], $_POST["date_deliverymin"], 0, $_POST["date_deliverymonth"], $_POST["date_deliveryday"], $_POST["date_deliveryyear"]); $date_delivery = dol_mktime($_POST["date_deliveryhour"], $_POST["date_deliverymin"], 0, $_POST["date_deliverymonth"], $_POST["date_deliveryday"], $_POST["date_deliveryyear"]);
// On va boucler 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 info diverses + qte a livrer // avec info diverses + qte a livrer
$classname = ucfirst($expedition->origin); $classname = ucfirst($object->origin);
$object = new $classname($db); $objectsrc = new $classname($db);
$object->fetch($expedition->origin_id); $objectsrc->fetch($object->origin_id);
//$object->fetch_lines(); //$object->fetch_lines();
$expedition->socid = $object->socid; $object->socid = $objectsrc->socid;
$expedition->ref_customer = $object->ref_client; $object->ref_customer = $objectsrc->ref_client;
$expedition->date_delivery = $date_delivery; // Date delivery planed $object->date_delivery = $date_delivery; // Date delivery planed
$expedition->fk_delivery_address = $object->fk_delivery_address; $object->fk_delivery_address = $objectsrc->fk_delivery_address;
$expedition->expedition_method_id = $_POST["expedition_method_id"]; $object->expedition_method_id = $_POST["expedition_method_id"];
$expedition->tracking_number = $_POST["tracking_number"]; $object->tracking_number = $_POST["tracking_number"];
$object->ref_int = $_POST["ref_int"];
//var_dump($_POST);exit; //var_dump($_POST);exit;
for ($i = 0 ; $i < sizeof($object->lines) ; $i++) for ($i = 0 ; $i < sizeof($objectsrc->lines) ; $i++)
{ {
$qty = "qtyl".$i; $qty = "qtyl".$i;
if ($_POST[$qty] > 0) if ($_POST[$qty] > 0)
@ -108,21 +109,21 @@ if ($_POST["action"] == 'add')
$idl = "idl".$i; $idl = "idl".$i;
$entrepot_id = isset($_POST[$ent])?$_POST[$ent]:$_POST["entrepot_id"]; $entrepot_id = isset($_POST[$ent])?$_POST[$ent]:$_POST["entrepot_id"];
$expedition->addline($entrepot_id,$_POST[$idl],$_POST[$qty]); $object->addline($entrepot_id,$_POST[$idl],$_POST[$qty]);
} }
} }
$ret=$expedition->create($user); $ret=$object->create($user);
if ($ret > 0) if ($ret > 0)
{ {
$db->commit(); $db->commit();
Header("Location: fiche.php?id=".$expedition->id); Header("Location: fiche.php?id=".$object->id);
exit; exit;
} }
else else
{ {
$db->rollback(); $db->rollback();
$mesg='<div class="error">'.$expedition->error.'</div>'; $mesg='<div class="error">'.$object->error.'</div>';
$_GET["commande_id"]=$_POST["commande_id"]; $_GET["commande_id"]=$_POST["commande_id"];
$_GET["action"]='create'; $_GET["action"]='create';
} }
@ -131,11 +132,10 @@ if ($_POST["action"] == 'add')
/* /*
* Build a receiving receipt * Build a receiving receipt
*/ */
if ($_GET["action"] == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer) if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)
{ {
$expedition = new Expedition($db); $object->fetch($_GET["id"]);
$expedition->fetch($_GET["id"]); $result = $object->create_delivery($user);
$result = $expedition->create_delivery($user);
if ($result > 0) if ($result > 0)
{ {
Header("Location: ".DOL_URL_ROOT.'/livraison/fiche.php?id='.$result); Header("Location: ".DOL_URL_ROOT.'/livraison/fiche.php?id='.$result);
@ -143,29 +143,28 @@ if ($_GET["action"] == 'create_delivery' && $conf->livraison_bon->enabled && $us
} }
else else
{ {
$mesg=$expedition->error; $mesg=$object->error;
} }
} }
if ($_REQUEST["action"] == 'confirm_valid' && $_REQUEST["confirm"] == 'yes' && $user->rights->expedition->valider) if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->expedition->valider)
{ {
$expedition = new Expedition($db); $object->fetch($_GET["id"]);
$expedition->fetch($_GET["id"]); $object->fetch_thirdparty();
$expedition->fetch_thirdparty();
$result = $expedition->valid($user); $result = $object->valid($user);
// Define output language // Define output language
$outputlangs = $langs; $outputlangs = $langs;
$newlang=''; $newlang='';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$expedition->client->default_lang; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (! empty($newlang)) if (! empty($newlang))
{ {
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
} }
$result=expedition_pdf_create($db,$expedition,$expedition->modelpdf,$outputlangs); $result=expedition_pdf_create($db,$object,$object->modelpdf,$outputlangs);
if ($result <= 0) if ($result <= 0)
{ {
dol_print_error($db,$result); dol_print_error($db,$result);
@ -173,13 +172,12 @@ if ($_REQUEST["action"] == 'confirm_valid' && $_REQUEST["confirm"] == 'yes' && $
} }
} }
if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes') if ($action == 'confirm_delete' && $confirm == 'yes')
{ {
if ($user->rights->expedition->supprimer ) if ($user->rights->expedition->supprimer )
{ {
$expedition = new Expedition($db); $object->fetch($_GET["id"]);
$expedition->fetch($_GET["id"]); $result = $object->delete();
$result = $expedition->delete();
if ($result > 0) if ($result > 0)
{ {
Header("Location: ".DOL_URL_ROOT.'/expedition/index.php'); Header("Location: ".DOL_URL_ROOT.'/expedition/index.php');
@ -187,21 +185,20 @@ if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes')
} }
else else
{ {
$mesg = $expedition->error; $mesg = $object->error;
} }
} }
} }
if ($_REQUEST["action"] == 'open') if ($action == 'open')
{ {
if ($user->rights->expedition->valider ) if ($user->rights->expedition->valider )
{ {
$expedition = new Expedition($db); $object->fetch($_GET["id"]);
$expedition->fetch($_GET["id"]); $result = $object->setStatut(0);
$result = $expedition->setStatut(0);
if ($result < 0) if ($result < 0)
{ {
$mesg = $expedition->error; $mesg = $object->error;
} }
} }
} }
@ -350,6 +347,7 @@ if ($_GET["action"] == 'create')
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.'">';
print '<input type="hidden" name="origin_id" value="'.$object->id.'">'; print '<input type="hidden" name="origin_id" value="'.$object->id.'">';
print '<input type="hidden" name="ref_int" value="'.$object->ref_int.'">';
if ($_GET["entrepot_id"]) if ($_GET["entrepot_id"])
{ {
print '<input type="hidden" name="entrepot_id" value="'.$_GET["entrepot_id"].'">'; print '<input type="hidden" name="entrepot_id" value="'.$_GET["entrepot_id"].'">';
@ -646,39 +644,38 @@ else
/* */ /* */
/* *************************************************************************** */ /* *************************************************************************** */
{ {
if (! empty($_REQUEST["id"]) || ! empty($_REQUEST["ref"])) if (! empty($id) || ! empty($ref))
{ {
$expedition = new Expedition($db); $result = $object->fetch($id,$ref);
$result = $expedition->fetch($_REQUEST["id"],$_REQUEST["ref"]);
if ($result < 0) if ($result < 0)
{ {
dol_print_error($db,$expedition->error); dol_print_error($db,$object->error);
exit -1; exit -1;
} }
$lines = $expedition->lines; $lines = $object->lines;
$num_prod = sizeof($lines); $num_prod = sizeof($lines);
if ($expedition->id > 0) if ($object->id > 0)
{ {
if ($mesg) if ($mesg)
{ {
print '<div class="error">'.$mesg.'</div>'; print '<div class="error">'.$mesg.'</div>';
} }
if (!empty($expedition->origin)) if (!empty($object->origin))
{ {
$typeobject = $expedition->origin; $typeobject = $object->origin;
$origin = $expedition->origin; $origin = $object->origin;
$expedition->fetch_origin(); $object->fetch_origin();
} }
$soc = new Societe($db); $soc = new Societe($db);
$soc->fetch($expedition->socid); $soc->fetch($object->socid);
// delivery link // delivery link
$expedition->fetchObjectLinked($expedition->id,$expedition->element,-1,-1); $object->fetchObjectLinked($object->id,$object->element,-1,-1);
$head=shipping_prepare_head($expedition); $head=shipping_prepare_head($object);
dol_fiche_head($head, 'shipping', $langs->trans("Sending"), 0, 'sending'); dol_fiche_head($head, 'shipping', $langs->trans("Sending"), 0, 'sending');
if ($mesg) print $mesg; if ($mesg) print $mesg;
@ -686,35 +683,35 @@ else
/* /*
* Confirmation de la suppression * Confirmation de la suppression
*/ */
if ($_GET["action"] == 'delete') if ($action == 'delete')
{ {
$ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('DeleteSending'),$langs->trans("ConfirmDeleteSending",$expedition->ref),'confirm_delete','',0,1); $ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteSending'),$langs->trans("ConfirmDeleteSending",$object->ref),'confirm_delete','',0,1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
/* /*
* Confirmation de la validation * Confirmation de la validation
*/ */
if ($_GET["action"] == 'valid') if ($action == 'valid')
{ {
$objectref = substr($expedition->ref, 1, 4); $objectref = substr($object->ref, 1, 4);
if ($objectref == 'PROV') if ($objectref == 'PROV')
{ {
$numref = $expedition->getNextNumRef($soc); $numref = $object->getNextNumRef($soc);
} }
else else
{ {
$numref = $expedition->ref; $numref = $object->ref;
} }
$ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('ValidateSending'),$langs->trans("ConfirmValidateSending",$numref),'confirm_valid','',0,1); $ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateSending'),$langs->trans("ConfirmValidateSending",$numref),'confirm_valid','',0,1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
/* /*
* Confirmation de l'annulation * Confirmation de l'annulation
*/ */
if ($_GET["action"] == 'annuler') if ($action == 'annuler')
{ {
$ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('CancelSending'),$langs->trans("ConfirmCancelSending",$expedition->ref),'confirm_cancel','',0,1); $ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('CancelSending'),$langs->trans("ConfirmCancelSending",$object->ref),'confirm_cancel','',0,1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
@ -762,7 +759,7 @@ 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">'; print '<td colspan="3">';
print $html->showrefnav($expedition,'ref','',1,'ref','ref'); print $html->showrefnav($object,'ref','',1,'ref','ref');
print '</td></tr>'; print '</td></tr>';
// Customer // Customer
@ -771,37 +768,37 @@ else
print "</tr>"; print "</tr>";
// Linked documents // Linked documents
if ($typeobject == 'commande' && $expedition->$typeobject->id && $conf->commande->enabled) if ($typeobject == 'commande' && $object->$typeobject->id && $conf->commande->enabled)
{ {
print '<tr><td>'; print '<tr><td>';
$object=new Commande($db); $objectsrc=new Commande($db);
$object->fetch($expedition->$typeobject->id); $objectsrc->fetch($object->$typeobject->id);
print $langs->trans("RefOrder").'</td>'; print $langs->trans("RefOrder").'</td>';
print '<td colspan="3">'; print '<td colspan="3">';
print $object->getNomUrl(1,'commande'); print $objectsrc->getNomUrl(1,'commande');
print "</td>\n"; print "</td>\n";
print '</tr>'; print '</tr>';
} }
if ($typeobject == 'propal' && $expedition->$typeobject->id && $conf->propal->enabled) if ($typeobject == 'propal' && $object->$typeobject->id && $conf->propal->enabled)
{ {
print '<tr><td>'; print '<tr><td>';
$object=new Propal($db); $objectsrc=new Propal($db);
$object->fetch($expedition->$typeobject->id); $objectsrc->fetch($object->$typeobject->id);
print $langs->trans("RefProposal").'</td>'; print $langs->trans("RefProposal").'</td>';
print '<td colspan="3">'; print '<td colspan="3">';
print $object->getNomUrl(1,'expedition'); print $objectsrc->getNomUrl(1,'expedition');
print "</td>\n"; print "</td>\n";
print '</tr>'; print '</tr>';
} }
// Ref customer // Ref customer
print '<tr><td>'.$langs->trans("RefCustomer").'</td>'; print '<tr><td>'.$langs->trans("RefCustomer").'</td>';
print '<td colspan="3">'.$expedition->ref_customer."</a></td>\n"; print '<td colspan="3">'.$object->ref_customer."</a></td>\n";
print '</tr>'; print '</tr>';
// Date creation // Date creation
print '<tr><td>'.$langs->trans("DateCreation").'</td>'; print '<tr><td>'.$langs->trans("DateCreation").'</td>';
print '<td colspan="3">'.dol_print_date($expedition->date_creation,"daytext")."</td>\n"; print '<td colspan="3">'.dol_print_date($object->date_creation,"daytext")."</td>\n";
print '</tr>'; print '</tr>';
// Delivery date planed // Delivery date planed
@ -810,21 +807,21 @@ else
print $langs->trans('DateDeliveryPlanned'); print $langs->trans('DateDeliveryPlanned');
print '</td>'; 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>'; if ($_GET['action'] != 'editdate_livraison') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
print '</tr></table>'; print '</tr></table>';
print '</td><td colspan="2">'; print '</td><td colspan="2">';
if ($_GET['action'] == 'editdate_livraison') if ($_GET['action'] == 'editdate_livraison')
{ {
print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$expedition->id.'" method="post">'; print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" 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="setdate_livraison">'; print '<input type="hidden" name="action" value="setdate_livraison">';
$html->select_date($expedition->date_delivery?$expedition->date_delivery:-1,'liv_',1,1,'',"setdate_livraison"); $html->select_date($object->date_delivery?$object->date_delivery:-1,'liv_',1,1,'',"setdate_livraison");
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">'; print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>'; print '</form>';
} }
else else
{ {
print $expedition->date_delivery ? dol_print_date($expedition->date_delivery,'dayhourtext') : '&nbsp;'; print $object->date_delivery ? dol_print_date($object->date_delivery,'dayhourtext') : '&nbsp;';
} }
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -835,26 +832,26 @@ else
{ {
print '<tr><td>'.$langs->trans('DeliveryAddress').'</td>'; print '<tr><td>'.$langs->trans('DeliveryAddress').'</td>';
print '<td colspan="3">'; print '<td colspan="3">';
if (!empty($expedition->fk_delivery_address)) if (!empty($object->fk_delivery_address))
{ {
$html->form_address($_SERVER['PHP_SELF'].'?id='.$expedition->id,$expedition->fk_delivery_address,$expedition->deliveryaddress->socid,'none','shipment',$expedition->id); $html->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->deliveryaddress->socid,'none','shipment',$object->id);
} }
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
// Weight // Weight
print '<tr><td>'.$html->editfieldkey("Weight",'trueWeight',$expedition->trueWeight,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">'; print '<tr><td>'.$html->editfieldkey("Weight",'trueWeight',$object->trueWeight,'id',$object->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print $html->editfieldval("Weight",'trueWeight',$expedition->trueWeight,'id',$expedition->id,$user->rights->expedition->creer); print $html->editfieldval("Weight",'trueWeight',$object->trueWeight,'id',$object->id,$user->rights->expedition->creer);
print $expedition->weight_units?measuring_units_string($expedition->weight_units,"weight"):''; print $object->weight_units?measuring_units_string($object->weight_units,"weight"):'';
print '</td></tr>'; print '</td></tr>';
// Volume Total // Volume Total
print '<tr><td>'.$langs->trans("Volume").'</td>'; print '<tr><td>'.$langs->trans("Volume").'</td>';
print '<td colspan="3">'; print '<td colspan="3">';
if ($expedition->trueVolume) if ($object->trueVolume)
{ {
// If sending volume defined // If sending volume defined
print $expedition->trueVolume.' '.measuring_units_string($expedition->volumeUnit,"volume"); print $object->trueVolume.' '.measuring_units_string($object->volumeUnit,"volume");
} }
else else
{ {
@ -871,26 +868,26 @@ else
print '</tr>'; print '</tr>';
// Width // Width
print '<tr><td>'.$html->editfieldkey("Width",'trueWidth',$expedition->trueWidth,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">'; print '<tr><td>'.$html->editfieldkey("Width",'trueWidth',$object->trueWidth,'id',$object->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print $html->editfieldval("Width",'trueWidth',$expedition->trueWidth,'id',$expedition->id,$user->rights->expedition->creer); print $html->editfieldval("Width",'trueWidth',$object->trueWidth,'id',$object->id,$user->rights->expedition->creer);
print $expedition->trueWidth?measuring_units_string($expedition->width_units,"size"):''; print $object->trueWidth?measuring_units_string($object->width_units,"size"):'';
print '</td></tr>'; print '</td></tr>';
// Height // Height
print '<tr><td>'.$html->editfieldkey("Height",'trueHeight',$expedition->trueHeight,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">'; print '<tr><td>'.$html->editfieldkey("Height",'trueHeight',$object->trueHeight,'id',$object->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print $html->editfieldval("Height",'trueHeight',$expedition->trueHeight,'id',$expedition->id,$user->rights->expedition->creer); print $html->editfieldval("Height",'trueHeight',$object->trueHeight,'id',$object->id,$user->rights->expedition->creer);
print $expedition->trueHeight?measuring_units_string($expedition->height_units,"size"):''; print $object->trueHeight?measuring_units_string($object->height_units,"size"):'';
print '</td></tr>'; print '</td></tr>';
// Depth // Depth
print '<tr><td>'.$html->editfieldkey("Depth",'trueDepth',$expedition->trueDepth,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">'; print '<tr><td>'.$html->editfieldkey("Depth",'trueDepth',$object->trueDepth,'id',$object->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print $html->editfieldval("Depth",'trueDepth',$expedition->trueDepth,'id',$expedition->id,$user->rights->expedition->creer); print $html->editfieldval("Depth",'trueDepth',$object->trueDepth,'id',$object->id,$user->rights->expedition->creer);
print $expedition->trueDepth?measuring_units_string($expedition->depth_units,"size"):''; print $object->trueDepth?measuring_units_string($object->depth_units,"size"):'';
print '</td></tr>'; print '</td></tr>';
// Status // Status
print '<tr><td>'.$langs->trans("Status").'</td>'; print '<tr><td>'.$langs->trans("Status").'</td>';
print '<td colspan="3">'.$expedition->getLibStatut(4)."</td>\n"; print '<td colspan="3">'.$object->getLibStatut(4)."</td>\n";
print '</tr>'; print '</tr>';
// Sending method // Sending method
@ -899,25 +896,25 @@ else
print $langs->trans('SendingMethod'); print $langs->trans('SendingMethod');
print '</td>'; 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>'; if ($_GET['action'] != 'editexpedition_method_id') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editexpedition_method_id&amp;id='.$object->id.'">'.img_edit($langs->trans('SetSendingMethod'),1).'</a></td>';
print '</tr></table>'; print '</tr></table>';
print '</td><td colspan="2">'; print '</td><td colspan="2">';
if ($_GET['action'] == 'editexpedition_method_id') if ($_GET['action'] == 'editexpedition_method_id')
{ {
print '<form name="setexpedition_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$expedition->id.'" method="post">'; print '<form name="setexpedition_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" 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="setexpedition_method_id">'; print '<input type="hidden" name="action" value="setexpedition_method_id">';
$expedition->fetch_delivery_methods(); $object->fetch_delivery_methods();
print $html->selectarray("expedition_method_id",$expedition->meths,$expedition->expedition_method_id,1,0,0,"",1); print $html->selectarray("expedition_method_id",$object->meths,$object->expedition_method_id,1,0,0,"",1);
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">'; print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>'; print '</form>';
} }
else else
{ {
if ($expedition->expedition_method_id > 0) if ($object->expedition_method_id > 0)
{ {
// Get code using getLabelFromKey // Get code using getLabelFromKey
$code=$langs->getLabelFromKey($db,$expedition->expedition_method_id,'c_shipment_mode','rowid','code'); $code=$langs->getLabelFromKey($db,$object->expedition_method_id,'c_shipment_mode','rowid','code');
print $langs->trans("SendingMethod".strtoupper($code)); print $langs->trans("SendingMethod".strtoupper($code));
} }
} }
@ -925,9 +922,9 @@ else
print '</tr>'; print '</tr>';
// Tracking Number // Tracking Number
$expedition->GetUrlTrackingStatus($expedition->tracking_number); $object->GetUrlTrackingStatus($object->tracking_number);
print '<tr><td>'.$html->editfieldkey("TrackingNumber",'trackingnumber',$expedition->tracking_number,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">'; print '<tr><td>'.$html->editfieldkey("TrackingNumber",'trackingnumber',$object->tracking_number,'id',$object->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print $html->editfieldval("TrackingNumber",'trackingnumber',$expedition->tracking_url,'id',$expedition->id,$user->rights->expedition->creer,'string',$expedition->tracking_number); print $html->editfieldval("TrackingNumber",'trackingnumber',$object->tracking_url,'id',$object->id,$user->rights->expedition->creer,'string',$object->tracking_number);
print '</td></tr>'; print '</td></tr>';
print "</table>\n"; print "</table>\n";
@ -939,7 +936,7 @@ else
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Products").'</td>'; print '<td>'.$langs->trans("Products").'</td>';
print '<td align="center">'.$langs->trans("QtyOrdered").'</td>'; print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
if ($expedition->fk_statut <= 1) if ($object->fk_statut <= 1)
{ {
print '<td align="center">'.$langs->trans("QtyToShip").'</td>'; print '<td align="center">'.$langs->trans("QtyToShip").'</td>';
} }
@ -1048,16 +1045,16 @@ else
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
/*if ($expedition->statut > 0 && $user->rights->expedition->valider) /*if ($object->statut > 0 && $user->rights->expedition->valider)
{ {
print '<a class="butAction" href="fiche.php?id='.$expedition->id.'&amp;action=open">'.$langs->trans("Modify").'</a>'; print '<a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=open">'.$langs->trans("Modify").'</a>';
}*/ }*/
if ($expedition->statut == 0 && $num_prod > 0) if ($object->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='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
} }
else else
{ {
@ -1065,14 +1062,14 @@ else
} }
} }
if ($conf->livraison_bon->enabled && $expedition->statut == 1 && $user->rights->expedition->livraison->creer && empty($expedition->linkedObjectsIds)) if ($conf->livraison_bon->enabled && $object->statut == 1 && $user->rights->expedition->livraison->creer && empty($object->linkedObjectsIds))
{ {
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='.$object->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='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
} }
print '</div>'; print '</div>';
@ -1087,17 +1084,17 @@ else
*/ */
if ($conf->expedition_bon->enabled) if ($conf->expedition_bon->enabled)
{ {
$expeditionref = dol_sanitizeFileName($expedition->ref); $objectref = dol_sanitizeFileName($object->ref);
$filedir = $conf->expedition->dir_output . "/sending/" .$expeditionref; $filedir = $conf->expedition->dir_output . "/sending/" .$objectref;
$urlsource = $_SERVER["PHP_SELF"]."?id=".$expedition->id; $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
$genallowed=$user->rights->expedition->lire; $genallowed=$user->rights->expedition->lire;
$delallowed=$user->rights->expedition->supprimer; $delallowed=$user->rights->expedition->supprimer;
//$genallowed=1; //$genallowed=1;
//$delallowed=0; //$delallowed=0;
$somethingshown=$formfile->show_documents('expedition',$expeditionref,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf,1,0,0,28,0,'','','',$soc->default_lang); $somethingshown=$formfile->show_documents('expedition',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
if ($genallowed && ! $somethingshown) $somethingshown=1; if ($genallowed && ! $somethingshown) $somethingshown=1;
} }
@ -1107,11 +1104,11 @@ else
print '</td></tr></table>'; print '</td></tr></table>';
if (!empty($origin) && $expedition->$origin->id) if (!empty($origin) && $object->$origin->id)
{ {
print '<br>'; print '<br>';
//show_list_sending_receive($expedition->origin,$expedition->origin_id," AND e.rowid <> ".$expedition->id); //show_list_sending_receive($object->origin,$object->origin_id," AND e.rowid <> ".$object->id);
show_list_sending_receive($expedition->origin,$expedition->origin_id); show_list_sending_receive($object->origin,$object->origin_id);
} }
} }