Fix: A lot of fix in shipping module

This commit is contained in:
Laurent Destailleur 2010-05-17 14:13:03 +00:00
parent eeb8fb09ba
commit 3082e61164
3 changed files with 228 additions and 64 deletions

View File

@ -51,7 +51,8 @@ class Expedition extends CommonObject
var $origin;
var $origin_id;
var $lignes;
var $meths;
var $expedition_method_id;
var $statut;
var $trueWeight;
var $weight_units;
@ -136,9 +137,9 @@ class Expedition extends CommonObject
$sql.= ", ".($this->expedition_method_id>0?$this->expedition_method_id:"null");
$sql.= ", '".addslashes($this->tracking_number)."'";
$sql.= ", ".$this->weight;
$sql.= ", ".$this->sizeS;
$sql.= ", ".$this->sizeW;
$sql.= ", ".$this->sizeH;
$sql.= ", ".$this->sizeS; // TODO Should use this->trueDepth
$sql.= ", ".$this->sizeW; // TODO Should use this->trueWidth
$sql.= ", ".$this->sizeH; // TODO Should use this->trueHeight
$sql.= ", ".$this->weight_units;
$sql.= ", ".$this->size_units;
$sql.= ")";
@ -553,9 +554,114 @@ class Expedition extends CommonObject
}
}
/**
* Supprime la fiche
*
/**
* \brief Update database
* \param user User that modify
* \param notrigger 0=launch triggers after, 1=disable triggers
* \return int <0 if KO, >0 if OK
*/
function update($user=0, $notrigger=0)
{
global $conf, $langs;
$error=0;
// Clean parameters
if (isset($this->ref)) $this->ref=trim($this->ref);
if (isset($this->entity)) $this->entity=trim($this->entity);
if (isset($this->ref_customer)) $this->ref_customer=trim($this->ref_customer);
if (isset($this->socid)) $this->socid=trim($this->socid);
if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
if (isset($this->fk_user_valid)) $this->fk_user_valid=trim($this->fk_user_valid);
if (isset($this->fk_adresse_livraison)) $this->fk_adresse_livraison=trim($this->fk_adresse_livraison);
if (isset($this->expedition_method_id)) $this->expedition_method_id=trim($this->expedition_method_id);
if (isset($this->tracking_number)) $this->tracking_number=trim($this->tracking_number);
if (isset($this->statut)) $this->statut=trim($this->statut);
if (isset($this->trueDepth)) $this->trueDepth=trim($this->trueDepth);
if (isset($this->trueWidth)) $this->trueWidth=trim($this->trueWidth);
if (isset($this->trueHeight)) $this->trueHeight=trim($this->trueHeight);
if (isset($this->size_units)) $this->size_units=trim($this->size_units);
if (isset($this->weight_units)) $this->weight_units=trim($this->weight_units);
if (isset($this->trueWeight)) $this->weight=trim($this->trueWeight);
if (isset($this->note)) $this->note=trim($this->note);
if (isset($this->model_pdf)) $this->model_pdf=trim($this->model_pdf);
// Check parameters
// Put here code to add control on parameters values
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
$sql.= " tms=".(strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
$sql.= " ref=".(isset($this->ref)?"'".addslashes($this->ref)."'":"null").",";
$sql.= " ref_customer=".(isset($this->ref_customer)?"'".addslashes($this->ref_customer)."'":"null").",";
$sql.= " fk_soc=".(isset($this->socid)?$this->socid:"null").",";
$sql.= " date_creation=".(strlen($this->date_creation)!=0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').",";
$sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").",";
$sql.= " date_valid=".(strlen($this->date_valid)!=0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').",";
$sql.= " fk_user_valid=".(isset($this->fk_user_valid)?$this->fk_user_valid:"null").",";
$sql.= " date_expedition=".(strlen($this->date_expedition)!=0 ? "'".$this->db->idate($this->date_expedition)."'" : 'null').",";
$sql.= " date_delivery=".(strlen($this->date_delivery)!=0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
$sql.= " fk_adresse_livraison=".(isset($this->fk_adresse_livraison)?$this->fk_adresse_livraison:"null").",";
$sql.= " fk_expedition_methode=".(isset($this->expedition_method_id)?$this->expedition_method_id:"null").",";
$sql.= " tracking_number=".(isset($this->tracking_number)?"'".addslashes($this->tracking_number)."'":"null").",";
$sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").",";
$sql.= " height=".(isset($this->trueHeight)?$this->trueHeight:"null").",";
$sql.= " width=".(isset($this->trueWidth)?$this->trueWidth:"null").",";
$sql.= " size_units=".(isset($this->size_units)?$this->size_units:"null").",";
$sql.= " size=".(isset($this->trueDepth)?$this->trueDepth:"null").",";
$sql.= " weight_units=".(isset($this->weight_units)?$this->weight_units:"null").",";
$sql.= " weight=".(isset($this->trueWeight)?$this->trueWeight:"null").",";
$sql.= " note=".(isset($this->note)?"'".addslashes($this->note)."'":"null").",";
$sql.= " model_pdf=".(isset($this->model_pdf)?"'".addslashes($this->model_pdf)."'":"null").",";
$sql.= " entity=".$conf->entity;
$sql.= " WHERE rowid=".$this->id;
$this->db->begin();
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
if (! $error)
{
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you
// want this action call a trigger.
//// Call triggers
//include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
//$interface=new Interfaces($this->db);
//$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return 1;
}
}
/**
* \brief Delete shipping
*/
function delete()
{
@ -894,11 +1000,18 @@ class Expedition extends CommonObject
}
}
if ($code) {
if ($code)
{
$classname = "methode_expedition_".strtolower($code);
require_once(DOL_DOCUMENT_ROOT."/includes/modules/expedition/methode_expedition_".strtolower($code).".modules.php");
$obj = new $classname();
$url = $obj->provider_url_status($this->tracking_number);
$url='';
if (file_exists(DOL_DOCUMENT_ROOT."/includes/modules/expedition/methode_expedition_".strtolower($code).".modules.php"))
{
require_once(DOL_DOCUMENT_ROOT."/includes/modules/expedition/methode_expedition_".strtolower($code).".modules.php");
$obj = new $classname();
$url = $obj->provider_url_status($this->tracking_number);
}
if ($url)
{
$this->tracking_url = sprintf('<a target="_blank" href="%s">url</a>',$url,$url);

View File

@ -49,7 +49,7 @@ $langs->load('other');
$langs->load('propal');
$origin = "expedition";
$origin_id = isset($_GET["id"])?$_GET["id"]:'';
$origin_id = isset($_REQUEST["id"])?$_REQUEST["id"]:'';
$id = $origin_id;
$origin = $_GET["origin"]?$_GET["origin"]:$_POST["origin"]; // Example: commande, propal
@ -216,6 +216,44 @@ if ($_POST['action'] == 'setdate_livraison' && $user->rights->expedition->creer)
}
}
// 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
*/
@ -269,7 +307,6 @@ $formproduct = new FormProduct($db);
*********************************************************************/
if ($_GET["action"] == 'create')
{
$expe = new Expedition($db);
print_fiche_titre($langs->trans("CreateASending"));
@ -316,11 +353,11 @@ if ($_GET["action"] == 'create')
// Ref
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;
}
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;
}
@ -339,10 +376,6 @@ if ($_GET["action"] == 'create')
print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
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
print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
print '<td colspan="3">';
@ -611,10 +644,10 @@ else
/* */
/* *************************************************************************** */
{
if ($_GET["id"] > 0)
if (! empty($_REQUEST["id"]) || ! empty($_REQUEST["ref"]))
{
$expedition = new Expedition($db);
$result = $expedition->fetch($_GET["id"]);
$result = $expedition->fetch($_REQUEST["id"],$_REQUEST["ref"]);
if ($result < 0)
{
dol_print_error($db,$expedition->error);
@ -749,7 +782,7 @@ else
print $langs->trans('DateDeliveryPlanned');
print '</td>';
if ($_GET['action'] != 'editdate_livraison' && $expedition->brouillon) 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='.$expedition->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editdate_livraison')
@ -782,20 +815,9 @@ else
}
// Weight
print '<tr><td>'.$langs->trans("TotalWeight").'</td>';
print '<td colspan="3">';
if ($expedition->trueWeight)
{
// 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 '<tr><td>'.$html->editfieldkey("TotalWeight",'trueWeight',$expedition->trueWeight,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print $html->editfieldval("TotalWeight",'trueWeight',$expedition->trueWeight,'id',$expedition->id,$user->rights->expedition->creer);
print measuring_units_string($expedition->weight_units,"weight");
print '</td></tr>';
// Volume Total
@ -816,17 +838,23 @@ else
print "</td>\n";
print '</tr>';
// Taille
print '<tr><td>'.$langs->trans("Size").'</td>';
print '<td colspan="3">';
if ($expedition->trueWidth || $expedition->trueHeight || $expedition->trueDepth)
{
// If sending size defined
print $expedition->trueSize.' '.measuring_units_string($expedition->size_units,"size");
}
else print '&nbsp;';
print "</td>\n";
print '</tr>';
// Width
print '<tr><td>'.$html->editfieldkey("Width",'trueWidth',$expedition->trueWidth,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print $html->editfieldval("Width",'trueWidth',$expedition->trueWidth,'id',$expedition->id,$user->rights->expedition->creer);
print measuring_units_string($expedition->width_units,"size");
print '</td></tr>';
// Height
print '<tr><td>'.$html->editfieldkey("Height",'trueHeight',$expedition->trueHeight,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print $html->editfieldval("Height",'trueHeight',$expedition->trueHeight,'id',$expedition->id,$user->rights->expedition->creer);
print measuring_units_string($expedition->height_units,"size");
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 measuring_units_string($expedition->depth_units,"size");
print '</td></tr>';
// Status
print '<tr><td>'.$langs->trans("Status").'</td>';
@ -834,26 +862,47 @@ else
print '</tr>';
// Sending method
print '<tr><td>'.$langs->trans("SendingMethod").'</td>';
print '<td colspan="3">';
if ($expedition->expedition_method_id > 0)
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
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
$code=$langs->getLabelFromKey($db,$expedition->expedition_method_id,'expedition_methode','rowid','code');
print $langs->trans("SendingMethod".strtoupper($code));
print '<form name="setexpedition_method_id" 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="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 '</tr>';
// Tracking Number
print '<tr><td>'.$langs->trans("TrackingNumber").'</td>';
print '<td>'.$expedition->tracking_number.'</td>';
print '<tr><td>'.$html->editfieldkey("TrackingNumber",'trackingnumber',$expedition->tracking_number,'id',$expedition->id,$user->rights->expedition->creer).'</td><td colspan="3">';
print $html->editfieldval("TrackingNumber",'trackingnumber',$expedition->tracking_number,'id',$expedition->id,$user->rights->expedition->creer);
print '</td></tr>';
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";
@ -888,6 +937,7 @@ else
{
print "<tr ".$bc[$var].">";
// Product
if ($lignes[$i]->fk_product > 0)
{
print '<td>';
@ -962,10 +1012,10 @@ else
{
print '<div class="tabsAction">';
if ($expedition->statut > 0 && $user->rights->expedition->valider)
/*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)
{

View File

@ -157,9 +157,9 @@ function show_list_sending_receive($origin='commande',$origin_id,$filter='')
print '<table class="liste" width="100%">';
print '<tr class="liste_titre">';
print '<td align="left">'.$langs->trans("Description").'</td>';
//print '<td align="left">'.$langs->trans("QtyOrdered").'</td>';
print '<td align="left">'.$langs->trans("SendingSheet").'</td>';
print '<td align="left">'.$langs->trans("Description").'</td>';
print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
print '<td align="center">'.$langs->trans("DateSending").'</td>';
if ($conf->livraison_bon->enabled)
@ -177,6 +177,10 @@ function show_list_sending_receive($origin='commande',$origin_id,$filter='')
$objp = $db->fetch_object($resql);
print "<tr $bc[$var]>";
// Sending id
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->exp_ref.'<a></td>';
// Description
if ($objp->fk_product > 0)
{
print '<td>';
@ -216,9 +220,6 @@ function show_list_sending_receive($origin='commande',$origin_id,$filter='')
//print '<td align="center">'.$objp->qty_asked.'</td>';
// Sending id
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->exp_ref.'<a></td>';
print '<td align="center">'.$objp->qty_shipped.'</td>';
// Date shipping was planed