From e9ee78ab8fe7dd0fa9fc4e049be4ddb33856c777 Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Wed, 25 Mar 2020 11:19:35 +0100 Subject: [PATCH 1/2] NEW hook on product load stats --- htdocs/product/class/product.class.php | 81 +++++++++++++++++++++----- 1 file changed, 66 insertions(+), 15 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 96b2165c65a..adb23d38f75 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2445,8 +2445,7 @@ class Product extends CommonObject public function load_stats_propale($socid = 0) { // phpcs:enable - global $conf; - global $user; + global $conf, $user, $hookmanager; $sql = "SELECT COUNT(DISTINCT p.fk_soc) as nb_customers, COUNT(DISTINCT p.rowid) as nb,"; $sql .= " COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty"; @@ -2497,6 +2496,11 @@ class Product extends CommonObject } } + $hookmanager->initHooks(array('productdao')); + $parameters = array('socid' => $socid); + $reshook = $hookmanager->executeHooks('loadStatsPropale', $parameters, $this, $action); + if ($reshook > 0) $this->stats_propale = $hookmanager->resArray['stats_propale']; + return 1; } else @@ -2517,8 +2521,7 @@ class Product extends CommonObject public function load_stats_proposal_supplier($socid = 0) { // phpcs:enable - global $conf; - global $user; + global $conf, $user, $hookmanager; $sql = "SELECT COUNT(DISTINCT p.fk_soc) as nb_suppliers, COUNT(DISTINCT p.rowid) as nb,"; $sql .= " COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty"; @@ -2544,6 +2547,12 @@ class Product extends CommonObject $this->stats_proposal_supplier['nb'] = $obj->nb; $this->stats_proposal_supplier['rows'] = $obj->nb_rows; $this->stats_proposal_supplier['qty'] = $obj->qty ? $obj->qty : 0; + + $hookmanager->initHooks(array('productdao')); + $parameters = array('socid' => $socid); + $reshook = $hookmanager->executeHooks('loadStatsProposalSupplier', $parameters, $this, $action); + if ($reshook > 0) $this->stats_proposal_supplier = $hookmanager->resArray['stats_proposal_supplier']; + return 1; } else @@ -2566,7 +2575,7 @@ class Product extends CommonObject public function load_stats_commande($socid = 0, $filtrestatut = '', $forVirtualStock = 0) { // phpcs:enable - global $conf, $user; + global $conf, $user, $hookmanager; $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty"; @@ -2643,7 +2652,10 @@ class Product extends CommonObject $this->stats_commande['qty'] -= $adeduire; } } - + $hookmanager->initHooks(array('productdao')); + $parameters = array('socid' => $socid, 'filtrestatut' => $filtrestatut, 'forVirtualStock' => $forVirtualStock); + $reshook = $hookmanager->executeHooks('loadStatsCommande', $parameters, $this, $action); + if ($reshook > 0) $this->stats_commande = $hookmanager->resArray['stats_commande']; return 1; } else @@ -2665,7 +2677,7 @@ class Product extends CommonObject public function load_stats_commande_fournisseur($socid = 0, $filtrestatut = '', $forVirtualStock = 0) { // phpcs:enable - global $conf, $user; + global $conf, $user, $hookmanager; $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_suppliers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty"; @@ -2696,6 +2708,12 @@ class Product extends CommonObject $this->stats_commande_fournisseur['nb'] = $obj->nb; $this->stats_commande_fournisseur['rows'] = $obj->nb_rows; $this->stats_commande_fournisseur['qty'] = $obj->qty ? $obj->qty : 0; + + $hookmanager->initHooks(array('productdao')); + $parameters = array('socid' => $socid, 'filtrestatut' => $filtrestatut, 'forVirtualStock' => $forVirtualStock); + $reshook = $hookmanager->executeHooks('loadStatsCommandeFournisseur', $parameters, $this, $action); + if ($reshook > 0) $this->stats_commande_fournisseur = $hookmanager->resArray['stats_commande_fournisseur']; + return 1; } else @@ -2718,7 +2736,7 @@ class Product extends CommonObject public function load_stats_sending($socid = 0, $filtrestatut = '', $forVirtualStock = 0, $filterShipmentStatus = '') { // phpcs:enable - global $conf, $user; + global $conf, $user, $hookmanager; $sql = "SELECT COUNT(DISTINCT e.fk_soc) as nb_customers, COUNT(DISTINCT e.rowid) as nb,"; $sql .= " COUNT(ed.rowid) as nb_rows, SUM(ed.qty) as qty"; @@ -2775,6 +2793,12 @@ class Product extends CommonObject } } } + + $hookmanager->initHooks(array('productdao')); + $parameters = array('socid' => $socid, 'filtrestatut' => $filtrestatut, 'forVirtualStock' => $forVirtualStock, 'filterShipmentStatus' => $filterShipmentStatus); + $reshook = $hookmanager->executeHooks('loadStatsSending', $parameters, $this, $action); + if ($reshook > 0) $this->stats_expedition = $hookmanager->resArray['stats_expedition']; + return 1; } else @@ -2796,7 +2820,7 @@ class Product extends CommonObject public function load_stats_reception($socid = 0, $filtrestatut = '', $forVirtualStock = 0) { // phpcs:enable - global $conf, $user; + global $conf, $user, $hookmanager; $sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_suppliers, COUNT(DISTINCT cf.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty"; @@ -2823,6 +2847,12 @@ class Product extends CommonObject $this->stats_reception['nb'] = $obj->nb; $this->stats_reception['rows'] = $obj->nb_rows; $this->stats_reception['qty'] = $obj->qty ? $obj->qty : 0; + + $hookmanager->initHooks(array('productdao')); + $parameters = array('socid' => $socid, 'filtrestatut' => $filtrestatut, 'forVirtualStock' => $forVirtualStock); + $reshook = $hookmanager->executeHooks('loadStatsReception', $parameters, $this, $action); + if ($reshook > 0) $this->stats_reception = $hookmanager->resArray['stats_reception']; + return 1; } else @@ -2844,7 +2874,7 @@ class Product extends CommonObject public function load_stats_inproduction($socid = 0, $filtrestatut = '', $forVirtualStock = 0) { // phpcs:enable - global $conf, $user; + global $conf, $user, $hookmanager; $sql = "SELECT COUNT(DISTINCT m.fk_soc) as nb_customers, COUNT(DISTINCT m.rowid) as nb,"; $sql .= " COUNT(mp.rowid) as nb_rows, SUM(mp.qty) as qty, role"; @@ -2910,6 +2940,11 @@ class Product extends CommonObject if ($this->stats_mrptoconsume['qty'] < 0) $this->stats_mrptoconsume['qty'] = 0; if ($this->stats_mrptoproduce['qty'] < 0) $this->stats_mrptoproduce['qty'] = 0; + $hookmanager->initHooks(array('productdao')); + $parameters = array('socid' => $socid, 'filtrestatut' => $filtrestatut, 'forVirtualStock' => $forVirtualStock); + $reshook = $hookmanager->executeHooks('loadStatsInProduction', $parameters, $this, $action); + if ($reshook > 0) $this->stats_mrptoproduce = $hookmanager->resArray['stats_mrptoproduce']; + return 1; } else @@ -2929,8 +2964,7 @@ class Product extends CommonObject public function load_stats_contrat($socid = 0) { // phpcs:enable - global $conf; - global $user; + global $conf, $user, $hookmanager; $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty"; @@ -2980,6 +3014,12 @@ class Product extends CommonObject } } } + + $hookmanager->initHooks(array('productdao')); + $parameters = array('socid' => $socid); + $reshook = $hookmanager->executeHooks('loadStatsContrat', $parameters, $this, $action); + if ($reshook > 0) $this->stats_contrat = $hookmanager->resArray['stats_contrat']; + return 1; } else @@ -2999,7 +3039,7 @@ class Product extends CommonObject public function load_stats_facture($socid = 0) { // phpcs:enable - global $db, $conf, $user; + global $db, $conf, $user, $hookmanager; $sql = "SELECT COUNT(DISTINCT f.fk_soc) as nb_customers, COUNT(DISTINCT f.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(".$db->ifsql('f.type != 2', 'fd.qty', 'fd.qty * -1').") as qty"; @@ -3049,6 +3089,12 @@ class Product extends CommonObject } } } + + $hookmanager->initHooks(array('productdao')); + $parameters = array('socid' => $socid); + $reshook = $hookmanager->executeHooks('loadStatsFacture', $parameters, $this, $action); + if ($reshook > 0) $this->stats_facture = $hookmanager->resArray['stats_facture']; + return 1; } else @@ -3068,8 +3114,7 @@ class Product extends CommonObject public function load_stats_facture_fournisseur($socid = 0) { // phpcs:enable - global $conf; - global $user; + global $conf, $user, $hookmanager; $sql = "SELECT COUNT(DISTINCT f.fk_soc) as nb_suppliers, COUNT(DISTINCT f.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty"; @@ -3098,6 +3143,12 @@ class Product extends CommonObject $this->stats_facture_fournisseur['nb'] = $obj->nb; $this->stats_facture_fournisseur['rows'] = $obj->nb_rows; $this->stats_facture_fournisseur['qty'] = $obj->qty ? $obj->qty : 0; + + $hookmanager->initHooks(array('productdao')); + $parameters = array('socid' => $socid); + $reshook = $hookmanager->executeHooks('loadStatsFactureFournisseur', $parameters, $this, $action); + if ($reshook > 0) $this->stats_facture_fournisseur = $hookmanager->resArray['stats_facture_fournisseur']; + return 1; } else From cef65a3c8f404e980a71ac417e7d4d2c02e16e82 Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Thu, 26 Mar 2020 09:20:14 +0100 Subject: [PATCH 2/2] FIX hook name and useless inithook --- htdocs/product/class/product.class.php | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index adb23d38f75..a4f60d48dcd 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2496,9 +2496,8 @@ class Product extends CommonObject } } - $hookmanager->initHooks(array('productdao')); $parameters = array('socid' => $socid); - $reshook = $hookmanager->executeHooks('loadStatsPropale', $parameters, $this, $action); + $reshook = $hookmanager->executeHooks('loadStatsCustomerProposal', $parameters, $this, $action); if ($reshook > 0) $this->stats_propale = $hookmanager->resArray['stats_propale']; return 1; @@ -2548,9 +2547,8 @@ class Product extends CommonObject $this->stats_proposal_supplier['rows'] = $obj->nb_rows; $this->stats_proposal_supplier['qty'] = $obj->qty ? $obj->qty : 0; - $hookmanager->initHooks(array('productdao')); $parameters = array('socid' => $socid); - $reshook = $hookmanager->executeHooks('loadStatsProposalSupplier', $parameters, $this, $action); + $reshook = $hookmanager->executeHooks('loadStatsSupplierProposal', $parameters, $this, $action); if ($reshook > 0) $this->stats_proposal_supplier = $hookmanager->resArray['stats_proposal_supplier']; return 1; @@ -2652,9 +2650,9 @@ class Product extends CommonObject $this->stats_commande['qty'] -= $adeduire; } } - $hookmanager->initHooks(array('productdao')); + $parameters = array('socid' => $socid, 'filtrestatut' => $filtrestatut, 'forVirtualStock' => $forVirtualStock); - $reshook = $hookmanager->executeHooks('loadStatsCommande', $parameters, $this, $action); + $reshook = $hookmanager->executeHooks('loadStatsCustomerOrder', $parameters, $this, $action); if ($reshook > 0) $this->stats_commande = $hookmanager->resArray['stats_commande']; return 1; } @@ -2709,9 +2707,8 @@ class Product extends CommonObject $this->stats_commande_fournisseur['rows'] = $obj->nb_rows; $this->stats_commande_fournisseur['qty'] = $obj->qty ? $obj->qty : 0; - $hookmanager->initHooks(array('productdao')); $parameters = array('socid' => $socid, 'filtrestatut' => $filtrestatut, 'forVirtualStock' => $forVirtualStock); - $reshook = $hookmanager->executeHooks('loadStatsCommandeFournisseur', $parameters, $this, $action); + $reshook = $hookmanager->executeHooks('loadStatsSupplierOrder', $parameters, $this, $action); if ($reshook > 0) $this->stats_commande_fournisseur = $hookmanager->resArray['stats_commande_fournisseur']; return 1; @@ -2794,7 +2791,6 @@ class Product extends CommonObject } } - $hookmanager->initHooks(array('productdao')); $parameters = array('socid' => $socid, 'filtrestatut' => $filtrestatut, 'forVirtualStock' => $forVirtualStock, 'filterShipmentStatus' => $filterShipmentStatus); $reshook = $hookmanager->executeHooks('loadStatsSending', $parameters, $this, $action); if ($reshook > 0) $this->stats_expedition = $hookmanager->resArray['stats_expedition']; @@ -2848,7 +2844,6 @@ class Product extends CommonObject $this->stats_reception['rows'] = $obj->nb_rows; $this->stats_reception['qty'] = $obj->qty ? $obj->qty : 0; - $hookmanager->initHooks(array('productdao')); $parameters = array('socid' => $socid, 'filtrestatut' => $filtrestatut, 'forVirtualStock' => $forVirtualStock); $reshook = $hookmanager->executeHooks('loadStatsReception', $parameters, $this, $action); if ($reshook > 0) $this->stats_reception = $hookmanager->resArray['stats_reception']; @@ -2940,7 +2935,6 @@ class Product extends CommonObject if ($this->stats_mrptoconsume['qty'] < 0) $this->stats_mrptoconsume['qty'] = 0; if ($this->stats_mrptoproduce['qty'] < 0) $this->stats_mrptoproduce['qty'] = 0; - $hookmanager->initHooks(array('productdao')); $parameters = array('socid' => $socid, 'filtrestatut' => $filtrestatut, 'forVirtualStock' => $forVirtualStock); $reshook = $hookmanager->executeHooks('loadStatsInProduction', $parameters, $this, $action); if ($reshook > 0) $this->stats_mrptoproduce = $hookmanager->resArray['stats_mrptoproduce']; @@ -3015,9 +3009,8 @@ class Product extends CommonObject } } - $hookmanager->initHooks(array('productdao')); $parameters = array('socid' => $socid); - $reshook = $hookmanager->executeHooks('loadStatsContrat', $parameters, $this, $action); + $reshook = $hookmanager->executeHooks('loadStatsContract', $parameters, $this, $action); if ($reshook > 0) $this->stats_contrat = $hookmanager->resArray['stats_contrat']; return 1; @@ -3090,9 +3083,8 @@ class Product extends CommonObject } } - $hookmanager->initHooks(array('productdao')); $parameters = array('socid' => $socid); - $reshook = $hookmanager->executeHooks('loadStatsFacture', $parameters, $this, $action); + $reshook = $hookmanager->executeHooks('loadStatsCustomerInvoice', $parameters, $this, $action); if ($reshook > 0) $this->stats_facture = $hookmanager->resArray['stats_facture']; return 1; @@ -3144,9 +3136,8 @@ class Product extends CommonObject $this->stats_facture_fournisseur['rows'] = $obj->nb_rows; $this->stats_facture_fournisseur['qty'] = $obj->qty ? $obj->qty : 0; - $hookmanager->initHooks(array('productdao')); $parameters = array('socid' => $socid); - $reshook = $hookmanager->executeHooks('loadStatsFactureFournisseur', $parameters, $this, $action); + $reshook = $hookmanager->executeHooks('loadStatsSupplierInvoice', $parameters, $this, $action); if ($reshook > 0) $this->stats_facture_fournisseur = $hookmanager->resArray['stats_facture_fournisseur']; return 1;