* Copyright (C) 2005 Laurent Destailleur * Copyright (C) 2005-2006 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. * * $Id$ * $Source$ */ // Code identique a /expedition/fiche.php /** \file htdocs/expedition/commande.php \ingroup expedition \version $Revision$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/project.class.php"); require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/order.lib.php"); $langs->load("bills"); $user->getrights('commande'); $user->getrights('expedition'); if (!$user->rights->commande->lire) accessforbidden(); // Sécurité accés client if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * Actions */ if ($_POST["action"] == 'confirm_cloture' && $_POST["confirm"] == 'yes') { $commande = new Commande($db); $commande->fetch($_GET["id"]); $result = $commande->cloture($user); } $html = new Form($db); /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ llxHeader('',$langs->trans("OrderCard")); if ($_GET["id"] > 0) { $commande = New Commande($db); if ( $commande->fetch($_GET["id"]) > 0) { $commande->livraison_array(1); $soc = new Societe($db); $soc->fetch($commande->soc_id); $author = new User($db); $author->id = $commande->user_author_id; $author->fetch(); $head = commande_prepare_head($commande); dolibarr_fiche_head($head, 'shipping', $langs->trans("CustomerOrder")); /* * Confirmation de la validation * */ if ($_GET["action"] == 'cloture') { $html->form_confirm("commande.php?id=".$_GET["id"],"Clôturer la commande","Etes-vous sûr de vouloir clôturer cette commande ?","confirm_cloture"); print "
"; } // Onglet commande $nbrow=8; if ($conf->projet->enabled) $nbrow++; print ''; // Ref print ''; print ''; print ''; // Ref commande client print ''; print ''; // Société print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Date de livraison print ''; print ''; print ''; // Adresse de livraison print ''; // Conditions et modes de réglement print ''; print ''; // Projet if ($conf->projet->enabled) { $langs->load('projects'); print ''; } // Lignes de 3 colonnes // Total HT print ''; print ''; print ''; // Total TVA print ''; print ''; // Total TTC print ''; print ''; // Statut print ''; print ''; print ''; print '
'.$langs->trans('Ref').''.$commande->ref.'
'; print ''; if ($_GET['action'] != 'refcdeclient') print ''; print '
'; print $langs->trans('RefCustomer').''; 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').''; print ''.$soc->nom.'
'.$langs->trans('Date').''.dolibarr_print_date($commande->date,'%A %d %B %Y').''.$langs->trans('Source').' : ' . $commande->sources[$commande->source] ; if ($commande->source == 0) { // Si source = propal $propal = new Propal($db); $propal->fetch($commande->propale_id); print ' -> '.$propal->ref.''; } print '
'; print ''; if ($_GET['action'] != 'editdate_livraison' && $commande->brouillon) print ''; print '
'; print $langs->trans('DateDelivery'); print 'id.'">'.img_edit($langs->trans('SetDateDelivery'),1).'
'; print '
'; if ($_GET['action'] == 'editdate_livraison') { print '
'; print ''; $html->select_date($commande->date_livraison,'liv_','','','',"setdate_livraison"); print ''; print '
'; } else { print dolibarr_print_date($commande->date_livraison,'%A %d %B %Y'); } print '
'.$langs->trans('NotePublic').' :
'; if ($commande->brouillon == 1 && $user->rights->commande->creer) { print '
'; print ''; print '
'; print '
'; print '
'; } else { print nl2br($commande->note); } print '
'; print ''; if ($_GET['action'] != 'editdelivery_adress' && $commande->brouillon) print ''; print '
'; print $langs->trans('DeliveryAddress'); print 'soc_id.'&id='.$commande->id.'">'.img_edit($langs->trans('SetDeliveryAddress'),1).'
'; print '
'; if ($_GET['action'] == 'editdelivery_adress') { $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'adresse_livraison_id','commande',$commande->id); } else { $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'none','commande',$commande->id); } print '
'; print ''; if ($_GET['action'] != 'editconditions' && $commande->brouillon) print ''; print '
'; print $langs->trans('PaymentConditions'); print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; print '
'; if ($_GET['action'] == 'editconditions') { $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->cond_reglement_id,'cond_reglement_id'); } else { $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->cond_reglement_id,'none'); } print '
'; print ''; if ($_GET['action'] != 'editmode' && $commande->brouillon) print ''; print '
'; print $langs->trans('PaymentMode'); print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; print '
'; if ($_GET['action'] == 'editmode') { $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'mode_reglement_id'); } else { $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'none'); } print '
'; print ''; if ($_GET['action'] != 'classer') print ''; print '
'; print $langs->trans('Project'); print ''.img_edit($langs->trans('SetProject')).'
'; print '
'; if ($_GET['action'] == 'classer') { $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->soc_id, $commande->projet_id, 'projetid'); } else { $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->soc_id, $commande->projet_id, 'none'); } print '
'.$langs->trans('TotalHT').''.price($commande->total_ht).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('TotalVAT').''.price($commande->total_tva).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('TotalTTC').''.price($commande->total_ttc).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('Status').''.$commande->getLibStatut(4).'

'; /** * Lignes de commandes avec quantité livrées et reste à livrer * */ echo ''; $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice"; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as l "; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product = p.rowid"; $sql.= " WHERE l.fk_commande = ".$commande->id; $sql.= " AND p.fk_product_type <> 1"; $sql.= " ORDER BY l.rowid"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; print ''; print ''; print ''; print ''; print ''; if ($conf->stock->enabled) { print ''; } else { print ''; } print "\n"; $var=true; $reste_a_livrer = array(); while ($i < $num) { $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 ''; $reste_a_livrer[$objp->fk_product] = $objp->qty - $quantite_livree; $reste_a_livrer_x = $objp->qty - $quantite_livree; $reste_a_livrer_total = $reste_a_livrer_total + $reste_a_livrer_x; print ''; if ($conf->stock->enabled) { if ($product->stock_reel < $reste_a_livrer_x) { print ''; } else { print ''; } } else { print ''; } print ""; $i++; $var=!$var; } $db->free(); if (! $num) { print '
'.$langs->trans("Description").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyShipped").''.$langs->trans("KeepToShip").''.$langs->trans("Stock").' 
'; print ''; print img_object($langs->trans("Product"),"product").' '.$product->ref.''; print $product->libelle?' - '.$product->libelle:''; print '".stripslashes(nl2br($objp->description))."'.$objp->qty.''; $quantite_livree = $commande->livraisons[$objp->fk_product]; print $quantite_livree; print ''; print $reste_a_livrer[$objp->fk_product]; print ''.$product->stock_reel.''.$product->stock_reel.' 
'.$langs->trans("NoArticleOfTypeProduct").'
'; } print "
"; } else { dolibarr_print_error($db); } print ''; /* * Boutons Actions */ if ($user->societe_id == 0) { print '
'; // Bouton expedier sans gestion des stocks if (! $conf->stock->enabled && $reste_a_livrer_total > 0 && ! $commande->brouillon && $user->rights->expedition->creer) { print ''.$langs->trans("NewSending").''; } print "
"; } // Bouton expedier avec gestion des stocks if ($conf->stock->enabled && $reste_a_livrer_total > 0 && ! $commande->brouillon && $user->rights->expedition->creer) { print '
'; print ''; print ''; print ''; print ''; $entrepot = new Entrepot($db); $langs->load("stocks"); print ''; print ''; print ''; /* print ''; print ''; */ print ''; print "
'.$langs->trans("Warehouse").''; $html->select_array("entrepot_id",$entrepot->list_array()); if (sizeof($entrepot->list_array()) <= 0) { print '   Aucun entrepôt définit, definissez en un'; } print '
Mode d\'expédition'; $html->select_array("entrepot_id",$entrepot->list_array()); print '
'; print ''; print '

"; print "
\n"; } /* * Alerte de seuil */ if ($reste_a_livrer_total > 0 && $conf->stock->enabled) { print '
'; foreach ($reste_a_livrer as $key => $value) { if ($value > 0) { $sql = "SELECT e.label as entrepot, ps.reel, p.label "; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e, ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p"; $sql .= " WHERE e.rowid = ps.fk_entrepot AND ps.fk_product = p.rowid AND ps.fk_product = $key"; $sql .= " AND e.statut = 1 AND reel < $value"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $var=True; while ($i < $num) { $obja = $db->fetch_object($resql); print ""; print ''; print "\n"; $i++; } $db->free($resql); } else { dolibarr_print_error($db); } } } print "
'.$obja->label.''.$obja->entrepot.'Stock : '.$obja->reel.'
"; } /* * 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, 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 = ".$commande->id; $sql .= " AND cd.rowid = ed.fk_commande_ligne"; $sql .= " AND ed.fk_expedition = e.rowid"; $sql .= " AND e.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 ''; $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_expedition).'
'; } $db->free($resql); } else { dolibarr_print_error($db); } } else { /* Commande non trouvée */ print "Commande inexistante"; } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>