* Copyright (C) 2005-2006 Laurent Destailleur * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2007 Franky Van Liedekerke * * 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. * * $Id$ * $Source$ */ /** \file htdocs/livraison/fiche.php \ingroup livraison \brief Fiche descriptive d'un bon de livraison \version $Revision$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/expedition.class.php"); require_once(DOL_DOCUMENT_ROOT."/livraison/livraison.class.php"); require_once(DOL_DOCUMENT_ROOT."/livraison/mods/modules_livraison.php"); if ($conf->stock->enabled) require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php"); $langs->load("sendings"); $langs->load("bills"); $langs->load('deliveries'); $user->getrights('expedition'); if (!$user->rights->expedition->livraison->lire) accessforbidden(); // Sécurité accés client if ($user->societe_id > 0) { $action = ''; $socid = $user->societe_id; } /* * Actions */ if ($_POST["action"] == 'add') { $db->begin(); // Creation de l'objet livraison $livraison = new Livraison($db); $livraison->date_livraison = time(); $livraison->note = $_POST["note"]; $livraison->commande_id = $_POST["commande_id"]; if (!$conf->expedition->enabled && $conf->stock->enabled) { $expedition->entrepot_id = $_POST["entrepot_id"]; } // On boucle sur chaque ligne de commande pour compléter objet livraison // avec qté à livrer $commande = new Commande($db); $commande->fetch($livraison->commande_id); $commande->fetch_lines(); for ($i = 0 ; $i < sizeof($commande->lignes) ; $i++) { $qty = "qtyl".$i; $idl = "idl".$i; if ($_POST[$qty] > 0) { $livraison->addline($_POST[$idl],$_POST[$qty]); } } $ret=$livraison->create($user); if ($ret > 0) { $db->commit(); Header("Location: fiche.php?id=".$livraison->id); exit; } else { $db->rollback(); $mesg='
'.$livraison->error.'
'; $_GET["commande_id"]=$_POST["commande_id"]; $_GET["action"]='create'; } } if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->expedition->livraison->valider) { $livraison = new Livraison($db); $livraison->fetch($_GET["id"]); $result = $livraison->valid($user); //$livraison->PdfWrite(); } if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') { if ($user->rights->expedition->livraison->supprimer ) { $livraison = new Livraison($db); $livraison->fetch($_GET["id"]); $expedition_id = $_GET["expid"]; $livraison->delete(); if ($conf->expedition->enabled) { Header("Location: ".DOL_URL_ROOT.'/expedition/fiche.php?id='.$expedition_id); } else { Header("Location: liste.php"); } } } /* * Générer ou regénérer le PDF */ if ($_REQUEST['action'] == 'builddoc') // En get ou en post { $livraision = new Livraison($db, 0, $_REQUEST['id']); $livraision->fetch($_REQUEST['id']); if ($_REQUEST['model']) { $livraision->set_pdf_model($user, $_REQUEST['model']); } if ($_REQUEST['lang_id']) { $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } $result=delivery_order_pdf_create($db, $_REQUEST['id'],$_REQUEST['model'],$outputlangs); if ($result <= 0) { dolibarr_print_error($db,$result); exit; } } /* * */ $html = new Form($db); /********************************************************************* * * Mode creation * *********************************************************************/ if ($_GET["action"] == 'create') { llxHeader('','Fiche expedition','ch-expedition.html',$form_search); print_titre($langs->trans("CreateADeliveryOrder")); if ($mesg) { print $mesg.'
'; } $commande = new Commande($db); $commande->livraison_array(); if ( $commande->fetch($_GET["commande_id"])) { $soc = new Societe($db); $soc->fetch($commande->socid); $author = new User($db); $author->id = $commande->user_author_id; $author->fetch(); if (!$conf->expedition->enabled && $conf->stock->enabled) { $entrepot = new Entrepot($db); } /* * Commande */ print '
'; print ''; print ''; if (!$conf->expedition->enabled && $conf->stock->enabled) { print ''; } print ''; print ''; print ''; print '"; print ""; print "\n"; print '\n"; print ''; if (!$conf->expedition->enabled && $conf->stock->enabled) { print ''; print ''; } print "\n"; if ($commande->note) { print '"; } print "
'.$langs->trans("Customer").''.$soc->nom.''; print "
".$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)."
"; /* * Lignes de commandes * */ echo '
'; $lignes = $commande->fetch_lines(1); /* Lecture des livraisons déjà effectuées */ $commande->livraison_array(); $num = sizeof($commande->lignes); $i = 0; if ($num) { print ''; print ''; print ''; print ''; print ''; if ($conf->stock->enabled) { print ''; } print "\n"; } $var=true; while ($i < $num) { $ligne = $commande->lignes[$i]; $var=!$var; print "\n"; if ($ligne->fk_product > 0) { $product = new Product($db); $product->fetch($ligne->fk_product); print ''; } else { print "\n"; } print ''; /* * */ print ''; $quantite_commandee = $ligne->qty; $quantite_a_livrer = $quantite_commandee - $quantite_livree; if ($conf->stock->enabled) { $stock = $product->stock_entrepot[$_GET["entrepot_id"]]; $stock+=0; // Convertit en numérique // Quantité à livrer print ''; // Stock if ($stock < $quantite_a_livrer) { print ''; } else { print ''; } } else { // Quantité à livrer print ''; } print "\n"; $i++; $var=!$var; } /* * */ print ''; print "
'.$langs->trans("Description").'Quan. commandéeQuan. livréeQuan. à livrer'.$langs->trans("Stock").'
'; print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; if ($ligne->description) print nl2br($ligne->description); print '".nl2br($ligne->description)."'.$ligne->qty.''; $quantite_livree = $commande->livraisons[$ligne->fk_product]; print $quantite_livree;; print ''; print ''; print ''; print ''.$stock.' '.img_alerte().''.$stock.''; print ''; print ''; print '

"; print '
'; } else { dolibarr_print_error($db); } } else /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ { if ($_GET["id"] > 0) { $livraison = new Livraison($db); $result = $livraison->fetch($_GET["id"]); if ( $livraison->id > 0) { $author = new User($db); $author->id = $livraison->user_author_id; $author->fetch(); llxHeader('','Fiche expedition','ch-expedition.html',$form_search,$author); $commande = New Commande($db); $commande->fetch($livraison->commande_id); $soc = new Societe($db); $soc->fetch($commande->socid); $h=0; if ($conf->expedition->enabled) { $head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$livraison->expedition_id; $head[$h][1] = $langs->trans("SendingCard"); $h++; } $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$livraison->id; $head[$h][1] = $langs->trans("DeliveryCard"); $hselected = $h; $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("Sending")); /* * Confirmation de la suppression * */ if ($_GET["action"] == 'delete') { $expedition_id = $_GET["expid"]; $html->form_confirm("fiche.php?id=$livraison->id&expid=$expedition_id","Supprimer le bon de livraison","Etes-vous sûr de vouloir supprimer ce bon de livraison ?","confirm_delete"); print '
'; } /* * Confirmation de la validation * */ if ($_GET["action"] == 'valid') { $html->form_confirm("fiche.php?id=$livraison->id","Valider le bon de livraison","Etes-vous sûr de vouloir valider ce bon de livraison ?","confirm_valid"); print '
'; } /* * Commande */ if ($commande->brouillon == 1 && $user->rights->commande->creer) { print '
'; } print ''; // Ref print ''; print ''; // Client print ''; print ''; print ""; // Commande liée print ''; print '\n"; print ''; // Commande liée print ''; print '\n"; print ''; // Date print ''; print '\n"; print ''; // Statut print ''; print '\n"; print ''; if (!$conf->expedition->enabled && $conf->stock->enabled) { // Entrepot $entrepot = new Entrepot($db); $entrepot->fetch($livraison->entrepot_id); print ''; print ''; print ''; } print "
'.$langs->trans("Ref").''.$livraison->ref.'
'.$langs->trans("Customer").''.$soc->getNomUrl(1).'
'.$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')."
'.$langs->trans("Status").''.$livraison->getLibStatut(4)."
'.$langs->trans("Warehouse").''.$entrepot->libelle.'
\n"; /* * Lignes produits */ echo '
'; $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 "; $resql = $db->query($sql); if ($resql) { $num_prod = $db->num_rows($resql); $i = 0; print ''; print ''; print ''; print ''; print "\n"; $var=true; while ($i < $num_prod) { $objp = $db->fetch_object($resql); $var=!$var; print ""; if ($objp->fk_product > 0) { $product = new Product($db); $product->fetch($objp->fk_product); print ''; } else { print "\n"; } print ''; print ''; print ""; $i++; $var=!$var; } $db->free($resql); } else { dolibarr_print_error($db); } print "
'.$langs->trans("Products").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyReceived").'
'; print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; if ($objp->description) print '
'.nl2br($objp->description); print '
".stripslashes(nl2br($objp->description))."'.$objp->qty_commande.''.$objp->qty_livre.'
\n"; print "\n\n"; /* * Boutons actions */ if ($user->societe_id == 0) { print '
'; if (! eregi('^(valid|delete)',$_REQUEST["action"])) { if ($livraison->statut == 0 && $user->rights->expedition->livraison->valider && $num_prod > 0) { print ''.$langs->trans("Validate").''; } print ''.$langs->trans('BuildPDF').''; if ($livraison->brouillon && $user->rights->expedition->livraison->supprimer) { if ($conf->expedition->enabled) { print ''.$langs->trans("Delete").''; } else { print ''.$langs->trans("Delete").''; } } } print '
'; } print "\n"; print "
"; /* * Documents générés */ $livraisonref = sanitize_string($livraison->ref); $filedir = $conf->livraison->dir_output . '/' . $livraisonref; $urlsource = $_SERVER["PHP_SELF"]."?id=".$livraison->id; $genallowed=$user->rights->expedition->livraison->creer; $delallowed=$user->rights->expedition->livraison->supprimer; //$genallowed=1; //$delallowed=0; $somethingshown=$html->show_documents('livraison',$livraisonref,$filedir,$urlsource,$genallowed,$delallowed,$livraison->modelpdf); /* * Déjà livre */ $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande"; $sql .= " , ld.qty as qty_livre, l.ref, ld.fk_livraison as livraison_id"; $sql .= ",".$db->pdate("l.date_livraison")." as date_livraison"; $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 .= " AND l.rowid <> ".$livraison->id; $sql .= " AND cd.rowid = ld.fk_commande_ligne"; $sql .= " AND ld.fk_livraison = l.rowid"; $sql .= " AND l.fk_statut > 0"; $sql .= " ORDER BY cd.fk_product"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; if ($num) { 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("Sending").''.$langs->trans("Description").''.$langs->trans("QtyShipped").''.$langs->trans("Date").'
'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.''; print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; if ($objp->description) print nl2br($objp->description); print '".stripslashes(nl2br($objp->description))."'.$objp->qty_livre.''.dolibarr_print_date($objp->date_livraison).'
'; } $db->free($resql); } else { dolibarr_print_error($db); } print '
'; // Rien à droite print '
'; } else { /* Expedition non trouvée */ llxHeader('','Fiche expedition','ch-expedition.html',$form_search); print "Expedition inexistante ou accés refusé"; } } else { /* Expedition non trouvée */ llxHeader('','Fiche expedition','ch-expedition.html',$form_search); print "Expedition inexistante ou accés refusé"; } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>