diff --git a/htdocs/admin/societe.php b/htdocs/admin/societe.php
index 2b8416405e3..eca79f38dd3 100644
--- a/htdocs/admin/societe.php
+++ b/htdocs/admin/societe.php
@@ -86,8 +86,7 @@ if ($_POST["action"] == 'updateMask')
/*
- * Affichage page configuration module societe
- *
+ * View
*/
$form=new Form($db);
@@ -132,11 +131,11 @@ if ($handle)
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/societe/".$file.".php");
$modCodeTiers = new $file;
-
+
// Show modules according to features level
if ($modCodeTiers->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
if ($modCodeTiers->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
-
+
$var = !$var;
print "
\n ".$modCodeTiers->nom." \n ";
print $modCodeTiers->info($langs);
diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php
index 28873f461d3..c653a45d06b 100644
--- a/htdocs/fourn/commande/fiche.php
+++ b/htdocs/fourn/commande/fiche.php
@@ -99,62 +99,90 @@ if ($_POST['action'] == 'addligne' && $user->rights->fournisseur->commande->cree
exit;
}
- $soc = new Societe($db, $commande->socid);
- $result=$soc->fetch($commande->socid);
- //print $result;
-
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
- if ($_POST["idprodfournprice"] > 0)
+ if ($_POST["idprodfournprice"]) // >0 or -1
{
$prodfournprice = new ProductFournisseur($db);
- $prodfournprice->fetch_product_fournisseur_price($_POST["idprodfournprice"]);
+ $idprod=$prodfournprice->get_buyprice($_POST['idprodfournprice'], $_POST['qty']);
+ if ($idprod > 0)
+ {
+ $prodfournprice->fetch($idprod);
+
+ // cas special pour lequel on a les meme reference que le fournisseur
+ // $label = '['.$nv_prod->ref.'] - '. $nv_prod->libelle;
+ $label = $prodfournprice->libelle;
+
+ $societe='';
+ if ($commande->socid)
+ {
+ $societe=new Societe($db);
+ $societe->fetch($commande->socid);
+ }
+
+ $desc = $prodfournprice->description;
+ $desc.= $prodfournprice->description && $_POST['np_desc'] ? "\n" : "";
+ $desc.= $_POST['np_desc'];
+
+ $tva_tx = get_default_tva($societe,$mysoc,$prodfournprice->tva_tx,$prodfournprice->id);
- $prod = new Product($db, $prodfournprice->product_id);
- $prod->fetch($prodfournprice->product_id);
+ $result=$commande->addline(
+ $desc,
+ $pu,
+ $_POST['qty'],
+ $tva_tx,
+ $prodfournprice->id,
+ $_POST['idprodfournprice'],
+ $prodfournprice->fourn_ref,
+ $_POST['remise_percent'],
+ 'HT'
+ );
- $libelle = $prod->libelle;
-
- $desc = $prod->description;
- $desc.= $prod->description && $_POST['np_desc'] ? "\n" : "";
- $desc.= $_POST['np_desc'];
-
- $tva_tx = get_default_tva($soc,$mysoc,$prod->tva_tx,$prodfournprice->product_id);
+ }
+ if ($idprod == -1)
+ {
+ // Quantity too low
+ $mesg=''.$langs->trans("ErrorQtyTooLowForThisSupplier").'
';
+ }
}
else
{
- $pu=$_POST['pu'];
- $tva_tx=$_POST['tva_tx'];
- $desc=$_POST['dp_desc'];
+ $tauxtva = price2num($_POST['tva_tx']);
+ if (! $_POST['dp_desc'])
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'
';
+ }
+ else
+ {
+ if (!empty($_POST['pu']))
+ {
+ $ht = price2num($_POST['pu']);
+ $result=$commande->addline($_POST['dp_desc'], $ht, $_POST['qty'], $tauxtva);
+ }
+ else
+ {
+ $ttc = price2num($_POST['amountttc']);
+ $ht = $ttc / (1 + ($tauxtva / 100));
+ $result=$commande->addline($_POST['dp_desc'], $ht, $_POST['qty'], $tauxtva);
+ }
+ }
}
+
//print "xx".$tva_tx; exit;
-
- $result=$commande->addline(
- $desc,
- $pu,
- $_POST['qty'],
- $tva_tx,
- $prodfournprice->product_id,
- $_POST['idprodfournprice'],
- $prodfournprice->fourn_ref,
- $_POST['remise_percent'],
- 'HT'
- );
-
- if ($result > 0)
- {
- if ($_REQUEST['lang_id'])
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
- }
- supplier_order_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
- }
- else
- {
- $mesg=''.$commande->error.'
';
- }
+ if ($result > 0)
+ {
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ supplier_order_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
+ }
+ else
+ {
+ $mesg=''.$commande->error.'
';
+ }
}
}
@@ -217,7 +245,7 @@ if ($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes
if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->commande->valider)
{
$commande = new CommandeFournisseur($db);
-
+
$commande->fetch($id);
$commande->date_commande=time();
@@ -437,7 +465,7 @@ if ($id > 0)
{
//if ($mesg) print $mesg.' ';
$commande = new CommandeFournisseur($db);
-
+
if ($commande->fetch($id) >= 0)
{
$soc = new Societe($db);
@@ -499,10 +527,10 @@ if ($id > 0)
$text=$langs->trans('ConfirmValidateOrder',$newref);
if ($conf->notification->enabled)
{
- require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
- $notify=new Notify($db);
- $text.=' ';
- $text.=$notify->confirmMessage(3,$commande->socid);
+ require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
+ $notify=new Notify($db);
+ $text.=' ';
+ $text.=$notify->confirmMessage(3,$commande->socid);
}
$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_valid');
@@ -665,7 +693,7 @@ if ($id > 0)
if ($num)
{
print ' ';
print '';
- $html->select_produits_fournisseurs($commande->fourn_id,'','idprodfournprice');
+ $html->select_produits_fournisseurs($commande->fourn_id,'','idprodfournprice',2,$filtre);
if (! $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) print ' ';
diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php
index 9cf64aa10fe..d4bb1b03faf 100644
--- a/htdocs/fourn/facture/fiche.php
+++ b/htdocs/fourn/facture/fiche.php
@@ -242,24 +242,30 @@ if ($_REQUEST['action'] == 'update_line')
if ($_GET['action'] == 'add_ligne')
{
$facfou = new FactureFournisseur($db, '', $_GET['facid']);
-
- if ($_POST['prodfournpriceid'])
+ $ret=$facfou->fetch($_GET['facid']);
+ if ($ret < 0)
{
- $nv_prod = new Product($db);
+ dolibarr_print_error($db,$facfou->error);
+ exit;
+ }
+
+ if ($_POST['prodfournpriceid']) // > 0 or -1
+ {
+ $nv_prod = new ProductFournisseur($db);
$idprod=$nv_prod->get_buyprice($_POST['prodfournpriceid'], $_POST['qty']);
if ($idprod > 0)
{
$result=$nv_prod->fetch($idprod);
- // cas sp�cial pour lequel on a les meme r�f�rence que le fournisseur
+ // cas special pour lequel on a les meme reference que le fournisseur
// $label = '['.$nv_prod->ref.'] - '. $nv_prod->libelle;
$label = $nv_prod->libelle;
$societe='';
- if ($_POST['socid'])
+ if ($facfou->socid)
{
$societe=new Societe($db);
- $societe->fetch($_POST['socid']);
+ $societe->fetch($facfou->socid);
}
$tvatx=get_default_tva($societe,$mysoc,$nv_prod->tva_tx);
@@ -268,7 +274,7 @@ if ($_GET['action'] == 'add_ligne')
}
if ($idprod == -1)
{
- // Quantit� insuffisante
+ // Quantity too low
$mesg=''.$langs->trans("ErrorQtyTooLowForThisSupplier").'
';
}
}
@@ -854,7 +860,7 @@ else
print ' ';
print '';
- // Ajout de produits/services pr�d�finis
+ // Ajout de produits/services predefinis
if ($conf->produit->enabled)
{
print '