* Copyright (C) 2005 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$ * */ /** \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; } /* * Actions */ 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(); $db->begin(); 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'; } } 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"); } } /* * Générer ou regénérer le PDF */ if ($_GET["action"] == 'pdf') { $expedition = new Expedition($db); $expedition->fetch($_GET["id"]); $expedition->PdfWrite(); } /* * */ $html = new Form($db); /********************************************************************* * * Mode creation * *********************************************************************/ if ($_GET["action"] == 'create') { llxHeader('','Fiche expedition','ch-expedition.html',$form_search); print_titre($langs->trans("CreateASending")); if ($mesg) { print $mesg.'
'; } $commande = new Commande($db); $commande->livraison_array(); if ( $commande->fetch($_GET["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 "
'.$langs->trans("Customer").''.$soc->nom.''; print "
".$langs->trans("Date")."".strftime("%A %d %B %Y",$commande->date)."'.$langs->trans("Order").': ' . $commande->ref; print "
'.$langs->trans("Warehouse").''; $ents = $entrepot->list_array(); print $ents[$_GET["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 ($conf->stock->enabled) { print ''; } print "\n"; } $var=true; while ($i < $num) { $ligne = $commande->lignes[$i]; $var=!$var; 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. à livrer'.$langs->trans("Stock").'
'; 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 ($conf->stock->enabled) { $stock = $product->stock_entrepot[$_POST["entrepot_id"]]; print ''; print ''.$stock.''.$stock.'

"; 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(); 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"); 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 == 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 "
'.$langs->trans("Customer").''; print ''.$soc->nom.''.$langs->trans("Author").''.$author->fullname.'
'.$langs->trans("Order").''.$commande->ref."  
'.$langs->trans("Date").'".strftime("%A %d %B %Y",$expedition->date)."'.$langs->trans("Warehouse").''.$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); $var=!$var; 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("Products").'Quan. commandéeQuan. livrée
'; print ''.stripslashes(nl2br($objp->description)).'".stripslashes(nl2br($objp->description))."'.$objp->qty_commande.''.$objp->qty_livre.'

\n"; print "\n\n"; /* * */ $file = $expedition->pdf_filename; if (file_exists($file)) { print_titre($langs->trans("Documents")); print ''; print ""; $b = ereg_replace($conf->expedition->dir_output."/","",$file); print ''; print ''; print ''; print "
".$langs->trans("Sending")." PDF'.basename($file).''.filesize($file). ' bytes'.dolibarr_print_date(filemtime($file),"%d %B %Y %H:%M:%S").'
"; } /* * */ if ($user->societe_id == 0) { print '
'; if ($expedition->statut == 0 && $user->rights->expedition->valider && $num_prod > 0) { print ''.$langs->trans("Validate").''; } print ''.$langs->trans('BuildPDF').''; 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('$Date$ - $Revision$'); ?>