From b57c40ef78ae366d03f0af2ff733080a47dd88eb Mon Sep 17 00:00:00 2001 From: lvessiller Date: Tue, 12 Jul 2022 11:32:12 +0200 Subject: [PATCH 1/7] FIX load product stock in inventory lines --- htdocs/product/inventory/inventory.php | 56 ++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 85cd0932f46..2c8a9bd2e13 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -103,6 +103,8 @@ if ($cancel) { $action = ''; } +$error = 0; + if ($action == 'cancel_record' && $permissiontoadd) { $object->setCanceled($user); } @@ -111,6 +113,8 @@ if ($action == 'update' && !empty($user->rights->stock->mouvement->creer)) { $stockmovment = new MouvementStock($db); $stockmovment->origin = $object; + $cacheOfProducts = array(); + $db->begin(); $sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,'; @@ -127,8 +131,29 @@ if ($action == 'update' && !empty($user->rights->stock->mouvement->creer)) { $qty_stock = $line->qty_stock; $qty_view = $line->qty_view; // The quantity viewed by inventorier, the qty we target + // Load real stock we have now. + $option = ''; + if (isset($cacheOfProducts[$line->fk_product])) { + $product_static = $cacheOfProducts[$line->fk_product]; + } else { + $product_static = new Product($db); + $result = $product_static->fetch($line->fk_product, '', '', '', 1, 1, 1); + + //$option = 'nobatch'; + $option .= ',novirtual'; + $product_static->load_stock($option); // Load stock_reel + stock_warehouse. + + $cacheOfProducts[$product_static->id] = $product_static; + } + + // Get the real quantity in stock now, but before the stock move for inventory. + $realqtynow = $product_static->stock_warehouse[$line->fk_warehouse]->real; + if ($conf->productbatch->enabled && $product_static->hasbatch()) { + $realqtynow = $product_static->stock_warehouse[$line->fk_warehouse]->detail_batch[$line->batch]->qty; + } + if (!is_null($qty_view)) { - $stock_movement_qty = price2num($qty_view - $qty_stock, 'MS'); + $stock_movement_qty = price2num($qty_view - $realqtynow, 'MS'); if ($stock_movement_qty != 0) { if ($stock_movement_qty < 0) { $movement_type = 1; @@ -144,6 +169,19 @@ if ($action == 'update' && !empty($user->rights->stock->mouvement->creer)) { setEventMessages($stockmovment->error, $stockmovment->errors, 'errors'); break; } + + // Update line with id of stock movement (and the start quantity if it has changed this last recording) + if ($qty_stock != $realqtynow) { + $sqlupdate = "UPDATE ".MAIN_DB_PREFIX."inventorydet"; + $sqlupdate .= " SET qty_stock = ".((float) $realqtynow); + $sqlupdate .= " WHERE rowid = ".((int) $line->rowid); + $resqlupdate = $db->query($sqlupdate); + if (! $resqlupdate) { + $error++; + setEventMessages($db->lasterror(), null, 'errors'); + break; + } + } } } $i++; @@ -191,6 +229,7 @@ if ($action =='updateinventorylines' && $permissiontoadd) { setEventMessages($langs->trans("FieldCannotBeNegative", $langs->transnoentitiesnoconv("RealQty")), null, 'errors'); } if ($result > 0) { + $inventoryline->qty_stock = price2num(GETPOST('stock_qty_'.$lineid, 'alpha'), 'MS'); // The new value that was set in as hidden field $inventoryline->qty_view = $qtytoupdate; $resultupdate = $inventoryline->update($user); } @@ -625,13 +664,14 @@ if ($object->id > 0) { $cacheOfWarehouses[$warehouse_static->id] = $warehouse_static; } + $option = ''; if (isset($cacheOfProducts[$obj->fk_product])) { $product_static = $cacheOfProducts[$obj->fk_product]; } else { $product_static = new Product($db); $result = $product_static->fetch($obj->fk_product, '', '', '', 1, 1, 1); - $option = 'nobatch'; + //$option = 'nobatch'; $option .= ',novirtual'; $product_static->load_stock($option); // Load stock_reel + stock_warehouse. This can also call load_virtual_stock() @@ -654,7 +694,17 @@ if ($object->id > 0) { // Expected quantity print ''; - print $obj->qty_stock; + $valuetoshow = $obj->qty_stock; + // For inventory not yet close, we overwrite with the real value in stock now + if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) { + if (!empty($conf->productbatch->enabled) && $product_static->hasbatch()) { + $valuetoshow = $product_static->stock_warehouse[$obj->fk_warehouse]->detail_batch[$obj->batch]->qty; + } else { + $valuetoshow = $product_static->stock_warehouse[$obj->fk_warehouse]->real; + } + } + print price2num($valuetoshow, 'MS'); + print ''; print ''; // Real quantity From be491cc6cf3c226c7528ee589edbc4cc6921c0cb Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 15 Jul 2022 16:22:22 +0200 Subject: [PATCH 2/7] FIX Accountancy - Model account list - Problem of CSRF --- htdocs/accountancy/admin/accountmodel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/admin/accountmodel.php b/htdocs/accountancy/admin/accountmodel.php index 0f4d538cfac..d98e444befe 100644 --- a/htdocs/accountancy/admin/accountmodel.php +++ b/htdocs/accountancy/admin/accountmodel.php @@ -679,7 +679,7 @@ if ($id) { // Can an entry be erased or disabled ? $iserasable = 1; $canbedisabled = 1; $canbemodified = 1; // true by default - $url = $_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(!empty($obj->rowid) ? $obj->rowid : (!empty($obj->code) ? $obj->code : '')).'&code='.(!empty($obj->code) ?urlencode($obj->code) : ''); + $url = $_SERVER["PHP_SELF"].'?token='.newToken().($page ? '&page='.$page : '').'&sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(!empty($obj->rowid) ? $obj->rowid : (!empty($obj->code) ? $obj->code : '')).'&code='.(!empty($obj->code) ?urlencode($obj->code) : ''); if ($param) { $url .= '&'.$param; } From 71af854bf4f402e5c23cc2eac2b3e6a74f05e5d2 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 15 Jul 2022 17:31:30 +0200 Subject: [PATCH 3/7] FIX Bank transfer - Link on supplier invoice was bad --- htdocs/compta/prelevement/list.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/prelevement/list.php b/htdocs/compta/prelevement/list.php index 095d07460b9..1bc250993b8 100644 --- a/htdocs/compta/prelevement/list.php +++ b/htdocs/compta/prelevement/list.php @@ -256,9 +256,17 @@ if ($result) { print ''; print ''; - print ''; - print img_object($langs->trans("ShowBill"), "bill"); - print ' '.$obj->invoiceref."\n"; + $link_to_bill = '/compta/facture/card.php?facid='; + $link_title = 'Invoice'; + $link_picto = 'bill'; + if ($type == 'bank-transfer') { + $link_to_bill = '/fourn/facture/card.php?facid='; + $link_title = 'SupplierInvoice'; + $link_picto = 'supplier_invoice'; + } + print ''; + print img_object($langs->trans($link_title), $link_picto); + print ' '.$obj->invoiceref."\n"; print ''; print ''; @@ -266,7 +274,7 @@ if ($result) { print $company->getNomUrl(1); print "\n"; - print ''.$obj->code_client."\n"; + print ''.$obj->code_client."\n"; print ''.dol_print_date($db->jdate($obj->datec), 'day')."\n"; From 149b86e459b3a51604105cafba1c7e05cb804d3d Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 16 Jul 2022 06:34:52 +0200 Subject: [PATCH 4/7] FIX Bank transfer - Link on code supplier invoice was bad --- htdocs/compta/prelevement/list.php | 31 +++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/htdocs/compta/prelevement/list.php b/htdocs/compta/prelevement/list.php index 1bc250993b8..787b9d05aaa 100644 --- a/htdocs/compta/prelevement/list.php +++ b/htdocs/compta/prelevement/list.php @@ -1,8 +1,9 @@ - * Copyright (C) 2005-2016 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2010-2018 Juanjo Menent +/* Copyright (C) 2005 Rodolphe Quiedeville + * Copyright (C) 2005-2016 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2010-2018 Juanjo Menent + * Copyright (C) 2022 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -108,7 +109,7 @@ llxHeader('', $langs->trans("WithdrawalsLines")); $sql = "SELECT p.rowid, p.ref, p.statut as status, p.datec"; $sql .= " , f.rowid as facid, f.ref as invoiceref, f.total_ttc"; -$sql .= " , s.rowid as socid, s.nom as name, s.code_client, s.email"; +$sql .= " , s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.email"; $sql .= " , pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl"; @@ -139,7 +140,7 @@ if ($search_bon) { } if ($type == 'bank-transfer') { if ($search_code) { - $sql .= natural_search("s.code_fourn", $search_code); + $sql .= natural_search("s.code_fournisseur", $search_code); } } else { if ($search_code) { @@ -204,7 +205,7 @@ if ($result) { print ''; print ' '; print ''; - print ''; + print ''; print ' '; print ' '; print ''; @@ -214,8 +215,12 @@ if ($result) { print ''; $columntitle = "WithdrawalsReceipts"; + $columntitlethirdparty = "CustomerCode"; + $columncodethirdparty = "s.code_client"; if ($type == 'bank-transfer') { $columntitle = "BankTransferReceipts"; + $columntitlethirdparty = "SupplierCode"; + $columncodethirdparty = "s.code_fournisseur"; } print ''; @@ -223,7 +228,7 @@ if ($result) { print_liste_field_titre("Line", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder); print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "f.ref", '', $param, '', $sortfield, $sortorder); print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder); - print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", '', $param, '', $sortfield, $sortorder, 'center '); + print_liste_field_titre($columntitlethirdparty, $_SERVER["PHP_SELF"], $columncodethirdparty, '', $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $param, '', $sortfield, $sortorder, 'right '); print_liste_field_titre(''); @@ -274,7 +279,15 @@ if ($result) { print $company->getNomUrl(1); print "\n"; - print ''.$obj->code_client."\n"; + + print ''; + $link_to_tab = '/comm/card.php?socid='; + $link_code = $obj->code_client; + if ($type == 'bank-transfer') { + $link_to_tab = 'fourn/card.php?socid='; + $link_code = $obj->code_fournisseur; + } + print ''.$link_code."\n"; print ''.dol_print_date($db->jdate($obj->datec), 'day')."\n"; From ce15b8c44ec86773664764f801f5ed6f09a2ae5d Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Mon, 18 Jul 2022 07:23:25 +0200 Subject: [PATCH 5/7] FIX #21472 On the bank transfer lists, a change of page switches to the lists of the direct debit module --- htdocs/compta/prelevement/list.php | 5 ++++- htdocs/compta/prelevement/orders_list.php | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/prelevement/list.php b/htdocs/compta/prelevement/list.php index 787b9d05aaa..a7bab4281c2 100644 --- a/htdocs/compta/prelevement/list.php +++ b/htdocs/compta/prelevement/list.php @@ -173,6 +173,9 @@ if ($result) { $param = "&statut=".urlencode($statut); $param .= "&search_bon=".urlencode($search_bon); + if ($type == 'bank-transfer') { + $param .= '&type=bank-transfer'; + } if ($limit > 0 && $limit != $conf->liste_limit) { $param .= '&limit='.urlencode($limit); } @@ -284,7 +287,7 @@ if ($result) { $link_to_tab = '/comm/card.php?socid='; $link_code = $obj->code_client; if ($type == 'bank-transfer') { - $link_to_tab = 'fourn/card.php?socid='; + $link_to_tab = '/fourn/card.php?socid='; $link_code = $obj->code_fournisseur; } print ''.$link_code."\n"; diff --git a/htdocs/compta/prelevement/orders_list.php b/htdocs/compta/prelevement/orders_list.php index 2733223b5b5..6737ea258ea 100644 --- a/htdocs/compta/prelevement/orders_list.php +++ b/htdocs/compta/prelevement/orders_list.php @@ -132,6 +132,9 @@ if ($result) { if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { $param .= '&contextpage='.urlencode($contextpage); } + if ($type == 'bank-transfer') { + $param .= '&type=bank-transfer'; + } if ($limit > 0 && $limit != $conf->liste_limit) { $param .= '&limit='.urlencode($limit); } From 276168ef6faea6cc6288d9d5cb578b3ce4895963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Courtier?= Date: Tue, 19 Jul 2022 17:14:57 +0200 Subject: [PATCH 6/7] Fix: tabhelp must be present in every module --- htdocs/core/modules/modIncoterm.class.php | 3 ++- .../template/core/modules/modMyModule.class.php | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/modIncoterm.class.php b/htdocs/core/modules/modIncoterm.class.php index 70e6c738801..c13555ef7cf 100644 --- a/htdocs/core/modules/modIncoterm.class.php +++ b/htdocs/core/modules/modIncoterm.class.php @@ -94,7 +94,8 @@ class modIncoterm extends DolibarrModules 'tabfieldvalue'=>array("code,libelle"), // List of fields (list of fields to edit a record) 'tabfieldinsert'=>array("code,libelle"), // List of fields (list of fields for insert) 'tabrowid'=>array("rowid"), // Name of columns with primary key (try to always name it 'rowid') - 'tabcond'=>array($conf->incoterm->enabled) + 'tabcond'=>array($conf->incoterm->enabled), + 'tabhelp' => array(array()) ); $this->boxes = array(); // List of boxes diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 0959a650d6e..3fca508f961 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -221,7 +221,10 @@ class modMyModule extends DolibarrModules // Name of columns with primary key (try to always name it 'rowid') 'tabrowid'=>array("rowid", "rowid", "rowid"), // Condition to show each dictionary - 'tabcond'=>array($conf->mymodule->enabled, $conf->mymodule->enabled, $conf->mymodule->enabled) + 'tabcond'=>array($conf->mymodule->enabled, $conf->mymodule->enabled, $conf->mymodule->enabled), + // Tooltip for every fields of dictionaries: DO NOT PUT AN EMPTY ARRAY + 'tabhelp'=>array(array('field1' => 'field1tooltip', 'field2' => 'field2tooltip'), array('field1' => 'field1tooltip', 'field2' => 'field2tooltip'), ...), + ); */ From 2aae7525daee3c79bf40c99d8c1d99fd951b42ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Courtier?= Date: Tue, 19 Jul 2022 17:27:15 +0200 Subject: [PATCH 7/7] Fix: tabhelp must be present in every module --- htdocs/core/modules/modPartnership.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/modules/modPartnership.class.php b/htdocs/core/modules/modPartnership.class.php index d7041eca754..36cad1a5b06 100644 --- a/htdocs/core/modules/modPartnership.class.php +++ b/htdocs/core/modules/modPartnership.class.php @@ -231,7 +231,8 @@ class modPartnership extends DolibarrModules // Name of columns with primary key (try to always name it 'rowid') 'tabrowid'=>array("rowid"), // Condition to show each dictionary - 'tabcond'=>array($conf->partnership->enabled) + 'tabcond'=>array($conf->partnership->enabled), + 'tabhelp' => array(array()) ); // Boxes/Widgets