* Copyright (C) 2005-2010 Laurent Destailleur * Copyright (C) 2005-2010 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. */ // Code identique a /expedition/fiche.php /** * \file htdocs/expedition/shipment.php * \ingroup expedition * \version $Id$ */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/class/expedition.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/order.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/sendings.lib.php"); if ($conf->product->enabled || $conf->service->enabled) require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php"); if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php"); if ($conf->stock->enabled) require_once(DOL_DOCUMENT_ROOT."/product/stock/class/entrepot.class.php"); $langs->load('orders'); $langs->load("companies"); $langs->load("bills"); $langs->load('propal'); $langs->load('deliveries'); $langs->load('stocks'); $id=empty($_GET['id']) ? 0 : intVal($_GET['id']); $action=empty($_GET['action']) ? (empty($_POST['action']) ? '' : $_POST['action']) : $_GET['action']; // Security check $socid=0; if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'commande',$id); /* * Actions */ // Categorisation dans projet if ($_POST['action'] == 'classin') { $commande = new Commande($db); $commande->fetch($_GET['id']); $commande->setProject($_POST['projectid']); } if ($_POST["action"] == 'confirm_cloture' && $_POST["confirm"] == 'yes') { $commande = new Commande($db); $commande->fetch($_GET["id"]); $result = $commande->cloture($user); } // Positionne ref commande client if ($_POST['action'] == 'setrefcustomer' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($_GET['id']); $commande->set_ref_client($user, $_POST['ref_customer']); } if ($_POST['action'] == 'setdatedelivery' && $user->rights->commande->creer) { //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year']; $datelivraison=dol_mktime(0, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']); $commande = new Commande($db); $commande->fetch($_GET['id']); $result=$commande->set_date_livraison($user,$datelivraison); if ($result < 0) { $mesg='
'.$commande->error.'
'; } } if ($_POST['action'] == 'setdeliveryaddress' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($_GET['id']); $commande->set_adresse_livraison($user,$_POST['delivery_address_id']); } if ($_POST['action'] == 'setmode' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($_GET['id']); $result=$commande->mode_reglement($_POST['mode_reglement_id']); if ($result < 0) dol_print_error($db,$commande->error); } if ($_POST['action'] == 'setconditions' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($_GET['id']); $result=$commande->cond_reglement($_POST['cond_reglement_id']); if ($result < 0) dol_print_error($db,$commande->error); } $html = new Form($db); $formproduct = new FormProduct($db); $formfile = new FormFile($db); /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ llxHeader('',$langs->trans('OrderCard'),''); $id = $_GET['id']; $ref= $_GET['ref']; if ($id > 0 || ! empty($ref)) { $commande = new Commande($db); if ( $commande->fetch($_GET['id'],$_GET['ref']) > 0) { $commande->loadExpeditions(1); $product_static=new Product($db); $soc = new Societe($db); $soc->fetch($commande->socid); $author = new User($db); $author->fetch($commande->user_author_id); $head = commande_prepare_head($commande); dol_fiche_head($head, 'shipping', $langs->trans("CustomerOrder"), 0, 'order'); /* * Confirmation de la validation */ if ($_GET["action"] == 'cloture') { $ret=$html->form_confirm($_SERVER['PHP_SELF']."?id=".$_GET["id"],$langs->trans("CloseOrder"),$langs->trans("ConfirmCloseOrder"),"confirm_cloture"); if ($ret == 'html') print '
'; } // Onglet commande $nbrow=7; if ($conf->projet->enabled) $nbrow++; print ''; // Ref print ''; print ''; print ''; // Ref commande client print ''; print ''; // Third party print ''; print ''; print ''; // Discounts for third party print ''; // Date print ''; print ''; print ''; print ''; // Delivery date planed print ''; print ''; print ''; // Delivery address if ($conf->global->COMMANDE_ADD_DELIVERY_ADDRESS) { print ''; } // Terms of payment print ''; // Mode of payment print ''; // Project 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').''; print $html->showrefnav($commande,'ref','',1,'ref','ref'); print '
'; print ''; if ($_GET['action'] != 'RefCustomerOrder' && $commande->brouillon) print ''; print '
'; print $langs->trans('RefCustomer').''; print ''.img_edit($langs->trans('Modify')).'
'; print '
'; if ($user->rights->commande->creer && $_GET['action'] == 'RefCustomerOrder') { print '
'; print ''; print ''; print ''; print ' '; print '
'; } else { print $commande->ref_client; } print '
'.$langs->trans('Company').''.$soc->getNomUrl(1).'
'.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); print '. '; $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL'); $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); $absolute_discount=price2num($absolute_discount,'MT'); $absolute_creditnote=price2num($absolute_creditnote,'MT'); if ($absolute_discount) { if ($commande->statut > 0) { print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)); } else { // Remise dispo de type non avoir $filter='fk_facture_source IS NULL'; print '
'; $html->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$commande->id,0,'remise_id',$soc->id,$absolute_discount,$filter); } } if ($absolute_creditnote) { print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)).'. '; } if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; print '
'.$langs->trans('Date').''.dol_print_date($commande->date,'daytext').''.$langs->trans('Source').' : '.$commande->getLabelSource(); if ($commande->source == 0 && $conf->propal->enabled && $commande->propale_id) { // Si source = propal $propal = new Propal($db); $propal->fetch($commande->propale_id); print ' -> '.$propal->ref.''; } print '
'; print ''; if ($_GET['action'] != 'editdate_livraison') print ''; print '
'; print $langs->trans('DateDeliveryPlanned'); print 'id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'
'; print '
'; if ($_GET['action'] == 'editdate_livraison') { print '
'; print ''; print ''; $html->select_date($commande->date_livraison>0?$commande->date_livraison:-1,'liv_','','','',"setdatedelivery"); print ''; print '
'; } else { print dol_print_date($commande->date_livraison,'daytext'); } print '
'.$langs->trans('NotePublic').' :
'; print nl2br($commande->note_public); print '
'; print ''; if ($_GET['action'] != 'editdelivery_adress' && $commande->brouillon) print ''; print '
'; print $langs->trans('DeliveryAddress'); print 'socid.'&id='.$commande->id.'">'.img_edit($langs->trans('SetDeliveryAddress'),1).'
'; print '
'; if ($_GET['action'] == 'editdelivery_adress') { $html->form_address($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->fk_delivery_address,$_GET['socid'],'delivery_address_id','commande',$commande->id); } else { $html->form_address($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->fk_delivery_address,$_GET['socid'],'none','commande',$commande->id); } print '
'; print ''; if ($_GET['action'] != 'editconditions' && $commande->brouillon) print ''; print '
'; print $langs->trans('PaymentConditionsShort'); 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->socid, $commande->fk_project, 'projectid'); } else { $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->fk_project, 'none'); } print '
'.$langs->trans('AmountHT').''.price($commande->total_ht).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($commande->total_tva).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($commande->total_ttc).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('Status').''.$commande->getLibStatut(4).'

'; /** * Lignes de commandes avec quantite livrees et reste a livrer * Les quantites livrees sont stockees dans $commande->expeditions[fk_product] */ print ''; $sql = "SELECT cd.rowid, cd.fk_product, cd.product_type, cd.description,"; $sql.= " cd.price, cd.tva_tx, cd.subprice,"; $sql.= " cd.qty,"; $sql.= ' cd.date_start,'; $sql.= ' cd.date_end,'; $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,'; $sql.= ' p.description as product_desc, p.fk_product_type as product_type'; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; $sql.= " WHERE cd.fk_commande = ".$commande->id; // $sql.= " AND p.fk_product_type <> 1"; Why this line ? //$sql.= " GROUP by cd.rowid, cd.fk_product"; $sql.= " ORDER BY cd.rang, cd.rowid"; //print $sql; dol_syslog("commande.php sql=".$sql, LOG_DEBUG); $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; // Show product and description $type=$objp->product_type?$objp->product_type:$objp->fk_product_type; // Try to enhance type detection using date_start and date_end for free lines where type // was not saved. if (! empty($objp->date_start)) $type=1; if (! empty($objp->date_end)) $type=1; print ""; // Product label if ($objp->fk_product > 0) { print ''; } else { print "\n"; } // Qty ordered print ''; // Qty already shipped $qtyProdCom=$objp->qty; print ''; // Qty remains to ship print ''; if ($objp->fk_product > 0) { $product = new Product($db); $product->fetch($objp->fk_product); } if ($objp->fk_product > 0 && $type == 0 && $conf->stock->enabled) { print ''; } else { print ''; } print "\n"; // Show subproducts details if ($objp->fk_product > 0 && ! empty($conf->global->PRODUIT_SOUSPRODUITS)) { // Set tree of subproducts in product->sousprods $product->get_sousproduits_arbo(); //var_dump($product->sousprods);exit; // Define a new tree with quantiies recalculated $prods_arbo = $product->get_arbo_each_prod($qtyProdCom); //var_dump($prods_arbo); if(sizeof($prods_arbo) > 0) { foreach($prods_arbo as $key => $value) { print '"; print $value[0]; print ''."\n"; } } } $i++; } $db->free($resql); if (! $num) { print '
'.$langs->trans("Description").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyShipped").''.$langs->trans("KeepToShip").''.$langs->trans("Stock").' 
'; print ''; // ancre pour retourner sur la ligne // Show product and description $product_static->type=$objp->fk_product_type; $product_static->id=$objp->fk_product; $product_static->ref=$objp->ref; $product_static->libelle=$objp->product_label; $text=$product_static->getNomUrl(1); $text.= ' - '.$objp->product_label; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); // Show range print_date_range($db->jdate($objp->date_start),$db->jdate($objp->date_end)); // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) { print ($objp->description && $objp->description!=$objp->product_label)?'
'.dol_htmlentitiesbr($objp->description):''; } print '
"; if ($type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); print $text.' '.nl2br($objp->description); // Show range print_date_range($db->jdate($objp->date_start),$db->jdate($objp->date_end)); print "'.$objp->qty.''; // Nb of sending products for this line of order $quantite_livree = $commande->expeditions[$objp->rowid]; print $quantite_livree; print ''; if ($type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $reste_a_livrer[$objp->fk_product] = $objp->qty - $quantite_livree; $reste_a_livrer_total += $reste_a_livrer[$objp->fk_product]; print $reste_a_livrer[$objp->fk_product]; } else { print '0 ('.$langs->trans("Service").')'; } print ''; print $product->stock_reel; if ($product->stock_reel < $reste_a_livrer[$objp->fk_product]) { print ' '.img_warning($langs->trans("StockTooLow")); } print ' 
'; $img=''; if ($value['stock'] < $value['stock_alert']) { $img=img_warning($langs->trans("StockTooLow")); } print "
      -> ".$value['fullpath']." (".$value['nb'].") ".$value['nb_total']."   ".$value['stock']." ".$img."
'.$langs->trans("NoArticleOfTypeProduct").'
'; } print "
"; } else { dol_print_error($db); } print ''; /* * Boutons Actions */ if ($user->societe_id == 0) { print '
'; // Bouton expedier sans gestion des stocks if (! $conf->stock->enabled && ($commande->statut > 0 && $commande->statut < 3)) { if ($user->rights->expedition->creer) { print ''.$langs->trans("NewSending").''; if ($reste_a_livrer_total <= 0) { print ' '.img_warning($langs->trans("WarningNoQtyLeftToSend")); } } else { print ''.$langs->trans("NewSending").''; } } print "
"; } // Bouton expedier avec gestion des stocks if ($conf->stock->enabled && ($commande->statut > 0 && $commande->statut < 3)) { if ($user->rights->expedition->creer) { print_titre($langs->trans("NewSending")); print '
'; print ''; print ''; print ''; print ''; print ''; $langs->load("stocks"); print ''; if ($conf->stock->enabled) { print ''; print ''; } print ''; print "
'.$langs->trans("WarehouseSource").''; $result=$formproduct->selectWarehouses(-1,'entrepot_id','',1); if ($result <= 0) { print '   No warehouse defined, add one'; } print ''; print ''; if ($reste_a_livrer_total <= 0) { print ' '.img_warning($langs->trans("WarningNoQtyLeftToSend")); } print '
"; print "
\n"; print '
'; $somethingshown=1; } else { print ''; } } show_list_sending_receive('commande',$commande->id); } else { /* Commande non trouvee */ print "Commande inexistante"; } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>