diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 2718169d1b1..d5c34fb6027 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1252,7 +1252,7 @@ if ($id > 0 || ! empty($ref)) $sql.= ' '.$db->pdate('pt.date_start').' as date_start,'; $sql.= ' '.$db->pdate('pt.date_end').' as date_end,'; $sql.= ' pt.product_type,'; - $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid,'; + $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,'; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid'; @@ -1308,9 +1308,9 @@ if ($id > 0 || ! empty($ref)) $product_static->type=$objp->fk_product_type; $product_static->id=$objp->fk_product; $product_static->ref=$objp->ref; - $product_static->libelle=$objp->product; + $product_static->libelle=$objp->product_label; $text=$product_static->getNomUrl(1); - $text.= ' - '.$objp->product; + $text.= ' - '.$objp->product_label; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); @@ -1320,7 +1320,7 @@ if ($id > 0 || ! empty($ref)) // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) { - print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; + print ($objp->description && $objp->description!=$objp->product_label)?'
'.dol_htmlentitiesbr($objp->description):''; } print ''; @@ -1513,7 +1513,7 @@ if ($id > 0 || ! empty($ref)) 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); + print ' - '.nl2br($objp->product_label); print '
'; } if ($_GET["action"] == 'editline') diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 2a23f0d3c36..8414fb5cb55 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1500,7 +1500,7 @@ else $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.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, '; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid'; @@ -1552,9 +1552,9 @@ else $product_static->type=$objp->fk_product_type; $product_static->id=$objp->fk_product; $product_static->ref=$objp->ref; - $product_static->libelle=$objp->product; + $product_static->libelle=$objp->product_label; $text=$product_static->getNomUrl(1); - $text.= ' - '.$objp->product; + $text.= ' - '.$objp->product_label; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); @@ -1564,7 +1564,7 @@ else // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) { - print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; + print ($objp->description && $objp->description!=$objp->product_label)?'
'.dol_htmlentitiesbr($objp->description):''; } print ''; @@ -1688,9 +1688,9 @@ else $product_static->type=$objp->fk_product_type; $product_static->id=$objp->fk_product; $product_static->ref=$objp->ref; - $product_static->libelle=$objp->product; + $product_static->libelle=$objp->product_label; $text=$product_static->getNomUrl(1); - $text.= ' - '.$objp->product; + $text.= ' - '.$objp->product_label; print $text; print '
'; } diff --git a/htdocs/commonobject.class.php b/htdocs/commonobject.class.php index 85ed93524d4..c203aa72264 100644 --- a/htdocs/commonobject.class.php +++ b/htdocs/commonobject.class.php @@ -778,6 +778,7 @@ class CommonObject // Now update field total_ht, total_ttc and tva $fieldht='total_ht'; if ($this->element == 'facture') $fieldht='total'; + if ($this->element == 'facturerec') $fieldht='total'; $fieldtva='tva'; if ($this->element == 'facture_fourn') $fieldtva='total_tva'; $fieldttc='total_ttc'; diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php index 5c4cb94b59c..66b68802198 100644 --- a/htdocs/compta/commande/fiche.php +++ b/htdocs/compta/commande/fiche.php @@ -359,7 +359,7 @@ if ($id > 0 || ! empty($ref)) $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.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,'; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX."commandedet as l"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid'; @@ -410,9 +410,9 @@ if ($id > 0 || ! empty($ref)) $product_static->type=$objp->fk_product_type; $product_static->id=$objp->fk_product; $product_static->ref=$objp->ref; - $product_static->libelle=$objp->product; + $product_static->libelle=$objp->product_label; $text=$product_static->getNomUrl(1); - $text.= ' - '.$objp->product; + $text.= ' - '.$objp->product_label; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); @@ -422,7 +422,7 @@ if ($id > 0 || ! empty($ref)) // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) { - print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; + print ($objp->description && $objp->description!=$objp->product_label)?'
'.dol_htmlentitiesbr($objp->description):''; } print ''; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 6a3d6239e47..a7171d3d996 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2711,7 +2711,7 @@ else $sql.= ' '.$db->pdate('l.date_start').' as date_start,'; $sql.= ' '.$db->pdate('l.date_end').' as date_end,'; $sql.= ' l.product_type,'; - $sql.= ' p.ref, p.fk_product_type, p.label as product,'; + $sql.= ' p.ref as product_ref, p.fk_product_type, p.label as product_label,'; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON l.fk_product=p.rowid'; @@ -2753,7 +2753,7 @@ else if (! empty($objp->date_start)) $type=1; if (! empty($objp->date_end)) $type=1; - // Ligne en mode visu + // Show line if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) { print ''; @@ -2765,10 +2765,10 @@ else // 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; + $product_static->ref=$objp->product_ref; + $product_static->libelle=$objp->product_label; $text=$product_static->getNomUrl(1); - $text.= ' - '.$objp->product; + $text.= ' - '.$objp->product_label; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); @@ -2776,7 +2776,7 @@ else 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):''; + if ($conf->global->PRODUIT_DESC_IN_FORM) print ($objp->description && $objp->description!=$objp->product_label)?'
'.dol_htmlentitiesbr($objp->description):''; print ''; } @@ -2906,10 +2906,10 @@ else print ''; $product_static->type=$objp->fk_product_type; $product_static->id=$objp->fk_product; - $product_static->ref=$objp->ref; - $product_static->libelle=$objp->product; + $product_static->ref=$objp->product_ref; + $product_static->libelle=$objp->product_label; $text=$product_static->getNomUrl(1); - $text.= ' - '.$objp->product; + $text.= ' - '.$objp->product_label; print $text; print '
'; } diff --git a/htdocs/compta/facture/facture-rec.class.php b/htdocs/compta/facture/facture-rec.class.php index 69394c7e208..31ad6dc5da1 100644 --- a/htdocs/compta/facture/facture-rec.class.php +++ b/htdocs/compta/facture/facture-rec.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2004-2009 Laurent Destailleur * * 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 @@ -18,11 +18,11 @@ */ /** - \file htdocs/compta/facture/facture-rec.class.php - \ingroup facture - \brief Fichier de la classe des factures recurentes - \version $Id$ -*/ + * \file htdocs/compta/facture/facture-rec.class.php + * \ingroup facture + * \brief Fichier de la classe des factures recurentes + * \version $Id$ + */ require_once(DOL_DOCUMENT_ROOT."/notify.class.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); @@ -30,9 +30,9 @@ require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); /** - \class FactureRec - \brief Classe de gestion des factures recurrentes/Modèles -*/ + * \class FactureRec + * \brief Classe de gestion des factures recurrentes/Mod�les + */ class FactureRec extends Facture { var $db ; @@ -44,47 +44,46 @@ class FactureRec extends Facture var $id ; var $socid; // Id client - var $client; // Objet societe client (à charger par fetch_client) + var $client; // Objet societe client (� charger par fetch_client) - var $number; - var $author; - var $date; - var $ref; - var $amount; - var $remise; - var $tva; - var $total; - var $note; - var $db_table; - var $propalid; - var $projetid; + var $number; + var $author; + var $date; + var $ref; + var $amount; + var $remise; + var $tva; + var $total; + var $note; + var $db_table; + var $propalid; + var $projetid; - /** - * \brief Initialisation de la class - * - */ - function FactureRec($DB, $facid=0) - { - $this->db = $DB ; - $this->facid = $facid; - } + /** + * \brief Initialisation de la class + */ + function FactureRec($DB, $facid=0) + { + $this->db = $DB ; + $this->facid = $facid; + } - /** - * \brief Créé la facture recurrente/modele - * \return int <0 si ko, id facture rec crée si ok - */ - function create($user) - { - global $langs; + /** + * \brief Create a predefined invoice + * \return int <0 if KO, id of invoice if OK + */ + function create($user) + { + global $langs; - $error=0; + $error=0; - // Nettoyage parametere + // Clean parameters $this->titre=trim($this->titre); - // Validation parameteres - if (! $this->titre) + // Validate parameters + if (empty($this->titre)) { $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Title")); return -3; @@ -92,73 +91,76 @@ class FactureRec extends Facture $this->db->begin(); - // Charge facture modele - $facsrc=new Facture($this->db); - $result=$facsrc->fetch($this->facid); - if ($result > 0) - { - // On positionne en mode brouillon la facture - $this->brouillon = 1; + // Charge facture modele + $facsrc=new Facture($this->db); + $result=$facsrc->fetch($this->facid); + if ($result > 0) + { + // On positionne en mode brouillon la facture + $this->brouillon = 1; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (titre, fk_soc, datec, amount, remise, note, fk_user_author,fk_projet, fk_cond_reglement, fk_mode_reglement) "; - $sql.= " VALUES ('$this->titre', '$facsrc->socid', ".$this->db->idate(mktime()).", '$facsrc->amount', '$facsrc->remise', '".addslashes($this->note)."','$user->id',"; - $sql.= " ".($facsrc->projetid?"'".$facsrc->projetid."'":"null").", "; - $sql.= " '".$facsrc->cond_reglement_id."',"; - $sql.= " '".$facsrc->mode_reglement_id."')"; - if ( $this->db->query($sql) ) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec"); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (titre, fk_soc, datec, amount, remise, note, fk_user_author,fk_projet, fk_cond_reglement, fk_mode_reglement) "; + $sql.= " VALUES ('$this->titre', '$facsrc->socid', ".$this->db->idate(mktime()).", '$facsrc->amount', '$facsrc->remise', '".addslashes($this->note)."','$user->id',"; + $sql.= " ".($facsrc->projetid?"'".$facsrc->projetid."'":"null").", "; + $sql.= " '".$facsrc->cond_reglement_id."',"; + $sql.= " '".$facsrc->mode_reglement_id."')"; + if ( $this->db->query($sql) ) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec"); - /* - * Produits - */ - for ($i = 0 ; $i < sizeof($facsrc->lignes) ; $i++) - { - $result_insert = $this->addline($this->id, - $facsrc->lignes[$i]->desc, - $facsrc->lignes[$i]->subprice, - $facsrc->lignes[$i]->qty, - $facsrc->lignes[$i]->tva_tx, - $facsrc->lignes[$i]->fk_product, - $facsrc->lignes[$i]->remise_percent); + /* + * Lines + */ + for ($i = 0 ; $i < sizeof($facsrc->lignes) ; $i++) + { + $result_insert = $this->addline($this->id, + $facsrc->lignes[$i]->desc, + $facsrc->lignes[$i]->subprice, + $facsrc->lignes[$i]->qty, + $facsrc->lignes[$i]->tva_tx, + $facsrc->lignes[$i]->fk_product, + $facsrc->lignes[$i]->remise_percent, + 'HT',0,'',0, + $facsrc->lignes[$i]->product_type + ); - if ($result_insert < 0) - { - $error++; - } - } + if ($result_insert < 0) + { + $error++; + } + } - if ($error) - { + if ($error) + { $this->db->rollback(); - } - else - { + } + else + { $this->db->commit(); - return $this->id; - } - } - else - { - $this->error=$this->db->error().' sql='.$sql; + return $this->id; + } + } + else + { + $this->error=$this->db->error().' sql='.$sql; $this->db->rollback(); - return -2; - } - } - else - { + return -2; + } + } + else + { $this->db->rollback(); - return -1; - } - } + return -1; + } + } /** - \brief Recupére l'objet facture et ses lignes de factures - \param rowid id de la facture a récupérer - \param societe_id id de societe - \return int >0 si ok, <0 si ko - */ + * \brief Recupere l'objet facture et ses lignes de factures + * \param rowid id de la facture a recuperer + * \param societe_id id de societe + * \return int >0 si ok, <0 si ko + */ function fetch($rowid, $societe_id=0) { dol_syslog("Facture::Fetch rowid=".$rowid.", societe_id=".$societe_id, LOG_DEBUG); @@ -242,8 +244,8 @@ class FactureRec extends Facture if ($this->statut == 0) $this->brouillon = 1; /* - * Lignes - */ + * Lines + */ $result=$this->fetch_lines(); if ($result < 0) { @@ -270,15 +272,15 @@ class FactureRec extends Facture /** - \brief Recupére les lignes de factures dans this->lignes - \return int 1 si ok, < 0 si erreur - */ + * \brief Recupere les lignes de factures predefinies dans this->lignes + * \return int 1 if OK, < 0 if KO + */ function fetch_lines() { - $sql = 'SELECT l.rowid, l.fk_product, l.description, l.price, l.qty, l.tva_taux, '; + $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.description, l.price, l.qty, l.tva_taux, '; $sql.= ' l.remise, l.remise_percent, l.subprice,'; $sql.= ' l.total_ht, l.total_tva, l.total_ttc,'; - $sql.= ' p.label as label, p.description as product_desc'; + $sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as label, p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; $sql.= ' WHERE l.fk_facture = '.$this->id; @@ -294,9 +296,12 @@ class FactureRec extends Facture $objp = $this->db->fetch_object($result); $faclig = new FactureLigne($this->db); $faclig->rowid = $objp->rowid; - $faclig->desc = $objp->description; // Description ligne - $faclig->libelle = $objp->label; // Label produit - $faclig->product_desc = $objp->product_desc; // Description produit + $faclig->desc = $objp->description; // Description line + $faclig->product_type = $objp->product_type; // Type of line + $faclig->product_ref = $objp->product_ref; // Ref product + $faclig->libelle = $objp->label; // Label product + $faclig->product_desc = $objp->product_desc; // Description product + $faclig->fk_product_type = $objp->fk_product_type; // Type of product $faclig->qty = $objp->qty; $faclig->subprice = $objp->subprice; $faclig->tva_tx = $objp->tva_taux; @@ -334,51 +339,66 @@ class FactureRec extends Facture } - /** - * Supprime la facture - */ - function delete($rowid) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = $rowid;"; + /** + * Supprime la facture + */ + function delete($rowid) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = $rowid;"; - if ($this->db->query( $sql) ) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = $rowid"; + if ($this->db->query( $sql) ) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = $rowid"; - if ($this->db->query( $sql) ) - { - return 1; - } - else - { - print "Err : ".$this->db->error(); - return -1; - } - } - else - { - print "Err : ".$this->db->error(); - return -2; - } - } + if ($this->db->query( $sql) ) + { + return 1; + } + else + { + print "Err : ".$this->db->error(); + return -1; + } + } + else + { + print "Err : ".$this->db->error(); + return -2; + } + } /** - * \brief Ajoute une ligne de facture + * \brief Add a line to invoice */ - function addline($facid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0) + function addline($facid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0) { + dol_syslog("FactureRec::Addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type", LOG_DEBUG); include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + // Check parameters + if ($type < 0) return -1; + if ($this->brouillon) { - if (strlen(trim($qty))==0) + // Clean parameters + $remise_percent=price2num($remise_percent); + $qty=price2num($qty); + if (! $qty) $qty=1; + if (! $ventil) $ventil=0; + if (! $info_bits) $info_bits=0; + $pu_ht=price2num($pu_ht); + $pu_ttc=price2num($pu_ttc); + $txtva=price2num($txtva); + + if ($price_base_type=='HT') { - $qty=1; + $pu=$pu_ht; + } + else + { + $pu=$pu_ttc; } - $remise = 0; - $price = $pu; - $subprice = $price; // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva @@ -389,26 +409,37 @@ class FactureRec extends Facture $total_tva = $tabprice[1]; $total_ttc = $tabprice[2]; + // \TODO A virer + // Anciens indicateurs: $price, $remise (a ne plus utiliser) if (trim(strlen($remise_percent)) > 0) { $remise = round(($pu * $remise_percent / 100), 2); $price = $pu - $remise; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (fk_facture,description,price,qty,tva_taux, fk_product, remise_percent, subprice, remise, total_ht, total_tva, total_ttc)"; + $product_type=$type; + if ($fk_product) + { + $product=new Product($this->db); + $result=$product->fetch($fk_product); + $product_type=$product->type; + } + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (fk_facture,description,price,qty,tva_taux, fk_product, product_type, remise_percent, subprice, remise, total_ht, total_tva, total_ttc)"; $sql .= " VALUES ('".$facid."', '".addslashes($desc)."'"; $sql .= ",".price2num($price); $sql .= ",".price2num($qty); $sql .= ",".price2num($txtva); $sql .= ",".($fk_product?"'".$fk_product."'":"null"); + $sql .= ",".$product_type; $sql .= ",'".price2num($remise_percent)."'"; - $sql .= ",'".price2num($subprice)."'"; + $sql .= ",'".price2num($pu_ht)."'"; $sql .= ",'".price2num($remise)."'"; $sql .= ",'".price2num($total_ht)."'"; $sql .= ",'".price2num($total_tva)."'"; $sql .= ",'".price2num($total_ttc)."') ;"; - dol_syslog("Facture-rec::addline sql=".$sql, LOG_DEBUG); + dol_syslog("FactureRec::addline sql=".$sql, LOG_DEBUG); if ($this->db->query( $sql)) { $this->id=$facid; // \TODO A virer @@ -418,7 +449,7 @@ class FactureRec extends Facture else { $this->error=$this->db->lasterror(); - dol_syslog("Facture-rec::addline sql=".$this->error, LOG_ERR); + dol_syslog("FactureRec::addline sql=".$this->error, LOG_ERR); return -1; } } diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 491c7c9632f..7b0625e7f09 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -21,7 +21,7 @@ /** * \file htdocs/compta/facture/fiche-rec.php * \ingroup facture - * \brief Page d'affichage d'une facture récurrent + * \brief Page d'affichage d'une facture r�current * \version $Id$ */ @@ -62,6 +62,7 @@ if ($_POST["action"] == 'add') { $facturerec = new FactureRec($db, $facid); $facturerec->titre = $_POST["titre"]; + $facturerec->note = $_POST["comment"]; if ($facturerec->create($user) > 0) { @@ -106,6 +107,7 @@ if ($_GET["action"] == 'create') if ($mesg) print $mesg.'
'; $facture = new Facture($db); + $product_static=new Product($db); if ($facture->fetch($_GET["facid"]) > 0) { @@ -118,32 +120,42 @@ if ($_GET["action"] == 'create') $facture->fetch_client(); - print ''.$langs->trans("Customer").' :'.$facture->client->nom.''; - print ''.$langs->trans("Comment").''; + print ''.$langs->trans("Customer").''.$facture->client->getNomUrl(1).''; + print ''; + //print $langs->trans("NotePrivate"); + print ''; - print ''.$langs->trans("Title").' :'; + print ''.$langs->trans("Title").''; + print ''; + print ''; print ''; - print ''; + print ''; + print ''; - print "".$langs->trans("Author")." :".$user->fullname.""; + print "".$langs->trans("Author")."".$user->fullname.""; - print "".$langs->trans("PaymentConditions")." :"; + print "".$langs->trans("PaymentConditions").""; $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$facture->id,$facture->cond_reglement_id,'none'); print ""; - print "".$langs->trans("PaymentMode")." :"; + print "".$langs->trans("PaymentMode").""; $html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$facture->id,$facture->mode_reglement_id,'none'); print ""; - print "".$langs->trans("Project")." :"; - if ($facture->projetid > 0) + if ($conf->projet->enabled) { - $proj = new Project($db); - $proj->fetch($facture->projetid); - print $proj->title; + print "".$langs->trans("Project").""; + if ($facture->projetid > 0) + { + $proj = new Project($db); + $proj->fetch($facture->projetid); + print $proj->title; + } + print ""; } - print ""; + + print ""; @@ -155,14 +167,22 @@ if ($_GET["action"] == 'create') } /* - * Lignes de factures - * + * Lines de factures */ print ''; print '"; + print ""; + + // Show product and description + $type=$objp->product_type?$objp->product_type:$objp->fk_product_type; + if ($objp->fk_product) { - print ''; + print ''; } else { - print "\n"; + print '\n"; } + + print ''; print ''; if ($objp->remise_percent > 0) @@ -298,8 +354,7 @@ else */ print '
'; - $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux, l.remise_percent, l.subprice"; + $sql = 'SELECT l.fk_product, l.product_type, l.description, l.qty, l.rowid, l.tva_taux,'; + $sql.= ' l.fk_remise_except,'; + $sql.= ' 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.= ' l.product_type,'; + $sql.= ' p.ref, p.fk_product_type, p.label as product,'; + $sql.= ' p.description as product_desc'; $sql.= " FROM ".MAIN_DB_PREFIX."facturedet as l"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product = p.rowid"; $sql.= " WHERE l.fk_facture = ".$facture->id; $sql.= " ORDER BY l.rowid"; @@ -196,15 +216,51 @@ if ($_GET["action"] == 'create') } $var=!$var; - print "
'.stripslashes(nl2br($objp->description)).''; + + 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($objp->date_start,$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 '
".nl2br($objp->description)."'; + print ''; // ancre pour retourner sur la ligne + + 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->tva_taux.' %'.$objp->qty.'
'; print ''; - print "'; + print ''; print "
'.$langs->trans("Customer").'"; - print ''.$soc->nom.''.$soc->getNomUrl(1).'". $langs->trans("PaymentConditions") ." : "; $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->cond_reglement_id,'none'); @@ -334,15 +389,19 @@ else } print "

"; + /* - * Lignes - * + * Lines */ - print_titre($langs->trans("Products")); + if ($conf->service->enabled) { + print_titre($langs->trans("ProductsAndServices")); + } else { + print_titre($langs->trans("Products")); + } print ''; print ''; - print ''; + print ''; print ''; print ''; print ''; @@ -353,23 +412,55 @@ else while ($i < $num) { $var=!$var; - if ($fac->lignes[$i]->produit_id > 0) + + $product_static=new Product($db); + + // Show product and description + $type=$fac->lignes[$i]->product_type?$fac->lignes[$i]->product_type:$fac->lignes[$i]->fk_product_type; + // Try to enhance type detection using date_start and date_end for free lines when type + // was not saved. + if (! empty($objp->date_start)) $type=1; + if (! empty($objp->date_end)) $type=1; + + // Show line + print ""; + if ($fac->lignes[$i]->fk_product > 0) { - $prod = New Product($db); - $prod->fetch($fac->lignes[$i]->produit_id); - print "'; - print ''; } else { - print ""; - print ''; + print ''; } - print ""; + print ""; print ''; print "\n"; $i++; @@ -456,7 +547,7 @@ else } else { - print ''; + print ''; } } else diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php index 7f1f5844974..44fc0b3147d 100644 --- a/htdocs/compta/propal.php +++ b/htdocs/compta/propal.php @@ -319,7 +319,7 @@ if ($id > 0 || ! empty($ref)) $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.fk_remise_except,'; $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,'; $sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc,'; - $sql.= ' p.rowid as prodid, p.label as product, p.ref, p.fk_product_type, '; + $sql.= ' p.rowid as prodid, p.label as product_label, p.ref, p.fk_product_type, '; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid'; @@ -371,9 +371,9 @@ if ($id > 0 || ! empty($ref)) $product_static->type=$objp->fk_product_type; $product_static->id=$objp->fk_product; $product_static->ref=$objp->ref; - $product_static->libelle=$objp->product; + $product_static->libelle=$objp->product_label; $text=$product_static->getNomUrl(1); - $text.= ' - '.$objp->product; + $text.= ' - '.$objp->product_label; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); @@ -383,7 +383,7 @@ if ($id > 0 || ! empty($ref)) // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) { - print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; + print ($objp->description && $objp->description!=$objp->product_label)?'
'.dol_htmlentitiesbr($objp->description):''; } print ''; } diff --git a/htdocs/expedition/commande.php b/htdocs/expedition/commande.php index 03b7e07174a..e2d4be6ed11 100644 --- a/htdocs/expedition/commande.php +++ b/htdocs/expedition/commande.php @@ -381,7 +381,7 @@ if ($id > 0 || ! empty($ref)) $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.label as product_label, 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"; @@ -437,9 +437,9 @@ if ($id > 0 || ! empty($ref)) $product_static->type=$objp->fk_product_type; $product_static->id=$objp->fk_product; $product_static->ref=$objp->ref; - $product_static->libelle=$objp->product; + $product_static->libelle=$objp->product_label; $text=$product_static->getNomUrl(1); - $text.= ' - '.$objp->product; + $text.= ' - '.$objp->product_label; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); @@ -449,7 +449,7 @@ if ($id > 0 || ! empty($ref)) // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) { - print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; + print ($objp->description && $objp->description!=$objp->product_label)?'
'.dol_htmlentitiesbr($objp->description):''; } print ''; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 9e80baa89fa..93133e15518 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -154,7 +154,7 @@ class Facture extends CommonObject $this->db->begin(); - // Facture récurrente + // Create invoice from a predefined invoice if ($this->fac_rec > 0) { require_once(DOL_DOCUMENT_ROOT.'/compta/facture/facture-rec.class.php'); @@ -171,7 +171,7 @@ class Facture extends CommonObject $this->remise_percent = $_facrec->remise_percent; $this->remise = $_facrec->remise; - // Nettoyage parametres + // Clean parametres if (! $this->type) $this->type = 0; $this->ref_client=trim($this->ref_client); $this->note=trim($this->note); @@ -297,7 +297,10 @@ class Facture extends CommonObject $_facrec->lignes[$i]->qty, $tva_tx, $_facrec->lignes[$i]->produit_id, - $_facrec->lignes[$i]->remise_percent); + $_facrec->lignes[$i]->remise_percent, + '','',0,0,'','HT', + $_facref->lignes[$i]->product_type + ); if ( $result_insert < 0) { @@ -595,7 +598,7 @@ class Facture extends CommonObject if ($this->statut == 0) $this->brouillon = 1; /* - * Lignes + * Lines */ $result=$this->fetch_lines(); if ($result < 0) @@ -623,8 +626,8 @@ class Facture extends CommonObject /** - * \brief Recupére les lignes de factures dans this->lignes - * \return int 1 si ok, < 0 si erreur + * \brief Recupere les lignes de factures dans this->lignes + * \return int 1 if OK, < 0 if KO */ function fetch_lines() { @@ -632,7 +635,7 @@ class Facture extends CommonObject $sql.= ' l.remise, l.remise_percent, l.fk_remise_except, l.subprice,'; $sql.= ' '.$this->db->pdate('l.date_start').' as date_start,'.$this->db->pdate('l.date_end').' as date_end,'; $sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc, l.fk_code_ventilation, l.fk_export_compta,'; - $sql.= ' p.fk_product_type as fk_product_type, p.label as label, p.description as product_desc'; + $sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as label, p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; $sql.= ' WHERE l.fk_facture = '.$this->id; @@ -650,10 +653,12 @@ class Facture extends CommonObject $faclig = new FactureLigne($this->db); $faclig->rowid = $objp->rowid; - $faclig->desc = $objp->description; // Description ligne - $faclig->libelle = $objp->label; // Label produit - $faclig->product_desc = $objp->product_desc; // Description produit + $faclig->desc = $objp->description; // Description line $faclig->product_type = $objp->product_type; // Type of line + $faclig->product_ref = $objp->product_ref; // Ref product + $faclig->libelle = $objp->label; // Label product + $faclig->product_desc = $objp->product_desc; // Description product + $faclig->fk_product_type = $objp->fk_product_type; // Type of product $faclig->qty = $objp->qty; $faclig->subprice = $objp->subprice; $faclig->tva_tx = $objp->tva_taux; @@ -661,7 +666,6 @@ class Facture extends CommonObject $faclig->fk_remise_except = $objp->fk_remise_except; $faclig->produit_id = $objp->fk_product; $faclig->fk_product = $objp->fk_product; - $faclig->fk_product_type = $objp->fk_product_type; $faclig->date_start = $objp->date_start; $faclig->date_end = $objp->date_end; $faclig->date_start = $objp->date_start; @@ -1542,7 +1546,7 @@ class Facture extends CommonObject $price = ($pu - $remise); } - $product_type=0; + $product_type=$type; if ($fk_product) { $product=new Product($this->db); @@ -1569,7 +1573,6 @@ class Facture 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; diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 77aba4913f6..6aae0cfd7a1 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -599,7 +599,7 @@ if ($id > 0 || ! empty($ref)) /* print '"; print ''; print ''; -*/ +*/ // Fournisseur print '"; print ''; @@ -727,7 +727,7 @@ if ($id > 0 || ! empty($ref)) print_date_range($commandline->date_start,$commandline->date_end); // Add description in form - if ($conf->global->PRODUIT_DESC_IN_FORM) print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; + if ($conf->global->PRODUIT_DESC_IN_FORM) print ($commandline->description && $commandline->description!=$product_static->libelle)?'
'.dol_htmlentitiesbr($commandline->description):''; } // Description - Editor wysiwyg diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 1676b2aa948..1515f331349 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -889,10 +889,10 @@ else print $html->textwithtooltip($text,$description,3,'','',$i); // Show range - print_date_range($objp->date_start,$objp->date_end); + print_date_range($fac->lignes[$i]->date_start,$fac->lignes[$i]->date_end); // Add description in form - if ($conf->global->PRODUIT_DESC_IN_FORM) print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; + if ($conf->global->PRODUIT_DESC_IN_FORM) print ($fac->lignes[$i]->description && $fac->lignes[$i]->description!=$product_static->libelle)?'
'.dol_htmlentitiesbr($fac->lignes[$i]->description):''; } // Description - Editor wysiwyg diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 61c869a5256..310d83ca5c6 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -69,6 +69,7 @@ class Form * \param tooltipon 1=tooltip sur texte, 2=tooltip sur picto, 3=tooltip sur les 2, 4=tooltip sur les 2 et forcé en Ajax * \param direction -1=Le picto est avant, 0=pas de picto, 1=le picto est après * \param img Code img du picto + * \param i Numero of tooltip * \return string Code html du tooltip (texte+picto) */ function textwithtooltip($text,$htmltext,$tooltipon=1,$direction=0,$img='',$i=1,$width='200',$shiftX='10') diff --git a/mysql/migration/2.6.0-2.7.0.sql b/mysql/migration/2.6.0-2.7.0.sql index 1893b65992b..7e90c3c7b1e 100644 --- a/mysql/migration/2.6.0-2.7.0.sql +++ b/mysql/migration/2.6.0-2.7.0.sql @@ -6,6 +6,8 @@ -- when current version is 2.6.0 or higher. -- +alter table llx_facturedet_rec add column product_type integer DEFAULT 0 after fk_product; + -- Usage of llx_menu_const and llx_menu_constraint is too complicated -- so we made first change to remove it alter table llx_menu_const drop foreign key fk_menu_const_fk_menu; diff --git a/mysql/tables/llx_facturedet_rec.sql b/mysql/tables/llx_facturedet_rec.sql index 0c57189f3bd..a2790e15357 100644 --- a/mysql/tables/llx_facturedet_rec.sql +++ b/mysql/tables/llx_facturedet_rec.sql @@ -1,5 +1,6 @@ -- =================================================================== -- Copyright (C) 2003 Rodolphe Quiedeville +-- Copyright (C) 2009 Laurent Destailleur -- -- 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 @@ -23,14 +24,15 @@ create table llx_facturedet_rec rowid integer AUTO_INCREMENT PRIMARY KEY, fk_facture integer NOT NULL, fk_product integer, + product_type integer DEFAULT 0, description text, tva_taux real DEFAULT 19.6, -- taux tva - qty real, -- quantité + qty real, -- quantity remise_percent real DEFAULT 0, -- pourcentage de remise remise real DEFAULT 0, -- montant de la remise subprice real, -- prix avant remise price real, -- prix final - total_ht real, -- Total HT de la ligne toute quantité et incluant remise ligne et globale - total_tva real, -- Total TVA de la ligne toute quantité et incluant remise ligne et globale - total_ttc real -- Total TTC de la ligne toute quantité et incluant remise ligne et globale + total_ht real, -- Total HT de la ligne toute quantity et incluant remise ligne et globale + total_tva real, -- Total TVA de la ligne toute quantity et incluant remise ligne et globale + total_ttc real -- Total TTC de la ligne toute quantity et incluant remise ligne et globale )type=innodb;
'.$langs->trans("Description").''.$langs->trans("Description").''.$langs->trans("Price").''.$langs->trans("ReductionShort").''.$langs->trans("Qty").'
"; - print ''; - print img_object($langs->trans("ShowProduct"),"product").' '.$prod->ref; - print ''; + print ''; + print ''; // ancre pour retourner sur la ligne + + // Show product and description + $product_static->type=$fac->lignes[$i]->fk_product_type; + $product_static->id=$fac->lignes[$i]->fk_product; + $product_static->ref=$fac->lignes[$i]->product_ref; + $product_static->libelle=$fac->lignes[$i]->libelle; + $text=$product_static->getNomUrl(1); + $text.= ' - '.$fac->lignes[$i]->libelle; + $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($fac->lignes[$i]->desc)); + print $html->textwithtooltip($text,$description,3,'','',$i); + + // Show range + print_date_range($fac->lignes[$i]->date_start,$fac->lignes[$i]->date_end); + + // Add description in form + if ($conf->global->PRODUIT_DESC_IN_FORM) print ($fac->lignes[$i]->desc && $fac->lignes[$i]->desc!=$fac->lignes[$i]->libelle)?'
'.dol_htmlentitiesbr($fac->lignes[$i]->desc):''; + print '
'.$fac->lignes[$i]->desc.'
 '.$fac->lignes[$i]->desc.''; + + if ($type==1) $text = img_object($langs->trans('Service'),'service'); + else $text = img_object($langs->trans('Product'),'product'); + print $text.' '.nl2br($fac->lignes[$i]->desc); + + // Show range + print_date_range($fac->lignes[$i]->date_start,$fac->lignes[$i]->date_end); + + print '".price($fac->lignes[$i]->price)."".price($fac->lignes[$i]->price)."'.$fac->lignes[$i]->remise_percent.' %".$fac->lignes[$i]->qty."
impayéeimpay�e
'.$langs->trans("RefSupplier")."'.$commande->ref_supplier.'
'.$langs->trans("Supplier")."'.$soc->getNomUrl(1,'supplier').'