Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2023-02-17 16:05:26 +01:00
commit 72f4be364e
8 changed files with 1904 additions and 7 deletions

View File

@ -200,6 +200,7 @@ $fieldstosearchall = array(
'f.ref_client'=>'RefCustomer',
'f.note_public'=>'NotePublic',
's.nom'=>"ThirdParty",
's.code_client'=>"CustomerCodeShort",
's.name_alias'=>"AliasNameShort",
's.zip'=>"Zip",
's.town'=>"Town",
@ -222,6 +223,7 @@ $arrayfields = array(
'p.title'=>array('label'=>"ProjectLabel", 'checked'=>0, 'enabled'=>(!isModEnabled('project') ? 0 : 1), 'position'=>41),
's.nom'=>array('label'=>"ThirdParty", 'checked'=>1, 'position'=>50),
's.name_alias'=>array('label'=>"AliasNameShort", 'checked'=>1, 'position'=>51),
's.code_client'=>array('label'=>"CustomerCodeShort", 'checked'=>-1, 'position'=>52),
's2.nom'=>array('label'=>'ParentCompany', 'position'=>32, 'checked'=>0),
's.town'=>array('label'=>"Town", 'checked'=>-1, 'position'=>55),
's.zip'=>array('label'=>"Zip", 'checked'=>1, 'position'=>60),
@ -574,7 +576,7 @@ $sql .= ' f.datef, f.date_valid, f.date_lim_reglement as datelimite, f.module_so
$sql .= ' f.paye as paye, f.fk_statut, f.close_code,';
$sql .= ' f.datec as date_creation, f.tms as date_update, f.date_closing as date_closing,';
$sql .= ' f.retained_warranty, f.retained_warranty_date_limit, f.situation_final, f.situation_cycle_ref, f.situation_counter,';
$sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.phone, s.fax, s.address, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur,';
$sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.code_client as code_client, s.email, s.phone, s.fax, s.address, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur,';
$sql .= " s.parent as fk_parent,";
$sql .= " s2.nom as name2,";
$sql .= ' typent.code as typent_code,';
@ -687,6 +689,9 @@ if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
if ($search_parent_name) {
$sql .= natural_search('s2.nom', $search_parent_name);
}
if ($search_company_code_client) {
$sql .= natural_search('s.code_client', $search_company_code_client);
}
if ($search_town) {
$sql .= natural_search('s.town', $search_town);
}
@ -1382,19 +1387,19 @@ if ($resql) {
}
// Project ref
if (!empty($arrayfields['p.ref']['checked'])) {
print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project_ref" value="'.$search_project_ref.'"></td>';
print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project_ref" value="'.dol_escape_htmltag($search_project_ref).'"></td>';
}
// Project label
if (!empty($arrayfields['p.title']['checked'])) {
print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project" value="'.$search_project.'"></td>';
print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
}
// Thirdparty
if (!empty($arrayfields['s.nom']['checked'])) {
print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_company" value="'.$search_company.'"'.($socid > 0 ? " disabled" : "").'></td>';
print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'"'.($socid > 0 ? " disabled" : "").'></td>';
}
// Alias
if (!empty($arrayfields['s.name_alias']['checked'])) {
print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_company_alias" value="'.$search_company_alias.'"></td>';
print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'"></td>';
}
// Parent company
if (!empty($arrayfields['s2.nom']['checked'])) {
@ -1402,6 +1407,10 @@ if ($resql) {
print '<input class="flat maxwidth100" type="text" name="search_parent_name" value="'.dol_escape_htmltag($search_parent_name).'">';
print '</td>';
}
// Customer Code
if (!empty($arrayfields['s.code_client']['checked'])) {
print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_company_code_client" value="'.dol_escape_htmltag($search_company_code_client).'"></td>';
}
// Town
if (!empty($arrayfields['s.town']['checked'])) {
print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
@ -1467,13 +1476,13 @@ if ($resql) {
if (!empty($arrayfields['f.total_localtax1']['checked'])) {
// Localtax1
print '<td class="liste_titre right">';
print '<input class="flat" type="text" size="4" name="search_montant_localtax1" value="'.$search_montant_localtax1.'">';
print '<input class="flat" type="text" size="4" name="search_montant_localtax1" value="'.dol_escape_htmltag($search_montant_localtax1).'">';
print '</td>';
}
if (!empty($arrayfields['f.total_localtax2']['checked'])) {
// Localtax2
print '<td class="liste_titre right">';
print '<input class="flat" type="text" size="4" name="search_montant_localtax2" value="'.$search_montant_localtax2.'">';
print '<input class="flat" type="text" size="4" name="search_montant_localtax2" value="'.dol_escape_htmltag($search_montant_localtax2).'">';
print '</td>';
}
if (!empty($arrayfields['f.total_ttc']['checked'])) {
@ -1654,6 +1663,9 @@ if ($resql) {
if (!empty($arrayfields['s2.nom']['checked'])) {
print_liste_field_titre($arrayfields['s2.nom']['label'], $_SERVER['PHP_SELF'], 's2.nom', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['s.code_client']['checked'])) {
print_liste_field_titre($arrayfields['s.code_client']['label'], $_SERVER['PHP_SELF'], 's.code_client', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['s.town']['checked'])) {
print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
}
@ -1850,6 +1862,7 @@ if ($resql) {
$companystatic->id = $obj->socid;
$companystatic->name = $obj->name;
$companystatic->name_alias = $obj->alias;
$companystatic->code_client = $obj->code_client;
$companystatic->client = $obj->client;
$companystatic->fournisseur = $obj->fournisseur;
$companystatic->code_client = $obj->code_client;
@ -2095,6 +2108,15 @@ if ($resql) {
$totalarray['nbfield']++;
}
}
// Customer Code
if (!empty($arrayfields['s.code_client']['checked'])) {
print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companystatic->code_client).'">';
print dol_escape_htmltag($companystatic->code_client);
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
// Town
if (!empty($arrayfields['s.town']['checked'])) {
print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">';

View File

@ -4,6 +4,7 @@
* Copyright (C) 2009-2010 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -253,6 +254,11 @@ function productlot_prepare_head($object)
$head[$h][2] = 'card';
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/stock/stats/expedition.php?showmessage=1&id=".$object->id;
$head[$h][1] = $langs->trans('Referers');
$head[$h][2] = 'referers';
$h++;
// Attachments
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
@ -648,6 +654,126 @@ function show_stats_for_company($product, $socid)
return $nblines++;
}
/**
* Show stats for product batch
*
* @param Productlot $batch Product batch object
* @param int $socid Thirdparty id
* @return integer NB of lines shown into array
*/
function show_stats_for_batch($batch, $socid)
{
global $conf, $langs, $user, $db, $hookmanager;
$langs->LoadLangs(array('sendings', 'orders', 'receptions'));
$form = new Form($db);
$nblines = 0;
print '<tr class="liste_titre">';
print '<td class="left" width="25%">'.$langs->trans("Referers").'</td>';
print '<td class="right" width="25%">'.$langs->trans("NbOfThirdParties").'</td>';
print '<td class="right" width="25%">'.$langs->trans("NbOfObjectReferers").'</td>';
print '<td class="right" width="25%">'.$langs->trans("TotalQuantity").'</td>';
print '</tr>';
// Expeditions
if (isModEnabled('expedition') && !empty($user->rights->expedition->lire)) {
$nblines++;
$ret = $batch->loadStatsExpedition($socid);
if ($ret < 0) {
dol_print_error($db);
}
$langs->load("bills");
print '<tr><td>';
print '<a href="'.dol_buildpath('/product/stock/stats/expedition.php', 1).'?id='.$batch->id.'">'.img_object('', 'bill', 'class="pictofixedwidth"').$langs->trans("Shipments").'</a>';
print '</td><td class="right">';
print $batch->stats_expedition['customers'];
print '</td><td class="right">';
print $batch->stats_expedition['nb'];
print '</td><td class="right">';
print $batch->stats_expedition['qty'];
print '</td>';
print '</tr>';
}
if (isModEnabled("reception") && !empty($user->rights->reception->lire)) {
$nblines++;
$ret = $batch->loadStatsReception($socid);
if ($ret < 0) {
dol_print_error($db);
}
$langs->load("bills");
print '<tr><td>';
print '<a href="'.dol_buildpath('/product/stock/stats/reception.php', 1).'?id='.$batch->id.'">'.img_object('', 'bill', 'class="pictofixedwidth"').$langs->trans("Receptions").'</a>';
print '</td><td class="right">';
print $batch->stats_reception['customers'];
print '</td><td class="right">';
print $batch->stats_reception['nb'];
print '</td><td class="right">';
print $batch->stats_reception['qty'];
print '</td>';
print '</tr>';
} elseif (isModEnabled('supplier_order') && !empty($user->rights->fournisseur->commande->lire)) {
$nblines++;
$ret = $batch->loadStatsSupplierOrder($socid);
if ($ret < 0) {
dol_print_error($db);
}
$langs->load("bills");
print '<tr><td>';
print '<a href="'.dol_buildpath('/product/stock/stats/commande_fournisseur.php', 1).'?id='.$batch->id.'">'.img_object('', 'bill', 'class="pictofixedwidth"').$langs->trans("SuppliersOrders").'</a>';
print '</td><td class="right">';
print $batch->stats_supplier_order['customers'];
print '</td><td class="right">';
print $batch->stats_supplier_order['nb'];
print '</td><td class="right">';
print $batch->stats_supplier_order['qty'];
print '</td>';
print '</tr>';
}
if (isModEnabled('mrp') && !empty($user->rights->mrp->read)) {
$nblines++;
$ret = $batch->loadStatsMo($socid);
if ($ret < 0) {
dol_print_error($db);
}
$langs->load("mrp");
print '<tr><td>';
print '<a href="'.dol_buildpath('/product/stock/stats/mo.php', 1).'?id='.$batch->id.'">'.img_object('', 'mrp', 'class="pictofixedwidth"').$langs->trans("MO").'</a>';
print '</td><td class="right">';
// print $form->textwithpicto($batch->stats_mo['customers_toconsume'], $langs->trans("ToConsume")); Makes no sense with batch, at this moment we don't know batch number
print $form->textwithpicto($batch->stats_mo['customers_consumed'], $langs->trans("QtyAlreadyConsumed"));
// print $form->textwithpicto($batch->stats_mo['customers_toproduce'], $langs->trans("QtyToProduce")); Makes no sense with batch, at this moment we don't know batch number
print $form->textwithpicto($batch->stats_mo['customers_produced'], $langs->trans("QtyAlreadyProduced"));
print '</td><td class="right">';
// print $form->textwithpicto($batch->stats_mo['nb_toconsume'], $langs->trans("ToConsume")); Makes no sense with batch, at this moment we don't know batch number
print $form->textwithpicto($batch->stats_mo['nb_consumed'], $langs->trans("QtyAlreadyConsumed"));
// print $form->textwithpicto($batch->stats_mo['nb_toproduce'], $langs->trans("QtyToProduce")); Makes no sense with batch, at this moment we don't know batch number
print $form->textwithpicto($batch->stats_mo['nb_produced'], $langs->trans("QtyAlreadyProduced"));
print '</td><td class="right">';
// print $form->textwithpicto($batch->stats_mo['qty_toconsume'], $langs->trans("ToConsume")); Makes no sense with batch, at this moment we don't know batch number
print $form->textwithpicto($batch->stats_mo['qty_consumed'], $langs->trans("QtyAlreadyConsumed"));
// print $form->textwithpicto($batch->stats_mo['qty_toproduce'], $langs->trans("QtyToProduce")); Makes no sense with batch, at this moment we don't know batch number
print $form->textwithpicto($batch->stats_mo['qty_produced'], $langs->trans("QtyAlreadyProduced"));
print '</td>';
print '</tr>';
}
$parameters = array('socid'=>$socid);
$reshook = $hookmanager->executeHooks('addMoreBatchProductStat', $parameters, $batch, $nblines); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
print $hookmanager->resPrint;
return $nblines++;
}
/**
* Return translation label of a unit key.
* Function kept for backward compatibility.

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2021 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -28,6 +29,7 @@ require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
// Load translation files required by the page
$langs->loadLangs(array('mrp', 'products', 'companies'));
@ -63,6 +65,14 @@ if (!$sortfield) {
$sortfield = "c.date_valid";
}
$search_month = GETPOST('search_month', 'int');
$search_year = GETPOST('search_year', 'int');
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
$search_month = '';
$search_year = '';
}
$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
@ -74,6 +84,7 @@ $staticmo = new Mo($db);
$staticmoligne = new MoLine($db);
$form = new Form($db);
$formother = new FormOther($db);
if ($id > 0 || !empty($ref)) {
$product = new Product($db);
@ -139,6 +150,12 @@ if ($id > 0 || !empty($ref)) {
$sql .= " WHERE c.rowid = cd.fk_mo";
$sql .= " AND c.entity IN (".getEntity('mo').")";
$sql .= " AND cd.fk_product = ".((int) $product->id);
if (!empty($search_month)) {
$sql .= ' AND MONTH(c.date_valid) IN ('.$db->sanitize($search_month).')';
}
if (!empty($search_year)) {
$sql .= ' AND YEAR(c.date_valid) IN ('.$db->sanitize($search_year).')';
}
if ($socid) {
$sql .= " AND s.rowid = ".((int) $socid);
}
@ -190,6 +207,18 @@ if ($id > 0 || !empty($ref)) {
$option .= '&page='.urlencode($page);
}
print '<div class="liste_titre liste_titre_bydiv centpercent">';
print '<div class="divsearchfield">';
print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - ';
print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
print '<div style="vertical-align: middle; display: inline-block">';
print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
print '</div>';
print '</div>';
print '</div>';
$i = 0;
print '<div class="div-table-responsive">';
print '<table class="tagtable liste listwithfilterbefore" width="100%">';

View File

@ -4,6 +4,7 @@
* Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -554,6 +555,289 @@ class Productlot extends CommonObject
}
}
/**
* Charge tableau des stats expedition pour le lot/numéro de série
*
* @param int $socid Id societe
* @return int Array of stats in $this->stats_expedition, <0 if ko or >0 if ok
*/
public function loadStatsExpedition($socid = 0)
{
// phpcs:enable
global $db, $conf, $user, $hookmanager, $action;
$sql = "SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
$sql .= " COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
$sql .= " FROM ".$this->db->prefix()."expeditiondet_batch as edb";
$sql .= " INNER JOIN ".$this->db->prefix()."expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
$sql .= " INNER JOIN ".$this->db->prefix()."expedition as exp ON (exp.rowid = ed.fk_expedition)";
// $sql .= ", ".$this->db->prefix()."societe as s";
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
}
$sql .= " WHERE exp.entity IN (".getEntity('expedition').")";
$sql .= " AND edb.batch = '".($this->db->escape($this->batch))."'";
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
//$sql.= " AND exp.fk_statut != 0";
if ($socid > 0) {
$sql .= " AND exp.fk_soc = ".((int) $socid);
}
$result = $this->db->query($sql);
if ($result) {
$obj = $this->db->fetch_object($result);
$this->stats_expedition['customers'] = $obj->nb_customers;
$this->stats_expedition['nb'] = $obj->nb;
$this->stats_expedition['rows'] = $obj->nb_rows;
$this->stats_expedition['qty'] = $obj->qty ? $obj->qty : 0;
// Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
// if it's a virtual product, maybe it is in invoice by extension
// if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
// $TFather = $this->getFather();
// if (is_array($TFather) && !empty($TFather)) {
// foreach ($TFather as &$fatherData) {
// $pFather = new Product($this->db);
// $pFather->id = $fatherData['id'];
// $qtyCoef = $fatherData['qty'];
//
// if ($fatherData['incdec']) {
// $pFather->loadStatsExpedition($socid);
//
// $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
// $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
// $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
// $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
// }
// }
// }
// }
$parameters = array('socid' => $socid);
$reshook = $hookmanager->executeHooks('loadStatsLotExpedition', $parameters, $this, $action);
if ($reshook > 0) {
$this->stats_expedition = $hookmanager->resArray['stats_expedition'];
}
return 1;
} else {
$this->error = $this->db->error();
return -1;
}
}
/**
* Charge tableau des stats commande fournisseur pour le lot/numéro de série
*
* @param int $socid Id societe
* @return int Array of stats in $this->stats_expedition, <0 if ko or >0 if ok
*/
public function loadStatsSupplierOrder($socid = 0)
{
// phpcs:enable
global $db, $conf, $user, $hookmanager, $action;
$sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
$sql .= " COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
$sql .= " FROM ".$this->db->prefix()."commande_fournisseur_dispatch as cfdi";
$sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_commandefourndet)";
$sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
// $sql .= ", ".$this->db->prefix()."societe as s";
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
}
$sql .= " WHERE cf.entity IN (".getEntity('expedition').")";
$sql .= " AND cfdi.batch = '".($this->db->escape($this->batch))."'";
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
//$sql.= " AND cf.fk_statut != 0";
if ($socid > 0) {
$sql .= " AND cf.fk_soc = ".((int) $socid);
}
$result = $this->db->query($sql);
if ($result) {
$obj = $this->db->fetch_object($result);
$this->stats_supplier_order['customers'] = $obj->nb_customers;
$this->stats_supplier_order['nb'] = $obj->nb;
$this->stats_supplier_order['rows'] = $obj->nb_rows;
$this->stats_supplier_order['qty'] = $obj->qty ? $obj->qty : 0;
// Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
// if it's a virtual product, maybe it is in invoice by extension
// if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
// $TFather = $this->getFather();
// if (is_array($TFather) && !empty($TFather)) {
// foreach ($TFather as &$fatherData) {
// $pFather = new Product($this->db);
// $pFather->id = $fatherData['id'];
// $qtyCoef = $fatherData['qty'];
//
// if ($fatherData['incdec']) {
// $pFather->stats_supplier_order($socid);
//
// $this->stats_supplier_order['customers'] += $pFather->stats_supplier_order['customers'];
// $this->stats_supplier_order['nb'] += $pFather->stats_supplier_order['nb'];
// $this->stats_supplier_order['rows'] += $pFather->stats_supplier_order['rows'];
// $this->stats_supplier_order['qty'] += $pFather->stats_supplier_order['qty'] * $qtyCoef;
// }
// }
// }
// }
$parameters = array('socid' => $socid);
$reshook = $hookmanager->executeHooks('loadStatsLotSupplierOrder', $parameters, $this, $action);
if ($reshook > 0) {
$this->stats_supplier_order = $hookmanager->resArray['stats_supplier_order'];
}
return 1;
} else {
$this->error = $this->db->error();
return -1;
}
}
/**
* Charge tableau des stats expedition pour le lot/numéro de série
*
* @param int $socid Id societe
* @return int Array of stats in $this->stats_expedition, <0 if ko or >0 if ok
*/
public function loadStatsReception($socid = 0)
{
// phpcs:enable
global $db, $conf, $user, $hookmanager, $action;
$sql = "SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
$sql .= " COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
$sql .= " FROM ".$this->db->prefix()."commande_fournisseur_dispatch as cfdi";
$sql .= " INNER JOIN ".$this->db->prefix()."reception as recep ON (recep.rowid = cfdi.fk_reception)";
// $sql .= ", ".$this->db->prefix()."societe as s";
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
}
$sql .= " WHERE recep.entity IN (".getEntity('reception').")";
$sql .= " AND cfdi.batch = '".($this->db->escape($this->batch))."'";
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
//$sql.= " AND exp.fk_statut != 0";
if ($socid > 0) {
$sql .= " AND recep.fk_soc = ".((int) $socid);
}
$result = $this->db->query($sql);
if ($result) {
$obj = $this->db->fetch_object($result);
$this->stats_reception['customers'] = $obj->nb_customers;
$this->stats_reception['nb'] = $obj->nb;
$this->stats_reception['rows'] = $obj->nb_rows;
$this->stats_reception['qty'] = $obj->qty ? $obj->qty : 0;
// Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
// if it's a virtual product, maybe it is in invoice by extension
// if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
// $TFather = $this->getFather();
// if (is_array($TFather) && !empty($TFather)) {
// foreach ($TFather as &$fatherData) {
// $pFather = new Product($this->db);
// $pFather->id = $fatherData['id'];
// $qtyCoef = $fatherData['qty'];
//
// if ($fatherData['incdec']) {
// $pFather->loadStatsReception($socid);
//
// $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
// $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
// $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
// $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
// }
// }
// }
// }
$parameters = array('socid' => $socid);
$reshook = $hookmanager->executeHooks('loadStatsLotReception', $parameters, $this, $action);
if ($reshook > 0) {
$this->stats_expedition = $hookmanager->resArray['stats_expedition'];
}
return 1;
} else {
$this->error = $this->db->error();
return -1;
}
}
/**
* Charge tableau des stats expedition pour le lot/numéro de série
*
* @param int $socid Id societe
* @return int Array of stats in $this->stats_expedition, <0 if ko or >0 if ok
*/
public function loadStatsMo($socid = 0)
{
// phpcs:enable
global $user, $hookmanager, $action;
$error = 0;
foreach (array('toconsume', 'consumed', 'toproduce', 'produced') as $role) {
$this->stats_mo['customers_'.$role] = 0;
$this->stats_mo['nb_'.$role] = 0;
$this->stats_mo['qty_'.$role] = 0;
$sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
$sql .= " SUM(mp.qty) as qty";
$sql .= " FROM ".$this->db->prefix()."mrp_mo as c";
$sql .= " INNER JOIN ".$this->db->prefix()."mrp_production as mp ON mp.fk_mo=c.rowid";
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= "INNER JOIN ".$this->db->prefix()."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
}
$sql .= " WHERE ";
$sql .= " c.entity IN (".getEntity('mo').")";
$sql .= " AND mp.batch = '".($this->db->escape($this->batch))."'";
$sql .= " AND mp.role ='".$this->db->escape($role)."'";
if ($socid > 0) {
$sql .= " AND c.fk_soc = ".((int) $socid);
}
$result = $this->db->query($sql);
if ($result) {
$obj = $this->db->fetch_object($result);
$this->stats_mo['customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
$this->stats_mo['nb_'.$role] = $obj->nb ? $obj->nb : 0;
$this->stats_mo['qty_'.$role] = $obj->qty ? price2num($obj->qty, 'MS') : 0; // qty may be a float due to the SUM()
} else {
$this->error = $this->db->error();
$error++;
}
}
if (!empty($error)) {
return -1;
}
$parameters = array('socid' => $socid);
$reshook = $hookmanager->executeHooks('loadStatsCustomerMO', $parameters, $this, $action);
if ($reshook > 0) {
$this->stats_mo = $hookmanager->resArray['stats_mo'];
}
return 1;
}
/**
* Return label of status of object

View File

@ -0,0 +1,376 @@
<?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/product/stock/stats/commande_fournisseur.php
* \ingroup product service facture
* \brief Page of supplier order statistics for a batch
*/
// Load Dolibarr environment
require '../../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
// Load translation files required by the page
$langs->loadLangs(array('companies', 'bills', 'products', 'orders'));
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$batch = GETPOST('batch', 'alpha');
$objectid = GETPOST('productid', 'int');
// Security check
$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
$socid = '';
if (!empty($user->socid)) {
$socid = $user->socid;
}
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('batchproductstatssupplierorder'));
$showmessage = GETPOST('showmessage');
// Load variable for pagination
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "cf.date_commande";
}
$search_month = GETPOST('search_month', 'int');
$search_year = GETPOST('search_year', 'int');
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
$search_month = '';
$search_year = '';
}
if (!$user->rights->produit->lire) accessforbidden();
/*
* View
*/
$commandefournisseurstatic = new CommandeFournisseur($db);
$societestatic = new Societe($db);
$form = new Form($db);
$formother = new FormOther($db);
if ($id > 0 || !empty($ref)) {
$object = new ProductLot($db);
if ($ref) {
$tmp = explode('_', $ref);
$objectid = $tmp[0];
$batch = $tmp[1];
}
$result = $object->fetch($id, $objectid, $batch);
$parameters = array('id'=>$id);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$helpurl = '';
$shortlabel = dol_trunc($object->batch, 16);
$title = $langs->trans('Batch')." ".$shortlabel." - ".$langs->trans('Referers');
$helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
llxHeader('', $title, $helpurl);
if ($result > 0) {
$head = productlot_prepare_head($object);
$titre = $langs->trans("CardProduct".$object->type);
$picto = 'lot';
print dol_get_fiche_head($head, 'referers', $langs->trans("Batch"), -1, $object->picto);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$shownav = 1;
if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
$shownav = 0;
}
dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch', $morehtmlref);
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield" width="100%">';
// Product
print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
$producttmp = new Product($db);
$producttmp->fetch($object->fk_product);
print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
print '</td></tr>';
print "</table>";
echo '<br>';
// // Sell by
// if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
// print '<tr><td>';
// print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
// print '</td><td>';
// print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
// print '</td>';
// print '</tr>';
// }
//
// // Eat by
// if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
// print '<tr><td>';
// print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
// print '</td><td>';
// print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
// print '</td>';
// print '</tr>';
// }
//
// if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABOLITY)) {
// print '<tr><td>'.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).'</td>';
// print '<td>'.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
// print '</tr>';
// // print '<tr><td>'.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).'</td>';
// // print '<td>'.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
// // print '</tr>';
// print '<tr><td>'.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).'</td>';
// print '<td>'.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
// print '</tr>';
// }
//
// // Quality control
// if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
// print '<tr><td>'.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).'</td>';
// print '<td>'.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
// print '</tr>';
// print '<tr><td>'.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).'</td>';
// print '<td>'.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'numeric').'</td>';
// print '</tr>';
// }
//
// // Other attributes
// include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
print '<table class="border centpercent tableforfield" width="100%">';
$nboflines = show_stats_for_batch($object, $socid);
print "</table>";
print '</div>';
print '<div style="clear:both"></div>';
print dol_get_fiche_end();
if ($showmessage && $nboflines > 1) {
print '<span class="opacitymedium">'.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).'</span>';
} elseif ($user->rights->fournisseur->commande->lire) {
$sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_fournisseur,";
$sql .= " cf.ref, cf.date_commande, cf.date_livraison as delivery_date, cf.fk_statut as statut, cf.rowid as facid,";
$sql .= " cfd.rowid, SUM(cfdi.qty) as qty";
// $sql.= ", cfd.total_ht * SUM(cfdi.qty) / cfd.qty as total_ht_pondere";
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ", sc.fk_soc, sc.fk_user ";
}
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande_fournisseur as cf ON (cf.fk_soc = s.rowid)";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as cfd ON (cfd.fk_commande = cf.rowid)";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfdi ON (cfdi.fk_commandefourndet = cfd.rowid)";
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE cf.entity IN (".getEntity('product').")";
$sql .= " AND cfdi.batch = '".($db->escape($object->batch))."'";
if (!empty($search_month)) {
$sql .= ' AND MONTH(cf.date_commande) IN ('.$db->sanitize($search_month).')';
}
if (!empty($search_year)) {
$sql .= ' AND YEAR(cf.date_commande) IN ('.$db->sanitize($search_year).')';
}
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
if ($socid) {
$sql .= " AND cf.fk_soc = ".((int) $socid);
}
$sql .= " GROUP BY cf.rowid";
$sql .= $db->order($sortfield, $sortorder);
// Calcul total qty and amount for global if full scan list
$total_ht_pondere = 0;
$total_qty = 0;
// Count total nb of records
$totalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$totalofrecords = $db->num_rows($result);
}
$sql .= $db->plimit($limit + 1, $offset);
$result = $db->query($sql);
if ($result) {
$num = $db->num_rows($result);
$option .= '&id='.$object->id;
if ($limit > 0 && $limit != $conf->liste_limit) {
$option .= '&limit='.urlencode($limit);
}
if (!empty($search_month)) {
$option .= '&search_month='.urlencode($search_month);
}
if (!empty($search_year)) {
$option .= '&search_year='.urlencode($search_year);
}
print '<form method="post" action="'.$_SERVER ['PHP_SELF'].'?id='.$object->id.'" name="search_form">'."\n";
print '<input type="hidden" name="token" value="'.newToken().'">';
if (!empty($sortfield)) {
print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
}
if (!empty($sortorder)) {
print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
}
print_barre_liste($langs->trans("SuppliersOrders"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
if (!empty($page)) {
$option .= '&page='.urlencode($page);
}
print '<div class="liste_titre liste_titre_bydiv centpercent">';
print '<div class="divsearchfield">';
print $langs->trans('Period').' ('.$langs->trans("OrderDate").') - ';
print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
print '<div style="vertical-align: middle; display: inline-block">';
print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
print '</div>';
print '</div>';
print '</div>';
$i = 0;
print '<div class="div-table-responsive">';
print '<table class="tagtable liste listwithfilterbefore" width="100%">';
print '<tr class="liste_titre">';
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "s.rowid", "", $option, '', $sortfield, $sortorder);
print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
print_liste_field_titre("SupplierCode", $_SERVER["PHP_SELF"], "s.code_fournisseur", "", $option, '', $sortfield, $sortorder);
print_liste_field_titre("OrderDate", $_SERVER["PHP_SELF"], "cf.date_commande", "", $option, 'align="center"', $sortfield, $sortorder);
print_liste_field_titre("DateDeliveryPlanned", $_SERVER["PHP_SELF"], "cf.date_livraison", "", $option, 'align="center"', $sortfield, $sortorder);
print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "cfdi.qty", "", $option, 'align="center"', $sortfield, $sortorder);
// print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "total_ht_pondere", "", $option, 'align="right"', $sortfield, $sortorder);
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "cf.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
print "</tr>\n";
if ($num > 0) {
while ($i < min($num, $limit)) {
$objp = $db->fetch_object($result);
if ($objp->type == Facture::TYPE_CREDIT_NOTE) {
$objp->qty = -($objp->qty);
}
// $total_ht_pondere += $objp->total_ht_pondere;
$total_qty += $objp->qty;
$commandefournisseurstatic->id = $objp->facid;
$commandefournisseurstatic->ref = $objp->ref;
$societestatic->fetch($objp->socid);
// $paiement = $commandefournisseurstatic->getSommePaiement();
print '<tr class="oddeven">';
print '<td>';
print $commandefournisseurstatic->getNomUrl(1);
print "</td>\n";
print '<td>'.$societestatic->getNomUrl(1).'</td>';
print "<td>".$objp->code_fournisseur."</td>\n";
print '<td class="center">';
print dol_print_date($db->jdate($objp->date_commande), 'dayhour')."</td>";
print '<td class="center">';
print dol_print_date($db->jdate($objp->delivery_date), 'dayhour')."</td>";
print '<td class="center">'.$objp->qty."</td>\n";
// print '<td align="right">'.price($objp->total_ht_pondere)."</td>\n";
print '<td align="right">'.$commandefournisseurstatic->LibStatut($objp->statut, 5).'</td>';
print "</tr>\n";
$i++;
}
}
print '<tr class="liste_total">';
if ($num < $limit) {
print '<td class="left">'.$langs->trans("Total").'</td>';
} else {
print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
}
print '<td colspan="2"></td>';
print '<td></td>';
print '<td></td>';
print '<td class="center">'.$total_qty.'</td>';
// print '<td class="right">'.$total_ht_pondere.'</td>';
print '<td></td>';
print "</table>";
print '</div>';
print '</form>';
} else {
dol_print_error($db);
}
$db->free($result);
}
}
} else {
dol_print_error();
}
// End of page
llxFooter();
$db->close();

View File

@ -0,0 +1,370 @@
<?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/product/stock/stats/expedition.php
* \ingroup product service facture
* \brief Page of expedition statistics for a batch
*/
// Load Dolibarr environment
require '../../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
// Load translation files required by the page
$langs->loadLangs(array('companies', 'bills', 'products', 'supplier_proposal', 'productbatch'));
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$batch = GETPOST('batch', 'alpha');
$objectid = GETPOST('productid', 'int');
// Security check
$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
$socid = '';
if (!empty($user->socid)) {
$socid = $user->socid;
}
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('batchproductstatsexpedition'));
$showmessage = GETPOST('showmessage');
// Load variable for pagination
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "exp.date_creation";
}
$search_month = GETPOST('search_month', 'int');
$search_year = GETPOST('search_year', 'int');
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
$search_month = '';
$search_year = '';
}
if (!$user->rights->produit->lire) accessforbidden();
/*
* View
*/
$expeditionstatic = new Expedition($db);
$societestatic = new Societe($db);
$form = new Form($db);
$formother = new FormOther($db);
if ($id > 0 || !empty($ref)) {
$object = new ProductLot($db);
if ($ref) {
$tmp = explode('_', $ref);
$objectid = $tmp[0];
$batch = $tmp[1];
}
$result = $object->fetch($id, $objectid, $batch);
$parameters = array('id'=>$id);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$helpurl = '';
$shortlabel = dol_trunc($object->batch, 16);
$title = $langs->trans('Batch')." ".$shortlabel." - ".$langs->trans('Referers');
$helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
llxHeader('', $title, $helpurl);
if ($result > 0) {
$head = productlot_prepare_head($object);
$titre = $langs->trans("CardProduct".$object->type);
$picto = 'lot';
print dol_get_fiche_head($head, 'referers', $langs->trans("Batch"), -1, $object->picto);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$shownav = 1;
if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
$shownav = 0;
}
dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch', $morehtmlref);
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield" width="100%">';
// Product
print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
$producttmp = new Product($db);
$producttmp->fetch($object->fk_product);
print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
print '</td></tr>';
print "</table>";
echo '<br>';
// // Sell by
// if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
// print '<tr><td>';
// print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
// print '</td><td>';
// print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
// print '</td>';
// print '</tr>';
// }
//
// // Eat by
// if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
// print '<tr><td>';
// print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
// print '</td><td>';
// print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
// print '</td>';
// print '</tr>';
// }
//
// if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABOLITY)) {
// print '<tr><td>'.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).'</td>';
// print '<td>'.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
// print '</tr>';
// // print '<tr><td>'.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).'</td>';
// // print '<td>'.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
// // print '</tr>';
// print '<tr><td>'.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).'</td>';
// print '<td>'.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
// print '</tr>';
// }
//
// // Quality control
// if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
// print '<tr><td>'.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).'</td>';
// print '<td>'.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
// print '</tr>';
// print '<tr><td>'.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).'</td>';
// print '<td>'.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'numeric').'</td>';
// print '</tr>';
// }
//
// // Other attributes
// include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
print '<table class="border centpercent tableforfield" width="100%">';
$nboflines = show_stats_for_batch($object, $socid);
print "</table>";
print '</div>';
print '<div style="clear:both"></div>';
print dol_get_fiche_end();
if ($showmessage && $nboflines > 1) {
print '<span class="opacitymedium">'.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).'</span>';
} elseif ($user->rights->expedition->lire) {
$sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client,";
$sql .= " exp.ref, exp.date_creation, exp.fk_statut as statut, exp.rowid as facid,";
$sql .= " d.rowid, db.qty";
// $sql.= ", d.total_ht as total_ht"; // We must keep the d.rowid here to not loose record because of the distinct used to ignore duplicate line when link on societe_commerciaux is used
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ", sc.fk_soc, sc.fk_user ";
}
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."expedition as exp ON (exp.fk_soc = s.rowid)";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."expeditiondet as d ON (d.fk_expedition = exp.rowid)";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as db ON (db.fk_expeditiondet = d.rowid)";
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE exp.entity IN (".getEntity('product').")";
$sql .= " AND db.batch = '".($db->escape($object->batch))."'";
if (!empty($search_month)) {
$sql .= ' AND MONTH(exp.date_creation) IN ('.$db->sanitize($search_month).')';
}
if (!empty($search_year)) {
$sql .= ' AND YEAR(exp.date_creation) IN ('.$db->sanitize($search_year).')';
}
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
if ($socid) {
$sql .= " AND exp.fk_soc = ".((int) $socid);
}
$sql .= $db->order($sortfield, $sortorder);
// Calcul total qty and amount for global if full scan list
$total_ht = 0;
$total_qty = 0;
// Count total nb of records
$totalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$totalofrecords = $db->num_rows($result);
}
$sql .= $db->plimit($limit + 1, $offset);
$result = $db->query($sql);
if ($result) {
$num = $db->num_rows($result);
$option .= '&id='.$object->id;
if ($limit > 0 && $limit != $conf->liste_limit) {
$option .= '&limit='.urlencode($limit);
}
if (!empty($search_month)) {
$option .= '&search_month='.urlencode($search_month);
}
if (!empty($search_year)) {
$option .= '&search_year='.urlencode($search_year);
}
print '<form method="post" action="'.$_SERVER ['PHP_SELF'].'?id='.$object->id.'" name="search_form">'."\n";
print '<input type="hidden" name="token" value="'.newToken().'">';
if (!empty($sortfield)) {
print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
}
if (!empty($sortorder)) {
print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
}
print_barre_liste($langs->trans("Shipments"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
if (!empty($page)) {
$option .= '&page='.urlencode($page);
}
print '<div class="liste_titre liste_titre_bydiv centpercent">';
print '<div class="divsearchfield">';
print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - ';
print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
print '<div style="vertical-align: middle; display: inline-block">';
print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
print '</div>';
print '</div>';
print '</div>';
$i = 0;
print '<div class="div-table-responsive">';
print '<table class="tagtable liste listwithfilterbefore" width="100%">';
print '<tr class="liste_titre">';
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "s.rowid", "", $option, '', $sortfield, $sortorder);
print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", $option, '', $sortfield, $sortorder);
print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "exp.date_creation", "", $option, 'align="center"', $sortfield, $sortorder);
print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder);
// print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "d.total_ht", "", $option, 'align="right"', $sortfield, $sortorder);
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "exp.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
print "</tr>\n";
if ($num > 0) {
while ($i < min($num, $limit)) {
$objp = $db->fetch_object($result);
if ($objp->type == Facture::TYPE_CREDIT_NOTE) {
$objp->qty = -($objp->qty);
}
$total_ht += $objp->total_ht;
$total_qty += $objp->qty;
$expeditionstatic->id = $objp->facid;
$expeditionstatic->ref = $objp->ref;
$societestatic->fetch($objp->socid);
// $paiement = $expeditionstatic->getSommePaiement();
print '<tr class="oddeven">';
print '<td>';
print $expeditionstatic->getNomUrl(1);
print "</td>\n";
print '<td>'.$societestatic->getNomUrl(1).'</td>';
print "<td>".$objp->code_client."</td>\n";
print '<td class="center">';
print dol_print_date($db->jdate($objp->date_creation), 'dayhour')."</td>";
print '<td class="center">'.$objp->qty."</td>\n";
// print '<td align="right">'.price($objp->total_ht)."</td>\n";
print '<td align="right">'.$expeditionstatic->LibStatut($objp->statut, 5).'</td>';
print "</tr>\n";
$i++;
}
}
print '<tr class="liste_total">';
if ($num < $limit) {
print '<td class="left">'.$langs->trans("Total").'</td>';
} else {
print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
}
print '<td colspan="2"></td>';
print '<td></td>';
print '<td class="center">'.$total_qty.'</td>';
print '<td></td>';
print "</table>";
print '</div>';
print '</form>';
} else {
dol_print_error($db);
}
$db->free($result);
}
}
} else {
dol_print_error();
}
// End of page
llxFooter();
$db->close();

View File

@ -0,0 +1,321 @@
<?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2021 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/product/stats/mo.php
* \ingroup product mo
* \brief Page of MO referring product
*/
// Load Dolibarr environment
require '../../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
// Load translation files required by the page
$langs->loadLangs(array('mrp', 'products', 'companies', 'productbatch'));
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
// Security check
$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
if ($user->socid) {
$socid = $user->socid;
}
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('batchproductstatsmo'));
// Load variable for pagination
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "c.date_valid";
}
$search_month = GETPOST('search_month', 'int');
$search_year = GETPOST('search_year', 'int');
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
$search_month = '';
$search_year = '';
}
if (!$user->rights->produit->lire) accessforbidden();
/*
* View
*/
$staticmo = new Mo($db);
$staticmoligne = new MoLine($db);
$form = new Form($db);
$formother = new FormOther($db);
if ($id > 0 || !empty($ref)) {
$object = new ProductLot($db);
if ($ref) {
$tmp = explode('_', $ref);
$objectid = $tmp[0];
$batch = $tmp[1];
}
$result = $object->fetch($id, $objectid, $batch);
$parameters = array('id'=>$id);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$helpurl = '';
$shortlabel = dol_trunc($object->batch, 16);
$title = $langs->trans('Batch')." ".$shortlabel." - ".$langs->trans('Referers');
$helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
llxHeader('', $title, $helpurl);
if ($result > 0) {
$head = productlot_prepare_head($object);
$titre = $langs->trans("CardProduct".$object->type);
$picto = 'lot';
print dol_get_fiche_head($head, 'referers', $langs->trans("Batch"), -1, $object->picto);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$shownav = 1;
if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
$shownav = 0;
}
dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch', $morehtmlref);
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border tableforfield" width="100%">';
// Product
print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
$producttmp = new Product($db);
$producttmp->fetch($object->fk_product);
print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
print '</td></tr>';
print "</table>";
echo '<br>';
print '<table class="border centpercent tableforfield" width="100%">';
$nboflines = show_stats_for_batch($object, $socid);
print "</table>";
print '</div>';
print '<div style="clear:both"></div>';
print dol_get_fiche_end();
$now = dol_now();
$sql = "SELECT";
// $sql .= " sum(".$db->ifsql("cd.role='toconsume'", "cd.qty", 0).') as nb_toconsume,';
$sql .= " sum(".$db->ifsql("cd.role='consumed'", "cd.qty", 0).') as nb_consumed,';
// $sql .= " sum(".$db->ifsql("cd.role='toproduce'", "cd.qty", 0).') as nb_toproduce,';
$sql .= " sum(".$db->ifsql("cd.role='produced'", "cd.qty", 0).') as nb_produced,';
$sql .= " c.rowid as rowid, c.ref, c.date_valid, c.status";
//$sql .= " s.nom as name, s.rowid as socid, s.code_client";
$sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c";
$sql .= ", ".MAIN_DB_PREFIX."mrp_production as cd";
$sql .= " WHERE c.rowid = cd.fk_mo";
$sql .= " AND c.entity IN (".getEntity('mo').")";
$sql .= " AND cd.batch = '".($db->escape($object->batch))."'";
if (!empty($search_month)) {
$sql .= ' AND MONTH(c.date_valid) IN ('.$db->sanitize($search_month).')';
}
if (!empty($search_year)) {
$sql .= ' AND YEAR(c.date_valid) IN ('.$db->sanitize($search_year).')';
}
if ($socid) {
$sql .= " AND s.rowid = ".((int) $socid);
}
$sql .= " GROUP BY c.rowid, c.ref, c.date_valid, c.status";
//$sql .= ", s.nom, s.rowid, s.code_client";
$sql .= $db->order($sortfield, $sortorder);
//Calcul total qty and amount for global if full scan list
$total_ht = 0;
$total_qty = 0;
// Count total nb of records
$totalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$totalofrecords = $db->num_rows($result);
}
$sql .= $db->plimit($limit + 1, $offset);
$result = $db->query($sql);
if ($result) {
$num = $db->num_rows($result);
$option = '&id='.$object->id;
if ($limit > 0 && $limit != $conf->liste_limit) {
$option .= '&limit='.urlencode($limit);
}
if (!empty($search_month)) {
$option .= '&search_month='.urlencode($search_month);
}
if (!empty($search_year)) {
$option .= '&search_year='.urlencode($search_year);
}
print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" name="search_form">'."\n";
print '<input type="hidden" name="token" value="'.newToken().'">';
if (!empty($sortfield)) {
print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
}
if (!empty($sortorder)) {
print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
}
print_barre_liste($langs->trans("MOs"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
if (!empty($page)) {
$option .= '&page='.urlencode($page);
}
print '<div class="liste_titre liste_titre_bydiv centpercent">';
print '<div class="divsearchfield">';
print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - ';
print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
print '<div style="vertical-align: middle; display: inline-block">';
print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
print '</div>';
print '</div>';
print '</div>';
$i = 0;
print '<div class="div-table-responsive">';
print '<table class="tagtable liste listwithfilterbefore" width="100%">';
print '<tr class="liste_titre">';
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "c.rowid", "", $option."&amp;id=".$object->id, '', $sortfield, $sortorder);
//print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&amp;id=".$object->id, '', $sortfield, $sortorder);
print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "c.date_valid", "", $option."&amp;id=".$object->id, 'align="center"', $sortfield, $sortorder);
//print_liste_field_titre("AmountHT"),$_SERVER["PHP_SELF"],"c.amount","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
// print_liste_field_titre("ToConsume", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$object->id, '', $sortfield, $sortorder, 'center ');
print_liste_field_titre("QtyAlreadyConsumed", $_SERVER["PHP_SELF"], "", "", $option."&amp;id=".$object->id, '', $sortfield, $sortorder, 'center ');
// print_liste_field_titre("QtyToProduce", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$object->id, '', $sortfield, $sortorder, 'center ');
print_liste_field_titre("QtyAlreadyProduced", $_SERVER["PHP_SELF"], "", "", $option."&amp;id=".$object->id, '', $sortfield, $sortorder, 'center ');
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "c.status", "", $option."&amp;id=".$object->id, '', $sortfield, $sortorder, 'right ');
print "</tr>\n";
$motmp = new Mo($db);
$total_consumed=$total_produced=0;
if ($num > 0) {
while ($i < min($num, $limit)) {
$objp = $db->fetch_object($result);
$motmp->id = $objp->rowid;
$motmp->ref = $objp->ref;
$motmp->status = $objp->status;
$total_consumed+=$objp->nb_consumed;
$total_produced+=$objp->nb_produced;
print '<tr class="oddeven">';
print '<td>';
print $motmp->getNomUrl(1, 'production');
print "</td>\n";
print "<td align=\"center\">";
print dol_print_date($db->jdate($objp->date_valid), 'dayhour')."</td>";
//print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
//print '<td align="right">';
// print '<td class="center">'.($objp->nb_toconsume > 0 ? $objp->nb_toconsume : '').'</td>';
print '<td class="center">'.($objp->nb_consumed > 0 ? $objp->nb_consumed : '').'</td>';
// print '<td class="center">'.($objp->nb_toproduce > 0 ? $objp->nb_toproduce : '').'</td>';
print '<td class="center">'.($objp->nb_produced > 0 ? $objp->nb_produced : '').'</td>';
//$mostatic->LibStatut($objp->statut,5).'</td>';
print '<td class="right">'.$motmp->getLibStatut(2).'</td>';
print "</tr>\n";
$i++;
}
}
print '<tr class="liste_total">';
if ($num < $limit) {
print '<td class="left">'.$langs->trans("Total").'</td>';
} else {
print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
}
print '<td></td>';
print '<td class="center">'.$total_consumed.'</td>';
print '<td class="center">'.$total_produced.'</td>';
print '<td></td>';
print "</table>";
print '</div>';
print '</form>';
print '</table>';
print '</div>';
print '</form>';
} else {
dol_print_error($db);
}
$db->free($result);
}
} else {
dol_print_error();
}
// End of page
llxFooter();
$db->close();

View File

@ -0,0 +1,369 @@
<?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/product/stock/stats/reception.php
* \ingroup product service facture
* \brief Page of reception statistics for a batch
*/
// Load Dolibarr environment
require '../../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
// Load translation files required by the page
$langs->loadLangs(array('companies', 'bills', 'products', 'supplier_proposal', 'productbatch'));
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$batch = GETPOST('batch', 'alpha');
$objectid = GETPOST('productid', 'int');
// Security check
$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
$socid = '';
if (!empty($user->socid)) {
$socid = $user->socid;
}
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('batchproductstatsreception'));
$showmessage = GETPOST('showmessage');
// Load variable for pagination
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "recep.date_creation";
}
$search_month = GETPOST('search_month', 'int');
$search_year = GETPOST('search_year', 'int');
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
$search_month = '';
$search_year = '';
}
if (!$user->rights->produit->lire) accessforbidden();
/*
* View
*/
$receptionstatic = new Reception($db);
$societestatic = new Societe($db);
$form = new Form($db);
$formother = new FormOther($db);
if ($id > 0 || !empty($ref)) {
$object = new ProductLot($db);
if ($ref) {
$tmp = explode('_', $ref);
$objectid = $tmp[0];
$batch = $tmp[1];
}
$result = $object->fetch($id, $objectid, $batch);
$parameters = array('id'=>$id);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$title = $langs->trans('ProductServiceCard');
$helpurl = '';
$shortlabel = dol_trunc($object->batch, 16);
$title = $langs->trans('Batch')." ".$shortlabel." - ".$langs->trans('Referers');
llxHeader('', $title, $helpurl);
if ($result > 0) {
$head = productlot_prepare_head($object);
$titre = $langs->trans("CardProduct".$object->type);
$picto = 'lot';
print dol_get_fiche_head($head, 'referers', $langs->trans("Batch"), -1, $object->picto);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$shownav = 1;
if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
$shownav = 0;
}
dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch', $morehtmlref);
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield" width="100%">';
// Product
print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
$producttmp = new Product($db);
$producttmp->fetch($object->fk_product);
print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
print '</td></tr>';
print "</table>";
echo '<br>';
// // Sell by
// if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
// print '<tr><td>';
// print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
// print '</td><td>';
// print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
// print '</td>';
// print '</tr>';
// }
//
// // Eat by
// if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
// print '<tr><td>';
// print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
// print '</td><td>';
// print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
// print '</td>';
// print '</tr>';
// }
//
// if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABOLITY)) {
// print '<tr><td>'.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).'</td>';
// print '<td>'.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
// print '</tr>';
// // print '<tr><td>'.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).'</td>';
// // print '<td>'.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
// // print '</tr>';
// print '<tr><td>'.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).'</td>';
// print '<td>'.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
// print '</tr>';
// }
//
// // Quality control
// if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
// print '<tr><td>'.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).'</td>';
// print '<td>'.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
// print '</tr>';
// print '<tr><td>'.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).'</td>';
// print '<td>'.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'numeric').'</td>';
// print '</tr>';
// }
//
// // Other attributes
// include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
print '<table class="border centpercent tableforfield" width="100%">';
$nboflines = show_stats_for_batch($object, $socid);
print "</table>";
print '</div>';
print '<div style="clear:both"></div>';
print dol_get_fiche_end();
if ($showmessage && $nboflines > 1) {
print '<span class="opacitymedium">'.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).'</span>';
} elseif ($user->rights->reception->lire) {
$sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_fournisseur,";
$sql .= " recep.ref, recep.date_creation, recep.fk_statut as statut, recep.rowid as facid,";
$sql .= " d.qty";
// $sql.= ", d.total_ht as total_ht"; // We must keep the d.rowid here to not loose record because of the distinct used to ignore duplicate line when link on societe_commerciaux is used
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ", sc.fk_soc, sc.fk_user ";
}
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."reception as recep ON (recep.fk_soc = s.rowid)";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as d ON (d.fk_reception = recep.rowid)";
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE recep.entity IN (".getEntity('product').")";
$sql .= " AND d.batch = '".($db->escape($object->batch))."'";
if (!empty($search_month)) {
$sql .= ' AND MONTH(recep.date_creation) IN ('.$db->sanitize($search_month).')';
}
if (!empty($search_year)) {
$sql .= ' AND YEAR(recep.date_creation) IN ('.$db->sanitize($search_year).')';
}
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
if ($socid) {
$sql .= " AND recep.fk_soc = ".((int) $socid);
}
$sql .= $db->order($sortfield, $sortorder);
// Calcul total qty and amount for global if full scan list
$total_ht = 0;
$total_qty = 0;
// Count total nb of records
$totalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$totalofrecords = $db->num_rows($result);
}
$sql .= $db->plimit($limit + 1, $offset);
$result = $db->query($sql);
if ($result) {
$num = $db->num_rows($result);
$option .= '&id='.$object->id;
if ($limit > 0 && $limit != $conf->liste_limit) {
$option .= '&limit='.urlencode($limit);
}
if (!empty($search_month)) {
$option .= '&search_month='.urlencode($search_month);
}
if (!empty($search_year)) {
$option .= '&search_year='.urlencode($search_year);
}
print '<form method="post" action="'.$_SERVER ['PHP_SELF'].'?id='.$object->id.'" name="search_form">'."\n";
print '<input type="hidden" name="token" value="'.newToken().'">';
if (!empty($sortfield)) {
print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
}
if (!empty($sortorder)) {
print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
}
print_barre_liste($langs->trans("Receptions"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
if (!empty($page)) {
$option .= '&page='.urlencode($page);
}
print '<div class="liste_titre liste_titre_bydiv centpercent">';
print '<div class="divsearchfield">';
print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - ';
print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
print '<div style="vertical-align: middle; display: inline-block">';
print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
print '</div>';
print '</div>';
print '</div>';
$i = 0;
print '<div class="div-table-responsive">';
print '<table class="tagtable liste listwithfilterbefore" width="100%">';
print '<tr class="liste_titre">';
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "s.rowid", "", $option, '', $sortfield, $sortorder);
print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
print_liste_field_titre("SupplierCode", $_SERVER["PHP_SELF"], "s.code_fournisseur", "", $option, '', $sortfield, $sortorder);
print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "recep.date_creation", "", $option, 'align="center"', $sortfield, $sortorder);
print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder);
// print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "d.total_ht", "", $option, 'align="right"', $sortfield, $sortorder);
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "recep.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
print "</tr>\n";
if ($num > 0) {
while ($i < min($num, $limit)) {
$objp = $db->fetch_object($result);
if ($objp->type == Facture::TYPE_CREDIT_NOTE) {
$objp->qty = -($objp->qty);
}
$total_ht += $objp->total_ht;
$total_qty += $objp->qty;
$receptionstatic->id = $objp->facid;
$receptionstatic->ref = $objp->ref;
$societestatic->fetch($objp->socid);
// $paiement = $receptionstatic->getSommePaiement();
print '<tr class="oddeven">';
print '<td>';
print $receptionstatic->getNomUrl(1);
print "</td>\n";
print '<td>'.$societestatic->getNomUrl(1).'</td>';
print "<td>".$objp->code_fournisseur."</td>\n";
print '<td class="center">';
print dol_print_date($db->jdate($objp->date_creation), 'dayhour')."</td>";
print '<td class="center">'.$objp->qty."</td>\n";
// print '<td align="right">'.price($objp->total_ht)."</td>\n";
print '<td align="right">'.$receptionstatic->LibStatut($objp->statut, 5).'</td>';
print "</tr>\n";
$i++;
}
}
print '<tr class="liste_total">';
if ($num < $limit) {
print '<td class="left">'.$langs->trans("Total").'</td>';
} else {
print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
}
print '<td colspan="2"></td>';
print '<td></td>';
print '<td class="center">'.$total_qty.'</td>';
print '<td></td>';
print "</table>";
print '</div>';
print '</form>';
} else {
dol_print_error($db);
}
$db->free($result);
}
}
} else {
dol_print_error();
}
// End of page
llxFooter();
$db->close();