2018-10-03 12:22:41 +02:00
< ? php
2019-06-18 14:07:52 +02:00
/* Copyright ( C ) 2003 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
* Copyright ( C ) 2018 Quentin Vial - Gouteyron < quentin . vial - gouteyron @ atm - consulting . fr >
* Copyright ( C ) 2019 Nicolas ZABOURI < info @ inovea - conseil . com >
2024-11-04 23:53:20 +01:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2018-10-03 12:22:41 +02:00
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2018-10-03 12:22:41 +02:00
*/
/**
2018-10-08 12:15:17 +02:00
* \file htdocs / reception / index . php
* \ingroup reception
* \brief Home page of reception area .
2018-10-03 12:22:41 +02:00
*/
2022-09-07 20:08:59 +02:00
// Load Dolibarr environment
2018-10-03 12:22:41 +02:00
require '../main.inc.php' ;
2018-10-08 12:15:17 +02:00
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/reception/class/reception.class.php' ;
2018-10-03 12:22:41 +02:00
2024-11-04 23:53:20 +01:00
/**
* @ var Conf $conf
* @ var DoliDB $db
* @ var HookManager $hookmanager
* @ var Translate $langs
* @ var User $user
*/
2019-06-18 14:07:52 +02:00
2024-06-30 21:02:50 +02:00
// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
2019-06-18 14:07:52 +02:00
$hookmanager -> initHooks ( array ( 'receptionindex' ));
2020-03-23 19:35:14 +01:00
$langs -> loadLangs ( array ( " orders " , " receptions " ));
2018-10-03 12:22:41 +02:00
2021-03-27 15:49:18 +01:00
$reception = new Reception ( $db );
// Security check
2021-12-01 15:40:53 +01:00
$socid = '' ;
2021-03-27 15:49:18 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
$result = restrictedArea ( $user , 'reception' , 0 , '' );
2018-10-03 12:22:41 +02:00
/*
* View
*/
2020-04-10 10:59:32 +02:00
$orderstatic = new CommandeFournisseur ( $db );
$companystatic = new Societe ( $db );
2018-10-03 12:22:41 +02:00
2020-04-10 10:59:32 +02:00
$helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:Módulo_Receptiones' ;
2024-06-08 18:53:19 +02:00
llxHeader ( '' , $langs -> trans ( " Reception " ), $helpurl , '' , 0 , 0 , '' , '' , '' , 'mod-reception page-dashboard' );
2018-10-03 12:22:41 +02:00
2020-04-20 15:57:15 +02:00
print load_fiche_titre ( $langs -> trans ( " ReceptionsArea " ), '' , 'dollyrevert' );
2018-10-03 12:22:41 +02:00
print '<div class="fichecenter"><div class="fichethirdleft">' ;
2023-11-27 11:56:32 +01:00
if ( getDolGlobalString ( 'MAIN_SEARCH_FORM_ON_HOME_AREAS' )) { // This may be useless due to the global search combo
2020-10-31 14:32:18 +01:00
print '<form method="post" action="list.php">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<div class="div-table-responsive-no-min">' ;
print '<table class="noborder nohover centpercent">' ;
print '<tr class="liste_titre"><td colspan="3">' . $langs -> trans ( " Search " ) . '</td></tr>' ;
print '<tr class="oddeven"><td>' ;
print $langs -> trans ( " Reception " ) . ':</td><td><input type="text" class="flat" name="sall" size="18"></td><td><input type="submit" value="' . $langs -> trans ( " Search " ) . '" class="button"></td></tr>' ;
print " </table></div></form><br> \n " ;
2018-10-03 12:22:41 +02:00
}
2020-03-23 19:35:14 +01:00
2018-10-03 12:22:41 +02:00
/*
2020-03-23 19:35:14 +01:00
* Draft receptions
2018-10-03 12:22:41 +02:00
*/
2020-03-23 19:35:14 +01:00
2018-10-08 12:15:17 +02:00
$sql = " SELECT e.rowid, e.ref, e.ref_supplier, " ;
2020-04-10 10:59:32 +02:00
$sql .= " s.nom as name, s.rowid as socid, " ;
$sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " reception as e " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception' " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " commande_fournisseur as c ON el.fk_source = c.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON s.rowid = e.fk_soc " ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2024-02-29 00:52:56 +01:00
$sql .= " AND EXISTS (SELECT sc.fk_soc FROM " . MAIN_DB_PREFIX . " societe_commerciaux as sc WHERE sc.fk_soc = e.fk_soc AND sc.fk_user = " . (( int ) $user -> id ) . " ) " ;
2018-10-03 12:22:41 +02:00
}
2024-02-29 00:52:56 +01:00
$sql .= " WHERE e.fk_statut = 0 " ;
2020-04-10 10:59:32 +02:00
$sql .= " AND e.entity IN ( " . getEntity ( 'reception' ) . " ) " ;
2021-02-26 20:53:03 +01:00
if ( $socid ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND c.fk_soc = " . (( int ) $socid );
2021-02-26 20:53:03 +01:00
}
2018-10-03 12:22:41 +02:00
2020-04-10 10:59:32 +02:00
$resql = $db -> query ( $sql );
2021-02-26 20:53:03 +01:00
if ( $resql ) {
2020-03-23 19:35:14 +01:00
print '<div class="div-table-responsive-no-min">' ;
print '<table class="noborder centpercent">' ;
print '<tr class="liste_titre">' ;
print '<th colspan="3">' . $langs -> trans ( " ReceptionsToValidate " ) . '</th></tr>' ;
2018-10-03 12:22:41 +02:00
$num = $db -> num_rows ( $resql );
2021-02-26 20:53:03 +01:00
if ( $num ) {
2018-10-03 12:22:41 +02:00
$i = 0 ;
2021-02-26 20:53:03 +01:00
while ( $i < $num ) {
2018-10-03 12:22:41 +02:00
$obj = $db -> fetch_object ( $resql );
2018-12-15 13:58:39 +01:00
2020-04-10 10:59:32 +02:00
$reception -> id = $obj -> rowid ;
$reception -> ref = $obj -> ref ;
$reception -> ref_supplier = $obj -> ref_supplier ;
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
print '<tr class="oddeven"><td class="nowrap">' ;
2018-10-08 12:15:17 +02:00
print $reception -> getNomUrl ( 1 );
2018-10-03 12:22:41 +02:00
print " </td> " ;
print '<td>' ;
print '<a href="' . DOL_URL_ROOT . '/comm/card.php?socid=' . $obj -> socid . '">' . $obj -> name . '</a>' ;
print '</td>' ;
print '<td>' ;
2021-02-26 20:53:03 +01:00
if ( $obj -> commande_fournisseur_id ) {
print '<a href="' . DOL_URL_ROOT . '/commande_fournisseur/card.php?id=' . $obj -> commande_fournisseur_id . '">' . $obj -> commande_fournisseur_ref . '</a>' ;
}
2018-10-03 12:22:41 +02:00
print '</td></tr>' ;
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-03-27 16:02:58 +01:00
print '<tr><td><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td><td></td><td></td></tr>' ;
2020-03-23 19:35:14 +01:00
}
print " </table></div><br> " ;
2018-10-03 12:22:41 +02:00
}
2021-10-24 00:37:37 +02:00
print '</div><div class="fichetwothirdright">' ;
2020-03-23 19:35:14 +01:00
$max = 5 ;
2018-10-03 12:22:41 +02:00
/*
2020-03-23 19:35:14 +01:00
* Latest receptions
2018-10-03 12:22:41 +02:00
*/
2020-03-23 19:35:14 +01:00
$sql = " SELECT e.rowid, e.ref, e.ref_supplier, " ;
2020-04-10 10:59:32 +02:00
$sql .= " s.nom as name, s.rowid as socid, " ;
$sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " reception as e " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception' AND el.sourcetype IN ('order_supplier') " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " commande_fournisseur as c ON el.fk_source = c.rowid AND el.sourcetype IN ('order_supplier') AND el.targettype = 'reception' " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON s.rowid = e.fk_soc " ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2021-02-26 20:53:03 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe_commerciaux as sc ON e.fk_soc = sc.fk_soc " ;
}
2020-04-10 10:59:32 +02:00
$sql .= " WHERE e.entity IN ( " . getEntity ( 'reception' ) . " ) " ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2021-08-23 17:41:11 +02:00
$sql .= " AND sc.fk_user = " . (( int ) $user -> id );
2021-02-26 20:53:03 +01:00
}
2020-04-10 10:59:32 +02:00
$sql .= " AND e.fk_statut = 1 " ;
2021-02-26 20:53:03 +01:00
if ( $socid ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND c.fk_soc = " . (( int ) $socid );
2021-02-26 20:53:03 +01:00
}
2020-04-10 10:59:32 +02:00
$sql .= " ORDER BY e.date_delivery DESC " ;
$sql .= $db -> plimit ( $max , 0 );
2020-03-23 19:35:14 +01:00
$resql = $db -> query ( $sql );
2021-02-26 20:53:03 +01:00
if ( $resql ) {
2018-10-03 12:22:41 +02:00
$num = $db -> num_rows ( $resql );
2021-02-26 20:53:03 +01:00
if ( $num ) {
2018-10-03 12:22:41 +02:00
$i = 0 ;
2020-03-23 19:35:14 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2018-10-03 12:22:41 +02:00
print '<tr class="liste_titre">' ;
2020-03-23 19:35:14 +01:00
print '<th colspan="3">' . $langs -> trans ( " LastReceptions " , $num ) . '</th></tr>' ;
2021-02-26 20:53:03 +01:00
while ( $i < $num ) {
2018-10-03 12:22:41 +02:00
$obj = $db -> fetch_object ( $resql );
2020-04-10 10:59:32 +02:00
$reception -> id = $obj -> rowid ;
$reception -> ref = $obj -> ref ;
$reception -> ref_supplier = $obj -> ref_supplier ;
2018-12-15 13:58:39 +01:00
2020-03-23 19:35:14 +01:00
print '<tr class="oddeven"><td>' ;
print $reception -> getNomUrl ( 1 );
2018-10-03 12:22:41 +02:00
print '</td>' ;
2020-03-23 19:35:14 +01:00
print '<td><a href="' . DOL_URL_ROOT . '/comm/card.php?socid=' . $obj -> socid . '">' . img_object ( $langs -> trans ( " ShowCompany " ), " company " ) . ' ' . $obj -> name . '</a></td>' ;
2018-10-03 12:22:41 +02:00
print '<td>' ;
2021-02-26 20:53:03 +01:00
if ( $obj -> commande_fournisseur_id > 0 ) {
2020-04-10 10:59:32 +02:00
$orderstatic -> id = $obj -> commande_fournisseur_id ;
$orderstatic -> ref = $obj -> commande_fournisseur_ref ;
2020-03-23 19:35:14 +01:00
print $orderstatic -> getNomUrl ( 1 );
2021-02-26 20:53:03 +01:00
} else {
print ' ' ;
}
2020-03-23 19:35:14 +01:00
print '</td></tr>' ;
2018-10-03 12:22:41 +02:00
$i ++ ;
}
2019-10-30 18:44:53 +01:00
print " </table></div><br> " ;
2018-10-03 12:22:41 +02:00
}
2020-03-23 19:35:14 +01:00
$db -> free ( $resql );
2021-02-26 20:53:03 +01:00
} else {
dol_print_error ( $db );
}
2018-10-03 12:22:41 +02:00
/*
2020-03-27 16:02:58 +01:00
* Open pruchase orders to process
2018-10-03 12:22:41 +02:00
*/
2020-03-23 19:35:14 +01:00
2018-10-08 12:15:17 +02:00
$sql = " SELECT c.rowid, c.ref, c.ref_supplier as ref_supplier, c.fk_statut as status, c.billed as billed, s.nom as name, s.rowid as socid " ;
2020-04-10 10:59:32 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " commande_fournisseur as c, " ;
$sql .= " " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " WHERE c.fk_soc = s.rowid " ;
$sql .= " AND c.entity IN ( " . getEntity ( 'supplier_order' ) . " ) " ;
$sql .= " AND c.fk_statut IN ( " . CommandeFournisseur :: STATUS_ORDERSENT . " , " . CommandeFournisseur :: STATUS_RECEIVED_PARTIALLY . " ) " ;
2021-02-26 20:53:03 +01:00
if ( $socid > 0 ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND c.fk_soc = " . (( int ) $socid );
2021-02-26 20:53:03 +01:00
}
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2024-02-29 00:52:56 +01:00
$sql .= " AND EXISTS (SELECT sc.fk_soc FROM " . MAIN_DB_PREFIX . " societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = " . (( int ) $user -> id ) . " ) " ;
2021-02-26 20:53:03 +01:00
}
2020-04-10 10:59:32 +02:00
$sql .= " ORDER BY c.rowid ASC " ;
$resql = $db -> query ( $sql );
2021-02-26 20:53:03 +01:00
if ( $resql ) {
2018-10-03 12:22:41 +02:00
$num = $db -> num_rows ( $resql );
2021-02-26 20:53:03 +01:00
if ( $num ) {
2020-03-23 19:35:14 +01:00
$langs -> load ( " orders " );
2018-10-03 12:22:41 +02:00
$i = 0 ;
2020-10-31 14:32:18 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2018-10-03 12:22:41 +02:00
print '<tr class="liste_titre">' ;
2024-02-29 00:52:56 +01:00
print '<th colspan="3">' . $langs -> trans ( " SuppliersOrdersToProcess " );
print ' <a href="' . DOL_URL_ROOT . '/reception/list.php?search_status=1" alt="' . $langs -> trans ( " GoOnList " ) . '"><span class="badge">' . $num . '</span></a>' ;
2021-02-26 20:53:03 +01:00
while ( $i < $num ) {
2018-10-03 12:22:41 +02:00
$obj = $db -> fetch_object ( $resql );
2018-12-15 13:58:39 +01:00
2020-04-10 10:59:32 +02:00
$orderstatic -> id = $obj -> rowid ;
$orderstatic -> ref = $obj -> ref ;
$orderstatic -> ref_supplier = $obj -> ref_supplier ;
$orderstatic -> statut = $obj -> status ;
$orderstatic -> facturee = $obj -> billed ;
2018-12-15 13:58:39 +01:00
2020-04-10 10:59:32 +02:00
$companystatic -> name = $obj -> name ;
$companystatic -> id = $obj -> socid ;
2018-12-15 13:58:39 +01:00
2020-03-23 19:35:14 +01:00
print '<tr class="oddeven">' ;
print '<td class="nowrap">' ;
2018-10-03 12:22:41 +02:00
print $orderstatic -> getNomUrl ( 1 );
print '</td>' ;
print '<td>' ;
2020-03-23 19:35:14 +01:00
print $companystatic -> getNomUrl ( 1 , 'customer' , 32 );
2018-10-03 12:22:41 +02:00
print '</td>' ;
2020-03-23 19:35:14 +01:00
print '<td class="right">' ;
print $orderstatic -> getLibStatut ( 3 );
2018-10-03 12:22:41 +02:00
print '</td>' ;
2020-03-23 19:35:14 +01:00
print '</tr>' ;
2018-10-03 12:22:41 +02:00
$i ++ ;
}
2019-10-30 18:44:53 +01:00
print " </table></div><br> " ;
2018-10-03 12:22:41 +02:00
}
}
2021-10-24 00:37:37 +02:00
print '</div></div>' ;
2018-10-03 12:22:41 +02:00
2019-06-18 14:07:52 +02:00
$parameters = array ( 'user' => $user );
$reshook = $hookmanager -> executeHooks ( 'dashboardWarehouseReceptions' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2018-10-03 12:22:41 +02:00
llxFooter ();
$db -> close ();