2018-10-03 12:22:41 +02:00
< ? php
/* 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 >
2018-10-09 17:05:45 +02:00
* Copyright ( C ) 2018 Quentin Vial - Gouteyron < quentin . vial - gouteyron @ atm - consulting . 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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
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
*/
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
$langs -> load ( " orders " );
2018-10-08 12:15:17 +02:00
$langs -> load ( " receptions " );
2018-10-03 12:22:41 +02:00
/*
* View
*/
2018-10-08 12:15:17 +02:00
$orderstatic = new CommandeFournisseur ( $db );
2018-10-03 12:22:41 +02:00
$companystatic = new Societe ( $db );
2018-10-08 12:15:17 +02:00
$reception = new Reception ( $db );
2018-10-03 12:22:41 +02:00
2018-10-08 12:15:17 +02:00
$helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:Módulo_Receptiones' ;
llxHeader ( '' , $langs -> trans ( " Reception " ), $helpurl );
2018-10-03 12:22:41 +02:00
2018-10-08 12:15:17 +02:00
print load_fiche_titre ( $langs -> trans ( " ReceptionsArea " ));
2018-10-03 12:22:41 +02:00
print '<div class="fichecenter"><div class="fichethirdleft">' ;
if ( ! empty ( $conf -> global -> MAIN_SEARCH_FORM_ON_HOME_AREAS )) // This is useless due to the global search combo
{
print '<form method="post" action="list.php">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="noborder nohover" width="100%">' ;
print '<tr class="liste_titre"><td colspan="3">' . $langs -> trans ( " Search " ) . '</td></tr>' ;
print '<tr class="oddeven"><td>' ;
2018-10-08 12:15:17 +02:00
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>' ;
2018-10-03 12:22:41 +02:00
print " </table></form><br> \n " ;
}
/*
2018-10-08 12:15:17 +02:00
* Receptions to validate
2018-10-03 12:22:41 +02:00
*/
$clause = " WHERE " ;
2018-10-08 12:15:17 +02:00
$sql = " SELECT e.rowid, e.ref, e.ref_supplier, " ;
2018-10-03 12:22:41 +02:00
$sql .= " s.nom as name, s.rowid as socid, " ;
2018-10-08 12:15:17 +02:00
$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 " ;
2018-10-03 12:22:41 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON s.rowid = e.fk_soc " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid )
{
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe_commerciaux as sc ON e.fk_soc = sc.fk_soc " ;
$sql .= $clause . " sc.fk_user = " . $user -> id ;
$clause = " AND " ;
}
$sql .= $clause . " e.fk_statut = 0 " ;
2018-10-08 12:15:17 +02:00
$sql .= " AND e.entity IN ( " . getEntity ( 'reception' ) . " ) " ;
2018-10-03 12:22:41 +02:00
if ( $socid ) $sql .= " AND c.fk_soc = " . $socid ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
if ( $num )
{
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2018-10-08 12:15:17 +02:00
print '<th colspan="3">' . $langs -> trans ( " ReceptionsToValidate " ) . '</th></tr>' ;
2018-10-03 12:22:41 +02:00
$i = 0 ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
2018-12-15 13:58:39 +01:00
2018-10-08 12:15:17 +02:00
$reception -> id = $obj -> rowid ;
$reception -> ref = $obj -> ref ;
2018-12-15 13:58:39 +01:00
$reception -> ref_supplier = $obj -> ref_supplier ;
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>' ;
2018-10-08 12:15:17 +02: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 ++ ;
}
print " </table><br> " ;
}
}
/*
2018-10-08 12:15:17 +02:00
* CommandeFournisseurs a traiter
2018-10-03 12:22:41 +02:00
*/
2018-10-08 12:15:17 +02:00
$sql = " SELECT c.rowid, c.ref, c.ref_supplier as ref_supplier, c.fk_statut, s.nom as name, s.rowid as socid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " commande_fournisseur as c, " ;
2018-10-03 12:22:41 +02:00
$sql .= " " . MAIN_DB_PREFIX . " societe as s " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
$sql .= " WHERE c.fk_soc = s.rowid " ;
$sql .= " AND c.entity = " . $conf -> entity ;
2018-10-10 12:19:57 +02:00
$sql .= " AND c.fk_statut = 3 " ; //Commandé
2018-10-03 12:22:41 +02:00
if ( $socid ) $sql .= " AND c.fk_soc = " . $socid ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
$sql .= " ORDER BY c.rowid ASC " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
if ( $num )
{
$langs -> load ( " orders " );
$i = 0 ;
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2018-10-08 12:15:17 +02:00
print '<th colspan="3">' . $langs -> trans ( " SuppliersOrdersToProcess " ) . '</th></tr>' ;
2018-10-03 12:22:41 +02:00
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
$orderstatic -> id = $obj -> rowid ;
$orderstatic -> ref = $obj -> ref ;
2018-10-08 12:15:17 +02:00
$orderstatic -> ref_supplier = $obj -> ref_supplier ;
2018-10-03 12:22:41 +02:00
$orderstatic -> statut = $obj -> fk_statut ;
$orderstatic -> facturee = 0 ;
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
$companystatic -> name = $obj -> name ;
2018-12-15 13:58:39 +01:00
$companystatic -> id = $obj -> socid ;
2018-10-03 12:22:41 +02:00
print '<tr class="oddeven">' ;
print '<td class="nowrap">' ;
print $orderstatic -> getNomUrl ( 1 );
print '</td>' ;
print '<td>' ;
print $companystatic -> getNomUrl ( 1 , 'customer' , 32 );
print '</td>' ;
print '<td align="right">' ;
print $orderstatic -> getLibStatut ( 3 );
print '</td>' ;
print '</tr>' ;
$i ++ ;
}
print " </table><br> " ;
}
}
//print '</td><td valign="top" width="70%">';
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">' ;
/*
2018-10-08 12:15:17 +02:00
* CommandeFournisseurs en traitement
2018-10-03 12:22:41 +02: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 " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " commande_fournisseur as c, " ;
2018-10-03 12:22:41 +02:00
$sql .= " " . MAIN_DB_PREFIX . " societe as s " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
$sql .= " WHERE c.fk_soc = s.rowid " ;
$sql .= " AND c.entity = " . $conf -> entity ;
2018-10-09 16:26:40 +02:00
$sql .= " AND c.fk_statut IN (4) " ;
2018-10-03 12:22:41 +02:00
if ( $socid ) $sql .= " AND c.fk_soc = " . $socid ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$langs -> load ( " orders " );
$num = $db -> num_rows ( $resql );
if ( $num )
{
$i = 0 ;
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2018-10-08 12:15:17 +02:00
print '<th colspan="3">' . $langs -> trans ( " SuppliersOrdersInProcess " ) . '</th></tr>' ;
2018-10-03 12:22:41 +02:00
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
$orderstatic -> id = $obj -> rowid ;
$orderstatic -> ref = $obj -> ref ;
2018-10-08 12:15:17 +02:00
$orderstatic -> ref_supplier = $obj -> ref_supplier ;
2018-10-03 12:22:41 +02:00
$orderstatic -> statut = $obj -> status ;
$orderstatic -> facturee = $obj -> billed ;
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
$companystatic -> name = $obj -> name ;
2018-12-15 13:58:39 +01:00
$companystatic -> id = $obj -> socid ;
2018-10-03 12:22:41 +02:00
print '<tr class="oddeven"><td>' ;
print $orderstatic -> getNomUrl ( 1 );
print '</td>' ;
print '<td>' ;
print $companystatic -> getNomUrl ( 1 , 'customer' );
print '</td>' ;
print '<td align="right">' ;
print $orderstatic -> getLibStatut ( 3 );
print '</td>' ;
print '</tr>' ;
$i ++ ;
}
print " </table><br> " ;
}
}
else dol_print_error ( $db );
/*
2018-10-08 12:15:17 +02:00
* Last receptions
2018-10-03 12:22:41 +02:00
*/
2018-10-08 12:15:17 +02:00
$sql = " SELECT e.rowid, e.ref, e.ref_supplier, " ;
2018-10-03 12:22:41 +02:00
$sql .= " s.nom as name, s.rowid as socid, " ;
2018-10-08 12:15:17 +02:00
$sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " reception as e " ;
2018-10-10 17:30:44 +02:00
$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' " ;
2018-10-03 12:22:41 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON s.rowid = e.fk_soc " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe_commerciaux as sc ON e.fk_soc = sc.fk_soc " ;
2018-10-08 12:15:17 +02:00
$sql .= " WHERE e.entity IN ( " . getEntity ( 'reception' ) . " ) " ;
2018-10-03 12:22:41 +02:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND sc.fk_user = " . $user -> id ;
$sql .= " AND e.fk_statut = 1 " ;
if ( $socid ) $sql .= " AND c.fk_soc = " . $socid ;
$sql .= " ORDER BY e.date_delivery DESC " ;
2018-10-10 17:30:44 +02:00
2018-10-03 12:22:41 +02:00
$sql .= $db -> plimit ( 5 , 0 );
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
if ( $num )
{
$i = 0 ;
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2018-10-08 12:15:17 +02:00
print '<th colspan="3">' . $langs -> trans ( " LastReceptions " , $num ) . '</th></tr>' ;
2018-10-03 12:22:41 +02:00
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
2018-12-15 13:58:39 +01:00
2018-10-08 12:15:17 +02:00
$reception -> id = $obj -> rowid ;
$reception -> ref = $obj -> ref ;
2018-12-15 13:58:39 +01:00
$reception -> ref_supplier = $obj -> ref_supplier ;
2018-10-03 12:22:41 +02:00
print '<tr class="oddeven"><td>' ;
2018-10-08 12:15:17 +02:00
print $reception -> getNomUrl ( 1 );
2018-10-03 12:22:41 +02:00
print '</td>' ;
print '<td><a href="' . DOL_URL_ROOT . '/comm/card.php?socid=' . $obj -> socid . '">' . img_object ( $langs -> trans ( " ShowCompany " ), " company " ) . ' ' . $obj -> name . '</a></td>' ;
print '<td>' ;
2018-10-08 12:15:17 +02:00
if ( $obj -> commande_fournisseur_id > 0 )
2018-10-03 12:22:41 +02:00
{
2018-10-08 12:15:17 +02:00
$orderstatic -> id = $obj -> commande_fournisseur_id ;
$orderstatic -> ref = $obj -> commande_fournisseur_ref ;
2018-10-03 12:22:41 +02:00
print $orderstatic -> getNomUrl ( 1 );
}
else print ' ' ;
print '</td></tr>' ;
$i ++ ;
}
print " </table><br> " ;
}
$db -> free ( $resql );
}
else dol_print_error ( $db );
print '</div></div></div>' ;
llxFooter ();
$db -> close ();