2
0
forked from Wavyzz/dolibarr

Fix: Found a dozen of bugs into sub module delivery of module shipment.

This commit is contained in:
Laurent Destailleur
2013-08-07 15:08:30 +02:00
parent 4d67d02f33
commit d5a57f3717
10 changed files with 850 additions and 748 deletions

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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');
}
}

View File

@@ -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);

View File

@@ -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;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -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';

View File

@@ -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);

View File

@@ -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;
}
}
}

View File

@@ -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='<div class="error">'.$object->error.'</div>';
}
}
/*
* 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 '</tr>';
// Date delivery real / Received
// TODO Can edit this date, even if delivery validated.
print '<tr><td>'.$langs->trans("DateReceived").'</td>';
print '<td colspan="3">'.dol_print_date($delivery->date_delivery,'daytext')."</td>\n";
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('DateReceived');
print '</td>';
if ($action != 'editdate_livraison') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$delivery->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($action == 'editdate_livraison')
{
print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$delivery->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="setdate_livraison">';
$form->select_date($delivery->date_delivery?$delivery->date_delivery:-1,'liv_',1,1,'',"setdate_livraison");
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
}
else
{
print $delivery->date_delivery ? dol_print_date($delivery->date_delivery,'dayhourtext') : '&nbsp;';
}
print '</td>';
print '</tr>';
// Note Public
// Note Public
print '<tr><td>'.$langs->trans("NotePublic").'</td>';
print '<td colspan="3">';
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 "</td></tr>";
// Note Private
print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
print '<td colspan="3">';
@@ -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 "</td></tr>";
// Statut
print '<tr><td>'.$langs->trans("Status").'</td>';
@@ -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 '</td><td valign="top" width="50%">';