2004-10-19 22:35:36 +02:00
< ? php
2005-01-07 16:11:07 +01:00
/* Copyright ( C ) 2004 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2012-12-01 15:45:05 +01:00
* Copyright ( C ) 2005 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
2011-02-03 23:19:36 +01:00
* Copyright ( C ) 2011 Juanjo Menent < jmenent @ 2 byte . es >
2013-05-07 15:34:40 +02:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2004-09-28 17:30:02 +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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2004-09-28 17:30:02 +02: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 />.
2004-09-28 17:30:02 +02:00
*/
2005-01-30 02:00:40 +01:00
/**
2008-11-05 23:34:14 +01:00
* \file htdocs / compta / prelevement / index . php
2012-08-05 14:37:45 +02:00
* \ingroup prelevement
2020-07-01 19:42:28 +02:00
* \brief Home page for direct debit orders
2008-11-05 23:34:14 +01:00
*/
2004-09-28 17:30:02 +02:00
2013-05-07 15:34:40 +02:00
2018-07-26 11:57:25 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/prelevement.lib.php' ;
2013-06-05 16:24:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'banks' , 'categories' , 'withdrawals' ));
2007-06-14 10:17:05 +02:00
2008-02-25 17:30:43 +01:00
// Security check
2019-01-27 11:55:16 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2021-02-23 21:09:01 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2021-10-04 04:36:58 +02:00
$result = restrictedArea ( $user , 'prelevement' , '' , 'bons' );
2007-06-14 10:17:05 +02:00
2021-12-18 14:55:35 +01:00
$usercancreate = $user -> rights -> prelevement -> bons -> creer ;
2015-05-15 20:10:17 +02:00
2010-09-05 15:24:59 +02:00
/*
* Actions
*/
2021-10-04 04:36:58 +02:00
// None
2004-09-28 17:30:02 +02:00
2005-07-25 15:08:19 +02:00
/*
2008-11-05 23:34:14 +01:00
* View
2005-07-25 15:08:19 +02:00
*/
2005-08-13 19:11:27 +02:00
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $langs -> trans ( " CustomersStandingOrdersArea " ));
2005-08-13 19:11:27 +02:00
2021-02-23 21:09:01 +01:00
if ( prelevement_check_config () < 0 ) {
2011-02-03 23:19:36 +01:00
$langs -> load ( " errors " );
2021-06-23 13:30:00 +02:00
setEventMessages ( $langs -> trans ( " ErrorModuleSetupNotComplete " , $langs -> transnoentitiesnoconv ( " PaymentByDirectDebit " )), null , 'errors' );
2011-02-03 23:19:36 +01:00
}
2021-12-18 14:55:35 +01:00
$newcardbutton = '' ;
if ( $usercancreate ) {
$newcardbutton .= dolGetButtonTitle ( $langs -> trans ( 'NewStandingOrder' ), '' , 'fa fa-plus-circle' , DOL_URL_ROOT . '/compta/prelevement/create.php?type=' );
}
print load_fiche_titre ( $langs -> trans ( " CustomersStandingOrdersArea " ), $newcardbutton );
2005-08-13 19:11:27 +02:00
2013-04-03 18:37:54 +02:00
2013-03-30 14:27:13 +01:00
print '<div class="fichecenter"><div class="fichethirdleft">' ;
2005-08-13 19:11:27 +02:00
2020-04-10 10:59:32 +02:00
$thirdpartystatic = new Societe ( $db );
$invoicestatic = new Facture ( $db );
2005-07-25 15:08:19 +02:00
$bprev = new BonPrelevement ( $db );
2019-10-30 18:52:54 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2017-03-07 22:45:22 +01:00
print '<tr class="liste_titre"><th colspan="2">' . $langs -> trans ( " Statistics " ) . '</th></tr>' ;
2017-04-14 11:22:48 +02:00
2017-04-14 13:02:29 +02:00
print '<tr class="oddeven"><td>' . $langs -> trans ( " NbOfInvoiceToWithdraw " ) . '</td>' ;
2019-02-10 16:08:03 +01:00
print '<td class="right">' ;
2012-04-18 14:27:31 +02:00
print '<a href="' . DOL_URL_ROOT . '/compta/prelevement/demandes.php?status=0">' ;
2020-05-30 23:46:14 +02:00
print $bprev -> nbOfInvoiceToPay ( 'direct-debit' );
2011-06-12 20:05:30 +02:00
print '</a>' ;
2005-07-25 15:08:19 +02:00
print '</td></tr>' ;
2017-04-14 11:22:48 +02:00
2017-04-14 13:02:29 +02:00
print '<tr class="oddeven"><td>' . $langs -> trans ( " AmountToWithdraw " ) . '</td>' ;
2021-03-29 13:41:28 +02:00
print '<td class="right"><span class="amount">' ;
2020-05-30 23:46:14 +02:00
print price ( $bprev -> SommeAPrelever ( 'direct-debit' ), '' , '' , 1 , - 1 , - 1 , 'auto' );
2021-03-29 13:41:28 +02:00
print '</span></td></tr></table></div><br>' ;
2005-07-25 15:08:19 +02:00
2005-01-30 02:00:40 +01:00
2011-06-12 20:05:30 +02:00
2005-01-07 16:11:07 +01:00
/*
2010-09-05 15:24:59 +02:00
* Invoices waiting for withdraw
2005-01-07 16:11:07 +01:00
*/
2018-12-02 14:31:45 +01:00
$sql = " SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type, " ;
2020-04-10 10:59:32 +02:00
$sql .= " pfd.date_demande, pfd.amount, " ;
2022-04-06 15:35:49 +02:00
$sql .= " s.nom as name, s.email, s.rowid as socid, s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6 " ;
2020-04-10 10:59:32 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f, " ;
$sql .= " " . MAIN_DB_PREFIX . " societe as s " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-02-23 21:09:01 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
2020-04-10 10:59:32 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " prelevement_facture_demande as pfd " ;
$sql .= " WHERE s.rowid = f.fk_soc " ;
$sql .= " AND f.entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
$sql .= " AND f.total_ttc > 0 " ;
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS )) {
2020-04-10 10:59:32 +02:00
$sql .= " AND f.fk_statut = " . Facture :: STATUS_VALIDATED ;
2019-09-06 14:45:55 +02:00
}
2020-07-01 19:42:28 +02:00
$sql .= " AND pfd.traite = 0 " ;
$sql .= " AND pfd.ext_payment_id IS NULL " ;
$sql .= " AND pfd.fk_facture = f.rowid " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-02-23 21:09:01 +01:00
}
if ( $socid ) {
2021-03-22 13:31:06 +01:00
$sql .= " AND f.fk_soc = " . (( int ) $socid );
2021-02-23 21:09:01 +01:00
}
2009-04-27 22:37:50 +02:00
2020-04-10 10:59:32 +02:00
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $resql ) {
2020-10-31 14:32:18 +01:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
print '<div class="div-table-responsive-no-min">' ;
print '<table class="noborder centpercent">' ;
print '<tr class="liste_titre">' ;
print '<th colspan="5">' . $langs -> trans ( " InvoiceWaitingWithdraw " ) . ' (' . $num . ')</th></tr>' ;
2021-02-23 21:09:01 +01:00
if ( $num ) {
while ( $i < $num && $i < 20 ) {
2020-10-31 14:32:18 +01:00
$obj = $db -> fetch_object ( $resql );
$invoicestatic -> id = $obj -> rowid ;
$invoicestatic -> ref = $obj -> ref ;
$invoicestatic -> statut = $obj -> fk_statut ;
$invoicestatic -> paye = $obj -> paye ;
$invoicestatic -> type = $obj -> type ;
$alreadypayed = $invoicestatic -> getSommePaiement ();
$thirdpartystatic -> id = $obj -> socid ;
$thirdpartystatic -> name = $obj -> name ;
$thirdpartystatic -> email = $obj -> email ;
2022-04-06 15:25:10 +02:00
$thirdpartystatic -> tva_intra = $obj -> tva_intra ;
2022-04-06 15:35:49 +02:00
$thirdpartystatic -> siren = $obj -> idprof1 ;
$thirdpartystatic -> siret = $obj -> idprof2 ;
$thirdpartystatic -> ape = $obj -> idprof3 ;
$thirdpartystatic -> idprof1 = $obj -> idprof1 ;
$thirdpartystatic -> idprof2 = $obj -> idprof2 ;
$thirdpartystatic -> idprof3 = $obj -> idprof3 ;
$thirdpartystatic -> idprof4 = $obj -> idprof4 ;
$thirdpartystatic -> idprof5 = $obj -> idprof5 ;
$thirdpartystatic -> idprof6 = $obj -> idprof6 ;
2020-10-31 14:32:18 +01:00
2022-06-10 16:46:09 +02:00
print '<tr class="oddeven"><td class="nowraponall">' ;
2020-10-31 14:32:18 +01:00
print $invoicestatic -> getNomUrl ( 1 , 'withdraw' );
print '</td>' ;
2022-06-10 16:46:09 +02:00
print '<td class="tdoverflowmax150">' ;
2020-10-31 14:32:18 +01:00
print $thirdpartystatic -> getNomUrl ( 1 , 'customer' );
print '</td>' ;
print '<td class="right">' ;
2022-04-06 15:25:10 +02:00
print '<span class="amount">' . price ( $obj -> amount ) . '</span>' ;
2020-10-31 14:32:18 +01:00
print '</td>' ;
print '<td class="right">' ;
print dol_print_date ( $db -> jdate ( $obj -> date_demande ), 'day' );
print '</td>' ;
print '<td class="right">' ;
print $invoicestatic -> getLibStatut ( 3 , $alreadypayed );
print '</td>' ;
print '</tr>' ;
$i ++ ;
}
} else {
2021-02-27 17:15:40 +01:00
$titlefortab = $langs -> transnoentitiesnoconv ( " StandingOrders " );
print '<tr class="oddeven"><td colspan="5" class="opacitymedium">' . $langs -> trans ( " NoInvoiceToWithdraw " , $titlefortab , $titlefortab ) . '</td></tr>' ;
2020-10-31 14:32:18 +01:00
}
print " </table></div><br> " ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
dol_print_error ( $db );
2004-09-28 17:30:02 +02:00
}
2008-11-05 23:34:14 +01:00
2021-10-23 17:18:35 +02:00
print '</div><div class="fichetwothirdright">' ;
2014-03-17 20:43:01 +01:00
/*
2020-07-01 19:42:28 +02:00
* Direct debit orders
2014-03-17 20:43:01 +01:00
*/
2020-07-01 19:42:28 +02:00
2020-04-10 10:59:32 +02:00
$limit = 5 ;
2014-03-17 20:43:01 +01:00
$sql = " SELECT p.rowid, p.ref, p.amount, p.datec, p.statut " ;
2020-04-10 10:59:32 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " prelevement_bons as p " ;
2020-05-27 20:14:11 +02:00
$sql .= " WHERE p.type = 'debit-order' " ;
2020-10-31 14:32:18 +01:00
$sql .= " AND entity IN ( " . getEntity ( 'prelevement' ) . " ) " ;
2020-04-10 10:59:32 +02:00
$sql .= " ORDER BY datec DESC " ;
$sql .= $db -> plimit ( $limit );
2014-03-17 20:43:01 +01:00
$result = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $result ) {
2020-10-31 14:32:18 +01:00
$num = $db -> num_rows ( $result );
$i = 0 ;
print " \n <!-- debut table --> \n " ;
print '<div class="div-table-responsive-no-min">' ;
print '<table class="noborder centpercent">' ;
print '<tr class="liste_titre">' ;
print '<th>' . $langs -> trans ( " LastWithdrawalReceipt " , $limit ) . '</th>' ;
print '<th>' . $langs -> trans ( " Date " ) . '</th>' ;
print '<th class="right">' . $langs -> trans ( " Amount " ) . '</th>' ;
print '<th class="right">' . $langs -> trans ( " Status " ) . '</th>' ;
print '</tr>' ;
if ( $num > 0 ) {
2021-02-23 21:09:01 +01:00
while ( $i < min ( $num , $limit )) {
2020-10-31 14:32:18 +01:00
$obj = $db -> fetch_object ( $result );
$bprev -> id = $obj -> rowid ;
$bprev -> ref = $obj -> ref ;
$bprev -> statut = $obj -> statut ;
2022-06-10 16:46:09 +02:00
print '<tr class="oddeven">' ;
print '<td class="nowraponall">' ;
2020-10-31 14:32:18 +01:00
print $bprev -> getNomUrl ( 1 );
print " </td> \n " ;
print '<td>' . dol_print_date ( $db -> jdate ( $obj -> datec ), " dayhour " ) . " </td> \n " ;
2022-06-10 16:46:09 +02:00
print '<td class="right nowraponall"><span class="amount">' . price ( $obj -> amount ) . " </span></td> \n " ;
2020-10-31 14:32:18 +01:00
print '<td class="right">' . $bprev -> getLibStatut ( 3 ) . " </td> \n " ;
print " </tr> \n " ;
$i ++ ;
}
} else {
2021-10-04 04:14:31 +02:00
print '<tr><td colspan="4"><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td></tr>' ;
2020-10-31 14:32:18 +01:00
}
print " </table></div><br> " ;
$db -> free ( $result );
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
dol_print_error ( $db );
2014-03-17 20:43:01 +01:00
}
2021-10-23 17:18:35 +02:00
print '</div></div>' ;
2004-09-28 17:30:02 +02:00
2018-08-08 12:29:36 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2013-03-16 14:53:15 +01:00
$db -> close ();