diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index fd60a6a84a4..54510bd3fae 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -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 ''; + print ''; } // Project label if (!empty($arrayfields['p.title']['checked'])) { - print ''; + print ''; } // Thirdparty if (!empty($arrayfields['s.nom']['checked'])) { - print ' 0 ? " disabled" : "").'>'; + print ' 0 ? " disabled" : "").'>'; } // Alias if (!empty($arrayfields['s.name_alias']['checked'])) { - print ''; + print ''; } // Parent company if (!empty($arrayfields['s2.nom']['checked'])) { @@ -1402,6 +1407,10 @@ if ($resql) { print ''; print ''; } + // Customer Code + if (!empty($arrayfields['s.code_client']['checked'])) { + print ''; + } // Town if (!empty($arrayfields['s.town']['checked'])) { print ''; @@ -1467,13 +1476,13 @@ if ($resql) { if (!empty($arrayfields['f.total_localtax1']['checked'])) { // Localtax1 print ''; - print ''; + print ''; print ''; } if (!empty($arrayfields['f.total_localtax2']['checked'])) { // Localtax2 print ''; - print ''; + print ''; print ''; } 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 ''; + print dol_escape_htmltag($companystatic->code_client); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } // Town if (!empty($arrayfields['s.town']['checked'])) { print ''; diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 8fc0ce26f7d..ed3f8d7a4a3 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -4,6 +4,7 @@ * Copyright (C) 2009-2010 Regis Houssin * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2015-2016 Marcos García + * Copyright (C) 2023 Gauthier VERDOL * * 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 ''; + print ''.$langs->trans("Referers").''; + print ''.$langs->trans("NbOfThirdParties").''; + print ''.$langs->trans("NbOfObjectReferers").''; + print ''.$langs->trans("TotalQuantity").''; + print ''; + + // 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 ''; + print ''.img_object('', 'bill', 'class="pictofixedwidth"').$langs->trans("Shipments").''; + print ''; + print $batch->stats_expedition['customers']; + print ''; + print $batch->stats_expedition['nb']; + print ''; + print $batch->stats_expedition['qty']; + print ''; + print ''; + } + + if (isModEnabled("reception") && !empty($user->rights->reception->lire)) { + $nblines++; + $ret = $batch->loadStatsReception($socid); + if ($ret < 0) { + dol_print_error($db); + } + $langs->load("bills"); + print ''; + print ''.img_object('', 'bill', 'class="pictofixedwidth"').$langs->trans("Receptions").''; + print ''; + print $batch->stats_reception['customers']; + print ''; + print $batch->stats_reception['nb']; + print ''; + print $batch->stats_reception['qty']; + print ''; + print ''; + } 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 ''; + print ''.img_object('', 'bill', 'class="pictofixedwidth"').$langs->trans("SuppliersOrders").''; + print ''; + print $batch->stats_supplier_order['customers']; + print ''; + print $batch->stats_supplier_order['nb']; + print ''; + print $batch->stats_supplier_order['qty']; + print ''; + print ''; + } + + if (isModEnabled('mrp') && !empty($user->rights->mrp->read)) { + $nblines++; + $ret = $batch->loadStatsMo($socid); + if ($ret < 0) { + dol_print_error($db); + } + $langs->load("mrp"); + print ''; + print ''.img_object('', 'mrp', 'class="pictofixedwidth"').$langs->trans("MO").''; + print ''; + // 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 ''; + // 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 ''; + // 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 ''; + print ''; + } + + $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. diff --git a/htdocs/product/stats/mo.php b/htdocs/product/stats/mo.php index 085a6687f5c..b401b40bc9e 100644 --- a/htdocs/product/stats/mo.php +++ b/htdocs/product/stats/mo.php @@ -2,6 +2,7 @@ /* Copyright (C) 2003-2007 Rodolphe Quiedeville * Copyright (C) 2004-2021 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2023 Gauthier VERDOL * * 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 '
'; + print '
'; + print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - '; + print $langs->trans('Month').': '; + print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5); + print '
'; + print ''; + print ''; + print '
'; + print '
'; + print '
'; + $i = 0; print '
'; print ''; diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php index 371eb85c040..7d12acae368 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2015 Florian Henry * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2018-2022 Frédéric France + * Copyright (C) 2023 Gauthier VERDOL * * 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 diff --git a/htdocs/product/stock/stats/commande_fournisseur.php b/htdocs/product/stock/stats/commande_fournisseur.php new file mode 100644 index 00000000000..e8f8463493f --- /dev/null +++ b/htdocs/product/stock/stats/commande_fournisseur.php @@ -0,0 +1,376 @@ + + * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2014 Florian Henry + * Copyright (C) 2023 Gauthier VERDOL + * + * 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 . + */ + +/** + * \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ó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 = ''.$langs->trans("BackToList").''; + + $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 '
'; + + print '
'; + print '
'; + + + // Product + print ''; + print "
'.$langs->trans("Product").''; + $producttmp = new Product($db); + $producttmp->fetch($object->fk_product); + print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label; + print '
"; + + echo '
'; + + // // Sell by + // if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { + // print ''; + // print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker'); + // print ''; + // print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker'); + // print ''; + // print ''; + // } + // + // // Eat by + // if (empty($conf->global->PRODUCT_DISABLE_EATBY)) { + // print ''; + // print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker'); + // print ''; + // print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker'); + // print ''; + // print ''; + // } + // + // if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABOLITY)) { + // print ''.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).''; + // print ''.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').''; + // print ''; + // // print ''.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).''; + // // print ''.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').''; + // // print ''; + // print ''.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).''; + // print ''.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').''; + // print ''; + // } + // + // // Quality control + // if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) { + // print ''.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).''; + // print ''.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').''; + // print ''; + // print ''.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).''; + // print ''.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'numeric').''; + // print ''; + // } + // + // // Other attributes + // include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + print ''; + + $nboflines = show_stats_for_batch($object, $socid); + + print "
"; + + print '
'; + print '
'; + + print dol_get_fiche_end(); + + if ($showmessage && $nboflines > 1) { + print ''.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).''; + } 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 '
'."\n"; + print ''; + if (!empty($sortfield)) { + print ''; + } + if (!empty($sortorder)) { + print ''; + } + + 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 '
'; + print '
'; + print $langs->trans('Period').' ('.$langs->trans("OrderDate").') - '; + print $langs->trans('Month').': '; + print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5); + print '
'; + print ''; + print ''; + print '
'; + print '
'; + print '
'; + + $i = 0; + print '
'; + print ''; + print ''; + 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 "\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 ''; + print '\n"; + print ''; + print "\n"; + print '"; + print '"; + print '\n"; + // print '\n"; + print ''; + print "\n"; + $i++; + } + } + print ''; + if ($num < $limit) { + print ''; + } else { + print ''; + } + print ''; + print ''; + print ''; + print ''; + // print ''; + print ''; + print "
'; + print $commandefournisseurstatic->getNomUrl(1); + print "'.$societestatic->getNomUrl(1).'".$objp->code_fournisseur."'; + print dol_print_date($db->jdate($objp->date_commande), 'dayhour')."'; + print dol_print_date($db->jdate($objp->delivery_date), 'dayhour')."'.$objp->qty."'.price($objp->total_ht_pondere)."'.$commandefournisseurstatic->LibStatut($objp->statut, 5).'
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$total_qty.''.$total_ht_pondere.'
"; + print '
'; + print '
'; + } else { + dol_print_error($db); + } + $db->free($result); + } + } +} else { + dol_print_error(); +} + +// End of page +llxFooter(); +$db->close(); diff --git a/htdocs/product/stock/stats/expedition.php b/htdocs/product/stock/stats/expedition.php new file mode 100644 index 00000000000..b18bee897e4 --- /dev/null +++ b/htdocs/product/stock/stats/expedition.php @@ -0,0 +1,370 @@ + + * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2014 Florian Henry + * Copyright (C) 2023 Gauthier VERDOL + * + * 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 . + */ + +/** + * \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ó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 = ''.$langs->trans("BackToList").''; + + $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 '
'; + + print '
'; + print ''; + + + // Product + print ''; + print "
'.$langs->trans("Product").''; + $producttmp = new Product($db); + $producttmp->fetch($object->fk_product); + print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label; + print '
"; + + echo '
'; + + // // Sell by + // if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { + // print ''; + // print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker'); + // print ''; + // print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker'); + // print ''; + // print ''; + // } + // + // // Eat by + // if (empty($conf->global->PRODUCT_DISABLE_EATBY)) { + // print ''; + // print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker'); + // print ''; + // print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker'); + // print ''; + // print ''; + // } + // + // if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABOLITY)) { + // print ''.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).''; + // print ''.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').''; + // print ''; + // // print ''.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).''; + // // print ''.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').''; + // // print ''; + // print ''.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).''; + // print ''.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').''; + // print ''; + // } + // + // // Quality control + // if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) { + // print ''.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).''; + // print ''.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').''; + // print ''; + // print ''.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).''; + // print ''.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'numeric').''; + // print ''; + // } + // + // // Other attributes + // include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + print ''; + + $nboflines = show_stats_for_batch($object, $socid); + + print "
"; + + print '
'; + print '
'; + + print dol_get_fiche_end(); + + if ($showmessage && $nboflines > 1) { + print ''.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).''; + } 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 '
'."\n"; + print ''; + if (!empty($sortfield)) { + print ''; + } + if (!empty($sortorder)) { + print ''; + } + + 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 '
'; + print '
'; + print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - '; + print $langs->trans('Month').': '; + print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5); + print '
'; + print ''; + print ''; + print '
'; + print '
'; + print '
'; + + $i = 0; + print '
'; + print ''; + print ''; + 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 "\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 ''; + print '\n"; + print ''; + print "\n"; + print '"; + print '\n"; + // print '\n"; + print ''; + print "\n"; + $i++; + } + } + print ''; + if ($num < $limit) { + print ''; + } else { + print ''; + } + print ''; + print ''; + print ''; + print ''; + print "
'; + print $expeditionstatic->getNomUrl(1); + print "'.$societestatic->getNomUrl(1).'".$objp->code_client."'; + print dol_print_date($db->jdate($objp->date_creation), 'dayhour')."'.$objp->qty."'.price($objp->total_ht)."'.$expeditionstatic->LibStatut($objp->statut, 5).'
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$total_qty.'
"; + print '
'; + print '
'; + } else { + dol_print_error($db); + } + $db->free($result); + } + } +} else { + dol_print_error(); +} + +// End of page +llxFooter(); +$db->close(); diff --git a/htdocs/product/stock/stats/mo.php b/htdocs/product/stock/stats/mo.php new file mode 100644 index 00000000000..06fcad417c7 --- /dev/null +++ b/htdocs/product/stock/stats/mo.php @@ -0,0 +1,321 @@ + + * Copyright (C) 2004-2021 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2023 Gauthier VERDOL + * + * 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 . + */ + +/** + * \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ó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 = ''.$langs->trans("BackToList").''; + + $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 '
'; + + print '
'; + print ''; + + // Product + print ''; + print "
'.$langs->trans("Product").''; + $producttmp = new Product($db); + $producttmp->fetch($object->fk_product); + print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label; + print '
"; + + echo '
'; + + print ''; + + $nboflines = show_stats_for_batch($object, $socid); + + print "
"; + + print '
'; + print '
'; + + 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 '
'."\n"; + print ''; + if (!empty($sortfield)) { + print ''; + } + if (!empty($sortorder)) { + print ''; + } + + 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 '
'; + print '
'; + print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - '; + print $langs->trans('Month').': '; + print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5); + print '
'; + print ''; + print ''; + print '
'; + print '
'; + print '
'; + + $i = 0; + print '
'; + print ''; + + print ''; + + print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "c.rowid", "", $option."&id=".$object->id, '', $sortfield, $sortorder); + //print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&id=".$object->id, '', $sortfield, $sortorder); + print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "c.date_valid", "", $option."&id=".$object->id, 'align="center"', $sortfield, $sortorder); + //print_liste_field_titre("AmountHT"),$_SERVER["PHP_SELF"],"c.amount","","&id=".$object->id,'align="right"',$sortfield,$sortorder); + // print_liste_field_titre("ToConsume", $_SERVER["PHP_SELF"], "", "", "&id=".$object->id, '', $sortfield, $sortorder, 'center '); + print_liste_field_titre("QtyAlreadyConsumed", $_SERVER["PHP_SELF"], "", "", $option."&id=".$object->id, '', $sortfield, $sortorder, 'center '); + // print_liste_field_titre("QtyToProduce", $_SERVER["PHP_SELF"], "", "", "&id=".$object->id, '', $sortfield, $sortorder, 'center '); + print_liste_field_titre("QtyAlreadyProduced", $_SERVER["PHP_SELF"], "", "", $option."&id=".$object->id, '', $sortfield, $sortorder, 'center '); + print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "c.status", "", $option."&id=".$object->id, '', $sortfield, $sortorder, 'right '); + print "\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 ''; + print '\n"; + print ""; + //print "\n"; + //print ''; + print ''; + // print ''; + print ''; + //$mostatic->LibStatut($objp->statut,5).''; + print ''; + print "\n"; + $i++; + } + } + print ''; + if ($num < $limit) { + print ''; + } else { + print ''; + } + print ''; + print ''; + print ''; + print ''; + print "
'; + print $motmp->getNomUrl(1, 'production'); + print ""; + print dol_print_date($db->jdate($objp->date_valid), 'dayhour')."".price($objp->total_ht)."'; + // print ''.($objp->nb_toconsume > 0 ? $objp->nb_toconsume : '').''.($objp->nb_consumed > 0 ? $objp->nb_consumed : '').''.($objp->nb_toproduce > 0 ? $objp->nb_toproduce : '').''.($objp->nb_produced > 0 ? $objp->nb_produced : '').''.$motmp->getLibStatut(2).'
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$total_consumed.''.$total_produced.'
"; + print '
'; + print '
'; + + print ''; + print ''; + print ''; + } else { + dol_print_error($db); + } + $db->free($result); + } +} else { + dol_print_error(); +} + +// End of page +llxFooter(); +$db->close(); diff --git a/htdocs/product/stock/stats/reception.php b/htdocs/product/stock/stats/reception.php new file mode 100644 index 00000000000..ec54553ed07 --- /dev/null +++ b/htdocs/product/stock/stats/reception.php @@ -0,0 +1,369 @@ + + * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2014 Florian Henry + * Copyright (C) 2023 Gauthier VERDOL + * + * 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 . + */ + +/** + * \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 = ''.$langs->trans("BackToList").''; + + $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 '
'; + + print '
'; + print ''; + + + // Product + print ''; + print "
'.$langs->trans("Product").''; + $producttmp = new Product($db); + $producttmp->fetch($object->fk_product); + print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label; + print '
"; + + echo '
'; + + // // Sell by + // if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { + // print ''; + // print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker'); + // print ''; + // print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker'); + // print ''; + // print ''; + // } + // + // // Eat by + // if (empty($conf->global->PRODUCT_DISABLE_EATBY)) { + // print ''; + // print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker'); + // print ''; + // print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker'); + // print ''; + // print ''; + // } + // + // if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABOLITY)) { + // print ''.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).''; + // print ''.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').''; + // print ''; + // // print ''.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).''; + // // print ''.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').''; + // // print ''; + // print ''.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).''; + // print ''.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').''; + // print ''; + // } + // + // // Quality control + // if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) { + // print ''.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).''; + // print ''.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').''; + // print ''; + // print ''.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).''; + // print ''.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'numeric').''; + // print ''; + // } + // + // // Other attributes + // include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + print ''; + + $nboflines = show_stats_for_batch($object, $socid); + + print "
"; + + print '
'; + print '
'; + + print dol_get_fiche_end(); + + if ($showmessage && $nboflines > 1) { + print ''.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).''; + } 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 '
'."\n"; + print ''; + if (!empty($sortfield)) { + print ''; + } + if (!empty($sortorder)) { + print ''; + } + + 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 '
'; + print '
'; + print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - '; + print $langs->trans('Month').': '; + print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5); + print '
'; + print ''; + print ''; + print '
'; + print '
'; + print '
'; + + $i = 0; + print '
'; + print ''; + print ''; + 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 "\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 ''; + print '\n"; + print ''; + print "\n"; + print '"; + print '\n"; + // print '\n"; + print ''; + print "\n"; + $i++; + } + } + print ''; + if ($num < $limit) { + print ''; + } else { + print ''; + } + print ''; + print ''; + print ''; + print ''; + print "
'; + print $receptionstatic->getNomUrl(1); + print "'.$societestatic->getNomUrl(1).'".$objp->code_fournisseur."'; + print dol_print_date($db->jdate($objp->date_creation), 'dayhour')."'.$objp->qty."'.price($objp->total_ht)."'.$receptionstatic->LibStatut($objp->statut, 5).'
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$total_qty.'
"; + print '
'; + print '
'; + } else { + dol_print_error($db); + } + $db->free($result); + } + } +} else { + dol_print_error(); +} + +// End of page +llxFooter(); +$db->close();