From ab9c320c7f4c48a8cf2d42f5e0435ec0de01db93 Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Tue, 3 Aug 2021 17:33:06 +0400 Subject: [PATCH 01/14] CLOSE #18326 Workflow: Close order on shipment closing. Allow an order to be closed automatically when all linked shipment have been closed and all products / items have been shipped. --- htdocs/admin/workflow.php | 10 ++++++++-- htdocs/core/modules/modWorkflow.class.php | 1 + .../interface_20_modWorkflow_WorkflowManager.class.php | 10 ++++++++-- htdocs/langs/en_US/workflow.lang | 1 + htdocs/langs/fr_FR/workflow.lang | 1 + 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/htdocs/admin/workflow.php b/htdocs/admin/workflow.php index 09156e08588..1b6fa5bebe7 100644 --- a/htdocs/admin/workflow.php +++ b/htdocs/admin/workflow.php @@ -91,15 +91,21 @@ $workflowcodes = array( ), // Automatic classification of order - 'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING'=>array( + 'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING'=>array( // when shipping validated 'family'=>'classify_order', 'position'=>40, 'enabled'=>(!empty($conf->expedition->enabled) && !empty($conf->commande->enabled)), 'picto'=>'order' ), - 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER'=>array( + 'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING_CLOSED'=>array( // when shipping closed 'family'=>'classify_order', 'position'=>41, + 'enabled'=>(!empty($conf->expedition->enabled) && !empty($conf->commande->enabled)), + 'picto'=>'order' + ), + 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER'=>array( + 'family'=>'classify_order', + 'position'=>42, 'enabled'=>(!empty($conf->facture->enabled) && !empty($conf->commande->enabled)), 'picto'=>'order', 'warning'=>'' diff --git a/htdocs/core/modules/modWorkflow.class.php b/htdocs/core/modules/modWorkflow.class.php index fbf7927ed1c..eaaf15d40a1 100644 --- a/htdocs/core/modules/modWorkflow.class.php +++ b/htdocs/core/modules/modWorkflow.class.php @@ -87,6 +87,7 @@ class modWorkflow extends DolibarrModules 0=>array('WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL', 'chaine', '1', 'WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL', 0, 'current', 0), 1=>array('WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL', 'chaine', '1', 'WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL', 0, 'current', 0), 2=>array('WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING', 'chaine', '1', 'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING', 0, 'current', 0), + 3=>array('WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING_CLOSED', 'chaine', '1', 'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING_CLOSED', 0, 'current', 0), 4=>array('WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER', 'chaine', '1', 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER', 0, 'current', 0), 5=>array('WORKFLOW_ORDER_CLASSIFY_BILLED_SUPPLIER_PROPOSAL', 'chaine', '1', 'WORKFLOW_ORDER_CLASSIFY_BILLED_SUPPLIER_PROPOSAL', 0, 'current', 0), 6=>array('WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER', 'chaine', '1', 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER', 0, 'current', 0), diff --git a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php index c6b2d38a99d..15d8dedda10 100644 --- a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php +++ b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php @@ -256,10 +256,15 @@ class InterfaceWorkflowManager extends DolibarrTriggers } } - if ($action == 'SHIPPING_VALIDATE') { + if (($action == 'SHIPPING_VALIDATE') || ($action == 'SHIPPING_CLOSED')) { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->commande->enabled) && !empty($conf->expedition->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING)) { + if (!empty($conf->commande->enabled) && !empty($conf->expedition->enabled) && !empty($conf->workflow->enabled) && + ( + (!empty($conf->global->WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING) && ($action == 'SHIPPING_VALIDATE')) || + (!empty($conf->global->WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING_CLOSED) && ($action == 'SHIPPING_CLOSED')) + ) + ) { $qtyshipped = array(); $qtyordred = array(); require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; @@ -318,6 +323,7 @@ class InterfaceWorkflowManager extends DolibarrTriggers } } } + // classify billed reception if ($action == 'BILL_SUPPLIER_VALIDATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id, LOG_DEBUG); diff --git a/htdocs/langs/en_US/workflow.lang b/htdocs/langs/en_US/workflow.lang index 15fd8ef07c2..fafbc6e8d8a 100644 --- a/htdocs/langs/en_US/workflow.lang +++ b/htdocs/langs/en_US/workflow.lang @@ -13,6 +13,7 @@ descWORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL=Classify linked source proposal as b descWORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER=Classify linked source sales order as billed when customer invoice is validated (and if the amount of the invoice is the same as the total amount of the linked order) descWORKFLOW_INVOICE_CLASSIFY_BILLED_ORDER=Classify linked source sales order as billed when customer invoice is set to paid (and if the amount of the invoice is the same as the total amount of the linked order) descWORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING=Classify linked source sales order as shipped when a shipment is validated (and if the quantity shipped by all shipments is the same as in the order to update) +descWORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING_CLOSED=Classify linked source sales order as shipped when a shipment is closed (and if the quantity shipped by all shipments is the same as in the order to update) # Autoclassify purchase order descWORKFLOW_ORDER_CLASSIFY_BILLED_SUPPLIER_PROPOSAL=Classify linked source vendor proposal as billed when vendor invoice is validated (and if the amount of the invoice is the same as the total amount of the linked proposal) descWORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER=Classify linked source purchase order as billed when vendor invoice is validated (and if the amount of the invoice is the same as the total amount of the linked order) diff --git a/htdocs/langs/fr_FR/workflow.lang b/htdocs/langs/fr_FR/workflow.lang index 2af480afa83..13fbbace793 100644 --- a/htdocs/langs/fr_FR/workflow.lang +++ b/htdocs/langs/fr_FR/workflow.lang @@ -13,6 +13,7 @@ descWORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL=Classer la/les proposition(s) commer descWORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER=Classer la/les commande(s) client(s) source(s) facturée(s) à la validation de la facture client (et si le montant de la facture est le même que le montant total des commandes liées) descWORKFLOW_INVOICE_CLASSIFY_BILLED_ORDER=Classer la/les commande(s) client(s) source(s) à Facturée quand une facture client est passée à Payé (et si le montant de la facture est identique à la somme des commandes sources) descWORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING=Classer la commande source à expédiée à la validation d'une expédition (et si les quantités expédiées dans le bon d'expédition sont les même que dans la commande mise à jour) +descWORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING_CLOSED=Classer la commande source à expédiée à la cloture d'une expédition (et si les quantités expédiées dans le bon d'expédition sont les même que dans la commande mise à jour) # Autoclassify purchase order descWORKFLOW_ORDER_CLASSIFY_BILLED_SUPPLIER_PROPOSAL=Classer la ou les proposition(s) commerciale(s) fournisseur sources facturées quand une facture fournisseur est validée (et si le montant de la facture est le même que le total des propositions sources liées) descWORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER=Classer la ou les commande(s) fournisseur(s) de source(s) à facturée(s) lorsque la facture fournisseur est validée (et si le montant de la facture est le même que le montant total des commandes liées) From 2caf002fa03b77e33010db751d72ee9f8937f46a Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Sat, 29 Aug 2020 13:15:55 +0200 Subject: [PATCH 02/14] CLOSE #18319 REST API - Shipment: Add 'close' action / endpoint / POST method. Allow "closing" a shipment through the REST API. --- .../expedition/class/api_shipments.class.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/htdocs/expedition/class/api_shipments.class.php b/htdocs/expedition/class/api_shipments.class.php index 2a4b6765b4e..3b4070b138b 100644 --- a/htdocs/expedition/class/api_shipments.class.php +++ b/htdocs/expedition/class/api_shipments.class.php @@ -626,6 +626,53 @@ class Shipments extends DolibarrApi } */ + /** + * Close a shipment (Classify it as "Delivered") + * + * @param int $id Expedition ID + * @param int $notrigger Disabled triggers + * + * @url POST {id}/close + * + * @return int + */ + public function close($id, $notrigger = 0) + { + if (!DolibarrApiAccess::$user->rights->expedition->creer) { + throw new RestException(401); + } + + $result = $this->shipment->fetch($id); + if (!$result) { + throw new RestException(404, 'Shipment not found'); + } + + if (!DolibarrApi::_checkAccessToResource('expedition', $this->commande->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->shipment->setClosed(); + if ($result == 0) { + throw new RestException(304, 'Error nothing done. May be object is already closed'); + } + if ($result < 0) { + throw new RestException(500, 'Error when closing Order: '.$this->commande->error); + } + + $result = $this->shipment->fetch($id); + if (!$result) { + throw new RestException(404, 'Shipment not found'); + } + + if (!DolibarrApi::_checkAccessToResource('expedition', $this->commande->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $this->shipment->fetchObjectLinked(); + + return $this->_cleanObjectDatas($this->shipment); + } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** * Clean sensible object datas From c06fef0d45383aa777decded2f4b1f6ca91cba54 Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Tue, 10 Aug 2021 14:48:23 +0400 Subject: [PATCH 03/14] Merge branch stock_decrease_on_credit_invoice --- htdocs/admin/stock.php | 20 ++++++++++++++++++ htdocs/commande/list.php | 2 +- htdocs/compta/facture/card.php | 15 ++++++++----- htdocs/compta/facture/class/facture.class.php | 21 ++++++++++++++++--- htdocs/core/actions_massactions.inc.php | 7 ++++++- htdocs/core/class/conf.class.php | 2 ++ htdocs/langs/en_US/stocks.lang | 1 + htdocs/langs/fr_FR/stocks.lang | 1 + htdocs/product/class/product.class.php | 18 ++++++++++++---- htdocs/product/stock/product.php | 1 + htdocs/reception/list.php | 2 +- 11 files changed, 75 insertions(+), 15 deletions(-) diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index a4a9e91e3ff..75b665e0fda 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -222,6 +222,26 @@ if (!empty($conf->facture->enabled)) { print "\n\n"; $found++; +print ''; +print ''.$langs->trans("DeStockOnCreditBill").''; +print ''; +if (!empty($conf->facture->enabled)) +{ + if ($conf->use_javascript_ajax) { + print ajax_constantonoff('STOCK_CALCULATE_ON_CREDIT_BILL'); + } else { + $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); + print $form->selectarray("STOCK_CALCULATE_ON_CREDIT_BILL", $arrval, $conf->global->STOCK_CALCULATE_ON_CREDIT_BILL); + } +} +else +{ + print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module30Name")); +} +print "\n\n"; +$found++; + + print ''; print ''.$langs->trans("DeStockOnValidateOrder").''; diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 73413d1070f..e5ddc324d0f 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -912,7 +912,7 @@ if ($resql) { print $langs->trans('ValidateInvoices'); print ''; print ''; - if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) { + if (!empty($conf->stock->enabled) && (!empty($conf->global->STOCK_CALCULATE_ON_BILL) || !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL) ) ) { print $form->selectyesno('validate_invoices', 0, 1, 1); print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')'; } else { diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 5c21f2b9539..9240d9c6cf8 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -627,7 +627,7 @@ if (empty($reshook)) { } // Check for warehouse - if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) { + if ( ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) || ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) ) { $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); @@ -687,7 +687,7 @@ if (empty($reshook)) { $object->fetch_thirdparty(); // Check parameters - if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) { + if ( ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) || ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) ) { $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); @@ -3894,7 +3894,12 @@ if ($action == 'create') { $text = $langs->trans('ConfirmDeleteBill', $object->ref); $formquestion = array(); - if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->statut >= 1) { + if ($object->statut >= 1 && + ( + ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) || + ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) + ) + ) { $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); @@ -3967,7 +3972,7 @@ if ($action == 'create') { } $formquestion = array(); - if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) { + if ( ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) || ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) ) { $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); @@ -4009,7 +4014,7 @@ if ($action == 'create') { $text = $langs->trans('ConfirmUnvalidateBill', $object->ref); $formquestion = array(); - if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) { + if (($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) || ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) ) { $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 9cbfb33e5bd..7a329046214 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2273,7 +2273,12 @@ class Facture extends CommonInvoice } // If we decrease stock on invoice validation, we increase back if a warehouse id was provided - if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $idwarehouse != -1) { + if ( $result >= 0 && !empty($conf->stock->enabled) && $idwarehouse != -1 && + ( + ($this->type != self::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) || + ($this->type == self::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) + ) + ) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); @@ -2712,7 +2717,12 @@ class Facture extends CommonInvoice $result = $this->thirdparty->set_as_client(); // Si active on decremente le produit principal et ses composants a la validation de facture - if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $idwarehouse > 0) { + if ( $result >= 0 && !empty($conf->stock->enabled) && $idwarehouse > 0 && + ( + ($this->type != self::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) || + ($this->type == self::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) + ) + ) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); @@ -3005,7 +3015,12 @@ class Facture extends CommonInvoice } // If we decrease stock on invoice validation, we increase back - if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) { + if ( $result >= 0 && !empty($conf->stock->enabled) && + ( + ($this->type != self::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) || + ($this->type == self::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) + ) + ) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index cf412223838..07894d84a1c 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1199,7 +1199,12 @@ if ($action == 'remove_file') { if (!$error && $massaction == 'validate' && $permissiontoadd) { $objecttmp = new $objectclass($db); - if (($objecttmp->element == 'facture' || $objecttmp->element == 'invoice') && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) { + if ( !empty($conf->stock->enabled) && ($objecttmp->element == 'facture' || $objecttmp->element == 'invoice') && + ( + !empty($conf->global->STOCK_CALCULATE_ON_BILL) || + !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL) + ) + ) { $langs->load("errors"); setEventMessages($langs->trans('ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null, 'errors'); $error++; diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 60ee78bbff5..20d52ce043e 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -531,6 +531,8 @@ class Conf if (!empty($this->productbatch->enabled)) { $this->global->STOCK_CALCULATE_ON_BILL = 0; + $this->global->STOCK_CALCULATE_ON_INVOICE_BILL = 0; + $this->global->STOCK_CALCULATE_ON_CREDIT_BILL = 0; $this->global->STOCK_CALCULATE_ON_VALIDATE_ORDER = 0; $this->global->STOCK_CALCULATE_ON_SHIPMENT = 1; $this->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE = 0; diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index efa5257498c..e78917d51e6 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -75,6 +75,7 @@ OrderDispatch=Item receipts RuleForStockManagementDecrease=Choose Rule for automatic stock decrease (manual decrease is always possible, even if an automatic decrease rule is activated) RuleForStockManagementIncrease=Choose Rule for automatic stock increase (manual increase is always possible, even if an automatic increase rule is activated) DeStockOnBill=Decrease real stocks on validation of customer invoice/credit note +DeStockOnCreditBill=Decrease (increase) real stocks on validation of customer credit (only) note DeStockOnValidateOrder=Decrease real stocks on validation of sales order DeStockOnShipment=Decrease real stocks on shipping validation DeStockOnShipmentOnClosing=Decrease real stocks when shipping is set to closed diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index f0fe7235a77..68003ebe864 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -75,6 +75,7 @@ OrderDispatch=Réceptions RuleForStockManagementDecrease=Règle de gestion des décrémentations automatiques de stock (la décrémentation manuelle est toujours possible, même si une décrémentation automatique est activée) RuleForStockManagementIncrease=Règle de gestion des incrémentations de stock (l'incrémentation manuelle est toujours possible, même si une incrémentation automatique est activée) DeStockOnBill=Décrémenter les stocks physiques sur validation des factures/avoirs clients +DeStockOnCreditBill=Décrémenter (incrémenter) les stocks physiques sur validation des avoirs (uniquement) clients DeStockOnValidateOrder=Décrémenterr les stocks physiques sur validation des commandes clients DeStockOnShipment=Décrémenter les stocks physiques sur validation des expéditions DeStockOnShipmentOnClosing=Décrémente les stocks physiques au classement "clôturée" de l'expédition diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 28bf0288c7b..9fba3448c1c 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2949,14 +2949,19 @@ class Product extends CommonObject // If stock decrease is on invoice validation, the theorical stock continue to // count the orders to ship in theorical stock when some are already removed b invoice validation. // If option DECREASE_ONLY_UNINVOICEDPRODUCTS is on, we make a compensation. - if (!empty($conf->global->STOCK_CALCULATE_ON_BILL)) { + if (!empty($conf->global->STOCK_CALCULATE_ON_BILL) || !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL) ) { if (!empty($conf->global->DECREASE_ONLY_UNINVOICEDPRODUCTS)) { $adeduire = 0; $sql = "SELECT sum(fd.qty) as count FROM ".MAIN_DB_PREFIX."facturedet fd "; $sql .= " JOIN ".MAIN_DB_PREFIX."facture f ON fd.fk_facture = f.rowid "; $sql .= " JOIN ".MAIN_DB_PREFIX."element_element el ON el.fk_target = f.rowid and el.targettype = 'facture' and sourcetype = 'commande'"; $sql .= " JOIN ".MAIN_DB_PREFIX."commande c ON el.fk_source = c.rowid "; - $sql .= " WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).") AND c.facture = 0 AND fd.fk_product = ".((int) $this->id); + + if(!empty($conf->global->STOCK_CALCULATE_ON_BILL)){ + $sql .= " WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).") AND c.facture = 0 AND fd.fk_product = ".((int) $this->id); + }else if(!empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)){ + $sql .= " WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).") AND c.facture = 0 AND fd.fk_product = ".((int) $this->id)." AND f.type = ".Facture::TYPE_CREDIT_NOTE; + } dol_syslog(__METHOD__.":: sql $sql", LOG_NOTICE); $resql = $this->db->query($sql); @@ -5306,11 +5311,16 @@ class Product extends CommonObject // Stock decrease mode if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) { $this->stock_theorique -= ($stock_commande_client - $stock_sending_client); - } elseif (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER)) { + if(!empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) { // this is not exclusive with STOCK_CALCULATE_ON_SHIPMENT(_CLOSE) + $this->stock_theorique -= $stock_commande_client; + } + + }elseif (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER)) { $this->stock_theorique += 0; - } elseif (!empty($conf->global->STOCK_CALCULATE_ON_BILL)) { + }elseif (!empty($conf->global->STOCK_CALCULATE_ON_BILL) || !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) { $this->stock_theorique -= $stock_commande_client; } + // Stock Increase mode if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) { $this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur); diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 0e4cf4b6a20..6134f402371 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -724,6 +724,7 @@ if ($id > 0 || $ref) { $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE) ? '- '.$langs->trans("DeStockOnShipment").'
' : ''); $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) ? '- '.$langs->trans("DeStockOnValidateOrder").'
' : ''); $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_BILL) ? '- '.$langs->trans("DeStockOnBill").'
' : ''); + $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL) ? '- '.$langs->trans("DeStockOnCreditBill").'
' : ''); $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) ? '- '.$langs->trans("ReStockOnBill").'
' : ''); $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) ? '- '.$langs->trans("ReStockOnValidateOrder").'
' : ''); $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) ? '- '.$langs->trans("ReStockOnDispatchOrder").'
' : ''); diff --git a/htdocs/reception/list.php b/htdocs/reception/list.php index a6ecd37cc6d..970e27933ed 100644 --- a/htdocs/reception/list.php +++ b/htdocs/reception/list.php @@ -644,7 +644,7 @@ if ($massaction == 'createbills') { print $langs->trans('ValidateInvoices'); print ''; print ''; - if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) { + if (!empty($conf->stock->enabled) && (!empty($conf->global->STOCK_CALCULATE_ON_BILL) || !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) ) { print $form->selectyesno('validate_invoices', 0, 1, 1); print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')'; } else { From 1770f79a6c8a90cd45fea7806dc55ef40e49c9a4 Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Thu, 12 Aug 2021 17:05:00 +0400 Subject: [PATCH 04/14] CLOSE #18401 Add __NEWREF__ subtitute to get new object reference. Allow the use of __NEWREF__ to get for example the new reference a draft order will get after validation. --- htdocs/core/lib/functions.lib.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 6e259e3c7fb..371a6381462 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6852,6 +6852,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, if ($onlykey) { $substitutionarray['__ID__'] = '__ID__'; $substitutionarray['__REF__'] = '__REF__'; + $substitutionarray['__NEWREF__'] = '__NEWREF__'; $substitutionarray['__REF_CLIENT__'] = '__REF_CLIENT__'; $substitutionarray['__REF_SUPPLIER__'] = '__REF_SUPPLIER__'; $substitutionarray['__NOTE_PUBLIC__'] = '__NOTE_PUBLIC__'; @@ -6932,6 +6933,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, } else { $substitutionarray['__ID__'] = $object->id; $substitutionarray['__REF__'] = $object->ref; + $substitutionarray['__NEWREF__'] = $object->newref; $substitutionarray['__REF_CLIENT__'] = (isset($object->ref_client) ? $object->ref_client : (isset($object->ref_customer) ? $object->ref_customer : null)); $substitutionarray['__REF_SUPPLIER__'] = (isset($object->ref_supplier) ? $object->ref_supplier : null); $substitutionarray['__NOTE_PUBLIC__'] = (isset($object->note_public) ? $object->note_public : null); From 099dd44ffa03fda1285e33b4200f3bb605d8852b Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Thu, 12 Aug 2021 17:13:35 +0400 Subject: [PATCH 05/14] CLOSE #18403 Add __URL_SHIPMENT__ substitute to get the URL of a shipment --- htdocs/core/lib/functions.lib.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 371a6381462..29140c4abbe 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7177,6 +7177,10 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, if (is_object($object) && $object->element == 'supplier_proposal') { $substitutionarray['__URL_SUPPLIER_PROPOSAL__'] = DOL_MAIN_URL_ROOT."/supplier_proposal/card.php?id=".$object->id; } + if (is_object($object) && $object->element == 'shipping') { + $substitutionarray['__URL_SHIPMENT__'] = DOL_MAIN_URL_ROOT."/expedition/card.php?id=".$object->id; + } + } if (is_object($object) && $object->element == 'action') { From eecbfc0ad4b3e91eaf765a2647ba8b70fdc044bb Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Sun, 29 Aug 2021 23:13:41 +0400 Subject: [PATCH 06/14] FIX #18542 REST API: set global $user variable to DolibarrApiAccess::user. --- htdocs/api/class/api_access.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/api/class/api_access.class.php b/htdocs/api/class/api_access.class.php index 99582b62047..eaaa29d7aa1 100644 --- a/htdocs/api/class/api_access.class.php +++ b/htdocs/api/class/api_access.class.php @@ -80,7 +80,7 @@ class DolibarrApiAccess implements iAuthenticate public function __isAllowed() { // phpcs:enable - global $conf, $db; + global $conf, $db, $user; $login = ''; $stored_key = ''; @@ -149,6 +149,7 @@ class DolibarrApiAccess implements iAuthenticate } $fuser->getrights(); static::$user = $fuser; + $user = $fuser; if ($fuser->socid) { static::$role = 'external'; From 0fce409155b1a69185be49be65d1fc0dea7f87f0 Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Mon, 30 Aug 2021 00:08:43 +0400 Subject: [PATCH 07/14] FIX #18544 Shipment REST API: load thirdparty object into the shipment before validating. --- htdocs/commande/class/api_orders.class.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 745fea5ab76..f5e9aea75bd 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -716,7 +716,9 @@ class Orders extends DolibarrApi if (!$result) { throw new RestException(404, 'Order not found'); } - + + $result = $this->commande->fetch_thirdparty(); // do not check result, as failure is not fatal (used only for mail notification substitutes) + if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -729,13 +731,6 @@ class Orders extends DolibarrApi throw new RestException(500, 'Error when validating Order: '.$this->commande->error); } $result = $this->commande->fetch($id); - if (!$result) { - throw new RestException(404, 'Order not found'); - } - - if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } $this->commande->fetchObjectLinked(); From 88c8dbc2c4d496e3cd02c8bc02fb452cdc559c64 Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Wed, 1 Sep 2021 16:37:40 +0400 Subject: [PATCH 08/14] [TEMPORARY] Document REST API: Disable ECM file listing for the moment. --- htdocs/api/class/api_documents.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 00fd1a91a8a..9f3b2bcad45 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -473,7 +473,7 @@ class Documents extends DolibarrApi if ($result < 0) { throw new RestException(503, 'Error when retrieve ecm list : ' . $this->db->lasterror()); } elseif (is_array($ecmfile->lines) && count($ecmfile->lines) > 0) { - $filearray['ecmfiles_infos'] = $ecmfile->lines; + //$filearray['ecmfiles_infos'] = $ecmfile->lines; } } } From 08ef5035484fbc6b2f91c8b6f792c69ff581c41b Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Sun, 5 Sep 2021 15:03:21 +0400 Subject: [PATCH 09/14] Increase max memory to 512MB. --- htdocs/main.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index e4677499bd6..19e97286e49 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -36,7 +36,7 @@ * \brief File that defines environment for Dolibarr GUI pages only (file not required by scripts) */ -//@ini_set('memory_limit', '128M'); // This may be useless if memory is hard limited by your PHP +@ini_set('memory_limit', '512M'); // This may be useless if memory is hard limited by your PHP // For optional tuning. Enabled if environment variable MAIN_SHOW_TUNING_INFO is defined. $micro_start_time = 0; From 0fa10c2de7ce6d5fe91d4d01a595721c85694d12 Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Mon, 6 Sep 2021 12:07:48 +0400 Subject: [PATCH 10/14] Oine external user login quick fix. --- htdocs/user/class/api_users.class.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index e0cbd849092..914bdcae386 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -151,7 +151,8 @@ class Users extends DolibarrApi */ public function get($id, $includepermissions = 0) { - if (empty(DolibarrApiAccess::$user->rights->user->user->lire) && empty(DolibarrApiAccess::$user->admin)) { + if (empty(DolibarrApiAccess::$user->rights->user->user->lire) && empty(DolibarrApiAccess::$user->admin) && + !(!empty(DolibarrApiAccess::$user->rights->user->self->creer) && (DolibarrApiAccess::$user->id == $id))) { throw new RestException(401, 'Not allowed'); } @@ -172,6 +173,7 @@ class Users extends DolibarrApi $this->useraccount->getRights(); } + $this->useraccount->societe_id = $this->useraccount->socid; return $this->_cleanObjectDatas($this->useraccount); } @@ -256,7 +258,7 @@ class Users extends DolibarrApi */ public function getInfo($includepermissions = 0) { - if (empty(DolibarrApiAccess::$user->rights->user->user->lire) && empty(DolibarrApiAccess::$user->admin)) { + if(empty(DolibarrApiAccess::$user->rights->user->self->creer) && empty(DolibarrApiAccess::$user->rights->user->user->lire) && empty(DolibarrApiAccess::$user->admin)) { throw new RestException(401, 'Not allowed'); } @@ -283,6 +285,8 @@ class Users extends DolibarrApi $this->useraccount->user_group_list = $this->_cleanUserGroupListDatas($userGroupList); + $this->useraccount->societe_id = $this->useraccount->socid; + //var_dump($this->useraccount); die(); return $this->_cleanObjectDatas($this->useraccount); } From 977d4d0d416e02350599fef4600062b75be87c72 Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Mon, 6 Sep 2021 16:16:37 +0400 Subject: [PATCH 11/14] Oine invoice in future quick fix. --- htdocs/compta/facture/card.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 9240d9c6cf8..eaa72c60fe8 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -993,7 +993,7 @@ if (empty($reshook)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $action = 'create'; - } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { + } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY * 86400))) { //86400 = seconds in a day $error++; setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); $action = 'create'; @@ -1054,7 +1054,7 @@ if (empty($reshook)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $action = 'create'; - } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { + } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY * 86400))) { //86400 = seconds in a day $error++; setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); $action = 'create'; @@ -1270,7 +1270,7 @@ if (empty($reshook)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $action = 'create'; - } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { + } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY * 86400))) { //86400 = seconds in a day $error++; setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); $action = 'create'; @@ -1321,11 +1321,17 @@ if (empty($reshook)) { $action = 'create'; } + var_dump($dateinvoice); //die(); + $futur = dol_get_last_hour(dol_now()) + 2*24*3600; + + var_dump($futur); + var_dump($dateinvoice - $futur); //die(); + if (empty($dateinvoice)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $action = 'create'; - } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { + } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY * 86400))) { //86400 = seconds in a day $error++; setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); $action = 'create'; @@ -1812,7 +1818,7 @@ if (empty($reshook)) { $error++; $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")); setEventMessages($mesg, null, 'errors'); - } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { + } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY * 86400))) { //86400 = seconds in a day $error++; setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); $action = 'create'; From 236a52170341fc58d6face42806d66115ec921f8 Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Mon, 6 Sep 2021 17:14:10 +0400 Subject: [PATCH 12/14] Revert "Oine invoice in future quick fix." This reverts commit 977d4d0d416e02350599fef4600062b75be87c72. --- htdocs/compta/facture/card.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index eaa72c60fe8..9240d9c6cf8 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -993,7 +993,7 @@ if (empty($reshook)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $action = 'create'; - } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY * 86400))) { //86400 = seconds in a day + } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { $error++; setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); $action = 'create'; @@ -1054,7 +1054,7 @@ if (empty($reshook)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $action = 'create'; - } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY * 86400))) { //86400 = seconds in a day + } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { $error++; setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); $action = 'create'; @@ -1270,7 +1270,7 @@ if (empty($reshook)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $action = 'create'; - } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY * 86400))) { //86400 = seconds in a day + } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { $error++; setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); $action = 'create'; @@ -1321,17 +1321,11 @@ if (empty($reshook)) { $action = 'create'; } - var_dump($dateinvoice); //die(); - $futur = dol_get_last_hour(dol_now()) + 2*24*3600; - - var_dump($futur); - var_dump($dateinvoice - $futur); //die(); - if (empty($dateinvoice)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $action = 'create'; - } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY * 86400))) { //86400 = seconds in a day + } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { $error++; setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); $action = 'create'; @@ -1818,7 +1812,7 @@ if (empty($reshook)) { $error++; $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")); setEventMessages($mesg, null, 'errors'); - } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY * 86400))) { //86400 = seconds in a day + } elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { $error++; setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); $action = 'create'; From ffdcd88007e5759c90c7c99832022bf54839dd64 Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Thu, 9 Sep 2021 19:56:28 +0400 Subject: [PATCH 13/14] FIX #18666 Order / Shipment list: Don't SQL JOIN category table when not necessary. --- htdocs/commande/list.php | 6 +++--- htdocs/expedition/list.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index e5ddc324d0f..6e85258b9ba 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -429,7 +429,7 @@ $sql .= ' p.rowid as project_id, p.ref as project_ref, p.title as project_label, $sql .= ' u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender,'; $sql .= ' c.fk_cond_reglement,c.fk_mode_reglement,c.fk_shipping_method,'; $sql .= ' c.fk_input_reason'; -if ($search_categ_cus) { +if (($search_categ_cus > 0) || ($search_categ_cus == -2)) { $sql .= ", cc.fk_categorie, cc.fk_soc"; } // Add fields from extrafields @@ -446,7 +446,7 @@ $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s'; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)"; -if (!empty($search_categ_cus)) { +if (($search_categ_cus > 0) || ($search_categ_cus == -2)) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ } $sql .= ', '.MAIN_DB_PREFIX.'commande as c'; @@ -793,7 +793,7 @@ if ($resql) { if ($search_product_category != '') { $param .= '&search_product_category='.urlencode($search_product_category); } - if ($search_categ_cus > 0) { + if (($search_categ_cus > 0) || ($search_categ_cus == -2)) { $param .= '&search_categ_cus='.urlencode($search_categ_cus); } if ($show_files) { diff --git a/htdocs/expedition/list.php b/htdocs/expedition/list.php index 5a110d33f2a..d119fc7b7d6 100644 --- a/htdocs/expedition/list.php +++ b/htdocs/expedition/list.php @@ -235,7 +235,7 @@ $sql .= " typent.code as typent_code,"; $sql .= " state.code_departement as state_code, state.nom as state_name,"; $sql .= " e.date_creation as date_creation, e.tms as date_update,"; $sql .= " u.login"; -if ($search_categ_cus) { +if (($search_categ_cus > 0) || ($search_categ_cus == -2)) { $sql .= ", cc.fk_categorie, cc.fk_soc"; } // Add fields from extrafields @@ -260,7 +260,7 @@ if ($search_product_category > 0) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; } $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; -if (!empty($search_categ_cus)) { +if (($search_categ_cus > 0) || ($search_categ_cus == -2)) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ } $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)"; @@ -449,7 +449,7 @@ if ($search_datereceipt_end) { if ($search_product_category != '') { $param .= '&search_product_category='.urlencode($search_product_category); } -if ($search_categ_cus > 0) { +if (($search_categ_cus > 0) || ($search_categ_cus == -2)) { $param .= '&search_categ_cus='.urlencode($search_categ_cus); } if ($search_status != '') { From af75d519e283287ccee5e1617e24c7f9f92eeff3 Mon Sep 17 00:00:00 2001 From: lainwir3d Date: Sun, 12 Sep 2021 15:47:56 +0400 Subject: [PATCH 14/14] CLOSE #18689 REST API module: add api key generate / modify right. --- htdocs/core/ajax/security.php | 2 +- htdocs/core/modules/modApi.class.php | 14 ++++++++------ htdocs/user/card.php | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/htdocs/core/ajax/security.php b/htdocs/core/ajax/security.php index 066e5b7812d..0056120c6bd 100644 --- a/htdocs/core/ajax/security.php +++ b/htdocs/core/ajax/security.php @@ -53,7 +53,7 @@ top_httphead(); // Registering the location of boxes if (isset($_GET['action']) && !empty($_GET['action'])) { - if ($_GET['action'] == 'getrandompassword' && $user->admin) { + if ($_GET['action'] == 'getrandompassword' && ($user->admin || $user->rights->api->apikey->generate)) { require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; $generic = $_GET['generic'] ? true : false; echo getRandomPassword($generic); diff --git a/htdocs/core/modules/modApi.class.php b/htdocs/core/modules/modApi.class.php index bf7fc2777ae..96fb2b955ff 100644 --- a/htdocs/core/modules/modApi.class.php +++ b/htdocs/core/modules/modApi.class.php @@ -134,16 +134,18 @@ class modApi extends DolibarrModules // Permissions $this->rights = array(); // Permission array used by this module + $this->rights_admin_allowed = 1; // Admin is always granted of permission (even when module is disabled) + $r = 0; // Add here list of permission defined by an id, a label, a boolean and two constant strings. // Example: - // $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) - // $this->rights[$r][1] = 'Permision label'; // Permission label - // $this->rights[$r][3] = 0; // Permission by default for new user (0/1) - // $this->rights[$r][4] = 'level1'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - // $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - // $r++; + $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) + $this->rights[$r][1] = 'Générer / modifier la clé API des utilisateurs'; // Permission label + $this->rights[$r][3] = 0; // Permission by default for new user (0/1) + $this->rights[$r][4] = 'apikey'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + $this->rights[$r][5] = 'generate'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + $r++; // Main menu entries diff --git a/htdocs/user/card.php b/htdocs/user/card.php index cb7aa69949c..fb6cbc539e3 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -1786,7 +1786,7 @@ if ($action == 'create' || $action == 'adduserldap') { print ''."\n"; // API key - if (!empty($conf->api->enabled) && ($user->id == $id || $user->admin)) { + if (!empty($conf->api->enabled) && ($user->id == $id || $user->admin || $user->rights->api->apikey->generate)) { print ''.$langs->trans("ApiKey").''; print ''; if (!empty($object->api_key)) { @@ -2309,7 +2309,7 @@ if ($action == 'create' || $action == 'adduserldap') { print "\n"; // API key - if (!empty($conf->api->enabled) && ($user->id == $id || $user->admin)) { + if (!empty($conf->api->enabled) && ($user->id == $id || $user->admin || $user->rights->api->apikey->generate)) { print ''.$langs->trans("ApiKey").''; print ''; print '';