Merge branch 'develop_NEW_supplier_price_reputation' of

https://github.com/atm-alexis/dolibarr into
atm-alexis-develop_NEW_supplier_price_reputation

Conflicts:
	htdocs/install/mysql/migration/3.9.0-4.0.0.sql
This commit is contained in:
Laurent Destailleur 2016-04-08 22:01:55 +02:00
commit 448758bbf4
6 changed files with 46 additions and 9 deletions

View File

@ -2095,7 +2095,8 @@ class Form
$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration, p.fk_product_type,";
$sql.= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,";
$sql.= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.fk_soc, s.nom as name";
$sql.= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.fk_soc, s.nom as name,";
$sql.= " pfp.supplier_reputation";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
if ($socid) $sql.= " AND pfp.fk_soc = ".$socid;
@ -2234,6 +2235,15 @@ class Form
$opt .= " - ".dol_trunc($objp->name,8);
$outval.=" - ".dol_trunc($objp->name,8);
}
if ($objp->supplier_reputation)
{
//TODO dictionnary
$reputations=array(''=>$langs->trans('Standard'),'FAVORITE'=>$langs->trans('Favorite'),'NOTTHGOOD'=>$langs->trans('NotTheGoodQualitySupplier'), 'DONOTORDER'=>$langs->trans('DoNotOrderThisProductToThisSupplier'));
$opt .= " - ".$reputations[$objp->supplier_reputation];
$outval.=" - ".$reputations[$objp->supplier_reputation];
}
}
else
{

View File

@ -178,9 +178,10 @@ class ProductFournisseur extends Product
* @param float $remise Discount regarding qty (amount)
* @param int $newnpr Set NPR or not
* @param int $delivery_time_days Delay in days for delivery (max). May be '' if not defined.
* @param string $supplier_reputation Reputation with this product to the defined supplier (empty, FAVORITE, DONOTORDER)
* @return int <0 if KO, >=0 if OK
*/
function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges=0, $remise_percent=0, $remise=0, $newnpr=0, $delivery_time_days=0)
function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges=0, $remise_percent=0, $remise=0, $newnpr=0, $delivery_time_days=0, $supplier_reputation='')
{
global $conf, $langs;
//global $mysoc;
@ -191,6 +192,7 @@ class ProductFournisseur extends Product
if (empty($charges)) $charges=0;
if (empty($availability)) $availability=0;
if (empty($remise_percent)) $remise_percent=0;
if (empty($supplier_reputation)) $supplier_reputation='';
if ($delivery_time_days != '' && ! is_numeric($delivery_time_days)) $delivery_time_days = '';
if ($price_base_type == 'TTC')
{
@ -225,7 +227,8 @@ class ProductFournisseur extends Product
$sql.= " entity = ".$conf->entity.",";
$sql.= " info_bits = ".$newnpr.",";
$sql.= " charges = ".$charges.",";
$sql.= " delivery_time_days = ".($delivery_time_days != '' ? $delivery_time_days : 'null');
$sql.= " delivery_time_days = ".($delivery_time_days != '' ? $delivery_time_days : 'null').",";
$sql.= " supplier_reputation = ".(empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'");
$sql.= " WHERE rowid = ".$this->product_fourn_price_id;
// TODO Add price_base_type and price_ttc
@ -268,7 +271,7 @@ class ProductFournisseur extends Product
{
// Add price for this quantity to supplier
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
$sql.= "datec, fk_product, fk_soc, ref_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, charges, unitcharges, fk_availability, info_bits, entity, delivery_time_days)";
$sql.= "datec, fk_product, fk_soc, ref_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, charges, unitcharges, fk_availability, info_bits, entity, delivery_time_days,supplier_reputation)";
$sql.= " values('".$this->db->idate($now)."',";
$sql.= " ".$this->id.",";
$sql.= " ".$fourn->id.",";
@ -285,8 +288,9 @@ class ProductFournisseur extends Product
$sql.= " ".$availability.",";
$sql.= " ".$newnpr.",";
$sql.= $conf->entity.",";
$sql.= $delivery_time_days;
$sql.=")";
$sql.= $delivery_time_days.",";
$sql.= (empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'");
$sql.=")";
dol_syslog(get_class($this)."::update_buyprice", LOG_DEBUG);
if (! $this->db->query($sql))
@ -359,7 +363,8 @@ class ProductFournisseur extends Product
{
global $conf;
$sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability,";
$sql.= " pfp.fk_soc, pfp.ref_fourn, pfp.fk_product, pfp.charges, pfp.unitcharges, pfp.fk_supplier_price_expression, pfp.delivery_time_days"; // , pfp.recuperableonly as fourn_tva_npr"; FIXME this field not exist in llx_product_fournisseur_price
$sql.= " pfp.fk_soc, pfp.ref_fourn, pfp.fk_product, pfp.charges, pfp.unitcharges, pfp.fk_supplier_price_expression, pfp.delivery_time_days,"; // , pfp.recuperableonly as fourn_tva_npr"; FIXME this field not exist in llx_product_fournisseur_price
$sql.=" pfp.supplier_reputation";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
$sql.= " WHERE pfp.rowid = ".$rowid;
@ -389,6 +394,7 @@ class ProductFournisseur extends Product
$this->delivery_time_days = $obj->delivery_time_days;
//$this->fourn_tva_npr = $obj->fourn_tva_npr; // TODO this field not exist in llx_product_fournisseur_price. We should add it ?
$this->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
$this->supplier_reputation = $obj->supplier_reputation;
if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression))
{
@ -437,7 +443,7 @@ class ProductFournisseur extends Product
$sql = "SELECT s.nom as supplier_name, s.rowid as fourn_id,";
$sql.= " pfp.rowid as product_fourn_pri_id, pfp.ref_fourn, pfp.fk_product as product_fourn_id, pfp.fk_supplier_price_expression,";
$sql.= " pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability, pfp.charges, pfp.unitcharges, pfp.info_bits, pfp.delivery_time_days";
$sql.= " pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability, pfp.charges, pfp.unitcharges, pfp.info_bits, pfp.delivery_time_days, pfp.supplier_reputation";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
$sql.= " WHERE pfp.entity IN (".getEntity('product', 1).")";
@ -476,6 +482,7 @@ class ProductFournisseur extends Product
$prodfourn->id = $prodid;
$prodfourn->fourn_tva_npr = $record["info_bits"];
$prodfourn->fk_supplier_price_expression = $record["fk_supplier_price_expression"];
$prodfourn->supplier_reputation = $record["supplier_reputation"];
if (!empty($conf->dynamicprices->enabled) && !empty($prodfourn->fk_supplier_price_expression)) {
$priceparser = new PriceParser($this->db);

View File

@ -361,3 +361,4 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_SUBMIT','Supplier order request submited','Executed when a supplier order is approved','order_supplier',12);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_RECEIVE','Supplier order request received','Executed when a supplier order is received','order_supplier',12);
ALTER TABLE llx_product_fournisseur_price ADD supplier_reputation varchar(10) NULL;

View File

@ -41,5 +41,6 @@ create table llx_product_fournisseur_price
fk_user integer,
fk_supplier_price_expression integer, -- Link to the rule for dynamic price calculation
import_key varchar(14), -- Import key
delivery_time_days integer
delivery_time_days integer,
supplier_reputation varchar(10)
)ENGINE=innodb;

View File

@ -45,3 +45,7 @@ MenuOrdersSupplierToBill=Supplier orders to invoice
NbDaysToDelivery=Delivery delay in days
DescNbDaysToDelivery=The biggest deliver delay of the products from this order
UseDoubleApproval=Use double approval when amount (without tax) is higher than (The second approval can be done by any user with the dedicated permission. Set to 0 for no double approval)
SupplierReputation=Supplier reputation
DoNotOrderThisProductToThisSupplier=Do not order
NotTheGoodQualitySupplier=Wrong quality
ReputationForThisProduct=Reputation

View File

@ -77,6 +77,8 @@ if ($id > 0 || $ref)
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
$reputations=array(''=>$langs->trans('Standard'),'FAVORITE'=>$langs->trans('Favorite'),'NOTTHGOOD'=>$langs->trans('NotTheGoodQualitySupplier'), 'DONOTORDER'=>$langs->trans('DoNotOrderThisProductToThisSupplier'));
if (! $sortfield) $sortfield="s.nom";
if (! $sortorder) $sortorder="ASC";
@ -141,6 +143,7 @@ if (empty($reshook))
$tva_tx = price2num($tva_tx);
$price_expression = GETPOST('eid', 'int') ? GETPOST('eid', 'int') : ''; // Discard expression if not in expression mode
$delivery_time_days = GETPOST('delivery_time_days', 'int') ? GETPOST('delivery_time_days', 'int') : '';
$supplier_reputation = GETPOST('supplier_reputation');
if ($tva_tx == '')
{
@ -379,6 +382,11 @@ if ($id > 0 || $ref)
}
print '</td></tr>';
//reputation
print '<tr><td class="fieldrequired">'.$langs->trans("SupplierReputation").'</td><td>';
echo $form->selectarray('supplier_reputation', $reputations,$product->supplier_reputation);
print '</td></tr>';
// Ref supplier
print '<tr><td class="fieldrequired">'.$langs->trans("SupplierRef").'</td><td>';
if ($rowid)
@ -566,6 +574,7 @@ if ($id > 0 || $ref)
$param="&id=".$object->id;
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Suppliers"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("ReputationForThisProduct"));
print_liste_field_titre($langs->trans("SupplierRef"));
if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) print_liste_field_titre($langs->trans("Availability"),$_SERVER["PHP_SELF"],"pfp.fk_availability","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("QtyMin"),$_SERVER["PHP_SELF"],"pfp.quantity","",$param,'align="right"',$sortfield,$sortorder);
@ -597,6 +606,11 @@ if ($id > 0 || $ref)
print "<tr ".$bc[$var].">";
print '<td>'.$productfourn->getSocNomUrl(1,'supplier').'</td>';
print '<td>';
if(!empty($productfourn->supplier_reputation) && !empty($reputations[$productfourn->supplier_reputation])) {
print $reputations[$productfourn->supplier_reputation];
}
print'</td>';
// Supplier
print '<td align="left">'.$productfourn->fourn_ref.'</td>';