diff --git a/htdocs/accountancy/admin/productaccount.php b/htdocs/accountancy/admin/productaccount.php
index bebca87404c..e07d0c24771 100644
--- a/htdocs/accountancy/admin/productaccount.php
+++ b/htdocs/accountancy/admin/productaccount.php
@@ -136,17 +136,25 @@ if ($action == 'update') {
$accounting = new AccountingAccount($db);
//$msg .= '
' . count($chk_prod) . ' ' . $langs->trans("SelectedLines") . '
';
+ $arrayofdifferentselectedvalues = array();
$cpt = 0; $ok = 0; $ko = 0;
- foreach ( $chk_prod as $productid ) {
-
+ foreach ( $chk_prod as $productid )
+ {
$accounting_account_id = GETPOST('codeventil_' . $productid);
- $result = $accounting->fetch($accounting_account_id, null, 1);
- if ($result < 0) {
+ $result = 0;
+ if ($accounting_account_id > 0)
+ {
+ $arrayofdifferentselectedvalues[$accounting_account_id]=$accounting_account_id;
+ $result = $accounting->fetch($accounting_account_id, null, 1);
+ }
+ if ($result <= 0) {
// setEventMessages(null, $accounting->errors, 'errors');
$msg .= '' . $langs->trans("ErrorDB") . ' : ' . $langs->trans("Product") . ' ' . $productid . ' ' . $langs->trans("NotVentilatedinAccount") . ' : id=' . $accounting_account_id . '
' . $sql . '
';
+ $ko++;
} else {
+ $db->begin();
$sql = " UPDATE " . MAIN_DB_PREFIX . "product";
if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
@@ -158,23 +166,23 @@ if ($action == 'update') {
$sql .= " WHERE rowid = " . $productid;
dol_syslog("/accountancy/admin/productaccount.php sql=" . $sql, LOG_DEBUG);
- if ($db->query($sql)) {
+ if ($db->query($sql))
+ {
$ok++;
- //$msg .= '' . $langs->trans("Product") . ' ' . $productid . ' - ' . $langs->trans("VentilatedinAccount") . ' : ' . length_accountg($accounting->account_number) . '
';
+ $db->commit();
} else {
$ko++;
- //$msg .= '' . $langs->trans("ErrorDB") . ' : ' . $langs->trans("Product") . ' ' . $productid . ' ' . $langs->trans("NotVentilatedinAccount") . ' : ' . length_accountg($accounting->account_number) . '
' . $sql . '
';
+ $db->rollback();
}
}
- $cpt ++;
+ $cpt++;
}
- } else {
- //$msg .= '' . $langs->trans("AnyLineVentilate") . '
';
+
}
+
if ($ko) setEventMessages($langs->trans("XLineFailedToBeBinded", $ko), null, 'errors');
if ($ok) setEventMessages($langs->trans("XLineSuccessfullyBinded", $ok), null, 'mesgs');
- //$msg .= '' . $langs->trans("EndProcessing") . '
';
}
}
diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php
index f5dd7159528..6b7e925832b 100644
--- a/htdocs/accountancy/class/accountingaccount.class.php
+++ b/htdocs/accountancy/class/accountingaccount.class.php
@@ -82,7 +82,7 @@ class AccountingAccount extends CommonObject
* @param int $rowid Id
* @param string $account_number Account number
* @param int $limittocurrentchart 1=Do not load record if it is into another accounting system
- * @return int <0 if KO, Id of record if OK and found
+ * @return int <0 if KO, 0 if not found, Id of record if OK and found
*/
function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0) {
global $conf;
@@ -135,7 +135,7 @@ class AccountingAccount extends CommonObject
$this->errors[] = "Error " . $this->db->lasterror();
}
}
- return - 1;
+ return -1;
}
/**
diff --git a/htdocs/product/card.php b/htdocs/product/card.php
index 9f91765b92d..a54f1d90885 100644
--- a/htdocs/product/card.php
+++ b/htdocs/product/card.php
@@ -1633,20 +1633,20 @@ else
print '';
if ($action == 'editbarcode')
{
- $tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode;
- if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type);
+ $tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode;
+ if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type);
- print '';
+ print '';
}
else
{
- print $object->barcode;
+ print $object->barcode;
}
print ' | '."\n";
}