2
0
forked from Wavyzz/dolibarr

Merge branch '4.0' of git@github.com:Dolibarr/dolibarr.git into develop

Conflicts:
	htdocs/core/class/extrafields.class.php
	htdocs/fourn/class/fournisseur.commande.class.php
	htdocs/fourn/class/fournisseur.facture.class.php
	htdocs/product/class/product.class.php
This commit is contained in:
Laurent Destailleur
2016-12-14 12:29:41 +01:00
8 changed files with 56 additions and 37 deletions

View File

@@ -106,7 +106,7 @@ $fsearch.=' <input type="text" name="min" id="min" value="'.$min.'" size="6">';
$calc=$conf->global->MAIN_INFO_LOCALTAX_CALC.$local; $calc=$conf->global->MAIN_INFO_LOCALTAX_CALC.$local;
// Affiche en-tete du rapport // Affiche en-tete du rapport
if ($conf->global->$calc==0 || $conf->global->$calc==1) // Calculate on invoice for goods and services if ($calc==0 || $calc==1) // Calculate on invoice for goods and services
{ {
$nom=$langs->transcountry($local==1?"LT1ReportByCustomersInInputOutputMode":"LT2ReportByCustomersInInputOutputMode",$mysoc->country_code); $nom=$langs->transcountry($local==1?"LT1ReportByCustomersInInputOutputMode":"LT2ReportByCustomersInInputOutputMode",$mysoc->country_code);
$calcmode=$calc==0?$langs->trans("CalcModeLT".$local):$langs->trans("CalcModeLT".$local."Rec"); $calcmode=$calc==0?$langs->trans("CalcModeLT".$local):$langs->trans("CalcModeLT".$local."Rec");
@@ -124,7 +124,7 @@ if ($conf->global->$calc==0 || $conf->global->$calc==1) // Calculate on invoice
$productsup=$langs->trans("Description"); $productsup=$langs->trans("Description");
$amountsup=$langs->trans("AmountHT"); $amountsup=$langs->trans("AmountHT");
} }
if ($conf->global->$calc==2) // Invoice for goods, payment for services if ($calc==2) // Invoice for goods, payment for services
{ {
$nom=$langs->transcountry($local==1?"LT1ReportByCustomersInInputOutputMode":"LT2ReportByCustomersInInputOutputMode",$mysoc->country_code); $nom=$langs->transcountry($local==1?"LT1ReportByCustomersInInputOutputMode":"LT2ReportByCustomersInInputOutputMode",$mysoc->country_code);
$calcmode=$langs->trans("CalcModeLT2Debt"); $calcmode=$langs->trans("CalcModeLT2Debt");
@@ -149,7 +149,7 @@ $vatcust=$langs->transcountry($local==1?"LT1":"LT2",$mysoc->country_code);
$vatsup=$langs->transcountry($local==1?"LT1":"LT2",$mysoc->country_code); $vatsup=$langs->transcountry($local==1?"LT1":"LT2",$mysoc->country_code);
// IRPF that the customer has retained me // IRPF that the customer has retained me
if($conf->global->$calc ==0 || $conf->global->$calc == 2) if($calc ==0 || $calc == 2)
{ {
print "<table class=\"noborder\" width=\"100%\">"; print "<table class=\"noborder\" width=\"100%\">";
print "<tr class=\"liste_titre\">"; print "<tr class=\"liste_titre\">";
@@ -232,7 +232,7 @@ if($conf->global->$calc ==0 || $conf->global->$calc == 2)
} }
// IRPF I retained my supplier // IRPF I retained my supplier
if($conf->global->$calc ==0 || $conf->global->$calc == 1){ if($calc ==0 || $calc == 1){
print "<table class=\"noborder\" width=\"100%\">"; print "<table class=\"noborder\" width=\"100%\">";
print "<tr class=\"liste_titre\">"; print "<tr class=\"liste_titre\">";
print '<td align="left">'.$langs->trans("Num")."</td>"; print '<td align="left">'.$langs->trans("Num")."</td>";
@@ -309,7 +309,7 @@ if($conf->global->$calc ==0 || $conf->global->$calc == 1){
} }
} }
if($conf->global->$calc ==0){ if($calc ==0){
// Total to pay // Total to pay
print '<br><br>'; print '<br><br>';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';

View File

@@ -771,7 +771,7 @@ class ExtraFields
} }
elseif ($type == 'price') elseif ($type == 'price')
{ {
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keysuffix.'options_'.$key.$keyprefix.'" value="'.price($value).'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency); $out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keysuffix.'options_'.$key.$keyprefix.'" value="'.price2num($value).'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency);
} }
elseif ($type == 'double') elseif ($type == 'double')
{ {

View File

@@ -1195,6 +1195,8 @@ class SMTPs
$host=preg_replace('@tcp://@i','',$host); // Remove prefix $host=preg_replace('@tcp://@i','',$host); // Remove prefix
$host=preg_replace('@ssl://@i','',$host); // Remove prefix $host=preg_replace('@ssl://@i','',$host); // Remove prefix
$host=dol_getprefix().'-'.$host;
//NOTE: Message-ID should probably contain the username of the user who sent the msg //NOTE: Message-ID should probably contain the username of the user who sent the msg
$_header .= 'Subject: ' . $this->getSubject() . "\r\n"; $_header .= 'Subject: ' . $this->getSubject() . "\r\n";
$_header .= 'Date: ' . date("r") . "\r\n"; $_header .= 'Date: ' . date("r") . "\r\n";

View File

@@ -325,8 +325,15 @@ function GETPOST($paramname,$check='',$method=0,$filter=NULL,$options=NULL)
*/ */
function dol_getprefix() function dol_getprefix()
{ {
global $conf;
if (isset($_SERVER["SERVER_NAME"]) && isset($_SERVER["DOCUMENT_ROOT"])) if (isset($_SERVER["SERVER_NAME"]) && isset($_SERVER["DOCUMENT_ROOT"]))
{ {
if (! empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID))
{
if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID == 'SERVER_NAME') return $_SERVER["SERVER_NAME"];
return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
}
return dol_hash($_SERVER["SERVER_NAME"].$_SERVER["DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT); return dol_hash($_SERVER["SERVER_NAME"].$_SERVER["DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
// Use this for a "clear" cookie name // Use this for a "clear" cookie name
//return dol_sanitizeFileName($_SERVER["SERVER_NAME"].$_SERVER["DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT); //return dol_sanitizeFileName($_SERVER["SERVER_NAME"].$_SERVER["DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);

View File

@@ -327,10 +327,10 @@ class CommandeFournisseur extends CommonOrder
$line->product_label = $objp->product_label; $line->product_label = $objp->product_label;
$line->product_desc = $objp->product_desc; $line->product_desc = $objp->product_desc;
$line->ref = $objp->product_ref; $line->ref = $objp->product_ref; // Ref of product
$line->product_ref = $objp->product_ref; $line->product_ref = $objp->product_ref; // Ref of product
$line->ref_fourn = $objp->ref_supplier; $line->ref_fourn = $objp->ref_supplier; // The supplier ref of price when product was added. May have change since
$line->ref_supplier = $objp->ref_supplier; $line->ref_supplier = $objp->ref_supplier; // The supplier ref of price when product was added. May have change since
$line->date_start = $this->db->jdate($objp->date_start); $line->date_start = $this->db->jdate($objp->date_start);
$line->date_end = $this->db->jdate($objp->date_end); $line->date_end = $this->db->jdate($objp->date_end);
@@ -1160,7 +1160,7 @@ class CommandeFournisseur extends CommonOrder
$this->lines[$i]->localtax2_tx, $this->lines[$i]->localtax2_tx,
$this->lines[$i]->fk_product, $this->lines[$i]->fk_product,
0, 0,
$this->lines[$i]->ref_fourn, $this->lines[$i]->ref_fourn, // $this->lines[$i]->ref_fourn comes from field ref into table of lines. Value may ba a ref that does not exists anymore, so we first try with value of product
$this->lines[$i]->remise_percent, $this->lines[$i]->remise_percent,
'HT', 'HT',
0, 0,
@@ -1322,7 +1322,7 @@ class CommandeFournisseur extends CommonOrder
* @param float $txlocaltax2 Localtax2 tax * @param float $txlocaltax2 Localtax2 tax
* @param int $fk_product Id product * @param int $fk_product Id product
* @param int $fk_prod_fourn_price Id supplier price * @param int $fk_prod_fourn_price Id supplier price
* @param string $fourn_ref Supplier reference * @param string $fourn_ref Supplier reference price
* @param float $remise_percent Remise * @param float $remise_percent Remise
* @param string $price_base_type HT or TTC * @param string $price_base_type HT or TTC
* @param float $pu_ttc Unit price TTC * @param float $pu_ttc Unit price TTC
@@ -1369,6 +1369,7 @@ class CommandeFournisseur extends CommonOrder
$pu=$pu_ttc; $pu=$pu_ttc;
} }
$desc=trim($desc); $desc=trim($desc);
$ref_supplier=''; // Ref of supplier price when we add line
// Check parameters // Check parameters
if ($qty < 1 && ! $fk_product) if ($qty < 1 && ! $fk_product)
@@ -1391,15 +1392,28 @@ class CommandeFournisseur extends CommonOrder
$prod = new Product($this->db, $fk_product); $prod = new Product($this->db, $fk_product);
if ($prod->fetch($fk_product) > 0) if ($prod->fetch($fk_product) > 0)
{ {
$result=$prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, $fourn_ref); // Search on couple $fk_prod_fourn_price/$qty first, then on triplet $qty/$fk_product/$fourn_ref $product_type = $prod->type;
$label = $prod->libelle;
// We use 'none' instead of $fourn_ref, because fourn_ref may not exists anymore. So we will take the first supplier price ok.
// If we want a dedicated supplier price, we must provide $fk_prod_fourn_price.
$result=$prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, 'none', $this->fk_soc); // Search on couple $fk_prod_fourn_price/$qty first, then on triplet $qty/$fk_product/$fourn_ref/$this->fk_soc
if ($result > 0) if ($result > 0)
{ {
$label = $prod->libelle; $pu = $prod->fourn_pu; // Unit price supplier price set by get_buyprice
$pu = $prod->fourn_pu; $ref_supplier = $prod->ref_supplier; // Ref supplier price set by get_buyprice
$ref_supplier = $prod->ref_supplier;
$product_type = $prod->type;
} }
if ($result == 0 || $result == -1) if ($result == 0) // If result == 0, we failed to found the supplier reference price
{
$langs->load("errors");
$this->error = "Ref " . $prod->ref . " " . $langs->trans("ErrorQtyTooLowForThisSupplier");
$this->db->rollback();
dol_syslog(get_class($this)."::addline we did not found supplier price, so we can't guess unit price");
//$pu = $prod->fourn_pu; // We do not overwrite unit price
//$ref = $prod->ref_fourn; // We do not overwrite ref supplier price
return -1;
}
if ($result == -1)
{ {
$langs->load("errors"); $langs->load("errors");
$this->error = "Ref " . $prod->ref . " " . $langs->trans("ErrorQtyTooLowForThisSupplier"); $this->error = "Ref " . $prod->ref . " " . $langs->trans("ErrorQtyTooLowForThisSupplier");
@@ -2899,15 +2913,7 @@ class CommandeFournisseurLigne extends CommonOrderLine
// From llx_product_fournisseur_price // From llx_product_fournisseur_price
/** /**
* Supplier ref * Supplier reference of price when we added the line. May have been changed after line was added.
* @var string
* @deprecated Use ref_supplier
* @see ref_supplier
*/
public $ref_fourn;
/**
* Supplier reference
* @var string * @var string
*/ */
public $ref_supplier; public $ref_supplier;

View File

@@ -2263,12 +2263,14 @@ class SupplierInvoiceLine extends CommonObjectLine
* @var string * @var string
*/ */
public $product_ref; public $product_ref;
/** /**
* Reference product supplier * Supplier reference of price when we added the line. May have been changed after line was added.
* TODO Rename field ref to ref_supplier into table llx_facture_fourn_det and llx_commande_fournisseurdet and update fields it into updateline * TODO Rename field ref to ref_supplier into table llx_facture_fourn_det and llx_commande_fournisseurdet and update fields into updateline
* @var string * @var string
*/ */
public $ref_supplier; public $ref_supplier;
/** /**
* @deprecated * @deprecated
* @see label * @see label

View File

@@ -944,7 +944,7 @@ class Product extends CommonObject
// Delete all child tables // Delete all child tables
if (! $error) if (! $error)
{ {
$elements = array('product_fournisseur_price','product_price','product_lang','categorie_product','product_stock','product_customer_price','product_lot','product_warehouse_properties'); $elements = array('product_fournisseur_price','product_price','product_lang','categorie_product','product_stock','product_customer_price','product_lot','product_warehouse_properties'); // product_batch is done before
foreach($elements as $table) foreach($elements as $table)
{ {
if (! $error) if (! $error)
@@ -1341,10 +1341,11 @@ class Product extends CommonObject
* @param int $prodfournprice Id du tarif = rowid table product_fournisseur_price * @param int $prodfournprice Id du tarif = rowid table product_fournisseur_price
* @param double $qty Quantity asked or -1 to get first entry found * @param double $qty Quantity asked or -1 to get first entry found
* @param int $product_id Filter on a particular product id * @param int $product_id Filter on a particular product id
* @param string $fourn_ref Filter on a supplier ref. 'none' to exclude ref in search. * @param string $fourn_ref Filter on a supplier price ref. 'none' to exclude ref in search.
* @param int $fk_soc If of supplier
* @return int <-1 if KO, -1 if qty not enough, 0 if OK but nothing found, id_product if OK and found. May also initialize some properties like (->ref_supplier, buyprice, fourn_pu, vatrate_supplier...) * @return int <-1 if KO, -1 if qty not enough, 0 if OK but nothing found, id_product if OK and found. May also initialize some properties like (->ref_supplier, buyprice, fourn_pu, vatrate_supplier...)
*/ */
function get_buyprice($prodfournprice, $qty, $product_id=0, $fourn_ref='') function get_buyprice($prodfournprice, $qty, $product_id=0, $fourn_ref='', $fk_soc=0)
{ {
global $conf; global $conf;
$result = 0; $result = 0;
@@ -1390,12 +1391,13 @@ class Product extends CommonObject
} }
else // If not found else // If not found
{ {
// We do a second search by doing a select again but searching with qty and id product // We do a second search by doing a select again but searching with less reliable criteria: couple qty/id product, and if set fourn_ref or fk_soc.
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.fk_soc,"; $sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.fk_soc,";
$sql.= " pfp.fk_product, pfp.ref_fourn as ref_supplier, pfp.tva_tx, pfp.fk_supplier_price_expression"; $sql.= " pfp.fk_product, pfp.ref_fourn as ref_supplier, pfp.tva_tx, pfp.fk_supplier_price_expression";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
$sql.= " WHERE pfp.fk_product = ".$product_id; $sql.= " WHERE pfp.fk_product = ".$product_id;
if ($fourn_ref != 'none') $sql.= " AND pfp.ref_fourn = '".$fourn_ref."'"; if ($fourn_ref != 'none') $sql.= " AND pfp.ref_fourn = '".$fourn_ref."'";
if ($fk_soc > 0) $sql.= " AND pfp.fk_soc = ".$fk_soc;
if ($qty > 0) $sql.= " AND pfp.quantity <= ".$qty; if ($qty > 0) $sql.= " AND pfp.quantity <= ".$qty;
$sql.= " ORDER BY pfp.quantity DESC"; $sql.= " ORDER BY pfp.quantity DESC";
$sql.= " LIMIT 1"; $sql.= " LIMIT 1";

View File

@@ -5,7 +5,7 @@
* Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014-2015 Philippe Grand <philippe.grand@atoo-net.com> * Copyright (C) 2014-2015 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2014 Ion agorria <ion@agorria.com> * Copyright (C) 2014 Ion agorria <ion@agorria.com>
* Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
@@ -286,8 +286,8 @@ if (empty($reshook))
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$npr = $obj->recuperableonly; $npr = $obj->recuperableonly;
$localtax1 = $obj->localtax1; $localtax1 = get_localtax($tva_tx,1);
$localtax2 = $obj->localtax2; $localtax2 = get_localtax($tva_tx,2);
$localtax1_type = $obj->localtax1_type; $localtax1_type = $obj->localtax1_type;
$localtax2_type = $obj->localtax2_type; $localtax2_type = $obj->localtax2_type;
} }