From 3b2d3dc6a6c67b50dfbd8f8481769aa113051d1f Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Fri, 17 Feb 2023 09:44:38 +0100 Subject: [PATCH] NEW : batch referential objets --- htdocs/core/lib/product.lib.php | 130 ++++++ htdocs/product/stats/mo.php | 28 ++ .../product/stock/class/productlot.class.php | 283 +++++++++++++ .../stock/stats/commande_fournisseur.php | 375 ++++++++++++++++++ htdocs/product/stock/stats/expedition.php | 369 +++++++++++++++++ htdocs/product/stock/stats/mo.php | 302 ++++++++++++++ htdocs/product/stock/stats/reception.php | 368 +++++++++++++++++ 7 files changed, 1855 insertions(+) create mode 100644 htdocs/product/stock/stats/commande_fournisseur.php create mode 100644 htdocs/product/stock/stats/expedition.php create mode 100644 htdocs/product/stock/stats/mo.php create mode 100644 htdocs/product/stock/stats/reception.php diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index e919bf2c8b6..4898ff96cc2 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -253,6 +253,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 +653,131 @@ function show_stats_for_company($product, $socid) return $nblines++; } +/** + * Show stats for company + * + * @param Product $product Product 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->load_stats_expedition($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->load_stats_reception($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->load_stats_supplier_order($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->load_stats_mo($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..3127f9e83a6 100644 --- a/htdocs/product/stats/mo.php +++ b/htdocs/product/stats/mo.php @@ -28,6 +28,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 +64,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 +83,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 +149,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 +206,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 6fe855543c9..c20f224a584 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -554,6 +554,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 load_stats_expedition($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->load_stats_expedition($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 load_stats_supplier_order($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 load_stats_reception($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->load_stats_expedition($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 load_stats_mo($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..a8a5d529b53 --- /dev/null +++ b/htdocs/product/stock/stats/commande_fournisseur.php @@ -0,0 +1,375 @@ + + * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2014 Florian Henry + * + * 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..f675f5745fb --- /dev/null +++ b/htdocs/product/stock/stats/expedition.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 + * + * 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..5a54ad9b75a --- /dev/null +++ b/htdocs/product/stock/stats/mo.php @@ -0,0 +1,302 @@ + + * Copyright (C) 2004-2021 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin + * + * 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); + + 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; + + print ''; + print '\n"; + print ""; + //print "\n"; + //print ''; + print ''; +// print ''; + print ''; + //$mostatic->LibStatut($objp->statut,5).''; + print ''; + print "\n"; + $i++; + } + } + + 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).'
'; + 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..f289c469a6d --- /dev/null +++ b/htdocs/product/stock/stats/reception.php @@ -0,0 +1,368 @@ + + * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2014 Florian Henry + * + * 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();