diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 13047234834..d8723334328 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -128,7 +128,7 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') // Protection and encryption of pdf if (empty($conf->global->MAIN_USE_FPDF) && ! empty($conf->global->PDF_SECURITY_ENCRYPTION)) - { + { /* Permission supported by TCPDF - print : Print the document; - modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble'; @@ -957,7 +957,7 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang)) { if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label) $label=$prodser->multilangs[$outputlangs->defaultlang]["label"]; - + //Manage HTML entities description test //Cause $prodser->description is store with htmlentities but $desc no $needdesctranslation=false; @@ -1032,10 +1032,10 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl if (empty($hideref)) { - if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->transnoentitiesnoconv("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref + if ($issupplierline) $ref_prodserv = $prodser->ref.($ref_supplier ? ' ('.$outputlangs->transnoentitiesnoconv("SupplierRef").' '.$ref_supplier.')' : ''); // Show local ref and supplier ref else $ref_prodserv = $prodser->ref; // Show local ref only - $ref_prodserv .= " - "; + if (! empty($libelleproduitservice)) $ref_prodserv .= " - "; } $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index d8f15c5b9b3..d8a1a1d824e 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -420,7 +420,7 @@ class FactureFournisseur extends CommonInvoice */ function fetch_lines() { - $sql = 'SELECT f.rowid, f.description, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx, f.tva'; + $sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx, f.tva'; $sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 '; $sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits'; $sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc'; @@ -428,7 +428,7 @@ class FactureFournisseur extends CommonInvoice $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid'; $sql.= ' WHERE fk_facture_fourn='.$this->id; - dol_syslog("FactureFournisseur::fetch_lines sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."::fetch_lines sql=".$sql, LOG_DEBUG); $resql_rows = $this->db->query($sql); if ($resql_rows) { @@ -443,10 +443,10 @@ class FactureFournisseur extends CommonInvoice $this->lines[$i] = new stdClass(); $this->lines[$i]->rowid = $obj->rowid; $this->lines[$i]->description = $obj->description; - $this->lines[$i]->ref = $obj->product_ref; // TODO deprecated $this->lines[$i]->product_ref = $obj->product_ref; // Internal reference - //$this->lines[$i]->ref_fourn = $obj->ref_fourn; // Reference fournisseur du produit - $this->lines[$i]->libelle = $obj->label; // Label du produit + $this->lines[$i]->ref = $obj->product_ref; // TODO deprecated. Replace with next line + //$this->lines[$i]->ref_supplier = $obj->ref_supplier; // Reference product supplier TODO Rename field ref into ref_supplier into table llx_facture_fourn_det and update it into updateline + $this->lines[$i]->libelle = $obj->label; // deprecated $this->lines[$i]->product_desc = $obj->product_desc; // Description du produit $this->lines[$i]->pu_ht = $obj->pu_ht; $this->lines[$i]->pu_ttc = $obj->pu_ttc; @@ -474,7 +474,7 @@ class FactureFournisseur extends CommonInvoice else { $this->error=$this->db->error(); - dol_syslog('FactureFournisseur::fetch_lines: Error '.$this->error,LOG_ERR); + dol_syslog(get_class($this).'::fetch_lines: Error '.$this->error,LOG_ERR); return -3; } } @@ -1127,7 +1127,7 @@ class FactureFournisseur extends CommonInvoice * Update a line detail into database * * @param int $id Id of line invoice - * @param string $label Description of line + * @param string $desc Description of line * @param double $pu Prix unitaire (HT ou TTC selon price_base_type) * @param double $vatrate VAT Rate * @param double $txlocaltax1 LocalTax1 Rate @@ -1141,9 +1141,9 @@ class FactureFournisseur extends CommonInvoice * @param int $notrigger Disable triggers * @return int <0 if KO, >0 if OK */ - function updateline($id, $label, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false) + function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false) { - dol_syslog(get_class($this)."::updateline $id,$label,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent", LOG_DEBUG); + dol_syslog(get_class($this)."::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent", LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; $pu = price2num($pu); @@ -1169,7 +1169,7 @@ class FactureFournisseur extends CommonInvoice $localtaxes_type=getLocalTaxesFromRate($vatrate,0,$this->thirdparty); - $tabprice = calcul_price_total($qty, $pu, $remise_percent, $vatrate, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty,$localtaxes_type); + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $vatrate, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; $total_ttc = $tabprice[2]; @@ -1192,7 +1192,7 @@ class FactureFournisseur extends CommonInvoice } $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det SET"; - $sql.= " description ='".$this->db->escape($label)."'"; + $sql.= " description ='".$this->db->escape($desc)."'"; $sql.= ", pu_ht = ".price2num($pu_ht); $sql.= ", pu_ttc = ".price2num($pu_ttc); $sql.= ", qty = ".price2num($qty); diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 10bbd8b270b..5efef7b7c35 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -40,8 +40,13 @@ class ProductFournisseur extends Product var $product_fourn_price_id; // id of ligne product-supplier var $id; // product id - var $fourn_ref; // ref supplier - var $fourn_qty; // quantity for price + var $fourn_ref; // deprecated + var $ref_supplier; // ref supplier (can be set by get_buyprice) + var $vatrate_supplier; // default vat rate for this supplier/qty/product (can be set by get_buyprice) + + var $fourn_qty; // quantity for price (can be set by get_buyprice) + var $fourn_pu; // unit price for quantity (can be set by get_buyprice) + var $fourn_price; // price for quantity var $fourn_remise_percent; // discount for quantity (percent) var $fourn_remise; // discount for quantity (amount) diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 566ae26f640..0f15ff42885 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -542,7 +542,7 @@ elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer) } if (GETPOST('addline_predefined') || (! GETPOST('dp_desc') && ! GETPOST('addline_predefined') && GETPOST('idprod', 'int')>0) // we push enter onto qty field - ) + ) { $predef=(($conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : ''); $idprod=GETPOST('idprod', 'int'); @@ -593,6 +593,7 @@ elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer) $type = $productsupplier->type; + // TODO Save the product supplier ref into database into field ref_supplier (must rename field ref into ref_supplier first) $result=$object->addline($desc, $productsupplier->fourn_pu, $tvatx, $localtax1tx, $localtax2tx, $qty, $idprod, $remise_percent, '', '', 0, $npr); } if ($idprod == 0) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 308ca339303..934706a1c95 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -902,14 +902,14 @@ class Product extends CommonObject /** - * Lit le prix pratique par un fournisseur - * On renseigne le couple prodfournprice/qty ou le triplet qty/product_id/fourn_ref + * Read price used by a provider + * We enter as input couple prodfournprice/qty or triplet qty/product_id/fourn_ref * * @param int $prodfournprice Id du tarif = rowid table product_fournisseur_price * @param double $qty Quantity asked * @param int $product_id Filter on a particular product id * @param string $fourn_ref Filter on a supplier ref - * @return int <-1 if KO, -1 if qty not enough, 0 si ok mais rien trouve, id_product si ok et trouve + * @return int <-1 if KO, -1 if qty not enough, 0 si ok mais rien trouve, id_product si ok et trouve. May also initialize some properties like (->ref_supplier, buyprice, fourn_pu, vatrate_supplier...) */ function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=0) { @@ -940,7 +940,7 @@ class Product extends CommonObject { // We do same select again but searching with qty, ref and id product $sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.fk_soc,"; - $sql.= " pfp.fk_product, pfp.ref_fourn, pfp.tva_tx"; + $sql.= " pfp.fk_product, pfp.ref_fourn as ref_supplier, pfp.tva_tx"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; $sql.= " WHERE pfp.ref_fourn = '".$fourn_ref."'"; $sql.= " AND pfp.fk_product = ".$product_id; @@ -955,9 +955,11 @@ class Product extends CommonObject $obj = $this->db->fetch_object($resql); if ($obj && $obj->quantity > 0) // If found { - $this->buyprice = $obj->price; // \deprecated + $this->buyprice = $obj->price; // deprecated + $this->fourn_qty = $obj->quantity; // min quantity for price $this->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id - $this->ref_fourn = $obj->ref_fourn; // Ref supplier + $this->ref_fourn = $obj->ref_supplier; // deprecated + $this->ref_supplier = $obj->ref_supplier; // Ref supplier $this->vatrate_supplier = $obj->tva_tx; // Vat ref supplier $result=$obj->fk_product; return $result;