diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 7c0f6db6f43..edb54f05694 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -893,6 +893,8 @@ if ($id > 0 || ! empty($ref)) if ($mesg) print $mesg."
"; + $product_static=new Product($db); + $propal = new Propal($db); $propal->fetch($_GET['propalid'],$_GET['ref']); @@ -1230,7 +1232,7 @@ if ($id > 0 || ! empty($ref)) print '
'; /* - * Lignes de propale + * Lines */ print ''; @@ -1292,15 +1294,20 @@ if ($id > 0 || ! empty($ref)) print '\n"; diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 0b21b9ea1ed..146152508d2 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -545,7 +545,8 @@ class Commande extends CommonObject // Added by Matelli (http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) // Add start and end dates to the new line $this->lines[$i]->date_start, - $this->lines[$i]->date_end + $this->lines[$i]->date_end, + $this->lines[$i]->type ); if ($resql < 0) @@ -614,7 +615,7 @@ class Commande extends CommonObject /** - * \brief Ajoute une ligne de produit (associe a un produit/service predefini ou non) + * \brief Add a line * \param commandeid Id de la commande * \param desc Description de la ligne * \param pu_ht Prix unitaire HT @@ -626,8 +627,9 @@ class Commande extends CommonObject * \param fk_remise_exscept Id remise * \param price_base_type HT or TTC * \param pu_ttc Prix unitaire TTC - * \param date_start Start date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - * \param date_end End date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) + * \param date_start Start date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) + * \param date_end End date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) + * \param type Type of line (0=product, 1=service) * \return int >0 si ok, <0 si ko * \see add_product * \remarks Les parametres sont deja cense etre juste et avec valeurs finales a l'appel @@ -635,9 +637,10 @@ class Commande extends CommonObject * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit) * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue) */ - function addline($commandeid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='') + function addline($commandeid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0) { - dol_syslog("Commande::addline commandeid=$commandeid, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start, date_end=$date_end", LOG_DEBUG); + dol_syslog("Commande::addline commandeid=$commandeid, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start, date_end=$date_end, type=$type", LOG_DEBUG); + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); // Clean parameters @@ -658,6 +661,9 @@ class Commande extends CommonObject } $desc=trim($desc); + // Check parameters + if ($type < 0) return -1; + if ($this->statut == 0) { $this->db->begin(); @@ -697,6 +703,7 @@ class Commande extends CommonObject $ligne->total_ht=$total_ht; $ligne->total_tva=$total_tva; $ligne->total_ttc=$total_ttc; + $ligne->product_type=$type; // \TODO Ne plus utiliser $ligne->price=$price; @@ -1597,22 +1604,23 @@ class Commande extends CommonObject /** - * \brief Mets a jour une ligne de commande - * \param rowid Id de la ligne de facture - * \param desc Description de la ligne - * \param pu Prix unitaire - * \param qty Quantity - * \param remise_percent Pourcentage de remise de la ligne - * \param tva_tx Taux TVA - * \param price_base_type HT or TTC - * \param info_bits Miscellanous informations on line - * \param date_start Start date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - * \param date_end End date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - * \return int < 0 si erreur, > 0 si ok + * \brief Update a line in database + * \param rowid Id of line to update + * \param desc Description de la ligne + * \param pu Prix unitaire + * \param qty Quantity + * \param remise_percent Pourcentage de remise de la ligne + * \param tva_tx Taux TVA + * \param price_base_type HT or TTC + * \param info_bits Miscellanous informations on line + * \param date_start Start date of the line + * \param date_end End date of the line + * \param type Type of line (0=product, 1=service) + * \return int < 0 si erreur, > 0 si ok */ - function updateline($rowid, $desc, $pu, $qty, $remise_percent=0, $txtva, $price_base_type='HT', $info_bits=0, $date_start='', $date_end='') + function updateline($rowid, $desc, $pu, $qty, $remise_percent=0, $txtva, $price_base_type='HT', $info_bits=0, $date_start='', $date_end='', $type=0) { - dol_syslog("Commande::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $date_start, $date_end"); + dol_syslog("Commande::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $date_start, $date_end, $type"); include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); if ($this->brouillon) @@ -1660,17 +1668,11 @@ class Commande extends CommonObject $sql.= ",remise_percent='".price2num($remise_percent)."'"; $sql.= ",tva_tx='".price2num($txtva)."'"; $sql.= ",qty='".price2num($qty)."'"; - //if ($date_end) { $sql.= ",date_start='$date_end'"; } - //else { $sql.=',date_start=null'; } - //if ($date_end) { $sql.= ",date_end='$date_end'"; } - //else { $sql.=',date_end=null'; } + $sql.= ",product_type='".$type."'"; $sql.= ",info_bits='".$info_bits."'"; $sql.= ",total_ht='".price2num($total_ht)."'"; $sql.= ",total_tva='".price2num($total_tva)."'"; $sql.= ",total_ttc='".price2num($total_ttc)."'"; - - // Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - // Save the start and end date in the database if ($date_start) { $sql.= ",date_start='".$this->db->idate($date_start)."'"; } else { $sql.=',date_start=null'; } if ($date_end) { $sql.= ",date_end='".$this->db->idate($date_end)."'"; } @@ -2133,6 +2135,7 @@ class CommandeLigne var $fk_facture; var $desc; // Description ligne var $fk_product; // Id produit predefini + var $product_type = 0; // Type 0 = product, 1 = Service var $qty; // Quantite (exemple 2) var $tva_tx; // Taux tva produit/service (exemple 19.6) @@ -2177,7 +2180,7 @@ class CommandeLigne */ function fetch($rowid) { - $sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.description, cd.price, cd.qty, cd.tva_tx,'; + $sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.price, cd.qty, cd.tva_tx,'; $sql.= ' cd.remise, cd.remise_percent, cd.fk_remise_except, cd.subprice,'; $sql.= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc, cd.marge_tx, cd.marque_tx, cd.rang,'; $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc'; @@ -2202,6 +2205,8 @@ class CommandeLigne $this->remise_percent = $objp->remise_percent; $this->fk_remise_except = $objp->fk_remise_except; $this->produit_id = $objp->fk_product; + $this->fk_product = $objp->fk_product; + $this->product_type = $objp->product_type; $this->info_bits = $objp->info_bits; $this->total_ht = $objp->total_ht; $this->total_tva = $objp->total_tva; @@ -2294,7 +2299,7 @@ class CommandeLigne // Insertion dans base de la ligne $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet'; $sql.= ' (fk_commande, description, qty, tva_tx,'; - $sql.= ' fk_product, remise_percent, subprice, price, remise, fk_remise_except,'; + $sql.= ' fk_product, product_type, remise_percent, subprice, price, remise, fk_remise_except,'; $sql.= ' rang, marge_tx, marque_tx,'; // Updated by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) // Insert in the database the start and end dates @@ -2305,6 +2310,7 @@ class CommandeLigne $sql.= " '".price2num($this->tva_tx)."',"; if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; } else { $sql.='null,'; } + $sql.= " '".$this->product_type."',"; $sql.= " '".price2num($this->remise_percent)."',"; $sql.= " ".($this->subprice!=''?"'".price2num($this->subprice)."'":"null").","; $sql.= " ".($this->price!=''?"'".price2num($this->price)."'":"null").","; diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 8c080088f5f..a7256f2fa57 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -289,6 +289,19 @@ if ($_REQUEST['action'] == 'setremiseabsolue' && $user->rights->facture->creer) */ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) { + $result=0; + + if (empty($_POST['idprod']) && $_POST["type"] < 0) + { + $fac->error = $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")) ; + $result = -1 ; + } + if (empty($_POST['idprod']) && empty($_POST["pu"])) + { + $fac->error = $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")) ; + $result = -1 ; + } + if ($_POST['qty'] && (($_POST['pu'] != '' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod'])) { $commande = new Commande($db); @@ -348,6 +361,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) $desc = $prod->description; $desc.= ($prod->description && $_POST['np_desc']) ? ((dol_textishtml($prod->description) || dol_textishtml($_POST['np_desc']))?"
":"\n") : ""; $desc.= $_POST['np_desc']; + $type = $prod->type; } else { @@ -355,48 +369,53 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) $tva_tx=eregi_replace('\*','',$_POST['tva_tx']); $tva_npr=eregi('\*',$_POST['tva_tx'])?1:0; $desc=$_POST['dp_desc']; + $type=$_POST["type"]; } $desc=dol_htmlcleanlastbr($desc); $info_bits=0; if ($tva_npr) $info_bits |= 0x01; - if($prod->price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($prod->price_min))) + if ($result >= 0) { - $mesg = '
'.$langs->trans("CantBeLessThanMinPrice",price2num($prod->price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).'
' ; - } - else - { - // Insert line - $result = $commande->addline( - $_POST['id'], - $desc, - $pu_ht, - $_POST['qty'], - $tva_tx, - $_POST['idprod'], - $_POST['remise_percent'], - $info_bits, - 0, - $price_base_type, - $pu_ttc, - $date_start, - $date_end - ); - - if ($result > 0) + if($prod->price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($prod->price_min))) { - $outputlangs = $langs; - if (! empty($_REQUEST['lang_id'])) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); + $mesg = '
'.$langs->trans("CantBeLessThanMinPrice",price2num($prod->price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).'
' ; } else { - $mesg='
'.$commande->error.'
'; + // Insert line + $result = $commande->addline( + $_POST['id'], + $desc, + $pu_ht, + $_POST['qty'], + $tva_tx, + $_POST['idprod'], + $_POST['remise_percent'], + $info_bits, + 0, + $price_base_type, + $pu_ttc, + $date_start, + $date_end, + $type + ); + + if ($result > 0) + { + $outputlangs = $langs; + if (! empty($_REQUEST['lang_id'])) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); + } + else + { + $mesg='
'.$commande->error.'
'; + } } } } @@ -411,9 +430,11 @@ if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POS if (! $commande->fetch($_POST['id']) > 0) dol_print_error($db); // Clean parameters - $description=dol_htmlcleanlastbr($_POST['eldesc']); + $date_start=''; + $date_end=''; $date_start=dol_mktime(0, 0, 0, $_POST['date_start'.$suffixe.'month'], $_POST['date_start'.$suffixe.'day'], $_POST['date_start'.$suffixe.'year']); $date_end=dol_mktime(0, 0, 0, $_POST['date_end'.$suffixe.'month'], $_POST['date_end'.$suffixe.'day'], $_POST['date_end'.$suffixe.'year']); + $description=dol_htmlcleanlastbr($_POST['eldesc']); // Define info_bits $info_bits=0; @@ -423,11 +444,37 @@ if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POS $vat_rate=$_POST['tva_tx']; $vat_rate=eregi_replace('\*','',$vat_rate); - if ($pruduct->price_min && ($_POST['productid']!='') && ( price2num($_POST['pu'])*(1-price2num($_POST['elremise_percent'])/100) < price2num($pruduct->price_min))) + // Check parameters + if (empty($_POST['productid']) && $_POST["type"] < 0) { - $mesg = '
'.$langs->trans("CantBeLessThanMinPrice",price2num($pruduct->price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).'
' ; + $mesg = '
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'
'; + $result = -1 ; + } + // Check minimum price + if(! empty($_POST['productid'])) + { + $productid = $_POST['productid']; + $product = new Product($db); + $product->fetch($productid); + $type=$product->type; + } + if ($product->price_min && ($_POST['productid']!='') && ( price2num($_POST['pu'])*(1-price2num($_POST['elremise_percent'])/100) < price2num($product->price_min))) + { + $mesg = '
'.$langs->trans("CantBeLessThanMinPrice",price2num($product->price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).'
' ; + $result=-1; + } + + // Define params + if (! empty($_POST['productid'])) + { + $type=$product->type; } else + { + $type=$_POST["type"]; + } + + if ($result >= 0) { $result = $commande->updateline($_POST['elrowid'], $description, @@ -438,7 +485,8 @@ if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POS 'HT', $info_bits, $date_start, - $date_end + $date_end, + $type ); if ($result >= 0) @@ -1110,6 +1158,8 @@ else { if ($mesg) print $mesg.'
'; + $product_static=new Product($db); + $commande = new Commande($db); $result=$commande->fetch($_GET['id'],$_GET['ref']); if ($result > 0) @@ -1402,17 +1452,15 @@ else print "\n"; /* - * Lignes de commandes + * Lines */ - $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, '; + $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.description, l.price, l.qty, l.tva_tx, '; $sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.info_bits,'; $sql.= ' l.total_ht, l.total_tva, l.total_ttc,'; + $sql.= ' '.$db->pdate('l.date_start').' as date_start,'; + $sql.= ' '.$db->pdate('l.date_end').' as date_end,'; $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid, '; $sql.= ' p.description as product_desc'; - // Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - // Load start and end dates - $sql.= ','.$db->pdate('l.date_start').' as date_start,'; - $sql.= ' '.$db->pdate('l.date_end').' as date_end'; $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; @@ -1443,6 +1491,13 @@ else $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; + // Ligne en mode visu if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) { @@ -1452,17 +1507,20 @@ else print ''; @@ -1592,17 +1652,28 @@ else print ''; print ''; print ''; print ''; print '
'; print ''; // ancre pour retourner sur la ligne; - // Affiche ligne produit - $text = ''; - if ($objp->fk_product_type==1) $text.= img_object($langs->trans('ShowService'),'service'); - else $text.= img_object($langs->trans('ShowProduct'),'product'); - $text.= ' '.$objp->ref.''; + // 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; + $text=$product_static->getNomUrl(1); $text.= ' - '.$objp->product; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); + + // Show range print_date_range($objp->date_start,$objp->date_end); + + // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) { print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; @@ -1333,7 +1340,11 @@ if ($id > 0 || ! empty($ref)) } else { - print nl2br($objp->description); + 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($objp->date_start,$objp->date_end); } print "
'; print ''; // ancre pour retourner sur la ligne - // Affiche ligne produit - $text = ''; - if ($objp->fk_product_type==1) $text.= img_object($langs->trans('ShowService'),'service'); - else $text.= img_object($langs->trans('ShowProduct'),'product'); - $text.= ' '.$objp->ref.''; + // 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; + $text=$product_static->getNomUrl(1); $text.= ' - '.$objp->product; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); - // Updated by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - // Print the start and end dates + + // Show range print_date_range($objp->date_start,$objp->date_end); + + // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) { print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; @@ -1496,9 +1554,11 @@ else } else { - print nl2br($objp->description); - // Updated by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - // Print the start and end dates + 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($objp->date_start,$objp->date_end); } print '
'; print ''; // ancre pour retourner sur la ligne + + + // Show product and description if ($objp->fk_product > 0) { print ''; - print ''; - if ($objp->fk_product_type==1) print img_object($langs->trans('ShowService'),'service'); - else print img_object($langs->trans('ShowProduct'),'product'); - print ' '.$objp->ref.''; - print ' - '.nl2br($objp->product); + $product_static->type=$objp->fk_product_type; + $product_static->id=$objp->fk_product; + $product_static->ref=$objp->ref; + $product_static->libelle=$objp->product; + $text=$product_static->getNomUrl(1); + $text.= ' - '.$objp->product; + print $text; print '
'; } - // editeur wysiwyg + else + { + print $html->select_type_of_lines($objp->product_type,'type',1); + if ($conf->produit->enabled && $conf->service->enabled) print '
'; + } + + // Editor wysiwyg if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) { require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); @@ -1611,7 +1682,10 @@ else } else { - print ''; + print ''; } print '
'; diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php index 01ac0e1f4c6..87e032361b5 100644 --- a/htdocs/compta/commande/fiche.php +++ b/htdocs/compta/commande/fiche.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005-2008 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -118,6 +118,8 @@ $id = $_GET['id']; $ref= $_GET['ref']; if ($id > 0 || ! empty($ref)) { + $product_static=new Product($db); + $commande = new Commande($db); if ( $commande->fetch($_GET['id'],$_GET['ref']) > 0) { @@ -207,7 +209,7 @@ if ($id > 0 || ! empty($ref)) print '
'.$langs->trans('Date').''.dol_print_date($commande->date,'daytext').''.$langs->trans('Source').' : '.$commande->getLabelSource(); - if ($commande->source == 0 && $conf->propal->enabled) + if ($commande->source == 0 && $conf->propal->enabled && $commande->propale_id) { // Si source = propal $propal = new Propal($db); @@ -345,10 +347,12 @@ if ($id > 0 || ! empty($ref)) print '
'; /* - * Lignes de commandes + * Lines */ - $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.fk_remise_except, l.remise_percent, l.subprice,'; + $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.description, l.price, l.qty, l.tva_tx, l.fk_remise_except, l.remise_percent, l.subprice,'; $sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc,'; + $sql.= ' '.$db->pdate('l.date_start').' as date_start,'; + $sql.= ' '.$db->pdate('l.date_end').' as date_end,'; $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid,'; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX."commandedet as l"; @@ -381,29 +385,40 @@ if ($id > 0 || ! empty($ref)) 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 ''; if ($objp->fk_product > 0) { print ''; print ''; // ancre pour retourner sur la ligne - // Affiche ligne produit - $text = ''; - if ($objp->fk_product_type==1) $text.= img_object($langs->trans('ShowService'),'service'); - else $text.= img_object($langs->trans('ShowProduct'),'product'); - $text.= ' '.$objp->ref.''; + // 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; + $text=$product_static->getNomUrl(1); $text.= ' - '.$objp->product; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); - // Print the start and end dates + + // Show range print_date_range($objp->date_start,$objp->date_end); + + // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) { print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; } - + print ''; } else @@ -431,7 +446,12 @@ if ($id > 0 || ! empty($ref)) } else { - print nl2br($objp->description); + 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($objp->date_start,$objp->date_end); } print "\n"; } @@ -446,7 +466,7 @@ if ($id > 0 || ! empty($ref)) } else print ' '; print ''; - + if ($objp->remise_percent > 0) { print ''.$objp->remise_percent."%\n"; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index fe701663b6c..6151ba07395 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -976,10 +976,12 @@ if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST $fac = new Facture($db,'',$_POST['facid']); if (! $fac->fetch($_POST['facid']) > 0) dol_print_error($db); + // Clean parameters $date_start=''; $date_end=''; $date_start=dol_mktime($_POST['date_start'.$suffixe.'hour'],$_POST['date_start'.$suffixe.'min'],$_POST['date_start'.$suffixe.'sec'],$_POST['date_start'.$suffixe.'month'],$_POST['date_start'.$suffixe.'day'],$_POST['date_start'.$suffixe.'year']); $date_end=dol_mktime($_POST['date_end'.$suffixe.'hour'],$_POST['date_end'.$suffixe.'min'],$_POST['date_end'.$suffixe.'sec'],$_POST['date_end'.$suffixe.'month'],$_POST['date_end'.$suffixe.'day'],$_POST['date_end'.$suffixe.'year']); + $description=dol_htmlcleanlastbr($_POST['desc']); // Define info_bits $info_bits=0; @@ -992,27 +994,27 @@ if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST // Check parameters if (empty($_POST['productid']) && $_POST["type"] < 0) { - $fac->error = $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")) ; + $mesg = '
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'
'; $result = -1 ; } // Check minimum price if(! empty($_POST['productid'])) { $productid = $_POST['productid']; - $pruduct = new Product($db); - $pruduct->fetch($productid); - $type=$pruduct->type; + $product = new Product($db); + $product->fetch($productid); + $type=$product->type; } - if($pruduct->price_min && ($_POST['productid']!='') && (price2num($_POST['price'])*(1-price2num($_POST['remise_percent'])/100) < price2num($pruduct->price_min))) + if($product->price_min && ($_POST['productid']!='') && (price2num($_POST['price'])*(1-price2num($_POST['remise_percent'])/100) < price2num($product->price_min))) { - $mesg = '
'.$langs->trans("CantBeLessThanMinPrice",price2num($pruduct->price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).'
'; + $mesg = '
'.$langs->trans("CantBeLessThanMinPrice",price2num($product->price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).'
'; $result=-1; } // Define params if (! empty($_POST['productid'])) { - $type=$pruduct->type; + $type=$product->type; } else { @@ -1023,7 +1025,7 @@ if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST if ($result >= 0) { $result = $fac->updateline($_POST['rowid'], - $_POST['desc'], + $description, $_POST['price'], $_POST['qty'], $_POST['remise_percent'], @@ -2682,7 +2684,7 @@ else /* - * Lines of invoice + * Lines */ $sql = 'SELECT l.fk_product, l.product_type, l.description, l.qty, l.rowid, l.tva_taux,'; $sql.= ' l.fk_remise_except,'; diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php index 3b980d73ee5..2c0cacd078b 100644 --- a/htdocs/compta/propal.php +++ b/htdocs/compta/propal.php @@ -138,6 +138,8 @@ if ($id > 0 || ! empty($ref)) { if ($mesg) print "$mesg
"; + $product_static=new Product($db); + $propal = new Propal($db); $propal->fetch($_GET['propalid'],$_GET["ref"]); @@ -310,8 +312,7 @@ if ($id > 0 || ! empty($ref)) print '
'; /* - * Lignes de propale - * + * Lines */ print ''; @@ -350,30 +351,40 @@ if ($id > 0 || ! empty($ref)) { $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; + if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) { print ''; if ($objp->fk_product > 0) { - print ''; } else @@ -401,19 +412,12 @@ if ($id > 0 || ! empty($ref)) } else { - print nl2br($objp->description); - if ($objp->date_start && $objp->date_end) - { - print ' (Du '.dol_print_date($objp->date_start).' au '.dol_print_date($objp->date_end).')'; - } - if ($objp->date_start && ! $objp->date_end) - { - print ' (A partir du '.dol_print_date($objp->date_start).')'; - } - if (! $objp->date_start && $objp->date_end) - { - print " (Jusqu'au ".dol_print_date($objp->date_end).')'; - } + 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($objp->date_start,$objp->date_end); } print "\n"; } diff --git a/htdocs/expedition/commande.php b/htdocs/expedition/commande.php index 84bbfae8735..47fd667f1fc 100644 --- a/htdocs/expedition/commande.php +++ b/htdocs/expedition/commande.php @@ -132,6 +132,8 @@ if ($id > 0 || ! empty($ref)) { $commande->loadExpeditions(1); + $product_static=new Product($db); + $soc = new Societe($db); $soc->fetch($commande->socid); @@ -225,7 +227,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; } - + // Conditions et modes de r�glement print '
'; - if ($objp->fk_product_type==1) - print img_object($langs->trans('ShowService'),'service'); - else - print img_object($langs->trans('ShowProduct'),'product'); - print ' '.$objp->ref.' - '.stripslashes(nl2br($objp->product)); - if ($objp->date_start && $objp->date_end) + print ''; + 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; + $text=$product_static->getNomUrl(1); + $text.= ' - '.$objp->product; + $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); + print $html->textwithtooltip($text,$description,3,'','',$i); + + // Show range + print_date_range($objp->date_start,$objp->date_end); + + // Add description in form + if ($conf->global->PRODUIT_DESC_IN_FORM) { - print ' (Du '.dol_print_date($objp->date_start).' au '.dol_print_date($objp->date_end).')'; + print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; } - if ($objp->date_start && ! $objp->date_end) - { - print ' (A partir du '.dol_print_date($objp->date_start).')'; - } - if (! $objp->date_start && $objp->date_end) - { - print " (Jusqu'au ".dol_print_date($objp->date_end).')'; - } - print ($objp->description && $objp->description!=$objp->product)?'
'.stripslashes(nl2br($objp->description)):''; print '
'.$langs->trans('Date').''.dol_print_date($commande->date,'daytext').''.$langs->trans('Source').' : '.$commande->getLabelSource(); - if ($commande->source == 0) + if ($commande->source == 0 && $conf->propal->enabled && $commande->propale_id) { // Si source = propal $propal = new Propal($db); @@ -269,11 +271,11 @@ if ($id > 0 || ! empty($ref)) 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_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'adresse_livraison_id','commande',$commande->id); @@ -284,7 +286,7 @@ if ($id > 0 || ! empty($ref)) } print '
'; print '
'; @@ -371,14 +373,18 @@ if ($id > 0 || ! empty($ref)) */ print ''; - $sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.price, cd.tva_tx, cd.subprice,"; - $sql.= " qty"; + $sql = "SELECT cd.rowid, cd.fk_product, cd.product_type, cd.description, cd.price, cd.tva_tx, cd.subprice,"; + $sql.= " cd.qty,"; + $sql.= ' '.$db->pdate('cd.date_start').' as date_start,'; + $sql.= ' '.$db->pdate('cd.date_end').' as date_end,'; + $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid,'; + $sql.= ' p.description as product_desc'; $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.rowid"; + $sql.= " ORDER BY cd.rang, cd.rowid"; //print $sql; dol_syslog("commande.php sql=".$sql, LOG_DEBUG); @@ -407,28 +413,36 @@ if ($id > 0 || ! empty($ref)) $reste_a_livrer = array(); while ($i < $num) { - $product = new Product($db); - $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 ""; if ($objp->fk_product > 0) { print '\n"; + print "\n"; } print '';
'; print ''; // ancre pour retourner sur la ligne - $product->fetch($objp->fk_product); - // LDR Add a product line from object product - $text = ''; - if ($product->type==1) $text.= img_object($langs->trans('ShowService'),'service'); - else $text.= img_object($langs->trans('ShowProduct'),'product'); - $text.= ' '.$product->ref.''; - $text.= ' - '.$product->libelle; + // 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; + $text=$product_static->getNomUrl(1); + $text.= ' - '.$objp->product; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); - // Print the start and end dates + + // Show range print_date_range($objp->date_start,$objp->date_end); + + // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) { print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; @@ -438,7 +452,14 @@ if ($id > 0 || ! empty($ref)) } else { - print "
".nl2br($objp->description).""; + 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($objp->date_start,$objp->date_end); + print "'.$objp->qty.'