diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 607e0573967..fdb23fbad2c 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -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('url',$url,$url); diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index b819e0036cb..f5f069376bf 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -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='
'.$mesg.'
'; + $_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 ''; - if ($conf->commande->enabled) + if ($origin == 'commande' && $conf->commande->enabled) { print $langs->trans("RefOrder").''.img_object($langs->trans("ShowOrder"),'order').' '.$object->ref; } - else + if ($origin == 'propal' && $conf->propal->enabled) { print $langs->trans("RefProposal").''.img_object($langs->trans("ShowProposal"),'propal').' '.$object->ref; } @@ -339,10 +376,6 @@ if ($_GET["action"] == 'create') print ''.$soc->getNomUrl(1).''; print ''; - // Date - print "".$langs->trans("Date").""; - print ''.dol_print_date($object->date,"day")."\n"; - // Date delivery planned print ''.$langs->trans("DateDeliveryPlanned").''; print ''; @@ -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 ''; - if ($_GET['action'] != 'editdate_livraison' && $expedition->brouillon) print 'id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).''; + if ($_GET['action'] != 'editdate_livraison') print 'id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).''; print ''; print ''; if ($_GET['action'] == 'editdate_livraison') @@ -782,20 +815,9 @@ else } // Weight - print ''.$langs->trans("TotalWeight").''; - print ''; - 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 ' '; - } + print ''.$html->editfieldkey("TotalWeight",'trueWeight',$expedition->trueWeight,'id',$expedition->id,$user->rights->expedition->creer).''; + print $html->editfieldval("TotalWeight",'trueWeight',$expedition->trueWeight,'id',$expedition->id,$user->rights->expedition->creer); + print measuring_units_string($expedition->weight_units,"weight"); print ''; // Volume Total @@ -816,17 +838,23 @@ else print "\n"; print ''; - // Taille - print ''.$langs->trans("Size").''; - print ''; - if ($expedition->trueWidth || $expedition->trueHeight || $expedition->trueDepth) - { - // If sending size defined - print $expedition->trueSize.' '.measuring_units_string($expedition->size_units,"size"); - } - else print ' '; - print "\n"; - print ''; + // Width + print ''.$html->editfieldkey("Width",'trueWidth',$expedition->trueWidth,'id',$expedition->id,$user->rights->expedition->creer).''; + print $html->editfieldval("Width",'trueWidth',$expedition->trueWidth,'id',$expedition->id,$user->rights->expedition->creer); + print measuring_units_string($expedition->width_units,"size"); + print ''; + + // Height + print ''.$html->editfieldkey("Height",'trueHeight',$expedition->trueHeight,'id',$expedition->id,$user->rights->expedition->creer).''; + print $html->editfieldval("Height",'trueHeight',$expedition->trueHeight,'id',$expedition->id,$user->rights->expedition->creer); + print measuring_units_string($expedition->height_units,"size"); + print ''; + + // Depth + print ''.$html->editfieldkey("Depth",'trueDepth',$expedition->trueDepth,'id',$expedition->id,$user->rights->expedition->creer).''; + print $html->editfieldval("Depth",'trueDepth',$expedition->trueDepth,'id',$expedition->id,$user->rights->expedition->creer); + print measuring_units_string($expedition->depth_units,"size"); + print ''; // Status print ''.$langs->trans("Status").''; @@ -834,26 +862,47 @@ else print ''; // Sending method - print ''.$langs->trans("SendingMethod").''; - print ''; - if ($expedition->expedition_method_id > 0) + print ''; + print ''; + + if ($_GET['action'] != 'editexpedition_method_id') print ''; + print '
'; + print $langs->trans('SendingMethod'); + print 'id.'">'.img_edit($langs->trans('SetSendingMethod'),1).'
'; + print ''; + 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 '
'; + print ''; + print ''; + $expedition->fetch_delivery_methods(); + $html->select_array("expedition_method_id",$expedition->meths,$expedition->expedition_method_id,1,0,0,0,"",1); + print ''; + print '
'; + } + 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 ' '; print ''; print ''; // Tracking Number - print ''.$langs->trans("TrackingNumber").''; - print ''.$expedition->tracking_number.''; + print ''.$html->editfieldkey("TrackingNumber",'trackingnumber',$expedition->tracking_number,'id',$expedition->id,$user->rights->expedition->creer).''; + print $html->editfieldval("TrackingNumber",'trackingnumber',$expedition->tracking_number,'id',$expedition->id,$user->rights->expedition->creer); + print ''; + if ($expedition->tracking_url) { - print ''.$expedition->tracking_url."\n"; + print ''.$html->editfieldkey("TrackingUrl",'trackingurl',$expedition->tracking_url,'id',$expedition->id,$user->rights->expedition->creer).''; + print $html->editfieldval("TrackingUrl",'trackingurl',$expedition->tracking_url,'id',$expedition->id,$user->rights->expedition->creer); + print ''; } - print ''; print "\n"; @@ -888,6 +937,7 @@ else { print ""; + // Product if ($lignes[$i]->fk_product > 0) { print ''; @@ -962,10 +1012,10 @@ else { print '
'; - if ($expedition->statut > 0 && $user->rights->expedition->valider) + /*if ($expedition->statut > 0 && $user->rights->expedition->valider) { print ''.$langs->trans("Modify").''; - } + }*/ if ($expedition->statut == 0 && $num_prod > 0) { diff --git a/htdocs/lib/sendings.lib.php b/htdocs/lib/sendings.lib.php index d8e111dd8aa..24637fb5802 100644 --- a/htdocs/lib/sendings.lib.php +++ b/htdocs/lib/sendings.lib.php @@ -157,9 +157,9 @@ function show_list_sending_receive($origin='commande',$origin_id,$filter='') print ''; print ''; - print ''; //print ''; print ''; + print ''; print ''; print ''; 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 ""; + // Sending id + print ''; + + // Description if ($objp->fk_product > 0) { print ''; - // Sending id - print ''; - print ''; // Date shipping was planed
'.$langs->trans("Description").''.$langs->trans("QtyOrdered").''.$langs->trans("SendingSheet").''.$langs->trans("Description").''.$langs->trans("QtyShipped").''.$langs->trans("DateSending").'
'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->exp_ref.''; @@ -216,9 +220,6 @@ function show_list_sending_receive($origin='commande',$origin_id,$filter='') //print ''.$objp->qty_asked.''.img_object($langs->trans("ShowSending"),'sending').' '.$objp->exp_ref.''.$objp->qty_shipped.'