Qual: id of an instance should not be provided into method of instance

This commit is contained in:
Laurent Destailleur 2013-06-14 00:21:17 +02:00
parent bd8f1f2d2f
commit 6750987dcb
2 changed files with 28 additions and 25 deletions

View File

@ -104,7 +104,7 @@ if ($action == 'convert')
if (! empty($price_base_type)) if (! empty($price_base_type))
{ {
print "$newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr<br>\n"; print "$newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr<br>\n";
$ret=$objectstatic->updatePrice($objectstatic->id, $newprice, $price_base_type, $user, $newvat, $newminprice, $newlevel, $newnpr); $ret=$objectstatic->updatePrice($newprice, $price_base_type, $user, $newvat, $newminprice, $newlevel, $newnpr);
} }
// Update multiprice // Update multiprice
foreach ($objectstatic->multiprices as $level => $multiprices) foreach ($objectstatic->multiprices as $level => $multiprices)
@ -128,7 +128,7 @@ if ($action == 'convert')
$newlevel=$level; $newlevel=$level;
print "$newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr<br>\n"; print "$newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr<br>\n";
$retm=$objectstatic->updatePrice($objectstatic->id, $newprice, $price_base_type, $user, $newvat, $newminprice, $newlevel, $newnpr); $retm=$objectstatic->updatePrice($newprice, $price_base_type, $user, $newvat, $newminprice, $newlevel, $newnpr);
if ($retm < 0) if ($retm < 0)
{ {
$error++; $error++;

View File

@ -51,7 +51,7 @@ $object = new Product($db);
if ($action == 'update_price' && ! $_POST["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) if ($action == 'update_price' && ! $_POST["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer))
{ {
$result = $object->fetch($id); $result = $object->fetch($id);
// MultiPrix // MultiPrix
if (! empty($conf->global->PRODUIT_MULTIPRICES)) if (! empty($conf->global->PRODUIT_MULTIPRICES))
{ {
@ -88,7 +88,7 @@ if ($action == 'update_price' && ! $_POST["cancel"] && ($user->rights->produit->
$newpsq = empty($newpsq) ? 0 : $newpsq; $newpsq = empty($newpsq) ? 0 : $newpsq;
} }
if ($object->updatePrice($object->id, $newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq) > 0) if ($object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq) > 0)
{ {
$action = ''; $action = '';
$mesg = '<div class="ok">'.$langs->trans("RecordSaved").'</div>'; $mesg = '<div class="ok">'.$langs->trans("RecordSaved").'</div>';
@ -112,8 +112,8 @@ $error=0;
if ($action == 'activate_price_by_qty') { // Activating product price by quantity add a new price, specified as by quantity if ($action == 'activate_price_by_qty') { // Activating product price by quantity add a new price, specified as by quantity
$result = $object->fetch($id); $result = $object->fetch($id);
$level=GETPOST('level'); $level=GETPOST('level');
$object->updatePrice($object->id, 0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 1); $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 1);
} }
if ($action == 'edit_price_by_qty') { // Edition d'un prix par quantité if ($action == 'edit_price_by_qty') { // Edition d'un prix par quantité
@ -131,7 +131,7 @@ if ($action == 'update_price_by_qty') { // Ajout / Mise à jour d'un prix par qu
$quantity=GETPOST('quantity'); $quantity=GETPOST('quantity');
$remise_percent=price2num(GETPOST('remise_percent')); $remise_percent=price2num(GETPOST('remise_percent'));
$remise=0; // TODO : allow dicsount by amount when available on documents $remise=0; // TODO : allow dicsount by amount when available on documents
if (empty($quantity)) if (empty($quantity))
{ {
$error++; $error++;
@ -148,10 +148,10 @@ if ($action == 'update_price_by_qty') { // Ajout / Mise à jour d'un prix par qu
{ {
$price = price2num($newprice) / (1 + ($object->tva_tx / 100)); $price = price2num($newprice) / (1 + ($object->tva_tx / 100));
} }
$price = price2num($newprice,'MU'); $price = price2num($newprice,'MU');
$unitPrice = price2num($price/$quantity,'MU'); $unitPrice = price2num($price/$quantity,'MU');
// Ajout / mise à jour // Ajout / mise à jour
if($rowid > 0) { if($rowid > 0) {
$sql = "UPDATE ".MAIN_DB_PREFIX."product_price_by_qty SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."product_price_by_qty SET";
@ -161,12 +161,12 @@ if ($action == 'update_price_by_qty') { // Ajout / Mise à jour d'un prix par qu
$sql.= " remise_percent=".$remise_percent.","; $sql.= " remise_percent=".$remise_percent.",";
$sql.= " remise=".$remise; $sql.= " remise=".$remise;
$sql.= " WHERE rowid = ".GETPOST('rowid'); $sql.= " WHERE rowid = ".GETPOST('rowid');
$result = $db->query($sql); $result = $db->query($sql);
} else { } else {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values (";
$sql.= $priceid.','.$price.','.$unitPrice.','.$quantity.','.$remise_percent.','.$remise.')'; $sql.= $priceid.','.$price.','.$unitPrice.','.$quantity.','.$remise_percent.','.$remise.')';
$result = $db->query($sql); $result = $db->query($sql);
} }
} }
@ -174,19 +174,19 @@ if ($action == 'update_price_by_qty') { // Ajout / Mise à jour d'un prix par qu
if ($action == 'delete_price_by_qty') { if ($action == 'delete_price_by_qty') {
$rowid = GETPOST('rowid'); $rowid = GETPOST('rowid');
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty";
$sql.= " WHERE rowid = ".GETPOST('rowid'); $sql.= " WHERE rowid = ".GETPOST('rowid');
$result = $db->query($sql); $result = $db->query($sql);
} }
if ($action == 'delete_all_price_by_qty') { if ($action == 'delete_all_price_by_qty') {
$priceid=GETPOST('priceid'); $priceid=GETPOST('priceid');
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty";
$sql.= " WHERE fk_product_price = ".$priceid; $sql.= " WHERE fk_product_price = ".$priceid;
$result = $db->query($sql); $result = $db->query($sql);
} }
@ -325,10 +325,10 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES))
if($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) { if($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) {
print '<tr><td>'.$langs->trans("PriceByQuantity").' '.$i; print '<tr><td>'.$langs->trans("PriceByQuantity").' '.$i;
print '</td><td>'; print '</td><td>';
if($object->prices_by_qty[$i] == 1) { if($object->prices_by_qty[$i] == 1) {
print '<table width="50%" class="noborder">'; print '<table width="50%" class="noborder">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("PriceByQuantityRange").' '.$i.'</td>'; print '<td>'.$langs->trans("PriceByQuantityRange").' '.$i.'</td>';
print '<td align="right">'.$langs->trans("HT").'</td>'; print '<td align="right">'.$langs->trans("HT").'</td>';
@ -383,7 +383,7 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES))
print '</tr>'; print '</tr>';
print '</form>'; print '</form>';
} }
print '</table>'; print '</table>';
} else { } else {
print $langs->trans("No"); print $langs->trans("No");
@ -422,16 +422,18 @@ else
print price($object->price_min).' '.$langs->trans($object->price_base_type); print price($object->price_min).' '.$langs->trans($object->price_base_type);
} }
print '</td></tr>'; print '</td></tr>';
// Price by quantity // Price by quantity
if($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) { if($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)
{
print '<tr><td>'.$langs->trans("PriceByQuantity"); print '<tr><td>'.$langs->trans("PriceByQuantity");
if($object->prices_by_qty[0] == 0) { if($object->prices_by_qty[0] == 0) {
print '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=activate_price_by_qty&level=1">'.$langs->trans("Activate"); print '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=activate_price_by_qty&level=1">'.$langs->trans("Activate");
} }
print '</td><td>'; print '</td><td>';
if($object->prices_by_qty[0] == 1) { if ($object->prices_by_qty[0] == 1)
{
print '<table width="50%" class="noborder">'; print '<table width="50%" class="noborder">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("PriceByQuantityRange").'</td>'; print '<td>'.$langs->trans("PriceByQuantityRange").'</td>';
@ -440,7 +442,8 @@ else
print '<td align="right">'.$langs->trans("Discount").'</td>'; print '<td align="right">'.$langs->trans("Discount").'</td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '</tr>'; print '</tr>';
foreach ($object->prices_by_qty_list[0] as $ii=> $prices) { foreach ($object->prices_by_qty_list[0] as $ii=> $prices)
{
if($action == 'edit_price_by_qty' && $rowid == $prices['rowid'] && ($user->rights->produit->creer || $user->rights->service->creer)) { if($action == 'edit_price_by_qty' && $rowid == $prices['rowid'] && ($user->rights->produit->creer || $user->rights->service->creer)) {
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">'; print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
print '<input type="hidden" name="action" value="update_price_by_qty">'; print '<input type="hidden" name="action" value="update_price_by_qty">';
@ -667,8 +670,8 @@ $sql.= " WHERE fk_product = ".$object->id;
$sql.= " AND p.fk_user_author = u.rowid"; $sql.= " AND p.fk_user_author = u.rowid";
if (! empty($socid) && ! empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND p.price_level = ".$soc->price_level; if (! empty($socid) && ! empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND p.price_level = ".$soc->price_level;
$sql.= " ORDER BY p.date_price DESC, p.price_level ASC"; $sql.= " ORDER BY p.date_price DESC, p.price_level ASC";
//$sql .= $db->plimit();
dol_syslog("sql=".$sql);
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
@ -680,7 +683,7 @@ if ($result)
// Il doit au moins y avoir la ligne de prix initial. // Il doit au moins y avoir la ligne de prix initial.
// On l'ajoute donc pour remettre a niveau (pb vieilles versions) // On l'ajoute donc pour remettre a niveau (pb vieilles versions)
$object->updatePrice($object->id, $object->price, $object->price_base_type, $user, $newprice_min); $object->updatePrice($object->price, $object->price_base_type, $user, $newprice_min);
$result = $db->query($sql); $result = $db->query($sql);
$num = $db->num_rows($result); $num = $db->num_rows($result);