Qual getSupplierPrices

use productfourn method list_product_fournisseur_price because query has
same purpose.
This commit is contained in:
fappels 2015-10-15 22:54:42 +02:00
parent b43047bc2f
commit 74c373a3af

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr> /* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2015 Francis Appels <francis.appels@z-application.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -48,80 +49,39 @@ if ($idprod > 0)
{ {
$producttmp=new ProductFournisseur($db); $producttmp=new ProductFournisseur($db);
$producttmp->fetch($idprod); $producttmp->fetch($idprod);
$productSupplierArray = $producttmp->list_product_fournisseur_price($idprod);
$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,"; if ( is_array($productSupplierArray))
$sql.= " pfp.ref_fourn,";
$sql.= " pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice, pfp.charges, pfp.unitcharges,";
$sql.= " pfp.fk_supplier_price_expression, pfp.tva_tx, s.nom as name";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = pfp.fk_product";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = pfp.fk_soc";
$sql.= " WHERE pfp.fk_product = ".$idprod;
$sql.= " AND p.tobuy = 1";
$sql.= " AND s.fournisseur = 1";
$sql.= " ORDER BY s.nom, pfp.ref_fourn DESC";
dol_syslog("Ajax::getSupplierPrices", LOG_DEBUG);
$result=$db->query($sql);
if ($result)
{ {
$num = $db->num_rows($result); foreach ($productSupplierArray as $productSupplier)
if ($num)
{ {
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; $price = $productSupplier->fourn_price * (1 - $productSupplier->fourn_remise_percent / 100);
$i = 0; $unitprice = $productSupplier->fourn_unitprice * (1 - $productSupplier->fourn_remise_percent / 100);
while ($i < $num)
$title = $productSupplier->fourn_name.' - '.$productSupplier->fourn_ref.' - ';
if ($productSupplier->fourn_qty == 1)
{ {
$objp = $db->fetch_object($result); $title.= price($price,0,$langs,0,0,-1,$conf->currency)."/";
}
$title.= $productSupplier->fourn_qty.' '.($productSupplier->fourn_qty == 1 ? $langs->trans("Unit") : $langs->trans("Units"));
if (!empty($objp->fk_supplier_price_expression)) { if ($productSupplier->fourn_qty > 1)
$priceparser = new PriceParser($db); {
$price_result = $priceparser->parseProductSupplier($idprod, $objp->fk_supplier_price_expression, $objp->quantity, $objp->tva_tx); $title.=" - ";
if ($price_result >= 0) { $title.= price($unitprice,0,$langs,0,0,-1,$conf->currency)."/".$langs->trans("Unit");
$objp->fprice = $price_result; $price = $unitprice;
if ($objp->quantity >= 1) }
{ if ($productSupplier->fourn_unitcharges > 0 && ($conf->global->MARGIN_TYPE == "2"))
$objp->unitprice = $objp->fprice / $objp->quantity; {
} $title.=" + ";
} $title.= price($productSupplier->fourn_unitcharges,0,$langs,0,0,-1,$conf->currency);
} $price += $productSupplier->fourn_unitcharges;
$price = $objp->fprice * (1 - $objp->remise_percent / 100);
$unitprice = $objp->unitprice * (1 - $objp->remise_percent / 100);
$title = $objp->name.' - '.$objp->ref_fourn.' - ';
if ($objp->quantity == 1)
{
$title.= price($price,0,$langs,0,0,-1,$conf->currency)."/";
}
$title.= $objp->quantity.' '.($objp->quantity == 1 ? $langs->trans("Unit") : $langs->trans("Units"));
if ($objp->quantity > 1)
{
$title.=" - ";
$title.= price($unitprice,0,$langs,0,0,-1,$conf->currency)."/".$langs->trans("Unit");
$price = $unitprice;
}
if ($objp->unitcharges > 0 && ($conf->global->MARGIN_TYPE == "2"))
{
$title.=" + ";
$title.= price($objp->unitcharges,0,$langs,0,0,-1,$conf->currency);
$price += $objp->unitcharges;
}
if ($objp->duration) $label .= " - ".$objp->duration;
$label = price($price,0,$langs,0,0,-1,$conf->currency)."/".$langs->trans("Unit");
if ($objp->ref_fourn) $label.=' ('.$objp->ref_fourn.')';
$prices[] = array("id" => $objp->idprodfournprice, "price" => price($price,0,'',0), "label" => $label, "title" => $title);
$i++;
} }
$db->free($result); $label = price($price,0,$langs,0,0,-1,$conf->currency)."/".$langs->trans("Unit");
if ($productSupplier->fourn_ref) $label.=' ('.$productSupplier->fourn_ref.')';
$prices[] = array("id" => $productSupplier->product_fourn_price_id, "price" => price($price,0,'',0), "label" => $label, "title" => $title);
} }
} }