Add stats of products in MO
This commit is contained in:
parent
f5a07dfb7e
commit
56704e4029
@ -65,7 +65,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port)
|
||||
*
|
||||
* @param string $element Current element
|
||||
* 'societe', 'socpeople', 'actioncomm', 'agenda', 'resource',
|
||||
* 'product', 'productprice', 'stock',
|
||||
* 'product', 'productprice', 'stock', 'bom', 'mo',
|
||||
* 'propal', 'supplier_proposal', 'invoice', 'facture_fourn', 'payment_various',
|
||||
* 'categorie', 'bank_account', 'bank_account', 'adherent', 'user',
|
||||
* 'commande', 'commande_fournisseur', 'expedition', 'intervention', 'survey',
|
||||
|
||||
@ -190,6 +190,7 @@ NumberOfSupplierProposals=Number of vendor proposals
|
||||
NumberOfSupplierOrders=Number of purchase orders
|
||||
NumberOfSupplierInvoices=Number of vendor invoices
|
||||
NumberOfContracts=Number of contracts
|
||||
NumberOfMos=Number of manufacturing orders
|
||||
NumberOfUnitsProposals=Number of units on proposals
|
||||
NumberOfUnitsCustomerOrders=Number of units on sales orders
|
||||
NumberOfUnitsCustomerInvoices=Number of units on customer invoices
|
||||
@ -197,6 +198,7 @@ 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
|
||||
NumberOfUnitsMos=Number of units to produce in manufacturing orders
|
||||
EMailTextInterventionAddedContact=A new intervention %s has been assigned to you.
|
||||
EMailTextInterventionValidated=The intervention %s has been validated.
|
||||
EMailTextInvoiceValidated=Invoice %s has been validated.
|
||||
|
||||
@ -3261,7 +3261,7 @@ class Product extends CommonObject
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Return nb of units or proposals in which product is included
|
||||
* Return nb of units in proposals 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
|
||||
@ -3313,7 +3313,7 @@ class Product extends CommonObject
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Return nb of units or proposals in which product is included
|
||||
* Return nb of units in proposals 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
|
||||
@ -3365,7 +3365,7 @@ class Product extends CommonObject
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Return nb of units or orders in which product is included
|
||||
* Return nb of units in 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
|
||||
@ -3416,7 +3416,7 @@ class Product extends CommonObject
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Return nb of units or orders in which product is included
|
||||
* Return nb of units in 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
|
||||
@ -3467,7 +3467,7 @@ class Product extends CommonObject
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Return nb of units or orders in which product is included
|
||||
* Return nb of units in 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
|
||||
@ -3519,6 +3519,59 @@ class Product extends CommonObject
|
||||
return $this->_get_stats($sql, $mode, $year);
|
||||
}
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Return nb of units in 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_mos($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter = '')
|
||||
{
|
||||
// phpcs:enable
|
||||
global $conf, $user;
|
||||
|
||||
$sql = "SELECT sum(c.qty), date_format(c.date_valid, '%Y%m')";
|
||||
if ($mode == 'bynumber') {
|
||||
$sql .= ", count(DISTINCT c.rowid)";
|
||||
}
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
|
||||
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.entity IN (".getEntity('mo').")";
|
||||
$sql .= " AND c.status > 0";
|
||||
|
||||
if ($this->id > 0) {
|
||||
$sql .= " AND c.fk_product =".$this->id;
|
||||
} else {
|
||||
$sql .= " AND c.fk_product > 0";
|
||||
}
|
||||
if ($filteronproducttype >= 0) {
|
||||
$sql .= " AND p.rowid = c.fk_product AND p.fk_product_type =".$filteronproducttype;
|
||||
}
|
||||
|
||||
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_valid,'%Y%m')";
|
||||
$sql .= " ORDER BY date_format(c.date_valid,'%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
|
||||
|
||||
@ -299,6 +299,12 @@ if ($result || empty($id))
|
||||
'label' => ($mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsContracts") : $langs->transnoentitiesnoconv("NumberOfContracts")));
|
||||
}
|
||||
|
||||
if ($conf->mrp->enabled) {
|
||||
$graphfiles['mrp'] = array('modulepart'=>'productstats_mrp',
|
||||
'file' => $object->id.'/mos12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year ? '_year'.$search_year : '').'.png',
|
||||
'label' => ($mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsMos") : $langs->transnoentitiesnoconv("NumberOfMos")));
|
||||
}
|
||||
|
||||
$px = new DolGraph();
|
||||
|
||||
if (!$error && count($graphfiles) > 0)
|
||||
@ -338,6 +344,7 @@ if ($result || empty($id))
|
||||
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);
|
||||
if ($key == 'mrp') $graph_data = $object->get_nb_mos($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters);
|
||||
|
||||
// TODO Save cachefile $graphfiles[$key]['file']
|
||||
}
|
||||
@ -384,6 +391,7 @@ if ($result || empty($id))
|
||||
if ($graphfiles == 'proposals_suppliers' && !$user->rights->supplier_proposal->lire) continue;
|
||||
if ($graphfiles == 'invoices_suppliers' && !$user->rights->fournisseur->facture->lire) continue;
|
||||
if ($graphfiles == 'orders_suppliers' && !$user->rights->fournisseur->commande->lire) continue;
|
||||
if ($graphfiles == 'mrp' && empty($user->rights->mrp->mo->read)) continue;
|
||||
|
||||
|
||||
if ($i % 2 == 0)
|
||||
@ -412,7 +420,7 @@ if ($result || empty($id))
|
||||
// Label
|
||||
print '<tr class="liste_titre"><td>';
|
||||
print $graphfiles[$key]['label'];
|
||||
print ' ('.$graphfiles[$key]['total'].')</td>';
|
||||
print ' <span class="opacitymedium">('.$graphfiles[$key]['total'].')</span></td>';
|
||||
print '<td align="right">'.$linktoregenerate.'</td>';
|
||||
print '</tr>';
|
||||
// Image
|
||||
|
||||
Loading…
Reference in New Issue
Block a user