* Copyright (C) 2005-2010 Laurent Destailleur * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2005-2010 Regis Houssin * * 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/livraison/fiche.php * \ingroup livraison * \brief Fiche descriptive d'un bon de livraison=reception * \version $Id$ */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/livraison/class/livraison.class.php"); require_once(DOL_DOCUMENT_ROOT."/includes/modules/livraison/modules_livraison.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/sendings.lib.php"); if ($conf->product->enabled || $conf->service->enabled) require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); if ($conf->expedition_bon->enabled) require_once(DOL_DOCUMENT_ROOT."/expedition/class/expedition.class.php"); if ($conf->stock->enabled) require_once(DOL_DOCUMENT_ROOT."/product/stock/class/entrepot.class.php"); if (!$user->rights->expedition->livraison->lire) accessforbidden(); $langs->load("sendings"); $langs->load("bills"); $langs->load('deliveries'); // Security check $id = isset($_GET["id"])?$_GET["id"]:''; if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'expedition',$id,'livraison','livraison'); /* * Actions */ if ($_POST["action"] == 'add') { $db->begin(); // Creation de l'objet livraison $delivery = new Livraison($db); $delivery->date_livraison = time(); $delivery->note = $_POST["note"]; $delivery->commande_id = $_POST["commande_id"]; if (!$conf->expedition_bon->enabled && $conf->stock->enabled) { $expedition->entrepot_id = $_POST["entrepot_id"]; } // On boucle sur chaque ligne de commande pour completer objet livraison // avec qte a livrer $commande = new Commande($db); $commande->fetch($delivery->commande_id); $commande->fetch_lines(); for ($i = 0 ; $i < sizeof($commande->lines) ; $i++) { $qty = "qtyl".$i; $idl = "idl".$i; if ($_POST[$qty] > 0) { $delivery->addline($_POST[$idl],$_POST[$qty]); } } $ret=$delivery->create($user); if ($ret > 0) { $db->commit(); Header("Location: fiche.php?id=".$delivery->id); exit; } else { $db->rollback(); $mesg='
'.$delivery->error.'
'; $_GET["commande_id"]=$_POST["commande_id"]; $_GET["action"]='create'; } } if ($_REQUEST["action"] == 'confirm_valid' && $_REQUEST["confirm"] == 'yes' && $user->rights->expedition->livraison->valider) { $delivery = new Livraison($db); $delivery->fetch($_GET["id"]); $delivery->fetch_thirdparty(); $result = $delivery->valid($user); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$delivery->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } $result=delivery_order_pdf_create($db, $delivery,$_REQUEST['model'],$outputlangs); if ($result <= 0) { dol_print_error($db,$result); exit; } } if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->rights->expedition->livraison->supprimer) { $delivery = new Livraison($db); $delivery->fetch($_GET["id"]); $db->begin(); $result=$delivery->delete(); if ($result > 0) { $db->commit(); Header("Location: ".DOL_URL_ROOT.'/expedition/index.php'); exit; } else { $db->rollback(); } } /* * Build document */ if ($_REQUEST['action'] == 'builddoc') // En get ou en post { $delivery = new Livraison($db); $delivery->fetch($_REQUEST['id']); if ($_REQUEST['model']) { $delivery->setDocModel($user, $_REQUEST['model']); } // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$delivery->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } $result=delivery_order_pdf_create($db, $delivery,$_REQUEST['model'],$outputlangs); if ($result <= 0) { dol_print_error($db,$result); exit; } } /* * View */ llxHeader('',$langs->trans('Delivery'),'Livraison'); $html = new Form($db); $formfile = new FormFile($db); /********************************************************************* * * Mode creation * *********************************************************************/ if ($_GET["action"] == 'create') { print_fiche_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->fetch($commande->user_author_id); if (!$conf->expedition_bon->enabled && $conf->stock->enabled) { $entrepot = new Entrepot($db); } /* * Commande */ print '
'; print ''; print ''; print ''; if (!$conf->expedition_bon->enabled && $conf->stock->enabled) { print ''; } print ''; print ''; print ''; print '"; print ""; print "\n"; print '\n"; print ''; if (!$conf->expedition_bon->enabled && $conf->stock->enabled) { print ''; print ''; } print "\n"; if ($commande->note) { print '"; } print "
'.$langs->trans("Customer").''.$soc->nom.''; print "
".$langs->trans("Date")."".dol_print_date($commande->date,'dayhourtext')."'.$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->getFullName($langs)."
Note : '.nl2br($commande->note)."
"; /* * Lignes de commandes * */ print '
'; $lignes = $commande->fetch_lines(1); // Lecture des livraisons deja effectuees $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) { $product = new Product($db); $ligne = $commande->lignes[$i]; $var=!$var; print "\n"; if ($ligne->fk_product > 0) { $product->fetch($ligne->fk_product); $product->load_stock(); print ''; } else { print "\n"; } print ''; /* * */ print ''; $quantite_commandee = $ligne->qty; $quantite_a_livrer = $quantite_commandee - $quantite_livree; if ($conf->stock->enabled) { $stock = $product->stock_warehouse[$_GET["entrepot_id"]]->real; $stock+=0; // Convertit en numerique // Quantite a livrer print ''; // Stock if ($stock < $quantite_a_livrer) { print ''; } else { print ''; } } else { // Quantite a livrer print ''; } print "\n"; $i++; $var=!$var; } /* * */ print ''; print "
'.$langs->trans("Description").'Quan. commandeeQuan. livreeQuan. a 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->id]; print $quantite_livree;; print ''; print ''; print ''; print ''.$stock.' '.img_warning().''.$stock.''; print ''; print ''; print '

"; print '
'; } else { dol_print_error($db); } } else /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ { if ($_GET["id"] > 0) { $delivery = new Livraison($db); $result = $delivery->fetch($_GET["id"]); $delivery->fetch_thirdparty(); $expedition=new Expedition($db); $result = $expedition->fetch($delivery->expedition_id); $typeobject = $expedition->origin; if ($delivery->origin_id) { $delivery->fetch_origin(); } if ( $delivery->id > 0) { $soc = new Societe($db); $soc->fetch($delivery->socid); $head=delivery_prepare_head($delivery); dol_fiche_head($head, 'delivery', $langs->trans("Sending"), 0, 'sending'); /* * Confirmation de la suppression * */ if ($_GET["action"] == 'delete') { $expedition_id = $_GET["expid"]; $ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$delivery->id.'&expid='.$expedition_id,$langs->trans("DeleteDeliveryReceipt"),$langs->trans("DeleteDeliveryReceiptConfirm"),'confirm_delete','','',1); if ($ret == 'html') print '
'; } /* * Confirmation de la validation * */ if ($_GET["action"] == 'valid') { $ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$delivery->id,$langs->trans("ValidateDeliveryReceipt"),$langs->trans("ValidateDeliveryReceiptConfirm"),'confirm_valid','','',1); if ($ret == 'html') print '
'; } /* * Livraison */ print ''; // Ref print ''; print ''; // Client print ''; print ''; print ""; // Document origine if ($typeobject == 'commande' && $expedition->origin_id && $conf->commande->enabled) { print ''; $order=new Commande($db); $order->fetch($expedition->origin_id); print '\n"; print ''; } if ($typeobject == 'propal' && $expedition->origin_id && $conf->propal->enabled) { $propal=new Propal($db); $propal->fetch($expedition->origin_id); print ''; print '\n"; print ''; } // Ref client print ''; print '\n"; print ''; // Date print ''; print '\n"; print ''; // Date delivery real / Received // TODO Can edit this date, even if validated. print ''; print '\n"; print ''; // Statut print ''; print '\n"; print ''; if (!$conf->expedition_bon->enabled && $conf->stock->enabled) { // Entrepot $entrepot = new Entrepot($db); $entrepot->fetch($delivery->entrepot_id); print ''; print ''; print ''; } print "
'.$langs->trans("Ref").''.$delivery->ref.'
'.$langs->trans("Customer").''.$soc->getNomUrl(1).'
'.$langs->trans("RefOrder").''; print $order->getNomUrl(1,'commande'); print "
'.$langs->trans("RefProposal").''; print $propal->getNomUrl(1,'expedition'); print "
'.$langs->trans("RefCustomer").''.$delivery->ref_customer."
'.$langs->trans("DateCreation").''.dol_print_date($delivery->date_creation,'daytext')."
'.$langs->trans("DateReceived").''.dol_print_date($delivery->date_delivery,'daytext')."
'.$langs->trans("Status").''.$delivery->getLibStatut(4)."
'.$langs->trans("Warehouse").''.$entrepot->libelle.'

\n"; /* * Lignes produits */ $num_prod = sizeof($delivery->lignes); $i = 0; $total = 0; print ''; if ($num_prod) { $i = 0; print ''; print ''; print ''; print ''; print "\n"; } $var=true; while ($i < $num_prod) { $var=!$var; print ""; if ($delivery->lignes[$i]->fk_product > 0) { $product = new Product($db); $product->fetch($delivery->lignes[$i]->fk_product); print '\n"; } print ''; print ''; print ""; $i++; } print "
'.$langs->trans("Products").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyReceived").'
'; // Affiche ligne produit $text = ''; if ($delivery->lignes[$i]->fk_product_type==1) $text.= img_object($langs->trans('ShowService'),'service'); else $text.= img_object($langs->trans('ShowProduct'),'product'); $text.= ' '.$delivery->lignes[$i]->ref.''; $text.= ' - '.$delivery->lignes[$i]->label; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($delivery->lignes[$i]->description)); //print $description; print $html->textwithtooltip($text,$description,3,'','',$i); print_date_range($delivery->lignes[$i]->date_start,$delivery->lignes[$i]->date_end); if ($conf->global->PRODUIT_DESC_IN_FORM) { print ($delivery->lignes[$i]->description && $delivery->lignes[$i]->description!=$delivery->lignes[$i]->label)?'
'.dol_htmlentitiesbr($delivery->lignes[$i]->description):''; } } else { print "
"; if ($delivery->lignes[$i]->fk_product_type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); print $text.' '.nl2br($delivery->lignes[$i]->description); print_date_range($objp->date_start,$objp->date_end); print "'.$delivery->lignes[$i]->qty_asked.''.$delivery->lignes[$i]->qty_shipped.'
\n"; print "\n\n"; /* * Boutons actions */ if ($user->societe_id == 0) { print '
'; if ($delivery->statut == 0 && $user->rights->expedition->livraison->valider && $num_prod > 0) { print ''.$langs->trans("Validate").''; } if ($user->rights->expedition->livraison->supprimer) { if ($conf->expedition_bon->enabled) { print ''.$langs->trans("Delete").''; } else { print ''.$langs->trans("Delete").''; } } print '
'; } print "\n"; print '
'; /* * Documents generated */ $deliveryref = dol_sanitizeFileName($delivery->ref); $filedir = $conf->expedition->dir_output . "/receipt/" . $deliveryref; $urlsource = $_SERVER["PHP_SELF"]."?id=".$delivery->id; $genallowed=$user->rights->expedition->livraison->creer; $delallowed=$user->rights->expedition->livraison->supprimer; $somethingshown=$formfile->show_documents('livraison',$deliveryref,$filedir,$urlsource,$genallowed,$delallowed,$delivery->modelpdf,1,0,0,28,0,'','','',$soc->default_lang); if ($genallowed && ! $somethingshown) $somethingshown=1; print ''; // Rien a droite print '
'; if ($expedition->origin_id) { print '
'; //show_list_sending_receive($expedition->origin,$expedition->origin_id," AND e.rowid <> ".$expedition->id); show_list_sending_receive($expedition->origin,$expedition->origin_id); } } else { /* Expedition non trouvee */ print "Expedition inexistante ou acces refuse"; } } else { /* Expedition non trouvee */ print "Expedition inexistante ou acces refuse"; } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>