From 19f68b0b6764ea77fa2cc393db84cc6c452a4df9 Mon Sep 17 00:00:00 2001 From: Vincent Maury Date: Sat, 8 Jun 2024 02:48:59 +0200 Subject: [PATCH] Add clean conditions to show "create purchase order" button in sale order card (#29906) * Add clean conditions to show "create purchase order" button in sale order card * Add clean conditions to show "create purchase order" button in sale order card * Add clean conditions to show "create purchase order" button in sale order card --- htdocs/commande/card.php | 7 ++++--- htdocs/core/class/commonorder.class.php | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 2975115fb92..77ba69204bf 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2949,11 +2949,12 @@ if ($action == 'create' && $usercancreate) { } $arrayforbutaction = array(); - // Create a purchase order - $arrayforbutaction[] = array('lang'=>'orders', 'enabled'=>(isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT && $object->getNbOfServicesLines() > 0), 'perm'=>$usercancreatepurchaseorder, 'label'=>'AddPurchaseOrder', 'url'=>'/fourn/commande/card.php?action=create&origin='.$object->element.'&originid='.$object->id); + if (getDolGlobalInt('COMMANDE_DISABLE_ADD_PURCHASE_ORDER') == 0) { + $arrayforbutaction[] = array('lang'=>'orders', 'enabled'=>(isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT && $object->getNbLinesProductOrServiceOnBuy(getDolGlobalInt('COMMANDE_ADD_PURCHASE_ORDER_IGNORE_FREE_PRODUCTS')) > 0), 'perm'=>$usercancreatepurchaseorder, 'label'=>'AddPurchaseOrder', 'url'=>'/fourn/commande/card.php?action=create&origin='.$object->element.'&originid='.$object->id); + } /*if (isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT && $object->getNbOfServicesLines() > 0) { - if ($usercancreatepurchaseorder) { + if ($usercancreatepurchaseorder) { isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT && $object->getNbOfServicesLines() > 0 print dolGetButtonAction('', $langs->trans('AddPurchaseOrder'), 'default', DOL_URL_ROOT.'/fourn/commande/card.php?action=create&origin='.$object->element.'&originid='.$object->id, ''); } }*/ diff --git a/htdocs/core/class/commonorder.class.php b/htdocs/core/class/commonorder.class.php index dc5de2b9863..b436cc21203 100644 --- a/htdocs/core/class/commonorder.class.php +++ b/htdocs/core/class/commonorder.class.php @@ -71,6 +71,28 @@ abstract class CommonOrder extends CommonObject return $return; } + /** return nb of fines of order where products or services that can be buyed + * + * @param boolean $ignoreFree Ignore free lines + * @return int number of products or services on buy in a command + */ + public function getNbLinesProductOrServiceOnBuy($ignoreFree = false) + { + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + $product = new Product($this->db); + $return = 0; + foreach ($this->lines as $line) { + if (empty($line->fk_product) && !$ignoreFree) { + $return ++; + } elseif ((int) $line->fk_product > 0) { + if ($product->fetch($line->fk_product) > 0) { + if ($product->status_buy) $return ++; + } + } + } + return $return; + } + /** * @var string code */