2008-10-25 19:27:15 +02:00
< ? php
2024-07-03 02:30:53 +02:00
/* Copyright ( C ) 2005 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2015 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2017 Charlie Benke < charlie @ patas - monkey . com >
* Copyright ( C ) 2017 ATM - CONSULTING < contact @ atm - consulting . fr >
* Copyright ( C ) 2024 MDW < mdeweerd @ users . noreply . github . com >
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2005-12-03 18:18:35 +01: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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2005-12-03 18:18:35 +01:00
* ( 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 />.
* or see https :// www . gnu . org /
2005-12-03 18:18:35 +01:00
*/
/**
2011-10-24 12:59:44 +02:00
* \file htdocs / core / lib / invoice . lib . php
2011-10-01 21:55:40 +02:00
* \brief Functions used by invoice module
2008-12-11 21:12:44 +01:00
* \ingroup invoice
*/
2008-10-25 19:27:15 +02:00
2011-10-01 21:55:40 +02:00
/**
* Initialize the array of tabs for customer invoice
*
* @ param Facture $object Invoice object
2024-10-14 01:59:44 +02:00
* @ return array < array { 0 : string , 1 : string , 2 : string } > Array of tabs to show
2011-10-01 21:55:40 +02:00
*/
2010-12-19 12:05:07 +01:00
function facture_prepare_head ( $object )
2008-10-25 19:27:15 +02:00
{
2023-03-14 11:12:07 +01:00
global $db , $langs , $conf , $user ;
2018-07-26 19:05:34 +02:00
2008-10-25 19:27:15 +02:00
$h = 0 ;
$head = array ();
2009-03-12 02:44:02 +01:00
2023-03-14 11:12:07 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/card.php?id=' . $object -> id ;
2020-09-09 13:57:35 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( 'CustomerInvoice' );
2008-10-25 19:27:15 +02:00
$head [ $h ][ 2 ] = 'compta' ;
$h ++ ;
2012-12-01 15:45:05 +01:00
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( 'MAIN_DISABLE_CONTACTS_TAB' )) {
2020-10-31 14:32:18 +01:00
$nbContact = count ( $object -> liste_contact ( - 1 , 'internal' )) + count ( $object -> liste_contact ( - 1 , 'external' ));
2024-03-08 02:50:35 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/contact.php?id=' . urlencode (( string ) ( $object -> id ));
2012-07-02 19:30:37 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( 'ContactsAddresses' );
2021-02-23 22:03:23 +01:00
if ( $nbContact > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbContact . '</span>' ;
}
2012-07-02 19:30:37 +02:00
$head [ $h ][ 2 ] = 'contact' ;
2012-03-17 16:05:58 +01:00
$h ++ ;
}
2008-10-25 19:27:15 +02:00
2023-04-19 13:58:08 +02:00
if ( isModEnabled ( 'prelevement' )) {
2020-10-31 14:32:18 +01:00
$nbStandingOrders = 0 ;
$sql = " SELECT COUNT(pfd.rowid) as nb " ;
2022-10-28 17:51:25 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " prelevement_demande as pfd " ;
2021-08-27 18:18:50 +02:00
$sql .= " WHERE pfd.fk_facture = " . (( int ) $object -> id );
2023-08-14 14:37:35 +02:00
$sql .= " AND type = 'ban' " ;
2020-10-31 14:32:18 +01:00
$resql = $db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2020-10-31 14:32:18 +01:00
$obj = $db -> fetch_object ( $resql );
2021-02-23 22:03:23 +01:00
if ( $obj ) {
$nbStandingOrders = $obj -> nb ;
}
} else {
dol_print_error ( $db );
}
2022-10-08 02:54:10 +02:00
$langs -> load ( " banks " );
2024-03-08 02:50:35 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/prelevement.php?id=' . urlencode (( string ) ( $object -> id ));
2008-10-25 19:27:15 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( 'StandingOrders' );
2021-02-23 22:03:23 +01:00
if ( $nbStandingOrders > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbStandingOrders . '</span>' ;
}
2008-10-25 19:27:15 +02:00
$head [ $h ][ 2 ] = 'standingorders' ;
$h ++ ;
}
2020-10-31 14:32:18 +01:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
2022-09-22 14:06:50 +02:00
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'invoice' , 'add' , 'core' );
2012-12-01 15:45:05 +01:00
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( 'MAIN_DISABLE_NOTES_TAB' )) {
2020-10-31 14:32:18 +01:00
$nbNote = 0 ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> note_private )) {
$nbNote ++ ;
}
if ( ! empty ( $object -> note_public )) {
$nbNote ++ ;
}
2023-03-14 11:12:07 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/note.php?id=' . $object -> id ;
2020-10-31 14:32:18 +01:00
$head [ $h ][ 1 ] = $langs -> trans ( 'Notes' );
2021-02-23 22:03:23 +01:00
if ( $nbNote > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' ;
}
2020-10-31 14:32:18 +01:00
$head [ $h ][ 2 ] = 'note' ;
$h ++ ;
}
2008-10-25 19:27:15 +02:00
2013-07-20 09:07:10 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2020-10-31 14:32:18 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php' ;
2020-04-10 10:59:32 +02:00
$upload_dir = $conf -> facture -> dir_output . " / " . dol_sanitizeFileName ( $object -> ref );
2019-01-27 11:55:16 +01:00
$nbFiles = count ( dol_dir_list ( $upload_dir , 'files' , 0 , '' , '(\.meta|_preview.*\.png)$' ));
2020-10-31 14:32:18 +01:00
$nbLinks = Link :: count ( $db , $object -> element , $object -> id );
2023-03-14 11:12:07 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/document.php?id=' . $object -> id ;
2008-10-25 19:27:15 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( 'Documents' );
2021-02-23 22:03:23 +01:00
if (( $nbFiles + $nbLinks ) > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . ( $nbFiles + $nbLinks ) . '</span>' ;
}
2008-10-25 19:27:15 +02:00
$head [ $h ][ 2 ] = 'documents' ;
$h ++ ;
2023-03-14 11:12:07 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/agenda.php?id=' . $object -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( " Events " );
2024-03-08 02:50:35 +01:00
if ( isModEnabled ( 'agenda' ) && ( $user -> hasRight ( 'agenda' , 'myactions' , 'read' ) || $user -> hasRight ( 'agenda' , 'allactions' , 'read' ))) {
2023-03-14 11:12:07 +01:00
$nbEvent = 0 ;
// Enable caching of thirdparty count actioncomm
require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php' ;
$cachekey = 'count_events_facture_' . $object -> id ;
$dataretrieved = dol_getcache ( $cachekey );
if ( ! is_null ( $dataretrieved )) {
$nbEvent = $dataretrieved ;
} else {
$sql = " SELECT COUNT(id) as nb " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " actioncomm " ;
$sql .= " WHERE fk_element = " . (( int ) $object -> id );
$sql .= " AND elementtype = 'invoice' " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
$nbEvent = $obj -> nb ;
} else {
dol_syslog ( 'Failed to count actioncomm ' . $db -> lasterror (), LOG_ERR );
}
dol_setcache ( $cachekey , $nbEvent , 120 ); // If setting cache fails, this is not a problem, so we do not test result.
}
$head [ $h ][ 1 ] .= '/' ;
$head [ $h ][ 1 ] .= $langs -> trans ( " Agenda " );
if ( $nbEvent > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbEvent . '</span>' ;
}
}
$head [ $h ][ 2 ] = 'agenda' ;
2008-10-25 19:27:15 +02:00
$h ++ ;
2022-09-22 14:06:50 +02:00
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'invoice' , 'add' , 'external' );
2019-01-27 11:55:16 +01:00
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'invoice' , 'remove' );
2012-12-01 15:45:05 +01:00
2008-10-25 19:27:15 +02:00
return $head ;
}
2013-03-06 03:36:43 +01:00
/**
2024-01-13 19:48:20 +01:00
* Return array head with list of tabs to view object information .
2013-03-06 03:36:43 +01:00
*
2024-10-14 01:59:44 +02:00
* @ return array < array { 0 : string , 1 : string , 2 : string } > Array of tabs to show
2013-03-06 03:36:43 +01:00
*/
2014-12-04 13:20:56 +01:00
function invoice_admin_prepare_head ()
2013-03-06 03:36:43 +01:00
{
2022-10-18 14:26:26 +02:00
global $langs , $conf , $user , $db ;
$extrafields = new ExtraFields ( $db );
$extrafields -> fetch_name_optionals_label ( 'facture' );
$extrafields -> fetch_name_optionals_label ( 'facturedet' );
$extrafields -> fetch_name_optionals_label ( 'facture_rec' );
$extrafields -> fetch_name_optionals_label ( 'facturedet_rec' );
2013-03-06 03:36:43 +01:00
$h = 0 ;
$head = array ();
2024-03-10 15:52:29 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/admin/invoice.php' ;
2013-03-24 07:11:44 +01:00
$head [ $h ][ 1 ] = $langs -> trans ( " Miscellaneous " );
2013-03-06 03:36:43 +01:00
$head [ $h ][ 2 ] = 'general' ;
$h ++ ;
2015-09-26 10:37:36 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/admin/payment.php' ;
$head [ $h ][ 1 ] = $langs -> trans ( " Payments " );
$head [ $h ][ 2 ] = 'payment' ;
$h ++ ;
2019-10-20 17:17:22 +02:00
2013-03-06 03:36:43 +01:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
2019-01-27 11:55:16 +01:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'invoice_admin' );
2013-03-06 03:36:43 +01:00
2024-03-10 15:52:29 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/admin/invoice_cust_extrafields.php' ;
2013-03-06 03:36:43 +01:00
$head [ $h ][ 1 ] = $langs -> trans ( " ExtraFieldsCustomerInvoices " );
2022-10-18 14:26:26 +02:00
$nbExtrafields = $extrafields -> attributes [ 'facture' ][ 'count' ];
if ( $nbExtrafields > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>' ;
}
2013-03-06 03:36:43 +01:00
$head [ $h ][ 2 ] = 'attributes' ;
$h ++ ;
2024-03-10 15:52:29 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/admin/invoicedet_cust_extrafields.php' ;
2013-06-10 16:05:41 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " ExtraFieldsLines " );
2022-10-18 14:26:26 +02:00
$nbExtrafields = $extrafields -> attributes [ 'facturedet' ][ 'count' ];
if ( $nbExtrafields > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>' ;
}
2013-06-10 16:05:41 +02:00
$head [ $h ][ 2 ] = 'attributeslines' ;
$h ++ ;
2018-07-26 19:05:34 +02:00
2024-03-10 15:52:29 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/admin/invoice_rec_cust_extrafields.php' ;
2017-07-11 09:26:25 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " ExtraFieldsCustomerInvoicesRec " );
2022-10-18 14:26:26 +02:00
$nbExtrafields = $extrafields -> attributes [ 'facture_rec' ][ 'count' ];
if ( $nbExtrafields > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>' ;
}
2017-07-11 09:26:25 +02:00
$head [ $h ][ 2 ] = 'attributesrec' ;
$h ++ ;
2018-07-26 19:05:34 +02:00
2024-03-10 15:52:29 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/admin/invoicedet_rec_cust_extrafields.php' ;
2017-07-11 09:26:25 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " ExtraFieldsLinesRec " );
2022-10-18 14:26:26 +02:00
$nbExtrafields = $extrafields -> attributes [ 'facturedet_rec' ][ 'count' ];
if ( $nbExtrafields > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>' ;
}
2017-07-11 09:26:25 +02:00
$head [ $h ][ 2 ] = 'attributeslinesrec' ;
$h ++ ;
2013-03-06 03:36:43 +01:00
2023-08-27 16:01:05 +02:00
if ( getDolGlobalInt ( 'INVOICE_USE_SITUATION' ) > 0 ) { // Warning, implementation with value 1 is seriously bugged and a new one not compatible is expected to become stable
2024-03-10 15:52:29 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/admin/invoice_situation.php' ;
2020-06-18 02:35:08 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " InvoiceSituation " );
$head [ $h ][ 2 ] = 'situation' ;
$h ++ ;
}
2020-01-31 14:54:42 +01:00
2019-01-27 11:55:16 +01:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'invoice_admin' , 'remove' );
2013-03-06 03:36:43 +01:00
return $head ;
}
2018-08-31 22:01:13 +02:00
/**
2024-01-13 19:48:20 +01:00
* Return array head with list of tabs to view object information .
2018-08-31 22:01:13 +02:00
*
2024-07-03 02:30:53 +02:00
* @ param FactureRec $object Invoice model object
2024-10-14 01:59:44 +02:00
* @ return array < array { 0 : string , 1 : string , 2 : string } > Array of tabs to show
2018-08-31 22:01:13 +02:00
*/
2017-04-09 11:29:54 +02:00
function invoice_rec_prepare_head ( $object )
{
2023-07-29 21:02:52 +02:00
global $db , $langs , $conf , $user ;
2018-07-26 19:05:34 +02:00
2017-04-09 11:29:54 +02:00
$h = 0 ;
$head = array ();
2022-02-07 14:34:27 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/card-rec.php?id=' . $object -> id ;
2021-02-15 22:04:35 +01:00
$head [ $h ][ 1 ] = $langs -> trans ( " RepeatableInvoice " );
2017-04-09 11:33:56 +02:00
$head [ $h ][ 2 ] = 'card' ;
2017-04-09 11:29:54 +02:00
$h ++ ;
2024-10-19 01:02:21 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/list.php?search_fk_fac_rec_source=' . $object -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( 'InvoicesGeneratedFromRec' );
2024-10-25 20:45:12 +02:00
//count facture rec
$nbFacture = 0 ;
$sql = " SELECT COUNT(rowid) as nb " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " facture " ;
$sql .= " WHERE fk_fac_rec_source = " . (( int ) $object -> id );
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
$nbFacture = $obj -> nb ;
} else {
2024-10-26 13:02:00 +02:00
dol_syslog ( 'Failed to count invoices with invoice model ' . $db -> lasterror (), LOG_ERR );
2024-10-25 20:45:12 +02:00
}
if ( $nbFacture > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbFacture . '</span>' ;
}
2024-10-19 01:02:21 +02:00
$head [ $h ][ 2 ] = 'generated' ;
$h ++ ;
2024-10-25 12:30:50 +02:00
if ( ! getDolGlobalString ( 'MAIN_DISABLE_NOTES_TAB' )) {
$nbNote = 0 ;
if ( ! empty ( $object -> note_private )) {
$nbNote ++ ;
}
if ( ! empty ( $object -> note_public )) {
$nbNote ++ ;
}
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/note-rec.php?id=' . $object -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( 'Notes' );
if ( $nbNote > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' ;
}
$head [ $h ][ 2 ] = 'note' ;
$h ++ ;
}
2023-07-29 21:02:52 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/agenda-rec.php?id=' . $object -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( " Events " );
2024-03-08 02:50:35 +01:00
if ( isModEnabled ( 'agenda' ) && ( $user -> hasRight ( 'agenda' , 'myactions' , 'read' ) || $user -> hasRight ( 'agenda' , 'allactions' , 'read' ))) {
2023-07-29 21:02:52 +02:00
$nbEvent = 0 ;
// Enable caching of thirdparty count actioncomm
require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php' ;
$cachekey = 'count_events_facturerec_' . $object -> id ;
$dataretrieved = dol_getcache ( $cachekey );
if ( ! is_null ( $dataretrieved )) {
$nbEvent = $dataretrieved ;
} else {
$sql = " SELECT COUNT(id) as nb " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " actioncomm " ;
$sql .= " WHERE fk_element = " . (( int ) $object -> id );
$sql .= " AND elementtype = 'invoicerec' " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
$nbEvent = $obj -> nb ;
} else {
dol_syslog ( 'Failed to count actioncomm ' . $db -> lasterror (), LOG_ERR );
}
dol_setcache ( $cachekey , $nbEvent , 120 ); // If setting cache fails, this is not a problem, so we do not test result.
}
$head [ $h ][ 1 ] .= '/' ;
$head [ $h ][ 1 ] .= $langs -> trans ( " Agenda " );
if ( $nbEvent > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbEvent . '</span>' ;
}
}
$head [ $h ][ 2 ] = 'agenda' ;
$h ++ ;
2020-10-31 14:32:18 +01:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'invoice-rec' );
2017-04-09 11:29:54 +02:00
2019-01-27 11:55:16 +01:00
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'invoice-rec' , 'remove' );
2017-04-09 11:29:54 +02:00
return $head ;
}
2021-04-05 19:34:56 +02:00
2022-02-07 14:34:27 +01:00
/**
2024-01-13 19:48:20 +01:00
* Return array head with list of tabs to view object information .
2022-02-07 14:34:27 +01:00
*
2024-10-25 13:20:54 +02:00
* @ param Facture | FactureFournisseurRec $object Invoice object
2024-10-14 01:59:44 +02:00
* @ return array < array { 0 : string , 1 : string , 2 : string } > Array of tabs to show
2022-02-07 14:34:27 +01:00
*/
function supplier_invoice_rec_prepare_head ( $object )
{
global $db , $langs , $conf ;
$h = 0 ;
$head = array ();
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/fourn/facture/card-rec.php?id=' . $object -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( " RepeatableSupplierInvoice " );
$head [ $h ][ 2 ] = 'card' ;
$h ++ ;
2024-10-25 13:20:54 +02:00
if ( ! getDolGlobalString ( 'MAIN_DISABLE_NOTES_TAB' )) {
$nbNote = 0 ;
if ( ! empty ( $object -> note_private )) {
$nbNote ++ ;
}
if ( ! empty ( $object -> note_public )) {
$nbNote ++ ;
}
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/fourn/facture/note-rec.php?id=' . $object -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( 'Notes' );
if ( $nbNote > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' ;
}
$head [ $h ][ 2 ] = 'note' ;
$h ++ ;
}
2024-10-19 01:02:21 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/fourn/facture/list.php?search_fk_fac_rec_source=' . $object -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( 'InvoicesGeneratedFromRec' );
2024-10-25 20:45:53 +02:00
//count facture rec
$nbFactureFourn = 0 ;
$sql = " SELECT COUNT(rowid) as nb " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " facture_fourn " ;
$sql .= " WHERE fk_fac_rec_source = " . (( int ) $object -> id );
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
$nbFactureFourn = $obj -> nb ;
} else {
2024-10-26 13:02:00 +02:00
dol_syslog ( 'Failed to count invoices with supplier invoice model ' . $db -> lasterror (), LOG_ERR );
2024-10-25 20:45:53 +02:00
}
if ( $nbFactureFourn > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbFactureFourn . '</span>' ;
}
2024-10-19 01:02:21 +02:00
$head [ $h ][ 2 ] = 'generated' ;
$h ++ ;
2022-02-07 14:34:27 +01:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'invoice_supplier_rec' );
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'invoice_supplier_rec' , 'remove' );
return $head ;
}
2021-04-27 16:02:46 +02:00
/**
* Return an HTML table that contains a pie chart of the number of customers or supplier invoices
2021-06-10 00:41:15 +02:00
*
* @ param string $mode Can be 'customers' or 'suppliers'
* @ return string A HTML table that contains a pie chart of customers or supplier invoices
2021-04-27 16:02:46 +02:00
*/
function getNumberInvoicesPieChart ( $mode )
{
global $conf , $db , $langs , $user ;
2023-02-04 12:31:50 +01:00
2024-02-27 15:30:37 +01:00
if (( $mode == 'customers' && isModEnabled ( 'invoice' ) && $user -> hasRight ( 'facture' , 'lire' ))
2023-02-08 13:48:17 +01:00
|| ( $mode == 'suppliers' && ( isModEnabled ( 'fournisseur' ) || isModEnabled ( 'supplier_invoice' )) && $user -> hasRight ( 'fournisseur' , 'facture' , 'lire' ))
2024-03-08 02:50:35 +01:00
) {
2023-09-19 09:48:14 +02:00
global $badgeStatus1 , $badgeStatus3 , $badgeStatus4 , $badgeStatus8 , $badgeStatus11 ;
2021-04-27 16:02:46 +02:00
include DOL_DOCUMENT_ROOT . '/theme/' . $conf -> theme . '/theme_vars.inc.php' ;
2021-04-29 09:31:49 +02:00
$now = date_create ( date ( 'Y-m-d' , dol_now ()));
$datenowsub30 = date_create ( date ( 'Y-m-d' , dol_now ()));
$datenowsub15 = date_create ( date ( 'Y-m-d' , dol_now ()));
$datenowadd30 = date_create ( date ( 'Y-m-d' , dol_now ()));
$datenowadd15 = date_create ( date ( 'Y-m-d' , dol_now ()));
$interval30days = date_interval_create_from_date_string ( '30 days' );
$interval15days = date_interval_create_from_date_string ( '15 days' );
date_sub ( $datenowsub30 , $interval30days );
date_sub ( $datenowsub15 , $interval15days );
date_add ( $datenowadd30 , $interval30days );
date_add ( $datenowadd15 , $interval15days );
2024-07-03 02:50:04 +02:00
$amount_mode = ( getDolGlobalInt ( 'FACTURE_VALIDATED_IN_AMOUNT' ) == 1 );
2024-10-14 01:59:44 +02:00
$sql = " SELECT " ;
2024-07-03 02:50:04 +02:00
$sql .= " sum( " . $db -> ifsql ( " f.date_lim_reglement < ' " . date_format ( $datenowsub30 , 'Y-m-d' ) . " ' " , $amount_mode ? " f.total_ht " : 1 , 0 ) . " ) as late30 " ;
$sql .= " , sum( " . $db -> ifsql ( " f.date_lim_reglement < ' " . date_format ( $datenowsub15 , 'Y-m-d' ) . " ' AND f.date_lim_reglement >= ' " . date_format ( $datenowsub30 , 'Y-m-d' ) . " ' " , $amount_mode ? " f.total_ht " : 1 , 0 ) . " ) as late15 " ;
$sql .= " , sum( " . $db -> ifsql ( " f.date_lim_reglement < ' " . date_format ( $now , 'Y-m-d' ) . " ' AND f.date_lim_reglement >= ' " . date_format ( $datenowsub15 , 'Y-m-d' ) . " ' " , $amount_mode ? " f.total_ht " : 1 , 0 ) . " ) as latenow " ;
$sql .= " , sum( " . $db -> ifsql ( " f.date_lim_reglement >= ' " . date_format ( $now , 'Y-m-d' ) . " ' AND f.date_lim_reglement < ' " . date_format ( $datenowadd15 , 'Y-m-d' ) . " ' " , $amount_mode ? " f.total_ht " : 1 , 0 ) . " ) as notlatenow " ;
$sql .= " , sum( " . $db -> ifsql ( " f.date_lim_reglement >= ' " . date_format ( $datenowadd15 , 'Y-m-d' ) . " ' AND f.date_lim_reglement < ' " . date_format ( $datenowadd30 , 'Y-m-d' ) . " ' " , $amount_mode ? " f.total_ht " : 1 , 0 ) . " ) as notlate15 " ;
$sql .= " , sum( " . $db -> ifsql ( " f.date_lim_reglement >= ' " . date_format ( $datenowadd30 , 'Y-m-d' ) . " ' " , $amount_mode ? " f.total_ht " : 1 , 0 ) . " ) as notlate30 " ;
2021-04-27 16:02:46 +02:00
if ( $mode == 'customers' ) {
2023-02-16 15:51:55 +01:00
$element = 'invoice' ;
2021-04-27 16:02:46 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
2021-06-10 00:41:15 +02:00
} elseif ( $mode == 'fourn' || $mode == 'suppliers' ) {
2023-02-16 15:51:55 +01:00
$element = 'supplier_invoice' ;
2021-04-27 16:02:46 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture_fourn as f " ;
} else {
return '' ;
}
2023-02-16 15:51:55 +01:00
$sql .= " WHERE f.entity IN ( " . getEntity ( $element ) . " ) " ;
$sql .= " AND f.type <> 2 " ;
2021-04-27 16:02:46 +02:00
$sql .= " AND f.fk_statut = 1 " ;
2021-06-10 00:41:15 +02:00
if ( isset ( $user -> socid ) && $user -> socid > 0 ) {
$sql .= " AND f.fk_soc = " . (( int ) $user -> socid );
}
2021-04-27 16:02:46 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
$i = 0 ;
$total = 0 ;
2021-04-29 09:31:49 +02:00
$dataseries = array ();
2021-06-10 00:55:10 +02:00
2021-04-27 16:02:46 +02:00
while ( $i < $num ) {
$obj = $db -> fetch_object ( $resql );
2022-02-07 14:34:27 +01:00
/*
$dataseries = array ( array ( $langs -> trans ( 'InvoiceLate30Days' ), $obj -> nblate30 )
2021-06-14 15:37:02 +02:00
, array ( $langs -> trans ( 'InvoiceLate15Days' ), $obj -> nblate15 - $obj -> nblate30 )
, array ( $langs -> trans ( 'InvoiceLateMinus15Days' ), $obj -> nblatenow - $obj -> nblate15 )
, array ( $langs -> trans ( 'InvoiceNotLate' ), $obj -> nbnotlatenow - $obj -> nbnotlate15 )
, array ( $langs -> trans ( 'InvoiceNotLate15Days' ), $obj -> nbnotlate15 - $obj -> nbnotlate30 )
2022-02-07 14:34:27 +01:00
, array ( $langs -> trans ( 'InvoiceNotLate30Days' ), $obj -> nbnotlate30 ));
*/
2024-07-03 02:50:04 +02:00
$dataseries [ $i ] = array ( $langs -> transnoentitiesnoconv ( 'NbOfOpenInvoices' ), $obj -> late30 , $obj -> late15 , $obj -> latenow , $obj -> notlatenow , $obj -> notlate15 , $obj -> notlate30 );
2021-04-27 16:02:46 +02:00
$i ++ ;
}
2021-10-13 14:14:30 +02:00
if ( ! empty ( $dataseries [ 0 ])) {
2021-10-13 14:26:43 +02:00
foreach ( $dataseries [ 0 ] as $key => $value ) {
if ( is_numeric ( $value )) {
$total += $value ;
}
2021-10-13 14:14:30 +02:00
}
2021-04-27 16:02:46 +02:00
}
2021-10-06 20:29:48 +02:00
$legend = array (
$langs -> trans ( 'InvoiceLate30Days' ),
$langs -> trans ( 'InvoiceLate15Days' ),
$langs -> trans ( 'InvoiceLateMinus15Days' ),
$mode == 'customers' ? $langs -> trans ( 'InvoiceNotLate' ) : $langs -> trans ( " InvoiceToPay " ),
$mode == 'customers' ? $langs -> trans ( 'InvoiceNotLate15Days' ) : $langs -> trans ( " InvoiceToPay15Days " ),
$mode == 'customers' ? $langs -> trans ( 'InvoiceNotLate30Days' ) : $langs -> trans ( " InvoiceToPay30Days " ),
);
2021-05-17 11:26:31 +02:00
$colorseries = array ( $badgeStatus8 , $badgeStatus1 , $badgeStatus3 , $badgeStatus4 , $badgeStatus11 , '-' . $badgeStatus11 );
2021-04-27 16:02:46 +02:00
2021-06-10 00:55:10 +02:00
$result = '<div class="div-table-responsive-no-min">' ;
$result .= '<table class="noborder nohover centpercent">' ;
$result .= '<tr class="liste_titre">' ;
2021-10-04 05:34:14 +02:00
$result .= '<td>' . $langs -> trans ( " NbOfOpenInvoices " ) . ' - ' ;
2021-06-10 00:55:10 +02:00
if ( $mode == 'customers' ) {
$result .= $langs -> trans ( " CustomerInvoice " );
} elseif ( $mode == 'fourn' || $mode == 'suppliers' ) {
$result .= $langs -> trans ( " SupplierInvoice " );
} else {
return '' ;
}
$result .= '</td>' ;
$result .= '</tr>' ;
if ( $conf -> use_javascript_ajax ) {
2021-10-04 05:27:07 +02:00
//var_dump($dataseries);
2021-04-27 16:02:46 +02:00
$dolgraph = new DolGraph ();
$dolgraph -> SetData ( $dataseries );
2021-10-04 05:27:07 +02:00
$dolgraph -> setLegend ( $legend );
2021-04-27 16:02:46 +02:00
$dolgraph -> SetDataColor ( array_values ( $colorseries ));
$dolgraph -> setShowLegend ( 2 );
$dolgraph -> setShowPercent ( 1 );
2021-10-04 05:27:07 +02:00
$dolgraph -> SetType ( array ( 'bars' , 'bars' , 'bars' , 'bars' , 'bars' , 'bars' ));
2022-02-07 14:34:27 +01:00
//$dolgraph->SetType(array('pie'));
$dolgraph -> setHeight ( '160' ); /* 160 min is required to show the 6 lines of legend */
$dolgraph -> setWidth ( '450' );
2021-10-04 05:34:14 +02:00
$dolgraph -> setHideXValues ( true );
2021-04-27 16:02:46 +02:00
if ( $mode == 'customers' ) {
$dolgraph -> draw ( 'idgraphcustomerinvoices' );
2021-06-10 00:41:15 +02:00
} elseif ( $mode == 'fourn' || $mode == 'suppliers' ) {
2021-04-27 16:02:46 +02:00
$dolgraph -> draw ( 'idgraphfourninvoices' );
} else {
return '' ;
}
$result .= '<tr maxwidth="255">' ;
2021-06-10 00:55:10 +02:00
$result .= '<td class="center">' . $dolgraph -> show ( $total ? 0 : $langs -> trans ( " NoOpenInvoice " )) . '</td>' ;
2021-04-27 16:02:46 +02:00
$result .= '</tr>' ;
2021-06-10 00:55:10 +02:00
} else {
// Print text lines
2021-04-27 16:02:46 +02:00
}
2021-06-10 00:55:10 +02:00
$result .= '</table>' ;
$result .= '</div>' ;
2021-04-29 09:31:49 +02:00
return $result ;
} else {
dol_print_error ( $db );
2021-04-27 16:02:46 +02:00
}
}
2023-02-04 12:31:50 +01:00
return '' ;
2021-04-27 16:02:46 +02:00
}
2023-02-04 12:31:50 +01:00
2021-04-05 19:34:56 +02:00
/**
* Return a HTML table that contains a list with customer invoice drafts
*
* @ param int $maxCount ( Optional ) The maximum count of elements inside the table
* @ param int $socid ( Optional ) Show only results from the customer with this id
* @ return string A HTML table that contains a list with customer invoice drafts
*/
function getCustomerInvoiceDraftTable ( $maxCount = 500 , $socid = 0 )
{
global $conf , $db , $langs , $user , $hookmanager ;
$result = '' ;
2024-02-27 15:30:37 +01:00
if ( isModEnabled ( 'invoice' ) && $user -> hasRight ( 'facture' , 'lire' )) {
2023-11-27 11:39:32 +01:00
$maxofloop = ( ! getDolGlobalString ( 'MAIN_MAXLIST_OVERLOAD' ) ? 500 : $conf -> global -> MAIN_MAXLIST_OVERLOAD );
2021-04-05 19:34:56 +02:00
2023-02-04 12:31:50 +01:00
$tmpinvoice = new Facture ( $db );
2021-04-05 19:34:56 +02:00
2023-02-04 12:31:50 +01:00
$sql = " SELECT f.rowid, f.ref, f.datef as date, f.total_ht, f.total_tva, f.total_ttc, f.ref_client " ;
$sql .= " , f.type, f.fk_statut as status, f.paye " ;
$sql .= " , s.nom as name " ;
$sql .= " , s.rowid as socid, s.email " ;
$sql .= " , s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur " ;
$sql .= " , cc.rowid as country_id, cc.code as country_code " ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2023-02-04 12:31:50 +01:00
$sql .= " , sc.fk_soc, sc.fk_user " ;
}
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f, " . MAIN_DB_PREFIX . " societe as s LEFT JOIN " . MAIN_DB_PREFIX . " c_country as cc ON cc.rowid = s.fk_pays " ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2023-02-04 12:31:50 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
$sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = " . Facture :: STATUS_DRAFT ;
$sql .= " AND f.entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2023-02-04 12:31:50 +01:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
}
2021-04-05 19:34:56 +02:00
2023-02-04 12:31:50 +01:00
if ( $socid ) {
$sql .= " AND f.fk_soc = " . (( int ) $socid );
}
// Add where from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhereCustomerDraft' , $parameters );
$sql .= $hookmanager -> resPrint ;
$sql .= " GROUP BY f.rowid, f.ref, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.ref_client, f.type, f.fk_statut, f.paye, " ;
$sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur, " ;
$sql .= " cc.rowid, cc.code " ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2023-02-04 12:31:50 +01:00
$sql .= " , sc.fk_soc, sc.fk_user " ;
}
2021-04-05 19:34:56 +02:00
2023-02-04 12:31:50 +01:00
// Add Group from hooks
2024-05-30 13:37:17 +02:00
$parameters = array ();
2023-02-04 12:31:50 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListGroupByCustomerDraft' , $parameters );
$sql .= $hookmanager -> resPrint ;
2021-04-05 19:34:56 +02:00
2023-02-04 12:31:50 +01:00
$resql = $db -> query ( $sql );
2021-04-05 19:34:56 +02:00
2023-02-04 12:31:50 +01:00
if ( $resql ) {
$num = $db -> num_rows ( $resql );
$nbofloop = min ( $num , $maxofloop );
2021-04-05 19:34:56 +02:00
2023-02-04 12:31:50 +01:00
$result .= '<div class="div-table-responsive-no-min">' ;
$result .= '<table class="noborder centpercent">' ;
2021-04-05 19:34:56 +02:00
2023-02-04 12:31:50 +01:00
$result .= '<tr class="liste_titre">' ;
$result .= '<th colspan="3">' ;
2024-05-02 12:41:33 +02:00
$result .= $langs -> trans ( " CustomersDraftInvoices " );
2023-02-04 12:31:50 +01:00
$result .= '<a href="' . DOL_URL_ROOT . '/compta/facture/list.php?search_status=' . Facture :: STATUS_DRAFT . '">' ;
2024-05-02 12:41:33 +02:00
$result .= '<span class="badge marginleftonly">' . $num . '</span>' ;
2023-02-04 12:31:50 +01:00
$result .= '</a>' ;
$result .= '</th>' ;
$result .= '</tr>' ;
if ( $num ) {
$companystatic = new Societe ( $db );
$i = 0 ;
$othernb = 0 ;
$tot_ttc = 0 ;
while ( $i < $nbofloop ) {
$obj = $db -> fetch_object ( $resql );
if ( $i >= $maxCount ) {
$othernb += 1 ;
$i ++ ;
$tot_ttc += $obj -> total_ttc ;
continue ;
}
$tmpinvoice -> id = $obj -> rowid ;
$tmpinvoice -> ref = $obj -> ref ;
$tmpinvoice -> date = $db -> jdate ( $obj -> date );
$tmpinvoice -> type = $obj -> type ;
$tmpinvoice -> total_ht = $obj -> total_ht ;
$tmpinvoice -> total_tva = $obj -> total_tva ;
$tmpinvoice -> total_ttc = $obj -> total_ttc ;
$tmpinvoice -> ref_client = $obj -> ref_client ;
$tmpinvoice -> statut = $obj -> status ;
$tmpinvoice -> paye = $obj -> paye ;
$companystatic -> id = $obj -> socid ;
$companystatic -> name = $obj -> name ;
$companystatic -> email = $obj -> email ;
$companystatic -> country_id = $obj -> country_id ;
$companystatic -> country_code = $obj -> country_code ;
$companystatic -> client = 1 ;
$companystatic -> code_client = $obj -> code_client ;
$companystatic -> code_fournisseur = $obj -> code_fournisseur ;
$companystatic -> code_compta = $obj -> code_compta ;
2024-08-14 16:51:53 +02:00
$companystatic -> code_compta_client = $obj -> code_compta ;
2023-02-04 12:31:50 +01:00
$companystatic -> code_compta_fournisseur = $obj -> code_compta_fournisseur ;
$result .= '<tr class="oddeven">' ;
$result .= '<td class="nowrap tdoverflowmax100">' ;
$result .= $tmpinvoice -> getNomUrl ( 1 , '' );
$result .= '</td>' ;
$result .= '<td class="nowrap tdoverflowmax100">' ;
$result .= $companystatic -> getNomUrl ( 1 , 'customer' );
$result .= '</td>' ;
$result .= '<td class="nowrap right"><span class="amount">' . price ( $obj -> total_ttc ) . '</span></td>' ;
$result .= '</tr>' ;
2021-04-05 19:34:56 +02:00
$tot_ttc += $obj -> total_ttc ;
2023-02-04 12:31:50 +01:00
$i ++ ;
2021-04-05 19:34:56 +02:00
}
2023-02-04 12:31:50 +01:00
if ( $othernb ) {
$result .= '<tr class="oddeven">' ;
$result .= '<td class="nowrap" colspan="3">' ;
$result .= '<span class="opacitymedium">' . $langs -> trans ( " More " ) . '...' . ( $othernb < $maxofloop ? ' (' . $othernb . ')' : '' ) . '</span>' ;
$result .= '</td>' ;
$result .= " </tr> \n " ;
}
2021-04-05 19:34:56 +02:00
2023-02-04 12:31:50 +01:00
$result .= '<tr class="liste_total"><td class="left">' . $langs -> trans ( " Total " ) . '</td>' ;
$result .= '<td colspan="2" class="right">' . price ( $tot_ttc ) . '</td>' ;
$result .= '</tr>' ;
} else {
2023-09-22 13:50:52 +02:00
$result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">' . $langs -> trans ( " NoInvoice " ) . '</span></td></tr>' ;
2021-04-05 19:34:56 +02:00
}
2023-02-04 12:31:50 +01:00
$result .= " </table></div> " ;
$db -> free ( $resql );
2021-04-05 19:34:56 +02:00
} else {
2023-02-04 12:31:50 +01:00
dol_print_error ( $db );
2021-04-05 19:34:56 +02:00
}
}
return $result ;
}
/**
* Return a HTML table that contains a list with customer invoice drafts
*
* @ param int $maxCount ( Optional ) The maximum count of elements inside the table
* @ param int $socid ( Optional ) Show only results from the customer with this id
* @ return string A HTML table that contains a list with customer invoice drafts
*/
function getDraftSupplierTable ( $maxCount = 500 , $socid = 0 )
{
global $conf , $db , $langs , $user , $hookmanager ;
$result = '' ;
2023-06-12 20:17:21 +02:00
if (( isModEnabled ( 'fournisseur' ) || isModEnabled ( 'supplier_invoice' )) && $user -> hasRight ( 'facture' , 'lire' )) {
2023-11-27 11:39:32 +01:00
$maxofloop = ( ! getDolGlobalString ( 'MAIN_MAXLIST_OVERLOAD' ) ? 500 : $conf -> global -> MAIN_MAXLIST_OVERLOAD );
2021-04-05 19:34:56 +02:00
2023-02-04 12:31:50 +01:00
$facturesupplierstatic = new FactureFournisseur ( $db );
$sql = " SELECT f.ref, f.rowid, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier, f.fk_statut as status, f.paye " ;
$sql .= " , s.nom as name " ;
$sql .= " , s.rowid as socid, s.email " ;
$sql .= " , s.code_client, s.code_compta " ;
$sql .= " , s.code_fournisseur, s.code_compta_fournisseur " ;
$sql .= " , cc.rowid as country_id, cc.code as country_code " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " facture_fourn as f, " . MAIN_DB_PREFIX . " societe as s LEFT JOIN " . MAIN_DB_PREFIX . " c_country as cc ON cc.rowid = s.fk_pays " ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2023-02-04 12:31:50 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
$sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = " . FactureFournisseur :: STATUS_DRAFT ;
$sql .= " AND f.entity IN ( " . getEntity ( 'invoice' ) . ')' ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2023-02-04 12:31:50 +01:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
}
if ( $socid ) {
$sql .= " AND f.fk_soc = " . (( int ) $socid );
}
// Add where from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhereSupplierDraft' , $parameters );
$sql .= $hookmanager -> resPrint ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
$nbofloop = min ( $num , $maxofloop );
$result .= '<div class="div-table-responsive-no-min">' ;
$result .= '<table class="noborder centpercent">' ;
$result .= '<tr class="liste_titre">' ;
$result .= '<th colspan="3">' ;
2024-05-02 12:41:33 +02:00
$result .= $langs -> trans ( " SuppliersDraftInvoices " );
2023-02-04 12:31:50 +01:00
$result .= '<a href="' . DOL_URL_ROOT . '/fourn/facture/list.php?search_status=' . FactureFournisseur :: STATUS_DRAFT . '">' ;
2024-05-02 12:41:33 +02:00
$result .= '<span class="badge marginleftonly">' . $num . '</span>' ;
2023-02-04 12:31:50 +01:00
$result .= '</a>' ;
$result .= '</th>' ;
$result .= '</tr>' ;
if ( $num ) {
$companystatic = new Societe ( $db );
$i = 0 ;
$othernb = 0 ;
$tot_ttc = 0 ;
while ( $i < $nbofloop ) {
$obj = $db -> fetch_object ( $resql );
if ( $i >= $maxCount ) {
$othernb += 1 ;
$i ++ ;
$tot_ttc += $obj -> total_ttc ;
continue ;
}
$facturesupplierstatic -> ref = $obj -> ref ;
$facturesupplierstatic -> id = $obj -> rowid ;
$facturesupplierstatic -> total_ht = $obj -> total_ht ;
$facturesupplierstatic -> total_tva = $obj -> total_tva ;
$facturesupplierstatic -> total_ttc = $obj -> total_ttc ;
$facturesupplierstatic -> ref_supplier = $obj -> ref_supplier ;
$facturesupplierstatic -> type = $obj -> type ;
$facturesupplierstatic -> statut = $obj -> status ;
2024-06-26 17:04:05 +02:00
$facturesupplierstatic -> status = $obj -> status ;
2023-02-04 12:31:50 +01:00
$facturesupplierstatic -> paye = $obj -> paye ;
2024-03-29 23:04:34 +01:00
$facturesupplierstatic -> paid = $obj -> paye ;
2023-02-04 12:31:50 +01:00
$companystatic -> id = $obj -> socid ;
$companystatic -> name = $obj -> name ;
$companystatic -> email = $obj -> email ;
$companystatic -> country_id = $obj -> country_id ;
$companystatic -> country_code = $obj -> country_code ;
$companystatic -> fournisseur = 1 ;
$companystatic -> code_client = $obj -> code_client ;
$companystatic -> code_fournisseur = $obj -> code_fournisseur ;
$companystatic -> code_compta = $obj -> code_compta ;
2024-08-14 16:51:53 +02:00
$companystatic -> code_compta_client = $obj -> code_compta ;
2023-02-04 12:31:50 +01:00
$companystatic -> code_compta_fournisseur = $obj -> code_compta_fournisseur ;
$result .= '<tr class="oddeven">' ;
$result .= '<td class="nowrap tdoverflowmax100">' ;
$result .= $facturesupplierstatic -> getNomUrl ( 1 , '' );
$result .= '</td>' ;
$result .= '<td class="nowrap tdoverflowmax100">' ;
$result .= $companystatic -> getNomUrl ( 1 , 'supplier' );
$result .= '</td>' ;
$result .= '<td class="right"><span class="amount">' . price ( $obj -> total_ttc ) . '</span></td>' ;
$result .= '</tr>' ;
2021-04-05 19:34:56 +02:00
$tot_ttc += $obj -> total_ttc ;
2023-02-04 12:31:50 +01:00
$i ++ ;
2021-04-05 19:34:56 +02:00
}
2023-02-04 12:31:50 +01:00
if ( $othernb ) {
$result .= '<tr class="oddeven">' ;
$result .= '<td class="nowrap" colspan="3">' ;
$result .= '<span class="opacitymedium">' . $langs -> trans ( " More " ) . '...' . ( $othernb < $maxofloop ? ' (' . $othernb . ')' : '' ) . '</span>' ;
$result .= '</td>' ;
$result .= " </tr> \n " ;
}
2021-04-05 19:34:56 +02:00
2023-02-04 12:31:50 +01:00
$result .= '<tr class="liste_total"><td class="left">' . $langs -> trans ( " Total " ) . '</td>' ;
$result .= '<td colspan="2" class="right">' . price ( $tot_ttc ) . '</td>' ;
$result .= '</tr>' ;
} else {
2023-09-22 13:50:52 +02:00
$result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">' . $langs -> trans ( " NoInvoice " ) . '</span></td></tr>' ;
2021-04-05 19:34:56 +02:00
}
2023-02-04 12:31:50 +01:00
$result .= " </table></div> " ;
$db -> free ( $resql );
2021-04-05 19:34:56 +02:00
} else {
2023-02-04 12:31:50 +01:00
dol_print_error ( $db );
2021-04-05 19:34:56 +02:00
}
}
return $result ;
}
/**
* Return a HTML table that contains a list with latest edited customer invoices
*
* @ param int $maxCount ( Optional ) The maximum count of elements inside the table
* @ param int $socid ( Optional ) Show only results from the customer with this id
* @ return string A HTML table that contains a list with latest edited customer invoices
*/
function getCustomerInvoiceLatestEditTable ( $maxCount = 5 , $socid = 0 )
{
global $conf , $db , $langs , $user ;
2021-06-10 01:10:35 +02:00
$sql = " SELECT f.rowid, f.entity, f.ref, f.fk_statut as status, f.paye, f.type, f.total_ht, f.total_tva, f.total_ttc, f.datec, " ;
$sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client " ;
2021-04-05 19:34:56 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " , " . MAIN_DB_PREFIX . " societe as s " ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2021-04-05 19:34:56 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
$sql .= " WHERE f.fk_soc = s.rowid " ;
$sql .= " AND f.entity IN ( " . getEntity ( 'facture' ) . " ) " ;
if ( $socid ) {
$sql .= " AND f.fk_soc = " . (( int ) $socid );
}
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-04-05 19:34:56 +02:00
}
$sql .= " ORDER BY f.tms DESC " ;
$sql .= $db -> plimit ( $maxCount , 0 );
$resql = $db -> query ( $sql );
if ( ! $resql ) {
dol_print_error ( $db );
}
$num = $db -> num_rows ( $resql );
$result = '<div class="div-table-responsive-no-min">' ;
$result .= '<table class="noborder centpercent">' ;
$result .= '<tr class="liste_titre">' ;
2021-08-23 23:53:58 +02:00
$result .= '<th colspan="3">' . $langs -> trans ( " LastCustomersBills " , $maxCount ) . '</th>' ;
$result .= '<th class="right">' . $langs -> trans ( " AmountTTC " ) . '</th>' ;
$result .= '<th class="right"></th>' ;
2021-04-05 19:34:56 +02:00
$result .= '</tr>' ;
if ( $num < 1 ) {
$result .= '</table>' ;
$result .= '</div>' ;
return $result ;
}
$formfile = new FormFile ( $db );
$objectstatic = new Facture ( $db );
$companystatic = new Societe ( $db );
$i = 0 ;
while ( $i < $num ) {
$obj = $db -> fetch_object ( $resql );
$objectstatic -> id = $obj -> rowid ;
$objectstatic -> ref = $obj -> ref ;
$objectstatic -> paye = $obj -> paye ;
$objectstatic -> statut = $obj -> status ;
2024-12-30 03:14:20 +01:00
$objectstatic -> status = $obj -> status ;
2021-06-10 01:10:35 +02:00
$objectstatic -> total_ht = $obj -> total_ht ;
$objectstatic -> total_tva = $obj -> total_tva ;
$objectstatic -> total_ttc = $obj -> total_ttc ;
$objectstatic -> type = $obj -> type ;
2021-04-05 19:34:56 +02:00
$companystatic -> id = $obj -> socid ;
$companystatic -> name = $obj -> socname ;
$companystatic -> client = $obj -> client ;
$companystatic -> canvas = $obj -> canvas ;
$filename = dol_sanitizeFileName ( $obj -> ref );
$filedir = $conf -> propal -> multidir_output [ $obj -> entity ] . '/' . $filename ;
2021-08-23 23:53:58 +02:00
$result .= '<tr class="nowrap">' ;
2021-04-05 19:34:56 +02:00
$result .= '<td class="oddeven">' ;
$result .= '<table class="nobordernopadding">' ;
$result .= '<tr class="nocellnopadd">' ;
$result .= '<td width="96" class="nobordernopadding nowrap">' . $objectstatic -> getNomUrl ( 1 ) . '</td>' ;
$result .= '<td width="16" class="nobordernopadding nowrap"> </td>' ;
$result .= '<td width="16" class="nobordernopadding right">' . $formfile -> getDocumentsLink ( $objectstatic -> element , $filename , $filedir ) . '</td>' ;
$result .= '</tr>' ;
$result .= '</table>' ;
$result .= '</td>' ;
2021-08-23 23:53:58 +02:00
$result .= '<td class="tdoverflowmax150">' . $companystatic -> getNomUrl ( 1 , 'customer' ) . '</td>' ;
2021-04-05 19:34:56 +02:00
$result .= '<td>' . dol_print_date ( $db -> jdate ( $obj -> datec ), 'day' ) . '</td>' ;
2021-08-23 23:53:58 +02:00
$result .= '<td class="right amount">' . price ( $obj -> total_ttc ) . '</td>' ;
2022-10-05 10:31:32 +02:00
2022-10-06 11:52:40 +02:00
// Load amount of existing payment of invoice (needed for complete status)
2022-10-05 10:31:32 +02:00
$payment = $objectstatic -> getSommePaiement ();
2024-12-30 03:14:20 +01:00
$result .= '<td class="right">' . $objectstatic -> getLibStatut ( 3 , $payment ) . '</td>' ;
2021-04-05 19:34:56 +02:00
$result .= '</tr>' ;
$i ++ ;
}
$result .= '</table>' ;
$result .= '</div>' ;
return $result ;
}
/**
* Return a HTML table that contains a list with latest edited supplier invoices
*
* @ param int $maxCount ( Optional ) The maximum count of elements inside the table
* @ param int $socid ( Optional ) Show only results from the supplier with this id
* @ return string A HTML table that contains a list with latest edited supplier invoices
*/
function getPurchaseInvoiceLatestEditTable ( $maxCount = 5 , $socid = 0 )
{
global $conf , $db , $langs , $user ;
2021-06-10 01:10:35 +02:00
$sql = " SELECT f.rowid, f.entity, f.ref, f.fk_statut as status, f.paye, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier, f.datec, " ;
$sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client " ;
2021-04-05 19:34:56 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture_fourn as f " ;
$sql .= " , " . MAIN_DB_PREFIX . " societe as s " ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2021-04-05 19:34:56 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
$sql .= " WHERE f.fk_soc = s.rowid " ;
$sql .= " AND f.entity IN ( " . getEntity ( 'facture_fourn' ) . " ) " ;
if ( $socid ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND f.fk_soc = " . (( int ) $socid );
2021-04-05 19:34:56 +02:00
}
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-04-05 19:34:56 +02:00
}
$sql .= " ORDER BY f.tms DESC " ;
$sql .= $db -> plimit ( $maxCount , 0 );
$resql = $db -> query ( $sql );
if ( ! $resql ) {
dol_print_error ( $db );
return '' ;
}
$num = $db -> num_rows ( $resql );
$result = '<div class="div-table-responsive-no-min">' ;
$result .= '<table class="noborder centpercent">' ;
$result .= '<tr class="liste_titre">' ;
2024-06-22 02:51:10 +02:00
$result .= '<th colspan="3">' . $langs -> trans ( " BoxTitleLastSupplierBills " , $maxCount ) . ' ' ;
$result .= '<a href="' . DOL_URL_ROOT . '/fourn/facture/list.php?sortfield=f.tms&sortorder=DESC">' ;
$result .= '<span class="badge">...</span>' ;
$result .= '</a>' ;
$result .= '</th>' ;
2021-08-23 23:53:58 +02:00
$result .= '<th class="right">' . $langs -> trans ( " AmountTTC " ) . '</th>' ;
$result .= '<th class="right"></th>' ;
2021-04-05 19:34:56 +02:00
$result .= '</tr>' ;
if ( $num < 1 ) {
$result .= '</table>' ;
$result .= '</div>' ;
return $result ;
}
$objectstatic = new FactureFournisseur ( $db );
$companystatic = new Societe ( $db );
$formfile = new FormFile ( $db );
$i = 0 ;
while ( $i < $num ) {
$obj = $db -> fetch_object ( $resql );
$objectstatic -> id = $obj -> rowid ;
$objectstatic -> ref = $obj -> ref ;
$objectstatic -> paye = $obj -> paye ;
2024-03-29 23:04:34 +01:00
$objectstatic -> paid = $obj -> paye ;
2021-04-05 19:34:56 +02:00
$objectstatic -> statut = $obj -> status ;
2024-03-29 23:04:34 +01:00
$objectstatic -> status = $obj -> status ;
2021-06-10 01:10:35 +02:00
$objectstatic -> total_ht = $obj -> total_ht ;
$objectstatic -> total_tva = $obj -> total_tva ;
$objectstatic -> total_ttc = $obj -> total_ttc ;
$objectstatic -> type = $obj -> type ;
2021-04-05 19:34:56 +02:00
$companystatic -> id = $obj -> socid ;
$companystatic -> name = $obj -> socname ;
$companystatic -> client = $obj -> client ;
$companystatic -> canvas = $obj -> canvas ;
$filename = dol_sanitizeFileName ( $obj -> ref );
$filedir = $conf -> propal -> multidir_output [ $obj -> entity ] . '/' . $filename ;
2021-08-23 23:53:58 +02:00
$result .= '<tr class="nowrap">' ;
2021-04-05 19:34:56 +02:00
$result .= '<td class="oddeven">' ;
$result .= '<table class="nobordernopadding">' ;
$result .= '<tr class="nocellnopadd">' ;
$result .= '<td width="96" class="nobordernopadding nowrap">' . $objectstatic -> getNomUrl ( 1 ) . '</td>' ;
$result .= '<td width="16" class="nobordernopadding nowrap"> </td>' ;
$result .= '<td width="16" class="nobordernopadding right">' . $formfile -> getDocumentsLink ( $objectstatic -> element , $filename , $filedir ) . '</td>' ;
$result .= '</tr>' ;
$result .= '</table>' ;
$result .= '</td>' ;
2021-08-23 23:53:58 +02:00
$result .= '<td class="tdoverflowmax150">' . $companystatic -> getNomUrl ( 1 , 'supplier' ) . '</td>' ;
2024-12-30 03:14:20 +01:00
$result .= '<td title="' . $langs -> trans ( " DateModification " ) . ': ' . dol_print_date ( $db -> jdate ( $obj -> datec ), 'dayhour' ) . '">' . dol_print_date ( $db -> jdate ( $obj -> datec ), 'day' ) . '</td>' ;
2021-08-23 23:53:58 +02:00
$result .= '<td class="amount right">' . price ( $obj -> total_ttc ) . '</td>' ;
2024-12-30 03:14:20 +01:00
$result .= '<td class="right">' . $objectstatic -> getLibStatut ( 3 ) . '</td>' ;
2021-04-05 19:34:56 +02:00
$result .= '</tr>' ;
$i ++ ;
}
$result .= '</table>' ;
$result .= '</div>' ;
return $result ;
}
/**
* Return a HTML table that contains of unpaid customers invoices
*
* @ param int $maxCount ( Optional ) The maximum count of elements inside the table
* @ param int $socid ( Optional ) Show only results from the supplier with this id
2024-01-13 19:48:20 +01:00
* @ return string A HTML table that contains a list with open ( unpaid ) supplier invoices
2021-04-05 19:34:56 +02:00
*/
function getCustomerInvoiceUnpaidOpenTable ( $maxCount = 500 , $socid = 0 )
{
global $conf , $db , $langs , $user , $hookmanager ;
$result = '' ;
2024-02-27 15:30:37 +01:00
if ( isModEnabled ( 'invoice' ) && $user -> hasRight ( 'facture' , 'lire' )) {
2021-04-05 19:34:56 +02:00
$tmpinvoice = new Facture ( $db );
2021-04-06 20:16:14 +02:00
$sql = " SELECT f.rowid, f.ref, f.fk_statut as status, f.datef, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms " ;
2021-04-05 19:34:56 +02:00
$sql .= " , f.date_lim_reglement as datelimite " ;
$sql .= " , s.nom as name " ;
$sql .= " , s.rowid as socid, s.email " ;
$sql .= " , s.code_client, s.code_compta " ;
$sql .= " , s.code_fournisseur, s.code_compta_fournisseur " ;
$sql .= " , cc.rowid as country_id, cc.code as country_code " ;
$sql .= " , sum(pf.amount) as am " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s LEFT JOIN " . MAIN_DB_PREFIX . " c_country as cc ON cc.rowid = s.fk_pays, " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " paiement_facture as pf on f.rowid=pf.fk_facture " ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2021-04-05 19:34:56 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
$sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = " . Facture :: STATUS_VALIDATED ;
$sql .= " AND f.entity IN ( " . getEntity ( 'invoice' ) . ')' ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-04-05 19:34:56 +02:00
}
if ( $socid ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND f.fk_soc = " . (( int ) $socid );
2021-04-05 19:34:56 +02:00
}
// Add where from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhereCustomerUnpaid' , $parameters );
$sql .= $hookmanager -> resPrint ;
2021-04-06 20:16:14 +02:00
$sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.datef, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms, f.date_lim_reglement, " ;
2021-04-05 19:34:56 +02:00
$sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code " ;
$sql .= " , s.code_fournisseur, s.code_compta_fournisseur " ;
$sql .= " ORDER BY f.datef ASC, f.ref ASC " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
$i = 0 ;
$othernb = 0 ;
$formfile = new FormFile ( $db );
print '<div class="div-table-responsive-no-min">' ;
print '<table class="noborder centpercent">' ;
print '<tr class="liste_titre">' ;
print '<th colspan="2">' ;
print $langs -> trans ( " BillsCustomersUnpaid " , $num ) . ' ' ;
print '<a href="' . DOL_URL_ROOT . '/compta/facture/list.php?search_status=' . Facture :: STATUS_VALIDATED . '">' ;
print '<span class="badge">' . $num . '</span>' ;
print '</a>' ;
print '</th>' ;
print '<th class="right">' . $langs -> trans ( " DateDue " ) . '</th>' ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_SHOW_HT_ON_SUMMARY' )) {
2021-04-05 19:34:56 +02:00
print '<th class="right">' . $langs -> trans ( " AmountHT " ) . '</th>' ;
}
print '<th class="right">' . $langs -> trans ( " AmountTTC " ) . '</th>' ;
print '<th class="right">' . $langs -> trans ( " Received " ) . '</th>' ;
print '<th width="16"> </th>' ;
print '</tr>' ;
if ( $num ) {
$societestatic = new Societe ( $db );
$total_ttc = $totalam = $total = 0 ;
while ( $i < $num ) {
$obj = $db -> fetch_object ( $resql );
if ( $i >= $maxCount ) {
$othernb += 1 ;
$i ++ ;
$total += $obj -> total_ht ;
$total_ttc += $obj -> total_ttc ;
2022-07-08 17:30:15 +02:00
$totalam += $obj -> am ;
2021-04-05 19:34:56 +02:00
continue ;
}
$tmpinvoice -> ref = $obj -> ref ;
$tmpinvoice -> id = $obj -> rowid ;
$tmpinvoice -> total_ht = $obj -> total_ht ;
$tmpinvoice -> total_tva = $obj -> total_tva ;
$tmpinvoice -> total_ttc = $obj -> total_ttc ;
$tmpinvoice -> type = $obj -> type ;
$tmpinvoice -> statut = $obj -> status ;
$tmpinvoice -> paye = $obj -> paye ;
$tmpinvoice -> date_lim_reglement = $db -> jdate ( $obj -> datelimite );
$societestatic -> id = $obj -> socid ;
$societestatic -> name = $obj -> name ;
$societestatic -> email = $obj -> email ;
$societestatic -> country_id = $obj -> country_id ;
$societestatic -> country_code = $obj -> country_code ;
$societestatic -> client = 1 ;
$societestatic -> code_client = $obj -> code_client ;
$societestatic -> code_fournisseur = $obj -> code_fournisseur ;
$societestatic -> code_compta = $obj -> code_compta ;
2024-08-14 16:51:53 +02:00
$societestatic -> code_compta_client = $obj -> code_compta ;
2021-04-05 19:34:56 +02:00
$societestatic -> code_compta_fournisseur = $obj -> code_compta_fournisseur ;
print '<tr class="oddeven">' ;
print '<td class="nowrap">' ;
print '<table class="nobordernopadding"><tr class="nocellnopadd">' ;
print '<td class="nobordernopadding nowrap">' ;
print $tmpinvoice -> getNomUrl ( 1 , '' );
print '</td>' ;
print '<td width="16" class="nobordernopadding hideonsmartphone right">' ;
$filename = dol_sanitizeFileName ( $obj -> ref );
$filedir = $conf -> facture -> dir_output . '/' . dol_sanitizeFileName ( $obj -> ref );
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?facid=' . $obj -> rowid ;
print $formfile -> getDocumentsLink ( $tmpinvoice -> element , $filename , $filedir );
print '</td></tr></table>' ;
print '</td>' ;
print '<td class="nowrap tdoverflowmax100">' ;
print $societestatic -> getNomUrl ( 1 , 'customer' );
print '</td>' ;
2022-02-07 14:34:27 +01:00
print '<td class="right">' ;
print dol_print_date ( $db -> jdate ( $obj -> datelimite ), 'day' );
if ( $tmpinvoice -> hasDelay ()) {
print img_warning ( $langs -> trans ( " Late " ));
}
print '</td>' ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_SHOW_HT_ON_SUMMARY' )) {
2021-04-05 19:34:56 +02:00
print '<td class="right"><span class="amount">' . price ( $obj -> total_ht ) . '</span></td>' ;
}
print '<td class="nowrap right"><span class="amount">' . price ( $obj -> total_ttc ) . '</span></td>' ;
print '<td class="nowrap right"><span class="amount">' . price ( $obj -> am ) . '</span></td>' ;
print '<td>' . $tmpinvoice -> getLibStatut ( 3 , $obj -> am ) . '</td>' ;
print '</tr>' ;
$total_ttc += $obj -> total_ttc ;
$total += $obj -> total_ht ;
$totalam += $obj -> am ;
$i ++ ;
}
if ( $othernb ) {
$colspan = 6 ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_SHOW_HT_ON_SUMMARY' )) {
2021-04-05 19:34:56 +02:00
$colspan ++ ;
}
print '<tr class="oddeven">' ;
print '<td class="nowrap" colspan="' . $colspan . '">' ;
print '<span class="opacitymedium">' . $langs -> trans ( " More " ) . '... (' . $othernb . ')</span>' ;
print '</td>' ;
print " </tr> \n " ;
}
2021-10-05 09:41:03 +02:00
print '<tr class="liste_total"><td colspan="2">' . $langs -> trans ( " Total " ) . ' <span style="font-weight: normal">(' . $langs -> trans ( " RemainderToTake " ) . ': ' . price ( $total_ttc - $totalam ) . ')</span> </td>' ;
2021-04-05 19:34:56 +02:00
print '<td> </td>' ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_SHOW_HT_ON_SUMMARY' )) {
2021-04-05 19:34:56 +02:00
print '<td class="right"><span class="amount">' . price ( $total ) . '</span></td>' ;
}
print '<td class="nowrap right"><span class="amount">' . price ( $total_ttc ) . '</span></td>' ;
print '<td class="nowrap right"><span class="amount">' . price ( $totalam ) . '</span></td>' ;
print '<td> </td>' ;
print '</tr>' ;
} else {
$colspan = 6 ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_SHOW_HT_ON_SUMMARY' )) {
2021-04-05 19:34:56 +02:00
$colspan ++ ;
}
print '<tr class="oddeven"><td colspan="' . $colspan . '" class="opacitymedium">' . $langs -> trans ( " NoInvoice " ) . '</td></tr>' ;
}
print '</table></div><br>' ;
$db -> free ( $resql );
} else {
dol_print_error ( $db );
}
}
return $result ;
}
/**
* Return a HTML table that contains of unpaid purchase invoices
*
* @ param int $maxCount ( Optional ) The maximum count of elements inside the table
* @ param int $socid ( Optional ) Show only results from the supplier with this id
2024-01-13 19:48:20 +01:00
* @ return string A HTML table that contains a list with open ( unpaid ) supplier invoices
2021-04-05 19:34:56 +02:00
*/
function getPurchaseInvoiceUnpaidOpenTable ( $maxCount = 500 , $socid = 0 )
{
global $conf , $db , $langs , $user , $hookmanager ;
$result = '' ;
2023-04-18 16:40:38 +02:00
if ( isModEnabled ( " supplier_invoice " ) && ( $user -> hasRight ( 'fournisseur' , 'facture' , 'lire' ) || $user -> hasRight ( 'supplier_invoice' , 'read' ))) {
2021-04-05 19:34:56 +02:00
$facstatic = new FactureFournisseur ( $db );
$sql = " SELECT ff.rowid, ff.ref, ff.fk_statut as status, ff.type, ff.libelle as label, ff.total_ht, ff.total_tva, ff.total_ttc, ff.paye " ;
$sql .= " , ff.date_lim_reglement " ;
$sql .= " , s.nom as name " ;
$sql .= " , s.rowid as socid, s.email " ;
$sql .= " , s.code_client, s.code_compta " ;
$sql .= " , s.code_fournisseur, s.code_compta_fournisseur " ;
$sql .= " , sum(pf.amount) as am " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture_fourn as ff " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn " ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2021-04-05 19:34:56 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
$sql .= " WHERE s.rowid = ff.fk_soc " ;
$sql .= " AND ff.entity = " . $conf -> entity ;
$sql .= " AND ff.paye = 0 " ;
$sql .= " AND ff.fk_statut = " . FactureFournisseur :: STATUS_VALIDATED ;
2024-01-09 13:08:22 +01:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-04-05 19:34:56 +02:00
}
if ( $socid ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND ff.fk_soc = " . (( int ) $socid );
2021-04-05 19:34:56 +02:00
}
// Add where from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhereSupplierUnpaid' , $parameters );
$sql .= $hookmanager -> resPrint ;
2021-04-06 20:16:14 +02:00
$sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.type, ff.libelle, ff.total_ht, ff.total_tva, ff.total_ttc, ff.paye, ff.date_lim_reglement, " ;
2021-04-05 19:34:56 +02:00
$sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur " ;
$sql .= " ORDER BY ff.date_lim_reglement ASC " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
$othernb = 0 ;
print '<div class="div-table-responsive-no-min">' ;
print '<table class="noborder centpercent">' ;
print '<tr class="liste_titre">' ;
print '<th colspan="2">' ;
print $langs -> trans ( " BillsSuppliersUnpaid " , $num ) . ' ' ;
print '<a href="' . DOL_URL_ROOT . '/fourn/facture/list.php?search_status=' . FactureFournisseur :: STATUS_VALIDATED . '">' ;
print '<span class="badge">' . $num . '</span>' ;
print '</a>' ;
print '</th>' ;
print '<th class="right">' . $langs -> trans ( " DateDue " ) . '</th>' ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_SHOW_HT_ON_SUMMARY' )) {
2021-04-05 19:34:56 +02:00
print '<th class="right">' . $langs -> trans ( " AmountHT " ) . '</th>' ;
}
print '<th class="right">' . $langs -> trans ( " AmountTTC " ) . '</th>' ;
print '<th class="right">' . $langs -> trans ( " Paid " ) . '</th>' ;
print '<th width="16"> </th>' ;
print " </tr> \n " ;
2024-12-30 03:14:20 +01:00
2021-04-05 19:34:56 +02:00
$societestatic = new Societe ( $db );
2024-12-30 03:14:20 +01:00
2021-04-05 19:34:56 +02:00
if ( $num ) {
$i = 0 ;
$total = $total_ttc = $totalam = 0 ;
while ( $i < $num ) {
$obj = $db -> fetch_object ( $resql );
if ( $i >= $maxCount ) {
$othernb += 1 ;
$i ++ ;
$total += $obj -> total_ht ;
$total_ttc += $obj -> total_ttc ;
continue ;
}
$facstatic -> ref = $obj -> ref ;
$facstatic -> id = $obj -> rowid ;
$facstatic -> type = $obj -> type ;
$facstatic -> total_ht = $obj -> total_ht ;
$facstatic -> total_tva = $obj -> total_tva ;
$facstatic -> total_ttc = $obj -> total_ttc ;
$facstatic -> statut = $obj -> status ;
2024-03-29 23:04:34 +01:00
$facstatic -> status = $obj -> status ;
$facstatic -> paid = $obj -> paye ;
2021-04-05 19:34:56 +02:00
$facstatic -> paye = $obj -> paye ;
$societestatic -> id = $obj -> socid ;
$societestatic -> name = $obj -> name ;
$societestatic -> email = $obj -> email ;
$societestatic -> client = 0 ;
$societestatic -> fournisseur = 1 ;
$societestatic -> code_client = $obj -> code_client ;
$societestatic -> code_fournisseur = $obj -> code_fournisseur ;
$societestatic -> code_compta = $obj -> code_compta ;
2024-08-14 16:51:53 +02:00
$societestatic -> code_compta_client = $obj -> code_compta ;
2021-04-05 19:34:56 +02:00
$societestatic -> code_compta_fournisseur = $obj -> code_compta_fournisseur ;
2021-08-23 23:53:58 +02:00
print '<tr class="oddeven">' ;
print '<td class="nowrap tdoverflowmax100">' ;
2021-04-05 19:34:56 +02:00
print $facstatic -> getNomUrl ( 1 , '' );
print '</td>' ;
print '<td class="nowrap tdoverflowmax100">' . $societestatic -> getNomUrl ( 1 , 'supplier' ) . '</td>' ;
print '<td class="right">' . dol_print_date ( $db -> jdate ( $obj -> date_lim_reglement ), 'day' ) . '</td>' ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_SHOW_HT_ON_SUMMARY' )) {
2021-04-05 19:34:56 +02:00
print '<td class="right"><span class="amount">' . price ( $obj -> total_ht ) . '</span></td>' ;
}
print '<td class="nowrap right"><span class="amount">' . price ( $obj -> total_ttc ) . '</span></td>' ;
print '<td class="nowrap right"><span class="amount">' . price ( $obj -> am ) . '</span></td>' ;
print '<td>' . $facstatic -> getLibStatut ( 3 , $obj -> am ) . '</td>' ;
print '</tr>' ;
$total += $obj -> total_ht ;
$total_ttc += $obj -> total_ttc ;
$totalam += $obj -> am ;
$i ++ ;
}
if ( $othernb ) {
$colspan = 6 ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_SHOW_HT_ON_SUMMARY' )) {
2021-04-05 19:34:56 +02:00
$colspan ++ ;
}
print '<tr class="oddeven">' ;
print '<td class="nowrap" colspan="' . $colspan . '">' ;
print '<span class="opacitymedium">' . $langs -> trans ( " More " ) . '... (' . $othernb . ')</span>' ;
print '</td>' ;
print " </tr> \n " ;
}
2021-10-05 09:41:03 +02:00
print '<tr class="liste_total"><td colspan="2">' . $langs -> trans ( " Total " ) . ' <span style="font-weight: normal">(' . $langs -> trans ( " RemainderToPay " ) . ': ' . price ( $total_ttc - $totalam ) . ')</span> </td>' ;
2021-04-05 19:34:56 +02:00
print '<td> </td>' ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_SHOW_HT_ON_SUMMARY' )) {
2021-04-05 19:34:56 +02:00
print '<td class="right">' . price ( $total ) . '</td>' ;
}
print '<td class="nowrap right">' . price ( $total_ttc ) . '</td>' ;
print '<td class="nowrap right">' . price ( $totalam ) . '</td>' ;
print '<td> </td>' ;
print '</tr>' ;
} else {
$colspan = 6 ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_SHOW_HT_ON_SUMMARY' )) {
2021-04-05 19:34:56 +02:00
$colspan ++ ;
}
print '<tr class="oddeven"><td colspan="' . $colspan . '" class="opacitymedium">' . $langs -> trans ( " NoInvoice " ) . '</td></tr>' ;
}
print '</table></div><br>' ;
} else {
dol_print_error ( $db );
}
}
return $result ;
}