diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 511af7fc027..f6bbb516aa4 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -194,20 +194,44 @@ if ($_GET['action'] == 'del_ligne') if ($_GET['action'] == 'add_ligne') { - $facfou = new FactureFournisseur($db, '', $_GET['facid']); - $tauxtva = price2num($_POST['tauxtva']); - if (strlen($_POST['label']) > 0 && !empty($_POST['amount'])) - { - $ht = price2num($_POST['amount']); - $facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']); - } - else - { - $ttc = price2num($_POST['amountttc']); - $ht = $ttc / (1 + ($tauxtva / 100)); - $facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']); - } - $_GET['action'] = 'edit'; + $facfou = new FactureFournisseur($db, '', $_GET['facid']); + + if ($_POST['idprod']) + { + $nv_prod = new Product($db); + $nv_prod->fetch($_POST['idprod']); + + // cas spécial pour lequel on a les meme référence que le fournisseur + // $label = '['.$nv_prod->ref.'] - '. $nv_prod->libelle; + $label = $nv_prod->libelle; + + $result=$nv_prod->get_buyprice($_POST['fourn_id'], $_POST['qty']); + if ($result > 0) + { + $facfou->addline($label, $nv_prod->fourn_pu, $nv_prod->tva_tx, $_POST['qty'], $_POST['idprod']); + } + if ($result == -1) + { + // \todo + // Quantité insuffisante + } + } + else + { + $tauxtva = price2num($_POST['tauxtva']); + if (strlen($_POST['label']) > 0 && !empty($_POST['amount'])) + { + $ht = price2num($_POST['amount']); + $facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']); + } + else + { + $ttc = price2num($_POST['amountttc']); + $ht = $ttc / (1 + ($tauxtva / 100)); + $facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']); + } + } + $_GET['action'] = 'edit'; } @@ -340,13 +364,14 @@ else print ''; print ''; - print ''; + print ''; print ''; print ''; - print ''; @@ -354,14 +379,17 @@ else print ''; - print ''; - print ''; + print ''; + print ''; - print ''; + print ''; + + print ''; - print ''; @@ -373,7 +401,7 @@ else $authorfullname=$author->fullname; } print ''; - print ''; + print ''; print ''; print '
'.$langs->trans('Company').''.stripslashes($fac->socnom).''.$societe->nom_url.''.$langs->trans('Comments').'
'.$langs->trans('Ref').''; print ''; + $rownb=9; + print ''; print '
'.$langs->trans('Label').''; print '
'.$langs->trans('AmountHT').' / '.$langs->trans('AmountTTC').''.price($fac->total_ht).' / '.price($fac->total_ttc).'
'.$langs->trans('AmountHT').''.price($fac->total_ht).'
'.$langs->trans('DateBill').''; + print '
'.$langs->trans('AmountTTC').''.price($fac->total_ttc).'
'.$langs->trans('DateInvoice').''; $html->select_date($fac->datep,'','','','',"update"); print '
'.$langs->trans('DateEcheance').''; + print '
'.$langs->trans('DateEcheance').''; $html->select_date($fac->date_echeance,'ech','','','',"update"); print '
'.$langs->trans('Author').''.$authorfullname.'
'.$langs->trans('Status').''.$fac->LibStatut($fac->paye,$fac->statut).'
'.$langs->trans('Status').''.$fac->LibStatut($fac->paye,$fac->statut,4).'
'; print ''; @@ -399,13 +427,13 @@ else { $var=!$var; print ''.$fac->lignes[$i][0].''; - print ''.price($fac->lignes[$i][1]).''; - print ''.price($fac->lignes[$i][1] * (1+($fac->lignes[$i][2]/100))).''; + print ''.price($fac->lignes[$i][1]).''; + print ''.price($fac->lignes[$i][1] * (1+($fac->lignes[$i][2]/100))).''; print ''.$fac->lignes[$i][3].''; - print ''.price($fac->lignes[$i][4]).''; + print ''.price($fac->lignes[$i][4]).''; print ''.$fac->lignes[$i][2].''; - print ''.price($fac->lignes[$i][5]).''; - print ''.price($fac->lignes[$i][6]).''; + print ''.price($fac->lignes[$i][5]).''; + print ''.price($fac->lignes[$i][6]).''; print ''; print ''.img_delete().''; print ''; @@ -432,8 +460,28 @@ else print ''; print ' '; print ''; - print ''; - print ''; + + // Ajout de produits/services prédéfinis + if ($conf->produit->enabled) + { + print '
'; + print ''; + $var=! $var; + print ''; + print ''; + $html->select_produits_fournisseurs($fac->socidp,'','idprod',$filtre); + print ''; + print ''; + print ' '; + print ' '; + print ' '; + print ' '; + print ''; + print ''; + print '
'; + } + + print ''; } else { diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index bfd24b68f97..6df4edc761e 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -703,25 +703,29 @@ class Form /** - * \brief Retourne la liste des produits fournisseurs - * \param selected Produit présélectionné - * \param htmlname Nom de la zone select - * \param filtretype Pour filtre sur type de produit - * \param limit Limite sur le nombre de lignes retournées - * \param filtre Pour filtre - */ + * \brief Retourne la liste des produits de fournisseurs + * \param socid Id société (0 pour aucun filtre) + * \param selected Produit présélectionné + * \param htmlname Nom de la zone select + * \param filtretype Pour filtre sur type de produit + * \param limit Limite sur le nombre de lignes retournées + * \param filtre Pour filtre + */ function select_produits_fournisseurs($socid,$selected='',$htmlname='productid',$filtretype='',$filtre='') { global $langs,$conf; - $sql = "SELECT p.rowid, p.label, p.ref, p.price as price, pf.price as fprice, pf.quantity, p.duration"; - $sql.= " FROM ".MAIN_DB_PREFIX."product as p "; - $sql .= " , ".MAIN_DB_PREFIX."product_fournisseur_price as pf "; - $sql.= " WHERE p.rowid = pf.fk_product AND pf.fk_soc = ".$socid; + $sql = "SELECT p.rowid, p.label, p.ref, p.price, pf.price as fprice, pf.quantity, p.duration"; + $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pf ON p.rowid = pf.fk_product"; + $sql.= " WHERE p.envente = 1"; + if ($socid) $sql.= " AND pf.fk_soc = ".$socid; if ($filtretype && $filtretype != '') $sql.=" AND p.fk_product_type=".$filtretype; if ($filtre) $sql.="$filtre"; $sql.= " ORDER BY p.ref DESC"; - + + dolibarr_syslog("html.form.class.php::select_produits_fournisseurs sql=$sql"); + $result=$this->db->query($sql); if ($result) { @@ -734,12 +738,12 @@ class Form { $objp = $this->db->fetch_object($result); $opt = '\n";