diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php
index 4a00894d26b..1d084c915d8 100644
--- a/htdocs/comm/action/card.php
+++ b/htdocs/comm/action/card.php
@@ -1491,6 +1491,10 @@ if ($id > 0) {
$("#fullday").change(function() {
setdatefields();
});
+ $("#actioncode").change(function() {
+ if ($("#actioncode").val() == \'AC_RDV\') $("#dateend").addClass("fieldrequired");
+ else $("#dateend").removeClass("fieldrequired");
+ });
})';
print ''."\n";
}
@@ -1535,7 +1539,11 @@ if ($id > 0) {
print '
| ';
+ print ''.$langs->trans("DateActionStart").'';
+ print ' - ';
+ print 'type_code == 'AC_RDV' ? ' class="fieldrequired"' : '').'>'.$langs->trans("DateActionEnd").'';
+ print ' | ';
$tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
if (GETPOST("afaire") == 1) {
print $form->selectDate($datep ? $datep : $object->datep, 'ap', 1, 1, 0, "action", 1, 1, 0, 'fulldaystart', '', '', '', 1, '', '', $object->fulldayevent ? ($tzforfullday ? $tzforfullday : 'tzuser') : 'tzuser');
diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php
index 9f902c51e29..ebfd7f070d7 100644
--- a/htdocs/comm/propal/card.php
+++ b/htdocs/comm/propal/card.php
@@ -246,8 +246,11 @@ if (empty($reshook)) {
// Remove line
$result = $object->deleteline($lineid);
// reorder lines
- if ($result) {
+ if ($result > 0) {
$object->line_order(true);
+ } else {
+ $langs->load("errors");
+ setEventMessages($object->error, $object->errors, 'errors');
}
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index 26c01ebd044..ef193898df7 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -990,6 +990,8 @@ class Propal extends CommonObject
$this->db->commit();
return 1;
} else {
+ $this->error = $line->error;
+ $this->errors = $line->errors;
$this->db->rollback();
return -1;
}
@@ -4178,36 +4180,40 @@ class PropaleLigne extends CommonObjectLine
$error = 0;
$this->db->begin();
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE rowid = ".((int) $this->rowid);
- dol_syslog("PropaleLigne::delete", LOG_DEBUG);
- if ($this->db->query($sql)) {
- // Remove extrafields
- if (!$error) {
- $this->id = $this->rowid;
- $result = $this->deleteExtraFields();
- if ($result < 0) {
- $error++;
- dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
- }
+ if (!$notrigger) {
+ // Call trigger
+ $result = $this->call_trigger('LINEPROPAL_DELETE', $user);
+ if ($result < 0) {
+ $error++;
}
+ }
+ // End call triggers
- if (!$error && !$notrigger) {
- // Call trigger
- $result = $this->call_trigger('LINEPROPAL_DELETE', $user);
- if ($result < 0) {
- $this->db->rollback();
- return -1;
+ if (!$error) {
+ $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propaldet WHERE rowid = " . ((int) $this->rowid);
+ dol_syslog("PropaleLigne::delete", LOG_DEBUG);
+ if ($this->db->query($sql)) {
+ // Remove extrafields
+ if (!$error) {
+ $this->id = $this->rowid;
+ $result = $this->deleteExtraFields();
+ if ($result < 0) {
+ $error++;
+ dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR);
+ }
}
+ } else {
+ $this->error = $this->db->error() . " sql=" . $sql;
+ $error++;
}
- // End call triggers
+ }
- $this->db->commit();
-
- return 1;
- } else {
- $this->error = $this->db->error()." sql=".$sql;
+ if ($error) {
$this->db->rollback();
return -1;
+ } else {
+ $this->db->commit();
+ return 1;
}
}
diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php
index 46789352bd7..f35def52f4c 100644
--- a/htdocs/core/class/discount.class.php
+++ b/htdocs/core/class/discount.class.php
@@ -54,12 +54,21 @@ class DiscountAbsolute
public $fk_soc;
public $discount_type; // 0 => customer discount, 1 => supplier discount
- public $amount_ht; //
- public $amount_tva; //
- public $amount_ttc; //
- public $multicurrency_amount_ht;
- public $multicurrency_amount_tva;
- public $multicurrency_amount_ttc;
+
+ public $total_ht;
+ public $total_tva;
+ public $total_ttc;
+ public $amount_ht; // deprecated
+ public $amount_tva; // deprecated
+ public $amount_ttc; // deprecated
+
+ public $multicurrency_total_ht;
+ public $multicurrency_total_tva;
+ public $multicurrency_total_ttc;
+ public $multicurrency_amount_ht; // deprecated
+ public $multicurrency_amount_tva; // deprecated
+ public $multicurrency_amount_ttc; // deprecated
+
// Vat rate
public $tva_tx;
public $vat_src_code;
@@ -163,13 +172,21 @@ class DiscountAbsolute
$this->fk_soc = $obj->fk_soc;
$this->discount_type = $obj->discount_type;
- $this->amount_ht = $obj->amount_ht;
- $this->amount_tva = $obj->amount_tva;
- $this->amount_ttc = $obj->amount_ttc;
+ $this->total_ht = $obj->amount_ht;
+ $this->total_tva = $obj->amount_tva;
+ $this->total_ttc = $obj->amount_ttc;
+ // For backward compatibility
+ $this->amount_ht = $this->total_ht;
+ $this->amount_tva = $this->total_tva;
+ $this->amount_ttc = $this->total_ttc;
- $this->multicurrency_amount_ht = $this->multicurrency_subprice = $obj->multicurrency_amount_ht;
- $this->multicurrency_amount_tva = $obj->multicurrency_amount_tva;
- $this->multicurrency_amount_ttc = $obj->multicurrency_amount_ttc;
+ $this->multicurrency_total_ht = $this->multicurrency_subprice = $obj->multicurrency_amount_ht;
+ $this->multicurrency_total_tva = $obj->multicurrency_amount_tva;
+ $this->multicurrency_total_ttc = $obj->multicurrency_amount_ttc;
+ // For backward compatibility
+ $this->multicurrency_amount_ht = $this->multicurrency_total_ht;
+ $this->multicurrency_amount_tva = $this->multicurrency_total_tva;
+ $this->multicurrency_amount_ttc = $this->multicurrency_total_ttc;
$this->tva_tx = $obj->tva_tx;
$this->vat_src_code = $obj->vat_src_code;
diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php
index 68b48af57ea..df4bfeedb9c 100644
--- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php
+++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php
@@ -897,7 +897,7 @@ class pdf_crabe extends ModelePDFFactures
$tab3_width = 80;
$tab3_height = 4;
if ($this->page_largeur < 210) { // To work with US executive format
- $tab3_posx -= 20;
+ $tab3_posx -= 15;
}
$default_font_size = pdf_getPDFFontSize($outputlangs);
@@ -1289,7 +1289,8 @@ class pdf_crabe extends ModelePDFFactures
$col1x = 120;
$col2x = 170;
if ($this->page_largeur < 210) { // To work with US executive format
- $col2x -= 20;
+ $col1x -= 15;
+ $col2x -= 10;
}
$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php
index 7f3b543ebba..5d5b3cf762a 100644
--- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php
+++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php
@@ -540,7 +540,7 @@ class pdf_sponge extends ModelePDFFactures
$pdf->useTemplate($tplidx);
}
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
- $this->_pagehead($pdf, $object, 0, $outputlangs);
+ $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
}
// $this->_pagefoot($pdf,$object,$outputlangs,1);
$pdf->setTopMargin($tab_top_newpage);
@@ -598,7 +598,7 @@ class pdf_sponge extends ModelePDFFactures
$pdf->useTemplate($tplidx);
}
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
- $this->_pagehead($pdf, $object, 0, $outputlangs);
+ $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
}
$height_note = $posyafter - $tab_top_newpage;
$pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
@@ -620,7 +620,7 @@ class pdf_sponge extends ModelePDFFactures
$pdf->useTemplate($tplidx);
}
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
- $this->_pagehead($pdf, $object, 0, $outputlangs);
+ $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
}
$posyafter = $tab_top_newpage;
@@ -922,7 +922,7 @@ class pdf_sponge extends ModelePDFFactures
$pdf->setPage($pagenb);
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
- $this->_pagehead($pdf, $object, 0, $outputlangs);
+ $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
}
}
@@ -940,7 +940,7 @@ class pdf_sponge extends ModelePDFFactures
}
$pagenb++;
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
- $this->_pagehead($pdf, $object, 0, $outputlangs);
+ $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
}
}
}
@@ -1026,7 +1026,7 @@ class pdf_sponge extends ModelePDFFactures
$tab3_width = 80;
$tab3_height = 4;
if ($this->page_largeur < 210) { // To work with US executive format
- $tab3_posx -= 20;
+ $tab3_posx -= 15;
}
$default_font_size = pdf_getPDFFontSize($outputlangs);
@@ -1356,7 +1356,8 @@ class pdf_sponge extends ModelePDFFactures
$col1x = 120;
$col2x = 170;
if ($this->page_largeur < 210) { // To work with US executive format
- $col2x -= 20;
+ $col1x -= 15;
+ $col2x -= 10;
}
$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php
index d1c1906d4a6..b18d10a29b1 100644
--- a/htdocs/core/modules/modProduct.class.php
+++ b/htdocs/core/modules/modProduct.class.php
@@ -857,7 +857,7 @@ class modProduct extends DolibarrModules
}
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
- 'sp.packagning'=>'1',
+ 'sp.packaging'=>'10',
));
}
diff --git a/htdocs/core/modules/modService.class.php b/htdocs/core/modules/modService.class.php
index 0390a23cc83..bdc3388da5c 100644
--- a/htdocs/core/modules/modService.class.php
+++ b/htdocs/core/modules/modService.class.php
@@ -786,7 +786,7 @@ class modService extends DolibarrModules
}
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
- 'sp.packagning'=>'1',
+ 'sp.packagning'=>'10',
));
}
diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index f7ead9bb174..649fb0e106f 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -33,7 +33,7 @@
* \brief File of class to manage suppliers orders
*/
-include_once DOL_DOCUMENT_ROOT.'/core/class/commonorder.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonorder.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
if (!empty($conf->productbatch->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
@@ -438,6 +438,7 @@ class CommandeFournisseur extends CommonOrder
* Lines
*/
$result = $this->fetch_lines();
+
if ($result < 0) {
return -1;
} else {
@@ -460,7 +461,7 @@ class CommandeFournisseur extends CommonOrder
{
global $conf;
// phpcs:enable
- //$result=$this->fetch_lines();
+
$this->lines = array();
$sql = "SELECT l.rowid, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
@@ -471,22 +472,12 @@ class CommandeFournisseur extends CommonOrder
$sql .= " l.fk_unit,";
$sql .= " l.date_start, l.date_end,";
$sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
- $sql .= ", pfp.rowid as fk_pfp, pfp.packaging, MAX(pfp.quantity) as max_qty";
- }
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pfp.entity IN (".getEntity('product_fournisseur_price').") AND l.fk_product = pfp.fk_product and l.ref = pfp.ref_fourn AND l.qty >= pfp.quantity AND pfp.fk_soc = ".((int) $this->socid);
- }
$sql .= " WHERE l.fk_commande = ".((int) $this->id);
if ($only_product) {
$sql .= ' AND p.fk_product_type = 0';
}
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
- $sql.= " GROUP BY l.rowid";
- $sql.= " HAVING (max_qty = MAX(pfp.quantity) OR max_qty IS NULL)";
- }
$sql .= " ORDER BY l.rang, l.rowid";
//print $sql;
@@ -536,11 +527,34 @@ class CommandeFournisseur extends CommonOrder
$line->ref_supplier = $objp->ref_supplier; // The supplier ref of price when product was added. May have change since
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
- $line->fk_fournprice = $objp->fk_pfp;
- $line->packaging = $objp->packaging;
+ // TODO We should not fetch this properties into the fetch_lines. This is NOT properties of a line.
+ // Move this into another method and call it when required.
+
+ // Take better packaging for $objp->qty (first supplier ref quantity <= $objp->qty)
+ $sqlsearchpackage = 'SELECT rowid, packaging FROM '.MAIN_DB_PREFIX."product_fournisseur_price";
+ $sqlsearchpackage .= ' WHERE entity IN ('.getEntity('product_fournisseur_price').")";
+ $sqlsearchpackage .= " AND fk_product = ".((int) $objp->fk_product);
+ $sqlsearchpackage .= " AND ref_fourn = '".$this->db->escape($objp->ref_supplier)."'";
+ $sqlsearchpackage .= " AND quantity <= ".((float) $objp->qty); // required to be qualified
+ $sqlsearchpackage .= " AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).")"; // required to be qualified
+ $sqlsearchpackage .= " AND fk_soc = ".((int) $this->socid);
+ $sqlsearchpackage .= " ORDER BY packaging ASC"; // Take the smaller package first
+ $sqlsearchpackage .= " LIMIT 1";
+
+ $resqlsearchpackage = $this->db->query($sqlsearchpackage);
+ if ($resqlsearchpackage) {
+ $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
+ if ($objsearchpackage) {
+ $line->fk_fournprice = $objsearchpackage->rowid;
+ $line->packaging = $objsearchpackage->packaging;
+ }
+ } else {
+ $this->error = $this->db->lasterror();
+ return -1;
+ }
}
- $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->fk_unit = $objp->fk_unit;
@@ -1817,6 +1831,7 @@ class CommandeFournisseur extends CommonOrder
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$prod = new Product($this->db, $fk_product);
$prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, 'none', ($this->fk_soc ? $this->fk_soc : $this->socid));
+
if ($qty < $prod->packaging) {
$qty = $prod->packaging;
} else {
@@ -3533,25 +3548,18 @@ class CommandeFournisseurLigne extends CommonOrderLine
global $conf;
$sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,';
- $sql .= ' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref,';
+ $sql .= ' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref as ref_supplier,';
$sql .= ' cd.remise, cd.remise_percent, cd.subprice,';
$sql .= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
$sql .= ' cd.total_localtax1, cd.total_localtax2,';
$sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
$sql .= ' cd.date_start, cd.date_end, cd.fk_unit,';
- $sql .= ' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc';
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
- $sql .= ", pfp.rowid as fk_pfp, pfp.packaging, MAX(pfp.quantity) as max_qty";
- }
- $sql .= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd';
+ $sql .= ' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
+ $sql .= ' c.fk_soc as socid';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseur as c, '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid';
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pfp.entity IN (".getEntity('product_fournisseur_price').") AND cd.fk_product = pfp.fk_product and cd.ref = pfp.ref_fourn AND cd.qty >= pfp.quantity";
- }
- $sql .= ' WHERE cd.rowid = '.((int) $rowid);
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
- $sql .= " GROUP BY cd.rowid HAVING (max_qty = MAX(pfp.quantity) OR max_qty IS NULL)";
- }
+ $sql .= ' WHERE cd.fk_commande = c.rowid AND cd.rowid = '.((int) $rowid);
+
$result = $this->db->query($sql);
if ($result) {
$objp = $this->db->fetch_object($result);
@@ -3562,8 +3570,8 @@ class CommandeFournisseurLigne extends CommonOrderLine
$this->fk_commande = $objp->fk_commande;
$this->desc = $objp->description;
$this->qty = $objp->qty;
- $this->ref_fourn = $objp->ref;
- $this->ref_supplier = $objp->ref;
+ $this->ref_fourn = $objp->ref_supplier;
+ $this->ref_supplier = $objp->ref_supplier;
$this->subprice = $objp->subprice;
$this->tva_tx = $objp->tva_tx;
$this->localtax1_tx = $objp->localtax1_tx;
@@ -3587,9 +3595,33 @@ class CommandeFournisseurLigne extends CommonOrderLine
$this->product_ref = $objp->product_ref;
$this->product_label = $objp->product_label;
$this->product_desc = $objp->product_desc;
+
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
- $this->packaging = $objp->packaging;
- $this->fk_fournprice = $objp->fk_pfp;
+ // TODO We should not fetch this properties into the fetch_lines. This is NOT properties of a line.
+ // Move this into another method and call it when required.
+
+ // Take better packaging for $objp->qty (first supplier ref quantity <= $objp->qty)
+ $sqlsearchpackage = 'SELECT rowid, packaging FROM '.MAIN_DB_PREFIX."product_fournisseur_price";
+ $sqlsearchpackage .= ' WHERE entity IN ('.getEntity('product_fournisseur_price').")";
+ $sqlsearchpackage .= " AND fk_product = ".((int) $objp->fk_product);
+ $sqlsearchpackage .= " AND ref_fourn = '".$this->db->escape($objp->ref_supplier)."'";
+ $sqlsearchpackage .= " AND quantity <= ".((float) $objp->qty); // required to be qualified
+ $sqlsearchpackage .= " AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).")"; // required to be qualified
+ $sqlsearchpackage .= " AND fk_soc = ".((int) $objp->socid);
+ $sqlsearchpackage .= " ORDER BY packaging ASC"; // Take the smaller package first
+ $sqlsearchpackage .= " LIMIT 1";
+
+ $resqlsearchpackage = $this->db->query($sqlsearchpackage);
+ if ($resqlsearchpackage) {
+ $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
+ if ($objsearchpackage) {
+ $this->fk_fournprice = $objsearchpackage->rowid;
+ $this->packaging = $objsearchpackage->packaging;
+ }
+ } else {
+ $this->error = $this->db->lasterror();
+ return -1;
+ }
}
$this->date_start = $this->db->jdate($objp->date_start);
diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php
index e20add0bb9d..fb7b9197695 100644
--- a/htdocs/fourn/class/fournisseur.product.class.php
+++ b/htdocs/fourn/class/fournisseur.product.class.php
@@ -317,7 +317,9 @@ class ProductFournisseur extends Product
$qty = price2num($qty, 'MS');
$unitBuyPrice = price2num($buyprice / $qty, 'MU');
- $packaging = price2num(((empty($this->packaging) || $this->packaging < $qty) ? $qty : $this->packaging), 'MS');
+ // We can have a puchase ref that need to buy 100 min for a given price and with a packaging of 50.
+ //$packaging = price2num(((empty($this->packaging) || $this->packaging < $qty) ? $qty : $this->packaging), 'MS');
+ $packaging = price2num((empty($this->packaging) ? $qty : $this->packaging), 'MS');
$error = 0;
$now = dol_now();
@@ -405,6 +407,7 @@ class ProductFournisseur extends Product
$sql .= ", packaging = ".(empty($packaging) ? 1 : $packaging);
}
$sql .= " WHERE rowid = ".((int) $this->product_fourn_price_id);
+ //print $sql;exit;
// TODO Add price_base_type and price_ttc
dol_syslog(get_class($this).'::update_buyprice update knowing id of line = product_fourn_price_id = '.$this->product_fourn_price_id, LOG_DEBUG);
@@ -593,13 +596,7 @@ class ProductFournisseur extends Product
$this->supplier_barcode = $obj->barcode;
$this->supplier_fk_barcode_type = $obj->fk_barcode_type;
}
-
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
- $this->packaging = $obj->packaging;
- if ($this->packaging < $this->fourn_qty) {
- $this->packaging = $this->fourn_qty;
- }
- }
+ $this->packaging = $obj->packaging;
if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) {
$priceparser = new PriceParser($this->db);
@@ -647,10 +644,7 @@ class ProductFournisseur extends Product
$sql .= " pfp.rowid as product_fourn_pri_id, pfp.entity, pfp.ref_fourn, pfp.desc_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.info_bits, pfp.delivery_time_days, pfp.supplier_reputation,";
$sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code, pfp.datec, pfp.tms,";
- $sql .= " pfp.barcode, pfp.fk_barcode_type";
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
- $sql .= ", pfp.packaging";
- }
+ $sql .= " pfp.barcode, pfp.fk_barcode_type, pfp.packaging";
$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."societe as s";
$sql .= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")";
$sql .= " AND pfp.fk_soc = s.rowid AND pfp.fk_product = p.rowid";
@@ -704,12 +698,7 @@ class ProductFournisseur extends Product
$prodfourn->fourn_multicurrency_id = $record["fk_multicurrency"];
$prodfourn->fourn_multicurrency_code = $record["multicurrency_code"];
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
- $prodfourn->packaging = $record["packaging"];
- if ($prodfourn->packaging < $prodfourn->fourn_qty) {
- $prodfourn->packaging = $prodfourn->fourn_qty;
- }
- }
+ $prodfourn->packaging = $record["packaging"];
if (!empty($conf->barcode->enabled)) {
$prodfourn->supplier_barcode = $record["barcode"];
diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql
index 434d30bdfe4..2ec43548bb6 100644
--- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql
+++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql
@@ -84,8 +84,8 @@ UPDATE llx_const set value = __ENCRYPT('eldy')__ WHERE __DECRYPT('value')__ = 'a
UPDATE llx_const set value = __ENCRYPT('eldy')__ WHERE __DECRYPT('value')__ = 'cameleo';
DELETE FROM llx_user_param where param = 'MAIN_THEME' and value in ('auguria', 'amarok', 'cameleo');
-ALTER TABLE llx_product_fournisseur_price ADD COLUMN packaging varchar(64) DEFAULT NULL;
-ALTER TABLE llx_product_fournisseur_price MODIFY COLUMN packaging varchar(64) DEFAULT NULL;
+ALTER TABLE llx_product_fournisseur_price ADD COLUMN packaging real DEFAULT NULL;
+ALTER TABLE llx_product_fournisseur_price MODIFY COLUMN packaging real DEFAULT NULL;
-- For v14
diff --git a/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql b/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql
index 83b97c201ad..8e61de28a73 100644
--- a/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql
+++ b/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql
@@ -50,7 +50,7 @@ create table llx_product_fournisseur_price
import_key varchar(14), -- Import key
delivery_time_days integer,
supplier_reputation varchar(10),
- packaging varchar(64) DEFAULT NULL,
+ packaging real DEFAULT NULL,
fk_multicurrency integer,
multicurrency_code varchar(3),
multicurrency_tx double(24,8) DEFAULT 1,
diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang
index 01a1526bf48..affa3914856 100644
--- a/htdocs/langs/en_US/products.lang
+++ b/htdocs/langs/en_US/products.lang
@@ -346,7 +346,7 @@ UseProductFournDesc=Add a feature to define the product description defined by t
ProductSupplierDescription=Vendor description for the product
UseProductSupplierPackaging=Use packaging on supplier prices (recalculate quantities according to packaging set on supplier price when adding/updating line in supplier documents)
PackagingForThisProduct=Packaging
-PackagingForThisProductDesc=You will automaticaly buy a multiple of this quantity. Can't be lower than the minimum purchase quantity
+PackagingForThisProductDesc=You will automaticaly purchase a multiple of this quantity.
QtyRecalculatedWithPackaging=The quantity of the line were recalculated according to supplier packaging
#Attributes
diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang
index 98faab0c423..0c412beed6e 100644
--- a/htdocs/langs/en_US/stocks.lang
+++ b/htdocs/langs/en_US/stocks.lang
@@ -176,7 +176,7 @@ ProductStockWarehouseCreated=Stock limit for alert and desired optimal stock cor
ProductStockWarehouseUpdated=Stock limit for alert and desired optimal stock correctly updated
ProductStockWarehouseDeleted=Stock limit for alert and desired optimal stock correctly deleted
AddNewProductStockWarehouse=Set new limit for alert and desired optimal stock
-AddStockLocationLine=Decrease quantity then click to add another warehouse for this product
+AddStockLocationLine=Decrease quantity then click to split the line
InventoryDate=Inventory date
Inventories=Inventories
NewInventory=New inventory
diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang
index a9ae791ec8d..14ae8fc0423 100644
--- a/htdocs/langs/fr_FR/products.lang
+++ b/htdocs/langs/fr_FR/products.lang
@@ -346,7 +346,7 @@ UseProductFournDesc=Ajouter une fonctionnalité pour définir la description pro
ProductSupplierDescription=Description du fournisseur du produit
UseProductSupplierPackaging=Utiliser le conditionnement/emballage sur les prix fournisseur (recalculer les quantités en fonction de l'emballage défini sur le prix fournisseur lors de l'ajout / mise à jour de la ligne dans les documents fournisseurs)
PackagingForThisProduct=Emballage
-PackagingForThisProductDesc=Sur une commande fournisseur, vous commanderez automatiquement cette quantité ou un multiple. Vous ne pourrez pas saisir un montant inférieur
+PackagingForThisProductDesc=Sur une commande fournisseur, vous commanderez automatiquement cette quantité ou un multiple.
QtyRecalculatedWithPackaging=La quantité de la ligne a été recalculée en fonction de l'emballage du fournisseur
#Attributes
diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php
index 3bf563c82f7..b63eb7e64df 100644
--- a/htdocs/product/fournisseurs.php
+++ b/htdocs/product/fournisseurs.php
@@ -319,9 +319,10 @@ if (empty($reshook)) {
if (empty($packaging)) {
$packaging = 1;
}
+ /* We can have a puchase ref that need to buy 100 min for a given price and with a packaging of 50.
if ($packaging < $quantity) {
$packaging = $quantity;
- }
+ }*/
$object->packaging = $packaging;
if (!empty($conf->multicurrency->enabled)) {
diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php
index 428ae862e09..561a2d825a5 100644
--- a/htdocs/reception/card.php
+++ b/htdocs/reception/card.php
@@ -267,10 +267,10 @@ if (empty($reshook)) {
$object->origin = $origin;
$object->origin_id = $origin_id;
$object->fk_project = GETPOST('projectid', 'int');
- $object->weight = GETPOST('weight', 'int') == '' ? "NULL" : GETPOST('weight', 'int');
- $object->sizeH = GETPOST('sizeH', 'int') == '' ? "NULL" : GETPOST('sizeH', 'int');
- $object->sizeW = GETPOST('sizeW', 'int') == '' ? "NULL" : GETPOST('sizeW', 'int');
- $object->sizeS = GETPOST('sizeS', 'int') == '' ? "NULL" : GETPOST('sizeS', 'int');
+ $object->weight = GETPOST('weight', 'int') == '' ? null : GETPOST('weight', 'int');
+ $object->sizeH = GETPOST('sizeH', 'int') == '' ? null : GETPOST('sizeH', 'int');
+ $object->sizeW = GETPOST('sizeW', 'int') == '' ? null : GETPOST('sizeW', 'int');
+ $object->sizeS = GETPOST('sizeS', 'int') == '' ? null : GETPOST('sizeS', 'int');
$object->size_units = GETPOST('size_units', 'int');
$object->weight_units = GETPOST('weight_units', 'int');
@@ -1940,15 +1940,16 @@ if ($action == 'create') {
// Warehouse source
if (!empty($conf->stock->enabled)) {
- print ' | ';
-
if ($lines[$i]->fk_entrepot > 0) {
$entrepot = new Entrepot($db);
$entrepot->fetch($lines[$i]->fk_entrepot);
- print $entrepot->getNomUrl(1);
- }
- print ' | ';
+ print '';
+ print $entrepot->getNomUrl(1);
+ print ' | ';
+ } else {
+ print ' | ';
+ }
}
// Batch number managment
diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php
index bb54a8164cd..28fb783e2c9 100644
--- a/htdocs/reception/class/reception.class.php
+++ b/htdocs/reception/class/reception.class.php
@@ -236,7 +236,6 @@ class Reception extends CommonObject
$this->user = $user;
-
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."reception (";
@@ -273,12 +272,12 @@ class Reception extends CommonObject
$sql .= ", ".((int) $this->fk_project);
$sql .= ", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) : "null");
$sql .= ", '".$this->db->escape($this->tracking_number)."'";
- $sql .= ", ".((double) $this->weight);
- $sql .= ", ".((double) $this->sizeS); // TODO Should use this->trueDepth
- $sql .= ", ".((double) $this->sizeW); // TODO Should use this->trueWidth
- $sql .= ", ".((double) $this->sizeH); // TODO Should use this->trueHeight
- $sql .= ", ".((double) $this->weight_units);
- $sql .= ", ".((double) $this->size_units);
+ $sql .= ", ".(is_null($this->weight) ? "NULL" : ((double) $this->weight));
+ $sql .= ", ".(is_null($this->sizeS) ? "NULL" : ((double) $this->sizeS)); // TODO Should use this->trueDepth
+ $sql .= ", ".(is_null($this->sizeW) ? "NULL" : ((double) $this->sizeW)); // TODO Should use this->trueWidth
+ $sql .= ", ".(is_null($this->sizeH) ? "NULL" : ((double) $this->sizeH)); // TODO Should use this->trueHeight
+ $sql .= ", ".(is_null($this->weight_units) ? "NULL" : ((double) $this->weight_units));
+ $sql .= ", ".(is_null($this->size_units) ? "NULL" : ((double) $this->size_units));
$sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
$sql .= ", ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null");
$sql .= ", ".(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null");
@@ -835,8 +834,14 @@ class Reception extends CommonObject
$line->qty = $qty;
$supplierorderline = new CommandeFournisseurLigne($this->db);
- $supplierorderline->fetch($id);
+ $result = $supplierorderline->fetch($id);
+ if ($result <= 0) {
+ $this->error = $supplierorderline->error;
+ $this->errors = $supplierorderline->errors;
+ return -1;
+ }
+ $fk_product = 0;
if (!empty($conf->stock->enabled) && !empty($supplierorderline->fk_product)) {
$fk_product = $supplierorderline->fk_product;