From 9f6e356684d3823b7d600d482f2e0fe86c43c0f4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Jun 2006 17:10:32 +0000 Subject: [PATCH] =?UTF-8?q?Maxi=20debuggage=20et=20am=E9lioration=20du=20m?= =?UTF-8?q?odule=20exp=E9dition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/comm/adresse_livraison.class.php | 8 +- htdocs/comm/adresse_livraison.php | 181 ++++++----- htdocs/commande/fiche.php | 4 +- htdocs/compta/facture/contact.php | 31 +- htdocs/conf/conf.class.php | 21 +- htdocs/expedition/commande.php | 6 +- htdocs/expedition/expedition.class.php | 31 +- htdocs/expedition/fiche.php | 130 +++++--- .../mods/pdf/ModelePdfExpedition.class.php | 15 +- .../pdf/pdf_expedition_dorade.modules.php | 37 ++- .../mods/pdf/pdf_expedition_merou.modules.php | 34 +- .../pdf/pdf_expedition_rouget.modules.php | 13 +- .../modules/propale/modules_propale.php | 51 ++- htdocs/langs/en_US/admin.lang | 14 +- htdocs/langs/en_US/orders.lang | 1 + htdocs/langs/en_US/sendings.lang | 1 + htdocs/langs/fr_FR/admin.lang | 16 +- htdocs/langs/fr_FR/orders.lang | 1 + htdocs/langs/fr_FR/sendings.lang | 1 + htdocs/lib/order.lib.php | 3 +- htdocs/livraison/fiche.php | 49 ++- htdocs/livraison/livraison.class.php | 306 +++++++++--------- 22 files changed, 546 insertions(+), 408 deletions(-) diff --git a/htdocs/comm/adresse_livraison.class.php b/htdocs/comm/adresse_livraison.class.php index 3c20dcc5564..9c8947fca78 100644 --- a/htdocs/comm/adresse_livraison.class.php +++ b/htdocs/comm/adresse_livraison.class.php @@ -23,18 +23,18 @@ /** \file htdocs/comm/adresse_livraison.class.php - \ingroup societe + \ingroup societe, expedition \brief Fichier de la classe des adresses de livraison \version $Revision$ */ /** - \class Societe + \class AdresseLivraison \brief Classe permettant la gestion des adresses de livraison */ -class Livraison +class AdresseLivraison { var $db; @@ -55,7 +55,7 @@ class Livraison * \param DB handler accès base de données * \param id id societe (0 par defaut) */ - function Livraison($DB, $id=0) + function AdresseLivraison($DB, $id=0) { global $conf; diff --git a/htdocs/comm/adresse_livraison.php b/htdocs/comm/adresse_livraison.php index 61d405d42c1..8dad4c631cf 100644 --- a/htdocs/comm/adresse_livraison.php +++ b/htdocs/comm/adresse_livraison.php @@ -73,7 +73,6 @@ if (!$user->rights->commercial->client->voir && $socid && !$user->societe_id > 0 } } -$livraison = new Livraison($db); @@ -83,6 +82,7 @@ $livraison = new Livraison($db); if ($_POST["action"] == 'add' || $_POST["action"] == 'update') { + $livraison = new AdresseLivraison($db); $livraison->socid = $_POST["socid"]; $livraison->label = $_POST["label"]; $livraison->nom = $_POST["nom"]; @@ -161,7 +161,7 @@ if ($_POST["action"] == 'add' || $_POST["action"] == 'update') if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->societe->supprimer) { - $livraison = new Livraison($db); + $livraison = new AdresseLivraison($db); $result = $livraison->delete($_GET["idl"], $socid); if ($result == 0) @@ -195,6 +195,8 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'create') * Fiche adresse de livraison en mode création */ + $livraison = new AdresseLivraison($db); + if ($_POST["label"] && $_POST["nom"]) { $livraison->socid=$_POST["socid"]; @@ -277,6 +279,7 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') /* * Fiche societe en mode edition */ + $livraison = new AdresseLivraison($db); print_titre($langs->trans("EditDeliveyAdress")); @@ -284,7 +287,6 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') { if ($reload || ! $_POST["nom"]) { - $livraison = new Livraison($db); $livraison->socid = $socid; $livraison->fetch_adresse($idl); } @@ -365,92 +367,105 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') } else { - /* - * Fiche société en mode visu - */ - $livraison = new Livraison($db); - $result=$livraison->fetch($socid); - $nblignes = sizeof($livraison->lignes); - if ($result < 0) - { - dolibarr_print_error($db,$livraison->error); - //exit; - } + /* + * Fiche société en mode visu + */ + $livraison = new AdresseLivraison($db); + $result=$livraison->fetch($socid); + if ($result < 0) + { + dolibarr_print_error($db,$livraison->error); + exit; + } + + $societe=new Societe($db); + $societe->fetch($livraison->socid); + $head = societe_prepare_head($societe); + + dolibarr_fiche_head($head, 'customer', $societe->nom); - $head = societe_prepare_head($livraison); - - dolibarr_fiche_head($head, 'company', $livraison->nom_societe); + // Confirmation de la suppression de la facture + if ($_GET["action"] == 'delete') + { + $html = new Form($db); + $html->form_confirm("adresse_livraison.php?socid=".$livraison->socid."&idl=".$_GET["idl"],$langs->trans("DeleteDeliveryAddress"),$langs->trans("ConfirmDeleteDeliveryAdress"),"confirm_delete"); + print "
\n"; + } + + if ($livraison->error) + { + print '
'; + print $livraison->error; + print '
'; + } + + $nblignes = sizeof($livraison->lignes); + if ($nblignes) + { + for ($i = 0 ; $i < $nblignes ; $i++) + { + + print ''; + + print ''; + print ''; + print ''; + + print ""; + + print '"; + print '"; + + print ''; + print ''; + + print '
'.$langs->trans('DeliveryAddressLabel').''.$livraison->lignes[$i]->label.''.$langs->trans('Note').' :
'.nl2br($livraison->lignes[$i]->note).'
'.$langs->trans('Name').''.$livraison->lignes[$i]->nom.'
".$langs->trans('Address')."".nl2br($livraison->lignes[$i]->adresse)."
'.$langs->trans('Zip').''.$livraison->lignes[$i]->cp."
'.$langs->trans('Town').''.$livraison->lignes[$i]->ville."
'.$langs->trans('Country').''.$livraison->lignes[$i]->pays.'
'; + + + /* + * + */ + + print '
'; + + if ($user->rights->societe->creer) + { + print ''.$langs->trans("Edit").''; + } + + if ($user->rights->societe->supprimer) + { + print ''.$langs->trans("Delete").''; + } + + + print '
'; + print '
'; + } + } + else + { + print $langs->trans("None"); + } + print ''; - // Confirmation de la suppression de la facture - if ($_GET["action"] == 'delete') - { - $html = new Form($db); - $html->form_confirm("adresse_livraison.php?socid=".$livraison->socid."&idl=".$_GET["idl"],$langs->trans("DeleteDeliveryAddress"),$langs->trans("ConfirmDeleteDeliveryAdress"),"confirm_delete"); - print "
\n"; - } + /* + * Bouton actions + */ + + if ($_GET["action"] == '') + { + print '
'; + if ($user->rights->societe->creer) + { + print ''.$langs->trans("Add").''; + } + print '
'; + } - if ($livraison->error) - { - print '
'; - print $livraison->error; - print '
'; - } - - for ($i = 0 ; $i < $nblignes ; $i++) - { - - print ''; - - print ''; - print ''; - print ''; - - print ""; - - print '"; - print '"; - - print ''; - print ''; - - print '
'.$langs->trans('DeliveryAddressLabel').''.$livraison->lignes[$i]->label.''.$langs->trans('Note').' :
'.nl2br($livraison->lignes[$i]->note).'
'.$langs->trans('Name').''.$livraison->lignes[$i]->nom.'
".$langs->trans('Address')."".nl2br($livraison->lignes[$i]->adresse)."
'.$langs->trans('Zip').''.$livraison->lignes[$i]->cp."
'.$langs->trans('Town').''.$livraison->lignes[$i]->ville."
'.$langs->trans('Country').''.$livraison->lignes[$i]->pays.'
'; - - - /* - * - */ - - print '
'; - - if ($user->rights->societe->creer) - { - print ''.$langs->trans("Edit").''; - } - - if ($user->rights->societe->supprimer) - { - print ''.$langs->trans("Delete").''; - } - - - print '
'; - print '
'; - } - print ''; - if ($_GET["action"] == '') - { - print '
'; - - if ($user->rights->societe->creer) - { - print ''.$langs->trans("Add").''; - } - print '
'; - } - } $db->close(); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 36e10bf409e..7b362d32e0f 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1500,7 +1500,7 @@ else print ''.$langs->trans("BuildPDF").''; } - // reBuild PDF + // ReBuild PDF if ($user->rights->commande->creer && $commande->statut >= 3) { print ''.$langs->trans("RebuildPDF").''; @@ -1521,7 +1521,7 @@ else } // Ship - if ($conf->expedition->enabled && $commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer) + if ($commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer) { print ''.$langs->trans('ShipProduct').''; } diff --git a/htdocs/compta/facture/contact.php b/htdocs/compta/facture/contact.php index 7a581aa7ab2..c2ce66b19b9 100644 --- a/htdocs/compta/facture/contact.php +++ b/htdocs/compta/facture/contact.php @@ -212,20 +212,18 @@ $html = new Form($db); /* Mode vue et edition */ /* */ /* *************************************************************************** */ -if ( isset($mesg)) - print $mesg; +if (isset($mesg)) print $mesg; $id = $_GET["facid"]; if ($id > 0) { - $facture = New Facture($db); - if ( $facture->fetch($_GET['facid'], $user->societe_id) > 0) - { - $soc = new Societe($db, $facture->socidp); - $soc->fetch($facture->socidp); + $facture = New Facture($db); + if ( $facture->fetch($_GET['facid'], $user->societe_id) > 0) + { + $facture->fetch_client(); + + $head = facture_prepare_head($facture); - $head = facture_prepare_head($facture); - - dolibarr_fiche_head($head, 'contact', $langs->trans('InvoiceCustomer')); + dolibarr_fiche_head($head, 'contact', $langs->trans('InvoiceCustomer')); /* * Facture synthese pour rappel @@ -238,9 +236,6 @@ if ($id > 0) print ""; // Customer - if ( is_null($facture->client) ) - $facture->fetch_client(); - print "".$langs->trans("Company").""; print ''.$facture->client->getNomUrl(1,'compta').''; print ""; @@ -281,7 +276,7 @@ if ($id > 0) print ''; print ''; - print $conf->global->MAIN_INFO_SOCIETE_NOM; + print $mysoc->nom; print ''; print ''; @@ -338,12 +333,12 @@ if ($id > 0) print "\n"; $societe = new Societe($db); - $var = true; + $var = true; foreach(array('internal','external') as $source) { - $tab = $facture->liste_contact(-1,$source); - $num=sizeof($tab); + $tab = $facture->liste_contact(-1,$source); + $num=sizeof($tab); $i = 0; while ($i < $num) @@ -368,7 +363,7 @@ if ($id > 0) } if ($tab[$i]['socid'] < 0) { - print $conf->global->MAIN_INFO_SOCIETE_NOM; + print $mysoc->nom; } if (! $tab[$i]['socid']) { diff --git a/htdocs/conf/conf.class.php b/htdocs/conf/conf.class.php index f4324b7ee45..31bc2b329fe 100644 --- a/htdocs/conf/conf.class.php +++ b/htdocs/conf/conf.class.php @@ -157,17 +157,16 @@ class Conf $this->commande->dir_output=DOL_DATA_ROOT."/commande"; $this->commande->dir_images=DOL_DATA_ROOT."/commande/images"; - if (defined('MAIN_MODULE_EXPEDITION') && MAIN_MODULE_EXPEDITION) - { - // Module expeditions - $this->expedition->enabled=defined("MAIN_SUBMODULE_EXPEDITION")?MAIN_SUBMODULE_EXPEDITION:0; - $this->expedition->dir_output=DOL_DATA_ROOT."/expedition"; - $this->expedition->dir_images=DOL_DATA_ROOT."/expedition/images"; - // Module bon de livraison - $this->livraison->enabled=defined("MAIN_SUBMODULE_LIVRAISON")?MAIN_SUBMODULE_LIVRAISON:0; - $this->livraison->dir_output=DOL_DATA_ROOT."/livraison"; - $this->livraison->dir_images=DOL_DATA_ROOT."/livraison/images"; - } + // 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_images=DOL_DATA_ROOT."/expedition/images"; + // 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_images=DOL_DATA_ROOT."/livraison/images"; // 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 e25c82982ec..df105fae665 100644 --- a/htdocs/expedition/commande.php +++ b/htdocs/expedition/commande.php @@ -424,9 +424,8 @@ if ($_GET["id"] > 0) } // Bouton expedier avec gestion des stocks - if ($conf->stock->enabled && $reste_a_livrer_total > 0 && ! $commande->brouillon && $user->rights->expedition->creer) + if ($conf->stock->enabled && $reste_a_livrer_total > 0 && $commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer) { - print '
'; print ''; print ''; @@ -587,7 +586,8 @@ if ($_GET["id"] > 0) } $db->free($resql); } - else { + else + { dolibarr_print_error($db); } } diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index 839a99f90d8..ce2b1551f94 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -223,18 +223,20 @@ class Expedition extends CommonObject if ($this->statut == 0) $this->brouillon = 1; - // ligne de produit associée à une expédition $this->lignes = array(); - $sql = "SELECT c.description, c.qty as qtycom, e.qty as qtyexp, e.fk_commande_ligne"; - $sql .= ", c.fk_product, c.label, p.ref"; - $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as e"; - $sql .= " , ".MAIN_DB_PREFIX."commandedet as c"; - $sql .= " , ".MAIN_DB_PREFIX."product as p"; - $sql .= " WHERE e.fk_expedition = ".$this->id; - $sql .= " AND e.fk_commande_ligne = c.rowid"; - $sql .= " AND c.fk_product = p.rowid"; + // TODO Supprimer cette partie. L'appelant qui fetch doit + // en fait appeler fetch_lignes pour charges ceci. + $sql = "SELECT c.description, c.qty as qtycom, c.fk_product, c.label, "; + $sql.= " e.qty as qtyexp, e.fk_commande_ligne,"; + $sql.= " p.ref"; + $sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as e"; + $sql.= " , ".MAIN_DB_PREFIX."commandedet as c"; + $sql.= " , ".MAIN_DB_PREFIX."product as p"; + $sql.= " WHERE e.fk_expedition = ".$this->id; + $sql.= " AND e.fk_commande_ligne = c.rowid"; + $sql.= " AND c.fk_product = p.rowid"; - $resultp = $this->db->query($sql); + $resultp = $this->db->query($sql); if ($resultp) { @@ -245,10 +247,11 @@ class Expedition extends CommonObject { $objp = $this->db->fetch_object($resultp); - $ligne = new ExpeditionLigne(); + $ligne = new ExpeditionLigne($this->db); $ligne->commande_ligne_id = $objp->fk_commande_ligne; $ligne->product_desc = $objp->description; // Description ligne + $ligne->qty_expedition = $objp->qtyexp; $ligne->qty_commande = $objp->qtycom; $ligne->fk_product = $objp->fk_product; @@ -432,7 +435,7 @@ class Expedition extends CommonObject function addline( $id, $qty ) { $num = sizeof($this->lignes); - $ligne = new ExpeditionLigne(); + $ligne = new ExpeditionLigne($this->db); $ligne->commande_ligne_id = $id; $ligne->qty = $qty; @@ -568,13 +571,13 @@ class Expedition extends CommonObject $i = 0; while ($i < $num) { - $ligne = new ExpeditionLigne(); + $ligne = new ExpeditionLigne($this->db); $obj = $this->db->fetch_object($resql); $ligne->fk_product = $obj->fk_product; $ligne->qty_commande = $obj->qtycom; $ligne->qty_expedition = $obj->qtyexp; - $ligne->description = stripslashes($obj->description); + $ligne->description = $obj->description; $this->lignes[$i] = $ligne; $i++; diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index d31ad85308c..07621348ed4 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -36,8 +36,10 @@ require_once(DOL_DOCUMENT_ROOT."/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php"); +$langs->load("companies"); $langs->load("bills"); $langs->load('deliveries'); +$langs->load('orders'); $user->getrights('expedition'); if (!$user->rights->expedition->lire) @@ -183,6 +185,7 @@ if ($_GET["action"] == 'create') $author->fetch(); $entrepot = new Entrepot($db); + /* * Commande */ @@ -190,32 +193,62 @@ if ($_GET["action"] == 'create') print ''; print ''; print ''; - print ''; - print ''; - print ''; - - print '"; + print '
'.$langs->trans("Customer").''.$soc->nom.''; - print "
'; + + // Ref commande + print ''; + print "\n"; + + // Ref commande client + print ''; + print ''; + + // Société + print ''; + print ''; + print ''; + + // Date + print ""; + print '\n"; - print ""; - print "\n"; - print '\n"; - - print ''; - print ''; - print "\n"; - - if ($commande->note) - { - print '"; - } - print "
'.$langs->trans("RefOrder").''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref.'
'; + print ''; + if ($_GET['action'] != 'refcdeclient' && $commande->brouillon) print ''; + print '
'; + print $langs->trans('RefCustomerOrderShort').''; + print ''.img_edit($langs->trans('Edit')).'
'; + print '
'; + if ($user->rights->commande->creer && $_GET['action'] == 'refcdeclient') + { + print ''; + print ''; + print ''; + print ' '; + print ''; + } + else + { + print $commande->ref_client; + } + print '
'.$langs->trans('Company').''.$soc->getNomUrl(1).'
".$langs->trans("Date")."'.dolibarr_print_date($commande->date,"%A %d %B %Y")."
".$langs->trans("Date")."".strftime("%A %d %B %Y",$commande->date)."'.$langs->trans("Order").''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref.''; - print "
'.$langs->trans("Warehouse").''; - $ents = $entrepot->list_array(); - print ''.img_object($langs->trans("ShowWarehouse"),'stock').' '.$ents[$_GET["entrepot_id"]].''; - print '".$langs->trans("Author")."$author->fullname
Note : '.nl2br($commande->note)."
"; + + if ($conf->stock->enabled) + { + print ''.$langs->trans("Warehouse").''; + print ''; + $ents = $entrepot->list_array(); + print ''.img_object($langs->trans("ShowWarehouse"),'stock').' '.$ents[$_GET["entrepot_id"]].''; + print ''; + } + + if ($commande->note) + { + print 'Note : '.nl2br($commande->note).""; + } + + print ""; /* * Lignes de commandes @@ -411,27 +444,34 @@ else // Client print ''.$langs->trans("Customer").''; - print ''.$soc->getNomUrl(1).''; - - // Auteur - print ''.$langs->trans("Author").''.$author->fullname.''; - + print ''.$soc->getNomUrl(1).''; print ""; // Commande liée - print ''.$langs->trans("Order").''; - print ''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref."\n"; - print '  '; + print ''.$langs->trans("RefOrder").''; + print ''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref."\n"; + print ''; + + // Commande liée + print ''.$langs->trans("RefCustomerOrderShort").''; + print ''.$commande->ref_client."\n"; + print ''; // Date print ''.$langs->trans("Date").''; - print "".strftime("%A %d %B %Y",$expedition->date)."\n"; - - // Entrepot - $entrepot = new Entrepot($db); - $entrepot->fetch($expedition->entrepot_id); - print ''.$langs->trans("Warehouse").''.$entrepot->libelle.''; - + print ''.dolibarr_print_date($expedition->date,"%A %d %B %Y")."\n"; + print ''; + + if (!$conf->expedition->enabled && $conf->stock->enabled) + { + // Entrepot + $entrepot = new Entrepot($db); + $entrepot->fetch($expedition->entrepot_id); + print ''.$langs->trans("Warehouse").''; + print ''.$entrepot->libelle.''; + print ''; + } + print "\n"; /* @@ -439,10 +479,10 @@ else */ echo '
'; - $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande"; - $sql .= " , ed.qty as qty_livre"; + $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande,"; + $sql .= " ed.qty as qty_livre"; $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."expeditiondet as ed"; - $sql .= " WHERE ed.fk_expedition = $expedition->id AND cd.rowid = ed.fk_commande_ligne "; + $sql .= " WHERE ed.fk_expedition = ".$expedition->id." AND cd.rowid = ed.fk_commande_ligne "; $resql = $db->query($sql); @@ -573,7 +613,7 @@ else print_titre($langs->trans("OtherSendingsForSameOrder")); print '
'; print ''; - print ''; + print ''; print ''; print ''; print ''; @@ -585,7 +625,7 @@ else $var=!$var; $objp = $db->fetch_object($resql); print ""; - print ''; + print ''; if ($objp->fk_product > 0) { $product = new Product($db); @@ -601,7 +641,7 @@ else print "\n"; } print ''; - print ''; + print ''; print ''; $i++; } @@ -629,7 +669,7 @@ else print_titre("Orders"); print '
'.$langs->trans("Sending").''.$langs->trans("Ref").''.$langs->trans("Description").''.$langs->trans("QtyShipped").''.$langs->trans("Date").'
'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.''.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.'".stripslashes(nl2br($objp->description))."'.$objp->qty_livre.''.dolibarr_print_date($objp->date_expedition).''.dolibarr_print_date($objp->date_expedition).'
'; - print ""; + print ""; print ''; print ''; print ''; diff --git a/htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php b/htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php index f94f7d7d900..a0375eac305 100644 --- a/htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php +++ b/htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php @@ -88,28 +88,28 @@ function expedition_pdf_create($db, $id, $modele='', $outputlangs='') $dir = DOL_DOCUMENT_ROOT."/expedition/mods/pdf/"; $modelisok=0; - $liste=array(); // Positionne modele sur le nom du modele de commande à utiliser $file = "pdf_expedition_".$modele.".modules.php"; - if ($modele && file_exists($dir.$file)) $modelisok=1; + if ($modele && file_exists($dir.$file)) $modelisok=1; // Si model pas encore bon if (! $modelisok) { if ($conf->global->EXPEDITION_ADDON_PDF) $modele = $conf->global->EXPEDITION_ADDON_PDF; $file = "pdf_expedition_".$modele.".modules.php"; - if (file_exists($dir.$file)) $modelisok=1; + if (file_exists($dir.$file)) $modelisok=1; } // Si model pas encore bon if (! $modelisok) { + $liste=array(); $model=new ModelePDFExpedition(); $liste=$model->liste_modeles($db); $modele=key($liste); // Renvoie premiere valeur de clé trouvé dans le tableau $file = "pdf_expedition_".$modele.".modules.php"; - if (file_exists($dir.$file)) $modelisok=1; + if (file_exists($dir.$file)) $modelisok=1; } // Charge le modele @@ -126,11 +126,12 @@ function expedition_pdf_create($db, $id, $modele='', $outputlangs='') $expeditionref = sanitize_string($expedition->ref); $dir = $conf->expedition->dir_output . "/" . $expeditionref; $file = $dir . "/" . $expeditionref . ".pdf"; - if ($obj->generate($expedition, $file)) + + if ($obj->generate($expedition, $file) > 0) // if ( $obj->write_pdf_file($id, $outputlangs) > 0) { // on supprime l'image correspondant au preview -// commande_delete_preview($db, $id); +// expedition_delete_preview($db, $id); return 1; } else @@ -144,7 +145,7 @@ function expedition_pdf_create($db, $id, $modele='', $outputlangs='') { if (! $conf->global->EXPEDITION_ADDON_PDF) { - print $langs->trans("Error")." ".$langs->trans("Error_EPXEDITION_ADDON_PDF_NotDefined"); + print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_PDF_NotDefined"); } else { diff --git a/htdocs/expedition/mods/pdf/pdf_expedition_dorade.modules.php b/htdocs/expedition/mods/pdf/pdf_expedition_dorade.modules.php index 6f52f9de5cc..0e830b7b6bd 100644 --- a/htdocs/expedition/mods/pdf/pdf_expedition_dorade.modules.php +++ b/htdocs/expedition/mods/pdf/pdf_expedition_dorade.modules.php @@ -85,12 +85,47 @@ Class pdf_expedition_dorade extends ModelePdfExpedition } - function generate(&$objExpe, $filename) + function generate(&$objExpe, $filename, $outputlangs='') { + global $user,$conf,$langs,$mysoc; + + if (! is_object($outputlangs)) $outputlangs=$langs; + $outputlangs->load("main"); + $outputlangs->load("companies"); + $outputlangs->load("bills"); + $outputlangs->load("propal"); + $outputlangs->load("products"); + + $outputlangs->setPhpLang(); + $this->expe = $objExpe; $this->expe->fetch_commande(); + // Définition de $dir et $file + if ($this->expe->specimen) + { + $dir = $conf->propal->dir_output; + $file = $dir . "/SPECIMEN.pdf"; + } + else + { + $expref = sanitize_string($this->expe->ref); + $dir = $conf->expedition->dir_output . "/" . $expref; + $file = $dir . "/" . $expref . ".pdf"; + } + + if (! file_exists($dir)) + { + if (create_exdir($dir) < 0) + { + $this->error=$outputlangs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } + + $filename=$file; + $this->pdf = new ModelePdfExpedition(); $this->pdf->expe = &$this->expe; diff --git a/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php b/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php index a91f935f319..7a78bd60bec 100644 --- a/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php +++ b/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php @@ -52,10 +52,19 @@ Class pdf_expedition_merou extends ModelePdfExpedition //Creation du Document //Initialisation des données //***************************** - function generate(&$objExpe, $file) + function generate(&$objExpe, $file, $outputlangs='') { - global $user,$langs,$conf; + global $user,$conf,$langs,$mysoc; + if (! is_object($outputlangs)) $outputlangs=$langs; + $outputlangs->load("main"); + $outputlangs->load("companies"); + $outputlangs->load("bills"); + $outputlangs->load("propal"); + $outputlangs->load("products"); + + $outputlangs->setPhpLang(); + //Initialisation des langues $langs->load("main"); $langs->load("bills"); @@ -63,9 +72,11 @@ Class pdf_expedition_merou extends ModelePdfExpedition //Generation de la fiche $this->expe = $objExpe; $this->expe->fetch_commande(); + //Creation du Client $soc = new Societe($this->db); $soc->fetch($this->expe->commande->socidp); + //Creation de l expediteur $this->expediteur = $soc; //Creation du destinataire @@ -74,6 +85,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition //print_r($pdf->expe); $idcontact = $this->expe->commande->getIdContact('external','DESTINATAIRE'); $this->destinataire->fetch($idcontact[0]); + //Creation du livreur $idcontact = $this->expe->commande->getIdContact('internal','LIVREUR'); $this->livreur = new User($this->db,$idcontact[0]); @@ -85,7 +97,8 @@ Class pdf_expedition_merou extends ModelePdfExpedition $expeditionref = sanitize_string($this->expe->ref); $dir = $conf->expedition->dir_output . "/" . $expeditionref; $file = $dir . "/" . $expeditionref . ".pdf"; - //Si le dossier n existe pas + + //Si le dossier n existe pas if (! file_exists($dir)) { umask(0); @@ -101,7 +114,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition if (file_exists($dir)) { // Initialisation Bon vierge - $pdf = new FPDF('l','mm','A5'); + $pdf = new FPDF('l','mm',$this->format); $pdf->Open(); $pdf->AddPage(); //Generation de l entete du fichier @@ -111,9 +124,13 @@ Class pdf_expedition_merou extends ModelePdfExpedition $pdf->SetAuthor($user->fullname); $pdf->SetMargins(10, 10, 10); $pdf->SetAutoPageBreak(1,0); + + $pdf->SetFont('Arial','', 7); + //Insertion de l entete $this->_pagehead($pdf, $this->expe); - //Initiailisation des coordonnées + + //Initialisation des coordonnées $tab_top = 53; $tab_height = 70; $pdf->SetFillColor(240,240,240); @@ -264,7 +281,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition $pdf->SetXY($Xoff,$Yoff); $pdf->SetFont('Arial','',8); $pdf->SetTextColor(0,0,0); - $pdf->MultiCell(0, 8, "Num Bon de Livraison : ".$exp->ref, '' , 'L'); + $pdf->MultiCell(0, 8, $langs->trans("Ref: ").$exp->ref, '' , 'L'); //$this->Code39($Xoff+43, $Yoff+1, $this->expe->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true); //Num Commande $Yoff = $Yoff+10; @@ -272,7 +289,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition $pdf->SetXY($Xoff,$Yoff); $pdf->SetFont('Arial','',8); $pdf->SetTextColor(0,0,0); - $pdf->MultiCell(0, 8, "Num Commande : ".$exp->commande->ref, '' , 'L'); + $pdf->MultiCell(0, 8, $langs->trans("RefOrder").': '.$exp->commande->ref, '' , 'L'); //$this->Code39($Xoff+43, $Yoff+1, $exp->commande->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true); //Definition Emplacement du bloc Societe $blSocX=11; @@ -345,12 +362,13 @@ Class pdf_expedition_merou extends ModelePdfExpedition $pdf->SetFont('Arial','B',8); $pdf->SetTextColor(0,0,0); $pdf->MultiCell(50, 8, "Livreur(s) : ".$livreur->fullname, '' , 'L'); + /**********************************/ //Emplacement Informations Expediteur (Client) /**********************************/ $Ydef = $Yoff; $blExpX=$Xoff-20; - $blW=50; + $blW=52; $Yoff = $Yoff+5; $Ydef = $Yoff; $blSocY = 1; diff --git a/htdocs/expedition/mods/pdf/pdf_expedition_rouget.modules.php b/htdocs/expedition/mods/pdf/pdf_expedition_rouget.modules.php index 17a53a8541f..807b7cfd4f0 100644 --- a/htdocs/expedition/mods/pdf/pdf_expedition_rouget.modules.php +++ b/htdocs/expedition/mods/pdf/pdf_expedition_rouget.modules.php @@ -66,10 +66,19 @@ Class pdf_expedition_rouget extends ModelePdfExpedition } - function generate(&$objExpe, $filename) + function generate(&$objExpe, $filename, $outputlangs='') { - global $langs; + global $user,$conf,$langs,$mysoc; + if (! is_object($outputlangs)) $outputlangs=$langs; + $outputlangs->load("main"); + $outputlangs->load("companies"); + $outputlangs->load("bills"); + $outputlangs->load("propal"); + $outputlangs->load("products"); + + $outputlangs->setPhpLang(); + $this->expe = $objExpe; $this->pdf = new FPDF(); diff --git a/htdocs/includes/modules/propale/modules_propale.php b/htdocs/includes/modules/propale/modules_propale.php index a6f07caa15a..075bef9dca7 100644 --- a/htdocs/includes/modules/propale/modules_propale.php +++ b/htdocs/includes/modules/propale/modules_propale.php @@ -146,31 +146,41 @@ function propale_pdf_create($db, $id, $modele='', $outputlangs='') $langs->load("propale"); $dir = DOL_DOCUMENT_ROOT."/includes/modules/propale/"; + $modelisok=0; - // Positionne modele sur le nom du modele de facture à utiliser - if (! strlen($modele)) + // Positionne modele sur le nom du modele de propale à utiliser + $file = "pdf_propale_".$modele.".modules.php"; + if ($modele && file_exists($dir.$file)) $modelisok=1; + + // Si model pas encore bon + if (! $modelisok) { - if ($conf->global->PROPALE_ADDON_PDF) - { - $modele = $conf->global->PROPALE_ADDON_PDF; - } - else - { - print $langs->trans("Error")." ".$langs->trans("Error_PROPALE_ADDON_PDF_NotDefined"); - return 0; - } + if ($conf->global->PROPALE_ADDON_PDF) $modele = $conf->global->PROPALE_ADDON_PDF; + $file = "pdf_propale_".$modele.".modules.php"; + if (file_exists($dir.$file)) $modelisok=1; } - // Charge le modele - $file = "pdf_propale_".$modele.".modules.php"; - if (file_exists($dir.$file)) + // Si model pas encore bon + if (! $modelisok) { - $classname = "pdf_propale_".$modele; + $liste=array(); + $model=new ModelePDFPropales(); + $liste=$model->liste_modeles($db); + $modele=key($liste); // Renvoie premiere valeur de clé trouvé dans le tableau + $file = "pdf_propale_".$modele.".modules.php"; + if (file_exists($dir.$file)) $modelisok=1; + } + + + // Charge le modele + if ($modelisok) + { + $classname = "pdf_expedition_".$modele; require_once($dir.$file); $obj = new $classname($db); - if ( $obj->write_pdf_file($id, $outputlangs) > 0) + if ($obj->write_pdf_file($id, $outputlangs) > 0) { // on supprime l'image correspondant au preview propale_delete_preview($db, $id); @@ -185,7 +195,14 @@ function propale_pdf_create($db, $id, $modele='', $outputlangs='') } else { - print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file); + if (! $conf->global->PROPALE_ADDON_PDF) + { + print $langs->trans("Error")." ".$langs->trans("Error_PROPALE_ADDON_PDF_NotDefined"); + } + else + { + print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file); + } return 0; } } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 05cd1a29a09..08065797bf2 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -466,10 +466,6 @@ LDAPSetupForVersion2=LDAP server configured for version 2 ProductSetup=Products module setup NumberOfProductShowInSelect=Max number of products in combos select lists (0=no limit) ConfirmDeleteProductLineAbility=Confirmation of removal of a line produces in the forms -##### Sendings ##### -SendingsSetup=Sending module setup -SendingsReceiptModel=Sending receipt model -SendingsAbility=Support sendings sheets ##### Syslog ##### SyslogSetup=Syslog module setup SyslogOutput=Log output @@ -492,7 +488,11 @@ NewRSS=New RSS ##### Mailing ##### MailingSetup=Mailing module setup MailingEMailFrom=Sender EMail (From) for emails sent by emailing module +##### Sendings ##### +SendingsSetup=Sending module setup +SendingsReceiptModel=Sending receipt model +SendingsAbility=Support sendings sheets for customer deliveries ##### Deliveries ##### -DeliveryOrderNumberingModules=Delivery order numbering module -DeliveryOrderModel=Delivery order model -DeliveriesOrderAbility=Deliveries order ability \ No newline at end of file +DeliveryOrderNumberingModules=Products deliveries receipt numbering module +DeliveryOrderModel=Products deliveries receipt model +DeliveriesOrderAbility=Products deliveries receipt ability \ No newline at end of file diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang index 6100d9042d1..cbaf1e192ba 100755 --- a/htdocs/langs/en_US/orders.lang +++ b/htdocs/langs/en_US/orders.lang @@ -66,6 +66,7 @@ ComptaCard=Accountancy card DraftOrders=Draft orders RelatedOrders=Related orders OnProcessOrders=On process orders +RefOrder=Ref. order RefCustomer=Ref. customer RefCustomerOrder=Ref. customer order CustomerOrder=Customer order diff --git a/htdocs/langs/en_US/sendings.lang b/htdocs/langs/en_US/sendings.lang index 178155308a5..857b11742c8 100644 --- a/htdocs/langs/en_US/sendings.lang +++ b/htdocs/langs/en_US/sendings.lang @@ -15,6 +15,7 @@ CreateASending=Create a sending CreateSending=Create sending QtyOrdered=Qty ordered QtyShipped=Qty shipped +QtyReceived=Qty received KeepToShip=Keep to ship OtherSendingsForSameOrder=Other sendings already shipped SendingsToValidate=Sending to validate \ No newline at end of file diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index bc3233b4c1b..1162e5b1b82 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -116,7 +116,7 @@ Module70Desc=Gestion des interventions Module75Name=Déplacements Module75Desc=Gestion des déplacements Module80Name=Expéditions -Module80Desc=Gestion des expéditions et bons de livraison +Module80Desc=Gestion des expéditions et réceptions client Module85Name=Banques et caisses Module85Desc=Gestion des comptes financiers de type Comptes bancaires, postaux ou Caisses liquides Module86Name=OSCommerce @@ -466,10 +466,6 @@ LDAPSetupForVersion2=Serveur LDAP configur ProductSetup=Configuration du module Produits NumberOfProductShowInSelect=Nombre de produits max dans les listes déroulantes (0=aucune limite) ConfirmDeleteProductLineAbility=Confirmation de suppression d'une ligne produit dans les formulaires -##### Sendings ##### -SendingsSetup=Configuration du module Expéditions/Livraisons -SendingsReceiptModel=Modèle du bordereau d'expédition -SendingsAbility=Prise en charge des bons d'expéditions ##### Syslog ##### SyslogSetup=Configuration du module Syslog SyslogOutput=Sortie des log @@ -492,7 +488,11 @@ NewRSS=Syndication d'un nouveau flux RSS ##### Mailing ##### MailingSetup=Configuration du module EMailing MailingEMailFrom=Email emetteur (From) des mails envoyés par EMailing +##### Sendings ##### +SendingsSetup=Configuration du module Expéditions/Livraisons +SendingsReceiptModel=Modèle du bordereau d'expédition +SendingsAbility=Prise en charge des bons d'expéditions vers le client ##### Deliveries ##### -DeliveryOrderNumberingModules=Module de numérotation des bons de livraison -DeliveryOrderModel=Modèle de bon de livraison -DeliveriesOrderAbility=Prise en charge des bons de livraison +DeliveryOrderNumberingModules=Module de numérotation des bons de réception client +DeliveryOrderModel=Modèle de bon de réception client +DeliveriesOrderAbility=Prise en charge des bons de réception client diff --git a/htdocs/langs/fr_FR/orders.lang b/htdocs/langs/fr_FR/orders.lang index 432dd12ca89..c877e434de6 100755 --- a/htdocs/langs/fr_FR/orders.lang +++ b/htdocs/langs/fr_FR/orders.lang @@ -66,6 +66,7 @@ ComptaCard=Fiche compta DraftOrders=Commandes brouillons RelatedOrders=Commandes rattachées OnProcessOrders=Commandes en cours de traitement +RefOrder=Réf. commande RefCustomer=Réf. client RefCustomerOrder=Réf. commande client CustomerOrder=Commande client diff --git a/htdocs/langs/fr_FR/sendings.lang b/htdocs/langs/fr_FR/sendings.lang index 84b4d7adfba..7823b85142a 100644 --- a/htdocs/langs/fr_FR/sendings.lang +++ b/htdocs/langs/fr_FR/sendings.lang @@ -15,6 +15,7 @@ CreateASending=Cr CreateSending=Créer expedition QtyOrdered=Qté commandée QtyShipped=Qté expédiée +QtyReceived=Qté reçue KeepToShip=Reste à expédier OtherSendingsForSameOrder=Autres expéditions déjà envoyés SendingsToValidate=Expéditions à valider \ No newline at end of file diff --git a/htdocs/lib/order.lib.php b/htdocs/lib/order.lib.php index 49e404bc1fa..3cb1f400663 100644 --- a/htdocs/lib/order.lib.php +++ b/htdocs/lib/order.lib.php @@ -46,7 +46,7 @@ function commande_prepare_head($commande) $h++; } - if ($conf->expedition->enabled && $user->rights->expedition->lire) + if (($conf->expedition->enabled || $conf->livraison->enabled) && $user->rights->expedition->lire) { $head[$h][0] = DOL_URL_ROOT.'/expedition/commande.php?id='.$commande->id; $head[$h][1] = $langs->trans("SendingCard"); @@ -60,7 +60,6 @@ function commande_prepare_head($commande) $head[$h][0] = DOL_URL_ROOT.'/compta/commande/fiche.php?id='.$commande->id; $head[$h][1] = $langs->trans("ComptaCard"); $head[$h][2] = 'accountancy'; - $hselected = $h; $h++; } diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php index c1ff83cb90d..3b6e1618e8e 100644 --- a/htdocs/livraison/fiche.php +++ b/htdocs/livraison/fiche.php @@ -21,8 +21,6 @@ * $Source$ */ - - /** \file htdocs/livraison/fiche.php \ingroup livraison @@ -34,13 +32,9 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/livraison/mods/modules_livraison.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/expedition.class.php"); +if ($conf->stock->enabled) require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php"); -if (!$conf->expedition->enabled && $conf->stock->enabled) -{ - require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php"); -} - - +$langs->load("sendings"); $langs->load("bills"); $langs->load('deliveries'); @@ -423,33 +417,34 @@ else // Client print ''; - print ''; - - // Auteur - print ''; - + print ''; print ""; // Commande liée - print ''; - print '\n"; - print ''; + print ''; + print '\n"; + print ''; + + // Commande liée + print ''; + print '\n"; + print ''; // Date print ''; - print "\n"; - + print '\n"; + print ''; + if (!$conf->expedition->enabled && $conf->stock->enabled) { // Entrepot $entrepot = new Entrepot($db); - $entrepot->fetch($expedition->entrepot_id); - print ''; + $entrepot->fetch($livraison->entrepot_id); + print ''; + print ''; + print ''; } - print ''; - print "
".$langs->trans("Order")." PDF
PDF'.$commande->ref.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
'.$langs->trans("Customer").''; - print ''.$soc->nom.''.$langs->trans("Author").''.$author->fullname.''.$soc->getNomUrl(1).'
'.$langs->trans("Order").''.$commande->ref."  
'.$langs->trans("RefOrder").''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref."
'.$langs->trans("RefCustomerOrderShort").''.$commande->ref_client."
'.$langs->trans("Date").'".dolibarr_print_date($livraison->date_creation,'%A %d %B %Y')."'.dolibarr_print_date($livraison->date_creation,'%A %d %B %Y')."
'.$langs->trans("Warehouse").''.$entrepot->libelle.'
'.$langs->trans("Warehouse").''.$entrepot->libelle.'
\n"; /* @@ -457,10 +452,10 @@ else */ echo '
'; - $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande"; - $sql .= " , ld.qty as qty_livre"; + $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande,"; + $sql .= " ld.qty as qty_livre"; $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."livraisondet as ld"; - $sql .= " WHERE ld.fk_livraison = $livraison->id AND cd.rowid = ld.fk_commande_ligne "; + $sql .= " WHERE ld.fk_livraison = ".$livraison->id." AND cd.rowid = ld.fk_commande_ligne "; $resql = $db->query($sql); @@ -472,7 +467,7 @@ else print ''; print ''; print ''; - print ''; + print ''; print "\n"; $var=true; diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php index baca52931fe..f9c2ef322bc 100644 --- a/htdocs/livraison/livraison.class.php +++ b/htdocs/livraison/livraison.class.php @@ -32,7 +32,7 @@ require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/expedition.class.php"); -/** +/** \class Livraison \brief Classe de gestion des bons de livraison */ @@ -40,7 +40,7 @@ class Livraison extends CommonObject { var $db; var $id; - + var $brouillon; var $commande_id; @@ -69,16 +69,19 @@ class Livraison extends CommonObject function create($user) { global $conf; + + dolibarr_syslog("Livraison::create "); + require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php"; $error = 0; - + /* On positionne en mode brouillon le bon de livraison */ $this->brouillon = 1; - + $this->user = $user; - + $this->db->begin(); - + $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraison (date_creation, fk_user_author, fk_adresse_livraison"; if ($this->commande_id) $sql.= ", fk_commande"; if ($this->expedition_id) $sql.= ", fk_expedition"; @@ -87,48 +90,49 @@ class Livraison extends CommonObject if ($this->commande_id) $sql.= ", $this->commande_id"; if ($this->expedition_id) $sql.= ", $this->expedition_id"; $sql.= ")"; - + $resql=$this->db->query($sql); if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."livraison"); - - $sql = "UPDATE ".MAIN_DB_PREFIX."livraison SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; - if ($this->db->query($sql)) + + $numref="(PROV".$this->id.")"; + $sql = "UPDATE ".MAIN_DB_PREFIX."livraison "; + $sql.= "SET ref='".addslashes($numref)."' WHERE rowid=".$this->id; + $resql=$this->db->query($sql); + if ($resql) { + if (! $conf->expedition->enabled) + { + $commande = new Commande($this->db); + $commande->id = $this->commande_id; + $this->lignes = $commande->fetch_lignes(); + } - if (!$conf->expedition->enabled) - { - $commande = new Commande($this->db); - $commande->id = $this->commande_id; - $lignes = $commande->fetch_lignes(); - } - /* - * Insertion des produits dans la base - */ + * Insertion des produits dans la base + */ for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) { - //TODO - if (! $this->create_line(0, $this->lignes[$i]->commande_ligne_id, $this->lignes[$i]->qty)) - { - $error++; - } + if (! $this->create_line(0, $this->lignes[$i]->commande_ligne_id, $this->lignes[$i]->qty)) + { + $error++; + } } - /* - * - */ - if (!$conf->expedition->enabled) + if (! $conf->expedition->enabled) { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 2 WHERE rowid=".$this->commande_id; - if (! $this->db->query($sql)) + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; + $sql.= " SET fk_statut = 2"; + $sql.= " WHERE rowid=".$this->commande_id; + $resql=$this->db->query($sql); + if (! $resql) { - $error++; - } + $error++; + } } - + if ($error==0) { $this->db->commit(); @@ -137,7 +141,8 @@ class Livraison extends CommonObject else { $error++; - $this->error=$this->db->error()." - sql=$sql"; + $this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; + dolibarr_syslog("Livraison::create Error -3 ".$this->error); $this->db->rollback(); return -3; } @@ -145,7 +150,8 @@ class Livraison extends CommonObject else { $error++; - $this->error=$this->db->error()." - sql=$sql"; + $this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; + dolibarr_syslog("Livraison::create Error -2 ".$this->error); $this->db->rollback(); return -2; } @@ -153,7 +159,8 @@ class Livraison extends CommonObject else { $error++; - $this->error=$this->db->error()." - sql=$sql"; + $this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; + dolibarr_syslog("Livraison::create Error -1 ".$this->error); $this->db->rollback(); return -1; } @@ -168,7 +175,7 @@ class Livraison extends CommonObject $error = 0; $idprod = 0; $j = 0; - + while (($j < sizeof($this->commande->lignes)) && idprod == 0) { if ($this->commande->lignes[$j]->id == $commande_ligne_id) @@ -177,22 +184,22 @@ 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.")"; - + if (! $this->db->query($sql) ) { $error++; } - + if ($error == 0 ) { return 1; } } - - /** + + /** * * Lit un bon de livraison * @@ -200,20 +207,20 @@ class Livraison extends CommonObject function fetch ($id) { global $conf; - + $sql = "SELECT l.rowid, l.date_creation, l.date_valid, l.ref, l.fk_user_author,"; $sql .=" l.fk_statut, l.fk_commande, l.fk_expedition, l.fk_user_valid, l.note, l.note_public"; $sql .= ", ".$this->db->pdate("l.date_livraison")." as date_livraison, l.fk_adresse_livraison, l.model_pdf"; $sql .= ", c.fk_soc"; $sql .= " FROM ".MAIN_DB_PREFIX."livraison as l, ".MAIN_DB_PREFIX."commande as c"; $sql .= " WHERE l.rowid = ".$id." AND c.rowid = l.fk_commande"; - + $result = $this->db->query($sql) ; - + if ( $result ) { $obj = $this->db->fetch_object($result); - + $this->id = $obj->rowid; $this->date_creation = $obj->date_creation; $this->date_valid = $obj->date_valid; @@ -230,15 +237,15 @@ class Livraison extends CommonObject $this->note_public = $obj->note_public; $this->modelpdf = $obj->model_pdf; $this->db->free(); - + if ($this->user_author_id) { $sql = "SELECT name, firstname"; $sql.= " FROM ".MAIN_DB_PREFIX."user"; $sql.= " WHERE rowid = ".$this->user_author_id; - + $resqluser = $this->db->query($sql); - + if ($resqluser) { $obju = $this->db->fetch_object($resqluser); @@ -246,12 +253,12 @@ class Livraison extends CommonObject $this->user_author_firstname = $obju->firstname; } } - + if ($this->statut == 0) $this->brouillon = 1; - + $file = $conf->livraison->dir_output . "/" .get_exdir($livraison->id) . "/" . $this->id.".pdf"; $this->pdf_filename = $file; - + return 1; } else @@ -269,15 +276,15 @@ class Livraison extends CommonObject function valid($user) { global $conf; - + require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php"; - + dolibarr_syslog("livraison.class.php::valid begin"); $this->db->begin(); - + $error = 0; - + if ($user->rights->expedition->livraison->valider) { if (defined('LIVRAISON_ADDON')) @@ -285,7 +292,7 @@ class Livraison extends CommonObject if (is_readable(DOL_DOCUMENT_ROOT .'/livraison/mods/'.LIVRAISON_ADDON.'.php')) { require_once DOL_DOCUMENT_ROOT .'/livraison/mods/'.LIVRAISON_ADDON.'.php'; - + // Definition du nom de module de numerotation de commande $modName=LIVRAISON_ADDON; @@ -293,7 +300,7 @@ class Livraison extends CommonObject $objMod = new $modName($this->db); $soc = new Societe($this->db); $soc->fetch($this->socidp); - + // on vérifie si le bon de livraison est en numérotation provisoire $livref = substr($this->ref, 1, 4); if ($livref == PROV) @@ -304,89 +311,89 @@ class Livraison extends CommonObject { $num = $this->ref; } - + // \todo Tester si non dejà au statut validé. Si oui, on arrete afin d'éviter // de décrémenter 2 fois le stock. - $sql = "UPDATE ".MAIN_DB_PREFIX."livraison SET ref='$num', fk_statut = 1, date_valid=now(), fk_user_valid=$user->id"; - $sql .= " WHERE rowid = $this->id AND fk_statut = 0"; - - if ($this->db->query($sql) ) - { + $sql = "UPDATE ".MAIN_DB_PREFIX."livraison "; + $sql.= " SET ref='".addslashes($num)."', fk_statut = 1, date_valid=now(), fk_user_valid=".$user->id; + $sql.= " WHERE rowid = $this->id AND fk_statut = 0"; + $resql=$this->db->query($sql); + if ($resql) + { + // Si module stock géré et que expedition faite depuis un entrepot + if (!$conf->expedition->enabled && $conf->stock->enabled && $this->entrepot_id) + { - // Si module stock géré et que expedition faite depuis un entrepot - if (!$conf->expedition->enabled && $conf->stock->enabled && $this->entrepot_id) - { - - //Enregistrement d'un mouvement de stock pour chaque produit de l'expedition - + //Enregistrement d'un mouvement de stock pour chaque produit de l'expedition - dolibarr_syslog("livraison.class.php::valid enregistrement des mouvements"); - $sql = "SELECT cd.fk_product, ld.qty "; - $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld"; - $sql.= " WHERE ld.fk_livraison = $this->id AND cd.rowid = ld.fk_commande_ligne"; - - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i=0; - while($i < $num) - { - dolibarr_syslog("livraison.class.php::valid movment $i"); + dolibarr_syslog("livraison.class.php::valid enregistrement des mouvements"); - $obj = $this->db->fetch_object($resql); + $sql = "SELECT cd.fk_product, ld.qty "; + $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld"; + $sql.= " WHERE ld.fk_livraison = $this->id AND cd.rowid = ld.fk_commande_ligne"; - $mouvS = new MouvementStock($this->db); - $result=$mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty); - if ($result < 0) - { - $this->db->rollback(); - $this->error=$this->db->error()." - sql=$sql"; - dolibarr_syslog("livraison.class.php::valid ".$this->error); - return -3; - } - $i++; - } - - } - else - { - $this->db->rollback(); - $this->error=$this->db->error()." - sql=$sql"; - dolibarr_syslog("livraison.class.php::valid ".$this->error); - return -2; - - } - } + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i=0; + while($i < $num) + { + dolibarr_syslog("livraison.class.php::valid movment $i"); - // On efface le répertoire de pdf provisoire - $livraisonref = sanitize_string($this->ref); - if ($conf->expedition->dir_output) + $obj = $this->db->fetch_object($resql); + + $mouvS = new MouvementStock($this->db); + $result=$mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty); + if ($result < 0) { - $dir = $conf->livraison->dir_output . "/" . $livraisonref ; - $file = $dir . "/" . $livraisonref . ".pdf"; - if (file_exists($file)) - { - if (!dol_delete_file($file)) - { - $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); - return 0; - } - } - if (file_exists($dir)) - { - if (!dol_delete_dir($dir)) - { - $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); - return 0; - } - } - } - - dolibarr_syslog("livraison.class.php::valid ok"); - } + $this->db->rollback(); + $this->error=$this->db->error()." - sql=$sql"; + dolibarr_syslog("livraison.class.php::valid ".$this->error); + return -3; + } + $i++; + } + + } + else + { + $this->db->rollback(); + $this->error=$this->db->error()." - sql=$sql"; + dolibarr_syslog("livraison.class.php::valid ".$this->error); + return -2; + + } + } + + // On efface le répertoire de pdf provisoire + $livraisonref = sanitize_string($this->ref); + if ($conf->expedition->dir_output) + { + $dir = $conf->livraison->dir_output . "/" . $livraisonref ; + $file = $dir . "/" . $livraisonref . ".pdf"; + if (file_exists($file)) + { + if (!dol_delete_file($file)) + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); + return 0; + } + } + if (file_exists($dir)) + { + if (!dol_delete_dir($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + return 0; + } + } + } + + dolibarr_syslog("livraison.class.php::valid ok"); + } else { $this->db->rollback(); @@ -411,22 +418,23 @@ class Livraison extends CommonObject /** \brief Créé le bon de livraison depuis une expédition existante \param user Utilisateur qui crée - \param sending_id id de l'expédition qui sert de modèle + \param sending_id Id de l'expédition qui sert de modèle */ function create_from_sending($user, $sending_id) { $expedition = new Expedition($this->db); - $expedition->fetch($sending_id); + $result=$expedition->fetch($sending_id); + $this->lines = array(); $this->date_livraison = time(); $this->expedition_id = $sending_id; for ($i = 0 ; $i < sizeof($expedition->lignes) ; $i++) { - $LivraisonLigne = new LivraisonLigne(); + $LivraisonLigne = new LivraisonLigne($this->db); $LivraisonLigne->commande_ligne_id = $expedition->lignes[$i]->commande_ligne_id; $LivraisonLigne->libelle = $expedition->lignes[$i]->libelle; $LivraisonLigne->description = $expedition->lignes[$i]->product_desc; - $LivraisonLigne->qty = $expedition->lignes[$i]->qty_commande; + $LivraisonLigne->qty = $expedition->lignes[$i]->qty_expedition; $LivraisonLigne->fk_product = $expedition->lignes[$i]->fk_product; $LivraisonLigne->ref = $expedition->lignes[$i]->ref; $this->lignes[$i] = $LivraisonLigne; @@ -449,7 +457,7 @@ class Livraison extends CommonObject function addline( $id, $qty ) { $num = sizeof($this->lignes); - $ligne = new livraisonLigne(); + $ligne = new livraisonLigne($this->db); $ligne->commande_ligne_id = $id; $ligne->qty = $qty; @@ -457,7 +465,7 @@ class Livraison extends CommonObject $this->lignes[$num] = $ligne; } - /** + /** * * */ @@ -466,11 +474,11 @@ class Livraison extends CommonObject if ($this->statut == 0) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet WHERE rowid = $idligne"; - + if ($this->db->query($sql) ) { $this->update_price(); - + return 1; } else @@ -488,13 +496,13 @@ class Livraison extends CommonObject $this->db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraisondet WHERE fk_livraison = $this->id ;"; - if ( $this->db->query($sql) ) + if ( $this->db->query($sql) ) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison WHERE rowid = $this->id;"; - if ( $this->db->query($sql) ) + if ( $this->db->query($sql) ) { $this->db->commit(); - + // On efface le répertoire de pdf provisoire $livref = sanitize_string($this->ref); if ($conf->livraison->dir_output) @@ -518,7 +526,7 @@ class Livraison extends CommonObject } } } - + return 1; } else @@ -544,12 +552,12 @@ class Livraison extends CommonObject $this->commande =& new Commande($this->db); $this->commande->fetch($this->commande_id); } - + /** * * */ - + function fetch_adresse_livraison($id) { $idadresse = $id; @@ -563,7 +571,7 @@ class Livraison extends CommonObject { $this->lignes = array(); - $sql = "SELECT c.label, c.description, c.qty as qtycom, l.qty as qtyliv"; + $sql = "SELECT c.label, c.description, c.qty as qtycom, l.qty as qtyliv"; $sql .= ", c.fk_product, c.price, p.ref"; $sql .= " FROM ".MAIN_DB_PREFIX."livraisondet as l"; $sql .= " , ".MAIN_DB_PREFIX."commandedet as c"; @@ -581,7 +589,7 @@ class Livraison extends CommonObject $i = 0; while ($i < $num) { - $ligne = new LivraisonLigne(); + $ligne = new LivraisonLigne($this->db); $obj = $this->db->fetch_object($resql); @@ -593,9 +601,9 @@ class Livraison extends CommonObject $ligne->description = stripslashes($obj->description); $ligne->price = $obj->price; - $this->lignes[$i] = $ligne; + $this->lignes[$i] = $ligne; $i++; - } + } $this->db->free($resql); }
'.$langs->trans("Products").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyShipped").''.$langs->trans("QtyReceived").'