* Copyright (C) 2004-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$ */ /** \file htdocs/compta/fiche.php \ingroup commande \brief Fiche commande \version $Revision$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/order.lib.php"); require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/project.class.php"); $langs->load("orders"); $langs->load("companies"); $langs->load("bills"); $user->getrights('commande'); if (! $user->rights->commande->lire) accessforbidden(); // Sécurité accés client if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * Actions */ if ($_GET["action"] == 'facturee') { $commande = new Commande($db); $commande->fetch($_GET["id"]); $commande->classer_facturee(); } llxHeader('',$langs->trans("OrderCard"),"Commande"); $html = new Form($db); /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ if ($_GET["id"] > 0) { $commande = new Commande($db); if ( $commande->fetch($_GET["id"]) > 0) { $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, 'accountancy', $langs->trans("CustomerOrder")); /* * Commande */ $nbrow=8; if ($conf->projet->enabled) $nbrow++; print ''; // Ref print ''; print ''; print ''; // Ref commande client print ''; print ''; // Société print ''; print ''; print ''; // Ligne info remises tiers print ''; // Date 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('Info').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); $aboslute_discount=$soc->getCurrentDiscount(); print '. '; if ($aboslute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); print '.'; print '
'.$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 (1 == 2 && $_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 (1 == 2 && $_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 * */ $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,'; $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid'; $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.= " ORDER BY l.rowid"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $total = 0; if ($num) print '
'; print ''; if ($num) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } $var=true; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; print ''; if ($objp->fk_product > 0) { print ''; } else { print '\n"; } print ''; print '\n"; print ''; if ($objp->remise_percent > 0) { print '\n"; } else { print ''; } print '\n"; print ''; print ''; print ''; print ''; $total = $total + ($objp->qty * $objp->price); $i++; } $db->free($resql); } else { dolibarr_print_error($db); } /* * Lignes de remise */ // Réductions relatives (Remises-Ristournes-Rabbais) /* Une réduction doit s'appliquer obligatoirement sur des lignes de factures et non globalement $var=!$var; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($_GET['action'] != 'editrelativediscount') { if (1 == 2 && $commande->brouillon && $user->rights->facture->creer) { print ''; } else { print ''; } if (1 == 2 && $commande->brouillon && $user->rights->facture->creer && $commande->remise_percent) { print ''; } else { print ''; } print ''; } else { print ''; } print ''; print ''; */ // Réductions (Remises-Ristournes-Rabbais) /* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées $var=!$var; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($_GET['action'] != 'editabsolutediscount') { if (1 == 2 && $commande->brouillon && $user->rights->facture->creer) { print ''; } else { print ''; } if (1 == 2 && $commande->brouillon && $user->rights->facture->creer && $commande->remise_absolue) { print ''; } else { print ''; } print ''; } else { print ''; } print ''; print ''; */ print '
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('Discount').''.$langs->trans('AmountHT').'   
'; if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); else print img_object($langs->trans('ShowProduct'),'product'); print ' '.$objp->ref.' - '.stripslashes(nl2br($objp->product)); print ($objp->description && $objp->description!=$objp->product)?'
'.stripslashes(nl2br($objp->description)):''; print '
'.stripslashes(nl2br($objp->description)); print "'.$objp->tva_tx.'%'.price($objp->subprice)."'.$objp->qty.''.$objp->remise_percent."% '.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."   
'; print $langs->trans('CustomerRelativeDiscount'); if ($commande->brouillon) print ' ('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).')'; print '   '; if ($_GET['action'] == 'editrelativediscount') { print '%'; } else { print $commande->remise_percent?$commande->remise_percent.'%':' '; } print ''; if ($_GET['action'] != 'editrelativediscount') print $commande->remise_percent?'-'.price($commande->remise_percent*$total/100):$langs->trans("DiscountNone"); else print ' '; print 'id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).' rowid.'">'; print img_delete(); print '  
'; print $langs->trans('CustomerAbsoluteDiscount'); if ($commande->brouillon) print ' ('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).')'; print '    '; if ($_GET['action'] == 'editabsolutediscount') { print '-'; } else { print $commande->remise_absolue?'-'.price($commande->remise_absolue):$langs->trans("DiscountNone"); } print 'id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).' rowid.'">'; print img_delete(); print '  
'; print ''; /* * Boutons actions */ if (! $user->societe_id && ! $commande->facturee) { print "
\n"; if ($commande->statut > 0 && $user->rights->facture->creer) { print ''.$langs->trans("CreateBill").''; } if ($commande->statut > 0 && $user->rights->commande->creer) { print ''.$langs->trans("ClassifyBilled").''; } print '
'; } print "
"; /* * Documents générés * */ $file = $conf->facture->dir_output . "/" . $commande->ref . "/" . $commande->ref . ".pdf"; $relativepath = $commande->ref."/".$commande->ref.".pdf"; $var=true; if (file_exists($file)) { print_titre($langs->trans("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"; } /* * Liste des factures */ $sql = "SELECT f.rowid,f.facnumber, f.total_ttc, ".$db->pdate("f.datef")." as df"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."co_fa as cf"; $sql .= " WHERE f.rowid = cf.fk_facture AND cf.fk_commande = ". $commande->id; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); if ($num) { print '
'; print_titre($langs->trans("RelatedBills")); $i = 0; $total = 0; print ''; print '"; print ''; print ''; print "\n"; $var=True; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print ""; print ''; print ''; print ''; $i++; } print "
'.$langs->trans("Ref")."'.$langs->trans("Date").''.$langs->trans("Price").'
'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->facnumber.''.dolibarr_print_date($objp->df).''.$objp->total_ttc.'
"; } } else { dolibarr_print_error($db); } print '
'; /* * Liste des expéditions */ $sql = "SELECT e.rowid,e.ref,".$db->pdate("e.date_expedition")." as de"; $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e"; $sql .= " WHERE e.fk_commande = ". $commande->id; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); if ($num) { print_titre($langs->trans("Sendings")); $i = 0; $total = 0; print ''; print "\n"; $var=True; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print ""; print ''; print "\n"; $i++; } print "
".$langs->trans("Sendings")."".$langs->trans("Date")."
'.img_object($langs->trans("ShowSending"),"sending").' '.$objp->ref.'".dolibarr_print_date($objp->de)."
"; } } else { dolibarr_print_error($db); } print "
"; } else { // Commande non trouvée print "Commande inexistante"; } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>