diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 9fc8d89197c..be631b3c427 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -863,7 +863,7 @@ if ($_GET['propalid'] > 0) print ''; if ($conf->projet->enabled) $rowspan++; - if ($conf->expedition->enabled || $conf->livraison->enabled) + if ($conf->expedition_bon->enabled || $conf->livraison_bon->enabled) { if ($conf->global->PROPALE_ADD_SHIPPING_DATE || !$conf->commande->enabled) $rowspan++; if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS || !$conf->commande->enabled) $rowspan++; @@ -908,7 +908,7 @@ if ($_GET['propalid'] > 0) // date de livraison (conditionne sur PROPALE_ADD_SHIPPING_DATE car carac a // gerer par les commandes et non les propales - if ($conf->expedition->enabled || $conf->livraison->enabled) + if ($conf->expedition_bon->enabled || $conf->livraison_bon->enabled) { if ($conf->global->PROPALE_ADD_SHIPPING_DATE || !$conf->commande->enabled) { diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 445f8a4bb30..54f714b68ef 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -210,7 +210,7 @@ class Commande extends CommonObject return 0; } - if (! $this->$user->rights->commande->valider) + if (! $user->rights->commande->valider) { $this->error='Autorisation insuffisante'; return -1; diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php index 3e3c33039ec..0448362ab61 100644 --- a/htdocs/compta/commande/fiche.php +++ b/htdocs/compta/commande/fiche.php @@ -28,6 +28,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/order.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/sendings.lib.php"); if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/project.class.php"); @@ -504,103 +505,7 @@ if ($_GET["id"] > 0) print ""; - /* - * Liste des expéditions/livraisons - */ - if ($conf->expedition->enabled && ($conf->expedition_bon->enabled || $conf->livraison->enabled)) - { - print '
'; - - $sql = "SELECT cd.fk_product, cd.rowid, cd.qty as qty_asked"; - $sql .= ", ed.qty as qty_shipped, e.ref, ed.fk_expedition as expedition_id"; - $sql .= ", ".$db->pdate("e.date_expedition")." as date_expedition"; - if ($conf->livraison->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref"; - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; - $sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; - if ($conf->livraison->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid"; - $sql .= " WHERE cd.fk_commande = ".$commande->id; - $sql .= " AND cd.rowid = ed.fk_origin_line"; - $sql .= " AND ed.fk_expedition = e.rowid"; - $sql .= " ORDER BY cd.fk_product"; - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - - if ($num) - { - if ($somethingshown) print '
'; - - print_titre($langs->trans("SendingsAndReceivingForSameOrder")); - print ''; - print ''; - print ''; - print ''; - print ''; - if ($conf->expedition_bon->enabled) - { - print ''; - } - if ($conf->livraison->enabled) - { - print ''; - } - print "\n"; - - $var=True; - while ($i < $num) - { - $var=!$var; - $objp = $db->fetch_object($resql); - print ""; - - if ($objp->fk_product > 0) - { - $product = new Product($db); - $product->fetch($objp->fk_product); - - print ''; - } - else - { - print "\n"; - } - print ''; - print ''; - if ($conf->expedition_bon->enabled) - { - print ''; - } - if ($conf->livraison->enabled) - { - if ($objp->livraison_id) - { - print ''; - } - else - { - print ''; - } - } - print ''; - - $i++; - } - - print '
'.$langs->trans("Product").''.$langs->trans("QtyShipped").''.$langs->trans("DateSending").''.$langs->trans("SendingSheet").''.$langs->trans("DeliveryOrder").'
'; - print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; - print '".nl2br($objp->description)."'.$objp->qty_shipped.''.dolibarr_print_date($objp->date_expedition).''.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.''.img_object($langs->trans("ShowSending"),'generic').' '.$objp->livraison_ref.' 
'; - } - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } - } - + show_list_sending_receive('commande',$commande->id); } else { diff --git a/htdocs/conf/conf.class.php b/htdocs/conf/conf.class.php index 7ec92a56fd5..8b0b5c6b720 100644 --- a/htdocs/conf/conf.class.php +++ b/htdocs/conf/conf.class.php @@ -180,14 +180,16 @@ class Conf // Module expeditions $this->expedition->enabled=defined("MAIN_MODULE_EXPEDITION")?MAIN_MODULE_EXPEDITION:0; - // Sous module bons d'expedition - $this->expedition_bon->enabled=defined("MAIN_SUBMODULE_EXPEDITION")?MAIN_SUBMODULE_EXPEDITION:0; $this->expedition->dir_output=DOL_DATA_ROOT."/expedition"; $this->expedition->dir_temp =DOL_DATA_ROOT."/expedition/temp"; + // Sous module bons d'expedition + $this->expedition_bon->enabled=defined("MAIN_SUBMODULE_EXPEDITION")?MAIN_SUBMODULE_EXPEDITION:0; + $this->expedition_bon->dir_output=DOL_DATA_ROOT."/expedition/sending"; + $this->expedition_bon->dir_temp =DOL_DATA_ROOT."/expedition/sending/temp"; // Sous module bons de livraison - $this->livraison->enabled=defined("MAIN_SUBMODULE_LIVRAISON")?MAIN_SUBMODULE_LIVRAISON:0; - $this->livraison->dir_output=DOL_DATA_ROOT."/livraison"; - $this->livraison->dir_temp =DOL_DATA_ROOT."/livraison/temp"; + $this->livraison_bon->enabled=defined("MAIN_SUBMODULE_LIVRAISON")?MAIN_SUBMODULE_LIVRAISON:0; + $this->livraison_bon->dir_output=DOL_DATA_ROOT."/expedition/receipt"; + $this->livraison_bon->dir_temp =DOL_DATA_ROOT."/expedition/receipt/temp"; // Module societe $this->societe->enabled=defined("MAIN_MODULE_SOCIETE")?MAIN_MODULE_SOCIETE:0; diff --git a/htdocs/expedition/commande.php b/htdocs/expedition/commande.php index 45bc7a093d0..bfd80ceacc3 100644 --- a/htdocs/expedition/commande.php +++ b/htdocs/expedition/commande.php @@ -33,6 +33,7 @@ require_once(DOL_DOCUMENT_ROOT."/project.class.php"); require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/order.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/sendings.lib.php"); $langs->load('orders'); $langs->load("companies"); @@ -406,171 +407,67 @@ if ($_GET["id"] > 0) } - print '
'; - - /* - * Documents générés - * - */ - $comref = sanitize_string($commande->ref); - $file = $conf->commande->dir_output . '/' . $comref . '/' . $comref . '.pdf'; - $relativepath = $comref.'/'.$comref.'.pdf'; - $filedir = $conf->commande->dir_output . '/' . $comref; - $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id; - $genallowed=0; - $delallowed=0; - - $somethingshown=$formfile->show_documents('commande',$comref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf); - - print ''; - // Bouton expedier avec gestion des stocks + + print '
'; + if ($conf->stock->enabled && $reste_a_livrer_total > 0 && $commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer) { print_titre($langs->trans("NewSending")); - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - - $entrepot = new Entrepot($db); - $langs->load("stocks"); - - print ''; - print ''; - print ''; - /* - print ''; - print ''; - */ - - print ''; - - print "
'.$langs->trans("Warehouse").''; - - if (sizeof($user->entrepots) === 1) - { - $uentrepot = array(); - $uentrepot[$user->entrepots[0]['id']] = $user->entrepots[0]['label']; - $html->select_array("entrepot_id",$uentrepot); - } - else - { - $html->select_array("entrepot_id",$entrepot->list_array()); - } - - if (sizeof($entrepot->list_array()) <= 0) - { - print '   Aucun entrepôt définit, definissez en un'; - } - print '
Mode d\'expédition'; - $html->select_array("entrepot_id",$entrepot->list_array()); - print '
'; - print ''; - print '
"; - print "
\n"; - - $somethingshown=1; - } + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + + $entrepot = new Entrepot($db); + $langs->load("stocks"); + + print ''; + print ''; + print ''; + /* + print ''; + print ''; + */ + + print ''; + + print "
'.$langs->trans("Warehouse").''; + + if (sizeof($user->entrepots) === 1) + { + $uentrepot = array(); + $uentrepot[$user->entrepots[0]['id']] = $user->entrepots[0]['label']; + $html->select_array("entrepot_id",$uentrepot); + } + else + { + $html->select_array("entrepot_id",$entrepot->list_array()); + } + + if (sizeof($entrepot->list_array()) <= 0) + { + print '   Aucun entrepôt définit, definissez en un'; + } + print '
Mode d\'expédition'; + $html->select_array("entrepot_id",$entrepot->list_array()); + print '
'; + print ''; + print '
"; + print "
\n"; + + $somethingshown=1; + } - print "
"; + print "
"; - /* - * Liste des expéditions - */ - $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande"; - $sql .= " , ed.qty as qty_livre, e.ref, ed.fk_expedition as expedition_id"; - $sql .= ",".$db->pdate("e.date_expedition")." as date_expedition"; - if ($conf->livraison->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref"; - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; - $sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; - if ($conf->livraison->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid"; - $sql .= " WHERE cd.fk_commande = ".$commande->id; - $sql .= " AND cd.rowid = ed.fk_origin_line"; - $sql .= " AND ed.fk_expedition = e.rowid"; - $sql .= " ORDER BY cd.fk_product"; + show_list_sending_receive('commande',$commande->id); + - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - - if ($num) - { - if ($somethingshown) print '
'; - - print_titre($langs->trans("SendingsAndReceivingForSameOrder")); - print ''; - print ''; - print ''; - print ''; - print ''; - if ($conf->expedition->enabled) - { - print ''; - } - if ($conf->livraison->enabled) - { - print ''; - } - print "\n"; - - $var=True; - while ($i < $num) - { - $var=!$var; - $objp = $db->fetch_object($resql); - print ""; - - if ($objp->fk_product > 0) - { - $product = new Product($db); - $product->fetch($objp->fk_product); - - print ''; - } - else - { - print "\n"; - } - print ''; - print ''; - if ($conf->expedition->enabled) - { - print ''; - } - if ($conf->livraison->enabled) - { - if ($objp->livraison_id) - { - print ''; - } - else - { - print ''; - } - } - print ''; - - $i++; - } - - print '
'.$langs->trans("Product").''.$langs->trans("QtyShipped").''.$langs->trans("DateSending").''.$langs->trans("SendingSheet").''.$langs->trans("DeliveryOrder").'
'; - print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; - if ($objp->description) print '
'.nl2br($objp->description); - print '
".nl2br($objp->description)."'.$objp->qty_livre.''.dolibarr_print_date($objp->date_expedition).''.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.''.img_object($langs->trans("ShowSending"),'generic').' '.$objp->livraison_ref.' 
'; - } - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } } else { diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index c9eccd37d4e..3385f168ec0 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -212,7 +212,7 @@ class Expedition extends CommonObject { $sql.=", pe.fk_propal as origin_id"; } - if ($conf->livraison->enabled) $sql.=", l.rowid as livraison_id"; + if ($conf->livraison_bon->enabled) $sql.=", l.rowid as livraison_id"; $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e"; if ($conf->commande->enabled) { @@ -224,7 +224,7 @@ class Expedition extends CommonObject $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."pr_exp as pe ON e.rowid = pe.fk_expedition"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."propal as p ON pe.fk_propal = p.rowid"; } - if ($conf->livraison->enabled) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON e.rowid = l.fk_expedition"; + if ($conf->livraison_bon->enabled) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON e.rowid = l.fk_expedition"; $sql.= " WHERE e.rowid = ".$id; $result = $this->db->query($sql) ; @@ -432,7 +432,7 @@ class Expedition extends CommonObject { global $conf; - if ($conf->livraison->enabled) + if ($conf->livraison_bon->enabled) { if ($this->statut == 1) { @@ -440,8 +440,15 @@ class Expedition extends CommonObject include_once(DOL_DOCUMENT_ROOT."/livraison/livraison.class.php"); $livraison = new Livraison($this->db); $result=$livraison->create_from_sending($user, $this->id); - - return $result; + if ($result > 0) + { + return $result; + } + else + { + $this->error=$livraison->error; + return $result; + } } else return 0; } @@ -695,7 +702,7 @@ class Expedition extends CommonObject $this->specimen=1; $socid = rand(1, $num_socs); $this->statut = 1; - if ($conf->livraison->enabled) + if ($conf->livraison_bon->enabled) { $this->livraison_id = 0; } diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index f6d4ec5102d..7b123111909 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2006 Laurent Destailleur + * Copyright (C) 2005-2008 Laurent Destailleur * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2005-2008 Régis Houssin * @@ -31,6 +31,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/mods/pdf/ModelePdfExpedition.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/sendings.lib.php"); if ($conf->produit->enabled) require_once(DOL_DOCUMENT_ROOT."/product.class.php"); if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); @@ -43,7 +44,7 @@ $langs->load('orders'); $langs->load('stocks'); $langs->load('other'); -if (!$user->rights->expedition->lire) +if (! $user->rights->expedition->lire) accessforbidden(); @@ -114,12 +115,20 @@ if ($_POST["action"] == 'add') /* * Génère un bon de livraison */ -if ($_GET["action"] == 'create_delivery' && $conf->livraison->enabled && $user->rights->expedition->livraison->creer) +if ($_GET["action"] == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer) { - $expedition = new Expedition($db); - $expedition->fetch($_GET["id"]); - $result = $expedition->create_delivery($user); - Header("Location: ".DOL_URL_ROOT.'/livraison/fiche.php?id='.$result); + $expedition = new Expedition($db); + $expedition->fetch($_GET["id"]); + $result = $expedition->create_delivery($user); + if ($result > 0) + { + Header("Location: ".DOL_URL_ROOT.'/livraison/fiche.php?id='.$result); + exit; + } + else + { + $mesg=$expedition->error; + } } if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->expedition->valider) @@ -138,6 +147,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') $expedition->fetch($_GET["id"]); $expedition->delete(); Header("Location: liste.php"); + exit; } } @@ -314,7 +324,7 @@ if ($_GET["action"] == 'create') { $ligne = $object->lignes[$indiceAsked]; $var=!$var; - print "\n"; + print "\n"; if ($ligne->fk_product > 0) { $product = new Product($db); @@ -412,7 +422,6 @@ if ($_GET["action"] == 'create') print "\n"; $indiceAsked++; - $var=!$var; } /* @@ -457,7 +466,7 @@ else $hselected = $h; $h++; - if ($conf->livraison->enabled && $expedition->livraison_id) + if ($conf->livraison_bon->enabled && $expedition->livraison_id) { $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$expedition->livraison_id; $head[$h][1] = $langs->trans("DeliveryCard"); @@ -466,6 +475,8 @@ else dolibarr_fiche_head($head, $hselected, $langs->trans("Sending")); + if ($mesg) print $mesg; + /* * Confirmation de la suppression * @@ -585,11 +596,11 @@ else } print "\n"; - $var=true; + $var=false; for ($i = 0 ; $i < $num_prod ; $i++) { - print ""; + print ""; if ($lignes[$i]->fk_product > 0) { print ''; @@ -649,7 +660,7 @@ else print ''.$langs->trans("Validate").''; } - if ($conf->livraison->enabled && $expedition->statut == 1 && $user->rights->expedition->livraison->creer && !$expedition->livraison_id) + if ($conf->livraison_bon->enabled && $expedition->statut == 1 && $user->rights->expedition->livraison->creer && !$expedition->livraison_id) { print ''.$langs->trans("DeliveryOrder").''; } @@ -666,99 +677,35 @@ else print "
"; + /* * Documents générés */ - - $expeditionref = sanitize_string($expedition->ref); - $filedir = $conf->expedition->dir_output . "/" .$expeditionref; - - $urlsource = $_SERVER["PHP_SELF"]."?id=".$expedition->id; - - $genallowed=$user->rights->expedition->lire && ($expedition->statut > 0); - $delallowed=$user->rights->expedition->supprimer; - //$genallowed=1; - //$delallowed=0; - - $somethingshown=$formfile->show_documents('expedition',$expeditionref,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf); - if ($genallowed && ! $somethingshown) $somethingshown=1; + if ($conf->expedition_bon->enabled) + { + $expeditionref = sanitize_string($expedition->ref); + $filedir = $conf->expedition->dir_output . "/" .$expeditionref; + + $urlsource = $_SERVER["PHP_SELF"]."?id=".$expedition->id; + + $genallowed=$user->rights->expedition->lire && ($expedition->statut > 0); + $delallowed=$user->rights->expedition->supprimer; + //$genallowed=1; + //$delallowed=0; + + $somethingshown=$formfile->show_documents('expedition',$expeditionref,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf); + if ($genallowed && ! $somethingshown) $somethingshown=1; + } - /* - * Autres expeditions - */ - $sql = "SELECT obj.fk_product, obj.description, obj.rowid, obj.qty as qty_asking"; - $sql.= ", ed.qty as qty_shipped, ed.fk_expedition as expedition_id"; - $sql.= ", e.ref, ".$db->pdate("e.date_expedition")." as date_expedition"; - $sql.= " FROM ".MAIN_DB_PREFIX.$expedition->origin."det as obj"; - $sql.= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; - $sql.= " WHERE obj.fk_".$expedition->origin." = ".$expedition->origin_id; - $sql.= " AND e.rowid <> ".$expedition->id; - $sql.= " AND obj.rowid = ed.fk_origin_line"; - $sql.= " AND ed.fk_expedition = e.rowid"; - $sql.= " ORDER BY obj.fk_product"; - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - - if ($num) - { - if ($somethingshown) print '
'; - - print_titre($langs->trans("OtherSendingsForSameOrder")); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - $var=True; - while ($i < $num) - { - $var=!$var; - $objp = $db->fetch_object($resql); - print ""; - print ''; - if ($objp->fk_product > 0) - { - $product = new Product($db); - $product->fetch($objp->fk_product); - - print ''; - } - else - { - print "\n"; - } - print ''; - print ''; - print ''; - $i++; - } - - print '
'.$langs->trans("Ref").''.$langs->trans("Description").''.$langs->trans("Qty").''.$langs->trans("Date").'
'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.''; - print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.dolibarr_trunc($product->libelle,20); - if ($objp->description) print nl2br(dolibarr_trunc($objp->description,24)); - print '".nl2br(dolibarr_trunc($objp->description,24))."'.$objp->qty_shipped.''.dolibarr_print_date($objp->date_expedition).'
'; - } - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } - - print '
'; // Rien a droite print '
'; + print '
'; + show_list_sending_receive($expedition->origin,$expedition->origin_id," AND e.rowid <> ".$expedition->id); + } else { diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index f04fc7d44bb..9424ee02d94 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -87,7 +87,7 @@ class Form $htmltext=ereg_replace("\r","",$htmltext); $htmltext=ereg_replace("
\n","
",$htmltext); $htmltext=ereg_replace("\n","",$htmltext); - + if ($conf->use_javascript_ajax && $tooltipon == 4) { $s = '
'."\n"; @@ -116,34 +116,34 @@ class Form $paramfortooltippicto.=' onmouseover="showtip(\''.$htmltext.'\')"'; $paramfortooltippicto.=' onMouseout="hidetip()"'; } - } + } - $s=""; - $s.=''; - if ($direction > 0) - { - if ($text) + $s=""; + $s.='
'; + if ($direction > 0) { - $s.=''.$text; - if ($direction) $s.=' '; - $s.=''; + if ($text) + { + $s.=''.$text; + if ($direction) $s.=' '; + $s.=''; + } + if ($direction) $s.=''.$img.''; } - if ($direction) $s.=''.$img.''; - } - else - { - if ($direction) $s.=''.$img.''; - if ($text) + else { - $s.=''; - if ($direction) $s.=' '; - $s.=$text.''; + if ($direction) $s.=''.$img.''; + if ($text) + { + $s.=''; + if ($direction) $s.=' '; + $s.=$text.''; + } } + $s.='
'; } - $s.=''; + return $s; } - return $s; - } /** \brief Affiche un texte avec picto help qui affiche un tooltip diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 88e0d561247..50cc3a316bc 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -1683,7 +1683,7 @@ function migrate_commande_expedition($db,$langs,$conf) */ function migrate_commande_livraison($db,$langs,$conf) { - if ($conf->livraison->enabled) + if ($conf->livraison_bon->enabled) { print ''; diff --git a/htdocs/lib/order.lib.php b/htdocs/lib/order.lib.php index 44aa83f3f61..10a0636cb4f 100644 --- a/htdocs/lib/order.lib.php +++ b/htdocs/lib/order.lib.php @@ -47,12 +47,12 @@ function commande_prepare_head($commande) $h++; } - if (($conf->expedition->enabled && $user->rights->expedition->lire) - || ($conf->livraison->enabled && $user->rights->expedition->livraison->lire)) + if (($conf->expedition_bon->enabled && $user->rights->expedition->lire) + || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire)) { $head[$h][0] = DOL_URL_ROOT.'/expedition/commande.php?id='.$commande->id; - if ($conf->expedition->enabled) $text=$langs->trans("Sendings"); - if ($conf->livraison->enabled) $text.='/'.$langs->trans("Receivings"); + if ($conf->expedition_bon->enabled) $text=$langs->trans("Sendings"); + if ($conf->livraison_bon->enabled) $text.='/'.$langs->trans("Receivings"); $head[$h][1] = $text; $head[$h][2] = 'shipping'; $h++; diff --git a/htdocs/lib/propal.lib.php b/htdocs/lib/propal.lib.php index be586febf71..de5fc8c7362 100644 --- a/htdocs/lib/propal.lib.php +++ b/htdocs/lib/propal.lib.php @@ -43,13 +43,14 @@ function propal_prepare_head($propal) $head[$h][2] = 'comm'; $h++; - if ((!$conf->commande->enabled && (($conf->expedition->enabled && $user->rights->expedition->lire) - || ($conf->livraison->enabled && $user->rights->expedition->livraison->lire)))) + if ((!$conf->commande->enabled && + (($conf->expedition_bon->enabled && $user->rights->expedition->lire) + || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire)))) { $langs->load("sendings"); $head[$h][0] = DOL_URL_ROOT.'/expedition/propal.php?propalid='.$propal->id; - if ($conf->expedition->enabled) $text=$langs->trans("Sendings"); - if ($conf->livraison->enabled) $text.='/'.$langs->trans("Receivings"); + if ($conf->expedition_bon->enabled) $text=$langs->trans("Sendings"); + if ($conf->livraison_bon->enabled) $text.='/'.$langs->trans("Receivings"); $head[$h][1] = $text; $head[$h][2] = 'shipping'; $h++; diff --git a/htdocs/lib/sendings.lib.php b/htdocs/lib/sendings.lib.php new file mode 100644 index 00000000000..e7c435558e9 --- /dev/null +++ b/htdocs/lib/sendings.lib.php @@ -0,0 +1,134 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + \file htdocs/lib/sendings.lib.php + \ingroup expedition + \brief Library for expedition module + \version $Id$ + */ + + +/** + * List sendings and receive receipts + * + * @param unknown_type $option + * @return unknown + */ +function show_list_sending_receive($origin='commande',$origin_id,$filter='') +{ + global $db, $conf, $langs, $bc; + + $sql = "SELECT obj.rowid, obj.fk_product, obj.description, obj.qty as qty_asking"; + $sql.= ", ed.qty as qty_shipped, ed.fk_expedition as expedition_id"; + $sql.= ", e.ref, ".$db->pdate("e.date_expedition")." as date_expedition"; + if ($conf->livraison_bon->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref"; + $sql.= " FROM ".MAIN_DB_PREFIX.$origin."det as obj"; + $sql.= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; + if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid"; + $sql.= " WHERE obj.fk_".$origin." = ".$origin_id; + if ($filter) $sql.=$filter; + $sql.= " AND obj.rowid = ed.fk_origin_line"; + $sql.= " AND ed.fk_expedition = e.rowid"; + $sql.= " ORDER BY obj.fk_product"; + + dolibarr_syslog("show_list_sending_receive sql=".$sql, LOG_DEBUG); + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + if ($num) + { + if ($somethingshown) print '
'; + + if ($filter) print_titre($langs->trans("OtherSendingsForSameOrder")); + else print_titre($langs->trans("SendingsAndReceivingForSameOrder")); + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + if ($conf->expedition_bon->enabled) + { + print ''; + } + if ($conf->livraison_bon->enabled) + { + print ''; + } + print "\n"; + + $var=True; + while ($i < $num) + { + $var=!$var; + $objp = $db->fetch_object($resql); + print ""; + print ''; + if ($objp->fk_product > 0) + { + $product = new Product($db); + $product->fetch($objp->fk_product); + + print ''; + } + else + { + print "\n"; + } + print ''; + print ''; + if ($conf->expedition_bon->enabled) + { + print ''; + } + if ($conf->livraison_bon->enabled) + { + if ($objp->livraison_id) + { + print ''; + } + else + { + print ''; + } + } + print ''; + $i++; + } + + print '
'.$langs->trans("Ref").''.$langs->trans("Description").''.$langs->trans("Qty").''.$langs->trans("DateSending").''.$langs->trans("SendingSheet").''.$langs->trans("DeliveryOrder").'
'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.''; + print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.dolibarr_trunc($product->libelle,20); + if ($objp->description) print dol_htmlentitiesbr(dolibarr_trunc($objp->description,24)); + print '".dol_htmlentitiesbr(dolibarr_trunc($objp->description,24))."'.$objp->qty_shipped.''.dolibarr_print_date($objp->date_expedition,'dayhour').''.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.''.img_object($langs->trans("ShowSending"),'generic').' '.$objp->livraison_ref.' 
'; + } + $db->free($resql); + } + else + { + dolibarr_print_error($db); + } + + return 1; +} + +?> \ No newline at end of file diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php index 8d226b5ea57..54a31bc19f1 100644 --- a/htdocs/livraison/fiche.php +++ b/htdocs/livraison/fiche.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2006 Laurent Destailleur + * Copyright (C) 2005-2008 Laurent Destailleur * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2005-2008 Regis Houssin @@ -425,13 +425,13 @@ else if ($conf->commande->enabled) { print ''.$langs->trans("RefOrder").''; - print ''.img_object($langs->trans("ShowOrder"),'order').' '.$livraison->$object->ref."\n"; + print ''.img_object($langs->trans("ShowOrder"),'order').' '.$livraison->commande->ref."\n"; print ''; } else { print ''.$langs->trans("RefProposal").''; - print ''.img_object($langs->trans("ShowProposal"),'propal').' '.$livraison->$object->ref."\n"; + print ''.img_object($langs->trans("ShowProposal"),'propal').' '.$livraison->propal->ref."\n"; print ''; } @@ -568,7 +568,7 @@ else $sql.= ", cd.rowid, cd.qty as qty_commande"; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sql.= " , ".MAIN_DB_PREFIX."livraisondet as ld, ".MAIN_DB_PREFIX."livraison as l"; - $sql.= " WHERE cd.fk_commande = ".$livraison->commande_id; + $sql.= " WHERE cd.fk_commande = ".$livraison->origin_id; $sql.= " AND l.rowid <> ".$livraison->id; $sql.= " AND cd.rowid = ld.fk_origin_line"; $sql.= " AND ld.fk_livraison = l.rowid"; diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php index b81990e2eb3..acaa912ad34 100644 --- a/htdocs/livraison/livraison.class.php +++ b/htdocs/livraison/livraison.class.php @@ -17,21 +17,19 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ */ /** \file htdocs/livraison/livraison.class.php \ingroup livraison \brief Fichier de la classe de gestion des bons de livraison - \version $Revision$ + \version $Id$ */ require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/expedition.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php"); -if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); +if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); @@ -47,7 +45,7 @@ class Livraison extends CommonObject var $brouillon; var $origin; var $origin_id; - + var $socid; /** * Initialisation @@ -76,7 +74,7 @@ class Livraison extends CommonObject { global $conf; - dolibarr_syslog("Livraison::create "); + dolibarr_syslog("Livraison::create"); $error = 0; @@ -84,14 +82,16 @@ class Livraison extends CommonObject $this->brouillon = 1; $this->user = $user; - + $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraison (date_creation, fk_user_author, fk_adresse_livraison"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraison (ref, fk_soc, date_creation, fk_user_author,"; + $sql.= " fk_adresse_livraison"; if ($this->commande_id) $sql.= ", fk_commande"; if ($this->expedition_id) $sql.= ", fk_expedition"; $sql.= ")"; - $sql.= " VALUES (now(), $user->id, $this->adresse_livraison_id"; + $sql.= " VALUES ('(PROV)', ".$this->socid.", now(), $user->id,"; + $sql.= " ".($this->adresse_livraison_id > 0?$this->adresse_livraison_id:"null"); if ($this->commande_id) $sql.= ", $this->commande_id"; if ($this->expedition_id) $sql.= ", $this->expedition_id"; $sql.= ")"; @@ -120,7 +120,10 @@ class Livraison extends CommonObject */ for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) { - if (! $this->create_line(0, $this->lignes[$i]->commande_ligne_id, $this->lignes[$i]->qty)) + $origin_id=$this->lignes[$i]->origin_ligne_id; + if (! $origin_id) $origin_id=$this->lignes[$i]->commande_ligne_id; // For backward compatibility + + if (! $this->create_line(0, $origin_id, $this->lignes[$i]->qty)) { $error++; } @@ -146,7 +149,7 @@ class Livraison extends CommonObject else { $error++; - $this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; + $this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror; dolibarr_syslog("Livraison::create Error -3 ".$this->error); $this->db->rollback(); return -3; @@ -155,7 +158,7 @@ class Livraison extends CommonObject else { $error++; - $this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; + $this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror; dolibarr_syslog("Livraison::create Error -2 ".$this->error); $this->db->rollback(); return -2; @@ -164,7 +167,7 @@ class Livraison extends CommonObject else { $error++; - $this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; + $this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror; dolibarr_syslog("Livraison::create Error -1 ".$this->error); $this->db->rollback(); return -1; @@ -181,6 +184,7 @@ class Livraison extends CommonObject $idprod = 0; $j = 0; + // Search product id while (($j < sizeof($this->commande->lignes)) && idprod == 0) { if ($this->commande->lignes[$j]->id == $commande_ligne_id) @@ -190,8 +194,12 @@ class Livraison extends CommonObject $j++; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraisondet (fk_livraison, fk_commande_ligne, qty)"; - $sql .= " VALUES ($this->id,".$commande_ligne_id.",".$qty.")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraisondet (fk_livraison, fk_origin_line,"; + if ($idprod) $sql.=" fk_product"; + $sql.= " qty)"; + $sql.= " VALUES (".$this->id.",".$commande_ligne_id.","; + if ($idprod) $sql.=" ".$idprod.","; + $sql.= $qty.")"; if (! $this->db->query($sql) ) { @@ -205,7 +213,6 @@ class Livraison extends CommonObject } /** - * * Lit un bon de livraison * */ @@ -234,7 +241,8 @@ class Livraison extends CommonObject $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."pr_liv as pl ON pl.fk_livraison = l.rowid"; } $sql.= " WHERE l.rowid = ".$id; - + + dolibarr_syslog("Livraison::fetch sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql) ; if ($result) { @@ -475,7 +483,7 @@ class Livraison extends CommonObject $LivraisonLigne->origin_ligne_id = $expedition->lignes[$i]->origin_line_id; $LivraisonLigne->libelle = $expedition->lignes[$i]->libelle; $LivraisonLigne->description = $expedition->lignes[$i]->product_desc; - $LivraisonLigne->qty = $expedition->lignes[$i]->qty_expedie; + $LivraisonLigne->qty = $expedition->lignes[$i]->qty_shipped; $LivraisonLigne->fk_product = $expedition->lignes[$i]->fk_product; $LivraisonLigne->ref = $expedition->lignes[$i]->ref; $this->lignes[$i] = $LivraisonLigne; @@ -487,7 +495,8 @@ class Livraison extends CommonObject $this->projetid = $expedition->projetidp; $this->date_livraison = $expedition->date_livraison; $this->adresse_livraison_id = $expedition->adresse_livraison_id; - + $this->socid = $expedition->socid; + return $this->create($user); } @@ -619,16 +628,16 @@ class Livraison extends CommonObject { $this->lignes = array(); - $sql = "SELECT p.label, p.ref"; - $sql.= ", l.description, l.fk_product, l.subprice, l.total_ht, l.qty as qtyliv"; + $sql = "SELECT p.label, p.ref,"; + $sql.= " l.description, l.fk_product, l.subprice, l.total_ht, l.qty as qtyliv"; //$sql.= ", c.qty as qtycom"; - $sql .= " FROM ".MAIN_DB_PREFIX."livraisondet as l"; + $sql.= " FROM ".MAIN_DB_PREFIX."livraisondet as l"; //$sql .= " , ".MAIN_DB_PREFIX."commandedet as c"; - $sql .= " , ".MAIN_DB_PREFIX."product as p"; - $sql .= " WHERE l.fk_livraison = ".$this->id; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on p.rowid = l.fk_product"; + $sql.= " WHERE l.fk_livraison = ".$this->id; //$sql .= " AND l.fk_commande_ligne = c.rowid"; - $sql .= " AND l.fk_product = p.rowid"; + dolibarr_syslog("Livraison::fetch_lignes sql=".$sql); $resql = $this->db->query($sql); if ($resql) {