2005-01-18 11:02:26 +01:00
< ? php
2005-01-31 16:14:59 +01:00
/* Copyright ( C ) 2002 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2008-09-06 00:37:21 +02:00
* Copyright ( C ) 2004 Eric Seigne < eric . seigne @ ryxeo . com >
2014-01-30 11:44:31 +01:00
* Copyright ( C ) 2004 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:11:07 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2005-01-18 11:02:26 +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-01-18 11:02:26 +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
2011-08-01 00:21:57 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2005-01-18 11:02:26 +01:00
*/
/**
2008-09-04 21:47:46 +02:00
* \file htdocs / compta / facture / impayees . php
* \ingroup facture
2009-08-19 19:07:48 +02:00
* \brief Page to list and build liste of unpaid invoices
2008-09-04 21:47:46 +02:00
*/
2005-01-18 11:02:26 +01:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php' ;
2005-01-18 11:02:26 +01:00
2009-01-21 17:53:50 +01:00
2005-01-18 11:02:26 +01:00
$langs -> load ( " bills " );
2011-11-11 16:10:50 +01:00
$id = ( GETPOST ( 'facid' , 'int' ) ? GETPOST ( 'facid' , 'int' ) : GETPOST ( 'id' , 'int' ));
$action = GETPOST ( 'action' , 'alpha' );
$option = GETPOST ( 'option' );
2008-09-04 21:47:46 +02:00
// Security check
2008-02-25 21:03:21 +01:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2011-11-11 16:10:50 +01:00
$result = restrictedArea ( $user , 'facture' , $id , '' );
2005-01-18 11:02:26 +01:00
2014-01-30 11:44:31 +01:00
$diroutputpdf = $conf -> facture -> dir_output . '/unpaid/temp' ;
if ( ! $user -> rights -> societe -> client -> voir || $socid ) $diroutputpdf .= '/private/' . $user -> id ; // If user has no permission to see all, output dir is specific to user
2005-01-18 11:02:26 +01:00
2008-09-04 21:47:46 +02:00
/*
2008-09-06 00:37:21 +02:00
* Action
2008-09-04 21:47:46 +02:00
*/
2005-01-18 11:02:26 +01:00
2013-12-14 02:31:06 +01:00
if ( $action == " builddoc " && $user -> rights -> facture -> lire && ! GETPOST ( 'button_search' ))
2005-01-18 11:02:26 +01:00
{
2008-09-04 21:47:46 +02:00
if ( is_array ( $_POST [ 'toGenerate' ]))
2006-11-18 02:16:10 +01:00
{
2013-01-07 00:14:38 +01:00
$arrayofinclusion = array ();
foreach ( $_POST [ 'toGenerate' ] as $tmppdf ) $arrayofinclusion [] = preg_quote ( $tmppdf . '.pdf' , '/' );
$factures = dol_dir_list ( $conf -> facture -> dir_output , 'all' , 1 , implode ( '|' , $arrayofinclusion ), '\.meta$|\.png' , 'date' , SORT_DESC );
2008-09-04 21:47:46 +02:00
// liste les fichiers
2011-09-20 15:32:16 +02:00
$files = array ();
2008-09-04 21:47:46 +02:00
$factures_bak = $factures ;
foreach ( $_POST [ 'toGenerate' ] as $basename ){
foreach ( $factures as $facture ){
if ( strstr ( $facture [ " name " ], $basename )){
2011-09-08 21:40:49 +02:00
$files [] = $conf -> facture -> dir_output . '/' . $basename . '/' . $facture [ " name " ];
2008-09-04 21:47:46 +02:00
}
}
2006-11-18 02:16:10 +01:00
}
2009-01-21 17:53:50 +01:00
2011-08-11 14:13:59 +02:00
// Define output language (Here it is not used because we do only merging existing PDF)
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' )) $newlang = GETPOST ( 'lang_id' );
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
// Create empty PDF
$pdf = pdf_getInstance ();
if ( class_exists ( 'TCPDF' ))
{
$pdf -> setPrintHeader ( false );
$pdf -> setPrintFooter ( false );
}
$pdf -> SetFont ( pdf_getPDFFont ( $outputlangs ));
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_PDF_COMPRESSION )) $pdf -> SetCompression ( false );
2009-01-21 17:53:50 +01:00
2008-09-06 00:37:21 +02:00
// Add all others
foreach ( $files as $file )
{
2008-09-04 21:47:46 +02:00
// Charge un document PDF depuis un fichier.
2009-01-21 17:53:50 +01:00
$pagecount = $pdf -> setSourceFile ( $file );
for ( $i = 1 ; $i <= $pagecount ; $i ++ )
2010-09-06 12:35:07 +02:00
{
$tplidx = $pdf -> importPage ( $i );
$s = $pdf -> getTemplatesize ( $tplidx );
$pdf -> AddPage ( $s [ 'h' ] > $s [ 'w' ] ? 'P' : 'L' );
$pdf -> useTemplate ( $tplidx );
}
2008-09-04 21:47:46 +02:00
}
2009-01-21 17:53:50 +01:00
2008-09-06 00:37:21 +02:00
// Create output dir if not exists
2012-02-19 18:34:22 +01:00
dol_mkdir ( $diroutputpdf );
2008-09-06 00:37:21 +02:00
2009-04-09 23:53:53 +02:00
// Save merged file
2009-08-19 19:07:48 +02:00
$filename = strtolower ( dol_sanitizeFileName ( $langs -> transnoentities ( " Unpaid " )));
2009-04-29 20:02:50 +02:00
if ( $option == 'late' ) $filename .= '_' . strtolower ( dol_sanitizeFileName ( $langs -> transnoentities ( " Late " )));
2009-01-21 17:53:50 +01:00
if ( $pagecount )
2008-10-21 23:27:20 +02:00
{
2012-04-30 15:01:25 +02:00
$now = dol_now ();
$file = $diroutputpdf . '/' . $filename . '_' . dol_print_date ( $now , 'dayhourlog' ) . '.pdf' ;
2010-09-01 12:22:11 +02:00
$pdf -> Output ( $file , 'F' );
2009-01-21 17:53:50 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
2010-09-06 12:35:07 +02:00
@ chmod ( $file , octdec ( $conf -> global -> MAIN_UMASK ));
2008-10-21 23:27:20 +02:00
}
2009-01-21 17:53:50 +01:00
else
2008-10-21 23:27:20 +02:00
{
$mesg = '<div class="error">' . $langs -> trans ( 'NoPDFAvailableForChecked' ) . '</div>' ;
}
2009-01-21 17:53:50 +01:00
}
2008-09-04 21:47:46 +02:00
else
2006-11-18 02:16:10 +01:00
{
2009-04-09 22:22:51 +02:00
$mesg = '<div class="error">' . $langs -> trans ( 'InvoiceNotChecked' ) . '</div>' ;
2006-11-18 02:16:10 +01:00
}
2008-09-04 21:47:46 +02:00
}
2006-11-18 02:16:10 +01:00
2012-12-27 14:37:15 +01:00
// Remove file
2013-01-10 08:27:12 +01:00
if ( $action == 'remove_file' )
{
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
$langs -> load ( " other " );
$upload_dir = $diroutputpdf ;
2012-12-27 14:37:15 +01:00
$file = $upload_dir . '/' . GETPOST ( 'file' );
2013-01-10 08:27:12 +01:00
$ret = dol_delete_file ( $file , 0 , 0 , 0 , '' );
if ( $ret ) setEventMessage ( $langs -> trans ( " FileWasRemoved " , GETPOST ( 'urlfile' )));
else setEventMessage ( $langs -> trans ( " ErrorFailToDeleteFile " , GETPOST ( 'urlfile' )), 'errors' );
$action = '' ;
}
2012-12-27 14:37:15 +01:00
2008-09-06 00:37:21 +02:00
/*
* View
*/
2013-12-14 02:31:06 +01:00
$form = new Form ( $db );
$formfile = new FormFile ( $db );
2009-08-19 19:07:48 +02:00
$title = $langs -> trans ( " BillsCustomersUnpaid " );
if ( $option == 'late' ) $title = $langs -> trans ( " BillsCustomersUnpaid " );
2008-09-06 00:37:21 +02:00
llxHeader ( '' , $title );
2010-09-06 12:35:07 +02:00
?>
2011-11-11 16:10:50 +01:00
< script type = " text/javascript " >
2011-11-12 09:23:54 +01:00
$ ( document ) . ready ( function () {
$ ( " #checkall " ) . click ( function () {
$ ( " .checkformerge " ) . attr ( 'checked' , true );
2010-09-06 12:35:07 +02:00
});
2011-11-12 09:23:54 +01:00
$ ( " #checknone " ) . click ( function () {
$ ( " .checkformerge " ) . attr ( 'checked' , false );
2010-09-06 12:35:07 +02:00
});
});
2008-09-06 00:37:21 +02:00
</ script >
< ? php
2010-11-13 03:58:29 +01:00
$now = dol_now ();
2009-01-07 16:21:16 +01:00
2011-11-11 16:10:50 +01:00
$search_ref = GETPOST ( " search_ref " );
$search_societe = GETPOST ( " search_societe " );
$search_montant_ht = GETPOST ( " search_montant_ht " );
$search_montant_ttc = GETPOST ( " search_montant_ttc " );
$late = GETPOST ( " late " );
2010-11-20 14:08:44 +01:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
$page = GETPOST ( " page " , 'int' );
if ( $page == - 1 ) { $page = 0 ; }
$offset = $conf -> liste_limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2008-09-06 00:37:21 +02:00
if ( ! $sortfield ) $sortfield = " f.date_lim_reglement " ;
if ( ! $sortorder ) $sortorder = " ASC " ;
2008-09-04 21:47:46 +02:00
$limit = $conf -> liste_limit ;
$sql = " SELECT s.nom, s.rowid as socid " ;
2013-03-25 13:04:03 +01:00
$sql .= " , f.rowid as facid, f.facnumber, f.increment, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.localtax1, f.localtax2, f.revenuestamp " ;
2010-05-08 21:49:29 +02:00
$sql .= " , f.datef as df, f.date_lim_reglement as datelimite " ;
2013-03-25 12:20:24 +01:00
$sql .= " , f.paye as paye, f.fk_statut, f.type " ;
2008-09-04 21:47:46 +02:00
$sql .= " , sum(pf.amount) as am " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , sc.fk_soc, sc.fk_user " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
$sql .= " , " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " paiement_facture as pf ON f.rowid=pf.fk_facture " ;
$sql .= " WHERE f.fk_soc = s.rowid " ;
2012-02-01 11:32:55 +01:00
$sql .= " AND f.entity = " . $conf -> entity ;
2011-12-03 15:30:58 +01:00
$sql .= " AND f.type IN (0,1,3) AND f.fk_statut = 1 " ;
2008-09-04 21:47:46 +02:00
$sql .= " AND f.paye = 0 " ;
2011-11-22 02:15:58 +01:00
if ( $option == 'late' ) $sql .= " AND f.date_lim_reglement < ' " . $db -> idate ( dol_now () - $conf -> facture -> client -> warning_delay ) . " ' " ;
2008-09-04 21:47:46 +02:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
2012-08-16 20:11:48 +02:00
if ( ! empty ( $socid )) $sql .= " AND s.rowid = " . $socid ;
if ( GETPOST ( 'filtre' ))
2008-09-04 21:47:46 +02:00
{
2012-08-16 20:11:48 +02:00
$filtrearr = explode ( " , " , GETPOST ( 'filtre' ));
2008-09-04 21:47:46 +02:00
foreach ( $filtrearr as $fil )
2006-11-18 02:16:10 +01:00
{
2009-10-20 15:14:44 +02:00
$filt = explode ( " : " , $fil );
2008-09-04 21:47:46 +02:00
$sql .= " AND " . $filt [ 0 ] . " = " . $filt [ 1 ];
2006-11-18 02:16:10 +01:00
}
2008-09-04 21:47:46 +02:00
}
2013-12-14 02:31:06 +01:00
if ( $search_ref ) $sql .= " AND f.facnumber LIKE '% " . $db -> escape ( $search_ref ) . " %' " ;
if ( $search_societe ) $sql .= " AND s.nom LIKE '% " . $db -> escape ( $search_societe ) . " %' " ;
if ( $search_montant_ht ) $sql .= " AND f.total = ' " . $db -> escape ( $search_montant_ht ) . " ' " ;
if ( $search_montant_ttc ) $sql .= " AND f.total_ttc = ' " . $db -> escape ( $search_montant_ttc ) . " ' " ;
2013-03-25 12:20:24 +01:00
if ( GETPOST ( 'sf_ref' )) $sql .= " AND f.facnumber LIKE '% " . $db -> escape ( GETPOST ( 'sf_ref' )) . " %' " ;
2014-01-30 11:44:31 +01:00
$sql .= " GROUP BY s.nom, s.rowid, f.rowid, f.facnumber, f.increment, f.total, f.tva, f.total_ttc, f.localtax1, f.localtax2, f.revenuestamp, f.datef, f.date_lim_reglement, f.paye, f.fk_statut, f.type " ;
2011-11-22 02:15:58 +01:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , sc.fk_soc, sc.fk_user " ;
2008-09-04 21:47:46 +02:00
$sql .= " ORDER BY " ;
2009-10-20 15:14:44 +02:00
$listfield = explode ( ',' , $sortfield );
2008-09-04 21:47:46 +02:00
foreach ( $listfield as $key => $value ) $sql .= $listfield [ $key ] . " " . $sortorder . " , " ;
$sql .= " f.facnumber DESC " ;
2006-11-18 02:16:10 +01:00
2008-09-04 21:47:46 +02:00
//$sql .= $db->plimit($limit+1,$offset);
2006-11-18 02:16:10 +01:00
2011-11-22 02:15:58 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
2008-09-04 21:47:46 +02:00
{
2011-11-22 02:15:58 +01:00
$num = $db -> num_rows ( $resql );
2006-11-18 02:16:10 +01:00
2012-08-16 20:11:48 +02:00
if ( ! empty ( $socid ))
2008-09-04 21:47:46 +02:00
{
$soc = new Societe ( $db );
$soc -> fetch ( $socid );
}
2006-11-18 02:16:10 +01:00
2009-01-09 23:52:45 +01:00
$param = " " ;
2012-08-16 20:11:48 +02:00
$param .= ( ! empty ( $socid ) ? " &socid= " . $socid : " " );
$param .= ( ! empty ( $option ) ? " &option= " . $option : " " );
2011-11-11 16:10:50 +01:00
if ( $search_ref ) $param .= '&search_ref=' . urlencode ( $search_ref );
if ( $search_societe ) $param .= '&search_societe=' . urlencode ( $search_societe );
if ( $search_montant_ht ) $param .= '&search_montant_ht=' . urlencode ( $search_montant_ht );
if ( $search_montant_ttc ) $param .= '&search_montant_ttc=' . urlencode ( $search_montant_ttc );
if ( $late ) $param .= '&late=' . urlencode ( $late );
2009-01-21 17:53:50 +01:00
2009-01-09 23:52:45 +01:00
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder ;
2009-10-21 11:51:52 +02:00
$urlsource .= str_replace ( '&' , '&' , $param );
2009-01-21 17:53:50 +01:00
2012-08-16 20:11:48 +02:00
$titre = ( ! empty ( $socid ) ? $langs -> trans ( " BillsCustomersUnpaidForCompany " , $soc -> nom ) : $langs -> trans ( " BillsCustomersUnpaid " ));
2008-09-04 21:47:46 +02:00
if ( $option == 'late' ) $titre .= ' (' . $langs -> trans ( " Late " ) . ')' ;
else $titre .= ' (' . $langs -> trans ( " All " ) . ')' ;
2009-01-21 17:53:50 +01:00
2008-09-04 21:47:46 +02:00
$link = '' ;
2009-08-19 19:07:48 +02:00
if ( empty ( $option )) $link = '<a href="' . $_SERVER [ " PHP_SELF " ] . '?option=late">' . $langs -> trans ( " ShowUnpaidLateOnly " ) . '</a>' ;
elseif ( $option == 'late' ) $link = '<a href="' . $_SERVER [ " PHP_SELF " ] . '">' . $langs -> trans ( " ShowUnpaidAll " ) . '</a>' ;
2008-09-04 21:47:46 +02:00
print_fiche_titre ( $titre , $link );
//print_barre_liste($titre,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',0); // We don't want pagination on this page
2011-07-13 16:41:02 +02:00
dol_htmloutput_mesg ( $mesg );
2009-01-21 17:53:50 +01:00
2013-12-14 02:31:06 +01:00
print '<form id="form_generate_pdf" method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
if ( $late ) print '<input type="hidden" name="late" value="' . dol_escape_htmltag ( $late ) . '">' ;
2008-09-04 21:47:46 +02:00
$i = 0 ;
print '<table class="liste" width="100%">' ;
print '<tr class="liste_titre">' ;
print_liste_field_titre ( $langs -> trans ( " Ref " ), $_SERVER [ " PHP_SELF " ], " f.facnumber " , " " , $param , " " , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " Date " ), $_SERVER [ " PHP_SELF " ], " f.datef " , " " , $param , 'align="center"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " DateDue " ), $_SERVER [ " PHP_SELF " ], " f.date_lim_reglement " , " " , $param , 'align="center"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " Company " ), $_SERVER [ " PHP_SELF " ], " s.nom " , " " , $param , " " , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " AmountHT " ), $_SERVER [ " PHP_SELF " ], " f.total " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2013-03-25 12:20:24 +01:00
print_liste_field_titre ( $langs -> trans ( " Taxes " ), $_SERVER [ " PHP_SELF " ], " f.tva " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2008-09-04 21:47:46 +02:00
print_liste_field_titre ( $langs -> trans ( " AmountTTC " ), $_SERVER [ " PHP_SELF " ], " f.total_ttc " , " " , $param , 'align="right"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " Received " ), $_SERVER [ " PHP_SELF " ], " am " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2013-07-14 21:02:00 +02:00
print_liste_field_titre ( $langs -> trans ( " Rest " ), $_SERVER [ " PHP_SELF " ], " am " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2008-09-04 21:47:46 +02:00
print_liste_field_titre ( $langs -> trans ( " Status " ), $_SERVER [ " PHP_SELF " ], " fk_statut,paye,am " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2009-04-09 22:22:51 +02:00
print_liste_field_titre ( $langs -> trans ( " Merge " ), $_SERVER [ " PHP_SELF " ], " " , " " , $param , 'align="center"' , $sortfield , $sortorder );
2008-09-04 21:47:46 +02:00
print " </tr> \n " ;
// Lignes des champs de filtre
print '<tr class="liste_titre">' ;
2009-04-09 22:22:51 +02:00
// Ref
2008-09-04 21:47:46 +02:00
print '<td class="liste_titre">' ;
2011-11-11 16:10:50 +01:00
print '<input class="flat" size="10" type="text" name="search_ref" value="' . $search_ref . '"></td>' ;
2008-09-04 21:47:46 +02:00
print '<td class="liste_titre"> </td>' ;
print '<td class="liste_titre"> </td>' ;
2013-12-14 02:31:06 +01:00
print '<td class="liste_titre" align="left"><input class="flat" type="text" size="10" name="search_societe" value="' . dol_escape_htmltag ( $search_societe ) . '"></td>' ;
print '<td class="liste_titre" align="right"><input class="flat" type="text" size="8" name="search_montant_ht" value="' . dol_escape_htmltag ( $search_montant_ht ) . '"></td>' ;
2012-08-16 20:11:48 +02:00
print '<td class="liste_titre"> </td>' ;
2013-12-14 02:31:06 +01:00
print '<td class="liste_titre" align="right"><input class="flat" type="text" size="8" name="search_montant_ttc" value="' . dol_escape_htmltag ( $search_montant_ttc ) . '"></td>' ;
2013-07-14 21:02:00 +02:00
print '<td class="liste_titre"> </td>' ;
print '<td class="liste_titre"> </td>' ;
print '<td class="liste_titre" align="right">' ;
2014-01-13 09:43:21 +01:00
print '<input type="image" class="liste_titre" name="button_search" src="' . img_picto ( $langs -> trans ( " Search " ), 'search.png' , '' , '' , 1 ) . '" value="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '" title="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '">' ;
2008-09-04 21:47:46 +02:00
print '</td>' ;
2010-09-06 12:35:07 +02:00
print '<td class="liste_titre" align="center">' ;
if ( $conf -> use_javascript_ajax ) print '<a href="#" id="checkall">' . $langs -> trans ( " All " ) . '</a> / <a href="#" id="checknone">' . $langs -> trans ( " None " ) . '</a>' ;
print '</td>' ;
2008-09-04 21:47:46 +02:00
print " </tr> \n " ;
if ( $num > 0 )
{
$var = True ;
$total_ht = 0 ;
2012-08-16 20:11:48 +02:00
$total_tva = 0 ;
2008-09-04 21:47:46 +02:00
$total_ttc = 0 ;
2009-08-19 19:16:47 +02:00
$total_paid = 0 ;
2011-12-03 15:21:33 +01:00
2011-11-11 16:10:50 +01:00
$facturestatic = new Facture ( $db );
2008-09-04 21:47:46 +02:00
while ( $i < $num )
2006-11-18 02:16:10 +01:00
{
2011-11-22 02:15:58 +01:00
$objp = $db -> fetch_object ( $resql );
2011-12-03 15:21:33 +01:00
$date_limit = $db -> jdate ( $objp -> datelimite );
2008-09-04 21:47:46 +02:00
$var =! $var ;
2012-08-05 21:59:45 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2010-04-09 09:55:37 +02:00
$classname = " impayee " ;
2008-09-04 21:47:46 +02:00
2013-04-25 01:13:13 +02:00
print '<td class="nowrap">' ;
2009-01-21 17:53:50 +01:00
2008-09-04 21:47:46 +02:00
$facturestatic -> id = $objp -> facid ;
$facturestatic -> ref = $objp -> facnumber ;
$facturestatic -> type = $objp -> type ;
2009-01-21 17:53:50 +01:00
2008-09-04 21:47:46 +02:00
print '<table class="nobordernopadding"><tr class="nocellnopadd">' ;
2009-04-09 22:22:51 +02:00
// Ref
2013-04-25 01:13:13 +02:00
print '<td class="nobordernopadding nowrap">' ;
2008-09-04 21:47:46 +02:00
print $facturestatic -> getNomUrl ( 1 );
print '</td>' ;
2009-01-21 17:53:50 +01:00
2009-04-09 22:22:51 +02:00
// Warning picto
2013-04-25 01:13:13 +02:00
print '<td width="20" class="nobordernopadding nowrap">' ;
2011-12-03 15:21:33 +01:00
if ( $date_limit < ( $now - $conf -> facture -> client -> warning_delay ) && ! $objp -> paye && $objp -> fk_statut == 1 ) print img_warning ( $langs -> trans ( " Late " ));
2008-09-04 21:47:46 +02:00
print '</td>' ;
2009-01-21 17:53:50 +01:00
2009-04-09 22:22:51 +02:00
// PDF Picto
2013-04-25 20:27:45 +02:00
print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">' ;
2011-07-13 16:41:02 +02:00
$filename = dol_sanitizeFileName ( $objp -> facnumber );
2009-04-29 20:02:50 +02:00
$filedir = $conf -> facture -> dir_output . '/' . dol_sanitizeFileName ( $objp -> facnumber );
2012-09-15 09:02:20 +02:00
print $formfile -> getDocumentsLink ( $facturestatic -> element , $filename , $filedir );
2011-07-13 16:41:02 +02:00
print '</td>' ;
2009-01-21 17:53:50 +01:00
2009-04-09 22:22:51 +02:00
print '</tr></table>' ;
2009-01-21 17:53:50 +01:00
2008-09-04 21:47:46 +02:00
print " </td> \n " ;
2006-11-18 02:16:10 +01:00
2013-07-19 14:23:42 +02:00
print '<td class="nowrap" align="center">' . dol_print_date ( $db -> jdate ( $objp -> df ), 'day' ) . '</td>' . " \n " ;
print '<td class="nowrap" align="center">' . dol_print_date ( $db -> jdate ( $objp -> datelimite ), 'day' ) . '</td>' . " \n " ;
2006-11-18 02:16:10 +01:00
2011-01-06 13:46:25 +01:00
print '<td><a href="' . DOL_URL_ROOT . '/comm/fiche.php?socid=' . $objp -> socid . '">' . img_object ( $langs -> trans ( " ShowCompany " ), " company " ) . ' ' . dol_trunc ( $objp -> nom , 28 ) . '</a></td>' ;
2006-11-18 02:16:10 +01:00
2013-03-25 12:20:24 +01:00
print '<td align="right">' . price ( $objp -> total_ht ) . '</td>' ;
print '<td align="right">' . price ( $objp -> total_tva );
$tx1 = price2num ( $objp -> localtax1 );
$tx2 = price2num ( $objp -> localtax2 );
2013-03-25 13:04:03 +01:00
$revenuestamp = price2num ( $objp -> revenuestamp );
if ( ! empty ( $tx1 ) || ! empty ( $tx2 ) || ! empty ( $revenuestamp )) print '+' . price ( $tx1 + $tx2 + $revenuestamp );
2013-03-25 12:20:24 +01:00
print '</td>' ;
print '<td align="right">' . price ( $objp -> total_ttc ) . '</td>' ;
print '<td align="right">' ;
$cn = $facturestatic -> getSumCreditNotesUsed ();
if ( ! empty ( $objp -> am )) print price ( $objp -> am );
2013-03-30 14:27:13 +01:00
if ( ! empty ( $objp -> am ) && ! empty ( $cn )) print '+' ;
2013-03-25 12:20:24 +01:00
if ( ! empty ( $cn )) print price ( $cn );
print '</td>' ;
2013-04-28 01:24:58 +02:00
2013-03-25 12:20:24 +01:00
// Remain to receive
2013-07-14 21:02:00 +02:00
print '<td align="right">' . (( ! empty ( $objp -> am ) || ! empty ( $cn )) ? price ( $objp -> total_ttc - $objp -> am - $cn ) : ' ' ) . '</td>' ;
2005-06-26 00:54:02 +02:00
2013-03-25 12:20:24 +01:00
// Status of invoice
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' ;
2008-09-04 21:47:46 +02:00
print $facturestatic -> LibStatut ( $objp -> paye , $objp -> fk_statut , 5 , $objp -> am );
print '</td>' ;
2006-11-18 02:16:10 +01:00
2009-04-09 22:22:51 +02:00
// Checkbox
print '<td align="center">' ;
2012-09-15 09:02:20 +02:00
if ( ! empty ( $formfile -> numoffiles ))
print '<input id="cb' . $objp -> facid . '" class="flat checkformerge" type="checkbox" name="toGenerate[]" value="' . $objp -> facnumber . '">' ;
else
print ' ' ;
2009-04-09 22:22:51 +02:00
print '</td>' ;
2006-11-18 02:16:10 +01:00
print " </tr> \n " ;
2008-09-04 21:47:46 +02:00
$total_ht += $objp -> total_ht ;
2013-03-25 13:04:03 +01:00
$total_tva += ( $objp -> total_tva + $tx1 + $tx2 + $revenuestamp );
2008-09-04 21:47:46 +02:00
$total_ttc += $objp -> total_ttc ;
2013-03-25 12:20:24 +01:00
$total_paid += $objp -> am + $cn ;
2008-09-04 21:47:46 +02:00
$i ++ ;
2006-11-18 02:16:10 +01:00
}
2008-09-04 21:47:46 +02:00
print '<tr class="liste_total">' ;
2011-11-11 16:10:50 +01:00
print '<td colspan="4" align="left">' . $langs -> trans ( " Total " ) . '</td>' ;
2013-03-25 12:20:24 +01:00
print '<td align="right"><b>' . price ( $total_ht ) . '</b></td>' ;
print '<td align="right"><b>' . price ( $total_tva ) . '</b></td>' ;
print '<td align="right"><b>' . price ( $total_ttc ) . '</b></td>' ;
print '<td align="right"><b>' . price ( $total_paid ) . '</b></td>' ;
2013-07-14 20:33:54 +02:00
print '<td align="right"><b>' . price ( $total_ttc - $total_paid ) . '</b></td>' ;
2009-07-30 00:34:58 +02:00
print '<td align="center"> </td>' ;
2013-07-30 18:36:13 +02:00
print '<td align="center"> </td>' ;
2008-09-04 21:47:46 +02:00
print " </tr> \n " ;
2006-11-18 02:16:10 +01:00
}
2005-01-18 11:02:26 +01:00
2008-09-04 21:47:46 +02:00
print " </table> " ;
2009-01-21 17:53:50 +01:00
2008-09-04 21:47:46 +02:00
/*
* Show list of available documents
*/
$filedir = $diroutputpdf ;
$genallowed = $user -> rights -> facture -> lire ;
$delallowed = $user -> rights -> facture -> lire ;
print '<br>' ;
print '<input type="hidden" name="option" value="' . $option . '">' ;
2013-12-14 02:31:06 +01:00
// We disable multilang because we concat already existing pdf.
$formfile -> show_documents ( 'unpaid' , '' , $filedir , $urlsource , $genallowed , $delallowed , '' , 1 , 1 , 0 , 48 , 1 , $param , $langs -> trans ( " PDFMerge " ), $langs -> trans ( " PDFMerge " ));
2009-01-21 17:53:50 +01:00
print '</form>' ;
2011-11-22 02:15:58 +01:00
$db -> free ( $resql );
2005-01-18 11:02:26 +01:00
}
2011-11-22 02:15:58 +01:00
else dol_print_error ( $db , '' );
2005-01-18 11:02:26 +01:00
2012-02-18 03:29:20 +01:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-08-16 20:11:48 +02:00
$db -> close ();
2005-01-18 11:02:26 +01:00
?>