From 71c9b94b223a5ee8b3418313d90b78cd6829fe71 Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Fri, 21 Feb 2020 11:08:34 +0100 Subject: [PATCH 01/12] NEW add const CASHDESK_FORCE_DECREASE_STOCK to force batch decrementation --- htdocs/compta/facture/class/facture.class.php | 105 +++++++++++++++++- htdocs/langs/en_US/admin.lang | 2 + htdocs/langs/en_US/errors.lang | 2 + htdocs/langs/fr_FR/admin.lang | 2 + htdocs/langs/fr_FR/errors.lang | 2 + htdocs/product/class/productbatch.class.php | 66 +++++++++++ htdocs/takepos/admin/terminal.php | 9 +- htdocs/takepos/invoice.php | 7 +- 8 files changed, 187 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index cb2bf087652..800dbc66b63 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2410,12 +2410,23 @@ class Facture extends CommonInvoice * @param string $force_number Reference to force on invoice * @param int $idwarehouse Id of warehouse to use for stock decrease if option to decreasenon stock is on (0=no decrease) * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @param int $batch_rule [=0] 0 not decrement batch, else batch rule to use + * 1=take in batches ordered by sellby and eatby dates * @return int <0 if KO, 0=Nothing done because invoice is not a draft, >0 if OK */ - public function validate($user, $force_number = '', $idwarehouse = 0, $notrigger = 0) + public function validate($user, $force_number = '', $idwarehouse = 0, $notrigger = 0, $batch_rule = 0) { global $conf, $langs; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $productStatic = null; + $warehouseStatic = null; + if ($batch_rule > 0) { + require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; + require_once DOL_DOCUMENT_ROOT . '/product/class/productbatch.class.php'; + require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php'; + $productStatic = new Product($this->db); + $warehouseStatic = new Entrepot($this->db); + } $now = dol_now(); @@ -2557,11 +2568,93 @@ class Facture extends CommonInvoice $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; // We decrease stock for product - if ($this->type == self::TYPE_CREDIT_NOTE) $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceValidatedInDolibarr", $num)); - else $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr", $num)); - if ($result < 0) { - $error++; - $this->error = $mouvP->error; + if ($this->type == self::TYPE_CREDIT_NOTE) { + $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceValidatedInDolibarr", $num)); + if ($result < 0) { + $error++; + $this->error = $mouvP->error; + } + } else { + $is_batch_line = false; + if ($batch_rule > 0) { + $productStatic->fetch($this->lines[$i]->fk_product); + if ($productStatic->hasbatch()) { + $is_batch_line = true; + $product_qty_remain = $this->lines[$i]->qty; + + $sortfield = null; + $sortorder = null; + // find all batch order by sellby (DLC) and eatby dates (DLUO) first + if ($batch_rule == Productbatch::BATCH_RULE_SELLBY_EATBY_DATES_FIRST) { + $sortfield = 'pl.sellby,pl.eatby,pb.qty,pl.rowid'; + $sortorder = 'ASC,ASC,ASC,ASC'; + } + + $resBatchList = Productbatch::findAllForProduct($this->db, $productStatic->id, $idwarehouse, (!empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER) ? null : 0), $sortfield, $sortorder); + if (!is_array($resBatchList)) { + $error++; + $this->error = $this->db->lasterror(); + } else { + $batchList = $resBatchList; + if (empty($batchList)) { + $error++; + $langs->load('errors'); + $warehouseStatic->fetch($idwarehouse); + $this->error = $langs->trans('ErrorBatchNoFoundForProductInWarehouse', $productStatic->label, $warehouseStatic->ref); + dol_syslog(__METHOD__ . ' Error: ' . $langs->transnoentitiesnoconv('ErrorBatchNoFoundForProductInWarehouse', $productStatic->label, $warehouseStatic->ref), LOG_ERR); + } else { + foreach ($batchList as $batch) { + if ($batch->qty <= 0) continue; // try to decrement only batches have positive quantity first + + // enough quantity in this batch + if ($batch->qty >= $product_qty_remain) { + $product_batch_qty = $product_qty_remain; + } + // not enough (take all in batch) + else { + $product_batch_qty = $batch->qty; + } + $result = $mouvP->livraison($user, $productStatic->id, $idwarehouse, $product_batch_qty, $this->lines[$i]->subprice, $langs->trans('InvoiceValidatedInDolibarr', $num), '', '', '', $batch->batch); + if ($result < 0) { + $error++; + $this->error = $mouvP->error; + break; + } + + $product_qty_remain -= $product_batch_qty; + // all product quantity was decremented + if ($product_qty_remain <= 0) break; + } + + if (!$error && $product_qty_remain>0) { + if ($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER) { + // take in the first batch + $batch = $batchList[0]; + $result = $mouvP->livraison($user, $productStatic->id, $idwarehouse, $product_qty_remain, $this->lines[$i]->subprice, $langs->trans('InvoiceValidatedInDolibarr', $num), '', '', '', $batch->batch); + if ($result < 0) { + $error++; + $this->error = $mouvP->error; + } + } else { + $error++; + $langs->load('errors'); + $warehouseStatic->fetch($idwarehouse); + $this->error = $langs->trans('ErrorBatchNoFoundEnoughQuantityForProductInWarehouse', $productStatic->label, $warehouseStatic->ref); + dol_syslog(__METHOD__ . ' Error: ' . $langs->transnoentitiesnoconv('ErrorBatchNoFoundEnoughQuantityForProductInWarehouse', $productStatic->label, $warehouseStatic->ref), LOG_ERR); + } + } + } + } + } + } + + if (!$is_batch_line) { + $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr", $num)); + if ($result < 0) { + $error++; + $this->error = $mouvP->error; + } + } } } } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index ee025ede17f..0f10ac291ff 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1686,6 +1686,8 @@ CashDeskIdWareHouse=Force and restrict warehouse to use for stock decrease StockDecreaseForPointOfSaleDisabled=Stock decrease from Point of Sale disabled StockDecreaseForPointOfSaleDisabledbyBatch=Stock decrease in POS is not compatible with module Serial/Lot management (currently active) so stock decrease is disabled. CashDeskYouDidNotDisableStockDecease=You did not disable stock decrease when making a sale from Point of Sale. Hence a warehouse is required. +CashDeskForceDecreaseStockLabel=Stock decrease for batch products was forced. +CashDeskForceDecreaseStockDesc=Decrease first by the oldest eatby and sellby dates. ##### Bookmark ##### BookmarkSetup=Bookmark module setup BookmarkDesc=This module allows you to manage bookmarks. You can also add shortcuts to any Dolibarr pages or external web sites on your left menu. diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 525131b2a61..2de7b74e82a 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -228,6 +228,8 @@ ErrorFieldRequiredForProduct=Field '%s' is required for product %s ProblemIsInSetupOfTerminal=Problem is in setup of terminal %s. ErrorAddAtLeastOneLineFirst=Add at least one line first ErrorRecordAlreadyInAccountingDeletionNotPossible=Error, record is already transferred in accounting, deletion is not possible. +ErrorBatchNoFoundForProductInWarehouse=No batch found for prorduct "%s" in warehouse "%s". +ErrorBatchNoFoundEnoughQuantityForProductInWarehouse=No enough quantity in batches for product "%s" in warehouse "%s". # Warnings WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup. WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user. diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 052f77a365e..221d5032bfb 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -1683,6 +1683,8 @@ CashDeskIdWareHouse=Forcer et restreindre l'emplacement/entrepôt à utiliser po StockDecreaseForPointOfSaleDisabled=Réduction de stock lors de l'utilisation du Point de Vente désactivée StockDecreaseForPointOfSaleDisabledbyBatch=La décrémentation de stock depuis ce module Point de Vente n'est pas encore compatible avec la gestion des numéros de lots/série. CashDeskYouDidNotDisableStockDecease=Vous n'avez pas désactivé la réduction de stock lors d'une vente depuis le Point de vente. Par conséquent, un entrepôt est nécessaire. +CashDeskForceDecreaseStockLabel=Décrémentation des stocks pour les lots a été forcé. +CashDeskForceDecreaseStockDesc=Décrémentation des lots par DLC et DLUO les plus anciennes. ##### Bookmark ##### BookmarkSetup=Configuration du module Marque-pages BookmarkDesc=Ce module vous permet de gérer des liens et raccourcis. Il permet aussi d'ajouter n'importe quelle page de Dolibarr ou lien web dans le menu d'accès rapide sur la gauche. diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index 1142524115c..f7ffea8ed10 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -227,6 +227,8 @@ ErrorNoFieldWithAttributeShowoncombobox=Aucun champ n'a la propriété 'showonco ErrorFieldRequiredForProduct=Le champ '%s' est obligatoire pour le produit %s ProblemIsInSetupOfTerminal=Le problème est dans la configuration du terminal %s. ErrorAddAtLeastOneLineFirst=Ajouter d'abord au moins une ligne +ErrorBatchNoFoundForProductInWarehouse=Aucun lot trouvé pour le produit "%s" dans l'entrepôt "%s". +ErrorBatchNoFoundEnoughQuantityForProductInWarehouse=Quantité insuffisante dans les lots pour le produit "%s" dans l'entepôt "%s". # Warnings WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Votre paramètre PHP upload_max_filesize (%s) est supérieur au paramètre PHP post_max_size (%s). Ceci n'est pas une configuration cohérente. WarningPasswordSetWithNoAccount=Un mot de passe a été fixé pour cet adhérent. Cependant, aucun compte d'utilisateur n'a été créé. Donc, ce mot de passe est stocké, mais ne peut être utilisé pour accéder à Dolibarr. Il peut être utilisé par un module/interface externe, mais si vous n'avez pas besoin de définir ni login ni mot de passe pour un adhérent, vous pouvez désactiver l'option «Gérer un login pour chaque adhérent" depuis la configuration du module Adhérents. Si vous avez besoin de gérer un login, mais pas de mot de passe, vous pouvez laisser ce champ vide pour éviter cet avertissement. Remarque: L'email peut également être utilisé comme login si l'adhérent est lié à un utilisateur. diff --git a/htdocs/product/class/productbatch.class.php b/htdocs/product/class/productbatch.class.php index a0a85bbec94..843bf2aa139 100644 --- a/htdocs/product/class/productbatch.class.php +++ b/htdocs/product/class/productbatch.class.php @@ -30,6 +30,11 @@ require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php"; */ class Productbatch extends CommonObject { + /** + * Batches rules + */ + const BATCH_RULE_SELLBY_EATBY_DATES_FIRST = 1; + /** * @var string ID to identify managed object */ @@ -540,4 +545,65 @@ class Productbatch extends CommonObject return -1; } } + + /** + * Return all batch for a product and a warehouse + * + * @param DoliDB $db Database object + * @param int $fk_product Id of product + * @param int $fk_warehouse Id of warehouse + * @param int $qty_min [=NULL] Minimum quantity + * @param string $sortfield [=NULL] List of sort fields, separated by comma. Example: 't1.fielda,t2.fieldb' + * @param string $sortorder [=NULL] Sort order, separated by comma. Example: 'ASC,DESC'; + * @return int|array <0 if KO, array of batch + * + * @throws Exception + */ + public static function findAllForProduct($db, $fk_product, $fk_warehouse = 0, $qty_min = null, $sortfield = null, $sortorder = null) + { + $productBatchList = array(); + + dol_syslog(__METHOD__ . ' fk_product=' . $fk_product . ', fk_warehouse=' . $fk_warehouse . ', qty_min=' . $qty_min . ', sortfield=' . $sortfield . ', sortorder=' . $sortorder, LOG_DEBUG); + + $sql = "SELECT"; + $sql .= " pl.rowid"; + $sql .= ", pl.fk_product"; + $sql .= ", pl.batch"; + $sql .= ", pl.sellby"; + $sql .= ", pl.eatby"; + $sql .= ", pb.qty"; + $sql .= " FROM " . MAIN_DB_PREFIX . "product_lot as pl"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = pl.fk_product"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_batch AS pb ON pl.batch = pb.batch"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock AS ps ON ps.rowid = pb.fk_product_stock"; + $sql .= " WHERE p.entity IN (" . getEntity('product') . ")"; + $sql .= " AND pl.fk_product = " . $fk_product; + if ($fk_warehouse > 0) { + $sql .= " AND ps.fk_entrepot = " . $fk_warehouse; + } + if ($qty_min !== null) { + $sql .= " AND pb.qty > " . $qty_min; + } + $sql .= $db->order($sortfield, $sortorder); + + $resql = $db->query($sql); + if ($resql) { + while ($obj = $db->fetch_object($resql)) { + $productBatch = new self($db); + $productBatch->id = $obj->rowid; + $productBatch->fk_product = $obj->fk_product; + $productBatch->batch = $obj->batch; + $productBatch->eatby = $db->jdate($obj->eatby); + $productBatch->sellby = $db->jdate($obj->sellby); + $productBatch->qty = $obj->qty; + $productBatchList[] = $productBatch; + } + $db->free($resql); + + return $productBatchList; + } else { + dol_syslog(__METHOD__ . ' Error: ' . $db->lasterror(), LOG_ERR); + return -1; + } + } } diff --git a/htdocs/takepos/admin/terminal.php b/htdocs/takepos/admin/terminal.php index b30cb4e7032..9ffc691ac46 100644 --- a/htdocs/takepos/admin/terminal.php +++ b/htdocs/takepos/admin/terminal.php @@ -179,7 +179,7 @@ if (!empty($conf->stock->enabled)) { print ''.$langs->trans("CashDeskDoNotDecreaseStock").''; // Force warehouse (this is not a default value) print ''; - if (empty($conf->productbatch->enabled)) { + if (empty($conf->productbatch->enabled) || !empty($conf->global->CASHDESK_FORCE_DECREASE_STOCK)) { print $form->selectyesno('CASHDESK_NO_DECREASE_STOCK'.$terminal, $conf->global->{'CASHDESK_NO_DECREASE_STOCK'.$terminal}, 1); } else @@ -207,6 +207,13 @@ if (!empty($conf->stock->enabled)) print ''.$langs->trans("StockDecreaseForPointOfSaleDisabled").''; } print ''; + + if (!empty($conf->productbatch->enabled) && !empty($conf->global->CASHDESK_FORCE_DECREASE_STOCK) && !$conf->global->{'CASHDESK_NO_DECREASE_STOCK'.$terminal}) { + print '' . $langs->trans('CashDeskForceDecreaseStockLabel') . ''; + print ''; + print '' . $langs->trans('CashDeskForceDecreaseStockDesc') . ''; + print ''; + } } if ($conf->receiptprinter->enabled) { diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 77c59b090ca..c9739b2c414 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -190,7 +190,12 @@ if ($action == 'valid' && $user->rights->facture->creer) $constantforkey = 'CASHDESK_ID_WAREHOUSE'.$_SESSION["takeposterminal"]; dol_syslog("Validate invoice with stock change into warehouse defined into constant ".$constantforkey." = ".$conf->global->$constantforkey); - $res = $invoice->validate($user, '', $conf->global->$constantforkey); + $batch_rule = 0; + if (!empty($conf->productbatch->enabled) && !empty($conf->global->CASHDESK_FORCE_DECREASE_STOCK)) { + require_once DOL_DOCUMENT_ROOT . '/product/class/productbatch.class.php'; + $batch_rule = Productbatch::BATCH_RULE_SELLBY_EATBY_DATES_FIRST; + } + $res = $invoice->validate($user, '', $conf->global->$constantforkey, 0, $batch_rule); $conf->global->STOCK_CALCULATE_ON_BILL = $savconst; } From ec19b2feefbf405a634af735178f2cd743c6612f Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Fri, 21 Feb 2020 12:00:16 +0100 Subject: [PATCH 02/12] FIX phpcs nestling too high level --- htdocs/compta/facture/class/facture.class.php | 73 ++++++++++--------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 800dbc66b63..e6fa9b68350 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2594,7 +2594,9 @@ class Facture extends CommonInvoice if (!is_array($resBatchList)) { $error++; $this->error = $this->db->lasterror(); - } else { + } + + if (!$error) { $batchList = $resBatchList; if (empty($batchList)) { $error++; @@ -2602,46 +2604,45 @@ class Facture extends CommonInvoice $warehouseStatic->fetch($idwarehouse); $this->error = $langs->trans('ErrorBatchNoFoundForProductInWarehouse', $productStatic->label, $warehouseStatic->ref); dol_syslog(__METHOD__ . ' Error: ' . $langs->transnoentitiesnoconv('ErrorBatchNoFoundForProductInWarehouse', $productStatic->label, $warehouseStatic->ref), LOG_ERR); - } else { - foreach ($batchList as $batch) { - if ($batch->qty <= 0) continue; // try to decrement only batches have positive quantity first + } - // enough quantity in this batch - if ($batch->qty >= $product_qty_remain) { - $product_batch_qty = $product_qty_remain; - } - // not enough (take all in batch) - else { - $product_batch_qty = $batch->qty; - } - $result = $mouvP->livraison($user, $productStatic->id, $idwarehouse, $product_batch_qty, $this->lines[$i]->subprice, $langs->trans('InvoiceValidatedInDolibarr', $num), '', '', '', $batch->batch); + foreach ($batchList as $batch) { + if ($batch->qty <= 0) continue; // try to decrement only batches have positive quantity first + + // enough quantity in this batch + if ($batch->qty >= $product_qty_remain) { + $product_batch_qty = $product_qty_remain; + } // not enough (take all in batch) + else { + $product_batch_qty = $batch->qty; + } + $result = $mouvP->livraison($user, $productStatic->id, $idwarehouse, $product_batch_qty, $this->lines[$i]->subprice, $langs->trans('InvoiceValidatedInDolibarr', $num), '', '', '', $batch->batch); + if ($result < 0) { + $error++; + $this->error = $mouvP->error; + break; + } + + $product_qty_remain -= $product_batch_qty; + // all product quantity was decremented + if ($product_qty_remain <= 0) break; + } + + if (!$error && $product_qty_remain > 0) { + if ($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER) { + // take in the first batch + $batch = $batchList[0]; + $result = $mouvP->livraison($user, $productStatic->id, $idwarehouse, $product_qty_remain, $this->lines[$i]->subprice, $langs->trans('InvoiceValidatedInDolibarr', $num), '', '', '', $batch->batch); if ($result < 0) { $error++; $this->error = $mouvP->error; - break; - } - - $product_qty_remain -= $product_batch_qty; - // all product quantity was decremented - if ($product_qty_remain <= 0) break; - } - - if (!$error && $product_qty_remain>0) { - if ($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER) { - // take in the first batch - $batch = $batchList[0]; - $result = $mouvP->livraison($user, $productStatic->id, $idwarehouse, $product_qty_remain, $this->lines[$i]->subprice, $langs->trans('InvoiceValidatedInDolibarr', $num), '', '', '', $batch->batch); - if ($result < 0) { - $error++; - $this->error = $mouvP->error; - } - } else { - $error++; - $langs->load('errors'); - $warehouseStatic->fetch($idwarehouse); - $this->error = $langs->trans('ErrorBatchNoFoundEnoughQuantityForProductInWarehouse', $productStatic->label, $warehouseStatic->ref); - dol_syslog(__METHOD__ . ' Error: ' . $langs->transnoentitiesnoconv('ErrorBatchNoFoundEnoughQuantityForProductInWarehouse', $productStatic->label, $warehouseStatic->ref), LOG_ERR); } + } else { + $error++; + $langs->load('errors'); + $warehouseStatic->fetch($idwarehouse); + $this->error = $langs->trans('ErrorBatchNoFoundEnoughQuantityForProductInWarehouse', $productStatic->label, $warehouseStatic->ref); + dol_syslog(__METHOD__ . ' Error: ' . $langs->transnoentitiesnoconv('ErrorBatchNoFoundEnoughQuantityForProductInWarehouse', $productStatic->label, $warehouseStatic->ref), LOG_ERR); } } } From 6264f78e398cb97fb856090988c33bd4a3e0399e Mon Sep 17 00:00:00 2001 From: gmilad <61253440+gmilad@users.noreply.github.com> Date: Fri, 21 Feb 2020 23:01:16 +0100 Subject: [PATCH 03/12] Update note.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bonsoir, Correction pour l'issue #13168 Cordialement, Gaëtan. --- htdocs/adherents/note.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/adherents/note.php b/htdocs/adherents/note.php index e232539491b..7e8175793fd 100644 --- a/htdocs/adherents/note.php +++ b/htdocs/adherents/note.php @@ -75,7 +75,7 @@ if ($id) $linkback = ''.$langs->trans("BackToList").''; - dol_banner_tab($object, 'rowid', $linkback); + dol_banner_tab($object, 'id', $linkback); print '
'; From 16b4e680f7a1decf24100258f1c5f1d6d1f1a7a3 Mon Sep 17 00:00:00 2001 From: futurehousestore Date: Sat, 22 Feb 2020 02:45:58 +0000 Subject: [PATCH 04/12] Add Products/Services by popularity in Orders --- htdocs/langs/en_US/other.lang | 6 +- htdocs/product/popucom.php | 217 ++++++++++++++++++++++++++++++++++ htdocs/product/popuprop.php | 9 +- htdocs/product/stats/card.php | 7 +- 4 files changed, 235 insertions(+), 4 deletions(-) create mode 100644 htdocs/product/popucom.php diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 59950289236..b32dd7ed07e 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -31,7 +31,7 @@ NextYearOfInvoice=Following year of invoice date DateNextInvoiceBeforeGen=Date of next invoice (before generation) DateNextInvoiceAfterGen=Date of next invoice (after generation) GraphInBarsAreLimitedTo3Measures=Grapics are limited to 3 measures in 'Bars' mode. The mode 'Lines' was automatically selected instead. -OnlyOneFieldForXAxisIsPossible=Only 1 field is currently possible as X-Axis. Only the first selected field has been selected. +OnlyOneFieldForXAxisIsPossible=Only 1 field is currently possible as X-Axis. Only the first selected field has been selected. AtLeastOneMeasureIsRequired=At least 1 field for measure is required AtLeastOneXAxisIsRequired=At least 1 field for X-Axis is required @@ -278,3 +278,7 @@ LinesToImport=Lines to import MemoryUsage=Memory usage RequestDuration=Duration of request +PopuProp=Products/Services by popularity in Proposals +PopuCom=Products/Services by popularity in Orders +ProductStatistics=Products/Services Statistics +NbOfQtyInOrders=Qty in orders diff --git a/htdocs/product/popucom.php b/htdocs/product/popucom.php new file mode 100644 index 00000000000..41f14e25176 --- /dev/null +++ b/htdocs/product/popucom.php @@ -0,0 +1,217 @@ + + * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2014 Marcos García + * Copyright (C) 2015 Jean-François Ferry + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/product/popucom.php + * \ingroup commande, produit + * \brief Liste des produits/services par popularite + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + +// Load translation files required by the page +//Required to translate NbOfCommande +$langs->load('commande'); + +$type=GETPOST("type", "int"); + +// Security check +if (! empty($user->socid)) $socid=$user->socid; +$result=restrictedArea($user, 'produit|service'); + +$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOST("page", 'int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (! $sortfield) $sortfield="c"; +if (! $sortorder) $sortorder="DESC"; +$offset = $limit * $page ; +$pageprev = $page - 1; +$pagenext = $page + 1; + + +$staticproduct=new Product($db); + + +/* + * View + */ + +$helpurl=''; +if ($type == '0') +{ + $helpurl='EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; +} +elseif ($type == '1') +{ + $helpurl='EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; +} +else +{ + $helpurl='EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; +} +$title=$langs->trans("Statistics"); + + +llxHeader('', $title, $helpurl); + +print load_fiche_titre($title, $mesg, 'products'); + + +$param = ''; +$title = $langs->trans("ListProductServiceByPopularity"); +if ((string) $type == '1') { + $title = $langs->trans("ListServiceByPopularity"); +} +if ((string) $type == '0') { + $title = $langs->trans("ListProductByPopularity"); +} + +if ($type != '') $param .= '&type='.$type; + + +$h=0; +$head = array(); + +$head[$h][0] = DOL_URL_ROOT.'/product/stats/card.php?id=all'; +$head[$h][1] = $langs->trans("Chart"); +$head[$h][2] = 'chart'; +$h++; + +$head[$h][0] = DOL_URL_ROOT.'/product/popuprop.php'; +$head[$h][1] = $langs->trans("PopuProp"); +$head[$h][2] = 'popularityprop'; +$h++; + +$head[$h][0] = DOL_URL_ROOT.'/product/popucom.php'; +$head[$h][1] = $langs->trans("PopuCom"); +$head[$h][2] = 'popularitycommande'; +$h++; + +dol_fiche_head($head, 'popularitycommande', $langs->trans("Statistics"), -1); + + +// Array of liens to show +$infoprod=array(); + + +// Add lines for commande +$sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type as type, SUM(pd.qty) as c"; +$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as pd"; +$sql.= ", ".MAIN_DB_PREFIX."product as p"; +$sql.= ' WHERE p.entity IN ('.getEntity('product').')'; +$sql.= " AND p.rowid = pd.fk_product"; +if ($type !== '') { + $sql.= " AND fk_product_type = ".$type; +} +$sql.= " GROUP BY p.rowid, p.label, p.ref, p.fk_product_type"; + +$result=$db->query($sql); +if ($result) +{ + $totalnboflines = $db->num_rows($result); +} + +$sql.= $db->order($sortfield, $sortorder); +$sql.= $db->plimit($limit+1, $offset); + +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + $i = 0; + + while ($i < $num) + { + $objp = $db->fetch_object($resql); + + $infoprod[$objp->rowid]=array('type'=>$objp->type, 'ref'=>$objp->ref, 'label'=>$objp->label); + $infoprod[$objp->rowid]['nblinecommande']=$objp->c; + + $i++; + } + $db->free($resql); +} +else +{ + dol_print_error($db); +} +//var_dump($infoprod); + + +print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $totalnboflines, ''); + +print ''; + +print ""; +print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder); +print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'p.fk_product_type', '', $param, '', $sortfield, $sortorder); +print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder); +print_liste_field_titre('NbOfQtyInOrders', $_SERVER["PHP_SELF"], 'c', '', $param, '', $sortfield, $sortorder, 'right '); +print "\n"; + +foreach($infoprod as $prodid => $vals) +{ + // Multilangs + if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active + { + $sql = "SELECT label"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql.= " WHERE fk_product=".$prodid; + $sql.= " AND lang='". $langs->getDefaultLang() ."'"; + $sql.= " LIMIT 1"; + + $resultp = $db->query($sql); + if ($resultp) + { + $objtp = $db->fetch_object($resultp); + if (! empty($objtp->label)) $vals['label'] = $objtp->label; + } + } + + print ""; + print ''; + print ''; + print ''; + print ''; + print "\n"; + $i++; +} + +print "
'; + if ($vals['type'] == 1) print img_object($langs->trans("ShowService"), "service"); + else print img_object($langs->trans("ShowProduct"), "product"); + print " "; + print $vals['ref'].''; + if ($vals['type'] == 1) print $langs->trans("Service"); + else print $langs->trans("Product"); + print ''.$vals['label'].''.$vals['nblinecommande'].'
"; + + + +dol_fiche_end(); + +// End of page +llxFooter(); +$db->close(); diff --git a/htdocs/product/popuprop.php b/htdocs/product/popuprop.php index 95bf2b965a2..4df11c7d755 100644 --- a/htdocs/product/popuprop.php +++ b/htdocs/product/popuprop.php @@ -99,11 +99,16 @@ $head[$h][1] = $langs->trans("Chart"); $head[$h][2] = 'chart'; $h++; -$head[$h][0] = $_SERVER['PHP_SELF']; -$head[$h][1] = $title; +$head[$h][0] = DOL_URL_ROOT.'/product/popuprop.php'; +$head[$h][1] = $langs->trans("PopuProp"); $head[$h][2] = 'popularityprop'; $h++; +$head[$h][0] = DOL_URL_ROOT.'/product/popucom.php'; +$head[$h][1] = $langs->trans("PopuCom"); +$head[$h][2] = 'popularitycommande'; +$h++; + dol_fiche_head($head, 'popularityprop', $langs->trans("Statistics"), -1); diff --git a/htdocs/product/stats/card.php b/htdocs/product/stats/card.php index 24387ef8b73..c35d8401a8a 100644 --- a/htdocs/product/stats/card.php +++ b/htdocs/product/stats/card.php @@ -161,10 +161,15 @@ if (empty($id) & empty($ref)) } $head[$h][0] = DOL_URL_ROOT.'/product/popuprop.php'.($type != '' ? '?type='.$type : ''); - $head[$h][1] = $title; + $head[$h][1] = $langs->trans("PopuProp"); $head[$h][2] = 'popularityprop'; $h++; + $head[$h][0] = DOL_URL_ROOT.'/product/popucom.php'.($type != '' ? '?type='.$type : ''); + $head[$h][1] = $langs->trans("PopuCom"); + $head[$h][2] = 'popularitycommande'; + $h++; + dol_fiche_head($head, 'chart', $langs->trans("Statistics"), -1); } From fddcc844fff7024936b3738cca8c025f6c682454 Mon Sep 17 00:00:00 2001 From: javierybar Date: Sat, 22 Feb 2020 11:30:48 +0100 Subject: [PATCH 05/12] Add orders to Receipt Printers module --- htdocs/core/class/dolreceiptprinter.class.php | 26 +++++++++++++++++++ htdocs/takepos/invoice.php | 24 ++++++++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index 9fa42a8cce8..d241c2a8c5a 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -49,6 +49,8 @@ * Print object total tax * Print object local tax * Print object total + * Print order lines for Printer1 + * Print order lines for Printer2 * Print payment method * * Code which can be placed everywhere @@ -188,6 +190,8 @@ class dolReceiptPrinter extends Printer 'dol_print_object_local_tax', 'dol_print_object_total', 'dol_print_object_number', + 'dol_print_order_lines_printer1', + 'dol_print_order_lines_printer2', 'dol_value_customer_firstname', 'dol_value_customer_lastname', 'dol_value_customer_mail', @@ -720,6 +724,28 @@ class dolReceiptPrinter extends Printer case 'DOL_BEEP': $this->printer->getPrintConnector() -> write("\x1e"); break; + case 'DOL_PRINT_ORDER_LINES_PRINTER1': + foreach ($object->lines as $line) { + if ($line->special_code==1) + { + $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1; + $spaces = str_repeat(' ', $spacestoadd); + $this->printer->text($line->ref.$spaces.$line->qty.' '.str_pad(price($line->total_ttc), 10, ' ', STR_PAD_LEFT)."\n"); + $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc))."\n"); + } + } + break; + case 'DOL_PRINT_ORDER_LINES_PRINTER2': + foreach ($object->lines as $line) { + if ($line->special_code==2) + { + $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1; + $spaces = str_repeat(' ', $spacestoadd); + $this->printer->text($line->ref.$spaces.$line->qty.' '.str_pad(price($line->total_ttc), 10, ' ', STR_PAD_LEFT)."\n"); + $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc))."\n"); + } + } + break; default: $this->printer->text($vals[$tplline]['tag']); $this->printer->text($vals[$tplline]['value']); diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index a01cc04d416..1a6b5801f2b 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -441,6 +441,10 @@ if ($action == "updatereduction") if ($action == "order" and $placeid != 0) { include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter"){ + require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php'; + $printer = new dolReceiptPrinter($db); + } $headerorder = '
'.$langs->trans('Place').' '.$place.'
'; $footerorder = '
'.$langs->trans("Label").''.$langs->trans("Qty").'
'.dol_print_date(dol_now(), 'dayhour').'
'; @@ -458,13 +462,20 @@ if ($action == "order" and $placeid != 0) $result = array_intersect($catsprinter1, $existing); $count = count($result); if ($count > 0) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where rowid=".$line->id; + $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='1' where rowid=".$line->id; //Set to print on printer 1 $db->query($sql); $order_receipt_printer1 .= ''.$line->product_label.''.$line->qty; if (!empty($line->array_options['options_order_notes'])) $order_receipt_printer1 .= "
(".$line->array_options['options_order_notes'].")"; $order_receipt_printer1 .= ''; } } + if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter"){ + $invoice->fetch($placeid); //Reload object before send to printer + $ret = $printer->sendToPrinter($invoice, $conf->global->{'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION["takeposterminal"]}, $conf->global->{'TAKEPOS_PRINTER_TO_USE'.$_SESSION["takeposterminal"]}); // PRINT TO PRINTER 1 + } + $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where special_code='1' and fk_facture=".$invoice->id; // Set as printed + $db->query($sql); + $invoice->fetch($placeid); //Reload object after set lines as printed foreach ($invoice->lines as $line) { @@ -476,15 +487,20 @@ if ($action == "order" and $placeid != 0) $result = array_intersect($catsprinter2, $existing); $count = count($result); if ($count > 0) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where rowid=".$line->id; + $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='2' where rowid=".$line->id; //Set to print on printer 2 $db->query($sql); $order_receipt_printer2 .= ''.$line->product_label.''.$line->qty; if (!empty($line->array_options['options_order_notes'])) $order_receipt_printer2 .= "
(".$line->array_options['options_order_notes'].")"; $order_receipt_printer2 .= ''; } } - - $invoice->fetch($placeid); + if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter"){ + $invoice->fetch($placeid); //Reload object before send to printer + $ret = $printer->sendToPrinter($invoice, $conf->global->{'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION["takeposterminal"]}, $conf->global->{'TAKEPOS_PRINTER_TO_USE'.$_SESSION["takeposterminal"]}); // PRINT TO PRINTER 2 + } + $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where special_code='2' and fk_facture=".$invoice->id; // Set as printed + $db->query($sql); + $invoice->fetch($placeid); //Reload object after set lines as printed } $sectionwithinvoicelink = ''; From 1d34ef213c74a5cc6c5c48216dd314eefe291495 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Feb 2020 12:19:46 +0100 Subject: [PATCH 06/12] Fix error management --- htdocs/compta/accounting-files.php | 269 +++++++++++++++-------------- htdocs/langs/en_US/errors.lang | 2 +- 2 files changed, 136 insertions(+), 135 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 18a7eef7b6a..3f7c24c5070 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -118,10 +118,10 @@ if (($action == "searchfiles" || $action == "dl")) { $error++; } - $sql = ''; - if (!$error) { + $sql = ''; + $wheretail = " '".$db->idate($date_start)."' AND '".$db->idate($date_stop)."'"; // Customer invoices @@ -178,152 +178,153 @@ if (($action == "searchfiles" || $action == "dl")) { $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT; } - } - if ($sql) { - $sql .= $db->order($sortfield, $sortorder); - //print $sql; + if ($sql) { + $sql .= $db->order($sortfield, $sortorder); + //print $sql; - $resd = $db->query($sql); - $files = array(); - $link = ''; + $resd = $db->query($sql); + $files = array(); + $link = ''; - if ($resd) - { - $numd = $db->num_rows($resd); + if ($resd) + { + $numd = $db->num_rows($resd); - $tmpinvoice = new Facture($db); - $tmpinvoicesupplier = new FactureFournisseur($db); - $tmpdonation = new Don($db); + $tmpinvoice = new Facture($db); + $tmpinvoicesupplier = new FactureFournisseur($db); + $tmpdonation = new Don($db); - $upload_dir = ''; - $i = 0; - while ($i < $numd) - { - $objd = $db->fetch_object($resd); + $upload_dir = ''; + $i = 0; + while ($i < $numd) + { + $objd = $db->fetch_object($resd); - switch ($objd->item) - { - case "Invoice": - $subdir = ''; - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); - $upload_dir = $conf->facture->dir_output.'/'.$subdir; - $link = "document.php?modulepart=facture&file=".str_replace('/', '%2F', $subdir).'%2F'; - break; - case "SupplierInvoice": - $tmpinvoicesupplier->fetch($objd->id); - $subdir = get_exdir($tmpinvoicesupplier->id, 2, 0, 1, $tmpinvoicesupplier, 'invoice_supplier'); // TODO Use first file - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); - $upload_dir = $conf->fournisseur->facture->dir_output.'/'.$subdir; - $link = "document.php?modulepart=facture_fournisseur&file=".str_replace('/', '%2F', $subdir).'%2F'; - break; - case "ExpenseReport": - $subdir = ''; - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); - $upload_dir = $conf->expensereport->dir_output.'/'.$subdir; - $link = "document.php?modulepart=expensereport&file=".str_replace('/', '%2F', $subdir).'%2F'; - break; - case "SalaryPayment": - $subdir = ''; - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); - $upload_dir = $conf->salaries->dir_output.'/'.$subdir; - $link = "document.php?modulepart=salaries&file=".str_replace('/', '%2F', $subdir).'%2F'; - break; - case "Donation": - $tmpdonation->fetch($objp->id); - $subdir = get_exdir(0, 0, 0, 0, $tmpdonation, 'donation'); - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); - $upload_dir = $conf->don->dir_output.'/'.$subdir; - $link = "document.php?modulepart=don&file=".str_replace('/', '%2F', $subdir).'%2F'; - break; - case "SocialContributions": - $subdir = ''; - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); - $upload_dir = $conf->tax->dir_output.'/'.$subdir; - $link = "document.php?modulepart=tax&file=".str_replace('/', '%2F', $subdir).'%2F'; - break; - default: - $subdir = ''; - $upload_dir = ''; - $link = ''; - break; - } + switch ($objd->item) + { + case "Invoice": + $subdir = ''; + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); + $upload_dir = $conf->facture->dir_output.'/'.$subdir; + $link = "document.php?modulepart=facture&file=".str_replace('/', '%2F', $subdir).'%2F'; + break; + case "SupplierInvoice": + $tmpinvoicesupplier->fetch($objd->id); + $subdir = get_exdir($tmpinvoicesupplier->id, 2, 0, 1, $tmpinvoicesupplier, 'invoice_supplier'); // TODO Use first file + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); + $upload_dir = $conf->fournisseur->facture->dir_output.'/'.$subdir; + $link = "document.php?modulepart=facture_fournisseur&file=".str_replace('/', '%2F', $subdir).'%2F'; + break; + case "ExpenseReport": + $subdir = ''; + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); + $upload_dir = $conf->expensereport->dir_output.'/'.$subdir; + $link = "document.php?modulepart=expensereport&file=".str_replace('/', '%2F', $subdir).'%2F'; + break; + case "SalaryPayment": + $subdir = ''; + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); + $upload_dir = $conf->salaries->dir_output.'/'.$subdir; + $link = "document.php?modulepart=salaries&file=".str_replace('/', '%2F', $subdir).'%2F'; + break; + case "Donation": + $tmpdonation->fetch($objp->id); + $subdir = get_exdir(0, 0, 0, 0, $tmpdonation, 'donation'); + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); + $upload_dir = $conf->don->dir_output.'/'.$subdir; + $link = "document.php?modulepart=don&file=".str_replace('/', '%2F', $subdir).'%2F'; + break; + case "SocialContributions": + $subdir = ''; + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); + $upload_dir = $conf->tax->dir_output.'/'.$subdir; + $link = "document.php?modulepart=tax&file=".str_replace('/', '%2F', $subdir).'%2F'; + break; + default: + $subdir = ''; + $upload_dir = ''; + $link = ''; + break; + } - if (!empty($upload_dir)) - { - $result = true; + if (!empty($upload_dir)) + { + $result = true; - $files = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview\.png)$', '', SORT_ASC, 1); - //var_dump($upload_dir); - //var_dump($files); - if (count($files) < 1) - { - $nofile = array(); - $nofile['id'] = $objd->id; - $nofile['entity'] = $objd->entity; - $nofile['date'] = $db->idate($objd->date); - $nofile['paid'] = $objd->paid; - $nofile['amount_ht'] = $objd->total_ht; - $nofile['amount_ttc'] = $objd->total_ttc; - $nofile['amount_vat'] = $objd->total_vat; - $nofile['ref'] = ($objd->ref ? $objd->ref : $objd->id); - $nofile['fk'] = $objd->fk_soc; - $nofile['item'] = $objd->item; - $nofile['thirdparty_name'] = $objd->thirdparty_name; - $nofile['thirdparty_code'] = $objd->thirdparty_code; - $nofile['country_code'] = $objd->country_code; - $nofile['vatnum'] = $objd->vatnum; + $files = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview\.png)$', '', SORT_ASC, 1); + //var_dump($upload_dir); + //var_dump($files); + if (count($files) < 1) + { + $nofile = array(); + $nofile['id'] = $objd->id; + $nofile['entity'] = $objd->entity; + $nofile['date'] = $db->idate($objd->date); + $nofile['paid'] = $objd->paid; + $nofile['amount_ht'] = $objd->total_ht; + $nofile['amount_ttc'] = $objd->total_ttc; + $nofile['amount_vat'] = $objd->total_vat; + $nofile['ref'] = ($objd->ref ? $objd->ref : $objd->id); + $nofile['fk'] = $objd->fk_soc; + $nofile['item'] = $objd->item; + $nofile['thirdparty_name'] = $objd->thirdparty_name; + $nofile['thirdparty_code'] = $objd->thirdparty_code; + $nofile['country_code'] = $objd->country_code; + $nofile['vatnum'] = $objd->vatnum; - $filesarray[$nofile['item'].'_'.$nofile['id']] = $nofile; - } - else - { - foreach ($files as $key => $file) - { - $file['id'] = $objd->id; - $file['entity'] = $objd->entity; - $file['date'] = $db->idate($objd->date); - $file['paid'] = $objd->paid; - $file['amount_ht'] = $objd->total_ht; - $file['amount_ttc'] = $objd->total_ttc; - $file['amount_vat'] = $objd->total_vat; - $file['ref'] = ($objd->ref ? $objd->ref : $objd->id); - $file['fk'] = $objd->fk_soc; - $file['item'] = $objd->item; + $filesarray[$nofile['item'].'_'.$nofile['id']] = $nofile; + } + else + { + foreach ($files as $key => $file) + { + $file['id'] = $objd->id; + $file['entity'] = $objd->entity; + $file['date'] = $db->idate($objd->date); + $file['paid'] = $objd->paid; + $file['amount_ht'] = $objd->total_ht; + $file['amount_ttc'] = $objd->total_ttc; + $file['amount_vat'] = $objd->total_vat; + $file['ref'] = ($objd->ref ? $objd->ref : $objd->id); + $file['fk'] = $objd->fk_soc; + $file['item'] = $objd->item; - $file['thirdparty_name'] = $objd->thirdparty_name; - $file['thirdparty_code'] = $objd->thirdparty_code; - $file['country_code'] = $objd->country_code; - $file['vatnum'] = $objd->vatnum; + $file['thirdparty_name'] = $objd->thirdparty_name; + $file['thirdparty_code'] = $objd->thirdparty_code; + $file['country_code'] = $objd->country_code; + $file['vatnum'] = $objd->vatnum; - // Save record into array (only the first time it is found) - if (empty($filesarray[$file['item'].'_'.$file['id']])) { - $filesarray[$file['item'].'_'.$file['id']] = $file; - } + // Save record into array (only the first time it is found) + if (empty($filesarray[$file['item'].'_'.$file['id']])) { + $filesarray[$file['item'].'_'.$file['id']] = $file; + } - // Add or concat file - if (empty($filesarray[$file['item'].'_'.$file['id']]['files'])) { - $filesarray[$file['item'].'_'.$file['id']]['files'] = array(); - } - $filesarray[$file['item'].'_'.$file['id']]['files'][] = array('link' => $link.$file['name'], 'name'=>$file['name'], 'ref'=>$file['ref'], 'fullname' => $file['fullname'], 'relpathnamelang' => $langs->trans($file['item']).'/'.$file['name']); - //var_dump($file['item'].'_'.$file['id']); - //var_dump($filesarray[$file['item'].'_'.$file['id']]['files']); - } - } - } + // Add or concat file + if (empty($filesarray[$file['item'].'_'.$file['id']]['files'])) { + $filesarray[$file['item'].'_'.$file['id']]['files'] = array(); + } + $filesarray[$file['item'].'_'.$file['id']]['files'][] = array('link' => $link.$file['name'], 'name'=>$file['name'], 'ref'=>$file['ref'], 'fullname' => $file['fullname'], 'relpathnamelang' => $langs->trans($file['item']).'/'.$file['name']); + //var_dump($file['item'].'_'.$file['id']); + //var_dump($filesarray[$file['item'].'_'.$file['id']]['files']); + } + } + } - $i++; - } - } - else - { - dol_print_error($db); - } + $i++; + } + } + else + { + dol_print_error($db); + } - $db->free($resd); - } - else { - setEventMessages($langs->trans("ErrorAtLeastOneObjectMustBeSelected"), null, 'errors'); + $db->free($resd); + } + else { + setEventMessages($langs->trans("ErrorSelectAtLeastOne"), null, 'errors'); + $error++; + } } } diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index cc56503c638..210d7082fdf 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -96,7 +96,7 @@ ErrorBadMaskFailedToLocatePosOfSequence=Error, mask without sequence number ErrorBadMaskBadRazMonth=Error, bad reset value ErrorMaxNumberReachForThisMask=Maximum number reached for this mask ErrorCounterMustHaveMoreThan3Digits=Counter must have more than 3 digits -ErrorSelectAtLeastOne=Error. Select at least one entry. +ErrorSelectAtLeastOne=Error, select at least one entry. ErrorDeleteNotPossibleLineIsConsolidated=Delete not possible because record is linked to a bank transaction that is conciliated ErrorProdIdAlreadyExist=%s is assigned to another third ErrorFailedToSendPassword=Failed to send password From d741a025f36aa2fe4cd3d1544173518d6fec8819 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Feb 2020 14:13:15 +0100 Subject: [PATCH 07/12] Fix duplicate error message --- htdocs/cron/class/cronjob.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 82a898a8ddf..81f86b1642d 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -1094,7 +1094,7 @@ class Cronjob extends CommonObject $errmsg = ''; if (!is_array($object->errors) || !in_array($object->error, $object->errors)) $errmsg .= $object->error; - if (is_array($object->errors) && count($object->errors)) $errmsg .= ($errmsg ? ', '.$errmsg : '').join(', ', $object->errors); + if (is_array($object->errors) && count($object->errors)) $errmsg .= (($errmsg ? ', ' : '').join(', ', $object->errors)); if (empty($errmsg)) $errmsg = $langs->trans('ErrorUnknown'); dol_syslog(get_class($this)."::run_jobs END result=".$result." error=".$errmsg, LOG_ERR); From 0d474b2ec9a6ba4725b0f9466f09aa6d706b8a67 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Feb 2020 14:20:42 +0100 Subject: [PATCH 08/12] CSS --- htdocs/compta/accounting-files.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 3f7c24c5070..bab53a8f77b 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -453,7 +453,7 @@ print ' - '.$form->selectDate($date_stop, 'date_stop', 0, 0, 0, "", 1, 1, 0)."\n if (!empty($conf->multicompany->enabled) && is_object($mc)) { $mc->getInfo($conf->entity); - print '('.$langs->trans("Entity").' : '; + print '('.$langs->trans("Entity").' : '; print ""; if (!empty($conf->global->MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES)) { print $mc->select_entities(GETPOSTISSET('search_entity') ? GETPOST('search_entity', 'int') : $mc->id, 'search_entity', '', false, false, false, false, true); From 76e33058a851a53d67bb03daa092b7e2cc12e223 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 23 Feb 2020 21:38:24 +0100 Subject: [PATCH 09/12] NEW Can select several fields to personalize list before submit. --- htdocs/core/class/html.form.class.php | 11 +++-- htdocs/core/js/lib_foot.js.php | 63 ++++++++++++++++++++------- htdocs/main.inc.php | 14 +++--- htdocs/theme/eldy/dropdown.inc.php | 2 +- htdocs/theme/eldy/global.inc.php | 10 ++--- 5 files changed, 68 insertions(+), 32 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e1e7d97f821..4ab0bc44d9d 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6693,8 +6693,10 @@ class Form @@ -7070,7 +7074,6 @@ class Form jQuery(".linkto").click(function() { console.log("We choose to show/hide link for rel="+jQuery(this).attr(\'rel\')); jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle(); - jQuery(this).toggle(); }); }); diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index 3d708101d13..0d9b0b59ff4 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -81,13 +81,31 @@ print "});\n"; // Wrapper to manage dropdown if (! defined('JS_JQUERY_DISABLE_DROPDOWN')) { - print "\n/* JS CODE TO ENABLE dropdown */\n"; + print "\n/* JS CODE TO ENABLE dropdown (hamburger, linkto, ...) */\n"; print ' - jQuery(document).ready(function () { - $(".dropdown dt a").on(\'click\', function () { - console.log("We click on dropdown"); - //console.log($(this).parent().parent().find(\'dd ul\')); - $(this).parent().parent().find(\'dd ul\').slideToggle(\'fast\'); + jQuery(document).ready(function () { + var lastopendropdown = null; + + // Click onto the link "link to" or "hamburger", toggle dropdown + $(".dropdown dt a").on(\'click\', function () { + console.log("toggle dropdown dt a"); + + //$(this).parent().parent().find(\'dd ul\').slideToggle(\'fast\'); + $(this).parent().parent().find(\'dd ul\').toggleClass("open"); + + if ($(this).parent().parent().find(\'dd ul\').hasClass("open")) { + lastopendropdown = $(this).parent().parent().find(\'dd ul\'); + //console.log(lastopendropdown); + } else { + // We closed the dropdown for hamburger selectfields + if ($("input:hidden[name=formfilteraction]").val() == "listafterchangingselectedfields") { + console.log("resubmit the form saved into lastopendropdown after clicking on hamburger"); + //$(".dropdown dt a").parents(\'form:first\').submit(); + //$(".dropdown dt a").closest("form").submit(); + lastopendropdown.closest("form").submit(); + } + } + // Note: Did not find a way to get exact height (value is update at exit) so i calculate a generic from nb of lines heigthofcontent = 21 * $(this).parent().parent().find(\'dd div ul li\').length; if (heigthofcontent > 300) heigthofcontent = 300; // limited by max-height on css .dropdown dd ul @@ -101,19 +119,32 @@ if (! defined('JS_JQUERY_DISABLE_DROPDOWN')) console.log("We reposition top by "+pix); $(this).parent().parent().find(\'dd\').css("top", pix); } - // $(".dropdown dd ul").slideToggle(\'fast\'); - }); - $(".dropdowncloseonclick").on(\'click\', function () { - console.log("Link has class dropdowncloseonclick, so we close/hide the popup ul"); - $(this).parent().parent().hide(); }); - $(document).bind(\'click\', function (e) { - //console.log("We click outside of dropdown, so we close it."); - var $clicked = $(e.target); - if (!$clicked.parents().hasClass("dropdown")) $(".dropdown dd ul").hide(); + // Click on a link into the popup "link to" or other dropdown that ask to close drop down on element click, so close dropdown + $(".dropdowncloseonclick").on(\'click\', function () { + console.log("Link has class dropdowncloseonclick, so we close/hide the popup ul"); + //$(this).parent().parent().hide(); // $(this).parent().parent() is ul + $(this).parent().parent().removeClass("open"); // $(this).parent().parent() is ul }); - }); + + // Click outside of any dropdown + $(document).bind(\'click\', function (e) { + var $clicked = $(e.target); // This is element we click on + if (!$clicked.parents().hasClass("dropdown")) { + console.log("close dropdown dd ul - we click outside"); + //$(".dropdown dd ul").hide(); + $(".dropdown dd ul").removeClass("open"); + + if ($("input:hidden[name=formfilteraction]").val() == "listafterchangingselectedfields") { + console.log("resubmit form saved into lastopendropdown after clicking outside of dropdown and having change selectlist from selectlist field of hamburger dropdown"); + //$(".dropdown dt a").parents(\'form:first\').submit(); + //$(".dropdown dt a").closest("form").submit(); + lastopendropdown.closest("form").submit(); + } + } + }); + }); '; } diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 0f1f0e01a87..8c1cdd829de 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1898,13 +1898,15 @@ function top_menu_user() $( document ).ready(function() { $(document).on("click", function(event) { if (!$(event.target).closest("#topmenu-login-dropdown").length) { - // Hide the menus. + //console.log("close login dropdown"); + // Hide the menus. $("#topmenu-login-dropdown").removeClass("open"); } }); $("#topmenu-login-dropdown .dropdown-toggle").on("click", function(event) { - event.preventDefault(); + console.log("toggle login dropdown"); + event.preventDefault(); $("#topmenu-login-dropdown").toggleClass("open"); }); @@ -1954,14 +1956,14 @@ function top_menu_bookmark() $( document ).ready(function() { $(document).on("click", function(event) { if (!$(event.target).closest("#topmenu-bookmark-dropdown").length) { - console.log("close"); + //console.log("close bookmark dropdown - we click outside"); // Hide the menus. $("#topmenu-bookmark-dropdown").removeClass("open"); } }); $("#topmenu-bookmark-dropdown .dropdown-toggle").on("click", function(event) { - console.log("toggle"); + console.log("toggle bookmark dropdown"); openBookMarkDropDown(); }); @@ -2077,7 +2079,7 @@ function top_menu_search() // close drop down $(document).on("click", function(event) { if (!$(event.target).closest("#topmenu-global-search-dropdown").length) { - console.log("click close"); + console.log("click close search - we click outside"); // Hide the menus. $("#topmenu-global-search-dropdown").removeClass("open"); } @@ -2085,7 +2087,7 @@ function top_menu_search() // Open drop down $("#topmenu-global-search-dropdown .dropdown-toggle").on("click", function(event) { - console.log("click open"); + console.log("toggle search dropdown"); openGlobalSearchDropDown(); }); diff --git a/htdocs/theme/eldy/dropdown.inc.php b/htdocs/theme/eldy/dropdown.inc.php index 580e9366bc1..69716ce5be3 100644 --- a/htdocs/theme/eldy/dropdown.inc.php +++ b/htdocs/theme/eldy/dropdown.inc.php @@ -9,7 +9,7 @@ button.dropdown-item.global-search-item { outline: none; } -.open>.dropdown-search, .open>.dropdown-bookmark, .open>.dropdown-menu{ +.open>.dropdown-search, .open>.dropdown-bookmark, .open>.dropdown-menu, .dropdown dd ul.open { display: block; } diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index f5c1e328a23..f280cb13d57 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -4983,7 +4983,7 @@ input.select2-input { } .select2-container--default .select2-selection--single .select2-selection__rendered { color: var(--colortext); - background-color: var(--colorbackvmenu1); + /* background-color: var(--colorbackvmenu1); */ } .select2-default { color: #999 !important; @@ -5079,8 +5079,8 @@ input.select2-input { box-shadow: none !important; } .select2-dropdown { - background-color: var(--colorbackvmenu1); - border: 1px solid var(--colorbackvmenu1);; + /*background-color: var(--colorbackvmenu1); + border: 1px solid var(--colorbackvmenu1); */ box-shadow: 1px 2px 10px var(--colorbackvmenu1); } .select2-dropdown-open { @@ -5405,9 +5405,9 @@ dl.dropdown { .dropdown dd ul li span { color: #888; } -.dropdown dd ul li a:hover { +/*.dropdown dd ul li a:hover { background-color: var(--inputbackgroundcolor); -} +}*/ dd.dropdowndd ul li { text-overflow: ellipsis; overflow: hidden; From 189c0d675ba4b73700093d98c272d028ed332297 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 23 Feb 2020 22:05:59 +0100 Subject: [PATCH 10/12] Fix memory report. Xdebug no more required. Try = null instead of unset. --- htdocs/compta/bank/graph.php | 61 ++++++++++++++++--------------- htdocs/core/lib/functions.lib.php | 13 +++---- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/htdocs/compta/bank/graph.php b/htdocs/compta/bank/graph.php index fbcd06a51bc..2e1f36cbeea 100644 --- a/htdocs/compta/bank/graph.php +++ b/htdocs/compta/bank/graph.php @@ -255,13 +255,14 @@ else $px1->draw($file, $fileurl); $show1 = $px1->show(); - unset($graph_datas); - unset($px1); - unset($datas); - unset($datamin); - unset($dataall); - unset($labels); - unset($amounts); + + $px1 = null; + $graph_datas =null; + $datas = null; + $datamin = null; + $dataall = null; + $labels = null; + $amounts = null; } // Graph Balance for the year @@ -392,13 +393,13 @@ else $show2 = $px2->show(); - unset($px2); - unset($graph_datas); - unset($datas); - unset($datamin); - unset($dataall); - unset($labels); - unset($amounts); + $px2 = null; + $graph_datas =null; + $datas = null; + $datamin = null; + $dataall = null; + $labels = null; + $amounts = null; } // Graph 3 - Balance for all time line @@ -460,7 +461,7 @@ else } else { - $datas[$i] = '' +$solde + $subtotal; + $datas[$i] = 0 + $solde + $subtotal; } $datamin[$i] = $object->min_desired; $dataall[$i] = $object->min_allowed; @@ -505,13 +506,13 @@ else $show3 = $px3->show(); - unset($px3); - unset($graph_datas); - unset($datas); - unset($datamin); - unset($dataall); - unset($labels); - unset($amounts); + $px3 = null; + $graph_datas =null; + $datas = null; + $datamin = null; + $dataall = null; + $labels = null; + $amounts = null; } // Tableau 4a - Credit/Debit @@ -634,10 +635,10 @@ else $show4 = $px4->show(); - unset($graph_datas); - unset($px4); - unset($debits); - unset($credits); + $px4 = null; + $graph_datas = null; + $debits = null; + $credits = null; } // Tableau 4b - Credit/Debit @@ -742,10 +743,10 @@ else $show5 = $px5->show(); - unset($graph_datas); - unset($px5); - unset($debits); - unset($credits); + $px5 = null; + $graph_datas = null; + $debits = null; + $credits = null; } } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index f5c05fdf969..5f06d72139e 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7618,15 +7618,12 @@ function printCommonFooter($zone = 'private') $micro_end_time = microtime(true); print ' - Build time: '.ceil(1000 * ($micro_end_time - $micro_start_time)).' ms'; } - if (function_exists("memory_get_usage")) - { - print ' - Mem: '.memory_get_usage(); + + if (function_exists("memory_get_usage")) { + print ' - Mem: '.memory_get_usage(); // Do not use true here, it seems it takes the peak amount } - if (function_exists("xdebug_memory_usage")) - { - print ' - XDebug time: '.ceil(1000 * xdebug_time_index()).' ms'; - print ' - XDebug mem: '.xdebug_memory_usage(); - print ' - XDebug mem peak: '.xdebug_peak_memory_usage(); + if (function_exists("memory_get_peak_usage")) { + print ' - Real mem peak: '.memory_get_peak_usage(true); } if (function_exists("zend_loader_file_encoded")) { From 686a93769c3baf61179885832aca085e8db9d4ff Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 23 Feb 2020 22:30:15 +0100 Subject: [PATCH 11/12] Fix delay before closing stale issues --- .github/workflows/stale-issues.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale-issues.yml b/.github/workflows/stale-issues.yml index 66eb3f0cd40..b50af3ec717 100644 --- a/.github/workflows/stale-issues.yml +++ b/.github/workflows/stale-issues.yml @@ -16,7 +16,7 @@ jobs: stale-issue-label: 'Issue Stale (automatic label)' exempt-issue-label: 'Priority High / Blocking' days-before-stale: 365 - days-before-close: 10 + days-before-close: 15 #stale-pr-message: 'This PR is stale because it has been open 1 year with no activity. If this PR is still mergeable (no conflict, nor Continuous Integration errors), please comment to confirm this merge is still expected. Without comment, this issue will be closed automatically by stale bot in 15 days.' #stale-pr-label: 'PR Stale (automatic label)' #exempt-pr-label: 'Priority Top Strategic' From ca39c680c7853565d1973630d38ddf6e16df9cba Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 23 Feb 2020 23:03:17 +0100 Subject: [PATCH 12/12] Rename field documentpdf into printable (this field already exists due to a very old PR nofinished for same goal). --- htdocs/core/actions_extrafields.inc.php | 4 +-- .../core/class/commondocgenerator.class.php | 4 +-- htdocs/core/class/extrafields.class.php | 34 +++++++++---------- htdocs/core/tpl/admin_extrafields_add.tpl.php | 2 +- .../core/tpl/admin_extrafields_edit.tpl.php | 4 +-- .../core/tpl/admin_extrafields_view.tpl.php | 2 +- .../install/mysql/migration/11.0.0-12.0.0.sql | 5 ++- .../install/mysql/tables/llx_extrafields.sql | 2 +- 8 files changed, 30 insertions(+), 27 deletions(-) diff --git a/htdocs/core/actions_extrafields.inc.php b/htdocs/core/actions_extrafields.inc.php index 486764b167e..abd82a18351 100644 --- a/htdocs/core/actions_extrafields.inc.php +++ b/htdocs/core/actions_extrafields.inc.php @@ -184,7 +184,7 @@ if ($action == 'add') GETPOST('langfile', 'alpha'), 1, (GETPOST('totalizable', 'alpha')?1:0), - (GETPOST('documentpdf', 'alpha')?1:0) + (GETPOST('printable', 'alpha')?1:0) ); if ($result > 0) { @@ -354,7 +354,7 @@ if ($action == 'update') GETPOST('langfile'), 1, (GETPOST('totalizable', 'alpha')?1:0), - (GETPOST('documentpdf', 'alpha')?1:0) + (GETPOST('printable', 'alpha')?1:0) ); if ($result > 0) { diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index eb214516a6f..1bd051d4b55 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -1213,7 +1213,7 @@ abstract class CommonDocGenerator foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) { // Enable extrafield ? - $enabled = !empty($extrafields->attributes[$object->table_element]['documentpdf'][$key]); + $enabled = !empty($extrafields->attributes[$object->table_element]['printable'][$key]); if(empty($enabled)){ continue; @@ -1425,7 +1425,7 @@ abstract class CommonDocGenerator } // Enable extrafield ? - $enabled = !empty($extrafields->attributes[$object->table_element]['documentpdf'][$key]); + $enabled = !empty($extrafields->attributes[$object->table_element]['printable'][$key]); // Load language if required diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index ff1e6267252..91803dc32db 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -225,10 +225,10 @@ class ExtraFields * @param string $langfile Language file * @param string $enabled Condition to have the field enabled or not * @param int $totalizable Is a measure. Must show a total on lists - * @param int $documentpdf Is extrafield displayed on PDF + * @param int $printable Is extrafield displayed on PDF * @return int <=0 if KO, >0 if OK */ - public function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique = 0, $required = 0, $default_value = '', $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $documentpdf = 0) + public function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique = 0, $required = 0, $default_value = '', $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $printable = 0) { if (empty($attrname)) return -1; if (empty($label)) return -1; @@ -246,7 +246,7 @@ class ExtraFields if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate') { // Add declaration of field into table - $result2 = $this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $help, $default_value, $computed, $entity, $langfile, $enabled, $totalizable, $documentpdf); + $result2 = $this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $help, $default_value, $computed, $entity, $langfile, $enabled, $totalizable, $printable); $err2 = $this->errno; if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS')) { @@ -375,11 +375,11 @@ class ExtraFields * @param string $langfile Language file * @param string $enabled Condition to have the field enabled or not * @param int $totalizable Is a measure. Must show a total on lists - * @param int $documentpdf Is extrafield displayed on PDF + * @param int $printable Is extrafield displayed on PDF * @return int <=0 if KO, >0 if OK * @throws Exception */ - private function create_label($attrname, $label = '', $type = '', $pos = 0, $size = 0, $elementtype = 'member', $unique = 0, $required = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $documentpdf = 0) + private function create_label($attrname, $label = '', $type = '', $pos = 0, $size = 0, $elementtype = 'member', $unique = 0, $required = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $printable = 0) { // phpcs:enable global $conf, $user; @@ -424,7 +424,7 @@ class ExtraFields $sql .= " perms,"; $sql .= " langs,"; $sql .= " list,"; - $sql .= " documentpdf,"; + $sql .= " printable,"; $sql .= " fielddefault,"; $sql .= " fieldcomputed,"; $sql .= " fk_user_author,"; @@ -448,7 +448,7 @@ class ExtraFields $sql .= " ".($perms ? "'".$this->db->escape($perms)."'" : "null").","; $sql .= " ".($langfile ? "'".$this->db->escape($langfile)."'" : "null").","; $sql .= " '".$this->db->escape($list)."',"; - $sql .= " '".$this->db->escape($documentpdf)."',"; + $sql .= " '".$this->db->escape($printable)."',"; $sql .= " ".($default ? "'".$this->db->escape($default)."'" : "null").","; $sql .= " ".($computed ? "'".$this->db->escape($computed)."'" : "null").","; $sql .= " ".(is_object($user) ? $user->id : 0).","; @@ -595,11 +595,11 @@ class ExtraFields * @param string $langfile Language file * @param string $enabled Condition to have the field enabled or not * @param int $totalizable Is extrafield totalizable on list - * @param int $documentpdf Is extrafield displayed on PDF + * @param int $printable Is extrafield displayed on PDF * @return int >0 if OK, <=0 if KO * @throws Exception */ - public function update($attrname, $label, $type, $length, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $documentpdf = 0) + public function update($attrname, $label, $type, $length, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $printable = 0) { if ($elementtype == 'thirdparty') $elementtype = 'societe'; if ($elementtype == 'contact') $elementtype = 'socpeople'; @@ -649,7 +649,7 @@ class ExtraFields { if ($label) { - $result = $this->update_label($attrname, $label, $type, $length, $elementtype, $unique, $required, $pos, $param, $alwayseditable, $perms, $list, $help, $default, $computed, $entity, $langfile, $enabled, $totalizable, $documentpdf); + $result = $this->update_label($attrname, $label, $type, $length, $elementtype, $unique, $required, $pos, $param, $alwayseditable, $perms, $list, $help, $default, $computed, $entity, $langfile, $enabled, $totalizable, $printable); } if ($result > 0) { @@ -707,15 +707,15 @@ class ExtraFields * @param string $langfile Language file * @param string $enabled Condition to have the field enabled or not * @param int $totalizable Is extrafield totalizable on list - * @param int $documentpdf Is extrafield displayed on PDF + * @param int $printable Is extrafield displayed on PDF * @return int <=0 if KO, >0 if OK * @throws Exception */ - private function update_label($attrname, $label, $type, $size, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '0', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $documentpdf = 0) + private function update_label($attrname, $label, $type, $size, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '0', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $printable = 0) { // phpcs:enable global $conf, $user; - dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled.", ".$totalizable.", ".$documentpdf); + dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled.", ".$totalizable.", ".$printable); // Clean parameters if ($elementtype == 'thirdparty') $elementtype = 'societe'; @@ -780,7 +780,7 @@ class ExtraFields $sql .= " alwayseditable,"; $sql .= " param,"; $sql .= " list,"; - $sql .= " documentpdf,"; + $sql .= " printable,"; $sql .= " totalizable,"; $sql .= " fielddefault,"; $sql .= " fieldcomputed,"; @@ -804,7 +804,7 @@ class ExtraFields $sql .= " '".$this->db->escape($alwayseditable)."',"; $sql .= " '".$this->db->escape($params)."',"; $sql .= " '".$this->db->escape($list)."', "; - $sql .= " '".$this->db->escape($documentpdf)."', "; + $sql .= " '".$this->db->escape($printable)."', "; $sql .= " ".$totalizable.","; $sql .= " ".(($default != '') ? "'".$this->db->escape($default)."'" : "null").","; $sql .= " ".($computed ? "'".$this->db->escape($computed)."'" : "null").","; @@ -882,7 +882,7 @@ class ExtraFields }*/ // We should not have several time this request. If we have, there is some optimization to do by calling a simple $extrafields->fetch_optionals() in top of code and not into subcode - $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,documentpdf,totalizable,fielddefault,fieldcomputed,entity,enabled,help"; + $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,printable,totalizable,fielddefault,fieldcomputed,entity,enabled,help"; $sql .= " FROM ".MAIN_DB_PREFIX."extrafields"; //$sql.= " WHERE entity IN (0,".$conf->entity.")"; // Filter is done later if ($elementtype) $sql .= " WHERE elementtype = '".$elementtype."'"; // Filed with object->table_element @@ -944,7 +944,7 @@ class ExtraFields $this->attributes[$tab->elementtype]['perms'][$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms); $this->attributes[$tab->elementtype]['langfile'][$tab->name] = $tab->langs; $this->attributes[$tab->elementtype]['list'][$tab->name] = $tab->list; - $this->attributes[$tab->elementtype]['documentpdf'][$tab->name] = $tab->documentpdf; + $this->attributes[$tab->elementtype]['printable'][$tab->name] = $tab->printable; $this->attributes[$tab->elementtype]['totalizable'][$tab->name] = $tab->totalizable; $this->attributes[$tab->elementtype]['entityid'][$tab->name] = $tab->entity; $this->attributes[$tab->elementtype]['enabled'][$tab->name] = $tab->enabled; diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index 37872f2a5c0..5f9a70d272b 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -198,7 +198,7 @@ $langs->load("modulebuilder"); textwithpicto($langs->trans("DisplayOnPdf"), $langs->trans("DisplayOnPdfDesc")); ?> -> +> trans("Totalizable"); ?>> diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index 8e14ad978ca..f2d3e4e7bb5 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -165,7 +165,7 @@ $list=$extrafields->attributes[$elementtype]['list'][$attrname]; $totalizable = $extrafields->attributes[$elementtype]['totalizable'][$attrname]; $help=$extrafields->attributes[$elementtype]['help'][$attrname]; $entitycurrentorall=$extrafields->attributes[$elementtype]['entityid'][$attrname]; -$documentpdf=$extrafields->attributes[$elementtype]['documentpdf'][$attrname]; +$printable=$extrafields->attributes[$elementtype]['printable'][$attrname]; if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_array($param)) { @@ -267,7 +267,7 @@ else textwithpicto($langs->trans("DisplayOnPdf"), $langs->trans("DisplayOnPdfDesc")); ?> -> +> textwithpicto($langs->trans("Totalizable"), $langs->trans("TotalizableDesc")); ?>> textwithpicto($langs->trans("HelpOnTooltip"), $langs->trans("HelpOnTooltipDesc")); ?> diff --git a/htdocs/core/tpl/admin_extrafields_view.tpl.php b/htdocs/core/tpl/admin_extrafields_view.tpl.php index 3bec8cb8d6f..769c12ceaa5 100644 --- a/htdocs/core/tpl/admin_extrafields_view.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_view.tpl.php @@ -93,7 +93,7 @@ if (is_array($extrafields->attributes[$elementtype]['type']) && count($extrafiel print ''.yn($extrafields->attributes[$elementtype]['required'][$key])."\n"; print ''.yn($extrafields->attributes[$elementtype]['alwayseditable'][$key])."\n"; print ''.$extrafields->attributes[$elementtype]['list'][$key]."\n"; - print ''.yn($extrafields->attributes[$elementtype]['documentpdf'][$key])."\n"; + print ''.yn($extrafields->attributes[$elementtype]['printable'][$key])."\n"; print ''.yn($extrafields->attributes[$elementtype]['totalizable'][$key])."\n"; if (! empty($conf->multicompany->enabled)) { print ''; diff --git a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql index 0a91f960807..e4d1dd51135 100644 --- a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql +++ b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql @@ -181,4 +181,7 @@ INSERT INTO llx_c_ticket_resolution (code, pos, label, active, use_default, desc DELETE FROM llx_const WHERE name = __ENCRYPT('DONATION_ART885')__; -ALTER TABLE llx_extrafields ADD COLUMN documentpdf integer DEFAULT 0; \ No newline at end of file +ALTER TABLE llx_extrafields MODIFY COLUMN printable integer DEFAULT 0; +ALTER TABLE llx_extrafields ADD COLUMN printable integer DEFAULT 0; + + diff --git a/htdocs/install/mysql/tables/llx_extrafields.sql b/htdocs/install/mysql/tables/llx_extrafields.sql index 4fd80c0d9c2..3578414d98b 100644 --- a/htdocs/install/mysql/tables/llx_extrafields.sql +++ b/htdocs/install/mysql/tables/llx_extrafields.sql @@ -36,7 +36,7 @@ create table llx_extrafields alwayseditable integer DEFAULT 0, -- 1 if field can be edited whatever is element status param text, -- extra parameters to define possible values of field list varchar(255) DEFAULT '1', -- visibility of field. 0=Never visible, 1=Visible on list and forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing - printable boolean DEFAULT FALSE, -- is the extrafield output on documents + printable integer DEFAULT 0, -- is the extrafield output on documents totalizable boolean DEFAULT FALSE, -- is extrafield totalizable on list langs varchar(64), -- example: fileofmymodule@mymodule help text, -- to store help tooltip