* Copyright (C) 2005 Laurent Destailleur * * 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/expedition/fiche.php \ingroup expedition \brief Fiche descriptive d'une expedition \version $Revision$ */ require("./pre.inc.php"); if (!$user->rights->expedition->lire) accessforbidden(); require("../propal.class.php"); require("../product/stock/entrepot.class.php"); /* * Sécurité accés client */ if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * */ if ($_POST["action"] == 'add') { $expedition = new Expedition($db); $expedition->date_expedition = time(); $expedition->note = $_POST["note"]; $expedition->commande_id = $_POST["commande_id"]; $expedition->entrepot_id = $_POST["entrepot_id"]; $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]); } } $expedition->create($user); $id = $expedition->id; Header("Location:fiche.php?id=$id"); } /* * */ 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->id = $_GET["id"]; $expedition->delete(); Header("Location: liste.php"); } } if ($_GET["action"] == 'pdf') { $expedition = new Expedition($db); $expedition->fetch($_GET["id"]); $expedition->PdfWrite(); } /* * */ $html = new Form($db); /********************************************************************* * * Mode creation * * ************************************************************************/ if ($_POST["action"] == 'create') { llxHeader('','Fiche expedition','ch-expedition.html',$form_search); print_titre("Créer une expédition"); $commande = new Commande($db); $commande->livraison_array(); if ( $commande->fetch($_POST["commande_id"])) { $soc = new Societe($db); $soc->fetch($commande->soc_id); $author = new User($db); $author->id = $commande->user_author_id; $author->fetch(); $entrepot = new Entrepot($db); /* * Commande */ print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print '"; print ""; print "\n"; print '\n"; print ''; print ''; print "\n"; if ($commande->note) { print '"; } print "
Client'.$soc->nom.''; print "
Date".strftime("%A %d %B %Y",$commande->date)."Commande : ' . $commande->ref ; print "
Entrepôt'; $ents = $entrepot->list_array(); print $ents[$_POST["entrepot_id"]]; print '".$langs->trans("Author")."$author->fullname
Note : '.nl2br($commande->note)."
"; /* * Lignes de commandes * */ echo '
'; $lignes = $commande->fetch_lignes(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 (defined("MAIN_MODULE_STOCK")) { print ''; } print "\n"; } $var=True; while ($i < $num) { $ligne = $commande->lignes[$i]; print "\n"; if ($ligne->product_id > 0) { $product = new Product($db); $product->fetch($ligne->product_id); print ''; } else { print "\n"; } print ''; /* * */ print ''; /* * */ print ''; if ($stock < $quantite_a_livrer) { print ''; } else { print ''; } } else { print ''; print ''; } print "\n"; $i++; $var=!$var; } /* * */ print ''; print "
'.$langs->trans("Description").'Quan. commandéeQuan. livréeQuan. à livrerStock
'; print ''.nl2br($ligne->description).'".nl2br($ligne->description)."'.$ligne->qty.''; $quantite_livree = $commande->livraisons[$ligne->product_id]; print $quantite_livree;; print ''; print ''; $quantite_commandee = $ligne->qty; $quantite_a_livrer = $quantite_commandee - $quantite_livree; if (defined("MAIN_MODULE_STOCK")) { $stock = $product->stock_entrepot[$_POST["entrepot_id"]]; print ''; print ''.$stock.''.$stock.'
"; print '
'; } else { print $db->error() . "
$sql";; } } 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(); llxHeader('','Fiche expedition','ch-expedition.html',$form_search,$author); $commande = New Commande($db); $commande->fetch($expedition->commande_id); $soc = new Societe($db); $soc->fetch($commande->soc_id); $h=0; $head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$expedition->id; $head[$h][1] = $langs->trans("SendingCard"); $hselected = $h; $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("Sending")." : ".$expedition->ref); /* * 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"); } /* * 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"); } /* * 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"); } /* * Commande */ if ($commande->brouillon == 1 && $user->rights->commande->creer) { print '
'; print ''; } print '
'; print ''; print ''; print ''; print ""; print ""; print '\n"; print ''; print ""; print "\n"; $entrepot = new Entrepot($db); $entrepot->fetch($expedition->entrepot_id); print ''; print "
Client'; print ''.$soc->nom.''.$langs->trans("Author").''.$author->fullname.'
Commande'.$commande->ref."  
Date".strftime("%A %d %B %Y",$expedition->date)."Entrepôt'.$entrepot->libelle.'
\n"; /* * Lignes * */ echo '
'; $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 "; $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); print ""; if ($objp->fk_product > 0) { print ''; } else { print "\n"; } print ''; print ''; print ""; $i++; $var=!$var; } $db->free($resql); } else { dolibarr_print_error($db); } print "
'.$langs->trans("Description").'Quan. commandéeQuan. livrée
'; print ''.stripslashes(nl2br($objp->description)).'".stripslashes(nl2br($objp->description))."'.$objp->qty_commande.''.$objp->qty_livre.'
\n"; /* * */ $file = $expedition->pdf_filename; if (file_exists($file)) { print '
'; print ""; $b = ereg_replace($conf->expedition->dir_output."/","",$file); print ''; print ''; print ''; print "
".$langs->trans("Sending")." PDF'.basename($file).''.filesize($file). ' bytes'.strftime("%e %B %Y %H:%M:%S",filemtime($file)).'
"; } print "\n\n"; /* * */ if ($user->societe_id == 0) { print '
'; if ($expedition->statut == 0 && $user->rights->expedition->valider && $num_prod > 0) { print ''.$langs->trans("Validate").''; } if ($expedition->brouillon && $user->rights->expedition->supprimer) { print ''.$langs->trans("Delete").''; } print "
"; } /* * Déjà livré * * */ $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande"; $sql .= " , ed.qty as qty_livre, e.ref"; $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) { print '
'; print ''; print ''; print ''; print ''; print ''; print "\n"; $var=True; while ($i < $num) { $objp = $db->fetch_object($resql); print ""; if ($objp->fk_product > 0) { print ''; } else { print "\n"; } print ''; print ''; print ''; $i++; } print '
'.$langs->trans("Description").'Quan. livréeExpédition'.$langs->trans("Date").'
'; print ''.stripslashes(nl2br($objp->description)).'".stripslashes(nl2br($objp->description))."'.$objp->qty_livre.''.$objp->ref.''.dolibarr_print_date($objp->date_expedition).'
'; } $db->free($resql); } /* * Documents générés * */ $file = $conf->commande->dir_output . "/" . $commande->ref . "/" . $commande->ref . ".pdf"; $relativepath = $commande->ref . "/" . $commande->ref . ".pdf"; $var=true; if (file_exists($file)) { print "
"; print_titre("Documents"); print ''; print ""; print ''; print ''; print ''; print ''; print "
".$langs->trans("Order")." PDF'.$commande->ref.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
\n"; print '
'; print_titre("Actions"); /* * Liste des actions * */ $sql = "SELECT ".$db->pdate("a.datea")." as da, a.note"; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; $sql .= " WHERE a.fk_soc = $commande->socidp AND a.fk_action in (9,10)"; $sql .= " AND a.fk_commande = $expedition->id"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num) { $i = 0; print ''; print "\n"; $var=True; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; print ""; print "\n"; print ''; print ""; $i++; } print "
".$langs->trans("Date")."".$langs->trans("Action")."
".strftime("%d %B %Y",$objp->da)."'.stripslashes($objp->note).'
"; } $db->free($resql); } else { dolibarr_print_error($db); } /* * * */ print "
"; } /* * * */ if ($action == 'presend') { $replytoname = $user->fullname; $from_name = $replytoname; $replytomail = $user->email; $from_mail = $replytomail; print "id&action=send\">\n"; print ''; print ''; print "

Envoyer la commande par mail"; print ""; print '"; print ""; print ""; print "
Destinataire'; $form = new Form($db); $form->select_array("destinataire",$soc->contact_email_array()); print "email\">
Expéditeur$from_name$from_mail
Reply-to$replytoname$replytomail
"; 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("Dernière modification $Date$ révision $Revision$"); ?>