diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 9fb99f69173..40e93721495 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -673,11 +673,11 @@ abstract class CommonObject
if ($this->origin == 'shipping') $this->origin = 'expedition';
if ($this->origin == 'delivery') $this->origin = 'livraison';
- $object = $this->origin;
+ $origin = $this->origin;
- $classname = ucfirst($object);
- $this->$object = new $classname($this->db);
- $this->$object->fetch($this->origin_id);
+ $classname = ucfirst($origin);
+ $this->$origin = new $classname($this->db);
+ $this->$origin->fetch($this->origin_id);
}
/**
@@ -1653,7 +1653,7 @@ abstract class CommonObject
}
/**
- * Fetch array of objects linked to current object. Links are loaded into this->linkedObjects array.
+ * Fetch array of objects linked to current object. Links are loaded into this->linkedObjects array and this->linkedObjectsIds
*
* @param int $sourceid Object source id
* @param string $sourcetype Object source type
diff --git a/htdocs/core/lib/sendings.lib.php b/htdocs/core/lib/sendings.lib.php
index f8cc1493b4b..06a89fbff80 100644
--- a/htdocs/core/lib/sendings.lib.php
+++ b/htdocs/core/lib/sendings.lib.php
@@ -50,7 +50,7 @@ function shipping_prepare_head($object)
{
// delivery link
$object->fetchObjectLinked($object->id,$object->element);
- if (! empty($object->linkedObjectsIds['delivery'][0]))
+ if (! empty($object->linkedObjectsIds['delivery'][0])) // If there is a delivery
{
$head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->linkedObjectsIds['delivery'][0];
$head[$h][1] = $langs->trans("DeliveryCard");
@@ -63,7 +63,7 @@ function shipping_prepare_head($object)
$head[$h][1] = $langs->trans("ContactsAddresses");
$head[$h][2] = 'contact';
$h++;
-
+
$head[$h][0] = DOL_URL_ROOT."/expedition/note.php?id=".$object->id;
$head[$h][1] = $langs->trans("Notes");
$head[$h][2] = 'note';
@@ -110,16 +110,29 @@ function delivery_prepare_head($object)
$head[$h][2] = 'delivery';
$h++;
+ /* We are on id of delivery, no shipment
+ $head[$h][0] = DOL_URL_ROOT."/expedition/contact.php?id=".$object->id;
+ $head[$h][1] = $langs->trans("ContactsAddresses");
+ $head[$h][2] = 'contact';
+ $h++;
+
+ $head[$h][0] = DOL_URL_ROOT."/expedition/note.php?id=".$object->id;
+ $head[$h][1] = $langs->trans("Notes");
+ $head[$h][2] = 'note';
+ $h++;*/
+
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
- // complete_head_from_modules use $object->id for this link so we temporary change it
- $tmpObjectId = $object->id;
- $object->id = $object->origin_id;
- complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery');
+ // complete_head_from_modules use $object->id for this link so we temporary change it
+ $tmpObjectId = $object->id;
+ $object->id = $object->origin_id;
+
+ complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery');
complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery','remove');
+
$object->id = $tmpObjectId;
return $head;
}
diff --git a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php
index 2f7a70b0e3f..a541b7b2b1e 100644
--- a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php
+++ b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php
@@ -540,9 +540,9 @@ class pdf_rouget extends ModelePdfExpedition
$Yoff = $Yoff+8;
$pdf->SetXY($this->page_largeur - $this->marge_droite - 100,$Yoff);
$pdf->MultiCell(100, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R');
- $Yoff = $Yoff+4;
+ $Yoff = $Yoff+3;
$pdf->SetXY($this->page_largeur - $this->marge_droite - 60,$Yoff);
- $pdf->MultiCell(60, 2, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->commande->date,"daytext",false,$outputlangs,true), 0, 'R');
+ $pdf->MultiCell(60, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date,"day",false,$outputlangs,true), 0, 'R');
}
}
diff --git a/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php b/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php
index 245632d55f2..5ce58a195af 100644
--- a/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php
+++ b/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php
@@ -696,6 +696,41 @@ class pdf_typhon extends ModelePDFDeliveryOrder
$posy+=2;
+ // Add list of linked orders on shipment
+ if ($object->origin == 'expedition' || $object->origin == 'shipping')
+ {
+ $Yoff=$posy-5;
+
+ include_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
+ $shipment = new Expedition($this->db);
+ $shipment->fetch($object->origin_id);
+
+ $origin = $shipment->origin;
+ $origin_id = $shipment->origin_id;
+
+ // TODO move to external function
+ if ($conf->$origin->enabled)
+ {
+ $outputlangs->load('orders');
+
+ $classname = ucfirst($origin);
+ $linkedobject = new $classname($this->db);
+ $result=$linkedobject->fetch($origin_id);
+ if ($result >= 0)
+ {
+ $pdf->SetFont('','', $default_font_size - 2);
+ $text=$linkedobject->ref;
+ if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')';
+ $Yoff = $Yoff+8;
+ $pdf->SetXY($this->page_largeur - $this->marge_droite - 100,$Yoff);
+ $pdf->MultiCell(100, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R');
+ $Yoff = $Yoff+3;
+ $pdf->SetXY($this->page_largeur - $this->marge_droite - 60,$Yoff);
+ $pdf->MultiCell(60, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date,"day",false,$outputlangs,true), 0, 'R');
+ }
+ }
+ }
+
// Show list of linked objects
$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php
index 97fb4a8cc9a..bee87ffe893 100644
--- a/htdocs/expedition/class/expedition.class.php
+++ b/htdocs/expedition/class/expedition.class.php
@@ -163,7 +163,7 @@ class Expedition extends CommonObject
global $conf, $langs;
$now=dol_now();
-
+
if (empty($this->model_pdf)) $this->model_pdf=$conf->global->EXPEDITION_ADDON_PDF;
require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
@@ -791,25 +791,25 @@ class Expedition extends CommonObject
{
global $conf, $langs, $user;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
+
$error=0;
-
+
$this->db->begin();
-
+
// Stock control
if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0)
{
require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php");
-
+
$langs->load("agenda");
-
+
// Loop on each product line to add a stock movement
$sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
$sql.= " WHERE ed.fk_expedition = ".$this->id;
$sql.= " AND cd.rowid = ed.fk_origin_line";
-
+
dol_syslog(get_class($this)."::delete select details sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
@@ -819,7 +819,7 @@ class Expedition extends CommonObject
{
dol_syslog(get_class($this)."::delete movement index ".$i);
$obj = $this->db->fetch_object($resql);
-
+
//var_dump($this->lines[$i]);
$mouvS = new MouvementStock($this->db);
// We decrement stock of product (and sub-products)
@@ -837,27 +837,27 @@ class Expedition extends CommonObject
$error++;
}
}
-
+
if(! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet";
$sql.= " WHERE fk_expedition = ".$this->id;
-
+
if ( $this->db->query($sql) )
{
// Delete linked object
$res = $this->deleteObjectLinked();
if ($res < 0) $error++;
-
+
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition";
$sql.= " WHERE rowid = ".$this->id;
-
+
if ($this->db->query($sql))
{
$this->db->commit();
-
+
// On efface le repertoire de pdf provisoire
$ref = dol_sanitizeFileName($this->ref);
if (! empty($conf->expedition->dir_output))
@@ -880,14 +880,14 @@ class Expedition extends CommonObject
}
}
}
-
+
// Call triggers
include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('SHIPPING_DELETE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// End call triggers
-
+
return 1;
}
else
@@ -911,12 +911,12 @@ class Expedition extends CommonObject
return -1;
}
}
- else
+ else
{
$this->db->rollback();
return -1;
}
-
+
}
/**
@@ -1208,7 +1208,7 @@ class Expedition extends CommonObject
else
{
$this->error=$this->db->error();
- dol_syslog("Commande::set_date_livraison ".$this->error,LOG_ERR);
+ dol_syslog(get_class($this)."::set_date_livraison ".$this->error,LOG_ERR);
return -1;
}
}
diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php
index 34c6a3a9adb..bfc6f764e01 100644
--- a/htdocs/expedition/fiche.php
+++ b/htdocs/expedition/fiche.php
@@ -82,7 +82,7 @@ if ($id > 0 || ! empty($ref))
/*
* Actions
-*/
+ */
if ($action == 'add')
{
@@ -184,7 +184,6 @@ if ($action == 'add')
*/
else if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)
{
- $object->fetch($id);
$result = $object->create_delivery($user);
if ($result > 0)
{
@@ -199,7 +198,6 @@ else if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user-
else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->expedition->valider)
{
- $object->fetch($id);
$object->fetch_thirdparty();
$result = $object->valid($user);
@@ -228,8 +226,6 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->exped
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer)
{
- $object->fetch($id);
- $object->fetch_thirdparty();
$result = $object->delete();
if ($result > 0)
{
@@ -244,7 +240,6 @@ else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expe
else if ($action == 'reopen' && $user->rights->expedition->valider)
{
- $object->fetch($id);
$result = $object->setStatut(0);
if ($result < 0)
{
@@ -275,26 +270,22 @@ else if ($action == 'settrackingnumber' || $action == 'settrackingurl'
{
$error=0;
- $shipping = new Expedition($db);
- $result=$shipping->fetch($id);
- if ($result < 0) dol_print_error($db,$shipping->error);
-
- if ($action == 'settrackingnumber') $shipping->tracking_number = trim(GETPOST('trackingnumber','alpha'));
- if ($action == 'settrackingurl') $shipping->tracking_url = trim(GETPOST('trackingurl','int'));
- if ($action == 'settrueWeight') $shipping->trueWeight = trim(GETPOST('trueWeight','int'));
- if ($action == 'settrueWidth') $shipping->trueWidth = trim(GETPOST('trueWidth','int'));
- if ($action == 'settrueHeight') $shipping->trueHeight = trim(GETPOST('trueHeight','int'));
- if ($action == 'settrueDepth') $shipping->trueDepth = trim(GETPOST('trueDepth','int'));
- if ($action == 'setshipping_method_id') $shipping->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
+ if ($action == 'settrackingnumber') $object->tracking_number = trim(GETPOST('trackingnumber','alpha'));
+ if ($action == 'settrackingurl') $object->tracking_url = trim(GETPOST('trackingurl','int'));
+ if ($action == 'settrueWeight') $object->trueWeight = trim(GETPOST('trueWeight','int'));
+ if ($action == 'settrueWidth') $object->trueWidth = trim(GETPOST('trueWidth','int'));
+ if ($action == 'settrueHeight') $object->trueHeight = trim(GETPOST('trueHeight','int'));
+ if ($action == 'settrueDepth') $object->trueDepth = trim(GETPOST('trueDepth','int'));
+ if ($action == 'setshipping_method_id') $object->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
if (! $error)
{
- if ($shipping->update($user) >= 0)
+ if ($object->update($user) >= 0)
{
- header("Location: fiche.php?id=".$shipping->id);
+ header("Location: fiche.php?id=".$object->id);
exit;
}
- setEventMessage($shipping->error,'errors');
+ setEventMessage($object->error,'errors');
}
$action="";
@@ -331,16 +322,11 @@ elseif ($action == 'remove_file')
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- $object = new Expedition($db);
- if ($object->fetch($id))
- {
- $object->fetch_thirdparty();
- $upload_dir = $conf->expedition->dir_output . "/sending";
- $file = $upload_dir . '/' . GETPOST('file');
- $ret=dol_delete_file($file,0,0,0,$object);
- if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
- else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
- }
+ $upload_dir = $conf->expedition->dir_output . "/sending";
+ $file = $upload_dir . '/' . GETPOST('file');
+ $ret=dol_delete_file($file,0,0,0,$object);
+ if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
+ else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
}
/*
@@ -381,11 +367,6 @@ if ($action == 'send' && ! GETPOST('addfile','alpha') && ! GETPOST('removedfile'
{
$langs->load('mails');
- $result=$object->fetch($id);
- $result=$object->fetch_thirdparty();
-
- if ($result > 0)
- {
// $ref = dol_sanitizeFileName($object->ref);
// $file = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf';
@@ -522,13 +503,6 @@ if ($action == 'send' && ! GETPOST('addfile','alpha') && ! GETPOST('removedfile'
$mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
';
dol_syslog('Failed to read file: '.$file);
}*/
- }
- else
- {
- $langs->load("other");
- $mesg=''.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Shipping")).'
';
- dol_syslog($langs->trans('ErrorFailedToReadEntity',$langs->trans("Shipping")));
- }
}
else if ($action == 'classifybilled')
@@ -638,8 +612,8 @@ if ($action == 'create')
print $form->select_date($object->date_livraison?$object->date_livraison:-1,'date_delivery',1,1);
print "\n";
print '';
-
- // Note Public
+
+ // Note Public
print ''.$langs->trans("NotePublic").' ';
print '';
$doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
@@ -652,7 +626,7 @@ if ($action == 'create')
print ' '.$langs->trans("NotePrivate").' ';
print '';
$doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
- print $doleditor->Create(1);
+ print $doleditor->Create(1);
print " ";
}
@@ -696,10 +670,10 @@ if ($action == 'create')
/*
* Lignes de commandes
*/
-
+
//$lines = $object->fetch_lines(1);
$numAsked = count($object->lines);
-
+
print '';
-
-
+
+
print ' ';
print '';
@@ -903,11 +877,11 @@ if ($action == 'create')
}
print "
";
-
+
print ' ';
-
+
print '';
-
+
print ' ';
}
else
@@ -923,670 +897,663 @@ else
/* */
/* *************************************************************************** */
{
- if (! empty($id) || ! empty($ref))
- {
- $result = $object->fetch($id,$ref);
- if ($result < 0)
- {
- dol_print_error($db,$object->error);
- exit -1;
- }
- $lines = $object->lines;
- $num_prod = count($lines);
+ $lines = $object->lines;
+ $num_prod = count($lines);
- if ($object->id > 0)
- {
- dol_htmloutput_mesg($mesg);
+ if ($object->id > 0)
+ {
+ dol_htmloutput_mesg($mesg);
- if (!empty($object->origin))
- {
- $typeobject = $object->origin;
- $origin = $object->origin;
- $object->fetch_origin();
- }
+ if (!empty($object->origin))
+ {
+ $typeobject = $object->origin;
+ $origin = $object->origin;
+ $object->fetch_origin();
+ }
- $soc = new Societe($db);
- $soc->fetch($object->socid);
+ $soc = new Societe($db);
+ $soc->fetch($object->socid);
- $head=shipping_prepare_head($object);
- dol_fiche_head($head, 'shipping', $langs->trans("Sending"), 0, 'sending');
+ $head=shipping_prepare_head($object);
+ dol_fiche_head($head, 'shipping', $langs->trans("Sending"), 0, 'sending');
- dol_htmloutput_mesg($mesg);
+ dol_htmloutput_mesg($mesg);
- /*
- * Confirmation de la suppression
- */
- if ($action == 'delete')
- {
- $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteSending'),$langs->trans("ConfirmDeleteSending",$object->ref),'confirm_delete','',0,1);
- if ($ret == 'html') print ' ';
- }
- /*
- * Confirmation de la validation
- */
- if ($action == 'valid')
- {
- $objectref = substr($object->ref, 1, 4);
- if ($objectref == 'PROV')
- {
- $numref = $object->getNextNumRef($soc);
- }
- else
- {
- $numref = $object->ref;
- }
+ /*
+ * Confirmation de la suppression
+ */
+ if ($action == 'delete')
+ {
+ $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteSending'),$langs->trans("ConfirmDeleteSending",$object->ref),'confirm_delete','',0,1);
+ if ($ret == 'html') print ' ';
+ }
- $text = $langs->trans("ConfirmValidateSending",$numref);
-
- if (! empty($conf->notification->enabled))
- {
- require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
- $notify=new Notify($db);
- $text.=' ';
- $text.=$notify->confirmMessage('SHIPPING_VALIDATE',$object->socid);
- }
-
- $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateSending'),$text,'confirm_valid','',0,1);
- if ($ret == 'html') print ' ';
- }
- /*
- * Confirmation de l'annulation
- */
- if ($action == 'annuler')
- {
- $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('CancelSending'),$langs->trans("ConfirmCancelSending",$object->ref),'confirm_cancel','',0,1);
- if ($ret == 'html') print ' ';
- }
-
- // Calculate true totalWeight and totalVolume for all products
- // by adding weight and volume of each product line.
- $totalWeight = '';
- $totalVolume = '';
- $weightUnit=0;
- $volumeUnit=0;
- for ($i = 0 ; $i < $num_prod ; $i++)
- {
- $weightUnit=0;
- $volumeUnit=0;
- if (! empty($lines[$i]->weight_units)) $weightUnit = $lines[$i]->weight_units;
- if (! empty($lines[$i]->volume_units)) $volumeUnit = $lines[$i]->volume_units;
-
- // TODO Use a function addvalueunits(val1,unit1,val2,unit2)=>(val,unit)
- if ($lines[$i]->weight_units < 50)
- {
- $trueWeightUnit=pow(10,$weightUnit);
- $totalWeight += $lines[$i]->weight*$lines[$i]->qty_shipped*$trueWeightUnit;
- }
- else
- {
- $trueWeightUnit=$weightUnit;
- $totalWeight += $lines[$i]->weight*$lines[$i]->qty_shipped;
- }
- if ($lines[$i]->volume_units < 50)
- {
- //print $lines[$i]->volume."x".$lines[$i]->volume_units."x".($lines[$i]->volume_units < 50)."x".$volumeUnit;
- $trueVolumeUnit=pow(10,$volumeUnit);
- //print $lines[$i]->volume;
- $totalVolume += $lines[$i]->volume*$lines[$i]->qty_shipped*$trueVolumeUnit;
- }
- else
- {
- $trueVolumeUnit=$volumeUnit;
- $totalVolume += $lines[$i]->volume*$lines[$i]->qty_shipped;
- }
- }
-
- print '';
-
- $linkback = ''.$langs->trans("BackToList").' ';
-
- // Ref
- print ''.$langs->trans("Ref").' ';
- print '';
- print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
- print ' ';
-
- // Customer
- print ''.$langs->trans("Customer").' ';
- print ''.$soc->getNomUrl(1).' ';
- print " ";
-
- // Linked documents
- if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
- {
- print '';
- $objectsrc=new Commande($db);
- $objectsrc->fetch($object->$typeobject->id);
- print $langs->trans("RefOrder").' ';
- print '';
- print $objectsrc->getNomUrl(1,'commande');
- print " \n";
- print ' ';
- }
- if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
- {
- print '';
- $objectsrc=new Propal($db);
- $objectsrc->fetch($object->$typeobject->id);
- print $langs->trans("RefProposal").' ';
- print '';
- print $objectsrc->getNomUrl(1,'expedition');
- print " \n";
- print ' ';
- }
-
- // Ref customer
- print ''.$langs->trans("RefCustomer").' ';
- print ''.$object->ref_customer." \n";
- print ' ';
-
- // Date creation
- print ''.$langs->trans("DateCreation").' ';
- print ''.dol_print_date($object->date_creation,"day")." \n";
- print ' ';
-
- // Delivery date planed
- print '';
- print '';
- print ' ';
- if ($action == 'editdate_livraison')
- {
- print '';
- }
- else
- {
- print $object->date_delivery ? dol_print_date($object->date_delivery,'dayhourtext') : ' ';
- }
- print ' ';
- print ' ';
-
- // Weight
- print ''.$form->editfieldkey("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer).' ';
- print $form->editfieldval("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer);
- print ($object->trueWeight && $object->weight_units!='')?' '.measuring_units_string($object->weight_units,"weight"):'';
- if ($totalWeight > 0)
- {
- if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': ';
- print $totalWeight.' '.measuring_units_string(0,"weight");
- if (!empty($object->trueWeight)) print ')';
- }
- print ' ';
-
- // Width
- print ''.$form->editfieldkey("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer).' ';
- print $form->editfieldval("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer);
- print ($object->trueWidth && $object->width_units!='')?' '.measuring_units_string($object->width_units,"size"):'';
- print ' ';
-
- // Height
- print ''.$form->editfieldkey("Height",'trueHeight',$object->trueHeight,$object,$user->rights->expedition->creer).' ';
- print $form->editfieldval("Height",'trueHeight',$object->trueHeight,$object,$user->rights->expedition->creer);
- print ($object->trueHeight && $object->height_units!='')?' '.measuring_units_string($object->height_units,"size"):'';
- print ' ';
-
- // Depth
- print ''.$form->editfieldkey("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer).' ';
- print $form->editfieldval("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer);
- print ($object->trueDepth && $object->depth_units!='')?' '.measuring_units_string($object->depth_units,"size"):'';
- print ' ';
-
- // Volume
- print '';
- print $langs->trans("Volume");
- print ' ';
- print '';
- $calculatedVolume=0;
- if ($object->trueWidth && $object->trueHeight && $object->trueDepth) $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth);
- // If sending volume not defined we use sum of products
- if ($calculatedVolume > 0)
+ /*
+ * Confirmation de la validation
+ */
+ if ($action == 'valid')
+ {
+ $objectref = substr($object->ref, 1, 4);
+ if ($objectref == 'PROV')
{
- print $calculatedVolume.' ';
- if ($volumeUnit < 50) print measuring_units_string(0,"volume");
- else print measuring_units_string($volumeUnit,"volume");
- }
- if ($totalVolume > 0)
- {
- if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': ';
- print $totalVolume.' '.measuring_units_string(0,"volume");
- if ($calculatedVolume) print ')';
- }
- print " \n";
- print ' ';
-
- // Status
- print ''.$langs->trans("Status").' ';
- print ''.$object->getLibStatut(4)." \n";
- print ' ';
-
- // Sending method
- print '';
- print '';
- print ' ';
- if ($action == 'editshipping_method_id')
- {
- print '';
- }
- else
- {
- if ($object->shipping_method_id > 0)
- {
- // Get code using getLabelFromKey
- $code=$langs->getLabelFromKey($db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
- print $langs->trans("SendingMethod".strtoupper($code));
- }
- }
- print ' ';
- print ' ';
-
- // Tracking Number
- print ''.$form->editfieldkey("TrackingNumber",'trackingnumber',$object->tracking_number,$object,$user->rights->expedition->creer).' ';
- print $form->editfieldval("TrackingNumber",'trackingnumber',$object->tracking_url,$object,$user->rights->expedition->creer,'string',$object->tracking_number);
- print ' ';
-
- // Other attributes
- $parameters=array('colspan' => ' colspan="3"');
- $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
-
- print "
\n";
-
- /*
- * Lignes produits
- */
- print '';
- print '';
- if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
- {
- print ' ';
- }
- print ''.$langs->trans("Products").' ';
- print ''.$langs->trans("QtyOrdered").' ';
- if ($object->statut <= 1)
- {
- print ''.$langs->trans("QtyToShip").' ';
- }
- else
- {
- print ''.$langs->trans("QtyShipped").' ';
- }
-
- print ''.$langs->trans("CalculatedWeight").' ';
- print ''.$langs->trans("CalculatedVolume").' ';
- //print ''.$langs->trans("Size").' ';
-
- if (! empty($conf->stock->enabled))
- {
- print ''.$langs->trans("WarehouseSource").' ';
- }
-
- print " \n";
-
- $var=false;
-
- if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
- {
- $object->fetch_thirdparty();
- $outputlangs = $langs;
- $newlang='';
- if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha');
- if (empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($newlang);
- }
- }
-
- for ($i = 0 ; $i < $num_prod ; $i++)
- {
- print "";
-
- if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
- {
- print ''.($i+1).' ';
- }
-
- // Predefined product or service
- if ($lines[$i]->fk_product > 0)
- {
- // Define output language
- if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
- {
- $prod = new Product($db);
- $prod->fetch($lines[$i]->fk_product);
- $label = ( ! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product_label;
- }
- else
- $label = (! empty($lines[$i]->label)?$lines[$i]->label:$lines[$i]->product_label);
-
- print '';
-
- // Show product and description
- $product_static->type=$lines[$i]->fk_product_type;
- $product_static->id=$lines[$i]->fk_product;
- $product_static->ref=$lines[$i]->ref;
- $text=$product_static->getNomUrl(1);
- $text.= ' - '.$label;
- $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($lines[$i]->description));
- print $form->textwithtooltip($text,$description,3,'','',$i);
- print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
- if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
- {
- print (! empty($lines[$i]->description) && $lines[$i]->description!=$lines[$i]->product)?' '.dol_htmlentitiesbr($lines[$i]->description):'';
- }
- }
- else
- {
- print " ";
- if ($lines[$i]->fk_product_type==1) $text = img_object($langs->trans('Service'),'service');
- else $text = img_object($langs->trans('Product'),'product');
-
- if (! empty($lines[$i]->label)) {
- $text.= ' '.$lines[$i]->label.' ';
- print $form->textwithtooltip($text,$lines[$i]->description,3,'','',$i);
- } else {
- print $text.' '.nl2br($lines[$i]->description);
- }
-
- print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
- print " \n";
- }
-
- // Qte commande
- print ''.$lines[$i]->qty_asked.' ';
-
- // Qte a expedier ou expedier
- print ''.$lines[$i]->qty_shipped.' ';
-
- // Weight
- print '';
- if ($lines[$i]->fk_product_type == 0) print $lines[$i]->weight*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->weight_units,"weight");
- else print ' ';
- print ' ';
-
- // Volume
- print '';
- if ($lines[$i]->fk_product_type == 0) print $lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume");
- else print ' ';
- print ' ';
-
- // Size
- //print ''.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume").' ';
-
- // Entrepot source
- if (! empty($conf->stock->enabled))
- {
- print '';
- if ($lines[$i]->entrepot_id > 0)
- {
- $entrepot = new Entrepot($db);
- $entrepot->fetch($lines[$i]->entrepot_id);
- print $entrepot->getNomUrl(1);
- }
- print ' ';
- }
-
- print " ";
-
- $var=!$var;
- }
- }
-
- print "
\n";
-
- print "\n\n";
-
-
- /*
- * Boutons actions
- */
-
- if (($user->societe_id == 0) && ($action!='presend'))
- {
- print '';
- print " \n";
- }
-
- print '';
-
-
- /*
- * Documents generated
- */
- if ($action != 'presend')
- {
- $objectref = dol_sanitizeFileName($object->ref);
- $filedir = $conf->expedition->dir_output . "/sending/" .$objectref;
-
- $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
-
- $genallowed=$user->rights->expedition->lire;
- $delallowed=$user->rights->expedition->supprimer;
- //$genallowed=1;
- //$delallowed=0;
-
- $somethingshown=$formfile->show_documents('expedition',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
-
- /*
- * Linked object block
- */
- $somethingshown=$object->showLinkedObjectBlock();
-
- if ($genallowed && ! $somethingshown) $somethingshown=1;
-
- print ' ';
-
- // List of actions on element
- include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
- $formactions=new FormActions($db);
- $somethingshown=$formactions->showactions($object,'shipping',$socid);
-
- print '
';
- }
-
- /*
- * Action presend
- */
- if ($action == 'presend')
- {
- $ref = dol_sanitizeFileName($object->ref);
- include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref,'/'));
- $file=$fileparams['fullname'];
-
- // Build document if it not exists
- if (! $file || ! is_readable($file))
- {
- // Define output language
- $outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($newlang);
- }
-
- $result=expedition_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- if ($result <= 0)
- {
- dol_print_error($db,$result);
- exit;
- }
- $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref,'/'));
- $file=$fileparams['fullname'];
- }
-
- print ' ';
- print_titre($langs->trans('SendShippingByEMail'));
-
- // Cree l'objet formulaire mail
- include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
- $formmail = new FormMail($db);
- $formmail->fromtype = 'user';
- $formmail->fromid = $user->id;
- $formmail->fromname = $user->getFullName($langs);
- $formmail->frommail = $user->email;
- $formmail->withfrom=1;
- $liste=array();
- foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value;
- $formmail->withto=GETPOST("sendto")?GETOST("sendto"):$liste;
- $formmail->withtocc=$liste;
- $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
- $formmail->withtopic=$langs->trans('SendShippingRef','__SHIPPINGREF__');
- $formmail->withfile=2;
- $formmail->withbody=1;
- $formmail->withdeliveryreceipt=1;
- $formmail->withcancel=1;
- // Tableau des substitutions
- $formmail->substit['__SHIPPINGREF__']=$object->ref;
- $formmail->substit['__SIGNATURE__']=$user->signature;
- $formmail->substit['__PERSONALIZED__']='';
- $formmail->substit['__CONTACTCIVNAME__']='';
-
- //Find the good contact adress
- //Find the good contact adress
- if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled)) {
- $objectsrc=new Commande($db);
- $objectsrc->fetch($object->$typeobject->id);
- }
- if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled)) {
- $objectsrc=new Propal($db);
- $objectsrc->fetch($object->$typeobject->id);
- }
- $custcontact='';
- $contactarr=array();
- $contactarr=$objectsrc->liste_contact(-1,'external');
-
- if (is_array($contactarr) && count($contactarr)>0) {
- foreach($contactarr as $contact) {
-
- if ($contact['libelle']==$langs->trans('TypeContact_commande_external_CUSTOMER')) {
-
- require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
-
- $contactstatic=new Contact($db);
- $contactstatic->fetch($contact['id']);
- $custcontact=$contactstatic->getFullName($langs,1);
- }
- }
-
- if (!empty($custcontact)) {
- $formmail->substit['__CONTACTCIVNAME__']=$custcontact;
- }
- }
-
- // Tableau des parametres complementaires
- $formmail->param['action']='send';
- $formmail->param['models']='shipping_send';
- $formmail->param['shippingid']=$object->id;
- $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
-
- // Init list of files
- if (GETPOST("mode")=='init')
- {
- $formmail->clear_attached_files();
- $formmail->add_attached_files($file,basename($file),dol_mimetype($file));
- }
-
- // Show form
- $formmail->show_form();
-
- print ' ';
- }
-
- if ($action != 'presend' && ! empty($origin) && $object->$origin->id)
- {
- print ' ';
- //show_list_sending_receive($object->origin,$object->origin_id," AND e.rowid <> ".$object->id);
- show_list_sending_receive($object->origin,$object->origin_id);
- }
- }
+ $numref = $object->getNextNumRef($soc);
+ }
+ else
+ {
+ $numref = $object->ref;
+ }
+
+ $text = $langs->trans("ConfirmValidateSending",$numref);
+
+ if (! empty($conf->notification->enabled))
+ {
+ require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
+ $notify=new Notify($db);
+ $text.=' ';
+ $text.=$notify->confirmMessage('SHIPPING_VALIDATE',$object->socid);
+ }
+
+ $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateSending'),$text,'confirm_valid','',0,1);
+ if ($ret == 'html') print ' ';
+ }
+ /*
+ * Confirmation de l'annulation
+ */
+ if ($action == 'annuler')
+ {
+ $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('CancelSending'),$langs->trans("ConfirmCancelSending",$object->ref),'confirm_cancel','',0,1);
+ if ($ret == 'html') print ' ';
+ }
+
+ // Calculate true totalWeight and totalVolume for all products
+ // by adding weight and volume of each product line.
+ $totalWeight = '';
+ $totalVolume = '';
+ $weightUnit=0;
+ $volumeUnit=0;
+ for ($i = 0 ; $i < $num_prod ; $i++)
+ {
+ $weightUnit=0;
+ $volumeUnit=0;
+ if (! empty($lines[$i]->weight_units)) $weightUnit = $lines[$i]->weight_units;
+ if (! empty($lines[$i]->volume_units)) $volumeUnit = $lines[$i]->volume_units;
+
+ // TODO Use a function addvalueunits(val1,unit1,val2,unit2)=>(val,unit)
+ if ($lines[$i]->weight_units < 50)
+ {
+ $trueWeightUnit=pow(10,$weightUnit);
+ $totalWeight += $lines[$i]->weight*$lines[$i]->qty_shipped*$trueWeightUnit;
+ }
+ else
+ {
+ $trueWeightUnit=$weightUnit;
+ $totalWeight += $lines[$i]->weight*$lines[$i]->qty_shipped;
+ }
+ if ($lines[$i]->volume_units < 50)
+ {
+ //print $lines[$i]->volume."x".$lines[$i]->volume_units."x".($lines[$i]->volume_units < 50)."x".$volumeUnit;
+ $trueVolumeUnit=pow(10,$volumeUnit);
+ //print $lines[$i]->volume;
+ $totalVolume += $lines[$i]->volume*$lines[$i]->qty_shipped*$trueVolumeUnit;
+ }
+ else
+ {
+ $trueVolumeUnit=$volumeUnit;
+ $totalVolume += $lines[$i]->volume*$lines[$i]->qty_shipped;
+ }
+ }
+
+ print '';
+
+ $linkback = ''.$langs->trans("BackToList").' ';
+
+ // Ref
+ print ''.$langs->trans("Ref").' ';
+ print '';
+ print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
+ print ' ';
+
+ // Customer
+ print ''.$langs->trans("Customer").' ';
+ print ''.$soc->getNomUrl(1).' ';
+ print " ";
+
+ // Linked documents
+ if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
+ {
+ print '';
+ $objectsrc=new Commande($db);
+ $objectsrc->fetch($object->$typeobject->id);
+ print $langs->trans("RefOrder").' ';
+ print '';
+ print $objectsrc->getNomUrl(1,'commande');
+ print " \n";
+ print ' ';
+ }
+ if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
+ {
+ print '';
+ $objectsrc=new Propal($db);
+ $objectsrc->fetch($object->$typeobject->id);
+ print $langs->trans("RefProposal").' ';
+ print '';
+ print $objectsrc->getNomUrl(1,'expedition');
+ print " \n";
+ print ' ';
+ }
+
+ // Ref customer
+ print ''.$langs->trans("RefCustomer").' ';
+ print ''.$object->ref_customer." \n";
+ print ' ';
+
+ // Date creation
+ print ''.$langs->trans("DateCreation").' ';
+ print ''.dol_print_date($object->date_creation,"day")." \n";
+ print ' ';
+
+ // Delivery date planned
+ print '';
+ print '';
+ print ' ';
+ if ($action == 'editdate_livraison')
+ {
+ print '';
+ }
+ else
+ {
+ print $object->date_delivery ? dol_print_date($object->date_delivery,'dayhourtext') : ' ';
+ }
+ print ' ';
+ print ' ';
+
+ // Weight
+ print ''.$form->editfieldkey("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer).' ';
+ print $form->editfieldval("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer);
+ print ($object->trueWeight && $object->weight_units!='')?' '.measuring_units_string($object->weight_units,"weight"):'';
+ if ($totalWeight > 0)
+ {
+ if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': ';
+ print $totalWeight.' '.measuring_units_string(0,"weight");
+ if (!empty($object->trueWeight)) print ')';
+ }
+ print ' ';
+
+ // Width
+ print ''.$form->editfieldkey("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer).' ';
+ print $form->editfieldval("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer);
+ print ($object->trueWidth && $object->width_units!='')?' '.measuring_units_string($object->width_units,"size"):'';
+ print ' ';
+
+ // Height
+ print ''.$form->editfieldkey("Height",'trueHeight',$object->trueHeight,$object,$user->rights->expedition->creer).' ';
+ print $form->editfieldval("Height",'trueHeight',$object->trueHeight,$object,$user->rights->expedition->creer);
+ print ($object->trueHeight && $object->height_units!='')?' '.measuring_units_string($object->height_units,"size"):'';
+ print ' ';
+
+ // Depth
+ print ''.$form->editfieldkey("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer).' ';
+ print $form->editfieldval("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer);
+ print ($object->trueDepth && $object->depth_units!='')?' '.measuring_units_string($object->depth_units,"size"):'';
+ print ' ';
+
+ // Volume
+ print '';
+ print $langs->trans("Volume");
+ print ' ';
+ print '';
+ $calculatedVolume=0;
+ if ($object->trueWidth && $object->trueHeight && $object->trueDepth) $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth);
+ // If sending volume not defined we use sum of products
+ if ($calculatedVolume > 0)
+ {
+ print $calculatedVolume.' ';
+ if ($volumeUnit < 50) print measuring_units_string(0,"volume");
+ else print measuring_units_string($volumeUnit,"volume");
+ }
+ if ($totalVolume > 0)
+ {
+ if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': ';
+ print $totalVolume.' '.measuring_units_string(0,"volume");
+ if ($calculatedVolume) print ')';
+ }
+ print " \n";
+ print ' ';
+
+ // Status
+ print ''.$langs->trans("Status").' ';
+ print ''.$object->getLibStatut(4)." \n";
+ print ' ';
+
+ // Sending method
+ print '';
+ print '';
+ print ' ';
+ if ($action == 'editshipping_method_id')
+ {
+ print '';
+ }
+ else
+ {
+ if ($object->shipping_method_id > 0)
+ {
+ // Get code using getLabelFromKey
+ $code=$langs->getLabelFromKey($db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
+ print $langs->trans("SendingMethod".strtoupper($code));
+ }
+ }
+ print ' ';
+ print ' ';
+
+ // Tracking Number
+ print ''.$form->editfieldkey("TrackingNumber",'trackingnumber',$object->tracking_number,$object,$user->rights->expedition->creer).' ';
+ print $form->editfieldval("TrackingNumber",'trackingnumber',$object->tracking_url,$object,$user->rights->expedition->creer,'string',$object->tracking_number);
+ print ' ';
+
+ // Other attributes
+ $parameters=array('colspan' => ' colspan="3"');
+ $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+
+ print "
\n";
+
+ /*
+ * Lignes produits
+ */
+ print '';
+ print '';
+ if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
+ {
+ print ' ';
+ }
+ print ''.$langs->trans("Products").' ';
+ print ''.$langs->trans("QtyOrdered").' ';
+ if ($object->statut <= 1)
+ {
+ print ''.$langs->trans("QtyToShip").' ';
+ }
+ else
+ {
+ print ''.$langs->trans("QtyShipped").' ';
+ }
+
+ print ''.$langs->trans("CalculatedWeight").' ';
+ print ''.$langs->trans("CalculatedVolume").' ';
+ //print ''.$langs->trans("Size").' ';
+
+ if (! empty($conf->stock->enabled))
+ {
+ print ''.$langs->trans("WarehouseSource").' ';
+ }
+
+ print " \n";
+
+ $var=false;
+
+ if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
+ {
+ $object->fetch_thirdparty();
+ $outputlangs = $langs;
+ $newlang='';
+ if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha');
+ if (empty($newlang)) $newlang=$object->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ }
+
+ for ($i = 0 ; $i < $num_prod ; $i++)
+ {
+ print "";
+
+ if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
+ {
+ print ''.($i+1).' ';
+ }
+
+ // Predefined product or service
+ if ($lines[$i]->fk_product > 0)
+ {
+ // Define output language
+ if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
+ {
+ $prod = new Product($db);
+ $prod->fetch($lines[$i]->fk_product);
+ $label = ( ! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product_label;
+ }
+ else
+ $label = (! empty($lines[$i]->label)?$lines[$i]->label:$lines[$i]->product_label);
+
+ print '';
+
+ // Show product and description
+ $product_static->type=$lines[$i]->fk_product_type;
+ $product_static->id=$lines[$i]->fk_product;
+ $product_static->ref=$lines[$i]->ref;
+ $text=$product_static->getNomUrl(1);
+ $text.= ' - '.$label;
+ $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($lines[$i]->description));
+ print $form->textwithtooltip($text,$description,3,'','',$i);
+ print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
+ if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
+ {
+ print (! empty($lines[$i]->description) && $lines[$i]->description!=$lines[$i]->product)?' '.dol_htmlentitiesbr($lines[$i]->description):'';
+ }
+ }
+ else
+ {
+ print " ";
+ if ($lines[$i]->fk_product_type==1) $text = img_object($langs->trans('Service'),'service');
+ else $text = img_object($langs->trans('Product'),'product');
+
+ if (! empty($lines[$i]->label)) {
+ $text.= ' '.$lines[$i]->label.' ';
+ print $form->textwithtooltip($text,$lines[$i]->description,3,'','',$i);
+ } else {
+ print $text.' '.nl2br($lines[$i]->description);
+ }
+
+ print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
+ print " \n";
+ }
+
+ // Qte commande
+ print ''.$lines[$i]->qty_asked.' ';
+
+ // Qte a expedier ou expedier
+ print ''.$lines[$i]->qty_shipped.' ';
+
+ // Weight
+ print '';
+ if ($lines[$i]->fk_product_type == 0) print $lines[$i]->weight*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->weight_units,"weight");
+ else print ' ';
+ print ' ';
+
+ // Volume
+ print '';
+ if ($lines[$i]->fk_product_type == 0) print $lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume");
+ else print ' ';
+ print ' ';
+
+ // Size
+ //print ''.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume").' ';
+
+ // Entrepot source
+ if (! empty($conf->stock->enabled))
+ {
+ print '';
+ if ($lines[$i]->entrepot_id > 0)
+ {
+ $entrepot = new Entrepot($db);
+ $entrepot->fetch($lines[$i]->entrepot_id);
+ print $entrepot->getNomUrl(1);
+ }
+ print ' ';
+ }
+
+ print " ";
+
+ $var=!$var;
+ }
+ }
+
+ print "
\n";
+
+ print "\n\n";
+
+
+ $object->fetchObjectLinked($object->id,$object->element);
+
+
+ /*
+ * Boutons actions
+ */
+
+ if (($user->societe_id == 0) && ($action!='presend'))
+ {
+ print '';
+ print " \n";
+ }
+
+
+ /*
+ * Documents generated
+ */
+ if ($action != 'presend')
+ {
+ print '';
+
+ $objectref = dol_sanitizeFileName($object->ref);
+ $filedir = $conf->expedition->dir_output . "/sending/" .$objectref;
+
+ $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
+
+ $genallowed=$user->rights->expedition->lire;
+ $delallowed=$user->rights->expedition->supprimer;
+
+ $somethingshown=$formfile->show_documents('expedition',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
+
+ /*
+ * Linked object block
+ */
+ $somethingshown=$object->showLinkedObjectBlock();
+
+ if ($genallowed && ! $somethingshown) $somethingshown=1;
+
+ print ' ';
+
+ // List of actions on element
+ include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
+ $formactions=new FormActions($db);
+ $somethingshown=$formactions->showactions($object,'shipping',$socid);
+
+ print '
';
+ }
+
+ /*
+ * Action presend
+ */
+ if ($action == 'presend')
+ {
+ $ref = dol_sanitizeFileName($object->ref);
+ include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref,'/'));
+ $file=$fileparams['fullname'];
+
+ // Build document if it not exists
+ if (! $file || ! is_readable($file))
+ {
+ // Define output language
+ $outputlangs = $langs;
+ $newlang='';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+
+ $result=expedition_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ if ($result <= 0)
+ {
+ dol_print_error($db,$result);
+ exit;
+ }
+ $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref,'/'));
+ $file=$fileparams['fullname'];
+ }
+
+ print ' ';
+ print_titre($langs->trans('SendShippingByEMail'));
+
+ // Cree l'objet formulaire mail
+ include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
+ $formmail = new FormMail($db);
+ $formmail->fromtype = 'user';
+ $formmail->fromid = $user->id;
+ $formmail->fromname = $user->getFullName($langs);
+ $formmail->frommail = $user->email;
+ $formmail->withfrom=1;
+ $liste=array();
+ foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value;
+ $formmail->withto=GETPOST("sendto")?GETOST("sendto"):$liste;
+ $formmail->withtocc=$liste;
+ $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
+ $formmail->withtopic=$langs->trans('SendShippingRef','__SHIPPINGREF__');
+ $formmail->withfile=2;
+ $formmail->withbody=1;
+ $formmail->withdeliveryreceipt=1;
+ $formmail->withcancel=1;
+ // Tableau des substitutions
+ $formmail->substit['__SHIPPINGREF__']=$object->ref;
+ $formmail->substit['__SIGNATURE__']=$user->signature;
+ $formmail->substit['__PERSONALIZED__']='';
+ $formmail->substit['__CONTACTCIVNAME__']='';
+
+ //Find the good contact adress
+ //Find the good contact adress
+ if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled)) {
+ $objectsrc=new Commande($db);
+ $objectsrc->fetch($object->$typeobject->id);
+ }
+ if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled)) {
+ $objectsrc=new Propal($db);
+ $objectsrc->fetch($object->$typeobject->id);
+ }
+ $custcontact='';
+ $contactarr=array();
+ $contactarr=$objectsrc->liste_contact(-1,'external');
+
+ if (is_array($contactarr) && count($contactarr)>0) {
+ foreach($contactarr as $contact) {
+
+ if ($contact['libelle']==$langs->trans('TypeContact_commande_external_CUSTOMER')) {
+
+ require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
+
+ $contactstatic=new Contact($db);
+ $contactstatic->fetch($contact['id']);
+ $custcontact=$contactstatic->getFullName($langs,1);
+ }
+ }
+
+ if (!empty($custcontact)) {
+ $formmail->substit['__CONTACTCIVNAME__']=$custcontact;
+ }
+ }
+
+ // Tableau des parametres complementaires
+ $formmail->param['action']='send';
+ $formmail->param['models']='shipping_send';
+ $formmail->param['shippingid']=$object->id;
+ $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
+
+ // Init list of files
+ if (GETPOST("mode")=='init')
+ {
+ $formmail->clear_attached_files();
+ $formmail->add_attached_files($file,basename($file),dol_mimetype($file));
+ }
+
+ // Show form
+ $formmail->show_form();
+
+ print ' ';
+ }
+
+ if ($action != 'presend' && ! empty($origin) && $object->$origin->id)
+ {
+ print ' ';
+ //show_list_sending_receive($object->origin,$object->origin_id," AND e.rowid <> ".$object->id);
+ show_list_sending_receive($object->origin,$object->origin_id);
+ }
}
diff --git a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql
index d6e654da66c..0832f299457 100755
--- a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql
+++ b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql
@@ -384,3 +384,5 @@ ALTER TABLE llx_societe_address CHANGE COLUMN tel phone varchar(20);
insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,localtax1,localtax1_type,note,active) values (143, 14,'5','0','9.975','1','TPS and TVQ rate',1);
+DELETE FROM llx_document_model WHERE nom ='elevement' AND type='delivery';
+DELETE FROM llx_document_model WHERE nom ='' AND type='delivery';
diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql
index 9b70e075e7c..e656799eb1f 100644
--- a/htdocs/install/mysql/migration/repair.sql
+++ b/htdocs/install/mysql/migration/repair.sql
@@ -61,6 +61,7 @@ UPDATE llx_product SET canvas = NULL where canvas = 'service@product';
DELETE FROM llx_boxes where box_id NOT IN (SELECT rowid FROM llx_boxes_def);
DELETE FROM llx_document_model WHERE nom ='elevement' AND type='delivery';
+DELETE FROM llx_document_model WHERE nom ='' AND type='delivery';
-- Fix: It seems this is missing for some users
insert into llx_c_actioncomm (id, code, type, libelle, module, position) values ( 1, 'AC_TEL', 'system', 'Phone call' ,NULL, 2);
diff --git a/htdocs/livraison/class/livraison.class.php b/htdocs/livraison/class/livraison.class.php
index 9bcf349e373..57f00161f8a 100644
--- a/htdocs/livraison/class/livraison.class.php
+++ b/htdocs/livraison/class/livraison.class.php
@@ -50,7 +50,7 @@ class Livraison extends CommonObject
var $socid;
var $ref_customer;
var $statut;
-
+
var $note_public;
var $note_private;
@@ -90,7 +90,7 @@ class Livraison extends CommonObject
global $conf;
dol_syslog("Livraison::create");
-
+
if (empty($this->model_pdf)) $this->model_pdf=$conf->global->LIVRAISON_ADDON_PDF;
$error = 0;
@@ -902,6 +902,41 @@ class Livraison extends CommonObject
}
}
+ /**
+ * Set the planned delivery date
+ *
+ * @param User $user Objet utilisateur qui modifie
+ * @param timestamp $date_livraison Date de livraison
+ * @return int <0 if KO, >0 if OK
+ */
+ function set_date_livraison($user, $date_livraison)
+ {
+ if ($user->rights->expedition->creer)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."livraison";
+ $sql.= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
+ $sql.= " WHERE rowid = ".$this->id;
+
+ dol_syslog(get_class($this)."::set_date_livraison sql=".$sql,LOG_DEBUG);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ $this->date_delivery = $date_livraison;
+ return 1;
+ }
+ else
+ {
+ $this->error=$this->db->error();
+ dol_syslog(get_class($this)."::set_date_livraison ".$this->error,LOG_ERR);
+ return -1;
+ }
+ }
+ else
+ {
+ return -2;
+ }
+ }
+
}
diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php
index 3012439a697..f29fb4703a4 100644
--- a/htdocs/livraison/fiche.php
+++ b/htdocs/livraison/fiche.php
@@ -42,6 +42,7 @@ if (! empty($conf->stock->enabled))
$langs->load("sendings");
$langs->load("bills");
$langs->load('deliveries');
+$langs->load('orders');
$action=GETPOST('action', 'alpha');
$confirm=GETPOST('confirm', 'alpha');
@@ -157,6 +158,23 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expeditio
}
}
+if ($action == 'setdate_livraison' && $user->rights->expedition->livraison->creer)
+{
+ $object = new Livraison($db);
+ $object->fetch($id);
+ $object->fetch_thirdparty();
+
+ //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
+ $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int'));
+
+ $object->fetch($id);
+ $result=$object->set_date_livraison($user,$datedelivery);
+ if ($result < 0)
+ {
+ $mesg=''.$object->error.'
';
+ }
+}
+
/*
* Build document
*/
@@ -447,7 +465,7 @@ else
$delivery = new Livraison($db);
$result = $delivery->fetch($id);
$delivery->fetch_thirdparty();
-
+
$expedition=new Expedition($db);
$result = $expedition->fetch($delivery->origin_id);
$typeobject = $expedition->origin;
@@ -534,19 +552,38 @@ else
print '';
// Date delivery real / Received
- // TODO Can edit this date, even if delivery validated.
- print ''.$langs->trans("DateReceived").' ';
- print ''.dol_print_date($delivery->date_delivery,'daytext')." \n";
+ print '';
+ print '';
+ print ' ';
+ if ($action == 'editdate_livraison')
+ {
+ print '';
+ }
+ else
+ {
+ print $delivery->date_delivery ? dol_print_date($delivery->date_delivery,'dayhourtext') : ' ';
+ }
+ print ' ';
print ' ';
-
- // Note Public
+
+ // Note Public
print ''.$langs->trans("NotePublic").' ';
print '';
print nl2br($delivery->note_public);
/*$doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
print $doleditor->Create(1);*/
print " ";
-
+
// Note Private
print ''.$langs->trans("NotePrivate").' ';
print '';
@@ -554,7 +591,7 @@ else
/*$doleditor = new DolEditor('note_pprivate', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
print $doleditor->Create(1);*/
print " ";
-
+
// Statut
print ''.$langs->trans("Status").' ';
@@ -712,6 +749,18 @@ else
$delallowed=$user->rights->expedition->livraison->supprimer;
$somethingshown=$formfile->show_documents('livraison',$deliveryref,$filedir,$urlsource,$genallowed,$delallowed,$delivery->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
+
+ /*
+ * Linked object block (of linked shipment)
+ */
+ if ($delivery->origin == 'expedition')
+ {
+ $shipment = new Expedition($db);
+ $shipment->fetch($delivery->origin_id);
+
+ $somethingshown=$shipment->showLinkedObjectBlock();
+ }
+
if ($genallowed && ! $somethingshown) $somethingshown=1;
print '';