diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 9dbf7ccd125..6e3fc66f89a 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -387,26 +387,37 @@ class Conf $this->fournisseur->payment->dir_output =$rootfordata."/fournisseur/payment"; // For backward compatibility $this->fournisseur->payment->dir_temp =$rootfordata."/fournisseur/payment/temp"; // For backward compatibility - // To prepare split of module fournisseur into fournisseur + supplier_order + supplier_invoice - if (! empty($this->fournisseur->enabled) && empty($this->global->MAIN_USE_NEW_SUPPLIERMOD)) // By default, if module supplier is on, we set new properties + // To prepare split of module vendor(fournisseur) into vendor + supplier_order + supplier_invoice + supplierproposal + if (! empty($this->fournisseur->enabled)) // By default, if module supplier is on, we set new properties { - $this->supplier_order=new stdClass(); - $this->supplier_order->enabled=1; - $this->supplier_order->multidir_output=array($this->entity => $rootfordata."/fournisseur/commande"); - $this->supplier_order->multidir_temp =array($this->entity => $rootfordata."/fournisseur/commande/temp"); - $this->supplier_order->dir_output=$rootfordata."/fournisseur/commande"; // For backward compatibility - $this->supplier_order->dir_temp=$rootfordata."/fournisseur/commande/temp"; // For backward compatibility - $this->supplier_invoice=new stdClass(); - $this->supplier_invoice->enabled=1; - $this->supplier_invoice->multidir_output=array($this->entity => $rootfordata."/fournisseur/facture"); - $this->supplier_invoice->multidir_temp =array($this->entity => $rootfordata."/fournisseur/facture/temp"); - $this->supplier_invoice->dir_output=$rootfordata."/fournisseur/facture"; // For backward compatibility - $this->supplier_invoice->dir_temp=$rootfordata."/fournisseur/facture/temp"; // For backward compatibility - $this->supplierproposal=new stdClass(); - $this->supplierproposal->multidir_output=array($this->entity => $rootfordata."/supplier_proposal"); - $this->supplierproposal->multidir_temp =array($this->entity => $rootfordata."/supplier_proposal/temp"); - $this->supplierproposal->dir_output=$rootfordata."/supplier_proposal"; // For backward compatibility - $this->supplierproposal->dir_temp=$rootfordata."/supplier_proposal/temp"; // For backward compatibility + if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) // This can be set to 1 once modules purchase order and supplier invoice exists + { + $this->supplier_order=new stdClass(); + $this->supplier_order->enabled=1; + $this->supplier_order->multidir_output=array($this->entity => $rootfordata."/fournisseur/commande"); + $this->supplier_order->multidir_temp =array($this->entity => $rootfordata."/fournisseur/commande/temp"); + $this->supplier_order->dir_output=$rootfordata."/fournisseur/commande"; // For backward compatibility + $this->supplier_order->dir_temp=$rootfordata."/fournisseur/commande/temp"; // For backward compatibility + } + + if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) // This can be set to 1 once modules purchase order and supplier invoice exists + { + $this->supplier_invoice=new stdClass(); + $this->supplier_invoice->enabled=1; + $this->supplier_invoice->multidir_output=array($this->entity => $rootfordata."/fournisseur/facture"); + $this->supplier_invoice->multidir_temp =array($this->entity => $rootfordata."/fournisseur/facture/temp"); + $this->supplier_invoice->dir_output=$rootfordata."/fournisseur/facture"; // For backward compatibility + $this->supplier_invoice->dir_temp=$rootfordata."/fournisseur/facture/temp"; // For backward compatibility + } + + if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) // This can be set to 1 once modules purchase order and supplier invoice exists + { + $this->supplier_proposal=new stdClass(); + $this->supplier_proposal->multidir_output=array($this->entity => $rootfordata."/supplier_proposal"); + $this->supplier_proposal->multidir_temp =array($this->entity => $rootfordata."/supplier_proposal/temp"); + $this->supplier_proposal->dir_output=$rootfordata."/supplier_proposal"; // For backward compatibility + $this->supplier_proposal->dir_temp=$rootfordata."/supplier_proposal/temp"; // For backward compatibility + } } } diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 0ad4c5dfc83..b92e21d69b3 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -184,12 +184,14 @@ NumberOfCustomerInvoices=Number of customer invoices NumberOfSupplierProposals=Number of vendor proposals NumberOfSupplierOrders=Number of purchase orders NumberOfSupplierInvoices=Number of vendor invoices +NumberOfContracts=Number of contracts NumberOfUnitsProposals=Number of units on proposals NumberOfUnitsCustomerOrders=Number of units on sales orders NumberOfUnitsCustomerInvoices=Number of units on customer invoices NumberOfUnitsSupplierProposals=Number of units on vendor proposals NumberOfUnitsSupplierOrders=Number of units on purchase orders NumberOfUnitsSupplierInvoices=Number of units on vendor invoices +NumberOfUnitsContracts=Number of units on contracts EMailTextInterventionAddedContact=A new intervention %s has been assigned to you. EMailTextInterventionValidated=The intervention %s has been validated. EMailTextInvoiceValidated=Invoice %s has been validated. diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 50ddded3600..da0ef540def 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3249,6 +3249,57 @@ class Product extends CommonObject return $this->_get_stats($sql, $mode, $year); } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return nb of units or orders in which product is included + * + * @param int $socid Limit count on a particular third party id + * @param string $mode 'byunit'=number of unit, 'bynumber'=nb of entities + * @param int $filteronproducttype 0=To filter on product only, 1=To filter on services only + * @param int $year Year (0=last 12 month) + * @param string $morefilter More sql filters + * @return array <0 if KO, result[month]=array(valuex,valuey) where month is 0 to 11 + */ + public function get_nb_contract($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter = '') + { + // phpcs:enable + global $conf, $user; + + $sql = "SELECT sum(d.qty), date_format(c.date_contrat, '%Y%m')"; + if ($mode == 'bynumber') { + $sql.= ", count(DISTINCT c.rowid)"; + } + $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as d, ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s"; + if ($filteronproducttype >= 0) { + $sql.=", ".MAIN_DB_PREFIX."product as p"; + } + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } + $sql.= " WHERE c.rowid = d.fk_contrat"; + if ($this->id > 0) { + $sql.= " AND d.fk_product =".$this->id; + } else { + $sql.=" AND d.fk_product > 0"; + } + if ($filteronproducttype >= 0) { + $sql.= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + } + $sql.= " AND c.fk_soc = s.rowid"; + $sql.= " AND c.entity IN (".getEntity('contract').")"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; + } + if ($socid > 0) { + $sql.= " AND c.fk_soc = ".$socid; + } + $sql.=$morefilter; + $sql.= " GROUP BY date_format(c.date_contrat,'%Y%m')"; + $sql.= " ORDER BY date_format(c.date_contrat,'%Y%m') DESC"; + + return $this->_get_stats($sql, $mode, $year); + } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Link a product/service to a parent product/service diff --git a/htdocs/product/stats/card.php b/htdocs/product/stats/card.php index 62209d568df..d01663a7723 100644 --- a/htdocs/product/stats/card.php +++ b/htdocs/product/stats/card.php @@ -1,6 +1,6 @@ - * Copyright (c) 2004-2017 Laurent Destailleur + * Copyright (c) 2004-2019 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2005 Eric Seigne * Copyright (C) 2013 Juanjo Menent @@ -40,8 +40,8 @@ $HEIGHT=DolGraph::getDefaultGraphSizeForStats('height', 160); $langs->loadLangs(array('companies', 'products', 'stocks', 'bills', 'other')); $id = GETPOST('id', 'int'); // For this page, id can also be 'all' -$ref = GETPOST('ref'); -$mode = (GETPOST('mode') ? GETPOST('mode') : 'byunit'); +$ref = GETPOST('ref', 'alpha'); +$mode = (GETPOST('mode', 'alpha') ? GETPOST('mode', 'alpha') : 'byunit'); $search_year = GETPOST('search_year', 'int'); $search_categ = GETPOST('search_categ', 'int'); @@ -269,7 +269,7 @@ if ($result || empty($id)) 'label' => ($mode=='byunit'?$langs->transnoentitiesnoconv("NumberOfUnitsCustomerOrders"):$langs->transnoentitiesnoconv("NumberOfCustomerOrders"))); } - if($conf->fournisseur->enabled) { + if($conf->supplier_order->enabled) { $graphfiles['orderssuppliers']=array('modulepart'=>'productstats_orderssuppliers', 'file' => $object->id.'/orderssuppliers12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year?'_year'.$search_year:'').'.png', 'label' => ($mode=='byunit'?$langs->transnoentitiesnoconv("NumberOfUnitsSupplierOrders"):$langs->transnoentitiesnoconv("NumberOfSupplierOrders"))); @@ -279,12 +279,20 @@ if ($result || empty($id)) $graphfiles['invoices']=array('modulepart'=>'productstats_invoices', 'file' => $object->id.'/invoices12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year?'_year'.$search_year:'').'.png', 'label' => ($mode=='byunit'?$langs->transnoentitiesnoconv("NumberOfUnitsCustomerInvoices"):$langs->transnoentitiesnoconv("NumberOfCustomerInvoices"))); + } + if($conf->supplier_invoice->enabled) { $graphfiles['invoicessuppliers']=array('modulepart'=>'productstats_invoicessuppliers', 'file' => $object->id.'/invoicessuppliers12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year?'_year'.$search_year:'').'.png', 'label' => ($mode=='byunit'?$langs->transnoentitiesnoconv("NumberOfUnitsSupplierInvoices"):$langs->transnoentitiesnoconv("NumberOfSupplierInvoices"))); } + if($conf->contrat->enabled) { + $graphfiles['contracts']=array('modulepart'=>'productstats_contracts', + 'file' => $object->id.'/contracts12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year?'_year'.$search_year:'').'.png', + 'label' => ($mode=='byunit'?$langs->transnoentitiesnoconv("NumberOfUnitsContracts"):$langs->transnoentitiesnoconv("NumberOfContracts"))); + } + $px = new DolGraph(); if (! $error && count($graphfiles)>0) @@ -323,6 +331,7 @@ if ($result || empty($id)) if ($key == 'proposalssuppliers') $graph_data = $object->get_nb_propalsupplier($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); if ($key == 'invoicessuppliers') $graph_data = $object->get_nb_achat($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); if ($key == 'orderssuppliers') $graph_data = $object->get_nb_ordersupplier($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); + if ($key == 'contracts') $graph_data = $object->get_nb_contract($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); // TODO Save cachefile $graphfiles[$key]['file'] } @@ -349,9 +358,9 @@ if ($result || empty($id)) dol_print_error($db, 'Error for calculating graph on key='.$key.' - '.$object->error); } } - } - $mesg = $langs->trans("ChartGenerated"); + //setEventMessages($langs->trans("ChartGenerated"), null, 'mesgs'); + } } // Show graphs @@ -387,9 +396,9 @@ if ($result || empty($id)) } else { - print $dategenerated=($mesg?''.$mesg.'':$langs->trans("ChartNotGenerated")); + $dategenerated=($mesg?''.$mesg.'':$langs->trans("ChartNotGenerated")); } - $linktoregenerate='id).((string) $type != ''?'&type='.$type:'').'&action=recalcul&mode='.$mode.'&search_year='.$search_year.'&search_categ='.$search_categ.'">'.img_picto($langs->trans("ReCalculate").' ('.$dategenerated.')', 'refresh').''; + $linktoregenerate='id).((string) $type != ''?'&type='.$type:'').'&action=recalcul&mode='.$mode.'&search_year='.$search_year.'&search_categ='.$search_categ.'">'.img_picto($langs->trans("ReCalculate").' ('.$dategenerated.')', 'refresh').''; // Show graph print '';