Fix: Pb with supplier orders

This commit is contained in:
Laurent Destailleur 2008-07-27 20:47:13 +00:00
parent f48f2b2df8
commit 214bbdd9a6
10 changed files with 1982 additions and 1938 deletions

View File

@ -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 "<tr ".$bc[$var].">\n <td width=\"140\">".$modCodeTiers->nom."</td>\n <td>";
print $modCodeTiers->info($langs);

View File

@ -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='<div class="error">'.$langs->trans("ErrorQtyTooLowForThisSupplier").'</div>';
}
}
else
{
$pu=$_POST['pu'];
$tva_tx=$_POST['tva_tx'];
$desc=$_POST['dp_desc'];
$tauxtva = price2num($_POST['tva_tx']);
if (! $_POST['dp_desc'])
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'</div>';
}
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='<div class="error">'.$commande->error.'</div>';
}
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='<div class="error">'.$commande->error.'</div>';
}
}
}
@ -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.'<br>';
$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.='<br>';
$text.=$notify->confirmMessage(3,$commande->socid);
require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
$notify=new Notify($db);
$text.='<br>';
$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 '<tr class="liste_titre">';
print '<td>'.$langs->trans('Description').'</td>';
print '<td>'.$langs->trans('Label').'</td>';
print '<td align="right" width="50">'.$langs->trans('VAT').'</td>';
print '<td align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
print '<td align="right" width="50">'.$langs->trans('Qty').'</td>';
@ -800,7 +828,7 @@ if ($id > 0)
print '<tr class="liste_titre">';
print '<td>';
print '<a name="add"></a>'; // ancre
print $langs->trans('Description').'</td>';
print $langs->trans('Label').'</td>';
print '<td align="right">'.$langs->trans('VAT').'</td>';
print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
print '<td align="right">'.$langs->trans('Qty').'</td>';
@ -868,7 +896,7 @@ if ($id > 0)
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td colspan="3">';
$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 '<br>';

View File

@ -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<73>cial pour lequel on a les meme r<>f<EFBFBD>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<EFBFBD> insuffisante
// Quantity too low
$mesg='<div class="error">'.$langs->trans("ErrorQtyTooLowForThisSupplier").'</div>';
}
}
@ -854,7 +860,7 @@ else
print '<td align="center" valign="middle" colspan="2"><input type="submit" class="button" value="'.$langs->trans('Add').'"></td></tr>';
print '</form>';
// Ajout de produits/services pr<EFBFBD>d<EFBFBD>finis
// Ajout de produits/services predefinis
if ($conf->produit->enabled)
{
print '<form name="addligne_predef" action="fiche.php?facid='.$fac->id.'&amp;action=add_ligne" method="post">';
@ -864,7 +870,7 @@ else
$var=! $var;
print '<tr '.$bc[$var].'>';
print '<td colspan="4">';
$html->select_produits_fournisseurs($fac->socid,'','prodfournpriceid',$filtre);
$html->select_produits_fournisseurs($fac->socid,'','prodfournpriceid',2,$filtre);
print '</td>';
print '<td align="right"><input type="text" name="qty" value="1" size="1"></td>';
print '<td>&nbsp;</td>';

View File

@ -673,13 +673,13 @@ class CommandeFournisseur extends Commande
* \param fk_product Id produit
* \param remise_percent Remise
* \param price_base_type HT or TTC
* \param int <0 si ko, >0 si ok
* \param int <=0 si ko, >0 si ok
*/
function addline($desc, $pu_ht, $qty, $txtva, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0, $price_base_type='HT', $pu_ttc=0)
{
global $langs,$mysoc;
dolibarr_syslog("Fournisseur.Commande::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
dolibarr_syslog("FournisseurCommande::addline $desc, $pu_ht, $qty, $txtva, $fk_product, $fk_prod_fourn_price, $fourn_ref, $remise_percent, $price_base_type, $pu_ttc");
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
// Clean parameters
@ -726,14 +726,14 @@ class CommandeFournisseur extends Commande
{
$this->error="Aucun tarif trouvé pour cette quantité. Quantité saisie insuffisante ?";
$this->db->rollback();
dolibarr_syslog("Fournisseur.commande::addline result=".$result." - ".$this->error);
dolibarr_syslog("FournisseurCommande::addline result=".$result." - ".$this->error, LOG_DEBUG);
return -1;
}
if ($result < -1)
{
$this->error=$prod->error;
$this->db->rollback();
dolibarr_syslog("Fournisseur.commande::addline result=".$result." - ".$this->error);
dolibarr_syslog("Fournisseur.commande::addline result=".$result." - ".$this->error, LOG_ERR);
return -1;
}
}
@ -754,7 +754,7 @@ class CommandeFournisseur extends Commande
$total_ttc = $tabprice[2];
$subprice = price2num($pu,'MU');
// \TODO A virer
// Anciens indicateurs: $price, $remise (a ne plus utiliser)
$remise = 0;
@ -777,7 +777,8 @@ class CommandeFournisseur extends Commande
$sql.= "'".price2num($total_tva)."',";
$sql.= "'".price2num($total_ttc)."'";
$sql.= ")";
dolibarr_syslog('Fournisseur.commande::addline sql='.$sql);
dolibarr_syslog('FournisseurCommande::addline sql='.$sql);
$resql=$this->db->query($sql);
//print $sql;
if ($resql)
@ -791,6 +792,7 @@ class CommandeFournisseur extends Commande
{
$this->error=$this->db->error();
$this->db->rollback();
dolibarr_syslog('FournisseurCommande::addline '.$this->error, LOG_ERR);
return -1;
}
}

View File

@ -295,7 +295,7 @@ class ProductFournisseur extends Product
/**
* \brief Charge les informations relatives à un prix de fournisseur
* \param rowid id ligne
* \return int < 0 si erreur, > 0 si ok
* \return int < 0 if KO, 0 if OK but not found, > 0 if OK
*/
function fetch_product_fournisseur_price($rowid)
{
@ -304,24 +304,32 @@ class ProductFournisseur extends Product
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product_fournisseur as pf";
$sql.= " WHERE pfp.rowid = ".$rowid." AND pf.rowid = pfp.fk_product_fournisseur";
dolibarr_syslog("Product::fetch_product_fournisseur_price sql=".$sql);
dolibarr_syslog("Product::fetch_product_fournisseur_price sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql) ;
if ($resql)
{
$obj = $this->db->fetch_object($resql);
$this->product_fourn_price_id = $rowid;
$this->product_fourn_id = $obj->product_fourn_id;
$this->fourn_ref = $obj->ref_fourn;
$this->fourn_price = $obj->price;
$this->fourn_qty = $obj->quantity;
$this->fourn_unitprice = $obj->unitprice;
$this->product_id = $obj->fk_product;
return 1;
if ($obj)
{
$this->product_fourn_price_id = $rowid;
$this->product_fourn_id = $obj->product_fourn_id;
$this->fourn_ref = $obj->ref_fourn;
$this->fourn_price = $obj->price;
$this->fourn_qty = $obj->quantity;
$this->fourn_unitprice = $obj->unitprice;
$this->product_id = $obj->fk_product; // deprecated
$this->fk_product = $obj->fk_product;
return 1;
}
else
{
return 0;
}
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Product::fetch_product_fournisseur_price error=".$this->error);
dolibarr_syslog("Product::fetch_product_fournisseur_price error=".$this->error, LOG_ERR);
return -1;
}
}

View File

@ -1127,13 +1127,14 @@ class Form
}
/**
\brief Retourne la liste des produits fournisseurs en Ajax si ajax activé ou renvoie à select_produits_fournisseurs_do
\param selected Produit pré-sélectionné
\param htmlname Nom de la zone select
\param filtretype Pour filtre sur type de produit
\param filtre Pour filtre sql
\brief Retourne la liste des produits fournisseurs en Ajax si ajax activé ou renvoie à select_produits_fournisseurs_do
\param socid Id third party
\param selected Produit pré-sélectionné
\param htmlname Nom de la zone select
\param filtretype Filter on product type (1=customer, 2=supplier)
\param filtre Pour filtre sql
*/
function select_produits_fournisseurs($socid,$selected='',$htmlname='productid',$filtretype='',$filtre='')
function select_produits_fournisseurs($socid,$selected='',$htmlname='productid',$filtretype=2,$filtre)
{
global $langs,$conf;
if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
@ -1143,7 +1144,7 @@ class Form
}
else
{
$this->select_produits_fournisseurs_do($socid,$selected,$htmlname,$filtretype,$filtre);
$this->select_produits_fournisseurs_do($socid,$selected,$htmlname,$filtretype,$filtre,'');
}
}
@ -1226,7 +1227,7 @@ class Form
{
$opt.= strtolower($langs->trans("Units"));
}
if ($objp->quantity > 1)
if ($objp->quantity >= 1)
{
$opt.=" (";
$opt.= price($objp->unitprice).$langs->trans("Currency".$conf->monnaie)."/".strtolower($langs->trans("Unit"));
@ -1255,8 +1256,8 @@ class Form
}
/**
\brief Retourne la liste des tarifs fournisseurs pour un produit
\param productid Id du produit
\brief Retourne la liste des tarifs fournisseurs pour un produit
\param productid Id product
*/
function select_product_fourn_price($productid,$htmlname='productfournpriceid')
{

View File

@ -13,7 +13,7 @@ OrderDate=Order date
BuyingPrice=Buying price
AddSupplierPrice=Add supplier price
ChangeSupplierPrice=Change supplier price
ErrorQtyTooLowForThisSupplier=Quantity too low for this supplier
ErrorQtyTooLowForThisSupplier=Quantity too low for this supplier or no price defined on this product for this supplier
ErrorSupplierCountryIsNotDefined=Country for this supplier is not defined. Correct this first.
ProductHasAlreadyReferenceInThisSupplier=This product has already a reference in this supplier
NoRecordedSuppliers=No suppliers recorded

View File

@ -13,6 +13,6 @@ OrderDate=Date commande
BuyingPrice=Prix d'achat
AddSupplierPrice=Ajouter prix fournisseur
ChangeSupplierPrice=Modifier prix fournisseur
ErrorQtyTooLowForThisSupplier=Quantité insuffisante pour ce fournisseur
ErrorQtyTooLowForThisSupplier=Quantité insuffisante pour ce fournisseur ou aucun tarif défini sur ce produit pour ce fournisseur
ErrorSupplierCountryIsNotDefined=Le pays de ce fournisseur n'est pas défini. Corriger sur sa fiche.
ProductHasAlreadyReferenceInThisSupplier=Ce produit a déjà une référence chez ce fournisseur

View File

@ -13,7 +13,7 @@ OrderDate=Date commande
BuyingPrice=Prix d'achat
AddSupplierPrice=Ajouter prix fournisseur
ChangeSupplierPrice=Modifier prix fournisseur
ErrorQtyTooLowForThisSupplier=Quantité insuffisante pour ce fournisseur
ErrorQtyTooLowForThisSupplier=Quantité insuffisante pour ce fournisseur ou aucun tarif défini sur ce produit pour ce fournisseur
ErrorSupplierCountryIsNotDefined=Le pays de ce fournisseur n'est pas défini. Corriger sur sa fiche.
ProductHasAlreadyReferenceInThisSupplier=Ce produit a déjà une référence chez ce fournisseur
NoRecordedSuppliers=Pas de fournisseurs enregistrés

File diff suppressed because it is too large Load Diff