* Copyright (C) 2005-2006 Laurent Destailleur * Copyright (C) 2005 Simon TOSSER * * 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$ */ // Code identique a /expedition/commande.php /** \file htdocs/expedition/fiche.php \ingroup expedition \brief Fiche descriptive d'une expedition \version $Revision$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT ."/expedition/mods/pdf/ModelePdfExpedition.class.php"); 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'); $langs->load('stocks'); $user->getrights('expedition'); if (!$user->rights->expedition->lire) accessforbidden(); // Sécurité accés client if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * Actions */ if ($_POST["action"] == 'add') { // \todo Mettre id entrepot sur ligne detail expedition et non sur fiche expedition $db->begin(); // Creation de l'objet expedition $expedition = new Expedition($db); $expedition->date_expedition = time(); $expedition->note = $_POST["note"]; $expedition->commande_id = $_POST["commande_id"]; $expedition->entrepot_id = $_POST["entrepot_id"]; // On boucle sur chaque ligne de commande pour compléter objet expedition // avec qté à livrer $commande = new Commande($db); $commande->fetch($expedition->commande_id); $commande->fetch_lignes(); for ($i = 0 ; $i < sizeof($commande->lignes) ; $i++) { $qty = "qtyl".$i; $idl = "idl".$i; if ($_POST[$qty] > 0) { $expedition->addline($_POST[$idl],$_POST[$qty]); } } $ret=$expedition->create($user); if ($ret > 0) { $db->commit(); Header("Location: fiche.php?id=".$expedition->id); exit; } else { $db->rollback(); $mesg='
'.$expedition->error.'
'; $_GET["commande_id"]=$_POST["commande_id"]; $_GET["action"]='create'; } } /* * Génère un bon de livraison */ if ($_GET["action"] == 'create_delivery' && $conf->livraison->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); } if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->expedition->valider) { $expedition = new Expedition($db); $expedition->fetch($_GET["id"]); $result = $expedition->valid($user); //$expedition->PdfWrite(); } if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') { if ($user->rights->expedition->supprimer ) { $expedition = new Expedition($db); $expedition->fetch($_GET["id"]); $expedition->delete(); Header("Location: liste.php"); } } /* * Générer ou regénérer le PDF */ if ($_REQUEST['action'] == 'builddoc') // En get ou en post { // Sauvegarde le dernier modèle choisi pour générer un document $expedition = new Expedition($db, 0, $_REQUEST['id']); $expedition->fetch($_REQUEST['id']); if ($_REQUEST['model']) { $expedition->set_pdf_model($user, $_REQUEST['model']); } if ($_REQUEST['lang_id']) { $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs"); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } $result=expedition_pdf_create($db, $expedition->id,$expedition->modelpdf,$outputlangs); if ($result <= 0) { dolibarr_print_error($db,$result); exit; } } /* * */ llxHeader('','Fiche expedition','ch-expedition.html',$form_search); $html = new Form($db); /********************************************************************* * * Mode creation * *********************************************************************/ if ($_GET["action"] == 'create') { print_titre($langs->trans("CreateASending")); if ($mesg) { print $mesg.'
'; } $commande = new Commande($db); $commande->expedition_array(); if ( $commande->fetch($_GET["commande_id"])) { $soc = new Societe($db); $soc->fetch($commande->socidp); $author = new User($db); $author->id = $commande->user_author_id; $author->fetch(); $entrepot = new Entrepot($db); /* * Commande */ print '
'; print ''; print ''; if ($_GET["entrepot_id"]) { print ''; } print ''; // Ref commande print ''; print "\n"; // Ref commande client print ''; print ''; // Sociét print ''; print ''; print ''; // Date print ""; print '\n"; // Entrepot (si forcé) if ($conf->stock->enabled && $_GET["entrepot_id"]) { print ''; print ''; } 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("Warehouse").''; $ents = $entrepot->list_array(); print ''.img_object($langs->trans("ShowWarehouse"),'stock').' '.$ents[$_GET["entrepot_id"]].''; print '
'.$langs->trans("NotePrivate").': '.nl2br($commande->note)."
"; /* * Lignes de commandes * */ echo '
'; $lignes = $commande->fetch_lignes(1); /* Lecture des expeditions déjà effectuées */ $commande->expedition_array(); $num = sizeof($commande->lignes); $i = 0; if ($num) { print ''; print ''; print ''; print ''; print ''; if ($conf->stock->enabled) { if ($_GET["entrepot_id"]) { print ''; } else { 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) { $defaultqty=0; if ($_GET["entrepot_id"]) { $stock = $product->stock_entrepot[$_GET["entrepot_id"]]; $stock+=0; // Convertit en numérique $defaultqty=min($quantite_a_livrer, $stock); } // Quantité à livrer print ''; // Stock if ($_GET["entrepot_id"]) { print ''; } else { $array=array(); $sql = "SELECT e.rowid, e.label, ps.reel"; $sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."entrepot as e"; $sql.= " WHERE ps.fk_entrepot = e.rowid AND fk_product = '".$product->id."'"; $result = $db->query($sql) ; if ($result) { $num = $db->num_rows($result); $i=0; if ($num > 0) { while ($i < $num) { $obj = $db->fetch_object($result); $array[$obj->rowid] = $obj->label.' ('.$obj->reel.')'; $i++; } } $db->free($result); } else { $this->error=$db->error(); return -1; } print ''; } } else { // Quantité à livrer print ''; } print "\n"; $i++; $var=!$var; } /* * */ print ''; print "
'.$langs->trans("Description").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyShipped").''.$langs->trans("QtyToShip").''.$langs->trans("Stock").''.$langs->trans("Warehouse").'
'; 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->expeditions[$ligne->fk_product]; print $quantite_livree;; print ''; print ''; print ''; print ''.$stock; if ($stock < $quantite_a_livrer) { print ' '.img_warning($langs->trans("StockTooLow")); } print ''; $html->select_array('warehouse'.$i,$array,'',1,0,0); print ''; print ''; print ''; print '

"; print ''; } else { dolibarr_print_error($db); } } else /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ { if ($_GET["id"] > 0) { $expedition = New Expedition($db); $result = $expedition->fetch($_GET["id"]); if ($expedition->id > 0) { $author = new User($db); $author->id = $expedition->user_author_id; $author->fetch(); $commande = New Commande($db); $commande->fetch($expedition->commande_id); $soc = new Societe($db); $soc->fetch($commande->socidp); $h=0; $head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$expedition->id; $head[$h][1] = $langs->trans("SendingCard"); $hselected = $h; $h++; if ($conf->livraison->enabled && $expedition->livraison_id) { $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$expedition->livraison_id; $head[$h][1] = $langs->trans("DeliveryCard"); $h++; } dolibarr_fiche_head($head, $hselected, $langs->trans("Sending")); /* * Confirmation de la suppression * */ if ($_GET["action"] == 'delete') { $html->form_confirm("fiche.php?id=$expedition->id","Supprimer l'expedition","Etes-vous sûr de vouloir supprimer cette expedition ?","confirm_delete"); print '
'; } /* * Confirmation de la validation * */ if ($_GET["action"] == 'valid') { $html->form_confirm("fiche.php?id=$expedition->id","Valider l'expédition","Etes-vous sûr de vouloir valider cette expédition ?","confirm_valid"); print '
'; } /* * Confirmation de l'annulation * */ if ($_GET["action"] == 'annuler') { $html->form_confirm("fiche.php?id=$expedition->id",$langs->trans("Cancel"),"Etes-vous sûr de vouloir annuler cette commande ?","confirm_cancel"); print '
'; } /* * Commande */ if ($commande->brouillon && $user->rights->commande->creer) { print '
'; 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($expedition->entrepot_id); print ''; print ''; print ''; } print "
'.$langs->trans("Ref").''.$expedition->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($expedition->date,"%A %d %B %Y")."
'.$langs->trans("Status").''.$expedition->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 .= " e.fk_statut, ed.qty as qty_livre"; $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; $sql .= " WHERE e.rowid = ".$expedition->id." AND e.rowid = ed.fk_expedition AND cd.rowid = ed.fk_commande_ligne"; $resql = $db->query($sql); if ($resql) { $num_prod = $db->num_rows($resql); $i = 0; print ''; print ''; print ''; if ($obj->fk_statut <= 1) { print ''; } else { 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("QtyToShip").''.$langs->trans("QtyShipped").'
'; 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 ($expedition->statut == 0 && $user->rights->expedition->valider && $num_prod > 0) { print ''.$langs->trans("Validate").''; } if ($conf->livraison->enabled && $expedition->statut == 1 && $user->rights->expedition->livraison->creer && !$expedition->livraison_id) { print ''.$langs->trans("DeliveryOrder").''; } if ($user->rights->expedition->lire && ($expedition->statut > 0)) { print ''.$langs->trans('BuildPDF').''; } if ($expedition->brouillon && $user->rights->expedition->supprimer) { print ''.$langs->trans("Delete").''; } print '
'; } print "\n"; 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=$html->show_documents('expedition',$expeditionref,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf); if ($genallowed && ! $somethingshown) $somethingshown=1; /* * Autres expeditions */ $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"; $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; $sql .= " WHERE cd.fk_commande = ".$expedition->commande_id; $sql .= " AND e.rowid <> ".$expedition->id; $sql .= " AND cd.rowid = ed.fk_commande_ligne"; $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("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_livre.''.dolibarr_print_date($objp->date_expedition).'
'; } $db->free($resql); } else { dolibarr_print_error($db); } print '
'; // Rien a droite print '
'; } else { dolibarr_print_error($db); } } else { print "Expedition inexistante ou accés refusé"; } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>