2018-12-08 21:33:54 +01:00
< ? php
/* Copyright ( C ) 2001 - 2002 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2010 Regis Houssin < regis . houssin @ capnetworks . com >
* Copyright ( C ) 2012 Vinícius Nogueira < viniciusvgn @ gmail . com >
* Copyright ( C ) 2014 Florian Henry < florian . henry @ open - cooncept . pro >
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
* Copyright ( C ) 2016 Juanjo Menent < jmenent @ 2 byte . es >
2019-01-28 21:39:22 +01:00
* Copyright ( C ) 2017 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2018-12-15 18:27:38 +01:00
* Copyright ( C ) 2018 Andreu Bisquerra < jove @ bisquerra . com >
2018-12-08 21:33:54 +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
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2018-12-08 21:33:54 +01:00
*/
/**
2018-12-19 16:12:55 +01:00
* \file htdocs / compta / cashcontrol / report . php
2019-01-07 19:35:20 +01:00
* \ingroup cashdesk | takepos
2018-12-08 21:33:54 +01:00
* \brief List of bank transactions
*/
2018-12-15 19:20:30 +01:00
require '../../main.inc.php' ;
2018-12-15 18:27:38 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/cashcontrol/class/cashcontrol.class.php' ;
2018-12-08 21:33:54 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
2019-01-07 19:35:20 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
2020-01-24 15:26:18 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/cashcontrol/class/cashcontrol.class.php' ;
2018-12-08 21:33:54 +01:00
2020-01-24 15:59:36 +01:00
$langs -> load ( " bills " );
2019-01-27 11:55:16 +01:00
$id = GETPOST ( 'id' , 'int' );
2018-12-08 21:33:54 +01:00
2020-01-30 01:48:28 +01:00
$_GET [ 'optioncss' ] = " print " ;
2020-03-15 13:57:31 +01:00
2020-01-30 01:48:28 +01:00
$cashcontrol = new CashControl ( $db );
2018-12-08 21:33:54 +01:00
$cashcontrol -> fetch ( $id );
2019-05-19 01:52:50 +02:00
//$limit = GETPOST('limit')?GETPOST('limit', 'int'):$conf->liste_limit;
2020-01-30 01:48:28 +01:00
$sortorder = 'ASC' ;
$sortfield = 'b.datev,b.dateo,b.rowid' ;
2018-12-08 21:33:54 +01:00
2020-01-30 01:48:28 +01:00
$arrayfields = array (
2018-12-08 21:33:54 +01:00
'b.rowid' => array ( 'label' => $langs -> trans ( " Ref " ), 'checked' => 1 ),
'b.dateo' => array ( 'label' => $langs -> trans ( " DateOperationShort " ), 'checked' => 1 ),
'b.num_chq' => array ( 'label' => $langs -> trans ( " Number " ), 'checked' => 1 ),
2018-12-15 18:27:38 +01:00
'ba.ref' => array ( 'label' => $langs -> trans ( " BankAccount " ), 'checked' => 1 ),
2020-01-24 15:59:36 +01:00
'cp.code' => array ( 'label' => $langs -> trans ( " PaymentMode " ), 'checked' => 1 ),
'b.debit' => array ( 'label' => $langs -> trans ( " Debit " ), 'checked' => 1 , 'position' => 600 ),
2018-12-08 21:33:54 +01:00
'b.credit' => array ( 'label' => $langs -> trans ( " Credit " ), 'checked' => 1 , 'position' => 605 ),
);
2018-12-19 16:12:55 +01:00
$syear = $cashcontrol -> year_close ;
$smonth = $cashcontrol -> month_close ;
$sday = $cashcontrol -> day_close ;
$posmodule = $cashcontrol -> posmodule ;
$terminalid = $cashcontrol -> posnumber ;
2018-12-08 21:33:54 +01:00
/*
* View
*/
2018-12-15 18:27:38 +01:00
2020-03-15 13:57:31 +01:00
$param = '' ;
2018-12-08 21:33:54 +01:00
llxHeader ( '' , $langs -> trans ( " CashControl " ), '' , '' , 0 , 0 , array (), array (), $param );
2018-12-19 16:12:55 +01:00
/* $sql = " SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro as conciliated, b.num_releve, b.num_chq, " ;
2018-12-08 21:33:54 +01:00
$sql .= " b.fk_account, b.fk_type, " ;
$sql .= " ba.rowid as bankid, ba.ref as bankref, " ;
$sql .= " bu.url_id, " ;
2019-05-04 17:23:57 +02:00
$sql .= " f.module_source, f.ref as ref " ;
2018-12-08 21:33:54 +01:00
$sql .= " FROM " ;
2018-12-19 16:12:55 +01:00
//if ($bid) $sql.= MAIN_DB_PREFIX."bank_class as l,";
2018-12-08 21:33:54 +01:00
$sql .= " " . MAIN_DB_PREFIX . " bank_account as ba, " ;
$sql .= " " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " bank_url as bu ON bu.fk_bank = b.rowid AND type = 'payment' " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " facture as f ON bu.url_id = f.rowid " ;
$sql .= " WHERE b.fk_account = ba.rowid " ;
2018-12-19 16:12:55 +01:00
// Define filter on invoice
$sql .= " AND f.module_source = ' " . $db -> escape ( $cashcontrol -> posmodule ) . " ' " ;
$sql .= " AND f.pos_source = ' " . $db -> escape ( $cashcontrol -> posnumber ) . " ' " ;
$sql .= " AND f.entity IN ( " . getEntity ( 'facture' ) . " ) " ;
// Define filter on data
if ( $syear && ! $smonth ) $sql .= " AND dateo BETWEEN ' " . $db -> idate ( dol_get_first_day ( $syear , 1 )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $syear , 12 )) . " ' " ;
elseif ( $syear && $smonth && ! $sday ) $sql .= " AND dateo BETWEEN ' " . $db -> idate ( dol_get_first_day ( $syear , $smonth )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $syear , $smonth )) . " ' " ;
elseif ( $syear && $smonth && $sday ) $sql .= " AND dateo BETWEEN ' " . $db -> idate ( dol_mktime ( 0 , 0 , 0 , $smonth , $sday , $syear )) . " ' AND ' " . $db -> idate ( dol_mktime ( 23 , 59 , 59 , $smonth , $sday , $syear )) . " ' " ;
else dol_print_error ( '' , 'Year not defined' );
// Define filter on bank account
$sql .= " AND (b.fk_account= " . $conf -> global -> CASHDESK_ID_BANKACCOUNT_CASH ;
$sql .= " OR b.fk_account= " . $conf -> global -> CASHDESK_ID_BANKACCOUNT_CB ;
$sql .= " OR b.fk_account= " . $conf -> global -> CASHDESK_ID_BANKACCOUNT_CHEQUE ;
2018-12-08 21:33:54 +01:00
$sql .= " ) " ;
2018-12-19 16:12:55 +01:00
*/
2019-05-04 17:23:57 +02:00
$sql = " SELECT f.rowid as facid, f.ref, f.datef as do, pf.amount as amount, b.fk_account as bankid, cp.code " ;
2020-01-30 01:48:28 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " paiement_facture as pf, " . MAIN_DB_PREFIX . " facture as f, " . MAIN_DB_PREFIX . " paiement as p, " . MAIN_DB_PREFIX . " c_paiement as cp, " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " WHERE pf.fk_facture = f.rowid AND p.rowid = pf.fk_paiement AND cp.id = p.fk_paiement AND p.fk_bank = b.rowid " ;
$sql .= " AND f.module_source = ' " . $db -> escape ( $posmodule ) . " ' " ;
$sql .= " AND f.pos_source = ' " . $db -> escape ( $terminalid ) . " ' " ;
$sql .= " AND f.paye = 1 " ;
$sql .= " AND p.entity IN ( " . getEntity ( 'facture' ) . " ) " ;
2018-12-19 16:12:55 +01:00
/* if ( $key == 'cash' ) $sql .= " AND cp.code = 'LIQ' " ;
elseif ( $key == 'cheque' ) $sql .= " AND cp.code = 'CHQ' " ;
elseif ( $key == 'card' ) $sql .= " AND cp.code = 'CB' " ;
else
{
dol_print_error ( 'Value for key = ' . $key . ' not supported' );
exit ;
} */
2020-01-30 01:48:28 +01:00
if ( $syear && ! $smonth ) $sql .= " AND datef BETWEEN ' " . $db -> idate ( dol_get_first_day ( $syear , 1 )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $syear , 12 )) . " ' " ;
elseif ( $syear && $smonth && ! $sday ) $sql .= " AND datef BETWEEN ' " . $db -> idate ( dol_get_first_day ( $syear , $smonth )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $syear , $smonth )) . " ' " ;
elseif ( $syear && $smonth && $sday ) $sql .= " AND datef BETWEEN ' " . $db -> idate ( dol_mktime ( 0 , 0 , 0 , $smonth , $sday , $syear )) . " ' AND ' " . $db -> idate ( dol_mktime ( 23 , 59 , 59 , $smonth , $sday , $syear )) . " ' " ;
2018-12-19 16:12:55 +01:00
else dol_print_error ( '' , 'Year not defined' );
2018-12-08 21:33:54 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
2018-12-15 18:27:38 +01:00
2018-12-08 21:33:54 +01:00
print " <center><h2> " ;
2020-01-30 01:48:28 +01:00
if ( $cashcontrol -> status == 2 ) print $langs -> trans ( " CashControl " ) . " " . $cashcontrol -> id ;
2018-12-15 19:46:51 +01:00
else print $langs -> trans ( " CashControl " ) . " - " . $langs -> trans ( " Draft " );
2018-12-19 16:12:55 +01:00
print " <br> " . $langs -> trans ( " DateCreationShort " ) . " : " . dol_print_date ( $cashcontrol -> date_creation , 'dayhour' ) . " </h2></center> " ;
2018-12-08 21:33:54 +01:00
2019-01-07 19:35:20 +01:00
$invoicetmp = new Facture ( $db );
print " <div style='text-align: right'><h2> " ;
print $langs -> trans ( " InitialBankBalance " ) . ' - ' . $langs -> trans ( " Cash " ) . " : " . price ( $cashcontrol -> opening );
print " </h2></div> " ;
2018-12-08 21:33:54 +01:00
print '<div class="div-table-responsive">' ;
print '<table class="tagtable liste">' . " \n " ;
2020-01-24 15:59:36 +01:00
$param = '' ;
2018-12-08 21:33:54 +01:00
// Fields title
print '<tr class="liste_titre">' ;
2019-01-27 11:55:16 +01:00
print_liste_field_titre ( $arrayfields [ 'b.rowid' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], 'b.rowid' , '' , $param , '' , $sortfield , $sortorder );
2020-01-24 15:59:36 +01:00
print_liste_field_titre ( $arrayfields [ 'b.dateo' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], 'b.dateo' , '' , $param , '"' , $sortfield , $sortorder , 'center ' );
print_liste_field_titre ( $arrayfields [ 'ba.ref' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], 'ba.ref' , '' , $param , '' , $sortfield , $sortorder , 'right ' );
print_liste_field_titre ( $arrayfields [ 'cp.code' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], 'cp.code' , '' , $param , '' , $sortfield , $sortorder , 'right ' );
print_liste_field_titre ( $arrayfields [ 'b.debit' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], 'b.amount' , '' , $param , '' , $sortfield , $sortorder , 'right ' );
print_liste_field_titre ( $arrayfields [ 'b.credit' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], 'b.amount' , '' , $param , '' , $sortfield , $sortorder , 'right ' );
2018-12-08 21:33:54 +01:00
print " </tr> \n " ;
$posconciliatecol = 0 ;
// Loop on each record
$sign = 1 ;
2020-01-30 01:48:28 +01:00
$cash = $bank = $cheque = $other = 0 ;
2018-12-08 21:33:54 +01:00
2020-01-24 15:59:36 +01:00
$totalarray = array ();
$cachebankaccount = array ();
$amountpertype = array ();
2019-05-19 01:52:50 +02:00
while ( $i < $num )
2018-12-08 21:33:54 +01:00
{
$objp = $db -> fetch_object ( $resql );
if ( empty ( $cachebankaccount [ $objp -> bankid ]))
{
$bankaccounttmp = new Account ( $db );
$bankaccounttmp -> fetch ( $objp -> bankid );
2020-01-30 01:48:28 +01:00
$cachebankaccount [ $objp -> bankid ] = $bankaccounttmp ;
2018-12-08 21:33:54 +01:00
$bankaccount = $bankaccounttmp ;
2020-05-21 15:05:19 +02:00
} else {
2018-12-08 21:33:54 +01:00
$bankaccount = $cachebankaccount [ $objp -> bankid ];
}
2018-12-15 18:27:38 +01:00
2020-01-24 15:59:36 +01:00
$invoicetmp -> fetch ( $objp -> facid );
/* if ( $first == " yes " )
2018-12-19 16:12:55 +01:00
{
2018-12-08 21:33:54 +01:00
print '<tr class="oddeven">' ;
2018-12-19 16:12:55 +01:00
print '<td>' . $langs -> trans ( " InitialBankBalance " ) . ' - ' . $langs -> trans ( " Cash " ) . '</td>' ;
2019-01-24 16:43:28 +01:00
print '<td></td><td></td><td></td><td class="right">' . price ( $cashcontrol -> opening ) . '</td>' ;
2018-12-19 16:12:55 +01:00
print '</tr>' ;
$first = " no " ;
2019-01-07 19:35:20 +01:00
} */
2018-12-08 21:33:54 +01:00
2018-12-19 16:12:55 +01:00
print '<tr class="oddeven">' ;
// Ref
2019-01-24 16:43:28 +01:00
print '<td class="nowrap left">' ;
2019-01-07 19:35:20 +01:00
print $invoicetmp -> getNomUrl ( 1 );
2018-12-08 21:33:54 +01:00
print '</td>' ;
2020-01-30 01:48:28 +01:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
2018-12-08 21:33:54 +01:00
// Date ope
2019-01-24 16:43:28 +01:00
print '<td class="nowrap left">' ;
2019-01-27 11:55:16 +01:00
print '<span id="dateoperation_' . $objp -> rowid . '">' . dol_print_date ( $db -> jdate ( $objp -> do ), " day " ) . " </span> " ;
2018-12-08 21:33:54 +01:00
print " </td> \n " ;
2020-01-30 01:48:28 +01:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
2018-12-08 21:33:54 +01:00
// Bank account
2019-01-24 16:43:28 +01:00
print '<td class="nowrap right">' ;
2018-12-08 21:33:54 +01:00
print $bankaccount -> getNomUrl ( 1 );
2020-01-30 01:48:28 +01:00
if ( $cashcontrol -> posmodule == " takepos " ) {
2020-01-24 15:59:36 +01:00
$var1 = 'CASHDESK_ID_BANKACCOUNT_CASH' . $cashcontrol -> posnumber ;
2020-05-21 15:05:19 +02:00
} else {
2020-01-24 15:59:36 +01:00
$var1 = 'CASHDESK_ID_BANKACCOUNT_CASH' ;
}
if ( $objp -> code == 'CHQ' ) {
$cheque += $objp -> amount ;
} elseif ( $objp -> code == 'CB' ) {
$bank += $objp -> amount ;
} else {
if ( $conf -> global -> $var1 == $bankaccount -> id ) $cash += $objp -> amount ;
//elseif ($conf->global->$var2 == $bankaccount->id) $bank+=$objp->amount;
//elseif ($conf->global->$var3 == $bankaccount->id) $cheque+=$objp->amount;
else $other += $objp -> amount ;
2019-08-18 09:33:02 +02:00
}
2018-12-08 21:33:54 +01:00
print " </td> \n " ;
2020-01-30 01:48:28 +01:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
2018-12-08 21:33:54 +01:00
2020-01-24 15:59:36 +01:00
// Type
print '<td class="right">' ;
print $objp -> code ;
if ( empty ( $amountpertype [ $objp -> code ])) $amountpertype [ $objp -> code ] = 0 ;
print " </td> \n " ;
2020-01-30 01:48:28 +01:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
2020-01-24 15:59:36 +01:00
// Debit
2019-01-24 16:43:28 +01:00
print '<td class="right">' ;
2018-12-08 21:33:54 +01:00
if ( $objp -> amount < 0 )
{
print price ( $objp -> amount * - 1 );
2019-11-05 12:47:38 +01:00
$totalarray [ 'val' ][ 'totaldebfield' ] += $objp -> amount ;
2020-01-24 15:59:36 +01:00
$amountpertype [ $objp -> code ] += $objp -> amount ;
2018-12-08 21:33:54 +01:00
}
print " </td> \n " ;
2020-01-30 01:48:28 +01:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
if ( ! $i ) $totalarray [ 'pos' ][ $totalarray [ 'nbfield' ]] = 'totaldebfield' ;
2018-12-08 21:33:54 +01:00
// Credit
2019-01-24 16:43:28 +01:00
print '<td class="right">' ;
2018-12-08 21:33:54 +01:00
if ( $objp -> amount > 0 )
{
print price ( $objp -> amount );
2019-11-05 12:47:38 +01:00
$totalarray [ 'val' ][ 'totalcredfield' ] += $objp -> amount ;
2020-01-24 15:59:36 +01:00
$amountpertype [ $objp -> code ] -= $objp -> amount ;
2018-12-08 21:33:54 +01:00
}
print " </td> \n " ;
2020-01-30 01:48:28 +01:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
if ( ! $i ) $totalarray [ 'pos' ][ $totalarray [ 'nbfield' ]] = 'totalcredfield' ;
2018-12-08 21:33:54 +01:00
print " </tr> " ;
$i ++ ;
}
// Show total line
2019-11-05 12:47:38 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php' ;
2018-12-08 21:33:54 +01:00
print " </table> " ;
2018-12-15 18:27:38 +01:00
2020-01-24 15:59:36 +01:00
//$cash = $amountpertype['LIQ'] + $cashcontrol->opening;
2020-01-24 15:26:18 +01:00
$cash = $cash + $cashcontrol -> opening ;
2020-01-24 15:59:36 +01:00
2018-12-19 16:12:55 +01:00
print " <div style='text-align: right'><h2> " ;
2020-01-24 15:26:18 +01:00
print $langs -> trans ( " Cash " ) . " : " . price ( $cash );
2020-03-15 13:57:31 +01:00
if ( $cashcontrol -> status == $cashcontrol :: STATUS_VALIDATED && $cash != $cashcontrol -> cash ) {
2020-01-24 15:26:18 +01:00
print ' <> <span class="amountremaintopay">' . $langs -> trans ( " Declared " ) . ': ' . price ( $cashcontrol -> cash ) . '</span>' ;
}
print " <br><br> " ;
2020-01-24 15:59:36 +01:00
//print '<br>';
2020-01-24 15:26:18 +01:00
print $langs -> trans ( " PaymentTypeCHQ " ) . " : " . price ( $cheque );
2020-03-15 13:57:31 +01:00
if ( $cashcontrol -> status == $cashcontrol :: STATUS_VALIDATED && $cheque != $cashcontrol -> cheque ) {
2020-01-24 15:26:18 +01:00
print ' <> <span class="amountremaintopay">' . $langs -> trans ( " Declared " ) . ': ' . price ( $cashcontrol -> cheque ) . '</span>' ;
}
print " <br><br> " ;
2020-01-24 15:59:36 +01:00
//print '<br>';
2020-01-24 15:26:18 +01:00
print $langs -> trans ( " PaymentTypeCB " ) . " : " . price ( $bank );
2020-03-15 13:57:31 +01:00
if ( $cashcontrol -> status == $cashcontrol :: STATUS_VALIDATED && $bank != $cashcontrol -> card ) {
2020-01-24 15:59:36 +01:00
print ' <> <span class="amountremaintopay">' . $langs -> trans ( " Declared " ) . ': ' . price ( $cashcontrol -> card ) . '</span>' ;
}
2020-01-24 15:26:18 +01:00
print " <br><br> " ;
2020-01-24 15:59:36 +01:00
// print '<br>';
2020-01-24 15:26:18 +01:00
if ( $other ) {
print '<br>' . $langs -> trans ( " Other " ) . " : " . price ( $other ) . " <br><br> " ;
}
2018-12-19 16:12:55 +01:00
print " </h2></div> " ;
2018-12-15 18:27:38 +01:00
2018-12-08 21:33:54 +01:00
//save totals to DB
2018-12-19 16:12:55 +01:00
/*
2018-12-08 21:33:54 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " pos_cash_fence " ;
$sql .= " SET " ;
$sql .= " cash=' " . $cash . " ' " ;
$sql .= " , card=' " . $bank . " ' " ;
2018-12-15 18:27:38 +01:00
$sql .= " where rowid= " . $id ;
2018-12-08 21:33:54 +01:00
$db -> query ( $sql );
2018-12-19 16:12:55 +01:00
*/
2018-12-08 21:33:54 +01:00
print " </div> " ;
print '</form>' ;
2018-12-15 18:27:38 +01:00
2018-12-08 21:33:54 +01:00
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2018-12-08 21:33:54 +01:00
dol_print_error ( $db );
}
llxFooter ();
$db -> close ();